1*190118d0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*190118d0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*190118d0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*190118d0SAndrew Rist  * distributed with this work for additional information
6*190118d0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*190118d0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*190118d0SAndrew Rist  * "License"); you may not use this file except in compliance
9*190118d0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*190118d0SAndrew Rist  *
11*190118d0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*190118d0SAndrew Rist  *
13*190118d0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*190118d0SAndrew Rist  * software distributed under the License is distributed on an
15*190118d0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*190118d0SAndrew Rist  * KIND, either express or implied.  See the License for the
17*190118d0SAndrew Rist  * specific language governing permissions and limitations
18*190118d0SAndrew Rist  * under the License.
19*190118d0SAndrew Rist  *
20*190118d0SAndrew Rist  *************************************************************/
21*190118d0SAndrew Rist 
22*190118d0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_editeng.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <paralist.hxx>
28cdf0e10cSrcweir #include <editeng/outliner.hxx>		// nur wegen Paragraph, muss geaendert werden!
29cdf0e10cSrcweir #include <editeng/numdef.hxx>
30cdf0e10cSrcweir 
DBG_NAME(Paragraph)31cdf0e10cSrcweir DBG_NAME(Paragraph)
32cdf0e10cSrcweir 
33cdf0e10cSrcweir ParagraphData::ParagraphData()
34cdf0e10cSrcweir : nDepth( -1 )
35cdf0e10cSrcweir , mnNumberingStartValue( -1 )
36cdf0e10cSrcweir , mbParaIsNumberingRestart( sal_False )
37cdf0e10cSrcweir {
38cdf0e10cSrcweir }
39cdf0e10cSrcweir 
ParagraphData(const ParagraphData & r)40cdf0e10cSrcweir ParagraphData::ParagraphData( const ParagraphData& r )
41cdf0e10cSrcweir : nDepth( r.nDepth )
42cdf0e10cSrcweir , mnNumberingStartValue( r.mnNumberingStartValue )
43cdf0e10cSrcweir , mbParaIsNumberingRestart( r.mbParaIsNumberingRestart )
44cdf0e10cSrcweir {
45cdf0e10cSrcweir }
46cdf0e10cSrcweir 
operator =(const ParagraphData & r)47cdf0e10cSrcweir ParagraphData& ParagraphData::operator=( const ParagraphData& r)
48cdf0e10cSrcweir {
49cdf0e10cSrcweir     nDepth = r.nDepth;
50cdf0e10cSrcweir     mnNumberingStartValue = r.mnNumberingStartValue;
51cdf0e10cSrcweir     mbParaIsNumberingRestart = r.mbParaIsNumberingRestart;
52cdf0e10cSrcweir     return *this;
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
operator ==(const ParagraphData & rCandidate) const55cdf0e10cSrcweir bool ParagraphData::operator==(const ParagraphData& rCandidate) const
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     return (nDepth == rCandidate.nDepth
58cdf0e10cSrcweir         && mnNumberingStartValue == rCandidate.mnNumberingStartValue
59cdf0e10cSrcweir         && mbParaIsNumberingRestart == rCandidate.mbParaIsNumberingRestart);
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
Paragraph(sal_Int16 nDDepth)62cdf0e10cSrcweir Paragraph::Paragraph( sal_Int16 nDDepth )
63cdf0e10cSrcweir : aBulSize( -1, -1)
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	DBG_CTOR( Paragraph, 0 );
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     DBG_ASSERT(  ( nDDepth >= -1 ) && ( nDDepth < SVX_MAX_NUM ), "Paragraph-CTOR: nDepth invalid!" );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	nDepth = nDDepth;
70cdf0e10cSrcweir 	nFlags = 0;
71cdf0e10cSrcweir 	bVisible = sal_True;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
Paragraph(const Paragraph & rPara)74cdf0e10cSrcweir Paragraph::Paragraph( const Paragraph& rPara )
75cdf0e10cSrcweir : ParagraphData( rPara )
76cdf0e10cSrcweir , aBulText( rPara.aBulText )
77cdf0e10cSrcweir , aBulSize( rPara.aBulSize )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir 	DBG_CTOR( Paragraph, 0 );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	nDepth = rPara.nDepth;
82cdf0e10cSrcweir 	nFlags = rPara.nFlags;
83cdf0e10cSrcweir 	bVisible = rPara.bVisible;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
Paragraph(const ParagraphData & rData)86cdf0e10cSrcweir Paragraph::Paragraph( const ParagraphData& rData )
87cdf0e10cSrcweir : nFlags( 0 )
88cdf0e10cSrcweir , aBulSize( -1, -1)
89cdf0e10cSrcweir , bVisible( sal_True )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 	DBG_CTOR( Paragraph, 0 );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     nDepth = rData.nDepth;
94cdf0e10cSrcweir     mnNumberingStartValue = rData.mnNumberingStartValue;
95cdf0e10cSrcweir     mbParaIsNumberingRestart = rData.mbParaIsNumberingRestart;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
~Paragraph()98cdf0e10cSrcweir Paragraph::~Paragraph()
99cdf0e10cSrcweir {
100cdf0e10cSrcweir 	DBG_DTOR( Paragraph, 0 );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
SetNumberingStartValue(sal_Int16 nNumberingStartValue)103cdf0e10cSrcweir void Paragraph::SetNumberingStartValue( sal_Int16 nNumberingStartValue )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     mnNumberingStartValue = nNumberingStartValue;
106cdf0e10cSrcweir     if( mnNumberingStartValue != -1 )
107cdf0e10cSrcweir         mbParaIsNumberingRestart = true;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
SetParaIsNumberingRestart(sal_Bool bParaIsNumberingRestart)110cdf0e10cSrcweir void Paragraph::SetParaIsNumberingRestart( sal_Bool bParaIsNumberingRestart )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir     mbParaIsNumberingRestart = bParaIsNumberingRestart;
113cdf0e10cSrcweir     if( !mbParaIsNumberingRestart )
114cdf0e10cSrcweir         mnNumberingStartValue = -1;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
Clear(sal_Bool bDestroyParagraphs)117cdf0e10cSrcweir void ParagraphList::Clear( sal_Bool bDestroyParagraphs )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir 	if ( bDestroyParagraphs )
120cdf0e10cSrcweir 	{
121cdf0e10cSrcweir 		for ( sal_uLong n = GetParagraphCount(); n; )
122cdf0e10cSrcweir 		{
123cdf0e10cSrcweir 			Paragraph* pPara = GetParagraph( --n );
124cdf0e10cSrcweir 			delete pPara;
125cdf0e10cSrcweir 		}
126cdf0e10cSrcweir 	}
127cdf0e10cSrcweir 	List::Clear();
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
MoveParagraphs(sal_uLong nStart,sal_uLong nDest,sal_uLong _nCount)130cdf0e10cSrcweir void ParagraphList::MoveParagraphs( sal_uLong nStart, sal_uLong nDest, sal_uLong _nCount )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir 	if ( ( nDest < nStart ) || ( nDest >= ( nStart + _nCount ) ) )
133cdf0e10cSrcweir 	{
134cdf0e10cSrcweir 		sal_uLong n;
135cdf0e10cSrcweir 		ParagraphList aParas;
136cdf0e10cSrcweir 		for ( n = 0; n < _nCount; n++ )
137cdf0e10cSrcweir 		{
138cdf0e10cSrcweir 			Paragraph* pPara = GetParagraph( nStart );
139cdf0e10cSrcweir 			aParas.Insert( pPara, LIST_APPEND );
140cdf0e10cSrcweir 			Remove( nStart );
141cdf0e10cSrcweir 		}
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 		if ( nDest > nStart )
144cdf0e10cSrcweir 			nDest -= _nCount;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 		for ( n = 0; n < _nCount; n++ )
147cdf0e10cSrcweir 		{
148cdf0e10cSrcweir 			Paragraph* pPara = aParas.GetParagraph( n );
149cdf0e10cSrcweir 			Insert( pPara, nDest++ );
150cdf0e10cSrcweir 		}
151cdf0e10cSrcweir 	}
152cdf0e10cSrcweir 	else
153cdf0e10cSrcweir 	{
154cdf0e10cSrcweir 		DBG_ERROR( "MoveParagraphs: Invalid Parameters" );
155cdf0e10cSrcweir 	}
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
NextVisible(Paragraph * pPara) const158cdf0e10cSrcweir Paragraph* ParagraphList::NextVisible( Paragraph* pPara ) const
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	sal_uLong n = GetAbsPos( pPara );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	Paragraph* p = GetParagraph( ++n );
163cdf0e10cSrcweir 	while ( p && !p->IsVisible() )
164cdf0e10cSrcweir 		p = GetParagraph( ++n );
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 	return p;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
PrevVisible(Paragraph * pPara) const169cdf0e10cSrcweir Paragraph* ParagraphList::PrevVisible( Paragraph* pPara ) const
170cdf0e10cSrcweir {
171cdf0e10cSrcweir 	sal_uLong n = GetAbsPos( pPara );
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 	Paragraph* p = n ? GetParagraph( --n ) : NULL;
174cdf0e10cSrcweir 	while ( p && !p->IsVisible() )
175cdf0e10cSrcweir 		p = n ? GetParagraph( --n ) : NULL;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	return p;
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
LastVisible() const180cdf0e10cSrcweir Paragraph* ParagraphList::LastVisible() const
181cdf0e10cSrcweir {
182cdf0e10cSrcweir 	sal_uLong n = GetParagraphCount();
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	Paragraph* p = n ? GetParagraph( --n ) : NULL;
185cdf0e10cSrcweir 	while ( p && !p->IsVisible() )
186cdf0e10cSrcweir 		p = n ? GetParagraph( --n ) : NULL;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	return p;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir 
HasChilds(Paragraph * pParagraph) const191cdf0e10cSrcweir sal_Bool ParagraphList::HasChilds( Paragraph* pParagraph ) const
192cdf0e10cSrcweir {
193cdf0e10cSrcweir 	sal_uLong n = GetAbsPos( pParagraph );
194cdf0e10cSrcweir 	Paragraph* pNext = GetParagraph( ++n );
195cdf0e10cSrcweir 	return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) ) ? sal_True : sal_False;
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
HasHiddenChilds(Paragraph * pParagraph) const198cdf0e10cSrcweir sal_Bool ParagraphList::HasHiddenChilds( Paragraph* pParagraph ) const
199cdf0e10cSrcweir {
200cdf0e10cSrcweir 	sal_uLong n = GetAbsPos( pParagraph );
201cdf0e10cSrcweir 	Paragraph* pNext = GetParagraph( ++n );
202cdf0e10cSrcweir 	return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && !pNext->IsVisible() ) ? sal_True : sal_False;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
HasVisibleChilds(Paragraph * pParagraph) const205cdf0e10cSrcweir sal_Bool ParagraphList::HasVisibleChilds( Paragraph* pParagraph ) const
206cdf0e10cSrcweir {
207cdf0e10cSrcweir 	sal_uLong n = GetAbsPos( pParagraph );
208cdf0e10cSrcweir 	Paragraph* pNext = GetParagraph( ++n );
209cdf0e10cSrcweir 	return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && pNext->IsVisible() ) ? sal_True : sal_False;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir 
GetChildCount(Paragraph * pParent) const212cdf0e10cSrcweir sal_uLong ParagraphList::GetChildCount( Paragraph* pParent ) const
213cdf0e10cSrcweir {
214cdf0e10cSrcweir 	sal_uLong nChildCount = 0;
215cdf0e10cSrcweir 	sal_uLong n = GetAbsPos( pParent );
216cdf0e10cSrcweir 	Paragraph* pPara = GetParagraph( ++n );
217cdf0e10cSrcweir 	while ( pPara && ( pPara->GetDepth() > pParent->GetDepth() ) )
218cdf0e10cSrcweir 	{
219cdf0e10cSrcweir 		nChildCount++;
220cdf0e10cSrcweir 		pPara = GetParagraph( ++n );
221cdf0e10cSrcweir 	}
222cdf0e10cSrcweir 	return nChildCount;
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
GetParent(Paragraph * pParagraph) const225cdf0e10cSrcweir Paragraph* ParagraphList::GetParent( Paragraph* pParagraph /*, sal_uInt16& rRelPos */ ) const
226cdf0e10cSrcweir {
227cdf0e10cSrcweir 	/* rRelPos = 0 */;
228cdf0e10cSrcweir 	sal_uLong n = GetAbsPos( pParagraph );
229cdf0e10cSrcweir 	Paragraph* pPrev = GetParagraph( --n );
230cdf0e10cSrcweir 	while ( pPrev && ( pPrev->GetDepth() >= pParagraph->GetDepth() ) )
231cdf0e10cSrcweir 	{
232cdf0e10cSrcweir //		if ( pPrev->GetDepth() == pParagraph->GetDepth() )
233cdf0e10cSrcweir //			rRelPos++;
234cdf0e10cSrcweir 		pPrev = GetParagraph( --n );
235cdf0e10cSrcweir 	}
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 	return pPrev;
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
Expand(Paragraph * pParent)240cdf0e10cSrcweir void ParagraphList::Expand( Paragraph* pParent )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir 	sal_uLong nChildCount = GetChildCount( pParent );
243cdf0e10cSrcweir 	sal_uLong nPos = GetAbsPos( pParent );
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 	for ( sal_uLong n = 1; n <= nChildCount; n++  )
246cdf0e10cSrcweir 	{
247cdf0e10cSrcweir 		Paragraph* pPara = GetParagraph( nPos+n );
248cdf0e10cSrcweir 		if ( !( pPara->IsVisible() ) )
249cdf0e10cSrcweir 		{
250cdf0e10cSrcweir 			pPara->bVisible = sal_True;
251cdf0e10cSrcweir 			aVisibleStateChangedHdl.Call( pPara );
252cdf0e10cSrcweir 		}
253cdf0e10cSrcweir 	}
254cdf0e10cSrcweir }
255cdf0e10cSrcweir 
Collapse(Paragraph * pParent)256cdf0e10cSrcweir void ParagraphList::Collapse( Paragraph* pParent )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir 	sal_uLong nChildCount = GetChildCount( pParent );
259cdf0e10cSrcweir 	sal_uLong nPos = GetAbsPos( pParent );
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 	for ( sal_uLong n = 1; n <= nChildCount; n++  )
262cdf0e10cSrcweir 	{
263cdf0e10cSrcweir 		Paragraph* pPara = GetParagraph( nPos+n );
264cdf0e10cSrcweir 		if ( pPara->IsVisible() )
265cdf0e10cSrcweir 		{
266cdf0e10cSrcweir 			pPara->bVisible = sal_False;
267cdf0e10cSrcweir 			aVisibleStateChangedHdl.Call( pPara );
268cdf0e10cSrcweir 		}
269cdf0e10cSrcweir 	}
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
GetVisPos(Paragraph * pPara)272cdf0e10cSrcweir sal_uLong ParagraphList::GetVisPos( Paragraph* pPara )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir 	sal_uLong nVisPos = 0;
275cdf0e10cSrcweir 	sal_uLong nPos = GetAbsPos( pPara );
276cdf0e10cSrcweir 	for ( sal_uLong n = 0; n < nPos; n++ )
277cdf0e10cSrcweir 	{
278cdf0e10cSrcweir 		Paragraph* _pPara = GetParagraph( n );
279cdf0e10cSrcweir 		if ( _pPara->IsVisible() )
280cdf0e10cSrcweir 			nVisPos++;
281cdf0e10cSrcweir 	}
282cdf0e10cSrcweir 	return nVisPos;
283cdf0e10cSrcweir }
284