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 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 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 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 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 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 388 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 407 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 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 443 void SfxApplication::ResetLastDir() 444 { 445 String aEmpty; 446 pAppData_Impl->aLastDir = aEmpty; 447 } 448 449 //-------------------------------------------------------------------- 450 451 SfxDispatcher* SfxApplication::GetDispatcher_Impl() 452 { 453 return pAppData_Impl->pViewFrame? pAppData_Impl->pViewFrame->GetDispatcher(): pAppData_Impl->pAppDispat; 454 } 455 456 //-------------------------------------------------------------------- 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 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 554 ResMgr* SfxApplication::CreateResManager( const char *pPrefix ) 555 { 556 String aMgrName = String::CreateFromAscii( pPrefix ); 557 return ResMgr::CreateResMgr(U2S(aMgrName)); 558 } 559 560 //--------------------------------------------------------------------- 561 562 SimpleResMgr* SfxApplication::CreateSimpleResManager() 563 { 564 SimpleResMgr *pRet; 565 const AllSettings& rAllSettings = Application::GetSettings(); 566 ::com::sun::star::lang::Locale aLocale = rAllSettings.GetUILocale(); 567 pRet = new SimpleResMgr( CREATEVERSIONRESMGR_NAME(sfx), aLocale ); 568 569 return pRet; 570 } 571 572 //-------------------------------------------------------------------- 573 574 ResMgr* SfxApplication::GetSfxResManager() 575 { 576 return SfxResId::GetResMgr(); 577 } 578 579 //-------------------------------------------------------------------- 580 581 SimpleResMgr* SfxApplication::GetSimpleResManager() 582 { 583 if ( !pAppData_Impl->pSimpleResManager ) 584 pAppData_Impl->pSimpleResManager = CreateSimpleResManager(); 585 return pAppData_Impl->pSimpleResManager; 586 } 587 588 //------------------------------------------------------------------------ 589 590 void SfxApplication::SetProgress_Impl 591 ( 592 SfxProgress *pProgress 593 594 ) 595 { 596 DBG_ASSERT( ( !pAppData_Impl->pProgress && pProgress ) || 597 ( pAppData_Impl->pProgress && !pProgress ), 598 "Progress acitivation/deacitivation mismatch" ); 599 600 if ( pAppData_Impl->pProgress && pProgress ) 601 { 602 pAppData_Impl->pProgress->Suspend(); 603 pAppData_Impl->pProgress->UnLock(); 604 delete pAppData_Impl->pProgress; 605 } 606 607 pAppData_Impl->pProgress = pProgress; 608 } 609 610 //------------------------------------------------------------------------ 611 612 sal_uInt16 SfxApplication::GetFreeIndex() 613 { 614 return pAppData_Impl->aIndexBitSet.GetFreeIndex()+1; 615 } 616 617 //------------------------------------------------------------------------ 618 619 void SfxApplication::ReleaseIndex(sal_uInt16 i) 620 { 621 pAppData_Impl->aIndexBitSet.ReleaseIndex(i-1); 622 } 623 624 //-------------------------------------------------------------------- 625 626 void SfxApplication::EnterAsynchronCall_Impl() 627 { 628 ++pAppData_Impl->nAsynchronCalls; 629 } 630 631 //-------------------------------------------------------------------- 632 633 void SfxApplication::LeaveAsynchronCall_Impl() 634 { 635 --pAppData_Impl->nAsynchronCalls; 636 } 637 638 //-------------------------------------------------------------------- 639 640 bool SfxApplication::IsInAsynchronCall_Impl() const 641 { 642 return pAppData_Impl->nAsynchronCalls > 0; 643 } 644 645 //-------------------------------------------------------------------- 646 647 Window* SfxApplication::GetTopWindow() const 648 { 649 SfxWorkWindow* pWork = GetWorkWindow_Impl( SfxViewFrame::Current() ); 650 return pWork ? pWork->GetWindow() : NULL; 651 } 652 653 //-------------------------------------------------------------------- 654 655 uno::Reference< task::XStatusIndicator > SfxApplication::GetStatusIndicator() const 656 { 657 if ( !pAppData_Impl->pViewFrame ) 658 return uno::Reference< task::XStatusIndicator >(); 659 660 SfxViewFrame *pTop = pAppData_Impl->pViewFrame; 661 while ( pTop->GetParentViewFrame_Impl() ) 662 pTop = pTop->GetParentViewFrame_Impl(); 663 664 return pTop->GetFrame().GetWorkWindow_Impl()->GetStatusIndicator(); 665 } 666 667 SfxTbxCtrlFactArr_Impl& SfxApplication::GetTbxCtrlFactories_Impl() const 668 { 669 return *pAppData_Impl->pTbxCtrlFac; 670 } 671 672 SfxStbCtrlFactArr_Impl& SfxApplication::GetStbCtrlFactories_Impl() const 673 { 674 return *pAppData_Impl->pStbCtrlFac; 675 } 676 677 SfxMenuCtrlFactArr_Impl& SfxApplication::GetMenuCtrlFactories_Impl() const 678 { 679 return *pAppData_Impl->pMenuCtrlFac; 680 } 681 682 SfxViewFrameArr_Impl& SfxApplication::GetViewFrames_Impl() const 683 { 684 return *pAppData_Impl->pViewFrames; 685 } 686 687 SfxViewShellArr_Impl& SfxApplication::GetViewShells_Impl() const 688 { 689 return *pAppData_Impl->pViewShells; 690 } 691 692 SfxObjectShellArr_Impl& SfxApplication::GetObjectShells_Impl() const 693 { 694 return *pAppData_Impl->pObjShells; 695 } 696 697 void SfxApplication::Invalidate( sal_uInt16 nId ) 698 { 699 for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst(); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame ) ) 700 Invalidate_Impl( pFrame->GetBindings(), nId ); 701 } 702 703 #define DOSTRING( x ) #x 704 #define STRING( x ) DOSTRING( x ) 705 706 typedef long (SAL_CALL *basicide_handle_basic_error)(void*); 707 typedef rtl_uString* (SAL_CALL *basicide_choose_macro)(void*, sal_Bool, rtl_uString*); 708 typedef void* (SAL_CALL *basicide_macro_organizer)(sal_Int16); 709 710 extern "C" { static void SAL_CALL thisModule() {} } 711 712 IMPL_LINK( SfxApplication, GlobalBasicErrorHdl_Impl, StarBASIC*, pStarBasic ) 713 { 714 // get basctl dllname 715 static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "basctl" ) ) ); 716 717 // load module 718 oslModule handleMod = osl_loadModuleRelative( 719 &thisModule, aLibName.pData, 0 ); 720 721 // get symbol 722 ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_handle_basic_error" ) ); 723 basicide_handle_basic_error pSymbol = (basicide_handle_basic_error) osl_getFunctionSymbol( handleMod, aSymbol.pData ); 724 725 // call basicide_handle_basic_error in basctl 726 long nRet = pSymbol( pStarBasic ); 727 728 return nRet; 729 } 730 731 sal_Bool SfxApplication::IsXScriptURL( const String& rScriptURL ) 732 { 733 sal_Bool result = sal_False; 734 735 ::com::sun::star::uno::Reference 736 < ::com::sun::star::lang::XMultiServiceFactory > xSMgr = 737 ::comphelper::getProcessServiceFactory(); 738 739 ::com::sun::star::uno::Reference 740 < ::com::sun::star::uri::XUriReferenceFactory > 741 xFactory( xSMgr->createInstance( 742 ::rtl::OUString::createFromAscii( 743 "com.sun.star.uri.UriReferenceFactory" ) ), 744 ::com::sun::star::uno::UNO_QUERY ); 745 746 if ( xFactory.is() ) 747 { 748 try 749 { 750 ::com::sun::star::uno::Reference 751 < ::com::sun::star::uri::XVndSunStarScriptUrl > 752 xUrl( xFactory->parse( rScriptURL ), 753 ::com::sun::star::uno::UNO_QUERY ); 754 755 if ( xUrl.is() ) 756 { 757 result = sal_True; 758 } 759 } 760 catch ( ::com::sun::star::uno::RuntimeException& ) 761 { 762 // ignore, will just return FALSE 763 } 764 } 765 return result; 766 } 767 768 ::rtl::OUString 769 SfxApplication::ChooseScript() 770 { 771 ::rtl::OUString aScriptURL; 772 773 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); 774 if ( pFact ) 775 { 776 OSL_TRACE("create selector dialog"); 777 778 const SfxViewFrame* pViewFrame = SfxViewFrame::Current(); 779 const SfxFrame* pFrame = pViewFrame ? &pViewFrame->GetFrame() : NULL; 780 uno::Reference< frame::XFrame > xFrame( pFrame ? pFrame->GetFrameInterface() : uno::Reference< frame::XFrame >() ); 781 782 AbstractScriptSelectorDialog* pDlg = 783 pFact->CreateScriptSelectorDialog( NULL, sal_False, xFrame ); 784 785 OSL_TRACE("done, now exec it"); 786 787 sal_uInt16 nRet = pDlg->Execute(); 788 789 OSL_TRACE("has returned"); 790 791 if ( nRet == RET_OK ) 792 { 793 aScriptURL = pDlg->GetScriptURL(); 794 } 795 796 delete pDlg; 797 } 798 return aScriptURL; 799 } 800 801 void SfxApplication::MacroOrganizer( sal_Int16 nTabId ) 802 { 803 // get basctl dllname 804 static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "basctl" ) ) ); 805 806 // load module 807 oslModule handleMod = osl_loadModuleRelative( 808 &thisModule, aLibName.pData, 0 ); 809 810 // get symbol 811 ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_macro_organizer" ) ); 812 basicide_macro_organizer pSymbol = (basicide_macro_organizer) osl_getFunctionSymbol( handleMod, aSymbol.pData ); 813 814 // call basicide_choose_macro in basctl 815 pSymbol( nTabId ); 816 } 817 818 ErrCode SfxApplication::CallBasic( const String& rCode, BasicManager* pMgr, SbxArray* pArgs, SbxValue* pRet ) 819 { 820 return pMgr->ExecuteMacro( rCode, pArgs, pRet); 821 } 822