Update ooo320-m1
[ooovba.git] / svx / source / outliner / paralist.cxx
blobe5493a24dc13d139448bfd9ab13e0899a98b0690
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: paralist.cxx,v $
10 * $Revision: 1.11.6.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <paralist.hxx>
35 #include <svx/outliner.hxx> // nur wegen Paragraph, muss geaendert werden!
36 #include <svx/numdef.hxx>
38 DBG_NAME(Paragraph)
40 ParagraphData::ParagraphData()
41 : nDepth( -1 )
42 , mnNumberingStartValue( -1 )
43 , mbParaIsNumberingRestart( sal_False )
47 ParagraphData::ParagraphData( const ParagraphData& r )
48 : nDepth( r.nDepth )
49 , mnNumberingStartValue( r.mnNumberingStartValue )
50 , mbParaIsNumberingRestart( r.mbParaIsNumberingRestart )
54 ParagraphData& ParagraphData::operator=( const ParagraphData& r)
56 nDepth = r.nDepth;
57 mnNumberingStartValue = r.mnNumberingStartValue;
58 mbParaIsNumberingRestart = r.mbParaIsNumberingRestart;
59 return *this;
62 bool ParagraphData::operator==(const ParagraphData& rCandidate) const
64 return (nDepth == rCandidate.nDepth
65 && mnNumberingStartValue == rCandidate.mnNumberingStartValue
66 && mbParaIsNumberingRestart == rCandidate.mbParaIsNumberingRestart);
69 Paragraph::Paragraph( sal_Int16 nDDepth )
70 : aBulSize( -1, -1)
72 DBG_CTOR( Paragraph, 0 );
74 DBG_ASSERT( ( nDDepth >= -1 ) && ( nDDepth < SVX_MAX_NUM ), "Paragraph-CTOR: nDepth invalid!" );
76 nDepth = nDDepth;
77 nFlags = 0;
78 bVisible = TRUE;
81 Paragraph::Paragraph( const Paragraph& rPara )
82 : ParagraphData( rPara )
83 , aBulText( rPara.aBulText )
84 , aBulSize( rPara.aBulSize )
86 DBG_CTOR( Paragraph, 0 );
88 nDepth = rPara.nDepth;
89 nFlags = rPara.nFlags;
90 bVisible = rPara.bVisible;
93 Paragraph::Paragraph( const ParagraphData& rData )
94 : nFlags( 0 )
95 , aBulSize( -1, -1)
96 , bVisible( TRUE )
98 DBG_CTOR( Paragraph, 0 );
100 nDepth = rData.nDepth;
101 mnNumberingStartValue = rData.mnNumberingStartValue;
102 mbParaIsNumberingRestart = rData.mbParaIsNumberingRestart;
105 Paragraph::~Paragraph()
107 DBG_DTOR( Paragraph, 0 );
110 void Paragraph::SetNumberingStartValue( sal_Int16 nNumberingStartValue )
112 mnNumberingStartValue = nNumberingStartValue;
113 if( mnNumberingStartValue != -1 )
114 mbParaIsNumberingRestart = true;
117 void Paragraph::SetParaIsNumberingRestart( sal_Bool bParaIsNumberingRestart )
119 mbParaIsNumberingRestart = bParaIsNumberingRestart;
120 if( !mbParaIsNumberingRestart )
121 mnNumberingStartValue = -1;
124 void ParagraphList::Clear( BOOL bDestroyParagraphs )
126 if ( bDestroyParagraphs )
128 for ( ULONG n = GetParagraphCount(); n; )
130 Paragraph* pPara = GetParagraph( --n );
131 delete pPara;
134 List::Clear();
137 void ParagraphList::MoveParagraphs( ULONG nStart, ULONG nDest, ULONG _nCount )
139 if ( ( nDest < nStart ) || ( nDest >= ( nStart + _nCount ) ) )
141 ULONG n;
142 ParagraphList aParas;
143 for ( n = 0; n < _nCount; n++ )
145 Paragraph* pPara = GetParagraph( nStart );
146 aParas.Insert( pPara, LIST_APPEND );
147 Remove( nStart );
150 if ( nDest > nStart )
151 nDest -= _nCount;
153 for ( n = 0; n < _nCount; n++ )
155 Paragraph* pPara = aParas.GetParagraph( n );
156 Insert( pPara, nDest++ );
159 else
161 DBG_ERROR( "MoveParagraphs: Invalid Parameters" );
165 Paragraph* ParagraphList::NextVisible( Paragraph* pPara ) const
167 ULONG n = GetAbsPos( pPara );
169 Paragraph* p = GetParagraph( ++n );
170 while ( p && !p->IsVisible() )
171 p = GetParagraph( ++n );
173 return p;
176 Paragraph* ParagraphList::PrevVisible( Paragraph* pPara ) const
178 ULONG n = GetAbsPos( pPara );
180 Paragraph* p = n ? GetParagraph( --n ) : NULL;
181 while ( p && !p->IsVisible() )
182 p = n ? GetParagraph( --n ) : NULL;
184 return p;
187 Paragraph* ParagraphList::LastVisible() const
189 ULONG n = GetParagraphCount();
191 Paragraph* p = n ? GetParagraph( --n ) : NULL;
192 while ( p && !p->IsVisible() )
193 p = n ? GetParagraph( --n ) : NULL;
195 return p;
198 BOOL ParagraphList::HasChilds( Paragraph* pParagraph ) const
200 ULONG n = GetAbsPos( pParagraph );
201 Paragraph* pNext = GetParagraph( ++n );
202 return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) ) ? TRUE : FALSE;
205 BOOL ParagraphList::HasHiddenChilds( Paragraph* pParagraph ) const
207 ULONG n = GetAbsPos( pParagraph );
208 Paragraph* pNext = GetParagraph( ++n );
209 return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && !pNext->IsVisible() ) ? TRUE : FALSE;
212 BOOL ParagraphList::HasVisibleChilds( Paragraph* pParagraph ) const
214 ULONG n = GetAbsPos( pParagraph );
215 Paragraph* pNext = GetParagraph( ++n );
216 return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && pNext->IsVisible() ) ? TRUE : FALSE;
219 ULONG ParagraphList::GetChildCount( Paragraph* pParent ) const
221 ULONG nChildCount = 0;
222 ULONG n = GetAbsPos( pParent );
223 Paragraph* pPara = GetParagraph( ++n );
224 while ( pPara && ( pPara->GetDepth() > pParent->GetDepth() ) )
226 nChildCount++;
227 pPara = GetParagraph( ++n );
229 return nChildCount;
232 Paragraph* ParagraphList::GetParent( Paragraph* pParagraph /*, USHORT& rRelPos */ ) const
234 /* rRelPos = 0 */;
235 ULONG n = GetAbsPos( pParagraph );
236 Paragraph* pPrev = GetParagraph( --n );
237 while ( pPrev && ( pPrev->GetDepth() >= pParagraph->GetDepth() ) )
239 // if ( pPrev->GetDepth() == pParagraph->GetDepth() )
240 // rRelPos++;
241 pPrev = GetParagraph( --n );
244 return pPrev;
247 void ParagraphList::Expand( Paragraph* pParent )
249 ULONG nChildCount = GetChildCount( pParent );
250 ULONG nPos = GetAbsPos( pParent );
252 for ( ULONG n = 1; n <= nChildCount; n++ )
254 Paragraph* pPara = GetParagraph( nPos+n );
255 if ( !( pPara->IsVisible() ) )
257 pPara->bVisible = TRUE;
258 aVisibleStateChangedHdl.Call( pPara );
263 void ParagraphList::Collapse( Paragraph* pParent )
265 ULONG nChildCount = GetChildCount( pParent );
266 ULONG nPos = GetAbsPos( pParent );
268 for ( ULONG n = 1; n <= nChildCount; n++ )
270 Paragraph* pPara = GetParagraph( nPos+n );
271 if ( pPara->IsVisible() )
273 pPara->bVisible = FALSE;
274 aVisibleStateChangedHdl.Call( pPara );
279 ULONG ParagraphList::GetVisPos( Paragraph* pPara )
281 ULONG nVisPos = 0;
282 ULONG nPos = GetAbsPos( pPara );
283 for ( ULONG n = 0; n < nPos; n++ )
285 Paragraph* _pPara = GetParagraph( n );
286 if ( _pPara->IsVisible() )
287 nVisPos++;
289 return nVisPos;