Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / view / frame.cxx
blob071312aefaad2061cc9e804aa8b2307847752920
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 <sfx2/appuno.hxx>
59 #include "workwin.hxx"
60 #include <sfx2/sfxuno.hxx>
61 #include <sfx2/msgpool.hxx>
62 #include "objshimp.hxx"
63 #include <sfx2/ipclient.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 SvCompatWeakHdl* SfxFrame::GetHdl()
85 return pImp->GetHdl();
88 //--------------------------------------------------------------------
89 void SfxFrame::Construct_Impl()
91 pImp = new SfxFrame_Impl( this );
92 if ( !pFramesArr_Impl )
93 pFramesArr_Impl = new SfxFrameArr_Impl;
94 pFramesArr_Impl->push_back( this );
97 //--------------------------------------------------------------------
99 SfxFrame::~SfxFrame()
101 RemoveTopFrame_Impl( this );
102 DELETEZ( pWindow );
104 SfxFrameArr_Impl::iterator it = std::find( pFramesArr_Impl->begin(), pFramesArr_Impl->end(), this );
105 if ( it != pFramesArr_Impl->end() )
106 pFramesArr_Impl->erase( it );
108 if ( pParentFrame )
110 pParentFrame->RemoveChildFrame_Impl( this );
111 pParentFrame = 0;
114 delete pImp->pDescr;
116 if ( pChildArr )
118 DBG_ASSERT( pChildArr->empty(), "Children are not removed!" );
119 delete pChildArr;
122 delete pImp;
125 sal_Bool SfxFrame::DoClose()
127 // Actually, one more PrepareClose is still needed!
128 sal_Bool bRet = sal_False;
129 if ( !pImp->bClosing )
131 pImp->bClosing = sal_True;
132 CancelTransfers();
134 // now close frame; it will be deleted if this call is successful, so don't use any members after that!
135 bRet = sal_True;
138 Reference< XCloseable > xCloseable ( pImp->xFrame, UNO_QUERY );
139 if ( (!GetCurrentDocument() || !GetCurrentDocument()->Get_Impl()->bDisposing ) && xCloseable.is())
140 xCloseable->close(sal_True);
141 else if ( pImp->xFrame.is() )
143 Reference < XFrame > xFrame = pImp->xFrame;
144 xFrame->setComponent( Reference < com::sun::star::awt::XWindow >(), Reference < XController >() );
145 xFrame->dispose();
147 else
148 bRet = DoClose_Impl();
150 catch( ::com::sun::star::util::CloseVetoException& )
152 pImp->bClosing = sal_False;
153 bRet = sal_False;
155 catch( ::com::sun::star::lang::DisposedException& )
160 return bRet;
163 sal_Bool SfxFrame::DoClose_Impl()
165 sal_Bool bRet = sal_True;
166 SfxBindings* pBindings = NULL;
167 if ( pImp->pCurrentViewFrame )
168 pBindings = &pImp->pCurrentViewFrame->GetBindings();
170 // For internal tasks Controllers and Tools must be cleared
171 if ( pImp->pWorkWin )
172 pImp->pWorkWin->DeleteControllers_Impl();
174 if ( pImp->pCurrentViewFrame )
175 bRet = pImp->pCurrentViewFrame->Close();
177 if ( pImp->bOwnsBindings )
178 DELETEZ( pBindings );
180 bRet = Close();
181 DBG_ASSERT( bRet, "Impossible state: frame closes, but controller refuses!");
182 return bRet;
185 sal_Bool SfxFrame::DocIsModified_Impl()
187 if ( pImp->pCurrentViewFrame && pImp->pCurrentViewFrame->GetObjectShell() &&
188 pImp->pCurrentViewFrame->GetObjectShell()->IsModified() )
189 return sal_True;
190 for( sal_uInt16 nPos = GetChildFrameCount(); nPos--; )
191 if( (*pChildArr)[ nPos ]->DocIsModified_Impl() )
192 return sal_True;
193 return sal_False;
196 sal_uInt16 SfxFrame::PrepareClose_Impl( sal_Bool bUI, sal_Bool bForBrowsing )
198 sal_uInt16 nRet = RET_OK;
200 // prevent recursive calls
201 if( !pImp->bPrepClosing )
203 pImp->bPrepClosing = sal_True;
205 SfxObjectShell* pCur = GetCurrentDocument() ;
206 if( pCur )
208 // SFX components have a known behaviour
209 // First check if this frame is the only view to its current document
210 int bOther = sal_False;
211 for ( const SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pCur );
212 !bOther && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, pCur ) )
214 bOther = ( &pFrame->GetFrame() != this );
217 SFX_APP()->NotifyEvent( SfxViewEventHint(SFX_EVENT_PREPARECLOSEVIEW, GlobalEventConfig::GetEventName( STR_EVENT_PREPARECLOSEVIEW ), pCur, GetController() ) );
219 if ( bOther )
220 // if there are other views only the current view of this frame must be asked
221 nRet = GetCurrentViewFrame()->GetViewShell()->PrepareClose( bUI, bForBrowsing );
222 else
223 // otherwise ask the document
224 nRet = pCur->PrepareClose( bUI, bForBrowsing );
227 if ( nRet == RET_OK )
229 // if this frame has child frames, ask them too
230 for( sal_uInt16 nPos = GetChildFrameCount(); nRet == RET_OK && nPos--; )
231 nRet = (*pChildArr)[ nPos ]->PrepareClose_Impl( bUI, bForBrowsing );
234 pImp->bPrepClosing = sal_False;
237 if ( nRet == RET_OK && pImp->pWorkWin )
238 // if closing was accepted by the component the UI subframes must be asked also
239 nRet = pImp->pWorkWin->PrepareClose_Impl();
241 return nRet;
244 //--------------------------------------------------------------------
246 SfxFrame* SfxFrame::GetChildFrame( sal_uInt16 nPos ) const
248 if ( pChildArr && pChildArr->size() > nPos )
250 DBG_ASSERT( nPos < pChildArr->size(), "Wrong Index!");
251 return (*pChildArr)[nPos];
254 return 0L;
257 void SfxFrame::RemoveChildFrame_Impl( SfxFrame* pFrame )
259 DBG_ASSERT( pChildArr, "Unknown Frame!");
260 SfxFrameArr_Impl::iterator it = std::find( pChildArr->begin(), pChildArr->end(), pFrame );
261 if ( it != pChildArr->end() )
262 pChildArr->erase( it );
265 SfxFrame& SfxFrame::GetTopFrame() const
267 const SfxFrame* pParent = this;
268 while ( pParent->pParentFrame )
269 pParent = pParent->pParentFrame;
270 return *const_cast< SfxFrame* >( pParent );
273 sal_Bool SfxFrame::IsClosing_Impl() const
275 return pImp->bClosing;
278 void SfxFrame::SetIsClosing_Impl()
280 pImp->bClosing = sal_True;
283 sal_uInt16 SfxFrame::GetChildFrameCount() const
285 return pChildArr ? pChildArr->size() : 0;
288 void SfxFrame::CancelTransfers( sal_Bool /*bCancelLoadEnv*/ )
290 if( !pImp->bInCancelTransfers )
292 pImp->bInCancelTransfers = sal_True;
293 SfxObjectShell* pObj = GetCurrentDocument();
294 if( pObj ) //&& !( pObj->Get_Impl()->nLoadedFlags & SFX_LOADED_ALL ))
296 SfxViewFrame* pFrm;
297 for( pFrm = SfxViewFrame::GetFirst( pObj );
298 pFrm && &pFrm->GetFrame() == this;
299 pFrm = SfxViewFrame::GetNext( *pFrm, pObj ) ) ;
300 // No more Frame in Document -> Cancel
301 if( !pFrm )
303 pObj->CancelTransfers();
304 GetCurrentDocument()->Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
308 // First stop multiload Frames
309 sal_uInt16 nCount = GetChildFrameCount();
310 for( sal_uInt16 n = 0; n<nCount; n++ )
311 GetChildFrame( n )->CancelTransfers();
313 // Check if StarOne-Loader should be canceled
314 SfxFrameWeak wFrame( this );
315 if (wFrame.Is())
316 pImp->bInCancelTransfers = sal_False;
320 SfxViewFrame* SfxFrame::GetCurrentViewFrame() const
322 return pImp->pCurrentViewFrame;
325 SfxDispatcher* SfxFrame::GetDispatcher_Impl() const
327 if ( pImp->pCurrentViewFrame )
328 return pImp->pCurrentViewFrame->GetDispatcher();
329 return GetParentFrame()->GetDispatcher_Impl();
332 SfxObjectShell* SfxFrame::GetCurrentDocument() const
334 return pImp->pCurrentViewFrame ?
335 pImp->pCurrentViewFrame->GetObjectShell() :
336 NULL;
339 void SfxFrame::SetCurrentViewFrame_Impl( SfxViewFrame *pFrame )
341 pImp->pCurrentViewFrame = pFrame;
344 sal_uInt32 SfxFrame::GetFrameType() const
346 return pImp->nType;
349 void SfxFrame::SetFrameType_Impl( sal_uInt32 n )
351 pImp->nType = n;
354 void SfxFrame::GetViewData_Impl()
356 // Update all modifiable data between load and unload, the
357 // fixed data is only processed once (after PrepareForDoc_Impl in
358 // updateDescriptor) to save time.
360 SfxViewFrame* pViewFrame = GetCurrentViewFrame();
361 if( pViewFrame && pViewFrame->GetViewShell() )
363 const SfxMedium *pMed = GetCurrentDocument()->GetMedium();
364 sal_Bool bReadOnly = pMed->GetOpenMode() == SFX_STREAM_READONLY;
365 GetDescriptor()->SetReadOnly( bReadOnly );
367 SfxItemSet *pSet = GetDescriptor()->GetArgs();
368 sal_Bool bGetViewData = sal_False;
369 if ( GetController().is() && pSet->GetItemState( SID_VIEW_DATA ) != SFX_ITEM_SET )
371 ::com::sun::star::uno::Any aData = GetController()->getViewData();
372 pSet->Put( SfxUsrAnyItem( SID_VIEW_DATA, aData ) );
373 bGetViewData = sal_True;
376 if ( pViewFrame->GetCurViewId() )
377 pSet->Put( SfxUInt16Item( SID_VIEW_ID, pViewFrame->GetCurViewId() ) );
378 if ( pChildArr )
380 // For Framesets also the data from the ChildViews hace to be processed
381 sal_uInt16 nCount = pChildArr->size();
382 for ( sal_uInt16 n=nCount; n>0; n--)
384 SfxFrame* pFrame = (*pChildArr)[n-1];
385 if ( bGetViewData )
386 pFrame->GetDescriptor()->GetArgs()->ClearItem( SID_VIEW_DATA );
387 pFrame->GetViewData_Impl();
393 void SfxFrame::UpdateDescriptor( SfxObjectShell *pDoc )
395 // For PrepareForDoc_Impl frames, the descriptor of the updated
396 // and new itemset to be initialized. All data fir restoring the view
397 // are thus saved. If the document be replaced, GetViewData_Impl (so)
398 // the latest information hinzugef by "added. All together then the
399 // browser-history saved in. When you activate such frame pick entry
400 // is complete itemsets and the descriptor in the OpenDoc sent;.
401 // Here only the fixed properties identified "other adjustable, the
402 // retrieved by GetViewData (saves time).
404 DBG_ASSERT( pDoc, "NULL-Document inserted ?!" );
406 GetParentFrame();
407 const SfxMedium *pMed = pDoc->GetMedium();
408 GetDescriptor()->SetActualURL( String(pMed->GetOrigURL()) );
410 SFX_ITEMSET_ARG( pMed->GetItemSet(), pItem, SfxBoolItem, SID_EDITDOC, sal_False );
411 sal_Bool bEditable = ( !pItem || pItem->GetValue() );
413 GetDescriptor()->SetEditable( bEditable );
415 // Mark FileOpen parameter
416 SfxItemSet* pItemSet = pMed->GetItemSet();
418 const SfxFilter* pFilter = pMed->GetOrigFilter();
419 String aFilter;
420 if ( pFilter )
421 aFilter = pFilter->GetFilterName();
423 SFX_ITEMSET_ARG( pItemSet, pRefererItem, SfxStringItem, SID_REFERER, sal_False);
424 SFX_ITEMSET_ARG( pItemSet, pOptionsItem, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False);
425 SFX_ITEMSET_ARG( pItemSet, pTitle1Item, SfxStringItem, SID_DOCINFO_TITLE, sal_False);
427 SfxItemSet *pSet = GetDescriptor()->GetArgs();
429 // Delete all old Items
430 pSet->ClearItem();
432 if ( pRefererItem )
433 pSet->Put( *pRefererItem );
434 else
435 pSet->Put( SfxStringItem( SID_REFERER, String() ) );
437 if ( pOptionsItem )
438 pSet->Put( *pOptionsItem );
440 if ( pTitle1Item )
441 pSet->Put( *pTitle1Item );
443 pSet->Put( SfxStringItem( SID_FILTER_NAME, aFilter ));
446 //-------------------------------------------------------------------------
448 SfxFrameDescriptor* SfxFrame::GetDescriptor() const
450 // Create a FrameDescriptor On Demand; if there is no TopLevel-Frame
451 // will result in an error, as no valid link is created.
453 if ( !pImp->pDescr )
455 DBG_ASSERT( !GetParentFrame(), "No TopLevel-Frame, but no Descriptor!" );
456 pImp->pDescr = new SfxFrameDescriptor;
457 if ( GetCurrentDocument() )
458 pImp->pDescr->SetURL( GetCurrentDocument()->GetMedium()->GetOrigURL() );
460 return pImp->pDescr;
463 //-------------------------------------------------------------------------
465 void SfxFrame::GetTargetList( TargetList& rList ) const
467 if ( !GetParentFrame() )
469 // An empty string for 'No Target'
470 rList.push_back( new String() );
471 rList.push_back( new String( "_top" ) );
472 rList.push_back( new String( "_parent" ) );
473 rList.push_back( new String( "_blank" ) );
474 rList.push_back( new String( "_self" ) );
477 SfxViewFrame* pView = GetCurrentViewFrame();
478 if( pView && pView->GetViewShell() && pChildArr )
480 sal_uInt16 nCount = pChildArr->size();
481 for ( sal_uInt16 n=0; n<nCount; n++)
483 SfxFrame* pFrame = (*pChildArr)[n];
484 pFrame->GetTargetList( rList );
489 //-------------------------------------------------------------------------
491 sal_Bool SfxFrame::IsParent( SfxFrame *pFrame ) const
493 SfxFrame *pParent = pParentFrame;
494 while ( pParent )
496 if ( pParent == pFrame )
497 return sal_True;
498 pParent = pParent->pParentFrame;
501 return sal_False;
504 void SfxFrame::InsertTopFrame_Impl( SfxFrame* pFrame )
506 SfxFrameArr_Impl& rArr = *SFX_APP()->Get_Impl()->pTopFrames;
507 rArr.push_back( pFrame );
510 void SfxFrame::RemoveTopFrame_Impl( SfxFrame* pFrame )
512 SfxFrameArr_Impl& rArr = *SFX_APP()->Get_Impl()->pTopFrames;
513 SfxFrameArr_Impl::iterator it = std::find( rArr.begin(), rArr.end(), pFrame );
514 if ( it != rArr.end() )
515 rArr.erase( it );
518 SfxFrameItem::SfxFrameItem( sal_uInt16 nWhichId, SfxViewFrame *p )
519 : SfxPoolItem( nWhichId ), pFrame( p ? &p->GetFrame() : NULL )
521 wFrame = pFrame;
524 SfxFrameItem::SfxFrameItem( sal_uInt16 nWhichId, SfxFrame *p ):
525 SfxPoolItem( nWhichId ),
526 pFrame( p ), wFrame( p )
530 SfxFrameItem::SfxFrameItem( SfxFrame *p ):
531 SfxPoolItem( 0 ),
532 pFrame( p ), wFrame( p )
536 int SfxFrameItem::operator==( const SfxPoolItem &rItem ) const
538 return ((SfxFrameItem&)rItem).pFrame == pFrame &&
539 ((SfxFrameItem&)rItem).wFrame == wFrame;
542 //--------------------------------------------------------------------
544 String SfxFrameItem::GetValueText() const
546 return String();
549 SfxPoolItem* SfxFrameItem::Clone( SfxItemPool *) const
551 SfxFrameItem* pNew = new SfxFrameItem( wFrame);
552 pNew->SetFramePtr_Impl( pFrame );
553 return pNew;
556 bool SfxFrameItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const
558 if ( wFrame )
560 rVal <<= wFrame->GetFrameInterface();
561 return sal_True;
564 return sal_False;
567 bool SfxFrameItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 )
569 Reference < XFrame > xFrame;
570 if ( (rVal >>= xFrame) && xFrame.is() )
572 SfxFrame* pFr = SfxFrame::GetFirst();
573 while ( pFr )
575 if ( pFr->GetFrameInterface() == xFrame )
577 wFrame = pFrame = pFr;
578 return sal_True;
581 pFr = SfxFrame::GetNext( *pFr );
583 return sal_True;
586 return sal_False;
590 SfxUsrAnyItem::SfxUsrAnyItem( sal_uInt16 nWhichId, const ::com::sun::star::uno::Any& rAny )
591 : SfxPoolItem( nWhichId )
593 aValue = rAny;
596 int SfxUsrAnyItem::operator==( const SfxPoolItem& /*rItem*/ ) const
598 return sal_False;
601 SfxPoolItem* SfxUsrAnyItem::Clone( SfxItemPool *) const
603 return new SfxUsrAnyItem( Which(), aValue );
606 bool SfxUsrAnyItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
608 rVal = aValue;
609 return sal_True;
612 bool SfxUsrAnyItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
614 aValue = rVal;
615 return sal_True;
618 SfxUnoFrameItem::SfxUnoFrameItem()
619 : SfxPoolItem()
620 , m_xFrame()
624 SfxUnoFrameItem::SfxUnoFrameItem( sal_uInt16 nWhichId, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rFrame )
625 : SfxPoolItem( nWhichId )
626 , m_xFrame( i_rFrame )
630 int SfxUnoFrameItem::operator==( const SfxPoolItem& i_rItem ) const
632 return i_rItem.ISA( SfxUnoFrameItem ) && static_cast< const SfxUnoFrameItem& >( i_rItem ).m_xFrame == m_xFrame;
635 SfxPoolItem* SfxUnoFrameItem::Clone( SfxItemPool* ) const
637 return new SfxUnoFrameItem( Which(), m_xFrame );
640 bool SfxUnoFrameItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
642 rVal <<= m_xFrame;
643 return sal_True;
646 bool SfxUnoFrameItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
648 return ( rVal >>= m_xFrame );
651 SfxFrameIterator::SfxFrameIterator( const SfxFrame& rFrame, sal_Bool bRecur )
652 : pFrame( &rFrame )
653 , bRecursive( bRecur )
656 SfxFrame* SfxFrameIterator::FirstFrame()
658 // GetFirst starts the iteration at the first child frame
659 return pFrame->GetChildFrame( 0 );
662 SfxFrame* SfxFrameIterator::NextFrame( SfxFrame& rPrev )
664 // If recursion is requested testing is done first on Children.
665 SfxFrame *pRet = NULL;
666 if ( bRecursive )
667 pRet = rPrev.GetChildFrame( 0 );
668 if ( !pRet )
670 // In other case continue with the siblings of rPrev
671 pRet = NextSibling_Impl( rPrev );
674 return pRet;
678 SfxFrame* SfxFrameIterator::NextSibling_Impl( SfxFrame& rPrev )
680 SfxFrame *pRet = NULL;
681 if ( &rPrev != pFrame )
683 SfxFrameArr_Impl& rArr = *rPrev.pParentFrame->pChildArr;
684 SfxFrameArr_Impl::iterator it = std::find( rArr.begin(), rArr.end(), &rPrev );
685 if ( it != rArr.end() && (++it) != rArr.end() )
686 pRet = *it;
688 if ( !pRet && rPrev.pParentFrame->pParentFrame )
689 pRet = NextSibling_Impl( *rPrev.pParentFrame );
692 return pRet;
695 sal_Bool SfxFrame::HasComponent() const
697 return sal_False;
700 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > SfxFrame::GetController() const
702 if ( pImp->pCurrentViewFrame && pImp->pCurrentViewFrame->GetViewShell() )
703 return pImp->pCurrentViewFrame->GetViewShell()->GetController();
704 else
705 return ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > ();
708 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SfxFrame::GetFrameInterface() const
710 return pImp->xFrame;
713 void SfxFrame::SetFrameInterface_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame )
715 pImp->xFrame = rFrame;
716 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
717 if ( !rFrame.is() && GetCurrentViewFrame() )
718 GetCurrentViewFrame()->GetBindings().SetRecorder_Impl( xRecorder );
721 void SfxFrame::Appear()
723 if ( GetCurrentViewFrame() )
725 GetCurrentViewFrame()->Show();
726 GetWindow().Show();
727 pImp->xFrame->getContainerWindow()->setVisible( sal_True );
728 if ( pParentFrame )
729 pParentFrame->Appear();
730 Reference < ::com::sun::star::awt::XTopWindow > xTopWindow( pImp->xFrame->getContainerWindow(), UNO_QUERY );
731 if ( xTopWindow.is() )
732 xTopWindow->toFront();
736 void SfxFrame::AppearWithUpdate()
738 Appear();
739 if ( GetCurrentViewFrame() )
740 GetCurrentViewFrame()->GetDispatcher()->Update_Impl( sal_True );
743 void SfxFrame::SetOwnsBindings_Impl( sal_Bool bSet )
745 pImp->bOwnsBindings = bSet;
748 sal_Bool SfxFrame::OwnsBindings_Impl() const
750 return pImp->bOwnsBindings;
753 void SfxFrame::SetToolSpaceBorderPixel_Impl( const SvBorder& rBorder )
755 pImp->aBorder = rBorder;
756 SfxViewFrame *pF = GetCurrentViewFrame();
757 if ( pF )
759 Point aPos ( rBorder.Left(), rBorder.Top() );
760 Size aSize( GetWindow().GetOutputSizePixel() );
761 long nDeltaX = rBorder.Left() + rBorder.Right();
762 if ( aSize.Width() > nDeltaX )
763 aSize.Width() -= nDeltaX;
764 else
765 aSize.Width() = 0;
767 long nDeltaY = rBorder.Top() + rBorder.Bottom();
768 if ( aSize.Height() > nDeltaY )
769 aSize.Height() -= nDeltaY;
770 else
771 aSize.Height() = 0;
773 if ( GetParentFrame() )
775 sal_Bool bHasTools = rBorder.Left() != rBorder.Right() || rBorder.Top() != rBorder.Bottom();
776 pF->GetWindow().SetBorderStyle( bHasTools ? WINDOW_BORDER_NORMAL : WINDOW_BORDER_NOBORDER );
779 pF->GetWindow().SetPosSizePixel( aPos, aSize );
783 Rectangle SfxFrame::GetTopOuterRectPixel_Impl() const
785 Size aSize( GetWindow().GetOutputSizePixel() );
786 Point aPoint;
787 return ( Rectangle ( aPoint, aSize ) );
790 SfxWorkWindow* SfxFrame::GetWorkWindow_Impl() const
792 if ( pImp->pWorkWin )
793 return pImp->pWorkWin;
794 else if ( pParentFrame )
795 return pParentFrame->GetWorkWindow_Impl();
796 else
797 return NULL;
800 void SfxFrame::CreateWorkWindow_Impl()
802 SfxFrame* pFrame = this;
804 if ( IsInPlace() )
806 // this makes sence only for inplace activated objects
809 Reference < XChild > xChild( GetCurrentDocument()->GetModel(), UNO_QUERY );
810 if ( xChild.is() )
812 Reference < XModel > xParent( xChild->getParent(), UNO_QUERY );
813 if ( xParent.is() )
815 Reference< XController > xParentCtrler = xParent->getCurrentController();
816 if ( xParentCtrler.is() )
818 Reference < XFrame > xFrame( xParentCtrler->getFrame() );
819 SfxFrame* pFr = SfxFrame::GetFirst();
820 while ( pFr )
822 if ( pFr->GetFrameInterface() == xFrame )
824 pFrame = pFr;
825 break;
828 pFr = SfxFrame::GetNext( *pFr );
834 catch(Exception&)
836 OSL_FAIL("SfxFrame::CreateWorkWindow_Impl: Exception cachted. Please try to submit a repoducable bug !");
840 pImp->pWorkWin = new SfxFrameWorkWin_Impl( &pFrame->GetWindow(), this, pFrame );
843 void SfxFrame::GrabFocusOnComponent_Impl()
845 if ( pImp->bReleasingComponent )
847 GetWindow().GrabFocus();
848 return;
851 Window* pFocusWindow = &GetWindow();
852 if ( GetCurrentViewFrame() && GetCurrentViewFrame()->GetViewShell() && GetCurrentViewFrame()->GetViewShell()->GetWindow() )
853 pFocusWindow = GetCurrentViewFrame()->GetViewShell()->GetWindow();
855 if( !pFocusWindow->HasChildPathFocus() )
856 pFocusWindow->GrabFocus();
859 void SfxFrame::ReleasingComponent_Impl( sal_Bool bSet )
861 pImp->bReleasingComponent = bSet;
864 sal_Bool SfxFrame::IsInPlace() const
866 return pImp->bInPlace;
869 void SfxFrame::SetInPlace_Impl( sal_Bool bSet )
871 pImp->bInPlace = bSet;
874 void SfxFrame::Resize()
876 if ( IsClosing_Impl() )
877 return;
879 if ( OwnsBindings_Impl() )
881 if ( IsInPlace() )
883 SetToolSpaceBorderPixel_Impl( SvBorder() );
885 else
887 // check for IPClient that contains UIactive object or object that is currently UI activating
888 SfxWorkWindow *pWork = GetWorkWindow_Impl();
889 SfxInPlaceClient* pClient = GetCurrentViewFrame()->GetViewShell() ? GetCurrentViewFrame()->GetViewShell()->GetUIActiveIPClient_Impl() : 0;
890 if ( pClient )
892 uno::Reference < lang::XUnoTunnel > xObj( pClient->GetObject()->getComponent(), uno::UNO_QUERY );
893 uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
894 sal_Int64 nHandle = (xObj.is()? xObj->getSomething( aSeq ): 0);
895 if ( nHandle )
897 SfxObjectShell* pDoc = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
898 pWork = SfxViewFrame::GetFirst( pDoc )->GetFrame().GetWorkWindow_Impl();
902 if ( pWork )
904 pWork->ArrangeChildren_Impl();
905 pWork->ShowChildren_Impl();
908 // problem in presence of UIActive object: when the window is resized, but the toolspace border
909 // remains the same, setting the toolspace border at the ContainerEnvironment doesn't force a
910 // resize on the IPEnvironment; without that no resize is called for the SfxViewFrame. So always
911 // set the window size of the SfxViewFrame explicit.
912 SetToolSpaceBorderPixel_Impl( pImp->aBorder );
915 else if ( pImp->pCurrentViewFrame )
917 pImp->pCurrentViewFrame->GetWindow().SetSizePixel( GetWindow().GetOutputSizePixel() );
922 SfxFrame* SfxFrame::GetFirst()
924 if ( !pFramesArr_Impl )
925 return 0;
926 return pFramesArr_Impl->empty() ? 0 : pFramesArr_Impl->front();
929 SfxFrame* SfxFrame::GetNext( SfxFrame& rFrame )
931 SfxFrameArr_Impl::iterator it = std::find( pFramesArr_Impl->begin(), pFramesArr_Impl->end(), &rFrame );
932 if ( it != pFramesArr_Impl->end() && (++it) != pFramesArr_Impl->end() )
933 return *it;
934 else
935 return NULL;
938 const SfxPoolItem* SfxFrame::OpenDocumentSynchron( SfxItemSet& i_rSet, const Reference< XFrame >& i_rTargetFrame )
940 i_rSet.Put( SfxUnoFrameItem( SID_FILLFRAME, i_rTargetFrame ) );
941 i_rSet.ClearItem( SID_TARGETNAME );
942 return SFX_APP()->GetDispatcher_Impl()->Execute( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, i_rSet );
945 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */