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