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