online: keep sidebar opened
[LibreOffice.git] / sfx2 / source / appl / appserv.cxx
blobd2db452e081545e6d8cfb4ebaa30f8659cda97ff
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/sequence.hxx>
48 #include <svtools/addresstemplate.hxx>
49 #include <svtools/miscopt.hxx>
50 #include <svtools/restartdialog.hxx>
51 #include <svl/visitem.hxx>
53 #include <unotools/configmgr.hxx>
54 #include <tools/diagnose_ex.h>
55 #include <vcl/weld.hxx>
56 #include <svl/intitem.hxx>
57 #include <svl/eitem.hxx>
58 #include <svl/stritem.hxx>
59 #include <basic/sbstar.hxx>
60 #include <basic/basrdll.hxx>
61 #include <basic/sberrors.hxx>
62 #include <vcl/help.hxx>
63 #include <rtl/ustrbuf.hxx>
64 #include <sal/log.hxx>
65 #include <osl/file.hxx>
66 #include <vcl/EnumContext.hxx>
67 #include <vcl/toolbox.hxx>
69 #include <unotools/moduleoptions.hxx>
70 #include <rtl/bootstrap.hxx>
72 #include <com/sun/star/frame/ModuleManager.hpp>
73 #include <com/sun/star/beans/XPropertySet.hpp>
75 #include <sfx2/app.hxx>
76 #include <sfx2/request.hxx>
77 #include <sfx2/dispatch.hxx>
78 #include <sfx2/bindings.hxx>
79 #include <sfx2/msg.hxx>
80 #include <sfx2/objface.hxx>
81 #include <sfx2/objsh.hxx>
82 #include <sfx2/viewsh.hxx>
83 #include <sfx2/docfac.hxx>
84 #include <sfx2/strings.hrc>
85 #include <sfx2/sfxresid.hxx>
86 #include <appdata.hxx>
87 #include <sfx2/viewfrm.hxx>
88 #include <sfx2/sfxdlg.hxx>
89 #include <sfx2/sfxsids.hrc>
90 #include <sorgitm.hxx>
91 #include <sfx2/sfxhelp.hxx>
92 #include <sfx2/zoomitem.hxx>
93 #include <sfx2/templatedlg.hxx>
94 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
95 #include <sfx2/sidebar/SidebarController.hxx>
96 #include <sfx2/safemode.hxx>
97 #include <sfx2/sfxuno.hxx>
98 #include <sfx2/devtools/DevelopmentToolDockingWindow.hxx>
100 #include <comphelper/types.hxx>
101 #include <officecfg/Office/Common.hxx>
102 #include <unotools/confignode.hxx>
103 #include <memory>
105 #include <openuriexternally.hxx>
107 #include "getbasctlfunction.hxx"
109 using namespace ::com::sun::star;
110 using namespace ::com::sun::star::beans;
111 using namespace ::com::sun::star::uno;
112 using namespace ::com::sun::star::frame;
113 using namespace ::com::sun::star::container;
114 using namespace ::com::sun::star::util;
115 using namespace ::com::sun::star::lang;
116 using namespace ::com::sun::star::ui;
118 namespace
120 OUString lcl_getAppName( vcl::EnumContext::Application eApp )
122 switch ( eApp )
124 case vcl::EnumContext::Application::Writer:
125 return "Writer";
126 case vcl::EnumContext::Application::Calc:
127 return "Calc";
128 case vcl::EnumContext::Application::Impress:
129 return "Impress";
130 case vcl::EnumContext::Application::Draw:
131 return "Draw";
132 case vcl::EnumContext::Application::Formula:
133 return "Formula";
134 case vcl::EnumContext::Application::Base:
135 return "Base";
136 default:
137 return OUString();
141 // lp#527938, debian#602953, fdo#33266, i#105408
142 bool lcl_isBaseAvailable()
146 // if we get css::sdbc::DriverManager, libsdbc2 is there
147 // and the bibliography is assumed to work
148 return css::sdbc::DriverManager::create(comphelper::getProcessComponentContext()).is();
150 catch (const Exception &)
152 TOOLS_INFO_EXCEPTION("sfx.appl", "assuming Base to be missing");
153 return false;
156 void lcl_tryLoadBibliography()
158 // lp#527938, debian#602953, fdo#33266, i#105408
159 // make sure we actually can instantiate services from base first
160 if(!lcl_isBaseAvailable())
162 if (officecfg::Office::Common::PackageKit::EnableBaseInstallation::get())
166 using namespace org::freedesktop::PackageKit;
167 using namespace svtools;
168 Reference< XSyncDbusSessionHelper > xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext()));
169 Sequence< OUString > vPackages { "libreoffice-base" };
170 xSyncDbusSessionHelper->InstallPackageNames(vPackages, OUString());
171 // I'll be back (hopefully)!
172 SolarMutexGuard aGuard;
173 executeRestartDialog(comphelper::getProcessComponentContext(), nullptr, RESTART_REASON_BIBLIOGRAPHY_INSTALL);
175 catch (const Exception &)
177 TOOLS_INFO_EXCEPTION("sfx.appl", "trying to install LibreOffice Base");
180 return;
183 try // fdo#48775
185 SfxStringItem aURL(SID_FILE_NAME, ".component:Bibliography/View1");
186 SfxStringItem aRef(SID_REFERER, "private:user");
187 SfxStringItem aTarget(SID_TARGETNAME, "_blank");
188 SfxViewFrame::Current()->GetDispatcher()->ExecuteList(SID_OPENDOC,
189 SfxCallMode::ASYNCHRON, { &aURL, &aRef, &aTarget });
191 catch (const Exception &)
193 TOOLS_INFO_EXCEPTION( "sfx.appl", "trying to load bibliography database");
197 /// Find the correct location of the document (CREDITS.fodt, etc.), and return
198 /// it in rURL if found.
199 static bool checkURL( const char *pName, const char *pExt, OUString &rURL )
201 using namespace osl;
202 DirectoryItem aDirItem;
204 #ifdef MACOSX
205 rURL = "$BRAND_BASE_DIR/Resources/" + OUString::createFromAscii( pName ) +
206 OUString::createFromAscii( pExt );
207 #else
208 rURL = "$BRAND_BASE_DIR/" + OUString::createFromAscii( pName ) +
209 OUString::createFromAscii( pExt );
210 #endif
211 rtl::Bootstrap::expandMacros( rURL );
213 if (!rURL.isEmpty())
214 return DirectoryItem::get( rURL, aDirItem ) == DirectoryItem::E_None;
215 else
216 return false;
219 /// Displays CREDITS or LICENSE in any of the available version
220 static void showDocument( const char* pBaseName )
222 try {
223 Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
224 auto args(::comphelper::InitPropertySequence({
225 {"ViewOnly", makeAny(true)},
226 {"ReadOnly", makeAny(true)}
227 }));
229 OUString aURL;
230 if ( checkURL ( pBaseName, ".fodt", aURL ) ||
231 checkURL ( pBaseName, ".html", aURL ) ||
232 checkURL ( pBaseName, "", aURL ) ) {
233 xDesktop->loadComponentFromURL( aURL, "_blank", 0, args );
235 } catch (const css::uno::Exception &) {
239 namespace
241 Reference<XFrame> GetRequestFrame(const SfxRequest& rReq)
243 const SfxItemSet* pArgs = rReq.GetInternalArgs_Impl();
244 const SfxPoolItem* pItem = nullptr;
245 Reference <XFrame> xFrame;
246 if (pArgs && pArgs->GetItemState(SID_FILLFRAME, false, &pItem) == SfxItemState::SET)
248 OSL_ENSURE( dynamic_cast< const SfxUnoFrameItem *>( pItem ) != nullptr, "SfxApplication::OfaExec_Impl: XFrames are to be transported via SfxUnoFrameItem by now!" );
249 xFrame = static_cast< const SfxUnoFrameItem*>( pItem )->GetFrame();
251 return xFrame;
254 class LicenseDialog : public weld::GenericDialogController
256 public:
257 LicenseDialog(weld::Window* pParent)
258 : GenericDialogController(pParent, "sfx/ui/licensedialog.ui", "LicenseDialog")
262 virtual short run() override
264 short nRet = GenericDialogController::run();
265 if (nRet == RET_OK)
266 showDocument("LICENSE");
267 return nRet;
271 class SafeModeQueryDialog : public weld::MessageDialogController
273 public:
274 SafeModeQueryDialog(weld::Window* pParent)
275 : MessageDialogController(pParent, "sfx/ui/safemodequerydialog.ui", "SafeModeQueryDialog")
279 virtual short run() override
281 short nRet = MessageDialogController::run();
282 if (nRet == RET_OK)
284 sfx2::SafeMode::putFlag();
285 uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
286 css::task::OfficeRestartManager::get(xContext)->requestRestart(
287 css::uno::Reference< css::task::XInteractionHandler >());
289 return nRet;
294 weld::Window* SfxRequest::GetFrameWeld() const
296 const SfxItemSet* pIntArgs = GetInternalArgs_Impl();
297 const SfxPoolItem* pItem = nullptr;
298 if (pIntArgs && pIntArgs->GetItemState(SID_DIALOG_PARENT, false, &pItem) == SfxItemState::SET)
300 assert(dynamic_cast<const SfxUnoAnyItem*>(pItem));
301 auto aAny = static_cast<const SfxUnoAnyItem*>(pItem)->GetValue();
302 Reference<awt::XWindow> xWindow;
303 aAny >>= xWindow;
304 return Application::GetFrameWeld(xWindow);
307 Reference<XFrame> xFrame(GetRequestFrame(*this));
308 if (!xFrame)
310 SAL_WARN("sfx.appl", "no parent for dialogs");
311 return nullptr;
313 return Application::GetFrameWeld(xFrame->getContainerWindow());
316 void SfxApplication::MiscExec_Impl( SfxRequest& rReq )
318 bool bDone = false;
319 switch ( rReq.GetSlot() )
321 case SID_SETOPTIONS:
323 if( rReq.GetArgs() )
324 SetOptions_Impl( *rReq.GetArgs() );
325 break;
328 case SID_QUITAPP:
329 case SID_LOGOUT:
331 // protect against reentrant calls
332 if ( pImpl->bInQuit )
333 return;
335 if ( rReq.GetSlot() == SID_LOGOUT )
337 for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
338 pObjSh; pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
340 if ( !pObjSh->IsModified() )
341 continue;
343 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pObjSh );
344 if ( !pFrame || !pFrame->GetWindow().IsReallyVisible() )
345 continue;
347 if (pObjSh->PrepareClose())
348 pObjSh->SetModified( false );
349 else
350 return;
353 SfxStringItem aNameItem( SID_FILE_NAME, "vnd.sun.star.cmd:logout" );
354 SfxStringItem aReferer( SID_REFERER, "private/user" );
355 pImpl->pAppDispat->ExecuteList(SID_OPENDOC,
356 SfxCallMode::SLOT, { &aNameItem, &aReferer });
357 return;
360 // try from nested requests again after 100ms
361 if( Application::GetDispatchLevel() > 1 )
363 /* Don't save the request for closing the application and try it later
364 again. This is an UI bound functionality ... and the user will try it again
365 if the dialog is closed. But we should not close the application automatically
366 if this dialog is closed by the user ...
367 So we ignore this request now and wait for a new user decision.
369 SAL_INFO("sfx.appl", "QueryExit => sal_False, DispatchLevel == " << Application::GetDispatchLevel() );
370 return;
373 // block reentrant calls
374 pImpl->bInQuit = true;
375 Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
377 rReq.ForgetAllArgs();
379 // if terminate() failed, pImpl->bInQuit will now be sal_False, allowing further calls of SID_QUITAPP
380 bool bTerminated = xDesktop->terminate();
381 if (!bTerminated)
382 // if terminate() was successful, SfxApplication is now dead!
383 pImpl->bInQuit = false;
385 // Set return value, terminate if possible
386 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bTerminated ) );
387 return;
390 case SID_CONFIG:
391 case SID_TOOLBOXOPTIONS:
392 case SID_CONFIGSTATUSBAR:
393 case SID_CONFIGMENU:
394 case SID_CONFIGACCEL:
395 case SID_CONFIGEVENT:
397 SfxAbstractDialogFactory* pFact =
398 SfxAbstractDialogFactory::Create();
400 const SfxStringItem* pStringItem = rReq.GetArg<SfxStringItem>(SID_CONFIG);
402 SfxItemSet aSet(
403 GetPool(), svl::Items<SID_CONFIG, SID_CONFIG> );
405 if ( pStringItem )
407 aSet.Put( SfxStringItem(
408 SID_CONFIG, pStringItem->GetValue() ) );
411 Reference <XFrame> xFrame(GetRequestFrame(rReq));
412 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateCustomizeTabDialog(rReq.GetFrameWeld(),
413 &aSet, xFrame ));
415 const short nRet = pDlg->Execute();
417 if ( nRet )
418 bDone = true;
419 break;
422 case SID_CLOSEDOCS:
425 Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
426 Reference< XIndexAccess > xTasks = xDesktop->getFrames();
427 if ( !xTasks.is() )
428 break;
430 sal_Int32 n=0;
433 if ( xTasks->getCount() <= n )
434 break;
436 Any aAny = xTasks->getByIndex(n);
437 Reference < XCloseable > xTask;
438 aAny >>= xTask;
441 xTask->close(true);
442 n++;
444 catch( CloseVetoException& )
448 while( true );
450 bool bOk = ( n == 0);
451 rReq.SetReturnValue( SfxBoolItem( 0, bOk ) );
452 bDone = true;
453 break;
456 case SID_SAVEDOCS:
458 bool bOK = true;
459 for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
460 pObjSh;
461 pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
463 SfxRequest aReq( SID_SAVEDOC, SfxCallMode::SLOT, pObjSh->GetPool() );
464 if ( pObjSh->IsModified() )
466 pObjSh->ExecuteSlot( aReq );
467 const SfxBoolItem *pItem = dynamic_cast<const SfxBoolItem*>( aReq.GetReturnValue() );
468 if ( !pItem || !pItem->GetValue() )
469 bOK = false;
473 rReq.SetReturnValue( SfxBoolItem( 0, bOK ) );
474 rReq.Done();
475 break;
478 case SID_SEND_FEEDBACK:
480 OUString module = SfxHelp::GetCurrentModuleIdentifier();
481 OUString sURL(officecfg::Office::Common::Menus::SendFeedbackURL::get() + //officecfg/registry/data/org/openoffice/Office/Common.xcu => https://hub.libreoffice.org/send-feedback/
482 "?LOversion=" + utl::ConfigManager::getAboutBoxProductVersion() +
483 "&LOlocale=" + utl::ConfigManager::getUILocale() +
484 "&LOmodule=" + module.subView(module.lastIndexOf('.') + 1 ) );
485 sfx2::openUriExternally(sURL, false);
486 break;
489 case SID_Q_AND_A:
491 // Askbot has URL's normalized to languages, not locales
492 // Get language from locale: ll or lll or ll-CC or lll-CC
494 OUString sURL(officecfg::Office::Common::Menus::QA_URL::get() + //https://hub.libreoffice.org/forum/
495 "?LOlocale=" + utl::ConfigManager::getUILocale());
496 sfx2::openUriExternally(sURL, false);
497 break;
499 case SID_DOCUMENTATION:
501 // Open documentation page based on locales
502 OUString sURL(officecfg::Office::Common::Menus::DocumentationURL::get() + //https://hub.libreoffice.org/documentation/
503 "?LOlocale=" + utl::ConfigManager::getUILocale());
504 sfx2::openUriExternally(sURL, false);
505 break;
507 case SID_GETINVOLVED:
509 // Open get involved/join us page based on locales
510 OUString sURL(officecfg::Office::Common::Menus::GetInvolvedURL::get() + //https://hub.libreoffice.org/joinus/
511 "?LOlocale=" + utl::ConfigManager::getUILocale());
512 sfx2::openUriExternally(sURL, false);
513 break;
515 case SID_DONATION:
517 // Open donation page based on language + script (BCP47) with language as fall back.
518 OUString aLang = LanguageTag(utl::ConfigManager::getUILocale()).getLanguage();
519 OUString aBcp47 = LanguageTag(utl::ConfigManager::getUILocale()).getBcp47();
520 OUString sURL(officecfg::Office::Common::Menus::DonationURL::get() + //https://hub.libreoffice.org/donation/
521 "?BCP47=" + aBcp47 + "&LOlang=" + aLang );
522 sfx2::openUriExternally(sURL, false);
523 break;
525 case SID_WHATSNEW:
527 // Open release notes depending on version and locale
528 OUString sURL(officecfg::Office::Common::Menus::ReleaseNotesURL::get() + //https://hub.libreoffice.org/ReleaseNotes/
529 "?LOvers=" + utl::ConfigManager::getProductVersion() +
530 "&LOlocale=" + LanguageTag(utl::ConfigManager::getUILocale()).getBcp47() );
531 sfx2::openUriExternally(sURL, false);
532 break;
534 case SID_HYPHENATIONMISSING:
536 // Open wiki page about hyphenation
537 OUString sURL(officecfg::Office::Common::Menus::HyphenationMissingURL::get() + //https://hub.libreoffice.org/HyphenationMissing/
538 "?LOlocale=" + utl::ConfigManager::getUILocale());
539 sfx2::openUriExternally(sURL, false);
540 break;
542 case SID_SHOW_LICENSE:
544 LicenseDialog aDialog(rReq.GetFrameWeld());
545 aDialog.run();
546 break;
549 case SID_SHOW_CREDITS:
551 showDocument( "CREDITS" );
552 break;
555 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
556 case SID_HELPINDEX:
558 Help* pHelp = Application::GetHelp();
559 if ( pHelp )
561 pHelp->Start(".uno:HelpIndex", rReq.GetFrameWeld()); // show start page
562 bDone = true;
564 break;
567 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
568 case SID_HELPTIPS:
570 // Evaluate Parameter
571 const SfxBoolItem* pOnItem = rReq.GetArg<SfxBoolItem>(SID_HELPTIPS);
572 bool bOn = pOnItem
573 ? pOnItem->GetValue()
574 : !Help::IsQuickHelpEnabled();
576 if ( bOn )
577 Help::EnableQuickHelp();
578 else
579 Help::DisableQuickHelp();
580 auto xChanges = comphelper::ConfigurationChanges::create();
581 officecfg::Office::Common::Help::Tip::set(bOn, xChanges);
582 xChanges->commit();
583 Invalidate(SID_HELPTIPS);
584 bDone = true;
586 // Record if possible
587 if ( !rReq.IsAPI() )
588 rReq.AppendItem( SfxBoolItem( SID_HELPTIPS, bOn) );
589 break;
591 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
592 case SID_EXTENDEDHELP:
594 Help::StartExtHelp();
595 break;
597 case SID_HELPBALLOONS:
599 // Evaluate Parameter
600 const SfxBoolItem* pOnItem = rReq.GetArg<SfxBoolItem>(SID_HELPBALLOONS);
601 bool bOn = pOnItem
602 ? pOnItem->GetValue()
603 : !Help::IsBalloonHelpEnabled();
605 if ( bOn )
606 Help::EnableBalloonHelp();
607 else
608 Help::DisableBalloonHelp();
609 auto xChanges = comphelper::ConfigurationChanges::create();
610 officecfg::Office::Common::Help::ExtendedTip::set(bOn, xChanges);
611 xChanges->commit();
612 Invalidate(SID_HELPBALLOONS);
613 bDone = true;
615 // Record if possible
616 if ( !rReq.IsAPI() )
617 rReq.AppendItem( SfxBoolItem( SID_HELPBALLOONS, bOn) );
618 break;
620 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
621 case SID_TIPOFTHEDAY:
623 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
624 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateTipOfTheDayDialog(rReq.GetFrameWeld()));
625 pDlg->StartExecuteAsync(nullptr);
626 bDone = true;
627 break;
630 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
631 case SID_ABOUT:
633 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
634 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateAboutDialog(rReq.GetFrameWeld()));
635 pDlg->Execute();
636 bDone = true;
637 break;
640 case SID_TEMPLATE_MANAGER:
642 SfxTemplateManagerDlg aDialog(rReq.GetFrameWeld());
643 aDialog.run();
644 bDone = true;
645 break;
648 case SID_TEMPLATE_ADDRESSBOOKSOURCE:
650 svt::AddressBookSourceDialog aDialog(rReq.GetFrameWeld(), ::comphelper::getProcessComponentContext());
651 aDialog.run();
652 bDone = true;
653 break;
656 #if HAVE_FEATURE_SCRIPTING
657 case SID_BASICSTOP:
658 StarBASIC::Stop();
659 break;
661 case SID_BASICBREAK :
662 BasicDLL::BasicBreak();
663 break;
664 #endif
666 case SID_ZOOM_50_PERCENT:
667 case SID_ZOOM_75_PERCENT:
668 case SID_ZOOM_100_PERCENT:
669 case SID_ZOOM_150_PERCENT:
670 case SID_ZOOM_200_PERCENT:
671 case SID_ZOOM_OPTIMAL:
672 case SID_ZOOM_ENTIRE_PAGE:
673 case SID_ZOOM_PAGE_WIDTH:
675 SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
676 if (!pCurrentShell)
677 return;
679 // make sure aZoom is initialized with a proper value if SetType
680 // doesn't work
681 SvxZoomItem aZoom( SvxZoomType::PERCENT, 100 );
683 switch (rReq.GetSlot())
685 case SID_ZOOM_50_PERCENT:
686 aZoom.SetValue(50);
687 break;
688 case SID_ZOOM_75_PERCENT:
689 aZoom.SetValue(75);
690 break;
691 case SID_ZOOM_100_PERCENT:
692 aZoom.SetValue(100);
693 break;
694 case SID_ZOOM_150_PERCENT:
695 aZoom.SetValue(150);
696 break;
697 case SID_ZOOM_200_PERCENT:
698 aZoom.SetValue(200);
699 break;
700 case SID_ZOOM_OPTIMAL:
701 aZoom.SetType( SvxZoomType::OPTIMAL );
702 break;
703 case SID_ZOOM_ENTIRE_PAGE:
704 aZoom.SetType( SvxZoomType::WHOLEPAGE );
705 break;
706 case SID_ZOOM_PAGE_WIDTH:
707 aZoom.SetType( SvxZoomType::PAGEWIDTH );
708 break;
711 pCurrentShell->GetDispatcher()->ExecuteList(SID_ATTR_ZOOM, SfxCallMode::ASYNCHRON, { &aZoom });
713 break;
715 case SID_TOOLBAR_MODE:
717 const SfxStringItem* pModeName = rReq.GetArg<SfxStringItem>( SID_TOOLBAR_MODE );
719 if ( !pModeName )
721 bDone = true;
722 break;
725 OUString aNewName(pModeName->GetValue());
726 uno::Reference< uno::XComponentContext > xContext =
727 ::comphelper::getProcessComponentContext();
729 // Get information about current frame and module
730 Reference<XFrame> xCurrentFrame;
731 vcl::EnumContext::Application eCurrentApp = vcl::EnumContext::Application::NONE;
732 OUString aCurrentMode;
734 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
735 if( pViewFrame )
737 xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface();
739 const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xContext );
740 eCurrentApp = vcl::EnumContext::GetApplicationEnum( xModuleManager->identify( xCurrentFrame ) );
742 OUString aPath = "org.openoffice.Office.UI.ToolbarMode/Applications/" +
743 lcl_getAppName( eCurrentApp );
745 const utl::OConfigurationTreeRoot aAppNode(
746 xContext,
747 aPath,
748 true);
749 if ( !aAppNode.isValid() )
751 bDone = true;
752 break;
755 aCurrentMode = comphelper::getString( aAppNode.getNodeValue( "Active" ) );
757 if ( aCurrentMode == aNewName )
759 bDone = true;
760 break;
763 // Save new toolbar mode for a current module
764 aAppNode.setNodeValue( "Active", makeAny( aNewName ) );
765 aAppNode.commit();
768 // Apply settings for all frames
769 pViewFrame = SfxViewFrame::GetFirst();
770 while( pViewFrame )
772 Reference<XFrame> xFrame = pViewFrame->GetFrame().GetFrameInterface();
774 // We want to change mode only for a current app module, ignore other apps
775 const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xContext );
776 vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum( xModuleManager->identify( xFrame ) );
777 if ( eApp != eCurrentApp )
779 pViewFrame = SfxViewFrame::GetNext( *pViewFrame );
780 continue;
783 Reference<css::beans::XPropertySet> xPropSet( xFrame, UNO_QUERY );
784 Reference<css::frame::XLayoutManager> xLayoutManager;
785 if ( xPropSet.is() )
789 Any aValue = xPropSet->getPropertyValue( "LayoutManager" );
790 aValue >>= xLayoutManager;
792 catch ( const css::uno::RuntimeException& )
794 throw;
796 catch ( css::uno::Exception& )
801 if ( xLayoutManager.is() )
803 css::uno::Sequence<OUString> aMandatoryToolbars;
804 css::uno::Sequence<OUString> aUserToolbars;
805 std::vector<OUString> aBackupList;
806 OUString aSidebarMode;
808 OUString aPath = "org.openoffice.Office.UI.ToolbarMode/Applications/" +
809 lcl_getAppName( eApp ) +
810 "/Modes";
812 // Read mode settings
813 const utl::OConfigurationTreeRoot aModesNode(
814 xContext,
815 aPath,
816 true);
817 if ( !aModesNode.isValid() )
819 bDone = true;
820 break;
823 const Sequence<OUString> aModeNodeNames( aModesNode.getNodeNames() );
825 for ( const auto& rModeNodeName : aModeNodeNames )
827 const utl::OConfigurationNode aModeNode( aModesNode.openNode( rModeNodeName ) );
828 if ( !aModeNode.isValid() )
829 continue;
831 OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( "CommandArg" ) );
833 if ( aCommandArg == aNewName )
835 aMandatoryToolbars = aModeNode.getNodeValue( "Toolbars" ).get< uno::Sequence<OUString> >();
836 aUserToolbars = aModeNode.getNodeValue( "UserToolbars" ).get< uno::Sequence<OUString> >();
837 aSidebarMode = comphelper::getString( aModeNode.getNodeValue( "Sidebar" ) );
838 break;
842 // Backup visible toolbar list and hide all toolbars
843 const Sequence<Reference<XUIElement>> aUIElements = xLayoutManager->getElements();
844 for ( const Reference< XUIElement >& xUIElement : aUIElements )
846 Reference< XPropertySet > xPropertySet( xUIElement, UNO_QUERY );
847 if ( xPropertySet.is() && xUIElement.is() )
851 OUString aResName;
852 sal_Int16 nType( -1 );
853 xPropertySet->getPropertyValue( "Type" ) >>= nType;
854 xPropertySet->getPropertyValue( "ResourceURL" ) >>= aResName;
856 if (( nType == css::ui::UIElementType::TOOLBAR ) &&
857 !aResName.isEmpty() )
859 if ( xLayoutManager->isElementVisible( aResName ) )
861 aBackupList.push_back( aResName );
863 xLayoutManager->hideElement( aResName );
866 catch ( const Exception& )
872 // Show/Hide the Notebookbar
873 const SfxStringItem pItem(SID_NOTEBOOKBAR, aNewName);
874 pViewFrame->GetDispatcher()->ExecuteList(SID_NOTEBOOKBAR, SfxCallMode::SYNCHRON, {&pItem});
876 // Show toolbars
877 for ( const OUString& rName : std::as_const(aMandatoryToolbars) )
879 xLayoutManager->createElement( rName );
880 xLayoutManager->showElement( rName );
883 for ( const OUString& rName : std::as_const(aUserToolbars) )
885 xLayoutManager->createElement( rName );
886 xLayoutManager->showElement( rName );
889 // Sidebar
890 pViewFrame->ShowChildWindow( SID_SIDEBAR );
892 if (comphelper::LibreOfficeKit::isActive())
893 aSidebarMode = "Opened";
895 sfx2::sidebar::SidebarController* pSidebar =
896 sfx2::sidebar::SidebarController::GetSidebarControllerForFrame( xFrame );
897 if ( pSidebar )
899 if ( aSidebarMode == "Arrow" )
901 pSidebar->FadeOut();
903 else if ( aSidebarMode == "Tabs" )
905 pSidebar->FadeIn();
906 pSidebar->RequestOpenDeck();
907 pSidebar->RequestCloseDeck();
909 else if ( aSidebarMode == "Opened" )
911 pSidebar->FadeIn();
912 pSidebar->RequestOpenDeck();
916 // Save settings
917 if ( pViewFrame == SfxViewFrame::Current() )
919 css::uno::Sequence<OUString> aBackup( comphelper::containerToSequence(aBackupList) );
921 for ( const auto& rModeNodeName : aModeNodeNames )
923 const utl::OConfigurationNode aModeNode( aModesNode.openNode( rModeNodeName ) );
924 if ( !aModeNode.isValid() )
925 continue;
927 OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( "CommandArg" ) );
929 if ( aCommandArg == aCurrentMode )
931 aModeNode.setNodeValue( "UserToolbars", makeAny( aBackup ) );
932 break;
935 aModesNode.commit();
939 pViewFrame = SfxViewFrame::GetNext(*pViewFrame);
942 bDone = true;
943 break;
945 case SID_TOOLBAR_MODE_UI:
947 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
948 ScopedVclPtr<VclAbstractDialog> pDlg(
949 pFact->CreateToolbarmodeDialog(rReq.GetFrameWeld()));
950 pDlg->Execute();
951 bDone = true;
952 break;
954 case SID_AVAILABLE_TOOLBARS:
956 const SfxStringItem* pToolbarName = rReq.GetArg<SfxStringItem>(SID_AVAILABLE_TOOLBARS);
958 if ( pToolbarName )
960 Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
961 Reference< XFrame > xFrame = xDesktop->getActiveFrame();
963 Reference< css::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
964 Reference< css::frame::XLayoutManager > xLayoutManager;
965 if ( xPropSet.is() )
969 Any aValue = xPropSet->getPropertyValue("LayoutManager");
970 aValue >>= xLayoutManager;
972 catch ( const css::uno::RuntimeException& )
974 throw;
976 catch ( css::uno::Exception& )
981 if ( xLayoutManager.is() )
983 OUString aToolbarName = "private:resource/toolbar/" +
984 pToolbarName->GetValue();
986 // Evaluate Parameter
987 bool bShow( !xLayoutManager->isElementVisible( aToolbarName ));
989 if ( bShow )
991 xLayoutManager->createElement( aToolbarName );
992 xLayoutManager->showElement( aToolbarName );
994 else
995 xLayoutManager->hideElement( aToolbarName );
999 bDone = true;
1000 break;
1002 case SID_MENUBAR:
1004 sfx2::SfxNotebookBar::ToggleMenubar();
1005 bDone = true;
1006 break;
1008 case SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW:
1010 SfxViewShell* pViewShell = SfxViewShell::Current();
1011 SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
1012 auto nID = rReq.GetSlot();
1013 pViewFrame->ToggleChildWindow(nID);
1015 bDone = true;
1016 break;
1018 case SID_INSPECT_SELECTED_OBJECT:
1020 SfxViewShell* pViewShell = SfxViewShell::Current();
1021 SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
1023 pViewFrame->ShowChildWindow(SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW, true);
1025 SfxChildWindow* pChild = pViewFrame->GetChildWindow(SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW);
1026 if (!pChild)
1027 return;
1029 auto pDockingWin = dynamic_cast<DevelopmentToolDockingWindow*>(pChild->GetWindow());
1030 if (pDockingWin)
1032 pDockingWin->changeToCurrentSelection();
1035 bDone = true;
1036 break;
1038 case SID_SAFE_MODE:
1040 SafeModeQueryDialog aDialog(rReq.GetFrameWeld());
1041 aDialog.run();
1042 break;
1044 case SID_TOOLBAR_LOCK:
1046 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1047 if (pViewFrame)
1049 Reference<XFrame> xCurrentFrame;
1050 uno::Reference<uno::XComponentContext> xContext
1051 = ::comphelper::getProcessComponentContext();
1052 xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface();
1053 const Reference<frame::XModuleManager> xModuleManager
1054 = frame::ModuleManager::create(xContext);
1055 const utl::OConfigurationTreeRoot aAppNode(
1056 xContext, "org.openoffice.Office.UI.GlobalSettings/Toolbars/States", true);
1057 if (aAppNode.isValid())
1059 bool isLocked = comphelper::getBOOL(aAppNode.getNodeValue("Locked"));
1060 aAppNode.setNodeValue("Locked", makeAny(!isLocked));
1061 aAppNode.commit();
1062 //TODO: apply immediately w/o restart needed
1063 SolarMutexGuard aGuard;
1064 svtools::executeRestartDialog(comphelper::getProcessComponentContext(), nullptr,
1065 svtools::RESTART_REASON_UI_CHANGE);
1068 break;
1070 default:
1071 break;
1074 if ( bDone )
1075 rReq.Done();
1078 void SfxApplication::MiscState_Impl(SfxItemSet &rSet)
1080 const WhichRangesContainer & pRanges = rSet.GetRanges();
1081 DBG_ASSERT(!pRanges.empty(), "Set without range");
1082 for ( auto const & pRange : pRanges )
1084 for(sal_uInt16 nWhich = pRange.first; nWhich <= pRange.second; ++nWhich)
1086 switch(nWhich)
1088 case SID_TEMPLATE_ADDRESSBOOKSOURCE:
1089 if ( !SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::DATABASE) )
1090 rSet.Put(SfxVisibilityItem(nWhich, false));
1091 break;
1092 case SID_QUITAPP:
1094 if ( pImpl->nDocModalMode )
1095 rSet.DisableItem(nWhich);
1096 else
1097 rSet.Put(SfxStringItem(nWhich, SfxResId(STR_QUITAPP)));
1098 break;
1101 case SID_CONFIG:
1102 case SID_TOOLBOXOPTIONS:
1103 case SID_CONFIGSTATUSBAR:
1104 case SID_CONFIGMENU:
1105 case SID_CONFIGACCEL:
1106 case SID_CONFIGEVENT:
1108 if( officecfg::Office::Common::Misc::DisableUICustomization::get() )
1109 rSet.DisableItem(nWhich);
1110 break;
1113 #if HAVE_FEATURE_SCRIPTING
1114 case SID_BASICSTOP:
1115 if ( !StarBASIC::IsRunning() )
1116 rSet.DisableItem(nWhich);
1117 break;
1118 #endif
1120 case SID_HELPTIPS:
1122 rSet.Put( SfxBoolItem( SID_HELPTIPS, Help::IsQuickHelpEnabled() ) );
1124 break;
1125 case SID_HELPBALLOONS:
1127 rSet.Put( SfxBoolItem( SID_HELPBALLOONS, Help::IsBalloonHelpEnabled() ) );
1129 break;
1131 case SID_EXTENDEDHELP:
1134 break;
1136 case SID_CLOSEDOCS:
1138 Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
1139 Reference< XIndexAccess > xTasks = xDesktop->getFrames();
1140 if ( !xTasks.is() || !xTasks->getCount() )
1141 rSet.DisableItem(nWhich);
1142 break;
1145 case SID_SAVEDOCS:
1147 bool bModified = false;
1148 for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
1149 pObjSh;
1150 pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
1152 if ( pObjSh->IsModified() )
1154 bModified = true;
1155 break;
1159 if ( !bModified )
1160 rSet.DisableItem( nWhich );
1161 break;
1164 case SID_TEMPLATE_MANAGER:
1166 if ( !officecfg::Office::Common::Misc::ExperimentalMode::get() )
1168 rSet.DisableItem( nWhich );
1169 rSet.Put( SfxVisibilityItem( nWhich, false ) );
1172 break;
1174 case SID_ZOOM_50_PERCENT:
1175 case SID_ZOOM_75_PERCENT:
1176 case SID_ZOOM_100_PERCENT:
1177 case SID_ZOOM_150_PERCENT:
1178 case SID_ZOOM_200_PERCENT:
1179 case SID_ZOOM_OPTIMAL:
1180 case SID_ZOOM_ENTIRE_PAGE:
1181 case SID_ZOOM_PAGE_WIDTH:
1183 SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
1185 const SfxPoolItem *pItem;
1186 SfxItemState aState = pCurrentShell ?
1187 pCurrentShell->GetDispatcher()->QueryState(SID_ATTR_ZOOM, pItem) : SfxItemState::DISABLED;
1188 if ( aState == SfxItemState::DISABLED )
1189 rSet.DisableItem( nWhich );
1191 break;
1193 case SID_MENUBAR:
1195 Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
1196 Reference< XFrame > xFrame = xDesktop->getActiveFrame();
1198 Reference< css::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
1199 Reference< css::frame::XLayoutManager > xLayoutManager;
1200 if ( xPropSet.is() )
1204 Any aValue = xPropSet->getPropertyValue("LayoutManager");
1205 aValue >>= xLayoutManager;
1207 catch ( const css::uno::RuntimeException& )
1209 throw;
1211 catch ( css::uno::Exception& )
1216 if ( xLayoutManager.is() )
1218 const bool bState
1219 = xLayoutManager->getElement("private:resource/menubar/menubar").is()
1220 && xLayoutManager->isElementVisible(
1221 "private:resource/menubar/menubar");
1223 SfxBoolItem aItem( SID_MENUBAR, bState );
1224 rSet.Put( aItem );
1226 break;
1228 case SID_SAFE_MODE:
1230 // no restart in safe mode when already in safe mode
1231 if ( Application::IsSafeModeEnabled() )
1232 rSet.DisableItem( SID_SAFE_MODE );
1233 break;
1235 case SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW:
1237 bool bSuccess = false;
1238 auto* pViewShell = SfxViewShell::Current();
1239 if (pViewShell)
1241 auto* pViewFrame = pViewShell->GetViewFrame();
1242 if (pViewFrame && pViewFrame->KnowsChildWindow(nWhich))
1244 rSet.Put(SfxBoolItem(nWhich, pViewFrame->HasChildWindow(nWhich)));
1245 bSuccess = true;
1249 if (!bSuccess)
1250 rSet.DisableItem(nWhich);
1252 break;
1253 case SID_INSPECT_SELECTED_OBJECT:
1255 bool bSuccess = false;
1256 auto* pViewShell = SfxViewShell::Current();
1257 if (pViewShell)
1259 auto* pViewFrame = pViewShell->GetViewFrame();
1260 if (pViewFrame && pViewFrame->KnowsChildWindow(SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW))
1262 bSuccess = true;
1265 if (!bSuccess)
1266 rSet.DisableItem(nWhich);
1268 break;
1269 case SID_TOOLBAR_LOCK:
1271 rSet.Put( SfxBoolItem( SID_TOOLBAR_LOCK, ToolBox::AlwaysLocked() ));
1273 break;
1274 default:
1275 break;
1281 #if HAVE_FEATURE_SCRIPTING
1283 #ifndef DISABLE_DYNLOADING
1285 typedef rtl_uString* (*basicide_choose_macro)(void*, void*, void*, sal_Bool);
1287 #else
1289 extern "C" rtl_uString* basicide_choose_macro(void*, void*, void*, sal_Bool);
1291 #endif
1293 static OUString ChooseMacro(weld::Window* pParent, const Reference<XModel>& rxLimitToDocument, const Reference<XFrame>& xDocFrame, bool bChooseOnly)
1295 #ifndef DISABLE_DYNLOADING
1296 basicide_choose_macro pSymbol = reinterpret_cast<basicide_choose_macro>(sfx2::getBasctlFunction("basicide_choose_macro"));
1297 #else
1298 #define pSymbol basicide_choose_macro
1299 #endif
1301 // call basicide_choose_macro in basctl
1302 rtl_uString* pScriptURL = pSymbol(pParent, rxLimitToDocument.get(), xDocFrame.get(), bChooseOnly);
1303 OUString aScriptURL( pScriptURL );
1304 rtl_uString_release( pScriptURL );
1305 return aScriptURL;
1307 #ifdef DISABLE_DYNLOADING
1308 #undef pSymbol
1309 #endif
1312 #endif
1314 namespace
1316 #if HAVE_FEATURE_SCRIPTING
1317 weld::Window* lcl_getDialogParent(const Reference<XFrame>& rxFrame)
1319 Reference<awt::XWindow> xContainerWindow;
1320 if (rxFrame.is())
1321 xContainerWindow = rxFrame->getContainerWindow();
1322 return Application::GetFrameWeld(xContainerWindow);
1325 SfxViewFrame* lcl_getBasicIDEViewFrame( SfxObjectShell const * i_pBasicIDE )
1327 SfxViewFrame* pView = SfxViewFrame::GetFirst( i_pBasicIDE );
1328 while ( pView )
1330 if ( pView->GetObjectShell()->GetFactory().GetDocumentServiceName() == "com.sun.star.script.BasicIDE" )
1331 break;
1332 pView = SfxViewFrame::GetNext( *pView, i_pBasicIDE );
1334 return pView;
1336 Reference< XFrame > lcl_findStartModuleFrame( const Reference<XComponentContext> & rxContext )
1340 Reference < XDesktop2 > xDesktop = Desktop::create( rxContext );
1341 Reference < XIndexAccess > xContainer( xDesktop->getFrames(), UNO_QUERY_THROW );
1343 Reference< XModuleManager2 > xCheck = ModuleManager::create(rxContext);
1345 sal_Int32 nCount = xContainer->getCount();
1346 for ( sal_Int32 i=0; i<nCount; ++i )
1350 Reference < XFrame > xFrame( xContainer->getByIndex(i), UNO_QUERY_THROW );
1351 OUString sModule = xCheck->identify( xFrame );
1352 if ( sModule == "com.sun.star.frame.StartModule" )
1353 return xFrame;
1355 catch( const UnknownModuleException& )
1357 // silence
1359 catch(const Exception&)
1361 // re-throw, caught below
1362 throw;
1366 catch( const Exception& )
1368 DBG_UNHANDLED_EXCEPTION("sfx.appl");
1370 return nullptr;
1372 #endif // HAVE_FEATURE_SCRIPTING
1375 void SfxApplication::OfaExec_Impl( SfxRequest& rReq )
1377 switch ( rReq.GetSlot() )
1379 case SID_OPTIONS_TREEDIALOG:
1381 OUString sPageURL;
1382 const SfxStringItem* pURLItem = rReq.GetArg<SfxStringItem>(SID_OPTIONS_PAGEURL);
1383 if ( pURLItem )
1384 sPageURL = pURLItem->GetValue();
1385 Reference <XFrame> xFrame(GetRequestFrame(rReq));
1386 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1387 VclPtr<VclAbstractDialog> pDlg =
1388 pFact->CreateFrameDialog(rReq.GetFrameWeld(), xFrame, rReq.GetSlot(), sPageURL );
1389 short nRet = pDlg->Execute();
1390 pDlg.disposeAndClear();
1391 SfxViewFrame* pView = SfxViewFrame::GetFirst();
1392 while ( pView )
1394 if (nRet == RET_OK)
1396 SfxObjectShell* pObjSh = pView->GetObjectShell();
1397 if (pObjSh)
1398 pObjSh->SetConfigOptionsChecked(false);
1400 pView->GetBindings().InvalidateAll(false);
1401 pView = SfxViewFrame::GetNext( *pView );
1403 break;
1406 case SID_MORE_DICTIONARIES:
1408 uno::Sequence<beans::PropertyValue> aArgs(1);
1409 aArgs[0].Name = "AdditionsTag";
1410 aArgs[0].Value <<= OUString("Dictionary");
1411 comphelper::dispatchCommand(".uno:AdditionsDialog", aArgs);
1412 break;
1414 #if HAVE_FEATURE_SCRIPTING
1415 case SID_BASICIDE_APPEAR:
1417 SfxViewFrame* pView = lcl_getBasicIDEViewFrame( nullptr );
1418 if ( !pView )
1420 SfxObjectShell* pBasicIDE = SfxObjectShell::CreateObject( "com.sun.star.script.BasicIDE" );
1421 pBasicIDE->DoInitNew();
1422 pBasicIDE->SetModified( false );
1425 // load the Basic IDE via direct access to the SFX frame loader. A generic loadComponentFromURL
1426 // (which could be done via SfxViewFrame::LoadDocumentIntoFrame) is not feasible here, since the Basic IDE
1427 // does not really play nice with the framework's concept. For instance, it is a "singleton document",
1428 // which conflicts, at the latest, with the framework's concept of loading into _blank frames.
1429 // So, since we know that our frame loader can handle it, we skip the generic framework loader
1430 // mechanism, and the type detection (which doesn't know about the Basic IDE).
1431 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1432 Reference< XSynchronousFrameLoader > xLoader(
1433 xContext->getServiceManager()->createInstanceWithContext("com.sun.star.comp.office.FrameLoader", xContext),
1434 UNO_QUERY_THROW );
1435 ::comphelper::NamedValueCollection aLoadArgs;
1436 aLoadArgs.put( "Model", pBasicIDE->GetModel() );
1437 aLoadArgs.put( "URL", OUString( "private:factory/sbasic" ) );
1439 Reference< XFrame > xTargetFrame( lcl_findStartModuleFrame( xContext ) );
1440 if ( !xTargetFrame.is() )
1441 xTargetFrame = SfxFrame::CreateBlankFrame();
1442 ENSURE_OR_THROW( xTargetFrame.is(), "could not obtain a frameto load the Basic IDE into!" );
1444 xLoader->load( aLoadArgs.getPropertyValues(), xTargetFrame );
1446 catch( const Exception& )
1448 DBG_UNHANDLED_EXCEPTION("sfx.appl");
1451 pView = lcl_getBasicIDEViewFrame( pBasicIDE );
1452 if ( pView )
1453 pView->SetName( "BASIC:1" );
1456 if ( pView )
1457 pView->GetFrame().Appear();
1459 const SfxItemSet* pArgs = rReq.GetArgs();
1460 if ( pArgs && pView )
1462 SfxViewShell* pViewShell = pView->GetViewShell();
1463 SfxObjectShell* pObjShell = pView->GetObjectShell();
1464 if ( pViewShell && pObjShell )
1466 SfxRequest aReq( SID_BASICIDE_SHOWWINDOW, SfxCallMode::SYNCHRON, pObjShell->GetPool() );
1467 aReq.SetArgs( *pArgs );
1468 pViewShell->ExecuteSlot( aReq );
1472 rReq.Done();
1474 break;
1476 case SID_BASICCHOOSER:
1478 const SfxItemSet* pArgs = rReq.GetArgs();
1479 const SfxPoolItem* pItem;
1480 bool bChooseOnly = false;
1481 Reference< XModel > xLimitToModel;
1482 if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_RECORDMACRO, false, &pItem) )
1484 bool bRecord = static_cast<const SfxBoolItem*>(pItem)->GetValue();
1485 if ( bRecord )
1487 // !Hack
1488 bChooseOnly = false;
1489 SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
1490 OSL_ENSURE( pCurrentShell, "macro recording outside an SFX document?" );
1491 if ( pCurrentShell )
1492 xLimitToModel = pCurrentShell->GetModel();
1496 Reference <XFrame> xFrame(GetRequestFrame(rReq));
1497 rReq.SetReturnValue(SfxStringItem(rReq.GetSlot(), ChooseMacro(rReq.GetFrameWeld(), xLimitToModel, xFrame, bChooseOnly)));
1498 rReq.Done();
1500 break;
1502 case SID_MACROORGANIZER:
1504 SAL_INFO("sfx.appl", "handling SID_MACROORGANIZER");
1505 const SfxItemSet* pArgs = rReq.GetArgs();
1506 const SfxPoolItem* pItem;
1507 sal_Int16 nTabId = 0;
1508 if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_MACROORGANIZER, false, &pItem) )
1510 nTabId = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
1513 SfxApplication::MacroOrganizer(rReq.GetFrameWeld(), nTabId);
1514 rReq.Done();
1516 break;
1518 case SID_RUNMACRO:
1520 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1521 SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: case ScriptOrg");
1523 Reference <XFrame> xFrame(GetRequestFrame(rReq));
1524 if ( !xFrame.is() )
1526 const SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1527 if ( pViewFrame )
1528 xFrame = pViewFrame->GetFrame().GetFrameInterface();
1531 do // artificial loop for flow control
1533 VclPtr<AbstractScriptSelectorDialog> pDlg(pFact->CreateScriptSelectorDialog(lcl_getDialogParent(xFrame), xFrame));
1534 OSL_ENSURE( pDlg, "SfxApplication::OfaExec_Impl( SID_RUNMACRO ): no dialog!" );
1535 if ( !pDlg )
1536 break;
1537 pDlg->SetRunLabel();
1539 pDlg->StartExecuteAsync([pDlg, xFrame](sal_Int32 nDialogResult) {
1540 if ( !nDialogResult )
1542 pDlg->disposeOnce();
1543 return;
1546 Sequence< Any > args;
1547 Sequence< sal_Int16 > outIndex;
1548 Sequence< Any > outArgs;
1549 Any ret;
1551 Reference< XInterface > xScriptContext;
1553 Reference< XController > xController;
1554 if ( xFrame.is() )
1555 xController = xFrame->getController();
1556 if ( xController.is() )
1557 xScriptContext = xController->getModel();
1558 if ( !xScriptContext.is() )
1559 xScriptContext = xController;
1561 SfxObjectShell::CallXScript( xScriptContext, pDlg->GetScriptURL(), args, ret, outIndex, outArgs );
1562 pDlg->disposeOnce();
1565 while ( false );
1566 rReq.Done();
1568 break;
1570 case SID_SCRIPTORGANIZER:
1572 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1573 SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: case ScriptOrg");
1574 const SfxItemSet* pArgs = rReq.GetArgs();
1575 const SfxPoolItem* pItem;
1576 OUString aLanguage;
1577 if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_SCRIPTORGANIZER, false, &pItem) )
1579 aLanguage = static_cast<const SfxScriptOrganizerItem*>(pItem)->getLanguage();
1582 OUString aLang( aLanguage );
1583 SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: about to create dialog for: " << aLang);
1584 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSvxScriptOrgDialog(rReq.GetFrameWeld(), aLanguage));
1585 if( pDlg )
1587 pDlg->Execute();
1589 else
1591 SAL_WARN("sfx.appl", "no dialog!!!");
1593 rReq.Done();
1595 break;
1596 #endif // HAVE_FEATURE_SCRIPTING
1598 case SID_OFFICE_CHECK_PLZ:
1600 bool bRet = false;
1601 const SfxStringItem* pStringItem = rReq.GetArg<SfxStringItem>(rReq.GetSlot());
1603 if ( pStringItem )
1605 bRet = true /*!!!SfxIniManager::CheckPLZ( aPLZ )*/;
1607 #if HAVE_FEATURE_SCRIPTING
1608 else
1609 SbxBase::SetError( ERRCODE_BASIC_WRONG_ARGS );
1610 #endif
1611 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bRet ) );
1613 break;
1615 case SID_AUTO_CORRECT_DLG:
1617 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1618 SfxItemSet aSet(GetPool(), svl::Items<SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG>);
1619 const SfxPoolItem* pItem=nullptr;
1620 const SfxItemSet* pSet = rReq.GetArgs();
1621 SfxItemPool* pSetPool = pSet ? pSet->GetPool() : nullptr;
1622 if ( pSet && pSet->GetItemState( pSetPool->GetWhich( SID_AUTO_CORRECT_DLG ), false, &pItem ) == SfxItemState::SET )
1623 aSet.Put( *pItem );
1625 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateAutoCorrTabDialog(rReq.GetFrameWeld(), &aSet));
1626 pDlg->Execute();
1628 break;
1631 case SID_NEWSD :
1633 SvtModuleOptions aModuleOpt;
1634 if ( !aModuleOpt.IsImpress() )
1636 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(rReq.GetFrameWeld(),
1637 VclMessageType::Warning, VclButtonsType::Ok,
1638 SfxResId(STR_MODULENOTINSTALLED)));
1639 xBox->run();
1640 return;
1643 Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
1644 Reference< frame::XDispatchProvider > xProv = drawing::ModuleDispatcher::create( xContext );
1646 OUString aCmd = OUString::createFromAscii( GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName() );
1647 Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
1648 Sequence < beans::PropertyValue > aSeq;
1649 if ( rReq.GetArgs() )
1650 TransformItems( rReq.GetSlot(), *rReq.GetArgs(), aSeq );
1651 Any aResult = xHelper->executeDispatch( xProv, aCmd, OUString(), 0, aSeq );
1652 frame::DispatchResultEvent aEvent;
1653 bool bSuccess = (aResult >>= aEvent) &&
1654 (aEvent.State == frame::DispatchResultState::SUCCESS);
1655 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
1657 break;
1659 case FN_LABEL :
1660 case FN_BUSINESS_CARD :
1661 case FN_XFORMS_INIT :
1663 Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
1664 Reference< frame::XDispatchProvider > xProv = text::ModuleDispatcher::create( xContext );
1666 OUString aCmd = OUString::createFromAscii( GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName() );
1667 Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
1668 Sequence < beans::PropertyValue > aSeq;
1669 if ( rReq.GetArgs() )
1670 TransformItems( rReq.GetSlot(), *rReq.GetArgs(), aSeq );
1671 Any aResult = xHelper->executeDispatch( xProv, aCmd, OUString(), 0, aSeq );
1672 frame::DispatchResultEvent aEvent;
1673 bool bSuccess = (aResult >>= aEvent) &&
1674 (aEvent.State == frame::DispatchResultState::SUCCESS);
1675 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
1677 break;
1679 case SID_ADDRESS_DATA_SOURCE:
1683 Reference< uno::XComponentContext > xORB = ::comphelper::getProcessComponentContext();
1684 Reference< ui::dialogs::XExecutableDialog > xDialog = ui::dialogs::AddressBookSourcePilot::createWithParent(xORB, nullptr);
1685 xDialog->execute();
1687 catch(const css::uno::Exception&)
1689 DBG_UNHANDLED_EXCEPTION("sfx.appl");
1692 break;
1694 case SID_COMP_BIBLIOGRAPHY:
1695 lcl_tryLoadBibliography();
1696 break;
1700 void SfxApplication::OfaState_Impl(SfxItemSet &rSet)
1702 SvtModuleOptions aModuleOpt;
1704 if( !aModuleOpt.IsWriter())
1706 rSet.DisableItem( FN_LABEL );
1707 rSet.DisableItem( FN_BUSINESS_CARD );
1708 rSet.DisableItem( FN_XFORMS_INIT );
1710 if ( comphelper::LibreOfficeKit::isActive() )
1711 rSet.DisableItem( SID_AUTO_CORRECT_DLG );
1713 bool bMacrosDisabled
1714 = officecfg::Office::Common::Security::Scripting::DisableMacrosExecution::get();
1715 if (bMacrosDisabled)
1717 rSet.DisableItem(SID_RUNMACRO);
1718 rSet.DisableItem(SID_MACROORGANIZER);
1719 rSet.DisableItem(SID_SCRIPTORGANIZER);
1720 rSet.DisableItem(SID_BASICIDE_APPEAR);
1724 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */