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