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 <com/sun/star/document/XEmbeddedScripts.hpp>
21 #include <com/sun/star/drawing/ModuleDispatcher.hpp>
22 #include <com/sun/star/embed/XStorage.hpp>
23 #include <com/sun/star/embed/ElementModes.hpp>
24 #include <com/sun/star/frame/Desktop.hpp>
25 #include <com/sun/star/frame/DispatchResultEvent.hpp>
26 #include <com/sun/star/frame/DispatchResultState.hpp>
27 #include <com/sun/star/frame/DispatchHelper.hpp>
28 #include <com/sun/star/frame/XDesktop.hpp>
29 #include <com/sun/star/frame/XFramesSupplier.hpp>
30 #include <com/sun/star/frame/XLayoutManager.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/lang/IllegalArgumentException.hpp>
33 #include <com/sun/star/sdbc/DriverManager.hpp>
34 #include <com/sun/star/system/SystemShellExecute.hpp>
35 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
36 #include <com/sun/star/system/SystemShellExecuteException.hpp>
37 #include <com/sun/star/task/XJobExecutor.hpp>
38 #include <com/sun/star/text/ModuleDispatcher.hpp>
39 #include <com/sun/star/ui/dialogs/AddressBookSourcePilot.hpp>
40 #include <com/sun/star/uno/Reference.hxx>
41 #include <com/sun/star/util/XCloseable.hpp>
42 #include <com/sun/star/util/CloseVetoException.hpp>
43 #include <org/freedesktop/PackageKit/SyncDbusSessionHelper.hpp>
45 #include <com/sun/star/frame/XComponentLoader.hpp>
47 #include <comphelper/processfactory.hxx>
48 #include <comphelper/storagehelper.hxx>
50 #include <svtools/addresstemplate.hxx>
51 #include <svtools/miscopt.hxx>
52 #include <svtools/restartdialog.hxx>
53 #include <svl/visitem.hxx>
54 #include <unotools/intlwrapper.hxx>
56 #include <unotools/configmgr.hxx>
57 #include <tools/diagnose_ex.h>
58 #include <vcl/msgbox.hxx>
59 #include <svl/intitem.hxx>
60 #include <svl/eitem.hxx>
61 #include <svl/stritem.hxx>
62 #include <basic/sbstar.hxx>
63 #include <basic/basmgr.hxx>
64 #include <basic/basrdll.hxx>
65 #include <svtools/sfxecode.hxx>
66 #include <svtools/ehdl.hxx>
67 #include <vcl/help.hxx>
68 #include <vcl/stdtext.hxx>
69 #include <rtl/ustrbuf.hxx>
70 #include <osl/file.hxx>
72 #include <unotools/pathoptions.hxx>
73 #include <unotools/moduleoptions.hxx>
74 #include <svtools/helpopt.hxx>
75 #include <toolkit/helper/vclunohelper.hxx>
76 #include <tools/shl.hxx>
77 #include <unotools/bootstrap.hxx>
78 #include <rtl/bootstrap.hxx>
79 #include <cppuhelper/exc_hlp.hxx>
81 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
82 #include <com/sun/star/frame/ModuleManager.hpp>
83 #include <com/sun/star/beans/XPropertySet.hpp>
85 #include "frmload.hxx"
86 #include <sfx2/app.hxx>
87 #include <sfx2/request.hxx>
88 #include <sfx2/dispatch.hxx>
89 #include <sfx2/bindings.hxx>
90 #include <sfx2/msg.hxx>
91 #include <sfx2/objface.hxx>
92 #include <sfx2/objitem.hxx>
93 #include <sfx2/objsh.hxx>
94 #include <sfx2/hintpost.hxx>
95 #include <sfx2/viewsh.hxx>
96 #include <sfx2/docfac.hxx>
97 #include <sfx2/docfile.hxx>
98 #include <sfx2/docfilt.hxx>
99 #include <sfx2/new.hxx>
100 #include "sfxtypes.hxx"
101 #include <sfx2/tabdlg.hxx>
102 #include "arrdecl.hxx"
103 #include <sfx2/sfx.hrc>
105 #include <sfx2/passwd.hxx>
106 #include <sfx2/sfxresid.hxx>
107 #include <sfx2/childwin.hxx>
108 #include "appdata.hxx"
109 #include <sfx2/minfitem.hxx>
110 #include <sfx2/event.hxx>
111 #include <sfx2/module.hxx>
112 #include <sfx2/viewfrm.hxx>
113 #include "sfxpicklist.hxx"
114 #include "imestatuswindow.hxx"
115 #include <sfx2/sfxdlg.hxx>
116 #include <sfx2/dialogs.hrc>
117 #include "sorgitm.hxx"
118 #include <sfx2/sfxhelp.hxx>
119 #include <sfx2/zoomitem.hxx>
120 #include "templatedlg.hxx"
122 #include <officecfg/Office/Common.hxx>
123 #include <officecfg/Setup.hxx>
125 using namespace ::com::sun::star
;
126 using namespace ::com::sun::star::beans
;
127 using namespace ::com::sun::star::uno
;
128 using namespace ::com::sun::star::frame
;
129 using namespace ::com::sun::star::container
;
130 using namespace ::com::sun::star::util
;
131 using namespace ::com::sun::star::script
;
132 using namespace ::com::sun::star::system
;
133 using namespace ::com::sun::star::lang
;
134 using namespace ::com::sun::star::document
;
138 // lp#527938, debian#602953, fdo#33266, i#105408
139 static bool lcl_isBaseAvailable()
143 // if we get com::sun::star::sdbc::DriverManager, libsdbc2 is there
144 // and the bibliography is assumed to work
145 return com::sun::star::sdbc::DriverManager::create(comphelper::getProcessComponentContext()).is();
147 catch (Exception
& e
)
151 "assuming Base to be missing; caught " << e
.Message
);
155 static void lcl_tryLoadBibliography()
157 // lp#527938, debian#602953, fdo#33266, i#105408
158 // make sure we actually can instanciate services from base first
159 if(!lcl_isBaseAvailable())
163 using namespace org::freedesktop::PackageKit
;
164 using namespace svtools
;
165 Reference
< XSyncDbusSessionHelper
> xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext()));
166 Sequence
< OUString
> vPackages(1);
167 vPackages
[0] = "libreoffice-base";
168 OUString sInteraction
;
169 xSyncDbusSessionHelper
->InstallPackageNames(0, vPackages
, sInteraction
);
170 // Ill be back (hopefully)!
171 SolarMutexGuard aGuard
;
172 executeRestartDialog(comphelper::getProcessComponentContext(), NULL
, RESTART_REASON_BIBLIOGRAPHY_INSTALL
);
174 catch (const Exception
& e
)
178 "trying to install LibreOffice Base, caught " << e
.Message
);
185 SfxStringItem
aURL(SID_FILE_NAME
, OUString(".component:Bibliography/View1"));
186 SfxStringItem
aRef(SID_REFERER
, OUString("private:user"));
187 SfxStringItem
aTarget(SID_TARGETNAME
, OUString("_blank"));
188 SfxViewFrame::Current()->GetDispatcher()->Execute( SID_OPENDOC
, SFX_CALLMODE_ASYNCHRON
, &aURL
, &aRef
, &aTarget
, 0L);
190 catch (const Exception
& e
)
192 SAL_INFO( "sfx.appl",
193 "trying to load bibliography database, caught " << e
.Message
);
197 /// Find the correct location of the document (LICENSE.fodt, etc.), and return
198 /// it in rURL if found.
199 static sal_Bool
checkURL( const char *pName
, const char *pExt
, OUString
&rURL
)
202 DirectoryItem aDirItem
;
204 rURL
= "$BRAND_BASE_DIR/" + OUString::createFromAscii( pName
) +
205 OUString::createFromAscii( pExt
);
206 rtl::Bootstrap::expandMacros( rURL
);
209 return DirectoryItem::get( rURL
, aDirItem
) == DirectoryItem::E_None
;
214 /// Displays CREDITS or LICENSE in any of the available version
215 static void showDocument( const char* pBaseName
)
218 Reference
< XDesktop2
> xDesktop
= Desktop::create( ::comphelper::getProcessComponentContext() );
219 Sequence
< com::sun::star::beans::PropertyValue
> args(2);
220 args
[0].Name
= "ViewOnly";
221 args
[0].Value
<<= sal_True
;
222 args
[1].Name
= "ReadOnly";
223 args
[1].Value
<<= sal_True
;
226 if ( checkURL ( pBaseName
, ".fodt", aURL
) ||
227 checkURL ( pBaseName
, ".html", aURL
) ||
228 checkURL ( pBaseName
, "", aURL
) ) {
229 xDesktop
->loadComponentFromURL( aURL
, OUString("_blank"), 0, args
);
231 } catch (const ::com::sun::star::uno::Exception
&) {
237 class LicenseDialog
: public ModalDialog
240 DECL_LINK(ShowHdl
, void *);
242 LicenseDialog(Window
*pParent
=NULL
);
245 LicenseDialog::LicenseDialog(Window
*pParent
)
246 : ModalDialog(pParent
, "LicenseDialog", "sfx/ui/licensedialog.ui")
248 get
<PushButton
>("show")->SetClickHdl(LINK(this, LicenseDialog
, ShowHdl
));
251 IMPL_LINK_NOARG(LicenseDialog
, ShowHdl
)
254 showDocument("LICENSE");
259 void SfxApplication::MiscExec_Impl( SfxRequest
& rReq
)
262 switch ( rReq
.GetSlot() )
267 SetOptions_Impl( *rReq
.GetArgs() );
272 case SID_EXITANDRETURN
:
275 // protect against reentrant calls
276 if ( pAppData_Impl
->bInQuit
)
279 if ( rReq
.GetSlot() == SID_LOGOUT
)
281 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
282 pObjSh
; pObjSh
= SfxObjectShell::GetNext( *pObjSh
) )
284 if ( !pObjSh
->IsModified() )
287 SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( pObjSh
);
288 if ( !pFrame
|| !pFrame
->GetWindow().IsReallyVisible() )
291 if ( pObjSh
->PrepareClose(2) )
292 pObjSh
->SetModified( sal_False
);
297 SfxStringItem
aNameItem( SID_FILE_NAME
, OUString("vnd.sun.star.cmd:logout") );
298 SfxStringItem
aReferer( SID_REFERER
, "private/user" );
299 pAppData_Impl
->pAppDispat
->Execute( SID_OPENDOC
, SFX_CALLMODE_SLOT
, &aNameItem
, &aReferer
, 0L );
303 // aus verschachtelten Requests nach 100ms nochmal probieren
304 if( Application::GetDispatchLevel() > 1 )
306 /* Dont save the request for closing the application and try it later
307 again. This is an UI bound functionality ... and the user will try it again
308 if the dialog is closed. But we should not close the application automaticly
309 if this dialog is closed by the user ...
310 So we ignore this request now and wait for a new user decision.
312 OSL_TRACE( "QueryExit => sal_False (DispatchLevel == %u)", Application::GetDispatchLevel() );
316 // block reentrant calls
317 pAppData_Impl
->bInQuit
= sal_True
;
318 Reference
< XDesktop2
> xDesktop
= Desktop::create ( ::comphelper::getProcessComponentContext() );
320 rReq
.ForgetAllArgs();
322 // if terminate() failed, pAppData_Impl->bInQuit will now be sal_False, allowing further calls of SID_QUITAPP
323 sal_Bool bTerminated
= xDesktop
->terminate();
325 // if terminate() was successful, SfxApplication is now dead!
326 pAppData_Impl
->bInQuit
= sal_False
;
328 // Set return value, terminate if possible
329 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bTerminated
) );
334 case SID_TOOLBOXOPTIONS
:
335 case SID_CONFIGSTATUSBAR
:
337 case SID_CONFIGACCEL
:
338 case SID_CONFIGEVENT
:
340 SfxAbstractDialogFactory
* pFact
=
341 SfxAbstractDialogFactory::Create();
345 SFX_REQUEST_ARG(rReq
, pStringItem
,
346 SfxStringItem
, SID_CONFIG
, sal_False
);
349 GetPool(), SID_CONFIG
, SID_CONFIG
);
353 aSet
.Put( SfxStringItem(
354 SID_CONFIG
, pStringItem
->GetValue() ) );
357 Reference
< XFrame
> xFrame
;
358 const SfxItemSet
* pIntSet
= rReq
.GetInternalArgs_Impl();
359 SFX_ITEMSET_ARG( pIntSet
, pFrameItem
, SfxUnoFrameItem
, SID_FILLFRAME
, sal_False
);
361 xFrame
= pFrameItem
->GetFrame();
363 SfxAbstractTabDialog
* pDlg
= pFact
->CreateTabDialog(
364 RID_SVXDLG_CUSTOMIZE
,
365 NULL
, &aSet
, xFrame
);
369 const short nRet
= pDlg
->Execute();
384 Reference
< XDesktop2
> xDesktop
= Desktop::create( ::comphelper::getProcessComponentContext() );
385 Reference
< XIndexAccess
> xTasks( xDesktop
->getFrames(), UNO_QUERY
);
392 if ( xTasks
->getCount() <= n
)
395 Any aAny
= xTasks
->getByIndex(n
);
396 Reference
< XCloseable
> xTask
;
400 xTask
->close(sal_True
);
403 catch( CloseVetoException
& )
409 sal_Bool bOk
= ( n
== 0);
410 rReq
.SetReturnValue( SfxBoolItem( 0, bOk
) );
417 sal_Bool bOK
= sal_True
;
418 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
420 pObjSh
= SfxObjectShell::GetNext( *pObjSh
) )
422 SfxRequest
aReq( SID_SAVEDOC
, 0, pObjSh
->GetPool() );
423 if ( pObjSh
->IsModified() )
425 pObjSh
->ExecuteSlot( aReq
);
426 SfxBoolItem
*pItem
= PTR_CAST( SfxBoolItem
, aReq
.GetReturnValue() );
427 if ( !pItem
|| !pItem
->GetValue() )
432 rReq
.SetReturnValue( SfxBoolItem( 0, bOK
) );
437 case SID_SEND_FEEDBACK
:
439 OUString module
= SfxHelp::GetCurrentModuleIdentifier();
440 OUString
sURL("http://hub.libreoffice.org/send-feedback/?LOversion=" + utl::ConfigManager::getAboutBoxProductVersion() +
441 "&LOlocale=" + utl::ConfigManager::getLocale() + "&LOmodule=" + module
.copy(module
.lastIndexOf('.') + 1 ) );
444 uno::Reference
< com::sun::star::system::XSystemShellExecute
> xSystemShellExecute(
445 com::sun::star::system::SystemShellExecute::create(::comphelper::getProcessComponentContext()) );
446 xSystemShellExecute
->execute( sURL
, OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY
);
448 catch ( uno::Exception
& )
454 case SID_SHOW_LICENSE
:
456 LicenseDialog aDialog
;
461 case SID_SHOW_CREDITS
:
463 showDocument( "CREDITS" );
467 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
470 Help
* pHelp
= Application::GetHelp();
473 pHelp
->Start( OUString(".uno:HelpIndex"), NULL
); // show start page
479 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
482 // Evaluate Parameter
483 SFX_REQUEST_ARG(rReq
, pOnItem
, SfxBoolItem
, SID_HELPTIPS
, sal_False
);
485 ? ((SfxBoolItem
*)pOnItem
)->GetValue()
486 : !Help::IsQuickHelpEnabled();
489 Help::EnableQuickHelp();
491 Help::DisableQuickHelp();
492 SvtHelpOptions().SetHelpTips( bOn
);
493 Invalidate(SID_HELPTIPS
);
496 // Record if possible
498 rReq
.AppendItem( SfxBoolItem( SID_HELPTIPS
, bOn
) );
501 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
502 case SID_EXTENDEDHELP
:
504 Help::StartExtHelp();
507 case SID_HELPBALLOONS
:
509 // Evaluate Parameter
510 SFX_REQUEST_ARG(rReq
, pOnItem
, SfxBoolItem
, SID_HELPBALLOONS
, sal_False
);
512 ? ((SfxBoolItem
*)pOnItem
)->GetValue()
513 : !Help::IsBalloonHelpEnabled();
516 Help::EnableBalloonHelp();
518 Help::DisableBalloonHelp();
519 SvtHelpOptions().SetExtendedHelp( bOn
);
520 Invalidate(SID_HELPBALLOONS
);
523 // Record if possible
525 rReq
.AppendItem( SfxBoolItem( SID_HELPBALLOONS
, bOn
) );
529 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
532 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
535 VclAbstractDialog
* pDlg
= pFact
->CreateVclDialog( 0, RID_DEFAULTABOUT
);
543 case SID_TEMPLATE_MANAGER
:
545 SfxTemplateManagerDlg dlg
;
551 case SID_TEMPLATE_ADDRESSBOKSOURCE
:
553 svt::AddressBookSourceDialog
aDialog(GetTopWindow(), ::comphelper::getProcessComponentContext());
559 #ifndef DISABLE_SCRIPTING
564 case SID_BASICBREAK
:
565 BASIC_DLL()->BasicBreak();
577 case SID_SHOW_IME_STATUS_WINDOW
:
578 if (pAppData_Impl
->m_xImeStatusWindow
->canToggle())
580 SfxBoolItem
const * pItem
= static_cast< SfxBoolItem
const * >(
581 rReq
.GetArg(SID_SHOW_IME_STATUS_WINDOW
, false,
583 bool bShow
= pItem
== 0
584 ? !pAppData_Impl
->m_xImeStatusWindow
->isShowing()
585 : ( pItem
->GetValue() == sal_True
);
586 pAppData_Impl
->m_xImeStatusWindow
->show(bShow
);
588 rReq
.AppendItem(SfxBoolItem(SID_SHOW_IME_STATUS_WINDOW
,
594 case SID_ZOOM_50_PERCENT
:
595 case SID_ZOOM_75_PERCENT
:
596 case SID_ZOOM_100_PERCENT
:
597 case SID_ZOOM_150_PERCENT
:
598 case SID_ZOOM_200_PERCENT
:
599 case SID_ZOOM_OPTIMAL
:
600 case SID_ZOOM_ENTIRE_PAGE
:
601 case SID_ZOOM_PAGE_WIDTH
:
603 SfxObjectShell
* pCurrentShell
= SfxObjectShell::Current();
607 // make sure aZoom is initialized with a proper value if SetType
609 SvxZoomItem
aZoom( SVX_ZOOM_PERCENT
, 100 );
611 switch (rReq
.GetSlot())
613 case SID_ZOOM_50_PERCENT
:
616 case SID_ZOOM_75_PERCENT
:
619 case SID_ZOOM_100_PERCENT
:
622 case SID_ZOOM_150_PERCENT
:
625 case SID_ZOOM_200_PERCENT
:
628 case SID_ZOOM_OPTIMAL
:
629 aZoom
.SetType( SVX_ZOOM_OPTIMAL
);
631 case SID_ZOOM_ENTIRE_PAGE
:
632 aZoom
.SetType( SVX_ZOOM_WHOLEPAGE
);
634 case SID_ZOOM_PAGE_WIDTH
:
635 aZoom
.SetType( SVX_ZOOM_PAGEWIDTH
);
639 pCurrentShell
->GetDispatcher()->Execute(SID_ATTR_ZOOM
, SFX_CALLMODE_ASYNCHRON
, &aZoom
, 0L);
643 case SID_AVAILABLE_TOOLBARS
:
645 SfxStringItem
const * pToolbarName
= static_cast< SfxStringItem
const *>(
646 rReq
.GetArg(SID_AVAILABLE_TOOLBARS
, false, TYPE(SfxStringItem
)));
650 Reference
< XDesktop2
> xDesktop
= Desktop::create ( ::comphelper::getProcessComponentContext() );
651 Reference
< XFrame
> xFrame
= xDesktop
->getActiveFrame();
653 Reference
< com::sun::star::beans::XPropertySet
> xPropSet( xFrame
, UNO_QUERY
);
654 Reference
< ::com::sun::star::frame::XLayoutManager
> xLayoutManager
;
659 Any aValue
= xPropSet
->getPropertyValue("LayoutManager");
660 aValue
>>= xLayoutManager
;
662 catch ( const ::com::sun::star::uno::RuntimeException
& )
666 catch ( ::com::sun::star::uno::Exception
& )
671 if ( xLayoutManager
.is() )
673 OUString
aToolbarResName( "private:resource/toolbar/" );
674 OUStringBuffer
aBuf( aToolbarResName
);
675 aBuf
.append( pToolbarName
->GetValue() );
677 // Evaluate Parameter
678 OUString
aToolbarName( aBuf
.makeStringAndClear() );
679 sal_Bool
bShow( !xLayoutManager
->isElementVisible( aToolbarName
));
683 xLayoutManager
->createElement( aToolbarName
);
684 xLayoutManager
->showElement( aToolbarName
);
687 xLayoutManager
->hideElement( aToolbarName
);
703 //--------------------------------------------------------------------
705 void SfxApplication::MiscState_Impl(SfxItemSet
&rSet
)
707 const sal_uInt16
*pRanges
= rSet
.GetRanges();
708 DBG_ASSERT(pRanges
&& *pRanges
, "Set without range");
711 for(sal_uInt16 nWhich
= *pRanges
++; nWhich
<= *pRanges
; ++nWhich
)
715 case SID_TEMPLATE_ADDRESSBOKSOURCE
:
716 if ( !SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE
) )
717 rSet
.Put(SfxVisibilityItem(nWhich
, sal_False
));
719 case SID_EXITANDRETURN
:
722 if ( pAppData_Impl
->nDocModalMode
)
723 rSet
.DisableItem(nWhich
);
725 rSet
.Put(SfxStringItem(nWhich
, SfxResId(STR_QUITAPP
).toString()));
730 case SID_TOOLBOXOPTIONS
:
731 case SID_CONFIGSTATUSBAR
:
733 case SID_CONFIGACCEL
:
734 case SID_CONFIGEVENT
:
736 if( SvtMiscOptions().DisableUICustomization() )
737 rSet
.DisableItem(nWhich
);
741 #ifndef DISABLE_SCRIPTING
743 if ( !StarBASIC::IsRunning() )
744 rSet
.DisableItem(nWhich
);
750 rSet
.Put( SfxBoolItem( SID_HELPTIPS
, Help::IsQuickHelpEnabled() ) );
753 case SID_HELPBALLOONS
:
755 rSet
.Put( SfxBoolItem( SID_HELPBALLOONS
, Help::IsBalloonHelpEnabled() ) );
759 case SID_EXTENDEDHELP
:
767 Reference
< XDesktop2
> xDesktop
= Desktop::create( ::comphelper::getProcessComponentContext() );
768 Reference
< XIndexAccess
> xTasks( xDesktop
->getFrames(), UNO_QUERY
);
769 if ( !xTasks
.is() || !xTasks
->getCount() )
770 rSet
.DisableItem(nWhich
);
776 sal_Bool bModified
= sal_False
;
777 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
779 pObjSh
= SfxObjectShell::GetNext( *pObjSh
) )
781 if ( pObjSh
->IsModified() )
783 bModified
= sal_True
;
789 rSet
.DisableItem( nWhich
);
793 case SID_SHOW_IME_STATUS_WINDOW
:
794 if (pAppData_Impl
->m_xImeStatusWindow
->canToggle())
795 rSet
.Put(SfxBoolItem(
796 SID_SHOW_IME_STATUS_WINDOW
,
797 pAppData_Impl
->m_xImeStatusWindow
->
800 rSet
.DisableItem(SID_SHOW_IME_STATUS_WINDOW
);
803 case SID_TEMPLATE_MANAGER
:
805 SvtMiscOptions aMiscOptions
;
806 if ( !aMiscOptions
.IsExperimentalMode() )
808 rSet
.DisableItem( nWhich
);
809 rSet
.Put( SfxVisibilityItem( nWhich
, sal_False
) );
814 case SID_ZOOM_50_PERCENT
:
815 case SID_ZOOM_75_PERCENT
:
816 case SID_ZOOM_100_PERCENT
:
817 case SID_ZOOM_150_PERCENT
:
818 case SID_ZOOM_200_PERCENT
:
819 case SID_ZOOM_OPTIMAL
:
820 case SID_ZOOM_ENTIRE_PAGE
:
821 case SID_ZOOM_PAGE_WIDTH
:
823 SfxObjectShell
* pCurrentShell
= SfxObjectShell::Current();
825 const SfxPoolItem
*pItem
;
826 SfxItemState aState
= pCurrentShell
?
827 pCurrentShell
->GetDispatcher()->QueryState(SID_ATTR_ZOOM
, pItem
) : SFX_ITEM_DISABLED
;
828 if ( aState
== SFX_ITEM_DISABLED
)
829 rSet
.DisableItem( nWhich
);
842 #ifndef DISABLE_SCRIPTING
844 #ifndef DISABLE_DYNLOADING
846 typedef rtl_uString
* (SAL_CALL
*basicide_choose_macro
)(XModel
*, sal_Bool
, rtl_uString
*);
847 typedef void (SAL_CALL
*basicide_macro_organizer
)( sal_Int16
);
849 extern "C" { static void SAL_CALL
thisModule() {} }
853 extern "C" rtl_uString
* basicide_choose_macro(XModel
*, sal_Bool
, rtl_uString
*);
854 extern "C" void basicide_macro_organizer( sal_Int16
);
858 OUString
ChooseMacro( const Reference
< XModel
>& rxLimitToDocument
, sal_Bool bChooseOnly
, const OUString
& rMacroDesc
= OUString() )
860 #ifndef DISABLE_DYNLOADING
861 // get basctl dllname
862 static OUString
aLibName( SVLIBRARY( "basctl" ) );
865 oslModule handleMod
= osl_loadModuleRelative(
866 &thisModule
, aLibName
.pData
, 0 );
869 OUString
aSymbol( "basicide_choose_macro" );
870 basicide_choose_macro pSymbol
= (basicide_choose_macro
) osl_getFunctionSymbol( handleMod
, aSymbol
.pData
);
872 #define pSymbol basicide_choose_macro
875 // call basicide_choose_macro in basctl
876 rtl_uString
* pScriptURL
= pSymbol( rxLimitToDocument
.get(), bChooseOnly
, rMacroDesc
.pData
);
877 OUString
aScriptURL( pScriptURL
);
878 rtl_uString_release( pScriptURL
);
881 #ifdef DISABLE_DYNLOADING
886 void MacroOrganizer( sal_Int16 nTabId
)
888 #ifndef DISABLE_DYNLOADING
889 // get basctl dllname
890 static OUString
aLibName( SVLIBRARY( "basctl" ) );
893 oslModule handleMod
= osl_loadModuleRelative(
894 &thisModule
, aLibName
.pData
, 0 );
897 OUString
aSymbol( "basicide_macro_organizer" );
898 basicide_macro_organizer pSymbol
= (basicide_macro_organizer
) osl_getFunctionSymbol( handleMod
, aSymbol
.pData
);
899 // call basicide_macro_organizer in basctl
902 basicide_macro_organizer( nTabId
);
910 #define RID_ERRBOX_MODULENOTINSTALLED (RID_OFA_START + 72)
912 ResMgr
* SfxApplication::GetOffResManager_Impl()
914 if ( !pAppData_Impl
->pOfaResMgr
)
915 pAppData_Impl
->pOfaResMgr
= CreateResManager( "ofa");
916 return pAppData_Impl
->pOfaResMgr
;
921 #ifndef DISABLE_SCRIPTING
922 Window
* lcl_getDialogParent( const Reference
< XFrame
>& _rxFrame
, Window
* _pFallback
)
924 if ( !_rxFrame
.is() )
929 Reference
< awt::XWindow
> xContainerWindow( _rxFrame
->getContainerWindow(), UNO_SET_THROW
);
930 Window
* pWindow
= VCLUnoHelper::GetWindow( xContainerWindow
);
931 OSL_ENSURE( pWindow
, "lcl_getDialogParent: cool, somebody implemented a VCL-less toolkit!" );
934 return pWindow
->GetSystemWindow();
936 catch( const Exception
& )
938 DBG_UNHANDLED_EXCEPTION();
943 const OUString
& lcl_getBasicIDEServiceName()
945 static const OUString
s_sBasicName( "com.sun.star.script.BasicIDE" );
949 SfxViewFrame
* lcl_getBasicIDEViewFrame( SfxObjectShell
* i_pBasicIDE
)
951 SfxViewFrame
* pView
= SfxViewFrame::GetFirst( i_pBasicIDE
);
954 if ( pView
->GetObjectShell()->GetFactory().GetDocumentServiceName() == lcl_getBasicIDEServiceName() )
956 pView
= SfxViewFrame::GetNext( *pView
, i_pBasicIDE
);
960 Reference
< XFrame
> lcl_findStartModuleFrame( const Reference
<XComponentContext
> & rxContext
)
964 Reference
< XDesktop2
> xDesktop
= Desktop::create( rxContext
);
965 Reference
< XIndexAccess
> xContainer( xDesktop
->getFrames(), UNO_QUERY_THROW
);
967 Reference
< XModuleManager2
> xCheck
= ModuleManager::create(rxContext
);
969 sal_Int32 nCount
= xContainer
->getCount();
970 for ( sal_Int32 i
=0; i
<nCount
; ++i
)
974 Reference
< XFrame
> xFrame( xContainer
->getByIndex(i
), UNO_QUERY_THROW
);
975 OUString sModule
= xCheck
->identify( xFrame
);
976 if ( sModule
== "com.sun.star.frame.StartModule" )
979 catch( const UnknownModuleException
& )
983 catch(const Exception
&)
985 // re-throw, caught below
990 catch( const Exception
& )
992 DBG_UNHANDLED_EXCEPTION();
996 #endif // !DISABLE_SCRIPTING
999 void SfxApplication::OfaExec_Impl( SfxRequest
& rReq
)
1001 switch ( rReq
.GetSlot() )
1003 case SID_OPTIONS_TREEDIALOG
:
1006 SFX_REQUEST_ARG( rReq
, pURLItem
, SfxStringItem
, SID_OPTIONS_PAGEURL
, sal_False
);
1008 sPageURL
= pURLItem
->GetValue();
1009 const SfxItemSet
* pArgs
= rReq
.GetInternalArgs_Impl();
1010 const SfxPoolItem
* pItem
= NULL
;
1011 Reference
< XFrame
> xFrame
;
1012 if ( pArgs
&& pArgs
->GetItemState( SID_FILLFRAME
, sal_False
, &pItem
) == SFX_ITEM_SET
)
1014 OSL_ENSURE( pItem
->ISA( SfxUnoFrameItem
), "SfxApplication::OfaExec_Impl: XFrames are to be transported via SfxUnoFrameItem by now!" );
1015 xFrame
= static_cast< const SfxUnoFrameItem
*>( pItem
)->GetFrame();
1017 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1020 VclAbstractDialog
* pDlg
=
1021 pFact
->CreateFrameDialog( NULL
, xFrame
, rReq
.GetSlot(), sPageURL
);
1022 short nRet
= pDlg
->Execute();
1024 SfxViewFrame
* pView
= SfxViewFrame::GetFirst();
1029 SfxObjectShell
* pObjSh
= pView
->GetObjectShell();
1031 pObjSh
->SetConfigOptionsChecked(false);
1033 pView
->GetBindings().InvalidateAll(sal_False
);
1034 pView
= SfxViewFrame::GetNext( *pView
);
1040 case SID_MORE_DICTIONARIES
:
1044 uno::Reference
< uno::XComponentContext
> xContext
=
1045 ::comphelper::getProcessComponentContext();
1046 uno::Reference
< css::system::XSystemShellExecute
> xSystemShell(
1047 css::system::SystemShellExecute::create(xContext
) );
1049 // read repository URL from configuration
1050 OUString
sTemplRepoURL(officecfg::Office::Common::Dictionaries::RepositoryURL::get());
1052 if ( xSystemShell
.is() && !sTemplRepoURL
.isEmpty() )
1054 OUStringBuffer
aURLBuf( sTemplRepoURL
);
1055 aURLBuf
.append("?lang=");
1057 // read locale from configuration
1058 OUString
sLocale(officecfg::Setup::L10N::ooLocale::get());
1059 if (sLocale
.isEmpty())
1062 aURLBuf
.append( sLocale
);
1063 xSystemShell
->execute(
1064 aURLBuf
.makeStringAndClear(),
1066 css::system::SystemShellExecuteFlags::URIS_ONLY
);
1069 catch( const ::com::sun::star::uno::Exception
& )
1071 SAL_WARN( "sfx.appl", "SfxApplication::OfaExec_Impl(SID_MORE_DICTIONARIES): caught an exception!" );
1075 #ifndef DISABLE_SCRIPTING
1076 case SID_BASICIDE_APPEAR
:
1078 SfxViewFrame
* pView
= lcl_getBasicIDEViewFrame( NULL
);
1081 SfxObjectShell
* pBasicIDE
= SfxObjectShell::CreateObject( lcl_getBasicIDEServiceName() );
1082 pBasicIDE
->DoInitNew( 0 );
1083 pBasicIDE
->SetModified( sal_False
);
1086 // load the Basic IDE via direct access to the SFX frame loader. A generic loadComponentFromURL
1087 // (which could be done via SfxViewFrame::LoadDocumentIntoFrame) is not feasible here, since the Basic IDE
1088 // does not really play nice with the framework's concept. For instance, it is a "singleton document",
1089 // which conflicts, at the latest, with the framework's concept of loading into _blank frames.
1090 // So, since we know that our frame loader can handle it, we skip the generic framework loader
1091 // mechanism, and the type detection (which doesn't know about the Basic IDE).
1092 Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
1093 Reference
< XSynchronousFrameLoader
> xLoader(
1094 xContext
->getServiceManager()->createInstanceWithContext(SfxFrameLoader_Impl::impl_getStaticImplementationName(), xContext
),
1096 ::comphelper::NamedValueCollection aLoadArgs
;
1097 aLoadArgs
.put( "Model", pBasicIDE
->GetModel() );
1098 aLoadArgs
.put( "URL", OUString( "private:factory/sbasic" ) );
1100 Reference
< XFrame
> xTargetFrame( lcl_findStartModuleFrame( xContext
) );
1101 if ( !xTargetFrame
.is() )
1102 xTargetFrame
= SfxFrame::CreateBlankFrame();
1103 ENSURE_OR_THROW( xTargetFrame
.is(), "could not obtain a frameto load the Basic IDE into!" );
1105 xLoader
->load( aLoadArgs
.getPropertyValues(), xTargetFrame
);
1107 catch( const Exception
& )
1109 DBG_UNHANDLED_EXCEPTION();
1112 pView
= lcl_getBasicIDEViewFrame( pBasicIDE
);
1114 pView
->SetName( OUString( "BASIC:1" ) );
1118 pView
->GetFrame().Appear();
1120 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1121 if ( pArgs
&& pView
)
1123 SfxViewShell
* pViewShell
= pView
->GetViewShell();
1124 SfxObjectShell
* pObjShell
= pView
->GetObjectShell();
1125 if ( pViewShell
&& pObjShell
)
1127 SfxRequest
aReq( SID_BASICIDE_SHOWWINDOW
, SFX_CALLMODE_SYNCHRON
, pObjShell
->GetPool() );
1128 aReq
.SetArgs( *pArgs
);
1129 pViewShell
->ExecuteSlot( aReq
);
1137 case SID_BASICCHOOSER
:
1139 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1140 const SfxPoolItem
* pItem
;
1141 sal_Bool bChooseOnly
= sal_False
;
1142 Reference
< XModel
> xLimitToModel
;
1143 if(pArgs
&& SFX_ITEM_SET
== pArgs
->GetItemState(SID_RECORDMACRO
, sal_False
, &pItem
) )
1145 sal_Bool bRecord
= ((SfxBoolItem
*)pItem
)->GetValue();
1149 bChooseOnly
= sal_False
;
1150 SfxObjectShell
* pCurrentShell
= SfxObjectShell::Current();
1151 OSL_ENSURE( pCurrentShell
, "macro recording outside an SFX document?" );
1152 if ( pCurrentShell
)
1153 xLimitToModel
= pCurrentShell
->GetModel();
1157 rReq
.SetReturnValue( SfxStringItem( rReq
.GetSlot(), ChooseMacro( xLimitToModel
, bChooseOnly
) ) );
1162 case SID_MACROORGANIZER
:
1164 OSL_TRACE("handling SID_MACROORGANIZER");
1165 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1166 const SfxPoolItem
* pItem
;
1167 sal_Int16 nTabId
= 0;
1168 if(pArgs
&& SFX_ITEM_SET
== pArgs
->GetItemState(SID_MACROORGANIZER
, sal_False
, &pItem
) )
1170 nTabId
= ((SfxUInt16Item
*)pItem
)->GetValue();
1173 SfxApplication::MacroOrganizer( nTabId
);
1180 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1181 OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
1183 Reference
< XFrame
> xFrame
;
1184 const SfxItemSet
* pIntSet
= rReq
.GetInternalArgs_Impl();
1185 SFX_ITEMSET_ARG( pIntSet
, pFrameItem
, SfxUnoFrameItem
, SID_FILLFRAME
, sal_False
);
1187 xFrame
= pFrameItem
->GetFrame();
1191 const SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
1193 xFrame
= pViewFrame
->GetFrame().GetFrameInterface();
1196 do // artificial loop for flow control
1198 AbstractScriptSelectorDialog
* pDlg
= pFact
->CreateScriptSelectorDialog(
1199 lcl_getDialogParent( xFrame
, GetTopWindow() ), sal_False
, xFrame
);
1200 OSL_ENSURE( pDlg
, "SfxApplication::OfaExec_Impl( SID_RUNMACRO ): no dialog!" );
1203 pDlg
->SetRunLabel();
1205 short nDialogResult
= pDlg
->Execute();
1206 if ( !nDialogResult
)
1212 Sequence
< Any
> args
;
1213 Sequence
< sal_Int16
> outIndex
;
1214 Sequence
< Any
> outArgs
;
1217 Reference
< XInterface
> xScriptContext
;
1219 Reference
< XController
> xController
;
1221 xController
= xFrame
->getController();
1222 if ( xController
.is() )
1223 xScriptContext
= xController
->getModel();
1224 if ( !xScriptContext
.is() )
1225 xScriptContext
= xController
;
1227 SfxObjectShell::CallXScript( xScriptContext
, pDlg
->GetScriptURL(), args
, ret
, outIndex
, outArgs
);
1235 case SID_SCRIPTORGANIZER
:
1237 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1238 OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
1239 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1240 const SfxPoolItem
* pItem
;
1242 if(pArgs
&& SFX_ITEM_SET
== pArgs
->GetItemState(SID_SCRIPTORGANIZER
, sal_False
, &pItem
) )
1244 aLanguage
= ((SfxScriptOrganizerItem
*)pItem
)->getLanguage();
1247 OUString
aLang( aLanguage
);
1248 OSL_TRACE("SfxApplication::OfaExec_Impl: about to create dialog for: %s", OUStringToOString( aLang
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
1249 // not sure about the Window*
1250 VclAbstractDialog
* pDlg
= pFact
->CreateSvxScriptOrgDialog( GetTopWindow(), aLanguage
);
1258 OSL_TRACE("no dialog!!!");
1263 #endif // !DISABLE_SCRIPTING
1265 case SID_OFFICE_CHECK_PLZ
:
1267 sal_Bool bRet
= sal_False
;
1268 SFX_REQUEST_ARG(rReq
, pStringItem
, SfxStringItem
, rReq
.GetSlot(), sal_False
);
1272 bRet
= sal_True
/*!!!SfxIniManager::CheckPLZ( aPLZ )*/;
1274 #ifndef DISABLE_SCRIPTING
1276 SbxBase::SetError( SbxERR_WRONG_ARGS
);
1278 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bRet
) );
1282 case SID_AUTO_CORRECT_DLG
:
1284 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1287 SfxItemSet
aSet(GetPool(), SID_AUTO_CORRECT_DLG
, SID_AUTO_CORRECT_DLG
);
1288 const SfxPoolItem
* pItem
=NULL
;
1289 const SfxItemSet
* pSet
= rReq
.GetArgs();
1290 SfxItemPool
* pSetPool
= pSet
? pSet
->GetPool() : NULL
;
1291 if ( pSet
&& pSet
->GetItemState( pSetPool
->GetWhich( SID_AUTO_CORRECT_DLG
), sal_False
, &pItem
) == SFX_ITEM_SET
)
1294 SfxAbstractTabDialog
* pDlg
= pFact
->CreateTabDialog( RID_OFA_AUTOCORR_DLG
, NULL
, &aSet
, NULL
);
1302 case SID_SD_AUTOPILOT
:
1305 SvtModuleOptions aModuleOpt
;
1306 if ( !aModuleOpt
.IsImpress() )
1308 ErrorBox( 0, ResId( RID_ERRBOX_MODULENOTINSTALLED
, *GetOffResManager_Impl() )).Execute();
1312 Reference
< uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
1313 Reference
< frame::XDispatchProvider
> xProv
= drawing::ModuleDispatcher::create( xContext
);
1315 OUString aCmd
= OUString::createFromAscii( GetInterface()->GetSlot( rReq
.GetSlot() )->GetUnoName() );
1316 Reference
< frame::XDispatchHelper
> xHelper( frame::DispatchHelper::create(xContext
) );
1317 Sequence
< beans::PropertyValue
> aSeq
;
1318 if ( rReq
.GetArgs() )
1319 TransformItems( rReq
.GetSlot(), *rReq
.GetArgs(), aSeq
);
1320 Any aResult
= xHelper
->executeDispatch( xProv
, aCmd
, OUString(), 0, aSeq
);
1321 frame::DispatchResultEvent aEvent
;
1322 sal_Bool bSuccess
= (aResult
>>= aEvent
) &&
1323 (aEvent
.State
== frame::DispatchResultState::SUCCESS
);
1324 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bSuccess
) );
1329 case FN_BUSINESS_CARD
:
1330 case FN_XFORMS_INIT
:
1332 Reference
< uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
1333 Reference
< frame::XDispatchProvider
> xProv
= text::ModuleDispatcher::create( xContext
);
1335 OUString aCmd
= OUString::createFromAscii( GetInterface()->GetSlot( rReq
.GetSlot() )->GetUnoName() );
1336 Reference
< frame::XDispatchHelper
> xHelper( frame::DispatchHelper::create(xContext
) );
1337 Sequence
< beans::PropertyValue
> aSeq
;
1338 if ( rReq
.GetArgs() )
1339 TransformItems( rReq
.GetSlot(), *rReq
.GetArgs(), aSeq
);
1340 Any aResult
= xHelper
->executeDispatch( xProv
, aCmd
, OUString(), 0, aSeq
);
1341 frame::DispatchResultEvent aEvent
;
1342 sal_Bool bSuccess
= (aResult
>>= aEvent
) &&
1343 (aEvent
.State
== frame::DispatchResultState::SUCCESS
);
1344 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bSuccess
) );
1348 case SID_ADDRESS_DATA_SOURCE
:
1352 Reference
< uno::XComponentContext
> xORB
= ::comphelper::getProcessComponentContext();
1353 Reference
< ui::dialogs::XExecutableDialog
> xDialog
;
1354 xDialog
= ui::dialogs::AddressBookSourcePilot::createWithParent(xORB
, 0);
1357 catch(const ::com::sun::star::uno::Exception
&)
1359 DBG_UNHANDLED_EXCEPTION();
1364 case SID_COMP_BIBLIOGRAPHY
:
1365 lcl_tryLoadBibliography();
1370 void SfxApplication::OfaState_Impl(SfxItemSet
&rSet
)
1372 SvtModuleOptions aModuleOpt
;
1374 if( !aModuleOpt
.IsWriter())
1376 rSet
.DisableItem( FN_LABEL
);
1377 rSet
.DisableItem( FN_BUSINESS_CARD
);
1378 rSet
.DisableItem( FN_XFORMS_INIT
);
1381 if ( !aModuleOpt
.IsImpress() )
1382 rSet
.DisableItem( SID_SD_AUTOPILOT
);
1385 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */