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/link.hxx>
30#include <tools/contnr.hxx>
31
32#include <memory>
33
34enum class SvListAction
35{
36 INSERTED = 1,
37 REMOVING = 2,
38 REMOVED = 3,
39 MOVING = 4,
40 MOVED = 5,
41 CLEARING = 6,
42 INSERTED_TREE = 7,
44 RESORTING = 9,
45 RESORTED = 10,
46 CLEARED = 11
47};
48
49class SvTreeListEntry;
50class SvListView;
51class SvViewDataEntry;
52
54
55// For the return values of Sortlink:
56// See International::Compare( pLeft, pRight )
57// ( Compare(a,b) ==> b.Compare(a) ==> strcmp(a,b) )
59{
62};
63
65{
66 friend class SvListView;
67
69 sal_uInt32 nEntryCount;
70
74
76
78
79 SvTreeListEntry* FirstVisible() const { return First(); }
80 SvTreeListEntry* NextVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16* pDepth=nullptr ) const;
82 SvTreeListEntry* LastVisible( const SvListView* ) const;
83 SvTreeListEntry* NextVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const;
84 SvTreeListEntry* PrevVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const;
85
86 bool IsEntryVisible( const SvListView*,SvTreeListEntry* pEntry ) const;
87 SvTreeListEntry* GetEntryAtVisPos( const SvListView*, sal_uInt32 nVisPos ) const;
88 sal_uInt32 GetVisiblePos( const SvListView*,SvTreeListEntry const * pEntry ) const;
89 sal_uInt32 GetVisibleCount( SvListView* ) const;
90 sal_uInt32 GetVisibleChildCount( const SvListView*,SvTreeListEntry* pParent ) const;
91
94
95 sal_uInt32 GetChildSelectionCount( const SvListView*,SvTreeListEntry* pParent ) const;
96
97 VCL_DLLPRIVATE void SetAbsolutePositions();
98
99 VCL_DLLPRIVATE void CloneChildren(
100 SvTreeListEntries& rDst, sal_uInt32& 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_uInt32& 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
122public:
123
124 SvTreeList() = delete;
126 ~SvTreeList();
127
128 void Broadcast(
129 SvListAction nActionId,
130 SvTreeListEntry* pEntry1=nullptr,
131 SvTreeListEntry* pEntry2=nullptr,
132 sal_uInt32 nPos=0
133 );
134
135 void EnableInvalidate( bool bEnable );
136 bool IsEnableInvalidate() const { return mbEnableInvalidate; }
137
138 // Notify all Listeners
139 void InvalidateEntry( SvTreeListEntry* );
140
141 sal_uInt32 GetEntryCount() const { return nEntryCount; }
142 SvTreeListEntry* First() const;
143 SvTreeListEntry* Next( SvTreeListEntry* pEntry, sal_uInt16* pDepth=nullptr ) const;
144 SvTreeListEntry* Prev( SvTreeListEntry* pEntry ) const;
145 SvTreeListEntry* Last() const;
146
147 SvTreeListEntry* FirstChild( SvTreeListEntry* pParent ) const;
148
149 sal_uInt32 Insert( SvTreeListEntry* pEntry,SvTreeListEntry* pPar,sal_uInt32 nPos = TREELIST_APPEND);
150 sal_uInt32 Insert( SvTreeListEntry* pEntry,sal_uInt32 nRootPos = TREELIST_APPEND )
151 { return Insert(pEntry, pRootItem.get(), nRootPos ); }
152
153 void InsertTree( SvTreeListEntry* pTree, SvTreeListEntry* pTargetParent, sal_uInt32 nListPos );
154
155 // Entries need to be in the same Model!
156 void Move( SvTreeListEntry* pSource, SvTreeListEntry* pTarget );
157
158 // Creates ChildList if needed
159 sal_uInt32 Move( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uInt32 nListPos);
160 sal_uInt32 Copy( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uInt32 nListPos);
161
162 bool Remove( const SvTreeListEntry* pEntry );
163 void Clear();
164
165 bool IsChild(const SvTreeListEntry* pParent, const SvTreeListEntry* pChild) const;
166 SvTreeListEntry* GetEntry( SvTreeListEntry* pParent, sal_uInt32 nPos ) const;
167 SvTreeListEntry* GetEntry( sal_uInt32 nRootPos ) const;
168 SvTreeListEntry* GetEntryAtAbsPos( sal_uInt32 nAbsPos ) const;
169
170 const SvTreeListEntry* GetParent( const SvTreeListEntry* pEntry ) const;
171 SvTreeListEntry* GetParent( SvTreeListEntry* pEntry );
172
173 SvTreeListEntry* GetRootLevelParent( SvTreeListEntry* pEntry ) const;
174 const SvTreeListEntries& GetChildList( SvTreeListEntry* pParent ) const;
175 SvTreeListEntries& GetChildList( SvTreeListEntry* pParent );
176
177 sal_uInt32 GetAbsPos( const SvTreeListEntry* pEntry ) const;
178 static sal_uInt32 GetRelPos( const SvTreeListEntry* pChild );
179
180 sal_uInt32 GetChildCount( const SvTreeListEntry* pParent ) const;
181 sal_uInt16 GetDepth( const SvTreeListEntry* pEntry ) const;
182 bool IsAtRootDepth( const SvTreeListEntry* pEntry ) const;
183
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;
189 { aCloneLink=rLink; }
190
192 { return aCloneLink; }
193
194 SvTreeListEntry* CloneEntry( SvTreeListEntry* pSource ) const; // Calls the Clone Link
195
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();
201};
202
204{
205 friend class SvTreeList;
206
207 struct SAL_DLLPRIVATE Impl;
208 std::unique_ptr<Impl> m_pImpl;
209
210protected:
211 std::unique_ptr<SvTreeList> pModel;
212
213 void ExpandListEntry( SvTreeListEntry* pParent );
214 void CollapseListEntry( SvTreeListEntry* pParent );
215 bool SelectListEntry( SvTreeListEntry* pEntry, bool bSelect );
216
217public:
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
227 );
228
229 sal_uInt32 GetVisibleCount() const
230 { return pModel->GetVisibleCount( const_cast<SvListView*>(this) ); }
231
233 { return pModel->FirstVisible(); }
234
236 { return pModel->NextVisible(this,pEntry); }
237
239 { return pModel->PrevVisible(this,pEntry); }
240
242 { return pModel->LastVisible(this); }
243
244 SvTreeListEntry* NextVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
245 { return pModel->NextVisible(this,pEntry,rDelta); }
246
247 SvTreeListEntry* PrevVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
248 { return pModel->PrevVisible(this,pEntry,rDelta); }
249
250 sal_uInt32 GetSelectionCount() const;
251
253 { return pModel->FirstSelected(this); }
254
256 { return pModel->NextSelected(this,pEntry); }
257
258 SvTreeListEntry* GetEntryAtAbsPos( sal_uInt32 nAbsPos ) const
259 { return pModel->GetEntryAtAbsPos(nAbsPos); }
260
261 SvTreeListEntry* GetEntryAtVisPos( sal_uInt32 nVisPos ) const
262 { return pModel->GetEntryAtVisPos(this,nVisPos); }
263
264 sal_uInt32 GetAbsPos( SvTreeListEntry const * pEntry ) const
265 { return pModel->GetAbsPos(pEntry); }
266
267 sal_uInt32 GetVisiblePos( SvTreeListEntry const * pEntry ) const
268 { return pModel->GetVisiblePos(this,pEntry); }
269
270 sal_uInt32 GetVisibleChildCount(SvTreeListEntry* pParent ) const
271 { return pModel->GetVisibleChildCount(this,pParent); }
272
273 bool IsEntryVisible( SvTreeListEntry* pEntry ) const
274 { return pModel->IsEntryVisible(this,pEntry); }
275
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;
283
284 virtual void InitViewData( SvViewDataEntry*, SvTreeListEntry* pEntry );
285
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 );
294};
295
296/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
friend class SvTreeList
Definition: treelist.hxx:205
sal_uInt32 GetVisiblePos(SvTreeListEntry const *pEntry) const
Definition: treelist.hxx:267
SvTreeListEntry * NextVisible(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:235
SvTreeListEntry * GetEntryAtAbsPos(sal_uInt32 nAbsPos) const
Definition: treelist.hxx:258
SvTreeListEntry * FirstVisible() const
Definition: treelist.hxx:232
SvTreeListEntry * PrevVisible(SvTreeListEntry *pEntry, sal_uInt16 &rDelta) const
Definition: treelist.hxx:247
SvTreeListEntry * PrevVisible(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:238
void Clear()
Definition: treelist.cxx:1084
SvTreeListEntry * NextVisible(SvTreeListEntry *pEntry, sal_uInt16 &rDelta) const
Definition: treelist.hxx:244
std::unique_ptr< SvTreeList > pModel
Definition: treelist.hxx:211
sal_uInt32 GetVisibleCount() const
Definition: treelist.hxx:229
bool IsEntryVisible(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:273
sal_uInt32 GetVisibleChildCount(SvTreeListEntry *pParent) const
Definition: treelist.hxx:270
SvTreeListEntry * NextSelected(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:255
std::unique_ptr< Impl > m_pImpl
Definition: treelist.hxx:208
SvTreeListEntry * LastVisible() const
Definition: treelist.hxx:241
SvTreeListEntry * FirstSelected() const
Definition: treelist.hxx:252
sal_uInt32 GetAbsPos(SvTreeListEntry const *pEntry) const
Definition: treelist.hxx:264
SvTreeListEntry * GetEntryAtVisPos(sal_uInt32 nVisPos) const
Definition: treelist.hxx:261
sal_uInt32 Insert(SvTreeListEntry *pEntry, sal_uInt32 nRootPos=TREELIST_APPEND)
Definition: treelist.hxx:150
SvTreeList()=delete
Link< SvTreeListEntry *, SvTreeListEntry * > aCloneLink
Definition: treelist.hxx:71
void SetSortMode(SvSortMode eMode)
Definition: treelist.hxx:196
sal_uInt32 GetEntryCount() const
Definition: treelist.hxx:141
SvListView & mrOwnerListView
Definition: treelist.hxx:68
std::unique_ptr< SvTreeListEntry > pRootItem
Definition: treelist.hxx:120
const Link< SvTreeListEntry *, SvTreeListEntry * > & GetCloneLink() const
Definition: treelist.hxx:191
Link< const SvSortData &, sal_Int32 > aCompareLink
Definition: treelist.hxx:72
SvTreeListEntry * FirstVisible() const
Definition: treelist.hxx:79
SvTreeList(const SvTreeList &)=delete
bool bAbsPositionsValid
Definition: treelist.hxx:75
void SetCloneLink(const Link< SvTreeListEntry *, SvTreeListEntry * > &rLink)
Definition: treelist.hxx:188
SvSortMode GetSortMode() const
Definition: treelist.hxx:197
sal_uInt32 nEntryCount
Definition: treelist.hxx:69
SvSortMode eSortMode
Definition: treelist.hxx:73
void SetCompareHdl(const Link< const SvSortData &, sal_Int32 > &rLink)
Definition: treelist.hxx:199
bool IsEnableInvalidate() const
Definition: treelist.hxx:136
bool mbEnableInvalidate
Definition: treelist.hxx:77
View-dependent data for a tree list entry created in the virtual function SvTreeListBox::CreateViewDa...
virtual void Insert(SotClipboardFormatId nFormat, const OUString &rFormatName) override
#define VCL_DLLPRIVATE
Definition: dllapi.h:31
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
Mode eMode
void Clear(EHistoryType eHistory)
INSERTED
None
css::uno::Reference< css::animations::XAnimationNode > Clone(const css::uno::Reference< css::animations::XAnimationNode > &xSourceNode, const SdPage *pSource=nullptr, const SdPage *pTarget=nullptr)
void dispose()
size_t GetAbsPos(const weld::TreeView &rTreeView, const weld::TreeIter &rIter)
Definition: builder.cxx:407
bool IsEntryVisible(const weld::TreeView &rTreeView, const weld::TreeIter &rIter)
Definition: builder.cxx:425
const SvTreeListEntry * pLeft
Definition: treelist.hxx:60
const SvTreeListEntry * pRight
Definition: treelist.hxx:61
SvSortMode
Definition: treelist.hxx:53
SvListAction
Definition: treelist.hxx:35
std::vector< std::unique_ptr< SvTreeListEntry > > SvTreeListEntries