1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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>
40 ParagraphData::ParagraphData()
42 , mnNumberingStartValue( -1 )
43 , mbParaIsNumberingRestart( sal_False
)
47 ParagraphData::ParagraphData( const ParagraphData
& r
)
49 , mnNumberingStartValue( r
.mnNumberingStartValue
)
50 , mbParaIsNumberingRestart( r
.mbParaIsNumberingRestart
)
54 ParagraphData
& ParagraphData::operator=( const ParagraphData
& r
)
57 mnNumberingStartValue
= r
.mnNumberingStartValue
;
58 mbParaIsNumberingRestart
= r
.mbParaIsNumberingRestart
;
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
)
72 DBG_CTOR( Paragraph
, 0 );
74 DBG_ASSERT( ( nDDepth
>= -1 ) && ( nDDepth
< SVX_MAX_NUM
), "Paragraph-CTOR: nDepth invalid!" );
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
)
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
);
137 void ParagraphList::MoveParagraphs( ULONG nStart
, ULONG nDest
, ULONG _nCount
)
139 if ( ( nDest
< nStart
) || ( nDest
>= ( nStart
+ _nCount
) ) )
142 ParagraphList aParas
;
143 for ( n
= 0; n
< _nCount
; n
++ )
145 Paragraph
* pPara
= GetParagraph( nStart
);
146 aParas
.Insert( pPara
, LIST_APPEND
);
150 if ( nDest
> nStart
)
153 for ( n
= 0; n
< _nCount
; n
++ )
155 Paragraph
* pPara
= aParas
.GetParagraph( n
);
156 Insert( pPara
, nDest
++ );
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
);
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
;
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
;
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() ) )
227 pPara
= GetParagraph( ++n
);
232 Paragraph
* ParagraphList::GetParent( Paragraph
* pParagraph
/*, USHORT& rRelPos */ ) const
235 ULONG n
= GetAbsPos( pParagraph
);
236 Paragraph
* pPrev
= GetParagraph( --n
);
237 while ( pPrev
&& ( pPrev
->GetDepth() >= pParagraph
->GetDepth() ) )
239 // if ( pPrev->GetDepth() == pParagraph->GetDepth() )
241 pPrev
= GetParagraph( --n
);
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
)
282 ULONG nPos
= GetAbsPos( pPara
);
283 for ( ULONG n
= 0; n
< nPos
; n
++ )
285 Paragraph
* _pPara
= GetParagraph( n
);
286 if ( _pPara
->IsVisible() )