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