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