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* LastSelected( const SvListView*) const;
93 
94  sal_uLong GetChildSelectionCount( const SvListView*,SvTreeListEntry* pParent ) const;
95 
96  VCL_DLLPRIVATE void SetAbsolutePositions();
97 
98  VCL_DLLPRIVATE void CloneChildren(
99  SvTreeListEntries& rDst, sal_uLong& rCloneCount, SvTreeListEntries& rSrc, SvTreeListEntry& rNewParent) const;
100 
105  VCL_DLLPRIVATE static void SetListPositions( SvTreeListEntries& rEntries );
106 
107  // rPos is not changed for SortModeNone
108  VCL_DLLPRIVATE void GetInsertionPos(
109  SvTreeListEntry const * pEntry,
110  SvTreeListEntry* pParent,
111  sal_uLong& rPos
112  );
113 
114  VCL_DLLPRIVATE void ResortChildren( SvTreeListEntry* pParent );
115 
116  SvTreeList(const SvTreeList&) = delete;
117  SvTreeList& operator= (const SvTreeList&) = delete;
118 
119  std::unique_ptr<SvTreeListEntry> pRootItem;
120 
121 public:
122 
123  SvTreeList() = delete;
125  ~SvTreeList();
126 
127  void Broadcast(
128  SvListAction nActionId,
129  SvTreeListEntry* pEntry1=nullptr,
130  SvTreeListEntry* pEntry2=nullptr,
131  sal_uLong nPos=0
132  );
133 
134  void EnableInvalidate( bool bEnable );
135 
136  // Notify all Listeners
137  void InvalidateEntry( SvTreeListEntry* );
138 
139  sal_uLong GetEntryCount() const { return nEntryCount; }
140  SvTreeListEntry* First() const;
141  SvTreeListEntry* Next( SvTreeListEntry* pEntry, sal_uInt16* pDepth=nullptr ) const;
142  SvTreeListEntry* Prev( SvTreeListEntry* pEntry ) const;
143  SvTreeListEntry* Last() const;
144 
145  SvTreeListEntry* FirstChild( SvTreeListEntry* pParent ) const;
146 
147  sal_uLong Insert( SvTreeListEntry* pEntry,SvTreeListEntry* pPar,sal_uLong nPos = TREELIST_APPEND);
148  sal_uLong Insert( SvTreeListEntry* pEntry,sal_uLong nRootPos = TREELIST_APPEND )
149  { return Insert(pEntry, pRootItem.get(), nRootPos ); }
150 
151  void InsertTree( SvTreeListEntry* pTree, SvTreeListEntry* pTargetParent, sal_uLong nListPos );
152 
153  // Entries need to be in the same Model!
154  void Move( SvTreeListEntry* pSource, SvTreeListEntry* pTarget );
155 
156  // Creates ChildList if needed
157  sal_uLong Move( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uLong nListPos);
158  sal_uLong Copy( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uLong nListPos);
159 
160  bool Remove( const SvTreeListEntry* pEntry );
161  void Clear();
162 
163  bool HasChildren( const SvTreeListEntry* pEntry ) const;
164  bool HasParent( const SvTreeListEntry* pEntry ) const;
165 
166  bool IsChild(const SvTreeListEntry* pParent, const SvTreeListEntry* pChild) const;
167  SvTreeListEntry* GetEntry( SvTreeListEntry* pParent, sal_uLong nPos ) const;
168  SvTreeListEntry* GetEntry( sal_uLong nRootPos ) const;
169  SvTreeListEntry* GetEntryAtAbsPos( sal_uLong nAbsPos ) const;
170 
171  const SvTreeListEntry* GetParent( const SvTreeListEntry* pEntry ) const;
172  SvTreeListEntry* GetParent( SvTreeListEntry* pEntry );
173 
174  SvTreeListEntry* GetRootLevelParent( SvTreeListEntry* pEntry ) const;
175  const SvTreeListEntries& GetChildList( SvTreeListEntry* pParent ) const;
176  SvTreeListEntries& GetChildList( SvTreeListEntry* pParent );
177 
178  std::pair<SvTreeListEntries::iterator, SvTreeListEntries::iterator>
179  GetChildIterators(SvTreeListEntry* pParent);
180 
181  sal_uLong GetAbsPos( const SvTreeListEntry* pEntry ) const;
182  static sal_uLong GetRelPos( const SvTreeListEntry* pChild );
183 
184  sal_uLong GetChildCount( const SvTreeListEntry* pParent ) const;
185  sal_uInt16 GetDepth( const SvTreeListEntry* pEntry ) const;
186  bool IsAtRootDepth( const SvTreeListEntry* pEntry ) const;
187 
188  // The Model calls the Clone Link to clone Entries.
189  // Thus we do not need to derive from the Model if we derive from SvTreeListEntry.
190  // The Handler needs to return a SvTreeListEntry*
191  SvTreeListEntry* Clone( SvTreeListEntry* pEntry, sal_uLong& nCloneCount ) const;
193  { aCloneLink=rLink; }
194 
196  { return aCloneLink; }
197 
198  SvTreeListEntry* CloneEntry( SvTreeListEntry* pSource ) const; // Calls the Clone Link
199 
200  void SetSortMode( SvSortMode eMode ) { eSortMode = eMode; }
201  SvSortMode GetSortMode() const { return eSortMode; }
202  sal_Int32 Compare(const SvTreeListEntry* pLeft, const SvTreeListEntry* pRight) const;
203  void SetCompareHdl( const Link<const SvSortData&, sal_Int32>& rLink ) { aCompareLink = rLink; }
204  void Resort();
205 };
206 
208 {
209  friend class SvTreeList;
210 
211  struct SAL_DLLPRIVATE Impl;
212  std::unique_ptr<Impl> m_pImpl;
213 
214 protected:
215  std::unique_ptr<SvTreeList> pModel;
216 
217  void ExpandListEntry( SvTreeListEntry* pParent );
218  void CollapseListEntry( SvTreeListEntry* pParent );
219  bool SelectListEntry( SvTreeListEntry* pEntry, bool bSelect );
220 
221 public:
222  SvListView(); // Sets the Model to 0
223  void dispose();
224  virtual ~SvListView();
225  void Clear();
226  virtual void ModelNotification(
227  SvListAction nActionId,
228  SvTreeListEntry* pEntry1,
229  SvTreeListEntry* pEntry2,
230  sal_uLong nPos
231  );
232 
234  { return pModel->GetVisibleCount( const_cast<SvListView*>(this) ); }
235 
237  { return pModel->FirstVisible(); }
238 
240  { return pModel->NextVisible(this,pEntry); }
241 
243  { return pModel->PrevVisible(this,pEntry); }
244 
246  { return pModel->LastVisible(this); }
247 
248  SvTreeListEntry* NextVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
249  { return pModel->NextVisible(this,pEntry,rDelta); }
250 
251  SvTreeListEntry* PrevVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
252  { return pModel->PrevVisible(this,pEntry,rDelta); }
253 
254  sal_uLong GetSelectionCount() const;
255 
257  { return pModel->FirstSelected(this); }
258 
260  { return pModel->NextSelected(this,pEntry); }
261 
263  { return pModel->LastSelected(this); }
265  { return pModel->GetEntryAtAbsPos(nAbsPos); }
266 
268  { return pModel->GetEntryAtVisPos(this,nVisPos); }
269 
270  sal_uLong GetAbsPos( SvTreeListEntry const * pEntry ) const
271  { return pModel->GetAbsPos(pEntry); }
272 
273  sal_uLong GetVisiblePos( SvTreeListEntry const * pEntry ) const
274  { return pModel->GetVisiblePos(this,pEntry); }
275 
277  { return pModel->GetVisibleChildCount(this,pParent); }
278 
279  bool IsEntryVisible( SvTreeListEntry* pEntry ) const
280  { return pModel->IsEntryVisible(this,pEntry); }
281 
282  bool IsExpanded( SvTreeListEntry* pEntry ) const;
283  bool IsAllExpanded( SvTreeListEntry* pEntry) const;
284  bool IsSelected(const SvTreeListEntry* pEntry) const;
285  void SetEntryFocus( SvTreeListEntry* pEntry, bool bFocus );
286  const SvViewDataEntry* GetViewData( const SvTreeListEntry* pEntry ) const;
287  SvViewDataEntry* GetViewData( SvTreeListEntry* pEntry );
288  bool HasViewData() const;
289 
290  virtual void InitViewData( SvViewDataEntry*, SvTreeListEntry* pEntry );
291 
292  virtual void ModelHasCleared();
293  virtual void ModelHasInserted( SvTreeListEntry* pEntry );
294  virtual void ModelHasInsertedTree( SvTreeListEntry* pEntry );
295  virtual void ModelIsMoving( SvTreeListEntry* pSource );
296  virtual void ModelHasMoved( SvTreeListEntry* pSource );
297  virtual void ModelIsRemoving( SvTreeListEntry* pEntry );
298  virtual void ModelHasRemoved( SvTreeListEntry* pEntry );
299  virtual void ModelHasEntryInvalidated( SvTreeListEntry* pEntry );
300 };
301 
302 #endif
303 
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvTreeListEntry * NextVisible(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:239
SvSortMode eSortMode
Definition: treelist.hxx:71
SvTreeListEntry * NextSelected(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:259
SvListAction
Definition: treelist.hxx:32
SvTreeListEntry * NextVisible(SvTreeListEntry *pEntry, sal_uInt16 &rDelta) const
Definition: treelist.hxx:248
size_t GetAbsPos(const weld::TreeView &rTreeView, const weld::TreeIter &rIter)
Definition: builder.cxx:427
bool IsEntryVisible(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:279
std::unique_ptr< Impl > m_pImpl
Definition: treelist.hxx:212
SvTreeListEntry * PrevVisible(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:242
void SetSortMode(SvSortMode eMode)
Definition: treelist.hxx:200
#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:119
SvTreeListEntry * LastSelected() const
Definition: treelist.hxx:262
SvTreeListEntry * PrevVisible(SvTreeListEntry *pEntry, sal_uInt16 &rDelta) const
Definition: treelist.hxx:251
sal_uLong GetAbsPos(SvTreeListEntry const *pEntry) const
Definition: treelist.hxx:270
void SetCompareHdl(const Link< const SvSortData &, sal_Int32 > &rLink)
Definition: treelist.hxx:203
void SetCloneLink(const Link< SvTreeListEntry *, SvTreeListEntry * > &rLink)
Definition: treelist.hxx:192
friend class SvTreeList
Definition: treelist.hxx:209
SvTreeListEntry * FirstSelected() const
Definition: treelist.hxx:256
Link< const SvSortData &, sal_Int32 > aCompareLink
Definition: treelist.hxx:70
const Link< SvTreeListEntry *, SvTreeListEntry * > & GetCloneLink() const
Definition: treelist.hxx:195
bool bAbsPositionsValid
Definition: treelist.hxx:73
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)
void Clear()
Definition: treelist.cxx:1118
SvTreeListEntry * FirstVisible() const
Definition: treelist.hxx:236
std::unique_ptr< SvTreeList > pModel
Definition: treelist.hxx:215
sal_uLong GetEntryCount() const
Definition: treelist.hxx:139
SvTreeListEntry * GetEntryAtVisPos(sal_uLong nVisPos) const
Definition: treelist.hxx:267
SvSortMode
Definition: treelist.hxx:51
bool mbEnableInvalidate
Definition: treelist.hxx:75
const SvTreeListEntry * pRight
Definition: treelist.hxx:59
SvTreeListEntry * LastVisible() const
Definition: treelist.hxx:245
SvTreeListEntry * FirstVisible() const
Definition: treelist.hxx:77
SvSortMode GetSortMode() const
Definition: treelist.hxx:201
sal_uLong GetVisibleCount() const
Definition: treelist.hxx:233
SvListView & mrOwnerListView
Definition: treelist.hxx:66
#define VCL_DLLPRIVATE
Definition: dllapi.h:31
SvTreeListEntry * GetEntryAtAbsPos(sal_uLong nAbsPos) const
Definition: treelist.hxx:264
sal_uLong Insert(SvTreeListEntry *pEntry, sal_uLong nRootPos=TREELIST_APPEND)
Definition: treelist.hxx:148
sal_uLong GetVisiblePos(SvTreeListEntry const *pEntry) const
Definition: treelist.hxx:273
void dispose()
sal_uLong GetVisibleChildCount(SvTreeListEntry *pParent) const
Definition: treelist.hxx:276
Link< SvTreeListEntry *, SvTreeListEntry * > aCloneLink
Definition: treelist.hxx:69
sal_uLong nEntryCount
Definition: treelist.hxx:67
bool IsEntryVisible(const weld::TreeView &rTreeView, const weld::TreeIter &rIter)
Definition: builder.cxx:445
std::vector< std::unique_ptr< SvTreeListEntry > > SvTreeListEntries
const SvTreeListEntry * pLeft
Definition: treelist.hxx:58