LCOV - code coverage report
Current view: top level - include/svtools - treelist.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 40 63 63.5 %
Date: 2014-11-03 Functions: 23 35 65.7 %
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             : #ifndef INCLUDED_SVTOOLS_TREELIST_HXX
      21             : #define INCLUDED_SVTOOLS_TREELIST_HXX
      22             : 
      23             : #include <svtools/svtdllapi.h>
      24             : #include <svtools/treelistentries.hxx>
      25             : #include <svtools/viewdataentry.hxx>
      26             : 
      27             : #include <tools/solar.h>
      28             : #include <tools/link.hxx>
      29             : #include <tools/contnr.hxx>
      30             : 
      31             : #include <limits.h>
      32             : #include <vector>
      33             : #include <boost/ptr_container/ptr_map.hpp>
      34             : 
      35             : enum class SvListAction
      36             : {
      37             :     INSERTED         = 1,
      38             :     REMOVING         = 2,
      39             :     REMOVED          = 3,
      40             :     MOVING           = 4,
      41             :     MOVED            = 5,
      42             :     CLEARING         = 6,
      43             :     INSERTED_TREE    = 7,
      44             :     INVALIDATE_ENTRY = 8,
      45             :     RESORTING        = 9,
      46             :     RESORTED         = 10,
      47             :     CLEARED          = 11,
      48             :     REVERSING        = 12,
      49             :     REVERSED         = 13
      50             : };
      51             : 
      52             : class SvTreeListEntry;
      53             : class SvListView;
      54             : 
      55             : enum SvSortMode { SortAscending, SortDescending, SortNone };
      56             : 
      57             : // For the return values of Sortlink:
      58             : // See International::Compare( pLeft, pRight )
      59             : // ( Compare(a,b) ==> b.Compare(a) ==> strcmp(a,b) )
      60             : struct SvSortData
      61             : {
      62             :     const SvTreeListEntry* pLeft;
      63             :     const SvTreeListEntry* pRight;
      64             : };
      65             : 
      66             : class SVT_DLLPUBLIC SvTreeList
      67             : {
      68             :     typedef std::vector<SvListView*> ListViewsType;
      69             : 
      70             :     friend class        SvListView;
      71             : 
      72             :     ListViewsType       aViewList;
      73             :     sal_uLong           nEntryCount;
      74             : 
      75             :     Link                aCloneLink;
      76             :     Link                aCompareLink;
      77             :     SvSortMode          eSortMode;
      78             : 
      79             :     sal_uInt16          nRefCount;
      80             : 
      81             :     bool                bAbsPositionsValid;
      82             : 
      83             :     bool mbEnableInvalidate;
      84             : 
      85        2071 :     SvTreeListEntry*        FirstVisible() const { return First(); }
      86             :     SvTreeListEntry*        NextVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
      87             :     SvTreeListEntry*        PrevVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
      88             :     SvTreeListEntry*        LastVisible( const SvListView*,sal_uInt16* pDepth=0 ) const;
      89             :     SvTreeListEntry*        NextVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const;
      90             :     SvTreeListEntry*        PrevVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const;
      91             : 
      92             :     bool               IsEntryVisible( const SvListView*,SvTreeListEntry* pEntry ) const;
      93             :     SvTreeListEntry*    GetEntryAtVisPos( const SvListView*,sal_uLong nVisPos ) const;
      94             :     sal_uLong           GetVisiblePos( const SvListView*,SvTreeListEntry* pEntry ) const;
      95             :     sal_uLong           GetVisibleCount( SvListView* ) const;
      96             :     sal_uLong           GetVisibleChildCount( const SvListView*,SvTreeListEntry* pParent ) const;
      97             : 
      98             :     SvTreeListEntry*        FirstSelected( const SvListView*) const;
      99             :     SvTreeListEntry*        NextSelected( const SvListView*,SvTreeListEntry* pEntry ) const;
     100             :     SvTreeListEntry*        PrevSelected( const SvListView*,SvTreeListEntry* pEntry ) const;
     101             :     SvTreeListEntry*        LastSelected( const SvListView*) const;
     102             : 
     103             :     bool                Select( SvListView*,SvTreeListEntry* pEntry, bool bSelect=true );
     104             :     void                SelectAll( SvListView*, bool bSelect ); // Does not call Select Handler
     105             :     sal_uLong           GetChildSelectionCount( const SvListView*,SvTreeListEntry* pParent ) const;
     106             : 
     107             :     void                Expand( SvListView*,SvTreeListEntry* pParent );
     108             :     void                Collapse( SvListView*,SvTreeListEntry* pParent );
     109             : 
     110             :     SVT_DLLPRIVATE void SetAbsolutePositions();
     111             : 
     112             :     SVT_DLLPRIVATE void CloneChildren(
     113             :         SvTreeListEntries& rDst, sal_uLong& rCloneCount, SvTreeListEntries& rSrc, SvTreeListEntry* pNewParent) const;
     114             : 
     115             :     /**
     116             :      * Invalidate the cached position data to have them re-generated before
     117             :      * the next access.
     118             :      */
     119             :     SVT_DLLPRIVATE void SetListPositions( SvTreeListEntries& rEntries );
     120             : 
     121             :     // rPos is not changed for SortModeNone
     122             :     SVT_DLLPRIVATE void GetInsertionPos(
     123             :                             SvTreeListEntry* pEntry,
     124             :                             SvTreeListEntry* pParent,
     125             :                             sal_uLong& rPos
     126             :                         );
     127             : 
     128             :     SVT_DLLPRIVATE void ResortChildren( SvTreeListEntry* pParent );
     129             :     SVT_DLLPRIVATE void ReverseChildren( SvTreeListEntry* pParent );
     130             : 
     131             :     SvTreeList(const SvTreeList&); // disabled
     132             :     SvTreeList& operator= (const SvTreeList&); // disabled
     133             : 
     134             : protected:
     135             :     SvTreeListEntry*        pRootItem;
     136             : 
     137             : public:
     138             : 
     139             :                         SvTreeList();
     140             :     virtual             ~SvTreeList();
     141             : 
     142             :     void                InsertView( SvListView* );
     143             :     void                RemoveView( SvListView* );
     144             :     sal_uLong           GetViewCount() const
     145             :     { return aViewList.size(); }
     146             : 
     147           0 :     SvListView*         GetView( sal_uLong nPos ) const
     148           0 :     { return ( nPos < aViewList.size() ) ? aViewList[ nPos ] : NULL; }
     149             : 
     150             :     void                Broadcast(
     151             :                             SvListAction nActionId,
     152             :                             SvTreeListEntry* pEntry1=0,
     153             :                             SvTreeListEntry* pEntry2=0,
     154             :                             sal_uLong nPos=0
     155             :                         );
     156             : 
     157             :     void                EnableInvalidate( bool bEnable );
     158             : 
     159             :     // Notify all Listeners
     160             :     void                InvalidateEntry( SvTreeListEntry* );
     161             : 
     162        2166 :     sal_uLong           GetEntryCount() const { return nEntryCount; }
     163             :     SvTreeListEntry*    First() const;
     164             :     SvTreeListEntry*    Next( SvTreeListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
     165             :     SvTreeListEntry*    Prev( SvTreeListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
     166             :     SvTreeListEntry*    Last() const;
     167             : 
     168             :     SvTreeListEntry*    FirstChild( SvTreeListEntry* pParent ) const;
     169             :     SvTreeListEntry*    NextSibling( SvTreeListEntry* pEntry ) const;
     170             :     SvTreeListEntry*    PrevSibling( SvTreeListEntry* pEntry ) const;
     171             :     SvTreeListEntry*    LastSibling( SvTreeListEntry* pEntry ) const;
     172             : 
     173             :     sal_uLong           Insert( SvTreeListEntry* pEntry,SvTreeListEntry* pPar,sal_uLong nPos = TREELIST_APPEND);
     174        1444 :     sal_uLong           Insert( SvTreeListEntry* pEntry,sal_uLong nRootPos = TREELIST_APPEND )
     175        1444 :     { return Insert(pEntry, pRootItem, nRootPos ); }
     176             : 
     177             :     void                InsertTree( SvTreeListEntry* pTree, SvTreeListEntry* pTargetParent, sal_uLong nListPos );
     178             : 
     179             :     // Entries need to be in the same Model!
     180             :     void                Move( SvTreeListEntry* pSource, SvTreeListEntry* pTarget );
     181             : 
     182             :     // Creates ChildList if needed
     183             :     sal_uLong           Move( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uLong nListPos);
     184             :     void                Copy( SvTreeListEntry* pSource, SvTreeListEntry* pTarget );
     185             :     sal_uLong           Copy( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uLong nListPos);
     186             : 
     187             :     bool Remove( const SvTreeListEntry* pEntry );
     188             :     void                Clear();
     189             : 
     190             :     bool HasChildren( const SvTreeListEntry* pEntry ) const;
     191             :     bool HasParent( const SvTreeListEntry* pEntry ) const;
     192             : 
     193             :     bool                IsChild(const SvTreeListEntry* pParent, const SvTreeListEntry* pChild) const;
     194             :     SvTreeListEntry*        GetEntry( SvTreeListEntry* pParent, sal_uLong nPos ) const;
     195             :     SvTreeListEntry*        GetEntry( sal_uLong nRootPos ) const;
     196             :     SvTreeListEntry*        GetEntryAtAbsPos( sal_uLong nAbsPos ) const;
     197             : 
     198             :     const SvTreeListEntry* GetParent( const SvTreeListEntry* pEntry ) const;
     199             :     SvTreeListEntry* GetParent( SvTreeListEntry* pEntry );
     200             : 
     201             :     SvTreeListEntry*        GetRootLevelParent( SvTreeListEntry* pEntry ) const;
     202             :     const SvTreeListEntries& GetChildList( SvTreeListEntry* pParent ) const;
     203             :     SvTreeListEntries& GetChildList( SvTreeListEntry* pParent );
     204             : 
     205             :     std::pair<SvTreeListEntries::iterator, SvTreeListEntries::iterator>
     206             :         GetChildIterators(SvTreeListEntry* pParent);
     207             : 
     208             :     sal_uLong GetAbsPos( const SvTreeListEntry* pEntry ) const;
     209             :     sal_uLong GetRelPos( const SvTreeListEntry* pChild ) const;
     210             : 
     211             :     sal_uLong GetChildCount( const SvTreeListEntry* pParent ) const;
     212             :     sal_uInt16 GetDepth( const SvTreeListEntry* pEntry ) const;
     213             :     bool IsAtRootDepth( const SvTreeListEntry* pEntry ) const;
     214             : 
     215             :     // The Model calls the Clone Link to clone Entries.
     216             :     // Thus we do not need to derive from the Model if we derive from SvTreeListEntry.
     217             :     // Declaration of the Clone Handler:
     218             :     // DECL_LINK(CloneHdl,SvTreeListEntry*);
     219             :     // The Handler needs to return a SvTreeListEntry*
     220             :     SvTreeListEntry*        Clone( SvTreeListEntry* pEntry, sal_uLong& nCloneCount ) const;
     221         534 :     void                SetCloneLink( const Link& rLink )
     222         534 :     { aCloneLink=rLink; }
     223             : 
     224           0 :     const Link&         GetCloneLink() const
     225           0 :     { return aCloneLink; }
     226             : 
     227             :     virtual SvTreeListEntry*    CloneEntry( SvTreeListEntry* pSource ) const; // Calls the Clone Link
     228             :     virtual SvTreeListEntry*    CreateEntry() const; // To create Entries
     229             : 
     230         266 :     sal_uInt16          GetRefCount() const { return nRefCount; }
     231         268 :     void                SetRefCount( sal_uInt16 nRef ) { nRefCount = nRef; }
     232             : 
     233         636 :     void                SetSortMode( SvSortMode eMode ) { eSortMode = eMode; }
     234           0 :     SvSortMode          GetSortMode() const { return eSortMode; }
     235             :     sal_Int32           Compare(const SvTreeListEntry* pLeft, const SvTreeListEntry* pRight) const;
     236         630 :     void                SetCompareHdl( const Link& rLink ) { aCompareLink = rLink; }
     237             :     const Link&         GetCompareHdl() const { return aCompareLink; }
     238             :     void                Resort();
     239             :     void                Reverse();
     240             : };
     241             : 
     242             : class SVT_DLLPUBLIC SvListView
     243             : {
     244             :     friend class SvTreeList;
     245             : 
     246             :     typedef boost::ptr_map<SvTreeListEntry*, SvViewDataEntry> SvDataTable;
     247             : 
     248             :     sal_uLong           nVisibleCount;
     249             :     sal_uLong           nSelectionCount;
     250             :     bool                bVisPositionsValid;
     251             : 
     252             :     SVT_DLLPRIVATE void InitTable();
     253             :     SVT_DLLPRIVATE void RemoveViewData( SvTreeListEntry* pParent );
     254             : 
     255             :     SvDataTable maDataTable;  // Mapping SvTreeListEntry -> ViewData
     256             : 
     257             :     void                ActionMoving( SvTreeListEntry* pEntry,SvTreeListEntry* pTargetPrnt,sal_uLong nChildPos);
     258             :     void                ActionMoved( SvTreeListEntry* pEntry,SvTreeListEntry* pTargetPrnt,sal_uLong nChildPos);
     259             :     void                ActionInserted( SvTreeListEntry* pEntry );
     260             :     void                ActionInsertedTree( SvTreeListEntry* pEntry );
     261             :     void                ActionRemoving( SvTreeListEntry* pEntry );
     262             :     void                ActionRemoved( SvTreeListEntry* pEntry );
     263             :     void                ActionClear();
     264             : 
     265             : protected:
     266             :     SvTreeList* pModel;
     267             : 
     268           4 :     void                ExpandListEntry( SvTreeListEntry* pParent )
     269           4 :     { pModel->Expand((SvListView*)this,pParent); }
     270             : 
     271           0 :     void                CollapseListEntry( SvTreeListEntry* pParent )
     272           0 :     { pModel->Collapse((SvListView*)this,pParent); }
     273             : 
     274         132 :     bool                SelectListEntry( SvTreeListEntry* pEntry, bool bSelect )
     275         132 :     { return pModel->Select((SvListView*)this,pEntry,bSelect); }
     276             : 
     277             : public:
     278             :                         SvListView();   // Sets the Model to 0
     279             :     virtual             ~SvListView();
     280             :     void                Clear();
     281             :     virtual void        SetModel( SvTreeList* );
     282             :     virtual void        ModelNotification(
     283             :                             SvListAction nActionId,
     284             :                             SvTreeListEntry* pEntry1,
     285             :                             SvTreeListEntry* pEntry2,
     286             :                             sal_uLong nPos
     287             :                         );
     288             : 
     289        9073 :     sal_uLong           GetVisibleCount() const
     290        9073 :     { return pModel->GetVisibleCount( (SvListView*)this ); }
     291             : 
     292        2071 :     SvTreeListEntry*        FirstVisible() const
     293        2071 :     { return pModel->FirstVisible(); }
     294             : 
     295        3944 :     SvTreeListEntry*        NextVisible( SvTreeListEntry* pEntry, sal_uInt16* pDepth=0 ) const
     296        3944 :     { return pModel->NextVisible(this,pEntry,pDepth); }
     297             : 
     298         136 :     SvTreeListEntry*        PrevVisible( SvTreeListEntry* pEntry, sal_uInt16* pDepth=0 ) const
     299         136 :     { return pModel->PrevVisible(this,pEntry,pDepth); }
     300             : 
     301         201 :     SvTreeListEntry*        LastVisible( sal_uInt16* pDepth=0 ) const
     302         201 :     { return pModel->LastVisible(this,pDepth); }
     303             : 
     304           0 :     SvTreeListEntry*        NextVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
     305           0 :     { return pModel->NextVisible(this,pEntry,rDelta); }
     306             : 
     307           0 :     SvTreeListEntry*        PrevVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
     308           0 :     { return pModel->PrevVisible(this,pEntry,rDelta); }
     309             : 
     310         134 :     sal_uLong           GetSelectionCount() const
     311         134 :     { return nSelectionCount; }
     312             : 
     313         974 :     SvTreeListEntry* FirstSelected() const
     314         974 :     { return pModel->FirstSelected(this); }
     315             : 
     316           2 :     SvTreeListEntry*        NextSelected( SvTreeListEntry* pEntry ) const
     317           2 :     { return pModel->NextSelected(this,pEntry); }
     318             : 
     319           0 :     SvTreeListEntry*        PrevSelected( SvTreeListEntry* pEntry ) const
     320           0 :     { return pModel->PrevSelected(this,pEntry); }
     321             : 
     322           0 :     SvTreeListEntry*        LastSelected() const
     323           0 :     { return pModel->LastSelected(this); }
     324           0 :     SvTreeListEntry*        GetEntryAtAbsPos( sal_uLong nAbsPos ) const
     325           0 :     { return pModel->GetEntryAtAbsPos(nAbsPos); }
     326             : 
     327        1994 :     SvTreeListEntry*        GetEntryAtVisPos( sal_uLong nVisPos ) const
     328        1994 :     { return pModel->GetEntryAtVisPos((SvListView*)this,nVisPos); }
     329             : 
     330           0 :     sal_uLong           GetAbsPos( SvTreeListEntry* pEntry ) const
     331           0 :     { return pModel->GetAbsPos(pEntry); }
     332             : 
     333        1129 :     sal_uLong           GetVisiblePos( SvTreeListEntry* pEntry ) const
     334        1129 :     { return pModel->GetVisiblePos((SvListView*)this,pEntry); }
     335             : 
     336           0 :     sal_uLong           GetVisibleChildCount(SvTreeListEntry* pParent ) const
     337           0 :     { return pModel->GetVisibleChildCount((SvListView*)this,pParent); }
     338             : 
     339           4 :     sal_uLong           GetChildSelectionCount( SvTreeListEntry* pParent ) const
     340           4 :     { return pModel->GetChildSelectionCount((SvListView*)this,pParent); }
     341             : 
     342             :     // Does not call the Select Handler
     343           0 :     virtual void        SelectAll( bool bSelect, bool )
     344           0 :     { pModel->SelectAll((SvListView*)this, bSelect); }
     345             : 
     346         215 :     bool               IsEntryVisible( SvTreeListEntry* pEntry ) const
     347         215 :     { return pModel->IsEntryVisible((SvListView*)this,pEntry); }
     348             : 
     349             :     bool                IsExpanded( SvTreeListEntry* pEntry ) const;
     350             :     bool                IsSelected( SvTreeListEntry* pEntry ) const;
     351             :     void                SetEntryFocus( SvTreeListEntry* pEntry, bool bFocus );
     352             :     const SvViewDataEntry*         GetViewData( const SvTreeListEntry* pEntry ) const;
     353             :     SvViewDataEntry*         GetViewData( SvTreeListEntry* pEntry );
     354       10377 :     bool                HasViewData() const
     355       10377 :     { return maDataTable.size() > 1; }  // There's always a ROOT
     356             : 
     357             :     virtual SvViewDataEntry* CreateViewData( SvTreeListEntry* pEntry );
     358             :     virtual void        InitViewData( SvViewDataEntry*, SvTreeListEntry* pEntry );
     359             : 
     360             :     virtual void        ModelHasCleared();
     361             :     virtual void        ModelHasInserted( SvTreeListEntry* pEntry );
     362             :     virtual void        ModelHasInsertedTree( SvTreeListEntry* pEntry );
     363             :     virtual void        ModelIsMoving(
     364             :                             SvTreeListEntry* pSource,
     365             :                             SvTreeListEntry* pTargetParent,
     366             :                             sal_uLong nPos
     367             :                         );
     368             :     virtual void        ModelHasMoved( SvTreeListEntry* pSource );
     369             :     virtual void        ModelIsRemoving( SvTreeListEntry* pEntry );
     370             :     virtual void        ModelHasRemoved( SvTreeListEntry* pEntry );
     371             :     virtual void        ModelHasEntryInvalidated( SvTreeListEntry* pEntry );
     372             : };
     373             : 
     374             : #endif
     375             : 
     376             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10