File: | home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx |
Warning: | line 697, column 13 Forming reference to null pointer |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 <libxml/xmlwriter.h> | |||
21 | #include <hintids.hxx> | |||
22 | #include <svl/itemiter.hxx> | |||
23 | #include <editeng/tstpitem.hxx> | |||
24 | #include <editeng/lrspitem.hxx> | |||
25 | #include <editeng/formatbreakitem.hxx> | |||
26 | #include <editeng/rsiditem.hxx> | |||
27 | #include <editeng/colritem.hxx> | |||
28 | #include <officecfg/Office/Common.hxx> | |||
29 | #include <svl/zforlist.hxx> | |||
30 | #include <comphelper/doublecheckedinit.hxx> | |||
31 | #include <comphelper/processfactory.hxx> | |||
32 | #include <unotools/configmgr.hxx> | |||
33 | #include <sal/log.hxx> | |||
34 | #include <com/sun/star/i18n/WordType.hpp> | |||
35 | #include <com/sun/star/i18n/XBreakIterator.hpp> | |||
36 | #include <fmtpdsc.hxx> | |||
37 | #include <fmthdft.hxx> | |||
38 | #include <fmtcntnt.hxx> | |||
39 | #include <doc.hxx> | |||
40 | #include <docfunc.hxx> | |||
41 | #include <drawdoc.hxx> | |||
42 | #include <MarkManager.hxx> | |||
43 | #include <IDocumentDrawModelAccess.hxx> | |||
44 | #include <IDocumentUndoRedo.hxx> | |||
45 | #include <DocumentContentOperationsManager.hxx> | |||
46 | #include <DocumentSettingManager.hxx> | |||
47 | #include <IDocumentFieldsAccess.hxx> | |||
48 | #include <IDocumentState.hxx> | |||
49 | #include <IDocumentLayoutAccess.hxx> | |||
50 | #include <IDocumentStylePoolAccess.hxx> | |||
51 | #include <rootfrm.hxx> | |||
52 | #include <txtfrm.hxx> | |||
53 | #include <hints.hxx> | |||
54 | #include <ndtxt.hxx> | |||
55 | #include <pam.hxx> | |||
56 | #include <UndoCore.hxx> | |||
57 | #include <UndoAttribute.hxx> | |||
58 | #include <UndoInsert.hxx> | |||
59 | #include <pagedesc.hxx> | |||
60 | #include <rolbck.hxx> | |||
61 | #include <mvsave.hxx> | |||
62 | #include <txatbase.hxx> | |||
63 | #include <swtblfmt.hxx> | |||
64 | #include <charfmt.hxx> | |||
65 | #include <docary.hxx> | |||
66 | #include <paratr.hxx> | |||
67 | #include <redline.hxx> | |||
68 | #include <reffld.hxx> | |||
69 | #include <fmtinfmt.hxx> | |||
70 | #include <breakit.hxx> | |||
71 | #include <SwUndoFmt.hxx> | |||
72 | #include <UndoManager.hxx> | |||
73 | #include <swmodule.hxx> | |||
74 | #include <modcfg.hxx> | |||
75 | #include <frameformats.hxx> | |||
76 | #include <memory> | |||
77 | ||||
78 | using namespace ::com::sun::star::i18n; | |||
79 | using namespace ::com::sun::star::lang; | |||
80 | using namespace ::com::sun::star::uno; | |||
81 | ||||
82 | /* | |||
83 | * Internal functions | |||
84 | */ | |||
85 | ||||
86 | static void SetTextFormatCollNext( SwTextFormatColl* pTextColl, const SwTextFormatColl* pDel ) | |||
87 | { | |||
88 | if ( &pTextColl->GetNextTextFormatColl() == pDel ) | |||
89 | { | |||
90 | pTextColl->SetNextTextFormatColl( *pTextColl ); | |||
91 | } | |||
92 | } | |||
93 | ||||
94 | static bool lcl_RstAttr( const SwNodePtr& rpNd, void* pArgs ) | |||
95 | { | |||
96 | const sw::DocumentContentOperationsManager::ParaRstFormat* pPara = static_cast<sw::DocumentContentOperationsManager::ParaRstFormat*>(pArgs); | |||
97 | SwContentNode* pNode = rpNd->GetContentNode(); | |||
98 | if (pPara && pPara->pLayout && pPara->pLayout->IsHideRedlines() | |||
99 | && pNode && pNode->GetRedlineMergeFlag() == SwNode::Merge::Hidden) | |||
100 | { | |||
101 | return true; | |||
102 | } | |||
103 | if( pNode && pNode->HasSwAttrSet() ) | |||
104 | { | |||
105 | const bool bLocked = pNode->IsModifyLocked(); | |||
106 | pNode->LockModify(); | |||
107 | ||||
108 | SwDoc& rDoc = pNode->GetDoc(); | |||
109 | ||||
110 | // remove unused attribute RES_LR_SPACE | |||
111 | // add list attributes | |||
112 | SfxItemSet aSavedAttrsSet( | |||
113 | rDoc.GetAttrPool(), | |||
114 | svl::Items< | |||
115 | RES_PARATR_NUMRULE, RES_PARATR_NUMRULE, | |||
116 | RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END - 1, | |||
117 | RES_PAGEDESC, RES_BREAK>{}); | |||
118 | const SfxItemSet* pAttrSetOfNode = pNode->GetpSwAttrSet(); | |||
119 | ||||
120 | std::vector<sal_uInt16> aClearWhichIds; | |||
121 | // restoring all paragraph list attributes | |||
122 | { | |||
123 | SfxItemSet aListAttrSet( rDoc.GetAttrPool(), svl::Items<RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END - 1>{} ); | |||
124 | aListAttrSet.Set(*pAttrSetOfNode); | |||
125 | if ( aListAttrSet.Count() ) | |||
126 | { | |||
127 | aSavedAttrsSet.Put(aListAttrSet); | |||
128 | SfxItemIter aIter( aListAttrSet ); | |||
129 | const SfxPoolItem* pItem = aIter.GetCurItem(); | |||
130 | while( pItem ) | |||
131 | { | |||
132 | aClearWhichIds.push_back( pItem->Which() ); | |||
133 | pItem = aIter.NextItem(); | |||
134 | } | |||
135 | } | |||
136 | } | |||
137 | ||||
138 | const SfxPoolItem* pItem; | |||
139 | ||||
140 | sal_uInt16 const aSavIds[3] = { RES_PAGEDESC, RES_BREAK, RES_PARATR_NUMRULE }; | |||
141 | for (sal_uInt16 aSavId : aSavIds) | |||
142 | { | |||
143 | if (SfxItemState::SET == pAttrSetOfNode->GetItemState(aSavId, false, &pItem)) | |||
144 | { | |||
145 | bool bSave = false; | |||
146 | switch( aSavId ) | |||
147 | { | |||
148 | case RES_PAGEDESC: | |||
149 | bSave = nullptr != static_cast<const SwFormatPageDesc*>(pItem)->GetPageDesc(); | |||
150 | break; | |||
151 | case RES_BREAK: | |||
152 | bSave = SvxBreak::NONE != static_cast<const SvxFormatBreakItem*>(pItem)->GetBreak(); | |||
153 | break; | |||
154 | case RES_PARATR_NUMRULE: | |||
155 | bSave = !static_cast<const SwNumRuleItem*>(pItem)->GetValue().isEmpty(); | |||
156 | break; | |||
157 | } | |||
158 | if( bSave ) | |||
159 | { | |||
160 | aSavedAttrsSet.Put(*pItem); | |||
161 | aClearWhichIds.push_back(aSavId); | |||
162 | } | |||
163 | } | |||
164 | } | |||
165 | ||||
166 | // do not clear items directly from item set and only clear to be kept | |||
167 | // attributes, if no deletion item set is found. | |||
168 | const bool bKeepAttributes = | |||
169 | !pPara || !pPara->pDelSet || pPara->pDelSet->Count() == 0; | |||
170 | if ( bKeepAttributes ) | |||
171 | { | |||
172 | pNode->ResetAttr( aClearWhichIds ); | |||
173 | } | |||
174 | ||||
175 | if( !bLocked ) | |||
176 | pNode->UnlockModify(); | |||
177 | ||||
178 | if( pPara ) | |||
179 | { | |||
180 | SwRegHistory aRegH( pNode, *pNode, pPara->pHistory ); | |||
181 | ||||
182 | if( pPara->pDelSet && pPara->pDelSet->Count() ) | |||
183 | { | |||
184 | OSL_ENSURE( !bKeepAttributes,do { if (true && (!(!bKeepAttributes))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "185" ": "), "%s", "<lcl_RstAttr(..)> - certain attributes are kept, but not needed." ); } } while (false) | |||
185 | "<lcl_RstAttr(..)> - certain attributes are kept, but not needed." )do { if (true && (!(!bKeepAttributes))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "185" ": "), "%s", "<lcl_RstAttr(..)> - certain attributes are kept, but not needed." ); } } while (false); | |||
186 | SfxItemIter aIter( *pPara->pDelSet ); | |||
187 | for (pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem()) | |||
188 | { | |||
189 | if ( ( pItem->Which() != RES_PAGEDESC && | |||
190 | pItem->Which() != RES_BREAK && | |||
191 | pItem->Which() != RES_PARATR_NUMRULE ) || | |||
192 | ( aSavedAttrsSet.GetItemState( pItem->Which(), false ) != SfxItemState::SET ) ) | |||
193 | { | |||
194 | pNode->ResetAttr( pItem->Which() ); | |||
195 | } | |||
196 | } | |||
197 | } | |||
198 | else if( pPara->bResetAll ) | |||
199 | pNode->ResetAllAttr(); | |||
200 | else | |||
201 | pNode->ResetAttr( RES_PARATR_BEGIN, POOLATTR_END - 1 ); | |||
202 | } | |||
203 | else | |||
204 | pNode->ResetAllAttr(); | |||
205 | ||||
206 | // only restore saved attributes, if needed | |||
207 | if (bKeepAttributes && aSavedAttrsSet.Count()) | |||
208 | { | |||
209 | pNode->LockModify(); | |||
210 | ||||
211 | pNode->SetAttr(aSavedAttrsSet); | |||
212 | ||||
213 | if( !bLocked ) | |||
214 | pNode->UnlockModify(); | |||
215 | } | |||
216 | } | |||
217 | return true; | |||
218 | } | |||
219 | ||||
220 | void SwDoc::RstTextAttrs(const SwPaM &rRg, bool bInclRefToxMark, | |||
221 | bool bExactRange, SwRootFrame const*const pLayout) | |||
222 | { | |||
223 | SwHistory* pHst = nullptr; | |||
224 | SwDataChanged aTmp( rRg ); | |||
225 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
226 | { | |||
227 | std::unique_ptr<SwUndoResetAttr> pUndo(new SwUndoResetAttr( rRg, RES_CHRFMT )); | |||
228 | pHst = &pUndo->GetHistory(); | |||
229 | GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); | |||
230 | } | |||
231 | const SwPosition *pStt = rRg.Start(), *pEnd = rRg.End(); | |||
232 | sw::DocumentContentOperationsManager::ParaRstFormat aPara( | |||
233 | pStt, pEnd, pHst, nullptr, pLayout ); | |||
234 | aPara.bInclRefToxMark = bInclRefToxMark; | |||
235 | aPara.bExactRange = bExactRange; | |||
236 | GetNodes().ForEach( pStt->nNode.GetIndex(), pEnd->nNode.GetIndex()+1, | |||
237 | sw::DocumentContentOperationsManager::lcl_RstTextAttr, &aPara ); | |||
238 | getIDocumentState().SetModified(); | |||
239 | } | |||
240 | ||||
241 | void SwDoc::ResetAttrs( const SwPaM &rRg, | |||
242 | bool bTextAttr, | |||
243 | const std::set<sal_uInt16> &rAttrs, | |||
244 | const bool bSendDataChangedEvents, | |||
245 | SwRootFrame const*const pLayout) | |||
246 | { | |||
247 | SwPaM* pPam = const_cast<SwPaM*>(&rRg); | |||
248 | if( !bTextAttr && !rAttrs.empty() && RES_TXTATR_END > *(rAttrs.begin()) ) | |||
249 | bTextAttr = true; | |||
250 | ||||
251 | if( !rRg.HasMark() ) | |||
252 | { | |||
253 | SwTextNode* pTextNd = rRg.GetPoint()->nNode.GetNode().GetTextNode(); | |||
254 | if( !pTextNd ) | |||
255 | return ; | |||
256 | ||||
257 | pPam = new SwPaM( *rRg.GetPoint() ); | |||
258 | ||||
259 | SwIndex& rSt = pPam->GetPoint()->nContent; | |||
260 | sal_Int32 nMkPos, nPtPos = rSt.GetIndex(); | |||
261 | ||||
262 | // Special case: if the Cursor is located within a URL attribute, we take over it's area | |||
263 | SwTextAttr const*const pURLAttr( | |||
264 | pTextNd->GetTextAttrAt(rSt.GetIndex(), RES_TXTATR_INETFMT)); | |||
265 | if (pURLAttr && !pURLAttr->GetINetFormat().GetValue().isEmpty()) | |||
266 | { | |||
267 | nMkPos = pURLAttr->GetStart(); | |||
268 | nPtPos = *pURLAttr->End(); | |||
269 | } | |||
270 | else | |||
271 | { | |||
272 | assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is())(static_cast <bool> (g_pBreakIt && g_pBreakIt-> GetBreakIter().is()) ? void (0) : __assert_fail ("g_pBreakIt && g_pBreakIt->GetBreakIter().is()" , "/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" , 272, __extension__ __PRETTY_FUNCTION__)); | |||
273 | Boundary aBndry = g_pBreakIt->GetBreakIter()->getWordBoundary( | |||
274 | pTextNd->GetText(), nPtPos, | |||
275 | g_pBreakIt->GetLocale( pTextNd->GetLang( nPtPos ) ), | |||
276 | WordType::ANY_WORD /*ANYWORD_IGNOREWHITESPACES*/, | |||
277 | true); | |||
278 | ||||
279 | if( aBndry.startPos < nPtPos && nPtPos < aBndry.endPos ) | |||
280 | { | |||
281 | nMkPos = aBndry.startPos; | |||
282 | nPtPos = aBndry.endPos; | |||
283 | } | |||
284 | else | |||
285 | { | |||
286 | nPtPos = nMkPos = rSt.GetIndex(); | |||
287 | if( bTextAttr ) | |||
288 | pTextNd->DontExpandFormat( rSt ); | |||
289 | } | |||
290 | } | |||
291 | ||||
292 | rSt = nMkPos; | |||
293 | pPam->SetMark(); | |||
294 | pPam->GetPoint()->nContent = nPtPos; | |||
295 | } | |||
296 | ||||
297 | // #i96644# | |||
298 | std::unique_ptr< SwDataChanged > xDataChanged; | |||
299 | if ( bSendDataChangedEvents ) | |||
300 | { | |||
301 | xDataChanged.reset( new SwDataChanged( *pPam ) ); | |||
302 | } | |||
303 | SwHistory* pHst = nullptr; | |||
304 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
305 | { | |||
306 | std::unique_ptr<SwUndoResetAttr> pUndo(new SwUndoResetAttr( rRg, | |||
307 | bTextAttr ? sal_uInt16(RES_CONDTXTFMTCOLL) : sal_uInt16(RES_TXTFMTCOLL) )); | |||
308 | if( !rAttrs.empty() ) | |||
309 | { | |||
310 | pUndo->SetAttrs( rAttrs ); | |||
311 | } | |||
312 | pHst = &pUndo->GetHistory(); | |||
313 | GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); | |||
314 | } | |||
315 | ||||
316 | const SwPosition *pStt = pPam->Start(), *pEnd = pPam->End(); | |||
317 | sw::DocumentContentOperationsManager::ParaRstFormat aPara( | |||
318 | pStt, pEnd, pHst, nullptr, pLayout); | |||
319 | ||||
320 | // mst: not including META here; it seems attrs with CH_TXTATR are omitted | |||
321 | SfxItemSet aDelSet(GetAttrPool(), svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_END - 1, | |||
322 | RES_TXTATR_INETFMT, RES_TXTATR_UNKNOWN_CONTAINER, | |||
323 | RES_PARATR_BEGIN, RES_FRMATR_END - 1, | |||
324 | RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END - 1>{}); | |||
325 | for( std::set<sal_uInt16>::const_reverse_iterator it = rAttrs.rbegin(); it != rAttrs.rend(); ++it ) | |||
326 | { | |||
327 | if( POOLATTR_END > *it ) | |||
328 | aDelSet.Put( *GetDfltAttr( *it )); | |||
329 | } | |||
330 | if( aDelSet.Count() ) | |||
331 | aPara.pDelSet = &aDelSet; | |||
332 | ||||
333 | bool bAdd = true; | |||
334 | SwNodeIndex aTmpStt( pStt->nNode ); | |||
335 | SwNodeIndex aTmpEnd( pEnd->nNode ); | |||
336 | if( pStt->nContent.GetIndex() ) // just one part | |||
337 | { | |||
338 | // set up a later, and all CharFormatAttr -> TextFormatAttr | |||
339 | SwTextNode* pTNd = aTmpStt.GetNode().GetTextNode(); | |||
340 | if( pTNd && pTNd->HasSwAttrSet() && pTNd->GetpSwAttrSet()->Count() ) | |||
341 | { | |||
342 | if (pHst) | |||
343 | { | |||
344 | SwRegHistory history(pTNd, *pTNd, pHst); | |||
345 | pTNd->FormatToTextAttr(pTNd); | |||
346 | } | |||
347 | else | |||
348 | { | |||
349 | pTNd->FormatToTextAttr(pTNd); | |||
350 | } | |||
351 | } | |||
352 | ||||
353 | ++aTmpStt; | |||
354 | } | |||
355 | if( pEnd->nContent.GetIndex() == pEnd->nNode.GetNode().GetContentNode()->Len() ) | |||
356 | { | |||
357 | // set up a later, and all CharFormatAttr -> TextFormatAttr | |||
358 | ++aTmpEnd; | |||
359 | bAdd = false; | |||
360 | } | |||
361 | else if( pStt->nNode != pEnd->nNode || !pStt->nContent.GetIndex() ) | |||
362 | { | |||
363 | SwTextNode* pTNd = aTmpEnd.GetNode().GetTextNode(); | |||
364 | if( pTNd && pTNd->HasSwAttrSet() && pTNd->GetpSwAttrSet()->Count() ) | |||
365 | { | |||
366 | if (pHst) | |||
367 | { | |||
368 | SwRegHistory history(pTNd, *pTNd, pHst); | |||
369 | pTNd->FormatToTextAttr(pTNd); | |||
370 | } | |||
371 | else | |||
372 | { | |||
373 | pTNd->FormatToTextAttr(pTNd); | |||
374 | } | |||
375 | } | |||
376 | } | |||
377 | ||||
378 | if( aTmpStt < aTmpEnd ) | |||
379 | GetNodes().ForEach( pStt->nNode, aTmpEnd, lcl_RstAttr, &aPara ); | |||
380 | else if( !rRg.HasMark() ) | |||
381 | { | |||
382 | aPara.bResetAll = false ; | |||
383 | ::lcl_RstAttr( &pStt->nNode.GetNode(), &aPara ); | |||
384 | aPara.bResetAll = true ; | |||
385 | } | |||
386 | ||||
387 | if( bTextAttr ) | |||
388 | { | |||
389 | if( bAdd ) | |||
390 | ++aTmpEnd; | |||
391 | GetNodes().ForEach( pStt->nNode, aTmpEnd, sw::DocumentContentOperationsManager::lcl_RstTextAttr, &aPara ); | |||
392 | } | |||
393 | ||||
394 | getIDocumentState().SetModified(); | |||
395 | ||||
396 | xDataChanged.reset(); //before delete pPam | |||
397 | ||||
398 | if( pPam != &rRg ) | |||
399 | delete pPam; | |||
400 | } | |||
401 | ||||
402 | /// Set the rsid of the next nLen symbols of rRg to the current session number | |||
403 | void SwDoc::UpdateRsid( const SwPaM &rRg, const sal_Int32 nLen ) | |||
404 | { | |||
405 | if (!SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->GetModuleConfig()->IsStoreRsid()) | |||
406 | return; | |||
407 | ||||
408 | SwTextNode *pTextNode = rRg.GetPoint()->nNode.GetNode().GetTextNode(); | |||
409 | if (!pTextNode) | |||
410 | { | |||
411 | return; | |||
412 | } | |||
413 | const sal_Int32 nStart(rRg.GetPoint()->nContent.GetIndex() - nLen); | |||
414 | SvxRsidItem aRsid( mnRsid, RES_CHRATR_RSID ); | |||
415 | ||||
416 | SfxItemSet aSet(GetAttrPool(), svl::Items<RES_CHRATR_RSID, RES_CHRATR_RSID>{}); | |||
417 | aSet.Put(aRsid); | |||
418 | bool const bRet(pTextNode->SetAttr(aSet, nStart, | |||
419 | rRg.GetPoint()->nContent.GetIndex())); | |||
420 | ||||
421 | if (bRet && GetIDocumentUndoRedo().DoesUndo()) | |||
422 | { | |||
423 | SwUndo *const pLastUndo = GetUndoManager().GetLastUndo(); | |||
424 | SwUndoInsert *const pUndoInsert(dynamic_cast<SwUndoInsert*>(pLastUndo)); | |||
425 | // this function is called after Insert so expects to find SwUndoInsert | |||
426 | assert(pUndoInsert)(static_cast <bool> (pUndoInsert) ? void (0) : __assert_fail ("pUndoInsert", "/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" , 426, __extension__ __PRETTY_FUNCTION__)); | |||
427 | if (pUndoInsert) | |||
428 | { | |||
429 | pUndoInsert->SetWithRsid(); | |||
430 | } | |||
431 | } | |||
432 | } | |||
433 | ||||
434 | bool SwDoc::UpdateParRsid( SwTextNode *pTextNode, sal_uInt32 nVal ) | |||
435 | { | |||
436 | if (!SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->GetModuleConfig()->IsStoreRsid()) | |||
437 | return false; | |||
438 | ||||
439 | if (!pTextNode) | |||
440 | { | |||
441 | return false; | |||
442 | } | |||
443 | ||||
444 | SvxRsidItem aRsid( nVal ? nVal : mnRsid, RES_PARATR_RSID ); | |||
445 | return pTextNode->SetAttr( aRsid ); | |||
446 | } | |||
447 | ||||
448 | /// Set the attribute according to the stated format. | |||
449 | /// If Undo is enabled, the old values is added to the Undo history. | |||
450 | void SwDoc::SetAttr( const SfxPoolItem& rAttr, SwFormat& rFormat ) | |||
451 | { | |||
452 | SfxItemSet aSet( GetAttrPool(), {{rAttr.Which(), rAttr.Which()}} ); | |||
453 | aSet.Put( rAttr ); | |||
454 | SetAttr( aSet, rFormat ); | |||
455 | } | |||
456 | ||||
457 | /// Set the attribute according to the stated format. | |||
458 | /// If Undo is enabled, the old values is added to the Undo history. | |||
459 | void SwDoc::SetAttr( const SfxItemSet& rSet, SwFormat& rFormat ) | |||
460 | { | |||
461 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
462 | { | |||
463 | SwUndoFormatAttrHelper aTmp( rFormat ); | |||
464 | rFormat.SetFormatAttr( rSet ); | |||
465 | if ( aTmp.GetUndo() ) | |||
466 | { | |||
467 | GetIDocumentUndoRedo().AppendUndo( aTmp.ReleaseUndo() ); | |||
468 | } | |||
469 | else | |||
470 | { | |||
471 | GetIDocumentUndoRedo().ClearRedo(); | |||
472 | } | |||
473 | } | |||
474 | else | |||
475 | { | |||
476 | rFormat.SetFormatAttr( rSet ); | |||
477 | } | |||
478 | getIDocumentState().SetModified(); | |||
479 | } | |||
480 | ||||
481 | void SwDoc::ResetAttrAtFormat( const sal_uInt16 nWhichId, | |||
482 | SwFormat& rChangedFormat ) | |||
483 | { | |||
484 | std::unique_ptr<SwUndo> pUndo; | |||
485 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
486 | pUndo.reset(new SwUndoFormatResetAttr( rChangedFormat, nWhichId )); | |||
487 | ||||
488 | const bool bAttrReset = rChangedFormat.ResetFormatAttr( nWhichId ); | |||
489 | ||||
490 | if ( bAttrReset ) | |||
491 | { | |||
492 | if ( pUndo ) | |||
493 | { | |||
494 | GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); | |||
495 | } | |||
496 | ||||
497 | getIDocumentState().SetModified(); | |||
498 | } | |||
499 | } | |||
500 | ||||
501 | static bool lcl_SetNewDefTabStops( SwTwips nOldWidth, SwTwips nNewWidth, | |||
502 | SvxTabStopItem& rChgTabStop ) | |||
503 | { | |||
504 | // Set the default values of all TabStops to the new value. | |||
505 | // Attention: we always work with the PoolAttribute here, so that | |||
506 | // we don't calculate the same value on the same TabStop (pooled!) for all sets. | |||
507 | // We send a FormatChg to modify. | |||
508 | ||||
509 | sal_uInt16 nOldCnt = rChgTabStop.Count(); | |||
510 | if( !nOldCnt || nOldWidth == nNewWidth ) | |||
511 | return false; | |||
512 | ||||
513 | // Find the default's beginning | |||
514 | sal_uInt16 n; | |||
515 | for( n = nOldCnt; n ; --n ) | |||
516 | if( SvxTabAdjust::Default != rChgTabStop[n - 1].GetAdjustment() ) | |||
517 | break; | |||
518 | ++n; | |||
519 | if( n < nOldCnt ) // delete the DefTabStops | |||
520 | rChgTabStop.Remove( n, nOldCnt - n ); | |||
521 | return true; | |||
522 | } | |||
523 | ||||
524 | /// Set the attribute as new default attribute in this document. | |||
525 | /// If Undo is enabled, the old value is added to the Undo history. | |||
526 | void SwDoc::SetDefault( const SfxPoolItem& rAttr ) | |||
527 | { | |||
528 | SfxItemSet aSet( GetAttrPool(), {{rAttr.Which(), rAttr.Which()}} ); | |||
529 | aSet.Put( rAttr ); | |||
530 | SetDefault( aSet ); | |||
531 | } | |||
532 | ||||
533 | void SwDoc::SetDefault( const SfxItemSet& rSet ) | |||
534 | { | |||
535 | if( !rSet.Count() ) | |||
536 | return; | |||
537 | ||||
538 | SwModify aCallMod; | |||
539 | SwAttrSet aOld( GetAttrPool(), rSet.GetRanges() ), | |||
540 | aNew( GetAttrPool(), rSet.GetRanges() ); | |||
541 | SfxItemIter aIter( rSet ); | |||
542 | const SfxPoolItem* pItem = aIter.GetCurItem(); | |||
543 | SfxItemPool* pSdrPool = GetAttrPool().GetSecondaryPool(); | |||
544 | do | |||
545 | { | |||
546 | bool bCheckSdrDflt = false; | |||
547 | const sal_uInt16 nWhich = pItem->Which(); | |||
548 | aOld.Put( GetAttrPool().GetDefaultItem( nWhich ) ); | |||
549 | GetAttrPool().SetPoolDefaultItem( *pItem ); | |||
550 | aNew.Put( GetAttrPool().GetDefaultItem( nWhich ) ); | |||
551 | ||||
552 | if (isCHRATR(nWhich) || isTXTATR(nWhich)) | |||
553 | { | |||
554 | aCallMod.Add( mpDfltTextFormatColl.get() ); | |||
555 | aCallMod.Add( mpDfltCharFormat.get() ); | |||
556 | bCheckSdrDflt = nullptr != pSdrPool; | |||
557 | } | |||
558 | else if ( isPARATR(nWhich) || | |||
559 | isPARATR_LIST(nWhich) ) | |||
560 | { | |||
561 | aCallMod.Add( mpDfltTextFormatColl.get() ); | |||
562 | bCheckSdrDflt = nullptr != pSdrPool; | |||
563 | } | |||
564 | else if (isGRFATR(nWhich)) | |||
565 | { | |||
566 | aCallMod.Add( mpDfltGrfFormatColl.get() ); | |||
567 | } | |||
568 | else if (isFRMATR(nWhich) || isDrawingLayerAttribute(nWhich) ) | |||
569 | { | |||
570 | aCallMod.Add( mpDfltGrfFormatColl.get() ); | |||
571 | aCallMod.Add( mpDfltTextFormatColl.get() ); | |||
572 | aCallMod.Add( mpDfltFrameFormat.get() ); | |||
573 | } | |||
574 | else if (isBOXATR(nWhich)) | |||
575 | { | |||
576 | aCallMod.Add( mpDfltFrameFormat.get() ); | |||
577 | } | |||
578 | ||||
579 | // also copy the defaults | |||
580 | if( bCheckSdrDflt ) | |||
581 | { | |||
582 | sal_uInt16 nSlotId = GetAttrPool().GetSlotId( nWhich ); | |||
583 | if( 0 != nSlotId && nSlotId != nWhich ) | |||
584 | { | |||
585 | sal_uInt16 nEdtWhich = pSdrPool->GetWhich( nSlotId ); | |||
586 | if( 0 != nEdtWhich && nSlotId != nEdtWhich ) | |||
587 | { | |||
588 | std::unique_ptr<SfxPoolItem> pCpy(pItem->Clone()); | |||
589 | pCpy->SetWhich( nEdtWhich ); | |||
590 | pSdrPool->SetPoolDefaultItem( *pCpy ); | |||
591 | } | |||
592 | } | |||
593 | } | |||
594 | ||||
595 | pItem = aIter.NextItem(); | |||
596 | } while (pItem); | |||
597 | ||||
598 | if( aNew.Count() && aCallMod.HasWriterListeners() ) | |||
599 | { | |||
600 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
601 | { | |||
602 | GetIDocumentUndoRedo().AppendUndo( std::make_unique<SwUndoDefaultAttr>( aOld, *this ) ); | |||
603 | } | |||
604 | ||||
605 | const SfxPoolItem* pTmpItem; | |||
606 | if( ( SfxItemState::SET == | |||
607 | aNew.GetItemState( RES_PARATR_TABSTOP, false, &pTmpItem ) ) && | |||
608 | static_cast<const SvxTabStopItem*>(pTmpItem)->Count() ) | |||
609 | { | |||
610 | // Set the default values of all TabStops to the new value. | |||
611 | // Attention: we always work with the PoolAttribute here, so that | |||
612 | // we don't calculate the same value on the same TabStop (pooled!) for all sets. | |||
613 | // We send a FormatChg to modify. | |||
614 | SwTwips nNewWidth = (*static_cast<const SvxTabStopItem*>(pTmpItem))[ 0 ].GetTabPos(), | |||
615 | nOldWidth = aOld.Get(RES_PARATR_TABSTOP)[ 0 ].GetTabPos(); | |||
616 | ||||
617 | bool bChg = false; | |||
618 | for (const SfxPoolItem* pItem2 : GetAttrPool().GetItemSurrogates(RES_PARATR_TABSTOP)) | |||
619 | { | |||
620 | auto pTabStopItem = dynamic_cast<const SvxTabStopItem*>(pItem2); | |||
621 | if(pTabStopItem) | |||
622 | bChg |= lcl_SetNewDefTabStops( nOldWidth, nNewWidth, | |||
623 | *const_cast<SvxTabStopItem*>(pTabStopItem) ); | |||
624 | } | |||
625 | ||||
626 | aNew.ClearItem( RES_PARATR_TABSTOP ); | |||
627 | aOld.ClearItem( RES_PARATR_TABSTOP ); | |||
628 | if( bChg ) | |||
629 | { | |||
630 | SwFormatChg aChgFormat( mpDfltCharFormat.get() ); | |||
631 | // notify the frames | |||
632 | aCallMod.ModifyNotification( &aChgFormat, &aChgFormat ); | |||
633 | } | |||
634 | } | |||
635 | } | |||
636 | ||||
637 | if( aNew.Count() && aCallMod.HasWriterListeners() ) | |||
638 | { | |||
639 | SwAttrSetChg aChgOld( aOld, aOld ); | |||
640 | SwAttrSetChg aChgNew( aNew, aNew ); | |||
641 | aCallMod.ModifyNotification( &aChgOld, &aChgNew ); // all changed are sent | |||
642 | } | |||
643 | ||||
644 | // remove the default formats from the object again | |||
645 | SwIterator<SwClient, SwModify> aClientIter(aCallMod); | |||
646 | for(SwClient* pClient = aClientIter.First(); pClient; pClient = aClientIter.Next()) | |||
647 | aCallMod.Remove( pClient ); | |||
648 | ||||
649 | getIDocumentState().SetModified(); | |||
650 | } | |||
651 | ||||
652 | /// Get the default attribute in this document | |||
653 | const SfxPoolItem& SwDoc::GetDefault( sal_uInt16 nFormatHint ) const | |||
654 | { | |||
655 | return GetAttrPool().GetDefaultItem( nFormatHint ); | |||
656 | } | |||
657 | ||||
658 | /// Delete the formats | |||
659 | void SwDoc::DelCharFormat(size_t nFormat, bool bBroadcast) | |||
660 | { | |||
661 | SwCharFormat * pDel = (*mpCharFormatTable)[nFormat]; | |||
662 | ||||
663 | if (bBroadcast) | |||
664 | BroadcastStyleOperation(pDel->GetName(), SfxStyleFamily::Char, | |||
665 | SfxHintId::StyleSheetErased); | |||
666 | ||||
667 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
668 | { | |||
669 | GetIDocumentUndoRedo().AppendUndo( | |||
670 | std::make_unique<SwUndoCharFormatDelete>(pDel, *this)); | |||
671 | } | |||
672 | ||||
673 | delete (*mpCharFormatTable)[nFormat]; | |||
674 | mpCharFormatTable->erase(mpCharFormatTable->begin() + nFormat); | |||
675 | ||||
676 | getIDocumentState().SetModified(); | |||
677 | } | |||
678 | ||||
679 | void SwDoc::DelCharFormat( SwCharFormat const *pFormat, bool bBroadcast ) | |||
680 | { | |||
681 | size_t nFormat = mpCharFormatTable->GetPos( pFormat ); | |||
682 | OSL_ENSURE( SIZE_MAX != nFormat, "Format not found," )do { if (true && (!((18446744073709551615UL) != nFormat ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "682" ": "), "%s", "Format not found,"); } } while (false ); | |||
683 | DelCharFormat( nFormat, bBroadcast ); | |||
684 | } | |||
685 | ||||
686 | void SwDoc::DelFrameFormat( SwFrameFormat *pFormat, bool bBroadcast ) | |||
687 | { | |||
688 | if( dynamic_cast<const SwTableBoxFormat*>( pFormat) != nullptr || dynamic_cast<const SwTableLineFormat*>( pFormat) != nullptr ) | |||
| ||||
689 | { | |||
690 | OSL_ENSURE( false, "Format is not in the DocArray any more, "do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "691" ": "), "%s", "Format is not in the DocArray any more, " "so it can be deleted with delete"); } } while (false) | |||
691 | "so it can be deleted with delete" )do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "691" ": "), "%s", "Format is not in the DocArray any more, " "so it can be deleted with delete"); } } while (false); | |||
692 | delete pFormat; | |||
693 | } | |||
694 | else | |||
695 | { | |||
696 | // The format has to be in the one or the other, we'll see in which one. | |||
697 | if (mpFrameFormatTable->ContainsFormat(*pFormat)) | |||
| ||||
698 | { | |||
699 | if (bBroadcast) | |||
700 | BroadcastStyleOperation(pFormat->GetName(), | |||
701 | SfxStyleFamily::Frame, | |||
702 | SfxHintId::StyleSheetErased); | |||
703 | ||||
704 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
705 | { | |||
706 | GetIDocumentUndoRedo().AppendUndo( | |||
707 | std::make_unique<SwUndoFrameFormatDelete>(pFormat, *this)); | |||
708 | } | |||
709 | ||||
710 | mpFrameFormatTable->erase( pFormat ); | |||
711 | delete pFormat; | |||
712 | } | |||
713 | else | |||
714 | { | |||
715 | bool contains = GetSpzFrameFormats()->ContainsFormat(*pFormat); | |||
716 | OSL_ENSURE( contains, "FrameFormat not found." )do { if (true && (!(contains))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "716" ": "), "%s", "FrameFormat not found."); } } while ( false); | |||
717 | if( contains ) | |||
718 | { | |||
719 | GetSpzFrameFormats()->erase( pFormat ); | |||
720 | delete pFormat; | |||
721 | } | |||
722 | } | |||
723 | } | |||
724 | } | |||
725 | ||||
726 | void SwDoc::DelTableFrameFormat( SwTableFormat *pFormat ) | |||
727 | { | |||
728 | SwFrameFormats::const_iterator it = mpTableFrameFormatTable->find( pFormat ); | |||
729 | OSL_ENSURE( it != mpTableFrameFormatTable->end(), "Format not found," )do { if (true && (!(it != mpTableFrameFormatTable-> end()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ( "legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "729" ": "), "%s", "Format not found,"); } } while (false ); | |||
730 | mpTableFrameFormatTable->erase( it ); | |||
731 | delete pFormat; | |||
732 | } | |||
733 | ||||
734 | SwFrameFormat* SwDoc::FindFrameFormatByName( const OUString& rName ) const | |||
735 | { | |||
736 | return static_cast<SwFrameFormat*>(FindFormatByName( static_cast<SwFormatsBase&>(*mpFrameFormatTable), rName )); | |||
737 | } | |||
738 | ||||
739 | /// Create the formats | |||
740 | SwFlyFrameFormat *SwDoc::MakeFlyFrameFormat( const OUString &rFormatName, | |||
741 | SwFrameFormat *pDerivedFrom ) | |||
742 | { | |||
743 | SwFlyFrameFormat *pFormat = new SwFlyFrameFormat( GetAttrPool(), rFormatName, pDerivedFrom ); | |||
744 | GetSpzFrameFormats()->push_back(pFormat); | |||
745 | getIDocumentState().SetModified(); | |||
746 | return pFormat; | |||
747 | } | |||
748 | ||||
749 | SwDrawFrameFormat *SwDoc::MakeDrawFrameFormat( const OUString &rFormatName, | |||
750 | SwFrameFormat *pDerivedFrom ) | |||
751 | { | |||
752 | SwDrawFrameFormat *pFormat = new SwDrawFrameFormat( GetAttrPool(), rFormatName, pDerivedFrom); | |||
753 | GetSpzFrameFormats()->push_back(pFormat); | |||
754 | getIDocumentState().SetModified(); | |||
755 | return pFormat; | |||
756 | } | |||
757 | ||||
758 | size_t SwDoc::GetTableFrameFormatCount(bool bUsed) const | |||
759 | { | |||
760 | if (!bUsed) | |||
761 | { | |||
762 | return mpTableFrameFormatTable->size(); | |||
763 | } | |||
764 | ||||
765 | SwAutoFormatGetDocNode aGetHt(&GetNodes()); | |||
766 | size_t nCount = 0; | |||
767 | for (SwFrameFormat* const & pFormat : *mpTableFrameFormatTable) | |||
768 | { | |||
769 | if (!pFormat->GetInfo(aGetHt)) | |||
770 | nCount++; | |||
771 | } | |||
772 | return nCount; | |||
773 | } | |||
774 | ||||
775 | SwFrameFormat& SwDoc::GetTableFrameFormat(size_t nFormat, bool bUsed) const | |||
776 | { | |||
777 | if (!bUsed) | |||
778 | { | |||
779 | return *((*mpTableFrameFormatTable)[nFormat]); | |||
780 | } | |||
781 | ||||
782 | SwAutoFormatGetDocNode aGetHt(&GetNodes()); | |||
783 | ||||
784 | size_t index = 0; | |||
785 | ||||
786 | for (SwFrameFormat* const & pFormat : *mpTableFrameFormatTable) | |||
787 | { | |||
788 | if (!pFormat->GetInfo(aGetHt)) | |||
789 | { | |||
790 | if (index == nFormat) | |||
791 | return *pFormat; | |||
792 | else | |||
793 | index++; | |||
794 | } | |||
795 | } | |||
796 | throw std::out_of_range("Format index out of range."); | |||
797 | } | |||
798 | ||||
799 | SwTableFormat* SwDoc::MakeTableFrameFormat( const OUString &rFormatName, | |||
800 | SwFrameFormat *pDerivedFrom ) | |||
801 | { | |||
802 | SwTableFormat* pFormat = new SwTableFormat( GetAttrPool(), rFormatName, pDerivedFrom ); | |||
803 | mpTableFrameFormatTable->push_back( pFormat ); | |||
804 | getIDocumentState().SetModified(); | |||
805 | ||||
806 | return pFormat; | |||
807 | } | |||
808 | ||||
809 | SwFrameFormat *SwDoc::MakeFrameFormat(const OUString &rFormatName, | |||
810 | SwFrameFormat *pDerivedFrom, | |||
811 | bool bBroadcast, bool bAuto) | |||
812 | { | |||
813 | SwFrameFormat *pFormat = new SwFrameFormat( GetAttrPool(), rFormatName, pDerivedFrom ); | |||
814 | ||||
815 | pFormat->SetAuto(bAuto); | |||
816 | mpFrameFormatTable->push_back( pFormat ); | |||
817 | getIDocumentState().SetModified(); | |||
818 | ||||
819 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
820 | { | |||
821 | GetIDocumentUndoRedo().AppendUndo( | |||
822 | std::make_unique<SwUndoFrameFormatCreate>(pFormat, pDerivedFrom, *this)); | |||
823 | } | |||
824 | ||||
825 | if (bBroadcast) | |||
826 | { | |||
827 | BroadcastStyleOperation(rFormatName, SfxStyleFamily::Frame, | |||
828 | SfxHintId::StyleSheetCreated); | |||
829 | } | |||
830 | ||||
831 | return pFormat; | |||
832 | } | |||
833 | ||||
834 | SwFormat *SwDoc::MakeFrameFormat_(const OUString &rFormatName, | |||
835 | SwFormat *pDerivedFrom, | |||
836 | bool bBroadcast, bool bAuto) | |||
837 | { | |||
838 | SwFrameFormat *pFrameFormat = dynamic_cast<SwFrameFormat*>(pDerivedFrom); | |||
839 | pFrameFormat = MakeFrameFormat( rFormatName, pFrameFormat, bBroadcast, bAuto ); | |||
840 | return dynamic_cast<SwFormat*>(pFrameFormat); | |||
841 | } | |||
842 | ||||
843 | SwCharFormat *SwDoc::MakeCharFormat( const OUString &rFormatName, | |||
844 | SwCharFormat *pDerivedFrom, | |||
845 | bool bBroadcast ) | |||
846 | { | |||
847 | SwCharFormat *pFormat = new SwCharFormat( GetAttrPool(), rFormatName, pDerivedFrom ); | |||
848 | mpCharFormatTable->push_back( pFormat ); | |||
849 | pFormat->SetAuto(false); | |||
850 | getIDocumentState().SetModified(); | |||
851 | ||||
852 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
853 | { | |||
854 | GetIDocumentUndoRedo().AppendUndo( | |||
855 | std::make_unique<SwUndoCharFormatCreate>(pFormat, pDerivedFrom, *this)); | |||
856 | } | |||
857 | ||||
858 | if (bBroadcast) | |||
859 | { | |||
860 | BroadcastStyleOperation(rFormatName, SfxStyleFamily::Char, | |||
861 | SfxHintId::StyleSheetCreated); | |||
862 | } | |||
863 | ||||
864 | return pFormat; | |||
865 | } | |||
866 | ||||
867 | SwFormat *SwDoc::MakeCharFormat_(const OUString &rFormatName, | |||
868 | SwFormat *pDerivedFrom, | |||
869 | bool bBroadcast, bool /*bAuto*/) | |||
870 | { | |||
871 | SwCharFormat *pCharFormat = dynamic_cast<SwCharFormat*>(pDerivedFrom); | |||
872 | pCharFormat = MakeCharFormat( rFormatName, pCharFormat, bBroadcast ); | |||
873 | return dynamic_cast<SwFormat*>(pCharFormat); | |||
874 | } | |||
875 | ||||
876 | /// Create the FormatCollections | |||
877 | SwTextFormatColl* SwDoc::MakeTextFormatColl( const OUString &rFormatName, | |||
878 | SwTextFormatColl *pDerivedFrom, | |||
879 | bool bBroadcast) | |||
880 | { | |||
881 | SwTextFormatColl *pFormatColl = new SwTextFormatColl( GetAttrPool(), rFormatName, | |||
882 | pDerivedFrom ); | |||
883 | mpTextFormatCollTable->push_back(pFormatColl); | |||
884 | pFormatColl->SetAuto(false); | |||
885 | getIDocumentState().SetModified(); | |||
886 | ||||
887 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
888 | { | |||
889 | GetIDocumentUndoRedo().AppendUndo( | |||
890 | std::make_unique<SwUndoTextFormatCollCreate>(pFormatColl, pDerivedFrom, | |||
891 | *this)); | |||
892 | } | |||
893 | ||||
894 | if (bBroadcast) | |||
895 | BroadcastStyleOperation(rFormatName, SfxStyleFamily::Para, | |||
896 | SfxHintId::StyleSheetCreated); | |||
897 | ||||
898 | return pFormatColl; | |||
899 | } | |||
900 | ||||
901 | SwFormat *SwDoc::MakeTextFormatColl_(const OUString &rFormatName, | |||
902 | SwFormat *pDerivedFrom, | |||
903 | bool bBroadcast, bool /*bAuto*/) | |||
904 | { | |||
905 | SwTextFormatColl *pTextFormatColl = dynamic_cast<SwTextFormatColl*>(pDerivedFrom); | |||
906 | pTextFormatColl = MakeTextFormatColl( rFormatName, pTextFormatColl, bBroadcast ); | |||
907 | return dynamic_cast<SwFormat*>(pTextFormatColl); | |||
908 | } | |||
909 | ||||
910 | //FEATURE::CONDCOLL | |||
911 | SwConditionTextFormatColl* SwDoc::MakeCondTextFormatColl( const OUString &rFormatName, | |||
912 | SwTextFormatColl *pDerivedFrom, | |||
913 | bool bBroadcast) | |||
914 | { | |||
915 | SwConditionTextFormatColl*pFormatColl = new SwConditionTextFormatColl( GetAttrPool(), | |||
916 | rFormatName, pDerivedFrom ); | |||
917 | mpTextFormatCollTable->push_back(pFormatColl); | |||
918 | pFormatColl->SetAuto(false); | |||
919 | getIDocumentState().SetModified(); | |||
920 | ||||
921 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
922 | { | |||
923 | GetIDocumentUndoRedo().AppendUndo( | |||
924 | std::make_unique<SwUndoCondTextFormatCollCreate>(pFormatColl, pDerivedFrom, | |||
925 | *this)); | |||
926 | } | |||
927 | ||||
928 | if (bBroadcast) | |||
929 | BroadcastStyleOperation(rFormatName, SfxStyleFamily::Para, | |||
930 | SfxHintId::StyleSheetCreated); | |||
931 | ||||
932 | return pFormatColl; | |||
933 | } | |||
934 | //FEATURE::CONDCOLL | |||
935 | ||||
936 | // GRF | |||
937 | SwGrfFormatColl* SwDoc::MakeGrfFormatColl( const OUString &rFormatName, | |||
938 | SwGrfFormatColl *pDerivedFrom ) | |||
939 | { | |||
940 | SwGrfFormatColl *pFormatColl = new SwGrfFormatColl( GetAttrPool(), rFormatName, | |||
941 | pDerivedFrom ); | |||
942 | mpGrfFormatCollTable->push_back( pFormatColl ); | |||
943 | pFormatColl->SetAuto(false); | |||
944 | getIDocumentState().SetModified(); | |||
945 | return pFormatColl; | |||
946 | } | |||
947 | ||||
948 | void SwDoc::DelTextFormatColl(size_t nFormatColl, bool bBroadcast) | |||
949 | { | |||
950 | OSL_ENSURE( nFormatColl, "Remove of Coll 0." )do { if (true && (!(nFormatColl))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "950" ": "), "%s", "Remove of Coll 0."); } } while (false ); | |||
951 | ||||
952 | // Who has the to-be-deleted as their Next? | |||
953 | SwTextFormatColl *pDel = (*mpTextFormatCollTable)[nFormatColl]; | |||
954 | if( mpDfltTextFormatColl.get() == pDel ) | |||
955 | return; // never delete default! | |||
956 | ||||
957 | if (bBroadcast) | |||
958 | BroadcastStyleOperation(pDel->GetName(), SfxStyleFamily::Para, | |||
959 | SfxHintId::StyleSheetErased); | |||
960 | ||||
961 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
962 | { | |||
963 | std::unique_ptr<SwUndoTextFormatCollDelete> pUndo; | |||
964 | if (RES_CONDTXTFMTCOLL == pDel->Which()) | |||
965 | { | |||
966 | pUndo.reset(new SwUndoCondTextFormatCollDelete(pDel, *this)); | |||
967 | } | |||
968 | else | |||
969 | { | |||
970 | pUndo.reset(new SwUndoTextFormatCollDelete(pDel, *this)); | |||
971 | } | |||
972 | ||||
973 | GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); | |||
974 | } | |||
975 | ||||
976 | // Remove the FormatColl | |||
977 | mpTextFormatCollTable->erase(mpTextFormatCollTable->begin() + nFormatColl); | |||
978 | // Correct next | |||
979 | for( SwTextFormatColls::const_iterator it = mpTextFormatCollTable->begin() + 1; it != mpTextFormatCollTable->end(); ++it ) | |||
980 | SetTextFormatCollNext( *it, pDel ); | |||
981 | delete pDel; | |||
982 | getIDocumentState().SetModified(); | |||
983 | } | |||
984 | ||||
985 | void SwDoc::DelTextFormatColl( SwTextFormatColl const *pColl, bool bBroadcast ) | |||
986 | { | |||
987 | size_t nFormat = mpTextFormatCollTable->GetPos( pColl ); | |||
988 | OSL_ENSURE( SIZE_MAX != nFormat, "Collection not found," )do { if (true && (!((18446744073709551615UL) != nFormat ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "988" ": "), "%s", "Collection not found,"); } } while ( false); | |||
989 | DelTextFormatColl( nFormat, bBroadcast ); | |||
990 | } | |||
991 | ||||
992 | static bool lcl_SetTextFormatColl( const SwNodePtr& rpNode, void* pArgs ) | |||
993 | { | |||
994 | SwContentNode* pCNd = rpNode->GetTextNode(); | |||
995 | ||||
996 | if( pCNd == nullptr) | |||
997 | return true; | |||
998 | ||||
999 | sw::DocumentContentOperationsManager::ParaRstFormat* pPara = static_cast<sw::DocumentContentOperationsManager::ParaRstFormat*>(pArgs); | |||
1000 | ||||
1001 | if (pPara->pLayout && pPara->pLayout->IsHideRedlines()) | |||
1002 | { | |||
1003 | if (pCNd->GetRedlineMergeFlag() == SwNode::Merge::Hidden) | |||
1004 | { | |||
1005 | return true; | |||
1006 | } | |||
1007 | if (pCNd->IsTextNode()) | |||
1008 | { | |||
1009 | pCNd = sw::GetParaPropsNode(*pPara->pLayout, SwNodeIndex(*pCNd)); | |||
1010 | } | |||
1011 | } | |||
1012 | ||||
1013 | SwTextFormatColl* pFormat = static_cast<SwTextFormatColl*>(pPara->pFormatColl); | |||
1014 | if ( pPara->bReset ) | |||
1015 | { | |||
1016 | lcl_RstAttr(pCNd, pPara); | |||
1017 | ||||
1018 | // #i62675# check, if paragraph style has changed | |||
1019 | if ( pPara->bResetListAttrs && | |||
1020 | pFormat != pCNd->GetFormatColl() && | |||
1021 | pFormat->GetItemState( RES_PARATR_NUMRULE ) == SfxItemState::SET ) | |||
1022 | { | |||
1023 | // Check, if the list style of the paragraph will change. | |||
1024 | bool bChangeOfListStyleAtParagraph( true ); | |||
1025 | SwTextNode& rTNd(dynamic_cast<SwTextNode&>(*pCNd)); | |||
1026 | { | |||
1027 | SwNumRule* pNumRuleAtParagraph(rTNd.GetNumRule()); | |||
1028 | if ( pNumRuleAtParagraph ) | |||
1029 | { | |||
1030 | const SwNumRuleItem& rNumRuleItemAtParagraphStyle = | |||
1031 | pFormat->GetNumRule(); | |||
1032 | if ( rNumRuleItemAtParagraphStyle.GetValue() == | |||
1033 | pNumRuleAtParagraph->GetName() ) | |||
1034 | { | |||
1035 | bChangeOfListStyleAtParagraph = false; | |||
1036 | } | |||
1037 | } | |||
1038 | } | |||
1039 | ||||
1040 | if ( bChangeOfListStyleAtParagraph ) | |||
1041 | { | |||
1042 | std::unique_ptr< SwRegHistory > pRegH; | |||
1043 | if ( pPara->pHistory ) | |||
1044 | { | |||
1045 | pRegH.reset(new SwRegHistory(&rTNd, rTNd, pPara->pHistory)); | |||
1046 | } | |||
1047 | ||||
1048 | pCNd->ResetAttr( RES_PARATR_NUMRULE ); | |||
1049 | ||||
1050 | // reset all list attributes | |||
1051 | pCNd->ResetAttr( RES_PARATR_LIST_LEVEL ); | |||
1052 | pCNd->ResetAttr( RES_PARATR_LIST_ISRESTART ); | |||
1053 | pCNd->ResetAttr( RES_PARATR_LIST_RESTARTVALUE ); | |||
1054 | pCNd->ResetAttr( RES_PARATR_LIST_ISCOUNTED ); | |||
1055 | pCNd->ResetAttr( RES_PARATR_LIST_ID ); | |||
1056 | } | |||
1057 | } | |||
1058 | } | |||
1059 | ||||
1060 | // add to History so that old data is saved, if necessary | |||
1061 | if( pPara->pHistory ) | |||
1062 | pPara->pHistory->Add( pCNd->GetFormatColl(), pCNd->GetIndex(), | |||
1063 | SwNodeType::Text ); | |||
1064 | ||||
1065 | pCNd->ChgFormatColl( pFormat ); | |||
1066 | ||||
1067 | pPara->nWhich++; | |||
1068 | ||||
1069 | return true; | |||
1070 | } | |||
1071 | ||||
1072 | bool SwDoc::SetTextFormatColl(const SwPaM &rRg, | |||
1073 | SwTextFormatColl *pFormat, | |||
1074 | const bool bReset, | |||
1075 | const bool bResetListAttrs, | |||
1076 | SwRootFrame const*const pLayout) | |||
1077 | { | |||
1078 | SwDataChanged aTmp( rRg ); | |||
1079 | const SwPosition *pStt = rRg.Start(), *pEnd = rRg.End(); | |||
1080 | SwHistory* pHst = nullptr; | |||
1081 | bool bRet = true; | |||
1082 | ||||
1083 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
1084 | { | |||
1085 | std::unique_ptr<SwUndoFormatColl> pUndo(new SwUndoFormatColl( rRg, pFormat, | |||
1086 | bReset, | |||
1087 | bResetListAttrs )); | |||
1088 | pHst = pUndo->GetHistory(); | |||
1089 | GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); | |||
1090 | } | |||
1091 | ||||
1092 | sw::DocumentContentOperationsManager::ParaRstFormat aPara( | |||
1093 | pStt, pEnd, pHst, nullptr, pLayout); | |||
1094 | aPara.pFormatColl = pFormat; | |||
1095 | aPara.bReset = bReset; | |||
1096 | // #i62675# | |||
1097 | aPara.bResetListAttrs = bResetListAttrs; | |||
1098 | ||||
1099 | GetNodes().ForEach( pStt->nNode.GetIndex(), pEnd->nNode.GetIndex()+1, | |||
1100 | lcl_SetTextFormatColl, &aPara ); | |||
1101 | if( !aPara.nWhich ) | |||
1102 | bRet = false; // didn't find a valid Node | |||
1103 | ||||
1104 | if (bRet) | |||
1105 | { | |||
1106 | getIDocumentState().SetModified(); | |||
1107 | } | |||
1108 | ||||
1109 | return bRet; | |||
1110 | } | |||
1111 | ||||
1112 | /// Copy the formats to itself | |||
1113 | SwFormat* SwDoc::CopyFormat( const SwFormat& rFormat, | |||
1114 | const SwFormatsBase& rFormatArr, | |||
1115 | FNCopyFormat fnCopyFormat, const SwFormat& rDfltFormat ) | |||
1116 | { | |||
1117 | // It's no autoformat, default format or collection format, | |||
1118 | // then search for it. | |||
1119 | if( !rFormat.IsAuto() || !rFormat.GetRegisteredIn() ) | |||
1120 | for( size_t n = 0; n < rFormatArr.GetFormatCount(); ++n ) | |||
1121 | { | |||
1122 | // Does the Doc already contain the template? | |||
1123 | if( rFormatArr.GetFormat(n)->GetName()==rFormat.GetName() ) | |||
1124 | return rFormatArr.GetFormat(n); | |||
1125 | } | |||
1126 | ||||
1127 | // Search for the "parent" first | |||
1128 | SwFormat* pParent = const_cast<SwFormat*>(&rDfltFormat); | |||
1129 | if( rFormat.DerivedFrom() && pParent != rFormat.DerivedFrom() ) | |||
1130 | pParent = CopyFormat( *rFormat.DerivedFrom(), rFormatArr, | |||
1131 | fnCopyFormat, rDfltFormat ); | |||
1132 | ||||
1133 | // Create the format and copy the attributes | |||
1134 | // #i40550# | |||
1135 | SwFormat* pNewFormat = (this->*fnCopyFormat)( rFormat.GetName(), pParent, false, true ); | |||
1136 | pNewFormat->SetAuto( rFormat.IsAuto() ); | |||
1137 | pNewFormat->CopyAttrs( rFormat ); // copy the attributes | |||
1138 | ||||
1139 | pNewFormat->SetPoolFormatId( rFormat.GetPoolFormatId() ); | |||
1140 | pNewFormat->SetPoolHelpId( rFormat.GetPoolHelpId() ); | |||
1141 | ||||
1142 | // Always set the HelpFile Id to default! | |||
1143 | pNewFormat->SetPoolHlpFileId( UCHAR_MAX(127*2 +1) ); | |||
1144 | ||||
1145 | return pNewFormat; | |||
1146 | } | |||
1147 | ||||
1148 | /// copy the frame format | |||
1149 | SwFrameFormat* SwDoc::CopyFrameFormat( const SwFrameFormat& rFormat ) | |||
1150 | { | |||
1151 | return static_cast<SwFrameFormat*>(CopyFormat( rFormat, *GetFrameFormats(), &SwDoc::MakeFrameFormat_, | |||
1152 | *GetDfltFrameFormat() )); | |||
1153 | } | |||
1154 | ||||
1155 | /// copy the char format | |||
1156 | SwCharFormat* SwDoc::CopyCharFormat( const SwCharFormat& rFormat ) | |||
1157 | { | |||
1158 | return static_cast<SwCharFormat*>(CopyFormat( rFormat, *GetCharFormats(), | |||
1159 | &SwDoc::MakeCharFormat_, | |||
1160 | *GetDfltCharFormat() )); | |||
1161 | } | |||
1162 | ||||
1163 | /// copy TextNodes | |||
1164 | SwTextFormatColl* SwDoc::CopyTextColl( const SwTextFormatColl& rColl ) | |||
1165 | { | |||
1166 | SwTextFormatColl* pNewColl = FindTextFormatCollByName( rColl.GetName() ); | |||
1167 | if( pNewColl ) | |||
1168 | return pNewColl; | |||
1169 | ||||
1170 | // search for the "parent" first | |||
1171 | SwTextFormatColl* pParent = mpDfltTextFormatColl.get(); | |||
1172 | if( pParent != rColl.DerivedFrom() ) | |||
1173 | pParent = CopyTextColl( *static_cast<SwTextFormatColl*>(rColl.DerivedFrom()) ); | |||
1174 | ||||
1175 | //FEATURE::CONDCOLL | |||
1176 | if( RES_CONDTXTFMTCOLL == rColl.Which() ) | |||
1177 | { | |||
1178 | pNewColl = new SwConditionTextFormatColl( GetAttrPool(), rColl.GetName(), | |||
1179 | pParent); | |||
1180 | mpTextFormatCollTable->push_back( pNewColl ); | |||
1181 | pNewColl->SetAuto(false); | |||
1182 | getIDocumentState().SetModified(); | |||
1183 | ||||
1184 | // copy the conditions | |||
1185 | static_cast<SwConditionTextFormatColl*>(pNewColl)->SetConditions( | |||
1186 | static_cast<const SwConditionTextFormatColl&>(rColl).GetCondColls() ); | |||
1187 | } | |||
1188 | else | |||
1189 | //FEATURE::CONDCOLL | |||
1190 | pNewColl = MakeTextFormatColl( rColl.GetName(), pParent ); | |||
1191 | ||||
1192 | // copy the auto formats or the attributes | |||
1193 | pNewColl->CopyAttrs( rColl ); | |||
1194 | ||||
1195 | if(rColl.IsAssignedToListLevelOfOutlineStyle()) | |||
1196 | pNewColl->AssignToListLevelOfOutlineStyle(rColl.GetAssignedOutlineStyleLevel()); | |||
1197 | pNewColl->SetPoolFormatId( rColl.GetPoolFormatId() ); | |||
1198 | pNewColl->SetPoolHelpId( rColl.GetPoolHelpId() ); | |||
1199 | ||||
1200 | // Always set the HelpFile Id to default! | |||
1201 | pNewColl->SetPoolHlpFileId( UCHAR_MAX(127*2 +1) ); | |||
1202 | ||||
1203 | if( &rColl.GetNextTextFormatColl() != &rColl ) | |||
1204 | pNewColl->SetNextTextFormatColl( *CopyTextColl( rColl.GetNextTextFormatColl() )); | |||
1205 | ||||
1206 | // create the NumRule if necessary | |||
1207 | if( this != rColl.GetDoc() ) | |||
1208 | { | |||
1209 | const SfxPoolItem* pItem; | |||
1210 | if( SfxItemState::SET == pNewColl->GetItemState( RES_PARATR_NUMRULE, | |||
1211 | false, &pItem )) | |||
1212 | { | |||
1213 | const OUString& rName = static_cast<const SwNumRuleItem*>(pItem)->GetValue(); | |||
1214 | if( !rName.isEmpty() ) | |||
1215 | { | |||
1216 | const SwNumRule* pRule = rColl.GetDoc()->FindNumRulePtr( rName ); | |||
1217 | if( pRule && !pRule->IsAutoRule() ) | |||
1218 | { | |||
1219 | SwNumRule* pDestRule = FindNumRulePtr( rName ); | |||
1220 | if( pDestRule ) | |||
1221 | pDestRule->SetInvalidRule( true ); | |||
1222 | else | |||
1223 | MakeNumRule( rName, pRule ); | |||
1224 | } | |||
1225 | } | |||
1226 | } | |||
1227 | } | |||
1228 | return pNewColl; | |||
1229 | } | |||
1230 | ||||
1231 | /// copy the graphic nodes | |||
1232 | SwGrfFormatColl* SwDoc::CopyGrfColl( const SwGrfFormatColl& rColl ) | |||
1233 | { | |||
1234 | SwGrfFormatColl* pNewColl = static_cast<SwGrfFormatColl*>(FindFormatByName( static_cast<SwFormatsBase const &>(*mpGrfFormatCollTable), rColl.GetName() )); | |||
1235 | if( pNewColl ) | |||
1236 | return pNewColl; | |||
1237 | ||||
1238 | // Search for the "parent" first | |||
1239 | SwGrfFormatColl* pParent = mpDfltGrfFormatColl.get(); | |||
1240 | if( pParent != rColl.DerivedFrom() ) | |||
1241 | pParent = CopyGrfColl( *static_cast<SwGrfFormatColl*>(rColl.DerivedFrom()) ); | |||
1242 | ||||
1243 | // if not, copy them | |||
1244 | pNewColl = MakeGrfFormatColl( rColl.GetName(), pParent ); | |||
1245 | ||||
1246 | // copy the attributes | |||
1247 | pNewColl->CopyAttrs( rColl ); | |||
1248 | ||||
1249 | pNewColl->SetPoolFormatId( rColl.GetPoolFormatId() ); | |||
1250 | pNewColl->SetPoolHelpId( rColl.GetPoolHelpId() ); | |||
1251 | ||||
1252 | // Always set the HelpFile Id to default! | |||
1253 | pNewColl->SetPoolHlpFileId( UCHAR_MAX(127*2 +1) ); | |||
1254 | ||||
1255 | return pNewColl; | |||
1256 | } | |||
1257 | ||||
1258 | void SwDoc::CopyFormatArr( const SwFormatsBase& rSourceArr, | |||
1259 | SwFormatsBase const & rDestArr, | |||
1260 | FNCopyFormat fnCopyFormat, | |||
1261 | SwFormat& rDfltFormat ) | |||
1262 | { | |||
1263 | SwFormat* pSrc, *pDest; | |||
1264 | ||||
1265 | // 1st step: Create all formats (skip the 0th - it's the default one) | |||
1266 | for( size_t nSrc = rSourceArr.GetFormatCount(); nSrc > 1; ) | |||
1267 | { | |||
1268 | pSrc = rSourceArr.GetFormat( --nSrc ); | |||
1269 | if( pSrc->IsDefault() || pSrc->IsAuto() ) | |||
1270 | continue; | |||
1271 | ||||
1272 | if( nullptr == FindFormatByName( rDestArr, pSrc->GetName() ) ) | |||
1273 | { | |||
1274 | if( RES_CONDTXTFMTCOLL == pSrc->Which() ) | |||
1275 | MakeCondTextFormatColl( pSrc->GetName(), static_cast<SwTextFormatColl*>(&rDfltFormat) ); | |||
1276 | else | |||
1277 | // #i40550# | |||
1278 | (this->*fnCopyFormat)( pSrc->GetName(), &rDfltFormat, false, true ); | |||
1279 | } | |||
1280 | } | |||
1281 | ||||
1282 | // 2nd step: Copy all attributes, set the right parents | |||
1283 | for( size_t nSrc = rSourceArr.GetFormatCount(); nSrc > 1; ) | |||
1284 | { | |||
1285 | pSrc = rSourceArr.GetFormat( --nSrc ); | |||
1286 | if( pSrc->IsDefault() || pSrc->IsAuto() ) | |||
1287 | continue; | |||
1288 | ||||
1289 | pDest = FindFormatByName( rDestArr, pSrc->GetName() ); | |||
1290 | pDest->SetAuto(false); | |||
1291 | pDest->DelDiffs( *pSrc ); | |||
1292 | ||||
1293 | // #i94285#: existing <SwFormatPageDesc> instance, before copying attributes | |||
1294 | const SfxPoolItem* pItem; | |||
1295 | if( &GetAttrPool() != pSrc->GetAttrSet().GetPool() && | |||
1296 | SfxItemState::SET == pSrc->GetAttrSet().GetItemState( | |||
1297 | RES_PAGEDESC, false, &pItem ) && | |||
1298 | static_cast<const SwFormatPageDesc*>(pItem)->GetPageDesc() ) | |||
1299 | { | |||
1300 | SwFormatPageDesc aPageDesc( *static_cast<const SwFormatPageDesc*>(pItem) ); | |||
1301 | const OUString& rNm = aPageDesc.GetPageDesc()->GetName(); | |||
1302 | SwPageDesc* pPageDesc = FindPageDesc( rNm ); | |||
1303 | if( !pPageDesc ) | |||
1304 | { | |||
1305 | pPageDesc = MakePageDesc(rNm); | |||
1306 | } | |||
1307 | aPageDesc.RegisterToPageDesc( *pPageDesc ); | |||
1308 | SwAttrSet aTmpAttrSet( pSrc->GetAttrSet() ); | |||
1309 | aTmpAttrSet.Put( aPageDesc ); | |||
1310 | pDest->SetFormatAttr( aTmpAttrSet ); | |||
1311 | } | |||
1312 | else | |||
1313 | { | |||
1314 | pDest->SetFormatAttr( pSrc->GetAttrSet() ); | |||
1315 | } | |||
1316 | ||||
1317 | pDest->SetPoolFormatId( pSrc->GetPoolFormatId() ); | |||
1318 | pDest->SetPoolHelpId( pSrc->GetPoolHelpId() ); | |||
1319 | ||||
1320 | // Always set the HelpFile Id to default! | |||
1321 | pDest->SetPoolHlpFileId( UCHAR_MAX(127*2 +1) ); | |||
1322 | ||||
1323 | if( pSrc->DerivedFrom() ) | |||
1324 | pDest->SetDerivedFrom( FindFormatByName( rDestArr, | |||
1325 | pSrc->DerivedFrom()->GetName() ) ); | |||
1326 | if( RES_TXTFMTCOLL == pSrc->Which() || | |||
1327 | RES_CONDTXTFMTCOLL == pSrc->Which() ) | |||
1328 | { | |||
1329 | SwTextFormatColl* pSrcColl = static_cast<SwTextFormatColl*>(pSrc), | |||
1330 | * pDstColl = static_cast<SwTextFormatColl*>(pDest); | |||
1331 | if( &pSrcColl->GetNextTextFormatColl() != pSrcColl ) | |||
1332 | pDstColl->SetNextTextFormatColl( *static_cast<SwTextFormatColl*>(FindFormatByName( | |||
1333 | rDestArr, pSrcColl->GetNextTextFormatColl().GetName() ) ) ); | |||
1334 | ||||
1335 | if(pSrcColl->IsAssignedToListLevelOfOutlineStyle()) | |||
1336 | pDstColl->AssignToListLevelOfOutlineStyle(pSrcColl->GetAssignedOutlineStyleLevel()); | |||
1337 | ||||
1338 | //FEATURE::CONDCOLL | |||
1339 | if( RES_CONDTXTFMTCOLL == pSrc->Which() ) | |||
1340 | // Copy the conditions, but delete the old ones first! | |||
1341 | static_cast<SwConditionTextFormatColl*>(pDstColl)->SetConditions( | |||
1342 | static_cast<SwConditionTextFormatColl*>(pSrc)->GetCondColls() ); | |||
1343 | //FEATURE::CONDCOLL | |||
1344 | } | |||
1345 | } | |||
1346 | } | |||
1347 | ||||
1348 | void SwDoc::CopyPageDescHeaderFooterImpl( bool bCpyHeader, | |||
1349 | const SwFrameFormat& rSrcFormat, SwFrameFormat& rDestFormat ) | |||
1350 | { | |||
1351 | // Treat the header and footer attributes in the right way: | |||
1352 | // Copy content nodes across documents! | |||
1353 | sal_uInt16 nAttr = bCpyHeader ? sal_uInt16(RES_HEADER) : sal_uInt16(RES_FOOTER); | |||
1354 | const SfxPoolItem* pItem; | |||
1355 | if( SfxItemState::SET != rSrcFormat.GetAttrSet().GetItemState( nAttr, false, &pItem )) | |||
1356 | return ; | |||
1357 | ||||
1358 | // The header only contains the reference to the format from the other document! | |||
1359 | std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone()); | |||
1360 | ||||
1361 | SwFrameFormat* pOldFormat; | |||
1362 | if( bCpyHeader ) | |||
1363 | pOldFormat = static_cast<SwFormatHeader*>(pNewItem.get())->GetHeaderFormat(); | |||
1364 | else | |||
1365 | pOldFormat = static_cast<SwFormatFooter*>(pNewItem.get())->GetFooterFormat(); | |||
1366 | ||||
1367 | if( !pOldFormat ) | |||
1368 | return; | |||
1369 | ||||
1370 | SwFrameFormat* pNewFormat = new SwFrameFormat( GetAttrPool(), "CpyDesc", | |||
1371 | GetDfltFrameFormat() ); | |||
1372 | pNewFormat->CopyAttrs( *pOldFormat ); | |||
1373 | ||||
1374 | if( SfxItemState::SET == pNewFormat->GetAttrSet().GetItemState( | |||
1375 | RES_CNTNT, false, &pItem )) | |||
1376 | { | |||
1377 | const SwFormatContent* pContent = static_cast<const SwFormatContent*>(pItem); | |||
1378 | if( pContent->GetContentIdx() ) | |||
1379 | { | |||
1380 | SwNodeIndex aTmpIdx( GetNodes().GetEndOfAutotext() ); | |||
1381 | const SwNodes& rSrcNds = rSrcFormat.GetDoc()->GetNodes(); | |||
1382 | SwStartNode* pSttNd = SwNodes::MakeEmptySection( aTmpIdx, | |||
1383 | bCpyHeader | |||
1384 | ? SwHeaderStartNode | |||
1385 | : SwFooterStartNode ); | |||
1386 | const SwNode& rCSttNd = pContent->GetContentIdx()->GetNode(); | |||
1387 | SwNodeRange aRg( rCSttNd, 0, *rCSttNd.EndOfSectionNode() ); | |||
1388 | aTmpIdx = *pSttNd->EndOfSectionNode(); | |||
1389 | rSrcNds.Copy_( aRg, aTmpIdx ); | |||
1390 | aTmpIdx = *pSttNd; | |||
1391 | rSrcFormat.GetDoc()->GetDocumentContentOperationsManager().CopyFlyInFlyImpl(aRg, nullptr, aTmpIdx); | |||
1392 | // TODO: investigate calling CopyWithFlyInFly? | |||
1393 | SwPaM const source(aRg.aStart, aRg.aEnd); | |||
1394 | SwPosition dest(aTmpIdx); | |||
1395 | sw::CopyBookmarks(source, dest); | |||
1396 | pNewFormat->SetFormatAttr( SwFormatContent( pSttNd )); | |||
1397 | } | |||
1398 | else | |||
1399 | pNewFormat->ResetFormatAttr( RES_CNTNT ); | |||
1400 | } | |||
1401 | if( bCpyHeader ) | |||
1402 | static_cast<SwFormatHeader*>(pNewItem.get())->RegisterToFormat(*pNewFormat); | |||
1403 | else | |||
1404 | static_cast<SwFormatFooter*>(pNewItem.get())->RegisterToFormat(*pNewFormat); | |||
1405 | rDestFormat.SetFormatAttr( *pNewItem ); | |||
1406 | } | |||
1407 | ||||
1408 | void SwDoc::CopyPageDesc( const SwPageDesc& rSrcDesc, SwPageDesc& rDstDesc, | |||
1409 | bool bCopyPoolIds ) | |||
1410 | { | |||
1411 | bool bNotifyLayout = false; | |||
1412 | SwRootFrame* pTmpRoot = getIDocumentLayoutAccess().GetCurrentLayout(); | |||
1413 | ||||
1414 | rDstDesc.SetLandscape( rSrcDesc.GetLandscape() ); | |||
1415 | rDstDesc.SetNumType( rSrcDesc.GetNumType() ); | |||
1416 | if( rDstDesc.ReadUseOn() != rSrcDesc.ReadUseOn() ) | |||
1417 | { | |||
1418 | rDstDesc.WriteUseOn( rSrcDesc.ReadUseOn() ); | |||
1419 | bNotifyLayout = true; | |||
1420 | } | |||
1421 | ||||
1422 | if( bCopyPoolIds ) | |||
1423 | { | |||
1424 | rDstDesc.SetPoolFormatId( rSrcDesc.GetPoolFormatId() ); | |||
1425 | rDstDesc.SetPoolHelpId( rSrcDesc.GetPoolHelpId() ); | |||
1426 | // Always set the HelpFile Id to default! | |||
1427 | rDstDesc.SetPoolHlpFileId( UCHAR_MAX(127*2 +1) ); | |||
1428 | } | |||
1429 | ||||
1430 | if( rSrcDesc.GetFollow() != &rSrcDesc ) | |||
1431 | { | |||
1432 | const SwPageDesc* pSrcFollow = rSrcDesc.GetFollow(); | |||
1433 | SwPageDesc* pFollow = FindPageDesc( pSrcFollow->GetName() ); | |||
1434 | if( !pFollow ) | |||
1435 | { | |||
1436 | // copy | |||
1437 | pFollow = MakePageDesc( pSrcFollow->GetName() ); | |||
1438 | CopyPageDesc( *pSrcFollow, *pFollow ); | |||
1439 | } | |||
1440 | rDstDesc.SetFollow( pFollow ); | |||
1441 | bNotifyLayout = true; | |||
1442 | } | |||
1443 | ||||
1444 | // the header and footer attributes are copied separately | |||
1445 | // the content sections have to be copied in their entirety | |||
1446 | { | |||
1447 | SfxItemSet aAttrSet( rSrcDesc.GetMaster().GetAttrSet() ); | |||
1448 | aAttrSet.ClearItem( RES_HEADER ); | |||
1449 | aAttrSet.ClearItem( RES_FOOTER ); | |||
1450 | ||||
1451 | rDstDesc.GetMaster().DelDiffs( aAttrSet ); | |||
1452 | rDstDesc.GetMaster().SetFormatAttr( aAttrSet ); | |||
1453 | ||||
1454 | aAttrSet.ClearItem(); | |||
1455 | aAttrSet.Put( rSrcDesc.GetLeft().GetAttrSet() ); | |||
1456 | aAttrSet.ClearItem( RES_HEADER ); | |||
1457 | aAttrSet.ClearItem( RES_FOOTER ); | |||
1458 | ||||
1459 | rDstDesc.GetLeft().DelDiffs( aAttrSet ); | |||
1460 | rDstDesc.GetLeft().SetFormatAttr( aAttrSet ); | |||
1461 | ||||
1462 | aAttrSet.ClearItem(); | |||
1463 | aAttrSet.Put( rSrcDesc.GetFirstMaster().GetAttrSet() ); | |||
1464 | aAttrSet.ClearItem( RES_HEADER ); | |||
1465 | aAttrSet.ClearItem( RES_FOOTER ); | |||
1466 | ||||
1467 | rDstDesc.GetFirstMaster().DelDiffs( aAttrSet ); | |||
1468 | rDstDesc.GetFirstMaster().SetFormatAttr( aAttrSet ); | |||
1469 | ||||
1470 | aAttrSet.ClearItem(); | |||
1471 | aAttrSet.Put( rSrcDesc.GetFirstLeft().GetAttrSet() ); | |||
1472 | aAttrSet.ClearItem( RES_HEADER ); | |||
1473 | aAttrSet.ClearItem( RES_FOOTER ); | |||
1474 | ||||
1475 | rDstDesc.GetFirstLeft().DelDiffs( aAttrSet ); | |||
1476 | rDstDesc.GetFirstLeft().SetFormatAttr( aAttrSet ); | |||
1477 | } | |||
1478 | ||||
1479 | CopyHeader( rSrcDesc.GetMaster(), rDstDesc.GetMaster() ); | |||
1480 | CopyFooter( rSrcDesc.GetMaster(), rDstDesc.GetMaster() ); | |||
1481 | if( !rDstDesc.IsHeaderShared() ) | |||
1482 | CopyHeader( rSrcDesc.GetLeft(), rDstDesc.GetLeft() ); | |||
1483 | else | |||
1484 | rDstDesc.GetLeft().SetFormatAttr( rDstDesc.GetMaster().GetHeader() ); | |||
1485 | if( !rDstDesc.IsFirstShared() ) | |||
1486 | { | |||
1487 | CopyHeader( rSrcDesc.GetFirstMaster(), rDstDesc.GetFirstMaster() ); | |||
1488 | rDstDesc.GetFirstLeft().SetFormatAttr(rDstDesc.GetFirstMaster().GetHeader()); | |||
1489 | } | |||
1490 | else | |||
1491 | { | |||
1492 | rDstDesc.GetFirstMaster().SetFormatAttr( rDstDesc.GetMaster().GetHeader() ); | |||
1493 | rDstDesc.GetFirstLeft().SetFormatAttr(rDstDesc.GetLeft().GetHeader()); | |||
1494 | } | |||
1495 | ||||
1496 | if( !rDstDesc.IsFooterShared() ) | |||
1497 | CopyFooter( rSrcDesc.GetLeft(), rDstDesc.GetLeft() ); | |||
1498 | else | |||
1499 | rDstDesc.GetLeft().SetFormatAttr( rDstDesc.GetMaster().GetFooter() ); | |||
1500 | if( !rDstDesc.IsFirstShared() ) | |||
1501 | { | |||
1502 | CopyFooter( rSrcDesc.GetFirstMaster(), rDstDesc.GetFirstMaster() ); | |||
1503 | rDstDesc.GetFirstLeft().SetFormatAttr(rDstDesc.GetFirstMaster().GetFooter()); | |||
1504 | } | |||
1505 | else | |||
1506 | { | |||
1507 | rDstDesc.GetFirstMaster().SetFormatAttr( rDstDesc.GetMaster().GetFooter() ); | |||
1508 | rDstDesc.GetFirstLeft().SetFormatAttr(rDstDesc.GetLeft().GetFooter()); | |||
1509 | } | |||
1510 | ||||
1511 | if( bNotifyLayout && pTmpRoot ) | |||
1512 | { | |||
1513 | for( auto aLayout : GetAllLayouts() ) | |||
1514 | aLayout->AllCheckPageDescs(); | |||
1515 | } | |||
1516 | ||||
1517 | // If foot notes change the pages have to be triggered | |||
1518 | if( !(rDstDesc.GetFootnoteInfo() == rSrcDesc.GetFootnoteInfo()) ) | |||
1519 | { | |||
1520 | sw::PageFootnoteHint aHint; | |||
1521 | rDstDesc.SetFootnoteInfo( rSrcDesc.GetFootnoteInfo() ); | |||
1522 | rDstDesc.GetMaster().CallSwClientNotify(aHint); | |||
1523 | rDstDesc.GetLeft().CallSwClientNotify(aHint); | |||
1524 | rDstDesc.GetFirstMaster().CallSwClientNotify(aHint); | |||
1525 | rDstDesc.GetFirstLeft().CallSwClientNotify(aHint); | |||
1526 | } | |||
1527 | } | |||
1528 | ||||
1529 | void SwDoc::ReplaceStyles( const SwDoc& rSource, bool bIncludePageStyles ) | |||
1530 | { | |||
1531 | ::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo()); | |||
1532 | ||||
1533 | CopyFormatArr( *rSource.mpCharFormatTable, *mpCharFormatTable, | |||
1534 | &SwDoc::MakeCharFormat_, *mpDfltCharFormat ); | |||
1535 | CopyFormatArr( *rSource.mpFrameFormatTable, *mpFrameFormatTable, | |||
1536 | &SwDoc::MakeFrameFormat_, *mpDfltFrameFormat ); | |||
1537 | CopyFormatArr( *rSource.mpTextFormatCollTable, *mpTextFormatCollTable, | |||
1538 | &SwDoc::MakeTextFormatColl_, *mpDfltTextFormatColl ); | |||
1539 | ||||
1540 | //To-Do: | |||
1541 | // a) in rtf export don't export our hideous pgdsctbl | |||
1542 | // extension to rtf anymore | |||
1543 | // b) in sd rtf import (View::InsertData) don't use | |||
1544 | // a super-fragile test for mere presence of \trowd to | |||
1545 | // indicate import of rtf into a table | |||
1546 | // c) then drop use of bIncludePageStyles | |||
1547 | if (bIncludePageStyles) | |||
1548 | { | |||
1549 | // and now the page templates | |||
1550 | SwPageDescs::size_type nCnt = rSource.m_PageDescs.size(); | |||
1551 | if( nCnt ) | |||
1552 | { | |||
1553 | // a different Doc -> Number formatter needs to be merged | |||
1554 | SwTableNumFormatMerge aTNFM( rSource, *this ); | |||
1555 | ||||
1556 | // 1st step: Create all formats (skip the 0th - it's the default!) | |||
1557 | while( nCnt ) | |||
1558 | { | |||
1559 | const SwPageDesc &rSrc = *rSource.m_PageDescs[ --nCnt ]; | |||
1560 | if( nullptr == FindPageDesc( rSrc.GetName() ) ) | |||
1561 | MakePageDesc( rSrc.GetName() ); | |||
1562 | } | |||
1563 | ||||
1564 | // 2nd step: Copy all attributes, set the right parents | |||
1565 | for (SwPageDescs::size_type i = rSource.m_PageDescs.size(); i; ) | |||
1566 | { | |||
1567 | const SwPageDesc &rSrc = *rSource.m_PageDescs[ --i ]; | |||
1568 | SwPageDesc* pDesc = FindPageDesc( rSrc.GetName() ); | |||
1569 | CopyPageDesc( rSrc, *pDesc); | |||
1570 | } | |||
1571 | } | |||
1572 | } | |||
1573 | ||||
1574 | // then there are the numbering templates | |||
1575 | const SwNumRuleTable::size_type nCnt = rSource.GetNumRuleTable().size(); | |||
1576 | if( nCnt ) | |||
1577 | { | |||
1578 | const SwNumRuleTable& rArr = rSource.GetNumRuleTable(); | |||
1579 | for( SwNumRuleTable::size_type n = 0; n < nCnt; ++n ) | |||
1580 | { | |||
1581 | const SwNumRule& rR = *rArr[ n ]; | |||
1582 | SwNumRule* pNew = FindNumRulePtr( rR.GetName()); | |||
1583 | if( pNew ) | |||
1584 | pNew->CopyNumRule(*this, rR); | |||
1585 | else | |||
1586 | { | |||
1587 | if( !rR.IsAutoRule() ) | |||
1588 | MakeNumRule( rR.GetName(), &rR ); | |||
1589 | else | |||
1590 | { | |||
1591 | // as we reset all styles, there shouldn't be any unknown | |||
1592 | // automatic SwNumRules, because all should have been | |||
1593 | // created by the style copying! | |||
1594 | // So just warn and ignore. | |||
1595 | SAL_WARN( "sw.core", "Found unknown auto SwNumRule during reset!" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "sw.core")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "Found unknown auto SwNumRule during reset!" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.core" ), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "1595" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Found unknown auto SwNumRule during reset!" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Found unknown auto SwNumRule during reset!"; ::sal ::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "1595" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Found unknown auto SwNumRule during reset!") == 1 ) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.core" ), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "1595" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Found unknown auto SwNumRule during reset!" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Found unknown auto SwNumRule during reset!"; ::sal ::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "1595" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1596 | } | |||
1597 | } | |||
1598 | } | |||
1599 | } | |||
1600 | ||||
1601 | if (undoGuard.UndoWasEnabled()) | |||
1602 | { | |||
1603 | // nodes array was modified! | |||
1604 | GetIDocumentUndoRedo().DelAllUndoObj(); | |||
1605 | } | |||
1606 | ||||
1607 | getIDocumentState().SetModified(); | |||
1608 | } | |||
1609 | ||||
1610 | SwFormat* SwDoc::FindFormatByName( const SwFormatsBase& rFormatArr, | |||
1611 | const OUString& rName ) | |||
1612 | { | |||
1613 | SwFormat* pFnd = nullptr; | |||
1614 | for( size_t n = 0; n < rFormatArr.GetFormatCount(); ++n ) | |||
1615 | { | |||
1616 | // Does the Doc already contain the template? | |||
1617 | if( rFormatArr.GetFormat(n)->HasName( rName ) ) | |||
1618 | { | |||
1619 | pFnd = rFormatArr.GetFormat(n); | |||
1620 | break; | |||
1621 | } | |||
1622 | } | |||
1623 | return pFnd; | |||
1624 | } | |||
1625 | ||||
1626 | void SwDoc::MoveLeftMargin(const SwPaM& rPam, bool bRight, bool bModulus, | |||
1627 | SwRootFrame const*const pLayout) | |||
1628 | { | |||
1629 | SwHistory* pHistory = nullptr; | |||
1630 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
1631 | { | |||
1632 | std::unique_ptr<SwUndoMoveLeftMargin> pUndo(new SwUndoMoveLeftMargin( rPam, bRight, | |||
1633 | bModulus )); | |||
1634 | pHistory = &pUndo->GetHistory(); | |||
1635 | GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); | |||
1636 | } | |||
1637 | ||||
1638 | const SvxTabStopItem& rTabItem = GetDefault( RES_PARATR_TABSTOP ); | |||
1639 | const sal_Int32 nDefDist = rTabItem.Count() ? rTabItem[0].GetTabPos() : 1134; | |||
1640 | const SwPosition &rStt = *rPam.Start(), &rEnd = *rPam.End(); | |||
1641 | SwNodeIndex aIdx( rStt.nNode ); | |||
1642 | while( aIdx <= rEnd.nNode ) | |||
1643 | { | |||
1644 | SwTextNode* pTNd = aIdx.GetNode().GetTextNode(); | |||
1645 | if( pTNd ) | |||
1646 | { | |||
1647 | pTNd = sw::GetParaPropsNode(*pLayout, aIdx); | |||
1648 | SvxLRSpaceItem aLS( static_cast<const SvxLRSpaceItem&>(pTNd->SwContentNode::GetAttr( RES_LR_SPACE )) ); | |||
1649 | ||||
1650 | // #i93873# See also lcl_MergeListLevelIndentAsLRSpaceItem in thints.cxx | |||
1651 | if ( pTNd->AreListLevelIndentsApplicable() ) | |||
1652 | { | |||
1653 | const SwNumRule* pRule = pTNd->GetNumRule(); | |||
1654 | if ( pRule ) | |||
1655 | { | |||
1656 | const int nListLevel = pTNd->GetActualListLevel(); | |||
1657 | if ( nListLevel >= 0 ) | |||
1658 | { | |||
1659 | const SwNumFormat& rFormat = pRule->Get(static_cast<sal_uInt16>(nListLevel)); | |||
1660 | if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT ) | |||
1661 | { | |||
1662 | aLS.SetTextLeft( rFormat.GetIndentAt() ); | |||
1663 | aLS.SetTextFirstLineOffset( static_cast<short>(rFormat.GetFirstLineIndent()) ); | |||
1664 | } | |||
1665 | } | |||
1666 | } | |||
1667 | } | |||
1668 | ||||
1669 | long nNext = aLS.GetTextLeft(); | |||
1670 | if( bModulus ) | |||
1671 | nNext = ( nNext / nDefDist ) * nDefDist; | |||
1672 | ||||
1673 | if( bRight ) | |||
1674 | nNext += nDefDist; | |||
1675 | else | |||
1676 | if(nNext >0) // fdo#75936 set limit for decreasing indent | |||
1677 | nNext -= nDefDist; | |||
1678 | ||||
1679 | aLS.SetTextLeft( nNext ); | |||
1680 | ||||
1681 | SwRegHistory aRegH( pTNd, *pTNd, pHistory ); | |||
1682 | pTNd->SetAttr( aLS ); | |||
1683 | aIdx = *sw::GetFirstAndLastNode(*pLayout, aIdx).second; | |||
1684 | } | |||
1685 | ++aIdx; | |||
1686 | } | |||
1687 | getIDocumentState().SetModified(); | |||
1688 | } | |||
1689 | ||||
1690 | bool SwDoc::DontExpandFormat( const SwPosition& rPos, bool bFlag ) | |||
1691 | { | |||
1692 | bool bRet = false; | |||
1693 | SwTextNode* pTextNd = rPos.nNode.GetNode().GetTextNode(); | |||
1694 | if( pTextNd ) | |||
1695 | { | |||
1696 | bRet = pTextNd->DontExpandFormat( rPos.nContent, bFlag ); | |||
1697 | if( bRet && GetIDocumentUndoRedo().DoesUndo() ) | |||
1698 | { | |||
1699 | GetIDocumentUndoRedo().AppendUndo( std::make_unique<SwUndoDontExpandFormat>(rPos) ); | |||
1700 | } | |||
1701 | } | |||
1702 | return bRet; | |||
1703 | } | |||
1704 | ||||
1705 | SwTableBoxFormat* SwDoc::MakeTableBoxFormat() | |||
1706 | { | |||
1707 | SwTableBoxFormat* pFormat = new SwTableBoxFormat( GetAttrPool(), mpDfltFrameFormat.get() ); | |||
1708 | pFormat->SetName("TableBox" + OUString::number(reinterpret_cast<sal_IntPtr>(pFormat))); | |||
1709 | getIDocumentState().SetModified(); | |||
1710 | return pFormat; | |||
1711 | } | |||
1712 | ||||
1713 | SwTableLineFormat* SwDoc::MakeTableLineFormat() | |||
1714 | { | |||
1715 | SwTableLineFormat* pFormat = new SwTableLineFormat( GetAttrPool(), mpDfltFrameFormat.get() ); | |||
1716 | pFormat->SetName("TableLine" + OUString::number(reinterpret_cast<sal_IntPtr>(pFormat))); | |||
1717 | getIDocumentState().SetModified(); | |||
1718 | return pFormat; | |||
1719 | } | |||
1720 | ||||
1721 | void SwDoc::EnsureNumberFormatter() | |||
1722 | { | |||
1723 | comphelper::doubleCheckedInit(mpNumberFormatter, []() | |||
1724 | { | |||
1725 | LanguageType eLang = LANGUAGE_SYSTEMLanguageType(0x0000); | |||
1726 | SvNumberFormatter* pRet = new SvNumberFormatter(comphelper::getProcessComponentContext(), eLang); | |||
1727 | pRet->SetEvalDateFormat( NF_EVALDATEFORMAT_FORMAT_INTL ); | |||
1728 | if (!utl::ConfigManager::IsFuzzing()) | |||
1729 | pRet->SetYear2000(officecfg::Office::Common::DateFormat::TwoDigitYear::get()); | |||
1730 | return pRet; | |||
1731 | }); | |||
1732 | } | |||
1733 | ||||
1734 | SwTableNumFormatMerge::SwTableNumFormatMerge( const SwDoc& rSrc, SwDoc& rDest ) | |||
1735 | : pNFormat( nullptr ) | |||
1736 | { | |||
1737 | // a different Doc -> Number formatter needs to be merged | |||
1738 | if( &rSrc != &rDest ) | |||
1739 | { | |||
1740 | SvNumberFormatter* pN = const_cast<SwDoc&>(rSrc).GetNumberFormatter( false ); | |||
1741 | if( pN ) | |||
1742 | { | |||
1743 | pNFormat = rDest.GetNumberFormatter(); | |||
1744 | pNFormat->MergeFormatter( *pN ); | |||
1745 | } | |||
1746 | } | |||
1747 | ||||
1748 | if( &rSrc != &rDest ) | |||
1749 | static_cast<SwGetRefFieldType*>(rSrc.getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::GetRef ))-> | |||
1750 | MergeWithOtherDoc( rDest ); | |||
1751 | } | |||
1752 | ||||
1753 | SwTableNumFormatMerge::~SwTableNumFormatMerge() | |||
1754 | { | |||
1755 | if( pNFormat ) | |||
1756 | pNFormat->ClearMergeTable(); | |||
1757 | } | |||
1758 | ||||
1759 | void SwDoc::SetTextFormatCollByAutoFormat( const SwPosition& rPos, sal_uInt16 nPoolId, | |||
1760 | const SfxItemSet* pSet ) | |||
1761 | { | |||
1762 | SwPaM aPam( rPos ); | |||
1763 | SwTextNode* pTNd = rPos.nNode.GetNode().GetTextNode(); | |||
1764 | assert(pTNd)(static_cast <bool> (pTNd) ? void (0) : __assert_fail ( "pTNd", "/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" , 1764, __extension__ __PRETTY_FUNCTION__)); | |||
1765 | ||||
1766 | if (mbIsAutoFormatRedline) | |||
1767 | { | |||
1768 | // create the redline object | |||
1769 | const SwTextFormatColl& rColl = *pTNd->GetTextColl(); | |||
1770 | SwRangeRedline* pRedl = new SwRangeRedline( RedlineType::FmtColl, aPam ); | |||
1771 | pRedl->SetMark(); | |||
1772 | ||||
1773 | // Only those items that are not set by the Set again in the Node | |||
1774 | // are of interest. Thus, we take the difference. | |||
1775 | SwRedlineExtraData_FormatColl aExtraData( rColl.GetName(), | |||
1776 | rColl.GetPoolFormatId() ); | |||
1777 | if( pSet && pTNd->HasSwAttrSet() ) | |||
1778 | { | |||
1779 | SfxItemSet aTmp( *pTNd->GetpSwAttrSet() ); | |||
1780 | aTmp.Differentiate( *pSet ); | |||
1781 | // we handle the adjust item separately | |||
1782 | const SfxPoolItem* pItem; | |||
1783 | if( SfxItemState::SET == pTNd->GetpSwAttrSet()->GetItemState( | |||
1784 | RES_PARATR_ADJUST, false, &pItem )) | |||
1785 | aTmp.Put( *pItem ); | |||
1786 | aExtraData.SetItemSet( aTmp ); | |||
1787 | } | |||
1788 | pRedl->SetExtraData( &aExtraData ); | |||
1789 | ||||
1790 | //TODO: Undo is still missing! | |||
1791 | getIDocumentRedlineAccess().AppendRedline( pRedl, true ); | |||
1792 | } | |||
1793 | ||||
1794 | SetTextFormatColl( aPam, getIDocumentStylePoolAccess().GetTextCollFromPool( nPoolId ) ); | |||
1795 | ||||
1796 | if (pSet && pSet->Count()) | |||
1797 | { | |||
1798 | aPam.SetMark(); | |||
1799 | aPam.GetMark()->nContent.Assign(pTNd, pTNd->GetText().getLength()); | |||
1800 | // sw_redlinehide: don't need layout currently because the only caller | |||
1801 | // passes in the properties node | |||
1802 | assert(static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(nullptr))->GetTextNodeForParaProps() == pTNd)(static_cast <bool> (static_cast<SwTextFrame const*> (pTNd->getLayoutFrame(nullptr))->GetTextNodeForParaProps () == pTNd) ? void (0) : __assert_fail ("static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(nullptr))->GetTextNodeForParaProps() == pTNd" , "/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" , 1802, __extension__ __PRETTY_FUNCTION__)); | |||
1803 | getIDocumentContentOperations().InsertItemSet( aPam, *pSet ); | |||
1804 | } | |||
1805 | } | |||
1806 | ||||
1807 | void SwDoc::SetFormatItemByAutoFormat( const SwPaM& rPam, const SfxItemSet& rSet ) | |||
1808 | { | |||
1809 | SwTextNode* pTNd = rPam.GetPoint()->nNode.GetNode().GetTextNode(); | |||
1810 | assert(pTNd)(static_cast <bool> (pTNd) ? void (0) : __assert_fail ( "pTNd", "/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" , 1810, __extension__ __PRETTY_FUNCTION__)); | |||
1811 | ||||
1812 | RedlineFlags eOld = getIDocumentRedlineAccess().GetRedlineFlags(); | |||
1813 | ||||
1814 | if (mbIsAutoFormatRedline) | |||
1815 | { | |||
1816 | // create the redline object | |||
1817 | SwRangeRedline* pRedl = new SwRangeRedline( RedlineType::Format, rPam ); | |||
1818 | if( !pRedl->HasMark() ) | |||
1819 | pRedl->SetMark(); | |||
1820 | ||||
1821 | // Only those items that are not set by the Set again in the Node | |||
1822 | // are of interest. Thus, we take the difference. | |||
1823 | SwRedlineExtraData_Format aExtraData( rSet ); | |||
1824 | ||||
1825 | pRedl->SetExtraData( &aExtraData ); | |||
1826 | ||||
1827 | //TODO: Undo is still missing! | |||
1828 | getIDocumentRedlineAccess().AppendRedline( pRedl, true ); | |||
1829 | ||||
1830 | getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld | RedlineFlags::Ignore ); | |||
1831 | } | |||
1832 | ||||
1833 | const sal_Int32 nEnd(rPam.End()->nContent.GetIndex()); | |||
1834 | std::vector<sal_uInt16> whichIds; | |||
1835 | SfxItemIter iter(rSet); | |||
1836 | for (SfxPoolItem const* pItem = iter.GetCurItem(); pItem; pItem = iter.NextItem()) | |||
1837 | { | |||
1838 | whichIds.push_back(pItem->Which()); | |||
1839 | whichIds.push_back(pItem->Which()); | |||
1840 | } | |||
1841 | whichIds.push_back(0); | |||
1842 | SfxItemSet currentSet(GetAttrPool(), whichIds.data()); | |||
1843 | pTNd->GetParaAttr(currentSet, nEnd, nEnd); | |||
1844 | for (size_t i = 0; whichIds[i]; i += 2) | |||
1845 | { // yuk - want to explicitly set the pool defaults too :-/ | |||
1846 | currentSet.Put(currentSet.Get(whichIds[i])); | |||
1847 | } | |||
1848 | ||||
1849 | getIDocumentContentOperations().InsertItemSet( rPam, rSet, SetAttrMode::DONTEXPAND ); | |||
1850 | ||||
1851 | // fdo#62536: DONTEXPAND does not work when there is already an AUTOFMT | |||
1852 | // here, so insert the old attributes as an empty hint to stop expand | |||
1853 | SwPaM endPam(*pTNd, nEnd); | |||
1854 | endPam.SetMark(); | |||
1855 | getIDocumentContentOperations().InsertItemSet(endPam, currentSet); | |||
1856 | ||||
1857 | getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld ); | |||
1858 | } | |||
1859 | ||||
1860 | void SwDoc::ChgFormat(SwFormat & rFormat, const SfxItemSet & rSet) | |||
1861 | { | |||
1862 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
1863 | { | |||
1864 | // copying <rSet> to <aSet> | |||
1865 | SfxItemSet aSet(rSet); | |||
1866 | // remove from <aSet> all items, which are already set at the format | |||
1867 | aSet.Differentiate(rFormat.GetAttrSet()); | |||
1868 | // <aSet> contains now all *new* items for the format | |||
1869 | ||||
1870 | // copying current format item set to <aOldSet> | |||
1871 | SfxItemSet aOldSet(rFormat.GetAttrSet()); | |||
1872 | // insert new items into <aOldSet> | |||
1873 | aOldSet.Put(aSet); | |||
1874 | // invalidate all new items in <aOldSet> in order to clear these items, | |||
1875 | // if the undo action is triggered. | |||
1876 | { | |||
1877 | SfxItemIter aIter(aSet); | |||
1878 | ||||
1879 | for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem()) | |||
1880 | { | |||
1881 | aOldSet.InvalidateItem(pItem->Which()); | |||
1882 | } | |||
1883 | } | |||
1884 | ||||
1885 | GetIDocumentUndoRedo().AppendUndo( | |||
1886 | std::make_unique<SwUndoFormatAttr>(aOldSet, rFormat, /*bSaveDrawPt*/true)); | |||
1887 | } | |||
1888 | ||||
1889 | rFormat.SetFormatAttr(rSet); | |||
1890 | } | |||
1891 | ||||
1892 | void SwDoc::RenameFormat(SwFormat & rFormat, const OUString & sNewName, | |||
1893 | bool bBroadcast) | |||
1894 | { | |||
1895 | SfxStyleFamily eFamily = SfxStyleFamily::All; | |||
1896 | ||||
1897 | if (GetIDocumentUndoRedo().DoesUndo()) | |||
1898 | { | |||
1899 | std::unique_ptr<SwUndo> pUndo; | |||
1900 | ||||
1901 | switch (rFormat.Which()) | |||
1902 | { | |||
1903 | case RES_CHRFMT: | |||
1904 | pUndo.reset(new SwUndoRenameCharFormat(rFormat.GetName(), sNewName, *this)); | |||
1905 | eFamily = SfxStyleFamily::Char; | |||
1906 | break; | |||
1907 | case RES_TXTFMTCOLL: | |||
1908 | pUndo.reset(new SwUndoRenameFormatColl(rFormat.GetName(), sNewName, *this)); | |||
1909 | eFamily = SfxStyleFamily::Para; | |||
1910 | break; | |||
1911 | case RES_FRMFMT: | |||
1912 | pUndo.reset(new SwUndoRenameFrameFormat(rFormat.GetName(), sNewName, *this)); | |||
1913 | eFamily = SfxStyleFamily::Frame; | |||
1914 | break; | |||
1915 | ||||
1916 | default: | |||
1917 | break; | |||
1918 | } | |||
1919 | ||||
1920 | if (pUndo) | |||
1921 | { | |||
1922 | GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); | |||
1923 | } | |||
1924 | } | |||
1925 | ||||
1926 | rFormat.SetName(sNewName); | |||
1927 | ||||
1928 | if (bBroadcast) | |||
1929 | BroadcastStyleOperation(sNewName, eFamily, SfxHintId::StyleSheetModified); | |||
1930 | } | |||
1931 | ||||
1932 | void SwDoc::dumpAsXml(xmlTextWriterPtr pWriter) const | |||
1933 | { | |||
1934 | bool bOwns = false; | |||
1935 | if (!pWriter) | |||
1936 | { | |||
1937 | pWriter = xmlNewTextWriterFilename("nodes.xml", 0); | |||
1938 | xmlTextWriterSetIndent(pWriter,1); | |||
1939 | xmlTextWriterSetIndentString(pWriter, BAD_CAST(xmlChar *)(" ")); | |||
1940 | xmlTextWriterStartDocument(pWriter, nullptr, nullptr, nullptr); | |||
1941 | bOwns = true; | |||
1942 | } | |||
1943 | xmlTextWriterStartElement(pWriter, BAD_CAST(xmlChar *)("SwDoc")); | |||
1944 | xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(xmlChar *)("ptr"), "%p", this); | |||
1945 | ||||
1946 | m_pNodes->dumpAsXml(pWriter); | |||
1947 | m_PageDescs.dumpAsXml(pWriter); | |||
1948 | maDBData.dumpAsXml(pWriter); | |||
1949 | mpMarkManager->dumpAsXml(pWriter); | |||
1950 | m_pUndoManager->dumpAsXml(pWriter); | |||
1951 | m_pDocumentSettingManager->dumpAsXml(pWriter); | |||
1952 | getIDocumentFieldsAccess().GetFieldTypes()->dumpAsXml(pWriter); | |||
1953 | mpTextFormatCollTable->dumpAsXml(pWriter); | |||
1954 | mpCharFormatTable->dumpAsXml(pWriter); | |||
1955 | mpFrameFormatTable->dumpAsXml(pWriter, "frmFormatTable"); | |||
1956 | mpSpzFrameFormatTable->dumpAsXml(pWriter, "spzFrameFormatTable"); | |||
1957 | mpSectionFormatTable->dumpAsXml(pWriter); | |||
1958 | mpTableFrameFormatTable->dumpAsXml(pWriter, "tableFrameFormatTable"); | |||
1959 | mpNumRuleTable->dumpAsXml(pWriter); | |||
1960 | getIDocumentRedlineAccess().GetRedlineTable().dumpAsXml(pWriter); | |||
1961 | getIDocumentRedlineAccess().GetExtraRedlineTable().dumpAsXml(pWriter); | |||
1962 | if (const SdrModel* pModel = getIDocumentDrawModelAccess().GetDrawModel()) | |||
1963 | pModel->dumpAsXml(pWriter); | |||
1964 | ||||
1965 | xmlTextWriterStartElement(pWriter, BAD_CAST(xmlChar *)("mbModified")); | |||
1966 | xmlTextWriterWriteAttribute(pWriter, BAD_CAST(xmlChar *)("value"), BAD_CAST(xmlChar *)(OString::boolean(getIDocumentState().IsModified()).getStr())); | |||
1967 | xmlTextWriterEndElement(pWriter); | |||
1968 | ||||
1969 | xmlTextWriterEndElement(pWriter); | |||
1970 | if (bOwns) | |||
1971 | { | |||
1972 | xmlTextWriterEndDocument(pWriter); | |||
1973 | xmlFreeTextWriter(pWriter); | |||
1974 | } | |||
1975 | } | |||
1976 | ||||
1977 | void SwDBData::dumpAsXml(xmlTextWriterPtr pWriter) const | |||
1978 | { | |||
1979 | xmlTextWriterStartElement(pWriter, BAD_CAST(xmlChar *)("SwDBData")); | |||
1980 | ||||
1981 | xmlTextWriterWriteAttribute(pWriter, BAD_CAST(xmlChar *)("sDataSource"), BAD_CAST(xmlChar *)(sDataSource.toUtf8().getStr())); | |||
1982 | xmlTextWriterWriteAttribute(pWriter, BAD_CAST(xmlChar *)("sCommand"), BAD_CAST(xmlChar *)(sCommand.toUtf8().getStr())); | |||
1983 | xmlTextWriterWriteAttribute(pWriter, BAD_CAST(xmlChar *)("nCommandType"), BAD_CAST(xmlChar *)(OString::number(nCommandType).getStr())); | |||
1984 | ||||
1985 | xmlTextWriterEndElement(pWriter); | |||
1986 | } | |||
1987 | ||||
1988 | std::set<Color> SwDoc::GetDocColors() | |||
1989 | { | |||
1990 | std::set<Color> aDocColors; | |||
1991 | SwAttrPool& rPool = GetAttrPool(); | |||
1992 | const sal_uInt16 pAttribs[] = {RES_CHRATR_COLOR, RES_CHRATR_HIGHLIGHT, RES_BACKGROUND}; | |||
1993 | for (sal_uInt16 nAttrib : pAttribs) | |||
1994 | { | |||
1995 | for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(nAttrib)) | |||
1996 | { | |||
1997 | auto pColorItem = static_cast<const SvxColorItem*>(pItem); | |||
1998 | Color aColor( pColorItem->GetValue() ); | |||
1999 | if (COL_AUTO != aColor) | |||
2000 | aDocColors.insert(aColor); | |||
2001 | } | |||
2002 | } | |||
2003 | return aDocColors; | |||
2004 | } | |||
2005 | ||||
2006 | // #i69627# | |||
2007 | namespace docfunc | |||
2008 | { | |||
2009 | bool HasOutlineStyleToBeWrittenAsNormalListStyle( SwDoc& rDoc ) | |||
2010 | { | |||
2011 | // If a parent paragraph style of one of the paragraph styles, which | |||
2012 | // are assigned to the list levels of the outline style, has a list style | |||
2013 | // set or inherits a list style from its parent style, the outline style | |||
2014 | // has to be written as a normal list style to the OpenDocument file | |||
2015 | // format or the OpenOffice.org file format. | |||
2016 | bool bRet( false ); | |||
2017 | ||||
2018 | const SwTextFormatColls* pTextFormatColls( rDoc.GetTextFormatColls() ); | |||
2019 | if ( pTextFormatColls ) | |||
2020 | { | |||
2021 | for ( auto pTextFormatColl : *pTextFormatColls ) | |||
2022 | { | |||
2023 | if ( pTextFormatColl->IsDefault() || | |||
2024 | ! pTextFormatColl->IsAssignedToListLevelOfOutlineStyle() ) | |||
2025 | { | |||
2026 | continue; | |||
2027 | } | |||
2028 | ||||
2029 | const SwTextFormatColl* pParentTextFormatColl = | |||
2030 | dynamic_cast<const SwTextFormatColl*>( pTextFormatColl->DerivedFrom()); | |||
2031 | if ( !pParentTextFormatColl ) | |||
2032 | continue; | |||
2033 | ||||
2034 | if ( SfxItemState::SET == pParentTextFormatColl->GetItemState( RES_PARATR_NUMRULE ) ) | |||
2035 | { | |||
2036 | // #i106218# consider that the outline style is set | |||
2037 | const SwNumRuleItem& rDirectItem = pParentTextFormatColl->GetNumRule(); | |||
2038 | if ( rDirectItem.GetValue() != rDoc.GetOutlineNumRule()->GetName() ) | |||
2039 | { | |||
2040 | bRet = true; | |||
2041 | break; | |||
2042 | } | |||
2043 | } | |||
2044 | } | |||
2045 | ||||
2046 | } | |||
2047 | return bRet; | |||
2048 | } | |||
2049 | } | |||
2050 | ||||
2051 | SwFrameFormats::SwFrameFormats() | |||
2052 | : m_PosIndex( m_Array.get<0>() ) | |||
2053 | , m_TypeAndNameIndex( m_Array.get<1>() ) | |||
2054 | { | |||
2055 | } | |||
2056 | ||||
2057 | SwFrameFormats::~SwFrameFormats() | |||
2058 | { | |||
2059 | DeleteAndDestroyAll(); | |||
2060 | } | |||
2061 | ||||
2062 | SwFrameFormats::const_iterator SwFrameFormats::find( const value_type& x ) const | |||
2063 | { | |||
2064 | ByTypeAndName::iterator it = m_TypeAndNameIndex.find( | |||
2065 | boost::make_tuple(x->Which(), x->GetName(), x) ); | |||
2066 | return m_Array.project<0>( it ); | |||
2067 | } | |||
2068 | ||||
2069 | std::pair<SwFrameFormats::const_range_iterator,SwFrameFormats::const_range_iterator> | |||
2070 | SwFrameFormats::rangeFind( sal_uInt16 type, const OUString& name ) const | |||
2071 | { | |||
2072 | return m_TypeAndNameIndex.equal_range( boost::make_tuple(type, name) ); | |||
2073 | } | |||
2074 | ||||
2075 | std::pair<SwFrameFormats::const_range_iterator,SwFrameFormats::const_range_iterator> | |||
2076 | SwFrameFormats::rangeFind( const value_type& x ) const | |||
2077 | { | |||
2078 | return rangeFind( x->Which(), x->GetName() ); | |||
2079 | } | |||
2080 | ||||
2081 | void SwFrameFormats::DeleteAndDestroyAll( bool keepDefault ) | |||
2082 | { | |||
2083 | if ( empty() ) | |||
2084 | return; | |||
2085 | const int _offset = keepDefault ? 1 : 0; | |||
2086 | for( const_iterator it = begin() + _offset; it != end(); ++it ) | |||
2087 | delete *it; | |||
2088 | if ( _offset ) | |||
2089 | m_PosIndex.erase( begin() + _offset, end() ); | |||
2090 | else | |||
2091 | m_Array.clear(); | |||
2092 | } | |||
2093 | ||||
2094 | std::pair<SwFrameFormats::const_iterator,bool> SwFrameFormats::push_back( const value_type& x ) | |||
2095 | { | |||
2096 | SAL_WARN_IF(x->m_ffList != nullptr, "sw.core", "Inserting already assigned item")do { if (true && (x->m_ffList != nullptr)) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN, "sw.core" )) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Inserting already assigned item") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "2096" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Inserting already assigned item"), 0 ); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Inserting already assigned item"; ::sal::detail::log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "2096" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Inserting already assigned item") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "2096" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Inserting already assigned item"), 0 ); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Inserting already assigned item"; ::sal::detail::log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "2096" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
2097 | assert(x->m_ffList == nullptr)(static_cast <bool> (x->m_ffList == nullptr) ? void ( 0) : __assert_fail ("x->m_ffList == nullptr", "/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" , 2097, __extension__ __PRETTY_FUNCTION__)); | |||
2098 | x->m_ffList = this; | |||
2099 | return m_PosIndex.push_back( x ); | |||
2100 | } | |||
2101 | ||||
2102 | bool SwFrameFormats::erase( const value_type& x ) | |||
2103 | { | |||
2104 | const_iterator const ret = find( x ); | |||
2105 | SAL_WARN_IF(x->m_ffList != this, "sw.core", "Removing invalid / unassigned item")do { if (true && (x->m_ffList != this)) { switch ( sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN, "sw.core") ) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Removing invalid / unassigned item") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "2105" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Removing invalid / unassigned item" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Removing invalid / unassigned item"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "2105" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Removing invalid / unassigned item") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "2105" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Removing invalid / unassigned item" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Removing invalid / unassigned item"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" ":" "2105" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
2106 | if (ret != end()) { | |||
2107 | assert( x == *ret )(static_cast <bool> (x == *ret) ? void (0) : __assert_fail ("x == *ret", "/home/maarten/src/libreoffice/core/sw/source/core/doc/docfmt.cxx" , 2107, __extension__ __PRETTY_FUNCTION__)); | |||
2108 | m_PosIndex.erase( ret ); | |||
2109 | x->m_ffList = nullptr; | |||
2110 | return true; | |||
2111 | } | |||
2112 | return false; | |||
2113 | } | |||
2114 | ||||
2115 | void SwFrameFormats::erase( size_type index_ ) | |||
2116 | { | |||
2117 | erase( begin() + index_ ); | |||
2118 | } | |||
2119 | ||||
2120 | void SwFrameFormats::erase( const_iterator const& position ) | |||
2121 | { | |||
2122 | (*position)->m_ffList = nullptr; | |||
2123 | m_PosIndex.erase( begin() + (position - begin()) ); | |||
2124 | } | |||
2125 | ||||
2126 | bool SwFrameFormats::ContainsFormat(const SwFrameFormat& x) const | |||
2127 | { | |||
2128 | return (x.m_ffList == this); | |||
2129 | } | |||
2130 | ||||
2131 | bool SwFrameFormats::IsAlive(SwFrameFormat const*const p) const | |||
2132 | { | |||
2133 | return find(const_cast<SwFrameFormat*>(p)) != end(); | |||
2134 | } | |||
2135 | ||||
2136 | bool SwFrameFormats::newDefault( const value_type& x ) | |||
2137 | { | |||
2138 | std::pair<iterator,bool> res = m_PosIndex.push_front( x ); | |||
2139 | if( ! res.second ) | |||
2140 | newDefault( res.first ); | |||
2141 | return res.second; | |||
2142 | } | |||
2143 | ||||
2144 | void SwFrameFormats::newDefault( const_iterator const& position ) | |||
2145 | { | |||
2146 | if (position == begin()) | |||
2147 | return; | |||
2148 | m_PosIndex.relocate( begin(), position ); | |||
2149 | } | |||
2150 | ||||
2151 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |