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