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