1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: appserv.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
33 #include <com/sun/star/uno/Reference.hxx>
34 #ifndef _COM_SUN_STAR_LANG_XMultiServiceFactory_HPP_
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/lang/IllegalArgumentException.hpp>
38 #include <com/sun/star/frame/DispatchResultEvent.hpp>
39 #include <com/sun/star/frame/DispatchResultState.hpp>
40 #include <com/sun/star/task/XJobExecutor.hpp>
41 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
42 #include <com/sun/star/frame/XDesktop.hpp>
43 #include <com/sun/star/frame/XDispatchHelper.hpp>
44 #include <com/sun/star/frame/XFramesSupplier.hpp>
45 #include <com/sun/star/util/XCloseable.hpp>
46 #ifndef _COM_SUN_STAR_UTIL_CloseVetoException_HPP_
47 #include <com/sun/star/util/CloseVetoException.hpp>
49 #include <com/sun/star/frame/XLayoutManager.hpp>
50 #include <com/sun/star/document/XEmbeddedScripts.hpp>
51 #include <com/sun/star/embed/XStorage.hpp>
52 #include <com/sun/star/embed/ElementModes.hpp>
53 #include <com/sun/star/system/XSystemShellExecute.hpp>
54 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
55 #include <com/sun/star/system/SystemShellExecuteException.hpp>
57 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
58 #include <comphelper/processfactory.hxx>
60 #include <comphelper/storagehelper.hxx>
62 #ifndef _SVT_DOC_ADDRESSTEMPLATE_HXX_
63 #include <svtools/addresstemplate.hxx>
65 #include <svtools/visitem.hxx>
66 #include <unotools/intlwrapper.hxx>
68 #ifndef _UNOTOOLS_CONFIGMGR_HXX_
69 #include <unotools/configmgr.hxx>
71 #include <tools/config.hxx>
72 #include <tools/diagnose_ex.h>
73 #include <vcl/msgbox.hxx>
74 #include <com/sun/star/system/XSystemShellExecute.hpp>
75 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
76 #include <svtools/cancel.hxx>
77 #include <svtools/intitem.hxx>
78 #include <svtools/eitem.hxx>
79 #include <svtools/stritem.hxx>
80 #include <basic/sbstar.hxx>
81 #include <basic/basmgr.hxx>
82 #include <basic/basrdll.hxx>
83 #include <svtools/sfxecode.hxx>
84 #include <svtools/ehdl.hxx>
85 #include <vcl/help.hxx>
86 #include <vcl/stdtext.hxx>
87 #include <rtl/ustrbuf.hxx>
89 #include <svtools/pathoptions.hxx>
90 #include <svtools/moduleoptions.hxx>
91 #include <svtools/regoptions.hxx>
92 #include <svtools/helpopt.hxx>
93 #include <svtools/miscopt.hxx>
94 #include <toolkit/helper/vclunohelper.hxx>
95 #include <tools/shl.hxx>
96 #include <unotools/bootstrap.hxx>
97 #include <vos/process.hxx>
98 #include <rtl/bootstrap.hxx>
99 #include <cppuhelper/exc_hlp.hxx>
101 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
102 #include <com/sun/star/beans/XPropertySet.hpp>
105 #include "referers.hxx"
106 #include <sfx2/app.hxx>
107 #include <sfx2/request.hxx>
108 #include <sfx2/dispatch.hxx>
109 #include <sfx2/bindings.hxx>
110 #include <sfx2/msg.hxx>
111 #include <sfx2/objface.hxx>
112 #include <sfx2/objitem.hxx>
113 #include <sfx2/objsh.hxx>
114 #include <sfx2/hintpost.hxx>
115 #include <sfx2/viewsh.hxx>
116 #include <sfx2/docfac.hxx>
117 #include <sfx2/docfile.hxx>
118 #include <sfx2/docfilt.hxx>
119 #include "docvor.hxx"
120 #include <sfx2/new.hxx>
121 #include <sfx2/templdlg.hxx>
122 #include "sfxtypes.hxx"
123 #include "sfxbasic.hxx"
124 #include <sfx2/tabdlg.hxx>
125 #include "arrdecl.hxx"
126 #include "fltfnc.hxx"
127 #include <sfx2/sfx.hrc>
129 #include <sfx2/passwd.hxx>
130 #include "sfxresid.hxx"
131 #include "arrdecl.hxx"
132 #include <sfx2/childwin.hxx>
133 #include "appdata.hxx"
134 #include <sfx2/macrconf.hxx>
135 #include "minfitem.hxx"
136 #include <sfx2/event.hxx>
137 #include <sfx2/module.hxx>
138 #include <sfx2/topfrm.hxx>
139 #include "sfxpicklist.hxx"
140 #include "imestatuswindow.hxx"
141 #include <sfx2/sfxdlg.hxx>
142 #include <sfx2/dialogs.hrc>
143 #include "sorgitm.hxx"
144 #include "sfxhelp.hxx"
146 using namespace ::com::sun::star
;
147 using namespace ::com::sun::star::beans
;
148 using namespace ::com::sun::star::uno
;
149 using namespace ::com::sun::star::frame
;
150 using namespace ::com::sun::star::container
;
151 using namespace ::com::sun::star::util
;
152 using namespace ::com::sun::star::script
;
153 using namespace ::com::sun::star::system
;
154 using namespace ::com::sun::star::lang
;
155 using namespace ::com::sun::star::document
;
157 namespace css
= com::sun::star
;
159 //-------------------------------------------------------------------------
160 long QuitAgain_Impl( void* pObj
, void* pArg
)
162 SfxApplication
* pApp
= (SfxApplication
*)pObj
;
163 Timer
* pTimer
= (Timer
*)pArg
;
165 pApp
->GetDispatcher_Impl()->Execute( SID_QUITAPP
, SFX_CALLMODE_ASYNCHRON
);
169 void SfxApplication::MiscExec_Impl( SfxRequest
& rReq
)
172 FASTBOOL bDone
= FALSE
;
173 switch ( rReq
.GetSlot() )
178 SetOptions_Impl( *rReq
.GetArgs() );
183 case SID_EXITANDRETURN
:
186 // protect against reentrant calls
187 if ( pAppData_Impl
->bInQuit
)
190 if ( rReq
.GetSlot() == SID_LOGOUT
)
192 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
193 pObjSh
; pObjSh
= SfxObjectShell::GetNext( *pObjSh
) )
195 if ( !pObjSh
->IsModified() )
198 SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( pObjSh
);
199 if ( !pFrame
|| !pFrame
->GetWindow().IsReallyVisible() )
202 if ( pObjSh
->PrepareClose(2) )
203 pObjSh
->SetModified( FALSE
);
208 String aName
= String::CreateFromAscii("vnd.sun.star.cmd:logout");
209 SfxStringItem
aNameItem( SID_FILE_NAME
, aName
);
210 SfxStringItem
aReferer( SID_REFERER
, DEFINE_CONST_UNICODE( "private/user" ) );
211 pAppData_Impl
->pAppDispat
->Execute( SID_OPENDOC
, SFX_CALLMODE_SLOT
, &aNameItem
, &aReferer
, 0L );
215 // aus verschachtelten Requests nach 100ms nochmal probieren
216 if( Application::GetDispatchLevel() > 1 )
218 /* Dont save the request for closing the application and try it later
219 again. This is an UI bound functionality ... and the user will try it again
220 if the dialog is closed. But we shouldnt close the application automaticly
221 if this dialog is closed by the user ...
222 So we ignore this request now and wait for a new user decision.
224 DBG_TRACE1( "QueryExit => FALSE (DispatchLevel == %u)", Application::GetDispatchLevel() );
228 // block reentrant calls
229 pAppData_Impl
->bInQuit
= TRUE
;
230 Reference
< XDesktop
> xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY
);
232 rReq
.ForgetAllArgs();
234 // if terminate() failed, pAppData_Impl->bInQuit will now be FALSE, allowing further calls of SID_QUITAPP
235 BOOL bTerminated
= xDesktop
->terminate();
237 // if terminate() was successful, SfxApplication is now dead!
238 pAppData_Impl
->bInQuit
= FALSE
;
240 // Returnwert setzten, ggf. terminieren
241 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bTerminated
) );
246 case SID_TOOLBOXOPTIONS
:
247 case SID_CONFIGSTATUSBAR
:
249 case SID_CONFIGACCEL
:
250 case SID_CONFIGEVENT
:
252 SfxAbstractDialogFactory
* pFact
=
253 SfxAbstractDialogFactory::Create();
257 SFX_REQUEST_ARG(rReq
, pStringItem
,
258 SfxStringItem
, SID_CONFIG
, sal_False
);
261 GetPool(), SID_CONFIG
, SID_CONFIG
);
265 aSet
.Put( SfxStringItem(
266 SID_CONFIG
, pStringItem
->GetValue() ) );
269 Reference
< XFrame
> xFrame
;
270 const SfxItemSet
* pIntSet
= rReq
.GetInternalArgs_Impl();
271 SFX_ITEMSET_ARG( pIntSet
, pFrame
, SfxUnoAnyItem
, SID_FILLFRAME
, FALSE
);
273 pFrame
->GetValue() >>= xFrame
;
275 SfxAbstractTabDialog
* pDlg
= pFact
->CreateTabDialog(
276 RID_SVXDLG_CUSTOMIZE
,
277 NULL
, &aSet
, xFrame
);
281 const short nRet
= pDlg
->Execute();
296 Reference
< XFramesSupplier
> xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY
);
297 Reference
< XIndexAccess
> xTasks( xDesktop
->getFrames(), UNO_QUERY
);
304 if ( xTasks
->getCount() <= n
)
307 Any aAny
= xTasks
->getByIndex(n
);
308 Reference
< XCloseable
> xTask
;
312 xTask
->close(sal_True
);
315 catch( CloseVetoException
& )
321 BOOL bOk
= ( n
== 0);
322 rReq
.SetReturnValue( SfxBoolItem( 0, bOk
) );
330 BOOL bTmpDone
= TRUE
;
331 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
333 pObjSh
= SfxObjectShell::GetNext( *pObjSh
) )
335 SfxRequest
aReq( SID_SAVEDOC
, 0, pObjSh
->GetPool() );
336 if ( pObjSh
->IsModified() )
338 pObjSh
->ExecuteSlot( aReq
);
339 SfxBoolItem
*pItem
= PTR_CAST( SfxBoolItem
, aReq
.GetReturnValue() );
340 bTmpDone
= aReq
.IsDone();
341 if ( !pItem
|| !pItem
->GetValue() )
346 rReq
.SetReturnValue( SfxBoolItem( 0, bOK
) );
351 case SID_HELP_SUPPORTPAGE
:
354 Reference
< com::sun::star::system::XSystemShellExecute
> xSystemShell
355 ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.system.SystemShellExecute" ) ), UNO_QUERY
);
356 if ( xSystemShell
.is()) {
357 rtl::OUString
aURI( DEFINE_CONST_UNICODE( "http://www.novell.com/support" ) );
358 xSystemShell
->execute( aURI
, ::rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS
);
362 } catch (const ::com::sun::star::uno::Exception
&) {
364 /* drop through on exception */
367 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
370 Help
* pHelp
= Application::GetHelp();
373 ULONG nHelpId
= ( rReq
.GetSlot() == SID_HELP_SUPPORTPAGE
) ? 66056 : 0;
374 if ( 66056 == nHelpId
)
376 // show Support page with new URL
377 String sHelpURL
= SfxHelp::CreateHelpURL( nHelpId
, String() );
378 String sParams
= sHelpURL
.Copy( sHelpURL
.Search( '?' ) );
379 sHelpURL
= String::CreateFromAscii("vnd.sun.star.help://shared/text/shared/05/00000001.xhp");
381 sHelpURL
+= String::CreateFromAscii("&UseDB=no");
382 pHelp
->Start( sHelpURL
, NULL
);
385 pHelp
->Start( nHelpId
, NULL
); // show start page
391 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
394 // Parameter aus werten
395 SFX_REQUEST_ARG(rReq
, pOnItem
, SfxBoolItem
, SID_HELPTIPS
, FALSE
);
397 ? ((SfxBoolItem
*)pOnItem
)->GetValue()
398 : !Help::IsQuickHelpEnabled();
402 Help::EnableQuickHelp();
404 Help::DisableQuickHelp();
405 SvtHelpOptions().SetHelpTips( bOn
);
406 Invalidate(SID_HELPTIPS
);
411 rReq
.AppendItem( SfxBoolItem( SID_HELPTIPS
, bOn
) );
414 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
415 case SID_EXTENDEDHELP
:
417 Help::StartExtHelp();
420 case SID_HELPBALLOONS
:
422 // Parameter auswerten
423 SFX_REQUEST_ARG(rReq
, pOnItem
, SfxBoolItem
, SID_HELPBALLOONS
, FALSE
);
425 ? ((SfxBoolItem
*)pOnItem
)->GetValue()
426 : !Help::IsBalloonHelpEnabled();
430 Help::EnableBalloonHelp();
432 Help::DisableBalloonHelp();
433 SvtHelpOptions().SetExtendedHelp( bOn
);
434 Invalidate(SID_HELPBALLOONS
);
439 rReq
.AppendItem( SfxBoolItem( SID_HELPBALLOONS
, bOn
) );
443 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
446 SvtHelpOptions aHelpOpt
;
447 SFX_REQUEST_ARG(rReq
, pOnItem
, SfxBoolItem
, SID_HELP_PI
, FALSE
);
448 sal_Bool bOn
= pOnItem
449 ? ((SfxBoolItem
*)pOnItem
)->GetValue()
450 : !aHelpOpt
.IsHelpAgentAutoStartMode();
451 aHelpOpt
.SetHelpAgentAutoStartMode( bOn
);
452 Invalidate(SID_HELP_PI
);
457 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
460 const String
sCWSSchema( String::CreateFromAscii( "[CWS:" ) );
461 rtl::OUString sDefault
;
462 String
sBuildId( utl::Bootstrap::getBuildIdData( sDefault
) );
463 OSL_ENSURE( sBuildId
.Len() > 0, "No BUILDID in bootstrap file" );
464 if ( sBuildId
.Len() > 0 && sBuildId
.Search( sCWSSchema
) == STRING_NOTFOUND
)
466 // no cws part in brand buildid -> try basis buildid
467 rtl::OUString
sBasisBuildId( DEFINE_CONST_OUSTRING(
468 "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("version") ":buildid}" ) );
469 rtl::Bootstrap::expandMacros( sBasisBuildId
);
470 sal_Int32 nIndex
= sBasisBuildId
.indexOf( sCWSSchema
);
472 sBuildId
+= String( sBasisBuildId
.copy( nIndex
) );
475 String
sProductSource( utl::Bootstrap::getProductSource( sDefault
) );
476 OSL_ENSURE( sProductSource
.Len() > 0, "No ProductSource in bootstrap file" );
478 // the product source is something like "DEV300", where the
479 // build id is something like "300m12(Build:12345)". For better readability,
480 // strip the duplicate UPD ("300").
481 if ( sProductSource
.Len() )
484 ( sProductSource
.Len() >= 3 )
485 && ( sBuildId
.Len() >= 3 )
486 && ( sProductSource
.Copy( sProductSource
.Len() - 3 ) == sBuildId
.Copy( 0, 3 ) );
487 OSL_ENSURE( bMatchingUPD
, "BUILDID and ProductSource do not match in their UPD" );
489 sProductSource
= sProductSource
.Copy( 0, sProductSource
.Len() - 3 );
491 // prepend the product source
492 sBuildId
.Insert( sProductSource
, 0 );
495 // --> PB 2008-10-30 #i94693#
496 /* if the build ids of the basis or ure layer are different from the build id
497 * of the brand layer then show them */
498 rtl::OUString
aBasisProductBuildId( DEFINE_CONST_OUSTRING(
499 "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("version") ":ProductBuildid}" ) );
500 rtl::Bootstrap::expandMacros( aBasisProductBuildId
);
501 rtl::OUString
aUREProductBuildId( DEFINE_CONST_OUSTRING(
502 "${$URE_BIN_DIR/" SAL_CONFIGFILE("version") ":ProductBuildid}" ) );
503 rtl::Bootstrap::expandMacros( aUREProductBuildId
);
504 if ( sBuildId
.Search( String( aBasisProductBuildId
) ) == STRING_NOTFOUND
505 || sBuildId
.Search( String( aUREProductBuildId
) ) == STRING_NOTFOUND
)
508 sTemp
+= String( aBasisProductBuildId
);
510 sTemp
+= String( aUREProductBuildId
);
511 sBuildId
.Insert( sTemp
, sBuildId
.Search( ')' ) );
515 // the build id format is "milestone(build)[cwsname]". For readability, it would
516 // be nice to have some more spaces in there.
518 if ( ( nPos
= sBuildId
.Search( sal_Unicode( '(' ) ) ) != STRING_NOTFOUND
)
519 sBuildId
.Insert( sal_Unicode( ' ' ), nPos
);
520 if ( ( nPos
= sBuildId
.Search( sal_Unicode( '[' ) ) ) != STRING_NOTFOUND
)
521 sBuildId
.Insert( sal_Unicode( ' ' ), nPos
);
523 // search for the resource of the about box
524 ResId
aDialogResId( RID_DEFAULTABOUT
, *pAppData_Impl
->pLabelResMgr
);
525 ResMgr
* pResMgr
= pAppData_Impl
->pLabelResMgr
;
526 if( ! pResMgr
->IsAvailable( aDialogResId
.SetRT( RSC_MODALDIALOG
) ) )
527 pResMgr
= GetOffResManager_Impl();
529 aDialogResId
.SetResMgr( pResMgr
);
530 if ( !pResMgr
->IsAvailable( aDialogResId
) )
532 DBG_ERRORFILE( "No RID_DEFAULTABOUT in label-resource-dll" );
535 // then show the about box
536 AboutDialog
* pDlg
= new AboutDialog( 0, aDialogResId
, sBuildId
);
543 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
546 SfxTemplateOrganizeDlg
*pDlg
=
547 new SfxTemplateOrganizeDlg(NULL
);
554 case SID_TEMPLATE_ADDRESSBOKSOURCE
:
556 svt::AddressBookSourceDialog
aDialog(GetTopWindow(), ::comphelper::getProcessServiceFactory());
566 case SID_BASICBREAK
:
567 BASIC_DLL()->BasicBreak();
572 GetpApp()->Exception( EXC_SYSTEM
);
576 case SID_SHOW_IME_STATUS_WINDOW
:
577 if (pAppData_Impl
->m_xImeStatusWindow
->canToggle())
579 SfxBoolItem
const * pItem
= static_cast< SfxBoolItem
const * >(
580 rReq
.GetArg(SID_SHOW_IME_STATUS_WINDOW
, false,
582 bool bShow
= pItem
== 0
583 ? !pAppData_Impl
->m_xImeStatusWindow
->isShowing()
584 : ( pItem
->GetValue() == TRUE
);
585 pAppData_Impl
->m_xImeStatusWindow
->show(bShow
);
587 rReq
.AppendItem(SfxBoolItem(SID_SHOW_IME_STATUS_WINDOW
,
593 case SID_AVAILABLE_TOOLBARS
:
595 SfxStringItem
const * pToolbarName
= static_cast< SfxStringItem
const *>(
596 rReq
.GetArg(SID_AVAILABLE_TOOLBARS
, false, TYPE(SfxStringItem
)));
600 com::sun::star::uno::Reference
< com::sun::star::frame::XFrame
> xFrame
;
601 Reference
< XFramesSupplier
> xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance(
602 DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY
);
603 xFrame
= xDesktop
->getActiveFrame();
605 Reference
< com::sun::star::beans::XPropertySet
> xPropSet( xFrame
, UNO_QUERY
);
606 Reference
< ::com::sun::star::frame::XLayoutManager
> xLayoutManager
;
611 Any aValue
= xPropSet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
612 aValue
>>= xLayoutManager
;
614 catch ( ::com::sun::star::uno::RuntimeException
& e
)
618 catch ( ::com::sun::star::uno::Exception
& )
623 if ( xLayoutManager
.is() )
625 rtl::OUString
aToolbarResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/" ));
626 rtl::OUStringBuffer
aBuf( aToolbarResName
);
627 aBuf
.append( pToolbarName
->GetValue() );
629 // Parameter auswerten
630 rtl::OUString
aToolbarName( aBuf
.makeStringAndClear() );
631 BOOL
bShow( !xLayoutManager
->isElementVisible( aToolbarName
));
635 xLayoutManager
->createElement( aToolbarName
);
636 xLayoutManager
->showElement( aToolbarName
);
639 xLayoutManager
->hideElement( aToolbarName
);
655 //--------------------------------------------------------------------
657 void SfxApplication::MiscState_Impl(SfxItemSet
&rSet
)
661 LocaleDataWrapper
aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
662 const USHORT
*pRanges
= rSet
.GetRanges();
663 DBG_ASSERT(pRanges
&& *pRanges
, "Set ohne Bereich");
666 for(USHORT nWhich
= *pRanges
++; nWhich
<= *pRanges
; ++nWhich
)
670 case SID_TEMPLATE_ADDRESSBOKSOURCE
:
671 if ( !SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE
) )
672 rSet
.Put(SfxVisibilityItem(nWhich
, sal_False
));
674 case SID_EXITANDRETURN
:
677 if ( pAppData_Impl
->nDocModalMode
)
678 rSet
.DisableItem(nWhich
);
680 rSet
.Put(SfxStringItem(nWhich
, String(SfxResId(STR_QUITAPP
))));
685 case SID_TOOLBOXOPTIONS
:
686 case SID_CONFIGSTATUSBAR
:
688 case SID_CONFIGACCEL
:
689 case SID_CONFIGEVENT
:
691 if( SvtMiscOptions().DisableUICustomization() )
692 rSet
.DisableItem(nWhich
);
697 if ( !StarBASIC::IsRunning() )
698 rSet
.DisableItem(nWhich
);
703 rSet
.Put( SfxBoolItem( SID_HELPTIPS
, Help::IsQuickHelpEnabled() ) );
706 case SID_HELPBALLOONS
:
708 rSet
.Put( SfxBoolItem( SID_HELPBALLOONS
, Help::IsBalloonHelpEnabled() ) );
713 rSet
.Put( SfxBoolItem( SID_HELP_PI
, SvtHelpOptions().IsHelpAgentAutoStartMode() ) );
717 case SID_EXTENDEDHELP
:
725 Reference
< XFramesSupplier
> xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY
);
726 Reference
< XIndexAccess
> xTasks( xDesktop
->getFrames(), UNO_QUERY
);
727 if ( !xTasks
.is() || !xTasks
->getCount() )
728 rSet
.DisableItem(nWhich
);
734 BOOL bModified
= FALSE
;
735 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
737 pObjSh
= SfxObjectShell::GetNext( *pObjSh
) )
739 if ( pObjSh
->IsModified() )
747 rSet
.DisableItem( nWhich
);
751 case SID_SHOW_IME_STATUS_WINDOW
:
752 if (pAppData_Impl
->m_xImeStatusWindow
->canToggle())
753 rSet
.Put(SfxBoolItem(
754 SID_SHOW_IME_STATUS_WINDOW
,
755 pAppData_Impl
->m_xImeStatusWindow
->
758 rSet
.DisableItem(SID_SHOW_IME_STATUS_WINDOW
);
770 static const ::rtl::OUString
& getProductRegistrationServiceName( )
772 static ::rtl::OUString s_sServiceName
= ::rtl::OUString::createFromAscii( "com.sun.star.setup.ProductRegistration" );
773 return s_sServiceName
;
776 typedef rtl_uString
* (SAL_CALL
*basicide_choose_macro
)(XModel
*, BOOL
, rtl_uString
*);
777 typedef void (SAL_CALL
*basicide_macro_organizer
)( INT16
);
779 #define DOSTRING( x ) #x
780 #define STRING( x ) DOSTRING( x )
782 extern "C" { static void SAL_CALL
thisModule() {} }
784 ::rtl::OUString
ChooseMacro( const Reference
< XModel
>& rxLimitToDocument
, BOOL bChooseOnly
, const ::rtl::OUString
& rMacroDesc
= ::rtl::OUString() )
786 // get basctl dllname
787 String sLibName
= String::CreateFromAscii( STRING( DLL_NAME
) );
788 sLibName
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "sfx" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "basctl" ) ) );
789 ::rtl::OUString
aLibName( sLibName
);
792 oslModule handleMod
= osl_loadModuleRelative(
793 &thisModule
, aLibName
.pData
, 0 );
796 ::rtl::OUString
aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_choose_macro" ) );
797 basicide_choose_macro pSymbol
= (basicide_choose_macro
) osl_getFunctionSymbol( handleMod
, aSymbol
.pData
);
799 // call basicide_choose_macro in basctl
800 rtl_uString
* pScriptURL
= pSymbol( rxLimitToDocument
.get(), bChooseOnly
, rMacroDesc
.pData
);
801 ::rtl::OUString
aScriptURL( pScriptURL
);
802 rtl_uString_release( pScriptURL
);
806 void MacroOrganizer( INT16 nTabId
)
808 // get basctl dllname
809 String sLibName
= String::CreateFromAscii( STRING( DLL_NAME
) );
810 sLibName
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "sfx" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "basctl" ) ) );
811 ::rtl::OUString
aLibName( sLibName
);
814 oslModule handleMod
= osl_loadModuleRelative(
815 &thisModule
, aLibName
.pData
, 0 );
818 ::rtl::OUString
aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_macro_organizer" ) );
819 basicide_macro_organizer pSymbol
= (basicide_macro_organizer
) osl_getFunctionSymbol( handleMod
, aSymbol
.pData
);
821 // call basicide_macro_organizer in basctl
825 #define RID_ERRBOX_MODULENOTINSTALLED (RID_OFA_START + 72)
827 ResMgr
* SfxApplication::GetOffResManager_Impl()
829 if ( !pAppData_Impl
->pOfaResMgr
)
830 pAppData_Impl
->pOfaResMgr
= CreateResManager( "ofa");
831 return pAppData_Impl
->pOfaResMgr
;
836 Window
* lcl_getDialogParent( const Reference
< XFrame
>& _rxFrame
, Window
* _pFallback
)
838 if ( !_rxFrame
.is() )
843 Reference
< awt::XWindow
> xContainerWindow( _rxFrame
->getContainerWindow(), UNO_SET_THROW
);
844 Window
* pWindow
= VCLUnoHelper::GetWindow( xContainerWindow
);
845 OSL_ENSURE( pWindow
, "lcl_getDialogParent: cool, somebody implemented a VCL-less toolkit!" );
848 return pWindow
->GetSystemWindow();
850 catch( const Exception
& )
852 DBG_UNHANDLED_EXCEPTION();
858 void SfxApplication::OfaExec_Impl( SfxRequest
& rReq
)
861 switch ( rReq
.GetSlot() )
863 case SID_OPTIONS_TREEDIALOG
:
866 SFX_REQUEST_ARG( rReq
, pURLItem
, SfxStringItem
, SID_OPTIONS_PAGEURL
, sal_False
);
868 sPageURL
= pURLItem
->GetValue();
869 const SfxItemSet
* pArgs
= rReq
.GetInternalArgs_Impl();
870 const SfxPoolItem
* pItem
= NULL
;
871 Reference
< XFrame
> xFrame
;
872 if ( pArgs
&& pArgs
->GetItemState( SID_FILLFRAME
, sal_False
, &pItem
) == SFX_ITEM_SET
)
873 ( (SfxUnoAnyItem
*)pItem
)->GetValue() >>= xFrame
;
874 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
877 VclAbstractDialog
* pDlg
=
878 pFact
->CreateFrameDialog( NULL
, xFrame
, rReq
.GetSlot(), sPageURL
);
881 SfxViewFrame
* pView
= SfxViewFrame::GetFirst();
884 pView
->GetBindings().InvalidateAll(FALSE
);
885 pView
= SfxViewFrame::GetNext( *pView
);
891 case SID_MORE_DICTIONARIES
:
895 uno::Reference
< lang::XMultiServiceFactory
> xSMGR
=
896 ::comphelper::getProcessServiceFactory();
897 uno::Reference
< css::system::XSystemShellExecute
> xSystemShell(
898 xSMGR
->createInstance( DEFINE_CONST_UNICODE("com.sun.star.system.SystemShellExecute" ) ),
899 uno::UNO_QUERY_THROW
);
900 if ( xSystemShell
.is() )
901 xSystemShell
->execute( DEFINE_CONST_UNICODE("http://extensions.go-oo.org/dictionary?cid=926385"), ::rtl::OUString(), css::system::SystemShellExecuteFlags::DEFAULTS
);
903 catch( const ::com::sun::star::uno::Exception
& )
905 DBG_ERRORFILE( "SfxApplication::OfaExec_Impl(SID_MORE_DICTIONARIES): caught an exception!" );
910 case SID_ONLINE_REGISTRATION
:
914 // create the ProductRegistration component
915 Reference
< com::sun::star::lang::XMultiServiceFactory
> xORB( ::comphelper::getProcessServiceFactory() );
916 Reference
< com::sun::star::task::XJobExecutor
> xProductRegistration
;
918 xProductRegistration
= xProductRegistration
.query( xORB
->createInstance( getProductRegistrationServiceName() ) );
919 DBG_ASSERT( xProductRegistration
.is(), "OfficeApplication::ExecuteApp_Impl: could not create the service!" );
921 // tell it that the user wants to register
922 if ( xProductRegistration
.is() )
924 xProductRegistration
->trigger( ::rtl::OUString::createFromAscii( "RegistrationRequired" ) );
927 catch( const ::com::sun::star::uno::Exception
& )
929 DBG_ERROR( "OfficeApplication::ExecuteApp_Impl(SID_ONLINE_REGISTRATION): caught an exception!" );
934 case SID_BASICIDE_APPEAR
:
936 SfxViewFrame
* pView
= SfxViewFrame::GetFirst();
937 ::rtl::OUString
aBasicName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.BasicIDE" ) );
940 if ( pView
->GetObjectShell()->GetFactory().GetDocumentServiceName() == aBasicName
)
942 pView
= SfxViewFrame::GetNext( *pView
);
947 SfxObjectShell
* pDocShell
= SfxObjectShell::CreateObject( aBasicName
);
948 pDocShell
->DoInitNew( 0 );
949 pDocShell
->SetModified( FALSE
);
950 pView
= SfxViewFrame::CreateViewFrame( *pDocShell
, 0 );
951 pView
->SetName( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC:1" ) ) );
955 pView
->GetFrame()->Appear();
957 const SfxItemSet
* pArgs
= rReq
.GetArgs();
958 if ( pArgs
&& pView
)
960 SfxViewShell
* pViewShell
= pView
->GetViewShell();
961 SfxObjectShell
* pObjShell
= pView
->GetObjectShell();
962 if ( pViewShell
&& pObjShell
)
964 SfxRequest
aReq( SID_BASICIDE_SHOWWINDOW
, SFX_CALLMODE_SYNCHRON
, pObjShell
->GetPool() );
965 aReq
.SetArgs( *pArgs
);
966 pViewShell
->ExecuteSlot( aReq
);
974 case SID_BASICCHOOSER
:
976 const SfxItemSet
* pArgs
= rReq
.GetArgs();
977 const SfxPoolItem
* pItem
;
978 BOOL bChooseOnly
= FALSE
;
979 Reference
< XModel
> xLimitToModel
;
980 if(pArgs
&& SFX_ITEM_SET
== pArgs
->GetItemState(SID_RECORDMACRO
, sal_False
, &pItem
) )
982 BOOL bRecord
= ((SfxBoolItem
*)pItem
)->GetValue();
987 SfxObjectShell
* pCurrentShell
= SfxObjectShell::Current();
988 OSL_ENSURE( pCurrentShell
, "macro recording outside an SFX document?" );
990 xLimitToModel
= pCurrentShell
->GetModel();
994 rReq
.SetReturnValue( SfxStringItem( rReq
.GetSlot(), ChooseMacro( xLimitToModel
, bChooseOnly
) ) );
999 case SID_MACROORGANIZER
:
1001 OSL_TRACE("handling SID_MACROORGANIZER");
1002 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1003 const SfxPoolItem
* pItem
;
1005 if(pArgs
&& SFX_ITEM_SET
== pArgs
->GetItemState(SID_MACROORGANIZER
, sal_False
, &pItem
) )
1007 nTabId
= ((SfxUInt16Item
*)pItem
)->GetValue();
1010 SfxApplication::MacroOrganizer( nTabId
);
1017 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1018 OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
1020 Reference
< XFrame
> xFrame
;
1021 const SfxItemSet
* pIntSet
= rReq
.GetInternalArgs_Impl();
1022 SFX_ITEMSET_ARG( pIntSet
, pFrameItem
, SfxUnoAnyItem
, SID_FILLFRAME
, FALSE
);
1024 pFrameItem
->GetValue() >>= xFrame
;
1028 const SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
1029 const SfxFrame
* pFrame
= pViewFrame
? pViewFrame
->GetFrame() : NULL
;
1031 xFrame
= pFrame
->GetFrameInterface();
1034 do // artificial loop for flow control
1036 AbstractScriptSelectorDialog
* pDlg
= pFact
->CreateScriptSelectorDialog(
1037 lcl_getDialogParent( xFrame
, GetTopWindow() ), FALSE
, xFrame
);
1038 OSL_ENSURE( pDlg
, "SfxApplication::OfaExec_Impl( SID_RUNMACRO ): no dialog!" );
1041 pDlg
->SetRunLabel();
1043 short nDialogResult
= pDlg
->Execute();
1044 if ( !nDialogResult
)
1047 Sequence
< Any
> args
;
1048 Sequence
< sal_Int16
> outIndex
;
1049 Sequence
< Any
> outArgs
;
1052 Reference
< XInterface
> xScriptContext
;
1054 Reference
< XController
> xController
;
1056 xController
= xFrame
->getController();
1057 if ( xController
.is() )
1058 xScriptContext
= xController
->getModel();
1059 if ( !xScriptContext
.is() )
1060 xScriptContext
= xController
;
1062 SfxObjectShell::CallXScript( xScriptContext
, pDlg
->GetScriptURL(), args
, ret
, outIndex
, outArgs
);
1069 case SID_SCRIPTORGANIZER
:
1071 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1072 OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
1073 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1074 const SfxPoolItem
* pItem
;
1076 if(pArgs
&& SFX_ITEM_SET
== pArgs
->GetItemState(SID_SCRIPTORGANIZER
, sal_False
, &pItem
) )
1078 aLanguage
= ((SfxScriptOrganizerItem
*)pItem
)->getLanguage();
1081 ::rtl::OUString
aLang( aLanguage
);
1082 OSL_TRACE("SfxApplication::OfaExec_Impl: about to create dialog for: %s", ::rtl::OUStringToOString( aLang
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
1083 // not sure about the Window*
1084 VclAbstractDialog
* pDlg
= pFact
->CreateSvxScriptOrgDialog( GetTopWindow(), aLanguage
);
1091 OSL_TRACE("no dialog!!!");
1097 case SID_OFFICE_CHECK_PLZ
:
1099 sal_Bool bRet
= sal_False
;
1100 SFX_REQUEST_ARG(rReq
, pStringItem
, SfxStringItem
, rReq
.GetSlot(), sal_False
);
1104 String aPLZ
= pStringItem
->GetValue();
1105 bRet
= TRUE
/*!!!SfxIniManager::CheckPLZ( aPLZ )*/;
1108 SbxBase::SetError( SbxERR_WRONG_ARGS
);
1109 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bRet
) );
1113 case SID_AUTO_CORRECT_DLG
:
1115 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1118 SfxItemSet
aSet(GetPool(), SID_AUTO_CORRECT_DLG
, SID_AUTO_CORRECT_DLG
);
1119 const SfxPoolItem
* pItem
=NULL
;
1120 const SfxItemSet
* pSet
= rReq
.GetArgs();
1121 SfxItemPool
* pSetPool
= pSet
? pSet
->GetPool() : NULL
;
1122 if ( pSet
&& pSet
->GetItemState( pSetPool
->GetWhich( SID_AUTO_CORRECT_DLG
), FALSE
, &pItem
) == SFX_ITEM_SET
)
1125 SfxAbstractTabDialog
* pDlg
= pFact
->CreateTabDialog( RID_OFA_AUTOCORR_DLG
, NULL
, &aSet
, NULL
);
1133 case SID_SD_AUTOPILOT
:
1136 SvtModuleOptions aModuleOpt
;
1137 if ( !aModuleOpt
.IsImpress() )
1139 ErrorBox( 0, ResId( RID_ERRBOX_MODULENOTINSTALLED
, *GetOffResManager_Impl() )).Execute();
1143 Reference
< com::sun::star::lang::XMultiServiceFactory
> xORB
= ::comphelper::getProcessServiceFactory();
1144 Reference
< com::sun::star::frame::XDispatchProvider
> xProv(
1145 xORB
->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.drawing.ModuleDispatcher")), UNO_QUERY
);
1149 ::rtl::OUString aCmd
= ::rtl::OUString::createFromAscii( GetInterface()->GetSlot( rReq
.GetSlot() )->GetUnoName() );
1150 Reference
< com::sun::star::frame::XDispatchHelper
> xHelper(
1151 xORB
->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")), UNO_QUERY
);
1154 Sequence
< com::sun::star::beans::PropertyValue
> aSeq
;
1155 if ( rReq
.GetArgs() )
1156 TransformItems( rReq
.GetSlot(), *rReq
.GetArgs(), aSeq
);
1157 Any aResult
= xHelper
->executeDispatch( xProv
, aCmd
, ::rtl::OUString(), 0, aSeq
);
1158 ::com::sun::star::frame::DispatchResultEvent aEvent
;
1159 sal_Bool bSuccess
= (
1160 (aResult
>>= aEvent
) &&
1161 (aEvent
.State
== ::com::sun::star::frame::DispatchResultState::SUCCESS
)
1163 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bSuccess
) );
1170 case FN_BUSINESS_CARD
:
1171 case FN_XFORMS_INIT
:
1173 Reference
< com::sun::star::lang::XMultiServiceFactory
> xORB
= ::comphelper::getProcessServiceFactory();
1174 Reference
< com::sun::star::frame::XDispatchProvider
> xProv(
1175 xORB
->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.text.ModuleDispatcher")), UNO_QUERY
);
1179 ::rtl::OUString aCmd
= ::rtl::OUString::createFromAscii( GetInterface()->GetSlot( rReq
.GetSlot() )->GetUnoName() );
1180 Reference
< com::sun::star::frame::XDispatchHelper
> xHelper(
1181 xORB
->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")), UNO_QUERY
);
1184 Sequence
< com::sun::star::beans::PropertyValue
> aSeq
;
1185 if ( rReq
.GetArgs() )
1186 TransformItems( rReq
.GetSlot(), *rReq
.GetArgs(), aSeq
);
1187 Any aResult
= xHelper
->executeDispatch( xProv
, aCmd
, ::rtl::OUString(), 0, aSeq
);
1188 ::com::sun::star::frame::DispatchResultEvent aEvent
;
1189 sal_Bool bSuccess
= (
1190 (aResult
>>= aEvent
) &&
1191 (aEvent
.State
== ::com::sun::star::frame::DispatchResultState::SUCCESS
)
1193 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bSuccess
) );
1199 case SID_ADDRESS_DATA_SOURCE
:
1201 ::rtl::OUString
sDialogServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.AddressBookSourcePilot" ) );
1204 Reference
< com::sun::star::lang::XMultiServiceFactory
> xORB
= ::comphelper::getProcessServiceFactory();
1205 Reference
< com::sun::star::ui::dialogs::XExecutableDialog
> xDialog
;
1207 xDialog
= Reference
< com::sun::star::ui::dialogs::XExecutableDialog
>(xORB
->createInstance(sDialogServiceName
), UNO_QUERY
);
1211 ShowServiceNotAvailableError(NULL
, sDialogServiceName
, TRUE
);
1213 catch(::com::sun::star::uno::Exception
&)
1219 case SID_COMP_BIBLIOGRAPHY
:
1221 SfxStringItem
aURL(SID_FILE_NAME
, String::CreateFromAscii(".component:Bibliography/View1"));
1222 SfxStringItem
aRef(SID_REFERER
, String::CreateFromAscii("private:user"));
1223 SfxStringItem
aTarget(SID_TARGETNAME
, String::CreateFromAscii("_blank"));
1224 SfxViewFrame::Current()->GetDispatcher()->Execute( SID_OPENDOC
, SFX_CALLMODE_ASYNCHRON
, &aURL
, &aRef
, &aTarget
, 0L);
1230 void SfxApplication::OfaState_Impl(SfxItemSet
&rSet
)
1232 const USHORT
*pRanges
= rSet
.GetRanges();
1233 DBG_ASSERT(pRanges
&& *pRanges
, "Set ohne Bereich");
1236 for(USHORT nWhich
= *pRanges
++; nWhich
<= *pRanges
; ++nWhich
)
1240 case SID_ONLINE_REGISTRATION
:
1242 ::svt::RegOptions aOptions
;
1243 if ( !aOptions
.allowMenu() )
1244 rSet
.DisableItem( SID_ONLINE_REGISTRATION
);
1251 SvtModuleOptions aModuleOpt
;
1253 if( !aModuleOpt
.IsWriter())
1255 rSet
.DisableItem( FN_LABEL
);
1256 rSet
.DisableItem( FN_BUSINESS_CARD
);
1257 rSet
.DisableItem( FN_XFORMS_INIT
);
1260 if ( !aModuleOpt
.IsImpress() )
1261 rSet
.DisableItem( SID_SD_AUTOPILOT
);