xref: /trunk/main/sfx2/source/appl/appserv.cxx (revision 91125485)
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/SystemShellExecute.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 //-------------------------------------------------------------------------
QuitAgain_Impl(void * pObj,void * pArg)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 
MiscExec_Impl(SfxRequest & rReq)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 shouldn't close the application automatically
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 
MiscState_Impl(SfxItemSet & rSet)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 
thisModule()663 extern "C" { static void SAL_CALL thisModule() {} }
664 
ChooseMacro(const Reference<XModel> & rxLimitToDocument,sal_Bool bChooseOnly,const::rtl::OUString & rMacroDesc=::rtl::OUString ())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 
MacroOrganizer(sal_Int16 nTabId)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 
GetOffResManager_Impl()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 {
lcl_getDialogParent(const Reference<XFrame> & _rxFrame,Window * _pFallback)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 
lcl_getBasicIDEServiceName()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 
lcl_getBasicIDEViewFrame(SfxObjectShell * i_pBasicIDE)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     }
lcl_findStartModuleFrame(const::comphelper::ComponentContext & i_rContext)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 
getConfigurationStringValue(const::rtl::OUString & rPackage,const::rtl::OUString & rRelPath,const::rtl::OUString & rKey,const::rtl::OUString & rDefaultValue)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 
OfaExec_Impl(SfxRequest & rReq)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< css::system::XSystemShellExecute > xSystemShell(
855                     css::system::SystemShellExecute::create(
856                         ::comphelper::getProcessComponentContext() ) );
857 
858                 // read repository URL from configuration
859                 ::rtl::OUString sTemplRepoURL =
860                     getConfigurationStringValue(
861                         ::rtl::OUString::createFromAscii("org.openoffice.Office.Common"),
862                         ::rtl::OUString::createFromAscii("Dictionaries"),
863                         ::rtl::OUString::createFromAscii("RepositoryURL"),
864                         ::rtl::OUString());
865 
866                 if ( xSystemShell.is() && sTemplRepoURL.getLength() > 0 )
867                 {
868                     ::rtl::OUStringBuffer aURLBuf( sTemplRepoURL );
869                     aURLBuf.appendAscii( "?" );
870                     aURLBuf.appendAscii( "lang=" );
871 
872                     // read locale from configuration
873                     ::rtl::OUString sLocale = getConfigurationStringValue(
874                         ::rtl::OUString::createFromAscii("org.openoffice.Setup"),
875                         ::rtl::OUString::createFromAscii("L10N"),
876                         ::rtl::OUString::createFromAscii("ooLocale"),
877                         ::rtl::OUString::createFromAscii("en-US"));
878 
879                     aURLBuf.append( sLocale );
880                     xSystemShell->execute(
881                         aURLBuf.makeStringAndClear(),
882                         ::rtl::OUString(),
883                         css::system::SystemShellExecuteFlags::DEFAULTS );
884                 }
885             }
886             catch( const ::com::sun::star::uno::Exception& )
887             {
888                 DBG_ERRORFILE( "SfxApplication::OfaExec_Impl(SID_MORE_DICTIONARIES): caught an exception!" );
889             }
890             break;
891         }
892 
893 		case SID_BASICIDE_APPEAR:
894 		{
895             SfxViewFrame* pView = lcl_getBasicIDEViewFrame( NULL );
896             if ( !pView )
897             {
898                 SfxObjectShell* pBasicIDE = SfxObjectShell::CreateObject( lcl_getBasicIDEServiceName() );
899                 pBasicIDE->DoInitNew( 0 );
900                 pBasicIDE->SetModified( sal_False );
901                 try
902                 {
903                     // load the Basic IDE via direct access to the SFX frame loader. A generic loadComponentFromURL
904                     // (which could be done via SfxViewFrame::LoadDocumentIntoFrame) is not feasible here, since the Basic IDE
905                     // does not really play nice with the framework's concept. For instance, it is a "singleton document",
906                     // which conflicts, at the latest, with the framework's concept of loading into _blank frames.
907                     // So, since we know that our frame loader can handle it, we skip the generic framework loader
908                     // mechanism, and the type detection (which doesn't know about the Basic IDE).
909                     ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
910                     Reference< XSynchronousFrameLoader > xLoader( aContext.createComponent(
911                         SfxFrameLoader_Impl::impl_getStaticImplementationName() ), UNO_QUERY_THROW );
912                     ::comphelper::NamedValueCollection aLoadArgs;
913                     aLoadArgs.put( "Model", pBasicIDE->GetModel() );
914                     aLoadArgs.put( "URL", ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:factory/sbasic" ) ) );
915 
916                     Reference< XFrame > xTargetFrame( lcl_findStartModuleFrame( aContext ) );
917                     if ( !xTargetFrame.is() )
918                         xTargetFrame = SfxFrame::CreateBlankFrame();
919                     ENSURE_OR_THROW( xTargetFrame.is(), "could not obtain a frameto load the Basic IDE into!" );
920 
921                     xLoader->load( aLoadArgs.getPropertyValues(), xTargetFrame );
922                 }
923                 catch( const Exception& )
924                 {
925                 	DBG_UNHANDLED_EXCEPTION();
926                 }
927 
928                 pView = lcl_getBasicIDEViewFrame( pBasicIDE );
929                 if ( pView )
930                     pView->SetName( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC:1" ) ) );
931             }
932 
933             if ( pView )
934                 pView->GetFrame().Appear();
935 
936             const SfxItemSet* pArgs = rReq.GetArgs();
937             if ( pArgs && pView )
938             {
939                 SfxViewShell* pViewShell = pView->GetViewShell();
940                 SfxObjectShell* pObjShell = pView->GetObjectShell();
941                 if ( pViewShell && pObjShell )
942                 {
943                     SfxRequest aReq( SID_BASICIDE_SHOWWINDOW, SFX_CALLMODE_SYNCHRON, pObjShell->GetPool() );
944                     aReq.SetArgs( *pArgs );
945                     pViewShell->ExecuteSlot( aReq );
946                 }
947             }
948 
949 			rReq.Done();
950 		}
951 		break;
952 
953 		case SID_BASICCHOOSER:
954 		{
955 			const SfxItemSet* pArgs = rReq.GetArgs();
956 			const SfxPoolItem* pItem;
957             sal_Bool bChooseOnly = sal_False;
958             Reference< XModel > xLimitToModel;
959             if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_RECORDMACRO, sal_False, &pItem) )
960             {
961                 sal_Bool bRecord = ((SfxBoolItem*)pItem)->GetValue();
962                 if ( bRecord )
963                 {
964                     // !Hack
965                     bChooseOnly = sal_False;
966                     SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
967                     OSL_ENSURE( pCurrentShell, "macro recording outside an SFX document?" );
968                     if ( pCurrentShell )
969                         xLimitToModel = pCurrentShell->GetModel();
970                 }
971             }
972 
973             rReq.SetReturnValue( SfxStringItem( rReq.GetSlot(), ChooseMacro( xLimitToModel, bChooseOnly ) ) );
974 			rReq.Done();
975 		}
976 		break;
977 
978 		case SID_MACROORGANIZER:
979 		{
980             OSL_TRACE("handling SID_MACROORGANIZER");
981 			const SfxItemSet* pArgs = rReq.GetArgs();
982 			const SfxPoolItem* pItem;
983             sal_Int16 nTabId = 0;
984             if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_MACROORGANIZER, sal_False, &pItem) )
985             {
986                 nTabId = ((SfxUInt16Item*)pItem)->GetValue();
987             }
988 
989             SfxApplication::MacroOrganizer( nTabId );
990 			rReq.Done();
991 		}
992 		break;
993 
994         case SID_RUNMACRO:
995         {
996             SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
997             OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
998 
999             Reference< XFrame > xFrame;
1000 			const SfxItemSet* pIntSet = rReq.GetInternalArgs_Impl();
1001             SFX_ITEMSET_ARG( pIntSet, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
1002             if ( pFrameItem )
1003                 xFrame = pFrameItem->GetFrame();
1004 
1005             if ( !xFrame.is() )
1006             {
1007                 const SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1008                 if ( pViewFrame )
1009                     xFrame = pViewFrame->GetFrame().GetFrameInterface();
1010             }
1011 
1012             do  // artificial loop for flow control
1013             {
1014                 AbstractScriptSelectorDialog* pDlg = pFact->CreateScriptSelectorDialog(
1015                     lcl_getDialogParent( xFrame, GetTopWindow() ), sal_False, xFrame );
1016                 OSL_ENSURE( pDlg, "SfxApplication::OfaExec_Impl( SID_RUNMACRO ): no dialog!" );
1017                 if ( !pDlg )
1018                     break;
1019                 pDlg->SetRunLabel();
1020 
1021                 short nDialogResult = pDlg->Execute();
1022                 if ( !nDialogResult )
1023                     break;
1024 
1025                 Sequence< Any > args;
1026                 Sequence< sal_Int16 > outIndex;
1027                 Sequence< Any > outArgs;
1028                 Any ret;
1029 
1030                 Reference< XInterface > xScriptContext;
1031 
1032                 Reference< XController > xController;
1033                 if ( xFrame.is() )
1034                     xController = xFrame->getController();
1035                 if ( xController.is() )
1036                     xScriptContext = xController->getModel();
1037                 if ( !xScriptContext.is() )
1038                     xScriptContext = xController;
1039 
1040                 SfxObjectShell::CallXScript( xScriptContext, pDlg->GetScriptURL(), args, ret, outIndex, outArgs,
1041                                              ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:user" ) ) );
1042             }
1043             while ( false );
1044 			rReq.Done();
1045 		}
1046         break;
1047 
1048         case SID_SCRIPTORGANIZER:
1049         {
1050             SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1051             OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
1052 			const SfxItemSet* pArgs = rReq.GetArgs();
1053 			const SfxPoolItem* pItem;
1054             String aLanguage;
1055             if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_SCRIPTORGANIZER, sal_False, &pItem) )
1056             {
1057                 aLanguage = ((SfxScriptOrganizerItem*)pItem)->getLanguage();
1058             }
1059 
1060             ::rtl::OUString aLang( aLanguage );
1061             OSL_TRACE("SfxApplication::OfaExec_Impl: about to create dialog for: %s", ::rtl::OUStringToOString( aLang , RTL_TEXTENCODING_ASCII_US ).pData->buffer);
1062             // not sure about the Window*
1063             VclAbstractDialog* pDlg = pFact->CreateSvxScriptOrgDialog( GetTopWindow(), aLanguage );
1064             if( pDlg )
1065             {
1066                 pDlg->Execute();
1067             }
1068             else
1069             {
1070                 OSL_TRACE("no dialog!!!");
1071             }
1072 			rReq.Done();
1073 		}
1074 		break;
1075 
1076 		case SID_OFFICE_CHECK_PLZ:
1077 		{
1078 			sal_Bool bRet = sal_False;
1079 			SFX_REQUEST_ARG(rReq, pStringItem, SfxStringItem, rReq.GetSlot(), sal_False);
1080 
1081 			if ( pStringItem )
1082 			{
1083 				String aPLZ = pStringItem->GetValue();
1084 				bRet = sal_True /*!!!SfxIniManager::CheckPLZ( aPLZ )*/;
1085 			}
1086 			else
1087 				SbxBase::SetError( SbxERR_WRONG_ARGS );
1088 			rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bRet ) );
1089 		}
1090 		break;
1091 
1092         case SID_AUTO_CORRECT_DLG:
1093 		{
1094 			SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1095 			if ( pFact )
1096 			{
1097 				SfxItemSet aSet(GetPool(), SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG);
1098 				const SfxPoolItem* pItem=NULL;
1099 				const SfxItemSet* pSet = rReq.GetArgs();
1100 				SfxItemPool* pSetPool = pSet ? pSet->GetPool() : NULL;
1101 				if ( pSet && pSet->GetItemState( pSetPool->GetWhich( SID_AUTO_CORRECT_DLG ), sal_False, &pItem ) == SFX_ITEM_SET )
1102 					aSet.Put( *pItem );
1103 
1104 			  	SfxAbstractTabDialog* pDlg = pFact->CreateTabDialog( RID_OFA_AUTOCORR_DLG, NULL, &aSet, NULL );
1105 			  	pDlg->Execute();
1106 			  	delete pDlg;
1107 			}
1108 
1109 			break;
1110 		}
1111 
1112 		case SID_SD_AUTOPILOT :
1113 		case SID_NEWSD :
1114 		{
1115 			SvtModuleOptions aModuleOpt;
1116 			if ( !aModuleOpt.IsImpress() )
1117 			{
1118 				ErrorBox( 0, ResId( RID_ERRBOX_MODULENOTINSTALLED, *GetOffResManager_Impl() )).Execute();
1119 				return;
1120 			}
1121 
1122 			Reference< com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
1123 			Reference< com::sun::star::frame::XDispatchProvider > xProv(
1124 				xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.drawing.ModuleDispatcher")), UNO_QUERY );
1125 
1126 			if ( xProv.is() )
1127 			{
1128 				::rtl::OUString aCmd = ::rtl::OUString::createFromAscii( GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName() );
1129 				Reference< com::sun::star::frame::XDispatchHelper > xHelper(
1130 					xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")), UNO_QUERY );
1131 				if ( xHelper.is() )
1132 				{
1133 					Sequence < com::sun::star::beans::PropertyValue > aSeq;
1134 					if ( rReq.GetArgs() )
1135 						TransformItems( rReq.GetSlot(), *rReq.GetArgs(), aSeq );
1136 					Any aResult = xHelper->executeDispatch( xProv, aCmd, ::rtl::OUString(), 0, aSeq );
1137 					::com::sun::star::frame::DispatchResultEvent aEvent;
1138 					sal_Bool bSuccess = (
1139 										 (aResult >>= aEvent) &&
1140                                          (aEvent.State == ::com::sun::star::frame::DispatchResultState::SUCCESS)
1141 										);
1142 					rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
1143 				}
1144 			}
1145 		}
1146 		break;
1147 
1148         case FN_LABEL :
1149         case FN_BUSINESS_CARD :
1150         case FN_XFORMS_INIT :
1151 		{
1152 			Reference< com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
1153 			Reference< com::sun::star::frame::XDispatchProvider > xProv(
1154 				xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.text.ModuleDispatcher")), UNO_QUERY );
1155 
1156 			if ( xProv.is() )
1157 			{
1158 				::rtl::OUString aCmd = ::rtl::OUString::createFromAscii( GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName() );
1159 				Reference< com::sun::star::frame::XDispatchHelper > xHelper(
1160 					xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")), UNO_QUERY );
1161 				if ( xHelper.is() )
1162 				{
1163 					Sequence < com::sun::star::beans::PropertyValue > aSeq;
1164 					if ( rReq.GetArgs() )
1165 						TransformItems( rReq.GetSlot(), *rReq.GetArgs(), aSeq );
1166 					Any aResult = xHelper->executeDispatch( xProv, aCmd, ::rtl::OUString(), 0, aSeq );
1167 					::com::sun::star::frame::DispatchResultEvent aEvent;
1168 					sal_Bool bSuccess = (
1169 										 (aResult >>= aEvent) &&
1170                                          (aEvent.State == ::com::sun::star::frame::DispatchResultState::SUCCESS)
1171 										);
1172 					rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
1173 				}
1174 			}
1175 		}
1176 		break;
1177 
1178 		case SID_ADDRESS_DATA_SOURCE:
1179 		{
1180             ::rtl::OUString sDialogServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.AddressBookSourcePilot" ) );
1181 			try
1182 			{
1183 				Reference< com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
1184 				Reference< com::sun::star::ui::dialogs::XExecutableDialog > xDialog;
1185 				if (xORB.is())
1186 					xDialog = Reference< com::sun::star::ui::dialogs::XExecutableDialog >(xORB->createInstance(sDialogServiceName), UNO_QUERY);
1187 				if (xDialog.is())
1188 					xDialog->execute();
1189 				else
1190 					ShowServiceNotAvailableError(NULL, sDialogServiceName, sal_True);
1191 			}
1192 			catch(::com::sun::star::uno::Exception&)
1193 			{
1194 			}
1195 		}
1196 		break;
1197 
1198 		case SID_COMP_BIBLIOGRAPHY:
1199 		{
1200 			SfxStringItem aURL(SID_FILE_NAME, String::CreateFromAscii(".component:Bibliography/View1"));
1201 			SfxStringItem aRef(SID_REFERER, String::CreateFromAscii("private:user"));
1202 			SfxStringItem aTarget(SID_TARGETNAME, String::CreateFromAscii("_blank"));
1203 			SfxViewFrame::Current()->GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, &aURL, &aRef, &aTarget, 0L);
1204 		}
1205 		break;
1206 	}
1207 }
1208 
OfaState_Impl(SfxItemSet & rSet)1209 void SfxApplication::OfaState_Impl(SfxItemSet &rSet)
1210 {
1211 	SvtModuleOptions aModuleOpt;
1212 
1213     if( !aModuleOpt.IsWriter())
1214     {
1215         rSet.DisableItem( FN_LABEL );
1216         rSet.DisableItem( FN_BUSINESS_CARD );
1217         rSet.DisableItem( FN_XFORMS_INIT );
1218     }
1219 
1220 	if ( !aModuleOpt.IsImpress() )
1221         rSet.DisableItem( SID_SD_AUTOPILOT );
1222 }
1223