LibreOffice Module vcl (master)  1
treelist.hxx
Go to the documentation of this file.
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_VCL_TREELIST_HXX
21 #define INCLUDED_VCL_TREELIST_HXX
22 
23 #include <vcl/dllapi.h>
24 #include <vcl/treelistentries.hxx>
25 
26 #include <tools/solar.h>
27 #include <tools/link.hxx>
28 #include <tools/contnr.hxx>
29 
30 #include <memory>
31 
32 enum class SvListAction
33 {
34  INSERTED = 1,
35  REMOVING = 2,
36  REMOVED = 3,
37  MOVING = 4,
38  MOVED = 5,
39  CLEARING = 6,
40  INSERTED_TREE = 7,
41  INVALIDATE_ENTRY = 8,
42  RESORTING = 9,
43  RESORTED = 10,
44  CLEARED = 11
45 };
46 
47 class SvTreeListEntry;
48 class SvListView;
49 class SvViewDataEntry;
50 
52 
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
57 {
60 };
61 
63 {
64  friend class SvListView;
65 
68 
72 
74 
76 
77  SvTreeListEntry* FirstVisible() const { return First(); }
78  SvTreeListEntry* NextVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16* pDepth=nullptr ) const;
79  SvTreeListEntry* PrevVisible( const SvListView*,SvTreeListEntry* pEntry ) const;
80  SvTreeListEntry* LastVisible( const SvListView* ) const;
81  SvTreeListEntry* NextVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const;
82  SvTreeListEntry* PrevVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const;
83 
84  bool IsEntryVisible( const SvListView*,SvTreeListEntry* pEntry ) const;
85  SvTreeListEntry* GetEntryAtVisPos( const SvListView*,sal_uLong nVisPos ) const;
86  sal_uLong GetVisiblePos( const SvListView*,SvTreeListEntry const * pEntry ) const;
89 
91  SvTreeListEntry* NextSelected( const SvListView*,SvTreeListEntry* pEntry ) const;
92  SvTreeListEntry* PrevSelected( const SvListView*,SvTreeListEntry* pEntry ) const;
93  SvTreeListEntry* LastSelected( const SvListView*) const;
94 
96 
97  VCL_DLLPRIVATE void SetAbsolutePositions();
98 
99  VCL_DLLPRIVATE void CloneChildren(
100  SvTreeListEntries& rDst, sal_uLong& rCloneCount, SvTreeListEntries& rSrc, SvTreeListEntry& rNewParent) const;
101 
106  VCL_DLLPRIVATE static void SetListPositions( SvTreeListEntries& rEntries );
107 
108  // rPos is not changed for SortModeNone
109  VCL_DLLPRIVATE void GetInsertionPos(
110  SvTreeListEntry const * pEntry,
111  SvTreeListEntry* pParent,
112  sal_uLong& rPos
113  );
114 
115  VCL_DLLPRIVATE void ResortChildren( SvTreeListEntry* pParent );
116 
117  SvTreeList(const SvTreeList&) = delete;
118  SvTreeList& operator= (const SvTreeList&) = delete;
119 
120  std::unique_ptr<SvTreeListEntry> pRootItem;
121 
122 public:
123 
124  SvTreeList() = delete;
126  ~SvTreeList();
127 
128  void Broadcast(
129  SvListAction nActionId,
130  SvTreeListEntry* pEntry1=nullptr,
131  SvTreeListEntry* pEntry2=nullptr,
132  sal_uLong nPos=0
133  );
134 
135  void EnableInvalidate( bool bEnable );
136 
137  // Notify all Listeners
138  void InvalidateEntry( SvTreeListEntry* );
139 
140  sal_uLong GetEntryCount() const { return nEntryCount; }
141  SvTreeListEntry* First() const;
142  SvTreeListEntry* Next( SvTreeListEntry* pEntry, sal_uInt16* pDepth=nullptr ) const;
143  SvTreeListEntry* Prev( SvTreeListEntry* pEntry ) const;
144  SvTreeListEntry* Last() const;
145 
146  SvTreeListEntry* FirstChild( SvTreeListEntry* pParent ) const;
147 
148  sal_uLong Insert( SvTreeListEntry* pEntry,SvTreeListEntry* pPar,sal_uLong nPos = TREELIST_APPEND);
149  sal_uLong Insert( SvTreeListEntry* pEntry,sal_uLong nRootPos = TREELIST_APPEND )
150  { return Insert(pEntry, pRootItem.get(), nRootPos ); }
151 
152  void InsertTree( SvTreeListEntry* pTree, SvTreeListEntry* pTargetParent, sal_uLong nListPos );
153 
154  // Entries need to be in the same Model!
155  void Move( SvTreeListEntry* pSource, SvTreeListEntry* pTarget );
156 
157  // Creates ChildList if needed
158  sal_uLong Move( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uLong nListPos);
159  sal_uLong Copy( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uLong nListPos);
160 
161  bool Remove( const SvTreeListEntry* pEntry );
162  void Clear();
163 
164  bool HasChildren( const SvTreeListEntry* pEntry ) const;
165  bool HasParent( const SvTreeListEntry* pEntry ) const;
166 
167  bool IsChild(const SvTreeListEntry* pParent, const SvTreeListEntry* pChild) const;
168  SvTreeListEntry* GetEntry( SvTreeListEntry* pParent, sal_uLong nPos ) const;
169  SvTreeListEntry* GetEntry( sal_uLong nRootPos ) const;
170  SvTreeListEntry* GetEntryAtAbsPos( sal_uLong nAbsPos ) const;
171 
172  const SvTreeListEntry* GetParent( const SvTreeListEntry* pEntry ) const;
173  SvTreeListEntry* GetParent( SvTreeListEntry* pEntry );
174 
175  SvTreeListEntry* GetRootLevelParent( SvTreeListEntry* pEntry ) const;
176  const SvTreeListEntries& GetChildList( SvTreeListEntry* pParent ) const;
177  SvTreeListEntries& GetChildList( SvTreeListEntry* pParent );
178 
179  std::pair<SvTreeListEntries::iterator, SvTreeListEntries::iterator>
180  GetChildIterators(SvTreeListEntry* pParent);
181 
182  sal_uLong GetAbsPos( const SvTreeListEntry* pEntry ) const;
183  static sal_uLong GetRelPos( const SvTreeListEntry* pChild );
184 
185  sal_uLong GetChildCount( const SvTreeListEntry* pParent ) const;
186  sal_uInt16 GetDepth( const SvTreeListEntry* pEntry ) const;
187  bool IsAtRootDepth( const SvTreeListEntry* pEntry ) const;
188 
189  // The Model calls the Clone Link to clone Entries.
190  // Thus we do not need to derive from the Model if we derive from SvTreeListEntry.
191  // The Handler needs to return a SvTreeListEntry*
192  SvTreeListEntry* Clone( SvTreeListEntry* pEntry, sal_uLong& nCloneCount ) const;
194  { aCloneLink=rLink; }
195 
197  { return aCloneLink; }
198 
199  SvTreeListEntry* CloneEntry( SvTreeListEntry* pSource ) const; // Calls the Clone Link
200 
201  void SetSortMode( SvSortMode eMode ) { eSortMode = eMode; }
202  SvSortMode GetSortMode() const { return eSortMode; }
203  sal_Int32 Compare(const SvTreeListEntry* pLeft, const SvTreeListEntry* pRight) const;
204  void SetCompareHdl( const Link<const SvSortData&, sal_Int32>& rLink ) { aCompareLink = rLink; }
205  void Resort();
206 };
207 
209 {
210  friend class SvTreeList;
211 
212  struct Impl;
213  std::unique_ptr<Impl> m_pImpl;
214 
215 protected:
216  std::unique_ptr<SvTreeList> pModel;
217 
218  void ExpandListEntry( SvTreeListEntry* pParent );
219  void CollapseListEntry( SvTreeListEntry* pParent );
220  bool SelectListEntry( SvTreeListEntry* pEntry, bool bSelect );
221 
222 public:
223  SvListView(); // Sets the Model to 0
224  void dispose();
225  virtual ~SvListView();
226  void Clear();
227  virtual void ModelNotification(
228  SvListAction nActionId,
229  SvTreeListEntry* pEntry1,
230  SvTreeListEntry* pEntry2,
231  sal_uLong nPos
232  );
233 
235  { return pModel->GetVisibleCount( const_cast<SvListView*>(this) ); }
236 
238  { return pModel->FirstVisible(); }
239 
240  SvTreeListEntry* NextVisible( SvTreeListEntry* pEntry, sal_uInt16* pDepth=nullptr ) const
241  { return pModel->NextVisible(this,pEntry,pDepth); }
242 
244  { return pModel->PrevVisible(this,pEntry); }
245 
247  { return pModel->LastVisible(this); }
248 
249  SvTreeListEntry* NextVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
250  { return pModel->NextVisible(this,pEntry,rDelta); }
251 
252  SvTreeListEntry* PrevVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
253  { return pModel->PrevVisible(this,pEntry,rDelta); }
254 
255  sal_uLong GetSelectionCount() const;
256 
258  { return pModel->FirstSelected(this); }
259 
261  { return pModel->NextSelected(this,pEntry); }
262 
264  { return pModel->PrevSelected(this,pEntry); }
265 
267  { return pModel->LastSelected(this); }
269  { return pModel->GetEntryAtAbsPos(nAbsPos); }
270 
272  { return pModel->GetEntryAtVisPos(this,nVisPos); }
273 
274  sal_uLong GetAbsPos( SvTreeListEntry const * pEntry ) const
275  { return pModel->GetAbsPos(pEntry); }
276 
277  sal_uLong GetVisiblePos( SvTreeListEntry const * pEntry ) const
278  { return pModel->GetVisiblePos(this,pEntry); }
279 
281  { return pModel->GetVisibleChildCount(this,pParent); }
282 
284  { return pModel->GetChildSelectionCount(this,pParent); }
285 
286  bool IsEntryVisible( SvTreeListEntry* pEntry ) const
287  { return pModel->IsEntryVisible(this,pEntry); }
288 
289  bool IsExpanded( SvTreeListEntry* pEntry ) const;
290  bool IsAllExpanded( SvTreeListEntry* pEntry) const;
291  bool IsSelected( SvTreeListEntry* pEntry ) const;
292  void SetEntryFocus( SvTreeListEntry* pEntry, bool bFocus );
293  const SvViewDataEntry* GetViewData( const SvTreeListEntry* pEntry ) const;
294  SvViewDataEntry* GetViewData( SvTreeListEntry* pEntry );
295  bool HasViewData() const;
296 
297  virtual void InitViewData( SvViewDataEntry*, SvTreeListEntry* pEntry );
298 
299  virtual void ModelHasCleared();
300  virtual void ModelHasInserted( SvTreeListEntry* pEntry );
301  virtual void ModelHasInsertedTree( SvTreeListEntry* pEntry );
302  virtual void ModelIsMoving( SvTreeListEntry* pSource );
303  virtual void ModelHasMoved( SvTreeListEntry* pSource );
304  virtual void ModelIsRemoving( SvTreeListEntry* pEntry );
305  virtual void ModelHasRemoved( SvTreeListEntry* pEntry );
306  virtual void ModelHasEntryInvalidated( SvTreeListEntry* pEntry );
307 };
308 
309 #endif
310 
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvSortMode eSortMode
Definition: treelist.hxx:71
SvTreeListEntry * NextSelected(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:260
SvListAction
Definition: treelist.hxx:32
SvTreeListEntry * NextVisible(SvTreeListEntry *pEntry, sal_uInt16 &rDelta) const
Definition: treelist.hxx:249
bool IsEntryVisible(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:286
std::unique_ptr< Impl > m_pImpl
Definition: treelist.hxx:212
SvTreeListEntry * PrevVisible(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:243
void SetSortMode(SvSortMode eMode)
Definition: treelist.hxx:201
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
sal_uIntPtr sal_uLong
View-dependent data for a tree list entry created in the virtual function SvTreeListBox::CreateViewDa...
std::unique_ptr< SvTreeListEntry > pRootItem
Definition: treelist.hxx:120
SvTreeListEntry * LastSelected() const
Definition: treelist.hxx:266
SvTreeListEntry * PrevVisible(SvTreeListEntry *pEntry, sal_uInt16 &rDelta) const
Definition: treelist.hxx:252
sal_uLong GetAbsPos(SvTreeListEntry const *pEntry) const
Definition: treelist.hxx:274
void SetCompareHdl(const Link< const SvSortData &, sal_Int32 > &rLink)
Definition: treelist.hxx:204
void SetCloneLink(const Link< SvTreeListEntry *, SvTreeListEntry * > &rLink)
Definition: treelist.hxx:193
friend class SvTreeList
Definition: treelist.hxx:210
SvTreeListEntry * FirstSelected() const
Definition: treelist.hxx:257
Link< const SvSortData &, sal_Int32 > aCompareLink
Definition: treelist.hxx:70
SvTreeListEntry * NextVisible(SvTreeListEntry *pEntry, sal_uInt16 *pDepth=nullptr) const
Definition: treelist.hxx:240
const Link< SvTreeListEntry *, SvTreeListEntry * > & GetCloneLink() const
Definition: treelist.hxx:196
bool bAbsPositionsValid
Definition: treelist.hxx:73
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)
void Clear()
Definition: treelist.cxx:1132
SvTreeListEntry * FirstVisible() const
Definition: treelist.hxx:237
std::unique_ptr< SvTreeList > pModel
Definition: treelist.hxx:216
sal_uLong GetEntryCount() const
Definition: treelist.hxx:140
SvTreeListEntry * GetEntryAtVisPos(sal_uLong nVisPos) const
Definition: treelist.hxx:271
SvSortMode
Definition: treelist.hxx:51
bool mbEnableInvalidate
Definition: treelist.hxx:75
const SvTreeListEntry * pRight
Definition: treelist.hxx:59
SvTreeListEntry * LastVisible() const
Definition: treelist.hxx:246
SvTreeListEntry * FirstVisible() const
Definition: treelist.hxx:77
SvSortMode GetSortMode() const
Definition: treelist.hxx:202
sal_uLong GetVisibleCount() const
Definition: treelist.hxx:234
SvListView & mrOwnerListView
Definition: treelist.hxx:66
SvTreeListEntry * PrevSelected(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:263
#define VCL_DLLPRIVATE
Definition: dllapi.h:31
SvTreeListEntry * GetEntryAtAbsPos(sal_uLong nAbsPos) const
Definition: treelist.hxx:268
sal_uLong Insert(SvTreeListEntry *pEntry, sal_uLong nRootPos=TREELIST_APPEND)
Definition: treelist.hxx:149
sal_uLong GetVisiblePos(SvTreeListEntry const *pEntry) const
Definition: treelist.hxx:277
void dispose()
sal_uLong GetChildSelectionCount(SvTreeListEntry *pParent) const
Definition: treelist.hxx:283
sal_uLong GetVisibleChildCount(SvTreeListEntry *pParent) const
Definition: treelist.hxx:280
Link< SvTreeListEntry *, SvTreeListEntry * > aCloneLink
Definition: treelist.hxx:69
sal_uLong nEntryCount
Definition: treelist.hxx:67
std::vector< std::unique_ptr< SvTreeListEntry > > SvTreeListEntries
const SvTreeListEntry * pLeft
Definition: treelist.hxx:58