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