LCOV - code coverage report
Current view: top level - svtools/source/contnr - treelistentry.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 57 99 57.6 %
Date: 2014-11-03 Functions: 24 30 80.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 <vcl/svapp.hxx>
      24             : #include <vcl/settings.hxx>
      25             : 
      26             : #include <limits>
      27             : 
      28        1146 : void SvTreeListEntry::ClearChildren()
      29             : {
      30        1146 :     maChildren.clear();
      31        1146 : }
      32             : 
      33           0 : void SvTreeListEntry::SetListPositions()
      34             : {
      35           0 :     SvTreeListEntries::iterator it = maChildren.begin(), itEnd = maChildren.end();
      36           0 :     sal_uLong nCur = 0;
      37           0 :     for (; it != itEnd; ++it)
      38             :     {
      39           0 :         SvTreeListEntry& rEntry = *it;
      40           0 :         rEntry.nListPos &= 0x80000000;
      41           0 :         rEntry.nListPos |= nCur;
      42           0 :         ++nCur;
      43             :     }
      44             : 
      45           0 :     nListPos &= (~0x80000000); // remove the invalid bit.
      46           0 : }
      47             : 
      48           0 : void SvTreeListEntry::InvalidateChildrensListPositions()
      49             : {
      50           0 :     nListPos |= 0x80000000;
      51           0 : }
      52             : 
      53        1720 : SvTreeListEntry::SvTreeListEntry()
      54             :     : pParent(NULL)
      55             :     , nAbsPos(0)
      56             :     , nListPos(0)
      57             :     , bIsMarked(false)
      58             :     , pUserData(NULL)
      59             :     , nEntryFlags(0)
      60        1720 :     , maBackColor(Application::GetSettings().GetStyleSettings().GetRowColor())
      61             : {
      62        1720 : }
      63             : 
      64           0 : SvTreeListEntry::SvTreeListEntry(const SvTreeListEntry& r)
      65             :     : pParent(NULL)
      66             :     , nAbsPos(r.nAbsPos)
      67           0 :     , nListPos(r.nListPos & 0x7FFFFFFF)
      68             :     , bIsMarked(r.bIsMarked)
      69             :     , pUserData(r.pUserData)
      70             :     , nEntryFlags(r.nEntryFlags)
      71           0 :     , maBackColor(Application::GetSettings().GetStyleSettings().GetRowColor())
      72             : {
      73           0 :     SvTreeListEntries::const_iterator it = r.maChildren.begin(), itEnd = r.maChildren.end();
      74           0 :     for (; it != itEnd; ++it)
      75           0 :         maChildren.push_back(new SvTreeListEntry(*it));
      76           0 : }
      77             : 
      78        5148 : SvTreeListEntry::~SvTreeListEntry()
      79             : {
      80             : #ifdef DBG_UTIL
      81             :     pParent     = 0;
      82             : #endif
      83             : 
      84        1716 :     maChildren.clear();
      85        1716 :     maItems.clear();
      86        3432 : }
      87             : 
      88        2399 : bool SvTreeListEntry::HasChildren() const
      89             : {
      90        2399 :     return !maChildren.empty();
      91             : }
      92             : 
      93           0 : bool SvTreeListEntry::HasChildListPos() const
      94             : {
      95           0 :     if( pParent && !(pParent->nListPos & 0x80000000) )
      96           0 :         return true;
      97           0 :     else return false;
      98             : }
      99             : 
     100        7719 : sal_uLong SvTreeListEntry::GetChildListPos() const
     101             : {
     102        7719 :     if( pParent && (pParent->nListPos & 0x80000000) )
     103           0 :         pParent->SetListPositions();
     104        7719 :     return ( nListPos & 0x7fffffff );
     105             : }
     106             : 
     107             : 
     108             : 
     109           0 : void SvTreeListEntry::Clone(SvTreeListEntry* pSource)
     110             : {
     111           0 :     nListPos &= 0x80000000;
     112           0 :     nListPos |= ( pSource->nListPos & 0x7fffffff);
     113           0 :     nAbsPos     = pSource->nAbsPos;
     114             : 
     115             :     SvLBoxItem* pNewItem;
     116           0 :     maItems.clear();
     117           0 :     ItemsType::iterator it = pSource->maItems.begin(), itEnd = pSource->maItems.end();
     118           0 :     for (; it != itEnd; ++it)
     119             :     {
     120           0 :         SvLBoxItem* pItem = &(*it);
     121           0 :         pNewItem = pItem->Create();
     122           0 :         pNewItem->Clone(pItem);
     123           0 :         maItems.push_back(pNewItem);
     124             :     }
     125             : 
     126           0 :     pUserData = pSource->GetUserData();
     127           0 :     nEntryFlags = pSource->nEntryFlags;
     128           0 : }
     129             : 
     130        8618 : size_t SvTreeListEntry::ItemCount() const
     131             : {
     132        8618 :     return maItems.size();
     133             : }
     134             : 
     135        2900 : void SvTreeListEntry::AddItem( SvLBoxItem* pItem )
     136             : {
     137        2900 :     maItems.push_back( pItem );
     138        2900 : }
     139             : 
     140        1450 : void SvTreeListEntry::EnableChildrenOnDemand( bool bEnable )
     141             : {
     142        1450 :     if ( bEnable )
     143           4 :         nEntryFlags |= SV_ENTRYFLAG_CHILDREN_ON_DEMAND;
     144             :     else
     145        1446 :         nEntryFlags &= (~SV_ENTRYFLAG_CHILDREN_ON_DEMAND);
     146        1450 : }
     147             : 
     148        1450 : void SvTreeListEntry::ReplaceItem( SvLBoxItem* pNewItem, size_t nPos )
     149             : {
     150             :     DBG_ASSERT(pNewItem,"ReplaceItem:No Item");
     151        1450 :     if (nPos >= maItems.size())
     152             :     {
     153             :         // Out of bound. Bail out.
     154           0 :         delete pNewItem;
     155        1450 :         return;
     156             :     }
     157             : 
     158        1450 :     maItems.erase(maItems.begin()+nPos);
     159        1450 :     maItems.insert(maItems.begin()+nPos, pNewItem);
     160             : }
     161             : 
     162           0 : const SvLBoxItem* SvTreeListEntry::GetItem( size_t nPos ) const
     163             : {
     164           0 :     return &maItems[nPos];
     165             : }
     166             : 
     167       13375 : SvLBoxItem* SvTreeListEntry::GetItem( size_t nPos )
     168             : {
     169       13375 :     return &maItems[nPos];
     170             : }
     171             : 
     172             : namespace {
     173             : 
     174             : class FindByType : std::unary_function<SvLBoxItem, void>
     175             : {
     176             :     sal_uInt16 mnId;
     177             : public:
     178        4406 :     FindByType(sal_uInt16 nId) : mnId(nId) {}
     179        4458 :     bool operator() (const SvLBoxItem& rItem) const
     180             :     {
     181        4458 :         return rItem.GetType() == mnId;
     182             :     }
     183             : };
     184             : 
     185             : class FindByPointer : std::unary_function<SvLBoxItem, void>
     186             : {
     187             :     const SvLBoxItem* mpItem;
     188             : public:
     189        4388 :     FindByPointer(const SvLBoxItem* p) : mpItem(p) {}
     190        8698 :     bool operator() (const SvLBoxItem& rItem) const
     191             :     {
     192        8698 :         return &rItem == mpItem;
     193             :     }
     194             : };
     195             : 
     196             : }
     197             : 
     198        2900 : const SvLBoxItem* SvTreeListEntry::GetFirstItem( sal_uInt16 nId ) const
     199             : {
     200        2900 :     ItemsType::const_iterator it = std::find_if(maItems.begin(), maItems.end(), FindByType(nId));
     201        2900 :     return it == maItems.end() ? NULL : &(*it);
     202             : }
     203             : 
     204        1506 : SvLBoxItem* SvTreeListEntry::GetFirstItem( sal_uInt16 nId )
     205             : {
     206        1506 :     ItemsType::iterator it = std::find_if(maItems.begin(), maItems.end(), FindByType(nId));
     207        1506 :     return it == maItems.end() ? NULL : &(*it);
     208             : }
     209             : 
     210        4388 : size_t SvTreeListEntry::GetPos( const SvLBoxItem* pItem ) const
     211             : {
     212        4388 :     ItemsType::const_iterator it = std::find_if(maItems.begin(), maItems.end(), FindByPointer(pItem));
     213        4388 :     return it == maItems.end() ? ITEM_NOT_FOUND : std::distance(maItems.begin(), it);
     214             : }
     215             : 
     216             : 
     217        1964 : void SvTreeListEntry::SetUserData( void* pPtr )
     218             : {
     219        1964 :     pUserData = pPtr;
     220        1964 : }
     221             : 
     222        2045 : bool SvTreeListEntry::HasChildrenOnDemand() const
     223             : {
     224        2045 :     return (bool)((nEntryFlags & SV_ENTRYFLAG_CHILDREN_ON_DEMAND)!=0);
     225             : }
     226             : 
     227        1783 : bool SvTreeListEntry::HasInUseEmphasis() const
     228             : {
     229        1783 :     return (bool)((nEntryFlags & SV_ENTRYFLAG_IN_USE)!=0);
     230             : }
     231             : 
     232             : 
     233          10 : void SvTreeListEntry::SetFlags( sal_uInt16 nFlags )
     234             : {
     235          10 :     nEntryFlags = nFlags;
     236        1237 : }
     237             : 
     238             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10