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