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