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>
49 #include "comphelper/configurationhelper.hxx"
51 #include <svtools/addresstemplate.hxx>
52 #include <svtools/miscopt.hxx>
53 #include <svtools/restartdialog.hxx>
54 #include <svl/visitem.hxx>
55 #include <unotools/intlwrapper.hxx>
57 #include <unotools/configmgr.hxx>
58 #include <tools/diagnose_ex.h>
59 #include <vcl/msgbox.hxx>
60 #include <svl/intitem.hxx>
61 #include <svl/eitem.hxx>
62 #include <svl/stritem.hxx>
63 #include <basic/sbstar.hxx>
64 #include <basic/basmgr.hxx>
65 #include <basic/basrdll.hxx>
66 #include <svtools/sfxecode.hxx>
67 #include <svtools/ehdl.hxx>
68 #include <vcl/help.hxx>
69 #include <vcl/stdtext.hxx>
70 #include <rtl/ustrbuf.hxx>
71 #include <osl/file.hxx>
73 #include <unotools/pathoptions.hxx>
74 #include <unotools/moduleoptions.hxx>
75 #include <svtools/helpopt.hxx>
76 #include <toolkit/helper/vclunohelper.hxx>
77 #include <tools/shl.hxx>
78 #include <unotools/bootstrap.hxx>
79 #include <rtl/bootstrap.hxx>
80 #include <cppuhelper/exc_hlp.hxx>
82 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
83 #include <com/sun/star/frame/ModuleManager.hpp>
84 #include <com/sun/star/beans/XPropertySet.hpp>
86 #include "frmload.hxx"
87 #include "referers.hxx"
88 #include <sfx2/app.hxx>
89 #include <sfx2/request.hxx>
90 #include <sfx2/dispatch.hxx>
91 #include <sfx2/bindings.hxx>
92 #include <sfx2/msg.hxx>
93 #include <sfx2/objface.hxx>
94 #include <sfx2/objitem.hxx>
95 #include <sfx2/objsh.hxx>
96 #include <sfx2/hintpost.hxx>
97 #include <sfx2/viewsh.hxx>
98 #include <sfx2/docfac.hxx>
99 #include <sfx2/docfile.hxx>
100 #include <sfx2/docfilt.hxx>
101 #include <sfx2/new.hxx>
102 #include "sfxtypes.hxx"
103 #include <sfx2/tabdlg.hxx>
104 #include "arrdecl.hxx"
105 #include "fltfnc.hxx"
106 #include <sfx2/sfx.hrc>
108 #include <sfx2/passwd.hxx>
109 #include "sfx2/sfxresid.hxx"
110 #include <sfx2/childwin.hxx>
111 #include "appdata.hxx"
112 #include "sfx2/minfitem.hxx"
113 #include <sfx2/event.hxx>
114 #include <sfx2/module.hxx>
115 #include <sfx2/viewfrm.hxx>
116 #include "sfxpicklist.hxx"
117 #include "imestatuswindow.hxx"
118 #include <sfx2/sfxdlg.hxx>
119 #include <sfx2/dialogs.hrc>
120 #include "sorgitm.hxx"
121 #include "sfx2/sfxhelp.hxx"
122 #include <sfx2/zoomitem.hxx>
123 #include "templatedlg.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( "sfx2.appl",
193 "trying to load bibliography database, caught " << e
.Message
);
197 /// Find the correct location of the document (LICENSE.odt, 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
= OUString( "$BRAND_BASE_DIR/" );
205 rURL
+= OUString::createFromAscii( pName
);
206 rURL
+= OUString::createFromAscii( pExt
);
207 rtl::Bootstrap::expandMacros( rURL
);
210 return DirectoryItem::get( rURL
, aDirItem
) == DirectoryItem::E_None
;
215 /// Displays CREDITS or LICENSE in any of the available version
216 static void showDocument( const char* pBaseName
)
219 Reference
< XDesktop2
> xDesktop
= Desktop::create( ::comphelper::getProcessComponentContext() );
220 Sequence
< com::sun::star::beans::PropertyValue
> args(2);
221 args
[0].Name
= OUString("ViewOnly");
222 args
[0].Value
<<= sal_True
;
223 args
[1].Name
= OUString("ReadOnly");
224 args
[1].Value
<<= sal_True
;
227 if ( checkURL ( pBaseName
, ".odt", aURL
) ||
228 checkURL ( pBaseName
, ".html", aURL
) ||
229 checkURL ( pBaseName
, "", aURL
) ) {
230 xDesktop
->loadComponentFromURL( aURL
, OUString("_blank"), 0, args
);
232 } catch (const ::com::sun::star::uno::Exception
&) {
238 class LicenseDialog
: public ModalDialog
241 DECL_LINK(ShowHdl
, void *);
243 LicenseDialog(Window
*pParent
=NULL
);
246 LicenseDialog::LicenseDialog(Window
*pParent
)
247 : ModalDialog(pParent
, "LicenseDialog", "sfx/ui/licensedialog.ui")
249 get
<PushButton
>("show")->SetClickHdl(LINK(this, LicenseDialog
, ShowHdl
));
252 IMPL_LINK_NOARG(LicenseDialog
, ShowHdl
)
255 showDocument("LICENSE");
260 void SfxApplication::MiscExec_Impl( SfxRequest
& rReq
)
263 switch ( rReq
.GetSlot() )
268 SetOptions_Impl( *rReq
.GetArgs() );
273 case SID_EXITANDRETURN
:
276 // protect against reentrant calls
277 if ( pAppData_Impl
->bInQuit
)
280 if ( rReq
.GetSlot() == SID_LOGOUT
)
282 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
283 pObjSh
; pObjSh
= SfxObjectShell::GetNext( *pObjSh
) )
285 if ( !pObjSh
->IsModified() )
288 SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( pObjSh
);
289 if ( !pFrame
|| !pFrame
->GetWindow().IsReallyVisible() )
292 if ( pObjSh
->PrepareClose(2) )
293 pObjSh
->SetModified( sal_False
);
298 SfxStringItem
aNameItem( SID_FILE_NAME
, OUString("vnd.sun.star.cmd:logout") );
299 SfxStringItem
aReferer( SID_REFERER
, "private/user" );
300 pAppData_Impl
->pAppDispat
->Execute( SID_OPENDOC
, SFX_CALLMODE_SLOT
, &aNameItem
, &aReferer
, 0L );
304 // aus verschachtelten Requests nach 100ms nochmal probieren
305 if( Application::GetDispatchLevel() > 1 )
307 /* Dont save the request for closing the application and try it later
308 again. This is an UI bound functionality ... and the user will try it again
309 if the dialog is closed. But we shouldnt close the application automaticly
310 if this dialog is closed by the user ...
311 So we ignore this request now and wait for a new user decision.
313 OSL_TRACE( "QueryExit => sal_False (DispatchLevel == %u)", Application::GetDispatchLevel() );
317 // block reentrant calls
318 pAppData_Impl
->bInQuit
= sal_True
;
319 Reference
< XDesktop2
> xDesktop
= Desktop::create ( ::comphelper::getProcessComponentContext() );
321 rReq
.ForgetAllArgs();
323 // if terminate() failed, pAppData_Impl->bInQuit will now be sal_False, allowing further calls of SID_QUITAPP
324 sal_Bool bTerminated
= xDesktop
->terminate();
326 // if terminate() was successful, SfxApplication is now dead!
327 pAppData_Impl
->bInQuit
= sal_False
;
329 // Set return value, terminate if possible
330 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bTerminated
) );
335 case SID_TOOLBOXOPTIONS
:
336 case SID_CONFIGSTATUSBAR
:
338 case SID_CONFIGACCEL
:
339 case SID_CONFIGEVENT
:
341 SfxAbstractDialogFactory
* pFact
=
342 SfxAbstractDialogFactory::Create();
346 SFX_REQUEST_ARG(rReq
, pStringItem
,
347 SfxStringItem
, SID_CONFIG
, sal_False
);
350 GetPool(), SID_CONFIG
, SID_CONFIG
);
354 aSet
.Put( SfxStringItem(
355 SID_CONFIG
, pStringItem
->GetValue() ) );
358 Reference
< XFrame
> xFrame
;
359 const SfxItemSet
* pIntSet
= rReq
.GetInternalArgs_Impl();
360 SFX_ITEMSET_ARG( pIntSet
, pFrameItem
, SfxUnoFrameItem
, SID_FILLFRAME
, sal_False
);
362 xFrame
= pFrameItem
->GetFrame();
364 SfxAbstractTabDialog
* pDlg
= pFact
->CreateTabDialog(
365 RID_SVXDLG_CUSTOMIZE
,
366 NULL
, &aSet
, xFrame
);
370 const short nRet
= pDlg
->Execute();
385 Reference
< XDesktop2
> xDesktop
= Desktop::create( ::comphelper::getProcessComponentContext() );
386 Reference
< XIndexAccess
> xTasks( xDesktop
->getFrames(), UNO_QUERY
);
393 if ( xTasks
->getCount() <= n
)
396 Any aAny
= xTasks
->getByIndex(n
);
397 Reference
< XCloseable
> xTask
;
401 xTask
->close(sal_True
);
404 catch( CloseVetoException
& )
410 sal_Bool bOk
= ( n
== 0);
411 rReq
.SetReturnValue( SfxBoolItem( 0, bOk
) );
418 sal_Bool bOK
= sal_True
;
419 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
421 pObjSh
= SfxObjectShell::GetNext( *pObjSh
) )
423 SfxRequest
aReq( SID_SAVEDOC
, 0, pObjSh
->GetPool() );
424 if ( pObjSh
->IsModified() )
426 pObjSh
->ExecuteSlot( aReq
);
427 SfxBoolItem
*pItem
= PTR_CAST( SfxBoolItem
, aReq
.GetReturnValue() );
428 if ( !pItem
|| !pItem
->GetValue() )
433 rReq
.SetReturnValue( SfxBoolItem( 0, bOK
) );
438 case SID_SEND_FEEDBACK
:
440 OUString module
= SfxHelp::GetCurrentModuleIdentifier();
441 OUString
sURL("http://hub.libreoffice.org/send-feedback/?LOversion=" + utl::ConfigManager::getAboutBoxProductVersion() +
442 "&LOlocale=" + utl::ConfigManager::getLocale() + "&LOmodule=" + module
.copy(module
.lastIndexOf(".") + 1 ) );
445 uno::Reference
< com::sun::star::system::XSystemShellExecute
> xSystemShellExecute(
446 com::sun::star::system::SystemShellExecute::create(::comphelper::getProcessComponentContext()) );
447 xSystemShellExecute
->execute( sURL
, OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY
);
449 catch ( uno::Exception
& )
455 case SID_SHOW_LICENSE
:
457 LicenseDialog aDialog
;
462 case SID_SHOW_CREDITS
:
464 showDocument( "CREDITS" );
468 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
471 Help
* pHelp
= Application::GetHelp();
474 pHelp
->Start( OUString(".uno:HelpIndex"), NULL
); // show start page
480 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
483 // Evaluate Parameter
484 SFX_REQUEST_ARG(rReq
, pOnItem
, SfxBoolItem
, SID_HELPTIPS
, sal_False
);
486 ? ((SfxBoolItem
*)pOnItem
)->GetValue()
487 : !Help::IsQuickHelpEnabled();
490 Help::EnableQuickHelp();
492 Help::DisableQuickHelp();
493 SvtHelpOptions().SetHelpTips( bOn
);
494 Invalidate(SID_HELPTIPS
);
497 // Record if possible
499 rReq
.AppendItem( SfxBoolItem( SID_HELPTIPS
, bOn
) );
502 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
503 case SID_EXTENDEDHELP
:
505 Help::StartExtHelp();
508 case SID_HELPBALLOONS
:
510 // Evaluate Parameter
511 SFX_REQUEST_ARG(rReq
, pOnItem
, SfxBoolItem
, SID_HELPBALLOONS
, sal_False
);
513 ? ((SfxBoolItem
*)pOnItem
)->GetValue()
514 : !Help::IsBalloonHelpEnabled();
517 Help::EnableBalloonHelp();
519 Help::DisableBalloonHelp();
520 SvtHelpOptions().SetExtendedHelp( bOn
);
521 Invalidate(SID_HELPBALLOONS
);
524 // Record if possible
526 rReq
.AppendItem( SfxBoolItem( SID_HELPBALLOONS
, bOn
) );
530 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
533 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
536 VclAbstractDialog
* pDlg
= pFact
->CreateVclDialog( 0, RID_DEFAULTABOUT
);
544 case SID_TEMPLATE_MANAGER
:
546 SfxTemplateManagerDlg dlg
;
552 case SID_TEMPLATE_ADDRESSBOKSOURCE
:
554 svt::AddressBookSourceDialog
aDialog(GetTopWindow(), ::comphelper::getProcessComponentContext());
560 #ifndef DISABLE_SCRIPTING
565 case SID_BASICBREAK
:
566 BASIC_DLL()->BasicBreak();
578 case SID_SHOW_IME_STATUS_WINDOW
:
579 if (pAppData_Impl
->m_xImeStatusWindow
->canToggle())
581 SfxBoolItem
const * pItem
= static_cast< SfxBoolItem
const * >(
582 rReq
.GetArg(SID_SHOW_IME_STATUS_WINDOW
, false,
584 bool bShow
= pItem
== 0
585 ? !pAppData_Impl
->m_xImeStatusWindow
->isShowing()
586 : ( pItem
->GetValue() == sal_True
);
587 pAppData_Impl
->m_xImeStatusWindow
->show(bShow
);
589 rReq
.AppendItem(SfxBoolItem(SID_SHOW_IME_STATUS_WINDOW
,
595 case SID_ZOOM_50_PERCENT
:
596 case SID_ZOOM_75_PERCENT
:
597 case SID_ZOOM_100_PERCENT
:
598 case SID_ZOOM_150_PERCENT
:
599 case SID_ZOOM_200_PERCENT
:
600 case SID_ZOOM_OPTIMAL
:
601 case SID_ZOOM_ENTIRE_PAGE
:
602 case SID_ZOOM_PAGE_WIDTH
:
604 SfxObjectShell
* pCurrentShell
= SfxObjectShell::Current();
608 // make sure aZoom is initialized with a proper value if SetType
610 SvxZoomItem
aZoom( SVX_ZOOM_PERCENT
, 100 );
612 switch (rReq
.GetSlot())
614 case SID_ZOOM_50_PERCENT
:
617 case SID_ZOOM_75_PERCENT
:
620 case SID_ZOOM_100_PERCENT
:
623 case SID_ZOOM_150_PERCENT
:
626 case SID_ZOOM_200_PERCENT
:
629 case SID_ZOOM_OPTIMAL
:
630 aZoom
.SetType( SVX_ZOOM_OPTIMAL
);
632 case SID_ZOOM_ENTIRE_PAGE
:
633 aZoom
.SetType( SVX_ZOOM_WHOLEPAGE
);
635 case SID_ZOOM_PAGE_WIDTH
:
636 aZoom
.SetType( SVX_ZOOM_PAGEWIDTH
);
640 pCurrentShell
->GetDispatcher()->Execute(SID_ATTR_ZOOM
, SFX_CALLMODE_ASYNCHRON
, &aZoom
, 0L);
644 case SID_AVAILABLE_TOOLBARS
:
646 SfxStringItem
const * pToolbarName
= static_cast< SfxStringItem
const *>(
647 rReq
.GetArg(SID_AVAILABLE_TOOLBARS
, false, TYPE(SfxStringItem
)));
651 Reference
< XDesktop2
> xDesktop
= Desktop::create ( ::comphelper::getProcessComponentContext() );
652 Reference
< XFrame
> xFrame
= xDesktop
->getActiveFrame();
654 Reference
< com::sun::star::beans::XPropertySet
> xPropSet( xFrame
, UNO_QUERY
);
655 Reference
< ::com::sun::star::frame::XLayoutManager
> xLayoutManager
;
660 Any aValue
= xPropSet
->getPropertyValue( OUString( "LayoutManager" ));
661 aValue
>>= xLayoutManager
;
663 catch ( const ::com::sun::star::uno::RuntimeException
& )
667 catch ( ::com::sun::star::uno::Exception
& )
672 if ( xLayoutManager
.is() )
674 OUString
aToolbarResName( "private:resource/toolbar/" );
675 OUStringBuffer
aBuf( aToolbarResName
);
676 aBuf
.append( pToolbarName
->GetValue() );
678 // Evaluate Parameter
679 OUString
aToolbarName( aBuf
.makeStringAndClear() );
680 sal_Bool
bShow( !xLayoutManager
->isElementVisible( aToolbarName
));
684 xLayoutManager
->createElement( aToolbarName
);
685 xLayoutManager
->showElement( aToolbarName
);
688 xLayoutManager
->hideElement( aToolbarName
);
704 //--------------------------------------------------------------------
706 void SfxApplication::MiscState_Impl(SfxItemSet
&rSet
)
708 const sal_uInt16
*pRanges
= rSet
.GetRanges();
709 DBG_ASSERT(pRanges
&& *pRanges
, "Set without range");
712 for(sal_uInt16 nWhich
= *pRanges
++; nWhich
<= *pRanges
; ++nWhich
)
716 case SID_TEMPLATE_ADDRESSBOKSOURCE
:
717 if ( !SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE
) )
718 rSet
.Put(SfxVisibilityItem(nWhich
, sal_False
));
720 case SID_EXITANDRETURN
:
723 if ( pAppData_Impl
->nDocModalMode
)
724 rSet
.DisableItem(nWhich
);
726 rSet
.Put(SfxStringItem(nWhich
, SfxResId(STR_QUITAPP
).toString()));
731 case SID_TOOLBOXOPTIONS
:
732 case SID_CONFIGSTATUSBAR
:
734 case SID_CONFIGACCEL
:
735 case SID_CONFIGEVENT
:
737 if( SvtMiscOptions().DisableUICustomization() )
738 rSet
.DisableItem(nWhich
);
742 #ifndef DISABLE_SCRIPTING
744 if ( !StarBASIC::IsRunning() )
745 rSet
.DisableItem(nWhich
);
751 rSet
.Put( SfxBoolItem( SID_HELPTIPS
, Help::IsQuickHelpEnabled() ) );
754 case SID_HELPBALLOONS
:
756 rSet
.Put( SfxBoolItem( SID_HELPBALLOONS
, Help::IsBalloonHelpEnabled() ) );
760 case SID_EXTENDEDHELP
:
768 Reference
< XDesktop2
> xDesktop
= Desktop::create( ::comphelper::getProcessComponentContext() );
769 Reference
< XIndexAccess
> xTasks( xDesktop
->getFrames(), UNO_QUERY
);
770 if ( !xTasks
.is() || !xTasks
->getCount() )
771 rSet
.DisableItem(nWhich
);
777 sal_Bool bModified
= sal_False
;
778 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
780 pObjSh
= SfxObjectShell::GetNext( *pObjSh
) )
782 if ( pObjSh
->IsModified() )
784 bModified
= sal_True
;
790 rSet
.DisableItem( nWhich
);
794 case SID_SHOW_IME_STATUS_WINDOW
:
795 if (pAppData_Impl
->m_xImeStatusWindow
->canToggle())
796 rSet
.Put(SfxBoolItem(
797 SID_SHOW_IME_STATUS_WINDOW
,
798 pAppData_Impl
->m_xImeStatusWindow
->
801 rSet
.DisableItem(SID_SHOW_IME_STATUS_WINDOW
);
804 case SID_TEMPLATE_MANAGER
:
806 SvtMiscOptions aMiscOptions
;
807 if ( !aMiscOptions
.IsExperimentalMode() )
809 rSet
.DisableItem( nWhich
);
810 rSet
.Put( SfxVisibilityItem( nWhich
, sal_False
) );
824 #ifndef DISABLE_SCRIPTING
826 #ifndef DISABLE_DYNLOADING
828 typedef rtl_uString
* (SAL_CALL
*basicide_choose_macro
)(XModel
*, sal_Bool
, rtl_uString
*);
829 typedef void (SAL_CALL
*basicide_macro_organizer
)( sal_Int16
);
831 extern "C" { static void SAL_CALL
thisModule() {} }
835 extern "C" rtl_uString
* basicide_choose_macro(XModel
*, sal_Bool
, rtl_uString
*);
836 extern "C" void basicide_macro_organizer( sal_Int16
);
840 OUString
ChooseMacro( const Reference
< XModel
>& rxLimitToDocument
, sal_Bool bChooseOnly
, const OUString
& rMacroDesc
= OUString() )
842 #ifndef DISABLE_DYNLOADING
843 // get basctl dllname
844 static OUString
aLibName( SVLIBRARY( "basctl" ) );
847 oslModule handleMod
= osl_loadModuleRelative(
848 &thisModule
, aLibName
.pData
, 0 );
851 OUString
aSymbol( "basicide_choose_macro" );
852 basicide_choose_macro pSymbol
= (basicide_choose_macro
) osl_getFunctionSymbol( handleMod
, aSymbol
.pData
);
854 #define pSymbol basicide_choose_macro
857 // call basicide_choose_macro in basctl
858 rtl_uString
* pScriptURL
= pSymbol( rxLimitToDocument
.get(), bChooseOnly
, rMacroDesc
.pData
);
859 OUString
aScriptURL( pScriptURL
);
860 rtl_uString_release( pScriptURL
);
863 #ifdef DISABLE_DYNLOADING
868 void MacroOrganizer( sal_Int16 nTabId
)
870 #ifndef DISABLE_DYNLOADING
871 // get basctl dllname
872 static OUString
aLibName( SVLIBRARY( "basctl" ) );
875 oslModule handleMod
= osl_loadModuleRelative(
876 &thisModule
, aLibName
.pData
, 0 );
879 OUString
aSymbol( "basicide_macro_organizer" );
880 basicide_macro_organizer pSymbol
= (basicide_macro_organizer
) osl_getFunctionSymbol( handleMod
, aSymbol
.pData
);
881 // call basicide_macro_organizer in basctl
884 basicide_macro_organizer( nTabId
);
892 #define RID_ERRBOX_MODULENOTINSTALLED (RID_OFA_START + 72)
894 ResMgr
* SfxApplication::GetOffResManager_Impl()
896 if ( !pAppData_Impl
->pOfaResMgr
)
897 pAppData_Impl
->pOfaResMgr
= CreateResManager( "ofa");
898 return pAppData_Impl
->pOfaResMgr
;
903 #ifndef DISABLE_SCRIPTING
904 Window
* lcl_getDialogParent( const Reference
< XFrame
>& _rxFrame
, Window
* _pFallback
)
906 if ( !_rxFrame
.is() )
911 Reference
< awt::XWindow
> xContainerWindow( _rxFrame
->getContainerWindow(), UNO_SET_THROW
);
912 Window
* pWindow
= VCLUnoHelper::GetWindow( xContainerWindow
);
913 OSL_ENSURE( pWindow
, "lcl_getDialogParent: cool, somebody implemented a VCL-less toolkit!" );
916 return pWindow
->GetSystemWindow();
918 catch( const Exception
& )
920 DBG_UNHANDLED_EXCEPTION();
925 const OUString
& lcl_getBasicIDEServiceName()
927 static const OUString
s_sBasicName( "com.sun.star.script.BasicIDE" );
931 SfxViewFrame
* lcl_getBasicIDEViewFrame( SfxObjectShell
* i_pBasicIDE
)
933 SfxViewFrame
* pView
= SfxViewFrame::GetFirst( i_pBasicIDE
);
936 if ( pView
->GetObjectShell()->GetFactory().GetDocumentServiceName() == lcl_getBasicIDEServiceName() )
938 pView
= SfxViewFrame::GetNext( *pView
, i_pBasicIDE
);
942 Reference
< XFrame
> lcl_findStartModuleFrame( const Reference
<XComponentContext
> & rxContext
)
946 Reference
< XDesktop2
> xDesktop
= Desktop::create( rxContext
);
947 Reference
< XIndexAccess
> xContainer( xDesktop
->getFrames(), UNO_QUERY_THROW
);
949 Reference
< XModuleManager2
> xCheck
= ModuleManager::create(rxContext
);
951 sal_Int32 nCount
= xContainer
->getCount();
952 for ( sal_Int32 i
=0; i
<nCount
; ++i
)
956 Reference
< XFrame
> xFrame( xContainer
->getByIndex(i
), UNO_QUERY_THROW
);
957 OUString sModule
= xCheck
->identify( xFrame
);
958 if ( sModule
== "com.sun.star.frame.StartModule" )
961 catch( const UnknownModuleException
& )
965 catch(const Exception
&)
967 // re-throw, caught below
972 catch( const Exception
& )
974 DBG_UNHANDLED_EXCEPTION();
978 #endif // !DISABLE_SCRIPTING
981 static OUString
getConfigurationStringValue(
982 const OUString
& rPackage
,
983 const OUString
& rRelPath
,
984 const OUString
& rKey
,
985 const OUString
& rDefaultValue
)
987 OUString
aDefVal( rDefaultValue
);
991 ::comphelper::ConfigurationHelper::readDirectKey(
992 comphelper::getProcessComponentContext(),
996 ::comphelper::ConfigurationHelper::E_READONLY
) >>= aDefVal
;
998 catch(const com::sun::star::uno::RuntimeException
&)
1000 catch(const com::sun::star::uno::Exception
&)
1006 void SfxApplication::OfaExec_Impl( SfxRequest
& rReq
)
1008 switch ( rReq
.GetSlot() )
1010 case SID_OPTIONS_TREEDIALOG
:
1013 SFX_REQUEST_ARG( rReq
, pURLItem
, SfxStringItem
, SID_OPTIONS_PAGEURL
, sal_False
);
1015 sPageURL
= pURLItem
->GetValue();
1016 const SfxItemSet
* pArgs
= rReq
.GetInternalArgs_Impl();
1017 const SfxPoolItem
* pItem
= NULL
;
1018 Reference
< XFrame
> xFrame
;
1019 if ( pArgs
&& pArgs
->GetItemState( SID_FILLFRAME
, sal_False
, &pItem
) == SFX_ITEM_SET
)
1021 OSL_ENSURE( pItem
->ISA( SfxUnoFrameItem
), "SfxApplication::OfaExec_Impl: XFrames are to be transported via SfxUnoFrameItem by now!" );
1022 xFrame
= static_cast< const SfxUnoFrameItem
*>( pItem
)->GetFrame();
1024 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1027 VclAbstractDialog
* pDlg
=
1028 pFact
->CreateFrameDialog( NULL
, xFrame
, rReq
.GetSlot(), sPageURL
);
1029 short nRet
= pDlg
->Execute();
1031 SfxViewFrame
* pView
= SfxViewFrame::GetFirst();
1036 SfxObjectShell
* pObjSh
= pView
->GetObjectShell();
1038 pObjSh
->SetConfigOptionsChecked(false);
1040 pView
->GetBindings().InvalidateAll(sal_False
);
1041 pView
= SfxViewFrame::GetNext( *pView
);
1047 case SID_MORE_DICTIONARIES
:
1051 uno::Reference
< uno::XComponentContext
> xContext
=
1052 ::comphelper::getProcessComponentContext();
1053 uno::Reference
< css::system::XSystemShellExecute
> xSystemShell(
1054 css::system::SystemShellExecute::create(xContext
) );
1056 // read repository URL from configuration
1057 OUString sTemplRepoURL
=
1058 getConfigurationStringValue(
1059 OUString("org.openoffice.Office.Common"),
1060 OUString("Dictionaries"),
1061 OUString("RepositoryURL"),
1064 if ( xSystemShell
.is() && !sTemplRepoURL
.isEmpty() )
1066 OUStringBuffer
aURLBuf( sTemplRepoURL
);
1067 aURLBuf
.appendAscii(RTL_CONSTASCII_STRINGPARAM("?lang="));
1069 // read locale from configuration
1070 OUString sLocale
= getConfigurationStringValue(
1071 OUString("org.openoffice.Setup"),
1073 OUString("ooLocale"),
1076 aURLBuf
.append( sLocale
);
1077 xSystemShell
->execute(
1078 aURLBuf
.makeStringAndClear(),
1080 css::system::SystemShellExecuteFlags::URIS_ONLY
);
1083 catch( const ::com::sun::star::uno::Exception
& )
1085 SAL_WARN( "sfx2.appl", "SfxApplication::OfaExec_Impl(SID_MORE_DICTIONARIES): caught an exception!" );
1089 #ifndef DISABLE_SCRIPTING
1090 case SID_BASICIDE_APPEAR
:
1092 SfxViewFrame
* pView
= lcl_getBasicIDEViewFrame( NULL
);
1095 SfxObjectShell
* pBasicIDE
= SfxObjectShell::CreateObject( lcl_getBasicIDEServiceName() );
1096 pBasicIDE
->DoInitNew( 0 );
1097 pBasicIDE
->SetModified( sal_False
);
1100 // load the Basic IDE via direct access to the SFX frame loader. A generic loadComponentFromURL
1101 // (which could be done via SfxViewFrame::LoadDocumentIntoFrame) is not feasible here, since the Basic IDE
1102 // does not really play nice with the framework's concept. For instance, it is a "singleton document",
1103 // which conflicts, at the latest, with the framework's concept of loading into _blank frames.
1104 // So, since we know that our frame loader can handle it, we skip the generic framework loader
1105 // mechanism, and the type detection (which doesn't know about the Basic IDE).
1106 Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
1107 Reference
< XSynchronousFrameLoader
> xLoader(
1108 xContext
->getServiceManager()->createInstanceWithContext(SfxFrameLoader_Impl::impl_getStaticImplementationName(), xContext
),
1110 ::comphelper::NamedValueCollection aLoadArgs
;
1111 aLoadArgs
.put( "Model", pBasicIDE
->GetModel() );
1112 aLoadArgs
.put( "URL", OUString( "private:factory/sbasic" ) );
1114 Reference
< XFrame
> xTargetFrame( lcl_findStartModuleFrame( xContext
) );
1115 if ( !xTargetFrame
.is() )
1116 xTargetFrame
= SfxFrame::CreateBlankFrame();
1117 ENSURE_OR_THROW( xTargetFrame
.is(), "could not obtain a frameto load the Basic IDE into!" );
1119 xLoader
->load( aLoadArgs
.getPropertyValues(), xTargetFrame
);
1121 catch( const Exception
& )
1123 DBG_UNHANDLED_EXCEPTION();
1126 pView
= lcl_getBasicIDEViewFrame( pBasicIDE
);
1128 pView
->SetName( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC:1" ) ) );
1132 pView
->GetFrame().Appear();
1134 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1135 if ( pArgs
&& pView
)
1137 SfxViewShell
* pViewShell
= pView
->GetViewShell();
1138 SfxObjectShell
* pObjShell
= pView
->GetObjectShell();
1139 if ( pViewShell
&& pObjShell
)
1141 SfxRequest
aReq( SID_BASICIDE_SHOWWINDOW
, SFX_CALLMODE_SYNCHRON
, pObjShell
->GetPool() );
1142 aReq
.SetArgs( *pArgs
);
1143 pViewShell
->ExecuteSlot( aReq
);
1151 case SID_BASICCHOOSER
:
1153 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1154 const SfxPoolItem
* pItem
;
1155 sal_Bool bChooseOnly
= sal_False
;
1156 Reference
< XModel
> xLimitToModel
;
1157 if(pArgs
&& SFX_ITEM_SET
== pArgs
->GetItemState(SID_RECORDMACRO
, sal_False
, &pItem
) )
1159 sal_Bool bRecord
= ((SfxBoolItem
*)pItem
)->GetValue();
1163 bChooseOnly
= sal_False
;
1164 SfxObjectShell
* pCurrentShell
= SfxObjectShell::Current();
1165 OSL_ENSURE( pCurrentShell
, "macro recording outside an SFX document?" );
1166 if ( pCurrentShell
)
1167 xLimitToModel
= pCurrentShell
->GetModel();
1171 rReq
.SetReturnValue( SfxStringItem( rReq
.GetSlot(), ChooseMacro( xLimitToModel
, bChooseOnly
) ) );
1176 case SID_MACROORGANIZER
:
1178 OSL_TRACE("handling SID_MACROORGANIZER");
1179 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1180 const SfxPoolItem
* pItem
;
1181 sal_Int16 nTabId
= 0;
1182 if(pArgs
&& SFX_ITEM_SET
== pArgs
->GetItemState(SID_MACROORGANIZER
, sal_False
, &pItem
) )
1184 nTabId
= ((SfxUInt16Item
*)pItem
)->GetValue();
1187 SfxApplication::MacroOrganizer( nTabId
);
1194 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1195 OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
1197 Reference
< XFrame
> xFrame
;
1198 const SfxItemSet
* pIntSet
= rReq
.GetInternalArgs_Impl();
1199 SFX_ITEMSET_ARG( pIntSet
, pFrameItem
, SfxUnoFrameItem
, SID_FILLFRAME
, sal_False
);
1201 xFrame
= pFrameItem
->GetFrame();
1205 const SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
1207 xFrame
= pViewFrame
->GetFrame().GetFrameInterface();
1210 do // artificial loop for flow control
1212 AbstractScriptSelectorDialog
* pDlg
= pFact
->CreateScriptSelectorDialog(
1213 lcl_getDialogParent( xFrame
, GetTopWindow() ), sal_False
, xFrame
);
1214 OSL_ENSURE( pDlg
, "SfxApplication::OfaExec_Impl( SID_RUNMACRO ): no dialog!" );
1217 pDlg
->SetRunLabel();
1219 short nDialogResult
= pDlg
->Execute();
1220 if ( !nDialogResult
)
1226 Sequence
< Any
> args
;
1227 Sequence
< sal_Int16
> outIndex
;
1228 Sequence
< Any
> outArgs
;
1231 Reference
< XInterface
> xScriptContext
;
1233 Reference
< XController
> xController
;
1235 xController
= xFrame
->getController();
1236 if ( xController
.is() )
1237 xScriptContext
= xController
->getModel();
1238 if ( !xScriptContext
.is() )
1239 xScriptContext
= xController
;
1241 SfxObjectShell::CallXScript( xScriptContext
, pDlg
->GetScriptURL(), args
, ret
, outIndex
, outArgs
);
1249 case SID_SCRIPTORGANIZER
:
1251 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1252 OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
1253 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1254 const SfxPoolItem
* pItem
;
1256 if(pArgs
&& SFX_ITEM_SET
== pArgs
->GetItemState(SID_SCRIPTORGANIZER
, sal_False
, &pItem
) )
1258 aLanguage
= ((SfxScriptOrganizerItem
*)pItem
)->getLanguage();
1261 OUString
aLang( aLanguage
);
1262 OSL_TRACE("SfxApplication::OfaExec_Impl: about to create dialog for: %s", OUStringToOString( aLang
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
1263 // not sure about the Window*
1264 VclAbstractDialog
* pDlg
= pFact
->CreateSvxScriptOrgDialog( GetTopWindow(), aLanguage
);
1272 OSL_TRACE("no dialog!!!");
1277 #endif // !DISABLE_SCRIPTING
1279 case SID_OFFICE_CHECK_PLZ
:
1281 sal_Bool bRet
= sal_False
;
1282 SFX_REQUEST_ARG(rReq
, pStringItem
, SfxStringItem
, rReq
.GetSlot(), sal_False
);
1286 bRet
= sal_True
/*!!!SfxIniManager::CheckPLZ( aPLZ )*/;
1288 #ifndef DISABLE_SCRIPTING
1290 SbxBase::SetError( SbxERR_WRONG_ARGS
);
1292 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bRet
) );
1296 case SID_AUTO_CORRECT_DLG
:
1298 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1301 SfxItemSet
aSet(GetPool(), SID_AUTO_CORRECT_DLG
, SID_AUTO_CORRECT_DLG
);
1302 const SfxPoolItem
* pItem
=NULL
;
1303 const SfxItemSet
* pSet
= rReq
.GetArgs();
1304 SfxItemPool
* pSetPool
= pSet
? pSet
->GetPool() : NULL
;
1305 if ( pSet
&& pSet
->GetItemState( pSetPool
->GetWhich( SID_AUTO_CORRECT_DLG
), sal_False
, &pItem
) == SFX_ITEM_SET
)
1308 SfxAbstractTabDialog
* pDlg
= pFact
->CreateTabDialog( RID_OFA_AUTOCORR_DLG
, NULL
, &aSet
, NULL
);
1316 case SID_SD_AUTOPILOT
:
1319 SvtModuleOptions aModuleOpt
;
1320 if ( !aModuleOpt
.IsImpress() )
1322 ErrorBox( 0, ResId( RID_ERRBOX_MODULENOTINSTALLED
, *GetOffResManager_Impl() )).Execute();
1326 Reference
< uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
1327 Reference
< frame::XDispatchProvider
> xProv
= drawing::ModuleDispatcher::create( xContext
);
1329 OUString aCmd
= OUString::createFromAscii( GetInterface()->GetSlot( rReq
.GetSlot() )->GetUnoName() );
1330 Reference
< frame::XDispatchHelper
> xHelper( frame::DispatchHelper::create(xContext
) );
1331 Sequence
< beans::PropertyValue
> aSeq
;
1332 if ( rReq
.GetArgs() )
1333 TransformItems( rReq
.GetSlot(), *rReq
.GetArgs(), aSeq
);
1334 Any aResult
= xHelper
->executeDispatch( xProv
, aCmd
, OUString(), 0, aSeq
);
1335 frame::DispatchResultEvent aEvent
;
1336 sal_Bool bSuccess
= (aResult
>>= aEvent
) &&
1337 (aEvent
.State
== frame::DispatchResultState::SUCCESS
);
1338 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bSuccess
) );
1343 case FN_BUSINESS_CARD
:
1344 case FN_XFORMS_INIT
:
1346 Reference
< uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
1347 Reference
< frame::XDispatchProvider
> xProv
= text::ModuleDispatcher::create( xContext
);
1349 OUString aCmd
= OUString::createFromAscii( GetInterface()->GetSlot( rReq
.GetSlot() )->GetUnoName() );
1350 Reference
< frame::XDispatchHelper
> xHelper( frame::DispatchHelper::create(xContext
) );
1351 Sequence
< beans::PropertyValue
> aSeq
;
1352 if ( rReq
.GetArgs() )
1353 TransformItems( rReq
.GetSlot(), *rReq
.GetArgs(), aSeq
);
1354 Any aResult
= xHelper
->executeDispatch( xProv
, aCmd
, OUString(), 0, aSeq
);
1355 frame::DispatchResultEvent aEvent
;
1356 sal_Bool bSuccess
= (aResult
>>= aEvent
) &&
1357 (aEvent
.State
== frame::DispatchResultState::SUCCESS
);
1358 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bSuccess
) );
1362 case SID_ADDRESS_DATA_SOURCE
:
1366 Reference
< uno::XComponentContext
> xORB
= ::comphelper::getProcessComponentContext();
1367 Reference
< ui::dialogs::XExecutableDialog
> xDialog
;
1368 xDialog
= ui::dialogs::AddressBookSourcePilot::createWithParent(xORB
, 0);
1371 catch(const ::com::sun::star::uno::Exception
&)
1373 DBG_UNHANDLED_EXCEPTION();
1378 case SID_COMP_BIBLIOGRAPHY
:
1379 lcl_tryLoadBibliography();
1384 void SfxApplication::OfaState_Impl(SfxItemSet
&rSet
)
1386 SvtModuleOptions aModuleOpt
;
1388 if( !aModuleOpt
.IsWriter())
1390 rSet
.DisableItem( FN_LABEL
);
1391 rSet
.DisableItem( FN_BUSINESS_CARD
);
1392 rSet
.DisableItem( FN_XFORMS_INIT
);
1395 if ( !aModuleOpt
.IsImpress() )
1396 rSet
.DisableItem( SID_SD_AUTOPILOT
);
1399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */