1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
23 #error "don't use this in new code"
26 #include <vcl/dllapi.h>
27 #include <vcl/toolkit/treelistentries.hxx>
29 #include <tools/link.hxx>
30 #include <tools/contnr.hxx>
34 enum class SvListAction
49 class SvTreeListEntry
;
51 class SvViewDataEntry
;
53 enum class SvSortMode
{ Ascending
, Descending
, None
};
55 // For the return values of Sortlink:
56 // See International::Compare( pLeft, pRight )
57 // ( Compare(a,b) ==> b.Compare(a) ==> strcmp(a,b) )
60 const SvTreeListEntry
* pLeft
;
61 const SvTreeListEntry
* pRight
;
64 class VCL_DLLPUBLIC SvTreeList final
66 friend class SvListView
;
68 SvListView
& mrOwnerListView
;
69 sal_uInt32 nEntryCount
;
71 Link
<SvTreeListEntry
*, SvTreeListEntry
*> aCloneLink
;
72 Link
<const SvSortData
&, sal_Int32
> aCompareLink
;
75 bool bAbsPositionsValid
;
77 bool mbEnableInvalidate
;
79 SvTreeListEntry
* FirstVisible() const { return First(); }
80 SvTreeListEntry
* NextVisible( const SvListView
*,SvTreeListEntry
* pEntry
, sal_uInt16
* pDepth
=nullptr ) const;
81 SvTreeListEntry
* PrevVisible( const SvListView
*,SvTreeListEntry
* pEntry
) 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;
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;
92 SvTreeListEntry
* FirstSelected( const SvListView
*) const;
93 SvTreeListEntry
* NextSelected( const SvListView
*,SvTreeListEntry
* pEntry
) const;
95 sal_uInt32
GetChildSelectionCount( const SvListView
*,SvTreeListEntry
* pParent
) const;
97 VCL_DLLPRIVATE
void SetAbsolutePositions();
99 VCL_DLLPRIVATE
void CloneChildren(
100 SvTreeListEntries
& rDst
, sal_uInt32
& rCloneCount
, SvTreeListEntries
& rSrc
, SvTreeListEntry
& rNewParent
) const;
103 * Invalidate the cached position data to have them re-generated before
106 VCL_DLLPRIVATE
static void SetListPositions( SvTreeListEntries
& rEntries
);
108 // rPos is not changed for SortModeNone
109 VCL_DLLPRIVATE
void GetInsertionPos(
110 SvTreeListEntry
const * pEntry
,
111 SvTreeListEntry
* pParent
,
115 VCL_DLLPRIVATE
void ResortChildren( SvTreeListEntry
* pParent
);
117 SvTreeList(const SvTreeList
&) = delete;
118 SvTreeList
& operator= (const SvTreeList
&) = delete;
120 std::unique_ptr
<SvTreeListEntry
> pRootItem
;
124 SvTreeList() = delete;
125 SvTreeList(SvListView
&);
129 SvListAction nActionId
,
130 SvTreeListEntry
* pEntry1
=nullptr,
131 SvTreeListEntry
* pEntry2
=nullptr,
135 void EnableInvalidate( bool bEnable
);
136 bool IsEnableInvalidate() const { return mbEnableInvalidate
; }
138 // Notify all Listeners
139 void InvalidateEntry( SvTreeListEntry
* );
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;
147 SvTreeListEntry
* FirstChild( SvTreeListEntry
* pParent
) const;
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
); }
153 void InsertTree( SvTreeListEntry
* pTree
, SvTreeListEntry
* pTargetParent
, sal_uInt32 nListPos
);
155 // Entries need to be in the same Model!
156 void Move( SvTreeListEntry
* pSource
, SvTreeListEntry
* pTarget
);
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
);
162 bool Remove( const SvTreeListEntry
* pEntry
);
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;
170 const SvTreeListEntry
* GetParent( const SvTreeListEntry
* pEntry
) const;
171 SvTreeListEntry
* GetParent( SvTreeListEntry
* pEntry
);
173 const SvTreeListEntries
& GetChildList( SvTreeListEntry
* pParent
) const;
174 SvTreeListEntries
& GetChildList( SvTreeListEntry
* pParent
);
176 sal_uInt32
GetAbsPos( const SvTreeListEntry
* pEntry
) const;
177 static sal_uInt32
GetRelPos( const SvTreeListEntry
* pChild
);
179 sal_uInt32
GetChildCount( const SvTreeListEntry
* pParent
) const;
180 sal_uInt16
GetDepth( const SvTreeListEntry
* pEntry
) const;
181 bool IsAtRootDepth( const SvTreeListEntry
* pEntry
) const;
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;
187 void SetCloneLink( const Link
<SvTreeListEntry
*,SvTreeListEntry
*>& rLink
)
188 { aCloneLink
=rLink
; }
190 const Link
<SvTreeListEntry
*,SvTreeListEntry
*>& GetCloneLink() const
191 { return aCloneLink
; }
193 SvTreeListEntry
* CloneEntry( SvTreeListEntry
* pSource
) const; // Calls the Clone Link
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
; }
202 class VCL_DLLPUBLIC SvListView
204 friend class SvTreeList
;
206 struct SAL_DLLPRIVATE Impl
;
207 std::unique_ptr
<Impl
> m_pImpl
;
210 std::unique_ptr
<SvTreeList
> pModel
;
212 void ExpandListEntry( SvTreeListEntry
* pParent
);
213 void CollapseListEntry( SvTreeListEntry
* pParent
);
214 bool SelectListEntry( SvTreeListEntry
* pEntry
, bool bSelect
);
217 SvListView(); // Sets the Model to 0
219 virtual ~SvListView();
221 virtual void ModelNotification(
222 SvListAction nActionId
,
223 SvTreeListEntry
* pEntry1
,
224 SvTreeListEntry
* pEntry2
,
228 sal_uInt32
GetVisibleCount() const
229 { return pModel
->GetVisibleCount( const_cast<SvListView
*>(this) ); }
231 SvTreeListEntry
* FirstVisible() const
232 { return pModel
->FirstVisible(); }
234 SvTreeListEntry
* NextVisible( SvTreeListEntry
* pEntry
) const
235 { return pModel
->NextVisible(this,pEntry
); }
237 SvTreeListEntry
* PrevVisible( SvTreeListEntry
* pEntry
) const
238 { return pModel
->PrevVisible(this,pEntry
); }
240 SvTreeListEntry
* LastVisible() const
241 { return pModel
->LastVisible(this); }
243 SvTreeListEntry
* NextVisible( SvTreeListEntry
* pEntry
, sal_uInt16
& rDelta
) const
244 { return pModel
->NextVisible(this,pEntry
,rDelta
); }
246 SvTreeListEntry
* PrevVisible( SvTreeListEntry
* pEntry
, sal_uInt16
& rDelta
) const
247 { return pModel
->PrevVisible(this,pEntry
,rDelta
); }
249 sal_uInt32
GetSelectionCount() const;
251 SvTreeListEntry
* FirstSelected() const
252 { return pModel
->FirstSelected(this); }
254 SvTreeListEntry
* NextSelected( SvTreeListEntry
* pEntry
) const
255 { return pModel
->NextSelected(this,pEntry
); }
257 SvTreeListEntry
* GetEntryAtAbsPos( sal_uInt32 nAbsPos
) const
258 { return pModel
->GetEntryAtAbsPos(nAbsPos
); }
260 SvTreeListEntry
* GetEntryAtVisPos( sal_uInt32 nVisPos
) const
261 { return pModel
->GetEntryAtVisPos(this,nVisPos
); }
263 sal_uInt32
GetAbsPos( SvTreeListEntry
const * pEntry
) const
264 { return pModel
->GetAbsPos(pEntry
); }
266 sal_uInt32
GetVisiblePos( SvTreeListEntry
const * pEntry
) const
267 { return pModel
->GetVisiblePos(this,pEntry
); }
269 sal_uInt32
GetVisibleChildCount(SvTreeListEntry
* pParent
) const
270 { return pModel
->GetVisibleChildCount(this,pParent
); }
272 bool IsEntryVisible( SvTreeListEntry
* pEntry
) const
273 { return pModel
->IsEntryVisible(this,pEntry
); }
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;
283 virtual void InitViewData( SvViewDataEntry
*, SvTreeListEntry
* pEntry
);
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
);
295 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */