LCOV - code coverage report
Current view: top level - svtools/source/contnr - treelistentry.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 107 0.0 %
Date: 2014-04-14 Functions: 0 32 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "svtools/treelistentry.hxx"
      21             : #include "svtools/treelist.hxx"
      22             : 
      23             : #include <limits>
      24             : 
      25           0 : void SvTreeListEntry::ClearChildren()
      26             : {
      27           0 :     maChildren.clear();
      28           0 : }
      29             : 
      30           0 : void SvTreeListEntry::SetListPositions()
      31             : {
      32           0 :     SvTreeListEntries::iterator it = maChildren.begin(), itEnd = maChildren.end();
      33           0 :     sal_uLong nCur = 0;
      34           0 :     for (; it != itEnd; ++it)
      35             :     {
      36           0 :         SvTreeListEntry& rEntry = *it;
      37           0 :         rEntry.nListPos &= 0x80000000;
      38           0 :         rEntry.nListPos |= nCur;
      39           0 :         ++nCur;
      40             :     }
      41             : 
      42           0 :     nListPos &= (~0x80000000); // remove the invalid bit.
      43           0 : }
      44             : 
      45           0 : void SvTreeListEntry::InvalidateChildrensListPositions()
      46             : {
      47           0 :     nListPos |= 0x80000000;
      48           0 : }
      49             : 
      50           0 : SvTreeListEntry::SvTreeListEntry()
      51             :     : pParent(NULL)
      52             :     , nAbsPos(0)
      53             :     , nListPos(0)
      54             :     , bIsMarked(false)
      55             :     , pUserData(NULL)
      56           0 :     , nEntryFlags(0)
      57             : {
      58           0 : }
      59             : 
      60           0 : SvTreeListEntry::SvTreeListEntry(const SvTreeListEntry& r)
      61             :     : pParent(NULL)
      62             :     , nAbsPos(r.nAbsPos)
      63           0 :     , nListPos(r.nListPos & 0x7FFFFFFF)
      64             :     , bIsMarked(r.bIsMarked)
      65             :     , pUserData(r.pUserData)
      66           0 :     , nEntryFlags(r.nEntryFlags)
      67             : {
      68           0 :     SvTreeListEntries::const_iterator it = r.maChildren.begin(), itEnd = r.maChildren.end();
      69           0 :     for (; it != itEnd; ++it)
      70           0 :         maChildren.push_back(new SvTreeListEntry(*it));
      71           0 : }
      72             : 
      73           0 : SvTreeListEntry::~SvTreeListEntry()
      74             : {
      75             : #ifdef DBG_UTIL
      76             :     pParent     = 0;
      77             : #endif
      78             : 
      79           0 :     maChildren.clear();
      80           0 :     maItems.clear();
      81           0 : }
      82             : 
      83           0 : bool SvTreeListEntry::HasChildren() const
      84             : {
      85           0 :     return !maChildren.empty();
      86             : }
      87             : 
      88           0 : bool SvTreeListEntry::HasChildListPos() const
      89             : {
      90           0 :     if( pParent && !(pParent->nListPos & 0x80000000) )
      91           0 :         return true;
      92           0 :     else return false;
      93             : }
      94             : 
      95           0 : sal_uLong SvTreeListEntry::GetChildListPos() const
      96             : {
      97           0 :     if( pParent && (pParent->nListPos & 0x80000000) )
      98           0 :         pParent->SetListPositions();
      99           0 :     return ( nListPos & 0x7fffffff );
     100             : }
     101             : 
     102           0 : SvTreeListEntries& SvTreeListEntry::GetChildEntries()
     103             : {
     104           0 :     return maChildren;
     105             : }
     106             : 
     107           0 : const SvTreeListEntries& SvTreeListEntry::GetChildEntries() const
     108             : {
     109           0 :     return maChildren;
     110             : }
     111             : 
     112           0 : void SvTreeListEntry::Clone(SvTreeListEntry* pSource)
     113             : {
     114           0 :     nListPos &= 0x80000000;
     115           0 :     nListPos |= ( pSource->nListPos & 0x7fffffff);
     116           0 :     nAbsPos     = pSource->nAbsPos;
     117             : 
     118             :     SvLBoxItem* pNewItem;
     119           0 :     maItems.clear();
     120           0 :     ItemsType::iterator it = pSource->maItems.begin(), itEnd = pSource->maItems.end();
     121           0 :     for (; it != itEnd; ++it)
     122             :     {
     123           0 :         SvLBoxItem* pItem = &(*it);
     124           0 :         pNewItem = pItem->Create();
     125           0 :         pNewItem->Clone(pItem);
     126           0 :         maItems.push_back(pNewItem);
     127             :     }
     128             : 
     129           0 :     pUserData = pSource->GetUserData();
     130           0 :     nEntryFlags = pSource->nEntryFlags;
     131           0 : }
     132             : 
     133           0 : size_t SvTreeListEntry::ItemCount() const
     134             : {
     135           0 :     return maItems.size();
     136             : }
     137             : 
     138           0 : void SvTreeListEntry::AddItem( SvLBoxItem* pItem )
     139             : {
     140           0 :     maItems.push_back( pItem );
     141           0 : }
     142             : 
     143           0 : void SvTreeListEntry::EnableChildrenOnDemand( bool bEnable )
     144             : {
     145           0 :     if ( bEnable )
     146           0 :         nEntryFlags |= SV_ENTRYFLAG_CHILDREN_ON_DEMAND;
     147             :     else
     148           0 :         nEntryFlags &= (~SV_ENTRYFLAG_CHILDREN_ON_DEMAND);
     149           0 : }
     150             : 
     151           0 : void SvTreeListEntry::ReplaceItem( SvLBoxItem* pNewItem, size_t nPos )
     152             : {
     153             :     DBG_ASSERT(pNewItem,"ReplaceItem:No Item");
     154           0 :     if (nPos >= maItems.size())
     155             :     {
     156             :         // Out of bound. Bail out.
     157           0 :         delete pNewItem;
     158           0 :         return;
     159             :     }
     160             : 
     161           0 :     maItems.erase(maItems.begin()+nPos);
     162           0 :     maItems.insert(maItems.begin()+nPos, pNewItem);
     163             : }
     164             : 
     165           0 : const SvLBoxItem* SvTreeListEntry::GetItem( size_t nPos ) const
     166             : {
     167           0 :     return &maItems[nPos];
     168             : }
     169             : 
     170           0 : SvLBoxItem* SvTreeListEntry::GetItem( size_t nPos )
     171             : {
     172           0 :     return &maItems[nPos];
     173             : }
     174             : 
     175             : namespace {
     176             : 
     177             : class FindByType : std::unary_function<SvLBoxItem, void>
     178             : {
     179             :     sal_uInt16 mnId;
     180             : public:
     181           0 :     FindByType(sal_uInt16 nId) : mnId(nId) {}
     182           0 :     bool operator() (const SvLBoxItem& rItem) const
     183             :     {
     184           0 :         return rItem.GetType() == mnId;
     185             :     }
     186             : };
     187             : 
     188             : class FindByPointer : std::unary_function<SvLBoxItem, void>
     189             : {
     190             :     const SvLBoxItem* mpItem;
     191             : public:
     192           0 :     FindByPointer(const SvLBoxItem* p) : mpItem(p) {}
     193           0 :     bool operator() (const SvLBoxItem& rItem) const
     194             :     {
     195           0 :         return &rItem == mpItem;
     196             :     }
     197             : };
     198             : 
     199             : }
     200             : 
     201           0 : const SvLBoxItem* SvTreeListEntry::GetFirstItem( sal_uInt16 nId ) const
     202             : {
     203           0 :     ItemsType::const_iterator it = std::find_if(maItems.begin(), maItems.end(), FindByType(nId));
     204           0 :     return it == maItems.end() ? NULL : &(*it);
     205             : }
     206             : 
     207           0 : SvLBoxItem* SvTreeListEntry::GetFirstItem( sal_uInt16 nId )
     208             : {
     209           0 :     ItemsType::iterator it = std::find_if(maItems.begin(), maItems.end(), FindByType(nId));
     210           0 :     return it == maItems.end() ? NULL : &(*it);
     211             : }
     212             : 
     213           0 : size_t SvTreeListEntry::GetPos( const SvLBoxItem* pItem ) const
     214             : {
     215           0 :     ItemsType::const_iterator it = std::find_if(maItems.begin(), maItems.end(), FindByPointer(pItem));
     216           0 :     return it == maItems.end() ? ITEM_NOT_FOUND : std::distance(maItems.begin(), it);
     217             : }
     218             : 
     219           0 : void* SvTreeListEntry::GetUserData() const
     220             : {
     221           0 :     return pUserData;
     222             : }
     223             : 
     224           0 : void SvTreeListEntry::SetUserData( void* pPtr )
     225             : {
     226           0 :     pUserData = pPtr;
     227           0 : }
     228             : 
     229           0 : bool SvTreeListEntry::HasChildrenOnDemand() const
     230             : {
     231           0 :     return (bool)((nEntryFlags & SV_ENTRYFLAG_CHILDREN_ON_DEMAND)!=0);
     232             : }
     233             : 
     234           0 : bool SvTreeListEntry::HasInUseEmphasis() const
     235             : {
     236           0 :     return (bool)((nEntryFlags & SV_ENTRYFLAG_IN_USE)!=0);
     237             : }
     238             : 
     239           0 : sal_uInt16 SvTreeListEntry::GetFlags() const
     240             : {
     241           0 :     return nEntryFlags;
     242             : }
     243             : 
     244           0 : void SvTreeListEntry::SetFlags( sal_uInt16 nFlags )
     245             : {
     246           0 :     nEntryFlags = nFlags;
     247           0 : }
     248             : 
     249             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10