xref: /aoo41x/main/sfx2/source/appl/appserv.cxx (revision ea0b7ef3)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sfx2.hxx"
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/lang/IllegalArgumentException.hpp>
29 #include <com/sun/star/frame/DispatchResultEvent.hpp>
30 #include <com/sun/star/frame/DispatchResultState.hpp>
31 #include <com/sun/star/task/XJobExecutor.hpp>
32 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
33 #include <com/sun/star/frame/XDesktop.hpp>
34 #include <com/sun/star/frame/XDispatchHelper.hpp>
35 #include <com/sun/star/frame/XFramesSupplier.hpp>
36 #include <com/sun/star/util/XCloseable.hpp>
37 #include <com/sun/star/util/CloseVetoException.hpp>
38 #include <com/sun/star/frame/XLayoutManager.hpp>
39 #include <com/sun/star/document/XEmbeddedScripts.hpp>
40 #include <com/sun/star/embed/XStorage.hpp>
41 #include <com/sun/star/embed/ElementModes.hpp>
42 #include <com/sun/star/system/XSystemShellExecute.hpp>
43 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
44 #include <com/sun/star/system/SystemShellExecuteException.hpp>
45 
46 #include <comphelper/processfactory.hxx>
47 #include <comphelper/storagehelper.hxx>
48 #include "comphelper/configurationhelper.hxx"
49 
50 #include <svtools/addresstemplate.hxx>
51 #include <svl/visitem.hxx>
52 #include <unotools/intlwrapper.hxx>
53 
54 #include <unotools/configmgr.hxx>
55 #include <tools/config.hxx>
56 #include <tools/diagnose_ex.h>
57 #include <vcl/msgbox.hxx>
58 #include <svl/intitem.hxx>
59 #include <svl/eitem.hxx>
60 #include <svl/stritem.hxx>
61 #include <basic/sbstar.hxx>
62 #include <basic/basmgr.hxx>
63 #include <basic/basrdll.hxx>
64 #include <svtools/sfxecode.hxx>
65 #include <svtools/ehdl.hxx>
66 #include <vcl/help.hxx>
67 #include <vcl/stdtext.hxx>
68 #include <rtl/ustrbuf.hxx>
69 
70 #include <unotools/pathoptions.hxx>
71 #include <unotools/moduleoptions.hxx>
72 #include <svtools/helpopt.hxx>
73 #include <toolkit/helper/vclunohelper.hxx>
74 #include <tools/shl.hxx>
75 #include <unotools/bootstrap.hxx>
76 #include <vos/process.hxx>
77 #include <rtl/bootstrap.hxx>
78 #include <cppuhelper/exc_hlp.hxx>
79 #include <rtl/ustrbuf.hxx>
80 
81 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
82 #include <com/sun/star/frame/XModuleManager.hpp>
83 #include <com/sun/star/beans/XPropertySet.hpp>
84 
85 #include "frmload.hxx"
86 #include "referers.hxx"
87 #include <sfx2/app.hxx>
88 #include <sfx2/request.hxx>
89 #include <sfx2/dispatch.hxx>
90 #include <sfx2/bindings.hxx>
91 #include <sfx2/msg.hxx>
92 #include <sfx2/objface.hxx>
93 #include <sfx2/objitem.hxx>
94 #include <sfx2/objsh.hxx>
95 #include <sfx2/hintpost.hxx>
96 #include <sfx2/viewsh.hxx>
97 #include <sfx2/docfac.hxx>
98 #include <sfx2/docfile.hxx>
99 #include <sfx2/docfilt.hxx>
100 #include "docvor.hxx"
101 #include <sfx2/new.hxx>
102 #include <sfx2/templdlg.hxx>
103 #include "sfxtypes.hxx"
104 #include <sfx2/tabdlg.hxx>
105 #include "arrdecl.hxx"
106 #include "fltfnc.hxx"
107 #include <sfx2/sfx.hrc>
108 #include "app.hrc"
109 #include <sfx2/passwd.hxx>
110 #include "sfx2/sfxresid.hxx"
111 #include "arrdecl.hxx"
112 #include <sfx2/childwin.hxx>
113 #include "appdata.hxx"
114 #include "sfx2/minfitem.hxx"
115 #include <sfx2/event.hxx>
116 #include <sfx2/module.hxx>
117 #include <sfx2/viewfrm.hxx>
118 #include "sfxpicklist.hxx"
119 #include "imestatuswindow.hxx"
120 #include <sfx2/sfxdlg.hxx>
121 #include <sfx2/dialogs.hrc>
122 #include "sorgitm.hxx"
123 #include "sfx2/sfxhelp.hxx"
124 #include <tools/svlibrary.hxx>
125 
126 using namespace ::com::sun::star;
127 using namespace ::com::sun::star::beans;
128 using namespace ::com::sun::star::uno;
129 using namespace ::com::sun::star::frame;
130 using namespace ::com::sun::star::container;
131 using namespace ::com::sun::star::util;
132 using namespace ::com::sun::star::script;
133 using namespace ::com::sun::star::system;
134 using namespace ::com::sun::star::lang;
135 using namespace ::com::sun::star::document;
136 
137 namespace css = com::sun::star;
138 
139 //-------------------------------------------------------------------------
140 long QuitAgain_Impl( void* pObj, void* pArg )
141 {
142 	SfxApplication* pApp = (SfxApplication*)pObj;
143 	Timer* pTimer = (Timer*)pArg;
144 	delete pTimer;
145 	pApp->GetDispatcher_Impl()->Execute( SID_QUITAPP, SFX_CALLMODE_ASYNCHRON );
146 	return 0;
147 }
148 
149 void SfxApplication::MiscExec_Impl( SfxRequest& rReq )
150 {
151 	DBG_MEMTEST();
152 	bool bDone = sal_False;
153 	switch ( rReq.GetSlot() )
154 	{
155 		case SID_SETOPTIONS:
156 		{
157 			if( rReq.GetArgs() )
158 				SetOptions_Impl( *rReq.GetArgs() );
159 			break;
160 		}
161 
162 		case SID_QUITAPP:
163 		case SID_EXITANDRETURN:
164         case SID_LOGOUT:
165 		{
166             // protect against reentrant calls
167             if ( pAppData_Impl->bInQuit )
168                 return;
169 
170             if ( rReq.GetSlot() == SID_LOGOUT )
171             {
172                 for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
173                     pObjSh; pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
174                 {
175                     if ( !pObjSh->IsModified() )
176                         continue;
177 
178                     SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pObjSh );
179                     if ( !pFrame || !pFrame->GetWindow().IsReallyVisible() )
180                         continue;
181 
182                     if ( pObjSh->PrepareClose(2) )
183                         pObjSh->SetModified( sal_False );
184                     else
185                         return;
186                 }
187 
188                 String aName = String::CreateFromAscii("vnd.sun.star.cmd:logout");
189                 SfxStringItem aNameItem( SID_FILE_NAME, aName );
190                 SfxStringItem aReferer( SID_REFERER, DEFINE_CONST_UNICODE( "private/user" ) );
191                 pAppData_Impl->pAppDispat->Execute( SID_OPENDOC, SFX_CALLMODE_SLOT, &aNameItem, &aReferer, 0L );
192                 return;
193             }
194 
195             // aus verschachtelten Requests nach 100ms nochmal probieren
196             if( Application::GetDispatchLevel() > 1 )
197             {
198                 /* Dont save the request for closing the application and try it later
199                    again. This is an UI bound functionality ... and the user will  try it again
200                    if the dialog is closed. But we shouldnt close the application automaticly
201                    if this dialog is closed by the user ...
202                    So we ignore this request now and wait for a new user decision.
203                 */
204                 DBG_TRACE1( "QueryExit => FALSE (DispatchLevel == %u)", Application::GetDispatchLevel() );
205                 return;
206             }
207 
208             // block reentrant calls
209             pAppData_Impl->bInQuit = sal_True;
210             Reference < XDesktop > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
211 
212             rReq.ForgetAllArgs();
213 
214             // if terminate() failed, pAppData_Impl->bInQuit will now be sal_False, allowing further calls of SID_QUITAPP
215 			sal_Bool bTerminated = xDesktop->terminate();
216 			if (!bTerminated)
217 				// if terminate() was successful, SfxApplication is now dead!
218 				pAppData_Impl->bInQuit = sal_False;
219 
220 			// Returnwert setzten, ggf. terminieren
221             rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bTerminated ) );
222 			return;
223 		}
224 
225 		case SID_CONFIG:
226 		case SID_TOOLBOXOPTIONS:
227 		case SID_CONFIGSTATUSBAR:
228 		case SID_CONFIGMENU:
229 		case SID_CONFIGACCEL:
230 		case SID_CONFIGEVENT:
231 		{
232 			SfxAbstractDialogFactory* pFact =
233 				SfxAbstractDialogFactory::Create();
234 
235 			if ( pFact )
236 			{
237 				SFX_REQUEST_ARG(rReq, pStringItem,
238 					SfxStringItem, SID_CONFIG, sal_False);
239 
240 				SfxItemSet aSet(
241 					GetPool(), SID_CONFIG, SID_CONFIG );
242 
243 				if ( pStringItem )
244 				{
245 					aSet.Put( SfxStringItem(
246 						SID_CONFIG, pStringItem->GetValue() ) );
247 				}
248 
249                 Reference< XFrame > xFrame;
250 				const SfxItemSet* pIntSet = rReq.GetInternalArgs_Impl();
251                 SFX_ITEMSET_ARG( pIntSet, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
252                 if ( pFrameItem )
253                     xFrame = pFrameItem->GetFrame();
254 
255 				SfxAbstractTabDialog* pDlg = pFact->CreateTabDialog(
256 					RID_SVXDLG_CUSTOMIZE,
257 					NULL, &aSet, xFrame );
258 
259 			  	if ( pDlg )
260 				{
261 					const short nRet = pDlg->Execute();
262 
263             		if ( nRet )
264                 		bDone = sal_True;
265 
266             		delete pDlg;
267 				}
268 			}
269 			break;
270 		}
271 
272 		case SID_CLOSEDOCS:
273 		case SID_CLOSEWINS:
274 		{
275 
276             Reference < XFramesSupplier > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
277             Reference< XIndexAccess > xTasks( xDesktop->getFrames(), UNO_QUERY );
278             if ( !xTasks.is() )
279                 break;
280 
281             sal_Int32 n=0;
282             do
283             {
284                 if ( xTasks->getCount() <= n )
285                     break;
286 
287                 Any aAny = xTasks->getByIndex(n);
288                 Reference < XCloseable > xTask;
289                 aAny >>= xTask;
290                 try
291                 {
292                     xTask->close(sal_True);
293                     n++;
294                 }
295                 catch( CloseVetoException& )
296                 {
297                 }
298             }
299             while( sal_True );
300 
301             sal_Bool bOk = ( n == 0);
302 			rReq.SetReturnValue( SfxBoolItem( 0, bOk ) );
303 			bDone = sal_True;
304 			break;
305 		}
306 
307 		case SID_SAVEDOCS:
308 		{
309 			sal_Bool bOK = sal_True;
310 			sal_Bool bTmpDone = sal_True;
311 			for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
312 				  pObjSh;
313 				  pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
314 			{
315 				SfxRequest aReq( SID_SAVEDOC, 0, pObjSh->GetPool() );
316 				if ( pObjSh->IsModified() )
317 				{
318 					pObjSh->ExecuteSlot( aReq );
319 					SfxBoolItem *pItem = PTR_CAST( SfxBoolItem, aReq.GetReturnValue() );
320 					bTmpDone = aReq.IsDone();
321 					if ( !pItem || !pItem->GetValue() )
322 						bOK = sal_False;
323 				}
324 			}
325 
326 			rReq.SetReturnValue( SfxBoolItem( 0, bOK ) );
327 			rReq.Done();
328 			break;
329 		}
330 
331         // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
332         case SID_HELPINDEX:
333         case SID_HELP_SUPPORTPAGE:
334         {
335             Help* pHelp = Application::GetHelp();
336             if ( pHelp )
337             {
338                 if ( rReq.GetSlot() == SID_HELP_SUPPORTPAGE )
339                 {
340                     // show Support page with new URL
341                     // Create a dummy Help URL to get the Language and System
342                     // but don't use a real command, otherwise we may get an anchor
343                     rtl::OUString sEmpty;
344                     rtl::OUString sTmp( SfxHelp::CreateHelpURL( sEmpty, sEmpty ) );
345 
346                     rtl::OUStringBuffer aBuff;
347                     aBuff.appendAscii( RTL_CONSTASCII_STRINGPARAM( "vnd.sun.star.help://shared/text/shared/05/00000001.xhp" ) );
348                     aBuff.append( sTmp.copy( sTmp.indexOf( sal_Unicode( '?' ) ) ) );
349                     aBuff.appendAscii( RTL_CONSTASCII_STRINGPARAM( "&UseDB=no" ) );
350 
351                     pHelp->Start( aBuff.makeStringAndClear(), NULL );
352                 }
353                 else
354                     pHelp->Start( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".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 typedef	rtl_uString* (SAL_CALL *basicide_choose_macro)(XModel*, sal_Bool, rtl_uString*);
658 typedef	void (SAL_CALL *basicide_macro_organizer)( sal_Int16 );
659 
660 #define DOSTRING( x )			   			#x
661 #define STRING( x )				   			DOSTRING( x )
662 
663 extern "C" { static void SAL_CALL thisModule() {} }
664 
665 ::rtl::OUString ChooseMacro( const Reference< XModel >& rxLimitToDocument, sal_Bool bChooseOnly, const ::rtl::OUString& rMacroDesc = ::rtl::OUString() )
666 {
667     // get basctl dllname
668     static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "basctl" ) ) );
669 
670     // load module
671 	oslModule handleMod = osl_loadModuleRelative(
672         &thisModule, aLibName.pData, 0 );
673 
674     // get symbol
675     ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_choose_macro" ) );
676     basicide_choose_macro pSymbol = (basicide_choose_macro) osl_getFunctionSymbol( handleMod, aSymbol.pData );
677 
678     // call basicide_choose_macro in basctl
679     rtl_uString* pScriptURL = pSymbol( rxLimitToDocument.get(), bChooseOnly, rMacroDesc.pData );
680     ::rtl::OUString aScriptURL( pScriptURL );
681     rtl_uString_release( pScriptURL );
682 	return aScriptURL;
683 }
684 
685 void MacroOrganizer( sal_Int16 nTabId )
686 {
687     // get basctl dllname
688     static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "basctl" ) ) );
689 
690     // load module
691 	oslModule handleMod = osl_loadModuleRelative(
692         &thisModule, aLibName.pData, 0 );
693 
694     // get symbol
695     ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_macro_organizer" ) );
696     basicide_macro_organizer pSymbol = (basicide_macro_organizer) osl_getFunctionSymbol( handleMod, aSymbol.pData );
697 
698     // call basicide_macro_organizer in basctl
699     pSymbol( nTabId );
700 }
701 
702 #define RID_ERRBOX_MODULENOTINSTALLED     (RID_OFA_START + 72)
703 
704 ResMgr* SfxApplication::GetOffResManager_Impl()
705 {
706     if ( !pAppData_Impl->pOfaResMgr )
707         pAppData_Impl->pOfaResMgr = CreateResManager( "ofa");
708     return pAppData_Impl->pOfaResMgr;
709 }
710 
711 namespace
712 {
713     Window* lcl_getDialogParent( const Reference< XFrame >& _rxFrame, Window* _pFallback )
714     {
715         if ( !_rxFrame.is() )
716             return _pFallback;
717 
718         try
719         {
720             Reference< awt::XWindow > xContainerWindow( _rxFrame->getContainerWindow(), UNO_SET_THROW );
721             Window* pWindow = VCLUnoHelper::GetWindow( xContainerWindow );
722             OSL_ENSURE( pWindow, "lcl_getDialogParent: cool, somebody implemented a VCL-less toolkit!" );
723 
724             if ( pWindow )
725                 return pWindow->GetSystemWindow();
726         }
727         catch( const Exception& )
728         {
729         	DBG_UNHANDLED_EXCEPTION();
730         }
731         return _pFallback;
732     }
733 
734     const ::rtl::OUString& lcl_getBasicIDEServiceName()
735     {
736         static const ::rtl::OUString s_sBasicName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.BasicIDE" ) );
737         return s_sBasicName;
738     }
739 
740     SfxViewFrame* lcl_getBasicIDEViewFrame( SfxObjectShell* i_pBasicIDE )
741     {
742         SfxViewFrame* pView = SfxViewFrame::GetFirst( i_pBasicIDE );
743         while ( pView )
744         {
745             if ( pView->GetObjectShell()->GetFactory().GetDocumentServiceName() == lcl_getBasicIDEServiceName() )
746                 break;
747             pView = SfxViewFrame::GetNext( *pView, i_pBasicIDE );
748         }
749         return pView;
750     }
751     Reference< XFrame > lcl_findStartModuleFrame( const ::comphelper::ComponentContext& i_rContext )
752     {
753         try
754         {
755             Reference < XFramesSupplier > xSupplier( i_rContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW );
756             Reference < XIndexAccess > xContainer( xSupplier->getFrames(), UNO_QUERY_THROW );
757 
758             Reference< XModuleManager > xCheck( i_rContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW );
759 
760             sal_Int32 nCount = xContainer->getCount();
761             for ( sal_Int32 i=0; i<nCount; ++i )
762             {
763                 try
764                 {
765                     Reference < XFrame > xFrame( xContainer->getByIndex(i), UNO_QUERY_THROW );
766                     ::rtl::OUString sModule = xCheck->identify( xFrame );
767                     if ( sModule.equalsAscii( "com.sun.star.frame.StartModule" ) )
768                         return xFrame;
769                 }
770                 catch( const UnknownModuleException& )
771                 {
772                     // silence
773                 }
774                 catch(const Exception&)
775                 {
776                     // re-throw, caught below
777                     throw;
778                 }
779             }
780         }
781         catch( const Exception& )
782         {
783                DBG_UNHANDLED_EXCEPTION();
784         }
785         return NULL;
786     }
787 }
788 
789 static ::rtl::OUString getConfigurationStringValue(
790     const ::rtl::OUString& rPackage,
791     const ::rtl::OUString& rRelPath,
792     const ::rtl::OUString& rKey,
793     const ::rtl::OUString& rDefaultValue )
794 {
795     ::rtl::OUString aDefVal( rDefaultValue );
796 
797     try
798     {
799         ::comphelper::ConfigurationHelper::readDirectKey(
800             comphelper::getProcessServiceFactory(),
801             rPackage,
802             rRelPath,
803             rKey,
804             ::comphelper::ConfigurationHelper::E_READONLY) >>= aDefVal;
805     }
806     catch(const com::sun::star::uno::RuntimeException& exRun)
807     { throw exRun; }
808     catch(const com::sun::star::uno::Exception&)
809     {}
810 
811     return aDefVal;
812 }
813 
814 void SfxApplication::OfaExec_Impl( SfxRequest& rReq )
815 {
816 	DBG_MEMTEST();
817 	switch ( rReq.GetSlot() )
818 	{
819 		case SID_OPTIONS_TREEDIALOG:
820 		{
821             String sPageURL;
822             SFX_REQUEST_ARG( rReq, pURLItem, SfxStringItem, SID_OPTIONS_PAGEURL, sal_False );
823             if ( pURLItem )
824                 sPageURL = pURLItem->GetValue();
825             const SfxItemSet* pArgs = rReq.GetInternalArgs_Impl();
826             const SfxPoolItem* pItem = NULL;
827             Reference < XFrame > xFrame;
828             if ( pArgs && pArgs->GetItemState( SID_FILLFRAME, sal_False, &pItem ) == SFX_ITEM_SET )
829             {
830                 OSL_ENSURE( pItem->ISA( SfxUnoFrameItem ), "SfxApplication::OfaExec_Impl: XFrames are to be transported via SfxUnoFrameItem by now!" );
831                 xFrame = static_cast< const SfxUnoFrameItem*>( pItem )->GetFrame();
832             }
833 			SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
834 			if ( pFact )
835 			{
836                 VclAbstractDialog* pDlg =
837                     pFact->CreateFrameDialog( NULL, xFrame, rReq.GetSlot(), sPageURL );
838 			  	pDlg->Execute();
839 			  	delete pDlg;
840 				SfxViewFrame* pView = SfxViewFrame::GetFirst();
841 				while ( pView )
842 				{
843 					pView->GetBindings().InvalidateAll(sal_False);
844 					pView = SfxViewFrame::GetNext( *pView );
845 				}
846 			}
847 			break;
848 		}
849 
850         case SID_MORE_DICTIONARIES:
851         {
852             try
853             {
854                 uno::Reference< lang::XMultiServiceFactory > xSMGR =
855                     ::comphelper::getProcessServiceFactory();
856                 uno::Reference< css::system::XSystemShellExecute > xSystemShell(
857                     xSMGR->createInstance( DEFINE_CONST_UNICODE("com.sun.star.system.SystemShellExecute" ) ),
858                     uno::UNO_QUERY_THROW );
859 
860                 // read repository URL from configuration
861                 ::rtl::OUString sTemplRepoURL =
862                     getConfigurationStringValue(
863                         ::rtl::OUString::createFromAscii("org.openoffice.Office.Common"),
864                         ::rtl::OUString::createFromAscii("Dictionaries"),
865                         ::rtl::OUString::createFromAscii("RepositoryURL"),
866                         ::rtl::OUString());
867 
868                 if ( xSystemShell.is() && sTemplRepoURL.getLength() > 0 )
869                 {
870                     ::rtl::OUStringBuffer aURLBuf( sTemplRepoURL );
871                     aURLBuf.appendAscii( "?" );
872                     aURLBuf.appendAscii( "lang=" );
873 
874                     // read locale from configuration
875                     ::rtl::OUString sLocale = getConfigurationStringValue(
876                         ::rtl::OUString::createFromAscii("org.openoffice.Setup"),
877                         ::rtl::OUString::createFromAscii("L10N"),
878                         ::rtl::OUString::createFromAscii("ooLocale"),
879                         ::rtl::OUString::createFromAscii("en-US"));
880 
881                     aURLBuf.append( sLocale );
882                     xSystemShell->execute(
883                         aURLBuf.makeStringAndClear(),
884                         ::rtl::OUString(),
885                         css::system::SystemShellExecuteFlags::DEFAULTS );
886                 }
887             }
888             catch( const ::com::sun::star::uno::Exception& )
889             {
890                 DBG_ERRORFILE( "SfxApplication::OfaExec_Impl(SID_MORE_DICTIONARIES): caught an exception!" );
891             }
892             break;
893         }
894 
895 		case SID_BASICIDE_APPEAR:
896 		{
897             SfxViewFrame* pView = lcl_getBasicIDEViewFrame( NULL );
898             if ( !pView )
899             {
900                 SfxObjectShell* pBasicIDE = SfxObjectShell::CreateObject( lcl_getBasicIDEServiceName() );
901                 pBasicIDE->DoInitNew( 0 );
902                 pBasicIDE->SetModified( sal_False );
903                 try
904                 {
905                     // load the Basic IDE via direct access to the SFX frame loader. A generic loadComponentFromURL
906                     // (which could be done via SfxViewFrame::LoadDocumentIntoFrame) is not feasible here, since the Basic IDE
907                     // does not really play nice with the framework's concept. For instance, it is a "singleton document",
908                     // which conflicts, at the latest, with the framework's concept of loading into _blank frames.
909                     // So, since we know that our frame loader can handle it, we skip the generic framework loader
910                     // mechanism, and the type detection (which doesn't know about the Basic IDE).
911                     ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
912                     Reference< XSynchronousFrameLoader > xLoader( aContext.createComponent(
913                         SfxFrameLoader_Impl::impl_getStaticImplementationName() ), UNO_QUERY_THROW );
914                     ::comphelper::NamedValueCollection aLoadArgs;
915                     aLoadArgs.put( "Model", pBasicIDE->GetModel() );
916                     aLoadArgs.put( "URL", ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:factory/sbasic" ) ) );
917 
918                     Reference< XFrame > xTargetFrame( lcl_findStartModuleFrame( aContext ) );
919                     if ( !xTargetFrame.is() )
920                         xTargetFrame = SfxFrame::CreateBlankFrame();
921                     ENSURE_OR_THROW( xTargetFrame.is(), "could not obtain a frameto load the Basic IDE into!" );
922 
923                     xLoader->load( aLoadArgs.getPropertyValues(), xTargetFrame );
924                 }
925                 catch( const Exception& )
926                 {
927                 	DBG_UNHANDLED_EXCEPTION();
928                 }
929 
930                 pView = lcl_getBasicIDEViewFrame( pBasicIDE );
931                 if ( pView )
932                     pView->SetName( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC:1" ) ) );
933             }
934 
935             if ( pView )
936                 pView->GetFrame().Appear();
937 
938             const SfxItemSet* pArgs = rReq.GetArgs();
939             if ( pArgs && pView )
940             {
941                 SfxViewShell* pViewShell = pView->GetViewShell();
942                 SfxObjectShell* pObjShell = pView->GetObjectShell();
943                 if ( pViewShell && pObjShell )
944                 {
945                     SfxRequest aReq( SID_BASICIDE_SHOWWINDOW, SFX_CALLMODE_SYNCHRON, pObjShell->GetPool() );
946                     aReq.SetArgs( *pArgs );
947                     pViewShell->ExecuteSlot( aReq );
948                 }
949             }
950 
951 			rReq.Done();
952 		}
953 		break;
954 
955 		case SID_BASICCHOOSER:
956 		{
957 			const SfxItemSet* pArgs = rReq.GetArgs();
958 			const SfxPoolItem* pItem;
959             sal_Bool bChooseOnly = sal_False;
960             Reference< XModel > xLimitToModel;
961             if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_RECORDMACRO, sal_False, &pItem) )
962             {
963                 sal_Bool bRecord = ((SfxBoolItem*)pItem)->GetValue();
964                 if ( bRecord )
965                 {
966                     // !Hack
967                     bChooseOnly = sal_False;
968                     SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
969                     OSL_ENSURE( pCurrentShell, "macro recording outside an SFX document?" );
970                     if ( pCurrentShell )
971                         xLimitToModel = pCurrentShell->GetModel();
972                 }
973             }
974 
975             rReq.SetReturnValue( SfxStringItem( rReq.GetSlot(), ChooseMacro( xLimitToModel, bChooseOnly ) ) );
976 			rReq.Done();
977 		}
978 		break;
979 
980 		case SID_MACROORGANIZER:
981 		{
982             OSL_TRACE("handling SID_MACROORGANIZER");
983 			const SfxItemSet* pArgs = rReq.GetArgs();
984 			const SfxPoolItem* pItem;
985             sal_Int16 nTabId = 0;
986             if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_MACROORGANIZER, sal_False, &pItem) )
987             {
988                 nTabId = ((SfxUInt16Item*)pItem)->GetValue();
989             }
990 
991             SfxApplication::MacroOrganizer( nTabId );
992 			rReq.Done();
993 		}
994 		break;
995 
996         case SID_RUNMACRO:
997         {
998             SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
999             OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
1000 
1001             Reference< XFrame > xFrame;
1002 			const SfxItemSet* pIntSet = rReq.GetInternalArgs_Impl();
1003             SFX_ITEMSET_ARG( pIntSet, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
1004             if ( pFrameItem )
1005                 xFrame = pFrameItem->GetFrame();
1006 
1007             if ( !xFrame.is() )
1008             {
1009                 const SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1010                 if ( pViewFrame )
1011                     xFrame = pViewFrame->GetFrame().GetFrameInterface();
1012             }
1013 
1014             do  // artificial loop for flow control
1015             {
1016                 AbstractScriptSelectorDialog* pDlg = pFact->CreateScriptSelectorDialog(
1017                     lcl_getDialogParent( xFrame, GetTopWindow() ), sal_False, xFrame );
1018                 OSL_ENSURE( pDlg, "SfxApplication::OfaExec_Impl( SID_RUNMACRO ): no dialog!" );
1019                 if ( !pDlg )
1020                     break;
1021                 pDlg->SetRunLabel();
1022 
1023                 short nDialogResult = pDlg->Execute();
1024                 if ( !nDialogResult )
1025                     break;
1026 
1027                 Sequence< Any > args;
1028                 Sequence< sal_Int16 > outIndex;
1029                 Sequence< Any > outArgs;
1030                 Any ret;
1031 
1032                 Reference< XInterface > xScriptContext;
1033 
1034                 Reference< XController > xController;
1035                 if ( xFrame.is() )
1036                     xController = xFrame->getController();
1037                 if ( xController.is() )
1038                     xScriptContext = xController->getModel();
1039                 if ( !xScriptContext.is() )
1040                     xScriptContext = xController;
1041 
1042                 SfxObjectShell::CallXScript( xScriptContext, pDlg->GetScriptURL(), args, ret, outIndex, outArgs );
1043             }
1044             while ( false );
1045 			rReq.Done();
1046 		}
1047         break;
1048 
1049         case SID_SCRIPTORGANIZER:
1050         {
1051             SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1052             OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
1053 			const SfxItemSet* pArgs = rReq.GetArgs();
1054 			const SfxPoolItem* pItem;
1055             String aLanguage;
1056             if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_SCRIPTORGANIZER, sal_False, &pItem) )
1057             {
1058                 aLanguage = ((SfxScriptOrganizerItem*)pItem)->getLanguage();
1059             }
1060 
1061             ::rtl::OUString aLang( aLanguage );
1062             OSL_TRACE("SfxApplication::OfaExec_Impl: about to create dialog for: %s", ::rtl::OUStringToOString( aLang , RTL_TEXTENCODING_ASCII_US ).pData->buffer);
1063             // not sure about the Window*
1064             VclAbstractDialog* pDlg = pFact->CreateSvxScriptOrgDialog( GetTopWindow(), aLanguage );
1065             if( pDlg )
1066             {
1067                 pDlg->Execute();
1068             }
1069             else
1070             {
1071                 OSL_TRACE("no dialog!!!");
1072             }
1073 			rReq.Done();
1074 		}
1075 		break;
1076 
1077 		case SID_OFFICE_CHECK_PLZ:
1078 		{
1079 			sal_Bool bRet = sal_False;
1080 			SFX_REQUEST_ARG(rReq, pStringItem, SfxStringItem, rReq.GetSlot(), sal_False);
1081 
1082 			if ( pStringItem )
1083 			{
1084 				String aPLZ = pStringItem->GetValue();
1085 				bRet = sal_True /*!!!SfxIniManager::CheckPLZ( aPLZ )*/;
1086 			}
1087 			else
1088 				SbxBase::SetError( SbxERR_WRONG_ARGS );
1089 			rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bRet ) );
1090 		}
1091 		break;
1092 
1093         case SID_AUTO_CORRECT_DLG:
1094 		{
1095 			SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1096 			if ( pFact )
1097 			{
1098 				SfxItemSet aSet(GetPool(), SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG);
1099 				const SfxPoolItem* pItem=NULL;
1100 				const SfxItemSet* pSet = rReq.GetArgs();
1101 				SfxItemPool* pSetPool = pSet ? pSet->GetPool() : NULL;
1102 				if ( pSet && pSet->GetItemState( pSetPool->GetWhich( SID_AUTO_CORRECT_DLG ), sal_False, &pItem ) == SFX_ITEM_SET )
1103 					aSet.Put( *pItem );
1104 
1105 			  	SfxAbstractTabDialog* pDlg = pFact->CreateTabDialog( RID_OFA_AUTOCORR_DLG, NULL, &aSet, NULL );
1106 			  	pDlg->Execute();
1107 			  	delete pDlg;
1108 			}
1109 
1110 			break;
1111 		}
1112 
1113 		case SID_SD_AUTOPILOT :
1114 		case SID_NEWSD :
1115 		{
1116 			SvtModuleOptions aModuleOpt;
1117 			if ( !aModuleOpt.IsImpress() )
1118 			{
1119 				ErrorBox( 0, ResId( RID_ERRBOX_MODULENOTINSTALLED, *GetOffResManager_Impl() )).Execute();
1120 				return;
1121 			}
1122 
1123 			Reference< com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
1124 			Reference< com::sun::star::frame::XDispatchProvider > xProv(
1125 				xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.drawing.ModuleDispatcher")), UNO_QUERY );
1126 
1127 			if ( xProv.is() )
1128 			{
1129 				::rtl::OUString aCmd = ::rtl::OUString::createFromAscii( GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName() );
1130 				Reference< com::sun::star::frame::XDispatchHelper > xHelper(
1131 					xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")), UNO_QUERY );
1132 				if ( xHelper.is() )
1133 				{
1134 					Sequence < com::sun::star::beans::PropertyValue > aSeq;
1135 					if ( rReq.GetArgs() )
1136 						TransformItems( rReq.GetSlot(), *rReq.GetArgs(), aSeq );
1137 					Any aResult = xHelper->executeDispatch( xProv, aCmd, ::rtl::OUString(), 0, aSeq );
1138 					::com::sun::star::frame::DispatchResultEvent aEvent;
1139 					sal_Bool bSuccess = (
1140 										 (aResult >>= aEvent) &&
1141                                          (aEvent.State == ::com::sun::star::frame::DispatchResultState::SUCCESS)
1142 										);
1143 					rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
1144 				}
1145 			}
1146 		}
1147 		break;
1148 
1149         case FN_LABEL :
1150         case FN_BUSINESS_CARD :
1151         case FN_XFORMS_INIT :
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.text.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 SID_ADDRESS_DATA_SOURCE:
1180 		{
1181             ::rtl::OUString sDialogServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.AddressBookSourcePilot" ) );
1182 			try
1183 			{
1184 				Reference< com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
1185 				Reference< com::sun::star::ui::dialogs::XExecutableDialog > xDialog;
1186 				if (xORB.is())
1187 					xDialog = Reference< com::sun::star::ui::dialogs::XExecutableDialog >(xORB->createInstance(sDialogServiceName), UNO_QUERY);
1188 				if (xDialog.is())
1189 					xDialog->execute();
1190 				else
1191 					ShowServiceNotAvailableError(NULL, sDialogServiceName, sal_True);
1192 			}
1193 			catch(::com::sun::star::uno::Exception&)
1194 			{
1195 			}
1196 		}
1197 		break;
1198 
1199 		case SID_COMP_BIBLIOGRAPHY:
1200 		{
1201 			SfxStringItem aURL(SID_FILE_NAME, String::CreateFromAscii(".component:Bibliography/View1"));
1202 			SfxStringItem aRef(SID_REFERER, String::CreateFromAscii("private:user"));
1203 			SfxStringItem aTarget(SID_TARGETNAME, String::CreateFromAscii("_blank"));
1204 			SfxViewFrame::Current()->GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, &aURL, &aRef, &aTarget, 0L);
1205 		}
1206 		break;
1207 	}
1208 }
1209 
1210 void SfxApplication::OfaState_Impl(SfxItemSet &rSet)
1211 {
1212 	SvtModuleOptions aModuleOpt;
1213 
1214     if( !aModuleOpt.IsWriter())
1215     {
1216         rSet.DisableItem( FN_LABEL );
1217         rSet.DisableItem( FN_BUSINESS_CARD );
1218         rSet.DisableItem( FN_XFORMS_INIT );
1219     }
1220 
1221 	if ( !aModuleOpt.IsImpress() )
1222         rSet.DisableItem( SID_SD_AUTOPILOT );
1223 }
1224