1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sfx2.hxx" 30 #include <com/sun/star/embed/EmbedStates.hpp> 31 #include <com/sun/star/uno/Reference.h> 32 #include <com/sun/star/awt/XWindow.hpp> 33 #include <com/sun/star/util/XURLTransformer.hpp> 34 #include <com/sun/star/util/XCloseable.hpp> 35 #include <com/sun/star/util/CloseVetoException.hpp> 36 #include <com/sun/star/lang/XComponent.hpp> 37 #include <com/sun/star/lang/DisposedException.hpp> 38 #include <com/sun/star/container/XChild.hpp> 39 40 #ifndef _MENU_HXX //autogen 41 #include <vcl/menu.hxx> 42 #endif 43 #include <svl/intitem.hxx> 44 #ifndef _SPLITWIN_HXX //autogen 45 #include <vcl/splitwin.hxx> 46 #endif 47 #include <svl/eitem.hxx> 48 #include <svl/stritem.hxx> 49 #ifndef _TOOLKIT_UNOHLP_HXX 50 #include <toolkit/helper/vclunohelper.hxx> 51 #endif 52 #include <com/sun/star/awt/PosSize.hpp> 53 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX 54 #include <comphelper/processfactory.hxx> 55 #endif 56 #include <vcl/msgbox.hxx> 57 58 #ifndef GCC 59 #endif 60 61 // wg. pTopFrames 62 #include "appdata.hxx" 63 #include <sfx2/app.hxx> 64 #include <sfx2/event.hxx> 65 #include <sfx2/unoctitm.hxx> 66 #include <sfx2/frame.hxx> 67 #include "arrdecl.hxx" 68 #include <sfx2/objsh.hxx> 69 #include <sfx2/dispatch.hxx> 70 #include <sfx2/docfile.hxx> 71 #include <sfx2/docfilt.hxx> 72 #include <sfx2/frmdescr.hxx> 73 #include "openflag.hxx" 74 #include <sfx2/viewsh.hxx> 75 #include <sfx2/viewfrm.hxx> 76 #include <sfx2/request.hxx> 77 #include <sfx2/fcontnr.hxx> 78 #include "impframe.hxx" 79 #include <sfx2/appuno.hxx> 80 #include <sfx2/viewfrm.hxx> 81 #include "workwin.hxx" 82 #include <sfx2/sfxuno.hxx> 83 #include <sfx2/msgpool.hxx> 84 #include "objshimp.hxx" 85 #include <sfx2/ipclient.hxx> 86 87 #ifdef DBG_UTIL 88 #include <sfx2/frmhtmlw.hxx> 89 #endif 90 91 using namespace com::sun::star; 92 93 static SfxFrameArr_Impl* pFramesArr_Impl=0; 94 95 using namespace ::com::sun::star::uno; 96 using namespace ::com::sun::star::util; 97 using namespace ::com::sun::star::frame; 98 using namespace ::com::sun::star::container; 99 100 TYPEINIT1(SfxFrame, SfxListener); 101 TYPEINIT1_AUTOFACTORY(SfxFrameItem, SfxPoolItem); 102 TYPEINIT1(SfxUsrAnyItem, SfxPoolItem); 103 TYPEINIT1_AUTOFACTORY(SfxUnoFrameItem, SfxPoolItem); 104 105 SvCompatWeakHdl* SfxFrame::GetHdl() 106 { 107 return pImp->GetHdl(); 108 } 109 110 //-------------------------------------------------------------------- 111 void SfxFrame::Construct_Impl() 112 { 113 pImp = new SfxFrame_Impl( this ); 114 if ( !pFramesArr_Impl ) 115 pFramesArr_Impl = new SfxFrameArr_Impl; 116 pFramesArr_Impl->Insert( this, pFramesArr_Impl->Count() ); 117 } 118 119 //-------------------------------------------------------------------- 120 121 SfxFrame::~SfxFrame() 122 { 123 RemoveTopFrame_Impl( this ); 124 DELETEZ( pWindow ); 125 126 pFramesArr_Impl->Remove( pFramesArr_Impl->GetPos( this ) ); 127 128 if ( pParentFrame ) 129 { 130 pParentFrame->RemoveChildFrame_Impl( this ); 131 pParentFrame = 0; 132 } 133 134 delete pImp->pDescr; 135 136 if ( pChildArr ) 137 { 138 DBG_ASSERT( !pChildArr->Count(), "Childs nicht entfernt!" ); 139 delete pChildArr; 140 } 141 142 delete pImp; 143 } 144 145 sal_Bool SfxFrame::DoClose() 146 { 147 // Eigentlich wird noch ein PrepareClose gebraucht !!! 148 sal_Bool bRet = sal_False; 149 if ( !pImp->bClosing ) 150 { 151 pImp->bClosing = sal_True; 152 CancelTransfers(); 153 154 // now close frame; it will be deleted if this call is successful, so don't use any members after that! 155 bRet = sal_True; 156 try 157 { 158 Reference< XCloseable > xCloseable ( pImp->xFrame, UNO_QUERY ); 159 if ( (!GetCurrentDocument() || !GetCurrentDocument()->Get_Impl()->bDisposing ) && xCloseable.is()) 160 xCloseable->close(sal_True); 161 else if ( pImp->xFrame.is() ) 162 { 163 Reference < XFrame > xFrame = pImp->xFrame; 164 xFrame->setComponent( Reference < com::sun::star::awt::XWindow >(), Reference < XController >() ); 165 xFrame->dispose(); 166 } 167 else 168 bRet = DoClose_Impl(); 169 } 170 catch( ::com::sun::star::util::CloseVetoException& ) 171 { 172 pImp->bClosing = sal_False; 173 bRet = sal_False; 174 } 175 catch( ::com::sun::star::lang::DisposedException& ) 176 { 177 } 178 } 179 180 return bRet; 181 } 182 183 sal_Bool SfxFrame::DoClose_Impl() 184 { 185 sal_Bool bRet = sal_True; 186 SfxBindings* pBindings = NULL; 187 if ( pImp->pCurrentViewFrame ) 188 pBindings = &pImp->pCurrentViewFrame->GetBindings(); 189 190 // Bei internen Tasks m"ussen Controller und Tools abger"aumt werden 191 if ( pImp->pWorkWin ) 192 pImp->pWorkWin->DeleteControllers_Impl(); 193 194 if ( pImp->pCurrentViewFrame ) 195 bRet = pImp->pCurrentViewFrame->Close(); 196 197 if ( pImp->bOwnsBindings ) 198 DELETEZ( pBindings ); 199 200 bRet = Close(); 201 DBG_ASSERT( bRet, "Impossible state: frame closes, but controller refuses!"); 202 return bRet; 203 } 204 205 sal_Bool SfxFrame::DocIsModified_Impl() 206 { 207 if ( pImp->pCurrentViewFrame && pImp->pCurrentViewFrame->GetObjectShell() && 208 pImp->pCurrentViewFrame->GetObjectShell()->IsModified() ) 209 return sal_True; 210 for( sal_uInt16 nPos = GetChildFrameCount(); nPos--; ) 211 if( pChildArr->GetObject( nPos )->DocIsModified_Impl() ) 212 return sal_True; 213 return sal_False; 214 } 215 216 sal_uInt16 SfxFrame::PrepareClose_Impl( sal_Bool bUI, sal_Bool bForBrowsing ) 217 { 218 sal_uInt16 nRet = RET_OK; 219 220 // prevent recursive calls 221 if( !pImp->bPrepClosing ) 222 { 223 pImp->bPrepClosing = sal_True; 224 225 SfxObjectShell* pCur = GetCurrentDocument() ; 226 if( pCur ) 227 { 228 // SFX components have a known behaviour 229 // First check if this frame is the only view to its current document 230 int bOther = sal_False; 231 for ( const SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pCur ); 232 !bOther && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, pCur ) ) 233 { 234 bOther = ( &pFrame->GetFrame() != this ); 235 } 236 237 SFX_APP()->NotifyEvent( SfxViewEventHint(SFX_EVENT_PREPARECLOSEVIEW, GlobalEventConfig::GetEventName( STR_EVENT_PREPARECLOSEVIEW ), pCur, GetController() ) ); 238 239 if ( bOther ) 240 // if there are other views only the current view of this frame must be asked 241 nRet = GetCurrentViewFrame()->GetViewShell()->PrepareClose( bUI, bForBrowsing ); 242 else 243 // otherwise ask the document 244 nRet = pCur->PrepareClose( bUI, bForBrowsing ); 245 } 246 247 if ( nRet == RET_OK ) 248 { 249 // if this frame has child frames, ask them too 250 for( sal_uInt16 nPos = GetChildFrameCount(); nRet == RET_OK && nPos--; ) 251 nRet = pChildArr->GetObject( nPos )->PrepareClose_Impl( bUI, bForBrowsing ); 252 } 253 254 pImp->bPrepClosing = sal_False; 255 } 256 257 if ( nRet == RET_OK && pImp->pWorkWin ) 258 // if closing was accepted by the component the UI subframes must be asked also 259 nRet = pImp->pWorkWin->PrepareClose_Impl(); 260 261 return nRet; 262 } 263 264 //-------------------------------------------------------------------- 265 266 SfxFrame* SfxFrame::GetChildFrame( sal_uInt16 nPos ) const 267 { 268 if ( pChildArr && pChildArr->Count() > nPos ) 269 { 270 DBG_ASSERT( nPos < pChildArr->Count(), "Falscher Index!"); 271 return (*pChildArr)[nPos]; 272 } 273 274 return 0L; 275 } 276 277 void SfxFrame::RemoveChildFrame_Impl( SfxFrame* pFrame ) 278 { 279 DBG_ASSERT( pChildArr, "Unbekannter Frame!"); 280 sal_uInt16 nPos = pChildArr->GetPos(pFrame); 281 pChildArr->Remove( nPos ); 282 }; 283 284 SfxFrame& SfxFrame::GetTopFrame() const 285 { 286 const SfxFrame* pParent = this; 287 while ( pParent->pParentFrame ) 288 pParent = pParent->pParentFrame; 289 return *const_cast< SfxFrame* >( pParent ); 290 } 291 292 sal_Bool SfxFrame::IsClosing_Impl() const 293 { 294 return pImp->bClosing; 295 } 296 297 void SfxFrame::SetIsClosing_Impl() 298 { 299 pImp->bClosing = sal_True; 300 } 301 302 sal_uInt16 SfxFrame::GetChildFrameCount() const 303 { 304 return pChildArr ? pChildArr->Count() : 0; 305 } 306 307 void SfxFrame::CancelTransfers( sal_Bool /*bCancelLoadEnv*/ ) 308 { 309 if( !pImp->bInCancelTransfers ) 310 { 311 pImp->bInCancelTransfers = sal_True; 312 SfxObjectShell* pObj = GetCurrentDocument(); 313 if( pObj ) //&& !( pObj->Get_Impl()->nLoadedFlags & SFX_LOADED_ALL )) 314 { 315 SfxViewFrame* pFrm; 316 for( pFrm = SfxViewFrame::GetFirst( pObj ); 317 pFrm && &pFrm->GetFrame() == this; 318 pFrm = SfxViewFrame::GetNext( *pFrm, pObj ) ) ; 319 // Keine anderer Frame mehr auf Doc -> Cancel 320 if( !pFrm ) 321 { 322 pObj->CancelTransfers(); 323 GetCurrentDocument()->Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) ); 324 } 325 } 326 327 // zuerst Nachladende Frames stoppen 328 sal_uInt16 nCount = GetChildFrameCount(); 329 for( sal_uInt16 n = 0; n<nCount; n++ ) 330 GetChildFrame( n )->CancelTransfers(); 331 332 // ggf. StarOne-Loader canceln 333 SfxFrameWeak wFrame( this ); 334 if (wFrame.Is()) 335 pImp->bInCancelTransfers = sal_False; 336 } 337 } 338 339 SfxViewFrame* SfxFrame::GetCurrentViewFrame() const 340 { 341 return pImp->pCurrentViewFrame; 342 } 343 344 SfxDispatcher* SfxFrame::GetDispatcher_Impl() const 345 { 346 if ( pImp->pCurrentViewFrame ) 347 return pImp->pCurrentViewFrame->GetDispatcher(); 348 return GetParentFrame()->GetDispatcher_Impl(); 349 } 350 351 SfxObjectShell* SfxFrame::GetCurrentDocument() const 352 { 353 return pImp->pCurrentViewFrame ? 354 pImp->pCurrentViewFrame->GetObjectShell() : 355 NULL; 356 } 357 358 void SfxFrame::SetCurrentViewFrame_Impl( SfxViewFrame *pFrame ) 359 { 360 pImp->pCurrentViewFrame = pFrame; 361 } 362 363 sal_uInt32 SfxFrame::GetFrameType() const 364 { 365 return pImp->nType; 366 } 367 368 void SfxFrame::SetFrameType_Impl( sal_uInt32 n ) 369 { 370 pImp->nType = n; 371 } 372 373 void SfxFrame::GetViewData_Impl() 374 { 375 // Alle zwischen Laden und Entfernen "anderbaren Daten aktualisieren; die 376 // festen Daten werden nur einmal ( nach PrepareForDoc_Impl in UpdateDescriptor ) 377 // geholt, um Zeit zu sparen. 378 SfxViewFrame* pViewFrame = GetCurrentViewFrame(); 379 if( pViewFrame && pViewFrame->GetViewShell() ) 380 { 381 const SfxMedium *pMed = GetCurrentDocument()->GetMedium(); 382 sal_Bool bReadOnly = pMed->GetOpenMode() == SFX_STREAM_READONLY; 383 GetDescriptor()->SetReadOnly( bReadOnly ); 384 385 SfxItemSet *pSet = GetDescriptor()->GetArgs(); 386 sal_Bool bGetViewData = sal_False; 387 if ( GetController().is() && pSet->GetItemState( SID_VIEW_DATA ) != SFX_ITEM_SET ) 388 { 389 ::com::sun::star::uno::Any aData = GetController()->getViewData(); 390 pSet->Put( SfxUsrAnyItem( SID_VIEW_DATA, aData ) ); 391 bGetViewData = sal_True; 392 } 393 394 if ( pViewFrame->GetCurViewId() ) 395 pSet->Put( SfxUInt16Item( SID_VIEW_ID, pViewFrame->GetCurViewId() ) ); 396 if ( pChildArr ) 397 { 398 // Bei Framesets m"ussen auch die Daten der ChildViews geholt werden 399 sal_uInt16 nCount = pChildArr->Count(); 400 for ( sal_uInt16 n=nCount; n>0; n--) 401 { 402 SfxFrame* pFrame = (*pChildArr)[n-1]; 403 if ( bGetViewData ) 404 pFrame->GetDescriptor()->GetArgs()->ClearItem( SID_VIEW_DATA ); 405 pFrame->GetViewData_Impl(); 406 } 407 } 408 } 409 } 410 411 void SfxFrame::UpdateDescriptor( SfxObjectShell *pDoc ) 412 { 413 // Beim PrepareForDoc_Impl wird der Descriptor des Frames aktualisiert 414 // und sein ItemSet neu initialisiert. Alle Daten, die f"ur ein sp"ateres 415 // Restaurieren der View n"otig sind, sind damit festgehalten. 416 // Soll das Dokument ersetzt werden, wird durch GetViewData_Impl (s.o.) 417 // die neueste Information hinzugef"ugt. Alles zusammen wird dann in der 418 // Browse-History gesichert. Beim Aktivieren eines solchen FramePickEntry 419 // wird das komplette ItemSet und der Descriptor im OpenDoc mitgeschickt. 420 // Hier werden nur die festen Eigenschaften gesichert; die "anderbaren werden 421 // durch GetViewData geholt ( spart Zeit ). 422 DBG_ASSERT( pDoc, "NULL-Document inserted ?!" ); 423 424 GetParentFrame(); 425 const SfxMedium *pMed = pDoc->GetMedium(); 426 GetDescriptor()->SetActualURL( pMed->GetOrigURL() ); 427 428 SFX_ITEMSET_ARG( pMed->GetItemSet(), pItem, SfxBoolItem, SID_EDITDOC, sal_False ); 429 sal_Bool bEditable = ( !pItem || pItem->GetValue() ); 430 431 GetDescriptor()->SetEditable( bEditable ); 432 433 // FileOpen-Parameter merken 434 SfxItemSet* pItemSet = pMed->GetItemSet(); 435 String aMedName( pMed->GetName() ); 436 437 const SfxFilter* pFilter = pMed->GetOrigFilter(); 438 String aFilter; 439 if ( pFilter ) 440 aFilter = pFilter->GetFilterName(); 441 442 SFX_ITEMSET_ARG( pItemSet, pRefererItem, SfxStringItem, SID_REFERER, sal_False); 443 SFX_ITEMSET_ARG( pItemSet, pOptionsItem, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False); 444 SFX_ITEMSET_ARG( pItemSet, pTitle1Item, SfxStringItem, SID_DOCINFO_TITLE, sal_False); 445 446 SfxItemSet *pSet = GetDescriptor()->GetArgs(); 447 448 // Alle alten Items l"oschen 449 pSet->ClearItem(); 450 451 if ( pRefererItem ) 452 pSet->Put( *pRefererItem ); 453 else 454 pSet->Put( SfxStringItem( SID_REFERER, String() ) ); 455 456 if ( pOptionsItem ) 457 pSet->Put( *pOptionsItem ); 458 459 if ( pTitle1Item ) 460 pSet->Put( *pTitle1Item ); 461 462 pSet->Put( SfxStringItem( SID_FILTER_NAME, aFilter )); 463 } 464 465 //------------------------------------------------------------------------- 466 467 void SfxFrame::SetDescriptor( SfxFrameDescriptor *pD ) 468 { 469 DBG_ASSERT( pD, "Kein Descriptor!" ); 470 DBG_ASSERT( pD != pImp->pDescr, "Descriptor ist schon gesetzt!" ); 471 472 if ( pImp->pDescr ) 473 { 474 // Nur TopLevel-Frames verwalten ihren Descriptor selbst, bei den 475 // anderen tut es das Frameset 476 if ( !pParentFrame ) 477 delete pImp->pDescr; 478 } 479 pImp->pDescr = pD; 480 } 481 482 //------------------------------------------------------------------------- 483 484 SfxFrameDescriptor* SfxFrame::GetDescriptor() const 485 { 486 // On Demand einen FrameDescriptor anlegen; wenn es kein TopLevel-Frame 487 // ist, f"uhrt es zu Fehlern, da keine g"ulige Verkettung hergestellt wird 488 489 if ( !pImp->pDescr ) 490 { 491 DBG_ASSERT( !GetParentFrame(), "Kein TopLevel-Frame, aber kein Descriptor!" ); 492 pImp->pDescr = new SfxFrameDescriptor; 493 if ( GetCurrentDocument() ) 494 pImp->pDescr->SetURL( GetCurrentDocument()->GetMedium()->GetOrigURL() ); 495 } 496 return pImp->pDescr; 497 } 498 499 //------------------------------------------------------------------------- 500 501 void SfxFrame::GetTargetList( TargetList& rList ) const 502 { 503 if ( !GetParentFrame() ) 504 { 505 // Einen Leerstring f"ur 'Kein Target' 506 rList.Insert( new String() ); 507 rList.Insert( new String( DEFINE_CONST_UNICODE( "_top" ) ) ); 508 rList.Insert( new String( DEFINE_CONST_UNICODE( "_parent" ) ) ); 509 rList.Insert( new String( DEFINE_CONST_UNICODE( "_blank" ) ) ); 510 rList.Insert( new String( DEFINE_CONST_UNICODE( "_self" ) ) ); 511 } 512 513 SfxViewFrame* pView = GetCurrentViewFrame(); 514 if( pView && pView->GetViewShell() && pChildArr ) 515 { 516 sal_uInt16 nCount = pChildArr->Count(); 517 for ( sal_uInt16 n=0; n<nCount; n++) 518 { 519 SfxFrame* pFrame = (*pChildArr)[n]; 520 pFrame->GetTargetList( rList ); 521 } 522 } 523 } 524 525 //------------------------------------------------------------------------- 526 527 SfxBroadcaster& SfxFrame::GetBroadcaster() const 528 { 529 return *pImp; 530 } 531 532 sal_Bool SfxFrame::IsParent( SfxFrame *pFrame ) const 533 { 534 SfxFrame *pParent = pParentFrame; 535 while ( pParent ) 536 { 537 if ( pParent == pFrame ) 538 return sal_True; 539 pParent = pParent->pParentFrame; 540 } 541 542 return sal_False; 543 } 544 545 void SfxFrame::InsertTopFrame_Impl( SfxFrame* pFrame ) 546 { 547 SfxFrameArr_Impl& rArr = *SFX_APP()->Get_Impl()->pTopFrames; 548 rArr.Insert( pFrame, rArr.Count() ); 549 } 550 551 void SfxFrame::RemoveTopFrame_Impl( SfxFrame* pFrame ) 552 { 553 SfxFrameArr_Impl& rArr = *SFX_APP()->Get_Impl()->pTopFrames; 554 rArr.Remove( rArr.GetPos( pFrame ) ); 555 } 556 557 SfxFrameItem::SfxFrameItem( sal_uInt16 nWhichId, SfxViewFrame *p ) 558 : SfxPoolItem( nWhichId ), pFrame( p ? &p->GetFrame() : NULL ) 559 { 560 wFrame = pFrame; 561 } 562 563 SfxFrameItem::SfxFrameItem( sal_uInt16 nWhichId, SfxFrame *p ): 564 SfxPoolItem( nWhichId ), 565 pFrame( p ), wFrame( p ) 566 { 567 } 568 569 SfxFrameItem::SfxFrameItem( SfxFrame *p ): 570 SfxPoolItem( 0 ), 571 pFrame( p ), wFrame( p ) 572 { 573 } 574 575 int SfxFrameItem::operator==( const SfxPoolItem &rItem ) const 576 { 577 return ((SfxFrameItem&)rItem).pFrame == pFrame && 578 ((SfxFrameItem&)rItem).wFrame == wFrame; 579 } 580 581 //-------------------------------------------------------------------- 582 583 String SfxFrameItem::GetValueText() const 584 { 585 return String(); 586 } 587 588 SfxPoolItem* SfxFrameItem::Clone( SfxItemPool *) const 589 { 590 SfxFrameItem* pNew = new SfxFrameItem( wFrame); 591 pNew->SetFramePtr_Impl( pFrame ); 592 return pNew; 593 } 594 595 sal_Bool SfxFrameItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const 596 { 597 if ( wFrame ) 598 { 599 rVal <<= wFrame->GetFrameInterface(); 600 return sal_True; 601 } 602 603 return sal_False; 604 } 605 606 sal_Bool SfxFrameItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 ) 607 { 608 Reference < XFrame > xFrame; 609 if ( (rVal >>= xFrame) && xFrame.is() ) 610 { 611 SfxFrame* pFr = SfxFrame::GetFirst(); 612 while ( pFr ) 613 { 614 if ( pFr->GetFrameInterface() == xFrame ) 615 { 616 wFrame = pFrame = pFr; 617 return sal_True; 618 } 619 620 pFr = SfxFrame::GetNext( *pFr ); 621 } 622 return sal_True; 623 } 624 625 return sal_False; 626 } 627 628 629 SfxUsrAnyItem::SfxUsrAnyItem( sal_uInt16 nWhichId, const ::com::sun::star::uno::Any& rAny ) 630 : SfxPoolItem( nWhichId ) 631 { 632 aValue = rAny; 633 } 634 635 int SfxUsrAnyItem::operator==( const SfxPoolItem& /*rItem*/ ) const 636 { 637 // return rItem.ISA( SfxUsrAnyItem ) && ((SfxUsrAnyItem&)rItem).aValue == aValue; 638 return sal_False; 639 } 640 641 SfxPoolItem* SfxUsrAnyItem::Clone( SfxItemPool *) const 642 { 643 return new SfxUsrAnyItem( Which(), aValue ); 644 } 645 646 sal_Bool SfxUsrAnyItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const 647 { 648 rVal = aValue; 649 return sal_True; 650 } 651 652 sal_Bool SfxUsrAnyItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) 653 { 654 aValue = rVal; 655 return sal_True; 656 } 657 658 SfxUnoFrameItem::SfxUnoFrameItem() 659 : SfxPoolItem() 660 , m_xFrame() 661 { 662 } 663 664 SfxUnoFrameItem::SfxUnoFrameItem( sal_uInt16 nWhichId, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rFrame ) 665 : SfxPoolItem( nWhichId ) 666 , m_xFrame( i_rFrame ) 667 { 668 } 669 670 int SfxUnoFrameItem::operator==( const SfxPoolItem& i_rItem ) const 671 { 672 return i_rItem.ISA( SfxUnoFrameItem ) && static_cast< const SfxUnoFrameItem& >( i_rItem ).m_xFrame == m_xFrame; 673 } 674 675 SfxPoolItem* SfxUnoFrameItem::Clone( SfxItemPool* ) const 676 { 677 return new SfxUnoFrameItem( Which(), m_xFrame ); 678 } 679 680 sal_Bool SfxUnoFrameItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const 681 { 682 rVal <<= m_xFrame; 683 return sal_True; 684 } 685 686 sal_Bool SfxUnoFrameItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) 687 { 688 return ( rVal >>= m_xFrame ); 689 } 690 691 SfxFrameIterator::SfxFrameIterator( const SfxFrame& rFrame, sal_Bool bRecur ) 692 : pFrame( &rFrame ) 693 , bRecursive( bRecur ) 694 {} 695 696 SfxFrame* SfxFrameIterator::FirstFrame() 697 { 698 // GetFirst beginnt die Iteration beim ersten ChildFrame 699 return pFrame->GetChildFrame( 0 ); 700 } 701 702 SfxFrame* SfxFrameIterator::NextFrame( SfxFrame& rPrev ) 703 { 704 // Zuerst auf Kinder testen, wenn Rekursion erw"unscht 705 SfxFrame *pRet = NULL; 706 if ( bRecursive ) 707 pRet = rPrev.GetChildFrame( 0 ); 708 if ( !pRet ) 709 { 710 // Anderenfalls mit den Geschwistern von rPrev weitermachen 711 pRet = NextSibling_Impl( rPrev ); 712 } 713 714 return pRet; 715 } 716 717 718 SfxFrame* SfxFrameIterator::NextSibling_Impl( SfxFrame& rPrev ) 719 { 720 SfxFrame *pRet = NULL; 721 if ( &rPrev != pFrame ) 722 { 723 SfxFrameArr_Impl& rArr = *rPrev.pParentFrame->pChildArr; 724 sal_uInt16 nPos = rArr.GetPos( &rPrev ); 725 if ( nPos+1 < rArr.Count() ) 726 pRet = rArr[nPos+1]; 727 728 if ( !pRet && rPrev.pParentFrame->pParentFrame ) 729 pRet = NextSibling_Impl( *rPrev.pParentFrame ); 730 } 731 732 return pRet; 733 } 734 735 sal_Bool SfxFrame::IsTop() const 736 { 737 return GetFrameInterface().is() ? GetFrameInterface()->isTop() : sal_False; 738 } 739 740 sal_Bool SfxFrame::HasComponent() const 741 { 742 return sal_False; 743 } 744 745 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > SfxFrame::GetController() const 746 { 747 if ( pImp->pCurrentViewFrame && pImp->pCurrentViewFrame->GetViewShell() ) 748 return pImp->pCurrentViewFrame->GetViewShell()->GetController(); 749 else 750 return ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > (); 751 } 752 753 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SfxFrame::GetFrameInterface() const 754 { 755 return pImp->xFrame; 756 } 757 758 void SfxFrame::SetFrameInterface_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame ) 759 { 760 pImp->xFrame = rFrame; 761 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder; 762 if ( !rFrame.is() && GetCurrentViewFrame() ) 763 GetCurrentViewFrame()->GetBindings().SetRecorder_Impl( xRecorder ); 764 } 765 766 void SfxFrame::Appear() 767 { 768 if ( GetCurrentViewFrame() ) 769 { 770 GetCurrentViewFrame()->Show(); 771 GetWindow().Show(); 772 pImp->xFrame->getContainerWindow()->setVisible( sal_True ); 773 if ( pParentFrame ) 774 pParentFrame->Appear(); 775 Reference < ::com::sun::star::awt::XTopWindow > xTopWindow( pImp->xFrame->getContainerWindow(), UNO_QUERY ); 776 if ( xTopWindow.is() ) 777 xTopWindow->toFront(); 778 } 779 } 780 781 void SfxFrame::AppearWithUpdate() 782 { 783 Appear(); 784 if ( GetCurrentViewFrame() ) 785 GetCurrentViewFrame()->GetDispatcher()->Update_Impl( sal_True ); 786 } 787 788 void SfxFrame::SetOwnsBindings_Impl( sal_Bool bSet ) 789 { 790 pImp->bOwnsBindings = bSet; 791 } 792 793 sal_Bool SfxFrame::OwnsBindings_Impl() const 794 { 795 return pImp->bOwnsBindings; 796 } 797 798 void SfxFrame::SetToolSpaceBorderPixel_Impl( const SvBorder& rBorder ) 799 { 800 pImp->aBorder = rBorder; 801 SfxViewFrame *pF = GetCurrentViewFrame(); 802 if ( pF ) 803 { 804 Point aPos ( rBorder.Left(), rBorder.Top() ); 805 Size aSize( GetWindow().GetOutputSizePixel() ); 806 long nDeltaX = rBorder.Left() + rBorder.Right(); 807 if ( aSize.Width() > nDeltaX ) 808 aSize.Width() -= nDeltaX; 809 else 810 aSize.Width() = 0; 811 812 long nDeltaY = rBorder.Top() + rBorder.Bottom(); 813 if ( aSize.Height() > nDeltaY ) 814 aSize.Height() -= nDeltaY; 815 else 816 aSize.Height() = 0; 817 818 if ( GetParentFrame() ) 819 { 820 sal_Bool bHasTools = rBorder.Left() != rBorder.Right() || rBorder.Top() != rBorder.Bottom(); 821 pF->GetWindow().SetBorderStyle( bHasTools ? WINDOW_BORDER_NORMAL : WINDOW_BORDER_NOBORDER ); 822 } 823 824 pF->GetWindow().SetPosSizePixel( aPos, aSize ); 825 } 826 } 827 828 Rectangle SfxFrame::GetTopOuterRectPixel_Impl() const 829 { 830 Size aSize( GetWindow().GetOutputSizePixel() ); 831 Point aPoint; 832 return ( Rectangle ( aPoint, aSize ) ); 833 } 834 835 SfxWorkWindow* SfxFrame::GetWorkWindow_Impl() const 836 { 837 if ( pImp->pWorkWin ) 838 return pImp->pWorkWin; 839 else if ( pParentFrame ) 840 return pParentFrame->GetWorkWindow_Impl(); 841 else 842 return NULL; 843 } 844 845 void SfxFrame::SetWorkWindow_Impl( SfxWorkWindow* pWorkwin ) 846 { 847 pImp->pWorkWin = pWorkwin; 848 } 849 850 void SfxFrame::CreateWorkWindow_Impl() 851 { 852 SfxFrame* pFrame = this; 853 854 if ( IsInPlace() ) 855 { 856 // this makes sence only for inplace activated objects 857 try 858 { 859 Reference < XChild > xChild( GetCurrentDocument()->GetModel(), UNO_QUERY ); 860 if ( xChild.is() ) 861 { 862 Reference < XModel > xParent( xChild->getParent(), UNO_QUERY ); 863 if ( xParent.is() ) 864 { 865 Reference< XController > xParentCtrler = xParent->getCurrentController(); 866 if ( xParentCtrler.is() ) 867 { 868 Reference < XFrame > xFrame( xParentCtrler->getFrame() ); 869 SfxFrame* pFr = SfxFrame::GetFirst(); 870 while ( pFr ) 871 { 872 if ( pFr->GetFrameInterface() == xFrame ) 873 { 874 pFrame = pFr; 875 break; 876 } 877 878 pFr = SfxFrame::GetNext( *pFr ); 879 } 880 } 881 } 882 } 883 } 884 catch(Exception&) 885 { 886 OSL_ENSURE(0,"SfxFrame::CreateWorkWindow_Impl: Exception cachted. Please try to submit a repoducable bug !"); 887 } 888 } 889 890 pImp->pWorkWin = new SfxFrameWorkWin_Impl( &pFrame->GetWindow(), this, pFrame ); 891 } 892 893 void SfxFrame::GrabFocusOnComponent_Impl() 894 { 895 if ( pImp->bReleasingComponent ) 896 { 897 GetWindow().GrabFocus(); 898 return; 899 } 900 901 Window* pFocusWindow = &GetWindow(); 902 if ( GetCurrentViewFrame() && GetCurrentViewFrame()->GetViewShell() && GetCurrentViewFrame()->GetViewShell()->GetWindow() ) 903 pFocusWindow = GetCurrentViewFrame()->GetViewShell()->GetWindow(); 904 905 if( !pFocusWindow->HasChildPathFocus() ) 906 pFocusWindow->GrabFocus(); 907 } 908 909 void SfxFrame::ReleasingComponent_Impl( sal_Bool bSet ) 910 { 911 pImp->bReleasingComponent = bSet; 912 } 913 914 sal_Bool SfxFrame::IsInPlace() const 915 { 916 return pImp->bInPlace; 917 } 918 919 void SfxFrame::SetInPlace_Impl( sal_Bool bSet ) 920 { 921 pImp->bInPlace = bSet; 922 } 923 924 void SfxFrame::Resize() 925 { 926 if ( IsClosing_Impl() ) 927 return; 928 929 if ( OwnsBindings_Impl() ) 930 { 931 if ( IsInPlace() ) 932 { 933 SetToolSpaceBorderPixel_Impl( SvBorder() ); 934 } 935 else 936 { 937 // check for IPClient that contains UIactive object or object that is currently UI activating 938 SfxWorkWindow *pWork = GetWorkWindow_Impl(); 939 SfxInPlaceClient* pClient = GetCurrentViewFrame()->GetViewShell() ? GetCurrentViewFrame()->GetViewShell()->GetUIActiveIPClient_Impl() : 0; 940 if ( pClient ) 941 { 942 uno::Reference < lang::XUnoTunnel > xObj( pClient->GetObject()->getComponent(), uno::UNO_QUERY ); 943 uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() ); 944 sal_Int64 nHandle = (xObj.is()? xObj->getSomething( aSeq ): 0); 945 if ( nHandle ) 946 { 947 SfxObjectShell* pDoc = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle )); 948 pWork = SfxViewFrame::GetFirst( pDoc )->GetFrame().GetWorkWindow_Impl(); 949 } 950 } 951 952 if ( pWork ) 953 { 954 pWork->ArrangeChilds_Impl(); 955 pWork->ShowChilds_Impl(); 956 } 957 958 // problem in presence of UIActive object: when the window is resized, but the toolspace border 959 // remains the same, setting the toolspace border at the ContainerEnvironment doesn't force a 960 // resize on the IPEnvironment; without that no resize is called for the SfxViewFrame. So always 961 // set the window size of the SfxViewFrame explicit. 962 SetToolSpaceBorderPixel_Impl( pImp->aBorder ); 963 } 964 } 965 else if ( pImp->pCurrentViewFrame ) 966 { 967 pImp->pCurrentViewFrame->GetWindow().SetSizePixel( GetWindow().GetOutputSizePixel() ); 968 } 969 970 } 971 972 SfxFrame* SfxFrame::GetFirst() 973 { 974 if ( !pFramesArr_Impl ) 975 return 0; 976 return pFramesArr_Impl->Count() ? pFramesArr_Impl->GetObject(0) : 0; 977 } 978 979 SfxFrame* SfxFrame::GetNext( SfxFrame& rFrame ) 980 { 981 sal_uInt16 nPos = pFramesArr_Impl->GetPos( &rFrame ); 982 if ( nPos+1 < pFramesArr_Impl->Count() ) 983 return pFramesArr_Impl->GetObject(nPos+1); 984 else 985 return NULL; 986 } 987 988 const SfxPoolItem* SfxFrame::OpenDocumentSynchron( SfxItemSet& i_rSet, const Reference< XFrame >& i_rTargetFrame ) 989 { 990 i_rSet.Put( SfxUnoFrameItem( SID_FILLFRAME, i_rTargetFrame ) ); 991 i_rSet.ClearItem( SID_TARGETNAME ); 992 return SFX_APP()->GetDispatcher_Impl()->Execute( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, i_rSet ); 993 } 994 995