xref: /aoo42x/main/svtools/inc/svtools/treelist.hxx (revision cf948285)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SVTREELIST_HXX
25 #define _SVTREELIST_HXX
26 
27 #include "svtools/svtdllapi.h"
28 #include <tools/solar.h>
29 #include <tools/list.hxx>
30 
31 #ifndef _TABLE_HXX
32 #include <tools/table.hxx>
33 #endif
34 #include <tools/link.hxx>
35 #include <tools/string.hxx>
36 #include <tools/debug.hxx>
37 
38 #define LISTACTION_INSERTED			1
39 #define LISTACTION_REMOVING         2
40 #define LISTACTION_REMOVED          3
41 #define LISTACTION_MOVING			4
42 #define LISTACTION_MOVED			5
43 #define LISTACTION_CLEARING 		6
44 #define LISTACTION_INSERTED_TREE	7
45 #define LISTACTION_INVALIDATE_ENTRY	8
46 #define LISTACTION_RESORTING		9
47 #define LISTACTION_RESORTED			10
48 #define LISTACTION_CLEARED			11
49 
50 #define SV_TREELIST_ROOT_ENTRY  (SvListEntry*)0
51 #define SV_TREELIST_ERROR		 0xFFFFFFFF
52 
53 // Entryflags, die an der View haengen
54 #define SVLISTENTRYFLAG_SELECTED		0x0001
55 #define SVLISTENTRYFLAG_EXPANDED		0x0002
56 #define SVLISTENTRYFLAG_FOCUSED			0x0004
57 #define SVLISTENTRYFLAG_CURSORED		0x0008
58 #define SVLISTENTRYFLAG_NOT_SELECTABLE	0x0010
59 // IAccessible2 implementation
60 #define SVLISTENTRYFLAG_OBJSELECTED	0x0040
61 
62 class SvListEntry;
63 
64 class SvTreeEntryList : public List // SvEntryListStd
65 {
66 public:
SvTreeEntryList(sal_uInt16 nInitPos=16,sal_uInt16 nResize=16)67 	SvTreeEntryList(sal_uInt16 nInitPos=16, sal_uInt16 nResize=16 )
68 			: List( nInitPos, nResize )
69 	{}
SvTreeEntryList(sal_uInt16 BlockSize,sal_uInt16 InitSize,sal_uInt16 Resize)70 	SvTreeEntryList(sal_uInt16 BlockSize, sal_uInt16 InitSize, sal_uInt16 Resize )
71 		: List(BlockSize, InitSize, Resize )
72 	{}
73 
74 	void DestroyAll();
75 };
76 
77 class SVT_DLLPUBLIC SvListEntry
78 {
79 friend class SvTreeList;
80 friend class SvListView;
81 
82 private:
83 	SvListEntry*		pParent;
84 	SvTreeEntryList*	pChilds;
85 	sal_uLong				nAbsPos;
86 	sal_uLong				nListPos;
87 
88 	void				SetListPositions();
InvalidateChildrensListPositions()89 	void				InvalidateChildrensListPositions()
90 						{
91 							nListPos |= 0x80000000;
92 						}
93 public:
94 						SvListEntry();
95 						SvListEntry( const SvListEntry& );
96 	virtual				~SvListEntry();
HasChilds()97 	sal_Bool				HasChilds() { return (sal_Bool)(pChilds!=0); }
HasChildListPos() const98 	sal_Bool				HasChildListPos() const
99 	{
100 		if( pParent && !(pParent->nListPos & 0x80000000) )
101 			return sal_True;
102 		else return sal_False;
103 	}
GetChildListPos() const104 	sal_uLong				GetChildListPos() const
105 	{
106 		if( pParent && (pParent->nListPos & 0x80000000) )
107 			pParent->SetListPositions();
108 		return ( nListPos & 0x7fffffff );
109 	}
110 	virtual void 		Clone( SvListEntry* pSource );
111 };
112 
113 class SvListView;
114 
115 class SvViewData
116 {
117 friend class SvTreeList;
118 friend class SvListView;
119 
120 	sal_uLong		nVisPos;
121 protected:
122 	sal_uInt16 		nFlags;
123 public:
124 	SvViewData();
125 	SvViewData( const SvViewData& );
126 	virtual ~SvViewData();
127 
IsSelected() const128 	sal_Bool IsSelected() const { return (sal_Bool)(nFlags&SVLISTENTRYFLAG_SELECTED)!=0; }
IsExpanded() const129 	sal_Bool IsExpanded() const { return (sal_Bool)(nFlags&SVLISTENTRYFLAG_EXPANDED)!=0; }
HasFocus() const130 	sal_Bool HasFocus() const { return (sal_Bool)(nFlags&SVLISTENTRYFLAG_FOCUSED)!=0; }
SetFocus(sal_Bool bFocus)131 	void SetFocus( sal_Bool bFocus)
132 	{
133 		if ( !bFocus )
134 			nFlags &= (~SVLISTENTRYFLAG_FOCUSED);
135 		else
136 			nFlags |= SVLISTENTRYFLAG_FOCUSED;
137 	}
IsCursored() const138 	sal_Bool IsCursored() const { return (sal_Bool)(nFlags&SVLISTENTRYFLAG_CURSORED)!=0; }
SetCursored(sal_Bool bCursored)139 	void SetCursored( sal_Bool bCursored )
140 	{
141 		if ( !bCursored )
142 			nFlags &= (~SVLISTENTRYFLAG_CURSORED);
143 		else
144 			nFlags |= SVLISTENTRYFLAG_CURSORED;
145 	}
146 
GetFlags() const147 	sal_uInt16 GetFlags() const { return nFlags; }
148 
SetSelectable(bool bSelectable)149 	void SetSelectable( bool bSelectable )
150 	{
151 		if( bSelectable )
152 			nFlags &= (~SVLISTENTRYFLAG_NOT_SELECTABLE);
153 		else
154 			nFlags |= SVLISTENTRYFLAG_NOT_SELECTABLE;
155 	}
IsSelectable() const156 	bool IsSelectable() const { return (bool)(nFlags&SVLISTENTRYFLAG_NOT_SELECTABLE)==0; }
157 	// IAccessible2 implementation
SetObjectSelected(sal_Bool bSelected)158 	void SetObjectSelected(sal_Bool bSelected)
159 	{
160 	if ( !bSelected )
161 		nFlags &= (~SVLISTENTRYFLAG_OBJSELECTED);
162 	else
163 		nFlags |= SVLISTENTRYFLAG_OBJSELECTED;
164 	}
165 };
166 
167 enum SvSortMode { SortAscending, SortDescending, SortNone };
168 
169 // Rueckgabewerte Sortlink:
170 // siehe International::Compare( pLeft, pRight )
171 // ( Compare(a,b) ==> b.Compare(a) ==> strcmp(a,b) )
172 struct SvSortData
173 {
174 	SvListEntry* pLeft;
175 	SvListEntry* pRight;
176 };
177 
178 class SVT_DLLPUBLIC SvTreeList
179 {
180 	friend class SvListView;
181 
182 	List			aViewList;
183 	sal_uLong           nEntryCount;
184 
185 	Link			aCloneLink;
186 	Link			aCompareLink;
187 	SvSortMode		eSortMode;
188 
189 	sal_uInt16			nRefCount;
190 
191 	sal_Bool			bAbsPositionsValid;
192 
FirstVisible() const193 	SvListEntry*    FirstVisible() const { return First(); }
194 	SvListEntry*    NextVisible( const SvListView*,SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
195 	SvListEntry*	PrevVisible( const SvListView*,SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
196 	SvListEntry*	LastVisible( const SvListView*,sal_uInt16* pDepth=0 ) const;
197 	SvListEntry*	NextVisible( const SvListView*,SvListEntry* pEntry, sal_uInt16& rDelta ) const;
198 	SvListEntry*	PrevVisible( const SvListView*,SvListEntry* pEntry, sal_uInt16& rDelta ) const;
199 
200 	sal_Bool			IsEntryVisible( const SvListView*,SvListEntry* pEntry ) const;
201 	SvListEntry*	GetEntryAtVisPos( const SvListView*,sal_uLong nVisPos ) const;
202 	sal_uLong			GetVisiblePos( const SvListView*,SvListEntry* pEntry ) const;
203 	sal_uLong			GetVisibleCount( const SvListView* ) const;
204 	sal_uLong			GetVisibleChildCount( const SvListView*,SvListEntry* pParent ) const;
205 
206 	SvListEntry*    FirstSelected( const SvListView*) const;
207 	SvListEntry*    NextSelected( const SvListView*,SvListEntry* pEntry ) const;
208 	SvListEntry*	PrevSelected( const SvListView*,SvListEntry* pEntry ) const;
209 	SvListEntry*	LastSelected( const SvListView*) const;
210 
211 	sal_Bool            Select( SvListView*,SvListEntry* pEntry, sal_Bool bSelect=sal_True );
212 	sal_uLong			SelectChilds( SvListView*,SvListEntry* pParent, sal_Bool bSelect );
213 	void			SelectAll( SvListView*,sal_Bool bSelect ); // ruft nicht Select-Hdl
214 	sal_uLong			GetChildSelectionCount( const SvListView*,SvListEntry* pParent ) const;
215 
216 	void            Expand( SvListView*,SvListEntry* pParent );
217 	void            Collapse( SvListView*,SvListEntry* pParent );
218 
219 //#if 0 // _SOLAR__PRIVATE
220 	SVT_DLLPRIVATE void 			SetAbsolutePositions();
221 	SVT_DLLPRIVATE SvTreeEntryList*CloneChilds( SvTreeEntryList* pChilds,
222 								 SvListEntry* pNewParent,
223 								 sal_uLong& nCloneCount ) const;
224 	SVT_DLLPRIVATE void			SetListPositions( SvTreeEntryList* );
225 
226 	// rPos wird bei SortModeNone nicht geaendert
227 	SVT_DLLPRIVATE void			GetInsertionPos( SvListEntry* pEntry, SvListEntry* pParent,
228 						sal_uLong& rPos );
229 	SVT_DLLPRIVATE void			ResortChilds( SvListEntry* pParent );
230 //#endif /* _SOLAR__PRIVATE */
231 
232 protected:
233 
234 	SvListEntry*      pRootItem;
235 
236 public:
237 
238 	SvTreeList();
239 	virtual ~SvTreeList();
240 
241 	void			InsertView( SvListView* );
242 	void			RemoveView( SvListView* );
GetViewCount() const243 	sal_uLong			GetViewCount() const { return aViewList.Count(); }
GetView(sal_uLong nPos) const244 	SvListView*		GetView(sal_uLong nPos) const {return (SvListView*)aViewList.GetObject(nPos);}
245 	void			Broadcast( sal_uInt16 nActionId, SvListEntry* pEntry1=0,
246 						SvListEntry* pEntry2=0, sal_uLong nPos=0 );
247 	// informiert alle Listener
248 	void			InvalidateEntry( SvListEntry* );
249 
GetEntryCount() const250 	sal_uLong			GetEntryCount() const { return nEntryCount; }
251 	SvListEntry*    First() const;
252 	SvListEntry*    Next( SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
253 	SvListEntry*	Prev( SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
254 	SvListEntry*	Last( sal_uInt16* pDepth=0 ) const;
255 
256 	SvListEntry*	FirstChild( SvListEntry* pParent ) const;
257 	SvListEntry*	NextSibling( SvListEntry* pEntry ) const;
258 	SvListEntry*	PrevSibling( SvListEntry* pEntry ) const;
259 	SvListEntry*	LastSibling( SvListEntry* pEntry ) const;
260 
261 	sal_uLong			Insert( SvListEntry* pEntry,SvListEntry* pPar,sal_uLong nPos=LIST_APPEND);
Insert(SvListEntry * pEntry,sal_uLong nRootPos=LIST_APPEND)262 	sal_uLong			Insert( SvListEntry* pEntry,sal_uLong nRootPos = LIST_APPEND ) { return Insert(pEntry, pRootItem, nRootPos ); }
263 	void			InsertTree( SvListEntry* pTree, SvListEntry* pTarget );
264 	void			InsertTree( SvListEntry* pTree, SvListEntry* pTargetParent,
265 								sal_uLong nListPos );
266 	// Entries muessen im gleichen Model stehen!
267 	void            Move( SvListEntry* pSource, SvListEntry* pTarget );
268 	// erzeugt ggf. Child-List
269 	sal_uLong   		Move( SvListEntry* pSource, SvListEntry* pTargetParent,
270 						  sal_uLong nListPos);
271 	void			Copy( SvListEntry* pSource, SvListEntry* pTarget );
272 	sal_uLong   		Copy( SvListEntry* pSource, SvListEntry* pTargetParent,
273 						  sal_uLong nListPos);
274 
275 	sal_Bool            Remove( SvListEntry* pEntry );
276 	void            Clear();
277 
278 	sal_Bool			HasChilds( SvListEntry* pEntry ) const;
HasParent(SvListEntry * pEntry) const279 	sal_Bool			HasParent( SvListEntry* pEntry ) const 	{ return (sal_Bool)(pEntry->pParent!=pRootItem); }
280 	sal_Bool			IsChild( SvListEntry* pParent, SvListEntry* pChild ) const;
281 	sal_Bool			IsInChildList( SvListEntry* pParent, SvListEntry* pChild) const;
282 	SvListEntry*	GetEntry( SvListEntry* pParent, sal_uLong nPos ) const;
283 	SvListEntry*	GetEntry( sal_uLong nRootPos ) const;
284 	SvListEntry*	GetEntryAtAbsPos( sal_uLong nAbsPos ) const;
285 	SvListEntry*	GetParent( SvListEntry* pEntry ) const;
286 	SvListEntry*	GetRootLevelParent( SvListEntry* pEntry ) const;
287 	SvTreeEntryList* GetChildList( SvListEntry* pParent ) const;
288 
289 	sal_uLong			GetAbsPos( SvListEntry* pEntry ) const;
GetRelPos(SvListEntry * pChild) const290 	sal_uLong			GetRelPos( SvListEntry* pChild ) const { return pChild->GetChildListPos(); }
291 	sal_uLong			GetChildCount( SvListEntry* pParent ) const;
292 	sal_uInt16          GetDepth( SvListEntry* pEntry ) const;
IsAtRootDepth(SvListEntry * pEntry) const293 	sal_Bool			IsAtRootDepth( SvListEntry* pEntry ) const { return (sal_Bool)(pEntry->pParent==pRootItem); }
294 
295 	// das Model ruft zum Clonen von Entries den Clone-Link auf,
296 	// damit man sich nicht vom Model ableiten muss, wenn man
297 	// sich von SvListEntry ableitet.
298 	// Deklaration des Clone-Handlers:
299 	// DECL_LINK(CloneHdl,SvListEntry*);
300 	// der Handler muss einen SvListEntry* zurueckgeben
301 	SvListEntry*	Clone( SvListEntry* pEntry, sal_uLong& nCloneCount ) const;
SetCloneLink(const Link & rLink)302 	void			SetCloneLink( const Link& rLink ) { aCloneLink=rLink; }
GetCloneLink() const303 	const Link&		GetCloneLink() const { return aCloneLink; }
304 	virtual SvListEntry* CloneEntry( SvListEntry* ) const; // ruft den Clone-Link
305 	virtual SvListEntry* CreateEntry() const; // zum 'new'en von Entries
306 
GetRefCount() const307 	sal_uInt16			GetRefCount() const { return nRefCount; }
SetRefCount(sal_uInt16 nRef)308 	void			SetRefCount( sal_uInt16 nRef ) { nRefCount = nRef; }
309 
SetSortMode(SvSortMode eMode)310 	void			SetSortMode( SvSortMode eMode ) { eSortMode = eMode; }
GetSortMode() const311 	SvSortMode		GetSortMode() const { return eSortMode; }
312 	virtual StringCompare Compare( SvListEntry*, SvListEntry* ) const;
SetCompareHdl(const Link & rLink)313 	void			SetCompareHdl( const Link& rLink ) { aCompareLink = rLink; }
GetCompareHdl() const314 	const Link& 	GetCompareHdl() const { return aCompareLink; }
315 	void			Resort();
316 
317 	void			CheckIntegrity() const;
318 };
319 
320 class SVT_DLLPUBLIC SvListView
321 {
322 	friend class SvTreeList;
323 
324 	sal_uLong           nVisibleCount;
325 	sal_uLong			nSelectionCount;
326 	sal_Bool            bVisPositionsValid;
327 
328 //#if 0 // _SOLAR__PRIVATE
329 	SVT_DLLPRIVATE void			InitTable();
330 	SVT_DLLPRIVATE void			ClearTable();
331 	SVT_DLLPRIVATE void			RemoveViewData( SvListEntry* pParent );
332 //#endif
333 
334 protected:
335 	Table			aDataTable;  // Mapping SvListEntry -> ViewData
336 	SvTreeList*		pModel;
337 
338 	void ActionMoving( SvListEntry* pEntry,SvListEntry* pTargetPrnt,sal_uLong nChildPos);
339 	void ActionMoved( SvListEntry* pEntry,SvListEntry* pTargetPrnt,sal_uLong nChildPos);
340 	void ActionInserted( SvListEntry* pEntry );
341 	void ActionInsertedTree( SvListEntry* pEntry );
342 	void ActionRemoving( SvListEntry* pEntry );
343 	void ActionRemoved( SvListEntry* pEntry );
344 	void ActionClear();
345 
346 public:
347 
348 	SvListView();   // !!! setzt das Model auf 0
349 	SvListView( SvTreeList* pModel );
350 	virtual ~SvListView();
351 	void            Clear();
GetModel() const352 	SvTreeList*		GetModel() const { return pModel; }
353 	virtual void	SetModel( SvTreeList* );
354 	virtual void	ModelNotification( sal_uInt16 nActionId, SvListEntry* pEntry1,
355 						SvListEntry* pEntry2, sal_uLong nPos );
356 
GetVisibleCount() const357 	sal_uLong			GetVisibleCount() const { return pModel->GetVisibleCount( (SvListView*)this );}
FirstVisible() const358 	SvListEntry*    FirstVisible() const { return pModel->FirstVisible(); }
NextVisible(SvListEntry * pEntry,sal_uInt16 * pDepth=0) const359 	SvListEntry*    NextVisible( SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const {return pModel->NextVisible(this,pEntry,pDepth); }
PrevVisible(SvListEntry * pEntry,sal_uInt16 * pDepth=0) const360 	SvListEntry*	PrevVisible( SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const {return pModel->PrevVisible(this,pEntry,pDepth); }
LastVisible(sal_uInt16 * pDepth=0) const361 	SvListEntry*	LastVisible( sal_uInt16* pDepth=0 ) const { return pModel->LastVisible(this,pDepth);}
NextVisible(SvListEntry * pEntry,sal_uInt16 & rDelta) const362 	SvListEntry*	NextVisible( SvListEntry* pEntry, sal_uInt16& rDelta ) const { return pModel->NextVisible(this,pEntry,rDelta); }
PrevVisible(SvListEntry * pEntry,sal_uInt16 & rDelta) const363 	SvListEntry*	PrevVisible( SvListEntry* pEntry, sal_uInt16& rDelta ) const { return pModel->PrevVisible(this,pEntry,rDelta); }
364 
GetSelectionCount() const365 	sal_uLong           GetSelectionCount() const { return nSelectionCount; }
FirstSelected() const366 	SvListEntry*	FirstSelected() const { return pModel->FirstSelected(this);}
NextSelected(SvListEntry * pEntry) const367 	SvListEntry*    NextSelected( SvListEntry* pEntry ) const { return pModel->NextSelected(this,pEntry); }
PrevSelected(SvListEntry * pEntry) const368 	SvListEntry*	PrevSelected( SvListEntry* pEntry ) const { return pModel->PrevSelected(this,pEntry); }
LastSelected() const369 	SvListEntry*	LastSelected() const { return pModel->LastSelected(this); }
GetEntryAtVisPos(sal_uLong nVisPos) const370 	SvListEntry*	GetEntryAtVisPos( sal_uLong nVisPos ) const { return pModel->GetEntryAtVisPos((SvListView*)this,nVisPos); }
GetVisiblePos(SvListEntry * pEntry) const371 	sal_uLong			GetVisiblePos( SvListEntry* pEntry ) const { return pModel->GetVisiblePos((SvListView*)this,pEntry); }
372 
GetVisibleChildCount(SvListEntry * pParent) const373 	sal_uLong			GetVisibleChildCount(SvListEntry* pParent ) const { return pModel->GetVisibleChildCount((SvListView*)this,pParent); }
GetChildSelectionCount(SvListEntry * pParent) const374 	sal_uLong			GetChildSelectionCount( SvListEntry* pParent ) const { return pModel->GetChildSelectionCount((SvListView*)this,pParent); }
Expand(SvListEntry * pParent)375 	void            Expand( SvListEntry* pParent ) { pModel->Expand((SvListView*)this,pParent); }
Collapse(SvListEntry * pParent)376 	void            Collapse( SvListEntry* pParent ) { pModel->Collapse((SvListView*)this,pParent); }
Select(SvListEntry * pEntry,sal_Bool bSelect=sal_True)377 	sal_Bool            Select( SvListEntry* pEntry, sal_Bool bSelect=sal_True ) { return pModel->Select((SvListView*)this,pEntry,bSelect); }
SelectChilds(SvListEntry * pParent,sal_Bool bSelect)378 	sal_uLong			SelectChilds( SvListEntry* pParent, sal_Bool bSelect ) { return pModel->SelectChilds((SvListView*)this,pParent, bSelect); }
379 	// ruft nicht Select-Hdl
SelectAll(sal_Bool bSelect,sal_Bool)380 	virtual void	SelectAll( sal_Bool bSelect, sal_Bool ) { pModel->SelectAll((SvListView*)this, bSelect); }
IsEntryVisible(SvListEntry * pEntry) const381 	sal_Bool			IsEntryVisible( SvListEntry* pEntry ) const	{ return pModel->IsEntryVisible((SvListView*)this,pEntry); }
382 	sal_Bool			IsExpanded( SvListEntry* pEntry ) const;
383 	sal_Bool			IsSelected( SvListEntry* pEntry ) const;
384 	sal_Bool			HasEntryFocus( SvListEntry* pEntry ) const;
385 	void			SetEntryFocus( SvListEntry* pEntry, sal_Bool bFocus ) const;
386 	SvViewData*		GetViewData( SvListEntry* pEntry ) const;
HasViewData() const387 	sal_Bool			HasViewData() const { return aDataTable.Count() > 1;}	// eine ROOT gibts immer
388 	virtual	SvViewData* CreateViewData( SvListEntry* pEntry );
389 	virtual	void InitViewData( SvViewData*, SvListEntry* pEntry );
390 
391 	virtual void 	ModelHasCleared();
392 	virtual void 	ModelHasInserted( SvListEntry* pEntry );
393 	virtual void 	ModelHasInsertedTree( SvListEntry* pEntry );
394 	virtual void 	ModelIsMoving( SvListEntry* pSource, SvListEntry* pTargetParent,
395 								sal_uLong nPos	);
396 	virtual void 	ModelHasMoved( SvListEntry* pSource );
397 	virtual void 	ModelIsRemoving( SvListEntry* pEntry );
398 	virtual void 	ModelHasRemoved( SvListEntry* pEntry );
399 	virtual void 	ModelHasEntryInvalidated( SvListEntry* pEntry );
400 };
401 
IsExpanded(SvListEntry * pEntry) const402 inline sal_Bool SvListView::IsExpanded( SvListEntry* pEntry ) const
403 {
404 	DBG_ASSERT(pEntry,"IsExpanded:No Entry");
405 	SvViewData* pData = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry );
406 	DBG_ASSERT(pData,"Entry not in Table");
407 	return pData && pData->IsExpanded();
408 }
IsSelected(SvListEntry * pEntry) const409 inline sal_Bool SvListView::IsSelected( SvListEntry* pEntry ) const
410 {
411 	DBG_ASSERT(pEntry,"IsExpanded:No Entry");
412 	SvViewData* pData = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry );
413 	DBG_ASSERT(pData,"Entry not in Table");
414 	return pData && pData->IsSelected();
415 }
HasEntryFocus(SvListEntry * pEntry) const416 inline sal_Bool SvListView::HasEntryFocus( SvListEntry* pEntry ) const
417 {
418 	DBG_ASSERT(pEntry,"IsExpanded:No Entry");
419 	SvViewData* pData = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry );
420 	DBG_ASSERT(pData,"Entry not in Table");
421 	return pData && pData->HasFocus();
422 }
SetEntryFocus(SvListEntry * pEntry,sal_Bool bFocus) const423 inline void SvListView::SetEntryFocus( SvListEntry* pEntry, sal_Bool bFocus ) const
424 {
425 	DBG_ASSERT(pEntry,"SetEntryFocus:No Entry");
426 	SvViewData* pData = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry );
427 	DBG_ASSERT(pData,"Entry not in Table");
428 	pData->SetFocus(bFocus);
429 }
430 
GetViewData(SvListEntry * pEntry) const431 inline SvViewData* SvListView::GetViewData( SvListEntry* pEntry ) const
432 {
433 #ifndef DBG_UTIL
434 	return (SvViewData*)aDataTable.Get( (sal_uLong)pEntry );
435 #else
436 	SvViewData* pResult = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry );
437 	DBG_ASSERT(pResult,"Entry not in model or wrong view");
438 	return pResult;
439 #endif
440 }
441 
HasChilds(SvListEntry * pEntry) const442 inline sal_Bool SvTreeList::HasChilds( SvListEntry* pEntry ) const
443 {
444 	if ( !pEntry )
445 		pEntry = pRootItem;
446 	return (sal_Bool)(pEntry->pChilds != 0);
447 }
448 
GetEntry(SvListEntry * pParent,sal_uLong nPos) const449 inline SvListEntry* SvTreeList::GetEntry( SvListEntry* pParent, sal_uLong nPos ) const
450 {   if ( !pParent )
451 		pParent = pRootItem;
452 	SvListEntry* pRet = 0;
453 	if ( pParent->pChilds )
454 		pRet = (SvListEntry*)(pParent->pChilds->GetObject(nPos));
455 	return pRet;
456 }
457 
GetEntry(sal_uLong nRootPos) const458 inline SvListEntry* SvTreeList::GetEntry( sal_uLong nRootPos ) const
459 {
460 	SvListEntry* pRet;
461 	if ( nEntryCount )
462 		pRet = (SvListEntry*)(pRootItem->pChilds->GetObject(nRootPos));
463 	else
464 		pRet = 0;
465 	return pRet;
466 }
467 
GetChildList(SvListEntry * pParent) const468 inline SvTreeEntryList* SvTreeList::GetChildList( SvListEntry* pParent ) const
469 {
470 	if ( !pParent )
471 		pParent = pRootItem;
472 	return pParent->pChilds;
473 }
474 
GetParent(SvListEntry * pEntry) const475 inline SvListEntry* SvTreeList::GetParent( SvListEntry* pEntry ) const
476 {
477 	SvListEntry* pParent = pEntry->pParent;
478 	if ( pParent==pRootItem )
479 		pParent = 0;
480 	return pParent;
481 }
482 
483 #define DECLARE_SVTREELIST( ClassName, Type )									\
484 class ClassName : public SvTreeList                                       	\
485 {                                                                           \
486 public:                                                                     \
487 	Type		First() const                                               \
488 					{ return (Type)SvTreeList::First(); }                     \
489     Type    	Next( SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const           \
490 					{ return (Type)SvTreeList::Next(pEntry,pDepth); }         \
491     Type		Prev( SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const           \
492 					{ return (Type)SvTreeList::Prev(pEntry,pDepth); }         \
493     Type		Last( sal_uInt16* pDepth=0 ) const           					\
494 					{ return (Type)SvTreeList::Last(pDepth); }         		\
495 																			\
496 	Type 		Clone( SvListEntry* pEntry, sal_uLong& nCloneCount ) const        \
497 					{ return (Type)SvTreeList::Clone(pEntry,nCloneCount); }   \
498 	Type		GetEntry( SvListEntry* pParent, sal_uLong nPos ) const            \
499 					{ return (Type)SvTreeList::GetEntry(pParent,nPos); }      \
500 	Type		GetEntry( sal_uLong nRootPos ) const                            \
501 					{ return (Type)SvTreeList::GetEntry(nRootPos); }          \
502 	Type		GetParent( SvListEntry* pEntry ) const                        \
503 					{ return (Type)SvTreeList::GetParent(pEntry); }           \
504     using SvTreeList::FirstChild;                                             \
505 	Type		FirstChild( Type pParent ) const							\
506 					{ return (Type)SvTreeList::FirstChild(pParent); }			\
507     using SvTreeList::NextSibling;                                             \
508 	Type		NextSibling( Type pEntry ) const							\
509 					{ return (Type)SvTreeList::NextSibling(pEntry); }			\
510     using SvTreeList::PrevSibling;                                             \
511 	Type		PrevSibling( Type pEntry ) const							\
512 					{ return (Type)SvTreeList::PrevSibling(pEntry); }			\
513     using SvTreeList::LastSibling;                                             \
514 	Type		LastSibling( Type pEntry ) const							\
515 					{ return (Type)SvTreeList::LastSibling(pEntry); }			\
516 	Type		GetEntryAtAbsPos( sal_uLong nAbsPos ) const						\
517 					{ return (Type)SvTreeList::GetEntryAtAbsPos( nAbsPos); }	\
518 };
519 
520 #endif
521