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