xref: /AOO41X/main/svtools/source/contnr/treelist.cxx (revision 5900e8ec128faec89519683efce668ccd8cc6084)
1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #define _TREELIST_CXX
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #ifndef GCC
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <svtools/treelist.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #ifdef DBG_UTIL
35cdf0e10cSrcweir // Prueft Integritaet der Liste nach jeder Operation
36cdf0e10cSrcweir //#define CHECK_INTEGRITY
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir DBG_NAME(SvListEntry);
41cdf0e10cSrcweir 
SvListEntry()42cdf0e10cSrcweir SvListEntry::SvListEntry()
43cdf0e10cSrcweir {
44cdf0e10cSrcweir 	DBG_CTOR(SvListEntry,0);
45cdf0e10cSrcweir 	pChilds     = 0;
46cdf0e10cSrcweir 	pParent     = 0;
47cdf0e10cSrcweir 	nListPos    = 0;
48cdf0e10cSrcweir 	nAbsPos     = 0;
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
SvListEntry(const SvListEntry & rEntry)51cdf0e10cSrcweir SvListEntry::SvListEntry( const SvListEntry& rEntry )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	DBG_CTOR(SvListEntry,0);
54cdf0e10cSrcweir 	pChilds  = 0;
55cdf0e10cSrcweir 	pParent  = 0;
56cdf0e10cSrcweir 	nListPos &= 0x80000000;
57cdf0e10cSrcweir 	nListPos |= ( rEntry.nListPos & 0x7fffffff);
58cdf0e10cSrcweir 	nAbsPos  = rEntry.nAbsPos;
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
~SvListEntry()61cdf0e10cSrcweir SvListEntry::~SvListEntry()
62cdf0e10cSrcweir {
63cdf0e10cSrcweir 	DBG_DTOR(SvListEntry,0);
64cdf0e10cSrcweir 	if ( pChilds )
65cdf0e10cSrcweir 	{
66cdf0e10cSrcweir 		pChilds->DestroyAll();
67cdf0e10cSrcweir 		delete pChilds;
68cdf0e10cSrcweir 	}
69cdf0e10cSrcweir #ifdef DBG_UTIL
70cdf0e10cSrcweir 	pChilds     = 0;
71cdf0e10cSrcweir 	pParent     = 0;
72cdf0e10cSrcweir #endif
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
Clone(SvListEntry * pSource)75cdf0e10cSrcweir void SvListEntry::Clone( SvListEntry* pSource)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	DBG_CHKTHIS(SvListEntry,0);
78cdf0e10cSrcweir 	nListPos &= 0x80000000;
79cdf0e10cSrcweir 	nListPos |= ( pSource->nListPos & 0x7fffffff);
80cdf0e10cSrcweir 	nAbsPos		= pSource->nAbsPos;
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
SetListPositions()83cdf0e10cSrcweir void SvListEntry::SetListPositions()
84cdf0e10cSrcweir {
85cdf0e10cSrcweir 	if( pChilds )
86cdf0e10cSrcweir 	{
87cdf0e10cSrcweir 		SvListEntry	*pEntry = (SvListEntry*)pChilds->First();
88cdf0e10cSrcweir 		sal_uLong		nCur = 0;
89cdf0e10cSrcweir 		while ( pEntry )
90cdf0e10cSrcweir 		{
91cdf0e10cSrcweir 			pEntry->nListPos &= 0x80000000;
92cdf0e10cSrcweir 			pEntry->nListPos |= nCur;
93cdf0e10cSrcweir 			nCur++;
94cdf0e10cSrcweir 			pEntry = (SvListEntry*)pChilds->Next();
95cdf0e10cSrcweir 		}
96cdf0e10cSrcweir 	}
97cdf0e10cSrcweir 	nListPos &= (~0x80000000);
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 
101cdf0e10cSrcweir DBG_NAME(SvViewData);
102cdf0e10cSrcweir 
SvViewData()103cdf0e10cSrcweir SvViewData::SvViewData()
104cdf0e10cSrcweir {
105cdf0e10cSrcweir 	DBG_CTOR(SvViewData,0);
106cdf0e10cSrcweir 	nFlags = 0;
107cdf0e10cSrcweir 	nVisPos = 0;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
SvViewData(const SvViewData & rData)110cdf0e10cSrcweir SvViewData::SvViewData( const SvViewData& rData )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir 	DBG_CTOR(SvViewData,0);
113cdf0e10cSrcweir 	nFlags	= rData.nFlags;
114cdf0e10cSrcweir 	nFlags &= ~( SVLISTENTRYFLAG_SELECTED | SVLISTENTRYFLAG_FOCUSED );
115cdf0e10cSrcweir 	nVisPos	= rData.nVisPos;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
~SvViewData()118cdf0e10cSrcweir SvViewData::~SvViewData()
119cdf0e10cSrcweir {
120cdf0e10cSrcweir 	DBG_DTOR(SvViewData,0);
121cdf0e10cSrcweir #ifdef DBG_UTIL
122cdf0e10cSrcweir 	nVisPos = 0x12345678;
123cdf0e10cSrcweir 	nFlags = 0x1234;
124cdf0e10cSrcweir #endif
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
DestroyAll()127cdf0e10cSrcweir void SvTreeEntryList::DestroyAll()
128cdf0e10cSrcweir {
129cdf0e10cSrcweir 	SvListEntry* pPtr = (SvListEntry*)First();
130cdf0e10cSrcweir 	while( pPtr )
131cdf0e10cSrcweir 	{
132cdf0e10cSrcweir 		delete pPtr;
133cdf0e10cSrcweir 		pPtr = (SvListEntry*)Next();
134cdf0e10cSrcweir 	}
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 
138cdf0e10cSrcweir /*************************************************************************
139cdf0e10cSrcweir |*
140cdf0e10cSrcweir |*    SvTreeList::
141cdf0e10cSrcweir |*
142cdf0e10cSrcweir |*    Beschreibung
143cdf0e10cSrcweir |*    Ersterstellung    17.08.94
144cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
145cdf0e10cSrcweir |*
146cdf0e10cSrcweir *************************************************************************/
147cdf0e10cSrcweir 
SvTreeList()148cdf0e10cSrcweir SvTreeList::SvTreeList()
149cdf0e10cSrcweir {
150cdf0e10cSrcweir 	nEntryCount = 0;
151cdf0e10cSrcweir 	bAbsPositionsValid = sal_False;
152cdf0e10cSrcweir 	nRefCount = 1;
153cdf0e10cSrcweir 	pRootItem = new SvListEntry;
154cdf0e10cSrcweir 	eSortMode = SortNone;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 
158cdf0e10cSrcweir /*************************************************************************
159cdf0e10cSrcweir |*
160cdf0e10cSrcweir |*    SvTreeList::~SvTreeList
161cdf0e10cSrcweir |*
162cdf0e10cSrcweir |*    Beschreibung
163cdf0e10cSrcweir |*    Ersterstellung    17.08.94
164cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
165cdf0e10cSrcweir |*
166cdf0e10cSrcweir *************************************************************************/
167cdf0e10cSrcweir 
~SvTreeList()168cdf0e10cSrcweir SvTreeList::~SvTreeList()
169cdf0e10cSrcweir {
170cdf0e10cSrcweir 	Clear();
171cdf0e10cSrcweir 	delete pRootItem;
172cdf0e10cSrcweir #ifdef DBG_UTIL
173cdf0e10cSrcweir 	pRootItem = 0;
174cdf0e10cSrcweir #endif
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir /*************************************************************************
178cdf0e10cSrcweir |*
179cdf0e10cSrcweir |*    SvTreeList::Broadcast
180cdf0e10cSrcweir |*
181cdf0e10cSrcweir |*    Beschreibung
182cdf0e10cSrcweir |*    Ersterstellung    17.08.94
183cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
184cdf0e10cSrcweir |*
185cdf0e10cSrcweir *************************************************************************/
186cdf0e10cSrcweir 
Broadcast(sal_uInt16 nActionId,SvListEntry * pEntry1,SvListEntry * pEntry2,sal_uLong nPos)187cdf0e10cSrcweir void SvTreeList::Broadcast( sal_uInt16 nActionId, SvListEntry* pEntry1,
188cdf0e10cSrcweir 	SvListEntry* pEntry2, sal_uLong nPos )
189cdf0e10cSrcweir {
190cdf0e10cSrcweir 	sal_uLong nViewCount = aViewList.Count();
191cdf0e10cSrcweir 	for( sal_uLong nCurView = 0; nCurView < nViewCount; nCurView++ )
192cdf0e10cSrcweir 	{
193cdf0e10cSrcweir 		SvListView* pView = (SvListView*)aViewList.GetObject( nCurView );
194cdf0e10cSrcweir 		if( pView )
195cdf0e10cSrcweir 			pView->ModelNotification( nActionId, pEntry1, pEntry2, nPos );
196cdf0e10cSrcweir 	}
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
InsertView(SvListView * pView)199cdf0e10cSrcweir void SvTreeList::InsertView( SvListView* pView)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir 	sal_uLong nPos = aViewList.GetPos( pView );
202cdf0e10cSrcweir 	if ( nPos == LIST_ENTRY_NOTFOUND )
203cdf0e10cSrcweir 	{
204cdf0e10cSrcweir 		aViewList.Insert( pView, LIST_APPEND );
205cdf0e10cSrcweir 		nRefCount++;
206cdf0e10cSrcweir 	}
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
RemoveView(SvListView * pView)209cdf0e10cSrcweir void SvTreeList::RemoveView( SvListView* pView )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir 	sal_uLong nPos = aViewList.GetPos( pView );
212cdf0e10cSrcweir 	if ( nPos != LIST_ENTRY_NOTFOUND )
213cdf0e10cSrcweir 	{
214cdf0e10cSrcweir 		aViewList.Remove( pView );
215cdf0e10cSrcweir 		nRefCount--;
216cdf0e10cSrcweir 	}
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 
220cdf0e10cSrcweir // Ein Entry ist sichtbar, wenn alle Parents expandiert sind
IsEntryVisible(const SvListView * pView,SvListEntry * pEntry) const221cdf0e10cSrcweir sal_Bool SvTreeList::IsEntryVisible( const SvListView* pView, SvListEntry* pEntry ) const
222cdf0e10cSrcweir {
223cdf0e10cSrcweir 	DBG_ASSERT(pView&&pEntry,"IsVisible:Invalid Params");
224cdf0e10cSrcweir 	sal_Bool bRetVal=sal_False;
225cdf0e10cSrcweir 	do
226cdf0e10cSrcweir 	{
227cdf0e10cSrcweir 		if ( pEntry == pRootItem )
228cdf0e10cSrcweir 		{
229cdf0e10cSrcweir 			bRetVal=sal_True;
230cdf0e10cSrcweir 			break;
231cdf0e10cSrcweir 		}
232cdf0e10cSrcweir 		pEntry = pEntry->pParent;
233cdf0e10cSrcweir 	}  while( pView->IsExpanded( pEntry ) );
234cdf0e10cSrcweir 	return bRetVal;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
GetDepth(SvListEntry * pEntry) const237cdf0e10cSrcweir sal_uInt16 SvTreeList::GetDepth( SvListEntry* pEntry ) const
238cdf0e10cSrcweir {
239cdf0e10cSrcweir 	DBG_ASSERT(pEntry&&pEntry!=pRootItem,"GetDepth:Bad Entry");
240cdf0e10cSrcweir 	sal_uInt16 nDepth = 0;
241cdf0e10cSrcweir 	while( pEntry->pParent != pRootItem )
242cdf0e10cSrcweir 	{
243cdf0e10cSrcweir 		nDepth++;
244cdf0e10cSrcweir 		pEntry = pEntry->pParent;
245cdf0e10cSrcweir 	}
246cdf0e10cSrcweir 	return nDepth;
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
249cdf0e10cSrcweir /*************************************************************************
250cdf0e10cSrcweir |*
251cdf0e10cSrcweir |*    SvTreeList::
252cdf0e10cSrcweir |*
253cdf0e10cSrcweir |*    Beschreibung
254cdf0e10cSrcweir |*    Ersterstellung    17.08.94
255cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
256cdf0e10cSrcweir |*
257cdf0e10cSrcweir *************************************************************************/
258cdf0e10cSrcweir 
Clear()259cdf0e10cSrcweir void SvTreeList::Clear()
260cdf0e10cSrcweir {
261cdf0e10cSrcweir 	Broadcast( LISTACTION_CLEARING );
262cdf0e10cSrcweir 	SvTreeEntryList* pRootList = pRootItem->pChilds;
263cdf0e10cSrcweir 	if ( pRootList )
264cdf0e10cSrcweir 	{
265cdf0e10cSrcweir 		SvListEntry* pEntry = (SvListEntry*)(pRootList->First());
266cdf0e10cSrcweir 		while( pEntry )
267cdf0e10cSrcweir 		{
268cdf0e10cSrcweir 			delete pEntry;
269cdf0e10cSrcweir 			pEntry = (SvListEntry*)(pRootList->Next());
270cdf0e10cSrcweir 		}
271cdf0e10cSrcweir 		delete pRootItem->pChilds;
272cdf0e10cSrcweir 		pRootItem->pChilds = 0;
273cdf0e10cSrcweir 	}
274cdf0e10cSrcweir 	nEntryCount = 0;
275cdf0e10cSrcweir 	Broadcast( LISTACTION_CLEARED );
276cdf0e10cSrcweir }
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 
279cdf0e10cSrcweir /*************************************************************************
280cdf0e10cSrcweir |*
281cdf0e10cSrcweir |*    SvTreeList::
282cdf0e10cSrcweir |*
283cdf0e10cSrcweir |*    Beschreibung
284cdf0e10cSrcweir |*    Ersterstellung    17.08.94
285cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
286cdf0e10cSrcweir |*
287cdf0e10cSrcweir *************************************************************************/
288cdf0e10cSrcweir 
IsChild(SvListEntry * pParent,SvListEntry * pChild) const289cdf0e10cSrcweir sal_Bool SvTreeList::IsChild( SvListEntry* pParent, SvListEntry* pChild ) const
290cdf0e10cSrcweir {
291cdf0e10cSrcweir 	if ( !pParent )
292cdf0e10cSrcweir 		pParent = pRootItem;
293cdf0e10cSrcweir 
294cdf0e10cSrcweir 	sal_Bool bIsChild = sal_False;
295cdf0e10cSrcweir 	SvTreeEntryList* pList = pParent->pChilds;
296cdf0e10cSrcweir 	if ( !pList )
297cdf0e10cSrcweir 		return sal_False;
298cdf0e10cSrcweir 	SvListEntry* pActualChild = (SvListEntry*)(pList->First());
299cdf0e10cSrcweir 	while( !bIsChild && pActualChild )
300cdf0e10cSrcweir 	{
301cdf0e10cSrcweir 		if ( pActualChild == pChild )
302cdf0e10cSrcweir 			bIsChild = sal_True;
303cdf0e10cSrcweir 		else
304cdf0e10cSrcweir 		{
305cdf0e10cSrcweir 			if ( pActualChild->pChilds )
306cdf0e10cSrcweir 				bIsChild = IsChild( pActualChild, pChild );
307cdf0e10cSrcweir 			pActualChild = (SvListEntry*)(pList->Next());
308cdf0e10cSrcweir 		}
309cdf0e10cSrcweir 	}
310cdf0e10cSrcweir 	return bIsChild;
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
Move(SvListEntry * pSrcEntry,SvListEntry * pTargetParent,sal_uLong nListPos)313cdf0e10cSrcweir sal_uLong SvTreeList::Move(SvListEntry* pSrcEntry,SvListEntry* pTargetParent,sal_uLong nListPos)
314cdf0e10cSrcweir {
315cdf0e10cSrcweir 	// pDest darf Null sein!
316cdf0e10cSrcweir 	DBG_ASSERT(pSrcEntry,"Entry?");
317cdf0e10cSrcweir 	if ( !pTargetParent )
318cdf0e10cSrcweir 		pTargetParent = pRootItem;
319cdf0e10cSrcweir 	DBG_ASSERT(pSrcEntry!=pTargetParent,"Move:Source=Target");
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 	Broadcast( LISTACTION_MOVING, pSrcEntry, pTargetParent, nListPos );
322cdf0e10cSrcweir 
323cdf0e10cSrcweir 	if ( !pTargetParent->pChilds )
324cdf0e10cSrcweir 		pTargetParent->pChilds = new SvTreeEntryList;
325cdf0e10cSrcweir 	if ( pSrcEntry == pTargetParent )
326cdf0e10cSrcweir 		return pSrcEntry->GetChildListPos();
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 	bAbsPositionsValid = sal_False;
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 	SvTreeEntryList* pDstList = pTargetParent->pChilds;
331cdf0e10cSrcweir 	SvTreeEntryList* pSrcList = pSrcEntry->pParent->pChilds;
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 	// Dummy-Ptr einfuegen, weil nListPos durch das
334cdf0e10cSrcweir 	// folgende Remove ungueltig werden koennte
335cdf0e10cSrcweir 	SvListEntry* pDummy = 0; pDstList->Insert( pDummy, nListPos );
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 	// loeschen
338cdf0e10cSrcweir 	pSrcList->Remove( pSrcEntry );
339cdf0e10cSrcweir 	// Hat Parent noch Childs ?
340cdf0e10cSrcweir 	if ( pSrcList->Count() == 0 )
341cdf0e10cSrcweir 	{
342cdf0e10cSrcweir 		// Keine Childs, deshalb Child-List loeschen
343cdf0e10cSrcweir 		SvListEntry* pParent = pSrcEntry->pParent;
344cdf0e10cSrcweir 		pParent->pChilds = 0;
345cdf0e10cSrcweir 		delete pSrcList;
346cdf0e10cSrcweir 		pSrcList = 0;
347cdf0e10cSrcweir 	}
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 	// Parent umsetzen (erst hier, weil wir zum Loeschen
350cdf0e10cSrcweir 	// der ChildList den alten Parent noch benoetigen!)
351cdf0e10cSrcweir 	pSrcEntry->pParent = pTargetParent;
352cdf0e10cSrcweir 
353cdf0e10cSrcweir 	pDstList->Replace( pSrcEntry, pDummy );
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 	// Listenpositionen in Zielliste korrigieren
356cdf0e10cSrcweir 	SetListPositions( pDstList );
357cdf0e10cSrcweir 	if ( pSrcList && (sal_uLong)pSrcList != (sal_uLong)pDstList )
358cdf0e10cSrcweir 		SetListPositions( pSrcList );
359cdf0e10cSrcweir 
360cdf0e10cSrcweir #ifdef CHECK_INTEGRITY
361cdf0e10cSrcweir CheckIntegrity();
362cdf0e10cSrcweir #endif
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 	sal_uLong nRetVal = pDstList->GetPos( pSrcEntry );
365cdf0e10cSrcweir 	DBG_ASSERT(nRetVal==pSrcEntry->GetChildListPos(),"ListPos not valid");
366cdf0e10cSrcweir 	Broadcast( LISTACTION_MOVED,pSrcEntry,pTargetParent,nRetVal);
367cdf0e10cSrcweir 	return nRetVal;
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
Copy(SvListEntry * pSrcEntry,SvListEntry * pTargetParent,sal_uLong nListPos)370cdf0e10cSrcweir sal_uLong SvTreeList::Copy(SvListEntry* pSrcEntry,SvListEntry* pTargetParent,sal_uLong nListPos)
371cdf0e10cSrcweir {
372cdf0e10cSrcweir 	// pDest darf Null sein!
373cdf0e10cSrcweir 	DBG_ASSERT(pSrcEntry,"Entry?");
374cdf0e10cSrcweir 	if ( !pTargetParent )
375cdf0e10cSrcweir 		pTargetParent = pRootItem;
376cdf0e10cSrcweir 	if ( !pTargetParent->pChilds )
377cdf0e10cSrcweir 		pTargetParent->pChilds = new SvTreeEntryList;
378cdf0e10cSrcweir 
379cdf0e10cSrcweir 	bAbsPositionsValid = sal_False;
380cdf0e10cSrcweir 
381cdf0e10cSrcweir 	sal_uLong nCloneCount = 0;
382cdf0e10cSrcweir 	SvListEntry* pClonedEntry = Clone( pSrcEntry, nCloneCount );
383cdf0e10cSrcweir 	nEntryCount += nCloneCount;
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 	SvTreeEntryList* pDstList = pTargetParent->pChilds;
386cdf0e10cSrcweir 	pClonedEntry->pParent = pTargetParent;		// Parent umsetzen
387cdf0e10cSrcweir 	pDstList->Insert( pClonedEntry, nListPos ); // Einfuegen
388cdf0e10cSrcweir 	SetListPositions( pDstList ); // Listenpositionen in Zielliste korrigieren
389cdf0e10cSrcweir 
390cdf0e10cSrcweir #ifdef CHECK_INTEGRITY
391cdf0e10cSrcweir CheckIntegrity();
392cdf0e10cSrcweir #endif
393cdf0e10cSrcweir 	Broadcast( LISTACTION_INSERTED_TREE, pClonedEntry );
394cdf0e10cSrcweir 	sal_uLong nRetVal = pDstList->GetPos( pClonedEntry );
395cdf0e10cSrcweir 	return nRetVal;
396cdf0e10cSrcweir }
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 
400cdf0e10cSrcweir /*************************************************************************
401cdf0e10cSrcweir |*
402cdf0e10cSrcweir |*    SvTreeList::
403cdf0e10cSrcweir |*
404cdf0e10cSrcweir |*    Beschreibung
405cdf0e10cSrcweir |*    Ersterstellung    17.08.94
406cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
407cdf0e10cSrcweir |*
408cdf0e10cSrcweir *************************************************************************/
409cdf0e10cSrcweir 
Move(SvListEntry * pSrcEntry,SvListEntry * pDstEntry)410cdf0e10cSrcweir void SvTreeList::Move( SvListEntry* pSrcEntry, SvListEntry* pDstEntry )
411cdf0e10cSrcweir {
412cdf0e10cSrcweir 	SvListEntry* pParent;
413cdf0e10cSrcweir 	sal_uLong nPos;
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 	if ( !pDstEntry )
416cdf0e10cSrcweir 	{
417cdf0e10cSrcweir 		pParent = pRootItem;
418cdf0e10cSrcweir 		nPos = 0UL;
419cdf0e10cSrcweir 	}
420cdf0e10cSrcweir 	else
421cdf0e10cSrcweir 	{
422cdf0e10cSrcweir 		pParent = pDstEntry->pParent;
423cdf0e10cSrcweir 		nPos = pDstEntry->GetChildListPos();
424cdf0e10cSrcweir 		nPos++;  // UNTER (Bildschirm) pDstEntry einfuegen
425cdf0e10cSrcweir 	}
426cdf0e10cSrcweir 	Move( pSrcEntry, pParent, nPos );
427cdf0e10cSrcweir }
428cdf0e10cSrcweir 
429cdf0e10cSrcweir /*************************************************************************
430cdf0e10cSrcweir |*
431cdf0e10cSrcweir |*    SvTreeList::
432cdf0e10cSrcweir |*
433cdf0e10cSrcweir |*    Beschreibung
434cdf0e10cSrcweir |*    Ersterstellung    17.08.94
435cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
436cdf0e10cSrcweir |*
437cdf0e10cSrcweir *************************************************************************/
438cdf0e10cSrcweir 
Copy(SvListEntry * pSrcEntry,SvListEntry * pDstEntry)439cdf0e10cSrcweir void SvTreeList::Copy( SvListEntry* pSrcEntry, SvListEntry* pDstEntry )
440cdf0e10cSrcweir {
441cdf0e10cSrcweir 	SvListEntry* pParent;
442cdf0e10cSrcweir 	sal_uLong nPos;
443cdf0e10cSrcweir 
444cdf0e10cSrcweir 	if ( !pDstEntry )
445cdf0e10cSrcweir 	{
446cdf0e10cSrcweir 		pParent = pRootItem;
447cdf0e10cSrcweir 		nPos = 0UL;
448cdf0e10cSrcweir 	}
449cdf0e10cSrcweir 	else
450cdf0e10cSrcweir 	{
451cdf0e10cSrcweir 		pParent = pDstEntry->pParent;
452cdf0e10cSrcweir 		nPos = pDstEntry->GetChildListPos()+1;
453cdf0e10cSrcweir 	}
454cdf0e10cSrcweir 	Copy( pSrcEntry, pParent, nPos );
455cdf0e10cSrcweir }
456cdf0e10cSrcweir 
457cdf0e10cSrcweir /*************************************************************************
458cdf0e10cSrcweir |*
459cdf0e10cSrcweir |*    SvTreeList::
460cdf0e10cSrcweir |*
461cdf0e10cSrcweir |*    Beschreibung
462cdf0e10cSrcweir |*    Ersterstellung    17.08.94
463cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
464cdf0e10cSrcweir |*
465cdf0e10cSrcweir *************************************************************************/
InsertTree(SvListEntry * pSrcEntry,SvListEntry * pDstEntry)466cdf0e10cSrcweir void SvTreeList::InsertTree( SvListEntry* pSrcEntry, SvListEntry* pDstEntry)
467cdf0e10cSrcweir {
468cdf0e10cSrcweir 	SvListEntry* pParent;
469cdf0e10cSrcweir 	sal_uLong nPos;
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 	if ( !pDstEntry )
472cdf0e10cSrcweir 	{
473cdf0e10cSrcweir 		pParent = pRootItem;
474cdf0e10cSrcweir 		nPos = 0UL;
475cdf0e10cSrcweir 	}
476cdf0e10cSrcweir 	else
477cdf0e10cSrcweir 	{
478cdf0e10cSrcweir 		pParent = pDstEntry->pParent;
479cdf0e10cSrcweir 		nPos = pDstEntry->GetChildListPos()+1;
480cdf0e10cSrcweir 	}
481cdf0e10cSrcweir 	InsertTree( pSrcEntry, pParent, nPos );
482cdf0e10cSrcweir }
483cdf0e10cSrcweir 
484cdf0e10cSrcweir 
InsertTree(SvListEntry * pSrcEntry,SvListEntry * pTargetParent,sal_uLong nListPos)485cdf0e10cSrcweir void SvTreeList::InsertTree(SvListEntry* pSrcEntry,
486cdf0e10cSrcweir 	SvListEntry* pTargetParent,sal_uLong nListPos)
487cdf0e10cSrcweir {
488cdf0e10cSrcweir 	DBG_ASSERT(pSrcEntry,"InsertTree:Entry?");
489cdf0e10cSrcweir 	if ( !pSrcEntry )
490cdf0e10cSrcweir 		return;
491cdf0e10cSrcweir 
492cdf0e10cSrcweir 	if ( !pTargetParent )
493cdf0e10cSrcweir 		pTargetParent = pRootItem;
494cdf0e10cSrcweir 	if ( !pTargetParent->pChilds )
495cdf0e10cSrcweir 		pTargetParent->pChilds = new SvTreeEntryList;
496cdf0e10cSrcweir 
497cdf0e10cSrcweir 	// Sortierung beruecksichtigen
498cdf0e10cSrcweir 	GetInsertionPos( pSrcEntry, pTargetParent, nListPos );
499cdf0e10cSrcweir 
500cdf0e10cSrcweir 	bAbsPositionsValid = sal_False;
501cdf0e10cSrcweir 
502cdf0e10cSrcweir 	pSrcEntry->pParent = pTargetParent; // Parent umsetzen
503cdf0e10cSrcweir 	SvTreeEntryList* pDstList = pTargetParent->pChilds;
504cdf0e10cSrcweir 	pDstList->Insert( pSrcEntry, nListPos ); // einfuegen
505cdf0e10cSrcweir 	SetListPositions(pDstList); // Listenpositionen in Zielliste korrigieren
506cdf0e10cSrcweir 	nEntryCount += GetChildCount( pSrcEntry );
507cdf0e10cSrcweir 	nEntryCount++; // der Parent ist ja auch neu
508cdf0e10cSrcweir 
509cdf0e10cSrcweir #ifdef CHECK_INTEGRITY
510cdf0e10cSrcweir CheckIntegrity();
511cdf0e10cSrcweir #endif
512cdf0e10cSrcweir 	Broadcast(LISTACTION_INSERTED_TREE, pSrcEntry );
513cdf0e10cSrcweir }
514cdf0e10cSrcweir 
CloneEntry(SvListEntry * pSource) const515cdf0e10cSrcweir SvListEntry* SvTreeList::CloneEntry( SvListEntry* pSource ) const
516cdf0e10cSrcweir {
517cdf0e10cSrcweir 	if( aCloneLink.IsSet() )
518cdf0e10cSrcweir 		return (SvListEntry*)aCloneLink.Call( pSource );
519cdf0e10cSrcweir 	SvListEntry* pEntry = CreateEntry();
520cdf0e10cSrcweir 	pSource->Clone( pEntry );
521cdf0e10cSrcweir 	return pSource;
522cdf0e10cSrcweir }
523cdf0e10cSrcweir 
CreateEntry() const524cdf0e10cSrcweir SvListEntry* SvTreeList::CreateEntry() const
525cdf0e10cSrcweir {
526cdf0e10cSrcweir 	return new SvListEntry;
527cdf0e10cSrcweir }
528cdf0e10cSrcweir 
529cdf0e10cSrcweir /*************************************************************************
530cdf0e10cSrcweir |*
531cdf0e10cSrcweir |*    SvTreeList::
532cdf0e10cSrcweir |*
533cdf0e10cSrcweir |*    Beschreibung
534cdf0e10cSrcweir |*    Ersterstellung    17.08.94
535cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
536cdf0e10cSrcweir |*
537cdf0e10cSrcweir *************************************************************************/
538cdf0e10cSrcweir 
Clone(SvListEntry * pEntry,sal_uLong & nCloneCount) const539cdf0e10cSrcweir SvListEntry* SvTreeList::Clone( SvListEntry* pEntry, sal_uLong& nCloneCount ) const
540cdf0e10cSrcweir {
541cdf0e10cSrcweir 	SvListEntry* pClonedEntry = CloneEntry( pEntry );
542cdf0e10cSrcweir 	nCloneCount = 1;
543cdf0e10cSrcweir 	SvTreeEntryList* pChilds = pEntry->pChilds;
544cdf0e10cSrcweir 	if ( pChilds )
545cdf0e10cSrcweir 		pClonedEntry->pChilds=CloneChilds(pChilds,pClonedEntry,nCloneCount);
546cdf0e10cSrcweir 	return pClonedEntry;
547cdf0e10cSrcweir }
548cdf0e10cSrcweir 
549cdf0e10cSrcweir /*************************************************************************
550cdf0e10cSrcweir |*
551cdf0e10cSrcweir |*    SvTreeList::
552cdf0e10cSrcweir |*
553cdf0e10cSrcweir |*    Beschreibung
554cdf0e10cSrcweir |*    Ersterstellung    17.08.94
555cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
556cdf0e10cSrcweir |*
557cdf0e10cSrcweir *************************************************************************/
558cdf0e10cSrcweir 
CloneChilds(SvTreeEntryList * pChilds,SvListEntry * pNewParent,sal_uLong & nCloneCount) const559cdf0e10cSrcweir SvTreeEntryList* SvTreeList::CloneChilds( SvTreeEntryList* pChilds,
560cdf0e10cSrcweir 									  SvListEntry* pNewParent,
561cdf0e10cSrcweir 									  sal_uLong& nCloneCount ) const
562cdf0e10cSrcweir {
563cdf0e10cSrcweir 	DBG_ASSERT(pChilds->Count(),"Childs?");
564cdf0e10cSrcweir 	SvTreeEntryList* pClonedChilds = new SvTreeEntryList;
565cdf0e10cSrcweir 	SvListEntry* pChild = (SvListEntry*)pChilds->First();
566cdf0e10cSrcweir 	while ( pChild )
567cdf0e10cSrcweir 	{
568cdf0e10cSrcweir 		SvListEntry* pNewChild = CloneEntry( pChild );
569cdf0e10cSrcweir 		nCloneCount++;
570cdf0e10cSrcweir 		pNewChild->pParent = pNewParent;
571cdf0e10cSrcweir 		SvTreeEntryList* pSubChilds = pChild->pChilds;
572cdf0e10cSrcweir 		if ( pSubChilds )
573cdf0e10cSrcweir 		{
574cdf0e10cSrcweir 			pSubChilds = CloneChilds( pSubChilds, pNewChild, nCloneCount );
575cdf0e10cSrcweir 			pNewChild->pChilds = pSubChilds;
576cdf0e10cSrcweir 		}
577cdf0e10cSrcweir 
578cdf0e10cSrcweir 		pClonedChilds->Insert( pNewChild, LIST_APPEND );
579cdf0e10cSrcweir 		pChild = (SvListEntry*)pChilds->Next();
580cdf0e10cSrcweir 	}
581cdf0e10cSrcweir 	return pClonedChilds;
582cdf0e10cSrcweir }
583cdf0e10cSrcweir 
584cdf0e10cSrcweir 
585cdf0e10cSrcweir /*************************************************************************
586cdf0e10cSrcweir |*
587cdf0e10cSrcweir |*    SvTreeList::GetChildCount
588cdf0e10cSrcweir |*
589cdf0e10cSrcweir |*    Beschreibung
590cdf0e10cSrcweir |*    Ersterstellung    17.08.94
591cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
592cdf0e10cSrcweir |*
593cdf0e10cSrcweir *************************************************************************/
594cdf0e10cSrcweir 
GetChildCount(SvListEntry * pParent) const595cdf0e10cSrcweir sal_uLong SvTreeList::GetChildCount( SvListEntry* pParent ) const
596cdf0e10cSrcweir {
597cdf0e10cSrcweir 	if ( !pParent )
598cdf0e10cSrcweir 		return GetEntryCount();
599cdf0e10cSrcweir 
600cdf0e10cSrcweir 	if ( !pParent || !pParent->pChilds)
601cdf0e10cSrcweir 		return 0;
602cdf0e10cSrcweir 	sal_uLong nCount = 0;
603cdf0e10cSrcweir 	sal_uInt16 nRefDepth = GetDepth( pParent );
604cdf0e10cSrcweir 	sal_uInt16 nActDepth = nRefDepth;
605cdf0e10cSrcweir 	do
606cdf0e10cSrcweir 	{
607cdf0e10cSrcweir 		pParent = Next( pParent, &nActDepth );
608cdf0e10cSrcweir 		nCount++;
609cdf0e10cSrcweir 	} while( pParent && nRefDepth < nActDepth );
610cdf0e10cSrcweir 	nCount--;
611cdf0e10cSrcweir 	return nCount;
612cdf0e10cSrcweir }
613cdf0e10cSrcweir 
614cdf0e10cSrcweir /*************************************************************************
615cdf0e10cSrcweir |*
616cdf0e10cSrcweir |*    SvTreeList::
617cdf0e10cSrcweir |*
618cdf0e10cSrcweir |*    Beschreibung
619cdf0e10cSrcweir |*    Ersterstellung    17.08.94
620cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
621cdf0e10cSrcweir |*
622cdf0e10cSrcweir *************************************************************************/
623cdf0e10cSrcweir 
GetVisibleChildCount(const SvListView * pView,SvListEntry * pParent) const624cdf0e10cSrcweir sal_uLong SvTreeList::GetVisibleChildCount(const SvListView* pView, SvListEntry* pParent) const
625cdf0e10cSrcweir {
626cdf0e10cSrcweir 	DBG_ASSERT(pView,"GetVisChildCount:No View");
627cdf0e10cSrcweir 	if ( !pParent )
628cdf0e10cSrcweir 		pParent = pRootItem;
629cdf0e10cSrcweir 	if ( !pParent || !pView->IsExpanded(pParent) || !pParent->pChilds )
630cdf0e10cSrcweir 		return 0;
631cdf0e10cSrcweir 	sal_uLong nCount = 0;
632cdf0e10cSrcweir 	sal_uInt16 nRefDepth = GetDepth( pParent );
633cdf0e10cSrcweir 	sal_uInt16 nActDepth = nRefDepth;
634cdf0e10cSrcweir 	do
635cdf0e10cSrcweir 	{
636cdf0e10cSrcweir 		pParent = NextVisible( pView, pParent, &nActDepth );
637cdf0e10cSrcweir 		nCount++;
638cdf0e10cSrcweir 	} while( pParent && nRefDepth < nActDepth );
639cdf0e10cSrcweir 	nCount--;
640cdf0e10cSrcweir 	return nCount;
641cdf0e10cSrcweir }
642cdf0e10cSrcweir 
GetChildSelectionCount(const SvListView * pView,SvListEntry * pParent) const643cdf0e10cSrcweir sal_uLong SvTreeList::GetChildSelectionCount(const SvListView* pView,SvListEntry* pParent) const
644cdf0e10cSrcweir {
645cdf0e10cSrcweir 	DBG_ASSERT(pView,"GetChildSelCount:No View");
646cdf0e10cSrcweir 	if ( !pParent )
647cdf0e10cSrcweir 		pParent = pRootItem;
648cdf0e10cSrcweir 	if ( !pParent || !pParent->pChilds)
649cdf0e10cSrcweir 		return 0;
650cdf0e10cSrcweir 	sal_uLong nCount = 0;
651cdf0e10cSrcweir 	sal_uInt16 nRefDepth = GetDepth( pParent );
652cdf0e10cSrcweir 	sal_uInt16 nActDepth = nRefDepth;
653cdf0e10cSrcweir 	do
654cdf0e10cSrcweir 	{
655cdf0e10cSrcweir 		pParent = Next( pParent, &nActDepth );
656cdf0e10cSrcweir 		if( pParent && pView->IsSelected( pParent ) && nRefDepth < nActDepth)
657cdf0e10cSrcweir 			nCount++;
658cdf0e10cSrcweir 	} while( pParent && nRefDepth < nActDepth );
659cdf0e10cSrcweir //	nCount--;
660cdf0e10cSrcweir 	return nCount;
661cdf0e10cSrcweir }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir 
664cdf0e10cSrcweir /*************************************************************************
665cdf0e10cSrcweir |*
666cdf0e10cSrcweir |*    SvTreeList::
667cdf0e10cSrcweir |*
668cdf0e10cSrcweir |*    Beschreibung
669cdf0e10cSrcweir |*    Ersterstellung    17.08.94
670cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
671cdf0e10cSrcweir |*
672cdf0e10cSrcweir *************************************************************************/
673cdf0e10cSrcweir 
First() const674cdf0e10cSrcweir SvListEntry* SvTreeList::First() const
675cdf0e10cSrcweir {
676cdf0e10cSrcweir 	if ( nEntryCount )
677cdf0e10cSrcweir 		return (SvListEntry*)(pRootItem->pChilds->GetObject(0));
678cdf0e10cSrcweir 	else
679cdf0e10cSrcweir 		return 0;
680cdf0e10cSrcweir }
681cdf0e10cSrcweir 
682cdf0e10cSrcweir /*************************************************************************
683cdf0e10cSrcweir |*
684cdf0e10cSrcweir |*    SvTreeList::Next
685cdf0e10cSrcweir |*
686cdf0e10cSrcweir |*    Beschreibung
687cdf0e10cSrcweir |*    Ersterstellung    17.08.94
688cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
689cdf0e10cSrcweir |*
690cdf0e10cSrcweir *************************************************************************/
Next(SvListEntry * pActEntry,sal_uInt16 * pDepth) const691cdf0e10cSrcweir SvListEntry* SvTreeList::Next( SvListEntry* pActEntry, sal_uInt16* pDepth ) const
692cdf0e10cSrcweir {
693cdf0e10cSrcweir     DBG_ASSERT( pActEntry && pActEntry->pParent, "SvTreeList::Next: invalid entry/parent!" );
694cdf0e10cSrcweir     if ( !pActEntry || !pActEntry->pParent )
695cdf0e10cSrcweir         return NULL;
696cdf0e10cSrcweir 
697cdf0e10cSrcweir 	sal_uInt16 nDepth = 0;
698cdf0e10cSrcweir 	int bWithDepth = sal_False;
699cdf0e10cSrcweir 	if ( pDepth )
700cdf0e10cSrcweir 	{
701cdf0e10cSrcweir 		nDepth = *pDepth;
702cdf0e10cSrcweir 		bWithDepth = sal_True;
703cdf0e10cSrcweir 	}
704cdf0e10cSrcweir 
705cdf0e10cSrcweir 	SvTreeEntryList* pActualList = pActEntry->pParent->pChilds;
706cdf0e10cSrcweir 	sal_uLong nActualPos = pActEntry->GetChildListPos();
707cdf0e10cSrcweir 
708cdf0e10cSrcweir 	if ( pActEntry->pChilds /* && pActEntry->pChilds->Count() */ )
709cdf0e10cSrcweir 	{
710cdf0e10cSrcweir 		nDepth++;
711cdf0e10cSrcweir 		pActEntry = (SvListEntry*)(pActEntry->pChilds->GetObject(0));
712cdf0e10cSrcweir 		if ( bWithDepth )
713cdf0e10cSrcweir 			*pDepth = nDepth;
714cdf0e10cSrcweir 		return pActEntry;
715cdf0e10cSrcweir 	}
716cdf0e10cSrcweir 
717cdf0e10cSrcweir 	if ( pActualList->Count() > ( nActualPos + 1 ) )
718cdf0e10cSrcweir 	{
719cdf0e10cSrcweir 		pActEntry = (SvListEntry*)(pActualList->GetObject( nActualPos + 1 ));
720cdf0e10cSrcweir 		if ( bWithDepth )
721cdf0e10cSrcweir 			*pDepth = nDepth;
722cdf0e10cSrcweir 		return pActEntry;
723cdf0e10cSrcweir 	}
724cdf0e10cSrcweir 
725cdf0e10cSrcweir 	SvListEntry* pParent = pActEntry->pParent;
726cdf0e10cSrcweir 	nDepth--;
727cdf0e10cSrcweir 	while( pParent != pRootItem && pParent != 0 )
728cdf0e10cSrcweir 	{
729cdf0e10cSrcweir 		DBG_ASSERT(pParent!=0,"TreeData corrupt!");
730cdf0e10cSrcweir 		pActualList = pParent->pParent->pChilds;
731cdf0e10cSrcweir 		DBG_ASSERT(pActualList,"TreeData corrupt!");
732cdf0e10cSrcweir 		nActualPos = pParent->GetChildListPos();
733cdf0e10cSrcweir 		if ( pActualList->Count() > ( nActualPos + 1 ) )
734cdf0e10cSrcweir 		{
735cdf0e10cSrcweir 			pActEntry = (SvListEntry*)(pActualList->GetObject( nActualPos + 1 ));
736cdf0e10cSrcweir 			if ( bWithDepth )
737cdf0e10cSrcweir 				*pDepth = nDepth;
738cdf0e10cSrcweir 			return pActEntry;
739cdf0e10cSrcweir 		}
740cdf0e10cSrcweir 		pParent = pParent->pParent;
741cdf0e10cSrcweir 		nDepth--;
742cdf0e10cSrcweir 	}
743cdf0e10cSrcweir 	return 0;
744cdf0e10cSrcweir }
745cdf0e10cSrcweir 
746cdf0e10cSrcweir /*************************************************************************
747cdf0e10cSrcweir |*
748cdf0e10cSrcweir |*    SvTreeList::Prev
749cdf0e10cSrcweir |*
750cdf0e10cSrcweir |*    Beschreibung
751cdf0e10cSrcweir |*    Ersterstellung    17.08.94
752cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
753cdf0e10cSrcweir |*
754cdf0e10cSrcweir *************************************************************************/
Prev(SvListEntry * pActEntry,sal_uInt16 * pDepth) const755cdf0e10cSrcweir SvListEntry* SvTreeList::Prev( SvListEntry* pActEntry, sal_uInt16* pDepth ) const
756cdf0e10cSrcweir {
757cdf0e10cSrcweir 	DBG_ASSERT(pActEntry!=0,"Entry?");
758cdf0e10cSrcweir 
759cdf0e10cSrcweir 	sal_uInt16 nDepth = 0;
760cdf0e10cSrcweir 	int bWithDepth = sal_False;
761cdf0e10cSrcweir 	if ( pDepth )
762cdf0e10cSrcweir 	{
763cdf0e10cSrcweir 		nDepth = *pDepth;
764cdf0e10cSrcweir 		bWithDepth = sal_True;
765cdf0e10cSrcweir 	}
766cdf0e10cSrcweir 
767cdf0e10cSrcweir 	SvTreeEntryList* pActualList = pActEntry->pParent->pChilds;
768cdf0e10cSrcweir 	sal_uLong nActualPos = pActEntry->GetChildListPos();
769cdf0e10cSrcweir 
770cdf0e10cSrcweir 	if ( nActualPos > 0 )
771cdf0e10cSrcweir 	{
772cdf0e10cSrcweir 		pActEntry = (SvListEntry*)(pActualList->GetObject( nActualPos - 1 ));
773cdf0e10cSrcweir 		while( pActEntry->pChilds /* && pActEntry->pChilds->Count() */ )
774cdf0e10cSrcweir 		{
775cdf0e10cSrcweir 			pActualList = pActEntry->pChilds;
776cdf0e10cSrcweir 			nDepth++;
777cdf0e10cSrcweir 			pActEntry = (SvListEntry*)(pActualList->Last());
778cdf0e10cSrcweir 		}
779cdf0e10cSrcweir 		if ( bWithDepth )
780cdf0e10cSrcweir 			*pDepth = nDepth;
781cdf0e10cSrcweir 		return pActEntry;
782cdf0e10cSrcweir 	}
783cdf0e10cSrcweir 	if ( pActEntry->pParent == pRootItem )
784cdf0e10cSrcweir 		return 0;
785cdf0e10cSrcweir 
786cdf0e10cSrcweir 	pActEntry = pActEntry->pParent;
787cdf0e10cSrcweir 
788cdf0e10cSrcweir 	if ( pActEntry )
789cdf0e10cSrcweir 	{
790cdf0e10cSrcweir 		nDepth--;
791cdf0e10cSrcweir 		if ( bWithDepth )
792cdf0e10cSrcweir 			*pDepth = nDepth;
793cdf0e10cSrcweir 		return pActEntry;
794cdf0e10cSrcweir 	}
795cdf0e10cSrcweir 	return 0;
796cdf0e10cSrcweir }
797cdf0e10cSrcweir 
798cdf0e10cSrcweir /*************************************************************************
799cdf0e10cSrcweir |*
800cdf0e10cSrcweir |*    SvTreeList::
801cdf0e10cSrcweir |*
802cdf0e10cSrcweir |*    Beschreibung
803cdf0e10cSrcweir |*    Ersterstellung    17.08.94
804cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
805cdf0e10cSrcweir |*
806cdf0e10cSrcweir *************************************************************************/
807cdf0e10cSrcweir 
Last(sal_uInt16 *) const808cdf0e10cSrcweir SvListEntry* SvTreeList::Last( sal_uInt16* /* nDepth */ ) const
809cdf0e10cSrcweir {
810cdf0e10cSrcweir 	SvTreeEntryList* pActList = pRootItem->pChilds;
811cdf0e10cSrcweir //	if ( pActList->Count() == 0 )
812cdf0e10cSrcweir //		return 0;
813cdf0e10cSrcweir 	SvListEntry* pEntry = 0;
814cdf0e10cSrcweir 	while( pActList )
815cdf0e10cSrcweir 	{
816cdf0e10cSrcweir 		pEntry = (SvListEntry*)(pActList->Last());
817cdf0e10cSrcweir 		pActList = pEntry->pChilds;
818cdf0e10cSrcweir //		if ( pActList->Count() == 0 )
819cdf0e10cSrcweir //			pActList = 0;
820cdf0e10cSrcweir 	}
821cdf0e10cSrcweir 	return pEntry;
822cdf0e10cSrcweir }
823cdf0e10cSrcweir 
824cdf0e10cSrcweir /*************************************************************************
825cdf0e10cSrcweir |*
826cdf0e10cSrcweir |*    SvTreeList::
827cdf0e10cSrcweir |*
828cdf0e10cSrcweir |*    Beschreibung
829cdf0e10cSrcweir |*    Ersterstellung    17.08.94
830cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
831cdf0e10cSrcweir |*
832cdf0e10cSrcweir *************************************************************************/
833cdf0e10cSrcweir 
GetVisiblePos(const SvListView * pView,SvListEntry * pEntry) const834cdf0e10cSrcweir sal_uLong SvTreeList::GetVisiblePos( const SvListView* pView, SvListEntry* pEntry ) const
835cdf0e10cSrcweir {
836cdf0e10cSrcweir 	DBG_ASSERT(pView&&pEntry,"View/Entry?");
837cdf0e10cSrcweir 
838cdf0e10cSrcweir 	if ( !pView->bVisPositionsValid )
839cdf0e10cSrcweir 	{
840cdf0e10cSrcweir 		// damit GetVisibleCount die Positionen aktualisiert
841cdf0e10cSrcweir 		((SvListView*)pView)->nVisibleCount = 0;
842cdf0e10cSrcweir 		GetVisibleCount( pView );
843cdf0e10cSrcweir 	}
844cdf0e10cSrcweir 	SvViewData* pViewData = pView->GetViewData( pEntry );
845cdf0e10cSrcweir 	return pViewData->nVisPos;
846cdf0e10cSrcweir }
847cdf0e10cSrcweir 
848cdf0e10cSrcweir /*************************************************************************
849cdf0e10cSrcweir |*
850cdf0e10cSrcweir |*    SvTreeList::
851cdf0e10cSrcweir |*
852cdf0e10cSrcweir |*    Beschreibung
853cdf0e10cSrcweir |*    Ersterstellung    17.08.94
854cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
855cdf0e10cSrcweir |*
856cdf0e10cSrcweir *************************************************************************/
857cdf0e10cSrcweir 
GetVisibleCount(const SvListView * pView) const858cdf0e10cSrcweir sal_uLong SvTreeList::GetVisibleCount( const SvListView* pView ) const
859cdf0e10cSrcweir {
860cdf0e10cSrcweir 	DBG_ASSERT(pView,"GetVisCount:No View");
861cdf0e10cSrcweir 	if( !pView->HasViewData() )
862cdf0e10cSrcweir 		return 0;
863cdf0e10cSrcweir 	if ( pView->nVisibleCount )
864cdf0e10cSrcweir 		return pView->nVisibleCount;
865cdf0e10cSrcweir 
866cdf0e10cSrcweir 	sal_uLong nPos = 0;
867cdf0e10cSrcweir 	SvListEntry* pEntry = First();  // erster Eintrag immer sichtbar
868cdf0e10cSrcweir 	while ( pEntry )
869cdf0e10cSrcweir 	{
870cdf0e10cSrcweir 		SvViewData* pViewData = pView->GetViewData( pEntry );
871cdf0e10cSrcweir 		pViewData->nVisPos = nPos;
872cdf0e10cSrcweir 		nPos++;
873cdf0e10cSrcweir 		pEntry = NextVisible( pView, pEntry );
874cdf0e10cSrcweir 	}
875cdf0e10cSrcweir #ifdef DBG_UTIL
876cdf0e10cSrcweir 	if( nPos > 10000000 )
877cdf0e10cSrcweir 	{
878cdf0e10cSrcweir 		DBG_ERROR("nVisibleCount bad");
879cdf0e10cSrcweir 	}
880cdf0e10cSrcweir #endif
881cdf0e10cSrcweir 	((SvListView*)pView)->nVisibleCount = nPos;
882cdf0e10cSrcweir 	((SvListView*)pView)->bVisPositionsValid = sal_True;
883cdf0e10cSrcweir 	return nPos;
884cdf0e10cSrcweir }
885cdf0e10cSrcweir 
886cdf0e10cSrcweir 
887cdf0e10cSrcweir /*************************************************************************
888cdf0e10cSrcweir |*
889cdf0e10cSrcweir |*    SvTreeList::
890cdf0e10cSrcweir |*
891cdf0e10cSrcweir |*    Beschreibung
892cdf0e10cSrcweir |*    Ersterstellung    17.08.94
893cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
894cdf0e10cSrcweir |*
895cdf0e10cSrcweir *************************************************************************/
896cdf0e10cSrcweir 
897cdf0e10cSrcweir // Funktion geht aus Geschwindigkeitsgruenden davon aus,
898cdf0e10cSrcweir // das der uebergebene Eintrag bereits sichtbar ist
899cdf0e10cSrcweir 
NextVisible(const SvListView * pView,SvListEntry * pActEntry,sal_uInt16 * pActDepth) const900cdf0e10cSrcweir SvListEntry* SvTreeList::NextVisible(const SvListView* pView,SvListEntry* pActEntry,sal_uInt16* pActDepth) const
901cdf0e10cSrcweir {
902cdf0e10cSrcweir 	DBG_ASSERT(pView,"NextVisible:No View");
903cdf0e10cSrcweir 	if ( !pActEntry )
904cdf0e10cSrcweir 		return 0;
905cdf0e10cSrcweir 
906cdf0e10cSrcweir 	sal_uInt16 nDepth = 0;
907cdf0e10cSrcweir 	int bWithDepth = sal_False;
908cdf0e10cSrcweir 	if ( pActDepth )
909cdf0e10cSrcweir 	{
910cdf0e10cSrcweir 		nDepth = *pActDepth;
911cdf0e10cSrcweir 		bWithDepth = sal_True;
912cdf0e10cSrcweir 	}
913cdf0e10cSrcweir 
914cdf0e10cSrcweir 	SvTreeEntryList* pActualList = pActEntry->pParent->pChilds;
915cdf0e10cSrcweir 	sal_uLong nActualPos = pActEntry->GetChildListPos();
916cdf0e10cSrcweir 
917cdf0e10cSrcweir 	if ( pView->IsExpanded(pActEntry) )
918cdf0e10cSrcweir 	{
919cdf0e10cSrcweir 		DBG_ASSERT(pActEntry->pChilds,"Childs?");
920cdf0e10cSrcweir 		nDepth++;
921cdf0e10cSrcweir 		pActEntry = (SvListEntry*)(pActEntry->pChilds->GetObject(0));
922cdf0e10cSrcweir 		if ( bWithDepth )
923cdf0e10cSrcweir 			*pActDepth = nDepth;
924cdf0e10cSrcweir 		return pActEntry;
925cdf0e10cSrcweir 	}
926cdf0e10cSrcweir 
927cdf0e10cSrcweir 	nActualPos++;
928cdf0e10cSrcweir 	if ( pActualList->Count() > nActualPos  )
929cdf0e10cSrcweir 	{
930cdf0e10cSrcweir 		pActEntry = (SvListEntry*)(pActualList->GetObject( nActualPos ));
931cdf0e10cSrcweir 		if ( bWithDepth )
932cdf0e10cSrcweir 			*pActDepth = nDepth;
933cdf0e10cSrcweir 		return pActEntry;
934cdf0e10cSrcweir 	}
935cdf0e10cSrcweir 
936cdf0e10cSrcweir 	SvListEntry* pParent = pActEntry->pParent;
937cdf0e10cSrcweir 	nDepth--;
938cdf0e10cSrcweir 	while( pParent != pRootItem )
939cdf0e10cSrcweir 	{
940cdf0e10cSrcweir 		pActualList = pParent->pParent->pChilds;
941cdf0e10cSrcweir 		nActualPos = pParent->GetChildListPos();
942cdf0e10cSrcweir 		nActualPos++;
943cdf0e10cSrcweir 		if ( pActualList->Count() > nActualPos )
944cdf0e10cSrcweir 		{
945cdf0e10cSrcweir 			pActEntry = (SvListEntry*)(pActualList->GetObject( nActualPos ));
946cdf0e10cSrcweir 			if ( bWithDepth )
947cdf0e10cSrcweir 				*pActDepth = nDepth;
948cdf0e10cSrcweir 			return pActEntry;
949cdf0e10cSrcweir 		}
950cdf0e10cSrcweir 		pParent = pParent->pParent;
951cdf0e10cSrcweir 		nDepth--;
952cdf0e10cSrcweir 	}
953cdf0e10cSrcweir 	return 0;
954cdf0e10cSrcweir }
955cdf0e10cSrcweir 
956cdf0e10cSrcweir 
957cdf0e10cSrcweir /*************************************************************************
958cdf0e10cSrcweir |*
959cdf0e10cSrcweir |*    SvTreeList::
960cdf0e10cSrcweir |*
961cdf0e10cSrcweir |*    Beschreibung
962cdf0e10cSrcweir |*    Ersterstellung    17.08.94
963cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
964cdf0e10cSrcweir |*
965cdf0e10cSrcweir *************************************************************************/
966cdf0e10cSrcweir 
967cdf0e10cSrcweir // Funktion geht aus Geschwindigkeitsgruenden davon aus,
968cdf0e10cSrcweir // das der uebergebene Eintrag bereits sichtbar ist
969cdf0e10cSrcweir 
PrevVisible(const SvListView * pView,SvListEntry * pActEntry,sal_uInt16 * pActDepth) const970cdf0e10cSrcweir SvListEntry* SvTreeList::PrevVisible(const SvListView* pView, SvListEntry* pActEntry, sal_uInt16* pActDepth) const
971cdf0e10cSrcweir {
972cdf0e10cSrcweir 	DBG_ASSERT(pView&&pActEntry,"PrevVis:View/Entry?");
973cdf0e10cSrcweir 
974cdf0e10cSrcweir 	sal_uInt16 nDepth = 0;
975cdf0e10cSrcweir 	int bWithDepth = sal_False;
976cdf0e10cSrcweir 	if ( pActDepth )
977cdf0e10cSrcweir 	{
978cdf0e10cSrcweir 		nDepth = *pActDepth;
979cdf0e10cSrcweir 		bWithDepth = sal_True;
980cdf0e10cSrcweir 	}
981cdf0e10cSrcweir 
982cdf0e10cSrcweir 	SvTreeEntryList* pActualList = pActEntry->pParent->pChilds;
983cdf0e10cSrcweir 	sal_uLong nActualPos = pActEntry->GetChildListPos();
984cdf0e10cSrcweir 
985cdf0e10cSrcweir 	if ( nActualPos > 0 )
986cdf0e10cSrcweir 	{
987cdf0e10cSrcweir 		pActEntry = (SvListEntry*)(pActualList->GetObject( nActualPos - 1 ));
988cdf0e10cSrcweir 		while( pView->IsExpanded(pActEntry) )
989cdf0e10cSrcweir 		{
990cdf0e10cSrcweir 			pActualList = pActEntry->pChilds;
991cdf0e10cSrcweir 			nDepth++;
992cdf0e10cSrcweir 			pActEntry = (SvListEntry*)(pActualList->Last());
993cdf0e10cSrcweir 		}
994cdf0e10cSrcweir 		if ( bWithDepth )
995cdf0e10cSrcweir 			*pActDepth = nDepth;
996cdf0e10cSrcweir 		return pActEntry;
997cdf0e10cSrcweir 	}
998cdf0e10cSrcweir 
999cdf0e10cSrcweir 	if ( pActEntry->pParent == pRootItem )
1000cdf0e10cSrcweir 		return 0;
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir 	pActEntry = pActEntry->pParent;
1003cdf0e10cSrcweir 	if ( pActEntry )
1004cdf0e10cSrcweir 	{
1005cdf0e10cSrcweir 		nDepth--;
1006cdf0e10cSrcweir 		if ( bWithDepth )
1007cdf0e10cSrcweir 			*pActDepth = nDepth;
1008cdf0e10cSrcweir 		return pActEntry;
1009cdf0e10cSrcweir 	}
1010cdf0e10cSrcweir 	return 0;
1011cdf0e10cSrcweir }
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir /*************************************************************************
1014cdf0e10cSrcweir |*
1015cdf0e10cSrcweir |*    SvTreeList::
1016cdf0e10cSrcweir |*
1017cdf0e10cSrcweir |*    Beschreibung
1018cdf0e10cSrcweir |*    Ersterstellung    17.08.94
1019cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
1020cdf0e10cSrcweir |*
1021cdf0e10cSrcweir *************************************************************************/
1022cdf0e10cSrcweir 
LastVisible(const SvListView * pView,sal_uInt16 * pDepth) const1023cdf0e10cSrcweir SvListEntry* SvTreeList::LastVisible( const SvListView* pView, sal_uInt16* pDepth) const
1024cdf0e10cSrcweir {
1025cdf0e10cSrcweir 	DBG_ASSERT(pView,"LastVis:No View");
1026cdf0e10cSrcweir 	SvListEntry* pEntry = Last();
1027cdf0e10cSrcweir 	while( pEntry && !IsEntryVisible( pView, pEntry ) )
1028cdf0e10cSrcweir 		pEntry = PrevVisible( pView, pEntry );
1029cdf0e10cSrcweir 	if ( pEntry && pDepth )
1030cdf0e10cSrcweir 		*pDepth = GetDepth( pEntry );
1031cdf0e10cSrcweir 	return pEntry;
1032cdf0e10cSrcweir }
1033cdf0e10cSrcweir 
1034cdf0e10cSrcweir /*************************************************************************
1035cdf0e10cSrcweir |*
1036cdf0e10cSrcweir |*    SvTreeList::
1037cdf0e10cSrcweir |*
1038cdf0e10cSrcweir |*    Beschreibung
1039cdf0e10cSrcweir |*    Ersterstellung    17.08.94
1040cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
1041cdf0e10cSrcweir |*
1042cdf0e10cSrcweir *************************************************************************/
1043cdf0e10cSrcweir 
NextVisible(const SvListView * pView,SvListEntry * pEntry,sal_uInt16 & nDelta) const1044cdf0e10cSrcweir SvListEntry* SvTreeList::NextVisible(const SvListView* pView,SvListEntry* pEntry,sal_uInt16& nDelta) const
1045cdf0e10cSrcweir {
1046cdf0e10cSrcweir 	DBG_ASSERT(pView&&pEntry&&IsEntryVisible(pView,pEntry),"NextVis:Wrong Prms/!Vis");
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir 	sal_uLong nVisPos = GetVisiblePos( pView, pEntry );
1049cdf0e10cSrcweir 	// nDelta Eintraege vorhanden ?
1050cdf0e10cSrcweir 	// Beispiel: 0,1,2,3,4,5,6,7,8,9 nVisPos=5 nDelta=7
1051cdf0e10cSrcweir 	//           nNewDelta = 10-nVisPos-1 == 4
1052cdf0e10cSrcweir 	if (  nVisPos+nDelta >= pView->nVisibleCount )
1053cdf0e10cSrcweir 	{
1054cdf0e10cSrcweir 		nDelta = (sal_uInt16)(pView->nVisibleCount-nVisPos);
1055cdf0e10cSrcweir 		nDelta--;
1056cdf0e10cSrcweir 	}
1057cdf0e10cSrcweir 	sal_uInt16 nDeltaTmp = nDelta;
1058cdf0e10cSrcweir 	while( nDeltaTmp )
1059cdf0e10cSrcweir 	{
1060cdf0e10cSrcweir 		pEntry = NextVisible( pView, pEntry );
1061cdf0e10cSrcweir 		nDeltaTmp--;
1062cdf0e10cSrcweir 		DBG_ASSERT(pEntry,"Entry?");
1063cdf0e10cSrcweir 	}
1064cdf0e10cSrcweir 	return pEntry;
1065cdf0e10cSrcweir }
1066cdf0e10cSrcweir 
1067cdf0e10cSrcweir /*************************************************************************
1068cdf0e10cSrcweir |*
1069cdf0e10cSrcweir |*    SvTreeList::
1070cdf0e10cSrcweir |*
1071cdf0e10cSrcweir |*    Beschreibung
1072cdf0e10cSrcweir |*    Ersterstellung    17.08.94
1073cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
1074cdf0e10cSrcweir |*
1075cdf0e10cSrcweir *************************************************************************/
1076cdf0e10cSrcweir 
PrevVisible(const SvListView * pView,SvListEntry * pEntry,sal_uInt16 & nDelta) const1077cdf0e10cSrcweir SvListEntry* SvTreeList::PrevVisible( const SvListView* pView, SvListEntry* pEntry, sal_uInt16& nDelta ) const
1078cdf0e10cSrcweir {
1079cdf0e10cSrcweir 	DBG_ASSERT(pView&&pEntry&&IsEntryVisible(pView,pEntry),"PrevVis:Parms/!Vis");
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir 	sal_uLong nVisPos = GetVisiblePos( pView, pEntry );
1082cdf0e10cSrcweir 	// nDelta Eintraege vorhanden ?
1083cdf0e10cSrcweir 	// Beispiel: 0,1,2,3,4,5,6,7,8,9 nVisPos=8 nDelta=20
1084cdf0e10cSrcweir 	//           nNewDelta = nNewVisPos
1085cdf0e10cSrcweir 	if (  nDelta > nVisPos )
1086cdf0e10cSrcweir 		nDelta = (sal_uInt16)nVisPos;
1087cdf0e10cSrcweir 	sal_uInt16 nDeltaTmp = nDelta;
1088cdf0e10cSrcweir 	while( nDeltaTmp )
1089cdf0e10cSrcweir 	{
1090cdf0e10cSrcweir 		pEntry = PrevVisible( pView, pEntry );
1091cdf0e10cSrcweir 		nDeltaTmp--;
1092cdf0e10cSrcweir 		DBG_ASSERT(pEntry,"Entry?");
1093cdf0e10cSrcweir 	}
1094cdf0e10cSrcweir 	return pEntry;
1095cdf0e10cSrcweir }
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir /*************************************************************************
1098cdf0e10cSrcweir |*
1099cdf0e10cSrcweir |*    SvTreeList::
1100cdf0e10cSrcweir |*
1101cdf0e10cSrcweir |*    Beschreibung
1102cdf0e10cSrcweir |*    Ersterstellung    17.08.94
1103cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
1104cdf0e10cSrcweir |*
1105cdf0e10cSrcweir *************************************************************************/
1106cdf0e10cSrcweir 
FirstSelected(const SvListView * pView) const1107cdf0e10cSrcweir SvListEntry* SvTreeList::FirstSelected( const SvListView* pView) const
1108cdf0e10cSrcweir {
1109cdf0e10cSrcweir 	DBG_ASSERT(pView,"FirstSel:No View");
1110cdf0e10cSrcweir 	if( !pView )
1111cdf0e10cSrcweir 		return 0;
1112cdf0e10cSrcweir 	SvListEntry* pActSelEntry = First();
1113cdf0e10cSrcweir 	while( pActSelEntry && !pView->IsSelected(pActSelEntry) )
1114cdf0e10cSrcweir 		pActSelEntry = NextVisible( pView, pActSelEntry );
1115cdf0e10cSrcweir 	return pActSelEntry;
1116cdf0e10cSrcweir }
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir 
FirstChild(SvListEntry * pParent) const1119cdf0e10cSrcweir SvListEntry* SvTreeList::FirstChild( SvListEntry* pParent ) const
1120cdf0e10cSrcweir {
1121cdf0e10cSrcweir 	if ( !pParent )
1122cdf0e10cSrcweir 		pParent = pRootItem;
1123cdf0e10cSrcweir 	SvListEntry* pResult;
1124cdf0e10cSrcweir 	if ( pParent->pChilds )
1125cdf0e10cSrcweir 		pResult = (SvListEntry*)(pParent->pChilds->GetObject( 0 ));
1126cdf0e10cSrcweir 	else
1127cdf0e10cSrcweir 		pResult = 0;
1128cdf0e10cSrcweir 	return pResult;
1129cdf0e10cSrcweir }
1130cdf0e10cSrcweir 
NextSibling(SvListEntry * pEntry) const1131cdf0e10cSrcweir SvListEntry* SvTreeList::NextSibling( SvListEntry* pEntry ) const
1132cdf0e10cSrcweir {
1133cdf0e10cSrcweir 	DBG_ASSERT(pEntry,"Entry?");
1134cdf0e10cSrcweir 	if( !pEntry )
1135cdf0e10cSrcweir 		return 0;
1136cdf0e10cSrcweir 	SvTreeEntryList* pList = pEntry->pParent->pChilds;
1137cdf0e10cSrcweir //	sal_uLong nPos = pList->GetPos( pEntry );
1138cdf0e10cSrcweir 	sal_uLong nPos = pEntry->GetChildListPos();
1139cdf0e10cSrcweir 	nPos++;
1140cdf0e10cSrcweir 	pEntry = (SvListEntry*)(pList->GetObject( nPos ));
1141cdf0e10cSrcweir 	return pEntry;
1142cdf0e10cSrcweir }
1143cdf0e10cSrcweir 
PrevSibling(SvListEntry * pEntry) const1144cdf0e10cSrcweir SvListEntry* SvTreeList::PrevSibling( SvListEntry* pEntry ) const
1145cdf0e10cSrcweir {
1146cdf0e10cSrcweir 	DBG_ASSERT(pEntry,"Entry?");
1147cdf0e10cSrcweir 	if( !pEntry )
1148cdf0e10cSrcweir 		return 0;
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir 	SvTreeEntryList* pList = pEntry->pParent->pChilds;
1151cdf0e10cSrcweir 	// sal_uLong nPos = pList->GetPos( pEntry );
1152cdf0e10cSrcweir 	sal_uLong nPos = pEntry->GetChildListPos();
1153cdf0e10cSrcweir 	if ( nPos == 0 )
1154cdf0e10cSrcweir 		return 0;
1155cdf0e10cSrcweir 	nPos--;
1156cdf0e10cSrcweir 	pEntry = (SvListEntry*)(pList->GetObject( nPos ));
1157cdf0e10cSrcweir 	return pEntry;
1158cdf0e10cSrcweir }
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir 
LastSibling(SvListEntry * pEntry) const1161cdf0e10cSrcweir SvListEntry* SvTreeList::LastSibling( SvListEntry* pEntry ) const
1162cdf0e10cSrcweir {
1163cdf0e10cSrcweir 	DBG_ASSERT(pEntry,"LastSibling:Entry?");
1164cdf0e10cSrcweir 	if( !pEntry )
1165cdf0e10cSrcweir 		return 0;
1166cdf0e10cSrcweir 	SvListEntry* pSib = 0;
1167cdf0e10cSrcweir 	SvTreeEntryList* pSibs = pEntry->pParent->pChilds;
1168cdf0e10cSrcweir 	if ( pSibs )
1169cdf0e10cSrcweir 		pSib = (SvListEntry*)(pSibs->Last());
1170cdf0e10cSrcweir 	return pSib;
1171cdf0e10cSrcweir }
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir 
1174cdf0e10cSrcweir 
1175cdf0e10cSrcweir /*************************************************************************
1176cdf0e10cSrcweir |*
1177cdf0e10cSrcweir |*    SvTreeList::
1178cdf0e10cSrcweir |*
1179cdf0e10cSrcweir |*    Beschreibung
1180cdf0e10cSrcweir |*    Ersterstellung    17.08.94
1181cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
1182cdf0e10cSrcweir |*
1183cdf0e10cSrcweir *************************************************************************/
1184cdf0e10cSrcweir 
NextSelected(const SvListView * pView,SvListEntry * pEntry) const1185cdf0e10cSrcweir SvListEntry* SvTreeList::NextSelected( const SvListView* pView, SvListEntry* pEntry ) const
1186cdf0e10cSrcweir {
1187cdf0e10cSrcweir 	DBG_ASSERT(pView&&pEntry,"NextSel:View/Entry?");
1188cdf0e10cSrcweir 	pEntry = Next( pEntry );
1189cdf0e10cSrcweir 	while( pEntry && !pView->IsSelected(pEntry) )
1190cdf0e10cSrcweir 		pEntry = Next( pEntry );
1191cdf0e10cSrcweir 	return pEntry;
1192cdf0e10cSrcweir }
1193cdf0e10cSrcweir 
1194cdf0e10cSrcweir /*************************************************************************
1195cdf0e10cSrcweir |*
1196cdf0e10cSrcweir |*    SvTreeList::
1197cdf0e10cSrcweir |*
1198cdf0e10cSrcweir |*    Beschreibung
1199cdf0e10cSrcweir |*    Ersterstellung    17.08.94
1200cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
1201cdf0e10cSrcweir |*
1202cdf0e10cSrcweir *************************************************************************/
1203cdf0e10cSrcweir 
PrevSelected(const SvListView * pView,SvListEntry * pEntry) const1204cdf0e10cSrcweir SvListEntry* SvTreeList::PrevSelected( const SvListView* pView, SvListEntry* pEntry) const
1205cdf0e10cSrcweir {
1206cdf0e10cSrcweir 	DBG_ASSERT(pView&&pEntry,"PrevSel:View/Entry?");
1207cdf0e10cSrcweir 	pEntry = Prev( pEntry );
1208cdf0e10cSrcweir 	while( pEntry && !pView->IsSelected(pEntry) )
1209cdf0e10cSrcweir 		pEntry = Prev( pEntry );
1210cdf0e10cSrcweir 
1211cdf0e10cSrcweir 	return pEntry;
1212cdf0e10cSrcweir }
1213cdf0e10cSrcweir 
1214cdf0e10cSrcweir /*************************************************************************
1215cdf0e10cSrcweir |*
1216cdf0e10cSrcweir |*    SvTreeList::
1217cdf0e10cSrcweir |*
1218cdf0e10cSrcweir |*    Beschreibung
1219cdf0e10cSrcweir |*    Ersterstellung    17.08.94
1220cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
1221cdf0e10cSrcweir |*
1222cdf0e10cSrcweir *************************************************************************/
1223cdf0e10cSrcweir 
LastSelected(const SvListView * pView) const1224cdf0e10cSrcweir SvListEntry* SvTreeList::LastSelected( const SvListView* pView ) const
1225cdf0e10cSrcweir {
1226cdf0e10cSrcweir 	DBG_ASSERT(pView,"LastSel:No View");
1227cdf0e10cSrcweir 	SvListEntry* pEntry = Last();
1228cdf0e10cSrcweir 	while( pEntry && !pView->IsSelected(pEntry) )
1229cdf0e10cSrcweir 		pEntry = Prev( pEntry );
1230cdf0e10cSrcweir 	return pEntry;
1231cdf0e10cSrcweir }
1232cdf0e10cSrcweir 
1233cdf0e10cSrcweir /*************************************************************************
1234cdf0e10cSrcweir |*
1235cdf0e10cSrcweir |*    SvTreeList::Insert
1236cdf0e10cSrcweir |*
1237cdf0e10cSrcweir |*    Beschreibung
1238cdf0e10cSrcweir |*    Ersterstellung    17.08.94
1239cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
1240cdf0e10cSrcweir |*
1241cdf0e10cSrcweir *************************************************************************/
Insert(SvListEntry * pEntry,SvListEntry * pParent,sal_uLong nPos)1242cdf0e10cSrcweir sal_uLong SvTreeList::Insert( SvListEntry* pEntry,SvListEntry* pParent,sal_uLong nPos )
1243cdf0e10cSrcweir {
1244cdf0e10cSrcweir 	DBG_ASSERT( pEntry,"Entry?");
1245cdf0e10cSrcweir 
1246cdf0e10cSrcweir 	if ( !pParent )
1247cdf0e10cSrcweir 		pParent = pRootItem;
1248cdf0e10cSrcweir 
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir 	SvTreeEntryList* pList = pParent->pChilds;
1251cdf0e10cSrcweir 	if ( !pList )
1252cdf0e10cSrcweir 	{
1253cdf0e10cSrcweir 		// Parent bekommt zum erstenmal ein Kind
1254cdf0e10cSrcweir 		pList = new SvTreeEntryList;
1255cdf0e10cSrcweir 		pParent->pChilds = pList;
1256cdf0e10cSrcweir 	}
1257cdf0e10cSrcweir 
1258cdf0e10cSrcweir 	// Sortierung beruecksichtigen
1259cdf0e10cSrcweir 	GetInsertionPos( pEntry, pParent, nPos );
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir 	bAbsPositionsValid = sal_False;
1262cdf0e10cSrcweir 	pEntry->pParent = pParent;
1263cdf0e10cSrcweir 
1264cdf0e10cSrcweir 	pList->Insert( pEntry, nPos );
1265cdf0e10cSrcweir 	nEntryCount++;
1266cdf0e10cSrcweir 	if( nPos != LIST_APPEND && (nPos != (pList->Count()-1)) )
1267cdf0e10cSrcweir 		SetListPositions( pList );
1268cdf0e10cSrcweir 	else
1269cdf0e10cSrcweir 		pEntry->nListPos = pList->Count()-1;
1270cdf0e10cSrcweir 
1271cdf0e10cSrcweir #ifdef CHECK_INTEGRITY
1272cdf0e10cSrcweir CheckIntegrity();
1273cdf0e10cSrcweir #endif
1274cdf0e10cSrcweir 	Broadcast( LISTACTION_INSERTED, pEntry );
1275cdf0e10cSrcweir 	return nPos; // pEntry->nListPos;
1276cdf0e10cSrcweir }
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir /*************************************************************************
1279cdf0e10cSrcweir |*
1280cdf0e10cSrcweir |*    SvTreeList::
1281cdf0e10cSrcweir |*
1282cdf0e10cSrcweir |*    Beschreibung
1283cdf0e10cSrcweir |*    Ersterstellung    17.08.94
1284cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
1285cdf0e10cSrcweir |*
1286cdf0e10cSrcweir *************************************************************************/
1287cdf0e10cSrcweir 
GetAbsPos(SvListEntry * pEntry) const1288cdf0e10cSrcweir sal_uLong SvTreeList::GetAbsPos( SvListEntry* pEntry) const
1289cdf0e10cSrcweir {
1290cdf0e10cSrcweir 	if ( !bAbsPositionsValid )
1291cdf0e10cSrcweir 		((SvTreeList*)this)->SetAbsolutePositions();
1292cdf0e10cSrcweir 	return pEntry->nAbsPos;
1293cdf0e10cSrcweir }
1294cdf0e10cSrcweir 
1295cdf0e10cSrcweir /*************************************************************************
1296cdf0e10cSrcweir |*
1297cdf0e10cSrcweir |*    SvTreeList::
1298cdf0e10cSrcweir |*
1299cdf0e10cSrcweir |*    Beschreibung
1300cdf0e10cSrcweir |*    Ersterstellung    17.08.94
1301cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
1302cdf0e10cSrcweir |*
1303cdf0e10cSrcweir *************************************************************************/
1304cdf0e10cSrcweir 
SetAbsolutePositions()1305cdf0e10cSrcweir void SvTreeList::SetAbsolutePositions()
1306cdf0e10cSrcweir {
1307cdf0e10cSrcweir 	sal_uLong nPos = 0;
1308cdf0e10cSrcweir 	SvListEntry* pEntry = First();
1309cdf0e10cSrcweir 	while ( pEntry )
1310cdf0e10cSrcweir 	{
1311cdf0e10cSrcweir 		pEntry->nAbsPos = nPos;
1312cdf0e10cSrcweir 		nPos++;
1313cdf0e10cSrcweir 		pEntry = Next( pEntry );
1314cdf0e10cSrcweir 	}
1315cdf0e10cSrcweir 	bAbsPositionsValid = sal_True;
1316cdf0e10cSrcweir #ifdef CHECK_INTEGRITY
1317cdf0e10cSrcweir CheckIntegrity();
1318cdf0e10cSrcweir #endif
1319cdf0e10cSrcweir }
1320cdf0e10cSrcweir 
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir /*************************************************************************
1323cdf0e10cSrcweir |*
1324cdf0e10cSrcweir |*    SvTreeList::Expand
1325cdf0e10cSrcweir |*
1326cdf0e10cSrcweir |*    Beschreibung
1327cdf0e10cSrcweir |*    Ersterstellung    17.08.94
1328cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
1329cdf0e10cSrcweir |*
1330cdf0e10cSrcweir *************************************************************************/
1331cdf0e10cSrcweir 
Expand(SvListView * pView,SvListEntry * pEntry)1332cdf0e10cSrcweir void SvTreeList::Expand( SvListView* pView, SvListEntry* pEntry )
1333cdf0e10cSrcweir {
1334cdf0e10cSrcweir 	DBG_ASSERT(pEntry&&pView,"Expand:View/Entry?");
1335cdf0e10cSrcweir 	if ( pView->IsExpanded(pEntry) )
1336cdf0e10cSrcweir 		return;
1337cdf0e10cSrcweir 
1338cdf0e10cSrcweir 	DBG_ASSERT(pEntry->pChilds,"Expand:No Childs!");
1339cdf0e10cSrcweir 
1340cdf0e10cSrcweir 	SvViewData* pViewData = pView->GetViewData(pEntry);
1341cdf0e10cSrcweir 	pViewData->nFlags |= SVLISTENTRYFLAG_EXPANDED;
1342cdf0e10cSrcweir 	SvListEntry* pParent = pEntry->pParent;
1343cdf0e10cSrcweir 	// wenn Parent sichtbar dann Statusdaten invalidieren
1344cdf0e10cSrcweir 	if ( pView->IsExpanded( pParent ) )
1345cdf0e10cSrcweir 	{
1346cdf0e10cSrcweir 		pView->bVisPositionsValid = sal_False;
1347cdf0e10cSrcweir 		pView->nVisibleCount = 0;
1348cdf0e10cSrcweir 	}
1349cdf0e10cSrcweir #ifdef CHECK_INTEGRITY
1350cdf0e10cSrcweir CheckIntegrity();
1351cdf0e10cSrcweir #endif
1352cdf0e10cSrcweir }
1353cdf0e10cSrcweir 
1354cdf0e10cSrcweir /*************************************************************************
1355cdf0e10cSrcweir |*
1356cdf0e10cSrcweir |*    SvTreeList::Collapse
1357cdf0e10cSrcweir |*
1358cdf0e10cSrcweir |*    Beschreibung
1359cdf0e10cSrcweir |*    Ersterstellung    17.08.94
1360cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
1361cdf0e10cSrcweir |*
1362cdf0e10cSrcweir *************************************************************************/
1363cdf0e10cSrcweir 
Collapse(SvListView * pView,SvListEntry * pEntry)1364cdf0e10cSrcweir void SvTreeList::Collapse( SvListView* pView, SvListEntry* pEntry )
1365cdf0e10cSrcweir {
1366cdf0e10cSrcweir 	DBG_ASSERT(pView&&pEntry,"Collapse:View/Entry?");
1367cdf0e10cSrcweir 	if ( !pView->IsExpanded(pEntry) )
1368cdf0e10cSrcweir 		return;
1369cdf0e10cSrcweir 
1370cdf0e10cSrcweir 	DBG_ASSERT(pEntry->pChilds,"Collapse:No Childs!");
1371cdf0e10cSrcweir 
1372cdf0e10cSrcweir 	SvViewData* pViewData = pView->GetViewData( pEntry );
1373cdf0e10cSrcweir 	pViewData->nFlags &=(~SVLISTENTRYFLAG_EXPANDED);
1374cdf0e10cSrcweir 
1375cdf0e10cSrcweir 	SvListEntry* pParent = pEntry->pParent;
1376cdf0e10cSrcweir 	if ( pView->IsExpanded(pParent) )
1377cdf0e10cSrcweir 	{
1378cdf0e10cSrcweir 		pView->nVisibleCount = 0;
1379cdf0e10cSrcweir 		pView->bVisPositionsValid = sal_False;
1380cdf0e10cSrcweir 	}
1381cdf0e10cSrcweir #ifdef CHECK_INTEGRITY
1382cdf0e10cSrcweir CheckIntegrity();
1383cdf0e10cSrcweir #endif
1384cdf0e10cSrcweir }
1385cdf0e10cSrcweir 
1386cdf0e10cSrcweir 
1387cdf0e10cSrcweir /*************************************************************************
1388cdf0e10cSrcweir |*
1389cdf0e10cSrcweir |*    SvTreeList::
1390cdf0e10cSrcweir |*
1391cdf0e10cSrcweir |*    Beschreibung
1392cdf0e10cSrcweir |*    Ersterstellung    17.08.94
1393cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
1394cdf0e10cSrcweir |*
1395cdf0e10cSrcweir *************************************************************************/
1396cdf0e10cSrcweir 
Select(SvListView * pView,SvListEntry * pEntry,sal_Bool bSelect)1397cdf0e10cSrcweir sal_Bool SvTreeList::Select( SvListView* pView, SvListEntry* pEntry, sal_Bool bSelect )
1398cdf0e10cSrcweir {
1399cdf0e10cSrcweir 	DBG_ASSERT(pView&&pEntry,"Select:View/Entry?");
1400cdf0e10cSrcweir 	SvViewData* pViewData = pView->GetViewData( pEntry );
1401cdf0e10cSrcweir 	if ( bSelect )
1402cdf0e10cSrcweir 	{
1403cdf0e10cSrcweir 		if ( pViewData->IsSelected() || !pViewData->IsSelectable() )
1404cdf0e10cSrcweir 			return sal_False;
1405cdf0e10cSrcweir 		else
1406cdf0e10cSrcweir 		{
1407cdf0e10cSrcweir 			pViewData->nFlags |= SVLISTENTRYFLAG_SELECTED;
1408cdf0e10cSrcweir 			pView->nSelectionCount++;
1409cdf0e10cSrcweir 		}
1410cdf0e10cSrcweir 	}
1411cdf0e10cSrcweir 	else
1412cdf0e10cSrcweir 	{
1413cdf0e10cSrcweir 		if ( !pViewData->IsSelected() )
1414cdf0e10cSrcweir 			return sal_False;
1415cdf0e10cSrcweir 		else
1416cdf0e10cSrcweir 		{
1417cdf0e10cSrcweir 			pViewData->nFlags &= ~( SVLISTENTRYFLAG_SELECTED );
1418cdf0e10cSrcweir 			pView->nSelectionCount--;
1419cdf0e10cSrcweir 		}
1420cdf0e10cSrcweir 	}
1421cdf0e10cSrcweir #ifdef CHECK_INTEGRITY
1422cdf0e10cSrcweir CheckIntegrity();
1423cdf0e10cSrcweir #endif
1424cdf0e10cSrcweir 	return sal_True;
1425cdf0e10cSrcweir }
1426cdf0e10cSrcweir 
1427cdf0e10cSrcweir /*************************************************************************
1428cdf0e10cSrcweir |*
1429cdf0e10cSrcweir |*    SvTreeList::Remove
1430cdf0e10cSrcweir |*
1431cdf0e10cSrcweir |*    Beschreibung
1432cdf0e10cSrcweir |*    Ersterstellung    17.08.94
1433cdf0e10cSrcweir |*    Letzte Aenderung  05.04.01
1434cdf0e10cSrcweir |*
1435cdf0e10cSrcweir *************************************************************************/
Remove(SvListEntry * pEntry)1436cdf0e10cSrcweir sal_Bool SvTreeList::Remove( SvListEntry* pEntry )
1437cdf0e10cSrcweir {
1438cdf0e10cSrcweir 	DBG_ASSERT(pEntry,"Cannot remove root, use clear");
1439cdf0e10cSrcweir 
1440cdf0e10cSrcweir 	if( !pEntry->pParent )
1441cdf0e10cSrcweir 	{
1442cdf0e10cSrcweir 		DBG_ERROR("Removing entry not in model!");
1443cdf0e10cSrcweir 		// unter gewissen Umstaenden (welche?) loescht der
1444cdf0e10cSrcweir 		// Explorer aus der View Eintraege, die er nicht in die View
1445cdf0e10cSrcweir 		// eingefuegt hat. Da sich der Kunde fuer ein platzendes
1446cdf0e10cSrcweir 		// Office nichts kaufen kann, fange ich diesen Fall ab.
1447cdf0e10cSrcweir 		return sal_False;
1448cdf0e10cSrcweir 	}
1449cdf0e10cSrcweir 
1450cdf0e10cSrcweir 	Broadcast( LISTACTION_REMOVING, pEntry );
1451cdf0e10cSrcweir 	sal_uLong nRemoved = 1 + GetChildCount(pEntry);
1452cdf0e10cSrcweir 	bAbsPositionsValid = sal_False;
1453cdf0e10cSrcweir 
1454cdf0e10cSrcweir 	SvListEntry* pParent = pEntry->pParent;
1455cdf0e10cSrcweir 	SvTreeEntryList* pList = pParent->pChilds;
1456cdf0e10cSrcweir 	DBG_ASSERT(pList,"Remove:No Childlist");
1457cdf0e10cSrcweir 	sal_Bool bLastEntry = sal_False;
1458cdf0e10cSrcweir 
1459cdf0e10cSrcweir 	if ( pEntry->HasChildListPos() )
1460cdf0e10cSrcweir 	{
1461cdf0e10cSrcweir 		sal_uLong nListPos = pEntry->GetChildListPos();
1462cdf0e10cSrcweir 		bLastEntry = (nListPos == (pList->Count()-1) ) ? sal_True : sal_False;
1463cdf0e10cSrcweir 		pList->Remove( nListPos );
1464cdf0e10cSrcweir 	}
1465cdf0e10cSrcweir 	else
1466cdf0e10cSrcweir 	{
1467cdf0e10cSrcweir 		pList->Remove( (void*) pEntry );
1468cdf0e10cSrcweir 	}
1469cdf0e10cSrcweir 
1470cdf0e10cSrcweir 
1471cdf0e10cSrcweir 	// moved to end of method because it is used later with Broadcast
1472cdf0e10cSrcweir 	// delete pEntry; // loescht auch alle Childs
1473cdf0e10cSrcweir 
1474cdf0e10cSrcweir 	if ( pList->Count() == 0 )
1475cdf0e10cSrcweir 	{
1476cdf0e10cSrcweir 		pParent->pChilds = 0;
1477cdf0e10cSrcweir 		delete pList;
1478cdf0e10cSrcweir 	}
1479cdf0e10cSrcweir 	else
1480cdf0e10cSrcweir 	{
1481cdf0e10cSrcweir 		if( !bLastEntry )
1482cdf0e10cSrcweir 			SetListPositions( pList );
1483cdf0e10cSrcweir 	}
1484cdf0e10cSrcweir 	nEntryCount -= nRemoved;
1485cdf0e10cSrcweir 
1486cdf0e10cSrcweir #ifdef CHECK_INTEGRITY
1487cdf0e10cSrcweir CheckIntegrity();
1488cdf0e10cSrcweir #endif
1489cdf0e10cSrcweir 	Broadcast( LISTACTION_REMOVED, pEntry );
1490cdf0e10cSrcweir 
1491cdf0e10cSrcweir 	delete pEntry; // loescht auch alle Childs
1492cdf0e10cSrcweir 	return sal_True;
1493cdf0e10cSrcweir }
1494cdf0e10cSrcweir 
1495cdf0e10cSrcweir /*************************************************************************
1496cdf0e10cSrcweir |*
1497cdf0e10cSrcweir |*    SvTreeList::
1498cdf0e10cSrcweir |*
1499cdf0e10cSrcweir |*    Beschreibung
1500cdf0e10cSrcweir |*    Ersterstellung    17.08.94
1501cdf0e10cSrcweir |*    Letzte Aenderung  17.08.94
1502cdf0e10cSrcweir |*
1503cdf0e10cSrcweir *************************************************************************/
1504cdf0e10cSrcweir 
SelectChilds(SvListView * pView,SvListEntry * pParent,sal_Bool bSelect)1505cdf0e10cSrcweir sal_uLong SvTreeList::SelectChilds(SvListView* pView, SvListEntry* pParent,sal_Bool bSelect )
1506cdf0e10cSrcweir {
1507cdf0e10cSrcweir 	DBG_ASSERT(pView&&pParent,"SelChilds:View/Parent?");
1508cdf0e10cSrcweir 	if ( !pParent->pChilds )
1509cdf0e10cSrcweir 		return 0;
1510cdf0e10cSrcweir 	if ( pParent->pChilds->Count() == 0 )
1511cdf0e10cSrcweir 		return 0;
1512cdf0e10cSrcweir 
1513cdf0e10cSrcweir 	sal_uInt16 nRefDepth = GetDepth( pParent );
1514cdf0e10cSrcweir 	sal_uInt16 nDepth = nRefDepth;
1515cdf0e10cSrcweir 	sal_uLong nCount = 0;
1516cdf0e10cSrcweir 	pParent = Next( pParent );
1517cdf0e10cSrcweir 	do
1518cdf0e10cSrcweir 	{
1519cdf0e10cSrcweir 		if ( Select( pView, pParent, bSelect ) )
1520cdf0e10cSrcweir 			nCount++; // nur die tatsaechlichen Selektierungen zaehlen
1521cdf0e10cSrcweir 		pParent = Next( pParent, &nDepth );
1522cdf0e10cSrcweir 	}
1523cdf0e10cSrcweir 	while( pParent && nDepth > nRefDepth );
1524cdf0e10cSrcweir #ifdef CHECK_INTEGRITY
1525cdf0e10cSrcweir CheckIntegrity();
1526cdf0e10cSrcweir #endif
1527cdf0e10cSrcweir 	return nCount;
1528cdf0e10cSrcweir }
1529cdf0e10cSrcweir 
SelectAll(SvListView * pView,sal_Bool bSelect)1530cdf0e10cSrcweir void SvTreeList::SelectAll( SvListView* pView, sal_Bool bSelect )
1531cdf0e10cSrcweir {
1532cdf0e10cSrcweir 	DBG_ASSERT(pView,"SelectAll:NoView");
1533cdf0e10cSrcweir 	SvListEntry* pEntry = First();
1534cdf0e10cSrcweir 	while ( pEntry )
1535cdf0e10cSrcweir 	{
1536cdf0e10cSrcweir 		SvViewData* pViewData = pView->GetViewData( pEntry );
1537cdf0e10cSrcweir 		if ( bSelect )
1538cdf0e10cSrcweir 			pViewData->nFlags |= SVLISTENTRYFLAG_SELECTED;
1539cdf0e10cSrcweir 		else
1540cdf0e10cSrcweir 			pViewData->nFlags &= (~SVLISTENTRYFLAG_SELECTED);
1541cdf0e10cSrcweir 
1542cdf0e10cSrcweir 		pEntry = Next( pEntry );
1543cdf0e10cSrcweir 	}
1544cdf0e10cSrcweir 	if ( bSelect )
1545cdf0e10cSrcweir 		pView->nSelectionCount = nEntryCount;
1546cdf0e10cSrcweir 	else
1547cdf0e10cSrcweir 		pView->nSelectionCount = 0;
1548cdf0e10cSrcweir #ifdef CHECK_INTEGRITY
1549cdf0e10cSrcweir CheckIntegrity();
1550cdf0e10cSrcweir #endif
1551cdf0e10cSrcweir }
1552cdf0e10cSrcweir 
1553cdf0e10cSrcweir 
GetEntryAtAbsPos(sal_uLong nAbsPos) const1554cdf0e10cSrcweir SvListEntry* SvTreeList::GetEntryAtAbsPos( sal_uLong nAbsPos ) const
1555cdf0e10cSrcweir {
1556cdf0e10cSrcweir 	SvListEntry* pEntry = First();
1557cdf0e10cSrcweir 	while ( nAbsPos && pEntry )
1558cdf0e10cSrcweir 	{
1559cdf0e10cSrcweir 		pEntry = Next( pEntry );
1560cdf0e10cSrcweir 		nAbsPos--;
1561cdf0e10cSrcweir 	}
1562cdf0e10cSrcweir 	return pEntry;
1563cdf0e10cSrcweir }
1564cdf0e10cSrcweir 
GetEntryAtVisPos(const SvListView * pView,sal_uLong nVisPos) const1565cdf0e10cSrcweir SvListEntry* SvTreeList::GetEntryAtVisPos( const SvListView* pView, sal_uLong nVisPos ) const
1566cdf0e10cSrcweir {
1567cdf0e10cSrcweir 	DBG_ASSERT(pView,"GetEntryAtVisPos:No View");
1568cdf0e10cSrcweir 	SvListEntry* pEntry = First();
1569cdf0e10cSrcweir 	while ( nVisPos && pEntry )
1570cdf0e10cSrcweir 	{
1571cdf0e10cSrcweir 		pEntry = NextVisible( pView, pEntry );
1572cdf0e10cSrcweir 		nVisPos--;
1573cdf0e10cSrcweir 	}
1574cdf0e10cSrcweir 	return pEntry;
1575cdf0e10cSrcweir }
1576cdf0e10cSrcweir 
SetListPositions(SvTreeEntryList * pList)1577cdf0e10cSrcweir void SvTreeList::SetListPositions( SvTreeEntryList* pList )
1578cdf0e10cSrcweir {
1579cdf0e10cSrcweir 	if( pList->Count() )
1580cdf0e10cSrcweir 	{
1581cdf0e10cSrcweir 		SvListEntry* pEntry = (SvListEntry*)(pList->GetObject(0));
1582cdf0e10cSrcweir 		if( pEntry->pParent )
1583cdf0e10cSrcweir 			pEntry->pParent->InvalidateChildrensListPositions();
1584cdf0e10cSrcweir 	}
1585cdf0e10cSrcweir 	/*
1586cdf0e10cSrcweir 	sal_uLong nListPos = 0;
1587cdf0e10cSrcweir 	SvListEntry* pEntry = (SvListEntry*)(pList->First());
1588cdf0e10cSrcweir 	while( pEntry )
1589cdf0e10cSrcweir 	{
1590cdf0e10cSrcweir 		pEntry->nListPos = nListPos;
1591cdf0e10cSrcweir 		nListPos++;
1592cdf0e10cSrcweir 		pEntry = (SvListEntry*)(pList->Next());
1593cdf0e10cSrcweir 	}
1594cdf0e10cSrcweir 	*/
1595cdf0e10cSrcweir }
1596cdf0e10cSrcweir 
1597cdf0e10cSrcweir 
InvalidateEntry(SvListEntry * pEntry)1598cdf0e10cSrcweir void SvTreeList::InvalidateEntry( SvListEntry* pEntry )
1599cdf0e10cSrcweir {
1600cdf0e10cSrcweir 	Broadcast( LISTACTION_INVALIDATE_ENTRY, pEntry );
1601cdf0e10cSrcweir }
1602cdf0e10cSrcweir 
IsInChildList(SvListEntry * pParent,SvListEntry * pChild) const1603cdf0e10cSrcweir sal_Bool SvTreeList::IsInChildList( SvListEntry* pParent, SvListEntry* pChild) const
1604cdf0e10cSrcweir {
1605cdf0e10cSrcweir 	if ( !pParent )
1606cdf0e10cSrcweir 		pParent = pRootItem;
1607cdf0e10cSrcweir 	sal_Bool bIsChild = sal_False;
1608cdf0e10cSrcweir 	if ( pParent->pChilds )
1609cdf0e10cSrcweir 		bIsChild = (sal_Bool)(pParent->pChilds->GetPos(pChild) != LIST_ENTRY_NOTFOUND);
1610cdf0e10cSrcweir 	return bIsChild;
1611cdf0e10cSrcweir }
1612cdf0e10cSrcweir 
1613cdf0e10cSrcweir 
lcl_CheckList(SvTreeEntryList * pList)1614cdf0e10cSrcweir void lcl_CheckList( SvTreeEntryList* pList )
1615cdf0e10cSrcweir {
1616cdf0e10cSrcweir 	SvListEntry* pEntry = (SvListEntry*)(pList->First());
1617cdf0e10cSrcweir 	sal_uLong nPos = 0;
1618cdf0e10cSrcweir 	while ( pEntry )
1619cdf0e10cSrcweir 	{
1620cdf0e10cSrcweir 		DBG_ASSERT(pEntry->GetChildListPos()==nPos,"Wrong ListPos");
1621cdf0e10cSrcweir 		pEntry = (SvListEntry*)(pList->Next());
1622cdf0e10cSrcweir 		nPos++;
1623cdf0e10cSrcweir 	}
1624cdf0e10cSrcweir }
1625cdf0e10cSrcweir 
CheckIntegrity() const1626cdf0e10cSrcweir void SvTreeList::CheckIntegrity() const
1627cdf0e10cSrcweir {
1628cdf0e10cSrcweir 	sal_uLong nMyEntryCount = 0;
1629cdf0e10cSrcweir 	if ( pRootItem->pChilds )
1630cdf0e10cSrcweir 	{
1631cdf0e10cSrcweir 		lcl_CheckList( pRootItem->pChilds );
1632cdf0e10cSrcweir 		SvListEntry* pEntry = First();
1633cdf0e10cSrcweir 		while( pEntry )
1634cdf0e10cSrcweir 		{
1635cdf0e10cSrcweir 			nMyEntryCount++;
1636cdf0e10cSrcweir 			if ( pEntry->pChilds )
1637cdf0e10cSrcweir 				lcl_CheckList( pEntry->pChilds );
1638cdf0e10cSrcweir 			pEntry = Next( pEntry );
1639cdf0e10cSrcweir 		}
1640cdf0e10cSrcweir 	}
1641cdf0e10cSrcweir 	DBG_ASSERT(nMyEntryCount==GetEntryCount(),"Entry count invalid");
1642cdf0e10cSrcweir }
1643cdf0e10cSrcweir 
GetRootLevelParent(SvListEntry * pEntry) const1644cdf0e10cSrcweir SvListEntry* SvTreeList::GetRootLevelParent( SvListEntry* pEntry ) const
1645cdf0e10cSrcweir {
1646cdf0e10cSrcweir 	DBG_ASSERT(pEntry,"GetRootLevelParent:No Entry");
1647cdf0e10cSrcweir 	SvListEntry* pCurParent = 0;
1648cdf0e10cSrcweir 	if ( pEntry )
1649cdf0e10cSrcweir 	{
1650cdf0e10cSrcweir 		pCurParent = pEntry->pParent;
1651cdf0e10cSrcweir 		if ( pCurParent == pRootItem )
1652cdf0e10cSrcweir 			return pEntry; // ist sein eigener Parent
1653cdf0e10cSrcweir 		while( pCurParent && pCurParent->pParent != pRootItem )
1654cdf0e10cSrcweir 			pCurParent = pCurParent->pParent;
1655cdf0e10cSrcweir 	}
1656cdf0e10cSrcweir 	return pCurParent;
1657cdf0e10cSrcweir }
1658cdf0e10cSrcweir 
1659cdf0e10cSrcweir 
1660cdf0e10cSrcweir 
1661cdf0e10cSrcweir 
1662cdf0e10cSrcweir //*************************************************************************
1663cdf0e10cSrcweir //*************************************************************************
1664cdf0e10cSrcweir //*************************************************************************
1665cdf0e10cSrcweir //*************************************************************************
1666cdf0e10cSrcweir //*************************************************************************
1667cdf0e10cSrcweir //*************************************************************************
1668cdf0e10cSrcweir //*************************************************************************
1669cdf0e10cSrcweir //*************************************************************************
1670cdf0e10cSrcweir 
1671cdf0e10cSrcweir DBG_NAME(SvListView);
1672cdf0e10cSrcweir 
SvListView(SvTreeList * pModell)1673cdf0e10cSrcweir SvListView::SvListView( SvTreeList* pModell )
1674cdf0e10cSrcweir {
1675cdf0e10cSrcweir 	DBG_CTOR(SvListView,0);
1676cdf0e10cSrcweir 	pModel = 0;
1677cdf0e10cSrcweir 	nSelectionCount = 0;
1678cdf0e10cSrcweir 	nVisibleCount = 0;
1679cdf0e10cSrcweir 	bVisPositionsValid = sal_False;
1680cdf0e10cSrcweir 	SetModel( pModell );
1681cdf0e10cSrcweir }
1682cdf0e10cSrcweir 
SvListView()1683cdf0e10cSrcweir SvListView::SvListView()
1684cdf0e10cSrcweir {
1685cdf0e10cSrcweir 	DBG_CTOR(SvListView,0);
1686cdf0e10cSrcweir 	pModel = 0;
1687cdf0e10cSrcweir 	nSelectionCount = 0;
1688cdf0e10cSrcweir 	nVisibleCount = 0;
1689cdf0e10cSrcweir 	bVisPositionsValid = sal_False;
1690cdf0e10cSrcweir }
1691cdf0e10cSrcweir 
1692cdf0e10cSrcweir 
~SvListView()1693cdf0e10cSrcweir SvListView::~SvListView()
1694cdf0e10cSrcweir {
1695cdf0e10cSrcweir 	DBG_DTOR(SvListView,0);
1696cdf0e10cSrcweir 	ClearTable();
1697cdf0e10cSrcweir }
1698cdf0e10cSrcweir 
InitTable()1699cdf0e10cSrcweir void SvListView::InitTable()
1700cdf0e10cSrcweir {
1701cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1702cdf0e10cSrcweir 	DBG_ASSERT(pModel,"InitTable:No Model");
1703cdf0e10cSrcweir 	DBG_ASSERT(!nSelectionCount&&!nVisibleCount&&!bVisPositionsValid,"InitTable: Not cleared!");
1704cdf0e10cSrcweir 
1705cdf0e10cSrcweir 	if( aDataTable.Count() )
1706cdf0e10cSrcweir 	{
1707cdf0e10cSrcweir 		DBG_ASSERT(aDataTable.Count()==1,"InitTable: TableCount != 1");
1708cdf0e10cSrcweir 		// die im Clear fuer die Root allozierten View-Daten loeschen
1709cdf0e10cSrcweir 		// Achtung: Das zu dem RootEntry (und damit auch der Entry)
1710cdf0e10cSrcweir 		// gehoerende Model kann bereits geloescht sein!
1711cdf0e10cSrcweir 		SvViewData* pViewData = (SvViewData*)aDataTable.GetObject( 0 );
1712cdf0e10cSrcweir 		delete pViewData;
1713cdf0e10cSrcweir 		aDataTable.Clear();
1714cdf0e10cSrcweir 	}
1715cdf0e10cSrcweir 
1716cdf0e10cSrcweir 	SvListEntry* pEntry;
1717cdf0e10cSrcweir 	SvViewData* pViewData;
1718cdf0e10cSrcweir 
1719cdf0e10cSrcweir 	// RootEntry einfuegen
1720cdf0e10cSrcweir 	pEntry = pModel->pRootItem;
1721cdf0e10cSrcweir 	pViewData = new SvViewData;
1722cdf0e10cSrcweir 	pViewData->nFlags = SVLISTENTRYFLAG_EXPANDED;
1723cdf0e10cSrcweir 	aDataTable.Insert( (sal_uLong)pEntry, pViewData );
1724cdf0e10cSrcweir 	// Jetzt alle anderen Entries
1725cdf0e10cSrcweir 	pEntry = pModel->First();
1726cdf0e10cSrcweir 	while( pEntry )
1727cdf0e10cSrcweir 	{
1728cdf0e10cSrcweir 		pViewData = CreateViewData( pEntry );
1729cdf0e10cSrcweir 		DBG_ASSERT(pViewData,"InitTable:No ViewData");
1730cdf0e10cSrcweir 		InitViewData( pViewData, pEntry );
1731cdf0e10cSrcweir 		aDataTable.Insert( (sal_uLong)pEntry, pViewData );
1732cdf0e10cSrcweir 		pEntry = pModel->Next( pEntry );
1733cdf0e10cSrcweir 	}
1734cdf0e10cSrcweir }
1735cdf0e10cSrcweir 
CreateViewData(SvListEntry *)1736cdf0e10cSrcweir SvViewData* SvListView::CreateViewData( SvListEntry* )
1737cdf0e10cSrcweir {
1738cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1739cdf0e10cSrcweir 	return new SvViewData;
1740cdf0e10cSrcweir }
1741cdf0e10cSrcweir 
ClearTable()1742cdf0e10cSrcweir void SvListView::ClearTable()
1743cdf0e10cSrcweir {
1744cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1745cdf0e10cSrcweir 	SvViewData* pViewData = (SvViewData*)aDataTable.First();
1746cdf0e10cSrcweir 	while( pViewData )
1747cdf0e10cSrcweir 	{
1748cdf0e10cSrcweir 		delete pViewData;
1749cdf0e10cSrcweir 		pViewData = (SvViewData*)aDataTable.Next();
1750cdf0e10cSrcweir 	}
1751cdf0e10cSrcweir 	aDataTable.Clear();
1752cdf0e10cSrcweir }
1753cdf0e10cSrcweir 
Clear()1754cdf0e10cSrcweir void SvListView::Clear()
1755cdf0e10cSrcweir {
1756cdf0e10cSrcweir 	ClearTable();
1757cdf0e10cSrcweir 	nSelectionCount = 0;
1758cdf0e10cSrcweir 	nVisibleCount = 0;
1759cdf0e10cSrcweir 	bVisPositionsValid = sal_False;
1760cdf0e10cSrcweir 	if( pModel )
1761cdf0e10cSrcweir 	{
1762cdf0e10cSrcweir 		// RootEntry einfuegen
1763cdf0e10cSrcweir 		SvListEntry* pEntry = pModel->pRootItem;
1764cdf0e10cSrcweir 		SvViewData* pViewData = new SvViewData;
1765cdf0e10cSrcweir 		pViewData->nFlags = SVLISTENTRYFLAG_EXPANDED;
1766cdf0e10cSrcweir 		aDataTable.Insert( (sal_uLong)pEntry, pViewData );
1767cdf0e10cSrcweir 	}
1768cdf0e10cSrcweir }
1769cdf0e10cSrcweir 
SetModel(SvTreeList * pNewModel)1770cdf0e10cSrcweir void SvListView::SetModel( SvTreeList* pNewModel )
1771cdf0e10cSrcweir {
1772cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1773cdf0e10cSrcweir 	sal_Bool bBroadcastCleared = sal_False;
1774cdf0e10cSrcweir 	if ( pModel )
1775cdf0e10cSrcweir 	{
1776cdf0e10cSrcweir 		pModel->RemoveView( this );
1777cdf0e10cSrcweir 		bBroadcastCleared = sal_True;
1778cdf0e10cSrcweir 		ModelNotification( LISTACTION_CLEARING,0,0,0 );
1779cdf0e10cSrcweir 		if ( pModel->GetRefCount() == 0 )
1780cdf0e10cSrcweir 			delete pModel;
1781cdf0e10cSrcweir 	}
1782cdf0e10cSrcweir 	pModel = pNewModel;
1783cdf0e10cSrcweir 	InitTable();
1784cdf0e10cSrcweir 	pNewModel->InsertView( this );
1785cdf0e10cSrcweir 	if( bBroadcastCleared )
1786cdf0e10cSrcweir 		ModelNotification( LISTACTION_CLEARED,0,0,0 );
1787cdf0e10cSrcweir }
1788cdf0e10cSrcweir 
1789cdf0e10cSrcweir 
ModelHasCleared()1790cdf0e10cSrcweir void SvListView::ModelHasCleared()
1791cdf0e10cSrcweir {
1792cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1793cdf0e10cSrcweir }
1794cdf0e10cSrcweir 
ModelHasInserted(SvListEntry *)1795cdf0e10cSrcweir void SvListView::ModelHasInserted( SvListEntry* )
1796cdf0e10cSrcweir {
1797cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1798cdf0e10cSrcweir }
1799cdf0e10cSrcweir 
ModelHasInsertedTree(SvListEntry *)1800cdf0e10cSrcweir void SvListView::ModelHasInsertedTree( SvListEntry* )
1801cdf0e10cSrcweir {
1802cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1803cdf0e10cSrcweir }
1804cdf0e10cSrcweir 
ModelIsMoving(SvListEntry *,SvListEntry *,sal_uLong)1805cdf0e10cSrcweir void SvListView::ModelIsMoving( SvListEntry* /*  pSource */ ,
1806cdf0e10cSrcweir 	SvListEntry* /* pTargetParent */ ,	sal_uLong /* nPos */	)
1807cdf0e10cSrcweir {
1808cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1809cdf0e10cSrcweir }
1810cdf0e10cSrcweir 
1811cdf0e10cSrcweir 
ModelHasMoved(SvListEntry *)1812cdf0e10cSrcweir void SvListView::ModelHasMoved( SvListEntry* )
1813cdf0e10cSrcweir {
1814cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1815cdf0e10cSrcweir }
1816cdf0e10cSrcweir 
ModelIsRemoving(SvListEntry *)1817cdf0e10cSrcweir void SvListView::ModelIsRemoving( SvListEntry* )
1818cdf0e10cSrcweir {
1819cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1820cdf0e10cSrcweir }
1821cdf0e10cSrcweir 
ModelHasRemoved(SvListEntry *)1822cdf0e10cSrcweir void SvListView::ModelHasRemoved( SvListEntry* )
1823cdf0e10cSrcweir {
1824cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1825cdf0e10cSrcweir }
1826cdf0e10cSrcweir 
ModelHasEntryInvalidated(SvListEntry *)1827cdf0e10cSrcweir void SvListView::ModelHasEntryInvalidated( SvListEntry*)
1828cdf0e10cSrcweir {
1829cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1830cdf0e10cSrcweir }
1831cdf0e10cSrcweir 
ActionMoving(SvListEntry * pEntry,SvListEntry *,sal_uLong)1832cdf0e10cSrcweir void SvListView::ActionMoving( SvListEntry* pEntry,SvListEntry*,sal_uLong)
1833cdf0e10cSrcweir {
1834cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1835cdf0e10cSrcweir 	SvListEntry* pParent = pEntry->pParent;
1836cdf0e10cSrcweir 	DBG_ASSERT(pParent,"Model not consistent");
1837cdf0e10cSrcweir 	if( pParent != pModel->pRootItem && pParent->pChilds->Count() == 1 )
1838cdf0e10cSrcweir 	{
1839cdf0e10cSrcweir 		SvViewData* pViewData = (SvViewData*)aDataTable.Get( (sal_uLong)pParent );
1840cdf0e10cSrcweir 		pViewData->nFlags &= (~SVLISTENTRYFLAG_EXPANDED);
1841cdf0e10cSrcweir 	}
1842cdf0e10cSrcweir 	// vorlaeufig
1843cdf0e10cSrcweir 	nVisibleCount = 0;
1844cdf0e10cSrcweir 	bVisPositionsValid = sal_False;
1845cdf0e10cSrcweir }
1846cdf0e10cSrcweir 
ActionMoved(SvListEntry *,SvListEntry *,sal_uLong)1847cdf0e10cSrcweir void SvListView::ActionMoved( SvListEntry* /* pEntry */ ,
1848cdf0e10cSrcweir 							SvListEntry* /* pTargetPrnt */ ,
1849cdf0e10cSrcweir 							sal_uLong /* nChildPos */ )
1850cdf0e10cSrcweir {
1851cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1852cdf0e10cSrcweir 	nVisibleCount = 0;
1853cdf0e10cSrcweir 	bVisPositionsValid = sal_False;
1854cdf0e10cSrcweir }
1855cdf0e10cSrcweir 
ActionInserted(SvListEntry * pEntry)1856cdf0e10cSrcweir void SvListView::ActionInserted( SvListEntry* pEntry )
1857cdf0e10cSrcweir {
1858cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1859cdf0e10cSrcweir 	DBG_ASSERT(pEntry,"Insert:No Entry");
1860cdf0e10cSrcweir 	SvViewData* pData = CreateViewData( pEntry );
1861cdf0e10cSrcweir 	InitViewData( pData, pEntry );
1862cdf0e10cSrcweir     #ifdef DBG_UTIL
1863cdf0e10cSrcweir 	sal_Bool bSuccess =
1864cdf0e10cSrcweir     #endif
1865cdf0e10cSrcweir         aDataTable.Insert( (sal_uLong)pEntry, pData );
1866cdf0e10cSrcweir 	DBG_ASSERT(bSuccess,"Entry already in View");
1867cdf0e10cSrcweir 	if ( nVisibleCount && pModel->IsEntryVisible( this, pEntry ))
1868cdf0e10cSrcweir 	{
1869cdf0e10cSrcweir 		nVisibleCount = 0;
1870cdf0e10cSrcweir 		bVisPositionsValid = sal_False;
1871cdf0e10cSrcweir 	}
1872cdf0e10cSrcweir }
1873cdf0e10cSrcweir 
ActionInsertedTree(SvListEntry * pEntry)1874cdf0e10cSrcweir void SvListView::ActionInsertedTree( SvListEntry* pEntry )
1875cdf0e10cSrcweir {
1876cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1877cdf0e10cSrcweir 	if ( pModel->IsEntryVisible( this, pEntry ))
1878cdf0e10cSrcweir 	{
1879cdf0e10cSrcweir 		nVisibleCount = 0;
1880cdf0e10cSrcweir 		bVisPositionsValid = sal_False;
1881cdf0e10cSrcweir 	}
1882cdf0e10cSrcweir 	// ueber Entry und seine Childs iterieren
1883cdf0e10cSrcweir 	SvListEntry* pCurEntry = pEntry;
1884cdf0e10cSrcweir 	sal_uInt16 nRefDepth = pModel->GetDepth( pCurEntry );
1885cdf0e10cSrcweir 	while( pCurEntry )
1886cdf0e10cSrcweir 	{
1887cdf0e10cSrcweir 		DBG_ASSERT(aDataTable.Get((sal_uLong)pCurEntry)==0,"Entry already in Table");
1888cdf0e10cSrcweir 		SvViewData* pViewData = CreateViewData( pCurEntry );
1889cdf0e10cSrcweir 		DBG_ASSERT(pViewData,"No ViewData");
1890cdf0e10cSrcweir 		InitViewData( pViewData, pEntry );
1891cdf0e10cSrcweir 		aDataTable.Insert( (sal_uLong)pCurEntry, pViewData );
1892cdf0e10cSrcweir 		pCurEntry = pModel->Next( pCurEntry );
1893cdf0e10cSrcweir 		if ( pCurEntry && pModel->GetDepth(pCurEntry) <= nRefDepth)
1894cdf0e10cSrcweir 			pCurEntry = 0;
1895cdf0e10cSrcweir 	}
1896cdf0e10cSrcweir }
1897cdf0e10cSrcweir 
RemoveViewData(SvListEntry * pParent)1898cdf0e10cSrcweir void SvListView::RemoveViewData( SvListEntry* pParent )
1899cdf0e10cSrcweir {
1900cdf0e10cSrcweir 	SvTreeEntryList* pChilds = pParent->pChilds;
1901cdf0e10cSrcweir 	if( pChilds )
1902cdf0e10cSrcweir 	{
1903cdf0e10cSrcweir 		SvListEntry* pCur = (SvListEntry*)pChilds->First();
1904cdf0e10cSrcweir 		while( pCur )
1905cdf0e10cSrcweir 		{
1906cdf0e10cSrcweir 			SvViewData* pViewData = (SvViewData*)aDataTable.Get((sal_uLong)pCur);
1907cdf0e10cSrcweir 			delete pViewData;
1908cdf0e10cSrcweir 			aDataTable.Remove( (sal_uLong)pCur );
1909cdf0e10cSrcweir 			if( pCur->HasChilds())
1910cdf0e10cSrcweir 				RemoveViewData( pCur );
1911cdf0e10cSrcweir 			pCur = (SvListEntry*)pChilds->Next();
1912cdf0e10cSrcweir 		}
1913cdf0e10cSrcweir 	}
1914cdf0e10cSrcweir }
1915cdf0e10cSrcweir 
1916cdf0e10cSrcweir 
1917cdf0e10cSrcweir 
ActionRemoving(SvListEntry * pEntry)1918cdf0e10cSrcweir void SvListView::ActionRemoving( SvListEntry* pEntry )
1919cdf0e10cSrcweir {
1920cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1921cdf0e10cSrcweir 	DBG_ASSERT(pEntry,"Remove:No Entry");
1922cdf0e10cSrcweir 
1923cdf0e10cSrcweir 	SvViewData* pViewData = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry );
1924cdf0e10cSrcweir 	sal_uLong nSelRemoved = 0;
1925cdf0e10cSrcweir 	if ( pViewData->IsSelected() )
1926cdf0e10cSrcweir 		nSelRemoved = 1 + pModel->GetChildSelectionCount( this, pEntry );
1927cdf0e10cSrcweir 	nSelectionCount -= nSelRemoved;
1928cdf0e10cSrcweir 	sal_uLong nVisibleRemoved = 0;
1929cdf0e10cSrcweir 	if ( pModel->IsEntryVisible( this, pEntry ) )
1930cdf0e10cSrcweir 		nVisibleRemoved = 1 + pModel->GetVisibleChildCount( this, pEntry );
1931cdf0e10cSrcweir 	if( nVisibleCount )
1932cdf0e10cSrcweir 	{
1933cdf0e10cSrcweir #ifdef DBG_UTIL
1934cdf0e10cSrcweir 		if( nVisibleCount < nVisibleRemoved )
1935cdf0e10cSrcweir 		{
1936cdf0e10cSrcweir 			DBG_ERROR("nVisibleRemoved bad");
1937cdf0e10cSrcweir 		}
1938cdf0e10cSrcweir #endif
1939cdf0e10cSrcweir 		nVisibleCount -= nVisibleRemoved;
1940cdf0e10cSrcweir 	}
1941cdf0e10cSrcweir 	bVisPositionsValid = sal_False;
1942cdf0e10cSrcweir 
1943cdf0e10cSrcweir 	pViewData = (SvViewData*)aDataTable.Get((sal_uLong)pEntry);
1944cdf0e10cSrcweir 	delete pViewData;
1945cdf0e10cSrcweir 	aDataTable.Remove( (sal_uLong)pEntry );
1946cdf0e10cSrcweir 	RemoveViewData( pEntry );
1947cdf0e10cSrcweir 
1948cdf0e10cSrcweir 	SvListEntry* pCurEntry = pEntry->pParent;
1949cdf0e10cSrcweir 	if ( pCurEntry && pCurEntry != pModel->pRootItem &&
1950cdf0e10cSrcweir 		 pCurEntry->pChilds->Count() == 1 )
1951cdf0e10cSrcweir 	{
1952cdf0e10cSrcweir 		pViewData = (SvViewData*)aDataTable.Get((sal_uLong)pCurEntry);
1953cdf0e10cSrcweir 		pViewData->nFlags &= (~SVLISTENTRYFLAG_EXPANDED);
1954cdf0e10cSrcweir 	}
1955cdf0e10cSrcweir }
1956cdf0e10cSrcweir 
ActionRemoved(SvListEntry *)1957cdf0e10cSrcweir void SvListView::ActionRemoved( SvListEntry* /* pEntry  */ )
1958cdf0e10cSrcweir {
1959cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1960cdf0e10cSrcweir }
1961cdf0e10cSrcweir 
ActionClear()1962cdf0e10cSrcweir void SvListView::ActionClear()
1963cdf0e10cSrcweir {
1964cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1965cdf0e10cSrcweir 	Clear();
1966cdf0e10cSrcweir }
1967cdf0e10cSrcweir 
ModelNotification(sal_uInt16 nActionId,SvListEntry * pEntry1,SvListEntry * pEntry2,sal_uLong nPos)1968cdf0e10cSrcweir void SvListView::ModelNotification( sal_uInt16 nActionId, SvListEntry* pEntry1,
1969cdf0e10cSrcweir 						SvListEntry* pEntry2, sal_uLong nPos )
1970cdf0e10cSrcweir {
1971cdf0e10cSrcweir 	DBG_CHKTHIS(SvListView,0);
1972cdf0e10cSrcweir 	switch( nActionId )
1973cdf0e10cSrcweir 	{
1974cdf0e10cSrcweir 		case LISTACTION_INSERTED:
1975cdf0e10cSrcweir 			ActionInserted( pEntry1 );
1976cdf0e10cSrcweir 			ModelHasInserted( pEntry1 );
1977cdf0e10cSrcweir 			break;
1978cdf0e10cSrcweir 		case LISTACTION_INSERTED_TREE:
1979cdf0e10cSrcweir 			ActionInsertedTree( pEntry1 );
1980cdf0e10cSrcweir 			ModelHasInsertedTree( pEntry1 );
1981cdf0e10cSrcweir 			break;
1982cdf0e10cSrcweir 		case LISTACTION_REMOVING:
1983cdf0e10cSrcweir 			ModelIsRemoving( pEntry1 );
1984cdf0e10cSrcweir 			ActionRemoving( pEntry1 );
1985cdf0e10cSrcweir 			break;
1986cdf0e10cSrcweir 		case LISTACTION_REMOVED:
1987cdf0e10cSrcweir 			ActionRemoved( pEntry1 );
1988cdf0e10cSrcweir 			ModelHasRemoved( pEntry1 );
1989cdf0e10cSrcweir 			break;
1990cdf0e10cSrcweir 		case LISTACTION_MOVING:
1991cdf0e10cSrcweir 			ModelIsMoving( pEntry1, pEntry2, nPos );
1992cdf0e10cSrcweir 			ActionMoving( pEntry1, pEntry2, nPos );
1993cdf0e10cSrcweir 			break;
1994cdf0e10cSrcweir 		case LISTACTION_MOVED:
1995cdf0e10cSrcweir 			ActionMoved( pEntry1, pEntry2, nPos );
1996cdf0e10cSrcweir 			ModelHasMoved( pEntry1 );
1997cdf0e10cSrcweir 			break;
1998cdf0e10cSrcweir 		case LISTACTION_CLEARING:
1999cdf0e10cSrcweir 			ActionClear();
2000cdf0e10cSrcweir 			ModelHasCleared(); //sic! wg. Kompatibilitaet!
2001cdf0e10cSrcweir 			break;
2002cdf0e10cSrcweir 		case LISTACTION_CLEARED:
2003cdf0e10cSrcweir 			break;
2004cdf0e10cSrcweir 		case LISTACTION_INVALIDATE_ENTRY:
2005cdf0e10cSrcweir 			// keine Action fuer die Basisklasse
2006cdf0e10cSrcweir 			ModelHasEntryInvalidated( pEntry1 );
2007cdf0e10cSrcweir 			break;
2008cdf0e10cSrcweir 		case LISTACTION_RESORTED:
2009cdf0e10cSrcweir 			bVisPositionsValid = sal_False;
2010cdf0e10cSrcweir 			break;
2011cdf0e10cSrcweir 		case LISTACTION_RESORTING:
2012cdf0e10cSrcweir 			break;
2013cdf0e10cSrcweir 		default:
2014cdf0e10cSrcweir 			DBG_ERROR("unknown ActionId");
2015cdf0e10cSrcweir 	}
2016cdf0e10cSrcweir }
2017cdf0e10cSrcweir 
InitViewData(SvViewData *,SvListEntry *)2018cdf0e10cSrcweir void SvListView::InitViewData( SvViewData*, SvListEntry* )
2019cdf0e10cSrcweir {
2020cdf0e10cSrcweir }
2021cdf0e10cSrcweir 
Compare(SvListEntry * pLeft,SvListEntry * pRight) const2022cdf0e10cSrcweir StringCompare SvTreeList::Compare( SvListEntry* pLeft, SvListEntry* pRight) const
2023cdf0e10cSrcweir {
2024cdf0e10cSrcweir 	if( aCompareLink.IsSet())
2025cdf0e10cSrcweir 	{
2026cdf0e10cSrcweir 		SvSortData aSortData;
2027cdf0e10cSrcweir 		aSortData.pLeft = pLeft;
2028cdf0e10cSrcweir 		aSortData.pRight = pRight;
2029cdf0e10cSrcweir 		return (StringCompare)aCompareLink.Call( &aSortData );
2030cdf0e10cSrcweir 	}
2031cdf0e10cSrcweir 	return COMPARE_EQUAL;
2032cdf0e10cSrcweir }
2033cdf0e10cSrcweir 
Resort()2034cdf0e10cSrcweir void SvTreeList::Resort()
2035cdf0e10cSrcweir {
2036cdf0e10cSrcweir 	Broadcast( LISTACTION_RESORTING );
2037cdf0e10cSrcweir 	bAbsPositionsValid = sal_False;
2038cdf0e10cSrcweir 	ResortChilds( pRootItem );
2039cdf0e10cSrcweir 	Broadcast( LISTACTION_RESORTED );
2040cdf0e10cSrcweir }
2041cdf0e10cSrcweir 
ResortChilds(SvListEntry * pParent)2042cdf0e10cSrcweir void SvTreeList::ResortChilds( SvListEntry* pParent )
2043cdf0e10cSrcweir {
2044cdf0e10cSrcweir 	DBG_ASSERT(pParent,"Parent not set");
2045cdf0e10cSrcweir 	List* pChildList = pParent->pChilds;
2046cdf0e10cSrcweir 	if( !pChildList )
2047cdf0e10cSrcweir 		return;
2048cdf0e10cSrcweir 	List aList( *pChildList );
2049cdf0e10cSrcweir 	pChildList->Clear();
2050cdf0e10cSrcweir 
2051cdf0e10cSrcweir 	sal_uLong nCount = aList.Count();
2052cdf0e10cSrcweir 	for( sal_uLong nCur = 0; nCur < nCount; nCur++ )
2053cdf0e10cSrcweir 	{
2054cdf0e10cSrcweir 		SvListEntry* pCurEntry = (SvListEntry*)aList.GetObject( nCur );
2055cdf0e10cSrcweir 		sal_uLong nListPos = LIST_APPEND;
2056cdf0e10cSrcweir 		GetInsertionPos( pCurEntry, pParent, nListPos );
2057cdf0e10cSrcweir 		pChildList->Insert( pCurEntry, nListPos );
2058cdf0e10cSrcweir 		if( pCurEntry->pChilds )
2059cdf0e10cSrcweir 			ResortChilds( pCurEntry );
2060cdf0e10cSrcweir 	}
2061cdf0e10cSrcweir 	SetListPositions( (SvTreeEntryList*)pChildList );
2062cdf0e10cSrcweir }
2063cdf0e10cSrcweir 
GetInsertionPos(SvListEntry * pEntry,SvListEntry * pParent,sal_uLong & rPos)2064cdf0e10cSrcweir void SvTreeList::GetInsertionPos( SvListEntry* pEntry, SvListEntry* pParent,
2065cdf0e10cSrcweir 	sal_uLong& rPos )
2066cdf0e10cSrcweir {
2067cdf0e10cSrcweir 	DBG_ASSERT(pEntry,"No Entry");
2068cdf0e10cSrcweir 
2069cdf0e10cSrcweir 	if( eSortMode == SortNone )
2070cdf0e10cSrcweir 		return;
2071cdf0e10cSrcweir 
2072cdf0e10cSrcweir 	rPos = LIST_APPEND;
2073cdf0e10cSrcweir 	SvTreeEntryList* pChildList = GetChildList( pParent );
2074cdf0e10cSrcweir 
2075cdf0e10cSrcweir 	if( pChildList && pChildList->Count() )
2076cdf0e10cSrcweir 	{
2077cdf0e10cSrcweir 		long i = 0;
2078cdf0e10cSrcweir 		long j = pChildList->Count()-1;
2079cdf0e10cSrcweir 		long k;
2080cdf0e10cSrcweir 		StringCompare eCompare = COMPARE_GREATER;
2081cdf0e10cSrcweir 
2082cdf0e10cSrcweir 		do
2083cdf0e10cSrcweir 		{
2084cdf0e10cSrcweir 			k = (i+j)/2;
2085cdf0e10cSrcweir 			SvListEntry* pTempEntry = (SvListEntry*)(pChildList->GetObject(k));
2086cdf0e10cSrcweir 			eCompare = Compare( pEntry, pTempEntry );
2087cdf0e10cSrcweir 			if( eSortMode == SortDescending && eCompare != COMPARE_EQUAL )
2088cdf0e10cSrcweir 			{
2089cdf0e10cSrcweir 				if( eCompare == COMPARE_LESS )
2090cdf0e10cSrcweir 					eCompare = COMPARE_GREATER;
2091cdf0e10cSrcweir 				else
2092cdf0e10cSrcweir 					eCompare = COMPARE_LESS;
2093cdf0e10cSrcweir 			}
2094cdf0e10cSrcweir 			if( eCompare == COMPARE_GREATER )
2095cdf0e10cSrcweir 				i = k + 1;
2096cdf0e10cSrcweir 			else
2097cdf0e10cSrcweir 				j = k - 1;
2098cdf0e10cSrcweir 		} while( (eCompare != COMPARE_EQUAL) && (i <= j) );
2099cdf0e10cSrcweir 
2100cdf0e10cSrcweir 		if( eCompare != COMPARE_EQUAL )
2101cdf0e10cSrcweir 		{
2102cdf0e10cSrcweir 			if(i > ((long)pChildList->Count() - 1)) // nicht gefunden, Ende der Liste
2103cdf0e10cSrcweir 				rPos = LIST_APPEND;
2104cdf0e10cSrcweir 			else
2105cdf0e10cSrcweir 				rPos = i;              // nicht gefunden, Mitte
2106cdf0e10cSrcweir 		}
2107cdf0e10cSrcweir 		else
2108cdf0e10cSrcweir 			rPos = k;
2109cdf0e10cSrcweir 	}
2110cdf0e10cSrcweir }
2111cdf0e10cSrcweir 
2112cdf0e10cSrcweir 
2113