Impress: Implement getPartName.
[LibreOffice.git] / include / svtools / treelist.hxx
blob04ab892e08283e0f8b7ef77ab64165d53abbeb84
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVTOOLS_TREELIST_HXX
21 #define INCLUDED_SVTOOLS_TREELIST_HXX
23 #include <svtools/svtdllapi.h>
24 #include <svtools/treelistentries.hxx>
25 #include <svtools/viewdataentry.hxx>
27 #include <tools/solar.h>
28 #include <tools/link.hxx>
29 #include <tools/debug.hxx>
30 #include <tools/contnr.hxx>
32 #include <limits.h>
33 #include <vector>
34 #include <boost/ptr_container/ptr_map.hpp>
36 #define LISTACTION_INSERTED 1
37 #define LISTACTION_REMOVING 2
38 #define LISTACTION_REMOVED 3
39 #define LISTACTION_MOVING 4
40 #define LISTACTION_MOVED 5
41 #define LISTACTION_CLEARING 6
42 #define LISTACTION_INSERTED_TREE 7
43 #define LISTACTION_INVALIDATE_ENTRY 8
44 #define LISTACTION_RESORTING 9
45 #define LISTACTION_RESORTED 10
46 #define LISTACTION_CLEARED 11
48 class SvTreeListEntry;
49 class SvListView;
51 enum SvSortMode { SortAscending, SortDescending, SortNone };
53 // For the return values of Sortlink:
54 // See International::Compare( pLeft, pRight )
55 // ( Compare(a,b) ==> b.Compare(a) ==> strcmp(a,b) )
56 struct SvSortData
58 const SvTreeListEntry* pLeft;
59 const SvTreeListEntry* pRight;
62 class SVT_DLLPUBLIC SvTreeList
64 typedef std::vector<SvListView*> ListViewsType;
66 friend class SvListView;
68 ListViewsType aViewList;
69 sal_uLong nEntryCount;
71 Link aCloneLink;
72 Link aCompareLink;
73 SvSortMode eSortMode;
75 sal_uInt16 nRefCount;
77 bool bAbsPositionsValid;
79 bool mbEnableInvalidate;
81 SvTreeListEntry* FirstVisible() const { return First(); }
82 SvTreeListEntry* NextVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
83 SvTreeListEntry* PrevVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
84 SvTreeListEntry* LastVisible( const SvListView*,sal_uInt16* pDepth=0 ) const;
85 SvTreeListEntry* NextVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const;
86 SvTreeListEntry* PrevVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const;
88 bool IsEntryVisible( const SvListView*,SvTreeListEntry* pEntry ) const;
89 SvTreeListEntry* GetEntryAtVisPos( const SvListView*,sal_uLong nVisPos ) const;
90 sal_uLong GetVisiblePos( const SvListView*,SvTreeListEntry* pEntry ) const;
91 sal_uLong GetVisibleCount( SvListView* ) const;
92 sal_uLong GetVisibleChildCount( const SvListView*,SvTreeListEntry* pParent ) const;
94 SvTreeListEntry* FirstSelected( const SvListView*) const;
95 SvTreeListEntry* NextSelected( const SvListView*,SvTreeListEntry* pEntry ) const;
96 SvTreeListEntry* PrevSelected( const SvListView*,SvTreeListEntry* pEntry ) const;
97 SvTreeListEntry* LastSelected( const SvListView*) const;
99 bool Select( SvListView*,SvTreeListEntry* pEntry, bool bSelect=true );
100 void SelectAll( SvListView*, bool bSelect ); // Does not call Select Handler
101 sal_uLong GetChildSelectionCount( const SvListView*,SvTreeListEntry* pParent ) const;
103 void Expand( SvListView*,SvTreeListEntry* pParent );
104 void Collapse( SvListView*,SvTreeListEntry* pParent );
106 SVT_DLLPRIVATE void SetAbsolutePositions();
108 SVT_DLLPRIVATE void CloneChildren(
109 SvTreeListEntries& rDst, sal_uLong& rCloneCount, SvTreeListEntries& rSrc, SvTreeListEntry* pNewParent) const;
112 * Invalidate the cached position data to have them re-generated before
113 * the next access.
115 SVT_DLLPRIVATE void SetListPositions( SvTreeListEntries& rEntries );
117 // rPos is not changed for SortModeNone
118 SVT_DLLPRIVATE void GetInsertionPos(
119 SvTreeListEntry* pEntry,
120 SvTreeListEntry* pParent,
121 sal_uLong& rPos
124 SVT_DLLPRIVATE void ResortChildren( SvTreeListEntry* pParent );
126 SvTreeList(const SvTreeList&); // disabled
127 SvTreeList& operator= (const SvTreeList&); // disabled
129 protected:
130 SvTreeListEntry* pRootItem;
132 public:
134 SvTreeList();
135 virtual ~SvTreeList();
137 void InsertView( SvListView* );
138 void RemoveView( SvListView* );
139 sal_uLong GetViewCount() const
140 { return aViewList.size(); }
142 SvListView* GetView( sal_uLong nPos ) const
143 { return ( nPos < aViewList.size() ) ? aViewList[ nPos ] : NULL; }
145 void Broadcast(
146 sal_uInt16 nActionId,
147 SvTreeListEntry* pEntry1=0,
148 SvTreeListEntry* pEntry2=0,
149 sal_uLong nPos=0
152 void EnableInvalidate( bool bEnable );
154 // Notify all Listeners
155 void InvalidateEntry( SvTreeListEntry* );
157 sal_uLong GetEntryCount() const { return nEntryCount; }
158 SvTreeListEntry* First() const;
159 SvTreeListEntry* Next( SvTreeListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
160 SvTreeListEntry* Prev( SvTreeListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
161 SvTreeListEntry* Last() const;
163 SvTreeListEntry* FirstChild( SvTreeListEntry* pParent ) const;
164 SvTreeListEntry* NextSibling( SvTreeListEntry* pEntry ) const;
165 SvTreeListEntry* PrevSibling( SvTreeListEntry* pEntry ) const;
166 SvTreeListEntry* LastSibling( SvTreeListEntry* pEntry ) const;
168 sal_uLong Insert( SvTreeListEntry* pEntry,SvTreeListEntry* pPar,sal_uLong nPos = TREELIST_APPEND);
169 sal_uLong Insert( SvTreeListEntry* pEntry,sal_uLong nRootPos = TREELIST_APPEND )
170 { return Insert(pEntry, pRootItem, nRootPos ); }
172 void InsertTree( SvTreeListEntry* pTree, SvTreeListEntry* pTargetParent, sal_uLong nListPos );
174 // Entries need to be in the same Model!
175 void Move( SvTreeListEntry* pSource, SvTreeListEntry* pTarget );
177 // Creates ChildList if needed
178 sal_uLong Move( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uLong nListPos);
179 void Copy( SvTreeListEntry* pSource, SvTreeListEntry* pTarget );
180 sal_uLong Copy( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uLong nListPos);
182 bool Remove( const SvTreeListEntry* pEntry );
183 void Clear();
185 bool HasChildren( const SvTreeListEntry* pEntry ) const;
186 bool HasParent( const SvTreeListEntry* pEntry ) const;
188 bool IsChild(const SvTreeListEntry* pParent, const SvTreeListEntry* pChild) const;
189 SvTreeListEntry* GetEntry( SvTreeListEntry* pParent, sal_uLong nPos ) const;
190 SvTreeListEntry* GetEntry( sal_uLong nRootPos ) const;
191 SvTreeListEntry* GetEntryAtAbsPos( sal_uLong nAbsPos ) const;
193 const SvTreeListEntry* GetParent( const SvTreeListEntry* pEntry ) const;
194 SvTreeListEntry* GetParent( SvTreeListEntry* pEntry );
196 SvTreeListEntry* GetRootLevelParent( SvTreeListEntry* pEntry ) const;
197 const SvTreeListEntries& GetChildList( SvTreeListEntry* pParent ) const;
198 SvTreeListEntries& GetChildList( SvTreeListEntry* pParent );
200 std::pair<SvTreeListEntries::iterator, SvTreeListEntries::iterator>
201 GetChildIterators(SvTreeListEntry* pParent);
203 sal_uLong GetAbsPos( const SvTreeListEntry* pEntry ) const;
204 sal_uLong GetRelPos( const SvTreeListEntry* pChild ) const;
206 sal_uLong GetChildCount( const SvTreeListEntry* pParent ) const;
207 sal_uInt16 GetDepth( const SvTreeListEntry* pEntry ) const;
208 bool IsAtRootDepth( const SvTreeListEntry* pEntry ) const;
210 // The Model calls the Clone Link to clone Entries.
211 // Thus we do not need to derive from the Model if we derive from SvTreeListEntry.
212 // Declaration of the Clone Handler:
213 // DECL_LINK(CloneHdl,SvTreeListEntry*);
214 // The Handler needs to return a SvTreeListEntry*
215 SvTreeListEntry* Clone( SvTreeListEntry* pEntry, sal_uLong& nCloneCount ) const;
216 void SetCloneLink( const Link& rLink )
217 { aCloneLink=rLink; }
219 const Link& GetCloneLink() const
220 { return aCloneLink; }
222 virtual SvTreeListEntry* CloneEntry( SvTreeListEntry* pSource ) const; // Calls the Clone Link
223 virtual SvTreeListEntry* CreateEntry() const; // To create Entries
225 sal_uInt16 GetRefCount() const { return nRefCount; }
226 void SetRefCount( sal_uInt16 nRef ) { nRefCount = nRef; }
228 void SetSortMode( SvSortMode eMode ) { eSortMode = eMode; }
229 SvSortMode GetSortMode() const { return eSortMode; }
230 sal_Int32 Compare(const SvTreeListEntry* pLeft, const SvTreeListEntry* pRight) const;
231 void SetCompareHdl( const Link& rLink ) { aCompareLink = rLink; }
232 const Link& GetCompareHdl() const { return aCompareLink; }
233 void Resort();
236 class SVT_DLLPUBLIC SvListView
238 friend class SvTreeList;
240 typedef boost::ptr_map<SvTreeListEntry*, SvViewDataEntry> SvDataTable;
242 sal_uLong nVisibleCount;
243 sal_uLong nSelectionCount;
244 bool bVisPositionsValid;
246 SVT_DLLPRIVATE void InitTable();
247 SVT_DLLPRIVATE void RemoveViewData( SvTreeListEntry* pParent );
249 SvDataTable maDataTable; // Mapping SvTreeListEntry -> ViewData
251 void ActionMoving( SvTreeListEntry* pEntry,SvTreeListEntry* pTargetPrnt,sal_uLong nChildPos);
252 void ActionMoved( SvTreeListEntry* pEntry,SvTreeListEntry* pTargetPrnt,sal_uLong nChildPos);
253 void ActionInserted( SvTreeListEntry* pEntry );
254 void ActionInsertedTree( SvTreeListEntry* pEntry );
255 void ActionRemoving( SvTreeListEntry* pEntry );
256 void ActionRemoved( SvTreeListEntry* pEntry );
257 void ActionClear();
259 protected:
260 SvTreeList* pModel;
262 void ExpandListEntry( SvTreeListEntry* pParent )
263 { pModel->Expand((SvListView*)this,pParent); }
265 void CollapseListEntry( SvTreeListEntry* pParent )
266 { pModel->Collapse((SvListView*)this,pParent); }
268 bool SelectListEntry( SvTreeListEntry* pEntry, bool bSelect )
269 { return pModel->Select((SvListView*)this,pEntry,bSelect); }
271 public:
272 SvListView(); // Sets the Model to 0
273 virtual ~SvListView();
274 void Clear();
275 virtual void SetModel( SvTreeList* );
276 virtual void ModelNotification(
277 sal_uInt16 nActionId,
278 SvTreeListEntry* pEntry1,
279 SvTreeListEntry* pEntry2,
280 sal_uLong nPos
283 sal_uLong GetVisibleCount() const
284 { return pModel->GetVisibleCount( (SvListView*)this ); }
286 SvTreeListEntry* FirstVisible() const
287 { return pModel->FirstVisible(); }
289 SvTreeListEntry* NextVisible( SvTreeListEntry* pEntry, sal_uInt16* pDepth=0 ) const
290 { return pModel->NextVisible(this,pEntry,pDepth); }
292 SvTreeListEntry* PrevVisible( SvTreeListEntry* pEntry, sal_uInt16* pDepth=0 ) const
293 { return pModel->PrevVisible(this,pEntry,pDepth); }
295 SvTreeListEntry* LastVisible( sal_uInt16* pDepth=0 ) const
296 { return pModel->LastVisible(this,pDepth); }
298 SvTreeListEntry* NextVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
299 { return pModel->NextVisible(this,pEntry,rDelta); }
301 SvTreeListEntry* PrevVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
302 { return pModel->PrevVisible(this,pEntry,rDelta); }
304 sal_uLong GetSelectionCount() const
305 { return nSelectionCount; }
307 SvTreeListEntry* FirstSelected() const
308 { return pModel->FirstSelected(this); }
310 SvTreeListEntry* NextSelected( SvTreeListEntry* pEntry ) const
311 { return pModel->NextSelected(this,pEntry); }
313 SvTreeListEntry* PrevSelected( SvTreeListEntry* pEntry ) const
314 { return pModel->PrevSelected(this,pEntry); }
316 SvTreeListEntry* LastSelected() const
317 { return pModel->LastSelected(this); }
318 SvTreeListEntry* GetEntryAtAbsPos( sal_uLong nAbsPos ) const
319 { return pModel->GetEntryAtAbsPos(nAbsPos); }
321 SvTreeListEntry* GetEntryAtVisPos( sal_uLong nVisPos ) const
322 { return pModel->GetEntryAtVisPos((SvListView*)this,nVisPos); }
324 sal_uLong GetAbsPos( SvTreeListEntry* pEntry ) const
325 { return pModel->GetAbsPos(pEntry); }
327 sal_uLong GetVisiblePos( SvTreeListEntry* pEntry ) const
328 { return pModel->GetVisiblePos((SvListView*)this,pEntry); }
330 sal_uLong GetVisibleChildCount(SvTreeListEntry* pParent ) const
331 { return pModel->GetVisibleChildCount((SvListView*)this,pParent); }
333 sal_uLong GetChildSelectionCount( SvTreeListEntry* pParent ) const
334 { return pModel->GetChildSelectionCount((SvListView*)this,pParent); }
336 // Does not call the Select Handler
337 virtual void SelectAll( bool bSelect, bool )
338 { pModel->SelectAll((SvListView*)this, bSelect); }
340 bool IsEntryVisible( SvTreeListEntry* pEntry ) const
341 { return pModel->IsEntryVisible((SvListView*)this,pEntry); }
343 bool IsExpanded( SvTreeListEntry* pEntry ) const;
344 bool IsSelected( SvTreeListEntry* pEntry ) const;
345 void SetEntryFocus( SvTreeListEntry* pEntry, bool bFocus );
346 const SvViewDataEntry* GetViewData( const SvTreeListEntry* pEntry ) const;
347 SvViewDataEntry* GetViewData( SvTreeListEntry* pEntry );
348 bool HasViewData() const
349 { return maDataTable.size() > 1; } // There's always a ROOT
351 virtual SvViewDataEntry* CreateViewData( SvTreeListEntry* pEntry );
352 virtual void InitViewData( SvViewDataEntry*, SvTreeListEntry* pEntry );
354 virtual void ModelHasCleared();
355 virtual void ModelHasInserted( SvTreeListEntry* pEntry );
356 virtual void ModelHasInsertedTree( SvTreeListEntry* pEntry );
357 virtual void ModelIsMoving(
358 SvTreeListEntry* pSource,
359 SvTreeListEntry* pTargetParent,
360 sal_uLong nPos
362 virtual void ModelHasMoved( SvTreeListEntry* pSource );
363 virtual void ModelIsRemoving( SvTreeListEntry* pEntry );
364 virtual void ModelHasRemoved( SvTreeListEntry* pEntry );
365 virtual void ModelHasEntryInvalidated( SvTreeListEntry* pEntry );
368 #endif
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */