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 <config_features.h> | |||
21 | ||||
22 | #include <comphelper/propertysequence.hxx> | |||
23 | #include <sfx2/dispatch.hxx> | |||
24 | #include <sfx2/event.hxx> | |||
25 | #include <sfx2/objitem.hxx> | |||
26 | #include <svx/dataaccessdescriptor.hxx> | |||
27 | #include <svtools/restartdialog.hxx> | |||
28 | #include <svl/eitem.hxx> | |||
29 | #include <svl/whiter.hxx> | |||
30 | #include <svl/isethint.hxx> | |||
31 | #include <svl/stritem.hxx> | |||
32 | #include <sfx2/request.hxx> | |||
33 | #include <sfx2/fcontnr.hxx> | |||
34 | #include <svl/ctloptions.hxx> | |||
35 | #include <svtools/colorcfg.hxx> | |||
36 | #include <svtools/accessibilityoptions.hxx> | |||
37 | #include <tools/diagnose_ex.h> | |||
38 | #include <unotools/useroptions.hxx> | |||
39 | #include <com/sun/star/document/UpdateDocMode.hpp> | |||
40 | #include <sfx2/docfile.hxx> | |||
41 | #include <sfx2/objface.hxx> | |||
42 | #include <vcl/settings.hxx> | |||
43 | #include <vcl/svapp.hxx> | |||
44 | ||||
45 | #include <view.hxx> | |||
46 | #include <pview.hxx> | |||
47 | #include <srcview.hxx> | |||
48 | #include <wrtsh.hxx> | |||
49 | #include <docsh.hxx> | |||
50 | #include <cmdid.h> | |||
51 | #include <initui.hxx> | |||
52 | #include <uitool.hxx> | |||
53 | #include <swmodule.hxx> | |||
54 | #include <wview.hxx> | |||
55 | #include <usrpref.hxx> | |||
56 | #include <gloslst.hxx> | |||
57 | #include <glosdoc.hxx> | |||
58 | #include <doc.hxx> | |||
59 | #include <IDocumentLayoutAccess.hxx> | |||
60 | #include <IDocumentFieldsAccess.hxx> | |||
61 | #include <prtopt.hxx> | |||
62 | #include <modcfg.hxx> | |||
63 | #include <fontcfg.hxx> | |||
64 | #include <barcfg.hxx> | |||
65 | #include <navicfg.hxx> | |||
66 | #include <uinums.hxx> | |||
67 | #include <dbconfig.hxx> | |||
68 | #include <mmconfigitem.hxx> | |||
69 | #include <strings.hrc> | |||
70 | #include <com/sun/star/container/XChild.hpp> | |||
71 | #include <com/sun/star/sdbc/XConnection.hpp> | |||
72 | #include <com/sun/star/sdb/TextConnectionSettings.hpp> | |||
73 | #include <com/sun/star/sdbc/XDataSource.hpp> | |||
74 | #include <com/sun/star/task/OfficeRestartManager.hpp> | |||
75 | #include <org/freedesktop/PackageKit/SyncDbusSessionHelper.hpp> | |||
76 | #include <swabstdlg.hxx> | |||
77 | #include <comphelper/dispatchcommand.hxx> | |||
78 | #include <comphelper/processfactory.hxx> | |||
79 | ||||
80 | #include <salhelper/simplereferenceobject.hxx> | |||
81 | #include <rtl/ref.hxx> | |||
82 | ||||
83 | #include <officecfg/Office/Common.hxx> | |||
84 | ||||
85 | using namespace ::com::sun::star; | |||
86 | ||||
87 | // Slotmaps for the application's methods | |||
88 | ||||
89 | // here are the SlotID's being included | |||
90 | // see Idl-file | |||
91 | #define ShellClass_SwModule | |||
92 | #include <sfx2/msg.hxx> | |||
93 | #include <swslots.hxx> | |||
94 | ||||
95 | SFX_IMPL_INTERFACE(SwModule, SfxModule)SfxInterface* SwModule::pInterface = nullptr; SfxInterface* SwModule ::GetStaticInterface() { if ( !pInterface ) { pInterface = new SfxInterface( "SwModule", false, GetInterfaceId(), SfxModule ::GetStaticInterface(), aSwModuleSlots_Impl[0], sal_uInt16(sizeof (aSwModuleSlots_Impl) / sizeof(SfxSlot) ) ); InitInterface_Impl (); } return pInterface; } SfxInterface* SwModule::GetInterface () const { return GetStaticInterface(); } void SwModule::RegisterInterface (const SfxModule* pMod) { GetStaticInterface()->Register(pMod ); } | |||
96 | ||||
97 | void SwModule::InitInterface_Impl() | |||
98 | { | |||
99 | GetStaticInterface()->RegisterStatusBar(StatusBarId::WriterStatusBar); | |||
100 | ||||
101 | GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_APPLICATION0, | |||
102 | SfxVisibilityFlags::Standard | SfxVisibilityFlags::Client | SfxVisibilityFlags::Viewer, | |||
103 | ToolbarId::Module_Toolbox); | |||
104 | } | |||
105 | ||||
106 | // other states | |||
107 | void SwModule::StateOther(SfxItemSet &rSet) | |||
108 | { | |||
109 | SfxWhichIter aIter(rSet); | |||
110 | sal_uInt16 nWhich = aIter.FirstWhich(); | |||
111 | ||||
112 | SwView* pActView = ::GetActiveView(); | |||
113 | bool bWebView = dynamic_cast<SwWebView*>( pActView ) != nullptr; | |||
114 | ||||
115 | while(nWhich) | |||
116 | { | |||
117 | switch(nWhich) | |||
118 | { | |||
119 | case FN_BUSINESS_CARD(20000 + 1052): | |||
120 | case FN_LABEL(20000 + 1051 ): | |||
121 | case FN_ENVELOP((20000 + 1050) ): | |||
122 | { | |||
123 | bool bDisable = false; | |||
124 | SfxViewShell* pCurrView = SfxViewShell::Current(); | |||
125 | if( !pCurrView || dynamic_cast< const SwView *>( pCurrView ) == nullptr ) | |||
126 | bDisable = true; | |||
127 | SwDocShell *pDocSh = static_cast<SwDocShell*>( SfxObjectShell::Current()); | |||
128 | if ( bDisable || | |||
129 | (pDocSh && (pDocSh->IsReadOnly() || | |||
130 | pDocSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED)) ) | |||
131 | rSet.DisableItem( nWhich ); | |||
132 | ||||
133 | } | |||
134 | break; | |||
135 | case FN_XFORMS_INIT(20000 + 1053): | |||
136 | // slot is always active! | |||
137 | break; | |||
138 | case FN_EDIT_FORMULA((20000 + 100) + 28): | |||
139 | { | |||
140 | SwWrtShell* pSh = nullptr; | |||
141 | SelectionType nSelection = SelectionType::NONE; | |||
142 | if( pActView ) | |||
143 | pSh = &pActView->GetWrtShell(); | |||
144 | if( pSh ) | |||
145 | nSelection = pSh->GetSelectionType(); | |||
146 | ||||
147 | if( (pSh && pSh->HasSelection()) || | |||
148 | !(nSelection & (SelectionType::Text | SelectionType::Table))) | |||
149 | rSet.DisableItem(nWhich); | |||
150 | } | |||
151 | break; | |||
152 | case SID_ATTR_METRICTypedWhichId<SfxUInt16Item>(((((10000 + 1499) + 1) + 499 ) + 1) + 8): | |||
153 | rSet.Put( SfxUInt16Item( SID_ATTR_METRICTypedWhichId<SfxUInt16Item>(((((10000 + 1499) + 1) + 499 ) + 1) + 8), static_cast< sal_uInt16 >(::GetDfltMetric(bWebView)))); | |||
154 | break; | |||
155 | case FN_SET_MODOPT_TBLNUMFMT((20000 + 200) + 52): | |||
156 | rSet.Put( SfxBoolItem( nWhich, m_pModuleConfig-> | |||
157 | IsInsTableFormatNum( bWebView ))); | |||
158 | break; | |||
159 | case FN_MAILMERGE_WIZARD((20000 + 300) + 64): | |||
160 | { | |||
161 | SfxObjectShell* pObjectShell = GetObjectShell(); | |||
162 | if (pObjectShell && pObjectShell->isExportLocked()) | |||
163 | rSet.DisableItem(nWhich); | |||
164 | break; | |||
165 | } | |||
166 | case FN_MAILMERGE_FIRST_ENTRY((20000 + 300) + 70): | |||
167 | case FN_MAILMERGE_PREV_ENTRY((20000 + 300) + 71): | |||
168 | case FN_MAILMERGE_NEXT_ENTRY((20000 + 300) + 72): | |||
169 | case FN_MAILMERGE_LAST_ENTRY((20000 + 300) + 73): | |||
170 | { | |||
171 | SwView* pView = ::GetActiveView(); | |||
172 | std::shared_ptr<SwMailMergeConfigItem> xConfigItem; | |||
173 | if (pView) | |||
174 | xConfigItem = pView->GetMailMergeConfigItem(); | |||
175 | if (!xConfigItem) | |||
176 | rSet.DisableItem(nWhich); | |||
177 | else if (xConfigItem->GetConnection().is() | |||
178 | && !xConfigItem->GetConnection()->isClosed()) | |||
179 | { | |||
180 | bool bFirst, bLast; | |||
181 | bool bValid = xConfigItem->IsResultSetFirstLast(bFirst, bLast); | |||
182 | ||||
183 | if (!bValid || | |||
184 | (bFirst && (nWhich == FN_MAILMERGE_FIRST_ENTRY((20000 + 300) + 70) || nWhich == FN_MAILMERGE_PREV_ENTRY((20000 + 300) + 71))) || | |||
185 | (bLast && (nWhich == FN_MAILMERGE_LAST_ENTRY((20000 + 300) + 73) || nWhich == FN_MAILMERGE_NEXT_ENTRY((20000 + 300) + 72)))) | |||
186 | { | |||
187 | rSet.DisableItem(nWhich); | |||
188 | } | |||
189 | } | |||
190 | } | |||
191 | break; | |||
192 | case FN_MAILMERGE_CURRENT_ENTRY((20000 + 300) + 74): | |||
193 | case FN_MAILMERGE_EXCLUDE_ENTRY((20000 + 300) + 75): | |||
194 | { | |||
195 | // just trigger calling statusChanged() of MMExcludeEntryController | |||
196 | // resp. MMCurrentEntryController | |||
197 | rSet.InvalidateItem(nWhich); | |||
198 | } | |||
199 | break; | |||
200 | case FN_MAILMERGE_CREATE_DOCUMENTS((20000 + 300) + 77): | |||
201 | case FN_MAILMERGE_SAVE_DOCUMENTS((20000 + 300) + 78): | |||
202 | case FN_MAILMERGE_PRINT_DOCUMENTS((20000 + 300) + 79): | |||
203 | case FN_MAILMERGE_EMAIL_DOCUMENTS((20000 + 300) + 80): | |||
204 | { | |||
205 | SwView* pView = ::GetActiveView(); | |||
206 | std::shared_ptr<SwMailMergeConfigItem> xConfigItem; | |||
207 | if (pView) | |||
208 | xConfigItem = pView->EnsureMailMergeConfigItem(); | |||
209 | ||||
210 | // #i51949# hide e-Mail option if e-Mail is not supported | |||
211 | // #i63267# printing might be disabled | |||
212 | if (!xConfigItem || | |||
213 | !xConfigItem->GetConnection().is() || | |||
214 | xConfigItem->GetConnection()->isClosed() || | |||
215 | !xConfigItem->GetResultSet().is() || | |||
216 | xConfigItem->GetCurrentDBData().sDataSource.isEmpty() || | |||
217 | xConfigItem->GetCurrentDBData().sCommand.isEmpty() || | |||
218 | (nWhich == FN_MAILMERGE_PRINT_DOCUMENTS((20000 + 300) + 79) && Application::GetSettings().GetMiscSettings().GetDisablePrinting()) || | |||
219 | (nWhich == FN_MAILMERGE_EMAIL_DOCUMENTS((20000 + 300) + 80) && !xConfigItem->IsMailAvailable())) | |||
220 | { | |||
221 | rSet.DisableItem(nWhich); | |||
222 | } | |||
223 | } | |||
224 | break; | |||
225 | default: | |||
226 | OSL_FAIL("::StateOther: default")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/apphdl.cxx" ":" "226" ": "), "%s", "::StateOther: default"); } } while ( false); | |||
227 | } | |||
228 | nWhich = aIter.NextWhich(); | |||
229 | } | |||
230 | } | |||
231 | ||||
232 | // start field dialog | |||
233 | static void NewXForms( SfxRequest& rReq ); // implementation: below | |||
234 | ||||
235 | std::shared_ptr<SwMailMergeConfigItem> SwView::EnsureMailMergeConfigItem(const SfxItemSet* pArgs) | |||
236 | { | |||
237 | // create if it does not exist yet | |||
238 | std::shared_ptr<SwMailMergeConfigItem> xMMConfig = GetMailMergeConfigItem(); | |||
239 | if (!xMMConfig) | |||
240 | { | |||
241 | xMMConfig = std::make_shared<SwMailMergeConfigItem>(); | |||
242 | xMMConfig->SetSourceView(this); | |||
243 | ||||
244 | //set the first used database as default source on the config item | |||
245 | const SfxPoolItem* pItem = nullptr; | |||
246 | if (pArgs && SfxItemState::SET == pArgs->GetItemState( | |||
247 | FN_PARAM_DATABASE_PROPERTIES((20000 + 2400)+22), false, &pItem)) | |||
248 | { | |||
249 | //mailmerge has been called from the database beamer | |||
250 | uno::Sequence< beans::PropertyValue> aDBValues; | |||
251 | if (static_cast<const SfxUnoAnyItem*>(pItem)->GetValue() >>= aDBValues) | |||
252 | { | |||
253 | SwDBData aDBData; | |||
254 | svx::ODataAccessDescriptor aDescriptor(aDBValues); | |||
255 | aDescriptor[svx::DataAccessDescriptorProperty::DataSource] >>= aDBData.sDataSource; | |||
256 | aDescriptor[svx::DataAccessDescriptorProperty::Command] >>= aDBData.sCommand; | |||
257 | aDescriptor[svx::DataAccessDescriptorProperty::CommandType] >>= aDBData.nCommandType; | |||
258 | ||||
259 | uno::Reference< sdbc::XConnection> xConnection; | |||
260 | uno::Reference< sdbc::XDataSource> xSource; | |||
261 | uno::Reference< sdbcx::XColumnsSupplier> xColumnsSupplier; | |||
262 | if (aDescriptor.has(svx::DataAccessDescriptorProperty::Connection)) | |||
263 | aDescriptor[svx::DataAccessDescriptorProperty::Connection] >>= xConnection; | |||
264 | uno::Reference<container::XChild> xChild(xConnection, uno::UNO_QUERY); | |||
265 | if (xChild.is()) | |||
266 | xSource.set(xChild->getParent(), uno::UNO_QUERY); | |||
267 | xMMConfig->SetCurrentConnection( | |||
268 | xSource, SharedConnection(xConnection, SharedConnection::NoTakeOwnership), | |||
269 | xColumnsSupplier, aDBData); | |||
270 | } | |||
271 | } | |||
272 | else | |||
273 | { | |||
274 | std::vector<OUString> aDBNameList; | |||
275 | std::vector<OUString> aAllDBNames; | |||
276 | GetWrtShell().GetAllUsedDB(aDBNameList, &aAllDBNames); | |||
277 | if (!aDBNameList.empty()) | |||
278 | { | |||
279 | OUString sDBName(aDBNameList[0]); | |||
280 | SwDBData aDBData; | |||
281 | sal_Int32 nIdx{ 0 }; | |||
282 | aDBData.sDataSource = sDBName.getToken(0, DB_DELIMu'\x00ff', nIdx); | |||
283 | aDBData.sCommand = sDBName.getToken(0, DB_DELIMu'\x00ff', nIdx); | |||
284 | aDBData.nCommandType = sDBName.getToken(0, DB_DELIMu'\x00ff', nIdx).toInt32(); | |||
285 | //set the currently used database for the wizard | |||
286 | xMMConfig->SetCurrentDBData(aDBData); | |||
287 | } | |||
288 | } | |||
289 | ||||
290 | SetMailMergeConfigItem(xMMConfig); | |||
291 | } | |||
292 | return xMMConfig; | |||
293 | } | |||
294 | ||||
295 | #if HAVE_FEATURE_DBCONNECTIVITY1 | |||
296 | ||||
297 | namespace | |||
298 | { | |||
299 | ||||
300 | SwView* lcl_LoadDoc(SwView* pView, const OUString& rURL) | |||
301 | { | |||
302 | SwView* pNewView = nullptr; | |||
303 | if(!rURL.isEmpty()) | |||
304 | { | |||
305 | SfxStringItem aURL(SID_FILE_NAME(5000 + 507), rURL); | |||
306 | SfxStringItem aTargetFrameName( SID_TARGETNAME(5000 + 560), "_blank" ); | |||
307 | SfxBoolItem aHidden( SID_HIDDEN(5000 + 534), true ); | |||
308 | SfxStringItem aReferer(SID_REFERER(5000 + 654), pView->GetDocShell()->GetTitle()); | |||
309 | const SfxObjectItem* pItem = static_cast<const SfxObjectItem*>( | |||
310 | pView->GetViewFrame()->GetDispatcher()->ExecuteList(SID_OPENDOC(5000 + 501), | |||
311 | SfxCallMode::SYNCHRON, | |||
312 | { &aURL, &aHidden, &aReferer, &aTargetFrameName })); | |||
313 | SfxShell* pShell = pItem ? pItem->GetShell() : nullptr; | |||
314 | ||||
315 | if(pShell) | |||
316 | { | |||
317 | SfxViewShell* pViewShell = pShell->GetViewShell(); | |||
318 | if(pViewShell) | |||
319 | { | |||
320 | pNewView = dynamic_cast<SwView*>(pViewShell); | |||
321 | if (pNewView) | |||
322 | { | |||
323 | pNewView->GetViewFrame()->GetFrame().Appear(); | |||
324 | } | |||
325 | else | |||
326 | { | |||
327 | pViewShell->GetViewFrame()->DoClose(); | |||
328 | } | |||
329 | } | |||
330 | } | |||
331 | } | |||
332 | else | |||
333 | { | |||
334 | SfxStringItem aFactory(SID_NEWDOCDIRECT(5000 + 537), SwDocShell::Factory().GetFilterContainer()->GetName()); | |||
335 | const SfxFrameItem* pItem = static_cast<const SfxFrameItem*>( | |||
336 | pView->GetViewFrame()->GetDispatcher()->ExecuteList( | |||
337 | SID_NEWDOCDIRECT(5000 + 537), SfxCallMode::SYNCHRON, { &aFactory })); | |||
338 | SfxFrame* pFrame = pItem ? pItem->GetFrame() : nullptr; | |||
339 | SfxViewFrame* pViewFrame = pFrame ? pFrame->GetCurrentViewFrame() : nullptr; | |||
340 | pNewView = pViewFrame ? dynamic_cast<SwView*>( pViewFrame->GetViewShell() ) : nullptr; | |||
341 | } | |||
342 | ||||
343 | return pNewView; | |||
344 | } | |||
345 | ||||
346 | class SwMailMergeWizardExecutor : public salhelper::SimpleReferenceObject | |||
347 | { | |||
348 | SwView* m_pView; // never owner | |||
349 | SwView* m_pView2Close; // never owner | |||
350 | VclPtr<AbstractMailMergeWizard> m_pWizard; // always owner | |||
351 | VclPtr<AbstractMailMergeWizard> m_pWizardToDestroyInCallback; | |||
352 | ||||
353 | void EndDialogHdl(sal_Int32 nResponse); | |||
354 | DECL_LINK( DestroyDialogHdl, void*, void )static void LinkStubDestroyDialogHdl(void *, void*); void DestroyDialogHdl (void*); | |||
355 | DECL_LINK( DestroyWizardHdl, void*, void )static void LinkStubDestroyWizardHdl(void *, void*); void DestroyWizardHdl (void*); | |||
356 | DECL_LINK( CancelHdl, void*, void )static void LinkStubCancelHdl(void *, void*); void CancelHdl( void*); | |||
357 | DECL_LINK( CloseFrameHdl, void*, void )static void LinkStubCloseFrameHdl(void *, void*); void CloseFrameHdl (void*); | |||
358 | ||||
359 | void ExecutionFinished(); | |||
360 | void ExecuteWizard(); | |||
361 | ||||
362 | public: | |||
363 | SwMailMergeWizardExecutor(); | |||
364 | virtual ~SwMailMergeWizardExecutor() override; | |||
365 | ||||
366 | void ExecuteMailMergeWizard( const SfxItemSet * pArgs ); | |||
367 | }; | |||
368 | ||||
369 | SwMailMergeWizardExecutor::SwMailMergeWizardExecutor() | |||
370 | : m_pView( nullptr ), | |||
371 | m_pView2Close( nullptr ), | |||
372 | m_pWizard( nullptr ) | |||
373 | { | |||
374 | } | |||
375 | ||||
376 | SwMailMergeWizardExecutor::~SwMailMergeWizardExecutor() | |||
377 | { | |||
378 | OSL_ENSURE( m_pWizard == nullptr, "SwMailMergeWizardExecutor: m_pWizard must be Null!" )do { if (true && (!(m_pWizard == nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "378" ": "), "%s", "SwMailMergeWizardExecutor: m_pWizard must be Null!" ); } } while (false); | |||
379 | } | |||
380 | ||||
381 | bool lcl_hasAllComponentsAvailable() | |||
382 | { | |||
383 | try | |||
384 | { | |||
385 | return css::sdb::TextConnectionSettings::create(comphelper::getProcessComponentContext()).is(); | |||
386 | } | |||
387 | catch (const css::uno::Exception &) | |||
388 | { | |||
389 | TOOLS_INFO_EXCEPTION(do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.core")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "assuming Base to be missing; caught " << " " << exceptionToString(tools_warn_exception )) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ( "sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "390" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "assuming Base to be missing; caught " << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "assuming Base to be missing; caught " << " " << exceptionToString(tools_warn_exception); ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "390" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "assuming Base to be missing; caught " << " " << exceptionToString(tools_warn_exception)) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.core"), ( "/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "390" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "assuming Base to be missing; caught " << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "assuming Base to be missing; caught " << " " << exceptionToString(tools_warn_exception); ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "390" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false) | |||
390 | "sw.core", "assuming Base to be missing; caught ")do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.core")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "assuming Base to be missing; caught " << " " << exceptionToString(tools_warn_exception )) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ( "sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "390" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "assuming Base to be missing; caught " << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "assuming Base to be missing; caught " << " " << exceptionToString(tools_warn_exception); ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "390" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "assuming Base to be missing; caught " << " " << exceptionToString(tools_warn_exception)) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.core"), ( "/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "390" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "assuming Base to be missing; caught " << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "assuming Base to be missing; caught " << " " << exceptionToString(tools_warn_exception); ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "390" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false); | |||
391 | return false; | |||
392 | } | |||
393 | } | |||
394 | ||||
395 | void SwMailMergeWizardExecutor::ExecuteMailMergeWizard( const SfxItemSet * pArgs ) | |||
396 | { | |||
397 | if(!lcl_hasAllComponentsAvailable()) | |||
398 | { | |||
399 | if (officecfg::Office::Common::PackageKit::EnableBaseInstallation::get()) | |||
400 | { | |||
401 | try | |||
402 | { | |||
403 | using namespace org::freedesktop::PackageKit; | |||
404 | using namespace svtools; | |||
405 | css::uno::Reference< XSyncDbusSessionHelper > xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext())); | |||
406 | const css::uno::Sequence< OUString > vPackages{ "libreoffice-base" }; | |||
407 | xSyncDbusSessionHelper->InstallPackageNames(vPackages, OUString()); | |||
408 | SolarMutexGuard aGuard; | |||
409 | executeRestartDialog(comphelper::getProcessComponentContext(), nullptr, RESTART_REASON_MAILMERGE_INSTALL); | |||
410 | } | |||
411 | catch (const css::uno::Exception &) | |||
412 | { | |||
413 | TOOLS_INFO_EXCEPTION(do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.core")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception )) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ( "sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "415" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception); ::sal:: detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "415" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.core") , ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "415" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception); ::sal:: detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "415" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false) | |||
414 | "sw.core",do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.core")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception )) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ( "sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "415" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception); ::sal:: detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "415" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.core") , ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "415" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception); ::sal:: detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "415" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false) | |||
415 | "trying to install LibreOffice Base, caught")do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.core")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception )) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ( "sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "415" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception); ::sal:: detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "415" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.core") , ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "415" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "trying to install LibreOffice Base, caught" << " " << exceptionToString(tools_warn_exception); ::sal:: detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.core"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "415" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false); | |||
416 | auto xRestartManager | |||
417 | = css::task::OfficeRestartManager::get(comphelper::getProcessComponentContext()); | |||
418 | if (!xRestartManager->isRestartRequested(false)) | |||
419 | { | |||
420 | // Base is absent, and could not initiate its install - ask user to do that manually | |||
421 | // Only show the dialog if restart is not initiated yet | |||
422 | std::unique_ptr<weld::MessageDialog> xWarnBox(Application::CreateMessageDialog( | |||
423 | nullptr, VclMessageType::Info, VclButtonsType::Ok, | |||
424 | SwResId(STR_NO_BASE_FOR_MERGEreinterpret_cast<char const *>("STR_NO_BASE_FOR_MERGE" "\004" u8"%PRODUCTNAME Base component is absent, and it is required to use Mail Merge." )))); | |||
425 | xWarnBox->run(); | |||
426 | } | |||
427 | } | |||
428 | } else { | |||
429 | auto xRestartManager | |||
430 | = css::task::OfficeRestartManager::get(comphelper::getProcessComponentContext()); | |||
431 | if (!xRestartManager->isRestartRequested(false)) | |||
432 | { | |||
433 | // Base is absent, and could not initiate its install - ask user to do that manually | |||
434 | // Only show the dialog if restart is not initiated yet | |||
435 | std::unique_ptr<weld::MessageDialog> xWarnBox(Application::CreateMessageDialog( | |||
436 | nullptr, VclMessageType::Info, VclButtonsType::Ok, | |||
437 | SwResId(STR_NO_BASE_FOR_MERGEreinterpret_cast<char const *>("STR_NO_BASE_FOR_MERGE" "\004" u8"%PRODUCTNAME Base component is absent, and it is required to use Mail Merge." )))); | |||
438 | xWarnBox->run(); | |||
439 | } | |||
440 | } | |||
441 | return; | |||
442 | } | |||
443 | if ( m_pView ) | |||
444 | { | |||
445 | OSL_FAIL("SwMailMergeWizardExecutor::ExecuteMailMergeWizard: Already executing the wizard!" )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/apphdl.cxx" ":" "445" ": "), "%s", "SwMailMergeWizardExecutor::ExecuteMailMergeWizard: Already executing the wizard!" ); } } while (false); | |||
446 | return; | |||
447 | } | |||
448 | ||||
449 | m_pView = ::GetActiveView(); | |||
450 | if (!m_pView) | |||
451 | return; | |||
452 | ||||
453 | // keep self alive until done. | |||
454 | acquire(); | |||
455 | ||||
456 | // create if it does not exist yet | |||
457 | std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->EnsureMailMergeConfigItem(pArgs); | |||
458 | ||||
459 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
460 | m_pWizard = pFact->CreateMailMergeWizard(*m_pView, xMMConfig); | |||
461 | ||||
462 | ExecuteWizard(); | |||
463 | } | |||
464 | ||||
465 | void SwMailMergeWizardExecutor::ExecutionFinished() | |||
466 | { | |||
467 | std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->GetMailMergeConfigItem(); | |||
468 | if (xMMConfig) | |||
469 | xMMConfig->Commit(); | |||
470 | ||||
471 | SwDoc* pDoc = m_pView->GetDocShell()->GetDoc(); | |||
472 | if (pDoc) | |||
473 | { | |||
474 | SwDBManager* pDbManager = pDoc->GetDBManager(); | |||
475 | if (pDbManager) | |||
476 | pDbManager->CommitLastRegistrations(); | |||
477 | ||||
478 | // Show the toolbar | |||
479 | m_pView->ShowUIElement("private:resource/toolbar/mailmerge"); | |||
480 | ||||
481 | // Update Mail Merge controls | |||
482 | const sal_uInt16 slotIds[] = { FN_MAILMERGE_FIRST_ENTRY((20000 + 300) + 70), | |||
483 | FN_MAILMERGE_PREV_ENTRY((20000 + 300) + 71), | |||
484 | FN_MAILMERGE_NEXT_ENTRY((20000 + 300) + 72), | |||
485 | FN_MAILMERGE_LAST_ENTRY((20000 + 300) + 73), | |||
486 | FN_MAILMERGE_CURRENT_ENTRY((20000 + 300) + 74), | |||
487 | FN_MAILMERGE_EXCLUDE_ENTRY((20000 + 300) + 75), | |||
488 | FN_MAILMERGE_CREATE_DOCUMENTS((20000 + 300) + 77), | |||
489 | FN_MAILMERGE_SAVE_DOCUMENTS((20000 + 300) + 78), | |||
490 | FN_MAILMERGE_PRINT_DOCUMENTS((20000 + 300) + 79), | |||
491 | FN_MAILMERGE_EMAIL_DOCUMENTS((20000 + 300) + 80), | |||
492 | 0 }; | |||
493 | m_pView->GetViewFrame()->GetBindings().Invalidate(slotIds); | |||
494 | } | |||
495 | ||||
496 | // release/destroy asynchronously | |||
497 | Application::PostUserEvent( LINK( this, SwMailMergeWizardExecutor, DestroyDialogHdl )::tools::detail::makeLink( ::tools::detail::castTo<SwMailMergeWizardExecutor *>(this), &SwMailMergeWizardExecutor::LinkStubDestroyDialogHdl ) ); | |||
498 | } | |||
499 | ||||
500 | void SwMailMergeWizardExecutor::ExecuteWizard() | |||
501 | { | |||
502 | m_pWizard->StartExecuteAsync([this](sal_Int32 nResult){ | |||
503 | EndDialogHdl(nResult); | |||
504 | }); | |||
505 | } | |||
506 | ||||
507 | void SwMailMergeWizardExecutor::EndDialogHdl(sal_Int32 nRet) | |||
508 | { | |||
509 | sal_uInt16 nRestartPage = m_pWizard->GetRestartPage(); | |||
510 | ||||
511 | switch ( nRet ) | |||
512 | { | |||
513 | case RET_LOAD_DOC100: | |||
514 | { | |||
515 | SwView* pNewView = lcl_LoadDoc(m_pView, m_pWizard->GetReloadDocument()); | |||
516 | ||||
517 | // Destroy wizard asynchronously, since we are deep inside the wizard and dialog | |||
518 | // machinery code here | |||
519 | m_pWizardToDestroyInCallback = m_pWizard; | |||
520 | Application::PostUserEvent( | |||
521 | LINK( this, SwMailMergeWizardExecutor, DestroyWizardHdl )::tools::detail::makeLink( ::tools::detail::castTo<SwMailMergeWizardExecutor *>(this), &SwMailMergeWizardExecutor::LinkStubDestroyWizardHdl ), nullptr ); | |||
522 | ||||
523 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
524 | std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->GetMailMergeConfigItem(); | |||
525 | if (pNewView) | |||
526 | { | |||
527 | pNewView->SetMailMergeConfigItem(xMMConfig); | |||
528 | m_pView = pNewView; | |||
529 | xMMConfig->DocumentReloaded(); | |||
530 | //new source view! | |||
531 | xMMConfig->SetSourceView( m_pView ); | |||
532 | m_pWizard = pFact->CreateMailMergeWizard(*m_pView, xMMConfig); | |||
533 | m_pWizard->ShowPage( nRestartPage ); | |||
534 | } | |||
535 | else | |||
536 | { | |||
537 | m_pWizard = pFact->CreateMailMergeWizard(*m_pView, xMMConfig); | |||
538 | } | |||
539 | ||||
540 | // execute the wizard again | |||
541 | ExecuteWizard(); | |||
542 | break; | |||
543 | } | |||
544 | case RET_TARGET_CREATED103: | |||
545 | { | |||
546 | std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->GetMailMergeConfigItem(); | |||
547 | SwView* pTargetView = xMMConfig->GetTargetView(); | |||
548 | OSL_ENSURE(pTargetView, "No target view has been created")do { if (true && (!(pTargetView))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "548" ": "), "%s", "No target view has been created"); } } while (false); | |||
549 | if(pTargetView) | |||
550 | { | |||
551 | // destroy wizard asynchronously | |||
552 | m_pWizardToDestroyInCallback = m_pWizard; | |||
553 | Application::PostUserEvent( | |||
554 | LINK( this, SwMailMergeWizardExecutor, DestroyWizardHdl )::tools::detail::makeLink( ::tools::detail::castTo<SwMailMergeWizardExecutor *>(this), &SwMailMergeWizardExecutor::LinkStubDestroyWizardHdl ), nullptr ); | |||
555 | ||||
556 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
557 | m_pWizard = pFact->CreateMailMergeWizard(*pTargetView, xMMConfig); | |||
558 | m_pWizard->ShowPage( nRestartPage ); | |||
559 | ||||
560 | // execute the wizard again | |||
561 | ExecuteWizard(); | |||
562 | } | |||
563 | else | |||
564 | { | |||
565 | // should not happen - just in case no target view has been created | |||
566 | ExecutionFinished(); | |||
567 | } | |||
568 | break; | |||
569 | } | |||
570 | case RET_REMOVE_TARGET104: | |||
571 | { | |||
572 | std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->GetMailMergeConfigItem(); | |||
573 | SwView* pTargetView = xMMConfig->GetTargetView(); | |||
574 | SwView* pSourceView = xMMConfig->GetSourceView(); | |||
575 | OSL_ENSURE(pTargetView && pSourceView, "source or target view not available" )do { if (true && (!(pTargetView && pSourceView ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" ":" "575" ": "), "%s", "source or target view not available" ); } } while (false); | |||
576 | if(pTargetView && pSourceView) | |||
577 | { | |||
578 | m_pView2Close = pTargetView; | |||
579 | pTargetView->GetViewFrame()->GetTopViewFrame()->GetWindow().Hide(); | |||
580 | pSourceView->GetViewFrame()->GetFrame().AppearWithUpdate(); | |||
581 | // the current view has be set when the target is destroyed | |||
582 | m_pView = pSourceView; | |||
583 | xMMConfig->SetTargetView(nullptr); | |||
584 | ||||
585 | // destroy wizard asynchronously | |||
586 | m_pWizardToDestroyInCallback = m_pWizard; | |||
587 | Application::PostUserEvent( | |||
588 | LINK( this, SwMailMergeWizardExecutor, CloseFrameHdl )::tools::detail::makeLink( ::tools::detail::castTo<SwMailMergeWizardExecutor *>(this), &SwMailMergeWizardExecutor::LinkStubCloseFrameHdl ), m_pWizard ); | |||
589 | ||||
590 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
591 | m_pWizard = pFact->CreateMailMergeWizard(*pSourceView, xMMConfig); | |||
592 | m_pWizard->ShowPage( nRestartPage ); | |||
593 | ||||
594 | // execute the wizard again | |||
595 | ExecuteWizard(); | |||
596 | } | |||
597 | else | |||
598 | { | |||
599 | // should not happen - just in case no target view has been created | |||
600 | ExecutionFinished(); | |||
601 | } | |||
602 | break; | |||
603 | } | |||
604 | case RET_CANCEL: | |||
605 | { | |||
606 | // close frame and destroy wizard asynchronously | |||
607 | Application::PostUserEvent( | |||
608 | LINK( this, SwMailMergeWizardExecutor, CancelHdl )::tools::detail::makeLink( ::tools::detail::castTo<SwMailMergeWizardExecutor *>(this), &SwMailMergeWizardExecutor::LinkStubCancelHdl ), m_pWizard ); | |||
609 | break; | |||
610 | } | |||
611 | default: // finish | |||
612 | { | |||
613 | std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->GetMailMergeConfigItem(); | |||
614 | SwView* pSourceView = xMMConfig ? xMMConfig->GetSourceView() : nullptr; | |||
615 | if(pSourceView) | |||
616 | { | |||
617 | xMMConfig->GetSourceView()->GetViewFrame()->GetFrame().Appear(); | |||
618 | } | |||
619 | ExecutionFinished(); | |||
620 | break; | |||
621 | } | |||
622 | ||||
623 | } // switch | |||
624 | } | |||
625 | ||||
626 | IMPL_LINK_NOARG(SwMailMergeWizardExecutor, DestroyDialogHdl, void*, void)void SwMailMergeWizardExecutor::LinkStubDestroyDialogHdl(void * instance, void* data) { return static_cast<SwMailMergeWizardExecutor *>(instance)->DestroyDialogHdl(data); } void SwMailMergeWizardExecutor ::DestroyDialogHdl(__attribute__ ((unused)) void*) | |||
627 | { | |||
628 | m_pWizard.disposeAndClear(); | |||
629 | ||||
630 | release(); | |||
631 | } | |||
632 | ||||
633 | IMPL_LINK_NOARG(SwMailMergeWizardExecutor, DestroyWizardHdl, void*, void)void SwMailMergeWizardExecutor::LinkStubDestroyWizardHdl(void * instance, void* data) { return static_cast<SwMailMergeWizardExecutor *>(instance)->DestroyWizardHdl(data); } void SwMailMergeWizardExecutor ::DestroyWizardHdl(__attribute__ ((unused)) void*) | |||
| ||||
634 | { | |||
635 | m_pWizardToDestroyInCallback.disposeAndClear(); | |||
636 | } | |||
637 | ||||
638 | IMPL_LINK_NOARG(SwMailMergeWizardExecutor, CancelHdl, void*, void)void SwMailMergeWizardExecutor::LinkStubCancelHdl(void * instance , void* data) { return static_cast<SwMailMergeWizardExecutor *>(instance)->CancelHdl(data); } void SwMailMergeWizardExecutor ::CancelHdl(__attribute__ ((unused)) void*) | |||
639 | { | |||
640 | std::shared_ptr<SwMailMergeConfigItem> xMMConfig = m_pView->GetMailMergeConfigItem(); | |||
641 | if (xMMConfig) | |||
642 | { | |||
643 | if (xMMConfig->GetTargetView()) | |||
644 | { | |||
645 | xMMConfig->GetTargetView()->GetViewFrame()->DoClose(); | |||
646 | xMMConfig->SetTargetView(nullptr); | |||
647 | } | |||
648 | if (xMMConfig->GetSourceView()) | |||
649 | { | |||
650 | auto pViewFrame(xMMConfig->GetSourceView()->GetViewFrame()); | |||
651 | pViewFrame->GetFrame().AppearWithUpdate(); | |||
652 | } | |||
653 | xMMConfig->Commit(); | |||
654 | } | |||
655 | ||||
656 | // Revoke created connections | |||
657 | SwDoc* pDoc = m_pView->GetDocShell()->GetDoc(); | |||
658 | SwDBManager* pDbManager = pDoc->GetDBManager(); | |||
659 | if (pDbManager) | |||
660 | pDbManager->RevokeLastRegistrations(); | |||
661 | ||||
662 | m_pWizard.disposeAndClear(); | |||
663 | release(); | |||
664 | } | |||
665 | ||||
666 | IMPL_LINK_NOARG(SwMailMergeWizardExecutor, CloseFrameHdl, void*, void)void SwMailMergeWizardExecutor::LinkStubCloseFrameHdl(void * instance , void* data) { return static_cast<SwMailMergeWizardExecutor *>(instance)->CloseFrameHdl(data); } void SwMailMergeWizardExecutor ::CloseFrameHdl(__attribute__ ((unused)) void*) | |||
667 | { | |||
668 | if ( m_pView2Close ) | |||
669 | { | |||
670 | m_pView2Close->GetViewFrame()->DoClose(); | |||
671 | m_pView2Close = nullptr; | |||
672 | } | |||
673 | m_pWizardToDestroyInCallback.disposeAndClear(); | |||
674 | } | |||
675 | } // namespace | |||
676 | ||||
677 | #endif // HAVE_FEATURE_DBCONNECTIVITY | |||
678 | ||||
679 | void SwModule::ExecOther(SfxRequest& rReq) | |||
680 | { | |||
681 | const SfxItemSet *pArgs = rReq.GetArgs(); | |||
682 | const SfxPoolItem* pItem = nullptr; | |||
683 | ||||
684 | sal_uInt16 nWhich = rReq.GetSlot(); | |||
685 | switch (nWhich) | |||
686 | { | |||
687 | case FN_ENVELOP((20000 + 1050) ): | |||
688 | InsertEnv( rReq ); | |||
689 | break; | |||
690 | ||||
691 | case FN_BUSINESS_CARD(20000 + 1052): | |||
692 | case FN_LABEL(20000 + 1051 ): | |||
693 | InsertLab(rReq, nWhich == FN_LABEL(20000 + 1051 )); | |||
694 | break; | |||
695 | ||||
696 | case FN_XFORMS_INIT(20000 + 1053): | |||
697 | NewXForms( rReq ); | |||
698 | break; | |||
699 | ||||
700 | case SID_ATTR_METRICTypedWhichId<SfxUInt16Item>(((((10000 + 1499) + 1) + 499 ) + 1) + 8): | |||
701 | if(pArgs && SfxItemState::SET == pArgs->GetItemState(nWhich, false, &pItem)) | |||
702 | { | |||
703 | FieldUnit eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); | |||
704 | switch( eUnit ) | |||
705 | { | |||
706 | case FieldUnit::MM: | |||
707 | case FieldUnit::CM: | |||
708 | case FieldUnit::INCH: | |||
709 | case FieldUnit::PICA: | |||
710 | case FieldUnit::POINT: | |||
711 | { | |||
712 | SwView* pActView = ::GetActiveView(); | |||
713 | bool bWebView = dynamic_cast<SwWebView*>( pActView ) != nullptr; | |||
714 | ::SetDfltMetric(eUnit, bWebView); | |||
715 | } | |||
716 | break; | |||
717 | default:;//prevent warning | |||
718 | } | |||
719 | } | |||
720 | break; | |||
721 | ||||
722 | case FN_SET_MODOPT_TBLNUMFMT((20000 + 200) + 52): | |||
723 | { | |||
724 | bool bWebView = dynamic_cast<SwWebView*>( ::GetActiveView() )!= nullptr , | |||
725 | bSet; | |||
726 | ||||
727 | if( pArgs && SfxItemState::SET == pArgs->GetItemState( | |||
728 | nWhich, false, &pItem )) | |||
729 | bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
730 | else | |||
731 | bSet = !m_pModuleConfig->IsInsTableFormatNum( bWebView ); | |||
732 | ||||
733 | m_pModuleConfig->SetInsTableFormatNum( bWebView, bSet ); | |||
734 | } | |||
735 | break; | |||
736 | #if HAVE_FEATURE_DBCONNECTIVITY1 | |||
737 | case FN_MAILMERGE_WIZARD((20000 + 300) + 64): | |||
738 | { | |||
739 | // show the mailmerge wizard | |||
740 | rtl::Reference< SwMailMergeWizardExecutor > xEx( new SwMailMergeWizardExecutor ); | |||
741 | xEx->ExecuteMailMergeWizard( pArgs ); | |||
742 | } | |||
743 | break; | |||
744 | case FN_MAILMERGE_FIRST_ENTRY((20000 + 300) + 70): | |||
745 | case FN_MAILMERGE_PREV_ENTRY((20000 + 300) + 71): | |||
746 | case FN_MAILMERGE_NEXT_ENTRY((20000 + 300) + 72): | |||
747 | case FN_MAILMERGE_LAST_ENTRY((20000 + 300) + 73): | |||
748 | case FN_MAILMERGE_CURRENT_ENTRY((20000 + 300) + 74): | |||
749 | { | |||
750 | SwView* pView = ::GetActiveView(); | |||
751 | const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = pView->GetMailMergeConfigItem(); | |||
752 | if (!xConfigItem) | |||
753 | return; | |||
754 | ||||
755 | const bool bHadConnection | |||
756 | = xConfigItem->GetConnection().is() && !xConfigItem->GetConnection()->isClosed(); | |||
757 | ||||
758 | sal_Int32 nPos = xConfigItem->GetResultSetPosition(); | |||
759 | switch (nWhich) | |||
760 | { | |||
761 | case FN_MAILMERGE_FIRST_ENTRY((20000 + 300) + 70): xConfigItem->MoveResultSet(1); break; | |||
762 | case FN_MAILMERGE_PREV_ENTRY((20000 + 300) + 71): xConfigItem->MoveResultSet(nPos - 1); break; | |||
763 | case FN_MAILMERGE_NEXT_ENTRY((20000 + 300) + 72): xConfigItem->MoveResultSet(nPos + 1); break; | |||
764 | case FN_MAILMERGE_LAST_ENTRY((20000 + 300) + 73): xConfigItem->MoveResultSet(-1); break; | |||
765 | case FN_MAILMERGE_CURRENT_ENTRY((20000 + 300) + 74): /* don't move the result set, just update the document */ break; | |||
766 | default: break; | |||
767 | } | |||
768 | ||||
769 | // now the record has to be merged into the source document | |||
770 | // TODO can we re-use PerformMailMerge() here somehow? | |||
771 | const SwDBData& rDBData = xConfigItem->GetCurrentDBData(); | |||
772 | uno::Sequence<uno::Any> vSelection({ uno::makeAny(xConfigItem->GetResultSetPosition()) }); | |||
773 | svx::ODataAccessDescriptor aDescriptor(::comphelper::InitPropertySequence({ | |||
774 | {"Selection", uno::makeAny(vSelection)}, | |||
775 | {"DataSourceName", uno::makeAny(rDBData.sDataSource)}, | |||
776 | {"Command", uno::makeAny(rDBData.sCommand)}, | |||
777 | {"CommandType", uno::makeAny(rDBData.nCommandType)}, | |||
778 | {"ActiveConnection", uno::makeAny(xConfigItem->GetConnection().getTyped())}, | |||
779 | {"Filter", uno::makeAny(xConfigItem->GetFilter())}, | |||
780 | {"Cursor", uno::makeAny(xConfigItem->GetResultSet())} | |||
781 | })); | |||
782 | ||||
783 | SwWrtShell& rSh = pView->GetWrtShell(); | |||
784 | SwMergeDescriptor aMergeDesc(DBMGR_MERGE, rSh, aDescriptor); | |||
785 | rSh.GetDBManager()->Merge(aMergeDesc); | |||
786 | ||||
787 | // update enabled / disabled status of the buttons in the toolbar | |||
788 | SfxBindings& rBindings = rSh.GetView().GetViewFrame()->GetBindings(); | |||
789 | rBindings.Invalidate(FN_MAILMERGE_FIRST_ENTRY((20000 + 300) + 70)); | |||
790 | rBindings.Invalidate(FN_MAILMERGE_PREV_ENTRY((20000 + 300) + 71)); | |||
791 | rBindings.Invalidate(FN_MAILMERGE_NEXT_ENTRY((20000 + 300) + 72)); | |||
792 | rBindings.Invalidate(FN_MAILMERGE_LAST_ENTRY((20000 + 300) + 73)); | |||
793 | rBindings.Invalidate(FN_MAILMERGE_CURRENT_ENTRY((20000 + 300) + 74)); | |||
794 | rBindings.Invalidate(FN_MAILMERGE_EXCLUDE_ENTRY((20000 + 300) + 75)); | |||
795 | if (!bHadConnection && xConfigItem->GetConnection().is() | |||
796 | && !xConfigItem->GetConnection()->isClosed()) | |||
797 | { | |||
798 | // The connection has been activated. Update controls that were disabled | |||
799 | rBindings.Invalidate(FN_MAILMERGE_CREATE_DOCUMENTS((20000 + 300) + 77)); | |||
800 | rBindings.Invalidate(FN_MAILMERGE_SAVE_DOCUMENTS((20000 + 300) + 78)); | |||
801 | rBindings.Invalidate(FN_MAILMERGE_PRINT_DOCUMENTS((20000 + 300) + 79)); | |||
802 | rBindings.Invalidate(FN_MAILMERGE_EMAIL_DOCUMENTS((20000 + 300) + 80)); | |||
803 | } | |||
804 | rBindings.Update(); | |||
805 | } | |||
806 | break; | |||
807 | case FN_MAILMERGE_CREATE_DOCUMENTS((20000 + 300) + 77): | |||
808 | { | |||
809 | std::shared_ptr<SwMailMergeConfigItem> xConfigItem = SwDBManager::PerformMailMerge(GetActiveView()); | |||
810 | ||||
811 | if (xConfigItem && xConfigItem->GetTargetView()) | |||
812 | xConfigItem->GetTargetView()->GetViewFrame()->GetFrame().Appear(); | |||
813 | } | |||
814 | break; | |||
815 | case FN_MAILMERGE_SAVE_DOCUMENTS((20000 + 300) + 78): | |||
816 | case FN_MAILMERGE_PRINT_DOCUMENTS((20000 + 300) + 79): | |||
817 | case FN_MAILMERGE_EMAIL_DOCUMENTS((20000 + 300) + 80): | |||
818 | { | |||
819 | std::shared_ptr<SwMailMergeConfigItem> xConfigItem = GetActiveView()->GetMailMergeConfigItem(); | |||
820 | if(!xConfigItem) | |||
821 | return; | |||
822 | xConfigItem->SetTargetView(nullptr); | |||
823 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
824 | switch (nWhich) | |||
825 | { | |||
826 | case FN_MAILMERGE_SAVE_DOCUMENTS((20000 + 300) + 78): pFact->ExecuteMMResultSaveDialog(rReq.GetFrameWeld()); break; | |||
827 | case FN_MAILMERGE_PRINT_DOCUMENTS((20000 + 300) + 79): pFact->ExecuteMMResultPrintDialog(rReq.GetFrameWeld()); break; | |||
828 | case FN_MAILMERGE_EMAIL_DOCUMENTS((20000 + 300) + 80): pFact->ExecuteMMResultEmailDialog(rReq.GetFrameWeld()); break; | |||
829 | } | |||
830 | } | |||
831 | break; | |||
832 | #endif | |||
833 | } | |||
834 | } | |||
835 | ||||
836 | // Catch notifications | |||
837 | ||||
838 | // Catch hint for DocInfo | |||
839 | void SwModule::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) | |||
840 | { | |||
841 | if( const SfxEventHint* pEvHint = dynamic_cast<const SfxEventHint*>( &rHint) ) | |||
842 | { | |||
843 | SwDocShell* pDocSh = dynamic_cast<SwDocShell*>( pEvHint->GetObjShell() ); | |||
844 | if( pDocSh ) | |||
845 | { | |||
846 | SwWrtShell* pWrtSh = pDocSh->GetWrtShell(); | |||
847 | switch( pEvHint->GetEventId() ) | |||
848 | { | |||
849 | case SfxEventHintId::LoadFinished: | |||
850 | // if it is a new document created from a template, | |||
851 | // update fixed fields | |||
852 | if (pDocSh->GetMedium()) | |||
853 | { | |||
854 | const SfxBoolItem* pTemplateItem = SfxItemSet::GetItem<SfxBoolItem>(pDocSh->GetMedium()->GetItemSet(), SID_TEMPLATE(5000 + 1519), false); | |||
855 | if (pTemplateItem && pTemplateItem->GetValue()) | |||
856 | { | |||
857 | // assume that not calling via SwEditShell::SetFixFields | |||
858 | // is allowed, because the shell hasn't been created yet | |||
859 | assert(!pWrtSh)(static_cast <bool> (!pWrtSh) ? void (0) : __assert_fail ("!pWrtSh", "/home/maarten/src/libreoffice/core/sw/source/uibase/app/apphdl.cxx" , 859, __extension__ __PRETTY_FUNCTION__)); | |||
860 | pDocSh->GetDoc()->getIDocumentFieldsAccess().SetFixFields(nullptr); | |||
861 | } | |||
862 | } | |||
863 | break; | |||
864 | case SfxEventHintId::CreateDoc: | |||
865 | // Update all FIX-Date/Time fields | |||
866 | if( pWrtSh ) | |||
867 | { | |||
868 | const SfxUInt16Item* pUpdateDocItem = SfxItemSet::GetItem<SfxUInt16Item>(pDocSh->GetMedium()->GetItemSet(), SID_UPDATEDOCMODE(5000 + 1668), false); | |||
869 | bool bUpdateFields = true; | |||
870 | if( pUpdateDocItem && pUpdateDocItem->GetValue() == document::UpdateDocMode::NO_UPDATE) | |||
871 | bUpdateFields = false; | |||
872 | if(bUpdateFields) | |||
873 | { | |||
874 | comphelper::dispatchCommand(".uno:UpdateInputFields", {}); | |||
875 | ||||
876 | // Are database fields contained? | |||
877 | // Get all used databases for the first time | |||
878 | SwDoc *pDoc = pDocSh->GetDoc(); | |||
879 | std::vector<OUString> aDBNameList; | |||
880 | pDoc->GetAllUsedDB( aDBNameList ); | |||
881 | if(!aDBNameList.empty()) | |||
882 | { // Open database beamer | |||
883 | ShowDBObj(pWrtSh->GetView(), pDoc->GetDBData()); | |||
884 | } | |||
885 | } | |||
886 | } | |||
887 | break; | |||
888 | default: break; | |||
889 | } | |||
890 | } | |||
891 | } | |||
892 | else if(const SfxItemSetHint* pSfxItemSetHint = dynamic_cast<const SfxItemSetHint*>(&rHint)) | |||
893 | { | |||
894 | if( SfxItemState::SET == pSfxItemSetHint->GetItemSet().GetItemState(SID_ATTR_PATHNAME(((((10000 + 1499) + 1) + 499) + 1) + 11))) | |||
895 | { | |||
896 | ::GetGlossaries()->UpdateGlosPath( false ); | |||
897 | SwGlossaryList* pList = ::GetGlossaryList(); | |||
898 | if(pList->IsActive()) | |||
899 | pList->Update(); | |||
900 | } | |||
901 | } | |||
902 | else | |||
903 | { | |||
904 | if (rHint.GetId() == SfxHintId::Deinitializing) | |||
905 | { | |||
906 | m_pWebUsrPref.reset(); | |||
907 | m_pUsrPref.reset(); | |||
908 | m_pModuleConfig.reset(); | |||
909 | m_pPrintOptions.reset(); | |||
910 | m_pWebPrintOptions.reset(); | |||
911 | m_pChapterNumRules.reset(); | |||
912 | m_pStdFontConfig.reset(); | |||
913 | m_pNavigationConfig.reset(); | |||
914 | m_pToolbarConfig.reset(); | |||
915 | m_pWebToolbarConfig.reset(); | |||
916 | m_pDBConfig.reset(); | |||
917 | if( m_pColorConfig ) | |||
918 | { | |||
919 | m_pColorConfig->RemoveListener(this); | |||
920 | m_pColorConfig.reset(); | |||
921 | } | |||
922 | if( m_pAccessibilityOptions ) | |||
923 | { | |||
924 | m_pAccessibilityOptions->RemoveListener(this); | |||
925 | m_pAccessibilityOptions.reset(); | |||
926 | } | |||
927 | if( m_pCTLOptions ) | |||
928 | { | |||
929 | m_pCTLOptions->RemoveListener(this); | |||
930 | m_pCTLOptions.reset(); | |||
931 | } | |||
932 | if( m_pUserOptions ) | |||
933 | { | |||
934 | m_pUserOptions->RemoveListener(this); | |||
935 | m_pUserOptions.reset(); | |||
936 | } | |||
937 | } | |||
938 | } | |||
939 | } | |||
940 | ||||
941 | void SwModule::ConfigurationChanged( utl::ConfigurationBroadcaster* pBrdCst, ConfigurationHints ) | |||
942 | { | |||
943 | if( pBrdCst == m_pUserOptions.get() ) | |||
944 | { | |||
945 | m_bAuthorInitialised = false; | |||
946 | } | |||
947 | else if ( pBrdCst == m_pColorConfig.get() || pBrdCst == m_pAccessibilityOptions.get() ) | |||
948 | { | |||
949 | bool bAccessibility = false; | |||
950 | if( pBrdCst == m_pColorConfig.get() ) | |||
951 | SwViewOption::ApplyColorConfigValues(*m_pColorConfig); | |||
952 | else | |||
953 | bAccessibility = true; | |||
954 | ||||
955 | //invalidate all edit windows | |||
956 | SfxViewShell* pViewShell = SfxViewShell::GetFirst(); | |||
957 | while(pViewShell) | |||
958 | { | |||
959 | if(pViewShell->GetWindow()) | |||
960 | { | |||
961 | if(dynamic_cast< const SwView *>( pViewShell ) != nullptr || | |||
962 | dynamic_cast< const SwPagePreview *>( pViewShell ) != nullptr || | |||
963 | dynamic_cast< const SwSrcView *>( pViewShell ) != nullptr) | |||
964 | { | |||
965 | if(bAccessibility) | |||
966 | { | |||
967 | if(dynamic_cast< const SwView *>( pViewShell ) != nullptr) | |||
968 | static_cast<SwView*>(pViewShell)->ApplyAccessibilityOptions(*m_pAccessibilityOptions); | |||
969 | else if(dynamic_cast< const SwPagePreview *>( pViewShell ) != nullptr) | |||
970 | static_cast<SwPagePreview*>(pViewShell)->ApplyAccessibilityOptions(*m_pAccessibilityOptions); | |||
971 | } | |||
972 | pViewShell->GetWindow()->Invalidate(); | |||
973 | } | |||
974 | } | |||
975 | pViewShell = SfxViewShell::GetNext( *pViewShell ); | |||
976 | } | |||
977 | } | |||
978 | else if( pBrdCst == m_pCTLOptions.get() ) | |||
979 | { | |||
980 | const SfxObjectShell* pObjSh = SfxObjectShell::GetFirst(); | |||
981 | while( pObjSh ) | |||
982 | { | |||
983 | if( auto pDocShell = dynamic_cast<const SwDocShell*>(pObjSh) ) | |||
984 | { | |||
985 | SwDoc* pDoc = const_cast<SwDocShell*>(pDocShell)->GetDoc(); | |||
986 | SwViewShell* pVSh = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell(); | |||
987 | if ( pVSh ) | |||
988 | pVSh->ChgNumberDigits(); | |||
989 | } | |||
990 | pObjSh = SfxObjectShell::GetNext(*pObjSh); | |||
991 | } | |||
992 | } | |||
993 | ||||
994 | } | |||
995 | ||||
996 | SwDBConfig* SwModule::GetDBConfig() | |||
997 | { | |||
998 | if(!m_pDBConfig) | |||
999 | m_pDBConfig.reset(new SwDBConfig); | |||
1000 | return m_pDBConfig.get(); | |||
1001 | } | |||
1002 | ||||
1003 | svtools::ColorConfig& SwModule::GetColorConfig() | |||
1004 | { | |||
1005 | if(!m_pColorConfig) | |||
1006 | { | |||
1007 | m_pColorConfig.reset(new svtools::ColorConfig); | |||
1008 | SwViewOption::ApplyColorConfigValues(*m_pColorConfig); | |||
1009 | m_pColorConfig->AddListener(this); | |||
1010 | } | |||
1011 | return *m_pColorConfig; | |||
1012 | } | |||
1013 | ||||
1014 | SvtAccessibilityOptions& SwModule::GetAccessibilityOptions() | |||
1015 | { | |||
1016 | if(!m_pAccessibilityOptions) | |||
1017 | { | |||
1018 | m_pAccessibilityOptions.reset(new SvtAccessibilityOptions); | |||
1019 | m_pAccessibilityOptions->AddListener(this); | |||
1020 | } | |||
1021 | return *m_pAccessibilityOptions; | |||
1022 | } | |||
1023 | ||||
1024 | SvtCTLOptions& SwModule::GetCTLOptions() | |||
1025 | { | |||
1026 | if(!m_pCTLOptions) | |||
1027 | { | |||
1028 | m_pCTLOptions.reset(new SvtCTLOptions); | |||
1029 | m_pCTLOptions->AddListener(this); | |||
1030 | } | |||
1031 | return *m_pCTLOptions; | |||
1032 | } | |||
1033 | ||||
1034 | SvtUserOptions& SwModule::GetUserOptions() | |||
1035 | { | |||
1036 | if(!m_pUserOptions) | |||
1037 | { | |||
1038 | m_pUserOptions.reset(new SvtUserOptions); | |||
1039 | m_pUserOptions->AddListener(this); | |||
1040 | } | |||
1041 | return *m_pUserOptions; | |||
1042 | } | |||
1043 | ||||
1044 | const SwMasterUsrPref *SwModule::GetUsrPref(bool bWeb) const | |||
1045 | { | |||
1046 | SwModule* pNonConstModule = const_cast<SwModule*>(this); | |||
1047 | if(bWeb && !m_pWebUsrPref) | |||
1048 | { | |||
1049 | // The SpellChecker is needed in SwMasterUsrPref's Load, but it must not | |||
1050 | // be created there #58256# | |||
1051 | pNonConstModule->m_pWebUsrPref.reset(new SwMasterUsrPref(true)); | |||
1052 | } | |||
1053 | else if(!bWeb && !m_pUsrPref) | |||
1054 | { | |||
1055 | pNonConstModule->m_pUsrPref.reset(new SwMasterUsrPref(false)); | |||
1056 | } | |||
1057 | return bWeb ? m_pWebUsrPref.get() : m_pUsrPref.get(); | |||
1058 | } | |||
1059 | ||||
1060 | void NewXForms( SfxRequest& rReq ) | |||
1061 | { | |||
1062 | // copied & excerpted from SwModule::InsertLab(..) | |||
1063 | ||||
1064 | // create new document | |||
1065 | SfxObjectShellLock xDocSh( new SwDocShell( SfxObjectCreateMode::STANDARD) ); | |||
1066 | xDocSh->DoInitNew(); | |||
1067 | ||||
1068 | // initialize XForms | |||
1069 | static_cast<SwDocShell*>( &xDocSh )->GetDoc()->initXForms( true ); | |||
1070 | ||||
1071 | // load document into frame | |||
1072 | SfxViewFrame::DisplayNewDocument( *xDocSh, rReq ); | |||
1073 | ||||
1074 | // set return value | |||
1075 | rReq.SetReturnValue( SfxVoidItem( rReq.GetSlot() ) ); | |||
1076 | } | |||
1077 | ||||
1078 | /* 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 |