bump product version to 5.0.4.1
[LibreOffice.git] / sfx2 / source / view / frame.cxx
bloba3717740e34abe58c823ad4dc66edf2faab710b4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/embed/EmbedStates.hpp>
21 #include <com/sun/star/uno/Reference.h>
22 #include <com/sun/star/awt/XWindow.hpp>
23 #include <com/sun/star/util/XURLTransformer.hpp>
24 #include <com/sun/star/util/XCloseable.hpp>
25 #include <com/sun/star/util/CloseVetoException.hpp>
26 #include <com/sun/star/lang/XComponent.hpp>
27 #include <com/sun/star/lang/DisposedException.hpp>
28 #include <com/sun/star/container/XChild.hpp>
30 #include <vcl/menu.hxx>
31 #include <svl/intitem.hxx>
32 #include <vcl/splitwin.hxx>
33 #include <svl/eitem.hxx>
34 #include <svl/stritem.hxx>
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <com/sun/star/awt/PosSize.hpp>
37 #include <comphelper/processfactory.hxx>
38 #include <vcl/msgbox.hxx>
40 // due to pTopFrames
41 #include "appdata.hxx"
42 #include <sfx2/app.hxx>
43 #include <sfx2/event.hxx>
44 #include <sfx2/unoctitm.hxx>
45 #include <sfx2/frame.hxx>
46 #include "arrdecl.hxx"
47 #include <sfx2/objsh.hxx>
48 #include <sfx2/dispatch.hxx>
49 #include <sfx2/docfile.hxx>
50 #include <sfx2/docfilt.hxx>
51 #include <sfx2/frmdescr.hxx>
52 #include "openflag.hxx"
53 #include <sfx2/viewsh.hxx>
54 #include <sfx2/viewfrm.hxx>
55 #include <sfx2/request.hxx>
56 #include <sfx2/fcontnr.hxx>
57 #include "impframe.hxx"
58 #include "workwin.hxx"
59 #include <sfx2/sfxuno.hxx>
60 #include <sfx2/msgpool.hxx>
61 #include "objshimp.hxx"
62 #include <sfx2/ipclient.hxx>
63 #include <childwinimpl.hxx>
65 #ifdef DBG_UTIL
66 #include <sfx2/frmhtmlw.hxx>
67 #endif
69 using namespace com::sun::star;
71 static SfxFrameArr_Impl* pFramesArr_Impl=0;
73 using namespace ::com::sun::star::uno;
74 using namespace ::com::sun::star::util;
75 using namespace ::com::sun::star::frame;
76 using namespace ::com::sun::star::container;
78 TYPEINIT1(SfxFrame, SfxListener);
79 TYPEINIT1_AUTOFACTORY(SfxFrameItem, SfxPoolItem);
80 TYPEINIT1(SfxUsrAnyItem, SfxPoolItem);
81 TYPEINIT1_AUTOFACTORY(SfxUnoFrameItem, SfxPoolItem);
83 void SfxFrame::Construct_Impl()
85 pImp = new SfxFrame_Impl( this );
86 if ( !pFramesArr_Impl )
87 pFramesArr_Impl = new SfxFrameArr_Impl;
88 pFramesArr_Impl->push_back( this );
93 SfxFrame::~SfxFrame()
95 RemoveTopFrame_Impl( this );
96 pWindow.disposeAndClear();
98 SfxFrameArr_Impl::iterator it = std::find( pFramesArr_Impl->begin(), pFramesArr_Impl->end(), this );
99 if ( it != pFramesArr_Impl->end() )
100 pFramesArr_Impl->erase( it );
102 if ( pParentFrame )
104 pParentFrame->RemoveChildFrame_Impl( this );
105 pParentFrame = 0;
108 delete pImp->pDescr;
110 if ( pChildArr )
112 DBG_ASSERT( pChildArr->empty(), "Children are not removed!" );
113 delete pChildArr;
116 delete pImp;
119 bool SfxFrame::DoClose()
121 // Actually, one more PrepareClose is still needed!
122 bool bRet = false;
123 if ( !pImp->bClosing )
125 pImp->bClosing = true;
126 CancelTransfers();
128 // now close frame; it will be deleted if this call is successful, so don't use any members after that!
129 bRet = true;
132 Reference< XCloseable > xCloseable ( pImp->xFrame, UNO_QUERY );
133 if ( (!GetCurrentDocument() || !GetCurrentDocument()->Get_Impl()->bDisposing ) && xCloseable.is())
134 xCloseable->close(sal_True);
135 else if ( pImp->xFrame.is() )
137 Reference < XFrame > xFrame = pImp->xFrame;
138 xFrame->setComponent( Reference < com::sun::star::awt::XWindow >(), Reference < XController >() );
139 xFrame->dispose();
141 else
142 bRet = DoClose_Impl();
144 catch( ::com::sun::star::util::CloseVetoException& )
146 pImp->bClosing = false;
147 bRet = false;
149 catch( ::com::sun::star::lang::DisposedException& )
154 return bRet;
157 bool SfxFrame::DoClose_Impl()
159 SfxBindings* pBindings = NULL;
160 if ( pImp->pCurrentViewFrame )
161 pBindings = &pImp->pCurrentViewFrame->GetBindings();
163 // For internal tasks Controllers and Tools must be cleared
164 if ( pImp->pWorkWin )
165 pImp->pWorkWin->DeleteControllers_Impl();
167 if ( pImp->pCurrentViewFrame )
168 pImp->pCurrentViewFrame->Close();
170 if ( pImp->bOwnsBindings )
171 DELETEZ( pBindings );
173 bool bRet = Close();
174 DBG_ASSERT( bRet, "Impossible state: frame closes, but controller refuses!");
175 return bRet;
178 bool SfxFrame::DocIsModified_Impl()
180 if ( pImp->pCurrentViewFrame && pImp->pCurrentViewFrame->GetObjectShell() &&
181 pImp->pCurrentViewFrame->GetObjectShell()->IsModified() )
182 return true;
183 for( sal_uInt16 nPos = GetChildFrameCount(); nPos--; )
184 if( (*pChildArr)[ nPos ]->DocIsModified_Impl() )
185 return true;
186 return false;
189 bool SfxFrame::PrepareClose_Impl( bool bUI )
191 bool nRet = true;
193 // prevent recursive calls
194 if( !pImp->bPrepClosing )
196 pImp->bPrepClosing = true;
198 SfxObjectShell* pCur = GetCurrentDocument() ;
199 if( pCur )
201 // SFX components have a known behaviour
202 // First check if this frame is the only view to its current document
203 bool bOther = false;
204 for ( const SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pCur );
205 !bOther && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, pCur ) )
207 bOther = ( &pFrame->GetFrame() != this );
210 SfxGetpApp()->NotifyEvent( SfxViewEventHint(SFX_EVENT_PREPARECLOSEVIEW, GlobalEventConfig::GetEventName( GlobalEventId::PREPARECLOSEVIEW ), pCur, GetController() ) );
212 if ( bOther )
213 // if there are other views only the current view of this frame must be asked
214 nRet = GetCurrentViewFrame()->GetViewShell()->PrepareClose( bUI );
215 else
216 // otherwise ask the document
217 nRet = pCur->PrepareClose( bUI );
220 if ( nRet )
222 // if this frame has child frames, ask them too
223 for( sal_uInt16 nPos = GetChildFrameCount(); nRet && nPos--; )
224 nRet = (*pChildArr)[ nPos ]->PrepareClose_Impl( bUI );
227 pImp->bPrepClosing = false;
230 if ( nRet && pImp->pWorkWin )
231 // if closing was accepted by the component the UI subframes must be asked also
232 nRet = pImp->pWorkWin->PrepareClose_Impl();
234 return nRet;
239 SfxFrame* SfxFrame::GetChildFrame( sal_uInt16 nPos ) const
241 if ( pChildArr && pChildArr->size() > nPos )
243 DBG_ASSERT( nPos < pChildArr->size(), "Wrong Index!");
244 return (*pChildArr)[nPos];
247 return 0L;
250 void SfxFrame::RemoveChildFrame_Impl( SfxFrame* pFrame )
252 DBG_ASSERT( pChildArr, "Unknown Frame!");
253 SfxFrameArr_Impl::iterator it = std::find( pChildArr->begin(), pChildArr->end(), pFrame );
254 if ( it != pChildArr->end() )
255 pChildArr->erase( it );
258 SfxFrame& SfxFrame::GetTopFrame() const
260 const SfxFrame* pParent = this;
261 while ( pParent->pParentFrame )
262 pParent = pParent->pParentFrame;
263 return *const_cast< SfxFrame* >( pParent );
266 bool SfxFrame::IsClosing_Impl() const
268 return pImp->bClosing;
271 void SfxFrame::SetIsClosing_Impl()
273 pImp->bClosing = true;
276 sal_uInt16 SfxFrame::GetChildFrameCount() const
278 return pChildArr ? pChildArr->size() : 0;
281 void SfxFrame::CancelTransfers( bool /*bCancelLoadEnv*/ )
283 if( !pImp->bInCancelTransfers )
285 pImp->bInCancelTransfers = true;
286 SfxObjectShell* pObj = GetCurrentDocument();
287 if( pObj ) //&& !( pObj->Get_Impl()->nLoadedFlags & SfxLoadedFlags::ALL ))
289 SfxViewFrame* pFrm;
290 for( pFrm = SfxViewFrame::GetFirst( pObj );
291 pFrm && &pFrm->GetFrame() == this;
292 pFrm = SfxViewFrame::GetNext( *pFrm, pObj ) ) ;
293 // No more Frame in Document -> Cancel
294 if( !pFrm )
296 pObj->CancelTransfers();
297 GetCurrentDocument()->Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
301 // First stop multiload Frames
302 sal_uInt16 nCount = GetChildFrameCount();
303 for( sal_uInt16 n = 0; n<nCount; n++ )
304 GetChildFrame( n )->CancelTransfers();
306 // Check if StarOne-Loader should be canceled
307 SfxFrameWeakRef wFrame( this );
308 if (wFrame.Is())
309 pImp->bInCancelTransfers = false;
313 SfxViewFrame* SfxFrame::GetCurrentViewFrame() const
315 return pImp->pCurrentViewFrame;
318 SfxDispatcher* SfxFrame::GetDispatcher_Impl() const
320 if ( pImp->pCurrentViewFrame )
321 return pImp->pCurrentViewFrame->GetDispatcher();
322 return GetParentFrame()->GetDispatcher_Impl();
325 bool SfxFrame::IsAutoLoadLocked_Impl() const
327 // Its own Docucument is locked?
328 const SfxObjectShell* pObjSh = GetCurrentDocument();
329 if ( !pObjSh || !pObjSh->IsAutoLoadLocked() )
330 return false;
332 // Its children are locked?
333 for ( sal_uInt16 n = GetChildFrameCount(); n--; )
334 if ( !GetChildFrame(n)->IsAutoLoadLocked_Impl() )
335 return false;
337 // otherwise allow AutoLoad
338 return true;
341 SfxObjectShell* SfxFrame::GetCurrentDocument() const
343 return pImp->pCurrentViewFrame ?
344 pImp->pCurrentViewFrame->GetObjectShell() :
345 NULL;
348 void SfxFrame::SetCurrentViewFrame_Impl( SfxViewFrame *pFrame )
350 pImp->pCurrentViewFrame = pFrame;
353 sal_uInt32 SfxFrame::GetFrameType() const
355 return pImp->nType;
358 void SfxFrame::SetFrameType_Impl( sal_uInt32 n )
360 pImp->nType = n;
363 void SfxFrame::GetViewData_Impl()
365 // Update all modifiable data between load and unload, the
366 // fixed data is only processed once (after PrepareForDoc_Impl in
367 // updateDescriptor) to save time.
369 SfxViewFrame* pViewFrame = GetCurrentViewFrame();
370 if( pViewFrame && pViewFrame->GetViewShell() )
372 const SfxMedium *pMed = GetCurrentDocument()->GetMedium();
373 bool bReadOnly = pMed->GetOpenMode() == SFX_STREAM_READONLY;
374 GetDescriptor()->SetReadOnly( bReadOnly );
376 SfxItemSet *pSet = GetDescriptor()->GetArgs();
377 bool bGetViewData = false;
378 if ( GetController().is() && pSet->GetItemState( SID_VIEW_DATA ) != SfxItemState::SET )
380 ::com::sun::star::uno::Any aData = GetController()->getViewData();
381 pSet->Put( SfxUsrAnyItem( SID_VIEW_DATA, aData ) );
382 bGetViewData = true;
385 if ( pViewFrame->GetCurViewId() )
386 pSet->Put( SfxUInt16Item( SID_VIEW_ID, pViewFrame->GetCurViewId() ) );
387 if ( pChildArr )
389 // For Framesets also the data from the ChildViews hace to be processed
390 sal_uInt16 nCount = pChildArr->size();
391 for ( sal_uInt16 n=nCount; n>0; n--)
393 SfxFrame* pFrame = (*pChildArr)[n-1];
394 if ( bGetViewData )
395 pFrame->GetDescriptor()->GetArgs()->ClearItem( SID_VIEW_DATA );
396 pFrame->GetViewData_Impl();
402 void SfxFrame::UpdateDescriptor( SfxObjectShell *pDoc )
404 // For PrepareForDoc_Impl frames, the descriptor of the updated
405 // and new itemset to be initialized. All data fir restoring the view
406 // are thus saved. If the document be replaced, GetViewData_Impl (so)
407 // the latest information hinzugef by "added. All together then the
408 // browser-history saved in. When you activate such frame pick entry
409 // is complete itemsets and the descriptor in the OpenDoc sent;.
410 // Here only the fixed properties identified "other adjustable, the
411 // retrieved by GetViewData (saves time).
413 assert(pDoc && "NULL-Document inserted ?!");
415 GetParentFrame();
416 const SfxMedium *pMed = pDoc->GetMedium();
417 GetDescriptor()->SetActualURL( pMed->GetOrigURL() );
419 SFX_ITEMSET_ARG( pMed->GetItemSet(), pItem, SfxBoolItem, SID_EDITDOC, false );
420 bool bEditable = ( !pItem || pItem->GetValue() );
422 GetDescriptor()->SetEditable( bEditable );
424 // Mark FileOpen parameter
425 SfxItemSet* pItemSet = pMed->GetItemSet();
427 const SfxFilter* pFilter = pMed->GetOrigFilter();
428 OUString aFilter;
429 if ( pFilter )
430 aFilter = pFilter->GetFilterName();
432 SFX_ITEMSET_ARG( pItemSet, pRefererItem, SfxStringItem, SID_REFERER, false);
433 SFX_ITEMSET_ARG( pItemSet, pOptionsItem, SfxStringItem, SID_FILE_FILTEROPTIONS, false);
434 SFX_ITEMSET_ARG( pItemSet, pTitle1Item, SfxStringItem, SID_DOCINFO_TITLE, false);
436 SfxItemSet *pSet = GetDescriptor()->GetArgs();
438 // Delete all old Items
439 pSet->ClearItem();
441 if ( pRefererItem )
442 pSet->Put( *pRefererItem );
443 else
444 pSet->Put( SfxStringItem( SID_REFERER, OUString() ) );
446 if ( pOptionsItem )
447 pSet->Put( *pOptionsItem );
449 if ( pTitle1Item )
450 pSet->Put( *pTitle1Item );
452 pSet->Put( SfxStringItem( SID_FILTER_NAME, aFilter ));
457 SfxFrameDescriptor* SfxFrame::GetDescriptor() const
459 // Create a FrameDescriptor On Demand; if there is no TopLevel-Frame
460 // will result in an error, as no valid link is created.
462 if ( !pImp->pDescr )
464 DBG_ASSERT( !GetParentFrame(), "No TopLevel-Frame, but no Descriptor!" );
465 pImp->pDescr = new SfxFrameDescriptor;
466 if ( GetCurrentDocument() )
467 pImp->pDescr->SetURL( GetCurrentDocument()->GetMedium()->GetOrigURL() );
469 return pImp->pDescr;
472 void SfxFrame::GetDefaultTargetList(TargetList& rList)
474 // An empty string for 'No Target'
475 rList.push_back( OUString() );
476 rList.push_back( OUString( "_top" ) );
477 rList.push_back( OUString( "_parent" ) );
478 rList.push_back( OUString( "_blank" ) );
479 rList.push_back( OUString( "_self" ) );
482 void SfxFrame::GetTargetList( TargetList& rList ) const
484 if ( !GetParentFrame() )
486 SfxFrame::GetDefaultTargetList(rList);
489 SfxViewFrame* pView = GetCurrentViewFrame();
490 if( pView && pView->GetViewShell() && pChildArr )
492 sal_uInt16 nCount = pChildArr->size();
493 for ( sal_uInt16 n=0; n<nCount; n++)
495 SfxFrame* pFrame = (*pChildArr)[n];
496 pFrame->GetTargetList( rList );
501 bool SfxFrame::IsParent( SfxFrame *pFrame ) const
503 SfxFrame *pParent = pParentFrame;
504 while ( pParent )
506 if ( pParent == pFrame )
507 return true;
508 pParent = pParent->pParentFrame;
511 return false;
514 void SfxFrame::InsertTopFrame_Impl( SfxFrame* pFrame )
516 SfxFrameArr_Impl& rArr = *SfxGetpApp()->Get_Impl()->pTopFrames;
517 rArr.push_back( pFrame );
520 void SfxFrame::RemoveTopFrame_Impl( SfxFrame* pFrame )
522 SfxFrameArr_Impl& rArr = *SfxGetpApp()->Get_Impl()->pTopFrames;
523 SfxFrameArr_Impl::iterator it = std::find( rArr.begin(), rArr.end(), pFrame );
524 if ( it != rArr.end() )
525 rArr.erase( it );
528 SfxFrameItem::SfxFrameItem( sal_uInt16 nWhichId, SfxViewFrame *p )
529 : SfxPoolItem( nWhichId ), pFrame( p ? &p->GetFrame() : NULL )
531 wFrame = pFrame;
534 SfxFrameItem::SfxFrameItem( sal_uInt16 nWhichId, SfxFrame *p ):
535 SfxPoolItem( nWhichId ),
536 pFrame( p ), wFrame( p )
540 SfxFrameItem::SfxFrameItem( SfxFrame *p ):
541 SfxPoolItem( 0 ),
542 pFrame( p ), wFrame( p )
546 bool SfxFrameItem::operator==( const SfxPoolItem &rItem ) const
548 return static_cast<const SfxFrameItem&>(rItem).pFrame == pFrame &&
549 static_cast<const SfxFrameItem&>(rItem).wFrame == wFrame;
552 SfxPoolItem* SfxFrameItem::Clone( SfxItemPool *) const
554 SfxFrameItem* pNew = new SfxFrameItem( wFrame);
555 pNew->SetFramePtr_Impl( pFrame );
556 return pNew;
559 bool SfxFrameItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const
561 if ( wFrame )
563 rVal <<= wFrame->GetFrameInterface();
564 return true;
567 return false;
570 bool SfxFrameItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 )
572 Reference < XFrame > xFrame;
573 if ( (rVal >>= xFrame) && xFrame.is() )
575 SfxFrame* pFr = SfxFrame::GetFirst();
576 while ( pFr )
578 if ( pFr->GetFrameInterface() == xFrame )
580 wFrame = pFrame = pFr;
581 return true;
584 pFr = SfxFrame::GetNext( *pFr );
586 return true;
589 return false;
593 SfxUsrAnyItem::SfxUsrAnyItem( sal_uInt16 nWhichId, const ::com::sun::star::uno::Any& rAny )
594 : SfxPoolItem( nWhichId )
596 aValue = rAny;
599 bool SfxUsrAnyItem::operator==( const SfxPoolItem& /*rItem*/ ) const
601 return false;
604 SfxPoolItem* SfxUsrAnyItem::Clone( SfxItemPool *) const
606 return new SfxUsrAnyItem( Which(), aValue );
609 bool SfxUsrAnyItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
611 rVal = aValue;
612 return true;
615 bool SfxUsrAnyItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
617 aValue = rVal;
618 return true;
621 SfxUnoFrameItem::SfxUnoFrameItem()
622 : SfxPoolItem()
623 , m_xFrame()
627 SfxUnoFrameItem::SfxUnoFrameItem( sal_uInt16 nWhichId, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rFrame )
628 : SfxPoolItem( nWhichId )
629 , m_xFrame( i_rFrame )
633 bool SfxUnoFrameItem::operator==( const SfxPoolItem& i_rItem ) const
635 return i_rItem.ISA( SfxUnoFrameItem ) && static_cast< const SfxUnoFrameItem& >( i_rItem ).m_xFrame == m_xFrame;
638 SfxPoolItem* SfxUnoFrameItem::Clone( SfxItemPool* ) const
640 return new SfxUnoFrameItem( Which(), m_xFrame );
643 bool SfxUnoFrameItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
645 rVal <<= m_xFrame;
646 return true;
649 bool SfxUnoFrameItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
651 return ( rVal >>= m_xFrame );
654 SfxFrameIterator::SfxFrameIterator( const SfxFrame& rFrame, bool bRecur )
655 : pFrame( &rFrame )
656 , bRecursive( bRecur )
659 SfxFrame* SfxFrameIterator::FirstFrame()
661 // GetFirst starts the iteration at the first child frame
662 return pFrame->GetChildFrame( 0 );
665 SfxFrame* SfxFrameIterator::NextFrame( SfxFrame& rPrev )
667 // If recursion is requested testing is done first on Children.
668 SfxFrame *pRet = NULL;
669 if ( bRecursive )
670 pRet = rPrev.GetChildFrame( 0 );
671 if ( !pRet )
673 // In other case continue with the siblings of rPrev
674 pRet = NextSibling_Impl( rPrev );
677 return pRet;
681 SfxFrame* SfxFrameIterator::NextSibling_Impl( SfxFrame& rPrev )
683 SfxFrame *pRet = NULL;
684 if ( &rPrev != pFrame )
686 SfxFrameArr_Impl& rArr = *rPrev.pParentFrame->pChildArr;
687 SfxFrameArr_Impl::iterator it = std::find( rArr.begin(), rArr.end(), &rPrev );
688 if ( it != rArr.end() && (++it) != rArr.end() )
689 pRet = *it;
691 if ( !pRet && rPrev.pParentFrame->pParentFrame )
692 pRet = NextSibling_Impl( *rPrev.pParentFrame );
695 return pRet;
698 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > SfxFrame::GetController() const
700 if ( pImp->pCurrentViewFrame && pImp->pCurrentViewFrame->GetViewShell() )
701 return pImp->pCurrentViewFrame->GetViewShell()->GetController();
702 else
703 return ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > ();
706 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SfxFrame::GetFrameInterface() const
708 return pImp->xFrame;
711 void SfxFrame::SetFrameInterface_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame )
713 pImp->xFrame = rFrame;
714 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
715 if ( !rFrame.is() && GetCurrentViewFrame() )
716 GetCurrentViewFrame()->GetBindings().SetRecorder_Impl( xRecorder );
719 void SfxFrame::Appear()
721 if ( GetCurrentViewFrame() )
723 GetCurrentViewFrame()->Show();
724 GetWindow().Show();
725 pImp->xFrame->getContainerWindow()->setVisible( sal_True );
726 if ( pParentFrame )
727 pParentFrame->Appear();
728 Reference < ::com::sun::star::awt::XTopWindow > xTopWindow( pImp->xFrame->getContainerWindow(), UNO_QUERY );
729 if ( xTopWindow.is() )
730 xTopWindow->toFront();
734 void SfxFrame::AppearWithUpdate()
736 Appear();
737 if ( GetCurrentViewFrame() )
738 GetCurrentViewFrame()->GetDispatcher()->Update_Impl( true );
741 void SfxFrame::SetOwnsBindings_Impl( bool bSet )
743 pImp->bOwnsBindings = bSet;
746 bool SfxFrame::OwnsBindings_Impl() const
748 return pImp->bOwnsBindings;
751 void SfxFrame::SetToolSpaceBorderPixel_Impl( const SvBorder& rBorder )
753 pImp->aBorder = rBorder;
754 SfxViewFrame *pF = GetCurrentViewFrame();
755 if ( pF )
757 Point aPos ( rBorder.Left(), rBorder.Top() );
758 Size aSize( GetWindow().GetOutputSizePixel() );
759 long nDeltaX = rBorder.Left() + rBorder.Right();
760 if ( aSize.Width() > nDeltaX )
761 aSize.Width() -= nDeltaX;
762 else
763 aSize.Width() = 0;
765 long nDeltaY = rBorder.Top() + rBorder.Bottom();
766 if ( aSize.Height() > nDeltaY )
767 aSize.Height() -= nDeltaY;
768 else
769 aSize.Height() = 0;
771 if ( GetParentFrame() )
773 bool bHasTools = rBorder.Left() != rBorder.Right() || rBorder.Top() != rBorder.Bottom();
774 pF->GetWindow().SetBorderStyle( bHasTools ? WindowBorderStyle::NORMAL : WindowBorderStyle::NOBORDER );
777 pF->GetWindow().SetPosSizePixel( aPos, aSize );
781 Rectangle SfxFrame::GetTopOuterRectPixel_Impl() const
783 Size aSize( GetWindow().GetOutputSizePixel() );
784 Point aPoint;
785 return ( Rectangle ( aPoint, aSize ) );
788 SfxWorkWindow* SfxFrame::GetWorkWindow_Impl() const
790 if ( pImp->pWorkWin )
791 return pImp->pWorkWin;
792 else if ( pParentFrame )
793 return pParentFrame->GetWorkWindow_Impl();
794 else
795 return NULL;
798 void SfxFrame::CreateWorkWindow_Impl()
800 SfxFrame* pFrame = this;
802 if ( IsInPlace() )
804 // this makes sense only for inplace activated objects
807 Reference < XChild > xChild( GetCurrentDocument()->GetModel(), UNO_QUERY );
808 if ( xChild.is() )
810 Reference < XModel > xParent( xChild->getParent(), UNO_QUERY );
811 if ( xParent.is() )
813 Reference< XController > xParentCtrler = xParent->getCurrentController();
814 if ( xParentCtrler.is() )
816 Reference < XFrame > xFrame( xParentCtrler->getFrame() );
817 SfxFrame* pFr = SfxFrame::GetFirst();
818 while ( pFr )
820 if ( pFr->GetFrameInterface() == xFrame )
822 pFrame = pFr;
823 break;
826 pFr = SfxFrame::GetNext( *pFr );
832 catch(Exception&)
834 OSL_FAIL("SfxFrame::CreateWorkWindow_Impl: Exception caught. Please try to submit a reproducable bug!");
838 pImp->pWorkWin = new SfxFrameWorkWin_Impl( &pFrame->GetWindow(), this, pFrame );
841 void SfxFrame::GrabFocusOnComponent_Impl()
843 if ( pImp->bReleasingComponent )
845 GetWindow().GrabFocus();
846 return;
849 vcl::Window* pFocusWindow = &GetWindow();
850 if ( GetCurrentViewFrame() && GetCurrentViewFrame()->GetViewShell() && GetCurrentViewFrame()->GetViewShell()->GetWindow() )
851 pFocusWindow = GetCurrentViewFrame()->GetViewShell()->GetWindow();
853 if( !pFocusWindow->HasChildPathFocus() )
854 pFocusWindow->GrabFocus();
857 void SfxFrame::ReleasingComponent_Impl( bool bSet )
859 pImp->bReleasingComponent = bSet;
862 bool SfxFrame::IsInPlace() const
864 return pImp->bInPlace;
867 void SfxFrame::SetInPlace_Impl( bool bSet )
869 pImp->bInPlace = bSet;
872 void SfxFrame::Resize()
874 if ( IsClosing_Impl() )
875 return;
877 if ( OwnsBindings_Impl() )
879 if ( IsInPlace() )
881 SetToolSpaceBorderPixel_Impl( SvBorder() );
883 else
885 // check for IPClient that contains UIactive object or object that is currently UI activating
886 SfxWorkWindow *pWork = GetWorkWindow_Impl();
887 SfxInPlaceClient* pClient = GetCurrentViewFrame()->GetViewShell() ? GetCurrentViewFrame()->GetViewShell()->GetUIActiveIPClient_Impl() : 0;
888 if ( pClient )
890 uno::Reference < lang::XUnoTunnel > xObj( pClient->GetObject()->getComponent(), uno::UNO_QUERY );
891 uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
892 sal_Int64 nHandle = (xObj.is()? xObj->getSomething( aSeq ): 0);
893 if ( nHandle )
895 SfxObjectShell* pDoc = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
896 SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pDoc );
897 pWork = pFrame ? pFrame->GetFrame().GetWorkWindow_Impl() : NULL;
901 if ( pWork )
903 pWork->ArrangeChildren_Impl();
904 pWork->ShowChildren_Impl();
907 // problem in presence of UIActive object: when the window is resized, but the toolspace border
908 // remains the same, setting the toolspace border at the ContainerEnvironment doesn't force a
909 // resize on the IPEnvironment; without that no resize is called for the SfxViewFrame. So always
910 // set the window size of the SfxViewFrame explicit.
911 SetToolSpaceBorderPixel_Impl( pImp->aBorder );
914 else if ( pImp->pCurrentViewFrame )
916 pImp->pCurrentViewFrame->GetWindow().SetSizePixel( GetWindow().GetOutputSizePixel() );
921 SfxFrame* SfxFrame::GetFirst()
923 if ( !pFramesArr_Impl )
924 return 0;
925 return pFramesArr_Impl->empty() ? 0 : pFramesArr_Impl->front();
928 SfxFrame* SfxFrame::GetNext( SfxFrame& rFrame )
930 SfxFrameArr_Impl::iterator it = std::find( pFramesArr_Impl->begin(), pFramesArr_Impl->end(), &rFrame );
931 if ( it != pFramesArr_Impl->end() && (++it) != pFramesArr_Impl->end() )
932 return *it;
933 else
934 return NULL;
937 const SfxPoolItem* SfxFrame::OpenDocumentSynchron( SfxItemSet& i_rSet, const Reference< XFrame >& i_rTargetFrame )
939 i_rSet.Put( SfxUnoFrameItem( SID_FILLFRAME, i_rTargetFrame ) );
940 i_rSet.ClearItem( SID_TARGETNAME );
941 return SfxGetpApp()->GetDispatcher_Impl()->Execute( SID_OPENDOC, SfxCallMode::SYNCHRON, i_rSet );
944 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */