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_sw.hxx" 26 27 28 #define _ZFORLIST_DECLARE_TABLE 29 #define _SVSTDARR_USHORTSSORT 30 #define _SVSTDARR_USHORTS 31 #include <hintids.hxx> 32 #include <rtl/logfile.hxx> 33 #include <svl/itemiter.hxx> 34 #include <sfx2/app.hxx> 35 #include <editeng/tstpitem.hxx> 36 #include <editeng/eeitem.hxx> 37 #include <editeng/langitem.hxx> 38 #include <editeng/lrspitem.hxx> 39 #include <editeng/brkitem.hxx> 40 #include <svl/whiter.hxx> 41 #ifndef _ZFORLIST_HXX //autogen 42 #define _ZFORLIST_DECLARE_TABLE 43 #include <svl/zforlist.hxx> 44 #endif 45 #include <comphelper/processfactory.hxx> 46 #include <unotools/misccfg.hxx> 47 #include <com/sun/star/i18n/WordType.hdl> 48 #include <fmtpdsc.hxx> 49 #include <fmthdft.hxx> 50 #include <fmtcntnt.hxx> 51 #include <frmatr.hxx> 52 #include <doc.hxx> 53 #include <IDocumentUndoRedo.hxx> 54 #include <rootfrm.hxx> 55 #include <pagefrm.hxx> 56 #include <hints.hxx> // fuer SwHyphenBug (in SetDefault) 57 #include <ndtxt.hxx> 58 #include <pam.hxx> 59 #include <UndoCore.hxx> 60 #include <UndoAttribute.hxx> 61 #include <ndgrf.hxx> 62 #include <pagedesc.hxx> // Fuer Sonderbehandlung in InsFrmFmt 63 #include <rolbck.hxx> // Undo-Attr 64 #include <mvsave.hxx> // servieren: Veraenderungen erkennen 65 #include <txatbase.hxx> 66 #include <swtable.hxx> 67 #include <swtblfmt.hxx> 68 #include <charfmt.hxx> 69 #include <docary.hxx> 70 #include <paratr.hxx> 71 #include <redline.hxx> 72 #include <reffld.hxx> 73 #include <txtinet.hxx> 74 #include <fmtinfmt.hxx> 75 #include <breakit.hxx> 76 #include <SwStyleNameMapper.hxx> 77 #include <fmtautofmt.hxx> 78 #include <istyleaccess.hxx> 79 #include <SwUndoFmt.hxx> 80 #include <docsh.hxx> 81 82 using namespace ::com::sun::star::i18n; 83 using namespace ::com::sun::star::lang; 84 using namespace ::com::sun::star::uno; 85 86 SV_IMPL_PTRARR(SwFrmFmts,SwFrmFmtPtr) 87 SV_IMPL_PTRARR(SwCharFmts,SwCharFmtPtr) 88 89 //Spezifische Frameformate (Rahmen) 90 SV_IMPL_PTRARR(SwSpzFrmFmts,SwFrmFmtPtr) 91 92 /* 93 * interne Funktionen 94 */ 95 96 sal_Bool SetTxtFmtCollNext( const SwTxtFmtCollPtr& rpTxtColl, void* pArgs ) 97 { 98 SwTxtFmtColl *pDel = (SwTxtFmtColl*) pArgs; 99 if ( &rpTxtColl->GetNextTxtFmtColl() == pDel ) 100 { 101 rpTxtColl->SetNextTxtFmtColl( *rpTxtColl ); 102 } 103 return sal_True; 104 } 105 106 /* 107 * Zuruecksetzen der harten Formatierung fuer Text 108 */ 109 110 // Uebergabeparameter fuer _Rst und lcl_SetTxtFmtColl 111 struct ParaRstFmt 112 { 113 SwFmtColl* pFmtColl; 114 SwHistory* pHistory; 115 const SwPosition *pSttNd, *pEndNd; 116 const SfxItemSet* pDelSet; 117 sal_uInt16 nWhich; 118 bool bReset; 119 // --> OD 2007-11-06 #i62575# 120 bool bResetListAttrs; 121 // <-- 122 bool bResetAll; 123 bool bInclRefToxMark; 124 125 bool bKeepOutlineLevelAttr; //#outline level,add by zhaojianwei 126 127 ParaRstFmt( const SwPosition* pStt, const SwPosition* pEnd, 128 SwHistory* pHst, sal_uInt16 nWhch = 0, const SfxItemSet* pSet = 0 ) 129 : pFmtColl(0), 130 pHistory(pHst), 131 pSttNd(pStt), 132 pEndNd(pEnd), 133 pDelSet(pSet), 134 nWhich(nWhch), 135 // --> OD 2007-11-06 #i62675# 136 bReset( false ), 137 bResetListAttrs( false ), 138 // <-- 139 bResetAll( true ), 140 bInclRefToxMark( false ), 141 bKeepOutlineLevelAttr( false ) //#outline level,add by zhaojianwei 142 {} 143 144 ParaRstFmt( SwHistory* pHst ) 145 : pFmtColl(0), 146 pHistory(pHst), 147 pSttNd(0), 148 pEndNd(0), 149 pDelSet(0), 150 nWhich(0), 151 // --> OD 2007-11-06 #i62675# 152 bReset( false ), 153 bResetListAttrs( false ), 154 // <-- 155 bResetAll( true ), 156 bInclRefToxMark( false ), 157 bKeepOutlineLevelAttr( false ) //#outline level,add by zhaojianwei 158 {} 159 }; 160 161 /* in pArgs steht die ChrFmtTablle vom Dokument 162 * (wird bei Selectionen am Start/Ende und bei keiner SSelection benoetigt) 163 */ 164 165 sal_Bool lcl_RstTxtAttr( const SwNodePtr& rpNd, void* pArgs ) 166 { 167 ParaRstFmt* pPara = (ParaRstFmt*)pArgs; 168 SwTxtNode * pTxtNode = (SwTxtNode*)rpNd->GetTxtNode(); 169 if( pTxtNode && pTxtNode->GetpSwpHints() ) 170 { 171 SwIndex aSt( pTxtNode, 0 ); 172 sal_uInt16 nEnd = pTxtNode->Len(); 173 174 if( &pPara->pSttNd->nNode.GetNode() == pTxtNode && 175 pPara->pSttNd->nContent.GetIndex() ) 176 aSt = pPara->pSttNd->nContent.GetIndex(); 177 178 if( &pPara->pEndNd->nNode.GetNode() == rpNd ) 179 nEnd = pPara->pEndNd->nContent.GetIndex(); 180 181 if( pPara->pHistory ) 182 { 183 // fuers Undo alle Attribute sichern 184 SwRegHistory aRHst( *pTxtNode, pPara->pHistory ); 185 pTxtNode->GetpSwpHints()->Register( &aRHst ); 186 pTxtNode->RstAttr( aSt, nEnd - aSt.GetIndex(), pPara->nWhich, 187 pPara->pDelSet, pPara->bInclRefToxMark ); 188 if( pTxtNode->GetpSwpHints() ) 189 pTxtNode->GetpSwpHints()->DeRegister(); 190 } 191 else 192 pTxtNode->RstAttr( aSt, nEnd - aSt.GetIndex(), pPara->nWhich, 193 pPara->pDelSet, pPara->bInclRefToxMark ); 194 } 195 return sal_True; 196 } 197 198 sal_Bool lcl_RstAttr( const SwNodePtr& rpNd, void* pArgs ) 199 { 200 ParaRstFmt* pPara = (ParaRstFmt*)pArgs; 201 SwCntntNode* pNode = (SwCntntNode*)rpNd->GetCntntNode(); 202 if( pNode && pNode->HasSwAttrSet() ) 203 { 204 const sal_Bool bLocked = pNode->IsModifyLocked(); 205 pNode->LockModify(); 206 207 SwDoc* pDoc = pNode->GetDoc(); 208 209 // --> OD 2008-04-14 #refactorlists# 210 // remove unused attribute RES_LR_SPACE 211 // add list attributes 212 SfxItemSet aSet( pDoc->GetAttrPool(), 213 RES_PAGEDESC, RES_BREAK, 214 RES_PARATR_NUMRULE, RES_PARATR_NUMRULE, 215 RES_PARATR_OUTLINELEVEL,RES_PARATR_OUTLINELEVEL,//#outline level,removed by zhaojianwei 216 RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END - 1, 217 0 ); 218 const SfxItemSet* pSet = pNode->GetpSwAttrSet(); 219 220 // --> OD 2008-04-15 #refactorlists# 221 // std::vector<sal_uInt16> aClearWhichIds; 222 SvUShorts aClearWhichIds; 223 // <-- 224 // --> OD 2008-04-15 #refactorlists# 225 // restoring all paragraph list attributes 226 { 227 SfxItemSet aListAttrSet( pDoc->GetAttrPool(), 228 RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END - 1, 229 0 ); 230 aListAttrSet.Set( *pSet ); 231 if ( aListAttrSet.Count() ) 232 { 233 aSet.Put( aListAttrSet ); 234 SfxItemIter aIter( aListAttrSet ); 235 const SfxPoolItem* pItem = aIter.GetCurItem(); 236 while( pItem ) 237 { 238 aClearWhichIds.Insert( pItem->Which(), aClearWhichIds.Count() ); 239 pItem = aIter.NextItem(); 240 } 241 } 242 } 243 // <-- 244 245 const SfxPoolItem* pItem; 246 // sal_uInt16 __READONLY_DATA aSavIds[ 3 ] = { RES_PAGEDESC, RES_BREAK, //#outline level,removed by zhaojianwei 247 // RES_PARATR_NUMRULE }; 248 //for( sal_uInt16 n = 0; n < 3; ++n ) 249 sal_uInt16 __READONLY_DATA aSavIds[ 4 ] = { RES_PAGEDESC, RES_BREAK, //->add by zhaojianwei 250 RES_PARATR_NUMRULE, 251 RES_PARATR_OUTLINELEVEL }; 252 for( sal_uInt16 n = 0; n < 4; ++n ) //<-end,zhaojianwei 253 { 254 if( SFX_ITEM_SET == pSet->GetItemState( aSavIds[ n ], sal_False, &pItem )) 255 { 256 bool bSave = false; 257 switch( aSavIds[ n ] ) 258 { 259 case RES_PAGEDESC: 260 bSave = 0 != ((SwFmtPageDesc*)pItem)->GetPageDesc(); 261 break; 262 case RES_BREAK: 263 bSave = SVX_BREAK_NONE != ((SvxFmtBreakItem*)pItem)->GetBreak(); 264 break; 265 case RES_PARATR_NUMRULE: 266 { 267 bSave = 0 != ((SwNumRuleItem*)pItem)->GetValue().Len(); 268 } 269 break; 270 case RES_PARATR_OUTLINELEVEL: //#outline level,add by zhaojianwei 271 { 272 bSave = pPara && pPara->bKeepOutlineLevelAttr; 273 } 274 break; //<-end,zhaojianwei 275 } 276 if( bSave ) 277 { 278 aSet.Put( *pItem ); 279 // --> OD 2008-04-15 #refactorlists# 280 // aClearWhichIds.push_back( aSavIds[n] ); 281 aClearWhichIds.Insert( aSavIds[n], aClearWhichIds.Count() ); 282 } 283 } 284 } 285 286 // --> OD 2008-04-14 #refactorlists# 287 // do not clear items directly from item set and only clear to be kept 288 // attributes, if no deletion item set is found. 289 // pNode->ClearItemsFromAttrSet( aClearWhichIds ); 290 const bool bKeepAttributes = 291 !pPara || !pPara->pDelSet || pPara->pDelSet->Count() == 0; 292 if ( bKeepAttributes ) 293 { 294 pNode->ResetAttr( aClearWhichIds ); 295 } 296 // <-- 297 298 if( !bLocked ) 299 pNode->UnlockModify(); 300 301 if( pPara ) 302 { 303 SwRegHistory aRegH( pNode, *pNode, pPara->pHistory ); 304 305 if( pPara->pDelSet && pPara->pDelSet->Count() ) 306 { 307 // --> OD 2008-04-15 #refactorlists# 308 ASSERT( !bKeepAttributes, 309 "<lcl_RstAttr(..)> - certain attributes are kept, but not needed. -> please inform OD" ); 310 // <-- 311 SfxItemIter aIter( *pPara->pDelSet ); 312 pItem = aIter.FirstItem(); 313 while( sal_True ) 314 { 315 // --> OD 2008-04-14 #refactorlists# 316 // 317 if ( ( pItem->Which() != RES_PAGEDESC && 318 pItem->Which() != RES_BREAK && 319 pItem->Which() != RES_PARATR_NUMRULE ) || 320 ( aSet.GetItemState( pItem->Which(), sal_False ) != SFX_ITEM_SET ) ) 321 { 322 pNode->ResetAttr( pItem->Which() ); 323 } 324 // <-- 325 if( aIter.IsAtEnd() ) 326 break; 327 pItem = aIter.NextItem(); 328 } 329 } 330 else if( pPara->bResetAll ) 331 pNode->ResetAllAttr(); 332 else 333 pNode->ResetAttr( RES_PARATR_BEGIN, POOLATTR_END - 1 ); 334 } 335 else 336 pNode->ResetAllAttr(); 337 338 // --> OD 2008-04-15 #refactorlists# 339 // only restore saved attributes, if needed 340 if ( bKeepAttributes && aSet.Count() ) 341 // <-- 342 { 343 pNode->LockModify(); 344 345 pNode->SetAttr( aSet ); 346 347 if( !bLocked ) 348 pNode->UnlockModify(); 349 } 350 } 351 return sal_True; 352 } 353 354 void SwDoc::RstTxtAttrs(const SwPaM &rRg, sal_Bool bInclRefToxMark ) 355 { 356 SwHistory* pHst = 0; 357 SwDataChanged aTmp( rRg, 0 ); 358 if (GetIDocumentUndoRedo().DoesUndo()) 359 { 360 SwUndoResetAttr* pUndo = new SwUndoResetAttr( rRg, RES_CHRFMT ); 361 pHst = &pUndo->GetHistory(); 362 GetIDocumentUndoRedo().AppendUndo(pUndo); 363 } 364 const SwPosition *pStt = rRg.Start(), *pEnd = rRg.End(); 365 ParaRstFmt aPara( pStt, pEnd, pHst ); 366 aPara.bInclRefToxMark = ( bInclRefToxMark == sal_True ); 367 GetNodes().ForEach( pStt->nNode.GetIndex(), pEnd->nNode.GetIndex()+1, 368 lcl_RstTxtAttr, &aPara ); 369 SetModified(); 370 } 371 372 void SwDoc::ResetAttrs( const SwPaM &rRg, 373 sal_Bool bTxtAttr, 374 const SvUShortsSort* pAttrs, 375 // --> OD 2008-11-28 #b96644# 376 const bool bSendDataChangedEvents ) 377 // <-- 378 { 379 SwPaM* pPam = (SwPaM*)&rRg; 380 if( !bTxtAttr && pAttrs && pAttrs->Count() && 381 RES_TXTATR_END > (*pAttrs)[ 0 ] ) 382 bTxtAttr = sal_True; 383 384 if( !rRg.HasMark() ) 385 { 386 SwTxtNode* pTxtNd = rRg.GetPoint()->nNode.GetNode().GetTxtNode(); 387 if( !pTxtNd ) 388 return ; 389 390 pPam = new SwPaM( *rRg.GetPoint() ); 391 392 SwIndex& rSt = pPam->GetPoint()->nContent; 393 sal_uInt16 nMkPos, nPtPos = rSt.GetIndex(); 394 395 // JP 22.08.96: Sonderfall: steht der Crsr in einem URL-Attribut 396 // dann wird dessen Bereich genommen 397 SwTxtAttr const*const pURLAttr( 398 pTxtNd->GetTxtAttrAt(rSt.GetIndex(), RES_TXTATR_INETFMT)); 399 if (pURLAttr && pURLAttr->GetINetFmt().GetValue().Len()) 400 { 401 nMkPos = *pURLAttr->GetStart(); 402 nPtPos = *pURLAttr->GetEnd(); 403 } 404 else 405 { 406 Boundary aBndry; 407 if( pBreakIt->GetBreakIter().is() ) 408 aBndry = pBreakIt->GetBreakIter()->getWordBoundary( 409 pTxtNd->GetTxt(), nPtPos, 410 pBreakIt->GetLocale( pTxtNd->GetLang( nPtPos ) ), 411 WordType::ANY_WORD /*ANYWORD_IGNOREWHITESPACES*/, 412 sal_True ); 413 414 if( aBndry.startPos < nPtPos && nPtPos < aBndry.endPos ) 415 { 416 nMkPos = (xub_StrLen)aBndry.startPos; 417 nPtPos = (xub_StrLen)aBndry.endPos; 418 } 419 else 420 { 421 nPtPos = nMkPos = rSt.GetIndex(); 422 if( bTxtAttr ) 423 pTxtNd->DontExpandFmt( rSt, sal_True ); 424 } 425 } 426 427 rSt = nMkPos; 428 pPam->SetMark(); 429 pPam->GetPoint()->nContent = nPtPos; 430 } 431 432 // --> OD 2008-11-28 #i96644# 433 // SwDataChanged aTmp( *pPam, 0 ); 434 std::auto_ptr< SwDataChanged > pDataChanged; 435 if ( bSendDataChangedEvents ) 436 { 437 pDataChanged.reset( new SwDataChanged( *pPam, 0 ) ); 438 } 439 // <-- 440 SwHistory* pHst = 0; 441 if (GetIDocumentUndoRedo().DoesUndo()) 442 { 443 SwUndoResetAttr* pUndo = new SwUndoResetAttr( rRg, 444 static_cast<sal_uInt16>(bTxtAttr ? RES_CONDTXTFMTCOLL : RES_TXTFMTCOLL )); 445 if( pAttrs && pAttrs->Count() ) 446 { 447 pUndo->SetAttrs( *pAttrs ); 448 } 449 pHst = &pUndo->GetHistory(); 450 GetIDocumentUndoRedo().AppendUndo(pUndo); 451 } 452 453 const SwPosition *pStt = pPam->Start(), *pEnd = pPam->End(); 454 ParaRstFmt aPara( pStt, pEnd, pHst ); 455 456 // mst: not including META here; it seems attrs with CH_TXTATR are omitted 457 sal_uInt16 __FAR_DATA aResetableSetRange[] = { 458 RES_FRMATR_BEGIN, RES_FRMATR_END-1, 459 RES_CHRATR_BEGIN, RES_CHRATR_END-1, 460 RES_PARATR_BEGIN, RES_PARATR_END-1, 461 // --> OD 2008-02-25 #refactorlists# 462 RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1, 463 // <-- 464 RES_TXTATR_INETFMT, RES_TXTATR_INETFMT, 465 RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT, 466 RES_TXTATR_CJK_RUBY, RES_TXTATR_CJK_RUBY, 467 RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER, 468 RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1, 469 0 470 }; 471 472 SfxItemSet aDelSet( GetAttrPool(), aResetableSetRange ); 473 if( pAttrs && pAttrs->Count() ) 474 { 475 for( sal_uInt16 n = pAttrs->Count(); n; ) 476 if( POOLATTR_END > (*pAttrs)[ --n ] ) 477 aDelSet.Put( *GetDfltAttr( (*pAttrs)[ n ] )); 478 479 if( aDelSet.Count() ) 480 aPara.pDelSet = &aDelSet; 481 } 482 483 sal_Bool bAdd = sal_True; 484 SwNodeIndex aTmpStt( pStt->nNode ); 485 SwNodeIndex aTmpEnd( pEnd->nNode ); 486 if( pStt->nContent.GetIndex() ) // nur ein Teil 487 { 488 // dann spaeter aufsetzen und alle CharFmtAttr -> TxtFmtAttr 489 SwTxtNode* pTNd = aTmpStt.GetNode().GetTxtNode(); 490 if( pTNd && pTNd->HasSwAttrSet() && pTNd->GetpSwAttrSet()->Count() ) 491 { 492 if (pHst) 493 { 494 SwRegHistory history(pTNd, *pTNd, pHst); 495 pTNd->FmtToTxtAttr(pTNd); 496 } 497 else 498 { 499 pTNd->FmtToTxtAttr(pTNd); 500 } 501 } 502 503 aTmpStt++; 504 } 505 if( pEnd->nContent.GetIndex() == pEnd->nNode.GetNode().GetCntntNode()->Len() ) 506 // dann spaeter aufsetzen und alle CharFmtAttr -> TxtFmtAttr 507 aTmpEnd++, bAdd = sal_False; 508 else if( pStt->nNode != pEnd->nNode || !pStt->nContent.GetIndex() ) 509 { 510 SwTxtNode* pTNd = aTmpEnd.GetNode().GetTxtNode(); 511 if( pTNd && pTNd->HasSwAttrSet() && pTNd->GetpSwAttrSet()->Count() ) 512 { 513 if (pHst) 514 { 515 SwRegHistory history(pTNd, *pTNd, pHst); 516 pTNd->FmtToTxtAttr(pTNd); 517 } 518 else 519 { 520 pTNd->FmtToTxtAttr(pTNd); 521 } 522 } 523 } 524 525 if( aTmpStt < aTmpEnd ) 526 GetNodes().ForEach( pStt->nNode, aTmpEnd, lcl_RstAttr, &aPara ); 527 else if( !rRg.HasMark() ) 528 { 529 aPara.bResetAll = false ; 530 ::lcl_RstAttr( &pStt->nNode.GetNode(), &aPara ); 531 aPara.bResetAll = true ; 532 } 533 534 if( bTxtAttr ) 535 { 536 if( bAdd ) 537 aTmpEnd++; 538 GetNodes().ForEach( pStt->nNode, aTmpEnd, lcl_RstTxtAttr, &aPara ); 539 } 540 541 if( pPam != &rRg ) 542 delete pPam; 543 544 SetModified(); 545 } 546 547 #define DELETECHARSETS if ( bDelete ) { delete pCharSet; delete pOtherSet; } 548 549 // Einfuegen der Hints nach Inhaltsformen; 550 // wird in SwDoc::Insert(..., SwFmtHint &rHt) benutzt 551 552 static bool 553 lcl_InsAttr(SwDoc *const pDoc, const SwPaM &rRg, const SfxItemSet& rChgSet, 554 const SetAttrMode nFlags, SwUndoAttr *const pUndo) 555 { 556 // teil die Sets auf (fuer Selektion in Nodes) 557 const SfxItemSet* pCharSet = 0; 558 const SfxItemSet* pOtherSet = 0; 559 bool bDelete = false; 560 bool bCharAttr = false; 561 bool bOtherAttr = false; 562 563 // Check, if we can work with rChgSet or if we have to create additional SfxItemSets 564 if ( 1 == rChgSet.Count() ) 565 { 566 SfxItemIter aIter( rChgSet ); 567 const SfxPoolItem* pItem = aIter.FirstItem(); 568 569 if (!IsInvalidItem(pItem)) 570 { 571 const sal_uInt16 nWhich = pItem->Which(); 572 573 if ( isCHRATR(nWhich) || 574 (RES_TXTATR_CHARFMT == nWhich) || 575 (RES_TXTATR_INETFMT == nWhich) || 576 (RES_TXTATR_AUTOFMT == nWhich) || 577 (RES_TXTATR_UNKNOWN_CONTAINER == nWhich) ) 578 { 579 pCharSet = &rChgSet; 580 bCharAttr = true; 581 } 582 583 if ( isPARATR(nWhich) 584 || isPARATR_LIST(nWhich) 585 || isFRMATR(nWhich) 586 || isGRFATR(nWhich) 587 || isUNKNOWNATR(nWhich) ) 588 { 589 pOtherSet = &rChgSet; 590 bOtherAttr = true; 591 } 592 } 593 } 594 595 // Build new itemset if either 596 // - rChgSet.Count() > 1 or 597 // - The attribute in rChgSet does not belong to one of the above categories 598 if ( !bCharAttr && !bOtherAttr ) 599 { 600 SfxItemSet* pTmpCharItemSet = new SfxItemSet( pDoc->GetAttrPool(), 601 RES_CHRATR_BEGIN, RES_CHRATR_END-1, 602 RES_TXTATR_AUTOFMT, RES_TXTATR_AUTOFMT, 603 RES_TXTATR_INETFMT, RES_TXTATR_INETFMT, 604 RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT, 605 RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER, 606 0 ); 607 608 SfxItemSet* pTmpOtherItemSet = new SfxItemSet( pDoc->GetAttrPool(), 609 RES_PARATR_BEGIN, RES_PARATR_END-1, 610 // --> OD 2008-02-25 #refactorlists# 611 RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1, 612 // <-- 613 RES_FRMATR_BEGIN, RES_FRMATR_END-1, 614 RES_GRFATR_BEGIN, RES_GRFATR_END-1, 615 RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1, 616 0 ); 617 618 pTmpCharItemSet->Put( rChgSet ); 619 pTmpOtherItemSet->Put( rChgSet ); 620 621 pCharSet = pTmpCharItemSet; 622 pOtherSet = pTmpOtherItemSet; 623 624 bDelete = true; 625 } 626 627 SwHistory* pHistory = pUndo ? &pUndo->GetHistory() : 0; 628 bool bRet = false; 629 const SwPosition *pStt = rRg.Start(), *pEnd = rRg.End(); 630 SwCntntNode* pNode = pStt->nNode.GetNode().GetCntntNode(); 631 632 if( pNode && pNode->IsTxtNode() ) 633 { 634 // -> #i27615# 635 if (rRg.IsInFrontOfLabel()) 636 { 637 SwTxtNode * pTxtNd = pNode->GetTxtNode(); 638 SwNumRule * pNumRule = pTxtNd->GetNumRule(); 639 640 // --> OD 2005-10-24 #126346# - make code robust: 641 if ( !pNumRule ) 642 { 643 ASSERT( false, 644 "<InsAttr(..)> - PaM in front of label, but text node has no numbering rule set. This is a serious defect, please inform OD." ); 645 DELETECHARSETS 646 return false; 647 } 648 // <-- 649 650 SwNumFmt aNumFmt = pNumRule->Get(static_cast<sal_uInt16>(pTxtNd->GetActualListLevel())); 651 SwCharFmt * pCharFmt = 652 pDoc->FindCharFmtByName(aNumFmt.GetCharFmtName()); 653 654 if (pCharFmt) 655 { 656 if (pHistory) 657 pHistory->Add(pCharFmt->GetAttrSet(), *pCharFmt); 658 659 if ( pCharSet ) 660 pCharFmt->SetFmtAttr(*pCharSet); 661 } 662 663 DELETECHARSETS 664 return true; 665 } 666 // <- #i27615# 667 668 const SwIndex& rSt = pStt->nContent; 669 670 // Attribute ohne Ende haben keinen Bereich 671 if ( !bCharAttr && !bOtherAttr ) 672 { 673 SfxItemSet aTxtSet( pDoc->GetAttrPool(), 674 RES_TXTATR_NOEND_BEGIN, RES_TXTATR_NOEND_END-1 ); 675 aTxtSet.Put( rChgSet ); 676 if( aTxtSet.Count() ) 677 { 678 SwRegHistory history( pNode, *pNode, pHistory ); 679 bRet = history.InsertItems( 680 aTxtSet, rSt.GetIndex(), rSt.GetIndex(), nFlags ) || bRet; 681 682 if (bRet && (pDoc->IsRedlineOn() || (!pDoc->IsIgnoreRedline() 683 && pDoc->GetRedlineTbl().Count()))) 684 { 685 SwPaM aPam( pStt->nNode, pStt->nContent.GetIndex()-1, 686 pStt->nNode, pStt->nContent.GetIndex() ); 687 688 if( pUndo ) 689 pUndo->SaveRedlineData( aPam, sal_True ); 690 691 if( pDoc->IsRedlineOn() ) 692 pDoc->AppendRedline( new SwRedline( nsRedlineType_t::REDLINE_INSERT, aPam ), true); 693 else 694 pDoc->SplitRedline( aPam ); 695 } 696 } 697 } 698 699 // TextAttribute mit Ende expandieren nie ihren Bereich 700 if ( !bCharAttr && !bOtherAttr ) 701 { 702 // CharFmt wird gesondert behandelt !!! 703 // JP 22.08.96: URL-Attribute auch!! 704 // TEST_TEMP ToDo: AutoFmt! 705 SfxItemSet aTxtSet( pDoc->GetAttrPool(), 706 RES_TXTATR_REFMARK, RES_TXTATR_TOXMARK, 707 RES_TXTATR_META, RES_TXTATR_METAFIELD, 708 RES_TXTATR_CJK_RUBY, RES_TXTATR_CJK_RUBY, 709 0 ); 710 711 aTxtSet.Put( rChgSet ); 712 if( aTxtSet.Count() ) 713 { 714 sal_uInt16 nInsCnt = rSt.GetIndex(); 715 sal_uInt16 nEnd = pStt->nNode == pEnd->nNode 716 ? pEnd->nContent.GetIndex() 717 : pNode->Len(); 718 SwRegHistory history( pNode, *pNode, pHistory ); 719 bRet = history.InsertItems( aTxtSet, nInsCnt, nEnd, nFlags ) 720 || bRet; 721 722 if (bRet && (pDoc->IsRedlineOn() || (!pDoc->IsIgnoreRedline() 723 && pDoc->GetRedlineTbl().Count()))) 724 { 725 // wurde Text-Inhalt eingefuegt? (RefMark/TOXMarks ohne Ende) 726 sal_Bool bTxtIns = nInsCnt != rSt.GetIndex(); 727 // wurde Inhalt eingefuegt oder ueber die Selektion gesetzt? 728 SwPaM aPam( pStt->nNode, bTxtIns ? nInsCnt + 1 : nEnd, 729 pStt->nNode, nInsCnt ); 730 if( pUndo ) 731 pUndo->SaveRedlineData( aPam, bTxtIns ); 732 733 if( pDoc->IsRedlineOn() ) 734 pDoc->AppendRedline( new SwRedline( bTxtIns 735 ? nsRedlineType_t::REDLINE_INSERT : nsRedlineType_t::REDLINE_FORMAT, aPam ), true); 736 else if( bTxtIns ) 737 pDoc->SplitRedline( aPam ); 738 } 739 } 740 } 741 } 742 743 // bei PageDesc's, die am Node gesetzt werden, muss immer das 744 // Auto-Flag gesetzt werden!! 745 if( pOtherSet && pOtherSet->Count() ) 746 { 747 SwTableNode* pTblNd; 748 const SwFmtPageDesc* pDesc; 749 if( SFX_ITEM_SET == pOtherSet->GetItemState( RES_PAGEDESC, 750 sal_False, (const SfxPoolItem**)&pDesc )) 751 { 752 if( pNode ) 753 { 754 // Auto-Flag setzen, nur in Vorlagen ist ohne Auto ! 755 SwFmtPageDesc aNew( *pDesc ); 756 // Bug 38479: AutoFlag wird jetzt in der WrtShell gesetzt 757 // aNew.SetAuto(); 758 759 // Tabellen kennen jetzt auch Umbrueche 760 if( 0 == (nFlags & nsSetAttrMode::SETATTR_APICALL) && 761 0 != ( pTblNd = pNode->FindTableNode() ) ) 762 { 763 SwTableNode* pCurTblNd = pTblNd; 764 while ( 0 != ( pCurTblNd = pCurTblNd->StartOfSectionNode()->FindTableNode() ) ) 765 pTblNd = pCurTblNd; 766 767 // dann am Tabellen Format setzen 768 SwFrmFmt* pFmt = pTblNd->GetTable().GetFrmFmt(); 769 SwRegHistory aRegH( pFmt, *pTblNd, pHistory ); 770 pFmt->SetFmtAttr( aNew ); 771 bRet = true; 772 } 773 else 774 { 775 SwRegHistory aRegH( pNode, *pNode, pHistory ); 776 bRet = pNode->SetAttr( aNew ) || bRet; 777 } 778 } 779 780 // bOtherAttr = true means that pOtherSet == rChgSet. In this case 781 // we know, that there is only one attribute in pOtherSet. We cannot 782 // perform the following operations, instead we return: 783 if ( bOtherAttr ) 784 return bRet; 785 786 const_cast<SfxItemSet*>(pOtherSet)->ClearItem( RES_PAGEDESC ); 787 if( !pOtherSet->Count() ) 788 { 789 DELETECHARSETS 790 return bRet; 791 } 792 } 793 794 // Tabellen kennen jetzt auch Umbrueche 795 const SvxFmtBreakItem* pBreak; 796 if( pNode && 0 == (nFlags & nsSetAttrMode::SETATTR_APICALL) && 797 0 != (pTblNd = pNode->FindTableNode() ) && 798 SFX_ITEM_SET == pOtherSet->GetItemState( RES_BREAK, 799 sal_False, (const SfxPoolItem**)&pBreak ) ) 800 { 801 SwTableNode* pCurTblNd = pTblNd; 802 while ( 0 != ( pCurTblNd = pCurTblNd->StartOfSectionNode()->FindTableNode() ) ) 803 pTblNd = pCurTblNd; 804 805 // dann am Tabellen Format setzen 806 SwFrmFmt* pFmt = pTblNd->GetTable().GetFrmFmt(); 807 SwRegHistory aRegH( pFmt, *pTblNd, pHistory ); 808 pFmt->SetFmtAttr( *pBreak ); 809 bRet = true; 810 811 // bOtherAttr = true means that pOtherSet == rChgSet. In this case 812 // we know, that there is only one attribute in pOtherSet. We cannot 813 // perform the following operations, instead we return: 814 if ( bOtherAttr ) 815 return bRet; 816 817 const_cast<SfxItemSet*>(pOtherSet)->ClearItem( RES_BREAK ); 818 if( !pOtherSet->Count() ) 819 { 820 DELETECHARSETS 821 return bRet; 822 } 823 } 824 825 { 826 // wenns eine PoolNumRule ist, diese ggfs. anlegen 827 const SwNumRuleItem* pRule; 828 sal_uInt16 nPoolId; 829 if( SFX_ITEM_SET == pOtherSet->GetItemState( RES_PARATR_NUMRULE, 830 sal_False, (const SfxPoolItem**)&pRule ) && 831 !pDoc->FindNumRulePtr( pRule->GetValue() ) && 832 USHRT_MAX != (nPoolId = SwStyleNameMapper::GetPoolIdFromUIName ( pRule->GetValue(), 833 nsSwGetPoolIdFromName::GET_POOLID_NUMRULE )) ) 834 pDoc->GetNumRuleFromPool( nPoolId ); 835 } 836 837 } 838 839 if( !rRg.HasMark() ) // kein Bereich 840 { 841 if( !pNode ) 842 { 843 DELETECHARSETS 844 return bRet; 845 } 846 847 if( pNode->IsTxtNode() && pCharSet && pCharSet->Count() ) 848 { 849 SwTxtNode* pTxtNd = static_cast<SwTxtNode*>(pNode); 850 const SwIndex& rSt = pStt->nContent; 851 sal_uInt16 nMkPos, nPtPos = rSt.GetIndex(); 852 const String& rStr = pTxtNd->GetTxt(); 853 854 // JP 22.08.96: Sonderfall: steht der Crsr in einem URL-Attribut 855 // dann wird dessen Bereich genommen 856 SwTxtAttr const*const pURLAttr( 857 pTxtNd->GetTxtAttrAt(rSt.GetIndex(), RES_TXTATR_INETFMT)); 858 if (pURLAttr && pURLAttr->GetINetFmt().GetValue().Len()) 859 { 860 nMkPos = *pURLAttr->GetStart(); 861 nPtPos = *pURLAttr->GetEnd(); 862 } 863 else 864 { 865 Boundary aBndry; 866 if( pBreakIt->GetBreakIter().is() ) 867 aBndry = pBreakIt->GetBreakIter()->getWordBoundary( 868 pTxtNd->GetTxt(), nPtPos, 869 pBreakIt->GetLocale( pTxtNd->GetLang( nPtPos ) ), 870 WordType::ANY_WORD /*ANYWORD_IGNOREWHITESPACES*/, 871 sal_True ); 872 873 if( aBndry.startPos < nPtPos && nPtPos < aBndry.endPos ) 874 { 875 nMkPos = (xub_StrLen)aBndry.startPos; 876 nPtPos = (xub_StrLen)aBndry.endPos; 877 } 878 else 879 nPtPos = nMkPos = rSt.GetIndex(); 880 } 881 882 // erstmal die zu ueberschreibenden Attribute aus dem 883 // SwpHintsArray entfernen, wenn die Selektion den gesamten 884 // Absatz umspannt. (Diese Attribute werden als FormatAttr. 885 // eingefuegt und verdraengen nie die TextAttr.!) 886 if( !(nFlags & nsSetAttrMode::SETATTR_DONTREPLACE ) && 887 pTxtNd->HasHints() && !nMkPos && nPtPos == rStr.Len() ) 888 { 889 SwIndex aSt( pTxtNd ); 890 if( pHistory ) 891 { 892 // fuers Undo alle Attribute sichern 893 SwRegHistory aRHst( *pTxtNd, pHistory ); 894 pTxtNd->GetpSwpHints()->Register( &aRHst ); 895 pTxtNd->RstAttr( aSt, nPtPos, 0, pCharSet ); 896 if( pTxtNd->GetpSwpHints() ) 897 pTxtNd->GetpSwpHints()->DeRegister(); 898 } 899 else 900 pTxtNd->RstAttr( aSt, nPtPos, 0, pCharSet ); 901 } 902 903 // the SwRegHistory inserts the attribute into the TxtNode! 904 SwRegHistory history( pNode, *pNode, pHistory ); 905 bRet = history.InsertItems( *pCharSet, nMkPos, nPtPos, nFlags ) 906 || bRet; 907 908 if( pDoc->IsRedlineOn() ) 909 { 910 SwPaM aPam( *pNode, nMkPos, *pNode, nPtPos ); 911 912 if( pUndo ) 913 pUndo->SaveRedlineData( aPam, sal_False ); 914 pDoc->AppendRedline( new SwRedline( nsRedlineType_t::REDLINE_FORMAT, aPam ), true); 915 } 916 } 917 if( pOtherSet && pOtherSet->Count() ) 918 { 919 SwRegHistory aRegH( pNode, *pNode, pHistory ); 920 bRet = pNode->SetAttr( *pOtherSet ) || bRet; 921 } 922 923 DELETECHARSETS 924 return bRet; 925 } 926 927 if( pDoc->IsRedlineOn() && pCharSet && pCharSet->Count() ) 928 { 929 if( pUndo ) 930 pUndo->SaveRedlineData( rRg, sal_False ); 931 pDoc->AppendRedline( new SwRedline( nsRedlineType_t::REDLINE_FORMAT, rRg ), true); 932 } 933 934 /* jetzt wenn Bereich */ 935 sal_uLong nNodes = 0; 936 937 SwNodeIndex aSt( pDoc->GetNodes() ); 938 SwNodeIndex aEnd( pDoc->GetNodes() ); 939 SwIndex aCntEnd( pEnd->nContent ); 940 941 if( pNode ) 942 { 943 sal_uInt16 nLen = pNode->Len(); 944 if( pStt->nNode != pEnd->nNode ) 945 aCntEnd.Assign( pNode, nLen ); 946 947 if( pStt->nContent.GetIndex() != 0 || aCntEnd.GetIndex() != nLen ) 948 { 949 // the SwRegHistory inserts the attribute into the TxtNode! 950 if( pNode->IsTxtNode() && pCharSet && pCharSet->Count() ) 951 { 952 SwRegHistory history( pNode, *pNode, pHistory ); 953 bRet = history.InsertItems(*pCharSet, 954 pStt->nContent.GetIndex(), aCntEnd.GetIndex(), nFlags) 955 || bRet; 956 } 957 958 if( pOtherSet && pOtherSet->Count() ) 959 { 960 SwRegHistory aRegH( pNode, *pNode, pHistory ); 961 bRet = pNode->SetAttr( *pOtherSet ) || bRet; 962 } 963 964 // lediglich Selektion in einem Node. 965 if( pStt->nNode == pEnd->nNode ) 966 { 967 DELETECHARSETS 968 return bRet; 969 } 970 ++nNodes; 971 aSt.Assign( pStt->nNode.GetNode(), +1 ); 972 } 973 else 974 aSt = pStt->nNode; 975 aCntEnd = pEnd->nContent; // aEnd wurde veraendert !! 976 } 977 else 978 aSt.Assign( pStt->nNode.GetNode(), +1 ); 979 980 // aSt zeigt jetzt auf den ersten vollen Node 981 982 /* 983 * die Selektion umfasst mehr als einen Node 984 */ 985 if( pStt->nNode < pEnd->nNode ) 986 { 987 pNode = pEnd->nNode.GetNode().GetCntntNode(); 988 if(pNode) 989 { 990 sal_uInt16 nLen = pNode->Len(); 991 if( aCntEnd.GetIndex() != nLen ) 992 { 993 // the SwRegHistory inserts the attribute into the TxtNode! 994 if( pNode->IsTxtNode() && pCharSet && pCharSet->Count() ) 995 { 996 SwRegHistory history( pNode, *pNode, pHistory ); 997 history.InsertItems(*pCharSet, 998 0, aCntEnd.GetIndex(), nFlags); 999 } 1000 1001 if( pOtherSet && pOtherSet->Count() ) 1002 { 1003 SwRegHistory aRegH( pNode, *pNode, pHistory ); 1004 pNode->SetAttr( *pOtherSet ); 1005 } 1006 1007 ++nNodes; 1008 aEnd = pEnd->nNode; 1009 } 1010 else 1011 aEnd.Assign( pEnd->nNode.GetNode(), +1 ); 1012 } 1013 else 1014 aEnd = pEnd->nNode; 1015 } 1016 else 1017 aEnd.Assign( pEnd->nNode.GetNode(), +1 ); 1018 1019 // aEnd zeigt jetzt HINTER den letzten voll Node 1020 1021 /* Bearbeitung der vollstaendig selektierten Nodes. */ 1022 // alle Attribute aus dem Set zuruecksetzen !! 1023 if( pCharSet && pCharSet->Count() && !( nsSetAttrMode::SETATTR_DONTREPLACE & nFlags ) ) 1024 { 1025 1026 ParaRstFmt aPara( pStt, pEnd, pHistory, 0, pCharSet ); 1027 pDoc->GetNodes().ForEach( aSt, aEnd, lcl_RstTxtAttr, &aPara ); 1028 } 1029 1030 sal_Bool bCreateSwpHints = pCharSet && ( 1031 SFX_ITEM_SET == pCharSet->GetItemState( RES_TXTATR_CHARFMT, sal_False ) || 1032 SFX_ITEM_SET == pCharSet->GetItemState( RES_TXTATR_INETFMT, sal_False ) ); 1033 1034 for(; aSt < aEnd; aSt++ ) 1035 { 1036 pNode = aSt.GetNode().GetCntntNode(); 1037 if( !pNode ) 1038 continue; 1039 1040 SwTxtNode* pTNd = pNode->GetTxtNode(); 1041 if( pHistory ) 1042 { 1043 SwRegHistory aRegH( pNode, *pNode, pHistory ); 1044 SwpHints *pSwpHints; 1045 1046 if( pTNd && pCharSet && pCharSet->Count() ) 1047 { 1048 pSwpHints = bCreateSwpHints ? &pTNd->GetOrCreateSwpHints() 1049 : pTNd->GetpSwpHints(); 1050 if( pSwpHints ) 1051 pSwpHints->Register( &aRegH ); 1052 1053 pTNd->SetAttr( *pCharSet, 0, pTNd->GetTxt().Len(), nFlags ); 1054 if( pSwpHints ) 1055 pSwpHints->DeRegister(); 1056 } 1057 if( pOtherSet && pOtherSet->Count() ) 1058 pNode->SetAttr( *pOtherSet ); 1059 } 1060 else 1061 { 1062 if( pTNd && pCharSet && pCharSet->Count() ) 1063 pTNd->SetAttr( *pCharSet, 0, pTNd->GetTxt().Len(), nFlags ); 1064 if( pOtherSet && pOtherSet->Count() ) 1065 pNode->SetAttr( *pOtherSet ); 1066 } 1067 ++nNodes; 1068 } 1069 1070 DELETECHARSETS 1071 return (nNodes != 0) || bRet; 1072 } 1073 1074 1075 bool SwDoc::InsertPoolItem( const SwPaM &rRg, const SfxPoolItem &rHt, 1076 const SetAttrMode nFlags ) 1077 { 1078 SwDataChanged aTmp( rRg, 0 ); 1079 SwUndoAttr* pUndoAttr = 0; 1080 if (GetIDocumentUndoRedo().DoesUndo()) 1081 { 1082 GetIDocumentUndoRedo().ClearRedo(); 1083 pUndoAttr = new SwUndoAttr( rRg, rHt, nFlags ); 1084 } 1085 1086 SfxItemSet aSet( GetAttrPool(), rHt.Which(), rHt.Which() ); 1087 aSet.Put( rHt ); 1088 bool bRet = lcl_InsAttr( this, rRg, aSet, nFlags, pUndoAttr ); 1089 1090 if (GetIDocumentUndoRedo().DoesUndo()) 1091 { 1092 GetIDocumentUndoRedo().AppendUndo( pUndoAttr ); 1093 } 1094 1095 if( bRet ) 1096 SetModified(); 1097 return bRet; 1098 } 1099 1100 bool SwDoc::InsertItemSet ( const SwPaM &rRg, const SfxItemSet &rSet, 1101 const SetAttrMode nFlags ) 1102 { 1103 SwDataChanged aTmp( rRg, 0 ); 1104 SwUndoAttr* pUndoAttr = 0; 1105 if (GetIDocumentUndoRedo().DoesUndo()) 1106 { 1107 GetIDocumentUndoRedo().ClearRedo(); 1108 pUndoAttr = new SwUndoAttr( rRg, rSet, nFlags ); 1109 } 1110 1111 bool bRet = lcl_InsAttr( this, rRg, rSet, nFlags, pUndoAttr ); 1112 1113 if (GetIDocumentUndoRedo().DoesUndo()) 1114 { 1115 GetIDocumentUndoRedo().AppendUndo( pUndoAttr ); 1116 } 1117 1118 if( bRet ) 1119 SetModified(); 1120 return bRet; 1121 } 1122 1123 1124 // Setze das Attribut im angegebenen Format. Ist Undo aktiv, wird 1125 // das alte in die Undo-History aufgenommen 1126 void SwDoc::SetAttr( const SfxPoolItem& rAttr, SwFmt& rFmt ) 1127 { 1128 SfxItemSet aSet( GetAttrPool(), rAttr.Which(), rAttr.Which() ); 1129 aSet.Put( rAttr ); 1130 SetAttr( aSet, rFmt ); 1131 } 1132 1133 1134 // Setze das Attribut im angegebenen Format. Ist Undo aktiv, wird 1135 // das alte in die Undo-History aufgenommen 1136 void SwDoc::SetAttr( const SfxItemSet& rSet, SwFmt& rFmt ) 1137 { 1138 if (GetIDocumentUndoRedo().DoesUndo()) 1139 { 1140 SwUndoFmtAttrHelper aTmp( rFmt ); 1141 rFmt.SetFmtAttr( rSet ); 1142 if ( aTmp.GetUndo() ) 1143 { 1144 GetIDocumentUndoRedo().AppendUndo( aTmp.ReleaseUndo() ); 1145 } 1146 else 1147 { 1148 GetIDocumentUndoRedo().ClearRedo(); 1149 } 1150 } 1151 else 1152 { 1153 rFmt.SetFmtAttr( rSet ); 1154 } 1155 SetModified(); 1156 } 1157 1158 // --> OD 2008-02-12 #newlistlevelattrs# 1159 void SwDoc::ResetAttrAtFormat( const sal_uInt16 nWhichId, 1160 SwFmt& rChangedFormat ) 1161 { 1162 SwUndo *const pUndo = (GetIDocumentUndoRedo().DoesUndo()) 1163 ? new SwUndoFmtResetAttr( rChangedFormat, nWhichId ) 1164 : 0; 1165 1166 const sal_Bool bAttrReset = rChangedFormat.ResetFmtAttr( nWhichId ); 1167 1168 if ( bAttrReset ) 1169 { 1170 if ( pUndo ) 1171 { 1172 GetIDocumentUndoRedo().AppendUndo( pUndo ); 1173 } 1174 1175 SetModified(); 1176 } 1177 else if ( pUndo ) 1178 delete pUndo; 1179 } 1180 // <-- 1181 1182 int lcl_SetNewDefTabStops( SwTwips nOldWidth, SwTwips nNewWidth, 1183 SvxTabStopItem& rChgTabStop ) 1184 { 1185 // dann aender bei allen TabStop die default's auf den neuen Wert 1186 // !!! Achtung: hier wird immer auf dem PoolAttribut gearbeitet, 1187 // damit nicht in allen Sets die gleiche Berechnung 1188 // auf dem gleichen TabStop (gepoolt!) vorgenommen 1189 // wird. Als Modify wird ein FmtChg verschickt. 1190 1191 sal_uInt16 nOldCnt = rChgTabStop.Count(); 1192 if( !nOldCnt || nOldWidth == nNewWidth ) 1193 return sal_False; 1194 1195 // suche den Anfang der Defaults 1196 SvxTabStop* pTabs = ((SvxTabStop*)rChgTabStop.GetStart()) 1197 + (nOldCnt-1); 1198 sal_uInt16 n; 1199 1200 for( n = nOldCnt; n ; --n, --pTabs ) 1201 if( SVX_TAB_ADJUST_DEFAULT != pTabs->GetAdjustment() ) 1202 break; 1203 ++n; 1204 if( n < nOldCnt ) // die DefTabStops loeschen 1205 rChgTabStop.Remove( n, nOldCnt - n ); 1206 return sal_True; 1207 } 1208 1209 // Setze das Attribut als neues default Attribut in diesem Dokument. 1210 // Ist Undo aktiv, wird das alte in die Undo-History aufgenommen 1211 void SwDoc::SetDefault( const SfxPoolItem& rAttr ) 1212 { 1213 SfxItemSet aSet( GetAttrPool(), rAttr.Which(), rAttr.Which() ); 1214 aSet.Put( rAttr ); 1215 SetDefault( aSet ); 1216 } 1217 1218 void SwDoc::SetDefault( const SfxItemSet& rSet ) 1219 { 1220 if( !rSet.Count() ) 1221 return; 1222 1223 SwModify aCallMod( 0 ); 1224 SwAttrSet aOld( GetAttrPool(), rSet.GetRanges() ), 1225 aNew( GetAttrPool(), rSet.GetRanges() ); 1226 SfxItemIter aIter( rSet ); 1227 sal_uInt16 nWhich; 1228 const SfxPoolItem* pItem = aIter.GetCurItem(); 1229 SfxItemPool* pSdrPool = GetAttrPool().GetSecondaryPool(); 1230 while( sal_True ) 1231 { 1232 sal_Bool bCheckSdrDflt = sal_False; 1233 nWhich = pItem->Which(); 1234 aOld.Put( GetAttrPool().GetDefaultItem( nWhich ) ); 1235 GetAttrPool().SetPoolDefaultItem( *pItem ); 1236 aNew.Put( GetAttrPool().GetDefaultItem( nWhich ) ); 1237 1238 if (isCHRATR(nWhich) || isTXTATR(nWhich)) 1239 { 1240 aCallMod.Add( pDfltTxtFmtColl ); 1241 aCallMod.Add( pDfltCharFmt ); 1242 bCheckSdrDflt = 0 != pSdrPool; 1243 } 1244 else if ( isPARATR(nWhich) || 1245 // --> OD 2008-02-25 #refactorlists# 1246 isPARATR_LIST(nWhich) ) 1247 // <-- 1248 { 1249 aCallMod.Add( pDfltTxtFmtColl ); 1250 bCheckSdrDflt = 0 != pSdrPool; 1251 } 1252 else if (isGRFATR(nWhich)) 1253 { 1254 aCallMod.Add( pDfltGrfFmtColl ); 1255 } 1256 else if (isFRMATR(nWhich)) 1257 { 1258 aCallMod.Add( pDfltGrfFmtColl ); 1259 aCallMod.Add( pDfltTxtFmtColl ); 1260 aCallMod.Add( pDfltFrmFmt ); 1261 } 1262 else if (isBOXATR(nWhich)) 1263 { 1264 aCallMod.Add( pDfltFrmFmt ); 1265 } 1266 1267 // copy also the defaults 1268 if( bCheckSdrDflt ) 1269 { 1270 sal_uInt16 nEdtWhich, nSlotId; 1271 if( 0 != (nSlotId = GetAttrPool().GetSlotId( nWhich ) ) && 1272 nSlotId != nWhich && 1273 0 != (nEdtWhich = pSdrPool->GetWhich( nSlotId )) && 1274 nSlotId != nEdtWhich ) 1275 { 1276 SfxPoolItem* pCpy = pItem->Clone(); 1277 pCpy->SetWhich( nEdtWhich ); 1278 pSdrPool->SetPoolDefaultItem( *pCpy ); 1279 delete pCpy; 1280 } 1281 } 1282 1283 if( aIter.IsAtEnd() ) 1284 break; 1285 pItem = aIter.NextItem(); 1286 } 1287 1288 if( aNew.Count() && aCallMod.GetDepends() ) 1289 { 1290 if (GetIDocumentUndoRedo().DoesUndo()) 1291 { 1292 GetIDocumentUndoRedo().AppendUndo( new SwUndoDefaultAttr( aOld ) ); 1293 } 1294 1295 const SfxPoolItem* pTmpItem; 1296 if( ( SFX_ITEM_SET == 1297 aNew.GetItemState( RES_PARATR_TABSTOP, sal_False, &pTmpItem ) ) && 1298 ((SvxTabStopItem*)pTmpItem)->Count() ) 1299 { 1300 // TabStop-Aenderungen behandeln wir erstmal anders: 1301 // dann aender bei allen TabStop die dafault's auf den neuen Wert 1302 // !!! Achtung: hier wird immer auf dem PoolAttribut gearbeitet, 1303 // damit nicht in allen Sets die gleiche Berechnung 1304 // auf dem gleichen TabStop (gepoolt!) vorgenommen 1305 // wird. Als Modify wird ein FmtChg verschickt. 1306 SwTwips nNewWidth = (*(SvxTabStopItem*)pTmpItem)[ 0 ].GetTabPos(), 1307 nOldWidth = ((SvxTabStopItem&)aOld.Get(RES_PARATR_TABSTOP))[ 0 ].GetTabPos(); 1308 1309 int bChg = sal_False; 1310 sal_uInt32 nMaxItems = GetAttrPool().GetItemCount2( RES_PARATR_TABSTOP ); 1311 for( sal_uInt32 n = 0; n < nMaxItems; ++n ) 1312 if( 0 != (pTmpItem = GetAttrPool().GetItem2( RES_PARATR_TABSTOP, n ) )) 1313 bChg |= lcl_SetNewDefTabStops( nOldWidth, nNewWidth, 1314 *(SvxTabStopItem*)pTmpItem ); 1315 1316 aNew.ClearItem( RES_PARATR_TABSTOP ); 1317 aOld.ClearItem( RES_PARATR_TABSTOP ); 1318 if( bChg ) 1319 { 1320 SwFmtChg aChgFmt( pDfltCharFmt ); 1321 // dann sage mal den Frames bescheid 1322 aCallMod.ModifyNotification( &aChgFmt, &aChgFmt ); 1323 } 1324 } 1325 } 1326 1327 if( aNew.Count() && aCallMod.GetDepends() ) 1328 { 1329 SwAttrSetChg aChgOld( aOld, aOld ); 1330 SwAttrSetChg aChgNew( aNew, aNew ); 1331 aCallMod.ModifyNotification( &aChgOld, &aChgNew ); // alle veraenderten werden verschickt 1332 } 1333 1334 // und die default-Formate wieder beim Object austragen 1335 SwClient* pDep; 1336 while( 0 != ( pDep = (SwClient*)aCallMod.GetDepends()) ) 1337 aCallMod.Remove( pDep ); 1338 1339 SetModified(); 1340 } 1341 1342 // Erfrage das Default Attribut in diesem Dokument. 1343 const SfxPoolItem& SwDoc::GetDefault( sal_uInt16 nFmtHint ) const 1344 { 1345 return GetAttrPool().GetDefaultItem( nFmtHint ); 1346 } 1347 1348 /* 1349 * Loeschen der Formate 1350 */ 1351 void SwDoc::DelCharFmt(sal_uInt16 nFmt, sal_Bool bBroadcast) 1352 { 1353 SwCharFmt * pDel = (*pCharFmtTbl)[nFmt]; 1354 1355 if (bBroadcast) 1356 BroadcastStyleOperation(pDel->GetName(), SFX_STYLE_FAMILY_CHAR, 1357 SFX_STYLESHEET_ERASED); 1358 1359 if (GetIDocumentUndoRedo().DoesUndo()) 1360 { 1361 SwUndo * pUndo = 1362 new SwUndoCharFmtDelete(pDel, this); 1363 1364 GetIDocumentUndoRedo().AppendUndo(pUndo); 1365 } 1366 1367 pCharFmtTbl->DeleteAndDestroy(nFmt); 1368 1369 SetModified(); 1370 } 1371 1372 void SwDoc::DelCharFmt( SwCharFmt *pFmt, sal_Bool bBroadcast ) 1373 { 1374 sal_uInt16 nFmt = pCharFmtTbl->GetPos( pFmt ); 1375 ASSERT( USHRT_MAX != nFmt, "Fmt not found," ); 1376 1377 DelCharFmt( nFmt, bBroadcast ); 1378 } 1379 1380 void SwDoc::DelFrmFmt( SwFrmFmt *pFmt, sal_Bool bBroadcast ) 1381 { 1382 if( pFmt->ISA( SwTableBoxFmt ) || pFmt->ISA( SwTableLineFmt )) 1383 { 1384 ASSERT( !this, "Format steht nicht mehr im DocArray, " 1385 "kann per delete geloescht werden" ); 1386 delete pFmt; 1387 } 1388 else 1389 { 1390 1391 //Das Format muss in einem der beiden Arrays stehen, in welchem 1392 //werden wir schon merken. 1393 sal_uInt16 nPos; 1394 if ( USHRT_MAX != ( nPos = pFrmFmtTbl->GetPos( pFmt )) ) 1395 { 1396 if (bBroadcast) 1397 BroadcastStyleOperation(pFmt->GetName(), 1398 SFX_STYLE_FAMILY_FRAME, 1399 SFX_STYLESHEET_ERASED); 1400 1401 if (GetIDocumentUndoRedo().DoesUndo()) 1402 { 1403 SwUndo * pUndo = new SwUndoFrmFmtDelete(pFmt, this); 1404 1405 GetIDocumentUndoRedo().AppendUndo(pUndo); 1406 } 1407 1408 pFrmFmtTbl->DeleteAndDestroy( nPos ); 1409 } 1410 else 1411 { 1412 nPos = GetSpzFrmFmts()->GetPos( pFmt ); 1413 ASSERT( nPos != USHRT_MAX, "FrmFmt not found." ); 1414 if( USHRT_MAX != nPos ) 1415 GetSpzFrmFmts()->DeleteAndDestroy( nPos ); 1416 } 1417 } 1418 } 1419 1420 void SwDoc::DelTblFrmFmt( SwTableFmt *pFmt ) 1421 { 1422 sal_uInt16 nPos = pTblFrmFmtTbl->GetPos( pFmt ); 1423 ASSERT( USHRT_MAX != nPos, "Fmt not found," ); 1424 pTblFrmFmtTbl->DeleteAndDestroy( nPos ); 1425 } 1426 1427 /* 1428 * Erzeugen der Formate 1429 */ 1430 SwFlyFrmFmt *SwDoc::MakeFlyFrmFmt( const String &rFmtName, 1431 SwFrmFmt *pDerivedFrom ) 1432 { 1433 SwFlyFrmFmt *pFmt = new SwFlyFrmFmt( GetAttrPool(), rFmtName, pDerivedFrom ); 1434 GetSpzFrmFmts()->Insert(pFmt, GetSpzFrmFmts()->Count()); 1435 SetModified(); 1436 return pFmt; 1437 } 1438 1439 SwDrawFrmFmt *SwDoc::MakeDrawFrmFmt( const String &rFmtName, 1440 SwFrmFmt *pDerivedFrom ) 1441 { 1442 SwDrawFrmFmt *pFmt = new SwDrawFrmFmt( GetAttrPool(), rFmtName, pDerivedFrom); 1443 GetSpzFrmFmts()->Insert(pFmt,GetSpzFrmFmts()->Count()); 1444 SetModified(); 1445 return pFmt; 1446 } 1447 1448 1449 sal_uInt16 SwDoc::GetTblFrmFmtCount(sal_Bool bUsed) const 1450 { 1451 sal_uInt16 nCount = pTblFrmFmtTbl->Count(); 1452 if(bUsed) 1453 { 1454 SwAutoFmtGetDocNode aGetHt( &GetNodes() ); 1455 for ( sal_uInt16 i = nCount; i; ) 1456 { 1457 if((*pTblFrmFmtTbl)[--i]->GetInfo( aGetHt )) 1458 1459 --nCount; 1460 } 1461 } 1462 1463 return nCount; 1464 } 1465 1466 1467 SwFrmFmt& SwDoc::GetTblFrmFmt(sal_uInt16 nFmt, sal_Bool bUsed ) const 1468 { 1469 sal_uInt16 nRemoved = 0; 1470 if(bUsed) 1471 { 1472 SwAutoFmtGetDocNode aGetHt( &GetNodes() ); 1473 for ( sal_uInt16 i = 0; i <= nFmt; i++ ) 1474 { 1475 while ( (*pTblFrmFmtTbl)[ i + nRemoved]->GetInfo( aGetHt )) 1476 { 1477 nRemoved++; 1478 } 1479 } 1480 } 1481 return *((*pTblFrmFmtTbl)[nRemoved + nFmt]); 1482 } 1483 1484 SwTableFmt* SwDoc::MakeTblFrmFmt( const String &rFmtName, 1485 SwFrmFmt *pDerivedFrom ) 1486 { 1487 SwTableFmt* pFmt = new SwTableFmt( GetAttrPool(), rFmtName, pDerivedFrom ); 1488 pTblFrmFmtTbl->Insert( pFmt, pTblFrmFmtTbl->Count() ); 1489 SetModified(); 1490 1491 return pFmt; 1492 } 1493 1494 SwFrmFmt *SwDoc::MakeFrmFmt(const String &rFmtName, 1495 SwFrmFmt *pDerivedFrom, 1496 sal_Bool bBroadcast, sal_Bool bAuto) 1497 { 1498 1499 SwFrmFmt *pFmt = new SwFrmFmt( GetAttrPool(), rFmtName, pDerivedFrom ); 1500 1501 pFmt->SetAuto(bAuto); 1502 pFrmFmtTbl->Insert( pFmt, pFrmFmtTbl->Count()); 1503 SetModified(); 1504 1505 if (bBroadcast) 1506 { 1507 BroadcastStyleOperation(rFmtName, SFX_STYLE_FAMILY_PARA, 1508 SFX_STYLESHEET_CREATED); 1509 1510 if (GetIDocumentUndoRedo().DoesUndo()) 1511 { 1512 SwUndo * pUndo = new SwUndoFrmFmtCreate(pFmt, pDerivedFrom, this); 1513 1514 GetIDocumentUndoRedo().AppendUndo(pUndo); 1515 } 1516 } 1517 1518 return pFmt; 1519 } 1520 1521 SwFmt *SwDoc::_MakeFrmFmt(const String &rFmtName, 1522 SwFmt *pDerivedFrom, 1523 sal_Bool bBroadcast, sal_Bool bAuto) 1524 { 1525 SwFrmFmt *pFrmFmt = dynamic_cast<SwFrmFmt*>(pDerivedFrom); 1526 pFrmFmt = MakeFrmFmt( rFmtName, pFrmFmt, bBroadcast, bAuto ); 1527 return dynamic_cast<SwFmt*>(pFrmFmt); 1528 } 1529 1530 1531 // --> OD 2005-01-13 #i40550# - add parameter <bAuto> - not relevant 1532 SwCharFmt *SwDoc::MakeCharFmt( const String &rFmtName, 1533 SwCharFmt *pDerivedFrom, 1534 sal_Bool bBroadcast, 1535 sal_Bool ) 1536 // <-- 1537 { 1538 SwCharFmt *pFmt = new SwCharFmt( GetAttrPool(), rFmtName, pDerivedFrom ); 1539 pCharFmtTbl->Insert( pFmt, pCharFmtTbl->Count() ); 1540 pFmt->SetAuto( sal_False ); 1541 SetModified(); 1542 1543 if (GetIDocumentUndoRedo().DoesUndo()) 1544 { 1545 SwUndo * pUndo = new SwUndoCharFmtCreate(pFmt, pDerivedFrom, this); 1546 1547 GetIDocumentUndoRedo().AppendUndo(pUndo); 1548 } 1549 1550 if (bBroadcast) 1551 { 1552 BroadcastStyleOperation(rFmtName, SFX_STYLE_FAMILY_CHAR, 1553 SFX_STYLESHEET_CREATED); 1554 } 1555 1556 return pFmt; 1557 } 1558 1559 SwFmt *SwDoc::_MakeCharFmt(const String &rFmtName, 1560 SwFmt *pDerivedFrom, 1561 sal_Bool bBroadcast, sal_Bool bAuto) 1562 { 1563 SwCharFmt *pCharFmt = dynamic_cast<SwCharFmt*>(pDerivedFrom); 1564 pCharFmt = MakeCharFmt( rFmtName, pCharFmt, bBroadcast, bAuto ); 1565 return dynamic_cast<SwFmt*>(pCharFmt); 1566 } 1567 1568 1569 /* 1570 * Erzeugen der FormatCollections 1571 */ 1572 // TXT 1573 // --> OD 2005-01-13 #i40550# - add parameter <bAuto> - not relevant 1574 SwTxtFmtColl* SwDoc::MakeTxtFmtColl( const String &rFmtName, 1575 SwTxtFmtColl *pDerivedFrom, 1576 sal_Bool bBroadcast, 1577 sal_Bool ) 1578 // <-- 1579 { 1580 SwTxtFmtColl *pFmtColl = new SwTxtFmtColl( GetAttrPool(), rFmtName, 1581 pDerivedFrom ); 1582 pTxtFmtCollTbl->Insert(pFmtColl, pTxtFmtCollTbl->Count()); 1583 pFmtColl->SetAuto( sal_False ); 1584 SetModified(); 1585 1586 if (GetIDocumentUndoRedo().DoesUndo()) 1587 { 1588 SwUndo * pUndo = new SwUndoTxtFmtCollCreate(pFmtColl, pDerivedFrom, 1589 this); 1590 GetIDocumentUndoRedo().AppendUndo(pUndo); 1591 } 1592 1593 if (bBroadcast) 1594 BroadcastStyleOperation(rFmtName, SFX_STYLE_FAMILY_PARA, 1595 SFX_STYLESHEET_CREATED); 1596 1597 return pFmtColl; 1598 } 1599 1600 SwFmt *SwDoc::_MakeTxtFmtColl(const String &rFmtName, 1601 SwFmt *pDerivedFrom, 1602 sal_Bool bBroadcast, sal_Bool bAuto) 1603 { 1604 SwTxtFmtColl *pTxtFmtColl = dynamic_cast<SwTxtFmtColl*>(pDerivedFrom); 1605 pTxtFmtColl = MakeTxtFmtColl( rFmtName, pTxtFmtColl, bBroadcast, bAuto ); 1606 return dynamic_cast<SwFmt*>(pTxtFmtColl); 1607 } 1608 1609 1610 //FEATURE::CONDCOLL 1611 SwConditionTxtFmtColl* SwDoc::MakeCondTxtFmtColl( const String &rFmtName, 1612 SwTxtFmtColl *pDerivedFrom, 1613 sal_Bool bBroadcast) 1614 { 1615 SwConditionTxtFmtColl*pFmtColl = new SwConditionTxtFmtColl( GetAttrPool(), 1616 rFmtName, pDerivedFrom ); 1617 pTxtFmtCollTbl->Insert(pFmtColl, pTxtFmtCollTbl->Count()); 1618 pFmtColl->SetAuto( sal_False ); 1619 SetModified(); 1620 1621 if (bBroadcast) 1622 BroadcastStyleOperation(rFmtName, SFX_STYLE_FAMILY_PARA, 1623 SFX_STYLESHEET_CREATED); 1624 1625 return pFmtColl; 1626 } 1627 //FEATURE::CONDCOLL 1628 1629 // GRF 1630 1631 SwGrfFmtColl* SwDoc::MakeGrfFmtColl( const String &rFmtName, 1632 SwGrfFmtColl *pDerivedFrom ) 1633 { 1634 SwGrfFmtColl *pFmtColl = new SwGrfFmtColl( GetAttrPool(), rFmtName, 1635 pDerivedFrom ); 1636 pGrfFmtCollTbl->Insert( pFmtColl, pGrfFmtCollTbl->Count() ); 1637 pFmtColl->SetAuto( sal_False ); 1638 SetModified(); 1639 return pFmtColl; 1640 } 1641 1642 void SwDoc::DelTxtFmtColl(sal_uInt16 nFmtColl, sal_Bool bBroadcast) 1643 { 1644 ASSERT( nFmtColl, "Remove fuer Coll 0." ); 1645 1646 // Wer hat die zu loeschende als Next 1647 SwTxtFmtColl *pDel = (*pTxtFmtCollTbl)[nFmtColl]; 1648 if( pDfltTxtFmtColl == pDel ) 1649 return; // default nie loeschen !! 1650 1651 if (bBroadcast) 1652 BroadcastStyleOperation(pDel->GetName(), SFX_STYLE_FAMILY_PARA, 1653 SFX_STYLESHEET_ERASED); 1654 1655 if (GetIDocumentUndoRedo().DoesUndo()) 1656 { 1657 SwUndoTxtFmtCollDelete * pUndo = 1658 new SwUndoTxtFmtCollDelete(pDel, this); 1659 1660 GetIDocumentUndoRedo().AppendUndo(pUndo); 1661 } 1662 1663 // Die FmtColl austragen 1664 pTxtFmtCollTbl->Remove(nFmtColl); 1665 // Next korrigieren 1666 pTxtFmtCollTbl->ForEach( 1, pTxtFmtCollTbl->Count(), 1667 &SetTxtFmtCollNext, pDel ); 1668 delete pDel; 1669 SetModified(); 1670 } 1671 1672 void SwDoc::DelTxtFmtColl( SwTxtFmtColl *pColl, sal_Bool bBroadcast ) 1673 { 1674 sal_uInt16 nFmt = pTxtFmtCollTbl->GetPos( pColl ); 1675 ASSERT( USHRT_MAX != nFmt, "Collection not found," ); 1676 DelTxtFmtColl( nFmt, bBroadcast ); 1677 } 1678 1679 sal_Bool lcl_SetTxtFmtColl( const SwNodePtr& rpNode, void* pArgs ) 1680 { 1681 // ParaSetFmtColl * pPara = (ParaSetFmtColl*)pArgs; 1682 SwCntntNode* pCNd = (SwCntntNode*)rpNode->GetTxtNode(); 1683 if( pCNd ) 1684 { 1685 ParaRstFmt* pPara = (ParaRstFmt*)pArgs; 1686 1687 SwTxtFmtColl* pFmt = static_cast<SwTxtFmtColl*>(pPara->pFmtColl); 1688 if ( pPara->bReset ) 1689 { 1690 1691 if( pFmt->GetAttrOutlineLevel() == 0 && pPara ) 1692 pPara->bKeepOutlineLevelAttr = true; 1693 1694 lcl_RstAttr( pCNd, pPara ); 1695 1696 // --> OD 2007-11-06 #i62675# 1697 // --> OD 2008-04-15 #refactorlists# 1698 // check, if paragraph style has changed 1699 if ( pPara->bResetListAttrs && 1700 pFmt != pCNd->GetFmtColl() && 1701 pFmt->GetItemState( RES_PARATR_NUMRULE ) == SFX_ITEM_SET ) 1702 { 1703 // --> OD 2009-09-07 #b6876367# 1704 // Check, if the list style of the paragraph will change. 1705 bool bChangeOfListStyleAtParagraph( true ); 1706 SwTxtNode* pTNd( dynamic_cast<SwTxtNode*>(pCNd) ); 1707 ASSERT( pTNd, 1708 "<lcl_SetTxtFmtColl(..)> - text node expected -> crash" ); 1709 { 1710 SwNumRule* pNumRuleAtParagraph( pTNd->GetNumRule() ); 1711 if ( pNumRuleAtParagraph ) 1712 { 1713 const SwNumRuleItem& rNumRuleItemAtParagraphStyle = 1714 pFmt->GetNumRule(); 1715 if ( rNumRuleItemAtParagraphStyle.GetValue() == 1716 pNumRuleAtParagraph->GetName() ) 1717 { 1718 bChangeOfListStyleAtParagraph = false; 1719 } 1720 } 1721 } 1722 1723 if ( bChangeOfListStyleAtParagraph ) 1724 { 1725 // --> OD 2008-04-08 #refactorlists# 1726 std::auto_ptr< SwRegHistory > pRegH; 1727 if ( pPara->pHistory ) 1728 { 1729 pRegH.reset( new SwRegHistory( pTNd, *pTNd, pPara->pHistory ) ); 1730 } 1731 1732 pCNd->ResetAttr( RES_PARATR_NUMRULE ); 1733 1734 // reset all list attributes 1735 pCNd->ResetAttr( RES_PARATR_LIST_LEVEL ); 1736 pCNd->ResetAttr( RES_PARATR_LIST_ISRESTART ); 1737 pCNd->ResetAttr( RES_PARATR_LIST_RESTARTVALUE ); 1738 pCNd->ResetAttr( RES_PARATR_LIST_ISCOUNTED ); 1739 pCNd->ResetAttr( RES_PARATR_LIST_ID ); 1740 } 1741 // <-- 1742 } 1743 // <-- 1744 } 1745 1746 // erst in die History aufnehmen, damit ggfs. alte Daten 1747 // gesichert werden koennen 1748 if( pPara->pHistory ) 1749 pPara->pHistory->Add( pCNd->GetFmtColl(), pCNd->GetIndex(), 1750 ND_TEXTNODE ); 1751 1752 pCNd->ChgFmtColl( pFmt ); 1753 1754 pPara->nWhich++; 1755 } 1756 return sal_True; 1757 } 1758 1759 sal_Bool SwDoc::SetTxtFmtColl( const SwPaM &rRg, 1760 SwTxtFmtColl *pFmt, 1761 bool bReset, 1762 bool bResetListAttrs ) 1763 { 1764 SwDataChanged aTmp( rRg, 0 ); 1765 const SwPosition *pStt = rRg.Start(), *pEnd = rRg.End(); 1766 SwHistory* pHst = 0; 1767 sal_Bool bRet = sal_True; 1768 1769 if (GetIDocumentUndoRedo().DoesUndo()) 1770 { 1771 // --> OD 2008-04-15 #refactorlists# 1772 SwUndoFmtColl* pUndo = new SwUndoFmtColl( rRg, pFmt, 1773 bReset, 1774 bResetListAttrs ); 1775 // <-- 1776 pHst = pUndo->GetHistory(); 1777 GetIDocumentUndoRedo().AppendUndo(pUndo); 1778 } 1779 1780 ParaRstFmt aPara( pStt, pEnd, pHst ); 1781 aPara.pFmtColl = pFmt; 1782 aPara.bReset = bReset; 1783 // --> OD 2007-11-06 #i62675# 1784 aPara.bResetListAttrs = bResetListAttrs; 1785 // <-- 1786 1787 GetNodes().ForEach( pStt->nNode.GetIndex(), pEnd->nNode.GetIndex()+1, 1788 lcl_SetTxtFmtColl, &aPara ); 1789 if( !aPara.nWhich ) 1790 bRet = sal_False; // keinen gueltigen Node gefunden 1791 1792 if( bRet ) 1793 SetModified(); 1794 return bRet; 1795 } 1796 1797 1798 // ---- Kopiere die Formate in sich selbst (SwDoc) ---------------------- 1799 1800 SwFmt* SwDoc::CopyFmt( const SwFmt& rFmt, 1801 const SvPtrarr& rFmtArr, 1802 FNCopyFmt fnCopyFmt, const SwFmt& rDfltFmt ) 1803 { 1804 // kein-Autoformat || default Format || Collection-Format 1805 // dann suche danach. 1806 if( !rFmt.IsAuto() || !rFmt.GetRegisteredIn() ) 1807 for( sal_uInt16 n = 0; n < rFmtArr.Count(); n++ ) 1808 { 1809 // ist die Vorlage schon im Doc vorhanden ?? 1810 if( ((SwFmt*)rFmtArr[n])->GetName().Equals( rFmt.GetName() )) 1811 return (SwFmt*)rFmtArr[n]; 1812 } 1813 1814 // suche erstmal nach dem "Parent" 1815 SwFmt* pParent = (SwFmt*)&rDfltFmt; 1816 if( rFmt.DerivedFrom() && pParent != rFmt.DerivedFrom() ) 1817 pParent = CopyFmt( *rFmt.DerivedFrom(), rFmtArr, 1818 fnCopyFmt, rDfltFmt ); 1819 1820 // erzeuge das Format und kopiere die Attribute 1821 // --> OD 2005-01-13 #i40550# 1822 SwFmt* pNewFmt = (this->*fnCopyFmt)( rFmt.GetName(), pParent, sal_False, sal_True ); 1823 // <-- 1824 pNewFmt->SetAuto( rFmt.IsAuto() ); 1825 pNewFmt->CopyAttrs( rFmt, sal_True ); // kopiere Attribute 1826 1827 pNewFmt->SetPoolFmtId( rFmt.GetPoolFmtId() ); 1828 pNewFmt->SetPoolHelpId( rFmt.GetPoolHelpId() ); 1829 1830 // HelpFile-Id immer auf dflt setzen !! 1831 pNewFmt->SetPoolHlpFileId( UCHAR_MAX ); 1832 1833 return pNewFmt; 1834 } 1835 1836 1837 // ---- kopiere das Frame-Format -------- 1838 SwFrmFmt* SwDoc::CopyFrmFmt( const SwFrmFmt& rFmt ) 1839 { 1840 1841 return (SwFrmFmt*)CopyFmt( rFmt, *GetFrmFmts(), &SwDoc::_MakeFrmFmt, 1842 *GetDfltFrmFmt() ); 1843 } 1844 1845 // ---- kopiere das Char-Format -------- 1846 SwCharFmt* SwDoc::CopyCharFmt( const SwCharFmt& rFmt ) 1847 { 1848 return (SwCharFmt*)CopyFmt( rFmt, *GetCharFmts(), 1849 &SwDoc::_MakeCharFmt, 1850 *GetDfltCharFmt() ); 1851 } 1852 1853 1854 // --- Kopiere TextNodes ---- 1855 1856 SwTxtFmtColl* SwDoc::CopyTxtColl( const SwTxtFmtColl& rColl ) 1857 { 1858 SwTxtFmtColl* pNewColl = FindTxtFmtCollByName( rColl.GetName() ); 1859 if( pNewColl ) 1860 return pNewColl; 1861 1862 // suche erstmal nach dem "Parent" 1863 SwTxtFmtColl* pParent = pDfltTxtFmtColl; 1864 if( pParent != rColl.DerivedFrom() ) 1865 pParent = CopyTxtColl( *(SwTxtFmtColl*)rColl.DerivedFrom() ); 1866 1867 1868 //FEATURE::CONDCOLL 1869 if( RES_CONDTXTFMTCOLL == rColl.Which() ) 1870 { 1871 pNewColl = new SwConditionTxtFmtColl( GetAttrPool(), rColl.GetName(), 1872 pParent); 1873 pTxtFmtCollTbl->Insert( pNewColl, pTxtFmtCollTbl->Count() ); 1874 pNewColl->SetAuto( sal_False ); 1875 SetModified(); 1876 1877 // Kopiere noch die Bedingungen 1878 ((SwConditionTxtFmtColl*)pNewColl)->SetConditions( 1879 ((SwConditionTxtFmtColl&)rColl).GetCondColls() ); 1880 } 1881 else 1882 //FEATURE::CONDCOLL 1883 pNewColl = MakeTxtFmtColl( rColl.GetName(), pParent ); 1884 1885 // kopiere jetzt noch die Auto-Formate oder kopiere die Attribute 1886 pNewColl->CopyAttrs( rColl, sal_True ); 1887 1888 // setze noch den Outline-Level 1889 //if( NO_NUMBERING != rColl.GetOutlineLevel() ) //#outline level,zhaojianwei 1890 // pNewColl->SetOutlineLevel( rColl.GetOutlineLevel() ); 1891 if(rColl.IsAssignedToListLevelOfOutlineStyle()) 1892 pNewColl->AssignToListLevelOfOutlineStyle(rColl.GetAssignedOutlineStyleLevel());//<-end,zhaojianwei 1893 //<-end 1894 pNewColl->SetPoolFmtId( rColl.GetPoolFmtId() ); 1895 pNewColl->SetPoolHelpId( rColl.GetPoolHelpId() ); 1896 1897 // HelpFile-Id immer auf dflt setzen !! 1898 pNewColl->SetPoolHlpFileId( UCHAR_MAX ); 1899 1900 if( &rColl.GetNextTxtFmtColl() != &rColl ) 1901 pNewColl->SetNextTxtFmtColl( *CopyTxtColl( rColl.GetNextTxtFmtColl() )); 1902 1903 // ggfs. die NumRule erzeugen 1904 if( this != rColl.GetDoc() ) 1905 { 1906 const SfxPoolItem* pItem; 1907 if( SFX_ITEM_SET == pNewColl->GetItemState( RES_PARATR_NUMRULE, 1908 sal_False, &pItem )) 1909 { 1910 const SwNumRule* pRule; 1911 const String& rName = ((SwNumRuleItem*)pItem)->GetValue(); 1912 if( rName.Len() && 1913 0 != ( pRule = rColl.GetDoc()->FindNumRulePtr( rName )) && 1914 !pRule->IsAutoRule() ) 1915 { 1916 SwNumRule* pDestRule = FindNumRulePtr( rName ); 1917 if( pDestRule ) 1918 pDestRule->SetInvalidRule( sal_True ); 1919 else 1920 MakeNumRule( rName, pRule ); 1921 } 1922 } 1923 } 1924 return pNewColl; 1925 } 1926 1927 // --- Kopiere GrafikNodes ---- 1928 1929 SwGrfFmtColl* SwDoc::CopyGrfColl( const SwGrfFmtColl& rColl ) 1930 { 1931 SwGrfFmtColl* pNewColl = FindGrfFmtCollByName( rColl.GetName() ); 1932 if( pNewColl ) 1933 return pNewColl; 1934 1935 // suche erstmal nach dem "Parent" 1936 SwGrfFmtColl* pParent = pDfltGrfFmtColl; 1937 if( pParent != rColl.DerivedFrom() ) 1938 pParent = CopyGrfColl( *(SwGrfFmtColl*)rColl.DerivedFrom() ); 1939 1940 // falls nicht, so kopiere sie 1941 pNewColl = MakeGrfFmtColl( rColl.GetName(), pParent ); 1942 1943 // noch die Attribute kopieren 1944 pNewColl->CopyAttrs( rColl ); 1945 1946 pNewColl->SetPoolFmtId( rColl.GetPoolFmtId() ); 1947 pNewColl->SetPoolHelpId( rColl.GetPoolHelpId() ); 1948 1949 // HelpFile-Id immer auf dflt setzen !! 1950 pNewColl->SetPoolHlpFileId( UCHAR_MAX ); 1951 1952 return pNewColl; 1953 } 1954 1955 SwPageDesc* lcl_FindPageDesc( const SwPageDescs& rArr, const String& rName ) 1956 { 1957 for( sal_uInt16 n = rArr.Count(); n; ) 1958 { 1959 SwPageDesc* pDesc = rArr[ --n ]; 1960 if( pDesc->GetName() == rName ) 1961 return pDesc; 1962 } 1963 return 0; 1964 } 1965 1966 void SwDoc::CopyFmtArr( const SvPtrarr& rSourceArr, 1967 SvPtrarr& rDestArr, 1968 FNCopyFmt fnCopyFmt, 1969 SwFmt& rDfltFmt ) 1970 { 1971 sal_uInt16 nSrc; 1972 SwFmt* pSrc, *pDest; 1973 1974 // 1. Schritt alle Formate anlegen (das 0. ueberspringen - Default!) 1975 for( nSrc = rSourceArr.Count(); nSrc > 1; ) 1976 { 1977 pSrc = (SwFmt*)rSourceArr[ --nSrc ]; 1978 if( pSrc->IsDefault() || pSrc->IsAuto() ) 1979 continue; 1980 1981 if( 0 == FindFmtByName( rDestArr, pSrc->GetName() ) ) 1982 { 1983 if( RES_CONDTXTFMTCOLL == pSrc->Which() ) 1984 MakeCondTxtFmtColl( pSrc->GetName(), (SwTxtFmtColl*)&rDfltFmt ); 1985 else 1986 // --> OD 2005-01-13 #i40550# 1987 (this->*fnCopyFmt)( pSrc->GetName(), &rDfltFmt, sal_False, sal_True ); 1988 // <-- 1989 } 1990 } 1991 1992 // 2. Schritt alle Attribute kopieren, richtige Parents setzen 1993 for( nSrc = rSourceArr.Count(); nSrc > 1; ) 1994 { 1995 pSrc = (SwFmt*)rSourceArr[ --nSrc ]; 1996 if( pSrc->IsDefault() || pSrc->IsAuto() ) 1997 continue; 1998 1999 pDest = FindFmtByName( rDestArr, pSrc->GetName() ); 2000 pDest->SetAuto( sal_False ); 2001 pDest->DelDiffs( *pSrc ); 2002 2003 // #i94285#: existing <SwFmtPageDesc> instance, before copying attributes 2004 const SfxPoolItem* pItem; 2005 if( &GetAttrPool() != pSrc->GetAttrSet().GetPool() && 2006 SFX_ITEM_SET == pSrc->GetAttrSet().GetItemState( 2007 RES_PAGEDESC, sal_False, &pItem ) && 2008 ((SwFmtPageDesc*)pItem)->GetPageDesc() ) 2009 { 2010 SwFmtPageDesc aPageDesc( *(SwFmtPageDesc*)pItem ); 2011 const String& rNm = aPageDesc.GetPageDesc()->GetName(); 2012 SwPageDesc* pPageDesc = ::lcl_FindPageDesc( aPageDescs, rNm ); 2013 if( !pPageDesc ) 2014 { 2015 pPageDesc = aPageDescs[ MakePageDesc( rNm ) ]; 2016 } 2017 aPageDesc.RegisterToPageDesc( *pPageDesc ); 2018 SwAttrSet aTmpAttrSet( pSrc->GetAttrSet() ); 2019 aTmpAttrSet.Put( aPageDesc ); 2020 pDest->SetFmtAttr( aTmpAttrSet ); 2021 } 2022 else 2023 { 2024 pDest->SetFmtAttr( pSrc->GetAttrSet() ); 2025 } 2026 2027 pDest->SetPoolFmtId( pSrc->GetPoolFmtId() ); 2028 pDest->SetPoolHelpId( pSrc->GetPoolHelpId() ); 2029 2030 // HelpFile-Id immer auf dflt setzen !! 2031 pDest->SetPoolHlpFileId( UCHAR_MAX ); 2032 2033 if( pSrc->DerivedFrom() ) 2034 pDest->SetDerivedFrom( FindFmtByName( rDestArr, 2035 pSrc->DerivedFrom()->GetName() ) ); 2036 if( RES_TXTFMTCOLL == pSrc->Which() || 2037 RES_CONDTXTFMTCOLL == pSrc->Which() ) 2038 { 2039 SwTxtFmtColl* pSrcColl = (SwTxtFmtColl*)pSrc, 2040 * pDstColl = (SwTxtFmtColl*)pDest; 2041 if( &pSrcColl->GetNextTxtFmtColl() != pSrcColl ) 2042 pDstColl->SetNextTxtFmtColl( *(SwTxtFmtColl*)FindFmtByName( 2043 rDestArr, pSrcColl->GetNextTxtFmtColl().GetName() ) ); 2044 2045 // setze noch den Outline-Level 2046 //if( NO_NUMBERING != pSrcColl->GetOutlineLevel() ) //#outline level,zhaojianwei 2047 // pDstColl->SetOutlineLevel( pSrcColl->GetOutlineLevel() ); 2048 if(pSrcColl->IsAssignedToListLevelOfOutlineStyle()) 2049 pDstColl->AssignToListLevelOfOutlineStyle(pSrcColl->GetAssignedOutlineStyleLevel());//<-end,zhaojianwei 2050 //<-end 2051 2052 //FEATURE::CONDCOLL 2053 if( RES_CONDTXTFMTCOLL == pSrc->Which() ) 2054 // Kopiere noch die Bedingungen 2055 // aber erst die alten loeschen! 2056 ((SwConditionTxtFmtColl*)pDstColl)->SetConditions( 2057 ((SwConditionTxtFmtColl*)pSrc)->GetCondColls() ); 2058 //FEATURE::CONDCOLL 2059 } 2060 } 2061 } 2062 2063 void SwDoc::CopyPageDescHeaderFooterImpl( bool bCpyHeader, 2064 const SwFrmFmt& rSrcFmt, SwFrmFmt& rDestFmt ) 2065 { 2066 // jetzt noch Header-/Footer-Attribute richtig behandeln 2067 // Contenten Nodes Dokumentuebergreifend kopieren! 2068 sal_uInt16 nAttr = static_cast<sal_uInt16>( bCpyHeader ? RES_HEADER : RES_FOOTER ); 2069 const SfxPoolItem* pItem; 2070 if( SFX_ITEM_SET != rSrcFmt.GetAttrSet().GetItemState( nAttr, sal_False, &pItem )) 2071 return ; 2072 2073 // Im Header steht noch der Verweis auf das Format aus dem 2074 // anderen Document!! 2075 SfxPoolItem* pNewItem = pItem->Clone(); 2076 2077 SwFrmFmt* pOldFmt; 2078 if( bCpyHeader ) 2079 pOldFmt = ((SwFmtHeader*)pNewItem)->GetHeaderFmt(); 2080 else 2081 pOldFmt = ((SwFmtFooter*)pNewItem)->GetFooterFmt(); 2082 2083 if( pOldFmt ) 2084 { 2085 SwFrmFmt* pNewFmt = new SwFrmFmt( GetAttrPool(), "CpyDesc", 2086 GetDfltFrmFmt() ); 2087 pNewFmt->CopyAttrs( *pOldFmt, sal_True ); 2088 2089 if( SFX_ITEM_SET == pNewFmt->GetAttrSet().GetItemState( 2090 RES_CNTNT, sal_False, &pItem )) 2091 { 2092 SwFmtCntnt* pCntnt = (SwFmtCntnt*)pItem; 2093 if( pCntnt->GetCntntIdx() ) 2094 { 2095 SwNodeIndex aTmpIdx( GetNodes().GetEndOfAutotext() ); 2096 const SwNodes& rSrcNds = rSrcFmt.GetDoc()->GetNodes(); 2097 SwStartNode* pSttNd = GetNodes().MakeEmptySection( aTmpIdx, 2098 bCpyHeader 2099 ? SwHeaderStartNode 2100 : SwFooterStartNode ); 2101 const SwNode& rCSttNd = pCntnt->GetCntntIdx()->GetNode(); 2102 SwNodeRange aRg( rCSttNd, 0, *rCSttNd.EndOfSectionNode() ); 2103 aTmpIdx = *pSttNd->EndOfSectionNode(); 2104 rSrcNds._Copy( aRg, aTmpIdx ); 2105 aTmpIdx = *pSttNd; 2106 rSrcFmt.GetDoc()->CopyFlyInFlyImpl( aRg, 0, aTmpIdx ); 2107 pNewFmt->SetFmtAttr( SwFmtCntnt( pSttNd )); 2108 } 2109 else 2110 pNewFmt->ResetFmtAttr( RES_CNTNT ); 2111 } 2112 if( bCpyHeader ) 2113 ((SwFmtHeader*)pNewItem)->RegisterToFormat(*pNewFmt); 2114 else 2115 ((SwFmtFooter*)pNewItem)->RegisterToFormat(*pNewFmt); 2116 rDestFmt.SetFmtAttr( *pNewItem ); 2117 } 2118 delete pNewItem; 2119 } 2120 2121 void SwDoc::CopyPageDesc( const SwPageDesc& rSrcDesc, SwPageDesc& rDstDesc, 2122 sal_Bool bCopyPoolIds ) 2123 { 2124 sal_Bool bNotifyLayout = sal_False; 2125 SwRootFrm* pTmpRoot = GetCurrentLayout();//swmod 080219 2126 2127 rDstDesc.SetLandscape( rSrcDesc.GetLandscape() ); 2128 rDstDesc.SetNumType( rSrcDesc.GetNumType() ); 2129 if( rDstDesc.ReadUseOn() != rSrcDesc.ReadUseOn() ) 2130 { 2131 rDstDesc.WriteUseOn( rSrcDesc.ReadUseOn() ); 2132 bNotifyLayout = sal_True; 2133 } 2134 2135 if( bCopyPoolIds ) 2136 { 2137 rDstDesc.SetPoolFmtId( rSrcDesc.GetPoolFmtId() ); 2138 rDstDesc.SetPoolHelpId( rSrcDesc.GetPoolHelpId() ); 2139 // HelpFile-Id immer auf dflt setzen !! 2140 rDstDesc.SetPoolHlpFileId( UCHAR_MAX ); 2141 } 2142 2143 if( rSrcDesc.GetFollow() != &rSrcDesc ) 2144 { 2145 SwPageDesc* pFollow = ::lcl_FindPageDesc( aPageDescs, 2146 rSrcDesc.GetFollow()->GetName() ); 2147 if( !pFollow ) 2148 { 2149 // dann mal kopieren 2150 sal_uInt16 nPos = MakePageDesc( rSrcDesc.GetFollow()->GetName() ); 2151 pFollow = aPageDescs[ nPos ]; 2152 CopyPageDesc( *rSrcDesc.GetFollow(), *pFollow ); 2153 } 2154 rDstDesc.SetFollow( pFollow ); 2155 bNotifyLayout = sal_True; 2156 } 2157 2158 // die Header/Footer-Attribute werden gesondert kopiert, die Content- 2159 // Sections muessen vollstaendig mitgenommen werden! 2160 { 2161 SfxItemSet aAttrSet( rSrcDesc.GetMaster().GetAttrSet() ); 2162 aAttrSet.ClearItem( RES_HEADER ); 2163 aAttrSet.ClearItem( RES_FOOTER ); 2164 2165 rDstDesc.GetMaster().DelDiffs( aAttrSet ); 2166 rDstDesc.GetMaster().SetFmtAttr( aAttrSet ); 2167 2168 aAttrSet.ClearItem(); 2169 aAttrSet.Put( rSrcDesc.GetLeft().GetAttrSet() ); 2170 aAttrSet.ClearItem( RES_HEADER ); 2171 aAttrSet.ClearItem( RES_FOOTER ); 2172 2173 rDstDesc.GetLeft().DelDiffs( aAttrSet ); 2174 rDstDesc.GetLeft().SetFmtAttr( aAttrSet ); 2175 } 2176 2177 CopyHeader( rSrcDesc.GetMaster(), rDstDesc.GetMaster() ); 2178 CopyFooter( rSrcDesc.GetMaster(), rDstDesc.GetMaster() ); 2179 if( !rDstDesc.IsHeaderShared() ) 2180 CopyHeader( rSrcDesc.GetLeft(), rDstDesc.GetLeft() ); 2181 else 2182 rDstDesc.GetLeft().SetFmtAttr( rDstDesc.GetMaster().GetHeader() ); 2183 2184 if( !rDstDesc.IsFooterShared() ) 2185 CopyFooter( rSrcDesc.GetLeft(), rDstDesc.GetLeft() ); 2186 else 2187 rDstDesc.GetLeft().SetFmtAttr( rDstDesc.GetMaster().GetFooter() ); 2188 2189 if( bNotifyLayout && pTmpRoot ) 2190 { 2191 std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();//swmod 080225 2192 std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::AllCheckPageDescs));//swmod 080226 2193 } 2194 2195 //Wenn sich FussnotenInfo veraendert, so werden die Seiten 2196 //angetriggert. 2197 if( !(rDstDesc.GetFtnInfo() == rSrcDesc.GetFtnInfo()) ) 2198 { 2199 rDstDesc.SetFtnInfo( rSrcDesc.GetFtnInfo() ); 2200 SwMsgPoolItem aInfo( RES_PAGEDESC_FTNINFO ); 2201 { 2202 rDstDesc.GetMaster().ModifyBroadcast( &aInfo, 0, TYPE(SwFrm) ); 2203 } 2204 { 2205 rDstDesc.GetLeft().ModifyBroadcast( &aInfo, 0, TYPE(SwFrm) ); 2206 } 2207 } 2208 } 2209 2210 void SwDoc::ReplaceStyles( SwDoc& rSource ) 2211 { 2212 ::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo()); 2213 2214 CopyFmtArr( *rSource.pCharFmtTbl, *pCharFmtTbl, 2215 &SwDoc::_MakeCharFmt, *pDfltCharFmt ); 2216 CopyFmtArr( *rSource.pFrmFmtTbl, *pFrmFmtTbl, 2217 &SwDoc::_MakeFrmFmt, *pDfltFrmFmt ); 2218 CopyFmtArr( *rSource.pTxtFmtCollTbl, *pTxtFmtCollTbl, 2219 &SwDoc::_MakeTxtFmtColl, *pDfltTxtFmtColl ); 2220 2221 // und jetzt noch die Seiten-Vorlagen 2222 sal_uInt16 nCnt = rSource.aPageDescs.Count(); 2223 if( nCnt ) 2224 { 2225 // ein anderes Doc -> Numberformatter muessen gemergt werden 2226 SwTblNumFmtMerge aTNFM( rSource, *this ); 2227 2228 // 1. Schritt alle Formate anlegen (das 0. ueberspringen - Default!) 2229 while( nCnt ) 2230 { 2231 SwPageDesc *pSrc = rSource.aPageDescs[ --nCnt ]; 2232 if( 0 == ::lcl_FindPageDesc( aPageDescs, pSrc->GetName() ) ) 2233 MakePageDesc( pSrc->GetName() ); 2234 } 2235 2236 // 2. Schritt alle Attribute kopieren, richtige Parents setzen 2237 for( nCnt = rSource.aPageDescs.Count(); nCnt; ) 2238 { 2239 SwPageDesc *pSrc = rSource.aPageDescs[ --nCnt ]; 2240 CopyPageDesc( *pSrc, *::lcl_FindPageDesc( aPageDescs, pSrc->GetName() )); 2241 } 2242 } 2243 2244 //JP 08.04.99: und dann sind da noch die Numerierungs-Vorlagen 2245 nCnt = rSource.GetNumRuleTbl().Count(); 2246 if( nCnt ) 2247 { 2248 const SwNumRuleTbl& rArr = rSource.GetNumRuleTbl(); 2249 for( sal_uInt16 n = 0; n < nCnt; ++n ) 2250 { 2251 const SwNumRule& rR = *rArr[ n ]; 2252 if( !rR.IsAutoRule() ) 2253 { 2254 SwNumRule* pNew = FindNumRulePtr( rR.GetName()); 2255 if( pNew ) 2256 pNew->CopyNumRule( this, rR ); 2257 else 2258 MakeNumRule( rR.GetName(), &rR ); 2259 } 2260 } 2261 } 2262 2263 if (undoGuard.UndoWasEnabled()) 2264 { 2265 // nodes array was modified! 2266 GetIDocumentUndoRedo().DelAllUndoObj(); 2267 } 2268 2269 SetModified(); 2270 } 2271 2272 SwFmt* SwDoc::FindFmtByName( const SvPtrarr& rFmtArr, 2273 const String& rName ) const 2274 { 2275 SwFmt* pFnd = 0; 2276 for( sal_uInt16 n = 0; n < rFmtArr.Count(); n++ ) 2277 { 2278 // ist die Vorlage schon im Doc vorhanden ?? 2279 if( ((SwFmt*)rFmtArr[n])->GetName() == rName ) 2280 { 2281 pFnd = (SwFmt*)rFmtArr[n]; 2282 break; 2283 } 2284 } 2285 return pFnd; 2286 } 2287 2288 void SwDoc::MoveLeftMargin( const SwPaM& rPam, sal_Bool bRight, sal_Bool bModulus ) 2289 { 2290 SwHistory* pHistory = 0; 2291 if (GetIDocumentUndoRedo().DoesUndo()) 2292 { 2293 SwUndoMoveLeftMargin* pUndo = new SwUndoMoveLeftMargin( rPam, bRight, 2294 bModulus ); 2295 pHistory = &pUndo->GetHistory(); 2296 GetIDocumentUndoRedo().AppendUndo( pUndo ); 2297 } 2298 2299 const SvxTabStopItem& rTabItem = (SvxTabStopItem&)GetDefault( RES_PARATR_TABSTOP ); 2300 sal_uInt16 nDefDist = rTabItem.Count() ? 2301 static_cast<sal_uInt16>(rTabItem[0].GetTabPos()) : 1134; 2302 const SwPosition &rStt = *rPam.Start(), &rEnd = *rPam.End(); 2303 SwNodeIndex aIdx( rStt.nNode ); 2304 while( aIdx <= rEnd.nNode ) 2305 { 2306 SwTxtNode* pTNd = aIdx.GetNode().GetTxtNode(); 2307 if( pTNd ) 2308 { 2309 SvxLRSpaceItem aLS( (SvxLRSpaceItem&)pTNd->SwCntntNode::GetAttr( RES_LR_SPACE ) ); 2310 2311 // --> FME 2008-09-16 #i93873# See also lcl_MergeListLevelIndentAsLRSpaceItem in thints.cxx 2312 if ( pTNd->AreListLevelIndentsApplicable() ) 2313 { 2314 const SwNumRule* pRule = pTNd->GetNumRule(); 2315 if ( pRule ) 2316 { 2317 const int nListLevel = pTNd->GetActualListLevel(); 2318 if ( nListLevel >= 0 ) 2319 { 2320 const SwNumFmt& rFmt = pRule->Get(static_cast<sal_uInt16>(nListLevel)); 2321 if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT ) 2322 { 2323 aLS.SetTxtLeft( rFmt.GetIndentAt() ); 2324 aLS.SetTxtFirstLineOfst( static_cast<short>(rFmt.GetFirstLineIndent()) ); 2325 } 2326 } 2327 } 2328 } 2329 2330 long nNext = aLS.GetTxtLeft(); 2331 if( bModulus ) 2332 nNext = ( nNext / nDefDist ) * nDefDist; 2333 2334 if( bRight ) 2335 nNext += nDefDist; 2336 else 2337 nNext -= nDefDist; 2338 2339 aLS.SetTxtLeft( nNext ); 2340 2341 SwRegHistory aRegH( pTNd, *pTNd, pHistory ); 2342 pTNd->SetAttr( aLS ); 2343 } 2344 aIdx++; 2345 } 2346 SetModified(); 2347 } 2348 2349 sal_Bool SwDoc::DontExpandFmt( const SwPosition& rPos, sal_Bool bFlag ) 2350 { 2351 sal_Bool bRet = sal_False; 2352 SwTxtNode* pTxtNd = rPos.nNode.GetNode().GetTxtNode(); 2353 if( pTxtNd ) 2354 { 2355 bRet = pTxtNd->DontExpandFmt( rPos.nContent, bFlag ); 2356 if( bRet && GetIDocumentUndoRedo().DoesUndo() ) 2357 { 2358 GetIDocumentUndoRedo().AppendUndo( new SwUndoDontExpandFmt(rPos) ); 2359 } 2360 } 2361 return bRet; 2362 } 2363 2364 SwTableBoxFmt* SwDoc::MakeTableBoxFmt() 2365 { 2366 SwTableBoxFmt* pFmt = new SwTableBoxFmt( GetAttrPool(), aEmptyStr, 2367 pDfltFrmFmt ); 2368 SetModified(); 2369 return pFmt; 2370 } 2371 2372 SwTableLineFmt* SwDoc::MakeTableLineFmt() 2373 { 2374 SwTableLineFmt* pFmt = new SwTableLineFmt( GetAttrPool(), aEmptyStr, 2375 pDfltFrmFmt ); 2376 SetModified(); 2377 return pFmt; 2378 } 2379 2380 void SwDoc::_CreateNumberFormatter() 2381 { 2382 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDoc::_CreateNumberFormatter" ); 2383 2384 ASSERT( !pNumberFormatter, "ist doch schon vorhanden" ); 2385 2386 2387 LanguageType eLang = LANGUAGE_SYSTEM; //System::GetLanguage(); 2388 /* ((const SvxLanguageItem&)GetAttrPool(). 2389 GetDefaultItem( RES_CHRATR_LANGUAGE )).GetLanguage(); 2390 */ 2391 Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory(); 2392 pNumberFormatter = new SvNumberFormatter( xMSF, eLang ); 2393 pNumberFormatter->SetEvalDateFormat( NF_EVALDATEFORMAT_FORMAT_INTL ); 2394 pNumberFormatter->SetYear2000(static_cast<sal_uInt16>(::utl::MiscCfg().GetYear2000())); 2395 2396 } 2397 2398 SwTblNumFmtMerge::SwTblNumFmtMerge( const SwDoc& rSrc, SwDoc& rDest ) 2399 : pNFmt( 0 ) 2400 { 2401 // ein anderes Doc -> Numberformatter muessen gemergt werden 2402 SvNumberFormatter* pN; 2403 if( &rSrc != &rDest && 0 != ( pN = ((SwDoc&)rSrc).GetNumberFormatter( sal_False ) )) 2404 ( pNFmt = rDest.GetNumberFormatter( sal_True ))->MergeFormatter( *pN ); 2405 2406 if( &rSrc != &rDest ) 2407 ((SwGetRefFieldType*)rSrc.GetSysFldType( RES_GETREFFLD ))-> 2408 MergeWithOtherDoc( rDest ); 2409 } 2410 2411 SwTblNumFmtMerge::~SwTblNumFmtMerge() 2412 { 2413 if( pNFmt ) 2414 pNFmt->ClearMergeTable(); 2415 } 2416 2417 2418 void SwDoc::SetTxtFmtCollByAutoFmt( const SwPosition& rPos, sal_uInt16 nPoolId, 2419 const SfxItemSet* pSet ) 2420 { 2421 SwPaM aPam( rPos ); 2422 SwTxtNode* pTNd = rPos.nNode.GetNode().GetTxtNode(); 2423 2424 if( mbIsAutoFmtRedline && pTNd ) 2425 { 2426 // dann das Redline Object anlegen 2427 const SwTxtFmtColl& rColl = *pTNd->GetTxtColl(); 2428 SwRedline* pRedl = new SwRedline( nsRedlineType_t::REDLINE_FMTCOLL, aPam ); 2429 pRedl->SetMark(); 2430 2431 // interressant sind nur die Items, die vom Set NICHT wieder 2432 // in den Node gesetzt werden. Also muss man die Differenz nehmen 2433 SwRedlineExtraData_FmtColl aExtraData( rColl.GetName(), 2434 rColl.GetPoolFmtId() ); 2435 if( pSet && pTNd->HasSwAttrSet() ) 2436 { 2437 SfxItemSet aTmp( *pTNd->GetpSwAttrSet() ); 2438 aTmp.Differentiate( *pSet ); 2439 // das Adjust Item behalten wir extra 2440 const SfxPoolItem* pItem; 2441 if( SFX_ITEM_SET == pTNd->GetpSwAttrSet()->GetItemState( 2442 RES_PARATR_ADJUST, sal_False, &pItem )) 2443 aTmp.Put( *pItem ); 2444 aExtraData.SetItemSet( aTmp ); 2445 } 2446 pRedl->SetExtraData( &aExtraData ); 2447 2448 // !!!!!!!!! Undo fehlt noch !!!!!!!!!!!!!!!!!! 2449 AppendRedline( pRedl, true ); 2450 } 2451 2452 SetTxtFmtColl( aPam, GetTxtCollFromPool( nPoolId ) ); 2453 2454 if( pSet && pTNd && pSet->Count() ) 2455 { 2456 aPam.SetMark(); 2457 aPam.GetMark()->nContent.Assign( pTNd, pTNd->GetTxt().Len() ); 2458 InsertItemSet( aPam, *pSet, 0 ); 2459 } 2460 } 2461 2462 void SwDoc::SetFmtItemByAutoFmt( const SwPaM& rPam, const SfxItemSet& rSet ) 2463 { 2464 SwTxtNode* pTNd = rPam.GetPoint()->nNode.GetNode().GetTxtNode(); 2465 2466 RedlineMode_t eOld = GetRedlineMode(); 2467 2468 if( mbIsAutoFmtRedline && pTNd ) 2469 { 2470 // dann das Redline Object anlegen 2471 SwRedline* pRedl = new SwRedline( nsRedlineType_t::REDLINE_FORMAT, rPam ); 2472 if( !pRedl->HasMark() ) 2473 pRedl->SetMark(); 2474 2475 // interressant sind nur die Items, die vom Set NICHT wieder 2476 // in den Node gesetzt werden. Also muss man die Differenz nehmen 2477 SwRedlineExtraData_Format aExtraData( rSet ); 2478 2479 /* 2480 if( pSet && pTNd->HasSwAttrSet() ) 2481 { 2482 SfxItemSet aTmp( *pTNd->GetpSwAttrSet() ); 2483 aTmp.Differentiate( *pSet ); 2484 // das Adjust Item behalten wir extra 2485 const SfxPoolItem* pItem; 2486 if( SFX_ITEM_SET == pTNd->GetpSwAttrSet()->GetItemState( 2487 RES_PARATR_ADJUST, sal_False, &pItem )) 2488 aTmp.Put( *pItem ); 2489 aExtraData.SetItemSet( aTmp ); 2490 } 2491 */ 2492 pRedl->SetExtraData( &aExtraData ); 2493 2494 // !!!!!!!!! Undo fehlt noch !!!!!!!!!!!!!!!!!! 2495 AppendRedline( pRedl, true ); 2496 2497 SetRedlineMode_intern( (RedlineMode_t)(eOld | nsRedlineMode_t::REDLINE_IGNORE)); 2498 } 2499 2500 InsertItemSet( rPam, rSet, nsSetAttrMode::SETATTR_DONTEXPAND ); 2501 SetRedlineMode_intern( eOld ); 2502 } 2503 2504 void SwDoc::ChgFmt(SwFmt & rFmt, const SfxItemSet & rSet) 2505 { 2506 if (GetIDocumentUndoRedo().DoesUndo()) 2507 { 2508 // copying <rSet> to <aSet> 2509 SfxItemSet aSet(rSet); 2510 // remove from <aSet> all items, which are already set at the format 2511 aSet.Differentiate(rFmt.GetAttrSet()); 2512 // <aSet> contains now all *new* items for the format 2513 2514 // copying current format item set to <aOldSet> 2515 SfxItemSet aOldSet(rFmt.GetAttrSet()); 2516 // insert new items into <aOldSet> 2517 aOldSet.Put(aSet); 2518 // invalidate all new items in <aOldSet> in order to clear these items, 2519 // if the undo action is triggered. 2520 { 2521 SfxItemIter aIter(aSet); 2522 2523 const SfxPoolItem * pItem = aIter.FirstItem(); 2524 while (pItem != NULL) 2525 { 2526 aOldSet.InvalidateItem(pItem->Which()); 2527 2528 pItem = aIter.NextItem(); 2529 } 2530 } 2531 2532 SwUndo * pUndo = new SwUndoFmtAttr(aOldSet, rFmt); 2533 2534 GetIDocumentUndoRedo().AppendUndo(pUndo); 2535 } 2536 2537 rFmt.SetFmtAttr(rSet); 2538 } 2539 2540 void SwDoc::RenameFmt(SwFmt & rFmt, const String & sNewName, 2541 sal_Bool bBroadcast) 2542 { 2543 SfxStyleFamily eFamily = SFX_STYLE_FAMILY_ALL; 2544 2545 if (GetIDocumentUndoRedo().DoesUndo()) 2546 { 2547 SwUndo * pUndo = NULL; 2548 2549 switch (rFmt.Which()) 2550 { 2551 case RES_CHRFMT: 2552 pUndo = new SwUndoRenameCharFmt(rFmt.GetName(), sNewName, this); 2553 eFamily = SFX_STYLE_FAMILY_PARA; 2554 break; 2555 case RES_TXTFMTCOLL: 2556 pUndo = new SwUndoRenameFmtColl(rFmt.GetName(), sNewName, this); 2557 eFamily = SFX_STYLE_FAMILY_CHAR; 2558 break; 2559 case RES_FRMFMT: 2560 pUndo = new SwUndoRenameFrmFmt(rFmt.GetName(), sNewName, this); 2561 eFamily = SFX_STYLE_FAMILY_FRAME; 2562 break; 2563 2564 default: 2565 break; 2566 } 2567 2568 if (pUndo) 2569 { 2570 GetIDocumentUndoRedo().AppendUndo(pUndo); 2571 } 2572 } 2573 2574 rFmt.SetName(sNewName); 2575 2576 if (bBroadcast) 2577 BroadcastStyleOperation(sNewName, eFamily, SFX_STYLESHEET_MODIFIED); 2578 } 2579 2580 // --> OD 2006-09-27 #i69627# 2581 namespace docfunc 2582 { 2583 bool HasOutlineStyleToBeWrittenAsNormalListStyle( SwDoc& rDoc ) 2584 { 2585 // If a parent paragraph style of one of the parargraph styles, which 2586 // are assigned to the list levels of the outline style, has a list style 2587 // set or inherits a list style from its parent style, the outline style 2588 // has to be written as a normal list style to the OpenDocument file 2589 // format or the OpenOffice.org file format. 2590 bool bRet( false ); 2591 2592 const SwTxtFmtColls* pTxtFmtColls( rDoc.GetTxtFmtColls() ); 2593 if ( pTxtFmtColls ) 2594 { 2595 const sal_uInt16 nCount = pTxtFmtColls->Count(); 2596 for ( sal_uInt16 i = 0; i < nCount; ++i ) 2597 { 2598 SwTxtFmtColl* pTxtFmtColl = (*pTxtFmtColls)[i]; 2599 2600 if ( pTxtFmtColl->IsDefault() || 2601 // pTxtFmtColl->GetOutlineLevel() == NO_NUMBERING ) //#outline level,zhaojianwei 2602 ! pTxtFmtColl->IsAssignedToListLevelOfOutlineStyle() ) //<-end,zhaojianwei 2603 { 2604 continue; 2605 } 2606 2607 const SwTxtFmtColl* pParentTxtFmtColl = 2608 dynamic_cast<const SwTxtFmtColl*>( pTxtFmtColl->DerivedFrom()); 2609 if ( !pParentTxtFmtColl ) 2610 continue; 2611 2612 if ( SFX_ITEM_SET == pParentTxtFmtColl->GetItemState( RES_PARATR_NUMRULE ) ) 2613 { 2614 // --> OD 2009-11-12 #i106218# 2615 // consider that the outline style is set 2616 const SwNumRuleItem& rDirectItem = pParentTxtFmtColl->GetNumRule(); 2617 if ( rDirectItem.GetValue() != rDoc.GetOutlineNumRule()->GetName() ) 2618 { 2619 bRet = true; 2620 break; 2621 } 2622 // <-- 2623 } 2624 } 2625 2626 } 2627 return bRet; 2628 } 2629 } 2630 // <-- 2631