Update git submodules
[LibreOffice.git] / include / vcl / toolkit / treelist.hxx
blob504a78363a5f00772ca8b97e504aa8274d2a8a54
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 #pragma once
22 #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
23 #error "don't use this in new code"
24 #endif
26 #include <config_options.h>
27 #include <vcl/dllapi.h>
28 #include <vcl/toolkit/treelistentries.hxx>
30 #include <tools/link.hxx>
31 #include <tools/contnr.hxx>
33 #include <memory>
35 enum class SvListAction
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
50 class SvTreeListEntry;
51 class SvListView;
52 class SvViewDataEntry;
54 enum class SvSortMode { Ascending, Descending, None };
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
61 const SvTreeListEntry* pLeft;
62 const SvTreeListEntry* pRight;
65 class UNLESS_MERGELIBS_MORE(VCL_DLLPUBLIC) SvTreeList final
67 friend class SvListView;
69 SvListView& mrOwnerListView;
70 sal_uInt32 nEntryCount;
72 Link<SvTreeListEntry*, SvTreeListEntry*> aCloneLink;
73 Link<const SvSortData&, sal_Int32> aCompareLink;
74 SvSortMode eSortMode;
76 bool bAbsPositionsValid;
78 bool mbEnableInvalidate;
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;
87 bool IsEntryVisible( const SvListView*,SvTreeListEntry* pEntry ) const;
88 SvTreeListEntry* GetEntryAtVisPos( const SvListView*, sal_uInt32 nVisPos ) const;
89 sal_uInt32 GetVisiblePos( const SvListView*,SvTreeListEntry const * pEntry ) const;
90 sal_uInt32 GetVisibleCount( SvListView* ) const;
91 sal_uInt32 GetVisibleChildCount( const SvListView*,SvTreeListEntry* pParent ) const;
93 SvTreeListEntry* FirstSelected( const SvListView*) const;
94 SvTreeListEntry* NextSelected( const SvListView*,SvTreeListEntry* pEntry ) const;
96 sal_uInt32 GetChildSelectionCount( const SvListView*,SvTreeListEntry* pParent ) const;
98 SAL_DLLPRIVATE void SetAbsolutePositions();
100 SAL_DLLPRIVATE void CloneChildren(
101 SvTreeListEntries& rDst, sal_uInt32& rCloneCount, SvTreeListEntries& rSrc, SvTreeListEntry& rNewParent) const;
104 * Invalidate the cached position data to have them re-generated before
105 * the next access.
107 SAL_DLLPRIVATE static void SetListPositions( SvTreeListEntries& rEntries );
109 // rPos is not changed for SortModeNone
110 SAL_DLLPRIVATE void GetInsertionPos(
111 SvTreeListEntry const * pEntry,
112 SvTreeListEntry* pParent,
113 sal_uInt32& rPos
116 SAL_DLLPRIVATE void ResortChildren( SvTreeListEntry* pParent );
118 SvTreeList(const SvTreeList&) = delete;
119 SvTreeList& operator= (const SvTreeList&) = delete;
121 std::unique_ptr<SvTreeListEntry> pRootItem;
123 public:
125 SvTreeList() = delete;
126 SvTreeList(SvListView&);
127 ~SvTreeList();
129 void Broadcast(
130 SvListAction nActionId,
131 SvTreeListEntry* pEntry1=nullptr,
132 SvTreeListEntry* pEntry2=nullptr,
133 sal_uInt32 nPos=0
136 void EnableInvalidate( bool bEnable );
137 bool IsEnableInvalidate() const { return mbEnableInvalidate; }
139 // Notify all Listeners
140 void InvalidateEntry( SvTreeListEntry* );
142 sal_uInt32 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;
148 SvTreeListEntry* FirstChild( SvTreeListEntry* pParent ) const;
150 sal_uInt32 Insert( SvTreeListEntry* pEntry,SvTreeListEntry* pPar,sal_uInt32 nPos = TREELIST_APPEND);
151 sal_uInt32 Insert( SvTreeListEntry* pEntry,sal_uInt32 nRootPos = TREELIST_APPEND )
152 { return Insert(pEntry, pRootItem.get(), nRootPos ); }
154 void InsertTree( SvTreeListEntry* pTree, SvTreeListEntry* pTargetParent, sal_uInt32 nListPos );
156 // Entries need to be in the same Model!
157 void Move( SvTreeListEntry* pSource, SvTreeListEntry* pTarget );
159 // Creates ChildList if needed
160 sal_uInt32 Move( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uInt32 nListPos);
161 sal_uInt32 Copy( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uInt32 nListPos);
163 bool Remove( const SvTreeListEntry* pEntry );
164 void Clear();
166 bool IsChild(const SvTreeListEntry* pParent, const SvTreeListEntry* pChild) const;
167 SvTreeListEntry* GetEntry( SvTreeListEntry* pParent, sal_uInt32 nPos ) const;
168 SvTreeListEntry* GetEntry( sal_uInt32 nRootPos ) const;
169 SvTreeListEntry* GetEntryAtAbsPos( sal_uInt32 nAbsPos ) const;
171 const SvTreeListEntry* GetParent( const SvTreeListEntry* pEntry ) const;
172 SvTreeListEntry* GetParent( SvTreeListEntry* pEntry );
174 const SvTreeListEntries& GetChildList( SvTreeListEntry* pParent ) const;
175 SvTreeListEntries& GetChildList( SvTreeListEntry* pParent );
177 sal_uInt32 GetAbsPos( const SvTreeListEntry* pEntry ) const;
178 static sal_uInt32 GetRelPos( const SvTreeListEntry* pChild );
180 sal_uInt32 GetChildCount( const SvTreeListEntry* pParent ) const;
181 sal_uInt16 GetDepth( const SvTreeListEntry* pEntry ) const;
182 bool IsAtRootDepth( const SvTreeListEntry* pEntry ) const;
184 // The Model calls the Clone Link to clone Entries.
185 // Thus we do not need to derive from the Model if we derive from SvTreeListEntry.
186 // The Handler needs to return a SvTreeListEntry*
187 SvTreeListEntry* Clone( SvTreeListEntry* pEntry, sal_uInt32& nCloneCount ) const;
188 void SetCloneLink( const Link<SvTreeListEntry*,SvTreeListEntry*>& rLink )
189 { aCloneLink=rLink; }
191 const Link<SvTreeListEntry*,SvTreeListEntry*>& GetCloneLink() const
192 { return aCloneLink; }
194 SvTreeListEntry* CloneEntry( SvTreeListEntry* pSource ) const; // Calls the Clone Link
196 void SetSortMode( SvSortMode eMode ) { eSortMode = eMode; }
197 SvSortMode GetSortMode() const { return eSortMode; }
198 sal_Int32 Compare(const SvTreeListEntry* pLeft, const SvTreeListEntry* pRight) const;
199 void SetCompareHdl( const Link<const SvSortData&, sal_Int32>& rLink ) { aCompareLink = rLink; }
200 void Resort();
203 class UNLESS_MERGELIBS_MORE(VCL_DLLPUBLIC) SvListView
205 friend class SvTreeList;
207 struct SAL_DLLPRIVATE Impl;
208 std::unique_ptr<Impl> m_pImpl;
210 protected:
211 std::unique_ptr<SvTreeList> pModel;
213 void ExpandListEntry( SvTreeListEntry* pParent );
214 void CollapseListEntry( SvTreeListEntry* pParent );
215 bool SelectListEntry( SvTreeListEntry* pEntry, bool bSelect );
217 public:
218 SvListView(); // Sets the Model to 0
219 void dispose();
220 virtual ~SvListView();
221 void Clear();
222 virtual void ModelNotification(
223 SvListAction nActionId,
224 SvTreeListEntry* pEntry1,
225 SvTreeListEntry* pEntry2,
226 sal_uInt32 nPos
229 sal_uInt32 GetVisibleCount() const
230 { return pModel->GetVisibleCount( const_cast<SvListView*>(this) ); }
232 SvTreeListEntry* FirstVisible() const
233 { return pModel->FirstVisible(); }
235 SvTreeListEntry* NextVisible( SvTreeListEntry* pEntry ) const
236 { return pModel->NextVisible(this,pEntry); }
238 SvTreeListEntry* PrevVisible( SvTreeListEntry* pEntry ) const
239 { return pModel->PrevVisible(this,pEntry); }
241 SvTreeListEntry* LastVisible() const
242 { return pModel->LastVisible(this); }
244 SvTreeListEntry* NextVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
245 { return pModel->NextVisible(this,pEntry,rDelta); }
247 SvTreeListEntry* PrevVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
248 { return pModel->PrevVisible(this,pEntry,rDelta); }
250 sal_uInt32 GetSelectionCount() const;
252 SvTreeListEntry* FirstSelected() const
253 { return pModel->FirstSelected(this); }
255 SvTreeListEntry* NextSelected( SvTreeListEntry* pEntry ) const
256 { return pModel->NextSelected(this,pEntry); }
258 SvTreeListEntry* GetEntryAtAbsPos( sal_uInt32 nAbsPos ) const
259 { return pModel->GetEntryAtAbsPos(nAbsPos); }
261 SvTreeListEntry* GetEntryAtVisPos( sal_uInt32 nVisPos ) const
262 { return pModel->GetEntryAtVisPos(this,nVisPos); }
264 sal_uInt32 GetAbsPos( SvTreeListEntry const * pEntry ) const
265 { return pModel->GetAbsPos(pEntry); }
267 sal_uInt32 GetVisiblePos( SvTreeListEntry const * pEntry ) const
268 { return pModel->GetVisiblePos(this,pEntry); }
270 sal_uInt32 GetVisibleChildCount(SvTreeListEntry* pParent ) const
271 { return pModel->GetVisibleChildCount(this,pParent); }
273 bool IsEntryVisible( SvTreeListEntry* pEntry ) const
274 { return pModel->IsEntryVisible(this,pEntry); }
276 bool IsExpanded( SvTreeListEntry* pEntry ) const;
277 bool IsAllExpanded( SvTreeListEntry* pEntry) const;
278 bool IsSelected(const SvTreeListEntry* pEntry) const;
279 void SetEntryFocus( SvTreeListEntry* pEntry, bool bFocus );
280 const SvViewDataEntry* GetViewData( const SvTreeListEntry* pEntry ) const;
281 SvViewDataEntry* GetViewData( SvTreeListEntry* pEntry );
282 bool HasViewData() const;
284 virtual void InitViewData( SvViewDataEntry*, SvTreeListEntry* pEntry );
286 virtual void ModelHasCleared();
287 virtual void ModelHasInserted( SvTreeListEntry* pEntry );
288 virtual void ModelHasInsertedTree( SvTreeListEntry* pEntry );
289 virtual void ModelIsMoving( SvTreeListEntry* pSource );
290 virtual void ModelHasMoved( SvTreeListEntry* pSource );
291 virtual void ModelIsRemoving( SvTreeListEntry* pEntry );
292 virtual void ModelHasRemoved( SvTreeListEntry* pEntry );
293 virtual void ModelHasEntryInvalidated( SvTreeListEntry* pEntry );
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */