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_editeng.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <paralist.hxx>
32*cdf0e10cSrcweir #include <editeng/outliner.hxx>		// nur wegen Paragraph, muss geaendert werden!
33*cdf0e10cSrcweir #include <editeng/numdef.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir DBG_NAME(Paragraph)
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir ParagraphData::ParagraphData()
38*cdf0e10cSrcweir : nDepth( -1 )
39*cdf0e10cSrcweir , mnNumberingStartValue( -1 )
40*cdf0e10cSrcweir , mbParaIsNumberingRestart( sal_False )
41*cdf0e10cSrcweir {
42*cdf0e10cSrcweir }
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir ParagraphData::ParagraphData( const ParagraphData& r )
45*cdf0e10cSrcweir : nDepth( r.nDepth )
46*cdf0e10cSrcweir , mnNumberingStartValue( r.mnNumberingStartValue )
47*cdf0e10cSrcweir , mbParaIsNumberingRestart( r.mbParaIsNumberingRestart )
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir }
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir ParagraphData& ParagraphData::operator=( const ParagraphData& r)
52*cdf0e10cSrcweir {
53*cdf0e10cSrcweir     nDepth = r.nDepth;
54*cdf0e10cSrcweir     mnNumberingStartValue = r.mnNumberingStartValue;
55*cdf0e10cSrcweir     mbParaIsNumberingRestart = r.mbParaIsNumberingRestart;
56*cdf0e10cSrcweir     return *this;
57*cdf0e10cSrcweir }
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir bool ParagraphData::operator==(const ParagraphData& rCandidate) const
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir     return (nDepth == rCandidate.nDepth
62*cdf0e10cSrcweir         && mnNumberingStartValue == rCandidate.mnNumberingStartValue
63*cdf0e10cSrcweir         && mbParaIsNumberingRestart == rCandidate.mbParaIsNumberingRestart);
64*cdf0e10cSrcweir }
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir Paragraph::Paragraph( sal_Int16 nDDepth )
67*cdf0e10cSrcweir : aBulSize( -1, -1)
68*cdf0e10cSrcweir {
69*cdf0e10cSrcweir 	DBG_CTOR( Paragraph, 0 );
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir     DBG_ASSERT(  ( nDDepth >= -1 ) && ( nDDepth < SVX_MAX_NUM ), "Paragraph-CTOR: nDepth invalid!" );
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 	nDepth = nDDepth;
74*cdf0e10cSrcweir 	nFlags = 0;
75*cdf0e10cSrcweir 	bVisible = sal_True;
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir Paragraph::Paragraph( const Paragraph& rPara )
79*cdf0e10cSrcweir : ParagraphData( rPara )
80*cdf0e10cSrcweir , aBulText( rPara.aBulText )
81*cdf0e10cSrcweir , aBulSize( rPara.aBulSize )
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir 	DBG_CTOR( Paragraph, 0 );
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 	nDepth = rPara.nDepth;
86*cdf0e10cSrcweir 	nFlags = rPara.nFlags;
87*cdf0e10cSrcweir 	bVisible = rPara.bVisible;
88*cdf0e10cSrcweir }
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir Paragraph::Paragraph( const ParagraphData& rData )
91*cdf0e10cSrcweir : nFlags( 0 )
92*cdf0e10cSrcweir , aBulSize( -1, -1)
93*cdf0e10cSrcweir , bVisible( sal_True )
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir 	DBG_CTOR( Paragraph, 0 );
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir     nDepth = rData.nDepth;
98*cdf0e10cSrcweir     mnNumberingStartValue = rData.mnNumberingStartValue;
99*cdf0e10cSrcweir     mbParaIsNumberingRestart = rData.mbParaIsNumberingRestart;
100*cdf0e10cSrcweir }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir Paragraph::~Paragraph()
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir 	DBG_DTOR( Paragraph, 0 );
105*cdf0e10cSrcweir }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir void Paragraph::SetNumberingStartValue( sal_Int16 nNumberingStartValue )
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir     mnNumberingStartValue = nNumberingStartValue;
110*cdf0e10cSrcweir     if( mnNumberingStartValue != -1 )
111*cdf0e10cSrcweir         mbParaIsNumberingRestart = true;
112*cdf0e10cSrcweir }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir void Paragraph::SetParaIsNumberingRestart( sal_Bool bParaIsNumberingRestart )
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir     mbParaIsNumberingRestart = bParaIsNumberingRestart;
117*cdf0e10cSrcweir     if( !mbParaIsNumberingRestart )
118*cdf0e10cSrcweir         mnNumberingStartValue = -1;
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir void ParagraphList::Clear( sal_Bool bDestroyParagraphs )
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir 	if ( bDestroyParagraphs )
124*cdf0e10cSrcweir 	{
125*cdf0e10cSrcweir 		for ( sal_uLong n = GetParagraphCount(); n; )
126*cdf0e10cSrcweir 		{
127*cdf0e10cSrcweir 			Paragraph* pPara = GetParagraph( --n );
128*cdf0e10cSrcweir 			delete pPara;
129*cdf0e10cSrcweir 		}
130*cdf0e10cSrcweir 	}
131*cdf0e10cSrcweir 	List::Clear();
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir void ParagraphList::MoveParagraphs( sal_uLong nStart, sal_uLong nDest, sal_uLong _nCount )
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir 	if ( ( nDest < nStart ) || ( nDest >= ( nStart + _nCount ) ) )
137*cdf0e10cSrcweir 	{
138*cdf0e10cSrcweir 		sal_uLong n;
139*cdf0e10cSrcweir 		ParagraphList aParas;
140*cdf0e10cSrcweir 		for ( n = 0; n < _nCount; n++ )
141*cdf0e10cSrcweir 		{
142*cdf0e10cSrcweir 			Paragraph* pPara = GetParagraph( nStart );
143*cdf0e10cSrcweir 			aParas.Insert( pPara, LIST_APPEND );
144*cdf0e10cSrcweir 			Remove( nStart );
145*cdf0e10cSrcweir 		}
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 		if ( nDest > nStart )
148*cdf0e10cSrcweir 			nDest -= _nCount;
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 		for ( n = 0; n < _nCount; n++ )
151*cdf0e10cSrcweir 		{
152*cdf0e10cSrcweir 			Paragraph* pPara = aParas.GetParagraph( n );
153*cdf0e10cSrcweir 			Insert( pPara, nDest++ );
154*cdf0e10cSrcweir 		}
155*cdf0e10cSrcweir 	}
156*cdf0e10cSrcweir 	else
157*cdf0e10cSrcweir 	{
158*cdf0e10cSrcweir 		DBG_ERROR( "MoveParagraphs: Invalid Parameters" );
159*cdf0e10cSrcweir 	}
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir Paragraph* ParagraphList::NextVisible( Paragraph* pPara ) const
163*cdf0e10cSrcweir {
164*cdf0e10cSrcweir 	sal_uLong n = GetAbsPos( pPara );
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 	Paragraph* p = GetParagraph( ++n );
167*cdf0e10cSrcweir 	while ( p && !p->IsVisible() )
168*cdf0e10cSrcweir 		p = GetParagraph( ++n );
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 	return p;
171*cdf0e10cSrcweir }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir Paragraph* ParagraphList::PrevVisible( Paragraph* pPara ) const
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir 	sal_uLong n = GetAbsPos( pPara );
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 	Paragraph* p = n ? GetParagraph( --n ) : NULL;
178*cdf0e10cSrcweir 	while ( p && !p->IsVisible() )
179*cdf0e10cSrcweir 		p = n ? GetParagraph( --n ) : NULL;
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 	return p;
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir Paragraph* ParagraphList::LastVisible() const
185*cdf0e10cSrcweir {
186*cdf0e10cSrcweir 	sal_uLong n = GetParagraphCount();
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 	Paragraph* p = n ? GetParagraph( --n ) : NULL;
189*cdf0e10cSrcweir 	while ( p && !p->IsVisible() )
190*cdf0e10cSrcweir 		p = n ? GetParagraph( --n ) : NULL;
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 	return p;
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir sal_Bool ParagraphList::HasChilds( Paragraph* pParagraph ) const
196*cdf0e10cSrcweir {
197*cdf0e10cSrcweir 	sal_uLong n = GetAbsPos( pParagraph );
198*cdf0e10cSrcweir 	Paragraph* pNext = GetParagraph( ++n );
199*cdf0e10cSrcweir 	return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) ) ? sal_True : sal_False;
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir sal_Bool ParagraphList::HasHiddenChilds( Paragraph* pParagraph ) const
203*cdf0e10cSrcweir {
204*cdf0e10cSrcweir 	sal_uLong n = GetAbsPos( pParagraph );
205*cdf0e10cSrcweir 	Paragraph* pNext = GetParagraph( ++n );
206*cdf0e10cSrcweir 	return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && !pNext->IsVisible() ) ? sal_True : sal_False;
207*cdf0e10cSrcweir }
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir sal_Bool ParagraphList::HasVisibleChilds( Paragraph* pParagraph ) const
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir 	sal_uLong n = GetAbsPos( pParagraph );
212*cdf0e10cSrcweir 	Paragraph* pNext = GetParagraph( ++n );
213*cdf0e10cSrcweir 	return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && pNext->IsVisible() ) ? sal_True : sal_False;
214*cdf0e10cSrcweir }
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir sal_uLong ParagraphList::GetChildCount( Paragraph* pParent ) const
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir 	sal_uLong nChildCount = 0;
219*cdf0e10cSrcweir 	sal_uLong n = GetAbsPos( pParent );
220*cdf0e10cSrcweir 	Paragraph* pPara = GetParagraph( ++n );
221*cdf0e10cSrcweir 	while ( pPara && ( pPara->GetDepth() > pParent->GetDepth() ) )
222*cdf0e10cSrcweir 	{
223*cdf0e10cSrcweir 		nChildCount++;
224*cdf0e10cSrcweir 		pPara = GetParagraph( ++n );
225*cdf0e10cSrcweir 	}
226*cdf0e10cSrcweir 	return nChildCount;
227*cdf0e10cSrcweir }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir Paragraph* ParagraphList::GetParent( Paragraph* pParagraph /*, sal_uInt16& rRelPos */ ) const
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir 	/* rRelPos = 0 */;
232*cdf0e10cSrcweir 	sal_uLong n = GetAbsPos( pParagraph );
233*cdf0e10cSrcweir 	Paragraph* pPrev = GetParagraph( --n );
234*cdf0e10cSrcweir 	while ( pPrev && ( pPrev->GetDepth() >= pParagraph->GetDepth() ) )
235*cdf0e10cSrcweir 	{
236*cdf0e10cSrcweir //		if ( pPrev->GetDepth() == pParagraph->GetDepth() )
237*cdf0e10cSrcweir //			rRelPos++;
238*cdf0e10cSrcweir 		pPrev = GetParagraph( --n );
239*cdf0e10cSrcweir 	}
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir 	return pPrev;
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir void ParagraphList::Expand( Paragraph* pParent )
245*cdf0e10cSrcweir {
246*cdf0e10cSrcweir 	sal_uLong nChildCount = GetChildCount( pParent );
247*cdf0e10cSrcweir 	sal_uLong nPos = GetAbsPos( pParent );
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 	for ( sal_uLong n = 1; n <= nChildCount; n++  )
250*cdf0e10cSrcweir 	{
251*cdf0e10cSrcweir 		Paragraph* pPara = GetParagraph( nPos+n );
252*cdf0e10cSrcweir 		if ( !( pPara->IsVisible() ) )
253*cdf0e10cSrcweir 		{
254*cdf0e10cSrcweir 			pPara->bVisible = sal_True;
255*cdf0e10cSrcweir 			aVisibleStateChangedHdl.Call( pPara );
256*cdf0e10cSrcweir 		}
257*cdf0e10cSrcweir 	}
258*cdf0e10cSrcweir }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir void ParagraphList::Collapse( Paragraph* pParent )
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir 	sal_uLong nChildCount = GetChildCount( pParent );
263*cdf0e10cSrcweir 	sal_uLong nPos = GetAbsPos( pParent );
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 	for ( sal_uLong n = 1; n <= nChildCount; n++  )
266*cdf0e10cSrcweir 	{
267*cdf0e10cSrcweir 		Paragraph* pPara = GetParagraph( nPos+n );
268*cdf0e10cSrcweir 		if ( pPara->IsVisible() )
269*cdf0e10cSrcweir 		{
270*cdf0e10cSrcweir 			pPara->bVisible = sal_False;
271*cdf0e10cSrcweir 			aVisibleStateChangedHdl.Call( pPara );
272*cdf0e10cSrcweir 		}
273*cdf0e10cSrcweir 	}
274*cdf0e10cSrcweir }
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir sal_uLong ParagraphList::GetVisPos( Paragraph* pPara )
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir 	sal_uLong nVisPos = 0;
279*cdf0e10cSrcweir 	sal_uLong nPos = GetAbsPos( pPara );
280*cdf0e10cSrcweir 	for ( sal_uLong n = 0; n < nPos; n++ )
281*cdf0e10cSrcweir 	{
282*cdf0e10cSrcweir 		Paragraph* _pPara = GetParagraph( n );
283*cdf0e10cSrcweir 		if ( _pPara->IsVisible() )
284*cdf0e10cSrcweir 			nVisPos++;
285*cdf0e10cSrcweir 	}
286*cdf0e10cSrcweir 	return nVisPos;
287*cdf0e10cSrcweir }
288