LCOV - code coverage report
Current view: top level - svtools/source/contnr - treelistentry.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 57 99 57.6 %
Date: 2015-06-13 12:38:46 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         118 : void SvTreeListEntry::ClearChildren()
      29             : {
      30         118 :     maChildren.clear();
      31         118 : }
      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         131 : SvTreeListEntry::SvTreeListEntry()
      54             :     : pParent(NULL)
      55             :     , nAbsPos(0)
      56             :     , nListPos(0)
      57             :     , bIsMarked(false)
      58             :     , pUserData(NULL)
      59             :     , nEntryFlags(SvTLEntryFlags::NONE)
      60         131 :     , maBackColor(Application::GetSettings().GetStyleSettings().GetWindowColor())
      61             : {
      62         131 : }
      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().GetWindowColor())
      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         387 : SvTreeListEntry::~SvTreeListEntry()
      79             : {
      80             : #ifdef DBG_UTIL
      81             :     pParent     = 0;
      82             : #endif
      83             : 
      84         129 :     maChildren.clear();
      85         129 :     maItems.clear();
      86         258 : }
      87             : 
      88         549 : bool SvTreeListEntry::HasChildren() const
      89             : {
      90         549 :     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        1158 : sal_uLong SvTreeListEntry::GetChildListPos() const
     101             : {
     102        1158 :     if( pParent && (pParent->nListPos & 0x80000000) )
     103           0 :         pParent->SetListPositions();
     104        1158 :     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           0 :     maItems.clear();
     116           0 :     ItemsType::iterator it = pSource->maItems.begin(), itEnd = pSource->maItems.end();
     117           0 :     for (; it != itEnd; ++it)
     118             :     {
     119           0 :         SvLBoxItem* pItem = &(*it);
     120           0 :         SvLBoxItem* pNewItem = pItem->Create();
     121           0 :         pNewItem->Clone(pItem);
     122           0 :         maItems.push_back(pNewItem);
     123             :     }
     124             : 
     125           0 :     pUserData = pSource->GetUserData();
     126           0 :     nEntryFlags = pSource->nEntryFlags;
     127           0 : }
     128             : 
     129         714 : size_t SvTreeListEntry::ItemCount() const
     130             : {
     131         714 :     return maItems.size();
     132             : }
     133             : 
     134         202 : void SvTreeListEntry::AddItem( SvLBoxItem* pItem )
     135             : {
     136         202 :     maItems.push_back( pItem );
     137         202 : }
     138             : 
     139         101 : void SvTreeListEntry::EnableChildrenOnDemand( bool bEnable )
     140             : {
     141         101 :     if ( bEnable )
     142           2 :         nEntryFlags |= SvTLEntryFlags::CHILDREN_ON_DEMAND;
     143             :     else
     144          99 :         nEntryFlags &= (~SvTLEntryFlags::CHILDREN_ON_DEMAND);
     145         101 : }
     146             : 
     147         101 : void SvTreeListEntry::ReplaceItem( SvLBoxItem* pNewItem, size_t nPos )
     148             : {
     149             :     DBG_ASSERT(pNewItem,"ReplaceItem:No Item");
     150         101 :     if (nPos >= maItems.size())
     151             :     {
     152             :         // Out of bound. Bail out.
     153           0 :         delete pNewItem;
     154         101 :         return;
     155             :     }
     156             : 
     157         101 :     maItems.erase(maItems.begin()+nPos);
     158         101 :     maItems.insert(maItems.begin()+nPos, pNewItem);
     159             : }
     160             : 
     161           0 : const SvLBoxItem* SvTreeListEntry::GetItem( size_t nPos ) const
     162             : {
     163           0 :     return &maItems[nPos];
     164             : }
     165             : 
     166         937 : SvLBoxItem* SvTreeListEntry::GetItem( size_t nPos )
     167             : {
     168         937 :     return &maItems[nPos];
     169             : }
     170             : 
     171             : namespace {
     172             : 
     173             : class FindByType : std::unary_function<SvLBoxItem, void>
     174             : {
     175             :     sal_uInt16 mnId;
     176             : public:
     177         331 :     explicit FindByType(sal_uInt16 nId) : mnId(nId) {}
     178         357 :     bool operator() (const SvLBoxItem& rItem) const
     179             :     {
     180         357 :         return rItem.GetType() == mnId;
     181             :     }
     182             : };
     183             : 
     184             : class FindByPointer : std::unary_function<SvLBoxItem, void>
     185             : {
     186             :     const SvLBoxItem* mpItem;
     187             : public:
     188         536 :     explicit FindByPointer(const SvLBoxItem* p) : mpItem(p) {}
     189         952 :     bool operator() (const SvLBoxItem& rItem) const
     190             :     {
     191         952 :         return &rItem == mpItem;
     192             :     }
     193             : };
     194             : 
     195             : }
     196             : 
     197         202 : const SvLBoxItem* SvTreeListEntry::GetFirstItem( sal_uInt16 nId ) const
     198             : {
     199         202 :     ItemsType::const_iterator it = std::find_if(maItems.begin(), maItems.end(), FindByType(nId));
     200         202 :     return it == maItems.end() ? NULL : &(*it);
     201             : }
     202             : 
     203         129 : SvLBoxItem* SvTreeListEntry::GetFirstItem( sal_uInt16 nId )
     204             : {
     205         129 :     ItemsType::iterator it = std::find_if(maItems.begin(), maItems.end(), FindByType(nId));
     206         129 :     return it == maItems.end() ? NULL : &(*it);
     207             : }
     208             : 
     209         536 : size_t SvTreeListEntry::GetPos( const SvLBoxItem* pItem ) const
     210             : {
     211         536 :     ItemsType::const_iterator it = std::find_if(maItems.begin(), maItems.end(), FindByPointer(pItem));
     212         536 :     return it == maItems.end() ? ITEM_NOT_FOUND : std::distance(maItems.begin(), it);
     213             : }
     214             : 
     215             : 
     216         586 : void SvTreeListEntry::SetUserData( void* pPtr )
     217             : {
     218         586 :     pUserData = pPtr;
     219         586 : }
     220             : 
     221         239 : bool SvTreeListEntry::HasChildrenOnDemand() const
     222             : {
     223         239 :     return (bool)(nEntryFlags & SvTLEntryFlags::CHILDREN_ON_DEMAND);
     224             : }
     225             : 
     226         109 : bool SvTreeListEntry::HasInUseEmphasis() const
     227             : {
     228         109 :     return (bool)(nEntryFlags & SvTLEntryFlags::IN_USE);
     229             : }
     230             : 
     231             : 
     232           5 : void SvTreeListEntry::SetFlags( SvTLEntryFlags nFlags )
     233             : {
     234           5 :     nEntryFlags = nFlags;
     235         803 : }
     236             : 
     237             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11