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
);
701 case SID_CURRENTTIME
:
703 rSet
.Put( SfxStringItem( nWhich
, aLocaleWrapper
.getTime( Time(), FALSE
) ) );
706 case SID_CURRENTDATE
:
708 rSet
.Put( SfxStringItem( nWhich
, aLocaleWrapper
.getDate( Date() ) ) );
714 rSet
.Put( SfxBoolItem( SID_HELPTIPS
, Help::IsQuickHelpEnabled() ) );
717 case SID_HELPBALLOONS
:
719 rSet
.Put( SfxBoolItem( SID_HELPBALLOONS
, Help::IsBalloonHelpEnabled() ) );
724 rSet
.Put( SfxBoolItem( SID_HELP_PI
, SvtHelpOptions().IsHelpAgentAutoStartMode() ) );
728 case SID_EXTENDEDHELP
:
736 Reference
< XFramesSupplier
> xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY
);
737 Reference
< XIndexAccess
> xTasks( xDesktop
->getFrames(), UNO_QUERY
);
738 if ( !xTasks
.is() || !xTasks
->getCount() )
739 rSet
.DisableItem(nWhich
);
745 BOOL bModified
= FALSE
;
746 for ( SfxObjectShell
*pObjSh
= SfxObjectShell::GetFirst();
748 pObjSh
= SfxObjectShell::GetNext( *pObjSh
) )
750 if ( pObjSh
->IsModified() )
758 rSet
.DisableItem( nWhich
);
762 case SID_SHOW_IME_STATUS_WINDOW
:
763 if (pAppData_Impl
->m_xImeStatusWindow
->canToggle())
764 rSet
.Put(SfxBoolItem(
765 SID_SHOW_IME_STATUS_WINDOW
,
766 pAppData_Impl
->m_xImeStatusWindow
->
769 rSet
.DisableItem(SID_SHOW_IME_STATUS_WINDOW
);
781 static const ::rtl::OUString
& getProductRegistrationServiceName( )
783 static ::rtl::OUString s_sServiceName
= ::rtl::OUString::createFromAscii( "com.sun.star.setup.ProductRegistration" );
784 return s_sServiceName
;
787 typedef rtl_uString
* (SAL_CALL
*basicide_choose_macro
)(XModel
*, BOOL
, rtl_uString
*);
788 typedef void (SAL_CALL
*basicide_macro_organizer
)( INT16
);
790 #define DOSTRING( x ) #x
791 #define STRING( x ) DOSTRING( x )
793 extern "C" { static void SAL_CALL
thisModule() {} }
795 ::rtl::OUString
ChooseMacro( const Reference
< XModel
>& rxLimitToDocument
, BOOL bChooseOnly
, const ::rtl::OUString
& rMacroDesc
= ::rtl::OUString() )
797 // get basctl dllname
798 String sLibName
= String::CreateFromAscii( STRING( DLL_NAME
) );
799 sLibName
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "sfx" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "basctl" ) ) );
800 ::rtl::OUString
aLibName( sLibName
);
803 oslModule handleMod
= osl_loadModuleRelative(
804 &thisModule
, aLibName
.pData
, 0 );
807 ::rtl::OUString
aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_choose_macro" ) );
808 basicide_choose_macro pSymbol
= (basicide_choose_macro
) osl_getFunctionSymbol( handleMod
, aSymbol
.pData
);
810 // call basicide_choose_macro in basctl
811 rtl_uString
* pScriptURL
= pSymbol( rxLimitToDocument
.get(), bChooseOnly
, rMacroDesc
.pData
);
812 ::rtl::OUString
aScriptURL( pScriptURL
);
813 rtl_uString_release( pScriptURL
);
817 void MacroOrganizer( INT16 nTabId
)
819 // get basctl dllname
820 String sLibName
= String::CreateFromAscii( STRING( DLL_NAME
) );
821 sLibName
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "sfx" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "basctl" ) ) );
822 ::rtl::OUString
aLibName( sLibName
);
825 oslModule handleMod
= osl_loadModuleRelative(
826 &thisModule
, aLibName
.pData
, 0 );
829 ::rtl::OUString
aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_macro_organizer" ) );
830 basicide_macro_organizer pSymbol
= (basicide_macro_organizer
) osl_getFunctionSymbol( handleMod
, aSymbol
.pData
);
832 // call basicide_macro_organizer in basctl
836 #define RID_ERRBOX_MODULENOTINSTALLED (RID_OFA_START + 72)
838 ResMgr
* SfxApplication::GetOffResManager_Impl()
840 if ( !pAppData_Impl
->pOfaResMgr
)
841 pAppData_Impl
->pOfaResMgr
= CreateResManager( "ofa");
842 return pAppData_Impl
->pOfaResMgr
;
847 Window
* lcl_getDialogParent( const Reference
< XFrame
>& _rxFrame
, Window
* _pFallback
)
849 if ( !_rxFrame
.is() )
854 Reference
< awt::XWindow
> xContainerWindow( _rxFrame
->getContainerWindow(), UNO_SET_THROW
);
855 Window
* pWindow
= VCLUnoHelper::GetWindow( xContainerWindow
);
856 OSL_ENSURE( pWindow
, "lcl_getDialogParent: cool, somebody implemented a VCL-less toolkit!" );
859 return pWindow
->GetSystemWindow();
861 catch( const Exception
& )
863 DBG_UNHANDLED_EXCEPTION();
869 void SfxApplication::OfaExec_Impl( SfxRequest
& rReq
)
872 switch ( rReq
.GetSlot() )
874 case SID_OPTIONS_TREEDIALOG
:
877 SFX_REQUEST_ARG( rReq
, pURLItem
, SfxStringItem
, SID_OPTIONS_PAGEURL
, sal_False
);
879 sPageURL
= pURLItem
->GetValue();
880 const SfxItemSet
* pArgs
= rReq
.GetInternalArgs_Impl();
881 const SfxPoolItem
* pItem
= NULL
;
882 Reference
< XFrame
> xFrame
;
883 if ( pArgs
&& pArgs
->GetItemState( SID_FILLFRAME
, sal_False
, &pItem
) == SFX_ITEM_SET
)
884 ( (SfxUnoAnyItem
*)pItem
)->GetValue() >>= xFrame
;
885 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
888 VclAbstractDialog
* pDlg
=
889 pFact
->CreateFrameDialog( NULL
, xFrame
, rReq
.GetSlot(), sPageURL
);
896 case SID_MORE_DICTIONARIES
:
900 uno::Reference
< lang::XMultiServiceFactory
> xSMGR
=
901 ::comphelper::getProcessServiceFactory();
902 uno::Reference
< css::system::XSystemShellExecute
> xSystemShell(
903 xSMGR
->createInstance( DEFINE_CONST_UNICODE("com.sun.star.system.SystemShellExecute" ) ),
904 uno::UNO_QUERY_THROW
);
905 if ( xSystemShell
.is() )
906 xSystemShell
->execute( DEFINE_CONST_UNICODE("http://extensions.go-oo.org/dictionary?cid=926385"), ::rtl::OUString(), css::system::SystemShellExecuteFlags::DEFAULTS
);
908 catch( const ::com::sun::star::uno::Exception
& )
910 DBG_ERRORFILE( "SfxApplication::OfaExec_Impl(SID_MORE_DICTIONARIES): caught an exception!" );
915 case SID_ONLINE_REGISTRATION
:
919 // create the ProductRegistration component
920 Reference
< com::sun::star::lang::XMultiServiceFactory
> xORB( ::comphelper::getProcessServiceFactory() );
921 Reference
< com::sun::star::task::XJobExecutor
> xProductRegistration
;
923 xProductRegistration
= xProductRegistration
.query( xORB
->createInstance( getProductRegistrationServiceName() ) );
924 DBG_ASSERT( xProductRegistration
.is(), "OfficeApplication::ExecuteApp_Impl: could not create the service!" );
926 // tell it that the user wants to register
927 if ( xProductRegistration
.is() )
929 xProductRegistration
->trigger( ::rtl::OUString::createFromAscii( "RegistrationRequired" ) );
932 catch( const ::com::sun::star::uno::Exception
& )
934 DBG_ERROR( "OfficeApplication::ExecuteApp_Impl(SID_ONLINE_REGISTRATION): caught an exception!" );
939 case SID_BASICIDE_APPEAR
:
941 SfxViewFrame
* pView
= SfxViewFrame::GetFirst();
942 ::rtl::OUString
aBasicName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.BasicIDE" ) );
945 if ( pView
->GetObjectShell()->GetFactory().GetDocumentServiceName() == aBasicName
)
947 pView
= SfxViewFrame::GetNext( *pView
);
952 SfxObjectShell
* pDocShell
= SfxObjectShell::CreateObject( aBasicName
);
953 pDocShell
->DoInitNew( 0 );
954 pDocShell
->SetModified( FALSE
);
955 pView
= SfxViewFrame::CreateViewFrame( *pDocShell
, 0 );
956 pView
->SetName( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC:1" ) ) );
960 pView
->GetFrame()->Appear();
962 const SfxItemSet
* pArgs
= rReq
.GetArgs();
963 if ( pArgs
&& pView
)
965 SfxViewShell
* pViewShell
= pView
->GetViewShell();
966 SfxObjectShell
* pObjShell
= pView
->GetObjectShell();
967 if ( pViewShell
&& pObjShell
)
969 SfxRequest
aReq( SID_BASICIDE_SHOWWINDOW
, SFX_CALLMODE_SYNCHRON
, pObjShell
->GetPool() );
970 aReq
.SetArgs( *pArgs
);
971 pViewShell
->ExecuteSlot( aReq
);
979 case SID_BASICCHOOSER
:
981 const SfxItemSet
* pArgs
= rReq
.GetArgs();
982 const SfxPoolItem
* pItem
;
983 BOOL bChooseOnly
= FALSE
;
984 Reference
< XModel
> xLimitToModel
;
985 if(pArgs
&& SFX_ITEM_SET
== pArgs
->GetItemState(SID_RECORDMACRO
, sal_False
, &pItem
) )
987 BOOL bRecord
= ((SfxBoolItem
*)pItem
)->GetValue();
992 SfxObjectShell
* pCurrentShell
= SfxObjectShell::Current();
993 OSL_ENSURE( pCurrentShell
, "macro recording outside an SFX document?" );
995 xLimitToModel
= pCurrentShell
->GetModel();
999 rReq
.SetReturnValue( SfxStringItem( rReq
.GetSlot(), ChooseMacro( xLimitToModel
, bChooseOnly
) ) );
1004 case SID_MACROORGANIZER
:
1006 OSL_TRACE("handling SID_MACROORGANIZER");
1007 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1008 const SfxPoolItem
* pItem
;
1010 if(pArgs
&& SFX_ITEM_SET
== pArgs
->GetItemState(SID_MACROORGANIZER
, sal_False
, &pItem
) )
1012 nTabId
= ((SfxUInt16Item
*)pItem
)->GetValue();
1015 SfxApplication::MacroOrganizer( nTabId
);
1022 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1023 OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
1025 Reference
< XFrame
> xFrame
;
1026 const SfxItemSet
* pIntSet
= rReq
.GetInternalArgs_Impl();
1027 SFX_ITEMSET_ARG( pIntSet
, pFrameItem
, SfxUnoAnyItem
, SID_FILLFRAME
, FALSE
);
1029 pFrameItem
->GetValue() >>= xFrame
;
1033 const SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
1034 const SfxFrame
* pFrame
= pViewFrame
? pViewFrame
->GetFrame() : NULL
;
1036 xFrame
= pFrame
->GetFrameInterface();
1039 do // artificial loop for flow control
1041 AbstractScriptSelectorDialog
* pDlg
= pFact
->CreateScriptSelectorDialog(
1042 lcl_getDialogParent( xFrame
, GetTopWindow() ), FALSE
, xFrame
);
1043 OSL_ENSURE( pDlg
, "SfxApplication::OfaExec_Impl( SID_RUNMACRO ): no dialog!" );
1046 pDlg
->SetRunLabel();
1048 short nDialogResult
= pDlg
->Execute();
1049 if ( !nDialogResult
)
1052 Sequence
< Any
> args
;
1053 Sequence
< sal_Int16
> outIndex
;
1054 Sequence
< Any
> outArgs
;
1057 Reference
< XInterface
> xScriptContext
;
1059 Reference
< XController
> xController
;
1061 xController
= xFrame
->getController();
1062 if ( xController
.is() )
1063 xScriptContext
= xController
->getModel();
1064 if ( !xScriptContext
.is() )
1065 xScriptContext
= xController
;
1067 SfxObjectShell::CallXScript( xScriptContext
, pDlg
->GetScriptURL(), args
, ret
, outIndex
, outArgs
);
1074 case SID_SCRIPTORGANIZER
:
1076 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1077 OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
1078 const SfxItemSet
* pArgs
= rReq
.GetArgs();
1079 const SfxPoolItem
* pItem
;
1081 if(pArgs
&& SFX_ITEM_SET
== pArgs
->GetItemState(SID_SCRIPTORGANIZER
, sal_False
, &pItem
) )
1083 aLanguage
= ((SfxScriptOrganizerItem
*)pItem
)->getLanguage();
1086 ::rtl::OUString
aLang( aLanguage
);
1087 OSL_TRACE("SfxApplication::OfaExec_Impl: about to create dialog for: %s", ::rtl::OUStringToOString( aLang
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
1088 // not sure about the Window*
1089 VclAbstractDialog
* pDlg
= pFact
->CreateSvxScriptOrgDialog( GetTopWindow(), aLanguage
);
1096 OSL_TRACE("no dialog!!!");
1102 case SID_OFFICE_CHECK_PLZ
:
1104 sal_Bool bRet
= sal_False
;
1105 SFX_REQUEST_ARG(rReq
, pStringItem
, SfxStringItem
, rReq
.GetSlot(), sal_False
);
1109 String aPLZ
= pStringItem
->GetValue();
1110 bRet
= TRUE
/*!!!SfxIniManager::CheckPLZ( aPLZ )*/;
1113 SbxBase::SetError( SbxERR_WRONG_ARGS
);
1114 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bRet
) );
1118 case SID_AUTO_CORRECT_DLG
:
1120 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1123 SfxItemSet
aSet(GetPool(), SID_AUTO_CORRECT_DLG
, SID_AUTO_CORRECT_DLG
);
1124 const SfxPoolItem
* pItem
=NULL
;
1125 const SfxItemSet
* pSet
= rReq
.GetArgs();
1126 SfxItemPool
* pSetPool
= pSet
? pSet
->GetPool() : NULL
;
1127 if ( pSet
&& pSet
->GetItemState( pSetPool
->GetWhich( SID_AUTO_CORRECT_DLG
), FALSE
, &pItem
) == SFX_ITEM_SET
)
1130 SfxAbstractTabDialog
* pDlg
= pFact
->CreateTabDialog( RID_OFA_AUTOCORR_DLG
, NULL
, &aSet
, NULL
);
1138 case SID_SD_AUTOPILOT
:
1141 SvtModuleOptions aModuleOpt
;
1142 if ( !aModuleOpt
.IsImpress() )
1144 ErrorBox( 0, ResId( RID_ERRBOX_MODULENOTINSTALLED
, *GetOffResManager_Impl() )).Execute();
1148 Reference
< com::sun::star::lang::XMultiServiceFactory
> xORB
= ::comphelper::getProcessServiceFactory();
1149 Reference
< com::sun::star::frame::XDispatchProvider
> xProv(
1150 xORB
->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.drawing.ModuleDispatcher")), UNO_QUERY
);
1154 ::rtl::OUString aCmd
= ::rtl::OUString::createFromAscii( GetInterface()->GetSlot( rReq
.GetSlot() )->GetUnoName() );
1155 Reference
< com::sun::star::frame::XDispatchHelper
> xHelper(
1156 xORB
->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")), UNO_QUERY
);
1159 Sequence
< com::sun::star::beans::PropertyValue
> aSeq
;
1160 if ( rReq
.GetArgs() )
1161 TransformItems( rReq
.GetSlot(), *rReq
.GetArgs(), aSeq
);
1162 Any aResult
= xHelper
->executeDispatch( xProv
, aCmd
, ::rtl::OUString(), 0, aSeq
);
1163 ::com::sun::star::frame::DispatchResultEvent aEvent
;
1164 sal_Bool bSuccess
= (
1165 (aResult
>>= aEvent
) &&
1166 (aEvent
.State
== ::com::sun::star::frame::DispatchResultState::SUCCESS
)
1168 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bSuccess
) );
1175 case FN_BUSINESS_CARD
:
1176 case FN_XFORMS_INIT
:
1178 Reference
< com::sun::star::lang::XMultiServiceFactory
> xORB
= ::comphelper::getProcessServiceFactory();
1179 Reference
< com::sun::star::frame::XDispatchProvider
> xProv(
1180 xORB
->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.text.ModuleDispatcher")), UNO_QUERY
);
1184 ::rtl::OUString aCmd
= ::rtl::OUString::createFromAscii( GetInterface()->GetSlot( rReq
.GetSlot() )->GetUnoName() );
1185 Reference
< com::sun::star::frame::XDispatchHelper
> xHelper(
1186 xORB
->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")), UNO_QUERY
);
1189 Sequence
< com::sun::star::beans::PropertyValue
> aSeq
;
1190 if ( rReq
.GetArgs() )
1191 TransformItems( rReq
.GetSlot(), *rReq
.GetArgs(), aSeq
);
1192 Any aResult
= xHelper
->executeDispatch( xProv
, aCmd
, ::rtl::OUString(), 0, aSeq
);
1193 ::com::sun::star::frame::DispatchResultEvent aEvent
;
1194 sal_Bool bSuccess
= (
1195 (aResult
>>= aEvent
) &&
1196 (aEvent
.State
== ::com::sun::star::frame::DispatchResultState::SUCCESS
)
1198 rReq
.SetReturnValue( SfxBoolItem( rReq
.GetSlot(), bSuccess
) );
1204 case SID_ADDRESS_DATA_SOURCE
:
1206 ::rtl::OUString
sDialogServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.AddressBookSourcePilot" ) );
1209 Reference
< com::sun::star::lang::XMultiServiceFactory
> xORB
= ::comphelper::getProcessServiceFactory();
1210 Reference
< com::sun::star::ui::dialogs::XExecutableDialog
> xDialog
;
1212 xDialog
= Reference
< com::sun::star::ui::dialogs::XExecutableDialog
>(xORB
->createInstance(sDialogServiceName
), UNO_QUERY
);
1216 ShowServiceNotAvailableError(NULL
, sDialogServiceName
, TRUE
);
1218 catch(::com::sun::star::uno::Exception
&)
1224 case SID_COMP_BIBLIOGRAPHY
:
1226 SfxStringItem
aURL(SID_FILE_NAME
, String::CreateFromAscii(".component:Bibliography/View1"));
1227 SfxStringItem
aRef(SID_REFERER
, String::CreateFromAscii("private:user"));
1228 SfxStringItem
aTarget(SID_TARGETNAME
, String::CreateFromAscii("_blank"));
1229 SfxViewFrame::Current()->GetDispatcher()->Execute( SID_OPENDOC
, SFX_CALLMODE_ASYNCHRON
, &aURL
, &aRef
, &aTarget
, 0L);
1235 void SfxApplication::OfaState_Impl(SfxItemSet
&rSet
)
1237 const USHORT
*pRanges
= rSet
.GetRanges();
1238 DBG_ASSERT(pRanges
&& *pRanges
, "Set ohne Bereich");
1241 for(USHORT nWhich
= *pRanges
++; nWhich
<= *pRanges
; ++nWhich
)
1245 case SID_ONLINE_REGISTRATION
:
1247 ::svt::RegOptions aOptions
;
1248 if ( !aOptions
.allowMenu() )
1249 rSet
.DisableItem( SID_ONLINE_REGISTRATION
);
1256 SvtModuleOptions aModuleOpt
;
1258 if( !aModuleOpt
.IsWriter())
1260 rSet
.DisableItem( FN_LABEL
);
1261 rSet
.DisableItem( FN_BUSINESS_CARD
);
1262 rSet
.DisableItem( FN_XFORMS_INIT
);
1265 if ( !aModuleOpt
.IsImpress() )
1266 rSet
.DisableItem( SID_SD_AUTOPILOT
);