LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / source / appl / appserv.cxx
blobfca05bece8411d7f9527e6d7b54da9aeeb2cf80b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <config_features.h>
21 #include <com/sun/star/drawing/ModuleDispatcher.hpp>
22 #include <com/sun/star/frame/Desktop.hpp>
23 #include <com/sun/star/frame/DispatchResultEvent.hpp>
24 #include <com/sun/star/frame/DispatchResultState.hpp>
25 #include <com/sun/star/frame/DispatchHelper.hpp>
26 #include <com/sun/star/frame/UnknownModuleException.hpp>
27 #include <com/sun/star/frame/XLayoutManager.hpp>
28 #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
29 #include <com/sun/star/sdbc/DriverManager.hpp>
30 #include <com/sun/star/text/ModuleDispatcher.hpp>
31 #include <com/sun/star/task/OfficeRestartManager.hpp>
32 #include <com/sun/star/task/XInteractionHandler.hpp>
33 #include <com/sun/star/ui/dialogs/AddressBookSourcePilot.hpp>
34 #include <com/sun/star/ui/UIElementType.hpp>
35 #include <com/sun/star/ui/XUIElement.hpp>
36 #include <com/sun/star/uno/Reference.hxx>
37 #include <com/sun/star/util/XCloseable.hpp>
38 #include <com/sun/star/util/CloseVetoException.hpp>
39 #include <org/freedesktop/PackageKit/SyncDbusSessionHelper.hpp>
41 #include <comphelper/dispatchcommand.hxx>
42 #include <comphelper/lok.hxx>
43 #include <comphelper/namedvaluecollection.hxx>
44 #include <comphelper/processfactory.hxx>
45 #include <comphelper/propertysequence.hxx>
46 #include <comphelper/propertyvalue.hxx>
47 #include <comphelper/sequence.hxx>
49 #include <svtools/addresstemplate.hxx>
50 #include <svtools/miscopt.hxx>
51 #include <svtools/restartdialog.hxx>
52 #include <svl/visitem.hxx>
54 #include <unotools/configmgr.hxx>
55 #include <tools/diagnose_ex.h>
56 #include <vcl/weld.hxx>
57 #include <svl/intitem.hxx>
58 #include <svl/eitem.hxx>
59 #include <svl/stritem.hxx>
60 #include <basic/sbstar.hxx>
61 #include <basic/basrdll.hxx>
62 #include <basic/sberrors.hxx>
63 #include <vcl/help.hxx>
64 #include <rtl/ustrbuf.hxx>
65 #include <sal/log.hxx>
66 #include <osl/file.hxx>
67 #include <vcl/EnumContext.hxx>
68 #include <vcl/toolbox.hxx>
70 #include <unotools/moduleoptions.hxx>
71 #include <rtl/bootstrap.hxx>
73 #include <com/sun/star/frame/ModuleManager.hpp>
74 #include <com/sun/star/beans/XPropertySet.hpp>
76 #include <sfx2/app.hxx>
77 #include <sfx2/request.hxx>
78 #include <sfx2/dispatch.hxx>
79 #include <sfx2/bindings.hxx>
80 #include <sfx2/msg.hxx>
81 #include <sfx2/objface.hxx>
82 #include <sfx2/objsh.hxx>
83 #include <sfx2/viewsh.hxx>
84 #include <sfx2/docfac.hxx>
85 #include <sfx2/strings.hrc>
86 #include <sfx2/sfxresid.hxx>
87 #include <appdata.hxx>
88 #include <sfx2/viewfrm.hxx>
89 #include <sfx2/sfxdlg.hxx>
90 #include <sfx2/sfxsids.hrc>
91 #include <sorgitm.hxx>
92 #include <sfx2/sfxhelp.hxx>
93 #include <sfx2/zoomitem.hxx>
94 #include <sfx2/templatedlg.hxx>
95 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
96 #include <sfx2/sidebar/SidebarController.hxx>
97 #include <sfx2/safemode.hxx>
98 #include <sfx2/sfxuno.hxx>
99 #include <sfx2/devtools/DevelopmentToolDockingWindow.hxx>
101 #include <comphelper/types.hxx>
102 #include <officecfg/Office/Common.hxx>
103 #include <unotools/confignode.hxx>
104 #include <memory>
106 #include <openuriexternally.hxx>
108 #include "getbasctlfunction.hxx"
110 using namespace ::com::sun::star;
111 using namespace ::com::sun::star::beans;
112 using namespace ::com::sun::star::uno;
113 using namespace ::com::sun::star::frame;
114 using namespace ::com::sun::star::container;
115 using namespace ::com::sun::star::util;
116 using namespace ::com::sun::star::lang;
117 using namespace ::com::sun::star::ui;
119 namespace
121 OUString lcl_getAppName( vcl::EnumContext::Application eApp )
123 switch ( eApp )
125 case vcl::EnumContext::Application::Writer:
126 return "Writer";
127 case vcl::EnumContext::Application::Calc:
128 return "Calc";
129 case vcl::EnumContext::Application::Impress:
130 return "Impress";
131 case vcl::EnumContext::Application::Draw:
132 return "Draw";
133 case vcl::EnumContext::Application::Formula:
134 return "Formula";
135 case vcl::EnumContext::Application::Base:
136 return "Base";
137 default:
138 return OUString();
142 // lp#527938, debian#602953, fdo#33266, i#105408
143 bool lcl_isBaseAvailable()
147 // if we get css::sdbc::DriverManager, libsdbc2 is there
148 // and the bibliography is assumed to work
149 return css::sdbc::DriverManager::create(comphelper::getProcessComponentContext()).is();
151 catch (const Exception &)
153 TOOLS_INFO_EXCEPTION("sfx.appl", "assuming Base to be missing");
154 return false;
157 void lcl_tryLoadBibliography()
159 // lp#527938, debian#602953, fdo#33266, i#105408
160 // make sure we actually can instantiate services from base first
161 if(!lcl_isBaseAvailable())
163 if (officecfg::Office::Common::PackageKit::EnableBaseInstallation::get())
167 using namespace org::freedesktop::PackageKit;
168 using namespace svtools;
169 Reference< XSyncDbusSessionHelper > xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext()));
170 Sequence< OUString > vPackages { "libreoffice-base" };
171 xSyncDbusSessionHelper->InstallPackageNames(vPackages, OUString());
172 // I'll be back (hopefully)!
173 SolarMutexGuard aGuard;
174 executeRestartDialog(comphelper::getProcessComponentContext(), nullptr, RESTART_REASON_BIBLIOGRAPHY_INSTALL);
176 catch (const Exception &)
178 TOOLS_INFO_EXCEPTION("sfx.appl", "trying to install LibreOffice Base");
181 return;
184 try // fdo#48775
186 SfxStringItem aURL(SID_FILE_NAME, ".component:Bibliography/View1");
187 SfxStringItem aRef(SID_REFERER, "private:user");
188 SfxStringItem aTarget(SID_TARGETNAME, "_blank");
189 const SfxViewFrame* pViewFrame = SfxViewFrame::Current();
190 if ( pViewFrame )
191 pViewFrame->GetDispatcher()->ExecuteList(SID_OPENDOC,
192 SfxCallMode::ASYNCHRON, { &aURL, &aRef, &aTarget });
194 catch (const Exception &)
196 TOOLS_INFO_EXCEPTION( "sfx.appl", "trying to load bibliography database");
200 /// Find the correct location of the document (CREDITS.fodt, etc.), and return
201 /// it in rURL if found.
202 static bool checkURL( const char *pName, const char *pExt, OUString &rURL )
204 using namespace osl;
205 DirectoryItem aDirItem;
207 #ifdef MACOSX
208 rURL = "$BRAND_BASE_DIR/Resources/" + OUString::createFromAscii( pName ) +
209 OUString::createFromAscii( pExt );
210 #else
211 rURL = "$BRAND_BASE_DIR/" + OUString::createFromAscii( pName ) +
212 OUString::createFromAscii( pExt );
213 #endif
214 rtl::Bootstrap::expandMacros( rURL );
216 if (!rURL.isEmpty())
217 return DirectoryItem::get( rURL, aDirItem ) == DirectoryItem::E_None;
218 else
219 return false;
222 /// Displays CREDITS or LICENSE in any of the available version
223 static void showDocument( const char* pBaseName )
225 try {
226 Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
227 auto args(::comphelper::InitPropertySequence({
228 {"ViewOnly", makeAny(true)},
229 {"ReadOnly", makeAny(true)}
230 }));
232 OUString aURL;
233 if ( checkURL ( pBaseName, ".fodt", aURL ) ||
234 checkURL ( pBaseName, ".html", aURL ) ||
235 checkURL ( pBaseName, "", aURL ) ) {
236 xDesktop->loadComponentFromURL( aURL, "_blank", 0, args );
238 } catch (const css::uno::Exception &) {
242 namespace
244 Reference<XFrame> GetRequestFrame(const SfxRequest& rReq)
246 const SfxItemSet* pArgs = rReq.GetInternalArgs_Impl();
247 const SfxPoolItem* pItem = nullptr;
248 Reference <XFrame> xFrame;
249 if (pArgs && pArgs->GetItemState(SID_FILLFRAME, false, &pItem) == SfxItemState::SET)
251 assert( dynamic_cast< const SfxUnoFrameItem *>( pItem ) && "SfxApplication::OfaExec_Impl: XFrames are to be transported via SfxUnoFrameItem by now!" );
252 xFrame = static_cast< const SfxUnoFrameItem*>( pItem )->GetFrame();
254 return xFrame;
257 class LicenseDialog : public weld::GenericDialogController
259 private:
260 std::unique_ptr<weld::Button> m_xBtnLicense;
261 std::unique_ptr<weld::Button> m_xBtnEula;
263 DECL_LINK(EulaHdl, weld::Button&, void);
264 DECL_LINK(LicenseHdl, weld::Button&, void);
266 public:
267 LicenseDialog(weld::Window* pParent)
268 : GenericDialogController(pParent, "sfx/ui/licensedialog.ui", "LicenseDialog")
269 , m_xBtnLicense(m_xBuilder->weld_button("license"))
270 , m_xBtnEula(m_xBuilder->weld_button("eula"))
272 m_xBtnLicense->connect_clicked( LINK(this, LicenseDialog, LicenseHdl) );
273 m_xBtnEula->connect_clicked( LINK(this, LicenseDialog, EulaHdl) );
276 virtual short run() override
278 short nRet = GenericDialogController::run();
279 return nRet;
283 IMPL_LINK_NOARG(LicenseDialog, EulaHdl, weld::Button&, void)
285 response(RET_OK);
286 showDocument("EULA.odt");
289 IMPL_LINK_NOARG(LicenseDialog, LicenseHdl, weld::Button&, void)
291 response(RET_OK);
292 showDocument("LICENSE");
296 class SafeModeQueryDialog : public weld::MessageDialogController
298 public:
299 SafeModeQueryDialog(weld::Window* pParent)
300 : MessageDialogController(pParent, "sfx/ui/safemodequerydialog.ui", "SafeModeQueryDialog")
304 virtual short run() override
306 short nRet = MessageDialogController::run();
307 if (nRet == RET_OK)
309 sfx2::SafeMode::putFlag();
310 uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
311 css::task::OfficeRestartManager::get(xContext)->requestRestart(
312 css::uno::Reference< css::task::XInteractionHandler >());
314 return nRet;
319 weld::Window* SfxRequest::GetFrameWeld() const
321 const SfxItemSet* pIntArgs = GetInternalArgs_Impl();
322 const SfxPoolItem* pItem = nullptr;
323 if (pIntArgs && pIntArgs->GetItemState(SID_DIALOG_PARENT, false, &pItem) == SfxItemState::SET)
325 assert(dynamic_cast<const SfxUnoAnyItem*>(pItem));
326 auto aAny = static_cast<const SfxUnoAnyItem*>(pItem)->GetValue();
327 Reference<awt::XWindow> xWindow;
328 aAny >>= xWindow;
329 return Application::GetFrameWeld(xWindow);
332 Reference<XFrame> xFrame(GetRequestFrame(*this));
333 if (!xFrame)
335 SAL_WARN("sfx.appl", "no parent for dialogs");
336 return nullptr;
338 return Application::GetFrameWeld(xFrame->getContainerWindow());
341 void SfxApplication::MiscExec_Impl( SfxRequest& rReq )
343 bool bDone = false;
344 switch ( rReq.GetSlot() )
346 case SID_SETOPTIONS:
348 if( rReq.GetArgs() )
349 SetOptions_Impl( *rReq.GetArgs() );
350 break;
353 case SID_QUITAPP:
354 case SID_LOGOUT:
356 // protect against reentrant calls
357 if ( pImpl->bInQuit )
358 return;
360 if ( rReq.GetSlot() == SID_LOGOUT )
362 for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
363 pObjSh; pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
365 if ( !pObjSh->IsModified() )
366 continue;
368 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pObjSh );
369 if ( !pFrame || !pFrame->GetWindow().IsReallyVisible() )
370 continue;
372 if (pObjSh->PrepareClose())
373 pObjSh->SetModified( false );
374 else
375 return;
378 SfxStringItem aNameItem( SID_FILE_NAME, "vnd.sun.star.cmd:logout" );
379 SfxStringItem aReferer( SID_REFERER, "private/user" );
380 pImpl->pAppDispat->ExecuteList(SID_OPENDOC,
381 SfxCallMode::SLOT, { &aNameItem, &aReferer });
382 return;
385 // try from nested requests again after 100ms
386 if( Application::GetDispatchLevel() > 1 )
388 /* Don't save the request for closing the application and try it later
389 again. This is an UI bound functionality ... and the user will try it again
390 if the dialog is closed. But we should not close the application automatically
391 if this dialog is closed by the user ...
392 So we ignore this request now and wait for a new user decision.
394 SAL_INFO("sfx.appl", "QueryExit => sal_False, DispatchLevel == " << Application::GetDispatchLevel() );
395 return;
398 // block reentrant calls
399 pImpl->bInQuit = true;
400 Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
402 rReq.ForgetAllArgs();
404 // if terminate() failed, pImpl->bInQuit will now be sal_False, allowing further calls of SID_QUITAPP
405 bool bTerminated = xDesktop->terminate();
406 if (!bTerminated)
407 // if terminate() was successful, SfxApplication is now dead!
408 pImpl->bInQuit = false;
410 // Set return value, terminate if possible
411 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bTerminated ) );
412 return;
415 case SID_CONFIG:
416 case SID_TOOLBOXOPTIONS:
417 case SID_CONFIGSTATUSBAR:
418 case SID_CONFIGMENU:
419 case SID_CONFIGACCEL:
420 case SID_CONFIGEVENT:
422 SfxAbstractDialogFactory* pFact =
423 SfxAbstractDialogFactory::Create();
425 const SfxStringItem* pStringItem = rReq.GetArg<SfxStringItem>(SID_CONFIG);
427 SfxItemSetFixed<SID_CONFIG, SID_CONFIG> aSet( GetPool() );
429 if ( pStringItem )
431 aSet.Put( SfxStringItem(
432 SID_CONFIG, pStringItem->GetValue() ) );
435 Reference <XFrame> xFrame(GetRequestFrame(rReq));
436 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateCustomizeTabDialog(rReq.GetFrameWeld(),
437 &aSet, xFrame ));
439 const short nRet = pDlg->Execute();
441 if ( nRet )
442 bDone = true;
443 break;
446 case SID_CLOSEDOCS:
449 Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
450 Reference< XIndexAccess > xTasks = xDesktop->getFrames();
451 if ( !xTasks.is() )
452 break;
454 sal_Int32 n=0;
457 if ( xTasks->getCount() <= n )
458 break;
460 Any aAny = xTasks->getByIndex(n);
461 Reference < XCloseable > xTask;
462 aAny >>= xTask;
465 xTask->close(true);
466 n++;
468 catch( CloseVetoException& )
472 while( true );
474 bool bOk = ( n == 0);
475 rReq.SetReturnValue( SfxBoolItem( 0, bOk ) );
476 bDone = true;
477 break;
480 case SID_SAVEDOCS:
482 bool bOK = true;
483 for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
484 pObjSh;
485 pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
487 SfxRequest aReq( SID_SAVEDOC, SfxCallMode::SLOT, pObjSh->GetPool() );
488 if ( pObjSh->IsModified() && !pObjSh->isSaveLocked())
490 pObjSh->ExecuteSlot( aReq );
491 const SfxBoolItem *pItem = dynamic_cast<const SfxBoolItem*>( aReq.GetReturnValue() );
492 if ( !pItem || !pItem->GetValue() )
493 bOK = false;
497 rReq.SetReturnValue( SfxBoolItem( 0, bOK ) );
498 rReq.Done();
499 break;
502 case SID_SEND_FEEDBACK:
504 OUString module = SfxHelp::GetCurrentModuleIdentifier();
505 OUString sURL("mailto:hello@collaboraoffice.com?Subject=Version:%20" + utl::ConfigManager::getAboutBoxProductVersion() +
506 ",%20Locale:%20" + utl::ConfigManager::getUILocale() + ",%20Module:%20" + module.subView(module.lastIndexOf('.') + 1 ) );
507 sfx2::openUriExternally(sURL, false, rReq.GetFrameWeld());
508 break;
511 case SID_Q_AND_A:
513 // Askbot has URL's normalized to languages, not locales
514 // Get language from locale: ll or lll or ll-CC or lll-CC
516 OUString sURL(officecfg::Office::Common::Menus::QA_URL::get() + //https://hub.libreoffice.org/forum/
517 "?LOlocale=" + utl::ConfigManager::getUILocale());
518 sfx2::openUriExternally(sURL, false, rReq.GetFrameWeld());
519 break;
521 case SID_DOCUMENTATION:
523 // Open documentation page based on locales
524 OUString sURL(officecfg::Office::Common::Menus::DocumentationURL::get() + //https://hub.libreoffice.org/documentation/
525 "?LOlocale=" + utl::ConfigManager::getUILocale());
526 sfx2::openUriExternally(sURL, false, rReq.GetFrameWeld());
527 break;
529 case SID_GETINVOLVED:
531 // Open get involved/join us page based on locales
532 OUString sURL(officecfg::Office::Common::Menus::GetInvolvedURL::get() + //https://hub.libreoffice.org/joinus/
533 "?LOlocale=" + utl::ConfigManager::getUILocale());
534 sfx2::openUriExternally(sURL, false, rReq.GetFrameWeld());
535 break;
537 case SID_DONATION:
539 // Open donation page based on language + script (BCP47) with language as fall back.
540 OUString aLang = LanguageTag(utl::ConfigManager::getUILocale()).getLanguage();
541 OUString aBcp47 = LanguageTag(utl::ConfigManager::getUILocale()).getBcp47();
542 OUString sURL(officecfg::Office::Common::Menus::DonationURL::get() + //https://hub.libreoffice.org/donation/
543 "?BCP47=" + aBcp47 + "&LOlang=" + aLang );
544 sfx2::openUriExternally(sURL, false, rReq.GetFrameWeld());
545 break;
547 case SID_WHATSNEW:
549 // Open release notes depending on version and locale
550 OUString sURL(officecfg::Office::Common::Menus::ReleaseNotesURL::get() + //https://hub.libreoffice.org/ReleaseNotes/
551 "?LOvers=" + utl::ConfigManager::getProductVersion() +
552 "&LOlocale=" + LanguageTag(utl::ConfigManager::getUILocale()).getBcp47() );
553 sfx2::openUriExternally(sURL, false, rReq.GetFrameWeld());
554 break;
556 case SID_HYPHENATIONMISSING:
558 // Open wiki page about hyphenation
559 OUString sURL(officecfg::Office::Common::Menus::HyphenationMissingURL::get() + //https://hub.libreoffice.org/HyphenationMissing/
560 "?LOlocale=" + utl::ConfigManager::getUILocale());
561 sfx2::openUriExternally(sURL, false, rReq.GetFrameWeld());
562 break;
564 case SID_SHOW_LICENSE:
566 LicenseDialog aDialog(rReq.GetFrameWeld());
567 aDialog.run();
568 break;
571 case SID_SHOW_CREDITS:
573 showDocument( "CREDITS" );
574 break;
577 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
578 case SID_HELPINDEX:
580 Help* pHelp = Application::GetHelp();
581 if ( pHelp )
583 pHelp->Start(".uno:HelpIndex", rReq.GetFrameWeld()); // show start page
584 bDone = true;
586 break;
589 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
590 case SID_HELPTIPS:
592 // Evaluate Parameter
593 const SfxBoolItem* pOnItem = rReq.GetArg<SfxBoolItem>(SID_HELPTIPS);
594 bool bOn = pOnItem
595 ? pOnItem->GetValue()
596 : !Help::IsQuickHelpEnabled();
598 if ( bOn )
599 Help::EnableQuickHelp();
600 else
601 Help::DisableQuickHelp();
602 auto xChanges = comphelper::ConfigurationChanges::create();
603 officecfg::Office::Common::Help::Tip::set(bOn, xChanges);
604 xChanges->commit();
605 Invalidate(SID_HELPTIPS);
606 bDone = true;
608 // Record if possible
609 if ( !rReq.IsAPI() )
610 rReq.AppendItem( SfxBoolItem( SID_HELPTIPS, bOn) );
611 break;
613 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
614 case SID_EXTENDEDHELP:
616 Help::StartExtHelp();
617 break;
619 case SID_HELPBALLOONS:
621 // Evaluate Parameter
622 const SfxBoolItem* pOnItem = rReq.GetArg<SfxBoolItem>(SID_HELPBALLOONS);
623 bool bOn = pOnItem
624 ? pOnItem->GetValue()
625 : !Help::IsBalloonHelpEnabled();
627 if ( bOn )
628 Help::EnableBalloonHelp();
629 else
630 Help::DisableBalloonHelp();
631 auto xChanges = comphelper::ConfigurationChanges::create();
632 officecfg::Office::Common::Help::ExtendedTip::set(bOn, xChanges);
633 xChanges->commit();
634 Invalidate(SID_HELPBALLOONS);
635 bDone = true;
637 // Record if possible
638 if ( !rReq.IsAPI() )
639 rReq.AppendItem( SfxBoolItem( SID_HELPBALLOONS, bOn) );
640 break;
642 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
643 case SID_TIPOFTHEDAY:
645 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
646 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateTipOfTheDayDialog(rReq.GetFrameWeld()));
647 pDlg->StartExecuteAsync(nullptr);
648 bDone = true;
649 break;
651 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
652 case SID_WIDGET_TEST_DIALOG:
654 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
655 VclPtr<VclAbstractDialog> pDlg(pFact->CreateWidgetTestDialog(rReq.GetFrameWeld()));
656 pDlg->StartExecuteAsync([pDlg](sal_Int32 /*nResult*/){
657 pDlg->disposeOnce();
659 bDone = true;
660 break;
663 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
664 case SID_ABOUT:
666 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
667 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateAboutDialog(rReq.GetFrameWeld()));
668 pDlg->StartExecuteAsync(nullptr);
669 bDone = true;
670 break;
673 case SID_TEMPLATE_MANAGER:
675 SfxTemplateManagerDlg aDialog(rReq.GetFrameWeld());
676 aDialog.run();
677 bDone = true;
678 break;
681 case SID_TEMPLATE_ADDRESSBOOKSOURCE:
683 svt::AddressBookSourceDialog aDialog(rReq.GetFrameWeld(), ::comphelper::getProcessComponentContext());
684 aDialog.run();
685 bDone = true;
686 break;
689 #if HAVE_FEATURE_SCRIPTING
690 case SID_BASICSTOP:
691 StarBASIC::Stop();
692 break;
694 case SID_BASICBREAK :
695 BasicDLL::BasicBreak();
696 break;
697 #endif
699 case SID_ZOOM_50_PERCENT:
700 case SID_ZOOM_75_PERCENT:
701 case SID_ZOOM_100_PERCENT:
702 case SID_ZOOM_150_PERCENT:
703 case SID_ZOOM_200_PERCENT:
704 case SID_ZOOM_OPTIMAL:
705 case SID_ZOOM_ENTIRE_PAGE:
706 case SID_ZOOM_PAGE_WIDTH:
708 SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
709 if (!pCurrentShell)
710 return;
712 // make sure aZoom is initialized with a proper value if SetType
713 // doesn't work
714 SvxZoomItem aZoom( SvxZoomType::PERCENT, 100 );
716 switch (rReq.GetSlot())
718 case SID_ZOOM_50_PERCENT:
719 aZoom.SetValue(50);
720 break;
721 case SID_ZOOM_75_PERCENT:
722 aZoom.SetValue(75);
723 break;
724 case SID_ZOOM_100_PERCENT:
725 aZoom.SetValue(100);
726 break;
727 case SID_ZOOM_150_PERCENT:
728 aZoom.SetValue(150);
729 break;
730 case SID_ZOOM_200_PERCENT:
731 aZoom.SetValue(200);
732 break;
733 case SID_ZOOM_OPTIMAL:
734 aZoom.SetType( SvxZoomType::OPTIMAL );
735 break;
736 case SID_ZOOM_ENTIRE_PAGE:
737 aZoom.SetType( SvxZoomType::WHOLEPAGE );
738 break;
739 case SID_ZOOM_PAGE_WIDTH:
740 aZoom.SetType( SvxZoomType::PAGEWIDTH );
741 break;
744 pCurrentShell->GetDispatcher()->ExecuteList(SID_ATTR_ZOOM, SfxCallMode::ASYNCHRON, { &aZoom });
746 break;
748 case SID_TOOLBAR_MODE:
750 const SfxStringItem* pModeName = rReq.GetArg<SfxStringItem>( SID_TOOLBAR_MODE );
752 if ( !pModeName )
754 bDone = true;
755 break;
758 OUString aNewName(pModeName->GetValue());
759 uno::Reference< uno::XComponentContext > xContext =
760 ::comphelper::getProcessComponentContext();
762 // Get information about current frame and module
763 Reference<XFrame> xCurrentFrame;
764 vcl::EnumContext::Application eCurrentApp = vcl::EnumContext::Application::NONE;
765 OUString aCurrentMode;
767 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
768 if( pViewFrame )
770 xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface();
772 const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xContext );
773 eCurrentApp = vcl::EnumContext::GetApplicationEnum( xModuleManager->identify( xCurrentFrame ) );
775 OUString aPath = "org.openoffice.Office.UI.ToolbarMode/Applications/" +
776 lcl_getAppName( eCurrentApp );
778 const utl::OConfigurationTreeRoot aAppNode(
779 xContext,
780 aPath,
781 true);
782 if ( !aAppNode.isValid() )
784 bDone = true;
785 break;
788 aCurrentMode = comphelper::getString( aAppNode.getNodeValue( "Active" ) );
790 if ( aCurrentMode == aNewName )
792 bDone = true;
793 break;
796 // Save new toolbar mode for a current module
797 aAppNode.setNodeValue( "Active", makeAny( aNewName ) );
798 aAppNode.commit();
801 // Apply settings for all frames
802 pViewFrame = SfxViewFrame::GetFirst();
803 while( pViewFrame )
805 // in LOK case we want to apply changes only to the current view
806 if (comphelper::LibreOfficeKit::isActive() &&
807 pViewFrame != SfxViewShell::Current()->GetViewFrame())
809 pViewFrame = SfxViewFrame::GetNext( *pViewFrame );
810 continue;
813 Reference<XFrame> xFrame = pViewFrame->GetFrame().GetFrameInterface();
815 // We want to change mode only for a current app module, ignore other apps
816 const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xContext );
817 vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum( xModuleManager->identify( xFrame ) );
818 if ( eApp != eCurrentApp )
820 pViewFrame = SfxViewFrame::GetNext( *pViewFrame );
821 continue;
824 Reference<css::beans::XPropertySet> xPropSet( xFrame, UNO_QUERY );
825 Reference<css::frame::XLayoutManager> xLayoutManager;
826 if ( xPropSet.is() )
830 Any aValue = xPropSet->getPropertyValue( "LayoutManager" );
831 aValue >>= xLayoutManager;
833 catch ( const css::uno::RuntimeException& )
835 throw;
837 catch ( css::uno::Exception& )
842 if ( xLayoutManager.is() )
844 css::uno::Sequence<OUString> aMandatoryToolbars;
845 css::uno::Sequence<OUString> aUserToolbars;
846 std::vector<OUString> aBackupList;
847 OUString aSidebarMode;
849 OUString aPath = "org.openoffice.Office.UI.ToolbarMode/Applications/" +
850 lcl_getAppName( eApp ) +
851 "/Modes";
853 // Read mode settings
854 const utl::OConfigurationTreeRoot aModesNode(
855 xContext,
856 aPath,
857 true);
858 if ( !aModesNode.isValid() )
860 bDone = true;
861 break;
864 const Sequence<OUString> aModeNodeNames( aModesNode.getNodeNames() );
866 for ( const auto& rModeNodeName : aModeNodeNames )
868 const utl::OConfigurationNode aModeNode( aModesNode.openNode( rModeNodeName ) );
869 if ( !aModeNode.isValid() )
870 continue;
872 OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( "CommandArg" ) );
874 if ( aCommandArg == aNewName )
876 aMandatoryToolbars = aModeNode.getNodeValue( "Toolbars" ).get< uno::Sequence<OUString> >();
877 aUserToolbars = aModeNode.getNodeValue( "UserToolbars" ).get< uno::Sequence<OUString> >();
878 aSidebarMode = comphelper::getString( aModeNode.getNodeValue( "Sidebar" ) );
879 break;
883 // Backup visible toolbar list and hide all toolbars
884 const Sequence<Reference<XUIElement>> aUIElements = xLayoutManager->getElements();
885 for ( const Reference< XUIElement >& xUIElement : aUIElements )
887 Reference< XPropertySet > xPropertySet( xUIElement, UNO_QUERY );
888 if ( xPropertySet.is() && xUIElement.is() )
892 OUString aResName;
893 sal_Int16 nType( -1 );
894 xPropertySet->getPropertyValue( "Type" ) >>= nType;
895 xPropertySet->getPropertyValue( "ResourceURL" ) >>= aResName;
897 if (( nType == css::ui::UIElementType::TOOLBAR ) &&
898 !aResName.isEmpty() )
900 if ( xLayoutManager->isElementVisible( aResName ) )
902 aBackupList.push_back( aResName );
904 xLayoutManager->hideElement( aResName );
907 catch ( const Exception& )
913 // Show/Hide the Notebookbar
914 const SfxStringItem pItem(SID_NOTEBOOKBAR, aNewName);
915 pViewFrame->GetDispatcher()->ExecuteList(SID_NOTEBOOKBAR, SfxCallMode::SYNCHRON, {&pItem});
917 // Show toolbars
918 for ( const OUString& rName : std::as_const(aMandatoryToolbars) )
920 xLayoutManager->createElement( rName );
921 xLayoutManager->showElement( rName );
924 for ( const OUString& rName : std::as_const(aUserToolbars) )
926 xLayoutManager->createElement( rName );
927 xLayoutManager->showElement( rName );
930 // Sidebar
931 pViewFrame->ShowChildWindow( SID_SIDEBAR );
933 if (comphelper::LibreOfficeKit::isActive())
934 aSidebarMode = "Opened";
936 sfx2::sidebar::SidebarController* pSidebar =
937 sfx2::sidebar::SidebarController::GetSidebarControllerForFrame( xFrame );
938 if ( pSidebar )
940 if ( aSidebarMode == "Arrow" )
942 pSidebar->FadeOut();
944 else if ( aSidebarMode == "Tabs" )
946 pSidebar->FadeIn();
947 pSidebar->RequestOpenDeck();
948 pSidebar->RequestCloseDeck();
950 else if ( aSidebarMode == "Opened" )
952 pSidebar->FadeIn();
953 pSidebar->RequestOpenDeck();
957 // Save settings
958 if ( pViewFrame == SfxViewFrame::Current() )
960 css::uno::Sequence<OUString> aBackup( comphelper::containerToSequence(aBackupList) );
962 for ( const auto& rModeNodeName : aModeNodeNames )
964 const utl::OConfigurationNode aModeNode( aModesNode.openNode( rModeNodeName ) );
965 if ( !aModeNode.isValid() )
966 continue;
968 OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( "CommandArg" ) );
970 if ( aCommandArg == aCurrentMode )
972 aModeNode.setNodeValue( "UserToolbars", makeAny( aBackup ) );
973 break;
976 aModesNode.commit();
980 pViewFrame = SfxViewFrame::GetNext(*pViewFrame);
983 bDone = true;
984 break;
986 case SID_TOOLBAR_MODE_UI:
988 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
989 ScopedVclPtr<VclAbstractDialog> pDlg(
990 pFact->CreateToolbarmodeDialog(rReq.GetFrameWeld()));
991 pDlg->Execute();
992 bDone = true;
993 break;
995 case SID_AVAILABLE_TOOLBARS:
997 const SfxStringItem* pToolbarName = rReq.GetArg<SfxStringItem>(SID_AVAILABLE_TOOLBARS);
999 if ( pToolbarName )
1001 Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
1002 Reference< XFrame > xFrame = xDesktop->getActiveFrame();
1004 Reference< css::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
1005 Reference< css::frame::XLayoutManager > xLayoutManager;
1006 if ( xPropSet.is() )
1010 Any aValue = xPropSet->getPropertyValue("LayoutManager");
1011 aValue >>= xLayoutManager;
1013 catch ( const css::uno::RuntimeException& )
1015 throw;
1017 catch ( css::uno::Exception& )
1022 if ( xLayoutManager.is() )
1024 OUString aToolbarName = "private:resource/toolbar/" +
1025 pToolbarName->GetValue();
1027 // Evaluate Parameter
1028 bool bShow( !xLayoutManager->isElementVisible( aToolbarName ));
1030 if ( bShow )
1032 xLayoutManager->createElement( aToolbarName );
1033 xLayoutManager->showElement( aToolbarName );
1035 else
1036 xLayoutManager->hideElement( aToolbarName );
1040 bDone = true;
1041 break;
1043 case SID_MENUBAR:
1045 sfx2::SfxNotebookBar::ToggleMenubar();
1046 bDone = true;
1047 break;
1049 case SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW:
1051 SfxViewShell* pViewShell = SfxViewShell::Current();
1052 SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
1053 auto nID = rReq.GetSlot();
1054 pViewFrame->ToggleChildWindow(nID);
1056 bDone = true;
1057 break;
1059 case SID_INSPECT_SELECTED_OBJECT:
1061 SfxViewShell* pViewShell = SfxViewShell::Current();
1062 SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
1064 pViewFrame->ShowChildWindow(SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW, true);
1066 SfxChildWindow* pChild = pViewFrame->GetChildWindow(SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW);
1067 if (!pChild)
1068 return;
1070 auto pDockingWin = dynamic_cast<DevelopmentToolDockingWindow*>(pChild->GetWindow());
1071 if (pDockingWin)
1073 pDockingWin->changeToCurrentSelection();
1076 bDone = true;
1077 break;
1079 case SID_SAFE_MODE:
1081 SafeModeQueryDialog aDialog(rReq.GetFrameWeld());
1082 aDialog.run();
1083 break;
1085 case SID_TOOLBAR_LOCK:
1087 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1088 if (pViewFrame)
1090 Reference<XFrame> xCurrentFrame;
1091 uno::Reference<uno::XComponentContext> xContext
1092 = ::comphelper::getProcessComponentContext();
1093 xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface();
1094 const Reference<frame::XModuleManager> xModuleManager
1095 = frame::ModuleManager::create(xContext);
1096 const utl::OConfigurationTreeRoot aAppNode(
1097 xContext, "org.openoffice.Office.UI.GlobalSettings/Toolbars/States", true);
1098 if (aAppNode.isValid())
1100 bool isLocked = comphelper::getBOOL(aAppNode.getNodeValue("Locked"));
1101 aAppNode.setNodeValue("Locked", makeAny(!isLocked));
1102 aAppNode.commit();
1103 //TODO: apply immediately w/o restart needed
1104 SolarMutexGuard aGuard;
1105 svtools::executeRestartDialog(comphelper::getProcessComponentContext(), nullptr,
1106 svtools::RESTART_REASON_UI_CHANGE);
1109 break;
1111 default:
1112 break;
1115 if ( bDone )
1116 rReq.Done();
1119 void SfxApplication::MiscState_Impl(SfxItemSet &rSet)
1121 const WhichRangesContainer & pRanges = rSet.GetRanges();
1122 DBG_ASSERT(!pRanges.empty(), "Set without range");
1123 for ( auto const & pRange : pRanges )
1125 for(sal_uInt16 nWhich = pRange.first; nWhich <= pRange.second; ++nWhich)
1127 switch(nWhich)
1129 case SID_TEMPLATE_ADDRESSBOOKSOURCE:
1130 if ( !SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::DATABASE) )
1131 rSet.Put(SfxVisibilityItem(nWhich, false));
1132 break;
1133 case SID_QUITAPP:
1135 if ( pImpl->nDocModalMode )
1136 rSet.DisableItem(nWhich);
1137 else
1138 rSet.Put(SfxStringItem(nWhich, SfxResId(STR_QUITAPP)));
1139 break;
1142 case SID_CONFIG:
1143 case SID_TOOLBOXOPTIONS:
1144 case SID_CONFIGSTATUSBAR:
1145 case SID_CONFIGMENU:
1146 case SID_CONFIGACCEL:
1147 case SID_CONFIGEVENT:
1149 if( officecfg::Office::Common::Misc::DisableUICustomization::get() )
1150 rSet.DisableItem(nWhich);
1151 break;
1154 #if HAVE_FEATURE_SCRIPTING
1155 case SID_BASICSTOP:
1156 if ( !StarBASIC::IsRunning() )
1157 rSet.DisableItem(nWhich);
1158 break;
1159 #endif
1161 case SID_HELPTIPS:
1163 rSet.Put( SfxBoolItem( SID_HELPTIPS, Help::IsQuickHelpEnabled() ) );
1165 break;
1166 case SID_HELPBALLOONS:
1168 rSet.Put( SfxBoolItem( SID_HELPBALLOONS, Help::IsBalloonHelpEnabled() ) );
1170 break;
1172 case SID_EXTENDEDHELP:
1175 break;
1177 case SID_CLOSEDOCS:
1179 Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
1180 Reference< XIndexAccess > xTasks = xDesktop->getFrames();
1181 if ( !xTasks.is() || !xTasks->getCount() )
1182 rSet.DisableItem(nWhich);
1183 break;
1186 case SID_SAVEDOCS:
1188 bool bModified = false;
1189 for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
1190 pObjSh;
1191 pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
1193 if ( pObjSh->IsModified() && !pObjSh->isSaveLocked() )
1195 bModified = true;
1196 break;
1200 if ( !bModified )
1201 rSet.DisableItem( nWhich );
1202 break;
1205 case SID_TEMPLATE_MANAGER:
1207 if ( !officecfg::Office::Common::Misc::ExperimentalMode::get() )
1209 rSet.DisableItem( nWhich );
1210 rSet.Put( SfxVisibilityItem( nWhich, false ) );
1213 break;
1215 case SID_ZOOM_50_PERCENT:
1216 case SID_ZOOM_75_PERCENT:
1217 case SID_ZOOM_100_PERCENT:
1218 case SID_ZOOM_150_PERCENT:
1219 case SID_ZOOM_200_PERCENT:
1220 case SID_ZOOM_OPTIMAL:
1221 case SID_ZOOM_ENTIRE_PAGE:
1222 case SID_ZOOM_PAGE_WIDTH:
1224 SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
1226 const SfxPoolItem *pItem;
1227 SfxItemState aState = pCurrentShell ?
1228 pCurrentShell->GetDispatcher()->QueryState(SID_ATTR_ZOOM, pItem) : SfxItemState::DISABLED;
1229 if ( aState == SfxItemState::DISABLED )
1230 rSet.DisableItem( nWhich );
1232 break;
1234 case SID_MENUBAR:
1236 Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
1237 Reference< XFrame > xFrame = xDesktop->getActiveFrame();
1239 Reference< css::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
1240 Reference< css::frame::XLayoutManager > xLayoutManager;
1241 if ( xPropSet.is() )
1245 Any aValue = xPropSet->getPropertyValue("LayoutManager");
1246 aValue >>= xLayoutManager;
1248 catch ( const css::uno::RuntimeException& )
1250 throw;
1252 catch ( css::uno::Exception& )
1257 if ( xLayoutManager.is() )
1259 const bool bState
1260 = xLayoutManager->getElement("private:resource/menubar/menubar").is()
1261 && xLayoutManager->isElementVisible(
1262 "private:resource/menubar/menubar");
1264 SfxBoolItem aItem( SID_MENUBAR, bState );
1265 rSet.Put( aItem );
1267 break;
1269 case SID_SAFE_MODE:
1271 // no restart in safe mode when already in safe mode
1272 if ( Application::IsSafeModeEnabled() )
1273 rSet.DisableItem( SID_SAFE_MODE );
1274 break;
1276 case SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW:
1278 bool bSuccess = false;
1279 auto* pViewShell = SfxViewShell::Current();
1280 if (pViewShell)
1282 auto* pViewFrame = pViewShell->GetViewFrame();
1283 if (pViewFrame && pViewFrame->KnowsChildWindow(nWhich))
1285 rSet.Put(SfxBoolItem(nWhich, pViewFrame->HasChildWindow(nWhich)));
1286 bSuccess = true;
1290 if (!bSuccess)
1291 rSet.DisableItem(nWhich);
1293 break;
1294 case SID_INSPECT_SELECTED_OBJECT:
1296 bool bSuccess = false;
1297 auto* pViewShell = SfxViewShell::Current();
1298 if (pViewShell)
1300 auto* pViewFrame = pViewShell->GetViewFrame();
1301 if (pViewFrame && pViewFrame->KnowsChildWindow(SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW))
1303 bSuccess = true;
1306 if (!bSuccess)
1307 rSet.DisableItem(nWhich);
1309 break;
1310 case SID_TOOLBAR_LOCK:
1312 rSet.Put( SfxBoolItem( SID_TOOLBAR_LOCK, ToolBox::AlwaysLocked() ));
1314 break;
1315 default:
1316 break;
1322 #if HAVE_FEATURE_SCRIPTING
1324 #ifndef DISABLE_DYNLOADING
1326 typedef rtl_uString* (*basicide_choose_macro)(void*, void*, void*, sal_Bool);
1328 #else
1330 extern "C" rtl_uString* basicide_choose_macro(void*, void*, void*, sal_Bool);
1332 #endif
1334 static OUString ChooseMacro(weld::Window* pParent, const Reference<XModel>& rxLimitToDocument, const Reference<XFrame>& xDocFrame, bool bChooseOnly)
1336 #ifndef DISABLE_DYNLOADING
1337 basicide_choose_macro pSymbol = reinterpret_cast<basicide_choose_macro>(sfx2::getBasctlFunction("basicide_choose_macro"));
1338 #else
1339 #define pSymbol basicide_choose_macro
1340 #endif
1342 // call basicide_choose_macro in basctl
1343 rtl_uString* pScriptURL = pSymbol(pParent, rxLimitToDocument.get(), xDocFrame.get(), bChooseOnly);
1344 OUString aScriptURL( pScriptURL );
1345 rtl_uString_release( pScriptURL );
1346 return aScriptURL;
1348 #ifdef DISABLE_DYNLOADING
1349 #undef pSymbol
1350 #endif
1353 #endif
1355 namespace
1357 #if HAVE_FEATURE_SCRIPTING
1358 weld::Window* lcl_getDialogParent(const Reference<XFrame>& rxFrame)
1360 Reference<awt::XWindow> xContainerWindow;
1361 if (rxFrame.is())
1362 xContainerWindow = rxFrame->getContainerWindow();
1363 return Application::GetFrameWeld(xContainerWindow);
1366 SfxViewFrame* lcl_getBasicIDEViewFrame( SfxObjectShell const * i_pBasicIDE )
1368 SfxViewFrame* pView = SfxViewFrame::GetFirst( i_pBasicIDE );
1369 while ( pView )
1371 if ( pView->GetObjectShell()->GetFactory().GetDocumentServiceName() == "com.sun.star.script.BasicIDE" )
1372 break;
1373 pView = SfxViewFrame::GetNext( *pView, i_pBasicIDE );
1375 return pView;
1377 Reference< XFrame > lcl_findStartModuleFrame( const Reference<XComponentContext> & rxContext )
1381 Reference < XDesktop2 > xDesktop = Desktop::create( rxContext );
1382 Reference < XIndexAccess > xContainer( xDesktop->getFrames(), UNO_QUERY_THROW );
1384 Reference< XModuleManager2 > xCheck = ModuleManager::create(rxContext);
1386 sal_Int32 nCount = xContainer->getCount();
1387 for ( sal_Int32 i=0; i<nCount; ++i )
1391 Reference < XFrame > xFrame( xContainer->getByIndex(i), UNO_QUERY_THROW );
1392 OUString sModule = xCheck->identify( xFrame );
1393 if ( sModule == "com.sun.star.frame.StartModule" )
1394 return xFrame;
1396 catch( const UnknownModuleException& )
1398 // silence
1400 catch(const Exception&)
1402 // re-throw, caught below
1403 throw;
1407 catch( const Exception& )
1409 DBG_UNHANDLED_EXCEPTION("sfx.appl");
1411 return nullptr;
1413 #endif // HAVE_FEATURE_SCRIPTING
1416 void SfxApplication::OfaExec_Impl( SfxRequest& rReq )
1418 switch ( rReq.GetSlot() )
1420 case SID_OPTIONS_TREEDIALOG:
1422 OUString sPageURL;
1423 const SfxStringItem* pURLItem = rReq.GetArg<SfxStringItem>(SID_OPTIONS_PAGEURL);
1424 if ( pURLItem )
1425 sPageURL = pURLItem->GetValue();
1426 Reference <XFrame> xFrame(GetRequestFrame(rReq));
1427 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1428 VclPtr<VclAbstractDialog> pDlg =
1429 pFact->CreateFrameDialog(rReq.GetFrameWeld(), xFrame, rReq.GetSlot(), sPageURL );
1430 short nRet = pDlg->Execute();
1431 pDlg.disposeAndClear();
1432 SfxViewFrame* pView = SfxViewFrame::GetFirst();
1433 while ( pView )
1435 if (nRet == RET_OK)
1437 SfxObjectShell* pObjSh = pView->GetObjectShell();
1438 if (pObjSh)
1439 pObjSh->SetConfigOptionsChecked(false);
1441 pView->GetBindings().InvalidateAll(false);
1442 pView = SfxViewFrame::GetNext( *pView );
1444 break;
1447 case SID_MORE_DICTIONARIES:
1449 uno::Sequence<beans::PropertyValue> aArgs{ comphelper::makePropertyValue(
1450 "AdditionsTag", OUString("Dictionary")) };
1451 comphelper::dispatchCommand(".uno:AdditionsDialog", aArgs);
1452 break;
1454 #if HAVE_FEATURE_SCRIPTING
1455 case SID_BASICIDE_APPEAR:
1457 SfxViewFrame* pView = lcl_getBasicIDEViewFrame( nullptr );
1458 if ( !pView )
1460 SfxObjectShell* pBasicIDE = SfxObjectShell::CreateObject( "com.sun.star.script.BasicIDE" );
1461 pBasicIDE->DoInitNew();
1462 pBasicIDE->SetModified( false );
1465 // load the Basic IDE via direct access to the SFX frame loader. A generic loadComponentFromURL
1466 // (which could be done via SfxViewFrame::LoadDocumentIntoFrame) is not feasible here, since the Basic IDE
1467 // does not really play nice with the framework's concept. For instance, it is a "singleton document",
1468 // which conflicts, at the latest, with the framework's concept of loading into _blank frames.
1469 // So, since we know that our frame loader can handle it, we skip the generic framework loader
1470 // mechanism, and the type detection (which doesn't know about the Basic IDE).
1471 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1472 Reference< XSynchronousFrameLoader > xLoader(
1473 xContext->getServiceManager()->createInstanceWithContext("com.sun.star.comp.office.FrameLoader", xContext),
1474 UNO_QUERY_THROW );
1475 ::comphelper::NamedValueCollection aLoadArgs;
1476 aLoadArgs.put( "Model", pBasicIDE->GetModel() );
1477 aLoadArgs.put( "URL", OUString( "private:factory/sbasic" ) );
1479 Reference< XFrame > xTargetFrame( lcl_findStartModuleFrame( xContext ) );
1480 if ( !xTargetFrame.is() )
1481 xTargetFrame = SfxFrame::CreateBlankFrame();
1482 ENSURE_OR_THROW( xTargetFrame.is(), "could not obtain a frameto load the Basic IDE into!" );
1484 xLoader->load( aLoadArgs.getPropertyValues(), xTargetFrame );
1486 catch( const Exception& )
1488 DBG_UNHANDLED_EXCEPTION("sfx.appl");
1491 pView = lcl_getBasicIDEViewFrame( pBasicIDE );
1492 if ( pView )
1493 pView->SetName( "BASIC:1" );
1496 if ( pView )
1497 pView->GetFrame().Appear();
1499 const SfxItemSet* pArgs = rReq.GetArgs();
1500 if ( pArgs && pView )
1502 SfxViewShell* pViewShell = pView->GetViewShell();
1503 SfxObjectShell* pObjShell = pView->GetObjectShell();
1504 if ( pViewShell && pObjShell )
1506 SfxRequest aReq( SID_BASICIDE_SHOWWINDOW, SfxCallMode::SYNCHRON, pObjShell->GetPool() );
1507 aReq.SetArgs( *pArgs );
1508 pViewShell->ExecuteSlot( aReq );
1512 rReq.Done();
1514 break;
1516 case SID_BASICCHOOSER:
1518 const SfxItemSet* pArgs = rReq.GetArgs();
1519 const SfxPoolItem* pItem;
1520 bool bChooseOnly = false;
1521 Reference< XModel > xLimitToModel;
1522 if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_RECORDMACRO, false, &pItem) )
1524 bool bRecord = static_cast<const SfxBoolItem*>(pItem)->GetValue();
1525 if ( bRecord )
1527 // !Hack
1528 bChooseOnly = false;
1529 SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
1530 OSL_ENSURE( pCurrentShell, "macro recording outside an SFX document?" );
1531 if ( pCurrentShell )
1532 xLimitToModel = pCurrentShell->GetModel();
1536 Reference <XFrame> xFrame(GetRequestFrame(rReq));
1537 rReq.SetReturnValue(SfxStringItem(rReq.GetSlot(), ChooseMacro(rReq.GetFrameWeld(), xLimitToModel, xFrame, bChooseOnly)));
1538 rReq.Done();
1540 break;
1542 case SID_MACROORGANIZER:
1544 SAL_INFO("sfx.appl", "handling SID_MACROORGANIZER");
1545 const SfxItemSet* pArgs = rReq.GetArgs();
1546 const SfxPoolItem* pItem;
1547 sal_Int16 nTabId = 0;
1548 if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_MACROORGANIZER, false, &pItem) )
1550 nTabId = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
1553 SfxApplication::MacroOrganizer(rReq.GetFrameWeld(), nTabId);
1554 rReq.Done();
1556 break;
1558 case SID_RUNMACRO:
1560 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1561 SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: case ScriptOrg");
1563 Reference <XFrame> xFrame(GetRequestFrame(rReq));
1564 if ( !xFrame.is() )
1566 const SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1567 if ( pViewFrame )
1568 xFrame = pViewFrame->GetFrame().GetFrameInterface();
1571 do // artificial loop for flow control
1573 VclPtr<AbstractScriptSelectorDialog> pDlg(pFact->CreateScriptSelectorDialog(lcl_getDialogParent(xFrame), xFrame));
1574 OSL_ENSURE( pDlg, "SfxApplication::OfaExec_Impl( SID_RUNMACRO ): no dialog!" );
1575 if ( !pDlg )
1576 break;
1577 pDlg->SetRunLabel();
1579 pDlg->StartExecuteAsync([pDlg, xFrame](sal_Int32 nDialogResult) {
1580 if ( !nDialogResult )
1582 pDlg->disposeOnce();
1583 return;
1586 Sequence< Any > args;
1587 Sequence< sal_Int16 > outIndex;
1588 Sequence< Any > outArgs;
1589 Any ret;
1591 Reference< XInterface > xScriptContext;
1593 Reference< XController > xController;
1594 if ( xFrame.is() )
1595 xController = xFrame->getController();
1596 if ( xController.is() )
1597 xScriptContext = xController->getModel();
1598 if ( !xScriptContext.is() )
1599 xScriptContext = xController;
1601 SfxObjectShell::CallXScript( xScriptContext, pDlg->GetScriptURL(), args, ret, outIndex, outArgs );
1602 pDlg->disposeOnce();
1605 while ( false );
1606 rReq.Done();
1608 break;
1610 case SID_SCRIPTORGANIZER:
1612 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1613 SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: case ScriptOrg");
1614 const SfxItemSet* pArgs = rReq.GetArgs();
1615 const SfxPoolItem* pItem;
1616 OUString aLanguage;
1617 if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_SCRIPTORGANIZER, false, &pItem) )
1619 aLanguage = static_cast<const SfxScriptOrganizerItem*>(pItem)->getLanguage();
1622 OUString aLang( aLanguage );
1623 SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: about to create dialog for: " << aLang);
1624 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSvxScriptOrgDialog(rReq.GetFrameWeld(), aLanguage));
1625 if( pDlg )
1627 pDlg->Execute();
1629 else
1631 SAL_WARN("sfx.appl", "no dialog!!!");
1633 rReq.Done();
1635 break;
1636 #endif // HAVE_FEATURE_SCRIPTING
1638 case SID_OFFICE_CHECK_PLZ:
1640 bool bRet = false;
1641 const SfxStringItem* pStringItem = rReq.GetArg<SfxStringItem>(rReq.GetSlot());
1643 if ( pStringItem )
1645 bRet = true /*!!!SfxIniManager::CheckPLZ( aPLZ )*/;
1647 #if HAVE_FEATURE_SCRIPTING
1648 else
1649 SbxBase::SetError( ERRCODE_BASIC_WRONG_ARGS );
1650 #endif
1651 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bRet ) );
1653 break;
1655 case SID_AUTO_CORRECT_DLG:
1657 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1658 SfxItemSetFixed<SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG> aSet(GetPool());
1659 const SfxPoolItem* pItem=nullptr;
1660 const SfxItemSet* pSet = rReq.GetArgs();
1661 SfxItemPool* pSetPool = pSet ? pSet->GetPool() : nullptr;
1662 if ( pSet && pSet->GetItemState( pSetPool->GetWhich( SID_AUTO_CORRECT_DLG ), false, &pItem ) == SfxItemState::SET )
1663 aSet.Put( *pItem );
1665 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateAutoCorrTabDialog(rReq.GetFrameWeld(), &aSet));
1666 pDlg->Execute();
1668 break;
1671 case SID_NEWSD :
1673 SvtModuleOptions aModuleOpt;
1674 if ( !aModuleOpt.IsImpress() )
1676 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(rReq.GetFrameWeld(),
1677 VclMessageType::Warning, VclButtonsType::Ok,
1678 SfxResId(STR_MODULENOTINSTALLED)));
1679 xBox->run();
1680 return;
1683 Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
1684 Reference< frame::XDispatchProvider > xProv = drawing::ModuleDispatcher::create( xContext );
1686 OUString aCmd = OUString::createFromAscii( GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName() );
1687 Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
1688 Sequence < beans::PropertyValue > aSeq;
1689 if ( rReq.GetArgs() )
1690 TransformItems( rReq.GetSlot(), *rReq.GetArgs(), aSeq );
1691 Any aResult = xHelper->executeDispatch( xProv, aCmd, OUString(), 0, aSeq );
1692 frame::DispatchResultEvent aEvent;
1693 bool bSuccess = (aResult >>= aEvent) &&
1694 (aEvent.State == frame::DispatchResultState::SUCCESS);
1695 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
1697 break;
1699 case FN_LABEL :
1700 case FN_BUSINESS_CARD :
1701 case FN_XFORMS_INIT :
1703 Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
1704 Reference< frame::XDispatchProvider > xProv = text::ModuleDispatcher::create( xContext );
1706 OUString aCmd = OUString::createFromAscii( GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName() );
1707 Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
1708 Sequence < beans::PropertyValue > aSeq;
1709 if ( rReq.GetArgs() )
1710 TransformItems( rReq.GetSlot(), *rReq.GetArgs(), aSeq );
1711 Any aResult = xHelper->executeDispatch( xProv, aCmd, OUString(), 0, aSeq );
1712 frame::DispatchResultEvent aEvent;
1713 bool bSuccess = (aResult >>= aEvent) &&
1714 (aEvent.State == frame::DispatchResultState::SUCCESS);
1715 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
1717 break;
1719 case SID_ADDRESS_DATA_SOURCE:
1723 Reference< uno::XComponentContext > xORB = ::comphelper::getProcessComponentContext();
1724 Reference< ui::dialogs::XExecutableDialog > xDialog = ui::dialogs::AddressBookSourcePilot::createWithParent(xORB, nullptr);
1725 xDialog->execute();
1727 catch(const css::uno::Exception&)
1729 DBG_UNHANDLED_EXCEPTION("sfx.appl");
1732 break;
1734 case SID_COMP_BIBLIOGRAPHY:
1735 lcl_tryLoadBibliography();
1736 break;
1740 void SfxApplication::OfaState_Impl(SfxItemSet &rSet)
1742 SvtModuleOptions aModuleOpt;
1744 if( !aModuleOpt.IsWriter())
1746 rSet.DisableItem( FN_LABEL );
1747 rSet.DisableItem( FN_BUSINESS_CARD );
1748 rSet.DisableItem( FN_XFORMS_INIT );
1750 if ( comphelper::LibreOfficeKit::isActive() )
1751 rSet.DisableItem( SID_AUTO_CORRECT_DLG );
1753 bool bMacrosDisabled
1754 = officecfg::Office::Common::Security::Scripting::DisableMacrosExecution::get();
1755 if (bMacrosDisabled)
1757 rSet.DisableItem(SID_RUNMACRO);
1758 rSet.DisableItem(SID_MACROORGANIZER);
1759 rSet.DisableItem(SID_SCRIPTORGANIZER);
1760 rSet.DisableItem(SID_BASICIDE_APPEAR);
1764 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */