xref: /aoo42x/main/sfx2/source/appl/appserv.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sfx2.hxx"
30 #include <com/sun/star/uno/Reference.hxx>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/lang/IllegalArgumentException.hpp>
33 #include <com/sun/star/frame/DispatchResultEvent.hpp>
34 #include <com/sun/star/frame/DispatchResultState.hpp>
35 #include <com/sun/star/task/XJobExecutor.hpp>
36 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
37 #include <com/sun/star/frame/XDesktop.hpp>
38 #include <com/sun/star/frame/XDispatchHelper.hpp>
39 #include <com/sun/star/frame/XFramesSupplier.hpp>
40 #include <com/sun/star/util/XCloseable.hpp>
41 #include <com/sun/star/util/CloseVetoException.hpp>
42 #include <com/sun/star/frame/XLayoutManager.hpp>
43 #include <com/sun/star/document/XEmbeddedScripts.hpp>
44 #include <com/sun/star/embed/XStorage.hpp>
45 #include <com/sun/star/embed/ElementModes.hpp>
46 #include <com/sun/star/system/XSystemShellExecute.hpp>
47 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
48 #include <com/sun/star/system/SystemShellExecuteException.hpp>
49 
50 #include <comphelper/processfactory.hxx>
51 #include <comphelper/storagehelper.hxx>
52 #include "comphelper/configurationhelper.hxx"
53 
54 #include <svtools/addresstemplate.hxx>
55 #include <svl/visitem.hxx>
56 #include <unotools/intlwrapper.hxx>
57 
58 #include <unotools/configmgr.hxx>
59 #include <tools/config.hxx>
60 #include <tools/diagnose_ex.h>
61 #include <vcl/msgbox.hxx>
62 #include <svl/intitem.hxx>
63 #include <svl/eitem.hxx>
64 #include <svl/stritem.hxx>
65 #include <basic/sbstar.hxx>
66 #include <basic/basmgr.hxx>
67 #include <basic/basrdll.hxx>
68 #include <svtools/sfxecode.hxx>
69 #include <svtools/ehdl.hxx>
70 #include <vcl/help.hxx>
71 #include <vcl/stdtext.hxx>
72 #include <rtl/ustrbuf.hxx>
73 
74 #include <unotools/pathoptions.hxx>
75 #include <unotools/moduleoptions.hxx>
76 #include <unotools/regoptions.hxx>
77 #include <svtools/helpopt.hxx>
78 #include <toolkit/helper/vclunohelper.hxx>
79 #include <tools/shl.hxx>
80 #include <unotools/bootstrap.hxx>
81 #include <vos/process.hxx>
82 #include <rtl/bootstrap.hxx>
83 #include <cppuhelper/exc_hlp.hxx>
84 #include <rtl/ustrbuf.hxx>
85 
86 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
87 #include <com/sun/star/frame/XModuleManager.hpp>
88 #include <com/sun/star/beans/XPropertySet.hpp>
89 
90 #include "frmload.hxx"
91 #include "referers.hxx"
92 #include <sfx2/app.hxx>
93 #include <sfx2/request.hxx>
94 #include <sfx2/dispatch.hxx>
95 #include <sfx2/bindings.hxx>
96 #include <sfx2/msg.hxx>
97 #include <sfx2/objface.hxx>
98 #include <sfx2/objitem.hxx>
99 #include <sfx2/objsh.hxx>
100 #include <sfx2/hintpost.hxx>
101 #include <sfx2/viewsh.hxx>
102 #include <sfx2/docfac.hxx>
103 #include <sfx2/docfile.hxx>
104 #include <sfx2/docfilt.hxx>
105 #include "docvor.hxx"
106 #include <sfx2/new.hxx>
107 #include <sfx2/templdlg.hxx>
108 #include "sfxtypes.hxx"
109 #include <sfx2/tabdlg.hxx>
110 #include "arrdecl.hxx"
111 #include "fltfnc.hxx"
112 #include <sfx2/sfx.hrc>
113 #include "app.hrc"
114 #include <sfx2/passwd.hxx>
115 #include "sfx2/sfxresid.hxx"
116 #include "arrdecl.hxx"
117 #include <sfx2/childwin.hxx>
118 #include "appdata.hxx"
119 #include "sfx2/minfitem.hxx"
120 #include <sfx2/event.hxx>
121 #include <sfx2/module.hxx>
122 #include <sfx2/viewfrm.hxx>
123 #include "sfxpicklist.hxx"
124 #include "imestatuswindow.hxx"
125 #include <sfx2/sfxdlg.hxx>
126 #include <sfx2/dialogs.hrc>
127 #include "sorgitm.hxx"
128 #include "sfx2/sfxhelp.hxx"
129 #include <tools/svlibrary.hxx>
130 
131 using namespace ::com::sun::star;
132 using namespace ::com::sun::star::beans;
133 using namespace ::com::sun::star::uno;
134 using namespace ::com::sun::star::frame;
135 using namespace ::com::sun::star::container;
136 using namespace ::com::sun::star::util;
137 using namespace ::com::sun::star::script;
138 using namespace ::com::sun::star::system;
139 using namespace ::com::sun::star::lang;
140 using namespace ::com::sun::star::document;
141 
142 namespace css = com::sun::star;
143 
144 //-------------------------------------------------------------------------
145 long QuitAgain_Impl( void* pObj, void* pArg )
146 {
147 	SfxApplication* pApp = (SfxApplication*)pObj;
148 	Timer* pTimer = (Timer*)pArg;
149 	delete pTimer;
150 	pApp->GetDispatcher_Impl()->Execute( SID_QUITAPP, SFX_CALLMODE_ASYNCHRON );
151 	return 0;
152 }
153 
154 void SfxApplication::MiscExec_Impl( SfxRequest& rReq )
155 {
156 	DBG_MEMTEST();
157 	bool bDone = sal_False;
158 	switch ( rReq.GetSlot() )
159 	{
160 		case SID_SETOPTIONS:
161 		{
162 			if( rReq.GetArgs() )
163 				SetOptions_Impl( *rReq.GetArgs() );
164 			break;
165 		}
166 
167 		case SID_QUITAPP:
168 		case SID_EXITANDRETURN:
169         case SID_LOGOUT:
170 		{
171             // protect against reentrant calls
172             if ( pAppData_Impl->bInQuit )
173                 return;
174 
175             if ( rReq.GetSlot() == SID_LOGOUT )
176             {
177                 for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
178                     pObjSh; pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
179                 {
180                     if ( !pObjSh->IsModified() )
181                         continue;
182 
183                     SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pObjSh );
184                     if ( !pFrame || !pFrame->GetWindow().IsReallyVisible() )
185                         continue;
186 
187                     if ( pObjSh->PrepareClose(2) )
188                         pObjSh->SetModified( sal_False );
189                     else
190                         return;
191                 }
192 
193                 String aName = String::CreateFromAscii("vnd.sun.star.cmd:logout");
194                 SfxStringItem aNameItem( SID_FILE_NAME, aName );
195                 SfxStringItem aReferer( SID_REFERER, DEFINE_CONST_UNICODE( "private/user" ) );
196                 pAppData_Impl->pAppDispat->Execute( SID_OPENDOC, SFX_CALLMODE_SLOT, &aNameItem, &aReferer, 0L );
197                 return;
198             }
199 
200             // aus verschachtelten Requests nach 100ms nochmal probieren
201             if( Application::GetDispatchLevel() > 1 )
202             {
203                 /* Dont save the request for closing the application and try it later
204                    again. This is an UI bound functionality ... and the user will  try it again
205                    if the dialog is closed. But we shouldnt close the application automaticly
206                    if this dialog is closed by the user ...
207                    So we ignore this request now and wait for a new user decision.
208                 */
209                 DBG_TRACE1( "QueryExit => FALSE (DispatchLevel == %u)", Application::GetDispatchLevel() );
210                 return;
211             }
212 
213             // block reentrant calls
214             pAppData_Impl->bInQuit = sal_True;
215             Reference < XDesktop > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
216 
217             rReq.ForgetAllArgs();
218 
219             // if terminate() failed, pAppData_Impl->bInQuit will now be sal_False, allowing further calls of SID_QUITAPP
220 			sal_Bool bTerminated = xDesktop->terminate();
221 			if (!bTerminated)
222 				// if terminate() was successful, SfxApplication is now dead!
223 				pAppData_Impl->bInQuit = sal_False;
224 
225 			// Returnwert setzten, ggf. terminieren
226             rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bTerminated ) );
227 			return;
228 		}
229 
230 		case SID_CONFIG:
231 		case SID_TOOLBOXOPTIONS:
232 		case SID_CONFIGSTATUSBAR:
233 		case SID_CONFIGMENU:
234 		case SID_CONFIGACCEL:
235 		case SID_CONFIGEVENT:
236 		{
237 			SfxAbstractDialogFactory* pFact =
238 				SfxAbstractDialogFactory::Create();
239 
240 			if ( pFact )
241 			{
242 				SFX_REQUEST_ARG(rReq, pStringItem,
243 					SfxStringItem, SID_CONFIG, sal_False);
244 
245 				SfxItemSet aSet(
246 					GetPool(), SID_CONFIG, SID_CONFIG );
247 
248 				if ( pStringItem )
249 				{
250 					aSet.Put( SfxStringItem(
251 						SID_CONFIG, pStringItem->GetValue() ) );
252 				}
253 
254                 Reference< XFrame > xFrame;
255 				const SfxItemSet* pIntSet = rReq.GetInternalArgs_Impl();
256                 SFX_ITEMSET_ARG( pIntSet, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
257                 if ( pFrameItem )
258                     xFrame = pFrameItem->GetFrame();
259 
260 				SfxAbstractTabDialog* pDlg = pFact->CreateTabDialog(
261 					RID_SVXDLG_CUSTOMIZE,
262 					NULL, &aSet, xFrame );
263 
264 			  	if ( pDlg )
265 				{
266 					const short nRet = pDlg->Execute();
267 
268             		if ( nRet )
269                 		bDone = sal_True;
270 
271             		delete pDlg;
272 				}
273 			}
274 			break;
275 		}
276 
277 		case SID_CLOSEDOCS:
278 		case SID_CLOSEWINS:
279 		{
280 
281             Reference < XFramesSupplier > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
282             Reference< XIndexAccess > xTasks( xDesktop->getFrames(), UNO_QUERY );
283             if ( !xTasks.is() )
284                 break;
285 
286             sal_Int32 n=0;
287             do
288             {
289                 if ( xTasks->getCount() <= n )
290                     break;
291 
292                 Any aAny = xTasks->getByIndex(n);
293                 Reference < XCloseable > xTask;
294                 aAny >>= xTask;
295                 try
296                 {
297                     xTask->close(sal_True);
298                     n++;
299                 }
300                 catch( CloseVetoException& )
301                 {
302                 }
303             }
304             while( sal_True );
305 
306             sal_Bool bOk = ( n == 0);
307 			rReq.SetReturnValue( SfxBoolItem( 0, bOk ) );
308 			bDone = sal_True;
309 			break;
310 		}
311 
312 		case SID_SAVEDOCS:
313 		{
314 			sal_Bool bOK = sal_True;
315 			sal_Bool bTmpDone = sal_True;
316 			for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
317 				  pObjSh;
318 				  pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
319 			{
320 				SfxRequest aReq( SID_SAVEDOC, 0, pObjSh->GetPool() );
321 				if ( pObjSh->IsModified() )
322 				{
323 					pObjSh->ExecuteSlot( aReq );
324 					SfxBoolItem *pItem = PTR_CAST( SfxBoolItem, aReq.GetReturnValue() );
325 					bTmpDone = aReq.IsDone();
326 					if ( !pItem || !pItem->GetValue() )
327 						bOK = sal_False;
328 				}
329 			}
330 
331 			rReq.SetReturnValue( SfxBoolItem( 0, bOK ) );
332 			rReq.Done();
333 			break;
334 		}
335 
336         // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
337         case SID_HELPINDEX:
338         case SID_HELP_SUPPORTPAGE:
339         {
340             Help* pHelp = Application::GetHelp();
341             if ( pHelp )
342             {
343                 if ( rReq.GetSlot() == SID_HELP_SUPPORTPAGE )
344                 {
345                     // show Support page with new URL
346                     String sHelpURL = SfxHelp::CreateHelpURL( String::CreateFromAscii(".uno:HelpSupport"), String() );
347                     String sParams = sHelpURL.Copy( sHelpURL.Search( '?' ) );
348                     sHelpURL = String::CreateFromAscii("vnd.sun.star.help://shared/text/shared/05/00000001.xhp");
349                     sHelpURL += sParams;
350                     sHelpURL += String::CreateFromAscii("&UseDB=no");
351                     pHelp->Start( sHelpURL, NULL );
352                 }
353                 else
354                     pHelp->Start( String::CreateFromAscii(".uno:HelpIndex"), NULL ); // show start page
355                 bDone = sal_True;
356             }
357             break;
358         }
359 
360 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
361 		case SID_HELPTIPS:
362 		{
363 			// Parameter aus werten
364 			SFX_REQUEST_ARG(rReq, pOnItem, SfxBoolItem, SID_HELPTIPS, sal_False);
365 			bool bOn = pOnItem
366 							? ((SfxBoolItem*)pOnItem)->GetValue()
367 							: !Help::IsQuickHelpEnabled();
368 
369 			// ausf"uhren
370 			if ( bOn )
371 				Help::EnableQuickHelp();
372 			else
373 				Help::DisableQuickHelp();
374 			SvtHelpOptions().SetHelpTips( bOn );
375 			Invalidate(SID_HELPTIPS);
376 			bDone = sal_True;
377 
378 			// ggf. recorden
379 			if ( !rReq.IsAPI() )
380 				rReq.AppendItem( SfxBoolItem( SID_HELPTIPS, bOn) );
381 			break;
382 		}
383 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
384 		case SID_EXTENDEDHELP:
385 		{
386 			Help::StartExtHelp();
387 			break;
388 		}
389 		case SID_HELPBALLOONS:
390 		{
391 			// Parameter auswerten
392 			SFX_REQUEST_ARG(rReq, pOnItem, SfxBoolItem, SID_HELPBALLOONS, sal_False);
393 			bool bOn = pOnItem
394 							? ((SfxBoolItem*)pOnItem)->GetValue()
395 							: !Help::IsBalloonHelpEnabled();
396 
397 			// ausf"uhren
398 			if ( bOn )
399 				Help::EnableBalloonHelp();
400 			else
401 				Help::DisableBalloonHelp();
402 			SvtHelpOptions().SetExtendedHelp( bOn );
403 			Invalidate(SID_HELPBALLOONS);
404 			bDone = sal_True;
405 
406 			// ggf. recorden
407 			if ( !rReq.IsAPI() )
408 				rReq.AppendItem( SfxBoolItem( SID_HELPBALLOONS, bOn) );
409 			break;
410 		}
411 
412 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
413 		case SID_HELP_PI:
414 		{
415 			SvtHelpOptions aHelpOpt;
416 			SFX_REQUEST_ARG(rReq, pOnItem, SfxBoolItem, SID_HELP_PI, sal_False);
417 			sal_Bool bOn = pOnItem
418 							? ((SfxBoolItem*)pOnItem)->GetValue()
419 							: !aHelpOpt.IsHelpAgentAutoStartMode();
420 			aHelpOpt.SetHelpAgentAutoStartMode( bOn );
421 			Invalidate(SID_HELP_PI);
422 			bDone = sal_True;
423 			break;
424 		}
425 
426 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
427 		case SID_ABOUT:
428 		{
429  			SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
430 			if ( pFact )
431             {
432                 VclAbstractDialog* pDlg = pFact->CreateVclDialog( 0, RID_DEFAULTABOUT );
433 			    pDlg->Execute();
434 			    delete pDlg;
435 			    bDone = sal_True;
436             }
437 			break;
438 		}
439 
440 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
441 		case SID_ORGANIZER:
442 		{
443 			SfxTemplateOrganizeDlg  *pDlg =
444 				new SfxTemplateOrganizeDlg(NULL);
445 			pDlg->Execute();
446 			delete pDlg;
447 			bDone = sal_True;
448 			break;
449 		}
450 
451 		case SID_TEMPLATE_ADDRESSBOKSOURCE:
452 		{
453 			svt::AddressBookSourceDialog aDialog(GetTopWindow(), ::comphelper::getProcessServiceFactory());
454 			aDialog.Execute();
455 			bDone = sal_True;
456 			break;
457 		}
458 
459 		case SID_BASICSTOP:
460 			StarBASIC::Stop();
461 			break;
462 
463         case SID_BASICBREAK :
464             BASIC_DLL()->BasicBreak();
465             break;
466 
467         case SID_CRASH :
468         {
469             // Provoke a crash:
470             char * crash = 0;
471             *crash = 0;
472             break;
473         }
474 
475         case SID_SHOW_IME_STATUS_WINDOW:
476             if (pAppData_Impl->m_xImeStatusWindow->canToggle())
477             {
478                 SfxBoolItem const * pItem = static_cast< SfxBoolItem const * >(
479                     rReq.GetArg(SID_SHOW_IME_STATUS_WINDOW, false,
480                                 TYPE(SfxBoolItem)));
481                 bool bShow = pItem == 0
482                     ? !pAppData_Impl->m_xImeStatusWindow->isShowing()
483                     : ( pItem->GetValue() == sal_True );
484                 pAppData_Impl->m_xImeStatusWindow->show(bShow);
485                 if (pItem == 0)
486                     rReq.AppendItem(SfxBoolItem(SID_SHOW_IME_STATUS_WINDOW,
487                                                 bShow));
488             }
489             bDone = true;
490             break;
491 
492         case SID_AVAILABLE_TOOLBARS:
493         {
494             SfxStringItem const * pToolbarName = static_cast< SfxStringItem const *>(
495                     rReq.GetArg(SID_AVAILABLE_TOOLBARS, false, TYPE(SfxStringItem)));
496 
497             if ( pToolbarName )
498             {
499                 com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame;
500                 Reference < XFramesSupplier > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance(
501                                                             DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
502                 xFrame = xDesktop->getActiveFrame();
503 
504 	            Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
505                 Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
506 	            if ( xPropSet.is() )
507 	            {
508 		            try
509 		            {
510 			            Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
511 			            aValue >>= xLayoutManager;
512                     }
513                     catch ( ::com::sun::star::uno::RuntimeException& e )
514                     {
515                         throw e;
516                     }
517                     catch ( ::com::sun::star::uno::Exception& )
518                     {
519                     }
520                 }
521 
522                 if ( xLayoutManager.is() )
523                 {
524                     rtl::OUString aToolbarResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/" ));
525                     rtl::OUStringBuffer aBuf( aToolbarResName );
526                     aBuf.append( pToolbarName->GetValue() );
527 
528                     // Parameter auswerten
529                     rtl::OUString aToolbarName( aBuf.makeStringAndClear() );
530                     sal_Bool bShow( !xLayoutManager->isElementVisible( aToolbarName ));
531 
532                     if ( bShow )
533                     {
534                         xLayoutManager->createElement( aToolbarName );
535                         xLayoutManager->showElement( aToolbarName );
536                     }
537                     else
538                         xLayoutManager->hideElement( aToolbarName );
539                 }
540             }
541 
542             bDone = true;
543             break;
544         }
545 
546         default:
547             break;
548 	}
549 
550 	if ( bDone )
551 		rReq.Done();
552 }
553 
554 //--------------------------------------------------------------------
555 
556 void SfxApplication::MiscState_Impl(SfxItemSet &rSet)
557 {
558 	DBG_MEMTEST();
559 
560 	LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
561 	const sal_uInt16 *pRanges = rSet.GetRanges();
562 	DBG_ASSERT(pRanges && *pRanges, "Set ohne Bereich");
563 	while ( *pRanges )
564 	{
565 		for(sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
566 		{
567 			switch(nWhich)
568 			{
569                 case SID_TEMPLATE_ADDRESSBOKSOURCE:
570                     if ( !SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE) )
571                         rSet.Put(SfxVisibilityItem(nWhich, sal_False));
572                     break;
573 				case SID_EXITANDRETURN:
574 				case SID_QUITAPP:
575 				{
576 					if ( pAppData_Impl->nDocModalMode )
577 						rSet.DisableItem(nWhich);
578 					else
579                         rSet.Put(SfxStringItem(nWhich, String(SfxResId(STR_QUITAPP))));
580 					break;
581 				}
582 
583 				case SID_BASICSTOP:
584 					if ( !StarBASIC::IsRunning() )
585 						rSet.DisableItem(nWhich);
586 					break;
587 
588 				case SID_HELPTIPS:
589 				{
590 					rSet.Put( SfxBoolItem( SID_HELPTIPS, Help::IsQuickHelpEnabled() ) );
591 				}
592 				break;
593 				case SID_HELPBALLOONS:
594 				{
595 					rSet.Put( SfxBoolItem( SID_HELPBALLOONS, Help::IsBalloonHelpEnabled() ) );
596 				}
597 				break;
598 				case SID_HELP_PI:
599 				{
600 					rSet.Put( SfxBoolItem( SID_HELP_PI, SvtHelpOptions().IsHelpAgentAutoStartMode() ) );
601 				}
602 				break;
603 
604 				case SID_EXTENDEDHELP:
605 				{
606 				}
607 				break;
608 
609 				case SID_CLOSEDOCS:
610 				case SID_CLOSEWINS:
611 				{
612                     Reference < XFramesSupplier > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
613                     Reference< XIndexAccess > xTasks( xDesktop->getFrames(), UNO_QUERY );
614                     if ( !xTasks.is() || !xTasks->getCount() )
615 						rSet.DisableItem(nWhich);
616 					break;
617 				}
618 
619 				case SID_SAVEDOCS:
620 				{
621 					sal_Bool bModified = sal_False;
622 					for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
623 						  pObjSh;
624 						  pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
625 					{
626 						if ( pObjSh->IsModified() )
627 						{
628 							bModified = sal_True;
629 							break;
630 						}
631 					}
632 
633 					if ( !bModified )
634 						rSet.DisableItem( nWhich );
635 					break;
636 				}
637 
638                 case SID_SHOW_IME_STATUS_WINDOW:
639                     if (pAppData_Impl->m_xImeStatusWindow->canToggle())
640                         rSet.Put(SfxBoolItem(
641                                      SID_SHOW_IME_STATUS_WINDOW,
642                                      pAppData_Impl->m_xImeStatusWindow->
643                                          isShowing()));
644                     else
645                         rSet.DisableItem(SID_SHOW_IME_STATUS_WINDOW);
646                     break;
647 
648                 default:
649 					break;
650 			}
651 		}
652 
653 		++pRanges;
654 	}
655 }
656 
657 static const ::rtl::OUString& getProductRegistrationServiceName( )
658 {
659 	static ::rtl::OUString s_sServiceName = ::rtl::OUString::createFromAscii( "com.sun.star.setup.ProductRegistration" );
660 	return s_sServiceName;
661 }
662 
663 typedef	rtl_uString* (SAL_CALL *basicide_choose_macro)(XModel*, sal_Bool, rtl_uString*);
664 typedef	void (SAL_CALL *basicide_macro_organizer)( sal_Int16 );
665 
666 #define DOSTRING( x )			   			#x
667 #define STRING( x )				   			DOSTRING( x )
668 
669 extern "C" { static void SAL_CALL thisModule() {} }
670 
671 ::rtl::OUString ChooseMacro( const Reference< XModel >& rxLimitToDocument, sal_Bool bChooseOnly, const ::rtl::OUString& rMacroDesc = ::rtl::OUString() )
672 {
673     // get basctl dllname
674     static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "basctl" ) ) );
675 
676     // load module
677 	oslModule handleMod = osl_loadModuleRelative(
678         &thisModule, aLibName.pData, 0 );
679 
680     // get symbol
681     ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_choose_macro" ) );
682     basicide_choose_macro pSymbol = (basicide_choose_macro) osl_getFunctionSymbol( handleMod, aSymbol.pData );
683 
684     // call basicide_choose_macro in basctl
685     rtl_uString* pScriptURL = pSymbol( rxLimitToDocument.get(), bChooseOnly, rMacroDesc.pData );
686     ::rtl::OUString aScriptURL( pScriptURL );
687     rtl_uString_release( pScriptURL );
688 	return aScriptURL;
689 }
690 
691 void MacroOrganizer( sal_Int16 nTabId )
692 {
693     // get basctl dllname
694     static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "basctl" ) ) );
695 
696     // load module
697 	oslModule handleMod = osl_loadModuleRelative(
698         &thisModule, aLibName.pData, 0 );
699 
700     // get symbol
701     ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_macro_organizer" ) );
702     basicide_macro_organizer pSymbol = (basicide_macro_organizer) osl_getFunctionSymbol( handleMod, aSymbol.pData );
703 
704     // call basicide_macro_organizer in basctl
705     pSymbol( nTabId );
706 }
707 
708 #define RID_ERRBOX_MODULENOTINSTALLED     (RID_OFA_START + 72)
709 
710 ResMgr* SfxApplication::GetOffResManager_Impl()
711 {
712     if ( !pAppData_Impl->pOfaResMgr )
713         pAppData_Impl->pOfaResMgr = CreateResManager( "ofa");
714     return pAppData_Impl->pOfaResMgr;
715 }
716 
717 namespace
718 {
719     Window* lcl_getDialogParent( const Reference< XFrame >& _rxFrame, Window* _pFallback )
720     {
721         if ( !_rxFrame.is() )
722             return _pFallback;
723 
724         try
725         {
726             Reference< awt::XWindow > xContainerWindow( _rxFrame->getContainerWindow(), UNO_SET_THROW );
727             Window* pWindow = VCLUnoHelper::GetWindow( xContainerWindow );
728             OSL_ENSURE( pWindow, "lcl_getDialogParent: cool, somebody implemented a VCL-less toolkit!" );
729 
730             if ( pWindow )
731                 return pWindow->GetSystemWindow();
732         }
733         catch( const Exception& )
734         {
735         	DBG_UNHANDLED_EXCEPTION();
736         }
737         return _pFallback;
738     }
739 
740     const ::rtl::OUString& lcl_getBasicIDEServiceName()
741     {
742         static const ::rtl::OUString s_sBasicName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.BasicIDE" ) );
743         return s_sBasicName;
744     }
745 
746     SfxViewFrame* lcl_getBasicIDEViewFrame( SfxObjectShell* i_pBasicIDE )
747     {
748         SfxViewFrame* pView = SfxViewFrame::GetFirst( i_pBasicIDE );
749         while ( pView )
750         {
751             if ( pView->GetObjectShell()->GetFactory().GetDocumentServiceName() == lcl_getBasicIDEServiceName() )
752                 break;
753             pView = SfxViewFrame::GetNext( *pView, i_pBasicIDE );
754         }
755         return pView;
756     }
757     Reference< XFrame > lcl_findStartModuleFrame( const ::comphelper::ComponentContext& i_rContext )
758     {
759         try
760         {
761             Reference < XFramesSupplier > xSupplier( i_rContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW );
762             Reference < XIndexAccess > xContainer( xSupplier->getFrames(), UNO_QUERY_THROW );
763 
764             Reference< XModuleManager > xCheck( i_rContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW );
765 
766             sal_Int32 nCount = xContainer->getCount();
767             for ( sal_Int32 i=0; i<nCount; ++i )
768             {
769                 try
770                 {
771                     Reference < XFrame > xFrame( xContainer->getByIndex(i), UNO_QUERY_THROW );
772                     ::rtl::OUString sModule = xCheck->identify( xFrame );
773                     if ( sModule.equalsAscii( "com.sun.star.frame.StartModule" ) )
774                         return xFrame;
775                 }
776                 catch( const UnknownModuleException& )
777                 {
778                     // silence
779                 }
780                 catch(const Exception&)
781                 {
782                     // re-throw, caught below
783                     throw;
784                 }
785             }
786         }
787         catch( const Exception& )
788         {
789                DBG_UNHANDLED_EXCEPTION();
790         }
791         return NULL;
792     }
793 }
794 
795 static ::rtl::OUString getConfigurationStringValue(
796     const ::rtl::OUString& rPackage,
797     const ::rtl::OUString& rRelPath,
798     const ::rtl::OUString& rKey,
799     const ::rtl::OUString& rDefaultValue )
800 {
801     ::rtl::OUString aDefVal( rDefaultValue );
802 
803     try
804     {
805         ::comphelper::ConfigurationHelper::readDirectKey(
806             comphelper::getProcessServiceFactory(),
807             rPackage,
808             rRelPath,
809             rKey,
810             ::comphelper::ConfigurationHelper::E_READONLY) >>= aDefVal;
811     }
812     catch(const com::sun::star::uno::RuntimeException& exRun)
813     { throw exRun; }
814     catch(const com::sun::star::uno::Exception&)
815     {}
816 
817     return aDefVal;
818 }
819 
820 void SfxApplication::OfaExec_Impl( SfxRequest& rReq )
821 {
822 	DBG_MEMTEST();
823 	switch ( rReq.GetSlot() )
824 	{
825 		case SID_OPTIONS_TREEDIALOG:
826 		{
827             String sPageURL;
828             SFX_REQUEST_ARG( rReq, pURLItem, SfxStringItem, SID_OPTIONS_PAGEURL, sal_False );
829             if ( pURLItem )
830                 sPageURL = pURLItem->GetValue();
831             const SfxItemSet* pArgs = rReq.GetInternalArgs_Impl();
832             const SfxPoolItem* pItem = NULL;
833             Reference < XFrame > xFrame;
834             if ( pArgs && pArgs->GetItemState( SID_FILLFRAME, sal_False, &pItem ) == SFX_ITEM_SET )
835             {
836                 OSL_ENSURE( pItem->ISA( SfxUnoFrameItem ), "SfxApplication::OfaExec_Impl: XFrames are to be transported via SfxUnoFrameItem by now!" );
837                 xFrame = static_cast< const SfxUnoFrameItem*>( pItem )->GetFrame();
838             }
839 			SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
840 			if ( pFact )
841 			{
842                 VclAbstractDialog* pDlg =
843                     pFact->CreateFrameDialog( NULL, xFrame, rReq.GetSlot(), sPageURL );
844 			  	pDlg->Execute();
845 			  	delete pDlg;
846 				SfxViewFrame* pView = SfxViewFrame::GetFirst();
847 				while ( pView )
848 				{
849 					pView->GetBindings().InvalidateAll(sal_False);
850 					pView = SfxViewFrame::GetNext( *pView );
851 				}
852 			}
853 			break;
854 		}
855 
856         case SID_MORE_DICTIONARIES:
857         {
858             try
859             {
860                 uno::Reference< lang::XMultiServiceFactory > xSMGR =
861                     ::comphelper::getProcessServiceFactory();
862                 uno::Reference< css::system::XSystemShellExecute > xSystemShell(
863                     xSMGR->createInstance( DEFINE_CONST_UNICODE("com.sun.star.system.SystemShellExecute" ) ),
864                     uno::UNO_QUERY_THROW );
865 
866                 // read repository URL from configuration
867                 ::rtl::OUString sTemplRepoURL =
868                     getConfigurationStringValue(
869                         ::rtl::OUString::createFromAscii("org.openoffice.Office.Common"),
870                         ::rtl::OUString::createFromAscii("Dictionaries"),
871                         ::rtl::OUString::createFromAscii("RepositoryURL"),
872                         ::rtl::OUString());
873 
874                 if ( xSystemShell.is() && sTemplRepoURL.getLength() > 0 )
875                 {
876                     ::rtl::OUStringBuffer aURLBuf( sTemplRepoURL );
877                     aURLBuf.appendAscii( "?" );
878                     aURLBuf.appendAscii( "lang=" );
879 
880                     // read locale from configuration
881                     ::rtl::OUString sLocale = getConfigurationStringValue(
882                         ::rtl::OUString::createFromAscii("org.openoffice.Setup"),
883                         ::rtl::OUString::createFromAscii("L10N"),
884                         ::rtl::OUString::createFromAscii("ooLocale"),
885                         ::rtl::OUString::createFromAscii("en-US"));
886 
887                     aURLBuf.append( sLocale );
888                     xSystemShell->execute(
889                         aURLBuf.makeStringAndClear(),
890                         ::rtl::OUString(),
891                         css::system::SystemShellExecuteFlags::DEFAULTS );
892                 }
893             }
894             catch( const ::com::sun::star::uno::Exception& )
895             {
896                 DBG_ERRORFILE( "SfxApplication::OfaExec_Impl(SID_MORE_DICTIONARIES): caught an exception!" );
897             }
898             break;
899         }
900 
901 		case SID_ONLINE_REGISTRATION:
902 		{
903 			try
904 			{
905 				// create the ProductRegistration component
906 				Reference< com::sun::star::lang::XMultiServiceFactory > xORB( ::comphelper::getProcessServiceFactory() );
907 				Reference< com::sun::star::task::XJobExecutor > xProductRegistration;
908 				if ( xORB.is() )
909 					xProductRegistration = xProductRegistration.query( xORB->createInstance( getProductRegistrationServiceName() ) );
910 				DBG_ASSERT( xProductRegistration.is(), "OfficeApplication::ExecuteApp_Impl: could not create the service!" );
911 
912 				// tell it that the user wants to register
913 				if ( xProductRegistration.is() )
914 				{
915 					xProductRegistration->trigger( ::rtl::OUString::createFromAscii( "RegistrationRequired" ) );
916 				}
917 			}
918 			catch( const ::com::sun::star::uno::Exception& )
919 			{
920 				DBG_ERROR( "OfficeApplication::ExecuteApp_Impl(SID_ONLINE_REGISTRATION): caught an exception!" );
921 			}
922 		}
923 		break;
924 
925 		case SID_BASICIDE_APPEAR:
926 		{
927             SfxViewFrame* pView = lcl_getBasicIDEViewFrame( NULL );
928             if ( !pView )
929             {
930                 SfxObjectShell* pBasicIDE = SfxObjectShell::CreateObject( lcl_getBasicIDEServiceName() );
931                 pBasicIDE->DoInitNew( 0 );
932                 pBasicIDE->SetModified( sal_False );
933                 try
934                 {
935                     // load the Basic IDE via direct access to the SFX frame loader. A generic loadComponentFromURL
936                     // (which could be done via SfxViewFrame::LoadDocumentIntoFrame) is not feasible here, since the Basic IDE
937                     // does not really play nice with the framework's concept. For instance, it is a "singleton document",
938                     // which conflicts, at the latest, with the framework's concept of loading into _blank frames.
939                     // So, since we know that our frame loader can handle it, we skip the generic framework loader
940                     // mechanism, and the type detection (which doesn't know about the Basic IDE).
941                     ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
942                     Reference< XSynchronousFrameLoader > xLoader( aContext.createComponent(
943                         SfxFrameLoader_Impl::impl_getStaticImplementationName() ), UNO_QUERY_THROW );
944                     ::comphelper::NamedValueCollection aLoadArgs;
945                     aLoadArgs.put( "Model", pBasicIDE->GetModel() );
946                     aLoadArgs.put( "URL", ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:factory/sbasic" ) ) );
947 
948                     Reference< XFrame > xTargetFrame( lcl_findStartModuleFrame( aContext ) );
949                     if ( !xTargetFrame.is() )
950                         xTargetFrame = SfxFrame::CreateBlankFrame();
951                     ENSURE_OR_THROW( xTargetFrame.is(), "could not obtain a frameto load the Basic IDE into!" );
952 
953                     xLoader->load( aLoadArgs.getPropertyValues(), xTargetFrame );
954                 }
955                 catch( const Exception& )
956                 {
957                 	DBG_UNHANDLED_EXCEPTION();
958                 }
959 
960                 pView = lcl_getBasicIDEViewFrame( pBasicIDE );
961                 if ( pView )
962                     pView->SetName( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC:1" ) ) );
963             }
964 
965             if ( pView )
966                 pView->GetFrame().Appear();
967 
968             const SfxItemSet* pArgs = rReq.GetArgs();
969             if ( pArgs && pView )
970             {
971                 SfxViewShell* pViewShell = pView->GetViewShell();
972                 SfxObjectShell* pObjShell = pView->GetObjectShell();
973                 if ( pViewShell && pObjShell )
974                 {
975                     SfxRequest aReq( SID_BASICIDE_SHOWWINDOW, SFX_CALLMODE_SYNCHRON, pObjShell->GetPool() );
976                     aReq.SetArgs( *pArgs );
977                     pViewShell->ExecuteSlot( aReq );
978                 }
979             }
980 
981 			rReq.Done();
982 		}
983 		break;
984 
985 		case SID_BASICCHOOSER:
986 		{
987 			const SfxItemSet* pArgs = rReq.GetArgs();
988 			const SfxPoolItem* pItem;
989             sal_Bool bChooseOnly = sal_False;
990             Reference< XModel > xLimitToModel;
991             if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_RECORDMACRO, sal_False, &pItem) )
992             {
993                 sal_Bool bRecord = ((SfxBoolItem*)pItem)->GetValue();
994                 if ( bRecord )
995                 {
996                     // !Hack
997                     bChooseOnly = sal_False;
998                     SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
999                     OSL_ENSURE( pCurrentShell, "macro recording outside an SFX document?" );
1000                     if ( pCurrentShell )
1001                         xLimitToModel = pCurrentShell->GetModel();
1002                 }
1003             }
1004 
1005             rReq.SetReturnValue( SfxStringItem( rReq.GetSlot(), ChooseMacro( xLimitToModel, bChooseOnly ) ) );
1006 			rReq.Done();
1007 		}
1008 		break;
1009 
1010 		case SID_MACROORGANIZER:
1011 		{
1012             OSL_TRACE("handling SID_MACROORGANIZER");
1013 			const SfxItemSet* pArgs = rReq.GetArgs();
1014 			const SfxPoolItem* pItem;
1015             sal_Int16 nTabId = 0;
1016             if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_MACROORGANIZER, sal_False, &pItem) )
1017             {
1018                 nTabId = ((SfxUInt16Item*)pItem)->GetValue();
1019             }
1020 
1021             SfxApplication::MacroOrganizer( nTabId );
1022 			rReq.Done();
1023 		}
1024 		break;
1025 
1026         case SID_RUNMACRO:
1027         {
1028             SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1029             OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
1030 
1031             Reference< XFrame > xFrame;
1032 			const SfxItemSet* pIntSet = rReq.GetInternalArgs_Impl();
1033             SFX_ITEMSET_ARG( pIntSet, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
1034             if ( pFrameItem )
1035                 xFrame = pFrameItem->GetFrame();
1036 
1037             if ( !xFrame.is() )
1038             {
1039                 const SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1040                 if ( pViewFrame )
1041                     xFrame = pViewFrame->GetFrame().GetFrameInterface();
1042             }
1043 
1044             do  // artificial loop for flow control
1045             {
1046                 AbstractScriptSelectorDialog* pDlg = pFact->CreateScriptSelectorDialog(
1047                     lcl_getDialogParent( xFrame, GetTopWindow() ), sal_False, xFrame );
1048                 OSL_ENSURE( pDlg, "SfxApplication::OfaExec_Impl( SID_RUNMACRO ): no dialog!" );
1049                 if ( !pDlg )
1050                     break;
1051                 pDlg->SetRunLabel();
1052 
1053                 short nDialogResult = pDlg->Execute();
1054                 if ( !nDialogResult )
1055                     break;
1056 
1057                 Sequence< Any > args;
1058                 Sequence< sal_Int16 > outIndex;
1059                 Sequence< Any > outArgs;
1060                 Any ret;
1061 
1062                 Reference< XInterface > xScriptContext;
1063 
1064                 Reference< XController > xController;
1065                 if ( xFrame.is() )
1066                     xController = xFrame->getController();
1067                 if ( xController.is() )
1068                     xScriptContext = xController->getModel();
1069                 if ( !xScriptContext.is() )
1070                     xScriptContext = xController;
1071 
1072                 SfxObjectShell::CallXScript( xScriptContext, pDlg->GetScriptURL(), args, ret, outIndex, outArgs );
1073             }
1074             while ( false );
1075 			rReq.Done();
1076 		}
1077         break;
1078 
1079         case SID_SCRIPTORGANIZER:
1080         {
1081             SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1082             OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
1083 			const SfxItemSet* pArgs = rReq.GetArgs();
1084 			const SfxPoolItem* pItem;
1085             String aLanguage;
1086             if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_SCRIPTORGANIZER, sal_False, &pItem) )
1087             {
1088                 aLanguage = ((SfxScriptOrganizerItem*)pItem)->getLanguage();
1089             }
1090 
1091             ::rtl::OUString aLang( aLanguage );
1092             OSL_TRACE("SfxApplication::OfaExec_Impl: about to create dialog for: %s", ::rtl::OUStringToOString( aLang , RTL_TEXTENCODING_ASCII_US ).pData->buffer);
1093             // not sure about the Window*
1094             VclAbstractDialog* pDlg = pFact->CreateSvxScriptOrgDialog( GetTopWindow(), aLanguage );
1095             if( pDlg )
1096             {
1097                 pDlg->Execute();
1098             }
1099             else
1100             {
1101                 OSL_TRACE("no dialog!!!");
1102             }
1103 			rReq.Done();
1104 		}
1105 		break;
1106 
1107 		case SID_OFFICE_CHECK_PLZ:
1108 		{
1109 			sal_Bool bRet = sal_False;
1110 			SFX_REQUEST_ARG(rReq, pStringItem, SfxStringItem, rReq.GetSlot(), sal_False);
1111 
1112 			if ( pStringItem )
1113 			{
1114 				String aPLZ = pStringItem->GetValue();
1115 				bRet = sal_True /*!!!SfxIniManager::CheckPLZ( aPLZ )*/;
1116 			}
1117 			else
1118 				SbxBase::SetError( SbxERR_WRONG_ARGS );
1119 			rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bRet ) );
1120 		}
1121 		break;
1122 
1123         case SID_AUTO_CORRECT_DLG:
1124 		{
1125 			SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1126 			if ( pFact )
1127 			{
1128 				SfxItemSet aSet(GetPool(), SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG);
1129 				const SfxPoolItem* pItem=NULL;
1130 				const SfxItemSet* pSet = rReq.GetArgs();
1131 				SfxItemPool* pSetPool = pSet ? pSet->GetPool() : NULL;
1132 				if ( pSet && pSet->GetItemState( pSetPool->GetWhich( SID_AUTO_CORRECT_DLG ), sal_False, &pItem ) == SFX_ITEM_SET )
1133 					aSet.Put( *pItem );
1134 
1135 			  	SfxAbstractTabDialog* pDlg = pFact->CreateTabDialog( RID_OFA_AUTOCORR_DLG, NULL, &aSet, NULL );
1136 			  	pDlg->Execute();
1137 			  	delete pDlg;
1138 			}
1139 
1140 			break;
1141 		}
1142 
1143 		case SID_SD_AUTOPILOT :
1144 		case SID_NEWSD :
1145 		{
1146 			SvtModuleOptions aModuleOpt;
1147 			if ( !aModuleOpt.IsImpress() )
1148 			{
1149 				ErrorBox( 0, ResId( RID_ERRBOX_MODULENOTINSTALLED, *GetOffResManager_Impl() )).Execute();
1150 				return;
1151 			}
1152 
1153 			Reference< com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
1154 			Reference< com::sun::star::frame::XDispatchProvider > xProv(
1155 				xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.drawing.ModuleDispatcher")), UNO_QUERY );
1156 
1157 			if ( xProv.is() )
1158 			{
1159 				::rtl::OUString aCmd = ::rtl::OUString::createFromAscii( GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName() );
1160 				Reference< com::sun::star::frame::XDispatchHelper > xHelper(
1161 					xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")), UNO_QUERY );
1162 				if ( xHelper.is() )
1163 				{
1164 					Sequence < com::sun::star::beans::PropertyValue > aSeq;
1165 					if ( rReq.GetArgs() )
1166 						TransformItems( rReq.GetSlot(), *rReq.GetArgs(), aSeq );
1167 					Any aResult = xHelper->executeDispatch( xProv, aCmd, ::rtl::OUString(), 0, aSeq );
1168 					::com::sun::star::frame::DispatchResultEvent aEvent;
1169 					sal_Bool bSuccess = (
1170 										 (aResult >>= aEvent) &&
1171                                          (aEvent.State == ::com::sun::star::frame::DispatchResultState::SUCCESS)
1172 										);
1173 					rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
1174 				}
1175 			}
1176 		}
1177 		break;
1178 
1179         case FN_LABEL :
1180         case FN_BUSINESS_CARD :
1181         case FN_XFORMS_INIT :
1182 		{
1183 			Reference< com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
1184 			Reference< com::sun::star::frame::XDispatchProvider > xProv(
1185 				xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.text.ModuleDispatcher")), UNO_QUERY );
1186 
1187 			if ( xProv.is() )
1188 			{
1189 				::rtl::OUString aCmd = ::rtl::OUString::createFromAscii( GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName() );
1190 				Reference< com::sun::star::frame::XDispatchHelper > xHelper(
1191 					xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")), UNO_QUERY );
1192 				if ( xHelper.is() )
1193 				{
1194 					Sequence < com::sun::star::beans::PropertyValue > aSeq;
1195 					if ( rReq.GetArgs() )
1196 						TransformItems( rReq.GetSlot(), *rReq.GetArgs(), aSeq );
1197 					Any aResult = xHelper->executeDispatch( xProv, aCmd, ::rtl::OUString(), 0, aSeq );
1198 					::com::sun::star::frame::DispatchResultEvent aEvent;
1199 					sal_Bool bSuccess = (
1200 										 (aResult >>= aEvent) &&
1201                                          (aEvent.State == ::com::sun::star::frame::DispatchResultState::SUCCESS)
1202 										);
1203 					rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
1204 				}
1205 			}
1206 		}
1207 		break;
1208 
1209 		case SID_ADDRESS_DATA_SOURCE:
1210 		{
1211             ::rtl::OUString sDialogServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.AddressBookSourcePilot" ) );
1212 			try
1213 			{
1214 				Reference< com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
1215 				Reference< com::sun::star::ui::dialogs::XExecutableDialog > xDialog;
1216 				if (xORB.is())
1217 					xDialog = Reference< com::sun::star::ui::dialogs::XExecutableDialog >(xORB->createInstance(sDialogServiceName), UNO_QUERY);
1218 				if (xDialog.is())
1219 					xDialog->execute();
1220 				else
1221 					ShowServiceNotAvailableError(NULL, sDialogServiceName, sal_True);
1222 			}
1223 			catch(::com::sun::star::uno::Exception&)
1224 			{
1225 			}
1226 		}
1227 		break;
1228 
1229 		case SID_COMP_BIBLIOGRAPHY:
1230 		{
1231 			SfxStringItem aURL(SID_FILE_NAME, String::CreateFromAscii(".component:Bibliography/View1"));
1232 			SfxStringItem aRef(SID_REFERER, String::CreateFromAscii("private:user"));
1233 			SfxStringItem aTarget(SID_TARGETNAME, String::CreateFromAscii("_blank"));
1234 			SfxViewFrame::Current()->GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, &aURL, &aRef, &aTarget, 0L);
1235 		}
1236 		break;
1237 	}
1238 }
1239 
1240 void SfxApplication::OfaState_Impl(SfxItemSet &rSet)
1241 {
1242 	const sal_uInt16 *pRanges = rSet.GetRanges();
1243 	DBG_ASSERT(pRanges && *pRanges, "Set ohne Bereich");
1244 	while ( *pRanges )
1245 	{
1246 		for(sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
1247 		{
1248 			switch(nWhich)
1249 			{
1250 				case SID_ONLINE_REGISTRATION:
1251 				{
1252 					::utl::RegOptions aOptions;
1253 					if ( !aOptions.allowMenu() )
1254 						rSet.DisableItem( SID_ONLINE_REGISTRATION );
1255 				}
1256 				break;
1257 			}
1258 		}
1259 	}
1260 
1261 	SvtModuleOptions aModuleOpt;
1262 
1263     if( !aModuleOpt.IsWriter())
1264     {
1265         rSet.DisableItem( FN_LABEL );
1266         rSet.DisableItem( FN_BUSINESS_CARD );
1267         rSet.DisableItem( FN_XFORMS_INIT );
1268     }
1269 
1270 	if ( !aModuleOpt.IsImpress() )
1271         rSet.DisableItem( SID_SD_AUTOPILOT );
1272 }
1273