1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
;
120 OUString
lcl_getAppName( vcl::EnumContext::Application eApp
)
124 case vcl::EnumContext::Application::Writer
:
126 case vcl::EnumContext::Application::Calc
:
128 case vcl::EnumContext::Application::Impress
:
130 case vcl::EnumContext::Application::Draw
:
132 case vcl::EnumContext::Application::Formula
:
134 case vcl::EnumContext::Application::Base
:
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");
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");
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
)
202 DirectoryItem aDirItem
;
205 rURL
= "$BRAND_BASE_DIR/Resources/" + OUString::createFromAscii( pName
) +
206 OUString::createFromAscii( pExt
);
208 rURL
= "$BRAND_BASE_DIR/" + OUString::createFromAscii( pName
) +
209 OUString::createFromAscii( pExt
);
211 rtl::Bootstrap::expandMacros( rURL
);
214 return DirectoryItem::get( rURL
, aDirItem
) == DirectoryItem::E_None
;
219 /// Displays CREDITS or LICENSE in any of the available version
220 static void showDocument( const char* pBaseName
)
223 Reference
< XDesktop2
> xDesktop
= Desktop::create( ::comphelper::getProcessComponentContext() );
224 auto args(::comphelper::InitPropertySequence({
225 {"ViewOnly", makeAny(true)},
226 {"ReadOnly", makeAny(true)}
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
&) {
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();
254 class LicenseDialog
: public weld::GenericDialogController
257 LicenseDialog(weld::Window
* pParent
)
258 : GenericDialogController(pParent
, "sfx/ui/licensedialog.ui", "LicenseDialog")
262 virtual short run() override
264 short nRet
= GenericDialogController::run();
266 showDocument("LICENSE");
271 class SafeModeQueryDialog
: public weld::MessageDialogController
274 SafeModeQueryDialog(weld::Window
* pParent
)
275 : MessageDialogController(pParent
, "sfx/ui/safemodequerydialog.ui", "SafeModeQueryDialog")
279 virtual short run() override
281 short nRet
= MessageDialogController::run();
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
>());
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
;
304 return Application::GetFrameWeld(xWindow
);
307 Reference
<XFrame
> xFrame(GetRequestFrame(*this));
310 SAL_WARN("sfx.appl", "no parent for dialogs");
313 return Application::GetFrameWeld(xFrame
->getContainerWindow());
316 void SfxApplication::MiscExec_Impl( SfxRequest
& rReq
)
319 switch ( rReq
.GetSlot() )
324 SetOptions_Impl( *rReq
.GetArgs() );
331 // protect against reentrant calls
332 if ( pImpl
->bInQuit
)
335 if ( rReq
.GetSlot() == SID_LOGOUT
)
337 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
338 pObjSh
; pObjSh
= SfxObjectShell::GetNext( *pObjSh
) )
340 if ( !pObjSh
->IsModified() )
343 SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( pObjSh
);
344 if ( !pFrame
|| !pFrame
->GetWindow().IsReallyVisible() )
347 if (pObjSh
->PrepareClose())
348 pObjSh
->SetModified( false );
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
});
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() );
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();
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
) );
391 case SID_TOOLBOXOPTIONS
:
392 case SID_CONFIGSTATUSBAR
:
394 case SID_CONFIGACCEL
:
395 case SID_CONFIGEVENT
:
397 SfxAbstractDialogFactory
* pFact
=
398 SfxAbstractDialogFactory::Create();
400 const SfxStringItem
* pStringItem
= rReq
.GetArg
<SfxStringItem
>(SID_CONFIG
);
403 GetPool(), svl::Items
<SID_CONFIG
, SID_CONFIG
> );
407 aSet
.Put( SfxStringItem(
408 SID_CONFIG
, pStringItem
->GetValue() ) );
411 Reference
<XFrame
> xFrame(GetRequestFrame(rReq
));
412 ScopedVclPtr
<SfxAbstractTabDialog
> pDlg(pFact
->CreateCustomizeTabDialog(rReq
.GetFrameWeld(),
415 const short nRet
= pDlg
->Execute();
425 Reference
< XDesktop2
> xDesktop
= Desktop::create( ::comphelper::getProcessComponentContext() );
426 Reference
< XIndexAccess
> xTasks
= xDesktop
->getFrames();
433 if ( xTasks
->getCount() <= n
)
436 Any aAny
= xTasks
->getByIndex(n
);
437 Reference
< XCloseable
> xTask
;
444 catch( CloseVetoException
& )
450 bool bOk
= ( n
== 0);
451 rReq
.SetReturnValue( SfxBoolItem( 0, bOk
) );
459 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
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() )
473 rReq
.SetReturnValue( SfxBoolItem( 0, bOK
) );
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);
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);
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);
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);
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);
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);
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);
542 case SID_SHOW_LICENSE
:
544 LicenseDialog
aDialog(rReq
.GetFrameWeld());
549 case SID_SHOW_CREDITS
:
551 showDocument( "CREDITS" );
555 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
558 Help
* pHelp
= Application::GetHelp();
561 pHelp
->Start(".uno:HelpIndex", rReq
.GetFrameWeld()); // show start page
567 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
570 // Evaluate Parameter
571 const SfxBoolItem
* pOnItem
= rReq
.GetArg
<SfxBoolItem
>(SID_HELPTIPS
);
573 ? pOnItem
->GetValue()
574 : !Help::IsQuickHelpEnabled();
577 Help::EnableQuickHelp();
579 Help::DisableQuickHelp();
580 auto xChanges
= comphelper::ConfigurationChanges::create();
581 officecfg::Office::Common::Help::Tip::set(bOn
, xChanges
);
583 Invalidate(SID_HELPTIPS
);
586 // Record if possible
588 rReq
.AppendItem( SfxBoolItem( SID_HELPTIPS
, bOn
) );
591 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
592 case SID_EXTENDEDHELP
:
594 Help::StartExtHelp();
597 case SID_HELPBALLOONS
:
599 // Evaluate Parameter
600 const SfxBoolItem
* pOnItem
= rReq
.GetArg
<SfxBoolItem
>(SID_HELPBALLOONS
);
602 ? pOnItem
->GetValue()
603 : !Help::IsBalloonHelpEnabled();
606 Help::EnableBalloonHelp();
608 Help::DisableBalloonHelp();
609 auto xChanges
= comphelper::ConfigurationChanges::create();
610 officecfg::Office::Common::Help::ExtendedTip::set(bOn
, xChanges
);
612 Invalidate(SID_HELPBALLOONS
);
615 // Record if possible
617 rReq
.AppendItem( SfxBoolItem( SID_HELPBALLOONS
, bOn
) );
620 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
621 case SID_TIPOFTHEDAY
:
623 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
624 ScopedVclPtr
<VclAbstractDialog
> pDlg(pFact
->CreateTipOfTheDayDialog(rReq
.GetFrameWeld()));
625 pDlg
->StartExecuteAsync(nullptr);
630 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
633 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
634 ScopedVclPtr
<VclAbstractDialog
> pDlg(pFact
->CreateAboutDialog(rReq
.GetFrameWeld()));
640 case SID_TEMPLATE_MANAGER
:
642 SfxTemplateManagerDlg
aDialog(rReq
.GetFrameWeld());
648 case SID_TEMPLATE_ADDRESSBOOKSOURCE
:
650 svt::AddressBookSourceDialog
aDialog(rReq
.GetFrameWeld(), ::comphelper::getProcessComponentContext());
656 #if HAVE_FEATURE_SCRIPTING
661 case SID_BASICBREAK
:
662 BasicDLL::BasicBreak();
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();
679 // make sure aZoom is initialized with a proper value if SetType
681 SvxZoomItem
aZoom( SvxZoomType::PERCENT
, 100 );
683 switch (rReq
.GetSlot())
685 case SID_ZOOM_50_PERCENT
:
688 case SID_ZOOM_75_PERCENT
:
691 case SID_ZOOM_100_PERCENT
:
694 case SID_ZOOM_150_PERCENT
:
697 case SID_ZOOM_200_PERCENT
:
700 case SID_ZOOM_OPTIMAL
:
701 aZoom
.SetType( SvxZoomType::OPTIMAL
);
703 case SID_ZOOM_ENTIRE_PAGE
:
704 aZoom
.SetType( SvxZoomType::WHOLEPAGE
);
706 case SID_ZOOM_PAGE_WIDTH
:
707 aZoom
.SetType( SvxZoomType::PAGEWIDTH
);
711 pCurrentShell
->GetDispatcher()->ExecuteList(SID_ATTR_ZOOM
, SfxCallMode::ASYNCHRON
, { &aZoom
});
715 case SID_TOOLBAR_MODE
:
717 const SfxStringItem
* pModeName
= rReq
.GetArg
<SfxStringItem
>( SID_TOOLBAR_MODE
);
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();
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(
749 if ( !aAppNode
.isValid() )
755 aCurrentMode
= comphelper::getString( aAppNode
.getNodeValue( "Active" ) );
757 if ( aCurrentMode
== aNewName
)
763 // Save new toolbar mode for a current module
764 aAppNode
.setNodeValue( "Active", makeAny( aNewName
) );
768 // Apply settings for all frames
769 pViewFrame
= SfxViewFrame::GetFirst();
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
);
783 Reference
<css::beans::XPropertySet
> xPropSet( xFrame
, UNO_QUERY
);
784 Reference
<css::frame::XLayoutManager
> xLayoutManager
;
789 Any aValue
= xPropSet
->getPropertyValue( "LayoutManager" );
790 aValue
>>= xLayoutManager
;
792 catch ( const css::uno::RuntimeException
& )
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
) +
812 // Read mode settings
813 const utl::OConfigurationTreeRoot
aModesNode(
817 if ( !aModesNode
.isValid() )
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() )
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" ) );
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() )
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
});
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
);
890 pViewFrame
->ShowChildWindow( SID_SIDEBAR
);
892 if (comphelper::LibreOfficeKit::isActive())
893 aSidebarMode
= "Opened";
895 sfx2::sidebar::SidebarController
* pSidebar
=
896 sfx2::sidebar::SidebarController::GetSidebarControllerForFrame( xFrame
);
899 if ( aSidebarMode
== "Arrow" )
903 else if ( aSidebarMode
== "Tabs" )
906 pSidebar
->RequestOpenDeck();
907 pSidebar
->RequestCloseDeck();
909 else if ( aSidebarMode
== "Opened" )
912 pSidebar
->RequestOpenDeck();
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() )
927 OUString aCommandArg
= comphelper::getString( aModeNode
.getNodeValue( "CommandArg" ) );
929 if ( aCommandArg
== aCurrentMode
)
931 aModeNode
.setNodeValue( "UserToolbars", makeAny( aBackup
) );
939 pViewFrame
= SfxViewFrame::GetNext(*pViewFrame
);
945 case SID_TOOLBAR_MODE_UI
:
947 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
948 ScopedVclPtr
<VclAbstractDialog
> pDlg(
949 pFact
->CreateToolbarmodeDialog(rReq
.GetFrameWeld()));
954 case SID_AVAILABLE_TOOLBARS
:
956 const SfxStringItem
* pToolbarName
= rReq
.GetArg
<SfxStringItem
>(SID_AVAILABLE_TOOLBARS
);
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
;
969 Any aValue
= xPropSet
->getPropertyValue("LayoutManager");
970 aValue
>>= xLayoutManager
;
972 catch ( const css::uno::RuntimeException
& )
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
));
991 xLayoutManager
->createElement( aToolbarName
);
992 xLayoutManager
->showElement( aToolbarName
);
995 xLayoutManager
->hideElement( aToolbarName
);
1004 sfx2::SfxNotebookBar::ToggleMenubar();
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
);
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
);
1029 auto pDockingWin
= dynamic_cast<DevelopmentToolDockingWindow
*>(pChild
->GetWindow());
1032 pDockingWin
->changeToCurrentSelection();
1040 SafeModeQueryDialog
aDialog(rReq
.GetFrameWeld());
1044 case SID_TOOLBAR_LOCK
:
1046 SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
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
));
1062 //TODO: apply immediately w/o restart needed
1063 SolarMutexGuard aGuard
;
1064 svtools::executeRestartDialog(comphelper::getProcessComponentContext(), nullptr,
1065 svtools::RESTART_REASON_UI_CHANGE
);
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
)
1088 case SID_TEMPLATE_ADDRESSBOOKSOURCE
:
1089 if ( !SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::DATABASE
) )
1090 rSet
.Put(SfxVisibilityItem(nWhich
, false));
1094 if ( pImpl
->nDocModalMode
)
1095 rSet
.DisableItem(nWhich
);
1097 rSet
.Put(SfxStringItem(nWhich
, SfxResId(STR_QUITAPP
)));
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
);
1113 #if HAVE_FEATURE_SCRIPTING
1115 if ( !StarBASIC::IsRunning() )
1116 rSet
.DisableItem(nWhich
);
1122 rSet
.Put( SfxBoolItem( SID_HELPTIPS
, Help::IsQuickHelpEnabled() ) );
1125 case SID_HELPBALLOONS
:
1127 rSet
.Put( SfxBoolItem( SID_HELPBALLOONS
, Help::IsBalloonHelpEnabled() ) );
1131 case SID_EXTENDEDHELP
:
1138 Reference
< XDesktop2
> xDesktop
= Desktop::create( ::comphelper::getProcessComponentContext() );
1139 Reference
< XIndexAccess
> xTasks
= xDesktop
->getFrames();
1140 if ( !xTasks
.is() || !xTasks
->getCount() )
1141 rSet
.DisableItem(nWhich
);
1147 bool bModified
= false;
1148 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
1150 pObjSh
= SfxObjectShell::GetNext( *pObjSh
) )
1152 if ( pObjSh
->IsModified() )
1160 rSet
.DisableItem( nWhich
);
1164 case SID_TEMPLATE_MANAGER
:
1166 if ( !officecfg::Office::Common::Misc::ExperimentalMode::get() )
1168 rSet
.DisableItem( nWhich
);
1169 rSet
.Put( SfxVisibilityItem( nWhich
, false ) );
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
);
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
& )
1211 catch ( css::uno::Exception
& )
1216 if ( xLayoutManager
.is() )
1219 = xLayoutManager
->getElement("private:resource/menubar/menubar").is()
1220 && xLayoutManager
->isElementVisible(
1221 "private:resource/menubar/menubar");
1223 SfxBoolItem
aItem( SID_MENUBAR
, bState
);
1230 // no restart in safe mode when already in safe mode
1231 if ( Application::IsSafeModeEnabled() )
1232 rSet
.DisableItem( SID_SAFE_MODE
);
1235 case SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW
:
1237 bool bSuccess
= false;
1238 auto* pViewShell
= SfxViewShell::Current();
1241 auto* pViewFrame
= pViewShell
->GetViewFrame();
1242 if (pViewFrame
&& pViewFrame
->KnowsChildWindow(nWhich
))
1244 rSet
.Put(SfxBoolItem(nWhich
, pViewFrame
->HasChildWindow(nWhich
)));
1250 rSet
.DisableItem(nWhich
);
1253 case SID_INSPECT_SELECTED_OBJECT
:
1255 bool bSuccess
= false;
1256 auto* pViewShell
= SfxViewShell::Current();
1259 auto* pViewFrame
= pViewShell
->GetViewFrame();
1260 if (pViewFrame
&& pViewFrame
->KnowsChildWindow(SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW
))
1266 rSet
.DisableItem(nWhich
);
1269 case SID_TOOLBAR_LOCK
:
1271 rSet
.Put( SfxBoolItem( SID_TOOLBAR_LOCK
, ToolBox::AlwaysLocked() ));
1281 #if HAVE_FEATURE_SCRIPTING
1283 #ifndef DISABLE_DYNLOADING
1285 typedef rtl_uString
* (*basicide_choose_macro
)(void*, void*, void*, sal_Bool
);
1289 extern "C" rtl_uString
* basicide_choose_macro(void*, void*, void*, sal_Bool
);
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"));
1298 #define pSymbol basicide_choose_macro
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
);
1307 #ifdef DISABLE_DYNLOADING
1316 #if HAVE_FEATURE_SCRIPTING
1317 weld::Window
* lcl_getDialogParent(const Reference
<XFrame
>& rxFrame
)
1319 Reference
<awt::XWindow
> xContainerWindow
;
1321 xContainerWindow
= rxFrame
->getContainerWindow();
1322 return Application::GetFrameWeld(xContainerWindow
);
1325 SfxViewFrame
* lcl_getBasicIDEViewFrame( SfxObjectShell
const * i_pBasicIDE
)
1327 SfxViewFrame
* pView
= SfxViewFrame::GetFirst( i_pBasicIDE
);
1330 if ( pView
->GetObjectShell()->GetFactory().GetDocumentServiceName() == "com.sun.star.script.BasicIDE" )
1332 pView
= SfxViewFrame::GetNext( *pView
, i_pBasicIDE
);
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" )
1355 catch( const UnknownModuleException
& )
1359 catch(const Exception
&)
1361 // re-throw, caught below
1366 catch( const Exception
& )
1368 DBG_UNHANDLED_EXCEPTION("sfx.appl");
1372 #endif // HAVE_FEATURE_SCRIPTING
1375 void SfxApplication::OfaExec_Impl( SfxRequest
& rReq
)
1377 switch ( rReq
.GetSlot() )
1379 case SID_OPTIONS_TREEDIALOG
:
1382 const SfxStringItem
* pURLItem
= rReq
.GetArg
<SfxStringItem
>(SID_OPTIONS_PAGEURL
);
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();
1396 SfxObjectShell
* pObjSh
= pView
->GetObjectShell();
1398 pObjSh
->SetConfigOptionsChecked(false);
1400 pView
->GetBindings().InvalidateAll(false);
1401 pView
= SfxViewFrame::GetNext( *pView
);
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
);
1414 #if HAVE_FEATURE_SCRIPTING
1415 case SID_BASICIDE_APPEAR
:
1417 SfxViewFrame
* pView
= lcl_getBasicIDEViewFrame( nullptr );
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
),
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
);
1453 pView
->SetName( "BASIC:1" );
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
);
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();
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
)));
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
);
1520 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1521 SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: case ScriptOrg");
1523 Reference
<XFrame
> xFrame(GetRequestFrame(rReq
));
1526 const SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
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!" );
1537 pDlg
->SetRunLabel();
1539 pDlg
->StartExecuteAsync([pDlg
, xFrame
](sal_Int32 nDialogResult
) {
1540 if ( !nDialogResult
)
1542 pDlg
->disposeOnce();
1546 Sequence
< Any
> args
;
1547 Sequence
< sal_Int16
> outIndex
;
1548 Sequence
< Any
> outArgs
;
1551 Reference
< XInterface
> xScriptContext
;
1553 Reference
< XController
> xController
;
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();
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
;
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
));
1591 SAL_WARN("sfx.appl", "no dialog!!!");
1596 #endif // HAVE_FEATURE_SCRIPTING
1598 case SID_OFFICE_CHECK_PLZ
:
1601 const SfxStringItem
* pStringItem
= rReq
.GetArg
<SfxStringItem
>(rReq
.GetSlot());
1605 bRet
= true /*!!!SfxIniManager::CheckPLZ( aPLZ )*/;
1607 #if HAVE_FEATURE_SCRIPTING
1609 SbxBase::SetError( ERRCODE_BASIC_WRONG_ARGS
);
1611 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bRet
) );
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
)
1625 ScopedVclPtr
<SfxAbstractTabDialog
> pDlg(pFact
->CreateAutoCorrTabDialog(rReq
.GetFrameWeld(), &aSet
));
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
)));
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
) );
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
) );
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);
1687 catch(const css::uno::Exception
&)
1689 DBG_UNHANDLED_EXCEPTION("sfx.appl");
1694 case SID_COMP_BIBLIOGRAPHY
:
1695 lcl_tryLoadBibliography();
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: */