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 .
20 #ifndef INCLUDED_VCL_TREELIST_HXX
21 #define INCLUDED_VCL_TREELIST_HXX
23 #include <vcl/dllapi.h>
24 #include <vcl/treelistentries.hxx>
26 #include <tools/solar.h>
27 #include <tools/link.hxx>
28 #include <tools/contnr.hxx>
32 enum class SvListAction
48 class SvTreeListEntry
;
50 class SvViewDataEntry
;
52 enum SvSortMode
{ SortAscending
, SortDescending
, SortNone
};
54 // For the return values of Sortlink:
55 // See International::Compare( pLeft, pRight )
56 // ( Compare(a,b) ==> b.Compare(a) ==> strcmp(a,b) )
59 const SvTreeListEntry
* pLeft
;
60 const SvTreeListEntry
* pRight
;
63 class VCL_DLLPUBLIC SvTreeList final
65 friend class SvListView
;
67 SvListView
& mrOwnerListView
;
68 sal_uLong nEntryCount
;
70 Link
<SvTreeListEntry
*, SvTreeListEntry
*> aCloneLink
;
71 Link
<const SvSortData
&, sal_Int32
> aCompareLink
;
74 bool bAbsPositionsValid
;
76 bool mbEnableInvalidate
;
78 SvTreeListEntry
* FirstVisible() const { return First(); }
79 SvTreeListEntry
* NextVisible( const SvListView
*,SvTreeListEntry
* pEntry
, sal_uInt16
* pDepth
=nullptr ) const;
80 SvTreeListEntry
* PrevVisible( const SvListView
*,SvTreeListEntry
* pEntry
) const;
81 SvTreeListEntry
* LastVisible( const SvListView
* ) const;
82 SvTreeListEntry
* NextVisible( const SvListView
*,SvTreeListEntry
* pEntry
, sal_uInt16
& rDelta
) const;
83 SvTreeListEntry
* PrevVisible( const SvListView
*,SvTreeListEntry
* pEntry
, sal_uInt16
& rDelta
) const;
85 bool IsEntryVisible( const SvListView
*,SvTreeListEntry
* pEntry
) const;
86 SvTreeListEntry
* GetEntryAtVisPos( const SvListView
*,sal_uLong nVisPos
) const;
87 sal_uLong
GetVisiblePos( const SvListView
*,SvTreeListEntry
const * pEntry
) const;
88 sal_uLong
GetVisibleCount( SvListView
* ) const;
89 sal_uLong
GetVisibleChildCount( const SvListView
*,SvTreeListEntry
* pParent
) const;
91 SvTreeListEntry
* FirstSelected( const SvListView
*) const;
92 SvTreeListEntry
* NextSelected( const SvListView
*,SvTreeListEntry
* pEntry
) const;
93 SvTreeListEntry
* PrevSelected( const SvListView
*,SvTreeListEntry
* pEntry
) const;
94 SvTreeListEntry
* LastSelected( const SvListView
*) const;
96 sal_uLong
GetChildSelectionCount( const SvListView
*,SvTreeListEntry
* pParent
) const;
98 VCL_DLLPRIVATE
void SetAbsolutePositions();
100 VCL_DLLPRIVATE
void CloneChildren(
101 SvTreeListEntries
& rDst
, sal_uLong
& rCloneCount
, SvTreeListEntries
& rSrc
, SvTreeListEntry
& rNewParent
) const;
104 * Invalidate the cached position data to have them re-generated before
107 VCL_DLLPRIVATE
static void SetListPositions( SvTreeListEntries
& rEntries
);
109 // rPos is not changed for SortModeNone
110 VCL_DLLPRIVATE
void GetInsertionPos(
111 SvTreeListEntry
const * pEntry
,
112 SvTreeListEntry
* pParent
,
116 VCL_DLLPRIVATE
void ResortChildren( SvTreeListEntry
* pParent
);
117 VCL_DLLPRIVATE
void ReverseChildren( SvTreeListEntry
* pParent
);
119 SvTreeList(const SvTreeList
&) = delete;
120 SvTreeList
& operator= (const SvTreeList
&) = delete;
122 std::unique_ptr
<SvTreeListEntry
> pRootItem
;
126 SvTreeList() = delete;
127 SvTreeList(SvListView
&);
131 SvListAction nActionId
,
132 SvTreeListEntry
* pEntry1
=nullptr,
133 SvTreeListEntry
* pEntry2
=nullptr,
137 void EnableInvalidate( bool bEnable
);
139 // Notify all Listeners
140 void InvalidateEntry( SvTreeListEntry
* );
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;
148 SvTreeListEntry
* FirstChild( SvTreeListEntry
* pParent
) const;
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
); }
154 void InsertTree( SvTreeListEntry
* pTree
, SvTreeListEntry
* pTargetParent
, sal_uLong nListPos
);
156 // Entries need to be in the same Model!
157 void Move( SvTreeListEntry
* pSource
, SvTreeListEntry
* pTarget
);
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
);
163 bool Remove( const SvTreeListEntry
* pEntry
);
166 bool HasChildren( const SvTreeListEntry
* pEntry
) const;
167 bool HasParent( const SvTreeListEntry
* pEntry
) const;
169 bool IsChild(const SvTreeListEntry
* pParent
, const SvTreeListEntry
* pChild
) const;
170 SvTreeListEntry
* GetEntry( SvTreeListEntry
* pParent
, sal_uLong nPos
) const;
171 SvTreeListEntry
* GetEntry( sal_uLong nRootPos
) const;
172 SvTreeListEntry
* GetEntryAtAbsPos( sal_uLong nAbsPos
) const;
174 const SvTreeListEntry
* GetParent( const SvTreeListEntry
* pEntry
) const;
175 SvTreeListEntry
* GetParent( SvTreeListEntry
* pEntry
);
177 SvTreeListEntry
* GetRootLevelParent( SvTreeListEntry
* pEntry
) const;
178 const SvTreeListEntries
& GetChildList( SvTreeListEntry
* pParent
) const;
179 SvTreeListEntries
& GetChildList( SvTreeListEntry
* pParent
);
181 std::pair
<SvTreeListEntries::iterator
, SvTreeListEntries::iterator
>
182 GetChildIterators(SvTreeListEntry
* pParent
);
184 sal_uLong
GetAbsPos( const SvTreeListEntry
* pEntry
) const;
185 static sal_uLong
GetRelPos( const SvTreeListEntry
* pChild
);
187 sal_uLong
GetChildCount( const SvTreeListEntry
* pParent
) const;
188 sal_uInt16
GetDepth( const SvTreeListEntry
* pEntry
) const;
189 bool IsAtRootDepth( const SvTreeListEntry
* pEntry
) const;
191 // The Model calls the Clone Link to clone Entries.
192 // Thus we do not need to derive from the Model if we derive from SvTreeListEntry.
193 // The Handler needs to return a SvTreeListEntry*
194 SvTreeListEntry
* Clone( SvTreeListEntry
* pEntry
, sal_uLong
& nCloneCount
) const;
195 void SetCloneLink( const Link
<SvTreeListEntry
*,SvTreeListEntry
*>& rLink
)
196 { aCloneLink
=rLink
; }
198 const Link
<SvTreeListEntry
*,SvTreeListEntry
*>& GetCloneLink() const
199 { return aCloneLink
; }
201 SvTreeListEntry
* CloneEntry( SvTreeListEntry
* pSource
) const; // Calls the Clone Link
203 void SetSortMode( SvSortMode eMode
) { eSortMode
= eMode
; }
204 SvSortMode
GetSortMode() const { return eSortMode
; }
205 sal_Int32
Compare(const SvTreeListEntry
* pLeft
, const SvTreeListEntry
* pRight
) const;
206 void SetCompareHdl( const Link
<const SvSortData
&, sal_Int32
>& rLink
) { aCompareLink
= rLink
; }
211 class VCL_DLLPUBLIC SvListView
213 friend class SvTreeList
;
216 std::unique_ptr
<Impl
> m_pImpl
;
219 std::unique_ptr
<SvTreeList
> pModel
;
221 void ExpandListEntry( SvTreeListEntry
* pParent
);
222 void CollapseListEntry( SvTreeListEntry
* pParent
);
223 bool SelectListEntry( SvTreeListEntry
* pEntry
, bool bSelect
);
226 SvListView(); // Sets the Model to 0
228 virtual ~SvListView();
230 virtual void ModelNotification(
231 SvListAction nActionId
,
232 SvTreeListEntry
* pEntry1
,
233 SvTreeListEntry
* pEntry2
,
237 sal_uLong
GetVisibleCount() const
238 { return pModel
->GetVisibleCount( const_cast<SvListView
*>(this) ); }
240 SvTreeListEntry
* FirstVisible() const
241 { return pModel
->FirstVisible(); }
243 SvTreeListEntry
* NextVisible( SvTreeListEntry
* pEntry
, sal_uInt16
* pDepth
=nullptr ) const
244 { return pModel
->NextVisible(this,pEntry
,pDepth
); }
246 SvTreeListEntry
* PrevVisible( SvTreeListEntry
* pEntry
) const
247 { return pModel
->PrevVisible(this,pEntry
); }
249 SvTreeListEntry
* LastVisible() const
250 { return pModel
->LastVisible(this); }
252 SvTreeListEntry
* NextVisible( SvTreeListEntry
* pEntry
, sal_uInt16
& rDelta
) const
253 { return pModel
->NextVisible(this,pEntry
,rDelta
); }
255 SvTreeListEntry
* PrevVisible( SvTreeListEntry
* pEntry
, sal_uInt16
& rDelta
) const
256 { return pModel
->PrevVisible(this,pEntry
,rDelta
); }
258 sal_uLong
GetSelectionCount() const;
260 SvTreeListEntry
* FirstSelected() const
261 { return pModel
->FirstSelected(this); }
263 SvTreeListEntry
* NextSelected( SvTreeListEntry
* pEntry
) const
264 { return pModel
->NextSelected(this,pEntry
); }
266 SvTreeListEntry
* PrevSelected( SvTreeListEntry
* pEntry
) const
267 { return pModel
->PrevSelected(this,pEntry
); }
269 SvTreeListEntry
* LastSelected() const
270 { return pModel
->LastSelected(this); }
271 SvTreeListEntry
* GetEntryAtAbsPos( sal_uLong nAbsPos
) const
272 { return pModel
->GetEntryAtAbsPos(nAbsPos
); }
274 SvTreeListEntry
* GetEntryAtVisPos( sal_uLong nVisPos
) const
275 { return pModel
->GetEntryAtVisPos(this,nVisPos
); }
277 sal_uLong
GetAbsPos( SvTreeListEntry
const * pEntry
) const
278 { return pModel
->GetAbsPos(pEntry
); }
280 sal_uLong
GetVisiblePos( SvTreeListEntry
const * pEntry
) const
281 { return pModel
->GetVisiblePos(this,pEntry
); }
283 sal_uLong
GetVisibleChildCount(SvTreeListEntry
* pParent
) const
284 { return pModel
->GetVisibleChildCount(this,pParent
); }
286 sal_uLong
GetChildSelectionCount( SvTreeListEntry
* pParent
) const
287 { return pModel
->GetChildSelectionCount(this,pParent
); }
289 bool IsEntryVisible( SvTreeListEntry
* pEntry
) const
290 { return pModel
->IsEntryVisible(this,pEntry
); }
292 bool IsExpanded( SvTreeListEntry
* pEntry
) const;
293 bool IsSelected( SvTreeListEntry
* pEntry
) const;
294 void SetEntryFocus( SvTreeListEntry
* pEntry
, bool bFocus
);
295 const SvViewDataEntry
* GetViewData( const SvTreeListEntry
* pEntry
) const;
296 SvViewDataEntry
* GetViewData( SvTreeListEntry
* pEntry
);
297 bool HasViewData() const;
299 virtual void InitViewData( SvViewDataEntry
*, SvTreeListEntry
* pEntry
);
301 virtual void ModelHasCleared();
302 virtual void ModelHasInserted( SvTreeListEntry
* pEntry
);
303 virtual void ModelHasInsertedTree( SvTreeListEntry
* pEntry
);
304 virtual void ModelIsMoving(
305 SvTreeListEntry
* pSource
,
306 SvTreeListEntry
* pTargetParent
,
309 virtual void ModelHasMoved( SvTreeListEntry
* pSource
);
310 virtual void ModelIsRemoving( SvTreeListEntry
* pEntry
);
311 virtual void ModelHasRemoved( SvTreeListEntry
* pEntry
);
312 virtual void ModelHasEntryInvalidated( SvTreeListEntry
* pEntry
);
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */