File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 192, column 9 Use of memory after it is freed |
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 <memory> | ||||||||
21 | |||||||||
22 | #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> | ||||||||
23 | #include <com/sun/star/beans/XPropertySet.hpp> | ||||||||
24 | #include <com/sun/star/container/XNameAccess.hpp> | ||||||||
25 | #include <com/sun/star/frame/XModel.hpp> | ||||||||
26 | #include <comphelper/flagguard.hxx> | ||||||||
27 | #include <o3tl/any.hxx> | ||||||||
28 | #include <sal/log.hxx> | ||||||||
29 | #include <hintids.hxx> | ||||||||
30 | #include <sfx2/styledlg.hxx> | ||||||||
31 | #include <svl/whiter.hxx> | ||||||||
32 | #include <sfx2/tplpitem.hxx> | ||||||||
33 | #include <sfx2/request.hxx> | ||||||||
34 | #include <sfx2/dispatch.hxx> | ||||||||
35 | #include <sfx2/newstyle.hxx> | ||||||||
36 | #include <sfx2/printer.hxx> | ||||||||
37 | #include <sfx2/viewfrm.hxx> | ||||||||
38 | #include <svl/stritem.hxx> | ||||||||
39 | #include <svl/languageoptions.hxx> | ||||||||
40 | #include <sfx2/htmlmode.hxx> | ||||||||
41 | #include <swmodule.hxx> | ||||||||
42 | #include <fchrfmt.hxx> | ||||||||
43 | #include <svtools/htmlcfg.hxx> | ||||||||
44 | #include <svx/xdef.hxx> | ||||||||
45 | #include <SwStyleNameMapper.hxx> | ||||||||
46 | #include <SwRewriter.hxx> | ||||||||
47 | #include <numrule.hxx> | ||||||||
48 | #include <swundo.hxx> | ||||||||
49 | #include <svx/drawitem.hxx> | ||||||||
50 | #include <view.hxx> | ||||||||
51 | #include <wrtsh.hxx> | ||||||||
52 | #include <docsh.hxx> | ||||||||
53 | #include <uitool.hxx> | ||||||||
54 | #include <cmdid.h> | ||||||||
55 | #include <viewopt.hxx> | ||||||||
56 | #include <doc.hxx> | ||||||||
57 | #include <drawdoc.hxx> | ||||||||
58 | #include <IDocumentDrawModelAccess.hxx> | ||||||||
59 | #include <IDocumentUndoRedo.hxx> | ||||||||
60 | #include <IDocumentSettingAccess.hxx> | ||||||||
61 | #include <IDocumentDeviceAccess.hxx> | ||||||||
62 | #include <IDocumentFieldsAccess.hxx> | ||||||||
63 | #include <IDocumentState.hxx> | ||||||||
64 | #include <frmfmt.hxx> | ||||||||
65 | #include <charfmt.hxx> | ||||||||
66 | #include <poolfmt.hxx> | ||||||||
67 | #include <pagedesc.hxx> | ||||||||
68 | #include <docstyle.hxx> | ||||||||
69 | #include <uiitems.hxx> | ||||||||
70 | #include <fmtcol.hxx> | ||||||||
71 | #include <edtwin.hxx> | ||||||||
72 | #include <unochart.hxx> | ||||||||
73 | #include <swabstdlg.hxx> | ||||||||
74 | #include <paratr.hxx> | ||||||||
75 | #include <tblafmt.hxx> | ||||||||
76 | #include <sfx2/watermarkitem.hxx> | ||||||||
77 | #include <SwUndoFmt.hxx> | ||||||||
78 | #include <strings.hrc> | ||||||||
79 | #include <AccessibilityCheck.hxx> | ||||||||
80 | |||||||||
81 | using namespace ::com::sun::star; | ||||||||
82 | |||||||||
83 | void SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh) | ||||||||
84 | { | ||||||||
85 | SfxWhichIter aIter(rSet); | ||||||||
86 | sal_uInt16 nWhich = aIter.FirstWhich(); | ||||||||
87 | SfxStyleFamily nActualFamily = SfxStyleFamily(USHRT_MAX(32767 *2 +1)); | ||||||||
88 | |||||||||
89 | SwWrtShell* pShell = pSh ? pSh : GetWrtShell(); | ||||||||
90 | if(!pShell) | ||||||||
91 | { | ||||||||
92 | while (nWhich) | ||||||||
93 | { | ||||||||
94 | rSet.DisableItem(nWhich); | ||||||||
95 | nWhich = aIter.NextWhich(); | ||||||||
96 | } | ||||||||
97 | return; | ||||||||
98 | } | ||||||||
99 | else | ||||||||
100 | { | ||||||||
101 | SfxViewFrame* pFrame = pShell->GetView().GetViewFrame(); | ||||||||
102 | std::unique_ptr<SfxPoolItem> pItem; | ||||||||
103 | pFrame->GetBindings().QueryState(SID_STYLE_FAMILYTypedWhichId<SfxUInt16Item>(5000 + 553), pItem); | ||||||||
104 | SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem.get()); | ||||||||
105 | if (pFamilyItem) | ||||||||
106 | { | ||||||||
107 | nActualFamily = static_cast<SfxStyleFamily>(pFamilyItem->GetValue()); | ||||||||
108 | } | ||||||||
109 | } | ||||||||
110 | |||||||||
111 | while (nWhich) | ||||||||
112 | { | ||||||||
113 | // determine current template to every family | ||||||||
114 | OUString aName; | ||||||||
115 | SwTableAutoFormat aTableAutoFormat("dummy"); // needed to check if can take a table auto format at current cursor position | ||||||||
116 | switch (nWhich) | ||||||||
117 | { | ||||||||
118 | case SID_STYLE_APPLY(5000 + 552): | ||||||||
119 | {// here the template and its family are passed to the StyleBox | ||||||||
120 | // so that this family is being showed | ||||||||
121 | if(pShell->IsFrameSelected()) | ||||||||
122 | { | ||||||||
123 | SwFrameFormat* pFormat = pShell->GetSelectedFrameFormat(); | ||||||||
124 | if( pFormat ) | ||||||||
125 | aName = pFormat->GetName(); | ||||||||
126 | } | ||||||||
127 | else | ||||||||
128 | { | ||||||||
129 | SwTextFormatColl* pColl = pShell->GetCurTextFormatColl(); | ||||||||
130 | if(pColl) | ||||||||
131 | aName = pColl->GetName(); | ||||||||
132 | } | ||||||||
133 | rSet.Put(SfxTemplateItem(nWhich, aName)); | ||||||||
134 | } | ||||||||
135 | break; | ||||||||
136 | case SID_STYLE_FAMILY1((5000 + 541)): | ||||||||
137 | if( !pShell->IsFrameSelected() ) | ||||||||
138 | { | ||||||||
139 | SwCharFormat* pFormat = pShell->GetCurCharFormat(); | ||||||||
140 | if(pFormat) | ||||||||
141 | aName = pFormat->GetName(); | ||||||||
142 | else | ||||||||
143 | aName = SwResId(STR_POOLCHR_STANDARDreinterpret_cast<char const *>("STR_POOLCHR_STANDARD" "\004" u8"Default Character Style")); | ||||||||
144 | rSet.Put(SfxTemplateItem(nWhich, aName)); | ||||||||
145 | } | ||||||||
146 | break; | ||||||||
147 | |||||||||
148 | case SID_STYLE_FAMILY2((5000 + 541) + 1): | ||||||||
149 | if(!pShell->IsFrameSelected()) | ||||||||
150 | { | ||||||||
151 | SwTextFormatColl* pColl = pShell->GetCurTextFormatColl(); | ||||||||
152 | if(pColl) | ||||||||
153 | aName = pColl->GetName(); | ||||||||
154 | |||||||||
155 | SfxTemplateItem aItem(nWhich, aName); | ||||||||
156 | |||||||||
157 | SfxStyleSearchBits nMask = SfxStyleSearchBits::Auto; | ||||||||
158 | if (m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE)) | ||||||||
159 | nMask = SfxStyleSearchBits::SwHtml; | ||||||||
160 | else | ||||||||
161 | { | ||||||||
162 | const FrameTypeFlags nSelection = pShell->GetFrameType(nullptr,true); | ||||||||
163 | if(pShell->GetCurTOX()) | ||||||||
164 | nMask = SfxStyleSearchBits::SwIndex ; | ||||||||
165 | else if(nSelection & FrameTypeFlags::HEADER || | ||||||||
166 | nSelection & FrameTypeFlags::FOOTER || | ||||||||
167 | nSelection & FrameTypeFlags::TABLE || | ||||||||
168 | nSelection & FrameTypeFlags::FLY_ANY || | ||||||||
169 | nSelection & FrameTypeFlags::FOOTNOTE || | ||||||||
170 | nSelection & FrameTypeFlags::FTNPAGE) | ||||||||
171 | nMask = SfxStyleSearchBits::SwExtra; | ||||||||
172 | else | ||||||||
173 | nMask = SfxStyleSearchBits::SwText; | ||||||||
174 | } | ||||||||
175 | |||||||||
176 | aItem.SetValue(nMask); | ||||||||
177 | rSet.Put(aItem); | ||||||||
178 | } | ||||||||
179 | |||||||||
180 | break; | ||||||||
181 | |||||||||
182 | case SID_STYLE_FAMILY3((5000 + 541) + 2): | ||||||||
183 | |||||||||
184 | if (m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE)) | ||||||||
185 | rSet.DisableItem( nWhich ); | ||||||||
186 | else | ||||||||
187 | { | ||||||||
188 | SwFrameFormat* pFormat = pShell->GetSelectedFrameFormat(); | ||||||||
189 | if(pFormat && pShell->IsFrameSelected()) | ||||||||
190 | { | ||||||||
191 | aName = pFormat->GetName(); | ||||||||
192 | rSet.Put(SfxTemplateItem(nWhich, aName)); | ||||||||
193 | } | ||||||||
194 | } | ||||||||
195 | break; | ||||||||
196 | |||||||||
197 | case SID_STYLE_FAMILY4((5000 + 541) + 3): | ||||||||
198 | { | ||||||||
199 | SvxHtmlOptions& rHtmlOpt = SvxHtmlOptions::Get(); | ||||||||
200 | if (m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE) && !rHtmlOpt.IsPrintLayoutExtension()) | ||||||||
201 | rSet.DisableItem( nWhich ); | ||||||||
202 | else | ||||||||
203 | { | ||||||||
204 | size_t n = pShell->GetCurPageDesc( false ); | ||||||||
205 | if( n < pShell->GetPageDescCnt() ) | ||||||||
206 | aName = pShell->GetPageDesc( n ).GetName(); | ||||||||
207 | |||||||||
208 | rSet.Put(SfxTemplateItem(nWhich, aName)); | ||||||||
209 | } | ||||||||
210 | } | ||||||||
211 | break; | ||||||||
212 | case SID_STYLE_FAMILY5((5000 + 541) + 4): | ||||||||
213 | { | ||||||||
214 | const SwNumRule* pRule = pShell->GetNumRuleAtCurrCursorPos(); | ||||||||
215 | if( pRule ) | ||||||||
216 | aName = pRule->GetName(); | ||||||||
217 | |||||||||
218 | rSet.Put(SfxTemplateItem(nWhich, aName)); | ||||||||
219 | } | ||||||||
220 | break; | ||||||||
221 | case SID_STYLE_FAMILY6((5000 + 541) + 5): | ||||||||
222 | { | ||||||||
223 | const SwTableNode *pTableNd = pShell->IsCursorInTable(); | ||||||||
224 | if( pTableNd ) | ||||||||
225 | aName = pTableNd->GetTable().GetTableStyleName(); | ||||||||
226 | |||||||||
227 | rSet.Put(SfxTemplateItem(nWhich, aName)); | ||||||||
228 | } | ||||||||
229 | break; | ||||||||
230 | |||||||||
231 | case SID_STYLE_WATERCAN(5000 + 554): | ||||||||
232 | { | ||||||||
233 | SwEditWin& rEdtWin = pShell->GetView().GetEditWin(); | ||||||||
234 | SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate(); | ||||||||
235 | rSet.Put(SfxBoolItem(nWhich, pApply && pApply->eType != SfxStyleFamily(0))); | ||||||||
236 | } | ||||||||
237 | break; | ||||||||
238 | case SID_STYLE_UPDATE_BY_EXAMPLE(5000 + 556): | ||||||||
239 | if( pShell->IsFrameSelected() | ||||||||
240 | ? SfxStyleFamily::Frame != nActualFamily | ||||||||
241 | : ( SfxStyleFamily::Frame == nActualFamily || | ||||||||
242 | SfxStyleFamily::Page == nActualFamily || | ||||||||
243 | (SfxStyleFamily::Pseudo == nActualFamily && !pShell->GetNumRuleAtCurrCursorPos()) || | ||||||||
244 | (SfxStyleFamily::Table == nActualFamily && !pShell->GetTableAutoFormat(aTableAutoFormat))) ) | ||||||||
245 | { | ||||||||
246 | rSet.DisableItem( nWhich ); | ||||||||
247 | } | ||||||||
248 | break; | ||||||||
249 | |||||||||
250 | case SID_STYLE_NEW_BY_EXAMPLE(5000 + 555): | ||||||||
251 | if( (pShell->IsFrameSelected() | ||||||||
252 | ? SfxStyleFamily::Frame != nActualFamily | ||||||||
253 | : SfxStyleFamily::Frame == nActualFamily) || | ||||||||
254 | (SfxStyleFamily::Pseudo == nActualFamily && !pShell->GetNumRuleAtCurrCursorPos()) || | ||||||||
255 | (SfxStyleFamily::Table == nActualFamily && !pShell->GetTableAutoFormat(aTableAutoFormat)) ) | ||||||||
256 | { | ||||||||
257 | rSet.DisableItem( nWhich ); | ||||||||
258 | } | ||||||||
259 | break; | ||||||||
260 | |||||||||
261 | case SID_CLASSIFICATION_APPLY(5000 + 672): | ||||||||
262 | // Just trigger ClassificationCategoriesController::statusChanged(). | ||||||||
263 | rSet.InvalidateItem(nWhich); | ||||||||
264 | break; | ||||||||
265 | case SID_CLASSIFICATION_DIALOG( 10000 + 1171 ): | ||||||||
266 | rSet.InvalidateItem(nWhich); | ||||||||
267 | break; | ||||||||
268 | case SID_STYLE_EDIT(5000 + 550): | ||||||||
269 | break; | ||||||||
270 | case SID_WATERMARK(5000 + 676): | ||||||||
271 | if (pSh) | ||||||||
272 | { | ||||||||
273 | SfxWatermarkItem aItem = pSh->GetWatermark(); | ||||||||
274 | rSet.Put(aItem); | ||||||||
275 | } | ||||||||
276 | break; | ||||||||
277 | default: | ||||||||
278 | OSL_FAIL("Invalid SlotId")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "278" ": "), "%s", "Invalid SlotId"); } } while (false); | ||||||||
279 | } | ||||||||
280 | nWhich = aIter.NextWhich(); | ||||||||
281 | } | ||||||||
282 | } | ||||||||
283 | |||||||||
284 | // evaluate StyleSheet-Requests | ||||||||
285 | void SwDocShell::ExecStyleSheet( SfxRequest& rReq ) | ||||||||
286 | { | ||||||||
287 | sal_uInt16 nSlot = rReq.GetSlot(); | ||||||||
288 | |||||||||
289 | const SfxItemSet* pArgs = rReq.GetArgs(); | ||||||||
290 | const SfxPoolItem* pItem; | ||||||||
291 | switch (nSlot) | ||||||||
292 | { | ||||||||
293 | case SID_STYLE_NEW(5000 + 549): | ||||||||
294 | if( pArgs && SfxItemState::SET == pArgs->GetItemState( SID_STYLE_FAMILYTypedWhichId<SfxUInt16Item>(5000 + 553), | ||||||||
295 | false, &pItem )) | ||||||||
296 | { | ||||||||
297 | const SfxStyleFamily nFamily = static_cast<SfxStyleFamily>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); | ||||||||
298 | |||||||||
299 | OUString sName; | ||||||||
300 | SfxStyleSearchBits nMask = SfxStyleSearchBits::Auto; | ||||||||
301 | if( SfxItemState::SET == pArgs->GetItemState( SID_STYLE_NEW(5000 + 549), | ||||||||
302 | false, &pItem )) | ||||||||
303 | sName = static_cast<const SfxStringItem*>(pItem)->GetValue(); | ||||||||
304 | if( SfxItemState::SET == pArgs->GetItemState( SID_STYLE_MASK(5000 + 562), | ||||||||
305 | false, &pItem )) | ||||||||
306 | nMask = static_cast<SfxStyleSearchBits>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); | ||||||||
307 | OUString sParent; | ||||||||
308 | if( SfxItemState::SET == pArgs->GetItemState( SID_STYLE_REFERENCETypedWhichId<SfxStringItem>(5000 + 1602), | ||||||||
309 | false, &pItem )) | ||||||||
310 | sParent = static_cast<const SfxStringItem*>(pItem)->GetValue(); | ||||||||
311 | |||||||||
312 | if (sName.isEmpty() && m_xBasePool) | ||||||||
313 | sName = SfxStyleDialogController::GenerateUnusedName(*m_xBasePool, nFamily); | ||||||||
314 | |||||||||
315 | Edit(sName, sParent, nFamily, nMask, true, OString(), nullptr, &rReq, nSlot); | ||||||||
316 | } | ||||||||
317 | break; | ||||||||
318 | |||||||||
319 | case SID_STYLE_APPLY(5000 + 552): | ||||||||
320 | if( !pArgs ) | ||||||||
321 | { | ||||||||
322 | GetView()->GetViewFrame()->GetDispatcher()->Execute(SID_STYLE_DESIGNER(5000 + 539)); | ||||||||
323 | break; | ||||||||
324 | } | ||||||||
325 | else | ||||||||
326 | { | ||||||||
327 | // convert internal StyleName to DisplayName (slot implementation uses the latter) | ||||||||
328 | const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(SID_APPLY_STYLE(5000 + 1703)); | ||||||||
329 | const SfxStringItem* pFamilyItem = rReq.GetArg<SfxStringItem>(SID_STYLE_FAMILYNAMETypedWhichId<SfxStringItem>(5000 + 566)); | ||||||||
330 | if ( pFamilyItem && pNameItem ) | ||||||||
331 | { | ||||||||
332 | uno::Reference< style::XStyleFamiliesSupplier > xModel(GetModel(), uno::UNO_QUERY); | ||||||||
333 | try | ||||||||
334 | { | ||||||||
335 | uno::Reference< container::XNameAccess > xStyles; | ||||||||
336 | uno::Reference< container::XNameAccess > xCont = xModel->getStyleFamilies(); | ||||||||
337 | xCont->getByName(pFamilyItem->GetValue()) >>= xStyles; | ||||||||
338 | uno::Reference< beans::XPropertySet > xInfo; | ||||||||
339 | xStyles->getByName( pNameItem->GetValue() ) >>= xInfo; | ||||||||
340 | OUString aUIName; | ||||||||
341 | xInfo->getPropertyValue("DisplayName") >>= aUIName; | ||||||||
342 | if ( !aUIName.isEmpty() ) | ||||||||
343 | rReq.AppendItem( SfxStringItem( SID_STYLE_APPLY(5000 + 552), aUIName ) ); | ||||||||
344 | } | ||||||||
345 | catch (const uno::Exception&) | ||||||||
346 | { | ||||||||
347 | } | ||||||||
348 | } | ||||||||
349 | } | ||||||||
350 | |||||||||
351 | [[fallthrough]]; | ||||||||
352 | |||||||||
353 | case SID_STYLE_EDIT(5000 + 550): | ||||||||
354 | case SID_STYLE_DELETE(5000 + 551): | ||||||||
355 | case SID_STYLE_HIDE(5000 + 1603): | ||||||||
356 | case SID_STYLE_SHOW(5000 + 1604): | ||||||||
357 | case SID_STYLE_WATERCAN(5000 + 554): | ||||||||
358 | case SID_STYLE_FAMILYTypedWhichId<SfxUInt16Item>(5000 + 553): | ||||||||
359 | case SID_STYLE_UPDATE_BY_EXAMPLE(5000 + 556): | ||||||||
360 | case SID_STYLE_NEW_BY_EXAMPLE(5000 + 555): | ||||||||
361 | { | ||||||||
362 | OUString aParam; | ||||||||
363 | SfxStyleFamily nFamily = SfxStyleFamily::Para; | ||||||||
364 | SfxStyleSearchBits nMask = SfxStyleSearchBits::Auto; | ||||||||
365 | SwWrtShell* pActShell = nullptr; | ||||||||
366 | |||||||||
367 | if( !pArgs ) | ||||||||
368 | { | ||||||||
369 | switch (nSlot) | ||||||||
370 | { | ||||||||
371 | case SID_STYLE_NEW_BY_EXAMPLE(5000 + 555): | ||||||||
372 | { | ||||||||
373 | SfxStyleSheetBasePool& rPool = *GetStyleSheetPool(); | ||||||||
374 | SfxNewStyleDlg aDlg(GetView()->GetFrameWeld(), rPool, nFamily); | ||||||||
375 | if (aDlg.run() == RET_OK) | ||||||||
376 | { | ||||||||
377 | aParam = aDlg.GetName(); | ||||||||
378 | rReq.AppendItem(SfxStringItem(nSlot, aParam)); | ||||||||
379 | } | ||||||||
380 | } | ||||||||
381 | break; | ||||||||
382 | |||||||||
383 | case SID_STYLE_UPDATE_BY_EXAMPLE(5000 + 556): | ||||||||
384 | case SID_STYLE_EDIT(5000 + 550): | ||||||||
385 | { | ||||||||
386 | SwTextFormatColl* pColl = GetWrtShell()->GetCurTextFormatColl(); | ||||||||
387 | if(pColl) | ||||||||
388 | { | ||||||||
389 | aParam = pColl->GetName(); | ||||||||
390 | rReq.AppendItem(SfxStringItem(nSlot, aParam)); | ||||||||
391 | } | ||||||||
392 | } | ||||||||
393 | break; | ||||||||
394 | } | ||||||||
395 | } | ||||||||
396 | else | ||||||||
397 | { | ||||||||
398 | SAL_WARN_IF( !pArgs->Count(), "sw.ui", "SfxBug ItemSet is empty" )do { if (true && (!pArgs->Count())) { switch (sal_detail_log_report (::SAL_DETAIL_LOG_LEVEL_WARN, "sw.ui")) { case SAL_DETAIL_LOG_ACTION_IGNORE : break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail ::getResult( ::sal::detail::StreamStart() << "SfxBug ItemSet is empty" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "398" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "SfxBug ItemSet is empty"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "SfxBug ItemSet is empty"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "398" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "SfxBug ItemSet is empty") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "398" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "SfxBug ItemSet is empty"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "SfxBug ItemSet is empty"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "398" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
399 | |||||||||
400 | SwWrtShell* pShell = GetWrtShell(); | ||||||||
401 | if( SfxItemState::SET == pArgs->GetItemState(nSlot, false, &pItem )) | ||||||||
402 | aParam = static_cast<const SfxStringItem*>(pItem)->GetValue(); | ||||||||
403 | |||||||||
404 | if( SfxItemState::SET == pArgs->GetItemState(SID_STYLE_FAMILYTypedWhichId<SfxUInt16Item>(5000 + 553), | ||||||||
405 | false, &pItem )) | ||||||||
406 | nFamily = static_cast<SfxStyleFamily>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); | ||||||||
407 | |||||||||
408 | if( SfxItemState::SET == pArgs->GetItemState(SID_STYLE_FAMILYNAMETypedWhichId<SfxStringItem>(5000 + 566), false, &pItem )) | ||||||||
409 | { | ||||||||
410 | OUString aFamily = static_cast<const SfxStringItem*>(pItem)->GetValue(); | ||||||||
411 | if(aFamily == "CharacterStyles") | ||||||||
412 | nFamily = SfxStyleFamily::Char; | ||||||||
413 | else | ||||||||
414 | if(aFamily == "ParagraphStyles") | ||||||||
415 | nFamily = SfxStyleFamily::Para; | ||||||||
416 | else | ||||||||
417 | if(aFamily == "PageStyles") | ||||||||
418 | nFamily = SfxStyleFamily::Page; | ||||||||
419 | else | ||||||||
420 | if(aFamily == "FrameStyles") | ||||||||
421 | nFamily = SfxStyleFamily::Frame; | ||||||||
422 | else | ||||||||
423 | if(aFamily == "NumberingStyles") | ||||||||
424 | nFamily = SfxStyleFamily::Pseudo; | ||||||||
425 | else | ||||||||
426 | if(aFamily == "TableStyles") | ||||||||
427 | nFamily = SfxStyleFamily::Table; | ||||||||
428 | } | ||||||||
429 | |||||||||
430 | if( SfxItemState::SET == pArgs->GetItemState(SID_STYLE_MASK(5000 + 562), | ||||||||
431 | false, &pItem )) | ||||||||
432 | nMask = static_cast<SfxStyleSearchBits>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); | ||||||||
433 | if( SfxItemState::SET == pArgs->GetItemState(FN_PARAM_WRTSHELL((20000 + 2400)), | ||||||||
434 | false, &pItem )) | ||||||||
435 | pActShell = pShell = static_cast<SwWrtShell*>(static_cast<const SwPtrItem*>(pItem)->GetValue()); | ||||||||
436 | |||||||||
437 | if( nSlot == SID_STYLE_UPDATE_BY_EXAMPLE(5000 + 556) && aParam.isEmpty() ) | ||||||||
438 | { | ||||||||
439 | switch( nFamily ) | ||||||||
440 | { | ||||||||
441 | case SfxStyleFamily::Para: | ||||||||
442 | { | ||||||||
443 | SwTextFormatColl* pColl = pShell->GetCurTextFormatColl(); | ||||||||
444 | if(pColl) | ||||||||
445 | aParam = pColl->GetName(); | ||||||||
446 | } | ||||||||
447 | break; | ||||||||
448 | case SfxStyleFamily::Frame: | ||||||||
449 | { | ||||||||
450 | SwFrameFormat* pFrame = m_pWrtShell->GetSelectedFrameFormat(); | ||||||||
451 | if( pFrame ) | ||||||||
452 | aParam = pFrame->GetName(); | ||||||||
453 | } | ||||||||
454 | break; | ||||||||
455 | case SfxStyleFamily::Char: | ||||||||
456 | { | ||||||||
457 | SwCharFormat* pChar = m_pWrtShell->GetCurCharFormat(); | ||||||||
458 | if( pChar ) | ||||||||
459 | aParam = pChar->GetName(); | ||||||||
460 | } | ||||||||
461 | break; | ||||||||
462 | case SfxStyleFamily::Pseudo: | ||||||||
463 | if(SfxItemState::SET == pArgs->GetItemState(SID_STYLE_UPD_BY_EX_NAME(5000 + 1585), false, &pItem)) | ||||||||
464 | { | ||||||||
465 | aParam = static_cast<const SfxStringItem*>(pItem)->GetValue(); | ||||||||
466 | } | ||||||||
467 | break; | ||||||||
468 | case SfxStyleFamily::Table: | ||||||||
469 | if(SfxItemState::SET == pArgs->GetItemState(SID_STYLE_UPD_BY_EX_NAME(5000 + 1585), false, &pItem)) | ||||||||
470 | { | ||||||||
471 | aParam = static_cast<const SfxStringItem*>(pItem)->GetValue(); | ||||||||
472 | } | ||||||||
473 | break; | ||||||||
474 | default: break; | ||||||||
475 | } | ||||||||
476 | rReq.AppendItem(SfxStringItem(nSlot, aParam)); | ||||||||
477 | } | ||||||||
478 | } | ||||||||
479 | if (!aParam.isEmpty() || nSlot == SID_STYLE_WATERCAN(5000 + 554) ) | ||||||||
480 | { | ||||||||
481 | sal_uInt16 nRet = 0xffff; | ||||||||
482 | bool bReturns = false; | ||||||||
483 | |||||||||
484 | switch(nSlot) | ||||||||
485 | { | ||||||||
486 | case SID_STYLE_EDIT(5000 + 550): | ||||||||
487 | Edit(aParam, OUString(), nFamily, nMask, false, OString(), pActShell); | ||||||||
488 | break; | ||||||||
489 | case SID_STYLE_DELETE(5000 + 551): | ||||||||
490 | Delete(aParam, nFamily); | ||||||||
491 | break; | ||||||||
492 | case SID_STYLE_HIDE(5000 + 1603): | ||||||||
493 | case SID_STYLE_SHOW(5000 + 1604): | ||||||||
494 | Hide(aParam, nFamily, nSlot == SID_STYLE_HIDE(5000 + 1603)); | ||||||||
495 | break; | ||||||||
496 | case SID_STYLE_APPLY(5000 + 552): | ||||||||
497 | // Shell-switch in ApplyStyles | ||||||||
498 | nRet = static_cast<sal_uInt16>(ApplyStyles(aParam, nFamily, pActShell, rReq.GetModifier() )); | ||||||||
499 | bReturns = true; | ||||||||
500 | break; | ||||||||
501 | case SID_STYLE_WATERCAN(5000 + 554): | ||||||||
502 | nRet = static_cast<sal_uInt16>(DoWaterCan(aParam, nFamily)); | ||||||||
503 | bReturns = true; | ||||||||
504 | break; | ||||||||
505 | case SID_STYLE_UPDATE_BY_EXAMPLE(5000 + 556): | ||||||||
506 | UpdateStyle(aParam, nFamily, pActShell); | ||||||||
507 | break; | ||||||||
508 | case SID_STYLE_NEW_BY_EXAMPLE(5000 + 555): | ||||||||
509 | MakeByExample(aParam, nFamily, nMask, pActShell); | ||||||||
510 | break; | ||||||||
511 | |||||||||
512 | default: | ||||||||
513 | OSL_FAIL("Invalid SlotId")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "513" ": "), "%s", "Invalid SlotId"); } } while (false); | ||||||||
514 | } | ||||||||
515 | |||||||||
516 | if (bReturns) | ||||||||
517 | { | ||||||||
518 | if(rReq.IsAPI()) // Basic only gets TRUE or FALSE | ||||||||
519 | rReq.SetReturnValue(SfxUInt16Item(nSlot, sal_uInt16(nRet !=0))); | ||||||||
520 | else | ||||||||
521 | rReq.SetReturnValue(SfxUInt16Item(nSlot, nRet)); | ||||||||
522 | } | ||||||||
523 | |||||||||
524 | rReq.Done(); | ||||||||
525 | } | ||||||||
526 | |||||||||
527 | break; | ||||||||
528 | } | ||||||||
529 | } | ||||||||
530 | } | ||||||||
531 | |||||||||
532 | namespace { | ||||||||
533 | |||||||||
534 | class ApplyStyle | ||||||||
535 | { | ||||||||
536 | public: | ||||||||
537 | ApplyStyle(SwDocShell &rDocSh, bool bNew, | ||||||||
538 | rtl::Reference< SwDocStyleSheet > const & xTmp, | ||||||||
539 | SfxStyleFamily nFamily, SfxAbstractApplyTabDialog *pDlg, | ||||||||
540 | rtl::Reference< SfxStyleSheetBasePool > const & xBasePool, | ||||||||
541 | bool bModified) | ||||||||
542 | : m_pDlg(pDlg) | ||||||||
543 | , m_rDocSh(rDocSh) | ||||||||
544 | , m_bNew(bNew) | ||||||||
545 | , m_xTmp(xTmp) | ||||||||
546 | , m_nFamily(nFamily) | ||||||||
547 | , m_xBasePool(xBasePool) | ||||||||
548 | , m_bModified(bModified) | ||||||||
549 | { | ||||||||
550 | } | ||||||||
551 | DECL_LINK( ApplyHdl, LinkParamNone*, void )static void LinkStubApplyHdl(void *, LinkParamNone*); void ApplyHdl (LinkParamNone*); | ||||||||
552 | void apply() | ||||||||
553 | { | ||||||||
554 | ApplyHdl(nullptr); | ||||||||
555 | } | ||||||||
556 | VclPtr<SfxAbstractApplyTabDialog> m_pDlg; | ||||||||
557 | private: | ||||||||
558 | SwDocShell &m_rDocSh; | ||||||||
559 | bool m_bNew; | ||||||||
560 | rtl::Reference< SwDocStyleSheet > m_xTmp; | ||||||||
561 | SfxStyleFamily m_nFamily; | ||||||||
562 | rtl::Reference< SfxStyleSheetBasePool > m_xBasePool; | ||||||||
563 | bool m_bModified; | ||||||||
564 | }; | ||||||||
565 | |||||||||
566 | } | ||||||||
567 | |||||||||
568 | IMPL_LINK_NOARG(ApplyStyle, ApplyHdl, LinkParamNone*, void)void ApplyStyle::LinkStubApplyHdl(void * instance, LinkParamNone * data) { return static_cast<ApplyStyle *>(instance)-> ApplyHdl(data); } void ApplyStyle::ApplyHdl(__attribute__ ((unused )) LinkParamNone*) | ||||||||
569 | { | ||||||||
570 | SwWrtShell* pWrtShell = m_rDocSh.GetWrtShell(); | ||||||||
571 | SwDoc* pDoc = m_rDocSh.GetDoc(); | ||||||||
572 | SwView* pView = m_rDocSh.GetView(); | ||||||||
573 | |||||||||
574 | pWrtShell->StartAllAction(); | ||||||||
575 | |||||||||
576 | if( SfxStyleFamily::Para == m_nFamily ) | ||||||||
577 | { | ||||||||
578 | SfxItemSet aSet( *m_pDlg->GetOutputItemSet() ); | ||||||||
579 | ::SfxToSwPageDescAttr( *pWrtShell, aSet ); | ||||||||
580 | // reset indent attributes at paragraph style, if a list style | ||||||||
581 | // will be applied and no indent attributes will be applied. | ||||||||
582 | m_xTmp->SetItemSet( aSet, true ); | ||||||||
583 | } | ||||||||
584 | else | ||||||||
585 | { | ||||||||
586 | if(SfxStyleFamily::Page == m_nFamily) | ||||||||
587 | { | ||||||||
588 | static const sal_uInt16 aInval[] = { | ||||||||
589 | SID_IMAGE_ORIENTATION(5000 + 1667), | ||||||||
590 | SID_ATTR_CHAR_FONT( 10000 + 7 ), | ||||||||
591 | FN_INSERT_CTRL((20000 + 300) + 89), FN_INSERT_OBJ_CTRL((20000 + 300) + 90), 0}; | ||||||||
592 | pView->GetViewFrame()->GetBindings().Invalidate(aInval); | ||||||||
593 | } | ||||||||
594 | SfxItemSet aTmpSet( *m_pDlg->GetOutputItemSet() ); | ||||||||
595 | if( SfxStyleFamily::Char == m_nFamily ) | ||||||||
596 | { | ||||||||
597 | ::ConvertAttrGenToChar(aTmpSet, m_xTmp->GetItemSet()); | ||||||||
598 | } | ||||||||
599 | |||||||||
600 | m_xTmp->SetItemSet( aTmpSet ); | ||||||||
601 | |||||||||
602 | if( SfxStyleFamily::Page == m_nFamily && SvtLanguageOptions().IsCTLFontEnabled() ) | ||||||||
603 | { | ||||||||
604 | const SfxPoolItem *pItem = nullptr; | ||||||||
605 | if( aTmpSet.GetItemState( m_rDocSh.GetPool().GetTrueWhich( SID_ATTR_FRAMEDIRECTION( 10000 + 944 ), false ) , true, &pItem ) == SfxItemState::SET ) | ||||||||
606 | SwChartHelper::DoUpdateAllCharts( pDoc ); | ||||||||
607 | } | ||||||||
608 | } | ||||||||
609 | |||||||||
610 | if(m_bNew) | ||||||||
611 | { | ||||||||
612 | if(SfxStyleFamily::Frame == m_nFamily || SfxStyleFamily::Para == m_nFamily) | ||||||||
613 | { | ||||||||
614 | // clear FillStyle so that it works as a derived attribute | ||||||||
615 | SfxItemSet aTmpSet(*m_pDlg->GetOutputItemSet()); | ||||||||
616 | |||||||||
617 | aTmpSet.ClearItem(XATTR_FILLSTYLE); | ||||||||
618 | m_xTmp->SetItemSet(aTmpSet); | ||||||||
619 | } | ||||||||
620 | } | ||||||||
621 | |||||||||
622 | if(SfxStyleFamily::Page == m_nFamily) | ||||||||
623 | pView->InvalidateRulerPos(); | ||||||||
624 | |||||||||
625 | if( m_bNew ) | ||||||||
626 | m_xBasePool->Broadcast(SfxStyleSheetHint(SfxHintId::StyleSheetCreated, *m_xTmp)); | ||||||||
627 | else | ||||||||
628 | m_xBasePool->Broadcast(SfxStyleSheetHint(SfxHintId::StyleSheetModified, *m_xTmp)); | ||||||||
629 | |||||||||
630 | pDoc->getIDocumentState().SetModified(); | ||||||||
631 | if( !m_bModified ) | ||||||||
632 | { | ||||||||
633 | pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified(); | ||||||||
634 | } | ||||||||
635 | |||||||||
636 | pWrtShell->EndAllAction(); | ||||||||
637 | } | ||||||||
638 | |||||||||
639 | namespace | ||||||||
640 | { | ||||||||
641 | /// Checks if there is an Endnote page style in use, and makes sure it has the same orientation | ||||||||
642 | /// with the Default (Standard) page style. | ||||||||
643 | void syncEndnoteOrientation(const uno::Reference< style::XStyleFamiliesSupplier >& xStyleFamSupp) | ||||||||
644 | { | ||||||||
645 | if (!xStyleFamSupp.is()) | ||||||||
646 | { | ||||||||
647 | SAL_WARN("sw.ui", "Ref to XStyleFamiliesSupplier is null.")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "sw.ui")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Ref to XStyleFamiliesSupplier is null.") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui"), ( "/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "647" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Ref to XStyleFamiliesSupplier is null." ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Ref to XStyleFamiliesSupplier is null."; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "647" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Ref to XStyleFamiliesSupplier is null.") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui"), ( "/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "647" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Ref to XStyleFamiliesSupplier is null." ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Ref to XStyleFamiliesSupplier is null."; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "647" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
648 | return; | ||||||||
649 | } | ||||||||
650 | uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamSupp->getStyleFamilies(); | ||||||||
651 | |||||||||
652 | if (!xStyleFamilies.is()) | ||||||||
653 | return; | ||||||||
654 | |||||||||
655 | uno::Reference<container::XNameAccess> xPageStyles(xStyleFamilies->getByName("PageStyles"), | ||||||||
656 | uno::UNO_QUERY); | ||||||||
657 | |||||||||
658 | if (!xPageStyles.is()) | ||||||||
659 | return; | ||||||||
660 | |||||||||
661 | uno::Reference<css::style::XStyle> xEndnotePageStyle(xPageStyles->getByName("Endnote"), | ||||||||
662 | uno::UNO_QUERY); | ||||||||
663 | |||||||||
664 | if (!xEndnotePageStyle.is()) | ||||||||
665 | return; | ||||||||
666 | |||||||||
667 | // Language-independent name of the "Default Style" is "Standard" | ||||||||
668 | uno::Reference<css::style::XStyle> xDefaultPageStyle(xPageStyles->getByName("Standard"), | ||||||||
669 | uno::UNO_QUERY); | ||||||||
670 | if (!xDefaultPageStyle.is()) | ||||||||
671 | return; | ||||||||
672 | |||||||||
673 | if (xEndnotePageStyle->isUserDefined() || !xEndnotePageStyle->isInUse()) | ||||||||
674 | return; | ||||||||
675 | |||||||||
676 | uno::Reference<beans::XPropertySet> xEndnotePagePropSet(xPageStyles->getByName("Endnote"), uno::UNO_QUERY); | ||||||||
677 | uno::Reference<beans::XPropertySet> xDefaultPagePropSet(xPageStyles->getByName("Standard"), uno::UNO_QUERY); | ||||||||
678 | |||||||||
679 | if (!xEndnotePagePropSet.is() || !xDefaultPagePropSet.is()) | ||||||||
680 | { | ||||||||
681 | SAL_WARN("sw.ui", "xEndnotePagePropSet or xDefaultPagePropSet is null.")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "sw.ui")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "xEndnotePagePropSet or xDefaultPagePropSet is null." ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "681" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "xEndnotePagePropSet or xDefaultPagePropSet is null." ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "xEndnotePagePropSet or xDefaultPagePropSet is null." ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "681" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "xEndnotePagePropSet or xDefaultPagePropSet is null." ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "681" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "xEndnotePagePropSet or xDefaultPagePropSet is null." ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "xEndnotePagePropSet or xDefaultPagePropSet is null." ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "681" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
682 | return; | ||||||||
683 | } | ||||||||
684 | |||||||||
685 | auto const bIsDefLandScape = *o3tl::doAccess<bool>( | ||||||||
686 | xDefaultPagePropSet->getPropertyValue("IsLandscape")); | ||||||||
687 | auto const bIsEndLandScape = *o3tl::doAccess<bool>( | ||||||||
688 | xEndnotePagePropSet->getPropertyValue("IsLandscape")); | ||||||||
689 | |||||||||
690 | if (bIsDefLandScape == bIsEndLandScape) | ||||||||
691 | return; | ||||||||
692 | |||||||||
693 | auto const nWidth = xEndnotePagePropSet->getPropertyValue("Width"); | ||||||||
694 | auto const nHeight = xEndnotePagePropSet->getPropertyValue("Height"); | ||||||||
695 | |||||||||
696 | xEndnotePagePropSet->setPropertyValue("IsLandscape", css::uno::toAny(bIsDefLandScape)); | ||||||||
697 | xEndnotePagePropSet->setPropertyValue("Width", nHeight); | ||||||||
698 | xEndnotePagePropSet->setPropertyValue("Height", nWidth); | ||||||||
699 | } | ||||||||
700 | } | ||||||||
701 | |||||||||
702 | void SwDocShell::Edit( | ||||||||
703 | const OUString &rName, | ||||||||
704 | const OUString &rParent, | ||||||||
705 | const SfxStyleFamily nFamily, | ||||||||
706 | SfxStyleSearchBits nMask, | ||||||||
707 | const bool bNew, | ||||||||
708 | const OString& sPage, | ||||||||
709 | SwWrtShell* pActShell, | ||||||||
710 | SfxRequest* pReq, | ||||||||
711 | sal_uInt16 nSlot) | ||||||||
712 | { | ||||||||
713 | assert( GetWrtShell() )(static_cast <bool> (GetWrtShell()) ? void (0) : __assert_fail ("GetWrtShell()", "/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" , 713, __extension__ __PRETTY_FUNCTION__)); | ||||||||
714 | const bool bBasic = pReq && pReq->IsAPI(); | ||||||||
715 | SfxStyleSheetBase *pStyle = nullptr; | ||||||||
716 | |||||||||
717 | bool bModified = m_xDoc->getIDocumentState().IsModified(); | ||||||||
718 | |||||||||
719 | SwUndoId nNewStyleUndoId(SwUndoId::EMPTY); | ||||||||
720 | |||||||||
721 | if( bNew ) | ||||||||
722 | { | ||||||||
723 | if (!bBasic) | ||||||||
724 | { | ||||||||
725 | // start undo action in order to get only one undo action for the | ||||||||
726 | // UI new style + change style operations | ||||||||
727 | m_pWrtShell->StartUndo(); | ||||||||
728 | } | ||||||||
729 | |||||||||
730 | if( SfxStyleSearchBits::All != nMask && SfxStyleSearchBits::AllVisible != nMask && SfxStyleSearchBits::Used != nMask ) | ||||||||
731 | nMask |= SfxStyleSearchBits::UserDefined; | ||||||||
732 | else | ||||||||
733 | nMask = SfxStyleSearchBits::UserDefined; | ||||||||
734 | |||||||||
735 | if ( nFamily == SfxStyleFamily::Para || nFamily == SfxStyleFamily::Char || nFamily == SfxStyleFamily::Frame ) | ||||||||
736 | { | ||||||||
737 | // Prevent undo append from being done during paragraph, character, and frame style Make | ||||||||
738 | // Do it after ok return from style dialog when derived from style is known | ||||||||
739 | ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo()); | ||||||||
740 | pStyle = &m_xBasePool->Make( rName, nFamily, nMask ); | ||||||||
741 | } | ||||||||
742 | else | ||||||||
743 | { | ||||||||
744 | pStyle = &m_xBasePool->Make( rName, nFamily, nMask ); | ||||||||
745 | } | ||||||||
746 | |||||||||
747 | // set the current one as Parent | ||||||||
748 | SwDocStyleSheet* pDStyle = static_cast<SwDocStyleSheet*>(pStyle); | ||||||||
749 | switch( nFamily ) | ||||||||
750 | { | ||||||||
751 | case SfxStyleFamily::Para: | ||||||||
752 | { | ||||||||
753 | if(!rParent.isEmpty()) | ||||||||
754 | { | ||||||||
755 | SwTextFormatColl* pColl = m_pWrtShell->FindTextFormatCollByName( rParent ); | ||||||||
756 | if(!pColl) | ||||||||
757 | { | ||||||||
758 | sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, SwGetPoolIdFromName::TxtColl); | ||||||||
759 | if(USHRT_MAX(32767 *2 +1) != nId) | ||||||||
760 | pColl = m_pWrtShell->GetTextCollFromPool( nId ); | ||||||||
761 | } | ||||||||
762 | pDStyle->GetCollection()->SetDerivedFrom( pColl ); | ||||||||
763 | pDStyle->PresetParent( rParent ); | ||||||||
764 | |||||||||
765 | /*When a new paragraph style is created based on a "to outline style | ||||||||
766 | assigned" paragraph style, the outline level attribute and the list | ||||||||
767 | style attribute of the new paragraph style have to be set to 0 | ||||||||
768 | respectively "".*/ | ||||||||
769 | if (pColl && pColl->IsAssignedToListLevelOfOutlineStyle()) | ||||||||
770 | { | ||||||||
771 | SwNumRuleItem aItem; | ||||||||
772 | pDStyle->GetCollection()->SetFormatAttr( aItem ); | ||||||||
773 | pDStyle->GetCollection()->SetAttrOutlineLevel( 0 ); | ||||||||
774 | } | ||||||||
775 | } | ||||||||
776 | else | ||||||||
777 | { | ||||||||
778 | SwTextFormatColl* pColl = m_pWrtShell->GetCurTextFormatColl(); | ||||||||
779 | pDStyle->GetCollection()->SetDerivedFrom( pColl ); | ||||||||
780 | if( pColl ) | ||||||||
781 | pDStyle->PresetParent( pColl->GetName() ); | ||||||||
782 | } | ||||||||
783 | } | ||||||||
784 | break; | ||||||||
785 | case SfxStyleFamily::Char: | ||||||||
786 | { | ||||||||
787 | if(!rParent.isEmpty()) | ||||||||
788 | { | ||||||||
789 | SwCharFormat* pCFormat = m_pWrtShell->FindCharFormatByName(rParent); | ||||||||
790 | if(!pCFormat) | ||||||||
791 | { | ||||||||
792 | sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, SwGetPoolIdFromName::ChrFmt); | ||||||||
793 | if(USHRT_MAX(32767 *2 +1) != nId) | ||||||||
794 | pCFormat = m_pWrtShell->GetCharFormatFromPool( nId ); | ||||||||
795 | } | ||||||||
796 | |||||||||
797 | pDStyle->GetCharFormat()->SetDerivedFrom( pCFormat ); | ||||||||
798 | pDStyle->PresetParent( rParent ); | ||||||||
799 | } | ||||||||
800 | else | ||||||||
801 | { | ||||||||
802 | SwCharFormat* pCFormat = m_pWrtShell->GetCurCharFormat(); | ||||||||
803 | pDStyle->GetCharFormat()->SetDerivedFrom( pCFormat ); | ||||||||
804 | if( pCFormat ) | ||||||||
805 | pDStyle->PresetParent( pCFormat->GetName() ); | ||||||||
806 | } | ||||||||
807 | } | ||||||||
808 | break; | ||||||||
809 | case SfxStyleFamily::Frame : | ||||||||
810 | { | ||||||||
811 | if(!rParent.isEmpty()) | ||||||||
812 | { | ||||||||
813 | SwFrameFormat* pFFormat = m_pWrtShell->GetDoc()->FindFrameFormatByName( rParent ); | ||||||||
814 | if(!pFFormat) | ||||||||
815 | { | ||||||||
816 | sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, SwGetPoolIdFromName::FrmFmt); | ||||||||
817 | if(USHRT_MAX(32767 *2 +1) != nId) | ||||||||
818 | pFFormat = m_pWrtShell->GetFrameFormatFromPool( nId ); | ||||||||
819 | } | ||||||||
820 | pDStyle->GetFrameFormat()->SetDerivedFrom( pFFormat ); | ||||||||
821 | pDStyle->PresetParent( rParent ); | ||||||||
822 | } | ||||||||
823 | } | ||||||||
824 | break; | ||||||||
825 | default: break; | ||||||||
826 | } | ||||||||
827 | |||||||||
828 | if (!bBasic) | ||||||||
829 | { | ||||||||
830 | //Get the undo id for the type of style that was created in order to re-use that comment for the grouped | ||||||||
831 | //create style + change style operations | ||||||||
832 | m_pWrtShell->GetLastUndoInfo(nullptr, &nNewStyleUndoId); | ||||||||
833 | } | ||||||||
834 | } | ||||||||
835 | else | ||||||||
836 | { | ||||||||
837 | pStyle = m_xBasePool->Find( rName, nFamily ); | ||||||||
838 | SAL_WARN_IF( !pStyle, "sw.ui", "Style not found" )do { if (true && (!pStyle)) { switch (sal_detail_log_report (::SAL_DETAIL_LOG_LEVEL_WARN, "sw.ui")) { case SAL_DETAIL_LOG_ACTION_IGNORE : break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail ::getResult( ::sal::detail::StreamStart() << "Style not found" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "838" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Style not found"), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << "Style not found"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "838" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Style not found") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "838" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Style not found"), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << "Style not found"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "838" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
839 | } | ||||||||
840 | |||||||||
841 | if(!pStyle) | ||||||||
842 | return; | ||||||||
843 | |||||||||
844 | // put dialogues together | ||||||||
845 | rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pStyle) ) ); | ||||||||
846 | if( SfxStyleFamily::Para == nFamily ) | ||||||||
847 | { | ||||||||
848 | SfxItemSet& rSet = xTmp->GetItemSet(); | ||||||||
849 | ::SwToSfxPageDescAttr( rSet ); | ||||||||
850 | // merge list level indent attributes into the item set if needed | ||||||||
851 | xTmp->MergeIndentAttrsOfListStyle( rSet ); | ||||||||
852 | } | ||||||||
853 | else if( SfxStyleFamily::Char == nFamily ) | ||||||||
854 | { | ||||||||
855 | ::ConvertAttrCharToGen(xTmp->GetItemSet()); | ||||||||
856 | } | ||||||||
857 | |||||||||
858 | if(SfxStyleFamily::Page == nFamily || SfxStyleFamily::Para == nFamily) | ||||||||
859 | { | ||||||||
860 | // create needed items for XPropertyList entries from the DrawModel so that | ||||||||
861 | // the Area TabPage can access them | ||||||||
862 | SfxItemSet& rSet = xTmp->GetItemSet(); | ||||||||
863 | const SwDrawModel* pDrawModel = GetDoc()->getIDocumentDrawModelAccess().GetDrawModel(); | ||||||||
864 | |||||||||
865 | rSet.Put(SvxColorListItem(pDrawModel->GetColorList(), SID_COLOR_TABLETypedWhichId<SvxColorListItem>( 10000 + 179 ))); | ||||||||
866 | rSet.Put(SvxGradientListItem(pDrawModel->GetGradientList(), SID_GRADIENT_LISTTypedWhichId<SvxGradientListItem>( 10000 + 180 ))); | ||||||||
867 | rSet.Put(SvxHatchListItem(pDrawModel->GetHatchList(), SID_HATCH_LISTTypedWhichId<SvxHatchListItem>( 10000 + 181 ))); | ||||||||
868 | rSet.Put(SvxBitmapListItem(pDrawModel->GetBitmapList(), SID_BITMAP_LISTTypedWhichId<SvxBitmapListItem>( 10000 + 182 ))); | ||||||||
869 | rSet.Put(SvxPatternListItem(pDrawModel->GetPatternList(), SID_PATTERN_LISTTypedWhichId<SvxPatternListItem>( 10000 + 183 ))); | ||||||||
870 | } | ||||||||
871 | |||||||||
872 | if (!bBasic) | ||||||||
873 | { | ||||||||
874 | // prior to the dialog the HtmlMode at the DocShell is being sunk | ||||||||
875 | sal_uInt16 nHtmlMode = ::GetHtmlMode(this); | ||||||||
876 | |||||||||
877 | // In HTML mode, we do not always have a printer. In order to show | ||||||||
878 | // the correct page size in the Format - Page dialog, we have to | ||||||||
879 | // get one here. | ||||||||
880 | SwWrtShell* pCurrShell = pActShell ? pActShell : m_pWrtShell; | ||||||||
881 | if( ( HTMLMODE_ON & nHtmlMode ) && | ||||||||
882 | !pCurrShell->getIDocumentDeviceAccess().getPrinter( false ) ) | ||||||||
883 | pCurrShell->InitPrt( pCurrShell->getIDocumentDeviceAccess().getPrinter( true ) ); | ||||||||
884 | |||||||||
885 | PutItem(SfxUInt16Item(SID_HTML_MODE(10000 + 414), nHtmlMode)); | ||||||||
886 | FieldUnit eMetric = ::GetDfltMetric(0 != (HTMLMODE_ON&nHtmlMode)); | ||||||||
887 | SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->PutItem(SfxUInt16Item(SID_ATTR_METRICTypedWhichId<SfxUInt16Item>(((((10000 + 1499) + 1) + 499 ) + 1) + 8), static_cast< sal_uInt16 >(eMetric))); | ||||||||
888 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | ||||||||
889 | VclPtr<SfxAbstractApplyTabDialog> pDlg(pFact->CreateTemplateDialog(GetView()->GetFrameWeld(), | ||||||||
890 | *xTmp, nFamily, sPage, pCurrShell, bNew)); | ||||||||
891 | auto pApplyStyleHelper = std::make_shared<ApplyStyle>(*this, bNew, xTmp, nFamily, pDlg.get(), m_xBasePool, bModified); | ||||||||
892 | pDlg->SetApplyHdl(LINK(pApplyStyleHelper.get(), ApplyStyle, ApplyHdl)::tools::detail::makeLink( ::tools::detail::castTo<ApplyStyle *>(pApplyStyleHelper.get()), &ApplyStyle::LinkStubApplyHdl )); | ||||||||
893 | |||||||||
894 | std::shared_ptr<SfxRequest> pRequest; | ||||||||
895 | if (pReq) | ||||||||
896 | { | ||||||||
897 | pRequest = std::make_shared<SfxRequest>(*pReq); | ||||||||
898 | pReq->Ignore(); // the 'old' request is not relevant any more | ||||||||
899 | } | ||||||||
900 | |||||||||
901 | bool bIsDefaultPage = nFamily == SfxStyleFamily::Page | ||||||||
902 | && rName == SwResId(STR_POOLPAGE_STANDARDreinterpret_cast<char const *>("STR_POOLPAGE_STANDARD" "\004" u8"Default Page Style")) | ||||||||
903 | && pStyle->IsUsed() | ||||||||
904 | && !pStyle->IsUserDefined(); | ||||||||
905 | |||||||||
906 | pDlg->StartExecuteAsync([bIsDefaultPage, bModified, bNew, nFamily, nSlot, nNewStyleUndoId, pApplyStyleHelper, pRequest, xTmp, this](sal_Int32 nResult){ | ||||||||
907 | if (RET_OK == nResult) | ||||||||
| |||||||||
908 | pApplyStyleHelper->apply(); | ||||||||
909 | |||||||||
910 | if (bNew) | ||||||||
911 | { | ||||||||
912 | switch( nFamily ) | ||||||||
913 | { | ||||||||
914 | case SfxStyleFamily::Para: | ||||||||
915 | { | ||||||||
916 | if(!xTmp->GetParent().isEmpty()) | ||||||||
917 | { | ||||||||
918 | SwTextFormatColl* pColl = m_pWrtShell->FindTextFormatCollByName(xTmp->GetParent()); | ||||||||
919 | if (GetDoc()->GetIDocumentUndoRedo().DoesUndo()) | ||||||||
920 | { | ||||||||
921 | GetDoc()->GetIDocumentUndoRedo().AppendUndo( | ||||||||
922 | std::make_unique<SwUndoTextFormatCollCreate>(xTmp->GetCollection(), pColl, *GetDoc())); | ||||||||
923 | } | ||||||||
924 | } | ||||||||
925 | } | ||||||||
926 | break; | ||||||||
927 | case SfxStyleFamily::Char: | ||||||||
928 | { | ||||||||
929 | if(!xTmp->GetParent().isEmpty()) | ||||||||
930 | { | ||||||||
931 | SwCharFormat* pCFormat = m_pWrtShell->FindCharFormatByName(xTmp->GetParent()); | ||||||||
932 | if (GetDoc()->GetIDocumentUndoRedo().DoesUndo()) | ||||||||
933 | { | ||||||||
934 | GetDoc()->GetIDocumentUndoRedo().AppendUndo( | ||||||||
935 | std::make_unique<SwUndoCharFormatCreate>(xTmp->GetCharFormat(), pCFormat, *GetDoc())); | ||||||||
936 | } | ||||||||
937 | } | ||||||||
938 | } | ||||||||
939 | break; | ||||||||
940 | case SfxStyleFamily::Frame: | ||||||||
941 | { | ||||||||
942 | if(!xTmp->GetParent().isEmpty()) | ||||||||
943 | { | ||||||||
944 | SwFrameFormat* pFFormat = m_pWrtShell->GetDoc()->FindFrameFormatByName(xTmp->GetParent()); | ||||||||
945 | if (GetDoc()->GetIDocumentUndoRedo().DoesUndo()) | ||||||||
946 | { | ||||||||
947 | GetDoc()->GetIDocumentUndoRedo().AppendUndo( | ||||||||
948 | std::make_unique<SwUndoFrameFormatCreate>(xTmp->GetFrameFormat(), pFFormat, *GetDoc())); | ||||||||
949 | } | ||||||||
950 | } | ||||||||
951 | } | ||||||||
952 | break; | ||||||||
953 | default: break; | ||||||||
954 | } | ||||||||
955 | |||||||||
956 | SwRewriter aRewriter; | ||||||||
957 | aRewriter.AddRule(UndoArg1, xTmp->GetName()); | ||||||||
958 | //Group the create style and change style operations together under the | ||||||||
959 | //one "create style" comment | ||||||||
960 | m_pWrtShell->EndUndo(nNewStyleUndoId, &aRewriter); | ||||||||
961 | } | ||||||||
962 | |||||||||
963 | if (RET_OK != nResult
| ||||||||
964 | { | ||||||||
965 | if (bNew
| ||||||||
966 | { | ||||||||
967 | GetWrtShell()->Undo(); | ||||||||
968 | m_xDoc->GetIDocumentUndoRedo().ClearRedo(); | ||||||||
969 | } | ||||||||
970 | |||||||||
971 | if (!bModified) | ||||||||
972 | m_xDoc->getIDocumentState().ResetModified(); | ||||||||
973 | } | ||||||||
974 | |||||||||
975 | // Update Watermark if new page style was created | ||||||||
976 | if (nSlot == SID_STYLE_NEW(5000 + 549) && nFamily == SfxStyleFamily::Page) | ||||||||
977 | { | ||||||||
978 | SwWrtShell* pShell = GetWrtShell(); | ||||||||
979 | const SfxWatermarkItem aWatermark = pShell->GetWatermark(); | ||||||||
980 | pShell->SetWatermark(aWatermark); | ||||||||
981 | } | ||||||||
982 | |||||||||
983 | pApplyStyleHelper->m_pDlg.disposeAndClear(); | ||||||||
984 | if (pRequest) | ||||||||
985 | pRequest->Done(); | ||||||||
986 | |||||||||
987 | if (bIsDefaultPage && bModified) | ||||||||
988 | { | ||||||||
989 | uno::Reference< style::XStyleFamiliesSupplier > xStyleFamSupp(GetModel(), uno::UNO_QUERY); | ||||||||
990 | |||||||||
991 | if (!xStyleFamSupp.is()) | ||||||||
992 | { | ||||||||
993 | SAL_WARN("sw.ui", "Ref to XStyleFamiliesSupplier is null.")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "sw.ui")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Ref to XStyleFamiliesSupplier is null.") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui"), ( "/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "993" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Ref to XStyleFamiliesSupplier is null." ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Ref to XStyleFamiliesSupplier is null."; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "993" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Ref to XStyleFamiliesSupplier is null.") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui"), ( "/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "993" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Ref to XStyleFamiliesSupplier is null." ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Ref to XStyleFamiliesSupplier is null."; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "993" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
994 | return; | ||||||||
995 | } | ||||||||
996 | |||||||||
997 | syncEndnoteOrientation(xStyleFamSupp); | ||||||||
998 | } | ||||||||
999 | }); | ||||||||
1000 | } | ||||||||
1001 | else | ||||||||
1002 | { | ||||||||
1003 | // prior to the dialog the HtmlMode at the DocShell is being sunk | ||||||||
1004 | PutItem(SfxUInt16Item(SID_HTML_MODE(10000 + 414), ::GetHtmlMode(this))); | ||||||||
1005 | |||||||||
1006 | GetWrtShell()->StartAllAction(); | ||||||||
1007 | |||||||||
1008 | if( SfxStyleFamily::Para == nFamily ) | ||||||||
1009 | ::SfxToSwPageDescAttr( *GetWrtShell(), xTmp->GetItemSet() ); | ||||||||
1010 | else | ||||||||
1011 | { | ||||||||
1012 | ::ConvertAttrGenToChar(xTmp->GetItemSet(), xTmp->GetItemSet()); | ||||||||
1013 | } | ||||||||
1014 | if(SfxStyleFamily::Page == nFamily) | ||||||||
1015 | m_pView->InvalidateRulerPos(); | ||||||||
1016 | |||||||||
1017 | if( bNew ) | ||||||||
1018 | m_xBasePool->Broadcast(SfxStyleSheetHint(SfxHintId::StyleSheetCreated, *xTmp)); | ||||||||
1019 | |||||||||
1020 | m_xDoc->getIDocumentState().SetModified(); | ||||||||
1021 | if( !bModified ) // Bug 57028 | ||||||||
1022 | { | ||||||||
1023 | m_xDoc->GetIDocumentUndoRedo().SetUndoNoResetModified(); | ||||||||
1024 | } | ||||||||
1025 | GetWrtShell()->EndAllAction(); | ||||||||
1026 | } | ||||||||
1027 | } | ||||||||
1028 | |||||||||
1029 | void SwDocShell::Delete(const OUString &rName, SfxStyleFamily nFamily) | ||||||||
1030 | { | ||||||||
1031 | SfxStyleSheetBase *pStyle = m_xBasePool->Find(rName, nFamily); | ||||||||
1032 | |||||||||
1033 | if(pStyle) | ||||||||
1034 | { | ||||||||
1035 | assert( GetWrtShell() )(static_cast <bool> (GetWrtShell()) ? void (0) : __assert_fail ("GetWrtShell()", "/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" , 1035, __extension__ __PRETTY_FUNCTION__)); | ||||||||
1036 | |||||||||
1037 | GetWrtShell()->StartAllAction(); | ||||||||
1038 | m_xBasePool->Remove(pStyle); | ||||||||
1039 | GetWrtShell()->EndAllAction(); | ||||||||
1040 | } | ||||||||
1041 | } | ||||||||
1042 | |||||||||
1043 | void SwDocShell::Hide(const OUString &rName, SfxStyleFamily nFamily, bool bHidden) | ||||||||
1044 | { | ||||||||
1045 | SfxStyleSheetBase *pStyle = m_xBasePool->Find(rName, nFamily); | ||||||||
1046 | |||||||||
1047 | if(pStyle) | ||||||||
1048 | { | ||||||||
1049 | assert( GetWrtShell() )(static_cast <bool> (GetWrtShell()) ? void (0) : __assert_fail ("GetWrtShell()", "/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" , 1049, __extension__ __PRETTY_FUNCTION__)); | ||||||||
1050 | |||||||||
1051 | GetWrtShell()->StartAllAction(); | ||||||||
1052 | rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pStyle) ) ); | ||||||||
1053 | xTmp->SetHidden( bHidden ); | ||||||||
1054 | GetWrtShell()->EndAllAction(); | ||||||||
1055 | } | ||||||||
1056 | } | ||||||||
1057 | |||||||||
1058 | // apply template | ||||||||
1059 | SfxStyleFamily SwDocShell::ApplyStyles(const OUString &rName, SfxStyleFamily nFamily, | ||||||||
1060 | SwWrtShell* pShell, const sal_uInt16 nMode ) | ||||||||
1061 | { | ||||||||
1062 | SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>( m_xBasePool->Find( rName, nFamily ) ); | ||||||||
1063 | |||||||||
1064 | SAL_WARN_IF( !pStyle, "sw.ui", "Style not found" )do { if (true && (!pStyle)) { switch (sal_detail_log_report (::SAL_DETAIL_LOG_LEVEL_WARN, "sw.ui")) { case SAL_DETAIL_LOG_ACTION_IGNORE : break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail ::getResult( ::sal::detail::StreamStart() << "Style not found" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "1064" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Style not found"), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << "Style not found"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "1064" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Style not found") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "1064" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Style not found"), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << "Style not found"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "1064" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
1065 | |||||||||
1066 | if(!pStyle) | ||||||||
1067 | return SfxStyleFamily::None; | ||||||||
1068 | |||||||||
1069 | SwWrtShell *pSh = pShell ? pShell : GetWrtShell(); | ||||||||
1070 | |||||||||
1071 | assert( pSh )(static_cast <bool> (pSh) ? void (0) : __assert_fail ("pSh" , "/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" , 1071, __extension__ __PRETTY_FUNCTION__)); | ||||||||
1072 | |||||||||
1073 | pSh->StartAllAction(); | ||||||||
1074 | |||||||||
1075 | switch (nFamily) | ||||||||
1076 | { | ||||||||
1077 | case SfxStyleFamily::Char: | ||||||||
1078 | { | ||||||||
1079 | SwFormatCharFormat aFormat(pStyle->GetCharFormat()); | ||||||||
1080 | pSh->SetAttrItem( aFormat, (nMode & KEY_SHIFT) ? | ||||||||
1081 | SetAttrMode::DONTREPLACE : SetAttrMode::DEFAULT ); | ||||||||
1082 | break; | ||||||||
1083 | } | ||||||||
1084 | case SfxStyleFamily::Para: | ||||||||
1085 | { | ||||||||
1086 | // #i62675# | ||||||||
1087 | // clear also list attributes at affected text nodes, if paragraph | ||||||||
1088 | // style has the list style attribute set. | ||||||||
1089 | pSh->SetTextFormatColl( pStyle->GetCollection(), true ); | ||||||||
1090 | break; | ||||||||
1091 | } | ||||||||
1092 | case SfxStyleFamily::Frame: | ||||||||
1093 | { | ||||||||
1094 | if ( pSh->IsFrameSelected() ) | ||||||||
1095 | pSh->SetFrameFormat( pStyle->GetFrameFormat() ); | ||||||||
1096 | break; | ||||||||
1097 | } | ||||||||
1098 | case SfxStyleFamily::Page: | ||||||||
1099 | { | ||||||||
1100 | pSh->SetPageStyle(pStyle->GetPageDesc()->GetName()); | ||||||||
1101 | break; | ||||||||
1102 | } | ||||||||
1103 | case SfxStyleFamily::Pseudo: | ||||||||
1104 | { | ||||||||
1105 | // reset indent attribute on applying list style | ||||||||
1106 | // continue list of list style | ||||||||
1107 | const SwNumRule* pNumRule = pStyle->GetNumRule(); | ||||||||
1108 | const OUString sListIdForStyle =pNumRule->GetDefaultListId(); | ||||||||
1109 | pSh->SetCurNumRule( *pNumRule, false, sListIdForStyle, true ); | ||||||||
1110 | break; | ||||||||
1111 | } | ||||||||
1112 | case SfxStyleFamily::Table: | ||||||||
1113 | { | ||||||||
1114 | pSh->SetTableStyle(pStyle->GetName()); | ||||||||
1115 | break; | ||||||||
1116 | } | ||||||||
1117 | default: | ||||||||
1118 | OSL_FAIL("Unknown family")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "1118" ": "), "%s", "Unknown family"); } } while (false); | ||||||||
1119 | } | ||||||||
1120 | pSh->EndAllAction(); | ||||||||
1121 | |||||||||
1122 | return nFamily; | ||||||||
1123 | } | ||||||||
1124 | |||||||||
1125 | // start watering-can | ||||||||
1126 | SfxStyleFamily SwDocShell::DoWaterCan(const OUString &rName, SfxStyleFamily nFamily) | ||||||||
1127 | { | ||||||||
1128 | assert( GetWrtShell() )(static_cast <bool> (GetWrtShell()) ? void (0) : __assert_fail ("GetWrtShell()", "/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" , 1128, __extension__ __PRETTY_FUNCTION__)); | ||||||||
1129 | |||||||||
1130 | SwEditWin& rEdtWin = m_pView->GetEditWin(); | ||||||||
1131 | SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate(); | ||||||||
1132 | bool bWaterCan = !(pApply && pApply->eType != SfxStyleFamily(0)); | ||||||||
1133 | |||||||||
1134 | if( rName.isEmpty() ) | ||||||||
1135 | bWaterCan = false; | ||||||||
1136 | |||||||||
1137 | SwApplyTemplate aTemplate; | ||||||||
1138 | aTemplate.eType = nFamily; | ||||||||
1139 | |||||||||
1140 | if(bWaterCan) | ||||||||
1141 | { | ||||||||
1142 | SwDocStyleSheet* pStyle = | ||||||||
1143 | static_cast<SwDocStyleSheet*>( m_xBasePool->Find(rName, nFamily) ); | ||||||||
1144 | |||||||||
1145 | SAL_WARN_IF( !pStyle, "sw.ui", "Where's the StyleSheet" )do { if (true && (!pStyle)) { switch (sal_detail_log_report (::SAL_DETAIL_LOG_LEVEL_WARN, "sw.ui")) { case SAL_DETAIL_LOG_ACTION_IGNORE : break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail ::getResult( ::sal::detail::StreamStart() << "Where's the StyleSheet" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "1145" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Where's the StyleSheet"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Where's the StyleSheet"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "1145" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Where's the StyleSheet") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "1145" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Where's the StyleSheet"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Where's the StyleSheet"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "1145" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
1146 | |||||||||
1147 | if(!pStyle) return nFamily; | ||||||||
1148 | |||||||||
1149 | switch(nFamily) | ||||||||
1150 | { | ||||||||
1151 | case SfxStyleFamily::Char: | ||||||||
1152 | aTemplate.aColl.pCharFormat = pStyle->GetCharFormat(); | ||||||||
1153 | break; | ||||||||
1154 | case SfxStyleFamily::Para: | ||||||||
1155 | aTemplate.aColl.pTextColl = pStyle->GetCollection(); | ||||||||
1156 | break; | ||||||||
1157 | case SfxStyleFamily::Frame: | ||||||||
1158 | aTemplate.aColl.pFrameFormat = pStyle->GetFrameFormat(); | ||||||||
1159 | break; | ||||||||
1160 | case SfxStyleFamily::Page: | ||||||||
1161 | aTemplate.aColl.pPageDesc = const_cast<SwPageDesc*>(pStyle->GetPageDesc()); | ||||||||
1162 | break; | ||||||||
1163 | case SfxStyleFamily::Pseudo: | ||||||||
1164 | aTemplate.aColl.pNumRule = const_cast<SwNumRule*>(pStyle->GetNumRule()); | ||||||||
1165 | break; | ||||||||
1166 | |||||||||
1167 | default: | ||||||||
1168 | OSL_FAIL("Unknown family")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" ":" "1168" ": "), "%s", "Unknown family"); } } while (false); | ||||||||
1169 | } | ||||||||
1170 | } | ||||||||
1171 | else | ||||||||
1172 | aTemplate.eType = SfxStyleFamily(0); | ||||||||
1173 | |||||||||
1174 | m_pView->GetEditWin().SetApplyTemplate(aTemplate); | ||||||||
1175 | |||||||||
1176 | return nFamily; | ||||||||
1177 | } | ||||||||
1178 | |||||||||
1179 | // update template | ||||||||
1180 | void SwDocShell::UpdateStyle(const OUString &rName, SfxStyleFamily nFamily, SwWrtShell* pShell) | ||||||||
1181 | { | ||||||||
1182 | SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell(); | ||||||||
1183 | assert( pCurrWrtShell )(static_cast <bool> (pCurrWrtShell) ? void (0) : __assert_fail ("pCurrWrtShell", "/home/maarten/src/libreoffice/core/sw/source/uibase/app/docst.cxx" , 1183, __extension__ __PRETTY_FUNCTION__)); | ||||||||
1184 | |||||||||
1185 | SwDocStyleSheet* pStyle = | ||||||||
1186 | static_cast<SwDocStyleSheet*>( m_xBasePool->Find(rName, nFamily) ); | ||||||||
1187 | |||||||||
1188 | if (!pStyle) | ||||||||
1189 | return; | ||||||||
1190 | |||||||||
1191 | switch(nFamily) | ||||||||
1192 | { | ||||||||
1193 | case SfxStyleFamily::Para: | ||||||||
1194 | { | ||||||||
1195 | SwTextFormatColl* pColl = pStyle->GetCollection(); | ||||||||
1196 | if(pColl && !pColl->IsDefault()) | ||||||||
1197 | { | ||||||||
1198 | GetWrtShell()->StartAllAction(); | ||||||||
1199 | |||||||||
1200 | SwRewriter aRewriter; | ||||||||
1201 | aRewriter.AddRule(UndoArg1, pColl->GetName()); | ||||||||
1202 | |||||||||
1203 | GetWrtShell()->StartUndo(SwUndoId::INSFMTATTR, &aRewriter); | ||||||||
1204 | GetWrtShell()->FillByEx(pColl); | ||||||||
1205 | // also apply template to remove hard set attributes | ||||||||
1206 | GetWrtShell()->SetTextFormatColl( pColl ); | ||||||||
1207 | GetWrtShell()->EndUndo(); | ||||||||
1208 | GetWrtShell()->EndAllAction(); | ||||||||
1209 | } | ||||||||
1210 | break; | ||||||||
1211 | } | ||||||||
1212 | case SfxStyleFamily::Frame: | ||||||||
1213 | { | ||||||||
1214 | SwFrameFormat* pFrame = pStyle->GetFrameFormat(); | ||||||||
1215 | if( pCurrWrtShell->IsFrameSelected() && pFrame && !pFrame->IsDefault() ) | ||||||||
1216 | { | ||||||||
1217 | SfxItemSet aSet( GetPool(), aFrameFormatSetRange ); | ||||||||
1218 | pCurrWrtShell->StartAllAction(); | ||||||||
1219 | pCurrWrtShell->GetFlyFrameAttr( aSet ); | ||||||||
1220 | |||||||||
1221 | // #i105535# | ||||||||
1222 | // no update of anchor attribute | ||||||||
1223 | aSet.ClearItem( RES_ANCHOR ); | ||||||||
1224 | |||||||||
1225 | pFrame->SetFormatAttr( aSet ); | ||||||||
1226 | |||||||||
1227 | // also apply template to remove hard set attributes | ||||||||
1228 | pCurrWrtShell->SetFrameFormat( pFrame, true ); | ||||||||
1229 | pCurrWrtShell->EndAllAction(); | ||||||||
1230 | } | ||||||||
1231 | } | ||||||||
1232 | break; | ||||||||
1233 | case SfxStyleFamily::Char: | ||||||||
1234 | { | ||||||||
1235 | SwCharFormat* pChar = pStyle->GetCharFormat(); | ||||||||
1236 | if( pChar && !pChar->IsDefault() ) | ||||||||
1237 | { | ||||||||
1238 | pCurrWrtShell->StartAllAction(); | ||||||||
1239 | pCurrWrtShell->FillByEx(pChar); | ||||||||
1240 | // also apply template to remove hard set attributes | ||||||||
1241 | pCurrWrtShell->EndAllAction(); | ||||||||
1242 | } | ||||||||
1243 | |||||||||
1244 | } | ||||||||
1245 | break; | ||||||||
1246 | case SfxStyleFamily::Pseudo: | ||||||||
1247 | { | ||||||||
1248 | const SwNumRule* pCurRule; | ||||||||
1249 | if( pStyle->GetNumRule() && | ||||||||
1250 | nullptr != ( pCurRule = pCurrWrtShell->GetNumRuleAtCurrCursorPos() )) | ||||||||
1251 | { | ||||||||
1252 | SwNumRule aRule( *pCurRule ); | ||||||||
1253 | // #i91400# | ||||||||
1254 | aRule.SetName( pStyle->GetNumRule()->GetName(), | ||||||||
1255 | pCurrWrtShell->GetDoc()->getIDocumentListsAccess() ); | ||||||||
1256 | pCurrWrtShell->ChgNumRuleFormats( aRule ); | ||||||||
1257 | } | ||||||||
1258 | } | ||||||||
1259 | break; | ||||||||
1260 | case SfxStyleFamily::Table: | ||||||||
1261 | { | ||||||||
1262 | |||||||||
1263 | SwTableAutoFormat aFormat(rName); | ||||||||
1264 | if (pCurrWrtShell->GetTableAutoFormat(aFormat)) | ||||||||
1265 | { | ||||||||
1266 | pCurrWrtShell->StartAllAction(); | ||||||||
1267 | pCurrWrtShell->GetDoc()->ChgTableStyle(rName, aFormat); | ||||||||
1268 | pCurrWrtShell->EndAllAction(); | ||||||||
1269 | } | ||||||||
1270 | |||||||||
1271 | } | ||||||||
1272 | break; | ||||||||
1273 | default: break; | ||||||||
1274 | } | ||||||||
1275 | } | ||||||||
1276 | |||||||||
1277 | // NewByExample | ||||||||
1278 | void SwDocShell::MakeByExample( const OUString &rName, SfxStyleFamily nFamily, | ||||||||
1279 | SfxStyleSearchBits nMask, SwWrtShell* pShell ) | ||||||||
1280 | { | ||||||||
1281 | SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell(); | ||||||||
1282 | SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>( m_xBasePool->Find( | ||||||||
1283 | rName, nFamily ) ); | ||||||||
1284 | if(!pStyle) | ||||||||
1285 | { | ||||||||
1286 | // preserve the current mask of PI, then the new one is | ||||||||
1287 | // immediately merged with the viewable area | ||||||||
1288 | if( SfxStyleSearchBits::All == nMask || SfxStyleSearchBits::Used == nMask ) | ||||||||
1289 | nMask = SfxStyleSearchBits::UserDefined; | ||||||||
1290 | else | ||||||||
1291 | nMask |= SfxStyleSearchBits::UserDefined; | ||||||||
1292 | |||||||||
1293 | if (nFamily == SfxStyleFamily::Para || nFamily == SfxStyleFamily::Char || nFamily == SfxStyleFamily::Frame) | ||||||||
1294 | { | ||||||||
1295 | // Prevent undo append from being done during paragraph, character, and frame style Make. Do it later | ||||||||
1296 | ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo()); | ||||||||
1297 | pStyle = static_cast<SwDocStyleSheet*>(&m_xBasePool->Make(rName, nFamily, nMask)); | ||||||||
1298 | } | ||||||||
1299 | else | ||||||||
1300 | { | ||||||||
1301 | pStyle = static_cast<SwDocStyleSheet*>(&m_xBasePool->Make(rName, nFamily, nMask)); | ||||||||
1302 | } | ||||||||
1303 | } | ||||||||
1304 | |||||||||
1305 | switch(nFamily) | ||||||||
1306 | { | ||||||||
1307 | case SfxStyleFamily::Para: | ||||||||
1308 | { | ||||||||
1309 | SwTextFormatColl* pColl = pStyle->GetCollection(); | ||||||||
1310 | if(pColl && !pColl->IsDefault()) | ||||||||
1311 | { | ||||||||
1312 | pCurrWrtShell->StartAllAction(); | ||||||||
1313 | pCurrWrtShell->FillByEx(pColl); | ||||||||
1314 | // also apply template to remove hard set attributes | ||||||||
1315 | SwTextFormatColl * pDerivedFrom = pCurrWrtShell->GetCurTextFormatColl(); | ||||||||
1316 | pColl->SetDerivedFrom(pDerivedFrom); | ||||||||
1317 | |||||||||
1318 | // set the mask at the Collection: | ||||||||
1319 | sal_uInt16 nId = pColl->GetPoolFormatId() & 0x87ff; | ||||||||
1320 | switch( nMask & static_cast<SfxStyleSearchBits>(0x0fff) ) | ||||||||
1321 | { | ||||||||
1322 | case SfxStyleSearchBits::SwText: | ||||||||
1323 | nId |= COLL_TEXT_BITS; | ||||||||
1324 | break; | ||||||||
1325 | case SfxStyleSearchBits::SwChapter: | ||||||||
1326 | nId |= COLL_DOC_BITS; | ||||||||
1327 | break; | ||||||||
1328 | case SfxStyleSearchBits::SwList: | ||||||||
1329 | nId |= COLL_LISTS_BITS; | ||||||||
1330 | break; | ||||||||
1331 | case SfxStyleSearchBits::SwIndex: | ||||||||
1332 | nId |= COLL_REGISTER_BITS; | ||||||||
1333 | break; | ||||||||
1334 | case SfxStyleSearchBits::SwExtra: | ||||||||
1335 | nId |= COLL_EXTRA_BITS; | ||||||||
1336 | break; | ||||||||
1337 | case SfxStyleSearchBits::SwHtml: | ||||||||
1338 | nId |= COLL_HTML_BITS; | ||||||||
1339 | break; | ||||||||
1340 | default: break; | ||||||||
1341 | } | ||||||||
1342 | pColl->SetPoolFormatId(nId); | ||||||||
1343 | |||||||||
1344 | if (GetDoc()->GetIDocumentUndoRedo().DoesUndo()) | ||||||||
1345 | { | ||||||||
1346 | GetDoc()->GetIDocumentUndoRedo().AppendUndo( | ||||||||
1347 | std::make_unique<SwUndoTextFormatCollCreate>(pColl, pDerivedFrom, *GetDoc())); | ||||||||
1348 | } | ||||||||
1349 | pCurrWrtShell->SetTextFormatColl(pColl); | ||||||||
1350 | pCurrWrtShell->EndAllAction(); | ||||||||
1351 | } | ||||||||
1352 | } | ||||||||
1353 | break; | ||||||||
1354 | case SfxStyleFamily::Frame: | ||||||||
1355 | { | ||||||||
1356 | SwFrameFormat* pFrame = pStyle->GetFrameFormat(); | ||||||||
1357 | if(pCurrWrtShell->IsFrameSelected() && pFrame && !pFrame->IsDefault()) | ||||||||
1358 | { | ||||||||
1359 | pCurrWrtShell->StartAllAction(); | ||||||||
1360 | |||||||||
1361 | SfxItemSet aSet(GetPool(), aFrameFormatSetRange ); | ||||||||
1362 | pCurrWrtShell->GetFlyFrameAttr( aSet ); | ||||||||
1363 | aSet.ClearItem(RES_ANCHOR); // tdf#112574 no anchor in styles | ||||||||
1364 | |||||||||
1365 | SwFrameFormat* pFFormat = pCurrWrtShell->GetSelectedFrameFormat(); | ||||||||
1366 | pFrame->SetDerivedFrom( pFFormat ); | ||||||||
1367 | pFrame->SetFormatAttr( aSet ); | ||||||||
1368 | if (GetDoc()->GetIDocumentUndoRedo().DoesUndo()) | ||||||||
1369 | { | ||||||||
1370 | GetDoc()->GetIDocumentUndoRedo().AppendUndo( | ||||||||
1371 | std::make_unique<SwUndoFrameFormatCreate>(pFrame, pFFormat, *GetDoc())); | ||||||||
1372 | } | ||||||||
1373 | // also apply template to remove hard set attributes | ||||||||
1374 | pCurrWrtShell->SetFrameFormat(pFrame); | ||||||||
1375 | pCurrWrtShell->EndAllAction(); | ||||||||
1376 | } | ||||||||
1377 | } | ||||||||
1378 | break; | ||||||||
1379 | case SfxStyleFamily::Char: | ||||||||
1380 | { | ||||||||
1381 | SwCharFormat* pChar = pStyle->GetCharFormat(); | ||||||||
1382 | if(pChar && !pChar->IsDefault()) | ||||||||
1383 | { | ||||||||
1384 | pCurrWrtShell->StartAllAction(); | ||||||||
1385 | pCurrWrtShell->FillByEx( pChar ); | ||||||||
1386 | SwCharFormat * pDerivedFrom = pCurrWrtShell->GetCurCharFormat(); | ||||||||
1387 | pChar->SetDerivedFrom( pDerivedFrom ); | ||||||||
1388 | SwFormatCharFormat aFormat( pChar ); | ||||||||
1389 | |||||||||
1390 | if (GetDoc()->GetIDocumentUndoRedo().DoesUndo()) | ||||||||
1391 | { | ||||||||
1392 | // Looks like sometimes pDerivedFrom can be null and this is not supported by redo code | ||||||||
1393 | // So use default format as a derived from in such situations | ||||||||
1394 | GetDoc()->GetIDocumentUndoRedo().AppendUndo( | ||||||||
1395 | std::make_unique<SwUndoCharFormatCreate>( | ||||||||
1396 | pChar, pDerivedFrom ? pDerivedFrom : GetDoc()->GetDfltCharFormat(), | ||||||||
1397 | *GetDoc())); | ||||||||
1398 | } | ||||||||
1399 | pCurrWrtShell->SetAttrItem(aFormat); | ||||||||
1400 | pCurrWrtShell->EndAllAction(); | ||||||||
1401 | } | ||||||||
1402 | } | ||||||||
1403 | break; | ||||||||
1404 | |||||||||
1405 | case SfxStyleFamily::Page: | ||||||||
1406 | { | ||||||||
1407 | pCurrWrtShell->StartAllAction(); | ||||||||
1408 | size_t nPgDsc = pCurrWrtShell->GetCurPageDesc(); | ||||||||
1409 | SwPageDesc& rSrc = const_cast<SwPageDesc&>(pCurrWrtShell->GetPageDesc( nPgDsc )); | ||||||||
1410 | SwPageDesc& rDest = *const_cast<SwPageDesc*>(pStyle->GetPageDesc()); | ||||||||
1411 | |||||||||
1412 | sal_uInt16 nPoolId = rDest.GetPoolFormatId(); | ||||||||
1413 | sal_uInt16 nHId = rDest.GetPoolHelpId(); | ||||||||
1414 | sal_uInt8 nHFId = rDest.GetPoolHlpFileId(); | ||||||||
1415 | |||||||||
1416 | pCurrWrtShell->GetDoc()->CopyPageDesc( rSrc, rDest ); | ||||||||
1417 | |||||||||
1418 | // PoolId must NEVER be copied! | ||||||||
1419 | rDest.SetPoolFormatId( nPoolId ); | ||||||||
1420 | rDest.SetPoolHelpId( nHId ); | ||||||||
1421 | rDest.SetPoolHlpFileId( nHFId ); | ||||||||
1422 | |||||||||
1423 | // when Headers/Footers are created, there is no Undo anymore! | ||||||||
1424 | pCurrWrtShell->GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj(); | ||||||||
1425 | |||||||||
1426 | pCurrWrtShell->EndAllAction(); | ||||||||
1427 | } | ||||||||
1428 | break; | ||||||||
1429 | |||||||||
1430 | case SfxStyleFamily::Pseudo: | ||||||||
1431 | { | ||||||||
1432 | const SwNumRule* pCurRule = pCurrWrtShell->GetNumRuleAtCurrCursorPos(); | ||||||||
1433 | |||||||||
1434 | if (pCurRule) | ||||||||
1435 | { | ||||||||
1436 | pCurrWrtShell->StartAllAction(); | ||||||||
1437 | |||||||||
1438 | SwNumRule aRule( *pCurRule ); | ||||||||
1439 | OUString sOrigRule( aRule.GetName() ); | ||||||||
1440 | // #i91400# | ||||||||
1441 | aRule.SetName( pStyle->GetNumRule()->GetName(), | ||||||||
1442 | pCurrWrtShell->GetDoc()->getIDocumentListsAccess() ); | ||||||||
1443 | pCurrWrtShell->ChgNumRuleFormats( aRule ); | ||||||||
1444 | |||||||||
1445 | pCurrWrtShell->ReplaceNumRule( sOrigRule, aRule.GetName() ); | ||||||||
1446 | |||||||||
1447 | pCurrWrtShell->EndAllAction(); | ||||||||
1448 | } | ||||||||
1449 | } | ||||||||
1450 | break; | ||||||||
1451 | |||||||||
1452 | case SfxStyleFamily::Table: | ||||||||
1453 | { | ||||||||
1454 | SwTableAutoFormat* pFormat = pStyle->GetTableFormat(); | ||||||||
1455 | if (pCurrWrtShell->GetTableAutoFormat(*pFormat)) | ||||||||
1456 | { | ||||||||
1457 | pCurrWrtShell->StartAllAction(); | ||||||||
1458 | |||||||||
1459 | pCurrWrtShell->SetTableStyle(rName); | ||||||||
1460 | |||||||||
1461 | pCurrWrtShell->EndAllAction(); | ||||||||
1462 | } | ||||||||
1463 | } | ||||||||
1464 | break; | ||||||||
1465 | |||||||||
1466 | default: break; | ||||||||
1467 | } | ||||||||
1468 | } | ||||||||
1469 | |||||||||
1470 | sfx::AccessibilityIssueCollection SwDocShell::runAccessibilityCheck() | ||||||||
1471 | { | ||||||||
1472 | sw::AccessibilityCheck aCheck(m_xDoc.get()); | ||||||||
1473 | aCheck.check(); | ||||||||
1474 | return aCheck.getIssueCollection(); | ||||||||
1475 | } | ||||||||
1476 | |||||||||
1477 | std::set<Color> SwDocShell::GetDocColors() | ||||||||
1478 | { | ||||||||
1479 | return m_xDoc->GetDocColors(); | ||||||||
1480 | } | ||||||||
1481 | |||||||||
1482 | void SwDocShell::LoadStyles( SfxObjectShell& rSource ) | ||||||||
1483 | { | ||||||||
1484 | LoadStyles_(rSource, false); | ||||||||
1485 | } | ||||||||
1486 | |||||||||
1487 | // bPreserveCurrentDocument determines whether SetFixFields() is called | ||||||||
1488 | // This call modifies the source document. This mustn't happen when the source | ||||||||
1489 | // is a document the user is working on. | ||||||||
1490 | // Calls of ::LoadStyles() normally use files especially loaded for the purpose | ||||||||
1491 | // of importing styles. | ||||||||
1492 | void SwDocShell::LoadStyles_( SfxObjectShell& rSource, bool bPreserveCurrentDocument ) | ||||||||
1493 | { | ||||||||
1494 | /* [Description] | ||||||||
1495 | |||||||||
1496 | This method is called by SFx if Styles have to be reloaded from a | ||||||||
1497 | document-template. Existing Styles should be overwritten by that. | ||||||||
1498 | That's why the document has to be reformatted. Therefore applications | ||||||||
1499 | will usually override this method and call the baseclass' implementation | ||||||||
1500 | in their implementation. | ||||||||
1501 | */ | ||||||||
1502 | // When the source is our document, we do the checking ourselves | ||||||||
1503 | // (much quicker and doesn't use the crutch StxStylePool). | ||||||||
1504 | if( dynamic_cast<const SwDocShell*>( &rSource) != nullptr) | ||||||||
1505 | { | ||||||||
1506 | // in order for the Headers/Footers not to get the fixed content | ||||||||
1507 | // of the template, update all the Source's | ||||||||
1508 | // FixFields once. | ||||||||
1509 | if(!bPreserveCurrentDocument) | ||||||||
1510 | static_cast<SwDocShell&>(rSource).m_xDoc->getIDocumentFieldsAccess().SetFixFields(nullptr); | ||||||||
1511 | if (m_pWrtShell) | ||||||||
1512 | { | ||||||||
1513 | // rhbz#818557, fdo#58893: EndAllAction will call SelectShell(), | ||||||||
1514 | // which pushes a bunch of SfxShells that are not cleared | ||||||||
1515 | // (for unknown reasons) when closing the document, causing crash; | ||||||||
1516 | // setting g_bNoInterrupt appears to avoid the problem. | ||||||||
1517 | ::comphelper::FlagRestorationGuard g(g_bNoInterrupt, true); | ||||||||
1518 | m_pWrtShell->StartAllAction(); | ||||||||
1519 | m_xDoc->ReplaceStyles( *static_cast<SwDocShell&>(rSource).m_xDoc ); | ||||||||
1520 | m_pWrtShell->EndAllAction(); | ||||||||
1521 | } | ||||||||
1522 | else | ||||||||
1523 | { | ||||||||
1524 | bool bModified = m_xDoc->getIDocumentState().IsModified(); | ||||||||
1525 | m_xDoc->ReplaceStyles( *static_cast<SwDocShell&>(rSource).m_xDoc ); | ||||||||
1526 | if (!bModified && m_xDoc->getIDocumentState().IsModified() && !m_pView) | ||||||||
1527 | { | ||||||||
1528 | // the View is created later, but overwrites the Modify-Flag. | ||||||||
1529 | // Undo doesn't work anymore anyways. | ||||||||
1530 | m_xDoc->GetIDocumentUndoRedo().SetUndoNoResetModified(); | ||||||||
1531 | } | ||||||||
1532 | } | ||||||||
1533 | } | ||||||||
1534 | else | ||||||||
1535 | SfxObjectShell::LoadStyles( rSource ); | ||||||||
1536 | } | ||||||||
1537 | |||||||||
1538 | void SwDocShell::FormatPage( | ||||||||
1539 | const OUString& rPage, | ||||||||
1540 | const OString& rPageId, | ||||||||
1541 | SwWrtShell& rActShell, | ||||||||
1542 | SfxRequest* pRequest) | ||||||||
1543 | { | ||||||||
1544 | Edit(rPage, OUString(), SfxStyleFamily::Page, SfxStyleSearchBits::Auto, false, rPageId, &rActShell, pRequest); | ||||||||
1545 | } | ||||||||
1546 | |||||||||
1547 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_PTR_HXX |
21 | #define INCLUDED_VCL_PTR_HXX |
22 | |
23 | #include <sal/config.h> |
24 | |
25 | #include <rtl/ref.hxx> |
26 | |
27 | #include <utility> |
28 | #include <type_traits> |
29 | |
30 | #ifdef DBG_UTIL |
31 | #ifndef _WIN32 |
32 | #include <vcl/vclmain.hxx> |
33 | #endif |
34 | #endif |
35 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase( |
44 | int (*)[sizeof(T)]) |
45 | { return std::is_base_of<VclReferenceBase, T>::value; } |
46 | |
47 | } // namespace vcl::detail |
48 | |
49 | /** |
50 | * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses. |
51 | * |
52 | * For more details on the design please see vcl/README.lifecycle |
53 | * |
54 | * @param reference_type must be a subclass of vcl::Window |
55 | */ |
56 | template <class reference_type> |
57 | class VclPtr |
58 | { |
59 | static_assert( |
60 | vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>( |
61 | nullptr), |
62 | "template argument type must be derived from VclReferenceBase"); |
63 | |
64 | ::rtl::Reference<reference_type> m_rInnerRef; |
65 | |
66 | public: |
67 | /** Constructor... |
68 | */ |
69 | VclPtr() |
70 | : m_rInnerRef() |
71 | {} |
72 | |
73 | /** Constructor... |
74 | */ |
75 | VclPtr (reference_type * pBody) |
76 | : m_rInnerRef(pBody) |
77 | {} |
78 | |
79 | /** Constructor... that doesn't take a ref. |
80 | */ |
81 | VclPtr (reference_type * pBody, __sal_NoAcquire) |
82 | : m_rInnerRef(pBody, SAL_NO_ACQUIRE) |
83 | {} |
84 | |
85 | /** Up-casting conversion constructor: Copies interface reference. |
86 | |
87 | Does not work for up-casts to ambiguous bases. For the special case of |
88 | up-casting to Reference< XInterface >, see the corresponding conversion |
89 | operator. |
90 | |
91 | @param rRef another reference |
92 | */ |
93 | template< class derived_type > |
94 | VclPtr( |
95 | const VclPtr< derived_type > & rRef, |
96 | typename std::enable_if< |
97 | std::is_base_of<reference_type, derived_type>::value, int>::type |
98 | = 0 ) |
99 | : m_rInnerRef( static_cast<reference_type*>(rRef) ) |
100 | { |
101 | } |
102 | |
103 | #if defined(DBG_UTIL) && !defined(_WIN32) |
104 | virtual ~VclPtr() |
105 | { |
106 | assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain ::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 106, __extension__ __PRETTY_FUNCTION__)); |
107 | // We can be one of the intermediate counts, but if we are the last |
108 | // VclPtr keeping this object alive, then something forgot to call dispose(). |
109 | assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)) |
110 | && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)); |
111 | } |
112 | VclPtr(VclPtr const &) = default; |
113 | VclPtr(VclPtr &&) = default; |
114 | VclPtr & operator =(VclPtr const &) = default; |
115 | VclPtr & operator =(VclPtr &&) = default; |
116 | #endif |
117 | |
118 | /** |
119 | * A construction helper for VclPtr. Since VclPtr types are created |
120 | * with a reference-count of one - to help fit into the existing |
121 | * code-flow; this helps us to construct them easily. |
122 | * |
123 | * For more details on the design please see vcl/README.lifecycle |
124 | * |
125 | * @tparam reference_type must be a subclass of vcl::Window |
126 | */ |
127 | template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg) |
128 | { |
129 | return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ); |
130 | } |
131 | |
132 | /** Probably most common used: handle->someBodyOp(). |
133 | */ |
134 | reference_type * operator->() const |
135 | { |
136 | return m_rInnerRef.get(); |
137 | } |
138 | |
139 | /** Get the body. Can be used instead of operator->(). |
140 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
141 | are the same. |
142 | */ |
143 | reference_type * get() const |
144 | { |
145 | return m_rInnerRef.get(); |
146 | } |
147 | |
148 | void set(reference_type *pBody) |
149 | { |
150 | m_rInnerRef.set(pBody); |
151 | } |
152 | |
153 | void reset(reference_type *pBody) |
154 | { |
155 | m_rInnerRef.set(pBody); |
156 | } |
157 | |
158 | /** Up-casting copy assignment operator. |
159 | |
160 | Does not work for up-casts to ambiguous bases. |
161 | |
162 | @param rRef another reference |
163 | */ |
164 | template<typename derived_type> |
165 | typename std::enable_if< |
166 | std::is_base_of<reference_type, derived_type>::value, |
167 | VclPtr &>::type |
168 | operator =(VclPtr<derived_type> const & rRef) |
169 | { |
170 | m_rInnerRef.set(rRef.get()); |
171 | return *this; |
172 | } |
173 | |
174 | VclPtr & operator =(reference_type * pBody) |
175 | { |
176 | m_rInnerRef.set(pBody); |
177 | return *this; |
178 | } |
179 | |
180 | operator reference_type * () const |
181 | { |
182 | return m_rInnerRef.get(); |
183 | } |
184 | |
185 | explicit operator bool () const |
186 | { |
187 | return m_rInnerRef.get() != nullptr; |
188 | } |
189 | |
190 | void clear() |
191 | { |
192 | m_rInnerRef.clear(); |
193 | } |
194 | |
195 | void reset() |
196 | { |
197 | m_rInnerRef.clear(); |
198 | } |
199 | |
200 | void disposeAndClear() |
201 | { |
202 | // hold it alive for the lifetime of this method |
203 | ::rtl::Reference<reference_type> aTmp(m_rInnerRef); |
204 | m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-) |
205 | if (aTmp.get()) { |
206 | aTmp->disposeOnce(); |
207 | } |
208 | } |
209 | |
210 | /** Needed to place VclPtr's into STL collection. |
211 | */ |
212 | bool operator< (const VclPtr<reference_type> & handle) const |
213 | { |
214 | return (m_rInnerRef < handle.m_rInnerRef); |
215 | } |
216 | }; // class VclPtr |
217 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) { |
261 | return !(p1 == p2); |
262 | } |
263 | |
264 | /** |
265 | * A construction helper for a temporary VclPtr. Since VclPtr types |
266 | * are created with a reference-count of one - to help fit into |
267 | * the existing code-flow; this helps us to construct them easily. |
268 | * see also VclPtr::Create and ScopedVclPtr |
269 | * |
270 | * For more details on the design please see vcl/README.lifecycle |
271 | * |
272 | * @param reference_type must be a subclass of vcl::Window |
273 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
278 | template<typename... Arg> VclPtrInstance(Arg &&... arg) |
279 | : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
280 | { |
281 | } |
282 | |
283 | /** |
284 | * Override and disallow this, to prevent people accidentally calling it and actually |
285 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
286 | */ |
287 | template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete; |
288 | }; |
289 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
294 | /** Constructor... |
295 | */ |
296 | ScopedVclPtr() |
297 | : VclPtr<reference_type>() |
298 | {} |
299 | |
300 | /** Constructor |
301 | */ |
302 | ScopedVclPtr (reference_type * pBody) |
303 | : VclPtr<reference_type>(pBody) |
304 | {} |
305 | |
306 | /** Copy constructor... |
307 | */ |
308 | ScopedVclPtr (const VclPtr<reference_type> & handle) |
309 | : VclPtr<reference_type>(handle) |
310 | {} |
311 | |
312 | /** |
313 | Assignment that releases the last reference. |
314 | */ |
315 | void disposeAndReset(reference_type *pBody) |
316 | { |
317 | if (pBody != this->get()) { |
318 | VclPtr<reference_type>::disposeAndClear(); |
319 | VclPtr<reference_type>::set(pBody); |
320 | } |
321 | } |
322 | |
323 | /** |
324 | Assignment that releases the last reference. |
325 | */ |
326 | ScopedVclPtr<reference_type>& operator = (reference_type * pBody) |
327 | { |
328 | disposeAndReset(pBody); |
329 | return *this; |
330 | } |
331 | |
332 | /** Up-casting conversion constructor: Copies interface reference. |
333 | |
334 | Does not work for up-casts to ambiguous bases. For the special case of |
335 | up-casting to Reference< XInterface >, see the corresponding conversion |
336 | operator. |
337 | |
338 | @param rRef another reference |
339 | */ |
340 | template< class derived_type > |
341 | ScopedVclPtr( |
342 | const VclPtr< derived_type > & rRef, |
343 | typename std::enable_if< |
344 | std::is_base_of<reference_type, derived_type>::value, int>::type |
345 | = 0 ) |
346 | : VclPtr<reference_type>( rRef ) |
347 | { |
348 | } |
349 | |
350 | /** Up-casting assignment operator. |
351 | |
352 | Does not work for up-casts to ambiguous bases. |
353 | |
354 | @param rRef another VclPtr |
355 | */ |
356 | template<typename derived_type> |
357 | typename std::enable_if< |
358 | std::is_base_of<reference_type, derived_type>::value, |
359 | ScopedVclPtr &>::type |
360 | operator =(VclPtr<derived_type> const & rRef) |
361 | { |
362 | disposeAndReset(rRef.get()); |
363 | return *this; |
364 | } |
365 | |
366 | /** |
367 | * Override and disallow this, to prevent people accidentally calling it and actually |
368 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
369 | */ |
370 | template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete; |
371 | |
372 | ~ScopedVclPtr() |
373 | { |
374 | VclPtr<reference_type>::disposeAndClear(); |
375 | assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get( ) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 375, __extension__ __PRETTY_FUNCTION__)); // make sure there are no lingering references |
376 | } |
377 | |
378 | private: |
379 | // Most likely we don't want this default copy-constructor. |
380 | ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete; |
381 | // And certainly we don't want a default assignment operator. |
382 | ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete; |
383 | // And disallow reset as that doesn't call disposeAndClear on the original reference |
384 | void reset() = delete; |
385 | void reset(reference_type *pBody) = delete; |
386 | |
387 | protected: |
388 | ScopedVclPtr (reference_type * pBody, __sal_NoAcquire) |
389 | : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE) |
390 | {} |
391 | }; |
392 | |
393 | /** |
394 | * A construction helper for ScopedVclPtr. Since VclPtr types are created |
395 | * with a reference-count of one - to help fit into the existing |
396 | * code-flow; this helps us to construct them easily. |
397 | * |
398 | * For more details on the design please see vcl/README.lifecycle |
399 | * |
400 | * @param reference_type must be a subclass of vcl::Window |
401 | */ |
402 | #if defined _MSC_VER |
403 | #pragma warning(push) |
404 | #pragma warning(disable: 4521) // " multiple copy constructors specified" |
405 | #endif |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
410 | template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg) |
411 | : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
412 | { |
413 | } |
414 | |
415 | /** |
416 | * Override and disallow this, to prevent people accidentally calling it and actually |
417 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
418 | */ |
419 | template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete; |
420 | |
421 | private: |
422 | // Prevent the above perfect forwarding ctor from hijacking (accidental) |
423 | // attempts at ScopedVclPtrInstance copy construction (where the hijacking |
424 | // would typically lead to somewhat obscure error messages); both non-const |
425 | // and const variants are needed here, as the ScopedVclPtr base class has a |
426 | // const--variant copy ctor, so the implicitly declared copy ctor for |
427 | // ScopedVclPtrInstance would also be the const variant, so non-const copy |
428 | // construction attempts would be hijacked by the perfect forwarding ctor; |
429 | // but if we only declared a non-const variant here, the const variant would |
430 | // no longer be implicitly declared (as there would already be an explicitly |
431 | // declared copy ctor), so const copy construction attempts would then be |
432 | // hijacked by the perfect forwarding ctor: |
433 | ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete; |
434 | ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete; |
435 | }; |
436 | #if defined _MSC_VER |
437 | #pragma warning(pop) |
438 | #endif |
439 | |
440 | #endif // INCLUDED_VCL_PTR_HXX |
441 | |
442 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_RTL_REF_HXX | ||||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||||
22 | |||||||||
23 | #include "sal/config.h" | ||||||||
24 | |||||||||
25 | #include <cassert> | ||||||||
26 | #include <cstddef> | ||||||||
27 | #include <functional> | ||||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
29 | #include <type_traits> | ||||||||
30 | #endif | ||||||||
31 | |||||||||
32 | #include "sal/types.h" | ||||||||
33 | |||||||||
34 | namespace rtl | ||||||||
35 | { | ||||||||
36 | |||||||||
37 | /** Template reference class for reference type. | ||||||||
38 | */ | ||||||||
39 | template <class reference_type> | ||||||||
40 | class Reference | ||||||||
41 | { | ||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||
43 | */ | ||||||||
44 | reference_type * m_pBody; | ||||||||
45 | |||||||||
46 | |||||||||
47 | public: | ||||||||
48 | /** Constructor... | ||||||||
49 | */ | ||||||||
50 | Reference() | ||||||||
51 | : m_pBody (NULL__null) | ||||||||
52 | {} | ||||||||
53 | |||||||||
54 | |||||||||
55 | /** Constructor... | ||||||||
56 | */ | ||||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||||
58 | : m_pBody (pBody) | ||||||||
59 | { | ||||||||
60 | } | ||||||||
61 | |||||||||
62 | /** Constructor... | ||||||||
63 | */ | ||||||||
64 | Reference (reference_type * pBody) | ||||||||
65 | : m_pBody (pBody) | ||||||||
66 | { | ||||||||
67 | if (m_pBody) | ||||||||
68 | m_pBody->acquire(); | ||||||||
69 | } | ||||||||
70 | |||||||||
71 | /** Copy constructor... | ||||||||
72 | */ | ||||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||||
74 | : m_pBody (handle.m_pBody) | ||||||||
75 | { | ||||||||
76 | if (m_pBody) | ||||||||
77 | m_pBody->acquire(); | ||||||||
78 | } | ||||||||
79 | |||||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
81 | /** Move constructor... | ||||||||
82 | */ | ||||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||||
84 | : m_pBody (handle.m_pBody) | ||||||||
85 | { | ||||||||
86 | handle.m_pBody = nullptr; | ||||||||
87 | } | ||||||||
88 | #endif | ||||||||
89 | |||||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||||
92 | |||||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||||
94 | |||||||||
95 | @param rRef another reference | ||||||||
96 | */ | ||||||||
97 | template< class derived_type > | ||||||||
98 | inline Reference( | ||||||||
99 | const Reference< derived_type > & rRef, | ||||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||||
101 | : m_pBody (rRef.get()) | ||||||||
102 | { | ||||||||
103 | if (m_pBody) | ||||||||
104 | m_pBody->acquire(); | ||||||||
105 | } | ||||||||
106 | #endif | ||||||||
107 | |||||||||
108 | /** Destructor... | ||||||||
109 | */ | ||||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||||
111 | { | ||||||||
112 | if (m_pBody) | ||||||||
113 | m_pBody->release(); | ||||||||
114 | } | ||||||||
115 | |||||||||
116 | /** Set... | ||||||||
117 | Similar to assignment. | ||||||||
118 | */ | ||||||||
119 | Reference<reference_type> & | ||||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||||
121 | { | ||||||||
122 | if (pBody) | ||||||||
123 | pBody->acquire(); | ||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||
125 | m_pBody = pBody; | ||||||||
126 | if (pOld) | ||||||||
127 | pOld->release(); | ||||||||
128 | return *this; | ||||||||
129 | } | ||||||||
130 | |||||||||
131 | /** Assignment. | ||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||
133 | bind it to the body represented by the handle. | ||||||||
134 | */ | ||||||||
135 | Reference<reference_type> & | ||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||
137 | { | ||||||||
138 | return set( handle.m_pBody ); | ||||||||
139 | } | ||||||||
140 | |||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
142 | /** Assignment. | ||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||
144 | * bind it to the body represented by the handle, and | ||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||
146 | */ | ||||||||
147 | Reference<reference_type> & | ||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||
149 | { | ||||||||
150 | // self-movement guts ourself | ||||||||
151 | if (m_pBody) | ||||||||
152 | m_pBody->release(); | ||||||||
153 | m_pBody = handle.m_pBody; | ||||||||
154 | handle.m_pBody = nullptr; | ||||||||
155 | return *this; | ||||||||
156 | } | ||||||||
157 | #endif | ||||||||
158 | |||||||||
159 | /** Assignment... | ||||||||
160 | */ | ||||||||
161 | Reference<reference_type> & | ||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||
163 | { | ||||||||
164 | return set( pBody ); | ||||||||
165 | } | ||||||||
166 | |||||||||
167 | /** Unbind the body from this handle. | ||||||||
168 | Note that for a handle representing a large body, | ||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||
171 | since in the second case two large objects exist in memory | ||||||||
172 | (the old body and the new body). | ||||||||
173 | */ | ||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||
175 | { | ||||||||
176 | if (m_pBody
| ||||||||
177 | { | ||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||
179 | m_pBody = NULL__null; | ||||||||
180 | pOld->release(); | ||||||||
181 | } | ||||||||
182 | return *this; | ||||||||
183 | } | ||||||||
184 | |||||||||
185 | |||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||
188 | are the same. | ||||||||
189 | */ | ||||||||
190 | reference_type * SAL_CALL get() const | ||||||||
191 | { | ||||||||
192 | return m_pBody; | ||||||||
| |||||||||
193 | } | ||||||||
194 | |||||||||
195 | |||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||
197 | */ | ||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||
199 | { | ||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||
201 | return m_pBody; | ||||||||
202 | } | ||||||||
203 | |||||||||
204 | |||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||
206 | */ | ||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||
208 | { | ||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||
210 | return *m_pBody; | ||||||||
211 | } | ||||||||
212 | |||||||||
213 | |||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||
215 | */ | ||||||||
216 | bool SAL_CALL is() const | ||||||||
217 | { | ||||||||
218 | return (m_pBody != NULL__null); | ||||||||
219 | } | ||||||||
220 | |||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||
223 | */ | ||||||||
224 | explicit operator bool() const | ||||||||
225 | { | ||||||||
226 | return is(); | ||||||||
227 | } | ||||||||
228 | #endif | ||||||||
229 | |||||||||
230 | /** Returns True if this points to pBody. | ||||||||
231 | */ | ||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||
233 | { | ||||||||
234 | return (m_pBody == pBody); | ||||||||
235 | } | ||||||||
236 | |||||||||
237 | |||||||||
238 | /** Returns True if handle points to the same body. | ||||||||
239 | */ | ||||||||
240 | bool | ||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||
242 | { | ||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||
244 | } | ||||||||
245 | |||||||||
246 | |||||||||
247 | /** Needed to place References into STL collection. | ||||||||
248 | */ | ||||||||
249 | bool | ||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||
251 | { | ||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||
253 | } | ||||||||
254 | |||||||||
255 | |||||||||
256 | /** Needed to place References into STL collection. | ||||||||
257 | */ | ||||||||
258 | bool | ||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||
260 | { | ||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||
262 | } | ||||||||
263 | |||||||||
264 | |||||||||
265 | /** Needed to place References into STL collection. | ||||||||
266 | */ | ||||||||
267 | bool | ||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||
269 | { | ||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||
271 | } | ||||||||
272 | }; | ||||||||
273 | |||||||||
274 | } // namespace rtl | ||||||||
275 | |||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
277 | namespace std | ||||||||
278 | { | ||||||||
279 | |||||||||
280 | /// @cond INTERNAL | ||||||||
281 | /** | ||||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||||
283 | |||||||||
284 | @since LibreOffice 6.3 | ||||||||
285 | */ | ||||||||
286 | template<typename T> | ||||||||
287 | struct hash<::rtl::Reference<T>> | ||||||||
288 | { | ||||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||||
290 | { return std::size_t(s.get()); } | ||||||||
291 | }; | ||||||||
292 | /// @endcond | ||||||||
293 | |||||||||
294 | } | ||||||||
295 | |||||||||
296 | #endif | ||||||||
297 | |||||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||||
299 | |||||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |