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 #pragma once
21 
22 #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
23 #error "don't use this in new code"
24 #endif
25 
26 #include <vcl/dllapi.h>
28 
29 #include <tools/solar.h>
30 #include <tools/link.hxx>
31 #include <tools/contnr.hxx>
32 
33 #include <memory>
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 };
49 
50 class SvTreeListEntry;
51 class SvListView;
52 class SvViewDataEntry;
53 
55 
56 // For the return values of Sortlink:
57 // See International::Compare( pLeft, pRight )
58 // ( Compare(a,b) ==> b.Compare(a) ==> strcmp(a,b) )
59 struct SvSortData
60 {
63 };
64 
66 {
67  friend class SvListView;
68 
71 
75 
77 
79 
80  SvTreeListEntry* FirstVisible() const { return First(); }
81  SvTreeListEntry* NextVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16* pDepth=nullptr ) const;
82  SvTreeListEntry* PrevVisible( const SvListView*,SvTreeListEntry* pEntry ) const;
83  SvTreeListEntry* LastVisible( const SvListView* ) const;
84  SvTreeListEntry* NextVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const;
85  SvTreeListEntry* PrevVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const;
86 
87  bool IsEntryVisible( const SvListView*,SvTreeListEntry* pEntry ) const;
88  SvTreeListEntry* GetEntryAtVisPos( const SvListView*,sal_uLong nVisPos ) const;
89  sal_uLong GetVisiblePos( const SvListView*,SvTreeListEntry const * pEntry ) const;
92 
94  SvTreeListEntry* NextSelected( const SvListView*,SvTreeListEntry* pEntry ) const;
95 
96  sal_uLong GetChildSelectionCount( const SvListView*,SvTreeListEntry* pParent ) const;
97 
98  VCL_DLLPRIVATE void SetAbsolutePositions();
99 
100  VCL_DLLPRIVATE void CloneChildren(
101  SvTreeListEntries& rDst, sal_uLong& rCloneCount, SvTreeListEntries& rSrc, SvTreeListEntry& rNewParent) const;
102 
107  VCL_DLLPRIVATE static void SetListPositions( SvTreeListEntries& rEntries );
108 
109  // rPos is not changed for SortModeNone
110  VCL_DLLPRIVATE void GetInsertionPos(
111  SvTreeListEntry const * pEntry,
112  SvTreeListEntry* pParent,
113  sal_uLong& rPos
114  );
115 
116  VCL_DLLPRIVATE void ResortChildren( SvTreeListEntry* pParent );
117 
118  SvTreeList(const SvTreeList&) = delete;
119  SvTreeList& operator= (const SvTreeList&) = delete;
120 
121  std::unique_ptr<SvTreeListEntry> pRootItem;
122 
123 public:
124 
125  SvTreeList() = delete;
127  ~SvTreeList();
128 
129  void Broadcast(
130  SvListAction nActionId,
131  SvTreeListEntry* pEntry1=nullptr,
132  SvTreeListEntry* pEntry2=nullptr,
133  sal_uLong nPos=0
134  );
135 
136  void EnableInvalidate( bool bEnable );
137  bool IsEnableInvalidate() const { return mbEnableInvalidate; }
138 
139  // Notify all Listeners
140  void InvalidateEntry( SvTreeListEntry* );
141 
142  sal_uLong GetEntryCount() const { return nEntryCount; }
143  SvTreeListEntry* First() const;
144  SvTreeListEntry* Next( SvTreeListEntry* pEntry, sal_uInt16* pDepth=nullptr ) const;
145  SvTreeListEntry* Prev( SvTreeListEntry* pEntry ) const;
146  SvTreeListEntry* Last() const;
147 
148  SvTreeListEntry* FirstChild( SvTreeListEntry* pParent ) const;
149 
150  sal_uLong Insert( SvTreeListEntry* pEntry,SvTreeListEntry* pPar,sal_uLong nPos = TREELIST_APPEND);
151  sal_uLong Insert( SvTreeListEntry* pEntry,sal_uLong nRootPos = TREELIST_APPEND )
152  { return Insert(pEntry, pRootItem.get(), nRootPos ); }
153 
154  void InsertTree( SvTreeListEntry* pTree, SvTreeListEntry* pTargetParent, sal_uLong nListPos );
155 
156  // Entries need to be in the same Model!
157  void Move( SvTreeListEntry* pSource, SvTreeListEntry* pTarget );
158 
159  // Creates ChildList if needed
160  sal_uLong Move( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uLong nListPos);
161  sal_uLong Copy( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uLong nListPos);
162 
163  bool Remove( const SvTreeListEntry* pEntry );
164  void Clear();
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  sal_uLong GetAbsPos( const SvTreeListEntry* pEntry ) const;
179  static sal_uLong GetRelPos( const SvTreeListEntry* pChild );
180 
181  sal_uLong GetChildCount( const SvTreeListEntry* pParent ) const;
182  sal_uInt16 GetDepth( const SvTreeListEntry* pEntry ) const;
183  bool IsAtRootDepth( const SvTreeListEntry* pEntry ) const;
184 
185  // The Model calls the Clone Link to clone Entries.
186  // Thus we do not need to derive from the Model if we derive from SvTreeListEntry.
187  // The Handler needs to return a SvTreeListEntry*
188  SvTreeListEntry* Clone( SvTreeListEntry* pEntry, sal_uLong& nCloneCount ) const;
190  { aCloneLink=rLink; }
191 
193  { return aCloneLink; }
194 
195  SvTreeListEntry* CloneEntry( SvTreeListEntry* pSource ) const; // Calls the Clone Link
196 
197  void SetSortMode( SvSortMode eMode ) { eSortMode = eMode; }
198  SvSortMode GetSortMode() const { return eSortMode; }
199  sal_Int32 Compare(const SvTreeListEntry* pLeft, const SvTreeListEntry* pRight) const;
200  void SetCompareHdl( const Link<const SvSortData&, sal_Int32>& rLink ) { aCompareLink = rLink; }
201  void Resort();
202 };
203 
205 {
206  friend class SvTreeList;
207 
208  struct SAL_DLLPRIVATE Impl;
209  std::unique_ptr<Impl> m_pImpl;
210 
211 protected:
212  std::unique_ptr<SvTreeList> pModel;
213 
214  void ExpandListEntry( SvTreeListEntry* pParent );
215  void CollapseListEntry( SvTreeListEntry* pParent );
216  bool SelectListEntry( SvTreeListEntry* pEntry, bool bSelect );
217 
218 public:
219  SvListView(); // Sets the Model to 0
220  void dispose();
221  virtual ~SvListView();
222  void Clear();
223  virtual void ModelNotification(
224  SvListAction nActionId,
225  SvTreeListEntry* pEntry1,
226  SvTreeListEntry* pEntry2,
227  sal_uLong nPos
228  );
229 
231  { return pModel->GetVisibleCount( const_cast<SvListView*>(this) ); }
232 
234  { return pModel->FirstVisible(); }
235 
237  { return pModel->NextVisible(this,pEntry); }
238 
240  { return pModel->PrevVisible(this,pEntry); }
241 
243  { return pModel->LastVisible(this); }
244 
245  SvTreeListEntry* NextVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
246  { return pModel->NextVisible(this,pEntry,rDelta); }
247 
248  SvTreeListEntry* PrevVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
249  { return pModel->PrevVisible(this,pEntry,rDelta); }
250 
251  sal_uLong GetSelectionCount() const;
252 
254  { return pModel->FirstSelected(this); }
255 
257  { return pModel->NextSelected(this,pEntry); }
258 
260  { return pModel->GetEntryAtAbsPos(nAbsPos); }
261 
263  { return pModel->GetEntryAtVisPos(this,nVisPos); }
264 
265  sal_uLong GetAbsPos( SvTreeListEntry const * pEntry ) const
266  { return pModel->GetAbsPos(pEntry); }
267 
268  sal_uLong GetVisiblePos( SvTreeListEntry const * pEntry ) const
269  { return pModel->GetVisiblePos(this,pEntry); }
270 
272  { return pModel->GetVisibleChildCount(this,pParent); }
273 
274  bool IsEntryVisible( SvTreeListEntry* pEntry ) const
275  { return pModel->IsEntryVisible(this,pEntry); }
276 
277  bool IsExpanded( SvTreeListEntry* pEntry ) const;
278  bool IsAllExpanded( SvTreeListEntry* pEntry) const;
279  bool IsSelected(const SvTreeListEntry* pEntry) const;
280  void SetEntryFocus( SvTreeListEntry* pEntry, bool bFocus );
281  const SvViewDataEntry* GetViewData( const SvTreeListEntry* pEntry ) const;
282  SvViewDataEntry* GetViewData( SvTreeListEntry* pEntry );
283  bool HasViewData() const;
284 
285  virtual void InitViewData( SvViewDataEntry*, SvTreeListEntry* pEntry );
286 
287  virtual void ModelHasCleared();
288  virtual void ModelHasInserted( SvTreeListEntry* pEntry );
289  virtual void ModelHasInsertedTree( SvTreeListEntry* pEntry );
290  virtual void ModelIsMoving( SvTreeListEntry* pSource );
291  virtual void ModelHasMoved( SvTreeListEntry* pSource );
292  virtual void ModelIsRemoving( SvTreeListEntry* pEntry );
293  virtual void ModelHasRemoved( SvTreeListEntry* pEntry );
294  virtual void ModelHasEntryInvalidated( SvTreeListEntry* pEntry );
295 };
296 
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvTreeListEntry * NextVisible(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:236
SvSortMode eSortMode
Definition: treelist.hxx:74
SvTreeListEntry * NextSelected(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:256
SvListAction
Definition: treelist.hxx:35
SvTreeListEntry * NextVisible(SvTreeListEntry *pEntry, sal_uInt16 &rDelta) const
Definition: treelist.hxx:245
size_t GetAbsPos(const weld::TreeView &rTreeView, const weld::TreeIter &rIter)
Definition: builder.cxx:394
bool IsEntryVisible(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:274
std::unique_ptr< Impl > m_pImpl
Definition: treelist.hxx:209
SvTreeListEntry * PrevVisible(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:239
void SetSortMode(SvSortMode eMode)
Definition: treelist.hxx:197
#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:121
SvTreeListEntry * PrevVisible(SvTreeListEntry *pEntry, sal_uInt16 &rDelta) const
Definition: treelist.hxx:248
sal_uLong GetAbsPos(SvTreeListEntry const *pEntry) const
Definition: treelist.hxx:265
void SetCompareHdl(const Link< const SvSortData &, sal_Int32 > &rLink)
Definition: treelist.hxx:200
void SetCloneLink(const Link< SvTreeListEntry *, SvTreeListEntry * > &rLink)
Definition: treelist.hxx:189
friend class SvTreeList
Definition: treelist.hxx:206
bool IsEnableInvalidate() const
Definition: treelist.hxx:137
SvTreeListEntry * FirstSelected() const
Definition: treelist.hxx:253
Link< const SvSortData &, sal_Int32 > aCompareLink
Definition: treelist.hxx:73
const Link< SvTreeListEntry *, SvTreeListEntry * > & GetCloneLink() const
Definition: treelist.hxx:192
bool bAbsPositionsValid
Definition: treelist.hxx:76
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)
void Clear()
Definition: treelist.cxx:1087
SvTreeListEntry * FirstVisible() const
Definition: treelist.hxx:233
std::unique_ptr< SvTreeList > pModel
Definition: treelist.hxx:212
sal_uLong GetEntryCount() const
Definition: treelist.hxx:142
SvTreeListEntry * GetEntryAtVisPos(sal_uLong nVisPos) const
Definition: treelist.hxx:262
SvSortMode
Definition: treelist.hxx:54
bool mbEnableInvalidate
Definition: treelist.hxx:78
const SvTreeListEntry * pRight
Definition: treelist.hxx:62
SvTreeListEntry * LastVisible() const
Definition: treelist.hxx:242
SvTreeListEntry * FirstVisible() const
Definition: treelist.hxx:80
SvSortMode GetSortMode() const
Definition: treelist.hxx:198
sal_uLong GetVisibleCount() const
Definition: treelist.hxx:230
SvListView & mrOwnerListView
Definition: treelist.hxx:69
#define VCL_DLLPRIVATE
Definition: dllapi.h:31
SvTreeListEntry * GetEntryAtAbsPos(sal_uLong nAbsPos) const
Definition: treelist.hxx:259
sal_uLong Insert(SvTreeListEntry *pEntry, sal_uLong nRootPos=TREELIST_APPEND)
Definition: treelist.hxx:151
sal_uLong GetVisiblePos(SvTreeListEntry const *pEntry) const
Definition: treelist.hxx:268
void dispose()
sal_uLong GetVisibleChildCount(SvTreeListEntry *pParent) const
Definition: treelist.hxx:271
Link< SvTreeListEntry *, SvTreeListEntry * > aCloneLink
Definition: treelist.hxx:72
sal_uLong nEntryCount
Definition: treelist.hxx:70
bool IsEntryVisible(const weld::TreeView &rTreeView, const weld::TreeIter &rIter)
Definition: builder.cxx:412
std::vector< std::unique_ptr< SvTreeListEntry > > SvTreeListEntries
const SvTreeListEntry * pLeft
Definition: treelist.hxx:61