Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / source / appl / appserv.cxx
blobd6190e604c781477fe16a73251d4f2521d3e4dc2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_features.h>
21 #include <com/sun/star/document/XEmbeddedScripts.hpp>
22 #include <com/sun/star/drawing/ModuleDispatcher.hpp>
23 #include <com/sun/star/frame/Desktop.hpp>
24 #include <com/sun/star/frame/DispatchResultEvent.hpp>
25 #include <com/sun/star/frame/DispatchResultState.hpp>
26 #include <com/sun/star/frame/DispatchHelper.hpp>
27 #include <com/sun/star/frame/UnknownModuleException.hpp>
28 #include <com/sun/star/frame/XLayoutManager.hpp>
29 #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
30 #include <com/sun/star/sdbc/DriverManager.hpp>
31 #include <com/sun/star/system/SystemShellExecute.hpp>
32 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
33 #include <com/sun/star/text/ModuleDispatcher.hpp>
34 #include <com/sun/star/task/OfficeRestartManager.hpp>
35 #include <com/sun/star/task/XInteractionHandler.hpp>
36 #include <com/sun/star/ui/dialogs/AddressBookSourcePilot.hpp>
37 #include <com/sun/star/ui/UIElementType.hpp>
38 #include <com/sun/star/ui/XUIElement.hpp>
39 #include <com/sun/star/uno/Reference.hxx>
40 #include <com/sun/star/util/XCloseable.hpp>
41 #include <com/sun/star/util/CloseVetoException.hpp>
42 #include <org/freedesktop/PackageKit/SyncDbusSessionHelper.hpp>
44 #include <comphelper/dispatchcommand.hxx>
45 #include <comphelper/lok.hxx>
46 #include <comphelper/namedvaluecollection.hxx>
47 #include <comphelper/processfactory.hxx>
48 #include <comphelper/propertysequence.hxx>
49 #include <comphelper/sequence.hxx>
51 #include <svtools/addresstemplate.hxx>
52 #include <svtools/miscopt.hxx>
53 #include <svtools/restartdialog.hxx>
54 #include <svl/visitem.hxx>
56 #include <unotools/configmgr.hxx>
57 #include <tools/svlibrary.h>
58 #include <tools/diagnose_ex.h>
59 #include <vcl/svapp.hxx>
60 #include <vcl/weld.hxx>
61 #include <svl/intitem.hxx>
62 #include <svl/eitem.hxx>
63 #include <svl/stritem.hxx>
64 #include <basic/sbstar.hxx>
65 #include <basic/basrdll.hxx>
66 #include <basic/sberrors.hxx>
67 #include <vcl/help.hxx>
68 #include <rtl/ustrbuf.hxx>
69 #include <sal/log.hxx>
70 #include <osl/file.hxx>
71 #include <vcl/EnumContext.hxx>
73 #include <unotools/moduleoptions.hxx>
74 #include <svtools/helpopt.hxx>
75 #include <toolkit/helper/vclunohelper.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/msg.hxx>
86 #include <sfx2/objface.hxx>
87 #include <sfx2/objsh.hxx>
88 #include <sfx2/viewsh.hxx>
89 #include <sfx2/docfac.hxx>
90 #include <sfx2/strings.hrc>
91 #include <sfx2/sfxresid.hxx>
92 #include <appdata.hxx>
93 #include <sfx2/viewfrm.hxx>
94 #include <sfx2/sfxdlg.hxx>
95 #include <sfx2/sfxsids.hrc>
96 #include <sorgitm.hxx>
97 #include <sfx2/sfxhelp.hxx>
98 #include <sfx2/zoomitem.hxx>
99 #include <sfx2/templatedlg.hxx>
100 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
101 #include <sfx2/sidebar/SidebarController.hxx>
102 #include <sfx2/safemode.hxx>
103 #include <sfx2/sfxuno.hxx>
105 #include <comphelper/types.hxx>
106 #include <officecfg/Office/Common.hxx>
107 #include <unotools/confignode.hxx>
108 #include <officecfg/Setup.hxx>
109 #include <memory>
111 #include <openuriexternally.hxx>
113 #include "getbasctlfunction.hxx"
115 using namespace ::com::sun::star;
116 using namespace ::com::sun::star::beans;
117 using namespace ::com::sun::star::uno;
118 using namespace ::com::sun::star::frame;
119 using namespace ::com::sun::star::container;
120 using namespace ::com::sun::star::util;
121 using namespace ::com::sun::star::script;
122 using namespace ::com::sun::star::system;
123 using namespace ::com::sun::star::lang;
124 using namespace ::com::sun::star::document;
125 using namespace ::com::sun::star::ui;
127 namespace
129 OUString lcl_getAppName( vcl::EnumContext::Application eApp )
131 switch ( eApp )
133 case vcl::EnumContext::Application::Writer:
134 return "Writer";
135 break;
136 case vcl::EnumContext::Application::Calc:
137 return "Calc";
138 break;
139 case vcl::EnumContext::Application::Impress:
140 return "Impress";
141 break;
142 case vcl::EnumContext::Application::Draw:
143 return "Draw";
144 break;
145 case vcl::EnumContext::Application::Formula:
146 return "Formula";
147 break;
148 case vcl::EnumContext::Application::Base:
149 return "Base";
150 break;
151 default:
152 return OUString();
153 break;
157 // lp#527938, debian#602953, fdo#33266, i#105408
158 bool lcl_isBaseAvailable()
162 // if we get css::sdbc::DriverManager, libsdbc2 is there
163 // and the bibliography is assumed to work
164 return css::sdbc::DriverManager::create(comphelper::getProcessComponentContext()).is();
166 catch (const Exception &)
168 TOOLS_INFO_EXCEPTION("sfx.appl", "assuming Base to be missing");
169 return false;
172 void lcl_tryLoadBibliography()
174 // lp#527938, debian#602953, fdo#33266, i#105408
175 // make sure we actually can instantiate services from base first
176 if(!lcl_isBaseAvailable())
178 if (officecfg::Office::Common::PackageKit::EnableBaseInstallation::get())
182 using namespace org::freedesktop::PackageKit;
183 using namespace svtools;
184 Reference< XSyncDbusSessionHelper > xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext()));
185 Sequence< OUString > vPackages { "libreoffice-base" };
186 xSyncDbusSessionHelper->InstallPackageNames(vPackages, OUString());
187 // I'll be back (hopefully)!
188 SolarMutexGuard aGuard;
189 executeRestartDialog(comphelper::getProcessComponentContext(), nullptr, RESTART_REASON_BIBLIOGRAPHY_INSTALL);
191 catch (const Exception &)
193 TOOLS_INFO_EXCEPTION("sfx.appl", "trying to install LibreOffice Base");
196 return;
199 try // fdo#48775
201 SfxStringItem aURL(SID_FILE_NAME, ".component:Bibliography/View1");
202 SfxStringItem aRef(SID_REFERER, "private:user");
203 SfxStringItem aTarget(SID_TARGETNAME, "_blank");
204 SfxViewFrame::Current()->GetDispatcher()->ExecuteList(SID_OPENDOC,
205 SfxCallMode::ASYNCHRON, { &aURL, &aRef, &aTarget });
207 catch (const Exception &)
209 TOOLS_INFO_EXCEPTION( "sfx.appl", "trying to load bibliography database");
213 /// Find the correct location of the document (CREDITS.fodt, etc.), and return
214 /// it in rURL if found.
215 static bool checkURL( const char *pName, const char *pExt, OUString &rURL )
217 using namespace osl;
218 DirectoryItem aDirItem;
220 #ifdef MACOSX
221 rURL = "$BRAND_BASE_DIR/Resources/" + OUString::createFromAscii( pName ) +
222 OUString::createFromAscii( pExt );
223 #else
224 rURL = "$BRAND_BASE_DIR/" + OUString::createFromAscii( pName ) +
225 OUString::createFromAscii( pExt );
226 #endif
227 rtl::Bootstrap::expandMacros( rURL );
229 if (!rURL.isEmpty())
230 return DirectoryItem::get( rURL, aDirItem ) == DirectoryItem::E_None;
231 else
232 return false;
235 /// Displays CREDITS or LICENSE in any of the available version
236 static void showDocument( const char* pBaseName )
238 try {
239 Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
240 auto args(::comphelper::InitPropertySequence({
241 {"ViewOnly", makeAny(true)},
242 {"ReadOnly", makeAny(true)}
243 }));
245 OUString aURL;
246 if ( checkURL ( pBaseName, ".fodt", aURL ) ||
247 checkURL ( pBaseName, ".html", aURL ) ||
248 checkURL ( pBaseName, "", aURL ) ) {
249 xDesktop->loadComponentFromURL( aURL, "_blank", 0, args );
251 } catch (const css::uno::Exception &) {
255 namespace
257 Reference<XFrame> GetRequestFrame(const SfxRequest& rReq)
259 const SfxItemSet* pArgs = rReq.GetInternalArgs_Impl();
260 const SfxPoolItem* pItem = nullptr;
261 Reference <XFrame> xFrame;
262 if (pArgs && pArgs->GetItemState(SID_FILLFRAME, false, &pItem) == SfxItemState::SET)
264 OSL_ENSURE( dynamic_cast< const SfxUnoFrameItem *>( pItem ) != nullptr, "SfxApplication::OfaExec_Impl: XFrames are to be transported via SfxUnoFrameItem by now!" );
265 xFrame = static_cast< const SfxUnoFrameItem*>( pItem )->GetFrame();
267 return xFrame;
270 vcl::Window* getFrameWindow(const Reference<XFrame>& rFrame)
272 if (rFrame.is())
276 Reference< awt::XWindow > xContainerWindow(rFrame->getContainerWindow(), UNO_SET_THROW);
277 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xContainerWindow);
278 return pWindow;
280 catch (const Exception&)
282 DBG_UNHANDLED_EXCEPTION("sfx.appl");
286 SAL_WARN( "sfx.appl", "no parent for dialogs" );
287 return nullptr;
290 class LicenseDialog : public weld::GenericDialogController
292 public:
293 LicenseDialog(weld::Window* pParent)
294 : GenericDialogController(pParent, "sfx/ui/licensedialog.ui", "LicenseDialog")
298 virtual short run() override
300 short nRet = GenericDialogController::run();
301 if (nRet == RET_OK)
302 showDocument("LICENSE");
303 return nRet;
307 class SafeModeQueryDialog : public weld::MessageDialogController
309 public:
310 SafeModeQueryDialog(weld::Window* pParent)
311 : MessageDialogController(pParent, "sfx/ui/safemodequerydialog.ui", "SafeModeQueryDialog")
315 virtual short run() override
317 short nRet = MessageDialogController::run();
318 if (nRet == RET_OK)
320 sfx2::SafeMode::putFlag();
321 uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
322 css::task::OfficeRestartManager::get(xContext)->requestRestart(
323 css::uno::Reference< css::task::XInteractionHandler >());
325 return nRet;
330 vcl::Window* SfxRequest::GetFrameWindow() const
332 return getFrameWindow(GetRequestFrame(*this));
335 weld::Window* SfxRequest::GetFrameWeld() const
337 const SfxItemSet* pIntArgs = GetInternalArgs_Impl();
338 const SfxPoolItem* pItem = nullptr;
339 if (pIntArgs && pIntArgs->GetItemState(SID_DIALOG_PARENT, false, &pItem) == SfxItemState::SET)
341 assert(dynamic_cast<const SfxUnoAnyItem*>(pItem));
342 auto aAny = static_cast<const SfxUnoAnyItem*>(pItem)->GetValue();
343 Reference<awt::XWindow> xWindow;
344 aAny >>= xWindow;
345 return Application::GetFrameWeld(xWindow);
348 vcl::Window* pWin = GetFrameWindow();
349 return pWin ? pWin->GetFrameWeld() : nullptr;
352 void SfxApplication::MiscExec_Impl( SfxRequest& rReq )
354 bool bDone = false;
355 switch ( rReq.GetSlot() )
357 case SID_SETOPTIONS:
359 if( rReq.GetArgs() )
360 SetOptions_Impl( *rReq.GetArgs() );
361 break;
364 case SID_QUITAPP:
365 case SID_LOGOUT:
367 // protect against reentrant calls
368 if ( pImpl->bInQuit )
369 return;
371 if ( rReq.GetSlot() == SID_LOGOUT )
373 for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
374 pObjSh; pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
376 if ( !pObjSh->IsModified() )
377 continue;
379 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pObjSh );
380 if ( !pFrame || !pFrame->GetWindow().IsReallyVisible() )
381 continue;
383 if (pObjSh->PrepareClose())
384 pObjSh->SetModified( false );
385 else
386 return;
389 SfxStringItem aNameItem( SID_FILE_NAME, "vnd.sun.star.cmd:logout" );
390 SfxStringItem aReferer( SID_REFERER, "private/user" );
391 pImpl->pAppDispat->ExecuteList(SID_OPENDOC,
392 SfxCallMode::SLOT, { &aNameItem, &aReferer });
393 return;
396 // try from nested requests again after 100ms
397 if( Application::GetDispatchLevel() > 1 )
399 /* Don't save the request for closing the application and try it later
400 again. This is an UI bound functionality ... and the user will try it again
401 if the dialog is closed. But we should not close the application automatically
402 if this dialog is closed by the user ...
403 So we ignore this request now and wait for a new user decision.
405 SAL_INFO("sfx.appl", "QueryExit => sal_False, DispatchLevel == " << Application::GetDispatchLevel() );
406 return;
409 // block reentrant calls
410 pImpl->bInQuit = true;
411 Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
413 rReq.ForgetAllArgs();
415 // if terminate() failed, pImpl->bInQuit will now be sal_False, allowing further calls of SID_QUITAPP
416 bool bTerminated = xDesktop->terminate();
417 if (!bTerminated)
418 // if terminate() was successful, SfxApplication is now dead!
419 pImpl->bInQuit = false;
421 // Set return value, terminate if possible
422 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bTerminated ) );
423 return;
426 case SID_CONFIG:
427 case SID_TOOLBOXOPTIONS:
428 case SID_CONFIGSTATUSBAR:
429 case SID_CONFIGMENU:
430 case SID_CONFIGACCEL:
431 case SID_CONFIGEVENT:
433 SfxAbstractDialogFactory* pFact =
434 SfxAbstractDialogFactory::Create();
436 const SfxStringItem* pStringItem = rReq.GetArg<SfxStringItem>(SID_CONFIG);
438 SfxItemSet aSet(
439 GetPool(), svl::Items<SID_CONFIG, SID_CONFIG>{} );
441 if ( pStringItem )
443 aSet.Put( SfxStringItem(
444 SID_CONFIG, pStringItem->GetValue() ) );
447 Reference <XFrame> xFrame(GetRequestFrame(rReq));
448 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateCustomizeTabDialog(rReq.GetFrameWeld(),
449 &aSet, xFrame ));
451 const short nRet = pDlg->Execute();
453 if ( nRet )
454 bDone = true;
455 break;
458 case SID_CLOSEDOCS:
461 Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
462 Reference< XIndexAccess > xTasks = xDesktop->getFrames();
463 if ( !xTasks.is() )
464 break;
466 sal_Int32 n=0;
469 if ( xTasks->getCount() <= n )
470 break;
472 Any aAny = xTasks->getByIndex(n);
473 Reference < XCloseable > xTask;
474 aAny >>= xTask;
477 xTask->close(true);
478 n++;
480 catch( CloseVetoException& )
484 while( true );
486 bool bOk = ( n == 0);
487 rReq.SetReturnValue( SfxBoolItem( 0, bOk ) );
488 bDone = true;
489 break;
492 case SID_SAVEDOCS:
494 bool bOK = true;
495 for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
496 pObjSh;
497 pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
499 SfxRequest aReq( SID_SAVEDOC, SfxCallMode::SLOT, pObjSh->GetPool() );
500 if ( pObjSh->IsModified() )
502 pObjSh->ExecuteSlot( aReq );
503 const SfxBoolItem *pItem = dynamic_cast<const SfxBoolItem*>( aReq.GetReturnValue() );
504 if ( !pItem || !pItem->GetValue() )
505 bOK = false;
509 rReq.SetReturnValue( SfxBoolItem( 0, bOK ) );
510 rReq.Done();
511 break;
514 case SID_SEND_FEEDBACK:
516 OUString module = SfxHelp::GetCurrentModuleIdentifier();
517 OUString sURL(officecfg::Office::Common::Menus::SendFeedbackURL::get() + //officecfg/registry/data/org/openoffice/Office/Common.xcu => https://hub.libreoffice.org/send-feedback/
518 "?LOversion=" + utl::ConfigManager::getAboutBoxProductVersion() +
519 "&LOlocale=" + utl::ConfigManager::getUILocale() +
520 "&LOmodule=" + module.subView(module.lastIndexOf('.') + 1 ) );
521 sfx2::openUriExternally(sURL, false);
522 break;
525 case SID_Q_AND_A:
527 // Askbot has URL's normalized to languages, not locales
528 // Get language from locale: ll or lll or ll-CC or lll-CC
530 OUString sURL(officecfg::Office::Common::Menus::QA_URL::get() + //https://hub.libreoffice.org/forum/
531 "?LOlocale=" + utl::ConfigManager::getUILocale());
532 sfx2::openUriExternally(sURL, false);
533 break;
535 case SID_DOCUMENTATION:
537 // Open documentation page based on locales
538 OUString sURL(officecfg::Office::Common::Menus::DocumentationURL::get() + //https://hub.libreoffice.org/documentation/
539 "?LOlocale=" + utl::ConfigManager::getUILocale());
540 sfx2::openUriExternally(sURL, false);
541 break;
543 case SID_GETINVOLVED:
545 // Open get involved/join us page based on locales
546 OUString sURL(officecfg::Office::Common::Menus::GetInvolvedURL::get() + //https://hub.libreoffice.org/joinus/
547 "?LOlocale=" + utl::ConfigManager::getUILocale());
548 sfx2::openUriExternally(sURL, false);
549 break;
551 case SID_DONATION:
553 // Open donation page based on language + script (BCP47) with language as fall back.
554 OUString aLang = LanguageTag(utl::ConfigManager::getUILocale()).getLanguage();
555 OUString aBcp47 = LanguageTag(utl::ConfigManager::getUILocale()).getBcp47();
556 OUString sURL(officecfg::Office::Common::Menus::DonationURL::get() + //https://hub.libreoffice.org/donation/
557 "?BCP47=" + aBcp47 + "&LOlang=" + aLang );
558 sfx2::openUriExternally(sURL, false);
559 break;
561 case SID_WHATSNEW:
563 // Open release notes depending on version and locale
564 OUString sURL(officecfg::Office::Common::Menus::ReleaseNotesURL::get() + //https://hub.libreoffice.org/ReleaseNotes/
565 "?LOvers=" + utl::ConfigManager::getProductVersion() +
566 "&LOlocale=" + LanguageTag(utl::ConfigManager::getUILocale()).getBcp47() );
567 sfx2::openUriExternally(sURL, false);
568 break;
570 case SID_SHOW_LICENSE:
572 LicenseDialog aDialog(rReq.GetFrameWeld());
573 aDialog.run();
574 break;
577 case SID_SHOW_CREDITS:
579 showDocument( "CREDITS" );
580 break;
583 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
584 case SID_HELPINDEX:
586 Help* pHelp = Application::GetHelp();
587 if ( pHelp )
589 pHelp->Start(".uno:HelpIndex", Application::GetDefDialogParent()); // show start page
590 bDone = true;
592 break;
595 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
596 case SID_HELPTIPS:
598 // Evaluate Parameter
599 const SfxBoolItem* pOnItem = rReq.GetArg<SfxBoolItem>(SID_HELPTIPS);
600 bool bOn = pOnItem
601 ? pOnItem->GetValue()
602 : !Help::IsQuickHelpEnabled();
604 if ( bOn )
605 Help::EnableQuickHelp();
606 else
607 Help::DisableQuickHelp();
608 SvtHelpOptions().SetHelpTips( bOn );
609 Invalidate(SID_HELPTIPS);
610 bDone = true;
612 // Record if possible
613 if ( !rReq.IsAPI() )
614 rReq.AppendItem( SfxBoolItem( SID_HELPTIPS, bOn) );
615 break;
617 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
618 case SID_EXTENDEDHELP:
620 Help::StartExtHelp();
621 break;
623 case SID_HELPBALLOONS:
625 // Evaluate Parameter
626 const SfxBoolItem* pOnItem = rReq.GetArg<SfxBoolItem>(SID_HELPBALLOONS);
627 bool bOn = pOnItem
628 ? pOnItem->GetValue()
629 : !Help::IsBalloonHelpEnabled();
631 if ( bOn )
632 Help::EnableBalloonHelp();
633 else
634 Help::DisableBalloonHelp();
635 SvtHelpOptions().SetExtendedHelp( bOn );
636 Invalidate(SID_HELPBALLOONS);
637 bDone = true;
639 // Record if possible
640 if ( !rReq.IsAPI() )
641 rReq.AppendItem( SfxBoolItem( SID_HELPBALLOONS, bOn) );
642 break;
644 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
645 case SID_TIPOFTHEDAY:
647 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
648 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateTipOfTheDayDialog(rReq.GetFrameWeld()));
649 pDlg->Execute();
650 bDone = true;
651 break;
654 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
655 case SID_ABOUT:
657 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
658 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateAboutDialog(rReq.GetFrameWeld()));
659 pDlg->Execute();
660 bDone = true;
661 break;
664 case SID_TEMPLATE_MANAGER:
666 SfxTemplateManagerDlg aDialog(rReq.GetFrameWeld());
667 aDialog.run();
668 bDone = true;
669 break;
672 case SID_TEMPLATE_ADDRESSBOKSOURCE:
674 svt::AddressBookSourceDialog aDialog(rReq.GetFrameWeld(), ::comphelper::getProcessComponentContext());
675 aDialog.run();
676 bDone = true;
677 break;
680 #if HAVE_FEATURE_SCRIPTING
681 case SID_BASICSTOP:
682 StarBASIC::Stop();
683 break;
685 case SID_BASICBREAK :
686 BasicDLL::BasicBreak();
687 break;
688 #endif
690 case SID_ZOOM_50_PERCENT:
691 case SID_ZOOM_75_PERCENT:
692 case SID_ZOOM_100_PERCENT:
693 case SID_ZOOM_150_PERCENT:
694 case SID_ZOOM_200_PERCENT:
695 case SID_ZOOM_OPTIMAL:
696 case SID_ZOOM_ENTIRE_PAGE:
697 case SID_ZOOM_PAGE_WIDTH:
699 SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
700 if (!pCurrentShell)
701 return;
703 // make sure aZoom is initialized with a proper value if SetType
704 // doesn't work
705 SvxZoomItem aZoom( SvxZoomType::PERCENT, 100 );
707 switch (rReq.GetSlot())
709 case SID_ZOOM_50_PERCENT:
710 aZoom.SetValue(50);
711 break;
712 case SID_ZOOM_75_PERCENT:
713 aZoom.SetValue(75);
714 break;
715 case SID_ZOOM_100_PERCENT:
716 aZoom.SetValue(100);
717 break;
718 case SID_ZOOM_150_PERCENT:
719 aZoom.SetValue(150);
720 break;
721 case SID_ZOOM_200_PERCENT:
722 aZoom.SetValue(200);
723 break;
724 case SID_ZOOM_OPTIMAL:
725 aZoom.SetType( SvxZoomType::OPTIMAL );
726 break;
727 case SID_ZOOM_ENTIRE_PAGE:
728 aZoom.SetType( SvxZoomType::WHOLEPAGE );
729 break;
730 case SID_ZOOM_PAGE_WIDTH:
731 aZoom.SetType( SvxZoomType::PAGEWIDTH );
732 break;
735 pCurrentShell->GetDispatcher()->ExecuteList(SID_ATTR_ZOOM, SfxCallMode::ASYNCHRON, { &aZoom });
737 break;
739 case SID_TOOLBAR_MODE:
741 const SfxStringItem* pModeName = rReq.GetArg<SfxStringItem>( SID_TOOLBAR_MODE );
743 if ( !pModeName )
745 bDone = true;
746 break;
749 OUString aNewName(pModeName->GetValue());
750 uno::Reference< uno::XComponentContext > xContext =
751 ::comphelper::getProcessComponentContext();
753 // Get information about current frame and module
754 Reference<XFrame> xCurrentFrame;
755 vcl::EnumContext::Application eCurrentApp = vcl::EnumContext::Application::NONE;
756 OUString aCurrentMode;
758 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
759 if( pViewFrame )
761 xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface();
763 const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xContext );
764 eCurrentApp = vcl::EnumContext::GetApplicationEnum( xModuleManager->identify( xCurrentFrame ) );
766 OUStringBuffer aPath("org.openoffice.Office.UI.ToolbarMode/Applications/");
767 aPath.append( lcl_getAppName( eCurrentApp ) );
769 const utl::OConfigurationTreeRoot aAppNode(
770 xContext,
771 aPath.makeStringAndClear(),
772 true);
773 if ( !aAppNode.isValid() )
775 bDone = true;
776 break;
779 aCurrentMode = comphelper::getString( aAppNode.getNodeValue( "Active" ) );
781 if ( aCurrentMode == aNewName )
783 bDone = true;
784 break;
787 // Save new toolbar mode for a current module
788 aAppNode.setNodeValue( "Active", makeAny( aNewName ) );
789 aAppNode.commit();
792 // Apply settings for all frames
793 pViewFrame = SfxViewFrame::GetFirst();
794 while( pViewFrame )
796 Reference<XFrame> xFrame = pViewFrame->GetFrame().GetFrameInterface();
798 // We want to change mode only for a current app module, ignore other apps
799 const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xContext );
800 vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum( xModuleManager->identify( xFrame ) );
801 if ( eApp != eCurrentApp )
803 pViewFrame = SfxViewFrame::GetNext( *pViewFrame );
804 continue;
807 Reference<css::beans::XPropertySet> xPropSet( xFrame, UNO_QUERY );
808 Reference<css::frame::XLayoutManager> xLayoutManager;
809 if ( xPropSet.is() )
813 Any aValue = xPropSet->getPropertyValue( "LayoutManager" );
814 aValue >>= xLayoutManager;
816 catch ( const css::uno::RuntimeException& )
818 throw;
820 catch ( css::uno::Exception& )
825 if ( xLayoutManager.is() )
827 css::uno::Sequence<OUString> aMandatoryToolbars;
828 css::uno::Sequence<OUString> aUserToolbars;
829 std::vector<OUString> aBackupList;
830 OUString aSidebarMode;
832 OUStringBuffer aPath( "org.openoffice.Office.UI.ToolbarMode/Applications/" );
833 aPath.append( lcl_getAppName( eApp ) );
834 aPath.append( "/Modes" );
836 // Read mode settings
837 const utl::OConfigurationTreeRoot aModesNode(
838 xContext,
839 aPath.makeStringAndClear(),
840 true);
841 if ( !aModesNode.isValid() )
843 bDone = true;
844 break;
847 const Sequence<OUString> aModeNodeNames( aModesNode.getNodeNames() );
849 for ( const auto& rModeNodeName : aModeNodeNames )
851 const utl::OConfigurationNode aModeNode( aModesNode.openNode( rModeNodeName ) );
852 if ( !aModeNode.isValid() )
853 continue;
855 OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( "CommandArg" ) );
857 if ( aCommandArg == aNewName )
859 aMandatoryToolbars = aModeNode.getNodeValue( "Toolbars" ).get< uno::Sequence<OUString> >();
860 aUserToolbars = aModeNode.getNodeValue( "UserToolbars" ).get< uno::Sequence<OUString> >();
861 aSidebarMode = comphelper::getString( aModeNode.getNodeValue( "Sidebar" ) );
862 break;
866 // Backup visible toolbar list and hide all toolbars
867 const Sequence<Reference<XUIElement>> aUIElements = xLayoutManager->getElements();
868 for ( const Reference< XUIElement >& xUIElement : aUIElements )
870 Reference< XPropertySet > xPropertySet( xUIElement, UNO_QUERY );
871 if ( xPropertySet.is() && xUIElement.is() )
875 OUString aResName;
876 sal_Int16 nType( -1 );
877 xPropertySet->getPropertyValue( "Type" ) >>= nType;
878 xPropertySet->getPropertyValue( "ResourceURL" ) >>= aResName;
880 if (( nType == css::ui::UIElementType::TOOLBAR ) &&
881 !aResName.isEmpty() )
883 if ( xLayoutManager->isElementVisible( aResName ) )
885 aBackupList.push_back( aResName );
887 xLayoutManager->hideElement( aResName );
890 catch ( const Exception& )
896 // Show/Hide the Notebookbar
897 const SfxStringItem pItem(SID_NOTEBOOKBAR, aNewName);
898 pViewFrame->GetDispatcher()->ExecuteList(SID_NOTEBOOKBAR, SfxCallMode::SYNCHRON, {&pItem});
900 // Show toolbars
901 for ( const OUString& rName : std::as_const(aMandatoryToolbars) )
903 xLayoutManager->createElement( rName );
904 xLayoutManager->showElement( rName );
907 for ( const OUString& rName : std::as_const(aUserToolbars) )
909 xLayoutManager->createElement( rName );
910 xLayoutManager->showElement( rName );
913 // Sidebar
914 pViewFrame->ShowChildWindow( SID_SIDEBAR );
916 sfx2::sidebar::SidebarController* pSidebar =
917 sfx2::sidebar::SidebarController::GetSidebarControllerForFrame( xFrame );
918 if ( pSidebar )
920 if ( aSidebarMode == "Arrow" )
922 pSidebar->FadeOut();
924 else if ( aSidebarMode == "Tabs" )
926 pSidebar->FadeIn();
927 pSidebar->RequestOpenDeck();
928 pSidebar->RequestCloseDeck();
930 else if ( aSidebarMode == "Opened" )
932 pSidebar->FadeIn();
933 pSidebar->RequestOpenDeck();
937 // Save settings
938 if ( pViewFrame == SfxViewFrame::Current() )
940 css::uno::Sequence<OUString> aBackup( comphelper::containerToSequence(aBackupList) );
942 for ( const auto& rModeNodeName : aModeNodeNames )
944 const utl::OConfigurationNode aModeNode( aModesNode.openNode( rModeNodeName ) );
945 if ( !aModeNode.isValid() )
946 continue;
948 OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( "CommandArg" ) );
950 if ( aCommandArg == aCurrentMode )
952 aModeNode.setNodeValue( "UserToolbars", makeAny( aBackup ) );
953 break;
956 aModesNode.commit();
960 pViewFrame = SfxViewFrame::GetNext(*pViewFrame);
963 bDone = true;
964 break;
966 case SID_TOOLBAR_MODE_UI:
968 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
969 ScopedVclPtr<VclAbstractDialog> pDlg(
970 pFact->CreateToolbarmodeDialog(rReq.GetFrameWeld()));
971 pDlg->Execute();
972 bDone = true;
973 break;
975 case SID_AVAILABLE_TOOLBARS:
977 const SfxStringItem* pToolbarName = rReq.GetArg<SfxStringItem>(SID_AVAILABLE_TOOLBARS);
979 if ( pToolbarName )
981 Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
982 Reference< XFrame > xFrame = xDesktop->getActiveFrame();
984 Reference< css::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
985 Reference< css::frame::XLayoutManager > xLayoutManager;
986 if ( xPropSet.is() )
990 Any aValue = xPropSet->getPropertyValue("LayoutManager");
991 aValue >>= xLayoutManager;
993 catch ( const css::uno::RuntimeException& )
995 throw;
997 catch ( css::uno::Exception& )
1002 if ( xLayoutManager.is() )
1004 OUStringBuffer aBuf( "private:resource/toolbar/" );
1005 aBuf.append( pToolbarName->GetValue() );
1007 // Evaluate Parameter
1008 OUString aToolbarName( aBuf.makeStringAndClear() );
1009 bool bShow( !xLayoutManager->isElementVisible( aToolbarName ));
1011 if ( bShow )
1013 xLayoutManager->createElement( aToolbarName );
1014 xLayoutManager->showElement( aToolbarName );
1016 else
1017 xLayoutManager->hideElement( aToolbarName );
1021 bDone = true;
1022 break;
1024 case SID_MENUBAR:
1026 sfx2::SfxNotebookBar::ToggleMenubar();
1027 bDone = true;
1028 break;
1030 case SID_SAFE_MODE:
1032 SafeModeQueryDialog aDialog(rReq.GetFrameWeld());
1033 aDialog.run();
1034 break;
1037 default:
1038 break;
1041 if ( bDone )
1042 rReq.Done();
1045 void SfxApplication::MiscState_Impl(SfxItemSet &rSet)
1047 const sal_uInt16 *pRanges = rSet.GetRanges();
1048 DBG_ASSERT(pRanges && *pRanges, "Set without range");
1049 while ( *pRanges )
1051 for(sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
1053 switch(nWhich)
1055 case SID_TEMPLATE_ADDRESSBOKSOURCE:
1056 if ( !SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::DATABASE) )
1057 rSet.Put(SfxVisibilityItem(nWhich, false));
1058 break;
1059 case SID_QUITAPP:
1061 if ( pImpl->nDocModalMode )
1062 rSet.DisableItem(nWhich);
1063 else
1064 rSet.Put(SfxStringItem(nWhich, SfxResId(STR_QUITAPP)));
1065 break;
1068 case SID_CONFIG:
1069 case SID_TOOLBOXOPTIONS:
1070 case SID_CONFIGSTATUSBAR:
1071 case SID_CONFIGMENU:
1072 case SID_CONFIGACCEL:
1073 case SID_CONFIGEVENT:
1075 if( SvtMiscOptions().DisableUICustomization() )
1076 rSet.DisableItem(nWhich);
1077 break;
1080 #if HAVE_FEATURE_SCRIPTING
1081 case SID_BASICSTOP:
1082 if ( !StarBASIC::IsRunning() )
1083 rSet.DisableItem(nWhich);
1084 break;
1085 #endif
1087 case SID_HELPTIPS:
1089 rSet.Put( SfxBoolItem( SID_HELPTIPS, Help::IsQuickHelpEnabled() ) );
1091 break;
1092 case SID_HELPBALLOONS:
1094 rSet.Put( SfxBoolItem( SID_HELPBALLOONS, Help::IsBalloonHelpEnabled() ) );
1096 break;
1098 case SID_EXTENDEDHELP:
1101 break;
1103 case SID_CLOSEDOCS:
1105 Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
1106 Reference< XIndexAccess > xTasks = xDesktop->getFrames();
1107 if ( !xTasks.is() || !xTasks->getCount() )
1108 rSet.DisableItem(nWhich);
1109 break;
1112 case SID_SAVEDOCS:
1114 bool bModified = false;
1115 for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
1116 pObjSh;
1117 pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
1119 if ( pObjSh->IsModified() )
1121 bModified = true;
1122 break;
1126 if ( !bModified )
1127 rSet.DisableItem( nWhich );
1128 break;
1131 case SID_TEMPLATE_MANAGER:
1133 if ( !officecfg::Office::Common::Misc::ExperimentalMode::get() )
1135 rSet.DisableItem( nWhich );
1136 rSet.Put( SfxVisibilityItem( nWhich, false ) );
1139 break;
1141 case SID_ZOOM_50_PERCENT:
1142 case SID_ZOOM_75_PERCENT:
1143 case SID_ZOOM_100_PERCENT:
1144 case SID_ZOOM_150_PERCENT:
1145 case SID_ZOOM_200_PERCENT:
1146 case SID_ZOOM_OPTIMAL:
1147 case SID_ZOOM_ENTIRE_PAGE:
1148 case SID_ZOOM_PAGE_WIDTH:
1150 SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
1152 const SfxPoolItem *pItem;
1153 SfxItemState aState = pCurrentShell ?
1154 pCurrentShell->GetDispatcher()->QueryState(SID_ATTR_ZOOM, pItem) : SfxItemState::DISABLED;
1155 if ( aState == SfxItemState::DISABLED )
1156 rSet.DisableItem( nWhich );
1158 break;
1160 case SID_MENUBAR:
1162 Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
1163 Reference< XFrame > xFrame = xDesktop->getActiveFrame();
1165 Reference< css::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
1166 Reference< css::frame::XLayoutManager > xLayoutManager;
1167 if ( xPropSet.is() )
1171 Any aValue = xPropSet->getPropertyValue("LayoutManager");
1172 aValue >>= xLayoutManager;
1174 catch ( const css::uno::RuntimeException& )
1176 throw;
1178 catch ( css::uno::Exception& )
1183 if ( xLayoutManager.is() )
1185 const bool bState
1186 = xLayoutManager->getElement("private:resource/menubar/menubar").is()
1187 && xLayoutManager->isElementVisible(
1188 "private:resource/menubar/menubar");
1190 SfxBoolItem aItem( SID_MENUBAR, bState );
1191 rSet.Put( aItem );
1193 break;
1195 case SID_SAFE_MODE:
1197 // no restart in safe mode when already in safe mode
1198 if ( Application::IsSafeModeEnabled() )
1199 rSet.DisableItem( SID_SAFE_MODE );
1200 break;
1203 default:
1204 break;
1208 ++pRanges;
1212 #if HAVE_FEATURE_SCRIPTING
1214 #ifndef DISABLE_DYNLOADING
1216 typedef rtl_uString* (*basicide_choose_macro)(void*, void*, void*, sal_Bool);
1218 #else
1220 extern "C" rtl_uString* basicide_choose_macro(void*, void*, void*, sal_Bool);
1222 #endif
1224 static OUString ChooseMacro(weld::Window* pParent, const Reference<XModel>& rxLimitToDocument, const Reference<XFrame>& xDocFrame, bool bChooseOnly)
1226 #ifndef DISABLE_DYNLOADING
1227 basicide_choose_macro pSymbol = reinterpret_cast<basicide_choose_macro>(sfx2::getBasctlFunction("basicide_choose_macro"));
1228 #else
1229 #define pSymbol basicide_choose_macro
1230 #endif
1232 // call basicide_choose_macro in basctl
1233 rtl_uString* pScriptURL = pSymbol(pParent, rxLimitToDocument.get(), xDocFrame.get(), bChooseOnly);
1234 OUString aScriptURL( pScriptURL );
1235 rtl_uString_release( pScriptURL );
1236 return aScriptURL;
1238 #ifdef DISABLE_DYNLOADING
1239 #undef pSymbol
1240 #endif
1243 #endif
1245 namespace
1247 #if HAVE_FEATURE_SCRIPTING
1248 weld::Window* lcl_getDialogParent(const Reference<XFrame>& rxFrame)
1250 Reference<awt::XWindow> xContainerWindow;
1251 if (rxFrame.is())
1252 xContainerWindow = rxFrame->getContainerWindow();
1253 return Application::GetFrameWeld(xContainerWindow);
1256 SfxViewFrame* lcl_getBasicIDEViewFrame( SfxObjectShell const * i_pBasicIDE )
1258 SfxViewFrame* pView = SfxViewFrame::GetFirst( i_pBasicIDE );
1259 while ( pView )
1261 if ( pView->GetObjectShell()->GetFactory().GetDocumentServiceName() == "com.sun.star.script.BasicIDE" )
1262 break;
1263 pView = SfxViewFrame::GetNext( *pView, i_pBasicIDE );
1265 return pView;
1267 Reference< XFrame > lcl_findStartModuleFrame( const Reference<XComponentContext> & rxContext )
1271 Reference < XDesktop2 > xDesktop = Desktop::create( rxContext );
1272 Reference < XIndexAccess > xContainer( xDesktop->getFrames(), UNO_QUERY_THROW );
1274 Reference< XModuleManager2 > xCheck = ModuleManager::create(rxContext);
1276 sal_Int32 nCount = xContainer->getCount();
1277 for ( sal_Int32 i=0; i<nCount; ++i )
1281 Reference < XFrame > xFrame( xContainer->getByIndex(i), UNO_QUERY_THROW );
1282 OUString sModule = xCheck->identify( xFrame );
1283 if ( sModule == "com.sun.star.frame.StartModule" )
1284 return xFrame;
1286 catch( const UnknownModuleException& )
1288 // silence
1290 catch(const Exception&)
1292 // re-throw, caught below
1293 throw;
1297 catch( const Exception& )
1299 DBG_UNHANDLED_EXCEPTION("sfx.appl");
1301 return nullptr;
1303 #endif // HAVE_FEATURE_SCRIPTING
1306 void SfxApplication::OfaExec_Impl( SfxRequest& rReq )
1308 switch ( rReq.GetSlot() )
1310 case SID_OPTIONS_TREEDIALOG:
1312 OUString sPageURL;
1313 const SfxStringItem* pURLItem = rReq.GetArg<SfxStringItem>(SID_OPTIONS_PAGEURL);
1314 if ( pURLItem )
1315 sPageURL = pURLItem->GetValue();
1316 Reference <XFrame> xFrame(GetRequestFrame(rReq));
1317 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1318 VclPtr<VclAbstractDialog> pDlg =
1319 pFact->CreateFrameDialog(rReq.GetFrameWeld(), xFrame, rReq.GetSlot(), sPageURL );
1320 short nRet = pDlg->Execute();
1321 pDlg.disposeAndClear();
1322 SfxViewFrame* pView = SfxViewFrame::GetFirst();
1323 while ( pView )
1325 if (nRet == RET_OK)
1327 SfxObjectShell* pObjSh = pView->GetObjectShell();
1328 if (pObjSh)
1329 pObjSh->SetConfigOptionsChecked(false);
1331 pView->GetBindings().InvalidateAll(false);
1332 pView = SfxViewFrame::GetNext( *pView );
1334 break;
1337 case SID_MORE_DICTIONARIES:
1339 uno::Sequence<beans::PropertyValue> aArgs(1);
1340 aArgs[0].Name = "AdditionsTag";
1341 aArgs[0].Value <<= OUString("Dictionary");
1342 comphelper::dispatchCommand(".uno:AdditionsDialog", aArgs);
1343 break;
1345 #if HAVE_FEATURE_SCRIPTING
1346 case SID_BASICIDE_APPEAR:
1348 SfxViewFrame* pView = lcl_getBasicIDEViewFrame( nullptr );
1349 if ( !pView )
1351 SfxObjectShell* pBasicIDE = SfxObjectShell::CreateObject( "com.sun.star.script.BasicIDE" );
1352 pBasicIDE->DoInitNew();
1353 pBasicIDE->SetModified( false );
1356 // load the Basic IDE via direct access to the SFX frame loader. A generic loadComponentFromURL
1357 // (which could be done via SfxViewFrame::LoadDocumentIntoFrame) is not feasible here, since the Basic IDE
1358 // does not really play nice with the framework's concept. For instance, it is a "singleton document",
1359 // which conflicts, at the latest, with the framework's concept of loading into _blank frames.
1360 // So, since we know that our frame loader can handle it, we skip the generic framework loader
1361 // mechanism, and the type detection (which doesn't know about the Basic IDE).
1362 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1363 Reference< XSynchronousFrameLoader > xLoader(
1364 xContext->getServiceManager()->createInstanceWithContext("com.sun.star.comp.office.FrameLoader", xContext),
1365 UNO_QUERY_THROW );
1366 ::comphelper::NamedValueCollection aLoadArgs;
1367 aLoadArgs.put( "Model", pBasicIDE->GetModel() );
1368 aLoadArgs.put( "URL", OUString( "private:factory/sbasic" ) );
1370 Reference< XFrame > xTargetFrame( lcl_findStartModuleFrame( xContext ) );
1371 if ( !xTargetFrame.is() )
1372 xTargetFrame = SfxFrame::CreateBlankFrame();
1373 ENSURE_OR_THROW( xTargetFrame.is(), "could not obtain a frameto load the Basic IDE into!" );
1375 xLoader->load( aLoadArgs.getPropertyValues(), xTargetFrame );
1377 catch( const Exception& )
1379 DBG_UNHANDLED_EXCEPTION("sfx.appl");
1382 pView = lcl_getBasicIDEViewFrame( pBasicIDE );
1383 if ( pView )
1384 pView->SetName( "BASIC:1" );
1387 if ( pView )
1388 pView->GetFrame().Appear();
1390 const SfxItemSet* pArgs = rReq.GetArgs();
1391 if ( pArgs && pView )
1393 SfxViewShell* pViewShell = pView->GetViewShell();
1394 SfxObjectShell* pObjShell = pView->GetObjectShell();
1395 if ( pViewShell && pObjShell )
1397 SfxRequest aReq( SID_BASICIDE_SHOWWINDOW, SfxCallMode::SYNCHRON, pObjShell->GetPool() );
1398 aReq.SetArgs( *pArgs );
1399 pViewShell->ExecuteSlot( aReq );
1403 rReq.Done();
1405 break;
1407 case SID_BASICCHOOSER:
1409 const SfxItemSet* pArgs = rReq.GetArgs();
1410 const SfxPoolItem* pItem;
1411 bool bChooseOnly = false;
1412 Reference< XModel > xLimitToModel;
1413 if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_RECORDMACRO, false, &pItem) )
1415 bool bRecord = static_cast<const SfxBoolItem*>(pItem)->GetValue();
1416 if ( bRecord )
1418 // !Hack
1419 bChooseOnly = false;
1420 SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
1421 OSL_ENSURE( pCurrentShell, "macro recording outside an SFX document?" );
1422 if ( pCurrentShell )
1423 xLimitToModel = pCurrentShell->GetModel();
1427 Reference <XFrame> xFrame(GetRequestFrame(rReq));
1428 rReq.SetReturnValue(SfxStringItem(rReq.GetSlot(), ChooseMacro(rReq.GetFrameWeld(), xLimitToModel, xFrame, bChooseOnly)));
1429 rReq.Done();
1431 break;
1433 case SID_MACROORGANIZER:
1435 SAL_INFO("sfx.appl", "handling SID_MACROORGANIZER");
1436 const SfxItemSet* pArgs = rReq.GetArgs();
1437 const SfxPoolItem* pItem;
1438 sal_Int16 nTabId = 0;
1439 if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_MACROORGANIZER, false, &pItem) )
1441 nTabId = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
1444 SfxApplication::MacroOrganizer(rReq.GetFrameWeld(), nTabId);
1445 rReq.Done();
1447 break;
1449 case SID_RUNMACRO:
1451 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1452 SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: case ScriptOrg");
1454 Reference <XFrame> xFrame(GetRequestFrame(rReq));
1455 if ( !xFrame.is() )
1457 const SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1458 if ( pViewFrame )
1459 xFrame = pViewFrame->GetFrame().GetFrameInterface();
1462 do // artificial loop for flow control
1464 ScopedVclPtr<AbstractScriptSelectorDialog> pDlg(pFact->CreateScriptSelectorDialog(lcl_getDialogParent(xFrame), xFrame));
1465 OSL_ENSURE( pDlg, "SfxApplication::OfaExec_Impl( SID_RUNMACRO ): no dialog!" );
1466 if ( !pDlg )
1467 break;
1468 pDlg->SetRunLabel();
1470 short nDialogResult = pDlg->Execute();
1471 if ( !nDialogResult )
1472 break;
1474 Sequence< Any > args;
1475 Sequence< sal_Int16 > outIndex;
1476 Sequence< Any > outArgs;
1477 Any ret;
1479 Reference< XInterface > xScriptContext;
1481 Reference< XController > xController;
1482 if ( xFrame.is() )
1483 xController = xFrame->getController();
1484 if ( xController.is() )
1485 xScriptContext = xController->getModel();
1486 if ( !xScriptContext.is() )
1487 xScriptContext = xController;
1489 SfxObjectShell::CallXScript( xScriptContext, pDlg->GetScriptURL(), args, ret, outIndex, outArgs );
1491 while ( false );
1492 rReq.Done();
1494 break;
1496 case SID_SCRIPTORGANIZER:
1498 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1499 SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: case ScriptOrg");
1500 const SfxItemSet* pArgs = rReq.GetArgs();
1501 const SfxPoolItem* pItem;
1502 OUString aLanguage;
1503 if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_SCRIPTORGANIZER, false, &pItem) )
1505 aLanguage = static_cast<const SfxScriptOrganizerItem*>(pItem)->getLanguage();
1508 OUString aLang( aLanguage );
1509 SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: about to create dialog for: " << aLang);
1510 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSvxScriptOrgDialog(rReq.GetFrameWeld(), aLanguage));
1511 if( pDlg )
1513 pDlg->Execute();
1515 else
1517 SAL_WARN("sfx.appl", "no dialog!!!");
1519 rReq.Done();
1521 break;
1522 #endif // HAVE_FEATURE_SCRIPTING
1524 case SID_OFFICE_CHECK_PLZ:
1526 bool bRet = false;
1527 const SfxStringItem* pStringItem = rReq.GetArg<SfxStringItem>(rReq.GetSlot());
1529 if ( pStringItem )
1531 bRet = true /*!!!SfxIniManager::CheckPLZ( aPLZ )*/;
1533 #if HAVE_FEATURE_SCRIPTING
1534 else
1535 SbxBase::SetError( ERRCODE_BASIC_WRONG_ARGS );
1536 #endif
1537 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bRet ) );
1539 break;
1541 case SID_AUTO_CORRECT_DLG:
1543 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1544 SfxItemSet aSet(GetPool(), svl::Items<SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG>{});
1545 const SfxPoolItem* pItem=nullptr;
1546 const SfxItemSet* pSet = rReq.GetArgs();
1547 SfxItemPool* pSetPool = pSet ? pSet->GetPool() : nullptr;
1548 if ( pSet && pSet->GetItemState( pSetPool->GetWhich( SID_AUTO_CORRECT_DLG ), false, &pItem ) == SfxItemState::SET )
1549 aSet.Put( *pItem );
1551 const SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1552 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateAutoCorrTabDialog(pViewFrame ? pViewFrame->GetWindow().GetFrameWeld() : nullptr, &aSet));
1553 pDlg->Execute();
1555 break;
1558 case SID_NEWSD :
1560 SvtModuleOptions aModuleOpt;
1561 if ( !aModuleOpt.IsImpress() )
1563 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
1564 VclMessageType::Warning, VclButtonsType::Ok,
1565 SfxResId(STR_MODULENOTINSTALLED)));
1566 xBox->run();
1567 return;
1570 Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
1571 Reference< frame::XDispatchProvider > xProv = drawing::ModuleDispatcher::create( xContext );
1573 OUString aCmd = OUString::createFromAscii( GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName() );
1574 Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
1575 Sequence < beans::PropertyValue > aSeq;
1576 if ( rReq.GetArgs() )
1577 TransformItems( rReq.GetSlot(), *rReq.GetArgs(), aSeq );
1578 Any aResult = xHelper->executeDispatch( xProv, aCmd, OUString(), 0, aSeq );
1579 frame::DispatchResultEvent aEvent;
1580 bool bSuccess = (aResult >>= aEvent) &&
1581 (aEvent.State == frame::DispatchResultState::SUCCESS);
1582 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
1584 break;
1586 case FN_LABEL :
1587 case FN_BUSINESS_CARD :
1588 case FN_XFORMS_INIT :
1590 Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
1591 Reference< frame::XDispatchProvider > xProv = text::ModuleDispatcher::create( xContext );
1593 OUString aCmd = OUString::createFromAscii( GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName() );
1594 Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
1595 Sequence < beans::PropertyValue > aSeq;
1596 if ( rReq.GetArgs() )
1597 TransformItems( rReq.GetSlot(), *rReq.GetArgs(), aSeq );
1598 Any aResult = xHelper->executeDispatch( xProv, aCmd, OUString(), 0, aSeq );
1599 frame::DispatchResultEvent aEvent;
1600 bool bSuccess = (aResult >>= aEvent) &&
1601 (aEvent.State == frame::DispatchResultState::SUCCESS);
1602 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
1604 break;
1606 case SID_ADDRESS_DATA_SOURCE:
1610 Reference< uno::XComponentContext > xORB = ::comphelper::getProcessComponentContext();
1611 Reference< ui::dialogs::XExecutableDialog > xDialog = ui::dialogs::AddressBookSourcePilot::createWithParent(xORB, nullptr);
1612 xDialog->execute();
1614 catch(const css::uno::Exception&)
1616 DBG_UNHANDLED_EXCEPTION("sfx.appl");
1619 break;
1621 case SID_COMP_BIBLIOGRAPHY:
1622 lcl_tryLoadBibliography();
1623 break;
1627 void SfxApplication::OfaState_Impl(SfxItemSet &rSet)
1629 SvtModuleOptions aModuleOpt;
1631 if( !aModuleOpt.IsWriter())
1633 rSet.DisableItem( FN_LABEL );
1634 rSet.DisableItem( FN_BUSINESS_CARD );
1635 rSet.DisableItem( FN_XFORMS_INIT );
1637 if ( comphelper::LibreOfficeKit::isActive() )
1638 rSet.DisableItem( SID_AUTO_CORRECT_DLG );
1640 bool bMacrosDisabled
1641 = officecfg::Office::Common::Security::Scripting::DisableMacrosExecution::get();
1642 if (bMacrosDisabled)
1644 rSet.DisableItem(SID_RUNMACRO);
1645 rSet.DisableItem(SID_MACROORGANIZER);
1646 rSet.DisableItem(SID_SCRIPTORGANIZER);
1647 rSet.DisableItem(SID_BASICIDE_APPEAR);
1651 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */