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