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 <config_wasm_strip.h>
23 #include <com/sun/star/drawing/ModuleDispatcher.hpp>
24 #include <com/sun/star/frame/Desktop.hpp>
25 #include <com/sun/star/frame/DispatchResultEvent.hpp>
26 #include <com/sun/star/frame/DispatchResultState.hpp>
27 #include <com/sun/star/frame/DispatchHelper.hpp>
28 #include <com/sun/star/frame/UnknownModuleException.hpp>
29 #include <com/sun/star/frame/XLayoutManager.hpp>
30 #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
31 #include <com/sun/star/embed/EmbedStates.hpp>
32 #include <com/sun/star/embed/XEmbeddedObject.hpp>
33 #include <com/sun/star/util/XModifiable.hpp>
34 #include <com/sun/star/sdbc/DriverManager.hpp>
35 #include <com/sun/star/text/ModuleDispatcher.hpp>
36 #include <com/sun/star/task/OfficeRestartManager.hpp>
37 #include <com/sun/star/task/XInteractionHandler.hpp>
38 #include <com/sun/star/ui/dialogs/AddressBookSourcePilot.hpp>
39 #include <com/sun/star/ui/UIElementType.hpp>
40 #include <com/sun/star/ui/XUIElement.hpp>
41 #include <com/sun/star/uno/Reference.hxx>
42 #include <com/sun/star/util/XCloseable.hpp>
43 #include <com/sun/star/util/CloseVetoException.hpp>
44 #include <org/freedesktop/PackageKit/SyncDbusSessionHelper.hpp>
46 #include <comphelper/dispatchcommand.hxx>
47 #include <comphelper/lok.hxx>
48 #include <comphelper/namedvaluecollection.hxx>
49 #include <comphelper/processfactory.hxx>
50 #include <comphelper/propertysequence.hxx>
51 #include <comphelper/propertyvalue.hxx>
52 #include <comphelper/sequence.hxx>
54 #include <svtools/addresstemplate.hxx>
55 #include <svtools/restartdialog.hxx>
56 #include <svtools/colorcfg.hxx>
57 #include <svl/visitem.hxx>
59 #include <unotools/configmgr.hxx>
60 #include <comphelper/diagnose_ex.hxx>
61 #include <vcl/weld.hxx>
62 #include <svl/intitem.hxx>
63 #include <svl/eitem.hxx>
64 #include <svl/stritem.hxx>
65 #include <basic/sbstar.hxx>
66 #include <basic/basrdll.hxx>
67 #include <basic/sberrors.hxx>
68 #include <vcl/help.hxx>
69 #include <sal/log.hxx>
70 #include <osl/file.hxx>
71 #include <vcl/EnumContext.hxx>
72 #include <vcl/toolbox.hxx>
74 #include <unotools/moduleoptions.hxx>
75 #include <unotools/securityoptions.hxx>
76 #include <rtl/bootstrap.hxx>
78 #include <com/sun/star/frame/ModuleManager.hpp>
79 #include <com/sun/star/beans/XPropertySet.hpp>
81 #include <sfx2/app.hxx>
82 #include <sfx2/request.hxx>
83 #include <sfx2/dispatch.hxx>
84 #include <sfx2/bindings.hxx>
85 #include <sfx2/minfitem.hxx>
86 #include <sfx2/msg.hxx>
87 #include <sfx2/objface.hxx>
88 #include <sfx2/objsh.hxx>
89 #include <sfx2/viewsh.hxx>
90 #include <sfx2/docfac.hxx>
91 #include <sfx2/strings.hrc>
92 #include <sfx2/sfxresid.hxx>
93 #include <appdata.hxx>
94 #include <sfx2/viewfrm.hxx>
95 #include <sfx2/sfxdlg.hxx>
96 #include <sfx2/sfxsids.hrc>
97 #include <sorgitm.hxx>
98 #include <sfx2/sfxhelp.hxx>
99 #include <sfx2/zoomitem.hxx>
100 #include <sfx2/templatedlg.hxx>
101 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
102 #include <sfx2/sidebar/SidebarController.hxx>
103 #include <sfx2/safemode.hxx>
104 #include <sfx2/sfxuno.hxx>
105 #include <DevelopmentToolDockingWindow.hxx>
107 #include <comphelper/types.hxx>
108 #include <officecfg/Office/Common.hxx>
109 #include <officecfg/Setup.hxx>
110 #include <unotools/confignode.hxx>
113 #include <openuriexternally.hxx>
115 #include "getbasctlfunction.hxx"
117 using namespace ::com::sun::star
;
118 using namespace ::com::sun::star::beans
;
119 using namespace ::com::sun::star::uno
;
120 using namespace ::com::sun::star::frame
;
121 using namespace ::com::sun::star::container
;
122 using namespace ::com::sun::star::util
;
123 using namespace ::com::sun::star::lang
;
124 using namespace ::com::sun::star::ui
;
128 OUString
lcl_getAppName( vcl::EnumContext::Application eApp
)
132 case vcl::EnumContext::Application::Writer
:
133 return u
"Writer"_ustr
;
134 case vcl::EnumContext::Application::Calc
:
136 case vcl::EnumContext::Application::Impress
:
137 return u
"Impress"_ustr
;
138 case vcl::EnumContext::Application::Draw
:
140 case vcl::EnumContext::Application::Formula
:
141 return u
"Formula"_ustr
;
142 case vcl::EnumContext::Application::Base
:
149 // lp#527938, debian#602953, fdo#33266, i#105408
150 bool lcl_isBaseAvailable()
154 // if we get css::sdbc::DriverManager, libsdbc2 is there
155 // and the bibliography is assumed to work
156 return css::sdbc::DriverManager::create(comphelper::getProcessComponentContext()).is();
158 catch (const Exception
&)
160 TOOLS_INFO_EXCEPTION("sfx.appl", "assuming Base to be missing");
164 void lcl_tryLoadBibliography()
166 // lp#527938, debian#602953, fdo#33266, i#105408
167 // make sure we actually can instantiate services from base first
168 if(!lcl_isBaseAvailable())
170 if (officecfg::Office::Common::PackageKit::EnableBaseInstallation::get())
174 using namespace org::freedesktop::PackageKit
;
175 using namespace svtools
;
176 Reference
< XSyncDbusSessionHelper
> xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext()));
177 Sequence
< OUString
> vPackages
{ u
"libreoffice-base"_ustr
};
178 xSyncDbusSessionHelper
->InstallPackageNames(vPackages
, OUString());
179 // I'll be back (hopefully)!
180 SolarMutexGuard aGuard
;
181 executeRestartDialog(comphelper::getProcessComponentContext(), nullptr, RESTART_REASON_BIBLIOGRAPHY_INSTALL
);
183 catch (const Exception
&)
185 TOOLS_INFO_EXCEPTION("sfx.appl", "trying to install LibreOffice Base");
193 SfxStringItem
aURL(SID_FILE_NAME
, u
".component:Bibliography/View1"_ustr
);
194 SfxStringItem
aRef(SID_REFERER
, u
"private:user"_ustr
);
195 SfxStringItem
aTarget(SID_TARGETNAME
, u
"_blank"_ustr
);
196 if (const SfxViewFrame
* pViewFrame
= SfxViewFrame::Current())
198 pViewFrame
->GetDispatcher()->ExecuteList(SID_OPENDOC
,
199 SfxCallMode::ASYNCHRON
, { &aURL
, &aRef
, &aTarget
});
202 catch (const Exception
&)
204 TOOLS_INFO_EXCEPTION( "sfx.appl", "trying to load bibliography database");
207 void lcl_disableActiveEmbeddedObjects(SfxObjectShell
* pObjSh
)
212 comphelper::EmbeddedObjectContainer
& rContainer
= pObjSh
->getEmbeddedObjectContainer();
213 if (!rContainer
.HasEmbeddedObjects())
216 const uno::Sequence
<OUString
> aNames
= rContainer
.GetObjectNames();
217 for (const auto& rName
: aNames
)
219 uno::Reference
<embed::XEmbeddedObject
> xEmbeddedObj
220 = rContainer
.GetEmbeddedObject(rName
);
221 if (!xEmbeddedObj
.is())
226 if (xEmbeddedObj
->getCurrentState() != embed::EmbedStates::LOADED
)
228 xEmbeddedObj
->changeState(embed::EmbedStates::LOADED
);
231 catch (const uno::Exception
&)
237 /// Find the correct location of the document (CREDITS.fodt, etc.), and return
238 /// it in rURL if found.
239 static bool checkURL( const char *pName
, const char *pExt
, OUString
&rURL
)
242 DirectoryItem aDirItem
;
245 rURL
= "$BRAND_BASE_DIR/Resources/" + OUString::createFromAscii( pName
) +
246 OUString::createFromAscii( pExt
);
248 rURL
= "$BRAND_BASE_DIR/" + OUString::createFromAscii( pName
) +
249 OUString::createFromAscii( pExt
);
251 rtl::Bootstrap::expandMacros( rURL
);
254 return DirectoryItem::get( rURL
, aDirItem
) == DirectoryItem::E_None
;
259 /// Displays CREDITS or LICENSE in any of the available version
260 static void showDocument( const char* pBaseName
)
263 Reference
< XDesktop2
> xDesktop
= Desktop::create( ::comphelper::getProcessComponentContext() );
264 auto args(::comphelper::InitPropertySequence({
265 {"ViewOnly", Any(true)},
266 {"ReadOnly", Any(true)}
270 if ( checkURL ( pBaseName
, ".fodt", aURL
) ||
271 checkURL ( pBaseName
, ".html", aURL
) ||
272 checkURL ( pBaseName
, "", aURL
) ) {
273 xDesktop
->loadComponentFromURL( aURL
, u
"_blank"_ustr
, 0, args
);
275 } catch (const css::uno::Exception
&) {
281 Reference
<XFrame
> GetRequestFrame(const SfxRequest
& rReq
)
283 const SfxItemSet
* pArgs
= rReq
.GetInternalArgs_Impl();
284 const SfxUnoFrameItem
* pItem
= nullptr;
285 Reference
<XFrame
> xFrame
;
286 if (pArgs
&& (pItem
= pArgs
->GetItemIfSet(SID_FILLFRAME
, false)))
288 xFrame
= pItem
->GetFrame();
293 Reference
<XFrame
> GetDocFrame(const SfxRequest
& rReq
)
295 const SfxFrameItem
* pFrameItem
= rReq
.GetArg
<SfxFrameItem
>(SID_DOCFRAME
);
296 SfxFrame
* pFrame
= pFrameItem
? pFrameItem
->GetFrame() : nullptr;
297 return pFrame
? pFrame
->GetFrameInterface() : nullptr;
300 class LicenseDialog
: public weld::GenericDialogController
303 LicenseDialog(weld::Window
* pParent
)
304 : GenericDialogController(pParent
, u
"sfx/ui/licensedialog.ui"_ustr
, u
"LicenseDialog"_ustr
)
308 virtual short run() override
310 short nRet
= GenericDialogController::run();
312 showDocument("LICENSE");
317 class SafeModeQueryDialog
: public weld::MessageDialogController
320 SafeModeQueryDialog(weld::Window
* pParent
)
321 : MessageDialogController(pParent
, u
"sfx/ui/safemodequerydialog.ui"_ustr
, u
"SafeModeQueryDialog"_ustr
)
325 virtual short run() override
327 short nRet
= MessageDialogController::run();
330 sfx2::SafeMode::putFlag();
331 const uno::Reference
< uno::XComponentContext
>& xContext
= comphelper::getProcessComponentContext();
332 css::task::OfficeRestartManager::get(xContext
)->requestRestart(
333 css::uno::Reference
< css::task::XInteractionHandler
>());
340 weld::Window
* SfxRequest::GetFrameWeld() const
342 const SfxItemSet
* pIntArgs
= GetInternalArgs_Impl();
343 const SfxUnoAnyItem
* pItem
= nullptr;
344 if (pIntArgs
&& (pItem
= pIntArgs
->GetItemIfSet(SID_DIALOG_PARENT
, false)))
346 Reference
<awt::XWindow
> xWindow
;
347 pItem
->GetValue() >>= xWindow
;
348 return Application::GetFrameWeld(xWindow
);
351 Reference
<XFrame
> xFrame(GetRequestFrame(*this));
353 xFrame
= GetDocFrame(*this);
356 SAL_WARN("sfx.appl", "no parent for dialogs");
359 return Application::GetFrameWeld(xFrame
->getContainerWindow());
362 void SfxApplication::MiscExec_Impl( SfxRequest
& rReq
)
365 switch ( rReq
.GetSlot() )
370 SetOptions( *rReq
.GetArgs() );
377 // protect against reentrant calls and avoid closing the same files in parallel
378 if (pImpl
->bInQuit
|| pImpl
->bClosingDocs
)
381 if ( rReq
.GetSlot() == SID_LOGOUT
)
383 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
384 pObjSh
; pObjSh
= SfxObjectShell::GetNext( *pObjSh
) )
386 if ( !pObjSh
->IsModified() )
389 SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( pObjSh
);
390 if ( !pFrame
|| !pFrame
->GetWindow().IsReallyVisible() )
393 if (pObjSh
->PrepareClose())
394 pObjSh
->SetModified( false );
399 SfxStringItem
aNameItem( SID_FILE_NAME
, u
"vnd.sun.star.cmd:logout"_ustr
);
400 SfxStringItem
aReferer( SID_REFERER
, u
"private/user"_ustr
);
401 pImpl
->pAppDispat
->ExecuteList(SID_OPENDOC
,
402 SfxCallMode::SLOT
, { &aNameItem
, &aReferer
});
406 // try from nested requests again after 100ms
407 if( Application::GetDispatchLevel() > 1 )
409 /* Don't save the request for closing the application and try it later
410 again. This is an UI bound functionality ... and the user will try it again
411 if the dialog is closed. But we should not close the application automatically
412 if this dialog is closed by the user ...
413 So we ignore this request now and wait for a new user decision.
415 SAL_INFO("sfx.appl", "QueryExit => sal_False, DispatchLevel == " << Application::GetDispatchLevel() );
419 // block reentrant calls
420 pImpl
->bInQuit
= true;
421 Reference
< XDesktop2
> xDesktop
= Desktop::create ( ::comphelper::getProcessComponentContext() );
423 rReq
.ForgetAllArgs();
425 // if terminate() failed, pImpl->bInQuit will now be sal_False, allowing further calls of SID_QUITAPP
426 bool bTerminated
= xDesktop
->terminate();
428 // if terminate() was successful, SfxApplication is now dead!
429 pImpl
->bInQuit
= false;
431 // Set return value, terminate if possible
432 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bTerminated
) );
437 case SID_TOOLBOXOPTIONS
:
438 case SID_CONFIGSTATUSBAR
:
440 case SID_CONFIGACCEL
:
441 case SID_CONFIGEVENT
:
443 SfxAbstractDialogFactory
* pFact
=
444 SfxAbstractDialogFactory::Create();
446 const SfxStringItem
* pStringItem
= rReq
.GetArg
<SfxStringItem
>(SID_CONFIG
);
448 SfxItemSetFixed
<SID_CONFIG
, SID_CONFIG
, SID_MACROINFO
, SID_MACROINFO
> aSet( GetPool() );
450 // SID_CONFIG property will determine the default page shown
453 aSet
.Put( SfxStringItem(
454 SID_CONFIG
, pStringItem
->GetValue() ) );
456 else if (rReq
.GetSlot() == SID_CONFIGEVENT
)
458 aSet
.Put( SfxStringItem(
459 SID_CONFIG
, u
"private:resource/event/"_ustr
) );
461 else if (rReq
.GetSlot() == SID_TOOLBOXOPTIONS
)
463 aSet
.Put( SfxStringItem(
464 SID_CONFIG
, u
"private:resource/toolbar/"_ustr
) );
467 #if HAVE_FEATURE_SCRIPTING
468 // Preselect a macro in the 'keyboard' page
469 if (auto const item
= rReq
.GetArg
<SfxMacroInfoItem
>(SID_MACROINFO
)) {
474 Reference
<XFrame
> xFrame(GetRequestFrame(rReq
));
475 ScopedVclPtr
<SfxAbstractTabDialog
> pDlg(pFact
->CreateCustomizeTabDialog(rReq
.GetFrameWeld(),
478 const short nRet
= pDlg
->Execute();
487 // protect against reentrant calls and avoid closing the same files in parallel
488 if (pImpl
->bInQuit
|| pImpl
->bClosingDocs
)
491 pImpl
->bClosingDocs
= true;
492 // closed all status for all visible frames
493 bool bClosedAll
= true;
495 // Iterate over all documents and close them
496 for (SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst(); pObjSh
;)
498 SfxObjectShell
* pNxtObjSh
= SfxObjectShell::GetNext(*pObjSh
);
499 // can close immediately
500 if (!pObjSh
->IsModified())
502 // don't close the last remaining frame for close dispatch
503 if (pNxtObjSh
|| !bClosedAll
)
508 // skip invisible frames when asking user to close
509 SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst(pObjSh
);
510 if (pFrame
&& pFrame
->GetWindow().IsReallyVisible())
512 // asks user to close
513 if (pObjSh
->PrepareClose())
515 pObjSh
->SetModified(false);
516 // get next pointer again after asking user since it can become invalid pointer from being manually closed by user
517 // don't close the last remaining frame for close dispatch
518 if ((pNxtObjSh
= SfxObjectShell::GetNext(*pObjSh
)) || !bClosedAll
)
521 // user disagrees to close
525 // get next pointer again after asking user since it can become invalid pointer from being manually closed by user
526 pNxtObjSh
= SfxObjectShell::GetNext(*pObjSh
);
533 pImpl
->bClosingDocs
= false;
535 // close dispatch status
536 bool bDispatchOk
= true;
537 // open backing window
540 // don't use pViewFrame = SfxViewFrame::Current() as dispatch won't load sometimes
541 SfxObjectShell
* pObjSh
= SfxObjectShell::GetFirst();
542 SfxViewFrame
* pViewFrame
= SfxViewFrame::GetFirst(pObjSh
);
545 Reference
<XFrame
> xCurrentFrame
= pViewFrame
->GetFrame().GetFrameInterface();
546 if (xCurrentFrame
.is())
548 uno::Reference
<frame::XDispatchProvider
> xProvider(xCurrentFrame
, uno::UNO_QUERY
);
551 uno::Reference
<frame::XDispatchHelper
> xDispatcher
552 = frame::DispatchHelper::create(::comphelper::getProcessComponentContext());
553 // use .uno:CloseDoc to be able to close windows of the same document
554 css::uno::Any aResult
=
555 xDispatcher
->executeDispatch(xProvider
,
556 u
".uno:CloseDoc"_ustr
,
559 uno::Sequence
<beans::PropertyValue
>());
560 css::frame::DispatchResultEvent aEvent
;
561 bDispatchOk
= (aResult
>>= aEvent
) && (aEvent
.State
== frame::DispatchResultState::SUCCESS
);
566 // terminate the application if the dispatch fails or
567 // if there is no visible frame left after the command is run (e.g user manually closes the document again that was already cancelled for closing)
568 if (!bDispatchOk
|| (!bClosedAll
&& !SfxObjectShell::GetFirst()))
570 SfxRequest
aReq(SID_QUITAPP
, SfxCallMode::SLOT
, GetPool());
574 rReq
.SetReturnValue(SfxBoolItem(0, bDispatchOk
));
582 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
584 pObjSh
= SfxObjectShell::GetNext( *pObjSh
) )
586 SfxRequest
aReq( SID_SAVEDOC
, SfxCallMode::SLOT
, pObjSh
->GetPool() );
587 if ( pObjSh
->IsModified() && !pObjSh
->isSaveLocked() )
589 pObjSh
->ExecuteSlot( aReq
);
590 const SfxBoolItem
* pItem(dynamic_cast<const SfxBoolItem
*>(aReq
.GetReturnValue().getItem()));
591 if ( !pItem
|| !pItem
->GetValue() )
596 rReq
.SetReturnValue( SfxBoolItem( 0, bOK
) );
601 case SID_SEND_FEEDBACK
:
603 OUString module
= SfxHelp::GetCurrentModuleIdentifier();
604 OUString
sURL(officecfg::Office::Common::Menus::SendFeedbackURL::get() + //officecfg/registry/data/org/openoffice/Office/Common.xcu => https://hub.libreoffice.org/send-feedback/
605 "?LOversion=" + utl::ConfigManager::getAboutBoxProductVersion() +
606 "&LOlocale=" + utl::ConfigManager::getUILocale() +
607 "&LOmodule=" + module
.subView(module
.lastIndexOf('.') + 1 ) );
608 sfx2::openUriExternally(sURL
, false, rReq
.GetFrameWeld());
614 // Askbot has URL's normalized to languages, not locales
615 // Get language from locale: ll or lll or ll-CC or lll-CC
617 OUString
sURL(officecfg::Office::Common::Menus::QA_URL::get() + //https://hub.libreoffice.org/forum/
618 "?LOlocale=" + utl::ConfigManager::getUILocale());
619 sfx2::openUriExternally(sURL
, false, rReq
.GetFrameWeld());
622 case SID_DOCUMENTATION
:
624 // Open documentation page based on locales
625 OUString
sURL(officecfg::Office::Common::Menus::DocumentationURL::get() + //https://hub.libreoffice.org/documentation/
626 "?LOlocale=" + utl::ConfigManager::getUILocale());
627 sfx2::openUriExternally(sURL
, false, rReq
.GetFrameWeld());
630 #if !ENABLE_WASM_STRIP_PINGUSER
631 case SID_GETINVOLVED
:
633 // Open get involved/join us page based on locales
634 OUString
sURL(officecfg::Office::Common::Menus::GetInvolvedURL::get() + //https://hub.libreoffice.org/joinus/
635 "?LOlocale=" + utl::ConfigManager::getUILocale());
636 sfx2::openUriExternally(sURL
, false, rReq
.GetFrameWeld());
641 // Open donation page based on language + script (BCP47) with language as fall back.
642 OUString aLang
= LanguageTag(utl::ConfigManager::getUILocale()).getLanguage();
643 OUString aBcp47
= LanguageTag(utl::ConfigManager::getUILocale()).getBcp47();
644 OUString
sURL(officecfg::Office::Common::Menus::DonationURL::get() + //https://hub.libreoffice.org/donation/
645 "?BCP47=" + aBcp47
+ "&LOlang=" + aLang
);
646 sfx2::openUriExternally(sURL
, false, rReq
.GetFrameWeld());
651 // Open release notes depending on version and locale
652 OUString
sURL(officecfg::Office::Common::Menus::ReleaseNotesURL::get() + //https://hub.libreoffice.org/ReleaseNotes/
653 "?LOvers=" + utl::ConfigManager::getProductVersion() +
654 "&LOlocale=" + LanguageTag(utl::ConfigManager::getUILocale()).getBcp47() );
655 sfx2::openUriExternally(sURL
, false, rReq
.GetFrameWeld());
658 case SID_HYPHENATIONMISSING
:
660 // Open wiki page about hyphenation
661 OUString
sURL(officecfg::Office::Common::Menus::HyphenationMissingURL::get() + //https://hub.libreoffice.org/HyphenationMissing/
662 "?LOlocale=" + utl::ConfigManager::getUILocale());
663 sfx2::openUriExternally(sURL
, false, rReq
.GetFrameWeld());
667 case SID_SHOW_LICENSE
:
669 LicenseDialog
aDialog(rReq
.GetFrameWeld());
674 case SID_SHOW_CREDITS
:
676 showDocument( "CREDITS" );
680 case FN_CHANGE_THEME
:
682 const SfxStringItem
* pNewThemeArg
= rReq
.GetArg
<SfxStringItem
>(FN_PARAM_NEW_THEME
);
684 = pNewThemeArg
? pNewThemeArg
->GetValue() : u
"COLOR_SCHEME_LIBREOFFICE_AUTOMATIC"_ustr
;
687 // toggle between light and dark mode
689 // There are two separate things that can be dark mode themed: UI and document
690 // The modes can be 0 (automatic - what the OS/VCL asks for), 1 (light), or 2 (dark)
692 // Since only gtk/osx/win support UI theme, toggle based on document colors
693 // Automatic in this case means "whatever GetUseDarkMode() says"
694 const bool bWasInDarkMode
695 = MiscSettings::GetAppColorMode() == 2
696 || (MiscSettings::GetAppColorMode() == 0 && MiscSettings::GetUseDarkMode());
698 // Set the UI theme. It would be nicest to use automatic whenever possible
699 sal_Int32 nUseMode
= 0; // automatic
700 if (MiscSettings::GetDarkMode() != 0)
701 MiscSettings::SetDarkMode(nUseMode
);
703 if (MiscSettings::GetUseDarkMode() == bWasInDarkMode
)
705 // automatic didn't toggle, so force the desired theme
706 nUseMode
= bWasInDarkMode
? 1 : 2;
707 MiscSettings::SetDarkMode(nUseMode
);
710 // Now set the document theme
711 // If the UI can be themed, then the document theme can always remain on automatic.
713 // NOTE: since SetDarkMode has run, GetUseDarkMode might return a different result.
714 if (MiscSettings::GetUseDarkMode() == bWasInDarkMode
)
716 nUseMode
= bWasInDarkMode
? 1 : 2;
717 sSchemeName
= bWasInDarkMode
? u
"Light" : u
"Dark";
719 MiscSettings::SetAppColorMode(nUseMode
);
721 svtools::EditableColorConfig aEditableConfig
;
722 // kit explicitly ignores changes to the global color scheme, except for the current ViewShell,
723 // so an attempted change to the same global color scheme when the now current ViewShell ignored
724 // the last change requires re-sending the change. In which case individual shells will have to
725 // decide if this color-scheme change is a change from their perspective to avoid unnecessary
727 if (!pNewThemeArg
|| comphelper::LibreOfficeKit::isActive()
728 || aEditableConfig
.GetCurrentSchemeName() != sSchemeName
)
730 aEditableConfig
.LoadScheme(sSchemeName
);
733 Invalidate(FN_CHANGE_THEME
);
736 case FN_INVERT_BACKGROUND
:
738 const SfxStringItem
* pNewThemeArg
= rReq
.GetArg
<SfxStringItem
>(FN_PARAM_NEW_THEME
);
740 svtools::EditableColorConfig aColorConfig
;
741 ::Color aDefLightColor
= svtools::ColorConfig::GetDefaultColor(svtools::DOCCOLOR
, 0);
742 ::Color aDefDarkColor
= svtools::ColorConfig::GetDefaultColor(svtools::DOCCOLOR
, 1);
746 ::Color aCurrentColor
= aColorConfig
.GetColorValue(svtools::DOCCOLOR
).nColor
;
748 if (aCurrentColor
== aDefLightColor
) {
749 aNewTheme
= OUString("Dark");
751 aNewTheme
= OUString("Light");
754 aNewTheme
= pNewThemeArg
->GetValue();
757 svtools::ColorConfigValue aValue
;
759 if(aNewTheme
== "Dark")
760 aValue
.nColor
= aDefDarkColor
;
762 aValue
.nColor
= aDefLightColor
;
764 aColorConfig
.SetColorValue(svtools::DOCCOLOR
, aValue
);
767 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
770 Help
* pHelp
= Application::GetHelp();
773 pHelp
->Start(u
".uno:HelpIndex"_ustr
, rReq
.GetFrameWeld()); // show start page
779 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
782 // Evaluate Parameter
783 const SfxBoolItem
* pOnItem
= rReq
.GetArg
<SfxBoolItem
>(SID_HELPTIPS
);
785 ? pOnItem
->GetValue()
786 : !Help::IsQuickHelpEnabled();
789 Help::EnableQuickHelp();
791 Help::DisableQuickHelp();
792 auto xChanges
= comphelper::ConfigurationChanges::create();
793 officecfg::Office::Common::Help::Tip::set(bOn
, xChanges
);
795 Invalidate(SID_HELPTIPS
);
798 // Record if possible
800 rReq
.AppendItem( SfxBoolItem( SID_HELPTIPS
, bOn
) );
803 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
804 case SID_EXTENDEDHELP
:
806 Help::StartExtHelp();
809 case SID_HELPBALLOONS
:
811 // Evaluate Parameter
812 const SfxBoolItem
* pOnItem
= rReq
.GetArg
<SfxBoolItem
>(SID_HELPBALLOONS
);
814 ? pOnItem
->GetValue()
815 : !Help::IsBalloonHelpEnabled();
818 Help::EnableBalloonHelp();
820 Help::DisableBalloonHelp();
821 auto xChanges
= comphelper::ConfigurationChanges::create();
822 officecfg::Office::Common::Help::ExtendedTip::set(bOn
, xChanges
);
824 Invalidate(SID_HELPBALLOONS
);
827 // Record if possible
829 rReq
.AppendItem( SfxBoolItem( SID_HELPBALLOONS
, bOn
) );
832 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
833 #if !ENABLE_WASM_STRIP_PINGUSER
834 case SID_TIPOFTHEDAY
:
836 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
837 ScopedVclPtr
<VclAbstractDialog
> pDlg(pFact
->CreateTipOfTheDayDialog(rReq
.GetFrameWeld()));
838 pDlg
->StartExecuteAsync(nullptr);
843 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
844 case SID_WIDGET_TEST_DIALOG
:
846 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
847 VclPtr
<VclAbstractDialog
> pDlg(pFact
->CreateWidgetTestDialog(rReq
.GetFrameWeld()));
848 pDlg
->StartExecuteAsync([pDlg
](sal_Int32
/*nResult*/){
855 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
858 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
859 ScopedVclPtr
<VclAbstractDialog
> pDlg(pFact
->CreateAboutDialog(rReq
.GetFrameWeld()));
860 pDlg
->StartExecuteAsync(nullptr);
865 case SID_TEMPLATE_MANAGER
:
867 SfxTemplateManagerDlg
aDialog(rReq
.GetFrameWeld());
873 case SID_TEMPLATE_ADDRESSBOOKSOURCE
:
875 svt::AddressBookSourceDialog
aDialog(rReq
.GetFrameWeld(), ::comphelper::getProcessComponentContext());
881 #if HAVE_FEATURE_SCRIPTING
886 case SID_BASICBREAK
:
887 BasicDLL::BasicBreak();
891 case SID_ZOOM_50_PERCENT
:
892 case SID_ZOOM_75_PERCENT
:
893 case SID_ZOOM_100_PERCENT
:
894 case SID_ZOOM_150_PERCENT
:
895 case SID_ZOOM_200_PERCENT
:
896 case SID_ZOOM_OPTIMAL
:
897 case SID_ZOOM_ENTIRE_PAGE
:
898 case SID_ZOOM_PAGE_WIDTH
:
900 SfxObjectShell
* pCurrentShell
= SfxObjectShell::Current();
904 // make sure aZoom is initialized with a proper value if SetType
906 SvxZoomItem
aZoom( SvxZoomType::PERCENT
, 100 );
908 switch (rReq
.GetSlot())
910 case SID_ZOOM_50_PERCENT
:
913 case SID_ZOOM_75_PERCENT
:
916 case SID_ZOOM_100_PERCENT
:
919 case SID_ZOOM_150_PERCENT
:
922 case SID_ZOOM_200_PERCENT
:
925 case SID_ZOOM_OPTIMAL
:
926 aZoom
.SetType( SvxZoomType::OPTIMAL
);
928 case SID_ZOOM_ENTIRE_PAGE
:
929 aZoom
.SetType( SvxZoomType::WHOLEPAGE
);
931 case SID_ZOOM_PAGE_WIDTH
:
932 aZoom
.SetType( SvxZoomType::PAGEWIDTH
);
936 pCurrentShell
->GetDispatcher()->ExecuteList(SID_ATTR_ZOOM
, SfxCallMode::ASYNCHRON
, { &aZoom
});
940 case SID_TOOLBAR_MODE
:
942 const SfxStringItem
* pModeName
= rReq
.GetArg
<SfxStringItem
>( SID_TOOLBAR_MODE
);
950 OUString
aNewName(pModeName
->GetValue());
951 const uno::Reference
< uno::XComponentContext
>& xContext
=
952 ::comphelper::getProcessComponentContext();
954 // Get information about current frame and module
955 Reference
<XFrame
> xCurrentFrame
;
956 vcl::EnumContext::Application eCurrentApp
= vcl::EnumContext::Application::NONE
;
957 OUString aCurrentMode
;
959 SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
962 xCurrentFrame
= pViewFrame
->GetFrame().GetFrameInterface();
964 const Reference
<frame::XModuleManager
> xModuleManager
= frame::ModuleManager::create( xContext
);
965 eCurrentApp
= vcl::EnumContext::GetApplicationEnum( xModuleManager
->identify( xCurrentFrame
) );
967 OUString aPath
= "org.openoffice.Office.UI.ToolbarMode/Applications/" +
968 lcl_getAppName( eCurrentApp
);
970 const utl::OConfigurationTreeRoot
aAppNode(
974 if ( !aAppNode
.isValid() )
980 aCurrentMode
= comphelper::getString( aAppNode
.getNodeValue( u
"Active"_ustr
) );
982 if ( !comphelper::LibreOfficeKit::isActive() && aCurrentMode
== aNewName
)
988 // Save new toolbar mode for a current module
989 aAppNode
.setNodeValue( u
"Active"_ustr
, Any( aNewName
) );
993 // Apply settings for all frames
994 pViewFrame
= SfxViewFrame::GetFirst();
997 // in LOK case we want to apply changes only to the current view
998 if (comphelper::LibreOfficeKit::isActive() &&
999 pViewFrame
!= &SfxViewShell::Current()->GetViewFrame())
1001 pViewFrame
= SfxViewFrame::GetNext( *pViewFrame
);
1005 Reference
<XFrame
> xFrame
= pViewFrame
->GetFrame().GetFrameInterface();
1007 // We want to change mode only for a current app module, ignore other apps
1008 const Reference
<frame::XModuleManager
> xModuleManager
= frame::ModuleManager::create( xContext
);
1009 vcl::EnumContext::Application eApp
= vcl::EnumContext::GetApplicationEnum( xModuleManager
->identify( xFrame
) );
1010 if ( eApp
!= eCurrentApp
)
1012 pViewFrame
= SfxViewFrame::GetNext( *pViewFrame
);
1016 Reference
<css::beans::XPropertySet
> xPropSet( xFrame
, UNO_QUERY
);
1017 Reference
<css::frame::XLayoutManager
> xLayoutManager
;
1018 if ( xPropSet
.is() )
1022 Any aValue
= xPropSet
->getPropertyValue( u
"LayoutManager"_ustr
);
1023 aValue
>>= xLayoutManager
;
1025 catch ( const css::uno::RuntimeException
& )
1029 catch ( css::uno::Exception
& )
1034 if ( xLayoutManager
.is() )
1036 css::uno::Sequence
<OUString
> aMandatoryToolbars
;
1037 css::uno::Sequence
<OUString
> aUserToolbars
;
1038 std::vector
<OUString
> aBackupList
;
1039 OUString aSidebarMode
;
1041 OUString aPath
= "org.openoffice.Office.UI.ToolbarMode/Applications/" +
1042 lcl_getAppName( eApp
) +
1045 // Read mode settings
1046 const utl::OConfigurationTreeRoot
aModesNode(
1050 if ( !aModesNode
.isValid() )
1056 const Sequence
<OUString
> aModeNodeNames( aModesNode
.getNodeNames() );
1058 for ( const auto& rModeNodeName
: aModeNodeNames
)
1060 const utl::OConfigurationNode
aModeNode( aModesNode
.openNode( rModeNodeName
) );
1061 if ( !aModeNode
.isValid() )
1064 OUString aCommandArg
= comphelper::getString( aModeNode
.getNodeValue( u
"CommandArg"_ustr
) );
1066 if ( aCommandArg
== aNewName
)
1068 aMandatoryToolbars
= aModeNode
.getNodeValue( u
"Toolbars"_ustr
).get
< uno::Sequence
<OUString
> >();
1069 aUserToolbars
= aModeNode
.getNodeValue( u
"UserToolbars"_ustr
).get
< uno::Sequence
<OUString
> >();
1070 aSidebarMode
= comphelper::getString( aModeNode
.getNodeValue( u
"Sidebar"_ustr
) );
1075 // Backup visible toolbar list and hide all toolbars
1076 const Sequence
<Reference
<XUIElement
>> aUIElements
= xLayoutManager
->getElements();
1077 for ( const Reference
< XUIElement
>& xUIElement
: aUIElements
)
1079 Reference
< XPropertySet
> xPropertySet( xUIElement
, UNO_QUERY
);
1080 if ( xPropertySet
.is() && xUIElement
.is() )
1085 sal_Int16
nType( -1 );
1086 xPropertySet
->getPropertyValue( u
"Type"_ustr
) >>= nType
;
1087 xPropertySet
->getPropertyValue( u
"ResourceURL"_ustr
) >>= aResName
;
1089 if (( nType
== css::ui::UIElementType::TOOLBAR
) &&
1090 !aResName
.isEmpty() )
1092 if ( xLayoutManager
->isElementVisible( aResName
) )
1094 aBackupList
.push_back( aResName
);
1096 xLayoutManager
->hideElement( aResName
);
1099 catch ( const Exception
& )
1105 // Show/Hide the Notebookbar
1106 const SfxStringItem
pItem(SID_NOTEBOOKBAR
, aNewName
);
1107 pViewFrame
->GetDispatcher()->ExecuteList(SID_NOTEBOOKBAR
, SfxCallMode::SYNCHRON
, {&pItem
});
1108 SfxPoolItemHolder aNbItem
;
1109 pViewFrame
->GetDispatcher()->QueryState(SID_NOTEBOOKBAR
, aNbItem
);
1112 for (const OUString
& rName
: aMandatoryToolbars
)
1114 xLayoutManager
->createElement( rName
);
1115 xLayoutManager
->showElement( rName
);
1118 for (const OUString
& rName
: aUserToolbars
)
1120 xLayoutManager
->createElement( rName
);
1121 xLayoutManager
->showElement( rName
);
1125 pViewFrame
->ShowChildWindow( SID_SIDEBAR
);
1127 if (comphelper::LibreOfficeKit::isActive())
1128 aSidebarMode
= "Opened";
1130 sfx2::sidebar::SidebarController
* pSidebar
=
1131 sfx2::sidebar::SidebarController::GetSidebarControllerForFrame( xFrame
);
1134 if ( aSidebarMode
== "Arrow" )
1136 pSidebar
->FadeOut();
1138 else if ( aSidebarMode
== "Tabs" )
1141 pSidebar
->RequestOpenDeck();
1142 pSidebar
->RequestCloseDeck();
1144 else if ( aSidebarMode
== "Opened" )
1147 pSidebar
->RequestOpenDeck();
1152 if ( pViewFrame
== SfxViewFrame::Current() )
1154 css::uno::Sequence
<OUString
> aBackup( comphelper::containerToSequence(aBackupList
) );
1156 for ( const auto& rModeNodeName
: aModeNodeNames
)
1158 const utl::OConfigurationNode
aModeNode( aModesNode
.openNode( rModeNodeName
) );
1159 if ( !aModeNode
.isValid() )
1162 OUString aCommandArg
= comphelper::getString( aModeNode
.getNodeValue( u
"CommandArg"_ustr
) );
1164 if ( aCommandArg
== aCurrentMode
)
1166 aModeNode
.setNodeValue( u
"UserToolbars"_ustr
, Any( aBackup
) );
1170 aModesNode
.commit();
1174 pViewFrame
= SfxViewFrame::GetNext(*pViewFrame
);
1180 case SID_TOOLBAR_MODE_UI
:
1182 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1183 ScopedVclPtr
<VclAbstractDialog
> pDlg(
1184 pFact
->CreateToolbarmodeDialog(rReq
.GetFrameWeld()));
1189 case SID_AVAILABLE_TOOLBARS
:
1191 const SfxStringItem
* pToolbarName
= rReq
.GetArg
<SfxStringItem
>(SID_AVAILABLE_TOOLBARS
);
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(u
"LayoutManager"_ustr
);
1205 aValue
>>= xLayoutManager
;
1207 catch ( const css::uno::RuntimeException
& )
1211 catch ( css::uno::Exception
& )
1216 if ( xLayoutManager
.is() )
1218 OUString aToolbarName
= "private:resource/toolbar/" +
1219 pToolbarName
->GetValue();
1221 // Evaluate Parameter
1222 bool bShow( !xLayoutManager
->isElementVisible( aToolbarName
));
1226 xLayoutManager
->createElement( aToolbarName
);
1227 xLayoutManager
->showElement( aToolbarName
);
1230 xLayoutManager
->hideElement( aToolbarName
);
1239 sfx2::SfxNotebookBar::ToggleMenubar();
1243 case SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW
:
1245 SfxViewShell
* pViewShell
= SfxViewShell::Current();
1246 SfxViewFrame
& rViewFrame
= pViewShell
->GetViewFrame();
1247 auto nID
= rReq
.GetSlot();
1248 rViewFrame
.ToggleChildWindow(nID
);
1253 case SID_INSPECT_SELECTED_OBJECT
:
1255 SfxViewShell
* pViewShell
= SfxViewShell::Current();
1256 SfxViewFrame
& rViewFrame
= pViewShell
->GetViewFrame();
1258 rViewFrame
.ShowChildWindow(SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW
, true);
1260 SfxChildWindow
* pChild
= rViewFrame
.GetChildWindow(SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW
);
1264 auto pDockingWin
= dynamic_cast<DevelopmentToolDockingWindow
*>(pChild
->GetWindow());
1267 pDockingWin
->changeToCurrentSelection();
1275 SafeModeQueryDialog
aDialog(rReq
.GetFrameWeld());
1279 case SID_TOOLBAR_LOCK
:
1281 if (SfxViewFrame
* pViewFrame
= SfxViewFrame::Current())
1283 Reference
<XFrame
> xCurrentFrame
;
1284 const uno::Reference
<uno::XComponentContext
>& xContext
1285 = ::comphelper::getProcessComponentContext();
1286 xCurrentFrame
= pViewFrame
->GetFrame().GetFrameInterface();
1287 const Reference
<frame::XModuleManager
> xModuleManager
1288 = frame::ModuleManager::create(xContext
);
1289 const utl::OConfigurationTreeRoot
aAppNode(
1290 xContext
, u
"org.openoffice.Office.UI.GlobalSettings/Toolbars/States"_ustr
, true);
1291 if (aAppNode
.isValid())
1293 bool isLocked
= comphelper::getBOOL(aAppNode
.getNodeValue(u
"Locked"_ustr
));
1294 aAppNode
.setNodeValue(u
"Locked"_ustr
, Any(!isLocked
));
1296 //TODO: apply immediately w/o restart needed
1297 SolarMutexGuard aGuard
;
1298 svtools::executeRestartDialog(comphelper::getProcessComponentContext(), nullptr,
1299 svtools::RESTART_REASON_UI_CHANGE
);
1312 void SfxApplication::MiscState_Impl(SfxItemSet
&rSet
)
1314 const WhichRangesContainer
& pRanges
= rSet
.GetRanges();
1315 DBG_ASSERT(!pRanges
.empty(), "Set without range");
1316 for ( auto const & pRange
: pRanges
)
1318 for(sal_uInt16 nWhich
= pRange
.first
; nWhich
<= pRange
.second
; ++nWhich
)
1322 case SID_TEMPLATE_ADDRESSBOOKSOURCE
:
1323 if (!SvtModuleOptions().IsDataBaseInstalled())
1324 rSet
.Put(SfxVisibilityItem(nWhich
, false));
1328 if (pImpl
->nDocModalMode
|| pImpl
->bClosingDocs
)
1329 rSet
.DisableItem(nWhich
);
1331 rSet
.Put(SfxStringItem(nWhich
, SfxResId(STR_QUITAPP
)));
1336 case SID_TOOLBOXOPTIONS
:
1337 case SID_CONFIGSTATUSBAR
:
1338 case SID_CONFIGMENU
:
1339 case SID_CONFIGACCEL
:
1340 case SID_CONFIGEVENT
:
1342 if( officecfg::Office::Common::Misc::DisableUICustomization::get() )
1343 rSet
.DisableItem(nWhich
);
1347 #if HAVE_FEATURE_SCRIPTING
1349 if ( !StarBASIC::IsRunning() )
1350 rSet
.DisableItem(nWhich
);
1354 case FN_CHANGE_THEME
:
1356 const bool bIsDarkMode
1357 = MiscSettings::GetAppColorMode() == 2
1358 || (!MiscSettings::GetAppColorMode() && MiscSettings::GetUseDarkMode());
1359 rSet
.Put(SfxBoolItem(FN_CHANGE_THEME
, bIsDarkMode
));
1364 rSet
.Put( SfxBoolItem( SID_HELPTIPS
, Help::IsQuickHelpEnabled() ) );
1367 case SID_HELPBALLOONS
:
1369 rSet
.Put( SfxBoolItem( SID_HELPBALLOONS
, Help::IsBalloonHelpEnabled() ) );
1373 case SID_EXTENDEDHELP
:
1380 if ( pImpl
->nDocModalMode
|| pImpl
->bInQuit
)
1382 rSet
.DisableItem(nWhich
);
1385 Reference
< XDesktop2
> xDesktop
= Desktop::create( ::comphelper::getProcessComponentContext() );
1386 Reference
< XIndexAccess
> xTasks
= xDesktop
->getFrames();
1387 if ( !xTasks
.is() || !xTasks
->getCount() )
1388 rSet
.DisableItem(nWhich
);
1394 bool bModified
= false;
1395 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
1397 pObjSh
= SfxObjectShell::GetNext( *pObjSh
) )
1399 if ( pObjSh
->IsModified() && !pObjSh
->isSaveLocked() )
1407 rSet
.DisableItem( nWhich
);
1411 case SID_TEMPLATE_MANAGER
:
1413 if ( !officecfg::Office::Common::Misc::ExperimentalMode::get() )
1415 rSet
.DisableItem( nWhich
);
1416 rSet
.Put( SfxVisibilityItem( nWhich
, false ) );
1421 case SID_ZOOM_50_PERCENT
:
1422 case SID_ZOOM_75_PERCENT
:
1423 case SID_ZOOM_100_PERCENT
:
1424 case SID_ZOOM_150_PERCENT
:
1425 case SID_ZOOM_200_PERCENT
:
1426 case SID_ZOOM_OPTIMAL
:
1427 case SID_ZOOM_ENTIRE_PAGE
:
1428 case SID_ZOOM_PAGE_WIDTH
:
1430 SfxObjectShell
* pCurrentShell(SfxObjectShell::Current());
1432 SfxPoolItemHolder aResult
;
1433 const SfxItemState
aState(pCurrentShell
?
1434 pCurrentShell
->GetDispatcher()->QueryState(SID_ATTR_ZOOM
, aResult
) : SfxItemState::DISABLED
);
1435 if ( aState
== SfxItemState::DISABLED
)
1436 rSet
.DisableItem( nWhich
);
1442 Reference
< XDesktop2
> xDesktop
= Desktop::create ( ::comphelper::getProcessComponentContext() );
1443 Reference
< XFrame
> xFrame
= xDesktop
->getActiveFrame();
1445 Reference
< css::beans::XPropertySet
> xPropSet( xFrame
, UNO_QUERY
);
1446 Reference
< css::frame::XLayoutManager
> xLayoutManager
;
1447 if ( xPropSet
.is() )
1451 Any aValue
= xPropSet
->getPropertyValue(u
"LayoutManager"_ustr
);
1452 aValue
>>= xLayoutManager
;
1454 catch ( const css::uno::RuntimeException
& )
1458 catch ( css::uno::Exception
& )
1463 if ( xLayoutManager
.is() )
1466 = xLayoutManager
->getElement(u
"private:resource/menubar/menubar"_ustr
).is()
1467 && xLayoutManager
->isElementVisible(
1468 u
"private:resource/menubar/menubar"_ustr
);
1470 SfxBoolItem
aItem( SID_MENUBAR
, bState
);
1477 // no restart in safe mode when already in safe mode
1478 if ( Application::IsSafeModeEnabled() )
1479 rSet
.DisableItem( SID_SAFE_MODE
);
1482 case SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW
:
1484 bool bSuccess
= false;
1485 auto* pViewShell
= SfxViewShell::Current();
1488 auto& rViewFrame
= pViewShell
->GetViewFrame();
1489 if (rViewFrame
.KnowsChildWindow(nWhich
))
1491 rSet
.Put(SfxBoolItem(nWhich
, rViewFrame
.HasChildWindow(nWhich
)));
1497 rSet
.DisableItem(nWhich
);
1500 case SID_INSPECT_SELECTED_OBJECT
:
1502 bool bSuccess
= false;
1503 auto* pViewShell
= SfxViewShell::Current();
1506 auto& rViewFrame
= pViewShell
->GetViewFrame();
1507 if (rViewFrame
.KnowsChildWindow(SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW
))
1513 rSet
.DisableItem(nWhich
);
1516 case SID_TOOLBAR_LOCK
:
1518 rSet
.Put( SfxBoolItem( SID_TOOLBAR_LOCK
, ToolBox::AlwaysLocked() ));
1528 #if HAVE_FEATURE_SCRIPTING
1530 #ifndef DISABLE_DYNLOADING
1532 typedef rtl_uString
* (*basicide_choose_macro
)(void*, void*, void*, sal_Bool
);
1536 extern "C" rtl_uString
* basicide_choose_macro(void*, void*, void*, sal_Bool
);
1540 static OUString
ChooseMacro(weld::Window
* pParent
, const Reference
<XModel
>& rxLimitToDocument
, const Reference
<XFrame
>& xDocFrame
, bool bChooseOnly
)
1542 #ifndef DISABLE_DYNLOADING
1543 basicide_choose_macro pSymbol
= reinterpret_cast<basicide_choose_macro
>(sfx2::getBasctlFunction("basicide_choose_macro"));
1545 #define pSymbol basicide_choose_macro
1548 // call basicide_choose_macro in basctl
1549 rtl_uString
* pScriptURL
= pSymbol(pParent
, rxLimitToDocument
.get(), xDocFrame
.get(), bChooseOnly
);
1550 OUString
aScriptURL( pScriptURL
);
1551 rtl_uString_release( pScriptURL
);
1554 #ifdef DISABLE_DYNLOADING
1563 #if HAVE_FEATURE_SCRIPTING
1564 weld::Window
* lcl_getDialogParent(const Reference
<XFrame
>& rxFrame
)
1566 Reference
<awt::XWindow
> xContainerWindow
;
1568 xContainerWindow
= rxFrame
->getContainerWindow();
1569 return Application::GetFrameWeld(xContainerWindow
);
1572 SfxViewFrame
* lcl_getBasicIDEViewFrame( SfxObjectShell
const * i_pBasicIDE
)
1574 SfxViewFrame
* pView
= SfxViewFrame::GetFirst( i_pBasicIDE
);
1577 if ( pView
->GetObjectShell()->GetFactory().GetDocumentServiceName() == "com.sun.star.script.BasicIDE" )
1579 pView
= SfxViewFrame::GetNext( *pView
, i_pBasicIDE
);
1583 Reference
< XFrame
> lcl_findStartModuleFrame( const Reference
<XComponentContext
> & rxContext
)
1587 Reference
< XDesktop2
> xDesktop
= Desktop::create( rxContext
);
1588 Reference
< XIndexAccess
> xContainer( xDesktop
->getFrames(), UNO_QUERY_THROW
);
1590 Reference
< XModuleManager2
> xCheck
= ModuleManager::create(rxContext
);
1592 sal_Int32 nCount
= xContainer
->getCount();
1593 for ( sal_Int32 i
=0; i
<nCount
; ++i
)
1597 Reference
< XFrame
> xFrame( xContainer
->getByIndex(i
), UNO_QUERY_THROW
);
1598 OUString sModule
= xCheck
->identify( xFrame
);
1599 if ( sModule
== "com.sun.star.frame.StartModule" )
1602 catch( const UnknownModuleException
& )
1606 catch(const Exception
&)
1608 // re-throw, caught below
1613 catch( const Exception
& )
1615 DBG_UNHANDLED_EXCEPTION("sfx.appl");
1619 #endif // HAVE_FEATURE_SCRIPTING
1622 void SfxApplication::OfaExec_Impl( SfxRequest
& rReq
)
1624 switch ( rReq
.GetSlot() )
1626 case SID_OPTIONS_TREEDIALOG
:
1629 const SfxStringItem
* pURLItem
= rReq
.GetArg
<SfxStringItem
>(SID_OPTIONS_PAGEURL
);
1631 sPageURL
= pURLItem
->GetValue();
1633 sal_uInt16 nPageID
= 0;
1634 const SfxUInt16Item
* pIDItem
= rReq
.GetArg
<SfxUInt16Item
>(SID_OPTIONS_PAGEID
);
1636 nPageID
= pIDItem
->GetValue();
1638 Reference
<XFrame
> xFrame(GetRequestFrame(rReq
));
1639 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1640 VclPtr
<VclAbstractDialog
> pDlg
=
1641 pFact
->CreateFrameDialog(rReq
.GetFrameWeld(), xFrame
, rReq
.GetSlot(), nPageID
, sPageURL
);
1642 short nRet
= pDlg
->Execute();
1643 pDlg
.disposeAndClear();
1644 SfxViewFrame
* pView
= SfxViewFrame::GetFirst();
1645 bool bDisableActiveContent
1646 = officecfg::Office::Common::Security::Scripting::DisableActiveContent::get();
1652 SfxObjectShell
* pObjSh
= pView
->GetObjectShell();
1655 pObjSh
->SetConfigOptionsChecked(false);
1657 // when active content is disabled via options dialog,
1658 // disable all current active embedded objects
1659 if (bDisableActiveContent
)
1660 lcl_disableActiveEmbeddedObjects(pObjSh
);
1663 pView
->GetBindings().InvalidateAll(false);
1664 pView
= SfxViewFrame::GetNext( *pView
);
1669 case SID_OPTIONS_SECURITY
:
1671 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1672 VclPtr
<AbstractSecurityOptionsDialog
> pDlg
=
1673 pFact
->CreateSvxSecurityOptionsDialog(rReq
.GetFrameWeld());
1675 if (pDlg
->Execute() == RET_OK
) {
1676 pDlg
->SetSecurityOptions();
1679 pDlg
.disposeAndClear();
1683 case SID_ADDITIONS_DIALOG
:
1685 OUString sAdditionsTag
= u
""_ustr
;
1687 const SfxStringItem
* pStringArg
= rReq
.GetArg
<SfxStringItem
>(FN_PARAM_ADDITIONS_TAG
);
1689 sAdditionsTag
= pStringArg
->GetValue();
1691 VclAbstractDialogFactory
* pFact
= VclAbstractDialogFactory::Create();
1692 VclPtr
<AbstractAdditionsDialog
> pDialog(
1693 pFact
->CreateAdditionsDialog(rReq
.GetFrameWeld(), sAdditionsTag
));
1694 pDialog
->StartExecuteAsync(
1695 [pDialog
] (sal_Int32
/*nResult*/)->void
1697 pDialog
->disposeOnce();
1703 case SID_MORE_DICTIONARIES
:
1705 uno::Sequence
<beans::PropertyValue
> aArgs
{ comphelper::makePropertyValue(
1706 u
"AdditionsTag"_ustr
, u
"Dictionary"_ustr
) };
1707 comphelper::dispatchCommand(u
".uno:AdditionsDialog"_ustr
, aArgs
);
1710 #if HAVE_FEATURE_SCRIPTING
1711 case SID_BASICIDE_APPEAR
:
1713 SfxViewFrame
* pView
= lcl_getBasicIDEViewFrame( nullptr );
1716 SfxObjectShell
* pBasicIDE
= SfxObjectShell::CreateObject( u
"com.sun.star.script.BasicIDE"_ustr
);
1717 pBasicIDE
->DoInitNew();
1718 pBasicIDE
->SetModified( false );
1721 // load the Basic IDE via direct access to the SFX frame loader. A generic loadComponentFromURL
1722 // (which could be done via SfxViewFrame::LoadDocumentIntoFrame) is not feasible here, since the Basic IDE
1723 // does not really play nice with the framework's concept. For instance, it is a "singleton document",
1724 // which conflicts, at the latest, with the framework's concept of loading into _blank frames.
1725 // So, since we know that our frame loader can handle it, we skip the generic framework loader
1726 // mechanism, and the type detection (which doesn't know about the Basic IDE).
1727 const Reference
< XComponentContext
>& xContext( ::comphelper::getProcessComponentContext() );
1728 Reference
< XSynchronousFrameLoader
> xLoader(
1729 xContext
->getServiceManager()->createInstanceWithContext(u
"com.sun.star.comp.office.FrameLoader"_ustr
, xContext
),
1731 ::comphelper::NamedValueCollection aLoadArgs
;
1732 aLoadArgs
.put( u
"Model"_ustr
, pBasicIDE
->GetModel() );
1733 aLoadArgs
.put( u
"URL"_ustr
, u
"private:factory/sbasic"_ustr
);
1735 Reference
< XFrame
> xTargetFrame( lcl_findStartModuleFrame( xContext
) );
1736 if ( !xTargetFrame
.is() )
1737 xTargetFrame
= SfxFrame::CreateBlankFrame();
1738 ENSURE_OR_THROW( xTargetFrame
.is(), "could not obtain a frameto load the Basic IDE into!" );
1740 xLoader
->load( aLoadArgs
.getPropertyValues(), xTargetFrame
);
1742 catch( const Exception
& )
1744 DBG_UNHANDLED_EXCEPTION("sfx.appl");
1747 pView
= lcl_getBasicIDEViewFrame( pBasicIDE
);
1749 pView
->SetName( u
"BASIC:1"_ustr
);
1753 pView
->GetFrame().Appear();
1755 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1756 if ( pArgs
&& pView
)
1758 SfxViewShell
* pViewShell
= pView
->GetViewShell();
1759 SfxObjectShell
* pObjShell
= pView
->GetObjectShell();
1760 if ( pViewShell
&& pObjShell
)
1762 SfxRequest
aReq( SID_BASICIDE_SHOWWINDOW
, SfxCallMode::SYNCHRON
, pObjShell
->GetPool() );
1763 aReq
.SetArgs( *pArgs
);
1764 pViewShell
->ExecuteSlot( aReq
);
1772 case SID_BASICCHOOSER
:
1774 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1775 const SfxBoolItem
* pItem
;
1776 bool bChooseOnly
= false;
1777 Reference
< XModel
> xLimitToModel
;
1778 if(pArgs
&& (pItem
= pArgs
->GetItemIfSet(SID_RECORDMACRO
, false)) )
1780 bool bRecord
= pItem
->GetValue();
1784 bChooseOnly
= false;
1785 SfxObjectShell
* pCurrentShell
= SfxObjectShell::Current();
1786 OSL_ENSURE( pCurrentShell
, "macro recording outside an SFX document?" );
1787 if ( pCurrentShell
)
1788 xLimitToModel
= pCurrentShell
->GetModel();
1792 Reference
<XFrame
> xFrame(GetRequestFrame(rReq
));
1793 rReq
.SetReturnValue(SfxStringItem(rReq
.GetSlot(), ChooseMacro(rReq
.GetFrameWeld(), xLimitToModel
, xFrame
, bChooseOnly
)));
1798 case SID_MACROORGANIZER
:
1800 SAL_INFO("sfx.appl", "handling SID_MACROORGANIZER");
1801 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1802 sal_Int16 nTabId
= 0;
1803 Reference
<XFrame
> xFrame
;
1806 if (const SfxUInt16Item
* pItem
= pArgs
->GetItemIfSet(SID_MACROORGANIZER
, false))
1807 nTabId
= pItem
->GetValue();
1808 if (const SfxBoolItem
* pItem
= rReq
.GetArg
<SfxBoolItem
>(FN_PARAM_2
))
1810 // if set then default to showing the macros of the document associated
1812 if (pItem
->GetValue())
1813 xFrame
= GetRequestFrame(rReq
);
1816 SfxApplication::MacroOrganizer(rReq
.GetFrameWeld(), xFrame
, nTabId
);
1823 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1824 SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: case ScriptOrg");
1826 Reference
<XFrame
> xFrame(GetRequestFrame(rReq
));
1829 if (const SfxViewFrame
* pViewFrame
= SfxViewFrame::Current())
1830 xFrame
= pViewFrame
->GetFrame().GetFrameInterface();
1833 do // artificial loop for flow control
1835 VclPtr
<AbstractScriptSelectorDialog
> pDlg(pFact
->CreateScriptSelectorDialog(lcl_getDialogParent(xFrame
), xFrame
));
1836 OSL_ENSURE( pDlg
, "SfxApplication::OfaExec_Impl( SID_RUNMACRO ): no dialog!" );
1839 pDlg
->SetRunLabel();
1841 pDlg
->StartExecuteAsync([pDlg
, xFrame
](sal_Int32 nDialogResult
) {
1842 if ( !nDialogResult
)
1844 pDlg
->disposeOnce();
1848 Sequence
< Any
> args
;
1849 Sequence
< sal_Int16
> outIndex
;
1850 Sequence
< Any
> outArgs
;
1853 Reference
< XInterface
> xScriptContext
;
1855 Reference
< XController
> xController
;
1857 xController
= xFrame
->getController();
1858 if ( xController
.is() )
1859 xScriptContext
= xController
->getModel();
1860 if ( !xScriptContext
.is() )
1861 xScriptContext
= xController
;
1863 SfxObjectShell::CallXScript( xScriptContext
, pDlg
->GetScriptURL(), args
, ret
, outIndex
, outArgs
);
1864 pDlg
->disposeOnce();
1872 case SID_SCRIPTORGANIZER
:
1874 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1875 SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: case ScriptOrg");
1876 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1877 const SfxScriptOrganizerItem
* pItem
;
1879 if(pArgs
&& (pItem
= pArgs
->GetItemIfSet(SID_SCRIPTORGANIZER
, false) ))
1881 aLanguage
= pItem
->getLanguage();
1884 OUString
aLang( aLanguage
);
1885 SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: about to create dialog for: " << aLang
);
1886 ScopedVclPtr
<VclAbstractDialog
> pDlg(pFact
->CreateSvxScriptOrgDialog(rReq
.GetFrameWeld(), aLanguage
));
1893 SAL_WARN("sfx.appl", "no dialog!!!");
1899 case SID_MACROMANAGER
:
1901 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1903 Reference
<XFrame
> xFrame(GetRequestFrame(rReq
));
1906 if (const SfxViewFrame
* pViewFrame
= SfxViewFrame::Current())
1907 xFrame
= pViewFrame
->GetFrame().GetFrameInterface();
1910 VclPtr
<AbstractMacroManagerDialog
> pDlg(
1911 pFact
->CreateMacroManagerDialog(lcl_getDialogParent(xFrame
), xFrame
));
1912 OSL_ENSURE(pDlg
, "SfxApplication::OfaExec_Impl(SID_MACROMANAGER): no dialog!");
1915 pDlg
->StartExecuteAsync(
1916 [pDlg
, xFrame
](sal_Int32 nDialogResult
)
1920 pDlg
->disposeOnce();
1925 Sequence
<sal_Int16
> outIndex
;
1926 Sequence
<Any
> outArgs
;
1929 Reference
<XInterface
> xScriptContext
;
1931 Reference
<XController
> xController
;
1933 xController
= xFrame
->getController();
1934 if (xController
.is())
1935 xScriptContext
= xController
->getModel();
1936 if (!xScriptContext
.is())
1937 xScriptContext
= xController
;
1939 SfxObjectShell::CallXScript(xScriptContext
, pDlg
->GetScriptURL(), args
, ret
,
1941 pDlg
->disposeOnce();
1943 pDlg
->LoadLastUsedMacro();
1948 #endif // HAVE_FEATURE_SCRIPTING
1950 case SID_OFFICE_CHECK_PLZ
:
1953 const SfxStringItem
* pStringItem
= rReq
.GetArg
<SfxStringItem
>(rReq
.GetSlot());
1957 bRet
= true /*!!!SfxIniManager::CheckPLZ( aPLZ )*/;
1959 #if HAVE_FEATURE_SCRIPTING
1961 SbxBase::SetError( ERRCODE_BASIC_WRONG_ARGS
);
1963 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bRet
) );
1967 case SID_AUTO_CORRECT_DLG
:
1969 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1970 SfxItemSetFixed
<SID_AUTO_CORRECT_DLG
, SID_AUTO_CORRECT_DLG
> aSet(GetPool());
1971 const SfxPoolItem
* pItem
=nullptr;
1972 const SfxItemSet
* pSet
= rReq
.GetArgs();
1973 if ( pSet
&& pSet
->GetItemState( SID_AUTO_CORRECT_DLG
, false, &pItem
) == SfxItemState::SET
)
1976 ScopedVclPtr
<SfxAbstractTabDialog
> pDlg(pFact
->CreateAutoCorrTabDialog(rReq
.GetFrameWeld(), &aSet
));
1984 if (!SvtModuleOptions().IsImpressInstalled())
1986 std::unique_ptr
<weld::MessageDialog
> xBox(Application::CreateMessageDialog(rReq
.GetFrameWeld(),
1987 VclMessageType::Warning
, VclButtonsType::Ok
,
1988 SfxResId(STR_MODULENOTINSTALLED
)));
1993 const Reference
< uno::XComponentContext
>& xContext
= ::comphelper::getProcessComponentContext();
1994 Reference
< frame::XDispatchProvider
> xProv
= drawing::ModuleDispatcher::create( xContext
);
1996 OUString aCmd
= GetInterface()->GetSlot( rReq
.GetSlot() )->GetUnoName();
1997 Reference
< frame::XDispatchHelper
> xHelper( frame::DispatchHelper::create(xContext
) );
1998 Sequence
< beans::PropertyValue
> aSeq
;
1999 if ( rReq
.GetArgs() )
2000 TransformItems( rReq
.GetSlot(), *rReq
.GetArgs(), aSeq
);
2001 Any aResult
= xHelper
->executeDispatch( xProv
, aCmd
, OUString(), 0, aSeq
);
2002 frame::DispatchResultEvent aEvent
;
2003 bool bSuccess
= (aResult
>>= aEvent
) &&
2004 (aEvent
.State
== frame::DispatchResultState::SUCCESS
);
2005 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bSuccess
) );
2010 case FN_BUSINESS_CARD
:
2011 case FN_XFORMS_INIT
:
2013 const Reference
< uno::XComponentContext
>& xContext
= ::comphelper::getProcessComponentContext();
2014 Reference
< frame::XDispatchProvider
> xProv
= text::ModuleDispatcher::create( xContext
);
2016 OUString aCmd
= GetInterface()->GetSlot( rReq
.GetSlot() )->GetUnoName();
2017 Reference
< frame::XDispatchHelper
> xHelper( frame::DispatchHelper::create(xContext
) );
2018 Sequence
< beans::PropertyValue
> aSeq
;
2019 if ( rReq
.GetArgs() )
2020 TransformItems( rReq
.GetSlot(), *rReq
.GetArgs(), aSeq
);
2021 Any aResult
= xHelper
->executeDispatch( xProv
, aCmd
, OUString(), 0, aSeq
);
2022 frame::DispatchResultEvent aEvent
;
2023 bool bSuccess
= (aResult
>>= aEvent
) &&
2024 (aEvent
.State
== frame::DispatchResultState::SUCCESS
);
2025 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bSuccess
) );
2029 case SID_ADDRESS_DATA_SOURCE
:
2033 const Reference
< uno::XComponentContext
>& xORB
= ::comphelper::getProcessComponentContext();
2034 Reference
< ui::dialogs::XExecutableDialog
> xDialog
= ui::dialogs::AddressBookSourcePilot::createWithParent(xORB
, nullptr);
2037 catch(const css::uno::Exception
&)
2039 DBG_UNHANDLED_EXCEPTION("sfx.appl");
2044 case SID_COMP_BIBLIOGRAPHY
:
2045 lcl_tryLoadBibliography();
2050 void SfxApplication::OfaState_Impl(SfxItemSet
&rSet
)
2052 if (!SvtModuleOptions().IsWriterInstalled())
2054 rSet
.DisableItem( FN_LABEL
);
2055 rSet
.DisableItem( FN_BUSINESS_CARD
);
2056 rSet
.DisableItem( FN_XFORMS_INIT
);
2058 if ( comphelper::LibreOfficeKit::isActive() )
2059 rSet
.DisableItem( SID_AUTO_CORRECT_DLG
);
2061 if (SvtSecurityOptions::IsMacroDisabled())
2063 rSet
.DisableItem(SID_RUNMACRO
);
2064 rSet
.DisableItem(SID_MACROORGANIZER
);
2065 rSet
.DisableItem(SID_SCRIPTORGANIZER
);
2066 rSet
.DisableItem(SID_BASICIDE_APPEAR
);
2067 rSet
.DisableItem(SID_MACROMANAGER
);
2071 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */