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