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 #include <stdio.h> 32 33 #include <sfx2/viewfrm.hxx> 34 #include <com/sun/star/document/MacroExecMode.hpp> 35 #include <com/sun/star/frame/XLoadable.hpp> 36 #include <com/sun/star/frame/XLayoutManager.hpp> 37 #include <com/sun/star/frame/XComponentLoader.hpp> 38 39 #include <toolkit/unohlp.hxx> 40 #include <vcl/splitwin.hxx> 41 #include <unotools/moduleoptions.hxx> 42 #include <svl/intitem.hxx> 43 #include <svl/visitem.hxx> 44 #include <svl/stritem.hxx> 45 #include <svl/eitem.hxx> 46 #include <svl/slstitm.hxx> 47 #include <svl/whiter.hxx> 48 #include <svl/undo.hxx> 49 #include <vcl/msgbox.hxx> 50 #include <svtools/sfxecode.hxx> 51 #include <svtools/ehdl.hxx> 52 #include <tools/diagnose_ex.h> 53 #include <com/sun/star/container/XIndexAccess.hpp> 54 #include <com/sun/star/frame/XFramesSupplier.hpp> 55 #include <com/sun/star/frame/FrameSearchFlag.hpp> 56 #include <com/sun/star/frame/XFrame.hpp> 57 #include <com/sun/star/frame/XFrames.hpp> 58 #include <com/sun/star/frame/XFramesSupplier.hpp> 59 #include <com/sun/star/awt/XWindow.hpp> 60 #include <com/sun/star/frame/XController.hpp> 61 #include <com/sun/star/frame/XModel2.hpp> 62 #include <com/sun/star/util/XURLTransformer.hpp> 63 #include <com/sun/star/util/XCloseable.hpp> 64 #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp> 65 #include <com/sun/star/document/MacroExecMode.hpp> 66 #include <com/sun/star/document/UpdateDocMode.hpp> 67 #include <com/sun/star/beans/XPropertySet.hpp> 68 #include <com/sun/star/uri/XUriReferenceFactory.hpp> 69 #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp> 70 #include <com/sun/star/embed/XStorage.hpp> 71 #include <com/sun/star/embed/EmbedStates.hpp> 72 #include <com/sun/star/document/XViewDataSupplier.hpp> 73 #include <com/sun/star/container/XIndexContainer.hpp> 74 #include <rtl/ustrbuf.hxx> 75 76 #include <unotools/localfilehelper.hxx> 77 #include <unotools/ucbhelper.hxx> 78 #include <comphelper/processfactory.hxx> 79 #include <comphelper/componentcontext.hxx> 80 #include <comphelper/namedvaluecollection.hxx> 81 #include <comphelper/configurationhelper.hxx> 82 #include <comphelper/docpasswordrequest.hxx> 83 #include <comphelper/docpasswordhelper.hxx> 84 85 #include <com/sun/star/uno/Reference.h> 86 #include <com/sun/star/ucb/XContent.hpp> 87 88 #include <basic/basmgr.hxx> 89 #include <basic/sbmod.hxx> 90 #include <basic/sbmeth.hxx> 91 #include <basic/sbx.hxx> 92 #include <comphelper/storagehelper.hxx> 93 #include <svtools/asynclink.hxx> 94 #include <svl/sharecontrolfile.hxx> 95 #include <svtools/svtools.hrc> 96 #include <svtools/svtdata.hxx> 97 #include <framework/framelistanalyzer.hxx> 98 99 #include <boost/optional.hpp> 100 101 using namespace ::com::sun::star; 102 using namespace ::com::sun::star::uno; 103 using namespace ::com::sun::star::ucb; 104 using namespace ::com::sun::star::frame; 105 using namespace ::com::sun::star::lang; 106 using ::com::sun::star::awt::XWindow; 107 using ::com::sun::star::beans::PropertyValue; 108 using ::com::sun::star::document::XViewDataSupplier; 109 using ::com::sun::star::container::XIndexContainer; 110 namespace css = ::com::sun::star; 111 112 // wg. ViewFrame::Current 113 #include "appdata.hxx" 114 #include <sfx2/taskpane.hxx> 115 #include <sfx2/app.hxx> 116 #include <sfx2/objface.hxx> 117 #include "openflag.hxx" 118 #include "objshimp.hxx" 119 #include <sfx2/viewsh.hxx> 120 #include <sfx2/objsh.hxx> 121 #include <sfx2/bindings.hxx> 122 #include <sfx2/dispatch.hxx> 123 #include "arrdecl.hxx" 124 #include "sfxtypes.hxx" 125 #include <sfx2/request.hxx> 126 #include <sfx2/docfac.hxx> 127 #include <sfx2/ipclient.hxx> 128 #include "sfx2/sfxresid.hxx" 129 #include "appbas.hxx" 130 #include <sfx2/objitem.hxx> 131 #include "sfx2/viewfac.hxx" 132 #include <sfx2/event.hxx> 133 #include "fltfnc.hxx" 134 #include <sfx2/docfile.hxx> 135 #include <sfx2/module.hxx> 136 #include <sfx2/msgpool.hxx> 137 #include <sfx2/viewfrm.hxx> 138 #include "viewimp.hxx" 139 #include <sfx2/sfxbasecontroller.hxx> 140 #include <sfx2/sfx.hrc> 141 #include "view.hrc" 142 #include <sfx2/frmdescr.hxx> 143 #include <sfx2/sfxuno.hxx> 144 #include <sfx2/progress.hxx> 145 #include "workwin.hxx" 146 #include "helper.hxx" 147 #include "macro.hxx" 148 #include "sfx2/minfitem.hxx" 149 #include "../appl/app.hrc" 150 #include "impviewframe.hxx" 151 152 //------------------------------------------------------------------------- 153 DBG_NAME(SfxViewFrame) 154 155 #define SfxViewFrame 156 #include "sfxslots.hxx" 157 #undef SfxViewFrame 158 159 //------------------------------------------------------------------------- 160 161 SFX_IMPL_INTERFACE(SfxViewFrame,SfxShell,SfxResId(0)) 162 { 163 SFX_CHILDWINDOW_REGISTRATION( SID_BROWSER ); 164 SFX_CHILDWINDOW_REGISTRATION( SID_RECORDING_FLOATWINDOW ); 165 166 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_FULLSCREEN | SFX_VISIBILITY_FULLSCREEN, SfxResId(RID_FULLSCREENTOOLBOX) ); 167 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_APPLICATION | SFX_VISIBILITY_STANDARD, SfxResId(RID_ENVTOOLBOX) ); 168 } 169 170 TYPEINIT2(SfxViewFrame,SfxShell,SfxListener); 171 TYPEINIT1(SfxViewFrameItem, SfxPoolItem); 172 173 //========================================================================= 174 175 //------------------------------------------------------------------------- 176 namespace 177 { 178 bool moduleHasToolPanels( SfxViewFrame_Impl& i_rViewFrameImpl ) 179 { 180 if ( !i_rViewFrameImpl.aHasToolPanels ) 181 { 182 i_rViewFrameImpl.aHasToolPanels.reset( ::sfx2::ModuleTaskPane::ModuleHasToolPanels( 183 i_rViewFrameImpl.rFrame.GetFrameInterface() ) ); 184 } 185 return *i_rViewFrameImpl.aHasToolPanels; 186 } 187 } 188 189 //------------------------------------------------------------------------- 190 static sal_Bool AskPasswordToModify_Impl( const uno::Reference< task::XInteractionHandler >& xHandler, const ::rtl::OUString& aPath, const SfxFilter* pFilter, sal_uInt32 nPasswordHash, const uno::Sequence< beans::PropertyValue > aInfo ) 191 { 192 // TODO/LATER: In future the info should replace the direct hash completely 193 sal_Bool bResult = ( !nPasswordHash && !aInfo.getLength() ); 194 195 OSL_ENSURE( pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ), "PasswordToModify feature is active for a filter that does not support it!" ); 196 197 if ( pFilter && xHandler.is() ) 198 { 199 sal_Bool bCancel = sal_False; 200 sal_Bool bFirstTime = sal_True; 201 202 while ( !bResult && !bCancel ) 203 { 204 sal_Bool bMSType = !pFilter->IsOwnFormat(); 205 206 ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest( 207 new ::comphelper::DocPasswordRequest( 208 bMSType ? ::comphelper::DocPasswordRequestType_MS : ::comphelper::DocPasswordRequestType_STANDARD, 209 bFirstTime ? ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER : ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER, 210 aPath, 211 sal_True ) ); 212 213 uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() ); 214 xHandler->handle( rRequest ); 215 216 if ( pPasswordRequest->isPassword() ) 217 { 218 if ( aInfo.getLength() ) 219 { 220 bResult = ::comphelper::DocPasswordHelper::IsModifyPasswordCorrect( pPasswordRequest->getPasswordToModify(), aInfo ); 221 } 222 else 223 { 224 // the binary format 225 bResult = ( SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pFilter->GetServiceName() ) ) == nPasswordHash ); 226 } 227 } 228 else 229 bCancel = sal_True; 230 231 bFirstTime = sal_False; 232 } 233 } 234 235 return bResult; 236 } 237 238 //------------------------------------------------------------------------- 239 void SfxViewFrame::SetDowning_Impl() 240 { 241 pImp->bIsDowning = sal_True; 242 } 243 244 //------------------------------------------------------------------------- 245 sal_Bool SfxViewFrame::IsDowning_Impl() const 246 { 247 return pImp->bIsDowning; 248 } 249 250 251 //-------------------------------------------------------------------- 252 class SfxViewNotificatedFrameList_Impl : 253 public SfxListener, public SfxViewFrameArr_Impl 254 { 255 public: 256 257 void InsertViewFrame( SfxViewFrame* pFrame ) 258 { 259 StartListening( *pFrame ); 260 C40_INSERT( SfxViewFrame, pFrame, Count() ); 261 } 262 void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); 263 }; 264 265 //------------------------------------------------------------------------- 266 void SfxViewNotificatedFrameList_Impl::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) 267 { 268 if ( rHint.IsA(TYPE(SfxSimpleHint)) ) 269 { 270 switch( ( (SfxSimpleHint&) rHint ).GetId() ) 271 { 272 case SFX_HINT_DYING: 273 SfxViewFrame* pFrame = (SfxViewFrame*) &rBC; 274 if( pFrame ) 275 { 276 sal_uInt16 nPos = C40_GETPOS( SfxViewFrame, pFrame ); 277 if( nPos != USHRT_MAX ) 278 Remove( nPos ); 279 } 280 break; 281 } 282 } 283 } 284 285 //------------------------------------------------------------------------- 286 287 long ReloadDecouple_Impl( void* pObj, void* pArg ) 288 { 289 ((SfxViewFrame*) pObj)->ExecReload_Impl( *(SfxRequest*)pArg ); 290 return 0; 291 } 292 293 void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq, sal_Bool bAsync ) 294 { 295 if( bAsync ) 296 { 297 if( !pImp->pReloader ) 298 pImp->pReloader = new svtools::AsynchronLink( 299 Link( this, ReloadDecouple_Impl ) ); 300 pImp->pReloader->Call( new SfxRequest( rReq ) ); 301 } 302 else ExecReload_Impl( rReq ); 303 } 304 305 void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq ) 306 { 307 SfxFrame *pParent = GetFrame().GetParentFrame(); 308 if ( rReq.GetSlot() == SID_RELOAD ) 309 { 310 // Bei CTRL-Reload den aktiven Frame reloaden 311 SfxViewFrame* pActFrame = this; 312 while ( pActFrame ) 313 pActFrame = pActFrame->GetActiveChildFrame_Impl(); 314 315 if ( pActFrame ) 316 { 317 sal_uInt16 nModifier = rReq.GetModifier(); 318 if ( nModifier & KEY_MOD1 ) 319 { 320 pActFrame->ExecReload_Impl( rReq ); 321 return; 322 } 323 } 324 325 // Wenn nur ein Reload der Graphiken eines oder mehrerer ChildFrames 326 // gemacht werden soll 327 SfxFrame& rFrame = GetFrame(); 328 if ( pParent == &rFrame && rFrame.GetChildFrameCount() ) 329 { 330 sal_Bool bReloadAvailable = sal_False; 331 SfxFrameIterator aIter( rFrame, sal_False ); 332 SfxFrame *pChild = aIter.FirstFrame(); 333 while ( pChild ) 334 { 335 SfxFrame *pNext = aIter.NextFrame( *pChild ); 336 SfxObjectShell *pShell = pChild->GetCurrentDocument(); 337 if( pShell && pShell->Get_Impl()->bReloadAvailable ) 338 { 339 bReloadAvailable = sal_True; 340 pChild->GetCurrentViewFrame()->ExecuteSlot( rReq ); 341 } 342 pChild = pNext; 343 } 344 345 // Der TopLevel-Frame selbst het keine Graphiken! 346 if ( bReloadAvailable ) 347 return; 348 } 349 } 350 else 351 { 352 // Bei CTRL-Edit den TopFrame bearbeiten 353 sal_uInt16 nModifier = rReq.GetModifier(); 354 355 if ( ( nModifier & KEY_MOD1 ) && pParent ) 356 { 357 SfxViewFrame *pTop = GetTopViewFrame(); 358 pTop->ExecReload_Impl( rReq ); 359 return; 360 } 361 } 362 363 SfxObjectShell* pSh = GetObjectShell(); 364 switch ( rReq.GetSlot() ) 365 { 366 case SID_EDITDOC: 367 { 368 if ( GetFrame().HasComponent() ) 369 break; 370 371 // Wg. Doppeltbelegung in Toolboxen (mit/ohne Ctrl) ist es auch 372 // m"oglich, da\s der Slot zwar enabled ist, aber Ctrl-Click 373 // trotzdem nicht geht! 374 if( !pSh || !pSh->HasName() || !(pSh->Get_Impl()->nLoadedFlags & SFX_LOADED_MAINDOCUMENT )) 375 break; 376 377 SfxMedium* pMed = pSh->GetMedium(); 378 379 SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_VIEWONLY, sal_False ); 380 if ( pItem && pItem->GetValue() ) 381 { 382 SfxApplication* pApp = SFX_APP(); 383 SfxAllItemSet aSet( pApp->GetPool() ); 384 aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetURLObject().GetMainURL(INetURLObject::NO_DECODE) ) ); 385 aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) ); 386 aSet.Put( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_blank") ) ); 387 SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, sal_False ); 388 if ( pReferer ) 389 aSet.Put( *pReferer ); 390 SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pVersionItem, SfxInt16Item, SID_VERSION, sal_False ); 391 if ( pVersionItem ) 392 aSet.Put( *pVersionItem ); 393 394 if( pMed->GetFilter() ) 395 { 396 aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) ); 397 SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False ); 398 if ( pOptions ) 399 aSet.Put( *pOptions ); 400 } 401 402 GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet ); 403 return; 404 } 405 406 sal_uInt16 nOpenMode; 407 sal_Bool bNeedsReload = sal_False; 408 if ( !pSh->IsReadOnly() ) 409 { 410 // Speichern und Readonly Reloaden 411 if( pSh->IsModified() ) 412 { 413 if ( pSh->PrepareClose() ) 414 { 415 // the storing could let the medium be changed 416 pMed = pSh->GetMedium(); 417 bNeedsReload = sal_True; 418 } 419 else 420 { 421 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_False ) ); 422 return; 423 } 424 } 425 nOpenMode = SFX_STREAM_READONLY; 426 } 427 else 428 { 429 if ( pSh->IsReadOnlyMedium() 430 && ( pSh->GetModifyPasswordHash() || pSh->GetModifyPasswordInfo().getLength() ) 431 && !pSh->IsModifyPasswordEntered() ) 432 { 433 ::rtl::OUString aDocumentName = INetURLObject( pMed->GetOrigURL() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET ); 434 if( !AskPasswordToModify_Impl( pMed->GetInteractionHandler(), aDocumentName, pMed->GetOrigFilter(), pSh->GetModifyPasswordHash(), pSh->GetModifyPasswordInfo() ) ) 435 { 436 // this is a read-only document, if it has "Password to modify" 437 // the user should enter password before he can edit the document 438 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_False ) ); 439 return; 440 } 441 442 pSh->SetModifyPasswordEntered(); 443 } 444 445 nOpenMode = SFX_STREAM_READWRITE; 446 pSh->SetReadOnlyUI( sal_False ); 447 448 // if only the view was in the readonly mode then there is no need to do the reload 449 if ( !pSh->IsReadOnly() ) 450 return; 451 } 452 453 // Parameter auswerten 454 // sal_Bool bReload = sal_True; 455 if ( rReq.IsAPI() ) 456 { 457 // per API steuern ob r/w oder r/o 458 SFX_REQUEST_ARG(rReq, pEditItem, SfxBoolItem, SID_EDITDOC, sal_False); 459 if ( pEditItem ) 460 nOpenMode = pEditItem->GetValue() ? SFX_STREAM_READWRITE : SFX_STREAM_READONLY; 461 } 462 463 // doing 464 465 String aTemp; 466 utl::LocalFileHelper::ConvertPhysicalNameToURL( pMed->GetPhysicalName(), aTemp ); 467 INetURLObject aPhysObj( aTemp ); 468 SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), 469 pVersionItem, SfxInt16Item, SID_VERSION, sal_False ); 470 471 INetURLObject aMedObj( pMed->GetName() ); 472 473 // the logic below is following, if the document seems not to need to be reloaded and the physical name is different 474 // to the logical one, then on file system it can be checked that the copy is still newer than the original and no document reload is required 475 if ( ( !bNeedsReload && ( (aMedObj.GetProtocol() == INET_PROT_FILE && 476 aMedObj.getFSysPath(INetURLObject::FSYS_DETECT) != aPhysObj.getFSysPath(INetURLObject::FSYS_DETECT) && 477 !::utl::UCBContentHelper::IsYounger( aMedObj.GetMainURL( INetURLObject::NO_DECODE ), aPhysObj.GetMainURL( INetURLObject::NO_DECODE ) )) 478 || pMed->IsRemote() ) ) 479 || pVersionItem ) 480 { 481 sal_Bool bOK = sal_False; 482 if ( !pVersionItem ) 483 { 484 sal_Bool bHasStorage = pMed->HasStorage_Impl(); 485 // switching edit mode could be possible without reload 486 if ( bHasStorage && pMed->GetStorage() == pSh->GetStorage() ) 487 { 488 // TODO/LATER: faster creation of copy 489 if ( !pSh->ConnectTmpStorage_Impl( pMed->GetStorage(), pMed ) ) 490 return; 491 } 492 493 pMed->CloseAndRelease(); 494 pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) ); 495 pMed->SetOpenMode( nOpenMode, pMed->IsDirect() ); 496 497 pMed->CompleteReOpen(); 498 if ( nOpenMode & STREAM_WRITE ) 499 pMed->LockOrigFileOnDemand( sal_False, sal_True ); 500 501 // LockOrigFileOnDemand might set the readonly flag itself, it should be set back 502 pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) ); 503 504 if ( !pMed->GetErrorCode() ) 505 bOK = sal_True; 506 } 507 508 if( !bOK ) 509 { 510 ErrCode nErr = pMed->GetErrorCode(); 511 if ( pVersionItem ) 512 nErr = ERRCODE_IO_ACCESSDENIED; 513 else 514 { 515 pMed->ResetError(); 516 pMed->SetOpenMode( SFX_STREAM_READONLY, pMed->IsDirect() ); 517 pMed->ReOpen(); 518 pSh->DoSaveCompleted( pMed ); 519 } 520 521 // r/o-Doc kann nicht in Editmode geschaltet werden? 522 rReq.Done( sal_False ); 523 524 if ( nOpenMode == SFX_STREAM_READWRITE && !rReq.IsAPI() ) 525 { 526 // dem ::com::sun::star::sdbcx::User anbieten, als Vorlage zu oeffnen 527 QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_OPENASTEMPLATE) ); 528 if ( RET_YES == aBox.Execute() ) 529 { 530 SfxApplication* pApp = SFX_APP(); 531 SfxAllItemSet aSet( pApp->GetPool() ); 532 aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) ); 533 SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, sal_False ); 534 if ( pReferer ) 535 aSet.Put( *pReferer ); 536 aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) ); 537 if ( pVersionItem ) 538 aSet.Put( *pVersionItem ); 539 540 if( pMed->GetFilter() ) 541 { 542 aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) ); 543 SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions, 544 SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False ); 545 if ( pOptions ) 546 aSet.Put( *pOptions ); 547 } 548 549 GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet ); 550 return; 551 } 552 else 553 nErr = 0; 554 } 555 556 ErrorHandler::HandleError( nErr ); 557 rReq.SetReturnValue( 558 SfxBoolItem( rReq.GetSlot(), sal_False ) ); 559 return; 560 } 561 else 562 { 563 pSh->DoSaveCompleted( pMed ); 564 pSh->Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) ); 565 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_True ) ); 566 rReq.Done( sal_True ); 567 // if( nOpenMode == SFX_STREAM_READONLY ) 568 // pMed->Close(); 569 return; 570 } 571 } 572 573 rReq.AppendItem( SfxBoolItem( SID_FORCERELOAD, sal_True) ); 574 rReq.AppendItem( SfxBoolItem( SID_SILENT, sal_True )); 575 } 576 577 case SID_RELOAD: 578 { 579 // Wg. Doppeltbelegung in Toolboxen (mit/ohne Ctrl) ist es auch 580 // m"oglich, da\s der Slot zwar enabled ist, aber Ctrl-Click 581 // trotzdem nicht geht! 582 if ( !pSh || !pSh->CanReload_Impl() ) 583 break; 584 SfxApplication* pApp = SFX_APP(); 585 SFX_REQUEST_ARG(rReq, pForceReloadItem, SfxBoolItem, 586 SID_FORCERELOAD, sal_False); 587 if( pForceReloadItem && !pForceReloadItem->GetValue() && 588 !pSh->GetMedium()->IsExpired() ) 589 return; 590 if( pImp->bReloading || pSh->IsInModalMode() ) 591 return; 592 593 // AutoLoad ist ggf. verboten 594 SFX_REQUEST_ARG(rReq, pAutoLoadItem, SfxBoolItem, SID_AUTOLOAD, sal_False); 595 if ( pAutoLoadItem && pAutoLoadItem->GetValue() && 596 GetFrame().IsAutoLoadLocked_Impl() ) 597 return; 598 599 SfxObjectShellLock xOldObj( pSh ); 600 pImp->bReloading = sal_True; 601 SFX_REQUEST_ARG(rReq, pURLItem, SfxStringItem, 602 SID_FILE_NAME, sal_False); 603 // editierbar "offnen? 604 sal_Bool bForEdit = !pSh->IsReadOnly(); 605 if ( rReq.GetSlot() == SID_EDITDOC ) 606 bForEdit = !bForEdit; 607 608 // ggf. beim User nachfragen 609 sal_Bool bDo = ( GetViewShell()->PrepareClose() != sal_False ); 610 SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, sal_False); 611 if ( bDo && GetFrame().DocIsModified_Impl() && 612 !rReq.IsAPI() && ( !pSilentItem || !pSilentItem->GetValue() ) ) 613 { 614 QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_LASTVERSION) ); 615 bDo = ( RET_YES == aBox.Execute() ); 616 } 617 618 if ( bDo ) 619 { 620 SfxMedium *pMedium = xOldObj->GetMedium(); 621 622 // Frameset abziehen, bevor FramesetView evtl. verschwindet 623 String aURL = pURLItem ? pURLItem->GetValue() : 624 pMedium->GetName(); 625 626 sal_Bool bHandsOff = 627 ( pMedium->GetURLObject().GetProtocol() == INET_PROT_FILE && !xOldObj->IsDocShared() ); 628 629 // bestehende SfxMDIFrames f"ur dieses Doc leeren 630 // eigenes Format oder R/O jetzt editierbar "offnen? 631 SfxObjectShellLock xNewObj; 632 633 // collect the views of the document 634 // TODO: when UNO ViewFactories are available for SFX-based documents, the below code should 635 // be UNOized, too 636 typedef ::std::pair< Reference< XFrame >, sal_uInt16 > ViewDescriptor; 637 ::std::list< ViewDescriptor > aViewFrames; 638 SfxViewFrame *pView = GetFirst( xOldObj ); 639 while ( pView ) 640 { 641 Reference< XFrame > xFrame( pView->GetFrame().GetFrameInterface() ); 642 OSL_ENSURE( xFrame.is(), "SfxViewFrame::ExecReload_Impl: no XFrame?!" ); 643 aViewFrames.push_back( ViewDescriptor( xFrame, pView->GetCurViewId() ) ); 644 645 pView = GetNext( *pView, xOldObj ); 646 } 647 648 DELETEZ( xOldObj->Get_Impl()->pReloadTimer ); 649 650 SfxItemSet* pNewSet = 0; 651 const SfxFilter *pFilter = pMedium->GetFilter(); 652 if( pURLItem ) 653 { 654 pNewSet = new SfxAllItemSet( pApp->GetPool() ); 655 pNewSet->Put( *pURLItem ); 656 657 // Filter Detection 658 SfxMedium aMedium( pURLItem->GetValue(), SFX_STREAM_READWRITE ); 659 SfxFilterMatcher().GuessFilter( aMedium, &pFilter ); 660 if ( pFilter ) 661 pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetName() ) ); 662 pNewSet->Put( *aMedium.GetItemSet() ); 663 } 664 else 665 { 666 pNewSet = new SfxAllItemSet( *pMedium->GetItemSet() ); 667 pNewSet->ClearItem( SID_VIEW_ID ); 668 pNewSet->ClearItem( SID_STREAM ); 669 pNewSet->ClearItem( SID_INPUTSTREAM ); 670 pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pMedium->GetFilter()->GetName() ) ); 671 672 // let the current security settings be checked again 673 pNewSet->Put( SfxUInt16Item( SID_MACROEXECMODE, document::MacroExecMode::USE_CONFIG ) ); 674 675 if ( rReq.GetSlot() == SID_EDITDOC || !bForEdit ) 676 // edit mode is switched or reload of readonly document 677 pNewSet->Put( SfxBoolItem( SID_DOC_READONLY, !bForEdit ) ); 678 else 679 // Reload of file opened for writing 680 pNewSet->ClearItem( SID_DOC_READONLY ); 681 } 682 683 // Falls eine salvagede Datei vorliegt, nicht nochmals die 684 // OrigURL mitschicken, denn die Tempdate ist nach Reload 685 // ungueltig 686 SFX_ITEMSET_ARG( pNewSet, pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False); 687 if( pSalvageItem ) 688 { 689 aURL = pSalvageItem->GetValue(); 690 pNewSet->ClearItem( SID_DOC_SALVAGE ); 691 } 692 693 // TODO/LATER: Temporary solution, the SfxMedium must know the original URL as aLogicName 694 // SfxMedium::Transfer_Impl() will be vorbidden then. 695 if ( xOldObj->IsDocShared() ) 696 pNewSet->Put( SfxStringItem( SID_FILE_NAME, xOldObj->GetSharedFileURL() ) ); 697 698 //pNewMedium = new SfxMedium( aURL, nMode, pMedium->IsDirect(), bUseFilter ? pMedium->GetFilter() : 0, pNewSet ); 699 //pNewSet = pNewMedium->GetItemSet(); 700 if ( pURLItem ) 701 pNewSet->Put( SfxStringItem( SID_REFERER, pMedium->GetName() ) ); 702 else 703 pNewSet->Put( SfxStringItem( SID_REFERER, String() ) ); 704 705 xOldObj->CancelTransfers(); 706 707 // eigentliches Reload 708 //pNewSet->Put( SfxFrameItem ( SID_DOCFRAME, GetFrame() ) ); 709 710 if ( pSilentItem && pSilentItem->GetValue() ) 711 pNewSet->Put( SfxBoolItem( SID_SILENT, sal_True ) ); 712 713 SFX_ITEMSET_ARG(pNewSet, pInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False); 714 SFX_ITEMSET_ARG(pNewSet, pMacroExecItem , SfxUInt16Item, SID_MACROEXECMODE , sal_False); 715 SFX_ITEMSET_ARG(pNewSet, pDocTemplateItem, SfxUInt16Item, SID_UPDATEDOCMODE , sal_False); 716 717 if (!pInteractionItem) 718 { 719 Reference < ::com::sun::star::task::XInteractionHandler > xHdl( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.comp.uui.UUIInteractionHandler")), UNO_QUERY ); 720 if (xHdl.is()) 721 pNewSet->Put( SfxUnoAnyItem(SID_INTERACTIONHANDLER,::com::sun::star::uno::makeAny(xHdl)) ); 722 } 723 724 if (!pMacroExecItem) 725 pNewSet->Put( SfxUInt16Item(SID_MACROEXECMODE,::com::sun::star::document::MacroExecMode::USE_CONFIG) ); 726 if (!pDocTemplateItem) 727 pNewSet->Put( SfxUInt16Item(SID_UPDATEDOCMODE,::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG) ); 728 729 xOldObj->SetModified( sal_False ); 730 // Altes Dok nicht cachen! Gilt nicht, wenn anderes 731 // Doc geladen wird. 732 733 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False); 734 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedReferer, SfxStringItem, SID_REFERER, sal_False); 735 736 sal_Bool bHasStorage = pMedium->HasStorage_Impl(); 737 if( bHandsOff ) 738 { 739 if ( bHasStorage && pMedium->GetStorage() == xOldObj->GetStorage() ) 740 { 741 // TODO/LATER: faster creation of copy 742 if ( !xOldObj->ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) ) 743 return; 744 } 745 746 pMedium->CloseAndRelease(); 747 } 748 749 xNewObj = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SFX_CREATE_MODE_STANDARD ); 750 751 if ( xOldObj->IsModifyPasswordEntered() ) 752 xNewObj->SetModifyPasswordEntered(); 753 754 uno::Sequence < beans::PropertyValue > aLoadArgs; 755 TransformItems( SID_OPENDOC, *pNewSet, aLoadArgs ); 756 try 757 { 758 uno::Reference < frame::XLoadable > xLoad( xNewObj->GetModel(), uno::UNO_QUERY ); 759 xLoad->load( aLoadArgs ); 760 } 761 catch ( uno::Exception& ) 762 { 763 xNewObj->DoClose(); 764 xNewObj = 0; 765 } 766 767 DELETEZ( pNewSet ); 768 769 if( !xNewObj.Is() ) 770 { 771 if( bHandsOff ) 772 { 773 // back to old medium 774 pMedium->ReOpen(); 775 pMedium->LockOrigFileOnDemand( sal_False, sal_True ); 776 777 xOldObj->DoSaveCompleted( pMedium ); 778 } 779 780 // r/o-Doc couldn't be switched to writing mode 781 if ( bForEdit && SID_EDITDOC == rReq.GetSlot() ) 782 { 783 // ask user for opening as template 784 QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_OPENASTEMPLATE) ); 785 if ( RET_YES == aBox.Execute() ) 786 { 787 SfxAllItemSet aSet( pApp->GetPool() ); 788 aSet.Put( SfxStringItem( SID_FILE_NAME, pMedium->GetName() ) ); 789 aSet.Put( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_blank") ) ); 790 if ( pSavedOptions ) 791 aSet.Put( *pSavedOptions ); 792 if ( pSavedReferer ) 793 aSet.Put( *pSavedReferer ); 794 aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) ); 795 if( pFilter ) 796 aSet.Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetFilterName() ) ); 797 GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet ); 798 } 799 } 800 else 801 { 802 // an error handling should be done here?! 803 // if ( !pSilentItem || !pSilentItem->GetValue() ) 804 // ErrorHandler::HandleError( nLoadError ); 805 } 806 } 807 else 808 { 809 if ( xNewObj->GetModifyPasswordHash() && xNewObj->GetModifyPasswordHash() != xOldObj->GetModifyPasswordHash() ) 810 { 811 xNewObj->SetModifyPasswordEntered( sal_False ); 812 xNewObj->SetReadOnly(); 813 } 814 else if ( rReq.GetSlot() == SID_EDITDOC && bForEdit && !xNewObj->IsReadOnlyMedium() ) 815 { 816 // the filter might request setting of the document to readonly state 817 // but in case of SID_EDITDOC it should not happen if the document 818 // can be opened for editing 819 xNewObj->SetReadOnlyUI( sal_False ); 820 } 821 822 if ( xNewObj->IsDocShared() ) 823 { 824 // the file is shared but the closing can change the sharing control file 825 xOldObj->DoNotCleanShareControlFile(); 826 } 827 828 // the Reload and Silent items were only temporary, remove them 829 xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_RELOAD ); 830 xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_SILENT ); 831 TransformItems( SID_OPENDOC, *xNewObj->GetMedium()->GetItemSet(), aLoadArgs ); 832 833 UpdateDocument_Impl(); 834 835 try 836 { 837 while ( !aViewFrames.empty() ) 838 { 839 LoadViewIntoFrame_Impl( *xNewObj, aViewFrames.front().first, aLoadArgs, aViewFrames.front().second, false ); 840 aViewFrames.pop_front(); 841 } 842 } 843 catch( const Exception& ) 844 { 845 // close the remaining frames 846 // Don't catch exceptions herein, if this fails, then we're left in an indetermined state, and 847 // crashing is better than trying to proceed 848 while ( !aViewFrames.empty() ) 849 { 850 Reference< util::XCloseable > xClose( aViewFrames.front().first, UNO_QUERY_THROW ); 851 xClose->close( sal_True ); 852 aViewFrames.pop_front(); 853 } 854 } 855 856 // Propagate document closure. 857 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_CLOSEDOC, GlobalEventConfig::GetEventName( STR_EVENT_CLOSEDOC ), xOldObj ) ); 858 } 859 860 // als erledigt recorden 861 rReq.Done( sal_True ); 862 rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), sal_True)); 863 return; 864 } 865 else 866 { 867 // als nicht erledigt recorden 868 rReq.Done(); 869 rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), sal_False)); 870 pImp->bReloading = sal_False; 871 return; 872 } 873 } 874 } 875 } 876 877 //------------------------------------------------------------------------- 878 void SfxViewFrame::StateReload_Impl( SfxItemSet& rSet ) 879 { 880 SfxObjectShell* pSh = GetObjectShell(); 881 if ( !pSh ) 882 // Ich bin gerade am Reloaden und Yielde so vor mich hin ... 883 return; 884 885 GetFrame().GetParentFrame(); 886 SfxWhichIter aIter( rSet ); 887 for ( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich() ) 888 { 889 if ( GetFrame().HasComponent() ) 890 { 891 // Wenn die Komponente es nicht selbst dispatched, dann 892 // macht es auch keinen Sinn! 893 rSet.DisableItem( nWhich ); 894 continue; 895 } 896 897 switch ( nWhich ) 898 { 899 case SID_EDITDOC: 900 { 901 if ( !pSh || !pSh->HasName() || !( pSh->Get_Impl()->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) 902 || pSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) 903 rSet.DisableItem( SID_EDITDOC ); 904 else 905 { 906 SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_EDITDOC, sal_False ); 907 if ( pItem && !pItem->GetValue() ) 908 rSet.DisableItem( SID_EDITDOC ); 909 else 910 rSet.Put( SfxBoolItem( nWhich, !pSh->IsReadOnly() ) ); 911 } 912 break; 913 } 914 915 case SID_RELOAD: 916 { 917 SfxFrame* pFrame = &GetTopFrame(); 918 919 if ( !pSh || !pSh->CanReload_Impl() || pSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) 920 rSet.DisableItem(nWhich); 921 else 922 { 923 // Wenn irgendein ChildFrame reloadable ist, wird der Slot 924 // enabled, damit man CTRL-Reload machen kann 925 sal_Bool bReloadAvailable = sal_False; 926 SfxFrameIterator aFrameIter( *pFrame, sal_True ); 927 for( SfxFrame* pNextFrame = aFrameIter.FirstFrame(); 928 pFrame; 929 pNextFrame = pNextFrame ? 930 aFrameIter.NextFrame( *pNextFrame ) : 0 ) 931 { 932 SfxObjectShell *pShell = pFrame->GetCurrentDocument(); 933 if( pShell && pShell->Get_Impl()->bReloadAvailable ) 934 { 935 bReloadAvailable = sal_True; 936 break; 937 } 938 pFrame = pNextFrame; 939 } 940 941 rSet.Put( SfxBoolItem( nWhich, bReloadAvailable)); 942 } 943 944 break; 945 } 946 } 947 } 948 } 949 950 951 //-------------------------------------------------------------------- 952 void SfxViewFrame::ExecHistory_Impl( SfxRequest &rReq ) 953 { 954 // gibt es an der obersten Shell einen Undo-Manager? 955 SfxShell *pSh = GetDispatcher()->GetShell(0); 956 ::svl::IUndoManager* pShUndoMgr = pSh->GetUndoManager(); 957 sal_Bool bOK = sal_False; 958 if ( pShUndoMgr ) 959 { 960 switch ( rReq.GetSlot() ) 961 { 962 case SID_CLEARHISTORY: 963 pShUndoMgr->Clear(); 964 bOK = sal_True; 965 break; 966 967 case SID_UNDO: 968 pShUndoMgr->Undo(); 969 GetBindings().InvalidateAll(sal_False); 970 bOK = sal_True; 971 break; 972 973 case SID_REDO: 974 pShUndoMgr->Redo(); 975 GetBindings().InvalidateAll(sal_False); 976 bOK = sal_True; 977 break; 978 979 case SID_REPEAT: 980 if ( pSh->GetRepeatTarget() ) 981 pShUndoMgr->Repeat( *pSh->GetRepeatTarget() ); 982 bOK = sal_True; 983 break; 984 } 985 } 986 else if ( GetViewShell() ) 987 { 988 // der SW hat eigenes Undo an der View 989 const SfxPoolItem *pRet = GetViewShell()->ExecuteSlot( rReq ); 990 if ( pRet ) 991 bOK = ((SfxBoolItem*)pRet)->GetValue(); 992 } 993 994 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bOK ) ); 995 rReq.Done(); 996 } 997 998 //-------------------------------------------------------------------- 999 void SfxViewFrame::StateHistory_Impl( SfxItemSet &rSet ) 1000 { 1001 // Undo-Manager suchen 1002 SfxShell *pSh = GetDispatcher()->GetShell(0); 1003 if ( !pSh ) 1004 // Ich bin gerade am Reloaden und Yielde so vor mich hin ... 1005 return; 1006 1007 ::svl::IUndoManager *pShUndoMgr = pSh->GetUndoManager(); 1008 if ( !pShUndoMgr ) 1009 { 1010 // der SW hat eigenes Undo an der View 1011 SfxWhichIter aIter( rSet ); 1012 SfxViewShell *pViewSh = GetViewShell(); 1013 if( !pViewSh ) return; 1014 for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() ) 1015 pViewSh->GetSlotState( nSID, 0, &rSet ); 1016 return; 1017 } 1018 1019 if ( pShUndoMgr->GetUndoActionCount() == 0 && 1020 pShUndoMgr->GetRedoActionCount() == 0 && 1021 pShUndoMgr->GetRepeatActionCount() == 0 ) 1022 rSet.DisableItem( SID_CLEARHISTORY ); 1023 1024 if ( pShUndoMgr && pShUndoMgr->GetUndoActionCount() ) 1025 { 1026 String aTmp( SvtResId( STR_UNDO ) ); 1027 aTmp+= pShUndoMgr->GetUndoActionComment(0); 1028 rSet.Put( SfxStringItem( SID_UNDO, aTmp ) ); 1029 } 1030 else 1031 rSet.DisableItem( SID_UNDO ); 1032 1033 if ( pShUndoMgr && pShUndoMgr->GetRedoActionCount() ) 1034 { 1035 String aTmp( SvtResId(STR_REDO) ); 1036 aTmp += pShUndoMgr->GetRedoActionComment(0); 1037 rSet.Put( SfxStringItem( SID_REDO, aTmp ) ); 1038 } 1039 else 1040 rSet.DisableItem( SID_REDO ); 1041 SfxRepeatTarget *pTarget = pSh->GetRepeatTarget(); 1042 if ( pShUndoMgr && pTarget && pShUndoMgr->GetRepeatActionCount() && 1043 pShUndoMgr->CanRepeat(*pTarget) ) 1044 { 1045 String aTmp( SvtResId(STR_REPEAT) ); 1046 aTmp += pShUndoMgr->GetRepeatActionComment(*pTarget); 1047 rSet.Put( SfxStringItem( SID_REPEAT, aTmp ) ); 1048 } 1049 else 1050 rSet.DisableItem( SID_REPEAT ); 1051 } 1052 1053 //-------------------------------------------------------------------- 1054 void SfxViewFrame::PopShellAndSubShells_Impl( SfxViewShell& i_rViewShell ) 1055 { 1056 i_rViewShell.PopSubShells_Impl(); 1057 sal_uInt16 nLevel = pDispatcher->GetShellLevel( i_rViewShell ); 1058 if ( nLevel != USHRT_MAX ) 1059 { 1060 if ( nLevel ) 1061 { 1062 // more sub shells on the stack, which were not affected by PopSubShells_Impl 1063 SfxShell *pSubShell = pDispatcher->GetShell( nLevel-1 ); 1064 if ( pSubShell == i_rViewShell.GetSubShell() ) 1065 // "real" sub shells will be deleted elsewhere 1066 pDispatcher->Pop( *pSubShell, SFX_SHELL_POP_UNTIL ); 1067 else 1068 pDispatcher->Pop( *pSubShell, SFX_SHELL_POP_UNTIL | SFX_SHELL_POP_DELETE ); 1069 } 1070 pDispatcher->Pop( i_rViewShell ); 1071 pDispatcher->Flush(); 1072 } 1073 1074 } 1075 1076 //-------------------------------------------------------------------- 1077 void SfxViewFrame::ReleaseObjectShell_Impl() 1078 1079 /* [Beschreibung] 1080 1081 Diese Methode entleert den SfxViewFrame, d.h. nimmt die <SfxObjectShell> 1082 vom Dispatcher und beendet seine <SfxListener>-Beziehung zu dieser 1083 SfxObjectShell (wodurch sie sich ggf. selbst zerst"ort). 1084 1085 Somit kann durch Aufruf von ReleaseObjectShell() und SetObjectShell() 1086 die SfxObjectShell ausgetauscht werden. 1087 1088 Zwischen RealeaseObjectShell() und SetObjectShell() darf die Kontrolle 1089 nicht an das System abgegeben werden. 1090 1091 1092 [Querverweise] 1093 1094 <SfxViewFrame::SetObjectShell(SfxObjectShell&)> 1095 */ 1096 { 1097 DBG_CHKTHIS(SfxViewFrame, 0); 1098 DBG_ASSERT( xObjSh.Is(), "no SfxObjectShell to release!" ); 1099 1100 GetFrame().ReleasingComponent_Impl( sal_True ); 1101 if ( GetWindow().HasChildPathFocus( sal_True ) ) 1102 { 1103 DBG_ASSERT( !GetActiveChildFrame_Impl(), "Wrong active child frame!" ); 1104 GetWindow().GrabFocus(); 1105 } 1106 1107 SfxViewShell *pDyingViewSh = GetViewShell(); 1108 if ( pDyingViewSh ) 1109 { 1110 PopShellAndSubShells_Impl( *pDyingViewSh ); 1111 pDyingViewSh->DisconnectAllClients(); 1112 SetViewShell_Impl(0); 1113 delete pDyingViewSh; 1114 } 1115 #ifdef DBG_UTIL 1116 else 1117 DBG_ERROR("Keine Shell"); 1118 #endif 1119 1120 if ( xObjSh.Is() ) 1121 { 1122 pImp->aLastType = xObjSh->Type(); 1123 pDispatcher->Pop( *xObjSh ); 1124 SfxModule* pModule = xObjSh->GetModule(); 1125 if( pModule ) 1126 pDispatcher->RemoveShell_Impl( *pModule ); 1127 pDispatcher->Flush(); 1128 EndListening( *xObjSh ); 1129 1130 Notify( *xObjSh, SfxSimpleHint(SFX_HINT_TITLECHANGED) ); 1131 Notify( *xObjSh, SfxSimpleHint(SFX_HINT_DOCCHANGED) ); 1132 1133 if ( 1 == xObjSh->GetOwnerLockCount() && pImp->bObjLocked && xObjSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) 1134 xObjSh->DoClose(); 1135 SfxObjectShellRef xDyingObjSh = xObjSh; 1136 xObjSh.Clear(); 1137 if( ( GetFrameType() & SFXFRAME_HASTITLE ) && pImp->nDocViewNo ) 1138 xDyingObjSh->GetNoSet_Impl().ReleaseIndex(pImp->nDocViewNo-1); 1139 if ( pImp->bObjLocked ) 1140 { 1141 xDyingObjSh->OwnerLock( sal_False ); 1142 pImp->bObjLocked = sal_False; 1143 } 1144 } 1145 1146 GetDispatcher()->SetDisableFlags( 0 ); 1147 } 1148 1149 //-------------------------------------------------------------------- 1150 sal_Bool SfxViewFrame::Close() 1151 { 1152 DBG_CHKTHIS(SfxViewFrame, 0); 1153 1154 DBG_ASSERT( GetFrame().IsClosing_Impl() || !GetFrame().GetFrameInterface().is(), "ViewFrame closed too early!" ); 1155 1156 // Wenn bis jetzt noch nicht gespeichert wurde, sollen eingebettete Objekte 1157 // auch nicht mehr automatisch gespeichert werden! 1158 if ( GetViewShell() ) 1159 GetViewShell()->DiscardClients_Impl(); 1160 Broadcast( SfxSimpleHint( SFX_HINT_DYING ) ); 1161 1162 if (SfxViewFrame::Current() == this) 1163 SfxViewFrame::SetViewFrame( NULL ); 1164 1165 // Da der Dispatcher leer ger"aumt wird, kann man ihn auch nicht mehr 1166 // vern"unftig verwenden - also besser still legen 1167 GetDispatcher()->Lock(sal_True); 1168 delete this; 1169 1170 return sal_True; 1171 } 1172 1173 //-------------------------------------------------------------------- 1174 1175 void SfxViewFrame::DoActivate( sal_Bool bUI, SfxViewFrame* pOldFrame ) 1176 { 1177 DBG_CHKTHIS(SfxViewFrame, 0); 1178 SFX_APP(); 1179 1180 pDispatcher->DoActivate_Impl( bUI, pOldFrame ); 1181 1182 // Wenn ich einen parent habe und dieser ist kein parent des alten 1183 // ViewFrames, erh"alt er ein ParentActivate 1184 if ( bUI ) 1185 { 1186 /* 1187 SfxMedium* pMed = GetObjectShell() ? GetObjectShell()->GetMedium() : NULL; 1188 if( pMed ) 1189 { 1190 SFX_ITEMSET_ARG( 1191 pMed->GetItemSet(), pInterceptorItem, SfxSlotInterceptorItem, 1192 SID_INTERCEPTOR, sal_False ); 1193 if( pInterceptorItem ) 1194 { 1195 SfxSlotInterceptor* pInter = pInterceptorItem->GetValue(); 1196 if( !pInter->GetBindings() ) 1197 pInter->SetBindings( &GetBindings() ); 1198 pInter->Activate( sal_True ); 1199 } 1200 } 1201 */ 1202 SfxViewFrame *pFrame = GetParentViewFrame(); 1203 while ( pFrame ) 1204 { 1205 if ( !pOldFrame || !pOldFrame->GetFrame().IsParent( &pFrame->GetFrame() ) ) 1206 pFrame->pDispatcher->DoParentActivate_Impl(); 1207 pFrame = pFrame->GetParentViewFrame(); 1208 } 1209 } 1210 } 1211 1212 //-------------------------------------------------------------------- 1213 void SfxViewFrame::DoDeactivate(sal_Bool bUI, SfxViewFrame* pNewFrame ) 1214 { 1215 DBG_CHKTHIS(SfxViewFrame, 0); 1216 SFX_APP(); 1217 pDispatcher->DoDeactivate_Impl( bUI, pNewFrame ); 1218 1219 // Wenn ich einen parent habe und dieser ist kein parent des neuen 1220 // ViewFrames, erh"alt er ein ParentDeactivate 1221 if ( bUI ) 1222 { 1223 // if ( GetFrame().GetWorkWindow_Impl() ) 1224 // GetFrame().GetWorkWindow_Impl()->SaveStatus_Impl(); 1225 /* 1226 SfxMedium* pMed = GetObjectShell() ? GetObjectShell()->GetMedium() : NULL; 1227 if( pMed ) 1228 { 1229 SFX_ITEMSET_ARG( 1230 pMed->GetItemSet(), pInterceptorItem, SfxSlotInterceptorItem, 1231 SID_INTERCEPTOR, sal_False ); 1232 if( pInterceptorItem ) 1233 pInterceptorItem->GetValue()->Activate( sal_False ); 1234 } 1235 */ 1236 SfxViewFrame *pFrame = GetParentViewFrame(); 1237 while ( pFrame ) 1238 { 1239 if ( !pNewFrame || !pNewFrame->GetFrame().IsParent( &pFrame->GetFrame() ) ) 1240 pFrame->pDispatcher->DoParentDeactivate_Impl(); 1241 pFrame = pFrame->GetParentViewFrame(); 1242 } 1243 } 1244 } 1245 1246 //------------------------------------------------------------------------ 1247 void SfxViewFrame::InvalidateBorderImpl( const SfxViewShell* pSh ) 1248 { 1249 if( pSh && !nAdjustPosPixelLock ) 1250 { 1251 if ( GetViewShell() && GetWindow().IsVisible() ) 1252 { 1253 if ( GetFrame().IsInPlace() ) 1254 { 1255 /* 1256 Size aSize( GetViewShell()->GetWindow()->GetSizePixel() ); 1257 1258 //Size aBorderSz( pEnv->GetBorderWin()->GetHatchBorderPixel() ); 1259 Point aOfs; //( aBorderSz.Width(), aBorderSz.Height() ); 1260 1261 DoAdjustPosSizePixel( GetViewShell(), aOfs, aSize );*/ 1262 return; 1263 } 1264 1265 DoAdjustPosSizePixel( (SfxViewShell *) GetViewShell(), Point(), 1266 GetWindow().GetOutputSizePixel() ); 1267 } 1268 } 1269 } 1270 1271 //------------------------------------------------------------------------ 1272 sal_Bool SfxViewFrame::SetBorderPixelImpl 1273 ( 1274 const SfxViewShell* pVSh, 1275 const SvBorder& rBorder 1276 ) 1277 1278 { 1279 pImp->aBorder = rBorder; 1280 1281 if ( IsResizeInToOut_Impl() && !GetFrame().IsInPlace() ) 1282 { 1283 Size aSize = pVSh->GetWindow()->GetOutputSizePixel(); 1284 if ( aSize.Width() && aSize.Height() ) 1285 { 1286 aSize.Width() += rBorder.Left() + rBorder.Right(); 1287 aSize.Height() += rBorder.Top() + rBorder.Bottom(); 1288 1289 Size aOldSize = GetWindow().GetOutputSizePixel(); 1290 GetWindow().SetOutputSizePixel( aSize ); 1291 Window* pParent = &GetWindow(); 1292 while ( pParent->GetParent() ) 1293 pParent = pParent->GetParent(); 1294 Size aOuterSize = pParent->GetOutputSizePixel(); 1295 aOuterSize.Width() += ( aSize.Width() - aOldSize.Width() ); 1296 aOuterSize.Height() += ( aSize.Height() - aOldSize.Height() ); 1297 pParent->SetOutputSizePixel( aOuterSize ); 1298 } 1299 } 1300 else 1301 { 1302 Point aPoint; 1303 Rectangle aEditArea( aPoint, GetWindow().GetOutputSizePixel() ); 1304 aEditArea.Left() += rBorder.Left(); 1305 aEditArea.Right() -= rBorder.Right(); 1306 aEditArea.Top() += rBorder.Top(); 1307 aEditArea.Bottom() -= rBorder.Bottom(); 1308 pVSh->GetWindow()->SetPosSizePixel( aEditArea.TopLeft(), aEditArea.GetSize() ); 1309 } 1310 1311 return sal_True; 1312 } 1313 1314 //------------------------------------------------------------------------ 1315 const SvBorder& SfxViewFrame::GetBorderPixelImpl 1316 ( 1317 const SfxViewShell* /*pSh*/ 1318 ) const 1319 1320 { 1321 return pImp->aBorder; 1322 } 1323 1324 //-------------------------------------------------------------------- 1325 void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) 1326 { 1327 {DBG_CHKTHIS(SfxViewFrame, 0);} 1328 1329 if( IsDowning_Impl()) 1330 return; 1331 1332 // we know only SimpleHints 1333 if ( rHint.IsA(TYPE(SfxSimpleHint)) ) 1334 { 1335 switch( ( (SfxSimpleHint&) rHint ).GetId() ) 1336 { 1337 case SFX_HINT_MODECHANGED: 1338 { 1339 UpdateTitle(); 1340 1341 if ( !xObjSh.Is() ) 1342 break; 1343 1344 // r/o Umschaltung? 1345 SfxBindings& rBind = GetBindings(); 1346 rBind.Invalidate( SID_RELOAD ); 1347 SfxDispatcher *pDispat = GetDispatcher(); 1348 sal_Bool bWasReadOnly = pDispat->GetReadOnly_Impl(); 1349 sal_Bool bIsReadOnly = xObjSh->IsReadOnly(); 1350 if ( !bWasReadOnly != !bIsReadOnly ) 1351 { 1352 // Dann auch TITLE_CHANGED 1353 UpdateTitle(); 1354 rBind.Invalidate( SID_FILE_NAME ); 1355 rBind.Invalidate( SID_DOCINFO_TITLE ); 1356 rBind.Invalidate( SID_EDITDOC ); 1357 1358 pDispat->GetBindings()->InvalidateAll(sal_True); 1359 pDispat->SetReadOnly_Impl( bIsReadOnly ); 1360 1361 // Dispatcher-Update nur erzwingen, wenn es nicht sowieso 1362 // demn"achst kommt, anderenfalls ist Zappelei oder gar 1363 // GPF m"oglich, da Writer z.B. gerne mal im Resize irgendwelche 1364 // Aktionen t"atigt, die ein SetReadOnlyUI am Dispatcher zur 1365 // Folge haben! 1366 if ( pDispat->IsUpdated_Impl() ) 1367 pDispat->Update_Impl(sal_True); 1368 } 1369 1370 Enable( !xObjSh->IsInModalMode() ); 1371 break; 1372 } 1373 1374 case SFX_HINT_TITLECHANGED: 1375 { 1376 UpdateTitle(); 1377 SfxBindings& rBind = GetBindings(); 1378 rBind.Invalidate( SID_FILE_NAME ); 1379 rBind.Invalidate( SID_DOCINFO_TITLE ); 1380 rBind.Invalidate( SID_EDITDOC ); 1381 rBind.Invalidate( SID_RELOAD ); 1382 break; 1383 } 1384 1385 case SFX_HINT_DEINITIALIZING: 1386 GetFrame().DoClose(); 1387 break; 1388 case SFX_HINT_DYING: 1389 // when the Object is being deleted, destroy the view too 1390 if ( xObjSh.Is() ) 1391 ReleaseObjectShell_Impl(); 1392 else 1393 GetFrame().DoClose(); 1394 break; 1395 1396 } 1397 } 1398 else if ( rHint.IsA(TYPE(SfxEventHint)) ) 1399 { 1400 // Wenn das Document asynchron geladen wurde, wurde der Dispatcher 1401 // auf ReadOnly gesetzt, was zur"?ckgenommen werden mu\s, wenn 1402 // das Document selbst nicht ReadOnly ist und das Laden fertig ist. 1403 switch ( ((SfxEventHint&)rHint).GetEventId() ) 1404 { 1405 case SFX_EVENT_MODIFYCHANGED: 1406 { 1407 SfxBindings& rBind = GetBindings(); 1408 rBind.Invalidate( SID_DOC_MODIFIED ); 1409 rBind.Invalidate( SID_SAVEDOC ); 1410 rBind.Invalidate( SID_RELOAD ); 1411 rBind.Invalidate( SID_EDITDOC ); 1412 break; 1413 } 1414 1415 case SFX_EVENT_OPENDOC: 1416 case SFX_EVENT_CREATEDOC: 1417 { 1418 if ( !xObjSh.Is() ) 1419 break; 1420 1421 SfxBindings& rBind = GetBindings(); 1422 rBind.Invalidate( SID_RELOAD ); 1423 rBind.Invalidate( SID_EDITDOC ); 1424 if ( !xObjSh->IsReadOnly() ) 1425 { 1426 // Im Gegensatz zu oben (TITLE_CHANGED) mu\s das UI nicht 1427 // upgedated werden, da es nicht gehidet war! 1428 1429 // #i21560# InvalidateAll() causes the assertion 1430 // 'SfxBindings::Invalidate while in update" when 1431 // the sfx slot SID_BASICIDE_APPEAR is executed 1432 // via API from another thread (Java). 1433 // According to MBA this call is not necessary anymore, 1434 // because each document has its own SfxBindings. 1435 // 1436 //GetDispatcher()->GetBindings()->InvalidateAll(sal_True); 1437 } 1438 1439 break; 1440 } 1441 1442 case SFX_EVENT_TOGGLEFULLSCREENMODE: 1443 { 1444 if ( GetFrame().OwnsBindings_Impl() ) 1445 GetBindings().GetDispatcher_Impl()->Update_Impl( sal_True ); 1446 break; 1447 } 1448 } 1449 } 1450 } 1451 1452 //------------------------------------------------------------------------ 1453 void SfxViewFrame::Construct_Impl( SfxObjectShell *pObjSh ) 1454 { 1455 pImp->bResizeInToOut = sal_True; 1456 pImp->bDontOverwriteResizeInToOut = sal_False; 1457 pImp->bObjLocked = sal_False; 1458 pImp->pFocusWin = 0; 1459 pImp->pActiveChild = NULL; 1460 pImp->nCurViewId = 0; 1461 pImp->bReloading = sal_False; 1462 pImp->bIsDowning = sal_False; 1463 pImp->bModal = sal_False; 1464 pImp->bEnabled = sal_True; 1465 pImp->nDocViewNo = 0; 1466 pImp->aMargin = Size( -1, -1 ); 1467 pImp->pWindow = 0; 1468 1469 SetPool( &SFX_APP()->GetPool() ); 1470 pDispatcher = new SfxDispatcher(this); 1471 if ( !GetBindings().GetDispatcher() ) 1472 GetBindings().SetDispatcher( pDispatcher ); 1473 1474 xObjSh = pObjSh; 1475 if ( xObjSh.Is() && xObjSh->IsPreview() ) 1476 SetQuietMode_Impl( sal_True ); 1477 1478 if ( pObjSh ) 1479 { 1480 pDispatcher->Push( *SFX_APP() ); 1481 SfxModule* pModule = xObjSh->GetModule(); 1482 if( pModule ) 1483 pDispatcher->Push( *pModule ); 1484 pDispatcher->Push( *this ); 1485 pDispatcher->Push( *pObjSh ); 1486 pDispatcher->Flush(); 1487 StartListening( *pObjSh ); 1488 pObjSh->ViewAssigned(); 1489 Notify( *pObjSh, SfxSimpleHint(SFX_HINT_TITLECHANGED) ); 1490 Notify( *pObjSh, SfxSimpleHint(SFX_HINT_DOCCHANGED) ); 1491 pDispatcher->SetReadOnly_Impl( pObjSh->IsReadOnly() ); 1492 } 1493 else 1494 { 1495 pDispatcher->Push( *SFX_APP() ); 1496 pDispatcher->Push( *this ); 1497 pDispatcher->Flush(); 1498 } 1499 1500 SfxViewFrame *pThis = this; // wegen der kranken Array-Syntax 1501 SfxViewFrameArr_Impl &rViewArr = SFX_APP()->GetViewFrames_Impl(); 1502 rViewArr.C40_INSERT(SfxViewFrame, pThis, rViewArr.Count() ); 1503 } 1504 1505 SfxViewFrame::SfxViewFrame 1506 ( 1507 SfxFrame& rFrame, 1508 SfxObjectShell* pObjShell 1509 ) 1510 1511 /* [Beschreibung] 1512 1513 Ctor des SfxViewFrame f"ur eine <SfxObjectShell> aus der Ressource. 1514 Die 'nViewId' der zu erzeugenden <SfxViewShell> kann angegeben werden 1515 (default ist die zuerst registrierte SfxViewShell-Subklasse). 1516 */ 1517 1518 : pImp( new SfxViewFrame_Impl( rFrame ) ) 1519 , pDispatcher(0) 1520 , pBindings( new SfxBindings ) 1521 , nAdjustPosPixelLock( 0 ) 1522 { 1523 DBG_CTOR( SfxViewFrame, NULL ); 1524 1525 rFrame.SetCurrentViewFrame_Impl( this ); 1526 rFrame.SetFrameType_Impl( GetFrameType() | SFXFRAME_HASTITLE ); 1527 Construct_Impl( pObjShell ); 1528 1529 pImp->pWindow = new SfxFrameViewWindow_Impl( this, rFrame.GetWindow() ); 1530 pImp->pWindow->SetSizePixel( rFrame.GetWindow().GetOutputSizePixel() ); 1531 rFrame.SetOwnsBindings_Impl( sal_True ); 1532 rFrame.CreateWorkWindow_Impl(); 1533 } 1534 1535 //------------------------------------------------------------------------ 1536 SfxViewFrame::~SfxViewFrame() 1537 { 1538 DBG_DTOR(SfxViewFrame, 0); 1539 1540 SetDowning_Impl(); 1541 1542 if ( SfxViewFrame::Current() == this ) 1543 SfxViewFrame::SetViewFrame( NULL ); 1544 1545 ReleaseObjectShell_Impl(); 1546 1547 if ( GetFrame().OwnsBindings_Impl() ) 1548 // Die Bindings l"oscht der Frame! 1549 KillDispatcher_Impl(); 1550 1551 delete pImp->pWindow; 1552 1553 if ( GetFrame().GetCurrentViewFrame() == this ) 1554 GetFrame().SetCurrentViewFrame_Impl( NULL ); 1555 1556 // von Frame-Liste abmelden 1557 SfxApplication *pSfxApp = SFX_APP(); 1558 SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl(); 1559 const SfxViewFrame *pThis = this; 1560 rFrames.Remove( rFrames.GetPos(pThis) ); 1561 1562 // Member l"oschen 1563 KillDispatcher_Impl(); 1564 1565 delete pImp; 1566 } 1567 1568 //------------------------------------------------------------------------ 1569 void SfxViewFrame::KillDispatcher_Impl() 1570 1571 // Dispatcher abr"aumen und l"oschen 1572 1573 { 1574 DBG_CHKTHIS(SfxViewFrame, 0); 1575 1576 SfxModule* pModule = xObjSh.Is() ? xObjSh->GetModule() : 0; 1577 if ( xObjSh.Is() ) 1578 ReleaseObjectShell_Impl(); 1579 if ( pDispatcher ) 1580 { 1581 if( pModule ) 1582 pDispatcher->Pop( *pModule, SFX_SHELL_POP_UNTIL ); 1583 else 1584 pDispatcher->Pop( *this ); 1585 DELETEZ(pDispatcher); 1586 } 1587 } 1588 1589 //------------------------------------------------------------------------ 1590 SfxViewFrame* SfxViewFrame::Current() 1591 { 1592 return SfxApplication::Get() ? SFX_APP()->Get_Impl()->pViewFrame : NULL; 1593 } 1594 1595 //-------------------------------------------------------------------- 1596 sal_uInt16 SfxViewFrame::Count() 1597 1598 /* [Beschreibung] 1599 1600 Liefert die Anzahl der sichtbaren <SfxViewFrame>-Instanzen. 1601 */ 1602 1603 { 1604 SfxApplication *pSfxApp = SFX_APP(); 1605 SfxViewFrameArr_Impl& rFrames = pSfxApp->GetViewFrames_Impl(); 1606 const sal_uInt16 nCount = rFrames.Count(); 1607 sal_uInt16 nFound = 0; 1608 for ( sal_uInt16 i = 0; i < nCount; ++i ) 1609 { 1610 SfxViewFrame *pFrame = rFrames[i]; 1611 if ( pFrame->IsVisible() ) 1612 ++nFound; 1613 } 1614 return nFound; 1615 } 1616 1617 //-------------------------------------------------------------------- 1618 // returns the first window of spec. type viewing the specified doc. 1619 SfxViewFrame* SfxViewFrame::GetFirst 1620 ( 1621 const SfxObjectShell* pDoc, 1622 sal_Bool bOnlyIfVisible 1623 ) 1624 { 1625 SfxApplication *pSfxApp = SFX_APP(); 1626 SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl(); 1627 1628 // search for a SfxDocument of the specified type 1629 for ( sal_uInt16 nPos = 0; nPos < rFrames.Count(); ++nPos ) 1630 { 1631 SfxViewFrame *pFrame = rFrames.GetObject(nPos); 1632 if ( ( !pDoc || pDoc == pFrame->GetObjectShell() ) 1633 && ( !bOnlyIfVisible || pFrame->IsVisible() ) 1634 ) 1635 return pFrame; 1636 } 1637 1638 return 0; 1639 } 1640 //-------------------------------------------------------------------- 1641 1642 // returns thenext window of spec. type viewing the specified doc. 1643 SfxViewFrame* SfxViewFrame::GetNext 1644 ( 1645 const SfxViewFrame& rPrev, 1646 const SfxObjectShell* pDoc, 1647 sal_Bool bOnlyIfVisible 1648 ) 1649 { 1650 SfxApplication *pSfxApp = SFX_APP(); 1651 SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl(); 1652 1653 // refind the specified predecessor 1654 sal_uInt16 nPos; 1655 for ( nPos = 0; nPos < rFrames.Count(); ++nPos ) 1656 if ( rFrames.GetObject(nPos) == &rPrev ) 1657 break; 1658 1659 // search for a Frame of the specified type 1660 for ( ++nPos; nPos < rFrames.Count(); ++nPos ) 1661 { 1662 SfxViewFrame *pFrame = rFrames.GetObject(nPos); 1663 if ( ( !pDoc || pDoc == pFrame->GetObjectShell() ) 1664 && ( !bOnlyIfVisible || pFrame->IsVisible() ) 1665 ) 1666 return pFrame; 1667 } 1668 return 0; 1669 } 1670 1671 void SfxViewFrame::CloseHiddenFrames_Impl() 1672 { 1673 SfxApplication *pSfxApp = SFX_APP(); 1674 SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl(); 1675 for ( sal_uInt16 nPos=0; nPos<rFrames.Count(); ) 1676 { 1677 SfxViewFrame *pFrame = rFrames.GetObject(nPos); 1678 if ( !pFrame->IsVisible() ) 1679 pFrame->DoClose(); 1680 else 1681 nPos++; 1682 } 1683 } 1684 1685 //-------------------------------------------------------------------- 1686 SfxProgress* SfxViewFrame::GetProgress() const 1687 { 1688 SfxObjectShell *pObjSh = GetObjectShell(); 1689 return pObjSh ? pObjSh->GetProgress() : 0; 1690 } 1691 1692 //-------------------------------------------------------------------- 1693 void SfxViewFrame::ShowStatusText( const String& /*rText*/) 1694 { 1695 /* OBSOLETE: If this is used, framework/uielement/progressbarwrapper.[h|c]xx & 1696 framework/uielement/statusindicatorinterfacewrapper.[h|c]xx must be 1697 extended to support a new interface to support ShowStatusText/HideStatusText 1698 SfxWorkWindow* pWorkWin = GetFrame().GetWorkWindow_Impl(); 1699 SfxStatusBarManager *pMgr = pWorkWin->GetStatusBarManager_Impl(); 1700 if ( pMgr ) 1701 { 1702 pMgr->GetStatusBar()->HideItems(); 1703 pMgr->GetStatusBar()->SetText( rText ); 1704 } 1705 */ 1706 } 1707 1708 //-------------------------------------------------------------------- 1709 void SfxViewFrame::HideStatusText() 1710 { 1711 /* OBSOLETE: If this is used, framework/uielement/progressbarwrapper.[h|c]xx & 1712 framework/uielement/statusindicatorinterfacewrapper.[h|c]xx must be 1713 extended to support a new interface to support ShowStatusText/HideStatusText 1714 SfxWorkWindow* pWorkWin = GetFrame().GetWorkWindow_Impl(); 1715 SfxStatusBarManager *pMgr = pWorkWin->GetStatusBarManager_Impl(); 1716 if ( pMgr ) 1717 pMgr->GetStatusBar()->ShowItems(); 1718 */ 1719 } 1720 1721 1722 //-------------------------------------------------------------------- 1723 #ifdef ENABLE_INIMANAGER//MUSTINI 1724 SfxIniManager* SfxViewFrame::GetIniManager() const 1725 { 1726 /* SfxIniManager *pIniMgr = GetObjectShell() 1727 ? GetObjectShell()->GetFactory().GetIniManager() 1728 : 0; 1729 if ( !pIniMgr )*/ //! 1730 return SFX_APP()->GetAppIniManager(); 1731 // return pIniMgr; 1732 } 1733 #endif 1734 1735 //-------------------------------------------------------------------- 1736 void SfxViewFrame::DoAdjustPosSizePixel //! teilen in Inner.../Outer... 1737 ( 1738 SfxViewShell* pSh, 1739 const Point& rPos, 1740 const Size& rSize 1741 ) 1742 { 1743 DBG_CHKTHIS(SfxViewFrame, 0); 1744 1745 // Components benutzen diese Methode nicht! 1746 if( pSh && pSh->GetWindow() && !nAdjustPosPixelLock ) 1747 { 1748 nAdjustPosPixelLock++; 1749 if ( pImp->bResizeInToOut ) 1750 pSh->InnerResizePixel( rPos, rSize ); 1751 else 1752 pSh->OuterResizePixel( rPos, rSize ); 1753 nAdjustPosPixelLock--; 1754 } 1755 } 1756 1757 //======================================================================== 1758 1759 int SfxViewFrameItem::operator==( const SfxPoolItem &rItem ) const 1760 { 1761 return PTR_CAST(SfxViewFrameItem, &rItem)->pFrame== pFrame; 1762 } 1763 1764 //-------------------------------------------------------------------- 1765 String SfxViewFrameItem::GetValueText() const 1766 { 1767 return String(); 1768 } 1769 1770 //-------------------------------------------------------------------- 1771 SfxPoolItem* SfxViewFrameItem::Clone( SfxItemPool *) const 1772 { 1773 return new SfxViewFrameItem( pFrame); 1774 } 1775 1776 //-------------------------------------------------------------------- 1777 void SfxViewFrame::SetViewShell_Impl( SfxViewShell *pVSh ) 1778 1779 /* [Beschreibung] 1780 1781 Interne Methode zum setzen der jeweils aktuellen <SfxViewShell>-Instanz, 1782 die in diesem SfxViewFrame aktiv ist. 1783 */ 1784 1785 { 1786 SfxShell::SetViewShell_Impl( pVSh ); 1787 1788 // Hack: InPlaceMode 1789 if ( pVSh ) 1790 pImp->bResizeInToOut = sal_False; 1791 } 1792 1793 //-------------------------------------------------------------------- 1794 /* 1795 Beschreibung: 1796 Der ParentViewFrame ist der ViewFrame des Containers bei internem InPlace 1797 */ 1798 1799 //TODO/LATER: is it still necessary? is there a replacement for GetParentViewFrame_Impl? 1800 SfxViewFrame* SfxViewFrame::GetParentViewFrame_Impl() const 1801 { 1802 return NULL; 1803 } 1804 1805 //-------------------------------------------------------------------- 1806 void SfxViewFrame::ForceOuterResize_Impl(sal_Bool bOn) 1807 { 1808 if ( !pImp->bDontOverwriteResizeInToOut ) 1809 pImp->bResizeInToOut = !bOn; 1810 } 1811 1812 void SfxViewFrame::ForceInnerResize_Impl(sal_Bool bOn) 1813 { 1814 pImp->bDontOverwriteResizeInToOut = bOn; 1815 } 1816 1817 //-------------------------------------------------------------------- 1818 sal_Bool SfxViewFrame::IsResizeInToOut_Impl() const 1819 { 1820 return pImp->bResizeInToOut; 1821 } 1822 //-------------------------------------------------------------------- 1823 void SfxViewFrame::DoAdjustPosSize( SfxViewShell *pSh, 1824 const Point rPos, const Size &rSize ) 1825 { 1826 DBG_CHKTHIS(SfxViewFrame, 0); 1827 if( pSh && !nAdjustPosPixelLock ) 1828 { 1829 Window *pWindow = pSh->GetWindow(); 1830 Point aPos = pWindow->LogicToPixel(rPos); 1831 Size aSize = pWindow->LogicToPixel(rSize); 1832 DoAdjustPosSizePixel(pSh, aPos, aSize); 1833 } 1834 } 1835 1836 //-------------------------------------------------------------------- 1837 void SfxViewFrame::GetDocNumber_Impl() 1838 { 1839 DBG_ASSERT( GetObjectShell(), "Kein Dokument!" ); 1840 GetObjectShell()->SetNamedVisibility_Impl(); 1841 pImp->nDocViewNo = GetObjectShell()->GetNoSet_Impl().GetFreeIndex()+1; 1842 } 1843 1844 //-------------------------------------------------------------------- 1845 1846 void SfxViewFrame::Enable( sal_Bool bEnable ) 1847 { 1848 if ( bEnable != pImp->bEnabled ) 1849 { 1850 pImp->bEnabled = bEnable; 1851 1852 // e.g. InPlace-Frames have a parent... 1853 SfxViewFrame *pParent = GetParentViewFrame_Impl(); 1854 if ( pParent ) 1855 { 1856 pParent->Enable( bEnable ); 1857 } 1858 else 1859 { 1860 Window *pWindow = &GetFrame().GetTopFrame().GetWindow(); 1861 if ( !bEnable ) 1862 pImp->bWindowWasEnabled = pWindow->IsInputEnabled(); 1863 if ( !bEnable || pImp->bWindowWasEnabled ) 1864 pWindow->EnableInput( bEnable, sal_True ); 1865 } 1866 1867 // cursor and focus 1868 SfxViewShell* pViewSh = GetViewShell(); 1869 if ( bEnable ) 1870 { 1871 // show cursor 1872 if ( pViewSh ) 1873 pViewSh->ShowCursor(); 1874 } 1875 else 1876 { 1877 // hide cursor 1878 if ( pViewSh ) 1879 pViewSh->ShowCursor(sal_False); 1880 } 1881 /* 1882 if ( !bEnable ) 1883 GetBindings().ENTERREGISTRATIONS(); 1884 GetDispatcher()->Lock( !bEnable ); 1885 if ( bEnable ) 1886 GetBindings().LEAVEREGISTRATIONS(); 1887 */ 1888 } 1889 } 1890 1891 //-------------------------------------------------------------------- 1892 void SfxViewFrame::Show() 1893 1894 /* [Beschreibung] 1895 1896 Diese Methode macht das Frame-Window sichtbar und ermittelt vorher 1897 den Fenstername. Au\serdem wird das Dokument festgehalten. Man darf 1898 i.d.R. nie das Window direkt showen! 1899 */ 1900 1901 { 1902 // zuerst locken damit in UpdateTitle() gilt: IsVisible() == sal_True (:#) 1903 if ( xObjSh.Is() ) 1904 { 1905 xObjSh->GetMedium()->GetItemSet()->ClearItem( SID_HIDDEN ); 1906 if ( !pImp->bObjLocked ) 1907 LockObjectShell_Impl( sal_True ); 1908 1909 // Doc-Shell Titel-Nummer anpassen, get unique view-no 1910 if ( 0 == pImp->nDocViewNo ) 1911 { 1912 GetDocNumber_Impl(); 1913 UpdateTitle(); 1914 } 1915 } 1916 else 1917 UpdateTitle(); 1918 1919 // Frame-Window anzeigen, aber nur wenn der ViewFrame kein eigenes Window 1920 // hat oder wenn er keine Component enth"alt 1921 if ( &GetWindow() == &GetFrame().GetWindow() || !GetFrame().HasComponent() ) 1922 GetWindow().Show(); 1923 GetFrame().GetWindow().Show(); 1924 1925 /* SfxViewFrame* pCurrent = SfxViewFrame::Current(); 1926 if ( GetFrame().GetFrameInterface()->isActive() && 1927 pCurrent != this && 1928 ( !pCurrent || pCurrent->GetParentViewFrame_Impl() != this ) && 1929 !GetActiveChildFrame_Impl() ) 1930 MakeActive_Impl( sal_False );*/ 1931 if ( xObjSh.Is() && xObjSh->Get_Impl()->bHiddenLockedByAPI ) 1932 { 1933 xObjSh->Get_Impl()->bHiddenLockedByAPI = sal_False; 1934 xObjSh->OwnerLock(sal_False); 1935 } 1936 } 1937 1938 //-------------------------------------------------------------------- 1939 sal_Bool SfxViewFrame::IsVisible() const 1940 { 1941 return pImp->bObjLocked; 1942 } 1943 1944 //-------------------------------------------------------------------- 1945 void SfxViewFrame::Hide() 1946 { 1947 GetWindow().Hide(); 1948 if ( pImp->bObjLocked ) 1949 LockObjectShell_Impl( sal_False ); 1950 } 1951 1952 //-------------------------------------------------------------------- 1953 void SfxViewFrame::LockObjectShell_Impl( sal_Bool bLock ) 1954 { 1955 DBG_ASSERT( pImp->bObjLocked != bLock, "Falscher Locked-Status!" ); 1956 1957 DBG_ASSERT( GetObjectShell(), "Kein Dokument!" ); 1958 GetObjectShell()->OwnerLock(bLock); 1959 pImp->bObjLocked = bLock; 1960 } 1961 1962 //-------------------------------------------------------------------- 1963 void SfxViewFrame::MakeActive_Impl( sal_Bool bGrabFocus ) 1964 { 1965 if ( GetViewShell() && !GetFrame().IsClosing_Impl() ) 1966 { 1967 if ( IsVisible() ) 1968 { 1969 if ( GetViewShell() ) 1970 { 1971 sal_Bool bPreview = sal_False; 1972 if ( GetObjectShell()->IsPreview() ) 1973 { 1974 bPreview = sal_True; 1975 } 1976 else 1977 { 1978 SfxViewFrame* pParent = GetParentViewFrame(); 1979 if ( pParent ) 1980 pParent->SetActiveChildFrame_Impl( this ); 1981 } 1982 1983 SfxViewFrame* pCurrent = SfxViewFrame::Current(); 1984 css::uno::Reference< css::frame::XFrame > xFrame = GetFrame().GetFrameInterface(); 1985 if ( !bPreview ) 1986 { 1987 SetViewFrame( this ); 1988 GetBindings().SetActiveFrame( css::uno::Reference< css::frame::XFrame >() ); 1989 uno::Reference< frame::XFramesSupplier > xSupp( xFrame, uno::UNO_QUERY ); 1990 if ( xSupp.is() ) 1991 xSupp->setActiveFrame( uno::Reference < frame::XFrame >() ); 1992 1993 css::uno::Reference< css::awt::XWindow > xContainerWindow = xFrame->getContainerWindow(); 1994 Window* pWindow = VCLUnoHelper::GetWindow(xContainerWindow); 1995 if (pWindow && pWindow->HasChildPathFocus() && bGrabFocus) 1996 { 1997 SfxInPlaceClient *pCli = GetViewShell()->GetUIActiveClient(); 1998 if ( ( !pCli || !pCli->IsObjectUIActive() ) && 1999 ( !pCurrent || pCurrent->GetParentViewFrame_Impl() != this ) ) 2000 GetFrame().GrabFocusOnComponent_Impl(); 2001 } 2002 } 2003 else 2004 { 2005 GetBindings().SetDispatcher( GetDispatcher() ); 2006 GetBindings().SetActiveFrame( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > () ); 2007 GetDispatcher()->Update_Impl( sal_False ); 2008 } 2009 } 2010 } 2011 } 2012 } 2013 2014 //------------------------------------------------------------------------- 2015 2016 void SfxViewFrame::SetQuietMode_Impl( sal_Bool bOn ) 2017 { 2018 GetDispatcher()->SetQuietMode_Impl( bOn ); 2019 } 2020 2021 //------------------------------------------------------------------------- 2022 2023 SfxObjectShell* SfxViewFrame::GetObjectShell() 2024 { 2025 return xObjSh; 2026 } 2027 2028 const Size& SfxViewFrame::GetMargin_Impl() const 2029 { 2030 return pImp->aMargin; 2031 } 2032 2033 void SfxViewFrame::SetActiveChildFrame_Impl( SfxViewFrame *pViewFrame ) 2034 { 2035 if ( pViewFrame != pImp->pActiveChild ) 2036 { 2037 if ( !pImp->pActiveChild ) 2038 GetDispatcher()->LockUI_Impl( sal_False ); 2039 2040 pImp->pActiveChild = pViewFrame; 2041 2042 Reference< XFramesSupplier > xFrame( GetFrame().GetFrameInterface(), UNO_QUERY ); 2043 Reference< XFrame > xActive; 2044 if ( pViewFrame ) 2045 xActive = pViewFrame->GetFrame().GetFrameInterface(); 2046 2047 if ( xFrame.is() ) // PB: #74432# xFrame cann be NULL 2048 xFrame->setActiveFrame( xActive ); 2049 } 2050 } 2051 2052 SfxViewFrame* SfxViewFrame::GetActiveChildFrame_Impl() const 2053 { 2054 SfxViewFrame *pViewFrame = pImp->pActiveChild; 2055 /* 2056 if ( !pViewFrame ) 2057 { 2058 // Wenn es keinen aktiven ChildFrame gibt, irgendeinen nehmen 2059 for ( sal_uInt16 n=0; n<GetChildFrameCount(); n++ ) 2060 { 2061 pViewFrame = 2062 PTR_CAST( SfxViewFrame, GetChildFrame(n)->GetChildFrame(0) ); 2063 if ( pViewFrame ) 2064 break; 2065 } 2066 } 2067 2068 pImp->pActiveChild = pViewFrame; 2069 */ 2070 return pViewFrame; 2071 } 2072 2073 //-------------------------------------------------------------------- 2074 SfxViewFrame* SfxViewFrame::LoadViewIntoFrame_Impl_NoThrow( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame, 2075 const sal_uInt16 i_nViewId, const bool i_bHidden ) 2076 { 2077 Reference< XFrame > xFrame( i_rFrame ); 2078 bool bOwnFrame = false; 2079 SfxViewShell* pSuccessView = NULL; 2080 try 2081 { 2082 if ( !xFrame.is() ) 2083 { 2084 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 2085 Reference < XFrame > xDesktop( aContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW ); 2086 2087 if ( !i_bHidden ) 2088 { 2089 try 2090 { 2091 // if there is a backing component, use it 2092 Reference< XFramesSupplier > xTaskSupplier( xDesktop , css::uno::UNO_QUERY_THROW ); 2093 ::framework::FrameListAnalyzer aAnalyzer( xTaskSupplier, Reference< XFrame >(), ::framework::FrameListAnalyzer::E_BACKINGCOMPONENT ); 2094 2095 if ( aAnalyzer.m_xBackingComponent.is() ) 2096 xFrame = aAnalyzer.m_xBackingComponent; 2097 } 2098 catch( uno::Exception& ) 2099 {} 2100 } 2101 2102 if ( !xFrame.is() ) 2103 xFrame.set( xDesktop->findFrame( DEFINE_CONST_UNICODE("_blank"), 0 ), UNO_SET_THROW ); 2104 2105 bOwnFrame = true; 2106 } 2107 2108 pSuccessView = LoadViewIntoFrame_Impl( 2109 i_rDoc, 2110 xFrame, 2111 Sequence< PropertyValue >(), // means "reuse existing model's args" 2112 i_nViewId, 2113 i_bHidden 2114 ); 2115 2116 if ( bOwnFrame && !i_bHidden ) 2117 { 2118 // ensure the frame/window is visible 2119 Reference< XWindow > xContainerWindow( xFrame->getContainerWindow(), UNO_SET_THROW ); 2120 xContainerWindow->setVisible( sal_True ); 2121 } 2122 } 2123 catch( const Exception& ) 2124 { 2125 DBG_UNHANDLED_EXCEPTION(); 2126 } 2127 2128 if ( pSuccessView ) 2129 return pSuccessView->GetViewFrame(); 2130 2131 if ( bOwnFrame ) 2132 { 2133 try 2134 { 2135 xFrame->dispose(); 2136 } 2137 catch( const Exception& ) 2138 { 2139 DBG_UNHANDLED_EXCEPTION(); 2140 } 2141 } 2142 2143 return NULL; 2144 } 2145 2146 //-------------------------------------------------------------------- 2147 SfxViewShell* SfxViewFrame::LoadViewIntoFrame_Impl( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame, 2148 const Sequence< PropertyValue >& i_rLoadArgs, const sal_uInt16 i_nViewId, 2149 const bool i_bHidden ) 2150 { 2151 Reference< XModel > xDocument( i_rDoc.GetModel(), UNO_SET_THROW ); 2152 2153 ::comphelper::NamedValueCollection aTransformLoadArgs( i_rLoadArgs.getLength() ? i_rLoadArgs : xDocument->getArgs() ); 2154 aTransformLoadArgs.put( "Model", xDocument ); 2155 if ( i_nViewId ) 2156 aTransformLoadArgs.put( "ViewId", sal_Int16( i_nViewId ) ); 2157 if ( i_bHidden ) 2158 aTransformLoadArgs.put( "Hidden", i_bHidden ); 2159 else 2160 aTransformLoadArgs.remove( "Hidden" ); 2161 2162 ::rtl::OUString sURL( RTL_CONSTASCII_USTRINGPARAM( "private:object" ) ); 2163 if ( !sURL.getLength() ) 2164 sURL = i_rDoc.GetFactory().GetFactoryURL(); 2165 2166 Reference< XComponentLoader > xLoader( i_rFrame, UNO_QUERY_THROW ); 2167 xLoader->loadComponentFromURL( sURL, ::rtl::OUString::createFromAscii( "_self" ), 0, 2168 aTransformLoadArgs.getPropertyValues() ); 2169 2170 SfxViewShell* pViewShell = SfxViewShell::Get( i_rFrame->getController() ); 2171 ENSURE_OR_THROW( pViewShell, 2172 "SfxViewFrame::LoadViewIntoFrame_Impl: loading an SFX doc into a frame resulted in a non-SFX view - quite impossible" ); 2173 return pViewShell; 2174 } 2175 2176 //-------------------------------------------------------------------- 2177 2178 SfxViewFrame* SfxViewFrame::LoadHiddenDocument( SfxObjectShell& i_rDoc, const sal_uInt16 i_nViewId ) 2179 { 2180 return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, true ); 2181 } 2182 2183 //-------------------------------------------------------------------- 2184 2185 SfxViewFrame* SfxViewFrame::LoadDocument( SfxObjectShell& i_rDoc, const sal_uInt16 i_nViewId ) 2186 { 2187 return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, false ); 2188 } 2189 2190 //-------------------------------------------------------------------- 2191 2192 SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rTargetFrame, const sal_uInt16 i_nViewId ) 2193 { 2194 return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_rTargetFrame, i_nViewId, false ); 2195 } 2196 2197 //-------------------------------------------------------------------- 2198 2199 SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const SfxFrameItem* i_pFrameItem, const sal_uInt16 i_nViewId ) 2200 { 2201 return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_pFrameItem && i_pFrameItem->GetFrame() ? i_pFrameItem->GetFrame()->GetFrameInterface() : NULL, i_nViewId, false ); 2202 } 2203 2204 //-------------------------------------------------------------------- 2205 SfxViewFrame* SfxViewFrame::DisplayNewDocument( SfxObjectShell& i_rDoc, const SfxRequest& i_rCreateDocRequest, const sal_uInt16 i_nViewId ) 2206 { 2207 SFX_REQUEST_ARG( i_rCreateDocRequest, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False ); 2208 SFX_REQUEST_ARG( i_rCreateDocRequest, pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False ); 2209 2210 return LoadViewIntoFrame_Impl_NoThrow( 2211 i_rDoc, 2212 pFrameItem ? pFrameItem->GetFrame() : NULL, 2213 i_nViewId, 2214 pHiddenItem ? pHiddenItem->GetValue() : false 2215 ); 2216 } 2217 2218 //-------------------------------------------------------------------- 2219 2220 SfxViewFrame* SfxViewFrame::Get( const Reference< XController>& i_rController, const SfxObjectShell* i_pDoc ) 2221 { 2222 if ( !i_rController.is() ) 2223 return NULL; 2224 2225 const SfxObjectShell* pDoc = i_pDoc; 2226 if ( !pDoc ) 2227 { 2228 Reference< XModel > xDocument( i_rController->getModel() ); 2229 for ( pDoc = SfxObjectShell::GetFirst( 0, false ); 2230 pDoc; 2231 pDoc = SfxObjectShell::GetNext( *pDoc, 0, false ) 2232 ) 2233 { 2234 if ( pDoc->GetModel() == xDocument ) 2235 break; 2236 } 2237 } 2238 2239 SfxViewFrame* pViewFrame = NULL; 2240 for ( pViewFrame = SfxViewFrame::GetFirst( pDoc, sal_False ); 2241 pViewFrame; 2242 pViewFrame = SfxViewFrame::GetNext( *pViewFrame, pDoc, sal_False ) 2243 ) 2244 { 2245 if ( pViewFrame->GetViewShell()->GetController() == i_rController ) 2246 break; 2247 } 2248 2249 return pViewFrame; 2250 } 2251 2252 //-------------------------------------------------------------------- 2253 2254 void SfxViewFrame::SaveCurrentViewData_Impl( const sal_uInt16 i_nNewViewId ) 2255 { 2256 SfxViewShell* pCurrentShell = GetViewShell(); 2257 ENSURE_OR_RETURN_VOID( pCurrentShell != NULL, "SfxViewFrame::SaveCurrentViewData_Impl: no current view shell -> no current view data!" ); 2258 2259 // determine the logical (API) view name 2260 const SfxObjectFactory& rDocFactory( pCurrentShell->GetObjectShell()->GetFactory() ); 2261 const sal_uInt16 nCurViewNo = rDocFactory.GetViewNo_Impl( GetCurViewId(), 0 ); 2262 const String sCurrentViewName = rDocFactory.GetViewFactory( nCurViewNo ).GetAPIViewName(); 2263 const sal_uInt16 nNewViewNo = rDocFactory.GetViewNo_Impl( i_nNewViewId, 0 ); 2264 const String sNewViewName = rDocFactory.GetViewFactory( nNewViewNo ).GetAPIViewName(); 2265 if ( ( sCurrentViewName.Len() == 0 ) || ( sNewViewName.Len() == 0 ) ) 2266 { 2267 // can't say anything about the view, the respective application did not yet migrate its code to 2268 // named view factories => bail out 2269 OSL_ENSURE( false, "SfxViewFrame::SaveCurrentViewData_Impl: views without API names? Shouldn't happen anymore?" ); 2270 return; 2271 } 2272 OSL_ENSURE( !sNewViewName.Equals( sCurrentViewName ), "SfxViewFrame::SaveCurrentViewData_Impl: suspicious: new and old view name are identical!" ); 2273 2274 // save the view data only when we're moving from a non-print-preview to the print-preview view 2275 if ( !sNewViewName.EqualsAscii( "PrintPreview" ) ) 2276 return; 2277 2278 // retrieve the view data from the view 2279 Sequence< PropertyValue > aViewData; 2280 pCurrentShell->WriteUserDataSequence( aViewData ); 2281 2282 try 2283 { 2284 // retrieve view data (for *all* views) from the model 2285 const Reference< XController > xController( pCurrentShell->GetController(), UNO_SET_THROW ); 2286 const Reference< XViewDataSupplier > xViewDataSupplier( xController->getModel(), UNO_QUERY_THROW ); 2287 const Reference< XIndexContainer > xViewData( xViewDataSupplier->getViewData(), UNO_QUERY_THROW ); 2288 2289 // look up the one view data item which corresponds to our current view, and remove it 2290 const sal_Int32 nCount = xViewData->getCount(); 2291 for ( sal_Int32 i=0; i<nCount; ++i ) 2292 { 2293 const ::comphelper::NamedValueCollection aCurViewData( xViewData->getByIndex(i) ); 2294 ::rtl::OUString sViewId( aCurViewData.getOrDefault( "ViewId", ::rtl::OUString() ) ); 2295 if ( sViewId.getLength() == 0 ) 2296 continue; 2297 2298 const SfxViewFactory* pViewFactory = rDocFactory.GetViewFactoryByViewName( sViewId ); 2299 if ( pViewFactory == NULL ) 2300 continue; 2301 2302 if ( pViewFactory->GetOrdinal() == GetCurViewId() ) 2303 { 2304 xViewData->removeByIndex(i); 2305 break; 2306 } 2307 } 2308 2309 // then replace it with the most recent view data we just obtained 2310 xViewData->insertByIndex( 0, makeAny( aViewData ) ); 2311 } 2312 catch( const Exception& ) 2313 { 2314 DBG_UNHANDLED_EXCEPTION(); 2315 } 2316 } 2317 2318 //-------------------------------------------------------------------- 2319 2320 sal_Bool SfxViewFrame::SwitchToViewShell_Impl 2321 ( 2322 sal_uInt16 nViewIdOrNo, /* > 0 2323 Registrierungs-Id der View, auf die umge- 2324 schaltet werden soll, bzw. die erstmalig 2325 erzeugt werden soll. 2326 2327 == 0 2328 Es soll die Default-View verwendet werden. */ 2329 2330 sal_Bool bIsIndex /* sal_True 2331 'nViewIdOrNo' ist keine Registrations-Id sondern 2332 ein Index in die f"ur die in diesem 2333 <SfxViewFrame> dargestellte <SfxObjectShell>. 2334 */ 2335 ) 2336 2337 /* [Beschreibung] 2338 2339 Interne Methode zum Umschalten auf eine andere <SfxViewShell>-Subklasse, 2340 die in diesem SfxMDIFrame erzeugt werden soll. Existiert noch 2341 keine SfxViewShell in diesem SfxMDIFrame, so wird erstmalig eine 2342 erzeugt. 2343 2344 2345 [R"uckgabewert] 2346 2347 sal_Bool sal_True 2348 die angeforderte SfxViewShell wurde erzeugt 2349 und eine ggf. bestehende gel"oscht 2350 2351 sal_False 2352 die angeforderte SfxViewShell konnte nicht 2353 erzeugt werden, die bestehende SfxViewShell 2354 existiert daher weiterhin 2355 */ 2356 2357 { 2358 try 2359 { 2360 ENSURE_OR_THROW( GetObjectShell() != NULL, "not possible without a document" ); 2361 2362 // if we already have a view shell, remove it 2363 SfxViewShell* pOldSh = GetViewShell(); 2364 OSL_PRECOND( pOldSh, "SfxViewFrame::SwitchToViewShell_Impl: that's called *switch* (not for *initial-load*) for a reason" ); 2365 if ( pOldSh ) 2366 { 2367 // ask wether it can be closed 2368 if ( !pOldSh->PrepareClose( sal_True ) ) 2369 return sal_False; 2370 2371 // remove sub shells from Dispatcher before switching to new ViewShell 2372 PopShellAndSubShells_Impl( *pOldSh ); 2373 } 2374 2375 GetBindings().ENTERREGISTRATIONS(); 2376 LockAdjustPosSizePixel(); 2377 2378 // ID of the new view 2379 SfxObjectFactory& rDocFact = GetObjectShell()->GetFactory(); 2380 const sal_uInt16 nViewId = ( bIsIndex || !nViewIdOrNo ) ? rDocFact.GetViewFactory( nViewIdOrNo ).GetOrdinal() : nViewIdOrNo; 2381 2382 // save the view data of the old view, so it can be restored later on (when needed) 2383 SaveCurrentViewData_Impl( nViewId ); 2384 2385 // create and load new ViewShell 2386 SfxViewShell* pNewSh = LoadViewIntoFrame_Impl( 2387 *GetObjectShell(), 2388 GetFrame().GetFrameInterface(), 2389 Sequence< PropertyValue >(), // means "reuse existing model's args" 2390 nViewId, 2391 false 2392 ); 2393 2394 // allow resize events to be processed 2395 UnlockAdjustPosSizePixel(); 2396 2397 if ( GetWindow().IsReallyVisible() ) 2398 DoAdjustPosSizePixel( pNewSh, Point(), GetWindow().GetOutputSizePixel() ); 2399 2400 GetBindings().LEAVEREGISTRATIONS(); 2401 delete pOldSh; 2402 } 2403 catch ( const com::sun::star::uno::Exception& ) 2404 { 2405 // the SfxCode is not able to cope with exceptions thrown while creating views 2406 // the code will crash in the stack unwinding procedure, so we shouldn't let exceptions go through here 2407 DBG_UNHANDLED_EXCEPTION(); 2408 return sal_False; 2409 } 2410 2411 DBG_ASSERT( SFX_APP()->GetViewFrames_Impl().Count() == SFX_APP()->GetViewShells_Impl().Count(), "Inconsistent view arrays!" ); 2412 return sal_True; 2413 } 2414 2415 //------------------------------------------------------------------------- 2416 void SfxViewFrame::SetCurViewId_Impl( const sal_uInt16 i_nID ) 2417 { 2418 pImp->nCurViewId = i_nID; 2419 } 2420 2421 //------------------------------------------------------------------------- 2422 sal_uInt16 SfxViewFrame::GetCurViewId() const 2423 { 2424 return pImp->nCurViewId; 2425 } 2426 2427 //------------------------------------------------------------------------- 2428 void SfxViewFrame::ExecView_Impl 2429 ( 2430 SfxRequest& rReq // der auszuf"uhrende <SfxRequest> 2431 ) 2432 2433 /* [Beschreibung] 2434 2435 Interne Methode zum Ausf"uhren der f"ur die <SfxShell> Subklasse 2436 SfxViewFrame in der <SVIDL> beschriebenen Slots. 2437 */ 2438 2439 { 2440 DBG_CHKTHIS(SfxViewFrame, 0); 2441 2442 // Wenn gerade die Shells ausgetauscht werden... 2443 if ( !GetObjectShell() || !GetViewShell() ) 2444 return; 2445 2446 switch ( rReq.GetSlot() ) 2447 { 2448 case SID_TERMINATE_INPLACEACTIVATION : 2449 { 2450 SfxInPlaceClient* pClient = GetViewShell()->GetUIActiveClient(); 2451 if ( pClient ) 2452 pClient->DeactivateObject(); 2453 break; 2454 } 2455 2456 case SID_VIEWSHELL: 2457 { 2458 const SfxPoolItem *pItem = 0; 2459 if ( rReq.GetArgs() 2460 && SFX_ITEM_SET == rReq.GetArgs()->GetItemState( SID_VIEWSHELL, sal_False, &pItem ) 2461 ) 2462 { 2463 const sal_uInt16 nViewId = static_cast< const SfxUInt16Item* >( pItem )->GetValue(); 2464 sal_Bool bSuccess = SwitchToViewShell_Impl( nViewId ); 2465 rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) ); 2466 } 2467 break; 2468 } 2469 2470 case SID_VIEWSHELL0: 2471 case SID_VIEWSHELL1: 2472 case SID_VIEWSHELL2: 2473 case SID_VIEWSHELL3: 2474 case SID_VIEWSHELL4: 2475 { 2476 const sal_uInt16 nViewNo = rReq.GetSlot() - SID_VIEWSHELL0; 2477 sal_Bool bSuccess = SwitchToViewShell_Impl( nViewNo, sal_True ); 2478 rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) ); 2479 break; 2480 } 2481 2482 case SID_NEWWINDOW: 2483 { 2484 // Hack. demnaechst virtuelle Funktion 2485 if ( !GetViewShell()->NewWindowAllowed() ) 2486 { 2487 OSL_ENSURE( false, "You should have disabled the 'Window/New Window' slot!" ); 2488 return; 2489 } 2490 2491 // ViewData bei FrameSets rekursiv holen 2492 GetFrame().GetViewData_Impl(); 2493 SfxMedium* pMed = GetObjectShell()->GetMedium(); 2494 2495 // do not open the new window hidden 2496 pMed->GetItemSet()->ClearItem( SID_HIDDEN ); 2497 2498 // the view ID (optional arg. TODO: this is currently not supported in the slot definition ...) 2499 SFX_REQUEST_ARG( rReq, pViewIdItem, SfxUInt16Item, SID_VIEW_ID, sal_False ); 2500 const sal_uInt16 nViewId = pViewIdItem ? pViewIdItem->GetValue() : GetCurViewId(); 2501 2502 Reference < XFrame > xFrame; 2503 // the frame (optional arg. TODO: this is currently not supported in the slot definition ...) 2504 SFX_REQUEST_ARG( rReq, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False ); 2505 if ( pFrameItem ) 2506 xFrame = pFrameItem->GetFrame(); 2507 2508 LoadViewIntoFrame_Impl_NoThrow( *GetObjectShell(), xFrame, nViewId, false ); 2509 2510 rReq.Done(); 2511 break; 2512 } 2513 2514 case SID_OBJECT: 2515 { 2516 SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, SID_OBJECT, sal_False ); 2517 2518 SfxViewShell *pViewShell = GetViewShell(); 2519 if ( pViewShell && pItem ) 2520 { 2521 pViewShell->DoVerb( pItem->GetValue() ); 2522 rReq.Done(); 2523 break;; 2524 } 2525 } 2526 } 2527 } 2528 2529 //------------------------------------------------------------------------- 2530 /* TODO as96863: 2531 This method try to collect informations about the count of currently open documents. 2532 But the algorithm is implemented very simple ... 2533 E.g. hidden documents should be ignored here ... but they are counted. 2534 TODO: export special helper "framework::FrameListAnalyzer" within the framework module 2535 and use it here. 2536 */ 2537 sal_Bool impl_maxOpenDocCountReached() 2538 { 2539 static ::rtl::OUString SERVICE_DESKTOP = ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop"); 2540 2541 try 2542 { 2543 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); 2544 css::uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey( 2545 xSMGR, 2546 ::rtl::OUString::createFromAscii("org.openoffice.Office.Common/"), 2547 ::rtl::OUString::createFromAscii("Misc"), 2548 ::rtl::OUString::createFromAscii("MaxOpenDocuments"), 2549 ::comphelper::ConfigurationHelper::E_READONLY); 2550 2551 // NIL means: count of allowed documents = infinite ! 2552 if ( ! aVal.hasValue()) 2553 return sal_False; 2554 2555 sal_Int32 nOpenDocs = 0; 2556 sal_Int32 nMaxDocs = 0; 2557 aVal >>= nMaxDocs; 2558 2559 css::uno::Reference< css::frame::XFramesSupplier > xDesktop(xSMGR->createInstance(SERVICE_DESKTOP), css::uno::UNO_QUERY_THROW); 2560 css::uno::Reference< css::container::XIndexAccess > xCont (xDesktop->getFrames() , css::uno::UNO_QUERY_THROW); 2561 2562 sal_Int32 c = xCont->getCount(); 2563 sal_Int32 i = 0; 2564 2565 for (i=0; i<c; ++i) 2566 { 2567 try 2568 { 2569 css::uno::Reference< css::frame::XFrame > xFrame; 2570 xCont->getByIndex(i) >>= xFrame; 2571 if ( ! xFrame.is()) 2572 continue; 2573 2574 // a) do not count the help window 2575 if (xFrame->getName().equalsAscii("OFFICE_HELP_TASK")) 2576 continue; 2577 2578 // b) count all other frames 2579 ++nOpenDocs; 2580 } 2581 catch(const css::uno::Exception&) 2582 // A IndexOutOfBoundException can happen in multithreaded environments, 2583 // where any other thread can change this container ! 2584 { continue; } 2585 } 2586 2587 return (nOpenDocs >= nMaxDocs); 2588 } 2589 catch(const css::uno::Exception&) 2590 {} 2591 2592 // Any internal error is no reason to stop opening documents ! 2593 // Limitation of opening documents is a special "nice to have" feature. 2594 // Otherwhise it can happen, that NO document will be opened ... 2595 return sal_False; 2596 } 2597 2598 //------------------------------------------------------------------------- 2599 void SfxViewFrame::StateView_Impl 2600 ( 2601 SfxItemSet& rSet /* leeres <SfxItemSet> mit <Which-Ranges>, 2602 welche die Ids der zu erfragenden 2603 Slots beschreiben. */ 2604 ) 2605 2606 /* [Beschreibung] 2607 2608 Diese interne Methode liefert in 'rSet' die Status der f"ur die 2609 <SfxShell> Subklasse SfxViewFrame in der <SVIDL> beschriebenen <Slots>. 2610 2611 In 'rSet' sind dabei genau die vom SFx als ung"ultig erkannten 2612 Slot-Ids als Which-ranges enthalten. Falls der an dieser Shell gesetzte 2613 <SfxItemPool> f"ur einzelne Slot-Ids ein Mapping hat, werden die 2614 entsprechenden Which-Ids verwendet, so da\s Items ggf. direkt mit 2615 einer mit Which-Ids arbeitenden Core-::com::sun::star::script::Engine ausgetauscht werden 2616 k"onnen. 2617 */ 2618 2619 { 2620 DBG_CHKTHIS(SfxViewFrame, 0); 2621 2622 SfxObjectShell *pDocSh = GetObjectShell(); 2623 2624 if ( !pDocSh ) 2625 // Ich bin gerade am Reloaden und Yielde so vor mich hin ... 2626 return; 2627 2628 const sal_uInt16 *pRanges = rSet.GetRanges(); 2629 DBG_ASSERT(pRanges, "Set ohne Bereich"); 2630 while ( *pRanges ) 2631 { 2632 for ( sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich ) 2633 { 2634 switch(nWhich) 2635 { 2636 case SID_VIEWSHELL: 2637 { 2638 rSet.Put( SfxUInt16Item( nWhich, pImp->nCurViewId ) ); 2639 break; 2640 } 2641 2642 case SID_VIEWSHELL0: 2643 case SID_VIEWSHELL1: 2644 case SID_VIEWSHELL2: 2645 case SID_VIEWSHELL3: 2646 case SID_VIEWSHELL4: 2647 { 2648 sal_uInt16 nViewNo = nWhich - SID_VIEWSHELL0; 2649 if ( GetObjectShell()->GetFactory().GetViewFactoryCount() > 2650 nViewNo && !GetObjectShell()->IsInPlaceActive() ) 2651 { 2652 SfxViewFactory &rViewFactory = 2653 GetObjectShell()->GetFactory().GetViewFactory(nViewNo); 2654 rSet.Put( SfxBoolItem( 2655 nWhich, pImp->nCurViewId == rViewFactory.GetOrdinal() ) ); 2656 } 2657 else 2658 rSet.DisableItem( nWhich ); 2659 break; 2660 } 2661 case SID_FRAMETITLE: 2662 { 2663 if( GetFrameType() & SFXFRAME_HASTITLE ) 2664 rSet.Put( SfxStringItem( 2665 SID_FRAMETITLE, pImp->aFrameTitle) ); 2666 else 2667 rSet.DisableItem( nWhich ); 2668 break; 2669 } 2670 2671 case SID_NEWWINDOW: 2672 { 2673 if ( !GetViewShell()->NewWindowAllowed() 2674 || impl_maxOpenDocCountReached() 2675 ) 2676 rSet.DisableItem( nWhich ); 2677 break; 2678 } 2679 } 2680 } 2681 } 2682 } 2683 2684 //------------------------------------------------------------------------- 2685 void SfxViewFrame::ToTop() 2686 { 2687 GetFrame().Appear(); 2688 } 2689 2690 //------------------------------------------------------------------------- 2691 SfxViewFrame* SfxViewFrame::GetParentViewFrame() const 2692 /* 2693 Beschreibung: 2694 Der ParentViewFrame ist der ViewFrame des ParentFrames 2695 */ 2696 { 2697 SfxFrame *pFrame = GetFrame().GetParentFrame(); 2698 return pFrame ? pFrame->GetCurrentViewFrame() : NULL; 2699 } 2700 2701 //------------------------------------------------------------------------- 2702 SfxFrame& SfxViewFrame::GetFrame() const 2703 /* 2704 Beschreibung: 2705 GetFrame liefert den Frame, in dem sich der ViewFrame befindet 2706 */ 2707 { 2708 return pImp->rFrame; 2709 } 2710 2711 //------------------------------------------------------------------------- 2712 SfxViewFrame* SfxViewFrame::GetTopViewFrame() const 2713 { 2714 return GetFrame().GetTopFrame().GetCurrentViewFrame(); 2715 } 2716 2717 Window& SfxViewFrame::GetWindow() const 2718 { 2719 return pImp->pWindow ? *pImp->pWindow : GetFrame().GetWindow(); 2720 } 2721 2722 sal_Bool SfxViewFrame::DoClose() 2723 { 2724 return GetFrame().DoClose(); 2725 } 2726 2727 String SfxViewFrame::GetActualPresentationURL_Impl() const 2728 { 2729 if ( xObjSh.Is() ) 2730 return xObjSh->GetMedium()->GetName(); 2731 return String(); 2732 } 2733 2734 void SfxViewFrame::SetModalMode( sal_Bool bModal ) 2735 { 2736 pImp->bModal = bModal; 2737 if ( xObjSh.Is() ) 2738 { 2739 for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( xObjSh ); 2740 !bModal && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, xObjSh ) ) 2741 bModal = pFrame->pImp->bModal; 2742 xObjSh->SetModalMode_Impl( bModal ); 2743 } 2744 } 2745 2746 sal_Bool SfxViewFrame::IsInModalMode() const 2747 { 2748 return pImp->bModal || GetFrame().GetWindow().IsInModalMode(); 2749 } 2750 2751 void SfxViewFrame::Resize( sal_Bool bForce ) 2752 { 2753 Size aSize = GetWindow().GetOutputSizePixel(); 2754 if ( bForce || aSize != pImp->aSize ) 2755 { 2756 pImp->aSize = aSize; 2757 SfxViewShell *pShell = GetViewShell(); 2758 if ( pShell ) 2759 { 2760 if ( GetFrame().IsInPlace() ) 2761 { 2762 Point aPoint = GetWindow().GetPosPixel(); 2763 DoAdjustPosSizePixel( pShell, aPoint, aSize ); 2764 } 2765 else 2766 { 2767 DoAdjustPosSizePixel( pShell, Point(), aSize ); 2768 } 2769 } 2770 } 2771 } 2772 2773 #define LINE_SEP 0x0A 2774 2775 void CutLines( ::rtl::OUString& rStr, sal_Int32 nStartLine, sal_Int32 nLines, sal_Bool bEraseTrailingEmptyLines ) 2776 { 2777 sal_Int32 nStartPos = 0; 2778 sal_Int32 nEndPos = 0; 2779 sal_Int32 nLine = 0; 2780 while ( nLine < nStartLine ) 2781 { 2782 nStartPos = rStr.indexOf( LINE_SEP, nStartPos ); 2783 if( nStartPos == -1 ) 2784 break; 2785 nStartPos++; // nicht das \n. 2786 nLine++; 2787 } 2788 2789 DBG_ASSERTWARNING( nStartPos != STRING_NOTFOUND, "CutLines: Startzeile nicht gefunden!" ); 2790 2791 if ( nStartPos != -1 ) 2792 { 2793 nEndPos = nStartPos; 2794 for ( sal_Int32 i = 0; i < nLines; i++ ) 2795 nEndPos = rStr.indexOf( LINE_SEP, nEndPos+1 ); 2796 2797 if ( nEndPos == -1 ) // kann bei letzter Zeile passieren 2798 nEndPos = rStr.getLength(); 2799 else 2800 nEndPos++; 2801 2802 ::rtl::OUString aEndStr = rStr.copy( nEndPos ); 2803 rStr = rStr.copy( 0, nStartPos ); 2804 rStr += aEndStr; 2805 } 2806 if ( bEraseTrailingEmptyLines ) 2807 { 2808 sal_Int32 n = nStartPos; 2809 sal_Int32 nLen = rStr.getLength(); 2810 while ( ( n < nLen ) && ( rStr.getStr()[ n ] == LINE_SEP ) ) 2811 n++; 2812 2813 if ( n > nStartPos ) 2814 { 2815 ::rtl::OUString aEndStr = rStr.copy( n ); 2816 rStr = rStr.copy( 0, nStartPos ); 2817 rStr += aEndStr; 2818 } 2819 } 2820 } 2821 2822 /* 2823 add new recorded dispatch macro script into the application global basic lib container 2824 It generates a new unique id for it and insert the macro by using this number as name for 2825 the modul 2826 */ 2827 void SfxViewFrame::AddDispatchMacroToBasic_Impl( const ::rtl::OUString& sMacro ) 2828 { 2829 /* 2830 // get lib and modul name from dialog 2831 SfxModule *pMod = GetObjectShell()->GetModule(); 2832 SfxRequest aReq( SID_BASICCHOOSER, SFX_CALLMODE_SYNCHRON, pMod->GetPool() ); 2833 const SfxPoolItem* pRet = pMod->ExecuteSlot( aReq ); 2834 if ( pRet ) 2835 ::rtl::OUString = ((SfxStringItem*)pRet)->GetValue(); 2836 */ 2837 if ( !sMacro.getLength() ) 2838 return; 2839 2840 SfxApplication* pSfxApp = SFX_APP(); 2841 SfxRequest aReq( SID_BASICCHOOSER, SFX_CALLMODE_SYNCHRON, pSfxApp->GetPool() ); 2842 aReq.AppendItem( SfxBoolItem(SID_RECORDMACRO,sal_True) ); 2843 const SfxPoolItem* pRet = SFX_APP()->ExecuteSlot( aReq ); 2844 String aScriptURL; 2845 if ( pRet ) 2846 aScriptURL = ((SfxStringItem*)pRet)->GetValue(); 2847 if ( aScriptURL.Len() ) 2848 { 2849 // parse scriptURL 2850 String aLibName; 2851 String aModuleName; 2852 String aMacroName; 2853 String aLocation; 2854 Reference< XMultiServiceFactory > xSMgr = ::comphelper::getProcessServiceFactory(); 2855 Reference< com::sun::star::uri::XUriReferenceFactory > xFactory( xSMgr->createInstance( 2856 ::rtl::OUString::createFromAscii( "com.sun.star.uri.UriReferenceFactory" ) ), UNO_QUERY ); 2857 if ( xFactory.is() ) 2858 { 2859 Reference< com::sun::star::uri::XVndSunStarScriptUrl > xUrl( xFactory->parse( aScriptURL ), UNO_QUERY ); 2860 if ( xUrl.is() ) 2861 { 2862 // get name 2863 ::rtl::OUString aName = xUrl->getName(); 2864 sal_Unicode cTok = '.'; 2865 sal_Int32 nIndex = 0; 2866 aLibName = aName.getToken( 0, cTok, nIndex ); 2867 if ( nIndex != -1 ) 2868 aModuleName = aName.getToken( 0, cTok, nIndex ); 2869 if ( nIndex != -1 ) 2870 aMacroName = aName.getToken( 0, cTok, nIndex ); 2871 2872 // get location 2873 ::rtl::OUString aLocKey = ::rtl::OUString::createFromAscii( "location" ); 2874 if ( xUrl->hasParameter( aLocKey ) ) 2875 aLocation = xUrl->getParameter( aLocKey ); 2876 } 2877 } 2878 2879 BasicManager* pBasMgr = 0; 2880 if ( aLocation.EqualsIgnoreCaseAscii( "application" ) ) 2881 { 2882 // application basic 2883 pBasMgr = pSfxApp->GetBasicManager(); 2884 } 2885 else if ( aLocation.EqualsIgnoreCaseAscii( "document" ) ) 2886 { 2887 pBasMgr = GetObjectShell()->GetBasicManager(); 2888 } 2889 2890 ::rtl::OUString aOUSource; 2891 if ( pBasMgr) 2892 { 2893 StarBASIC* pBasic = pBasMgr->GetLib( aLibName ); 2894 if ( pBasic ) 2895 { 2896 SbModule* pModule = pBasic->FindModule( aModuleName ); 2897 if ( pModule ) 2898 { 2899 SbMethod* pMethod = (SbMethod*)pModule->GetMethods()->Find( aMacroName, SbxCLASS_METHOD ); 2900 aOUSource = pModule->GetSource32(); 2901 sal_uInt16 nStart, nEnd; 2902 pMethod->GetLineRange( nStart, nEnd ); 2903 sal_uIntPtr nlStart = nStart; 2904 sal_uIntPtr nlEnd = nEnd; 2905 CutLines( aOUSource, nlStart-1, nlEnd-nlStart+1, sal_True ); 2906 } 2907 } 2908 } 2909 2910 // open lib container and break operation if it couldn't be opened 2911 com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer > xLibCont; 2912 if ( aLocation.EqualsIgnoreCaseAscii( "application" ) ) 2913 { 2914 xLibCont = SFX_APP()->GetBasicContainer(); 2915 } 2916 else if ( aLocation.EqualsIgnoreCaseAscii( "document" ) ) 2917 { 2918 xLibCont = GetObjectShell()->GetBasicContainer(); 2919 } 2920 2921 if(!xLibCont.is()) 2922 { 2923 DBG_ERRORFILE("couldn't get access to the basic lib container. Adding of macro isn't possible."); 2924 return; 2925 } 2926 2927 // get LibraryContainer 2928 com::sun::star::uno::Any aTemp; 2929 com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xRoot( 2930 xLibCont, 2931 com::sun::star::uno::UNO_QUERY); 2932 2933 ::rtl::OUString sLib( aLibName ); 2934 com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xLib; 2935 if(xRoot->hasByName(sLib)) 2936 { 2937 // library must be loaded 2938 aTemp = xRoot->getByName(sLib); 2939 xLibCont->loadLibrary(sLib); 2940 aTemp >>= xLib; 2941 } 2942 else 2943 { 2944 xLib = com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >( 2945 xLibCont->createLibrary(sLib), 2946 com::sun::star::uno::UNO_QUERY); 2947 } 2948 2949 // pack the macro as direct usable "sub" routine 2950 ::rtl::OUString sCode; 2951 ::rtl::OUStringBuffer sRoutine(10000); 2952 ::rtl::OUString sMacroName( aMacroName ); 2953 sal_Bool bReplace = sal_False; 2954 2955 // get module 2956 ::rtl::OUString sModule( aModuleName ); 2957 if(xLib->hasByName(sModule)) 2958 { 2959 if ( aOUSource.getLength() ) 2960 { 2961 sRoutine.append( aOUSource ); 2962 } 2963 else 2964 { 2965 aTemp = xLib->getByName(sModule); 2966 aTemp >>= sCode; 2967 sRoutine.append( sCode ); 2968 } 2969 2970 bReplace = sal_True; 2971 } 2972 2973 // append new method 2974 sRoutine.appendAscii("\nsub " ); 2975 sRoutine.append (sMacroName ); 2976 sRoutine.appendAscii("\n" ); 2977 sRoutine.append (sMacro ); 2978 sRoutine.appendAscii("\nend sub\n"); 2979 2980 // create the modul inside the library and insert the macro routine 2981 aTemp <<= sRoutine.makeStringAndClear(); 2982 if ( bReplace ) 2983 { 2984 com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont( 2985 xLib, 2986 com::sun::star::uno::UNO_QUERY); 2987 xModulCont->replaceByName(sModule,aTemp); 2988 } 2989 else 2990 { 2991 com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont( 2992 xLib, 2993 com::sun::star::uno::UNO_QUERY); 2994 xModulCont->insertByName(sModule,aTemp); 2995 } 2996 2997 // #i17355# update the Basic IDE 2998 for ( SfxViewShell* pViewShell = SfxViewShell::GetFirst(); pViewShell; pViewShell = SfxViewShell::GetNext( *pViewShell ) ) 2999 { 3000 if ( pViewShell->GetName().EqualsAscii( "BasicIDE" ) ) 3001 { 3002 SfxViewFrame* pViewFrame = pViewShell->GetViewFrame(); 3003 SfxDispatcher* pDispat = pViewFrame ? pViewFrame->GetDispatcher() : NULL; 3004 if ( pDispat ) 3005 { 3006 SfxMacroInfoItem aInfoItem( SID_BASICIDE_ARG_MACROINFO, pBasMgr, aLibName, aModuleName, String(), String() ); 3007 pDispat->Execute( SID_BASICIDE_UPDATEMODULESOURCE, SFX_CALLMODE_SYNCHRON, &aInfoItem, 0L ); 3008 } 3009 } 3010 } 3011 } 3012 else 3013 { 3014 // add code for "session only" macro 3015 } 3016 } 3017 3018 void SfxViewFrame::MiscExec_Impl( SfxRequest& rReq ) 3019 { 3020 DBG_MEMTEST(); 3021 switch ( rReq.GetSlot() ) 3022 { 3023 case SID_STOP_RECORDING : 3024 case SID_RECORDMACRO : 3025 { 3026 // try to find any active recorder on this frame 3027 ::rtl::OUString sProperty = rtl::OUString::createFromAscii("DispatchRecorderSupplier"); 3028 com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame( 3029 GetFrame().GetFrameInterface(), 3030 com::sun::star::uno::UNO_QUERY); 3031 3032 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(xFrame,com::sun::star::uno::UNO_QUERY); 3033 com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty); 3034 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier; 3035 aProp >>= xSupplier; 3036 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder; 3037 if (xSupplier.is()) 3038 xRecorder = xSupplier->getDispatchRecorder(); 3039 3040 sal_Bool bIsRecording = xRecorder.is(); 3041 SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, SID_RECORDMACRO, sal_False); 3042 if ( pItem && pItem->GetValue() == bIsRecording ) 3043 return; 3044 3045 if ( xRecorder.is() ) 3046 { 3047 // disable active recording 3048 aProp <<= com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier >(); 3049 xSet->setPropertyValue(sProperty,aProp); 3050 3051 SFX_REQUEST_ARG( rReq, pRecordItem, SfxBoolItem, FN_PARAM_1, sal_False); 3052 if ( !pRecordItem || !pRecordItem->GetValue() ) 3053 // insert script into basic library container of application 3054 AddDispatchMacroToBasic_Impl(xRecorder->getRecordedMacro()); 3055 3056 xRecorder->endRecording(); 3057 xRecorder = NULL; 3058 GetBindings().SetRecorder_Impl( xRecorder ); 3059 3060 SetChildWindow( SID_RECORDING_FLOATWINDOW, sal_False ); 3061 if ( rReq.GetSlot() != SID_RECORDMACRO ) 3062 GetBindings().Invalidate( SID_RECORDMACRO ); 3063 } 3064 else if ( rReq.GetSlot() == SID_RECORDMACRO ) 3065 { 3066 // enable recording 3067 com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xFactory( 3068 ::comphelper::getProcessServiceFactory(), 3069 com::sun::star::uno::UNO_QUERY); 3070 3071 xRecorder = com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder >( 3072 xFactory->createInstance(rtl::OUString::createFromAscii("com.sun.star.frame.DispatchRecorder")), 3073 com::sun::star::uno::UNO_QUERY); 3074 3075 xSupplier = com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier >( 3076 xFactory->createInstance(rtl::OUString::createFromAscii("com.sun.star.frame.DispatchRecorderSupplier")), 3077 com::sun::star::uno::UNO_QUERY); 3078 3079 xSupplier->setDispatchRecorder(xRecorder); 3080 xRecorder->startRecording(xFrame); 3081 aProp <<= xSupplier; 3082 xSet->setPropertyValue(sProperty,aProp); 3083 GetBindings().SetRecorder_Impl( xRecorder ); 3084 SetChildWindow( SID_RECORDING_FLOATWINDOW, sal_True ); 3085 } 3086 3087 rReq.Done(); 3088 break; 3089 } 3090 3091 case SID_TOGGLESTATUSBAR: 3092 { 3093 com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame( 3094 GetFrame().GetFrameInterface(), 3095 com::sun::star::uno::UNO_QUERY); 3096 3097 Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY ); 3098 Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager; 3099 if ( xPropSet.is() ) 3100 { 3101 try 3102 { 3103 Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))); 3104 aValue >>= xLayoutManager; 3105 } 3106 catch ( Exception& ) 3107 { 3108 } 3109 } 3110 3111 if ( xLayoutManager.is() ) 3112 { 3113 rtl::OUString aStatusbarResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" )); 3114 // Parameter auswerten 3115 SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, rReq.GetSlot(), sal_False); 3116 sal_Bool bShow( sal_True ); 3117 if ( !pShowItem ) 3118 bShow = xLayoutManager->isElementVisible( aStatusbarResString ); 3119 else 3120 bShow = pShowItem->GetValue(); 3121 3122 if ( bShow ) 3123 { 3124 xLayoutManager->createElement( aStatusbarResString ); 3125 xLayoutManager->showElement( aStatusbarResString ); 3126 } 3127 else 3128 xLayoutManager->hideElement( aStatusbarResString ); 3129 3130 if ( !pShowItem ) 3131 rReq.AppendItem( SfxBoolItem( SID_TOGGLESTATUSBAR, bShow ) ); 3132 } 3133 rReq.Done(); 3134 break; 3135 } 3136 3137 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 3138 case SID_WIN_FULLSCREEN: 3139 { 3140 SFX_REQUEST_ARG(rReq, pItem, SfxBoolItem, rReq.GetSlot(), sal_False); 3141 SfxViewFrame *pTop = GetTopViewFrame(); 3142 if ( pTop ) 3143 { 3144 WorkWindow* pWork = (WorkWindow*) pTop->GetFrame().GetTopWindow_Impl(); 3145 if ( pWork ) 3146 { 3147 com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame( 3148 GetFrame().GetFrameInterface(), 3149 com::sun::star::uno::UNO_QUERY); 3150 3151 Reference< ::com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY ); 3152 Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager; 3153 if ( xPropSet.is() ) 3154 { 3155 try 3156 { 3157 Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))); 3158 aValue >>= xLayoutManager; 3159 } 3160 catch ( Exception& ) 3161 { 3162 } 3163 } 3164 3165 sal_Bool bNewFullScreenMode = pItem ? pItem->GetValue() : !pWork->IsFullScreenMode(); 3166 if ( bNewFullScreenMode != pWork->IsFullScreenMode() ) 3167 { 3168 Reference< ::com::sun::star::beans::XPropertySet > xLMPropSet( xLayoutManager, UNO_QUERY ); 3169 if ( xLMPropSet.is() ) 3170 { 3171 try 3172 { 3173 xLMPropSet->setPropertyValue( 3174 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HideCurrentUI" )), 3175 makeAny( bNewFullScreenMode )); 3176 } 3177 catch ( ::com::sun::star::beans::UnknownPropertyException& ) 3178 { 3179 } 3180 } 3181 pWork->ShowFullScreenMode( bNewFullScreenMode ); 3182 pWork->SetMenuBarMode( bNewFullScreenMode ? MENUBAR_MODE_HIDE : MENUBAR_MODE_NORMAL ); 3183 GetFrame().GetWorkWindow_Impl()->SetFullScreen_Impl( bNewFullScreenMode ); 3184 if ( !pItem ) 3185 rReq.AppendItem( SfxBoolItem( SID_WIN_FULLSCREEN, bNewFullScreenMode ) ); 3186 rReq.Done(); 3187 } 3188 else 3189 rReq.Ignore(); 3190 } 3191 } 3192 else 3193 rReq.Ignore(); 3194 3195 GetDispatcher()->Update_Impl( sal_True ); 3196 break; 3197 } 3198 } 3199 } 3200 3201 void SfxViewFrame::MiscState_Impl(SfxItemSet &rSet) 3202 { 3203 DBG_MEMTEST(); 3204 3205 const sal_uInt16 *pRanges = rSet.GetRanges(); 3206 DBG_ASSERT(pRanges && *pRanges, "Set ohne Bereich"); 3207 while ( *pRanges ) 3208 { 3209 for(sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich) 3210 { 3211 switch(nWhich) 3212 { 3213 case SID_CURRENT_URL: 3214 { 3215 // Bei internem InPlace den ContainerFrame nehmen 3216 SfxViewFrame *pFrame = this; 3217 if ( pFrame->GetParentViewFrame_Impl() ) 3218 pFrame = pFrame->GetParentViewFrame_Impl(); 3219 rSet.Put( SfxStringItem( nWhich, pFrame->GetActualPresentationURL_Impl() ) ); 3220 break; 3221 } 3222 3223 case SID_RECORDMACRO : 3224 { 3225 const char* pName = GetObjectShell()->GetFactory().GetShortName(); 3226 if ( strcmp(pName,"swriter") && strcmp(pName,"scalc") ) 3227 { 3228 rSet.DisableItem( nWhich ); 3229 break; 3230 } 3231 3232 ::rtl::OUString sProperty = rtl::OUString::createFromAscii("DispatchRecorderSupplier"); 3233 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet( 3234 GetFrame().GetFrameInterface(), 3235 com::sun::star::uno::UNO_QUERY); 3236 3237 com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty); 3238 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier; 3239 if ( aProp >>= xSupplier ) 3240 rSet.Put( SfxBoolItem( nWhich, xSupplier.is() ) ); 3241 else 3242 rSet.DisableItem( nWhich ); 3243 break; 3244 } 3245 3246 case SID_STOP_RECORDING : 3247 { 3248 const char* pName = GetObjectShell()->GetFactory().GetShortName(); 3249 if ( strcmp(pName,"swriter") && strcmp(pName,"scalc") ) 3250 { 3251 rSet.DisableItem( nWhich ); 3252 break; 3253 } 3254 3255 ::rtl::OUString sProperty = rtl::OUString::createFromAscii("DispatchRecorderSupplier"); 3256 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet( 3257 GetFrame().GetFrameInterface(), 3258 com::sun::star::uno::UNO_QUERY); 3259 3260 com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty); 3261 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier; 3262 if ( !(aProp >>= xSupplier) || !xSupplier.is() ) 3263 rSet.DisableItem( nWhich ); 3264 break; 3265 } 3266 3267 case SID_TOGGLESTATUSBAR: 3268 { 3269 com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager; 3270 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet( 3271 GetFrame().GetFrameInterface(), 3272 com::sun::star::uno::UNO_QUERY); 3273 com::sun::star::uno::Any aProp = xSet->getPropertyValue( 3274 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )) ); 3275 3276 if ( !( aProp >>= xLayoutManager )) 3277 rSet.Put( SfxBoolItem( nWhich, sal_False )); 3278 else 3279 { 3280 rtl::OUString aStatusbarResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" )); 3281 sal_Bool bShow = xLayoutManager->isElementVisible( aStatusbarResString ); 3282 rSet.Put( SfxBoolItem( nWhich, bShow )); 3283 } 3284 break; 3285 } 3286 3287 case SID_WIN_FULLSCREEN: 3288 { 3289 SfxViewFrame* pTop = GetTopViewFrame(); 3290 if ( pTop ) 3291 { 3292 WorkWindow* pWork = (WorkWindow*) pTop->GetFrame().GetTopWindow_Impl(); 3293 if ( pWork ) 3294 { 3295 rSet.Put( SfxBoolItem( nWhich, pWork->IsFullScreenMode() ) ); 3296 break; 3297 } 3298 } 3299 3300 rSet.DisableItem( nWhich ); 3301 break; 3302 } 3303 3304 case SID_FORMATMENUSTATE : 3305 { 3306 DBG_ERROR("Outdated slot!"); 3307 rSet.DisableItem( nWhich ); 3308 break; 3309 } 3310 3311 default: 3312 //! DBG_ASSERT(FALSE, "Falscher Server fuer GetState"); 3313 break; 3314 } 3315 } 3316 3317 ++pRanges; 3318 } 3319 } 3320 3321 void SfxViewFrame::ChildWindowExecute( SfxRequest &rReq ) 3322 3323 /* [Beschreibung] 3324 3325 Diese Methode kann in der Execute-Methode f"ur das ein- und ausschalten 3326 von Child-Windows eingesetzt werden, um dieses inkl. API-Anbindung zu 3327 implementieren. 3328 3329 Einfach in der IDL als 'ExecuteMethod' eintragen. 3330 */ 3331 3332 { 3333 // Parameter auswerten 3334 sal_uInt16 nSID = rReq.GetSlot(); 3335 3336 SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nSID, sal_False); 3337 if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER ) 3338 { 3339 if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE)) 3340 return; 3341 Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface(); 3342 Reference < XFrame > xBeamer( xFrame->findFrame( DEFINE_CONST_UNICODE("_beamer"), FrameSearchFlag::CHILDREN ) ); 3343 sal_Bool bShow = sal_False; 3344 sal_Bool bHasChild = xBeamer.is(); 3345 bShow = pShowItem ? pShowItem->GetValue() : !bHasChild; 3346 if ( pShowItem ) 3347 { 3348 if( bShow == bHasChild ) 3349 return; 3350 } 3351 else 3352 rReq.AppendItem( SfxBoolItem( nSID, bShow ) ); 3353 3354 if ( !bShow ) 3355 { 3356 SetChildWindow( SID_BROWSER, sal_False ); 3357 } 3358 else 3359 { 3360 ::com::sun::star::util::URL aTargetURL; 3361 aTargetURL.Complete = ::rtl::OUString::createFromAscii(".component:DB/DataSourceBrowser"); 3362 Reference < ::com::sun::star::util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY ); 3363 xTrans->parseStrict( aTargetURL ); 3364 3365 Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY ); 3366 Reference < ::com::sun::star::frame::XDispatch > xDisp; 3367 if ( xProv.is() ) 3368 xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString::createFromAscii("_beamer"), 31 ); 3369 if ( xDisp.is() ) 3370 { 3371 Sequence < ::com::sun::star::beans::PropertyValue > aArgs(1); 3372 ::com::sun::star::beans::PropertyValue* pArg = aArgs.getArray(); 3373 pArg[0].Name = rtl::OUString::createFromAscii("Referer"); 3374 pArg[0].Value <<= ::rtl::OUString::createFromAscii("private:user"); 3375 xDisp->dispatch( aTargetURL, aArgs ); 3376 } 3377 } 3378 3379 rReq.Done(); 3380 return; 3381 } 3382 3383 sal_Bool bShow = sal_False; 3384 sal_Bool bHasChild = HasChildWindow(nSID); 3385 bShow = pShowItem ? pShowItem->GetValue() : !bHasChild; 3386 3387 // ausf"uhren 3388 if ( !pShowItem || bShow != bHasChild ) 3389 ToggleChildWindow( nSID ); 3390 3391 GetBindings().Invalidate( nSID ); 3392 GetDispatcher()->Update_Impl( sal_True ); 3393 3394 // ggf. recorden 3395 if ( nSID == SID_HYPERLINK_DIALOG || nSID == SID_SEARCH_DLG ) 3396 { 3397 rReq.Ignore(); 3398 } 3399 else 3400 { 3401 rReq.AppendItem( SfxBoolItem( nSID, bShow ) ); 3402 rReq.Done(); 3403 } 3404 } 3405 3406 //-------------------------------------------------------------------- 3407 3408 void SfxViewFrame::ChildWindowState( SfxItemSet& rState ) 3409 3410 /* [Beschreibung] 3411 3412 Diese Methode kann in der Status-Methode f"ur das Ein- und Ausschalt- 3413 Zustand von Child-Windows eingesetzt werden, um dieses zu implementieren. 3414 3415 Einfach in der IDL als 'StateMethod' eintragen. 3416 */ 3417 3418 { 3419 SfxWhichIter aIter( rState ); 3420 for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() ) 3421 { 3422 if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER ) 3423 { 3424 rState.Put( SfxBoolItem( nSID, HasChildWindow( SID_BROWSER ) ) ); 3425 } 3426 else if ( nSID == SID_HYPERLINK_DIALOG ) 3427 { 3428 const SfxPoolItem* pDummy = NULL; 3429 SfxItemState eState = GetDispatcher()->QueryState( SID_HYPERLINK_SETLINK, pDummy ); 3430 if ( SFX_ITEM_DISABLED == eState ) 3431 rState.DisableItem(nSID); 3432 else 3433 { 3434 if ( KnowsChildWindow(nSID) ) 3435 rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID)) ); 3436 else 3437 rState.DisableItem(nSID); 3438 } 3439 } 3440 else if ( nSID == SID_BROWSER ) 3441 { 3442 Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface()-> 3443 findFrame( DEFINE_CONST_UNICODE("_beamer"), FrameSearchFlag::CHILDREN ); 3444 if ( !xFrame.is() ) 3445 rState.DisableItem( nSID ); 3446 else if ( KnowsChildWindow(nSID) ) 3447 rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) ); 3448 } 3449 else if ( nSID == SID_TASKPANE ) 3450 { 3451 if ( !KnowsChildWindow( nSID ) ) 3452 { 3453 OSL_ENSURE( false, "SID_TASKPANE state requested, but no task pane child window exists for this ID!" ); 3454 rState.DisableItem( nSID ); 3455 } 3456 else if ( !moduleHasToolPanels( *pImp ) ) 3457 { 3458 rState.Put( SfxVisibilityItem( nSID, sal_False ) ); 3459 } 3460 else 3461 { 3462 rState.Put( SfxBoolItem( nSID, HasChildWindow( nSID ) ) ); 3463 } 3464 } 3465 else if ( KnowsChildWindow(nSID) ) 3466 rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) ); 3467 else 3468 rState.DisableItem(nSID); 3469 } 3470 } 3471 3472 //-------------------------------------------------------------------- 3473 SfxWorkWindow* SfxViewFrame::GetWorkWindow_Impl( sal_uInt16 /*nId*/ ) 3474 { 3475 SfxWorkWindow* pWork = 0; 3476 pWork = GetFrame().GetWorkWindow_Impl(); 3477 return pWork; 3478 } 3479 3480 /* 3481 void SfxViewFrame::SetChildWindow(sal_uInt16 nId, sal_Bool bOn) 3482 { 3483 SetChildWindow( nId, bOn, sal_True ); 3484 }*/ 3485 3486 void SfxViewFrame::SetChildWindow(sal_uInt16 nId, sal_Bool bOn, sal_Bool bSetFocus ) 3487 { 3488 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId ); 3489 if ( pWork ) 3490 pWork->SetChildWindow_Impl( nId, bOn, bSetFocus ); 3491 } 3492 3493 //-------------------------------------------------------------------- 3494 3495 void SfxViewFrame::ToggleChildWindow(sal_uInt16 nId) 3496 { 3497 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId ); 3498 if ( pWork ) 3499 pWork->ToggleChildWindow_Impl( nId, sal_True ); 3500 } 3501 3502 //-------------------------------------------------------------------- 3503 3504 sal_Bool SfxViewFrame::HasChildWindow( sal_uInt16 nId ) 3505 { 3506 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId ); 3507 return pWork ? pWork->HasChildWindow_Impl(nId) : sal_False; 3508 } 3509 3510 //-------------------------------------------------------------------- 3511 3512 sal_Bool SfxViewFrame::KnowsChildWindow( sal_uInt16 nId ) 3513 { 3514 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId ); 3515 return pWork ? pWork->KnowsChildWindow_Impl(nId) : sal_False; 3516 } 3517 3518 //-------------------------------------------------------------------- 3519 3520 void SfxViewFrame::ShowChildWindow( sal_uInt16 nId, sal_Bool bVisible ) 3521 { 3522 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId ); 3523 if ( pWork ) 3524 { 3525 GetDispatcher()->Update_Impl(sal_True); 3526 pWork->ShowChildWindow_Impl(nId, bVisible, sal_True ); 3527 } 3528 } 3529 3530 //-------------------------------------------------------------------- 3531 3532 SfxChildWindow* SfxViewFrame::GetChildWindow(sal_uInt16 nId) 3533 { 3534 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId ); 3535 return pWork ? pWork->GetChildWindow_Impl(nId) : NULL; 3536 } 3537 3538 void SfxViewFrame::UpdateDocument_Impl() 3539 { 3540 SfxObjectShell* pDoc = GetObjectShell(); 3541 if ( pDoc->IsLoadingFinished() ) 3542 pDoc->CheckSecurityOnLoading_Impl(); 3543 3544 // check if document depends on a template 3545 pDoc->UpdateFromTemplate_Impl(); 3546 } 3547 3548 void SfxViewFrame::SetViewFrame( SfxViewFrame* pFrame ) 3549 { 3550 SFX_APP()->SetViewFrame_Impl( pFrame ); 3551 } 3552 3553 // --------------------------------------------------------------------------------------------------------------------- 3554 void SfxViewFrame::ActivateToolPanel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rFrame, const ::rtl::OUString& i_rPanelURL ) 3555 { 3556 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 3557 3558 // look up the SfxFrame for the given XFrame 3559 SfxFrame* pFrame = NULL; 3560 for ( pFrame = SfxFrame::GetFirst(); pFrame; pFrame = SfxFrame::GetNext( *pFrame ) ) 3561 { 3562 if ( pFrame->GetFrameInterface() == i_rFrame ) 3563 break; 3564 } 3565 SfxViewFrame* pViewFrame = pFrame ? pFrame->GetCurrentViewFrame() : NULL; 3566 ENSURE_OR_RETURN_VOID( pViewFrame != NULL, "SfxViewFrame::ActivateToolPanel: did not find an SfxFrame for the given XFrame!" ); 3567 3568 pViewFrame->ActivateToolPanel_Impl( i_rPanelURL ); 3569 } 3570 3571 // --------------------------------------------------------------------------------------------------------------------- 3572 void SfxViewFrame::ActivateToolPanel_Impl( const ::rtl::OUString& i_rPanelURL ) 3573 { 3574 // ensure the task pane is visible 3575 ENSURE_OR_RETURN_VOID( KnowsChildWindow( SID_TASKPANE ), "SfxViewFrame::ActivateToolPanel: this frame/module does not allow for a task pane!" ); 3576 if ( !HasChildWindow( SID_TASKPANE ) ) 3577 ToggleChildWindow( SID_TASKPANE ); 3578 3579 SfxChildWindow* pTaskPaneChildWindow = GetChildWindow( SID_TASKPANE ); 3580 ENSURE_OR_RETURN_VOID( pTaskPaneChildWindow, "SfxViewFrame::ActivateToolPanel_Impl: just switched it on, but it is not there!" ); 3581 3582 ::sfx2::ITaskPaneToolPanelAccess* pPanelAccess = dynamic_cast< ::sfx2::ITaskPaneToolPanelAccess* >( pTaskPaneChildWindow ); 3583 ENSURE_OR_RETURN_VOID( pPanelAccess, "SfxViewFrame::ActivateToolPanel_Impl: task pane child window does not implement a required interface!" ); 3584 pPanelAccess->ActivateToolPanel( i_rPanelURL ); 3585 } 3586