xref: /aoo42x/main/sfx2/source/appl/app.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sfx2.hxx"
30 
31 #if defined UNX
32 #include <limits.h>
33 #else // UNX
34 #include <stdlib.h>
35 #define PATH_MAX _MAX_PATH
36 #endif // UNX
37 
38 #include <sfx2/app.hxx>
39 #include <sfx2/frame.hxx>
40 #include <vos/process.hxx>
41 #include <tools/simplerm.hxx>
42 #include <tools/config.hxx>
43 #include <basic/basrdll.hxx>
44 #include <basic/sbmeth.hxx>
45 #include <basic/sbmod.hxx>
46 #include <svtools/asynclink.hxx>
47 #include <svl/stritem.hxx>
48 #include <vcl/sound.hxx>
49 #include <svl/eitem.hxx>
50 #include <svl/urlbmk.hxx>
51 #include <vcl/msgbox.hxx>
52 #include <svtools/sfxecode.hxx>
53 #include <svtools/ehdl.hxx>
54 
55 #include <svl/svdde.hxx>
56 #include <tools/urlobj.hxx>
57 #include <unotools/tempfile.hxx>
58 #include <osl/file.hxx>
59 
60 #define _SVSTDARR_STRINGSDTOR
61 #include <svl/svstdarr.hxx>
62 
63 #include <com/sun/star/uno/Sequence.hxx>
64 #include <com/sun/star/uno/Any.hxx>
65 #include <com/sun/star/lang/XInitialization.hpp>
66 #include <com/sun/star/frame/XFrameActionListener.hpp>
67 #include <com/sun/star/frame/XComponentLoader.hpp>
68 #include <com/sun/star/frame/XFrame.hpp>
69 #include <com/sun/star/frame/FrameActionEvent.hpp>
70 #include <com/sun/star/frame/FrameAction.hpp>
71 #include <com/sun/star/loader/XImplementationLoader.hpp>
72 #include <com/sun/star/loader/CannotActivateFactoryException.hpp>
73 #include <com/sun/star/mozilla/XPluginInstance.hpp>
74 #include <com/sun/star/frame/XFramesSupplier.hpp>
75 #include <com/sun/star/container/XIndexAccess.hpp>
76 #include <com/sun/star/beans/XPropertySet.hpp>
77 #include <comphelper/processfactory.hxx>
78 #include <com/sun/star/uri/XUriReferenceFactory.hpp>
79 #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
80 #include <basic/basmgr.hxx>
81 #include <toolkit/helper/vclunohelper.hxx>
82 #include <vcl/svapp.hxx>
83 #include <rtl/logfile.hxx>
84 #include <sfx2/appuno.hxx>
85 #include "sfx2/sfxhelp.hxx"
86 #include <sfx2/request.hxx>
87 #include "sfxtypes.hxx"
88 #include "sfx2/sfxresid.hxx"
89 #include "arrdecl.hxx"
90 #include <sfx2/progress.hxx>
91 #include <sfx2/objsh.hxx>
92 #include <sfx2/docfac.hxx>
93 #include <sfx2/docfile.hxx>
94 #include <sfx2/docfilt.hxx>
95 #include "fltfnc.hxx"
96 #include "nfltdlg.hxx"
97 #include <sfx2/new.hxx>
98 #include <sfx2/bindings.hxx>
99 #include <sfx2/dispatch.hxx>
100 #include <sfx2/viewsh.hxx>
101 #include <sfx2/genlink.hxx>
102 #include <sfx2/viewfrm.hxx>
103 #include "appdata.hxx"
104 #include "openflag.hxx"
105 #include "app.hrc"
106 #include "virtmenu.hxx"
107 #include <sfx2/module.hxx>
108 #include <sfx2/event.hxx>
109 #include "imestatuswindow.hxx"
110 #include "workwin.hxx"
111 #include <sfx2/module.hxx>
112 #include <sfx2/tbxctrl.hxx>
113 #include <sfx2/sfxdlg.hxx>
114 #include "sfx2/stbitem.hxx"
115 #include "eventsupplier.hxx"
116 #include <sfx2/dockwin.hxx>
117 #include <tools/svlibrary.hxx>
118 
119 #ifdef DBG_UTIL
120 #include <sfx2/tbxctrl.hxx>
121 #include <sfx2/mnuitem.hxx>
122 #endif
123 
124 #if defined( WNT ) || defined( OS2 )
125 #define DDE_AVAILABLE
126 #endif
127 
128 #include <unotools/saveopt.hxx>
129 #include <unotools/undoopt.hxx>
130 #include <svtools/helpopt.hxx>
131 #include <unotools/pathoptions.hxx>
132 #include <unotools/viewoptions.hxx>
133 #include <unotools/moduleoptions.hxx>
134 #include <unotools/historyoptions.hxx>
135 #include <svtools/menuoptions.hxx>
136 #include <svtools/miscopt.hxx>
137 #include <unotools/useroptions.hxx>
138 #include <unotools/startoptions.hxx>
139 #include <unotools/securityoptions.hxx>
140 #include <unotools/localisationoptions.hxx>
141 #include <unotools/inetoptions.hxx>
142 #include <unotools/fontoptions.hxx>
143 #include <unotools/internaloptions.hxx>
144 #include <unotools/workingsetoptions.hxx>
145 #include <unotools/syslocaleoptions.hxx>
146 #include <unotools/syslocale.hxx>
147 #include <framework/addonsoptions.hxx>
148 #include <svtools/ttprops.hxx>
149 #include <unotools/extendedsecurityoptions.hxx>
150 
151 using namespace ::com::sun::star;
152 
153 // Static member
154 SfxApplication* SfxApplication::pApp = NULL;
155 static BasicDLL*       pBasic   = NULL;
156 
157 class SfxPropertyHandler : public PropertyHandler
158 {
159     virtual void Property( ApplicationProperty& );
160 };
161 
162 static SfxPropertyHandler*	pPropertyHandler = 0;
163 
164 SfxPropertyHandler* GetOrCreatePropertyHandler()
165 {
166 	if ( !pPropertyHandler )
167 	{
168 		::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
169 		if ( !pPropertyHandler )
170 			pPropertyHandler = new SfxPropertyHandler;
171 	}
172 
173 	return pPropertyHandler;
174 }
175 
176 void SfxPropertyHandler::Property( ApplicationProperty& rProp )
177 {
178 	TTProperties* pTTProperties = PTR_CAST( TTProperties, &rProp );
179 	if ( pTTProperties )
180 	{
181 		pTTProperties->nPropertyVersion = TT_PROPERTIES_VERSION;
182 		switch ( pTTProperties->nActualPR )
183 		{
184 			case TT_PR_SLOTS:
185 			{
186 				pTTProperties->nSidOpenUrl = SID_OPENURL;
187 				pTTProperties->nSidFileName = SID_FILE_NAME;
188 				pTTProperties->nSidNewDocDirect = SID_NEWDOCDIRECT;
189 				pTTProperties->nSidCopy = SID_COPY;
190 				pTTProperties->nSidPaste = SID_PASTE;
191 				pTTProperties->nSidSourceView = SID_SOURCEVIEW;
192 				pTTProperties->nSidSelectAll = SID_SELECTALL;
193 				pTTProperties->nSidReferer = SID_REFERER;
194 				pTTProperties->nActualPR = 0;
195 			}
196 			break;
197 			case TT_PR_DISPATCHER:
198 			{
199                 // interface for TestTool
200                 SfxViewFrame* pViewFrame=0;
201                 SfxDispatcher* pDispatcher=0;
202 				pViewFrame = SfxViewFrame::Current();
203 				if ( !pViewFrame )
204 					pViewFrame = SfxViewFrame::GetFirst();
205 				if ( pViewFrame )
206 					pDispatcher = pViewFrame->GetDispatcher();
207 				else
208 					pDispatcher = NULL;
209 				if ( !pDispatcher )
210 					pTTProperties->nActualPR = TT_PR_ERR_NODISPATCHER;
211 				else
212 				{
213 					pDispatcher->SetExecuteMode(EXECUTEMODE_DIALOGASYNCHRON);
214                     if ( pTTProperties->mnSID == SID_NEWDOCDIRECT
215                       || pTTProperties->mnSID == SID_OPENDOC )
216                     {
217                         SfxPoolItem** pArgs = pTTProperties->mppArgs;
218                         SfxAllItemSet aSet( SFX_APP()->GetPool() );
219                         if ( pArgs && *pArgs )
220                         {
221                             for ( SfxPoolItem **pArg = pArgs; *pArg; ++pArg )
222                                 aSet.Put( **pArg );
223                         }
224                         if ( pTTProperties->mnSID == SID_NEWDOCDIRECT )
225                         {
226                             String aFactory = String::CreateFromAscii("private:factory/");
227                             if ( pArgs && *pArgs )
228                             {
229                                 SFX_ITEMSET_ARG( &aSet, pFactoryName, SfxStringItem, SID_NEWDOCDIRECT, sal_False );
230                                 if ( pFactoryName )
231                                     aFactory += pFactoryName->GetValue();
232                                 else
233                                     aFactory += String::CreateFromAscii("swriter");
234                             }
235                             else
236                                 aFactory += String::CreateFromAscii("swriter");
237 
238                             aSet.Put( SfxStringItem( SID_FILE_NAME, aFactory ) );
239                             aSet.ClearItem( SID_NEWDOCDIRECT );
240                             pTTProperties->mnSID = SID_OPENDOC;
241                         }
242 
243                         aSet.Put( SfxStringItem( SID_TARGETNAME, DEFINE_CONST_UNICODE("_blank") ) );
244                         if ( pDispatcher->ExecuteFunction( pTTProperties->mnSID, aSet, pTTProperties->mnMode )
245                                     == EXECUTE_NO )
246                             pTTProperties->nActualPR = TT_PR_ERR_NOEXECUTE;
247                         else
248                             pTTProperties->nActualPR = 0;
249                     }
250                     else
251                     {
252                         if ( pDispatcher->ExecuteFunction(
253                                 pTTProperties->mnSID, pTTProperties->mppArgs, pTTProperties->mnMode )
254                             == EXECUTE_NO )
255                             pTTProperties->nActualPR = TT_PR_ERR_NOEXECUTE;
256                         else
257                             pTTProperties->nActualPR = 0;
258                     }
259 				}
260 			}
261 			break;
262 /*
263 			case TT_PR_IMG:
264 			{
265 				SvDataMemberObjectRef aDataObject = new SvDataMemberObject();
266 				SvData* pDataBmp = new SvData( FORMAT_BITMAP );
267 				pDataBmp->SetData( pTTProperties->mpBmp );
268 				aDataObject->Append( pDataBmp );
269 				aDataObject->CopyClipboard();
270 				pTTProperties->nActualPR = 0;
271 			}
272 			break;
273 */
274 			default:
275 			{
276 				pTTProperties->nPropertyVersion = 0;
277 			}
278 		}
279 		return;
280 	}
281 }
282 
283 #include <framework/imageproducer.hxx>
284 #include <framework/acceleratorinfo.hxx>
285 #include <framework/sfxhelperfunctions.hxx>
286 #include "sfx2/imagemgr.hxx"
287 #include "fwkhelper.hxx"
288 
289 ::osl::Mutex SfxApplication::gMutex;
290 
291 SfxApplication* SfxApplication::GetOrCreate()
292 {
293 	// SFX on demand
294     ::osl::MutexGuard aGuard(SfxApplication::gMutex);
295     if ( !pApp )
296     {
297         SfxApplication *pNew = new SfxApplication;
298 
299         //TODO/CLEANUP
300         //ist das Mutex-Handling OK?
301         static ::osl::Mutex aProtector;
302         ::osl::MutexGuard aGuard2( aProtector );
303 
304         RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxApplication::SetApp" );
305         pApp = pNew;
306 
307         // at the moment a bug may occur when Initialize_Impl returns sal_False, but this is only temporary because all code that may cause such a
308         // fault will be moved outside the SFX
309         pApp->Initialize_Impl();
310 
311 		::framework::SetImageProducer( GetImage );
312         ::framework::SetRefreshToolbars( RefreshToolbars );
313         ::framework::SetToolBoxControllerCreator( SfxToolBoxControllerFactory );
314         ::framework::SetStatusBarControllerCreator( SfxStatusBarControllerFactory );
315 		::framework::SetDockingWindowCreator( SfxDockingWindowFactory );
316         ::framework::SetIsDockingWindowVisible( IsDockingWindowVisible );
317         ::framework::SetActivateToolPanel( &SfxViewFrame::ActivateToolPanel );
318 
319 		SfxHelp* pSfxHelp = new SfxHelp;
320 		Application::SetHelp( pSfxHelp );
321 		if ( SvtHelpOptions().IsHelpTips() )
322 			Help::EnableQuickHelp();
323 		else
324 			Help::DisableQuickHelp();
325 		if ( SvtHelpOptions().IsHelpTips() && SvtHelpOptions().IsExtendedHelp() )
326 			Help::EnableBalloonHelp();
327 		else
328 			Help::DisableBalloonHelp();
329 	}
330 	return pApp;
331 }
332 
333 SfxApplication::SfxApplication()
334     : pAppData_Impl( 0 )
335 {
336 	RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxApplication::SfxApplication" );
337 
338     SetName( DEFINE_CONST_UNICODE("StarOffice") );
339 	GetpApp()->SetPropertyHandler( GetOrCreatePropertyHandler() );
340 
341     SvtViewOptions::AcquireOptions();
342 
343 	pAppData_Impl = new SfxAppData_Impl( this );
344 	pAppData_Impl->UpdateApplicationSettings( SvtMenuOptions().IsEntryHidingEnabled() );
345     pAppData_Impl->m_xImeStatusWindow->init();
346     pApp->PreInit();
347 
348 	RTL_LOGFILE_CONTEXT_TRACE( aLog, "{ initialize DDE" );
349 
350 #ifdef DDE_AVAILABLE
351 #ifndef DBG_UTIL
352     InitializeDde();
353 #else
354     if( !InitializeDde() )
355     {
356         ByteString aStr( "Kein DDE-Service moeglich. Fehler: " );
357         if( GetDdeService() )
358             aStr += ByteString::CreateFromInt32(GetDdeService()->GetError());
359         else
360             aStr += '?';
361         DBG_ASSERT( sal_False, aStr.GetBuffer() );
362     }
363 #endif
364 #endif
365 
366     pBasic   = new BasicDLL;
367 	StarBASIC::SetGlobalErrorHdl( LINK( this, SfxApplication, GlobalBasicErrorHdl_Impl ) );
368 	RTL_LOGFILE_CONTEXT_TRACE( aLog, "} initialize DDE" );
369 }
370 
371 SfxApplication::~SfxApplication()
372 {
373     OSL_ENSURE( GetObjectShells_Impl().Count() == 0, "Memory leak: some object shells were not removed!" );
374 
375     Broadcast( SfxSimpleHint(SFX_HINT_DYING) );
376 
377     SfxModule::DestroyModules_Impl();
378 
379     // delete global options
380     SvtViewOptions::ReleaseOptions();
381 	delete pBasic;
382 
383     if ( !pAppData_Impl->bDowning )
384         Deinitialize();
385 
386     delete pAppData_Impl;
387     pApp = 0;
388 }
389 
390 //====================================================================
391 
392 const String& SfxApplication::GetLastDir_Impl() const
393 
394 /*  [Beschreibung]
395 
396     Interne Methode, mit der im SFx das zuletzt mit der Methode
397     <SfxApplication::SetLastDir_Impl()> gesetzte Verzeichnis
398     zurueckgegeben wird.
399 
400     Dieses ist i.d.R. das zuletzt durch den SfxFileDialog
401     angesprochene Verzeichnis.
402 
403     [Querverweis]
404     <SfxApplication::SetLastDir_Impl()>
405 */
406 
407 {
408     return pAppData_Impl->aLastDir;
409 }
410 
411 const String& SfxApplication::GetLastSaveDirectory() const
412 
413 /*  [Beschreibung]
414 
415     Wie <SfxApplication::GetLastDir_Impl()>, nur extern
416 
417     [Querverweis]
418     <SfxApplication::GetLastDir_Impl()>
419 */
420 
421 {
422     return GetLastDir_Impl();
423 }
424 
425 //--------------------------------------------------------------------
426 
427 void SfxApplication::SetLastDir_Impl
428 (
429     const String&   rNewDir     /*  kompletter Verzeichnis-Pfad als String */
430     )
431 
432 /*  [Beschreibung]
433 
434     Interne Methode, mit der ein Verzeichnis-Pfad gesetzt wird, der
435     zuletzt (z.B. durch den SfxFileDialog) angesprochen wurde.
436 
437     [Querverweis]
438     <SfxApplication::GetLastDir_Impl()>
439 */
440 
441 {
442     pAppData_Impl->aLastDir = rNewDir;
443 }
444 
445 //--------------------------------------------------------------------
446 
447 void SfxApplication::ResetLastDir()
448 {
449     String aEmpty;
450     pAppData_Impl->aLastDir = aEmpty;
451 }
452 
453 //--------------------------------------------------------------------
454 
455 SfxDispatcher* SfxApplication::GetDispatcher_Impl()
456 {
457     return pAppData_Impl->pViewFrame? pAppData_Impl->pViewFrame->GetDispatcher(): pAppData_Impl->pAppDispat;
458 }
459 
460 //--------------------------------------------------------------------
461 void SfxApplication::SetViewFrame_Impl( SfxViewFrame *pFrame )
462 {
463     if ( pFrame != pAppData_Impl->pViewFrame )
464     {
465 		// get the containerframes ( if one of the frames is an InPlaceFrame )
466         SfxViewFrame *pOldContainerFrame = pAppData_Impl->pViewFrame;
467         while ( pOldContainerFrame && pOldContainerFrame->GetParentViewFrame_Impl() )
468             pOldContainerFrame = pOldContainerFrame->GetParentViewFrame_Impl();
469         SfxViewFrame *pNewContainerFrame = pFrame;
470         while ( pNewContainerFrame && pNewContainerFrame->GetParentViewFrame_Impl() )
471             pNewContainerFrame = pNewContainerFrame->GetParentViewFrame_Impl();
472 
473 		// DocWinActivate : both frames belong to the same TopWindow
474 		// TopWinActivate : both frames belong to different TopWindows
475 // not used anymore!
476 //		sal_Bool bDocWinActivate = pOldContainerFrame && pNewContainerFrame &&
477 //        			pOldContainerFrame->GetTopViewFrame() == pNewContainerFrame->GetTopViewFrame();
478 		sal_Bool bTaskActivate = pOldContainerFrame != pNewContainerFrame;
479 
480 		if ( pOldContainerFrame )
481 		{
482 			if ( bTaskActivate )
483                 NotifyEvent( SfxViewEventHint( SFX_EVENT_DEACTIVATEDOC, GlobalEventConfig::GetEventName(STR_EVENT_DEACTIVATEDOC), pOldContainerFrame->GetObjectShell(), pOldContainerFrame->GetFrame().GetController() ) );
484 		    pOldContainerFrame->DoDeactivate( bTaskActivate, pFrame );
485 
486 	        if( pOldContainerFrame->GetProgress() )
487 	            pOldContainerFrame->GetProgress()->Suspend();
488 		}
489 
490         pAppData_Impl->pViewFrame = pFrame;
491 
492         //const SfxObjectShell* pSh = pViewFrame ? pViewFrame->GetObjectShell() : 0;
493         //if ( !pSh )
494         //{
495         //    // otherwise BaseURL is set in activation of document
496         //    INetURLObject aObject( SvtPathOptions().GetWorkPath() );
497         //    aObject.setFinalSlash();
498         //    INetURLObject::SetBaseURL( aObject.GetMainURL( INetURLObject::NO_DECODE ) );
499         //}
500 
501         if( pNewContainerFrame )
502 		{
503             pNewContainerFrame->DoActivate( bTaskActivate );
504 	        if ( bTaskActivate && pNewContainerFrame->GetObjectShell() )
505             {
506                 pNewContainerFrame->GetObjectShell()->PostActivateEvent_Impl( pNewContainerFrame );
507                 NotifyEvent(SfxViewEventHint(SFX_EVENT_ACTIVATEDOC, GlobalEventConfig::GetEventName(STR_EVENT_ACTIVATEDOC), pNewContainerFrame->GetObjectShell(), pNewContainerFrame->GetFrame().GetController() ) );
508             }
509 
510             SfxProgress *pProgress = pNewContainerFrame->GetProgress();
511             if ( pProgress )
512             {
513                 if( pProgress->IsSuspended() )
514                     pProgress->Resume();
515                 else
516                     pProgress->SetState( pProgress->GetState() );
517             }
518 
519             if ( pAppData_Impl->pViewFrame->GetViewShell() )
520             {
521                 SfxDispatcher* pDisp = pAppData_Impl->pViewFrame->GetDispatcher();
522                 pDisp->Flush();
523                 pDisp->Update_Impl(sal_True);
524 			}
525 		}
526     }
527 
528     // even if the frame actually didn't change, ensure its document is forwarded
529     // to SfxObjectShell::SetCurrentComponent.
530     // Otherwise, the CurrentComponent might not be correct, in case it has meanwhile
531     // been reset to some other document, by some non-SFX component.
532     // #i49133# / 2007-12-19 / frank.schoenheit@sun.com
533     if ( pFrame && pFrame->GetViewShell() )
534         pFrame->GetViewShell()->SetCurrentDocument();
535 }
536 
537 //--------------------------------------------------------------------
538 
539 short SfxApplication::QuerySave_Impl( SfxObjectShell& rDoc, sal_Bool /*bAutoSave*/ )
540 {
541     if ( !rDoc.IsModified() )
542         return RET_NO;
543 
544     String aMsg( SfxResId( STR_ISMODIFIED ) );
545     aMsg.SearchAndReplaceAscii( "%1", rDoc.GetTitle() );
546 
547     SfxFrame& rFrame = SfxViewFrame::GetFirst(&rDoc)->GetFrame();
548     rFrame.Appear();
549 
550 	WinBits nBits = WB_YES_NO_CANCEL | WB_DEF_NO;
551     QueryBox aBox( &rFrame.GetWindow(), nBits, aMsg );
552 
553     return aBox.Execute();
554 }
555 
556 //---------------------------------------------------------------------
557 
558 ResMgr* SfxApplication::CreateResManager( const char *pPrefix )
559 {
560     String aMgrName = String::CreateFromAscii( pPrefix );
561     return ResMgr::CreateResMgr(U2S(aMgrName));
562 }
563 
564 //---------------------------------------------------------------------
565 
566 SimpleResMgr* SfxApplication::CreateSimpleResManager()
567 {
568 	SimpleResMgr	*pRet;
569 	const AllSettings& rAllSettings	= Application::GetSettings();
570     ::com::sun::star::lang::Locale aLocale = rAllSettings.GetUILocale();
571 	pRet = new SimpleResMgr( CREATEVERSIONRESMGR_NAME(sfx), aLocale );
572 
573 	return pRet;
574 }
575 
576 //--------------------------------------------------------------------
577 
578 ResMgr* SfxApplication::GetSfxResManager()
579 {
580 	return SfxResId::GetResMgr();
581 }
582 
583 //--------------------------------------------------------------------
584 
585 SimpleResMgr* SfxApplication::GetSimpleResManager()
586 {
587     if ( !pAppData_Impl->pSimpleResManager )
588         pAppData_Impl->pSimpleResManager = CreateSimpleResManager();
589     return pAppData_Impl->pSimpleResManager;
590 }
591 
592 //------------------------------------------------------------------------
593 
594 void SfxApplication::SetProgress_Impl
595 (
596     SfxProgress *pProgress
597 
598 )
599 {
600     DBG_ASSERT( ( !pAppData_Impl->pProgress && pProgress ) ||
601                 ( pAppData_Impl->pProgress && !pProgress ),
602                 "Progress acitivation/deacitivation mismatch" );
603 
604     if ( pAppData_Impl->pProgress && pProgress )
605     {
606         pAppData_Impl->pProgress->Suspend();
607         pAppData_Impl->pProgress->UnLock();
608         delete pAppData_Impl->pProgress;
609     }
610 
611     pAppData_Impl->pProgress = pProgress;
612 }
613 
614 //------------------------------------------------------------------------
615 
616 sal_uInt16 SfxApplication::GetFreeIndex()
617 {
618     return pAppData_Impl->aIndexBitSet.GetFreeIndex()+1;
619 }
620 
621 //------------------------------------------------------------------------
622 
623 void SfxApplication::ReleaseIndex(sal_uInt16 i)
624 {
625     pAppData_Impl->aIndexBitSet.ReleaseIndex(i-1);
626 }
627 
628 //--------------------------------------------------------------------
629 
630 void SfxApplication::EnterAsynchronCall_Impl()
631 {
632     ++pAppData_Impl->nAsynchronCalls;
633 }
634 
635 //--------------------------------------------------------------------
636 
637 void SfxApplication::LeaveAsynchronCall_Impl()
638 {
639     --pAppData_Impl->nAsynchronCalls;
640 }
641 
642 //--------------------------------------------------------------------
643 
644 bool SfxApplication::IsInAsynchronCall_Impl() const
645 {
646     return pAppData_Impl->nAsynchronCalls > 0;
647 }
648 
649 //--------------------------------------------------------------------
650 
651 Window* SfxApplication::GetTopWindow() const
652 {
653     SfxWorkWindow* pWork = GetWorkWindow_Impl( SfxViewFrame::Current() );
654     return pWork ? pWork->GetWindow() : NULL;
655 }
656 
657 //--------------------------------------------------------------------
658 
659 uno::Reference< task::XStatusIndicator > SfxApplication::GetStatusIndicator() const
660 {
661     if ( !pAppData_Impl->pViewFrame )
662         return uno::Reference< task::XStatusIndicator >();
663 
664     SfxViewFrame *pTop = pAppData_Impl->pViewFrame;
665     while ( pTop->GetParentViewFrame_Impl() )
666         pTop = pTop->GetParentViewFrame_Impl();
667 
668     return pTop->GetFrame().GetWorkWindow_Impl()->GetStatusIndicator();
669 }
670 
671 SfxTbxCtrlFactArr_Impl&     SfxApplication::GetTbxCtrlFactories_Impl() const
672 {
673     return *pAppData_Impl->pTbxCtrlFac;
674 }
675 
676 SfxStbCtrlFactArr_Impl&     SfxApplication::GetStbCtrlFactories_Impl() const
677 {
678     return *pAppData_Impl->pStbCtrlFac;
679 }
680 
681 SfxMenuCtrlFactArr_Impl&    SfxApplication::GetMenuCtrlFactories_Impl() const
682 {
683     return *pAppData_Impl->pMenuCtrlFac;
684 }
685 
686 SfxViewFrameArr_Impl&       SfxApplication::GetViewFrames_Impl() const
687 {
688     return *pAppData_Impl->pViewFrames;
689 }
690 
691 SfxViewShellArr_Impl&       SfxApplication::GetViewShells_Impl() const
692 {
693     return *pAppData_Impl->pViewShells;
694 }
695 
696 SfxObjectShellArr_Impl&     SfxApplication::GetObjectShells_Impl() const
697 {
698     return *pAppData_Impl->pObjShells;
699 }
700 
701 void SfxApplication::Invalidate( sal_uInt16 nId )
702 {
703     for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst(); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame ) )
704         Invalidate_Impl( pFrame->GetBindings(), nId );
705 }
706 
707 #define DOSTRING( x )			   			#x
708 #define STRING( x )				   			DOSTRING( x )
709 
710 typedef	long (SAL_CALL *basicide_handle_basic_error)(void*);
711 typedef	rtl_uString* (SAL_CALL *basicide_choose_macro)(void*, sal_Bool, rtl_uString*);
712 typedef	void* (SAL_CALL *basicide_macro_organizer)(sal_Int16);
713 
714 extern "C" { static void SAL_CALL thisModule() {} }
715 
716 IMPL_LINK( SfxApplication, GlobalBasicErrorHdl_Impl, StarBASIC*, pStarBasic )
717 {
718     // get basctl dllname
719     static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "basctl" ) ) );
720 
721     // load module
722 	oslModule handleMod = osl_loadModuleRelative(
723         &thisModule, aLibName.pData, 0 );
724 
725     // get symbol
726     ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_handle_basic_error" ) );
727     basicide_handle_basic_error pSymbol = (basicide_handle_basic_error) osl_getFunctionSymbol( handleMod, aSymbol.pData );
728 
729     // call basicide_handle_basic_error in basctl
730     long nRet = pSymbol( pStarBasic );
731 
732 	return nRet;
733 }
734 
735 sal_Bool SfxApplication::IsXScriptURL( const String& rScriptURL )
736 {
737 	sal_Bool result = sal_False;
738 
739     ::com::sun::star::uno::Reference
740 		< ::com::sun::star::lang::XMultiServiceFactory > xSMgr =
741         	::comphelper::getProcessServiceFactory();
742 
743     ::com::sun::star::uno::Reference
744 		< ::com::sun::star::uri::XUriReferenceFactory >
745         	xFactory( xSMgr->createInstance(
746             	::rtl::OUString::createFromAscii(
747                 	"com.sun.star.uri.UriReferenceFactory" ) ),
748 				::com::sun::star::uno::UNO_QUERY );
749 
750     if ( xFactory.is() )
751     {
752 		try
753 		{
754         	::com::sun::star::uno::Reference
755 				< ::com::sun::star::uri::XVndSunStarScriptUrl >
756             		xUrl( xFactory->parse( rScriptURL ),
757 						::com::sun::star::uno::UNO_QUERY );
758 
759         	if ( xUrl.is() )
760         	{
761             	result = sal_True;
762         	}
763 		}
764 		catch ( ::com::sun::star::uno::RuntimeException& )
765 		{
766 			// ignore, will just return FALSE
767 		}
768 	}
769 	return result;
770 }
771 
772 ::rtl::OUString
773 SfxApplication::ChooseScript()
774 {
775 	::rtl::OUString aScriptURL;
776 
777 	SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
778 	if ( pFact )
779 	{
780 		OSL_TRACE("create selector dialog");
781 
782         const SfxViewFrame* pViewFrame = SfxViewFrame::Current();
783         const SfxFrame* pFrame = pViewFrame ? &pViewFrame->GetFrame() : NULL;
784         uno::Reference< frame::XFrame > xFrame( pFrame ? pFrame->GetFrameInterface() : uno::Reference< frame::XFrame >() );
785 
786 	  	AbstractScriptSelectorDialog* pDlg =
787 			pFact->CreateScriptSelectorDialog( NULL, sal_False, xFrame );
788 
789 		OSL_TRACE("done, now exec it");
790 
791 	  	sal_uInt16 nRet = pDlg->Execute();
792 
793 		OSL_TRACE("has returned");
794 
795 		if ( nRet == RET_OK )
796 		{
797 			aScriptURL = pDlg->GetScriptURL();
798 		}
799 
800 	  	delete pDlg;
801 	}
802     return aScriptURL;
803 }
804 
805 void SfxApplication::MacroOrganizer( sal_Int16 nTabId )
806 {
807     // get basctl dllname
808     static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "basctl" ) ) );
809 
810     // load module
811 	oslModule handleMod = osl_loadModuleRelative(
812         &thisModule, aLibName.pData, 0 );
813 
814     // get symbol
815     ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_macro_organizer" ) );
816     basicide_macro_organizer pSymbol = (basicide_macro_organizer) osl_getFunctionSymbol( handleMod, aSymbol.pData );
817 
818     // call basicide_choose_macro in basctl
819     pSymbol( nTabId );
820 }
821 
822 ErrCode SfxApplication::CallBasic( const String& rCode, BasicManager* pMgr, SbxArray* pArgs, SbxValue* pRet )
823 {
824     return pMgr->ExecuteMacro( rCode, pArgs, pRet);
825 }
826