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 const SvTreeListEntries& GetChildList( SvTreeListEntry* pParent ) const;
174 SvTreeListEntries& GetChildList( SvTreeListEntry* pParent );
175
176 sal_uInt32 GetAbsPos( const SvTreeListEntry* pEntry ) const;
177 static sal_uInt32 GetRelPos( const SvTreeListEntry* pChild );
178
179 sal_uInt32 GetChildCount( const SvTreeListEntry* pParent ) const;
180 sal_uInt16 GetDepth( const SvTreeListEntry* pEntry ) const;
181 bool IsAtRootDepth( const SvTreeListEntry* pEntry ) const;
182
183 // The Model calls the Clone Link to clone Entries.
184 // Thus we do not need to derive from the Model if we derive from SvTreeListEntry.
185 // The Handler needs to return a SvTreeListEntry*
186 SvTreeListEntry* Clone( SvTreeListEntry* pEntry, sal_uInt32& nCloneCount ) const;
188 { aCloneLink=rLink; }
189
191 { return aCloneLink; }
192
193 SvTreeListEntry* CloneEntry( SvTreeListEntry* pSource ) const; // Calls the Clone Link
194
195 void SetSortMode( SvSortMode eMode ) { eSortMode = eMode; }
196 SvSortMode GetSortMode() const { return eSortMode; }
197 sal_Int32 Compare(const SvTreeListEntry* pLeft, const SvTreeListEntry* pRight) const;
198 void SetCompareHdl( const Link<const SvSortData&, sal_Int32>& rLink ) { aCompareLink = rLink; }
199 void Resort();
200};
201
203{
204 friend class SvTreeList;
205
206 struct SAL_DLLPRIVATE Impl;
207 std::unique_ptr<Impl> m_pImpl;
208
209protected:
210 std::unique_ptr<SvTreeList> pModel;
211
212 void ExpandListEntry( SvTreeListEntry* pParent );
213 void CollapseListEntry( SvTreeListEntry* pParent );
214 bool SelectListEntry( SvTreeListEntry* pEntry, bool bSelect );
215
216public:
217 SvListView(); // Sets the Model to 0
218 void dispose();
219 virtual ~SvListView();
220 void Clear();
221 virtual void ModelNotification(
222 SvListAction nActionId,
223 SvTreeListEntry* pEntry1,
224 SvTreeListEntry* pEntry2,
225 sal_uInt32 nPos
226 );
227
228 sal_uInt32 GetVisibleCount() const
229 { return pModel->GetVisibleCount( const_cast<SvListView*>(this) ); }
230
232 { return pModel->FirstVisible(); }
233
235 { return pModel->NextVisible(this,pEntry); }
236
238 { return pModel->PrevVisible(this,pEntry); }
239
241 { return pModel->LastVisible(this); }
242
243 SvTreeListEntry* NextVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
244 { return pModel->NextVisible(this,pEntry,rDelta); }
245
246 SvTreeListEntry* PrevVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const
247 { return pModel->PrevVisible(this,pEntry,rDelta); }
248
249 sal_uInt32 GetSelectionCount() const;
250
252 { return pModel->FirstSelected(this); }
253
255 { return pModel->NextSelected(this,pEntry); }
256
257 SvTreeListEntry* GetEntryAtAbsPos( sal_uInt32 nAbsPos ) const
258 { return pModel->GetEntryAtAbsPos(nAbsPos); }
259
260 SvTreeListEntry* GetEntryAtVisPos( sal_uInt32 nVisPos ) const
261 { return pModel->GetEntryAtVisPos(this,nVisPos); }
262
263 sal_uInt32 GetAbsPos( SvTreeListEntry const * pEntry ) const
264 { return pModel->GetAbsPos(pEntry); }
265
266 sal_uInt32 GetVisiblePos( SvTreeListEntry const * pEntry ) const
267 { return pModel->GetVisiblePos(this,pEntry); }
268
269 sal_uInt32 GetVisibleChildCount(SvTreeListEntry* pParent ) const
270 { return pModel->GetVisibleChildCount(this,pParent); }
271
272 bool IsEntryVisible( SvTreeListEntry* pEntry ) const
273 { return pModel->IsEntryVisible(this,pEntry); }
274
275 bool IsExpanded( SvTreeListEntry* pEntry ) const;
276 bool IsAllExpanded( SvTreeListEntry* pEntry) const;
277 bool IsSelected(const SvTreeListEntry* pEntry) const;
278 void SetEntryFocus( SvTreeListEntry* pEntry, bool bFocus );
279 const SvViewDataEntry* GetViewData( const SvTreeListEntry* pEntry ) const;
280 SvViewDataEntry* GetViewData( SvTreeListEntry* pEntry );
281 bool HasViewData() const;
282
283 virtual void InitViewData( SvViewDataEntry*, SvTreeListEntry* pEntry );
284
285 virtual void ModelHasCleared();
286 virtual void ModelHasInserted( SvTreeListEntry* pEntry );
287 virtual void ModelHasInsertedTree( SvTreeListEntry* pEntry );
288 virtual void ModelIsMoving( SvTreeListEntry* pSource );
289 virtual void ModelHasMoved( SvTreeListEntry* pSource );
290 virtual void ModelIsRemoving( SvTreeListEntry* pEntry );
291 virtual void ModelHasRemoved( SvTreeListEntry* pEntry );
292 virtual void ModelHasEntryInvalidated( SvTreeListEntry* pEntry );
293};
294
295/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
friend class SvTreeList
Definition: treelist.hxx:204
sal_uInt32 GetVisiblePos(SvTreeListEntry const *pEntry) const
Definition: treelist.hxx:266
SvTreeListEntry * NextVisible(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:234
SvTreeListEntry * GetEntryAtAbsPos(sal_uInt32 nAbsPos) const
Definition: treelist.hxx:257
SvTreeListEntry * FirstVisible() const
Definition: treelist.hxx:231
SvTreeListEntry * PrevVisible(SvTreeListEntry *pEntry, sal_uInt16 &rDelta) const
Definition: treelist.hxx:246
SvTreeListEntry * PrevVisible(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:237
void Clear()
Definition: treelist.cxx:1069
SvTreeListEntry * NextVisible(SvTreeListEntry *pEntry, sal_uInt16 &rDelta) const
Definition: treelist.hxx:243
std::unique_ptr< SvTreeList > pModel
Definition: treelist.hxx:210
sal_uInt32 GetVisibleCount() const
Definition: treelist.hxx:228
bool IsEntryVisible(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:272
sal_uInt32 GetVisibleChildCount(SvTreeListEntry *pParent) const
Definition: treelist.hxx:269
SvTreeListEntry * NextSelected(SvTreeListEntry *pEntry) const
Definition: treelist.hxx:254
std::unique_ptr< Impl > m_pImpl
Definition: treelist.hxx:207
SvTreeListEntry * LastVisible() const
Definition: treelist.hxx:240
SvTreeListEntry * FirstSelected() const
Definition: treelist.hxx:251
sal_uInt32 GetAbsPos(SvTreeListEntry const *pEntry) const
Definition: treelist.hxx:263
SvTreeListEntry * GetEntryAtVisPos(sal_uInt32 nVisPos) const
Definition: treelist.hxx:260
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:195
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:190
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:187
SvSortMode GetSortMode() const
Definition: treelist.hxx:196
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:198
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:408
bool IsEntryVisible(const weld::TreeView &rTreeView, const weld::TreeIter &rIter)
Definition: builder.cxx:426
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