Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <sal/macros.h>
31 : : #include <hintids.hxx>
32 : : #include <editeng/ulspitem.hxx>
33 : : #include <editeng/lrspitem.hxx>
34 : : #include <editeng/fhgtitem.hxx>
35 : : #include <doc.hxx> // for GetAttrPool
36 : : #include <fmtcol.hxx>
37 : : #include <fmtcolfunc.hxx>
38 : : #include <hints.hxx>
39 : : #include <calc.hxx>
40 : : #include <node.hxx>
41 : : #include <numrule.hxx>
42 : : #include <paratr.hxx>
43 : : #include <switerator.hxx>
44 : : #include <svl/intitem.hxx>
45 : :
46 [ + + ][ + + ]: 300210 : TYPEINIT1( SwTxtFmtColl, SwFmtColl );
47 [ - + ][ + - ]: 10407 : TYPEINIT1( SwGrfFmtColl, SwFmtColl );
48 [ - + ][ + + ]: 32151 : TYPEINIT1( SwConditionTxtFmtColl, SwTxtFmtColl );
49 [ # # ][ # # ]: 0 : TYPEINIT1( SwCollCondition, SwClient );
50 : :
51 : : namespace TxtFmtCollFunc
52 : : {
53 : :
54 : : // #i71574#
55 : 8584 : void CheckTxtFmtCollForDeletionOfAssignmentToOutlineStyle(
56 : : SwFmt* pFmt,
57 : : const SwNumRuleItem* pNewNumRuleItem )
58 : : {
59 [ - + ]: 8584 : SwTxtFmtColl* pTxtFmtColl = dynamic_cast<SwTxtFmtColl*>(pFmt);
60 [ - + ]: 8584 : if ( !pTxtFmtColl )
61 : : {
62 : : OSL_FAIL( "<TxtFmtCollFunc::CheckTxtFmtCollFuncForDeletionOfAssignmentToOutlineStyle> - misuse of method - it's only for instances of <SwTxtFmtColl>" );
63 : 8584 : return;
64 : : }
65 : :
66 : : // #i73790#
67 [ + + + + ]: 16985 : if ( !pTxtFmtColl->StayAssignedToListLevelOfOutlineStyle() &&
[ + + ]
68 : 8401 : pTxtFmtColl->IsAssignedToListLevelOfOutlineStyle() )
69 : : {
70 [ + + ]: 626 : if ( !pNewNumRuleItem )
71 : : {
72 : 521 : pTxtFmtColl->GetItemState( RES_PARATR_NUMRULE, sal_False, (const SfxPoolItem**)&pNewNumRuleItem );
73 : : }
74 [ + - ]: 626 : if ( pNewNumRuleItem )
75 : : {
76 [ + - ]: 626 : String sNumRuleName = pNewNumRuleItem->GetValue();
77 [ + - ][ - + ]: 1252 : if ( sNumRuleName.Len() == 0 ||
[ - + ]
78 [ + - ]: 626 : sNumRuleName != pTxtFmtColl->GetDoc()->GetOutlineNumRule()->GetName() )
79 : : {
80 : : // delete assignment of paragraph style to list level of outline style.
81 [ # # ]: 0 : pTxtFmtColl->DeleteAssignmentToListLevelOfOutlineStyle();
82 [ + - ]: 626 : }
83 : : }
84 : : }
85 : : }
86 : :
87 : 980 : SwNumRule* GetNumRule( SwTxtFmtColl& rTxtFmtColl )
88 : : {
89 : 980 : SwNumRule* pNumRule( 0 );
90 : :
91 : 980 : const SwNumRuleItem* pNumRuleItem( 0 );
92 [ + - ]: 980 : rTxtFmtColl.GetItemState( RES_PARATR_NUMRULE, sal_False, (const SfxPoolItem**)&pNumRuleItem );
93 [ + + ]: 980 : if ( pNumRuleItem )
94 : : {
95 [ + - ]: 499 : const String sNumRuleName = pNumRuleItem->GetValue();
96 [ + + ]: 499 : if ( sNumRuleName.Len() > 0 )
97 : : {
98 [ + - ]: 472 : pNumRule = rTxtFmtColl.GetDoc()->FindNumRulePtr( sNumRuleName );
99 [ + - ]: 499 : }
100 : : }
101 : :
102 : 980 : return pNumRule;
103 : : }
104 : :
105 : 490 : void AddToNumRule( SwTxtFmtColl& rTxtFmtColl )
106 : : {
107 : 490 : SwNumRule* pNumRule = GetNumRule( rTxtFmtColl );
108 [ + + ]: 490 : if ( pNumRule )
109 : : {
110 : 472 : pNumRule->AddParagraphStyle( rTxtFmtColl );
111 : : }
112 : 490 : }
113 : :
114 : 490 : void RemoveFromNumRule( SwTxtFmtColl& rTxtFmtColl )
115 : : {
116 : 490 : SwNumRule* pNumRule = GetNumRule( rTxtFmtColl );
117 [ - + ]: 490 : if ( pNumRule )
118 : : {
119 : 0 : pNumRule->RemoveParagraphStyle( rTxtFmtColl );
120 : : }
121 : 490 : }
122 : : } // end of namespace TxtFmtCollFunc
123 : :
124 : : /*
125 : : * SwTxtFmtColl TXT
126 : : */
127 : :
128 : 112051 : void SwTxtFmtColl::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
129 : : {
130 [ + + ]: 112051 : if( GetDoc()->IsInDtor() )
131 : : {
132 [ + - ]: 1787 : SwFmtColl::Modify( pOld, pNew );
133 : 112051 : return;
134 : : }
135 : :
136 : 110264 : bool bNewParent( false ); // #i66431# - adjust type of <bNewParent>
137 : 110264 : SvxULSpaceItem *pNewULSpace = 0, *pOldULSpace = 0;
138 : 110264 : SvxLRSpaceItem *pNewLRSpace = 0, *pOldLRSpace = 0;
139 : 110264 : SvxFontHeightItem* aFontSizeArr[3] = {0,0,0};
140 : : // #i70223#
141 : 110264 : const bool bAssignedToListLevelOfOutlineStyle(IsAssignedToListLevelOfOutlineStyle());//#outline level ,zhaojianwei
142 : 110264 : const SwNumRuleItem* pNewNumRuleItem( 0L );
143 : :
144 : 110264 : SwAttrSetChg *pNewChgSet = 0, *pOldChgSet = 0;
145 : :
146 [ # # ][ + + : 110264 : switch( pOld ? pOld->Which() : pNew ? pNew->Which() : 0 )
- - - - -
- - ][ + - ]
147 : : {
148 : : case RES_ATTRSET_CHG:
149 : : // Only recalculate if we're not the sender!
150 : 102644 : pNewChgSet = (SwAttrSetChg*)pNew;
151 : 102644 : pOldChgSet = (SwAttrSetChg*)pOld;
152 : 102644 : pNewChgSet->GetChgSet()->GetItemState(
153 [ + - ]: 102644 : RES_LR_SPACE, sal_False, (const SfxPoolItem**)&pNewLRSpace );
154 : 102644 : pNewChgSet->GetChgSet()->GetItemState(
155 [ + - ]: 102644 : RES_UL_SPACE, sal_False, (const SfxPoolItem**)&pNewULSpace );
156 : 102644 : pNewChgSet->GetChgSet()->GetItemState( RES_CHRATR_FONTSIZE,
157 [ + - ]: 102644 : sal_False, (const SfxPoolItem**)&(aFontSizeArr[0]) );
158 : 102644 : pNewChgSet->GetChgSet()->GetItemState( RES_CHRATR_CJK_FONTSIZE,
159 [ + - ]: 102644 : sal_False, (const SfxPoolItem**)&(aFontSizeArr[1]) );
160 : 102644 : pNewChgSet->GetChgSet()->GetItemState( RES_CHRATR_CTL_FONTSIZE,
161 [ + - ]: 102644 : sal_False, (const SfxPoolItem**)&(aFontSizeArr[2]) );
162 : : // #i70223#, #i84745#
163 : : // check, if attribute set is applied to this paragraph style
164 [ + + + + ]: 103633 : if ( bAssignedToListLevelOfOutlineStyle &&
[ + + ]
165 : 989 : pNewChgSet->GetTheChgdSet() == &GetAttrSet() )
166 : : {
167 : 288 : pNewChgSet->GetChgSet()->GetItemState( RES_PARATR_NUMRULE, sal_False,
168 [ + - ]: 288 : (const SfxPoolItem**)&pNewNumRuleItem );
169 : : }
170 : :
171 : 102644 : break;
172 : :
173 : : case RES_FMT_CHG:
174 [ + + ]: 7620 : if( GetAttrSet().GetParent() )
175 : : {
176 : 5652 : const SfxItemSet* pParent = GetAttrSet().GetParent();
177 [ + - ]: 5652 : pNewLRSpace = (SvxLRSpaceItem*)&pParent->Get( RES_LR_SPACE );
178 [ + - ]: 5652 : pNewULSpace = (SvxULSpaceItem*)&pParent->Get( RES_UL_SPACE );
179 [ + - ]: 5652 : aFontSizeArr[0] = (SvxFontHeightItem*)&pParent->Get( RES_CHRATR_FONTSIZE );
180 [ + - ]: 5652 : aFontSizeArr[1] = (SvxFontHeightItem*)&pParent->Get( RES_CHRATR_CJK_FONTSIZE );
181 [ + - ]: 5652 : aFontSizeArr[2] = (SvxFontHeightItem*)&pParent->Get( RES_CHRATR_CTL_FONTSIZE );
182 : : // #i66431# - modify has to be propagated, because of new parent format.
183 : 5652 : bNewParent = true;
184 : : }
185 : 7620 : break;
186 : :
187 : : case RES_LR_SPACE:
188 : 0 : pNewLRSpace = (SvxLRSpaceItem*)pNew;
189 : 0 : break;
190 : : case RES_UL_SPACE:
191 : 0 : pNewULSpace = (SvxULSpaceItem*)pNew;
192 : 0 : break;
193 : : case RES_CHRATR_FONTSIZE:
194 : 0 : aFontSizeArr[0] = (SvxFontHeightItem*)pNew;
195 : 0 : break;
196 : : case RES_CHRATR_CJK_FONTSIZE:
197 : 0 : aFontSizeArr[1] = (SvxFontHeightItem*)pNew;
198 : 0 : break;
199 : : case RES_CHRATR_CTL_FONTSIZE:
200 : 0 : aFontSizeArr[2] = (SvxFontHeightItem*)pNew;
201 : 0 : break;
202 : : // #i70223#
203 : : case RES_PARATR_NUMRULE:
204 : : {
205 [ # # ]: 0 : if ( bAssignedToListLevelOfOutlineStyle )
206 : : {
207 : 0 : pNewNumRuleItem = (SwNumRuleItem*)pNew;
208 : : }
209 : : }
210 : : default:
211 : 0 : break;
212 : : }
213 : :
214 : : // #i70223#
215 [ + + ][ + + ]: 110264 : if ( bAssignedToListLevelOfOutlineStyle && pNewNumRuleItem )
216 : : {
217 : : TxtFmtCollFunc::CheckTxtFmtCollForDeletionOfAssignmentToOutlineStyle(
218 [ + - ]: 288 : this, pNewNumRuleItem );
219 : : }
220 : :
221 : 110264 : int bWeiter = sal_True;
222 : :
223 : : // Check against the own attributes
224 [ + + ][ + + ]: 116099 : if( pNewLRSpace && SFX_ITEM_SET == GetItemState( RES_LR_SPACE, sal_False,
[ + + ]
225 [ + - ]: 5835 : (const SfxPoolItem**)&pOldLRSpace ))
226 : : {
227 : 113 : int bChg = sal_False;
228 [ + + ]: 113 : if( pOldLRSpace != pNewLRSpace ) // Avoid recursion (SetAttr!)
229 : : {
230 [ + - ]: 87 : SvxLRSpaceItem aNew( *pOldLRSpace );
231 : : // We had a relative value -> recalculate
232 [ + + ]: 87 : if( 100 != aNew.GetPropLeft() )
233 : : {
234 : 2 : long nTmp = aNew.GetLeft(); // keep so that we can compare
235 : 2 : aNew.SetLeft( pNewLRSpace->GetLeft(), aNew.GetPropLeft() );
236 : 2 : bChg |= nTmp != aNew.GetLeft();
237 : : }
238 : : // We had a relative value -> recalculate
239 [ + + ]: 87 : if( 100 != aNew.GetPropRight() )
240 : : {
241 : 2 : long nTmp = aNew.GetRight(); // keep so that we can compare
242 : 2 : aNew.SetRight( pNewLRSpace->GetRight(), aNew.GetPropRight() );
243 : 2 : bChg |= nTmp != aNew.GetRight();
244 : : }
245 : : // We had a relative value -> recalculate
246 [ - + ]: 87 : if( 100 != aNew.GetPropTxtFirstLineOfst() )
247 : : {
248 : 0 : short nTmp = aNew.GetTxtFirstLineOfst(); // keep so that we can compare
249 : 0 : aNew.SetTxtFirstLineOfst( pNewLRSpace->GetTxtFirstLineOfst(),
250 [ # # ]: 0 : aNew.GetPropTxtFirstLineOfst() );
251 : 0 : bChg |= nTmp != aNew.GetTxtFirstLineOfst();
252 : : }
253 [ - + ]: 87 : if( bChg )
254 : : {
255 [ # # ]: 0 : SetFmtAttr( aNew );
256 [ # # ][ # # ]: 0 : bWeiter = 0 != pOldChgSet || bNewParent;
257 : : }
258 : : // We set it to absolute -> do not propagate it further, unless
259 : : // we set it!
260 [ - + ]: 87 : else if( pNewChgSet )
261 [ + - ]: 87 : bWeiter = pNewChgSet->GetTheChgdSet() == &GetAttrSet();
262 : : }
263 : : }
264 : :
265 [ + + ][ + + ]: 119325 : if( pNewULSpace && SFX_ITEM_SET == GetItemState(
[ + + ][ + + ]
266 [ + - ]: 9061 : RES_UL_SPACE, sal_False, (const SfxPoolItem**)&pOldULSpace ) &&
267 : : pOldULSpace != pNewULSpace ) // Avoid recursion (SetAttr!)
268 : : {
269 [ + - ]: 1885 : SvxULSpaceItem aNew( *pOldULSpace );
270 : 1885 : int bChg = sal_False;
271 : : // We had a relative value -> recalculate
272 [ + + ]: 1885 : if( 100 != aNew.GetPropUpper() )
273 : : {
274 : 2 : sal_uInt16 nTmp = aNew.GetUpper(); // keep so that we can compare
275 : 2 : aNew.SetUpper( pNewULSpace->GetUpper(), aNew.GetPropUpper() );
276 : 2 : bChg |= nTmp != aNew.GetUpper();
277 : : }
278 : : // We had a relative value -> recalculate
279 [ + + ]: 1885 : if( 100 != aNew.GetPropLower() )
280 : : {
281 : 2 : sal_uInt16 nTmp = aNew.GetLower(); // keep so that we can compare
282 : 2 : aNew.SetLower( pNewULSpace->GetLower(), aNew.GetPropLower() );
283 : 2 : bChg |= nTmp != aNew.GetLower();
284 : : }
285 [ + + ]: 1885 : if( bChg )
286 : : {
287 [ + - ]: 2 : SetFmtAttr( aNew );
288 [ + - ][ + - ]: 2 : bWeiter = 0 != pOldChgSet || bNewParent;
289 : : }
290 : : // We set it to absolute -> do not propagate it further, unless
291 : : // we set it!
292 [ + + ]: 1883 : else if( pNewChgSet )
293 [ + - ]: 1885 : bWeiter = pNewChgSet->GetTheChgdSet() == &GetAttrSet();
294 : : }
295 : :
296 : :
297 [ + + ]: 441056 : for( int nC = 0, nArrLen = sizeof(aFontSizeArr) / sizeof( aFontSizeArr[0]);
298 : : nC < nArrLen; ++nC )
299 : : {
300 : 330792 : SvxFontHeightItem *pFSize = aFontSizeArr[ nC ], *pOldFSize;
301 [ + + ][ + + ]: 365937 : if( pFSize && SFX_ITEM_SET == GetItemState(
[ + + ][ + + ]
302 [ + - ]: 35145 : pFSize->Which(), sal_False, (const SfxPoolItem**)&pOldFSize ) &&
303 : : // Avoid recursion (SetAttr!)
304 : : pFSize != pOldFSize )
305 : : {
306 [ + + + - ]: 11670 : if( 100 == pOldFSize->GetProp() &&
[ + + ]
307 : 5832 : SFX_MAPUNIT_RELATIVE == pOldFSize->GetPropUnit() )
308 : : {
309 : : // We set it to absolute -> do not propagate it further, unless
310 : : // we set it!
311 [ + + ]: 5832 : if( pNewChgSet )
312 : 1870 : bWeiter = pNewChgSet->GetTheChgdSet() == &GetAttrSet();
313 : : }
314 : : else
315 : : {
316 : : // We had a relative value -> recalculate
317 : 6 : sal_uInt32 nTmp = pOldFSize->GetHeight(); // keep so that we can compare
318 [ + - ]: 6 : SvxFontHeightItem aNew(240 , 100, pFSize->Which());
319 : 6 : aNew.SetHeight( pFSize->GetHeight(), pOldFSize->GetProp(),
320 [ + - ]: 12 : pOldFSize->GetPropUnit() );
321 [ + - ]: 6 : if( nTmp != aNew.GetHeight() )
322 : : {
323 [ + - ]: 6 : SetFmtAttr( aNew );
324 [ + - ][ + - ]: 6 : bWeiter = 0 != pOldChgSet || bNewParent;
325 : : }
326 : : // We set it to absolute -> do not propagate it further, unless
327 : : // we set it!
328 [ # # ]: 0 : else if( pNewChgSet )
329 [ + - ]: 6 : bWeiter = pNewChgSet->GetTheChgdSet() == &GetAttrSet();
330 : : }
331 : : }
332 : : }
333 : :
334 [ + + ]: 110264 : if( bWeiter )
335 [ + - ]: 112051 : SwFmtColl::Modify( pOld, pNew );
336 : : }
337 : :
338 : 0 : sal_Bool SwTxtFmtColl::IsAtDocNodeSet() const
339 : : {
340 [ # # ]: 0 : SwIterator<SwCntntNode,SwFmtColl> aIter( *this );
341 [ # # ]: 0 : const SwNodes& rNds = GetDoc()->GetNodes();
342 [ # # ][ # # ]: 0 : for( SwCntntNode* pNode = aIter.First(); pNode; pNode = aIter.Next() )
[ # # ]
343 [ # # ]: 0 : if( &(pNode->GetNodes()) == &rNds )
344 : 0 : return sal_True;
345 : :
346 [ # # ]: 0 : return sal_False;
347 : : }
348 : :
349 : 25639 : sal_Bool SwTxtFmtColl::SetFmtAttr( const SfxPoolItem& rAttr )
350 : : {
351 : 25639 : const bool bIsNumRuleItem = rAttr.Which() == RES_PARATR_NUMRULE;
352 [ + + ]: 25639 : if ( bIsNumRuleItem )
353 : : {
354 : 445 : TxtFmtCollFunc::RemoveFromNumRule( *this );
355 : : }
356 : :
357 : 25639 : const sal_Bool bRet = SwFmtColl::SetFmtAttr( rAttr );
358 : :
359 [ + + ]: 25639 : if ( bIsNumRuleItem )
360 : : {
361 : 445 : TxtFmtCollFunc::AddToNumRule( *this );
362 : : }
363 : :
364 : 25639 : return bRet;
365 : : }
366 : :
367 : 10316 : sal_Bool SwTxtFmtColl::SetFmtAttr( const SfxItemSet& rSet )
368 : : {
369 : : const bool bIsNumRuleItemAffected =
370 : 10316 : rSet.GetItemState( RES_PARATR_NUMRULE, sal_False ) == SFX_ITEM_SET;
371 [ + + ]: 10316 : if ( bIsNumRuleItemAffected )
372 : : {
373 : 45 : TxtFmtCollFunc::RemoveFromNumRule( *this );
374 : : }
375 : :
376 : 10316 : const sal_Bool bRet = SwFmtColl::SetFmtAttr( rSet );
377 : :
378 [ + + ]: 10316 : if ( bIsNumRuleItemAffected )
379 : : {
380 : 45 : TxtFmtCollFunc::AddToNumRule( *this );
381 : : }
382 : :
383 : 10316 : return bRet;
384 : : }
385 : :
386 : 10425 : sal_Bool SwTxtFmtColl::ResetFmtAttr( sal_uInt16 nWhich1, sal_uInt16 nWhich2 )
387 : : {
388 : : const bool bIsNumRuleItemAffected =
389 : : ( nWhich2 != 0 && nWhich2 > nWhich1 )
390 : : ? ( nWhich1 <= RES_PARATR_NUMRULE &&
391 : : RES_PARATR_NUMRULE <= nWhich2 )
392 [ - + ][ # # ]: 10425 : : nWhich1 == RES_PARATR_NUMRULE;
[ # # ][ # # ]
393 [ - + ]: 10425 : if ( bIsNumRuleItemAffected )
394 : : {
395 : 0 : TxtFmtCollFunc::RemoveFromNumRule( *this );
396 : : }
397 : :
398 : 10425 : const sal_Bool bRet = SwFmtColl::ResetFmtAttr( nWhich1, nWhich2 );
399 : :
400 : 10425 : return bRet;
401 : : }
402 : :
403 : : // #i73790#
404 : 1172 : sal_uInt16 SwTxtFmtColl::ResetAllFmtAttr()
405 : : {
406 : 1172 : const bool bOldState( mbStayAssignedToListLevelOfOutlineStyle );
407 : 1172 : mbStayAssignedToListLevelOfOutlineStyle = true;
408 : : // #i70748#
409 : : // Outline level is no longer a member, it is a attribute now.
410 : : // Thus, it needs to be restored, if the paragraph style is assigned
411 : : // to the outline style
412 : 1172 : const int nAssignedOutlineStyleLevel = IsAssignedToListLevelOfOutlineStyle()
413 : : ? GetAssignedOutlineStyleLevel()
414 [ + + ]: 1172 : : -1;
415 : :
416 : 1172 : sal_uInt16 nRet = SwFmtColl::ResetAllFmtAttr();
417 : :
418 : : // #i70748#
419 [ + + ]: 1172 : if ( nAssignedOutlineStyleLevel != -1 )
420 : : {
421 : 183 : AssignToListLevelOfOutlineStyle( nAssignedOutlineStyleLevel );
422 : : }
423 : :
424 : 1172 : mbStayAssignedToListLevelOfOutlineStyle = bOldState;
425 : :
426 : 1172 : return nRet;
427 : : }
428 : :
429 : 0 : bool SwTxtFmtColl::AreListLevelIndentsApplicable() const
430 : : {
431 : 0 : bool bAreListLevelIndentsApplicable( true );
432 : :
433 [ # # ]: 0 : if ( GetItemState( RES_PARATR_NUMRULE ) != SFX_ITEM_SET )
434 : : {
435 : : // no list style applied to paragraph style
436 : 0 : bAreListLevelIndentsApplicable = false;
437 : : }
438 [ # # ]: 0 : else if ( GetItemState( RES_LR_SPACE, sal_False ) == SFX_ITEM_SET )
439 : : {
440 : : // paragraph style has hard-set indent attributes
441 : 0 : bAreListLevelIndentsApplicable = false;
442 : : }
443 [ # # ]: 0 : else if ( GetItemState( RES_PARATR_NUMRULE, sal_False ) == SFX_ITEM_SET )
444 : : {
445 : : // list style is directly applied to paragraph style and paragraph
446 : : // style has no hard-set indent attributes
447 : 0 : bAreListLevelIndentsApplicable = true;
448 : : }
449 : : else
450 : : {
451 : : // list style is applied through one of the parent paragraph styles and
452 : : // paragraph style has no hard-set indent attributes
453 : :
454 : : // check parent paragraph styles
455 [ # # ]: 0 : const SwTxtFmtColl* pColl = dynamic_cast<const SwTxtFmtColl*>(DerivedFrom());
456 [ # # ]: 0 : while ( pColl )
457 : : {
458 [ # # ]: 0 : if ( pColl->GetAttrSet().GetItemState( RES_LR_SPACE, sal_False ) == SFX_ITEM_SET )
459 : : {
460 : : // indent attributes found in the paragraph style hierarchy.
461 : 0 : bAreListLevelIndentsApplicable = false;
462 : 0 : break;
463 : : }
464 : :
465 [ # # ]: 0 : if ( pColl->GetAttrSet().GetItemState( RES_PARATR_NUMRULE, sal_False ) == SFX_ITEM_SET )
466 : : {
467 : : // paragraph style with the list style found and until now no
468 : : // indent attributes are found in the paragraph style hierarchy.
469 : 0 : bAreListLevelIndentsApplicable = true;
470 : 0 : break;
471 : : }
472 : :
473 [ # # ]: 0 : pColl = dynamic_cast<const SwTxtFmtColl*>(pColl->DerivedFrom());
474 : : OSL_ENSURE( pColl,
475 : : "<SwTxtFmtColl::AreListLevelIndentsApplicable()> - something wrong in paragraph style hierarchy. The applied list style is not found." );
476 : : }
477 : : }
478 : :
479 : 0 : return bAreListLevelIndentsApplicable;
480 : : }
481 : :
482 : : //FEATURE::CONDCOLL
483 : :
484 : 135 : SwCollCondition::SwCollCondition( SwTxtFmtColl* pColl, sal_uLong nMasterCond,
485 : : sal_uLong nSubCond )
486 : 135 : : SwClient( pColl ), nCondition( nMasterCond )
487 : : {
488 : 135 : aSubCondition.nSubCondition = nSubCond;
489 : 135 : }
490 : :
491 : :
492 : 0 : SwCollCondition::SwCollCondition( SwTxtFmtColl* pColl, sal_uLong nMasterCond,
493 : : const String& rSubExp )
494 : 0 : : SwClient( pColl ), nCondition( nMasterCond )
495 : : {
496 [ # # ]: 0 : if( USRFLD_EXPRESSION & nCondition )
497 [ # # ][ # # ]: 0 : aSubCondition.pFldExpression = new String( rSubExp );
498 : : else
499 : 0 : aSubCondition.nSubCondition = 0;
500 : 0 : }
501 : :
502 : :
503 : 0 : SwCollCondition::SwCollCondition( const SwCollCondition& rCopy )
504 : 0 : : SwClient( (SwModify*)rCopy.GetRegisteredIn() ), nCondition( rCopy.nCondition )
505 : : {
506 [ # # ]: 0 : if( USRFLD_EXPRESSION & rCopy.nCondition )
507 [ # # ][ # # ]: 0 : aSubCondition.pFldExpression = new String( *rCopy.GetFldExpression() );
508 : : else
509 : 0 : aSubCondition.nSubCondition = rCopy.aSubCondition.nSubCondition;
510 : 0 : }
511 : :
512 : :
513 : 135 : SwCollCondition::~SwCollCondition()
514 : : {
515 [ - + ]: 135 : if( USRFLD_EXPRESSION & nCondition )
516 [ # # ][ # # ]: 0 : delete aSubCondition.pFldExpression;
517 [ - + ]: 135 : }
518 : :
519 : 0 : void SwCollCondition::RegisterToFormat( SwFmt& rFmt )
520 : : {
521 : 0 : rFmt.Add( this );
522 : 0 : }
523 : :
524 : :
525 : :
526 : 0 : int SwCollCondition::operator==( const SwCollCondition& rCmp ) const
527 : : {
528 : 0 : int nRet = 0;
529 [ # # ]: 0 : if( nCondition == rCmp.nCondition )
530 : : {
531 [ # # ]: 0 : if( USRFLD_EXPRESSION & nCondition )
532 : : {
533 : : // The SubCondition contains the expression for the UserField
534 : 0 : const String* pTmp = aSubCondition.pFldExpression;
535 [ # # ]: 0 : if( !pTmp )
536 : 0 : pTmp = rCmp.aSubCondition.pFldExpression;
537 [ # # ]: 0 : if( pTmp )
538 : : {
539 : 0 : SwTxtFmtColl* pColl = GetTxtFmtColl();
540 [ # # ]: 0 : if( !pColl )
541 : 0 : pColl = rCmp.GetTxtFmtColl();
542 : :
543 [ # # ]: 0 : if( pColl )
544 : : {
545 [ # # ]: 0 : SwCalc aCalc( *pColl->GetDoc() );
546 [ # # ][ # # ]: 0 : nRet = 0 != aCalc.Calculate( *pTmp ).GetBool();
[ # # ][ # # ]
547 : : }
548 : : }
549 : : }
550 [ # # ]: 0 : else if( aSubCondition.nSubCondition ==
551 : : rCmp.aSubCondition.nSubCondition )
552 : 0 : nRet = 1;
553 : : }
554 : 0 : return nRet;
555 : : }
556 : :
557 : :
558 : 0 : void SwCollCondition::SetCondition( sal_uLong nCond, sal_uLong nSubCond )
559 : : {
560 [ # # ]: 0 : if( USRFLD_EXPRESSION & nCondition )
561 [ # # ]: 0 : delete aSubCondition.pFldExpression;
562 : 0 : nCondition = nCond;
563 : 0 : aSubCondition.nSubCondition = nSubCond;
564 : 0 : }
565 : :
566 : :
567 [ + - ]: 1462 : SwConditionTxtFmtColl::~SwConditionTxtFmtColl()
568 : : {
569 [ - + ]: 2924 : }
570 : :
571 : 112 : const SwCollCondition* SwConditionTxtFmtColl::HasCondition(
572 : : const SwCollCondition& rCond ) const
573 : : {
574 : 112 : const SwCollCondition* pFnd = 0;
575 : : sal_uInt16 n;
576 : :
577 [ - + ]: 112 : for( n = 0; n < aCondColls.size(); ++n )
578 [ # # ]: 0 : if( *( pFnd = &aCondColls[ n ]) == rCond )
579 : 0 : break;
580 : :
581 [ - + ]: 112 : return n < aCondColls.size() ? pFnd : 0;
582 : : }
583 : :
584 : :
585 : 0 : void SwConditionTxtFmtColl::InsertCondition( const SwCollCondition& rCond )
586 : : {
587 [ # # ]: 0 : for( sal_uInt16 n = 0; n < aCondColls.size(); ++n )
588 [ # # ]: 0 : if( aCondColls[ n ] == rCond )
589 : : {
590 : 0 : aCondColls.erase( aCondColls.begin() + n );
591 : 0 : break;
592 : : }
593 : :
594 : : // Not found -> so insert it
595 [ # # ]: 0 : SwCollCondition* pNew = new SwCollCondition( rCond );
596 : 0 : aCondColls.push_back( pNew );
597 : 0 : }
598 : :
599 : :
600 : 0 : sal_Bool SwConditionTxtFmtColl::RemoveCondition( const SwCollCondition& rCond )
601 : : {
602 : 0 : sal_Bool bRet = sal_False;
603 [ # # ]: 0 : for( sal_uInt16 n = 0; n < aCondColls.size(); ++n )
604 [ # # ]: 0 : if( aCondColls[ n ] == rCond )
605 : : {
606 : 0 : aCondColls.erase( aCondColls.begin() + n );
607 : 0 : bRet = sal_True;
608 : : }
609 : :
610 : 0 : return bRet;
611 : : }
612 : :
613 : 0 : void SwConditionTxtFmtColl::SetConditions( const SwFmtCollConditions& rCndClls )
614 : : {
615 : : // Copy the Conditions, but first delete the old ones
616 : 0 : aCondColls.clear();
617 : 0 : SwDoc& rDoc = *GetDoc();
618 [ # # ]: 0 : for( sal_uInt16 n = 0; n < rCndClls.size(); ++n )
619 : : {
620 : 0 : const SwCollCondition* pFnd = &rCndClls[ n ];
621 : 0 : SwTxtFmtColl* pTmpColl = pFnd->GetTxtFmtColl()
622 : 0 : ? rDoc.CopyTxtColl( *pFnd->GetTxtFmtColl() )
623 [ # # ]: 0 : : 0;
624 : : SwCollCondition* pNew;
625 [ # # ]: 0 : if( USRFLD_EXPRESSION & pFnd->GetCondition() )
626 : : pNew = new SwCollCondition( pTmpColl, pFnd->GetCondition(),
627 [ # # ]: 0 : *pFnd->GetFldExpression() );
628 : : else
629 : : pNew = new SwCollCondition( pTmpColl, pFnd->GetCondition(),
630 [ # # ]: 0 : pFnd->GetSubCondition() );
631 : 0 : aCondColls.push_back( pNew );
632 : : }
633 : 0 : }
634 : : //#outline level, zhaojianwei
635 : 1893 : void SwTxtFmtColl::SetAttrOutlineLevel( int nLevel)
636 : : {
637 : : OSL_ENSURE( 0 <= nLevel && nLevel <= MAXLEVEL ,"SwTxtFmtColl: Level Out Of Range" );
638 : : SetFmtAttr( SfxUInt16Item( RES_PARATR_OUTLINELEVEL,
639 [ + - ]: 1893 : static_cast<sal_uInt16>(nLevel) ) );
640 : 1893 : }
641 : :
642 : 19385 : int SwTxtFmtColl::GetAttrOutlineLevel() const
643 : : {
644 : 19385 : return ((const SfxUInt16Item &)GetFmtAttr(RES_PARATR_OUTLINELEVEL)).GetValue();
645 : : }
646 : :
647 : 5571 : int SwTxtFmtColl::GetAssignedOutlineStyleLevel() const
648 : : {
649 : : OSL_ENSURE( IsAssignedToListLevelOfOutlineStyle(),
650 : : "<SwTxtFmtColl::GetAssignedOutlineStyleLevel()> - misuse of method");
651 : 5571 : return GetAttrOutlineLevel() - 1;
652 : : }
653 : :
654 : 457 : void SwTxtFmtColl::AssignToListLevelOfOutlineStyle(const int nAssignedListLevel)
655 : : {
656 : 457 : mbAssignedToOutlineStyle = true;
657 [ + - ]: 457 : SetAttrOutlineLevel(nAssignedListLevel+1);
658 : :
659 : : // #i100277#
660 [ + - ]: 457 : SwIterator<SwTxtFmtColl,SwFmtColl> aIter( *this );
661 [ + - ]: 457 : SwTxtFmtColl* pDerivedTxtFmtColl = aIter.First();
662 [ - + ]: 457 : while ( pDerivedTxtFmtColl != 0 )
663 : : {
664 [ # # ]: 0 : if ( !pDerivedTxtFmtColl->IsAssignedToListLevelOfOutlineStyle() )
665 : : {
666 [ # # ][ # # ]: 0 : if ( pDerivedTxtFmtColl->GetItemState( RES_PARATR_NUMRULE, sal_False ) == SFX_ITEM_DEFAULT )
667 : : {
668 [ # # ]: 0 : SwNumRuleItem aItem(aEmptyStr);
669 [ # # ][ # # ]: 0 : pDerivedTxtFmtColl->SetFmtAttr( aItem );
670 : : }
671 [ # # ][ # # ]: 0 : if ( pDerivedTxtFmtColl->GetItemState( RES_PARATR_OUTLINELEVEL, sal_False ) == SFX_ITEM_DEFAULT )
672 : : {
673 [ # # ]: 0 : pDerivedTxtFmtColl->SetAttrOutlineLevel( 0 );
674 : : }
675 : : }
676 : :
677 [ # # ]: 0 : pDerivedTxtFmtColl = aIter.Next();
678 [ + - ]: 457 : }
679 : 457 : }
680 : :
681 : 656 : void SwTxtFmtColl::DeleteAssignmentToListLevelOfOutlineStyle()
682 : : {
683 : 656 : mbAssignedToOutlineStyle = false;
684 : 656 : ResetFmtAttr(RES_PARATR_OUTLINELEVEL);
685 : 656 : }
686 : : //<-end,zhaojianwei
687 : :
688 : : //FEATURE::CONDCOLL
689 : :
690 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|