xref: /aoo41x/main/sfx2/source/view/frame2.cxx (revision d119d52d)
1*d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d119d52dSAndrew Rist  * distributed with this work for additional information
6*d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d119d52dSAndrew Rist  *
11*d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d119d52dSAndrew Rist  *
13*d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15*d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d119d52dSAndrew Rist  * specific language governing permissions and limitations
18*d119d52dSAndrew Rist  * under the License.
19*d119d52dSAndrew Rist  *
20*d119d52dSAndrew Rist  *************************************************************/
21*d119d52dSAndrew Rist 
22*d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "impframe.hxx"
28cdf0e10cSrcweir #include "objshimp.hxx"
29cdf0e10cSrcweir #include "sfx2/sfxhelp.hxx"
30cdf0e10cSrcweir #include "workwin.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "sfx2/app.hxx"
33cdf0e10cSrcweir #include "sfx2/bindings.hxx"
34cdf0e10cSrcweir #include "sfx2/dispatch.hxx"
35cdf0e10cSrcweir #include "sfx2/docfac.hxx"
36cdf0e10cSrcweir #include "sfx2/docfile.hxx"
37cdf0e10cSrcweir #include "sfx2/event.hxx"
38cdf0e10cSrcweir #include "sfx2/objface.hxx"
39cdf0e10cSrcweir #include "sfx2/request.hxx"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <com/sun/star/awt/XWindow2.hpp>
42cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
43cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
44cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
45cdf0e10cSrcweir #include <com/sun/star/frame/XFramesSupplier.hpp>
46cdf0e10cSrcweir #include <com/sun/star/frame/XLayoutManager.hpp>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
49cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
50cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
51cdf0e10cSrcweir #include <svl/eitem.hxx>
52cdf0e10cSrcweir #include <svl/intitem.hxx>
53cdf0e10cSrcweir #include <svl/itemset.hxx>
54cdf0e10cSrcweir #include <svl/rectitem.hxx>
55cdf0e10cSrcweir #include <svl/stritem.hxx>
56cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
57cdf0e10cSrcweir #include <tools/diagnose_ex.h>
58cdf0e10cSrcweir 
59cdf0e10cSrcweir using namespace ::com::sun::star;
60cdf0e10cSrcweir using namespace ::com::sun::star::uno;
61cdf0e10cSrcweir using namespace ::com::sun::star::frame;
62cdf0e10cSrcweir using namespace ::com::sun::star::util;
63cdf0e10cSrcweir using namespace ::com::sun::star::container;
64cdf0e10cSrcweir using namespace ::com::sun::star::beans;
65cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory;
66cdf0e10cSrcweir using ::com::sun::star::lang::XComponent;
67cdf0e10cSrcweir using ::com::sun::star::frame::XComponentLoader;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir //------------------------------------------------------------------------
70cdf0e10cSrcweir 
71cdf0e10cSrcweir class SfxFrameWindow_Impl : public Window
72cdf0e10cSrcweir {
73cdf0e10cSrcweir public:
74cdf0e10cSrcweir 	SfxFrame*           pFrame;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     SfxFrameWindow_Impl( SfxFrame* pF, Window& i_rContainerWindow );
77cdf0e10cSrcweir     ~SfxFrameWindow_Impl( );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     virtual void        DataChanged( const DataChangedEvent& rDCEvt );
80cdf0e10cSrcweir 	virtual void		StateChanged( StateChangedType nStateChange );
81cdf0e10cSrcweir 	virtual long 		PreNotify( NotifyEvent& rNEvt );
82cdf0e10cSrcweir 	virtual long		Notify( NotifyEvent& rEvt );
83cdf0e10cSrcweir 	virtual void        Resize();
84cdf0e10cSrcweir     virtual void        GetFocus();
85cdf0e10cSrcweir 	void				DoResize();
86cdf0e10cSrcweir 	DECL_LINK(			CloserHdl, void* );
87cdf0e10cSrcweir };
88cdf0e10cSrcweir 
SfxFrameWindow_Impl(SfxFrame * pF,Window & i_rContainerWindow)89cdf0e10cSrcweir SfxFrameWindow_Impl::SfxFrameWindow_Impl( SfxFrame* pF, Window& i_rContainerWindow )
90cdf0e10cSrcweir         : Window( &i_rContainerWindow, WB_BORDER | WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_3DLOOK )
91cdf0e10cSrcweir         , pFrame( pF )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
~SfxFrameWindow_Impl()95cdf0e10cSrcweir SfxFrameWindow_Impl::~SfxFrameWindow_Impl( )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)99cdf0e10cSrcweir void SfxFrameWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     Window::DataChanged( rDCEvt );
102cdf0e10cSrcweir     SfxWorkWindow *pWorkWin = pFrame->GetWorkWindow_Impl();
103cdf0e10cSrcweir     if ( pWorkWin )
104cdf0e10cSrcweir         pWorkWin->DataChanged_Impl( rDCEvt );
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
Notify(NotifyEvent & rNEvt)107cdf0e10cSrcweir long SfxFrameWindow_Impl::Notify( NotifyEvent& rNEvt )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	if ( pFrame->IsClosing_Impl() || !pFrame->GetFrameInterface().is() )
110cdf0e10cSrcweir 		return sal_False;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
113cdf0e10cSrcweir     if ( !pView || !pView->GetObjectShell() )
114cdf0e10cSrcweir         return Window::Notify( rNEvt );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     if ( rNEvt.GetType() == EVENT_GETFOCUS )
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         if ( pView->GetViewShell() && !pView->GetViewShell()->GetUIActiveIPClient_Impl() && !pFrame->IsInPlace() )
119cdf0e10cSrcweir         {
120cdf0e10cSrcweir             DBG_TRACE("SfxFrame: GotFocus");
121cdf0e10cSrcweir             pView->MakeActive_Impl( sal_False );
122cdf0e10cSrcweir         }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         // TODO/LATER: do we still need this code?
125cdf0e10cSrcweir         Window* pWindow = rNEvt.GetWindow();
126cdf0e10cSrcweir         rtl::OString sHelpId;
127cdf0e10cSrcweir         while ( !sHelpId.getLength() && pWindow )
128cdf0e10cSrcweir         {
129cdf0e10cSrcweir             sHelpId = pWindow->GetHelpId();
130cdf0e10cSrcweir             pWindow = pWindow->GetParent();
131cdf0e10cSrcweir         }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         if ( sHelpId.getLength() )
134cdf0e10cSrcweir             SfxHelp::OpenHelpAgent( pFrame, sHelpId );
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 		// if focus was on an external window, the clipboard content might have been changed
137cdf0e10cSrcweir 		pView->GetBindings().Invalidate( SID_PASTE );
138cdf0e10cSrcweir 		pView->GetBindings().Invalidate( SID_PASTE_SPECIAL );
139cdf0e10cSrcweir 		return sal_True;
140cdf0e10cSrcweir 	}
141cdf0e10cSrcweir     else if( rNEvt.GetType() == EVENT_KEYINPUT )
142cdf0e10cSrcweir 	{
143cdf0e10cSrcweir         if ( pView->GetViewShell()->KeyInput( *rNEvt.GetKeyEvent() ) )
144cdf0e10cSrcweir             return sal_True;
145cdf0e10cSrcweir 	}
146cdf0e10cSrcweir     else if ( rNEvt.GetType() == EVENT_EXECUTEDIALOG /*|| rNEvt.GetType() == EVENT_INPUTDISABLE*/ )
147cdf0e10cSrcweir 	{
148cdf0e10cSrcweir         pView->SetModalMode( sal_True );
149cdf0e10cSrcweir 		return sal_True;
150cdf0e10cSrcweir 	}
151cdf0e10cSrcweir 	else if ( rNEvt.GetType() == EVENT_ENDEXECUTEDIALOG /*|| rNEvt.GetType() == EVENT_INPUTENABLE*/ )
152cdf0e10cSrcweir 	{
153cdf0e10cSrcweir 		//EnableInput( sal_True, sal_True );
154cdf0e10cSrcweir         pView->SetModalMode( sal_False );
155cdf0e10cSrcweir 		return sal_True;
156cdf0e10cSrcweir 	}
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     return Window::Notify( rNEvt );
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
PreNotify(NotifyEvent & rNEvt)161cdf0e10cSrcweir long SfxFrameWindow_Impl::PreNotify( NotifyEvent& rNEvt )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir 	sal_uInt16 nType = rNEvt.GetType();
164cdf0e10cSrcweir 	if ( nType == EVENT_KEYINPUT || nType == EVENT_KEYUP )
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir 		SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
167cdf0e10cSrcweir 		SfxViewShell* pShell = pView ? pView->GetViewShell() : NULL;
168cdf0e10cSrcweir 		if ( pShell && pShell->HasKeyListeners_Impl() && pShell->HandleNotifyEvent_Impl( rNEvt ) )
169cdf0e10cSrcweir 			return sal_True;
170cdf0e10cSrcweir 	}
171cdf0e10cSrcweir 	else if ( nType == EVENT_MOUSEBUTTONUP || nType == EVENT_MOUSEBUTTONDOWN )
172cdf0e10cSrcweir     {
173cdf0e10cSrcweir 		Window* pWindow = rNEvt.GetWindow();
174cdf0e10cSrcweir 		SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
175cdf0e10cSrcweir 		SfxViewShell* pShell = pView ? pView->GetViewShell() : NULL;
176cdf0e10cSrcweir 		if ( pShell )
177cdf0e10cSrcweir 			if ( pWindow == pShell->GetWindow() || pShell->GetWindow()->IsChild( pWindow ) )
178cdf0e10cSrcweir 				if ( pShell->HasMouseClickListeners_Impl() && pShell->HandleNotifyEvent_Impl( rNEvt ) )
179cdf0e10cSrcweir 					return sal_True;
180cdf0e10cSrcweir 	}
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 	if ( nType == EVENT_MOUSEBUTTONDOWN )
183cdf0e10cSrcweir     {
184cdf0e10cSrcweir         Window* pWindow = rNEvt.GetWindow();
185cdf0e10cSrcweir         const MouseEvent* pMEvent = rNEvt.GetMouseEvent();
186cdf0e10cSrcweir         Point aPos = pWindow->OutputToScreenPixel( pMEvent->GetPosPixel() );
187cdf0e10cSrcweir         SfxWorkWindow *pWorkWin = pFrame->GetWorkWindow_Impl();
188cdf0e10cSrcweir         if ( pWorkWin )
189cdf0e10cSrcweir             pWorkWin->EndAutoShow_Impl( aPos );
190cdf0e10cSrcweir     }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 	return Window::PreNotify( rNEvt );
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
GetFocus()195cdf0e10cSrcweir void SfxFrameWindow_Impl::GetFocus()
196cdf0e10cSrcweir {
197cdf0e10cSrcweir     if ( pFrame && !pFrame->IsClosing_Impl() && pFrame->GetCurrentViewFrame() && pFrame->GetFrameInterface().is() )
198cdf0e10cSrcweir         pFrame->GetCurrentViewFrame()->MakeActive_Impl( sal_True );
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
Resize()201cdf0e10cSrcweir void SfxFrameWindow_Impl::Resize()
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
204cdf0e10cSrcweir 		DoResize();
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
StateChanged(StateChangedType nStateChange)207cdf0e10cSrcweir void SfxFrameWindow_Impl::StateChanged( StateChangedType nStateChange )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir 	if ( nStateChange == STATE_CHANGE_INITSHOW )
210cdf0e10cSrcweir 	{
211cdf0e10cSrcweir         pFrame->pImp->bHidden = sal_False;
212cdf0e10cSrcweir         if ( pFrame->IsInPlace() )
213cdf0e10cSrcweir             // TODO/MBA: workaround for bug in LayoutManager: the final resize does not get through because the
214cdf0e10cSrcweir             // LayoutManager works asynchronously and between resize and time execution the DockingAcceptor was exchanged so that
215cdf0e10cSrcweir             // the resize event never is sent to the component
216cdf0e10cSrcweir             SetSizePixel( GetParent()->GetOutputSizePixel() );
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 		DoResize();
219cdf0e10cSrcweir         SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
220cdf0e10cSrcweir         if ( pView )
221cdf0e10cSrcweir             pView->GetBindings().GetWorkWindow_Impl()->ShowChilds_Impl();
222cdf0e10cSrcweir 	}
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     Window::StateChanged( nStateChange );
225cdf0e10cSrcweir }
226cdf0e10cSrcweir 
DoResize()227cdf0e10cSrcweir void SfxFrameWindow_Impl::DoResize()
228cdf0e10cSrcweir {
229cdf0e10cSrcweir     if ( !pFrame->pImp->bLockResize )
230cdf0e10cSrcweir         pFrame->Resize();
231cdf0e10cSrcweir }
232cdf0e10cSrcweir 
CreateBlankFrame()233cdf0e10cSrcweir Reference < XFrame > SfxFrame::CreateBlankFrame()
234cdf0e10cSrcweir {
235cdf0e10cSrcweir     Reference < XFrame > xFrame;
236cdf0e10cSrcweir     try
237cdf0e10cSrcweir     {
238cdf0e10cSrcweir         ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
239cdf0e10cSrcweir         Reference < XFrame > xDesktop( aContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW );
240cdf0e10cSrcweir         xFrame.set( xDesktop->findFrame( DEFINE_CONST_UNICODE("_blank"), 0 ), UNO_SET_THROW );
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir     catch( const Exception& )
243cdf0e10cSrcweir     {
244cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
245cdf0e10cSrcweir     }
246cdf0e10cSrcweir     return xFrame;
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
Create(SfxObjectShell & rDoc,Window & rWindow,sal_uInt16 nViewId,bool bHidden)249cdf0e10cSrcweir SfxFrame* SfxFrame::Create( SfxObjectShell& rDoc, Window& rWindow, sal_uInt16 nViewId, bool bHidden )
250cdf0e10cSrcweir {
251cdf0e10cSrcweir     SfxFrame* pFrame = NULL;
252cdf0e10cSrcweir     try
253cdf0e10cSrcweir     {
254cdf0e10cSrcweir         // create and initialize new top level frame for this window
255cdf0e10cSrcweir         ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
256cdf0e10cSrcweir         Reference < XFramesSupplier > xDesktop( aContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW );
257cdf0e10cSrcweir         Reference < XFrame > xFrame( aContext.createComponent( "com.sun.star.frame.Frame"), UNO_QUERY_THROW );
258cdf0e10cSrcweir 
259cdf0e10cSrcweir         Reference< awt::XWindow2 > xWin( VCLUnoHelper::GetInterface ( &rWindow ), uno::UNO_QUERY_THROW );
260cdf0e10cSrcweir         xFrame->initialize( xWin.get() );
261cdf0e10cSrcweir         xDesktop->getFrames()->append( xFrame );
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 	    if ( xWin->isActive() )
264cdf0e10cSrcweir             xFrame->activate();
265cdf0e10cSrcweir 
266cdf0e10cSrcweir         // create load arguments
267cdf0e10cSrcweir         Sequence< PropertyValue > aLoadArgs;
268cdf0e10cSrcweir         TransformItems( SID_OPENDOC, *rDoc.GetMedium()->GetItemSet(), aLoadArgs );
269cdf0e10cSrcweir 
270cdf0e10cSrcweir         ::comphelper::NamedValueCollection aArgs( aLoadArgs );
271cdf0e10cSrcweir         aArgs.put( "Model", rDoc.GetModel() );
272cdf0e10cSrcweir         aArgs.put( "Hidden", bHidden );
273cdf0e10cSrcweir         if ( nViewId )
274cdf0e10cSrcweir             aArgs.put( "ViewId", nViewId );
275cdf0e10cSrcweir 
276cdf0e10cSrcweir         aLoadArgs = aArgs.getPropertyValues();
277cdf0e10cSrcweir 
278cdf0e10cSrcweir         // load the doc into that frame
279cdf0e10cSrcweir         ::rtl::OUString sLoaderURL( RTL_CONSTASCII_USTRINGPARAM( "private:object" ) );
280cdf0e10cSrcweir         Reference< XComponentLoader > xLoader( xFrame, UNO_QUERY_THROW );
281cdf0e10cSrcweir         xLoader->loadComponentFromURL(
282cdf0e10cSrcweir             sLoaderURL,
283cdf0e10cSrcweir             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_self" ) ),
284cdf0e10cSrcweir             0,
285cdf0e10cSrcweir             aLoadArgs
286cdf0e10cSrcweir         );
287cdf0e10cSrcweir 
288cdf0e10cSrcweir         for (   pFrame = SfxFrame::GetFirst();
289cdf0e10cSrcweir                 pFrame;
290cdf0e10cSrcweir                 pFrame = SfxFrame::GetNext( *pFrame )
291cdf0e10cSrcweir             )
292cdf0e10cSrcweir         {
293cdf0e10cSrcweir             if ( pFrame->GetFrameInterface() == xFrame )
294cdf0e10cSrcweir                 break;
295cdf0e10cSrcweir         }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir         OSL_ENSURE( pFrame, "SfxFrame::Create: load succeeded, but no SfxFrame was created during this!" );
298cdf0e10cSrcweir     }
299cdf0e10cSrcweir     catch( const Exception& )
300cdf0e10cSrcweir     {
301cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
302cdf0e10cSrcweir     }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir     return pFrame;
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
Create(const Reference<XFrame> & i_rFrame)307cdf0e10cSrcweir SfxFrame* SfxFrame::Create( const Reference < XFrame >& i_rFrame )
308cdf0e10cSrcweir {
309cdf0e10cSrcweir     // create a new TopFrame to an external XFrame object ( wrap controller )
310cdf0e10cSrcweir     ENSURE_OR_THROW( i_rFrame.is(), "NULL frame not allowed" );
311cdf0e10cSrcweir     Window* pWindow = VCLUnoHelper::GetWindow( i_rFrame->getContainerWindow() );
312cdf0e10cSrcweir     ENSURE_OR_THROW( pWindow, "frame without container window not allowed" );
313cdf0e10cSrcweir 
314cdf0e10cSrcweir     SfxFrame* pFrame = new SfxFrame( *pWindow, false );
315cdf0e10cSrcweir     pFrame->SetFrameInterface_Impl( i_rFrame );
316cdf0e10cSrcweir     return pFrame;
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
SfxFrame(Window & i_rContainerWindow,bool i_bHidden)319cdf0e10cSrcweir SfxFrame::SfxFrame( Window& i_rContainerWindow, bool i_bHidden )
320cdf0e10cSrcweir     :pParentFrame( NULL )
321cdf0e10cSrcweir     ,pChildArr( NULL )
322cdf0e10cSrcweir     ,pImp( NULL )
323cdf0e10cSrcweir 	,pWindow( NULL )
324cdf0e10cSrcweir {
325cdf0e10cSrcweir     Construct_Impl();
326cdf0e10cSrcweir 
327cdf0e10cSrcweir     pImp->bHidden = i_bHidden;
328cdf0e10cSrcweir 	InsertTopFrame_Impl( this );
329cdf0e10cSrcweir     pImp->pExternalContainerWindow = &i_rContainerWindow;
330cdf0e10cSrcweir 
331cdf0e10cSrcweir     pWindow = new SfxFrameWindow_Impl( this, i_rContainerWindow );
332cdf0e10cSrcweir 
333cdf0e10cSrcweir     // always show pWindow, which is the ComponentWindow of the XFrame we live in
334cdf0e10cSrcweir     // nowadays, since SfxFrames can be created with an XFrame only, hiding or showing the complete XFrame
335cdf0e10cSrcweir     // is not done at level of the container window, not at SFX level. Thus, the component window can
336cdf0e10cSrcweir     // always be visible.
337cdf0e10cSrcweir     pWindow->Show();
338cdf0e10cSrcweir }
339cdf0e10cSrcweir 
SetPresentationMode(sal_Bool bSet)340cdf0e10cSrcweir void SfxFrame::SetPresentationMode( sal_Bool bSet )
341cdf0e10cSrcweir {
342cdf0e10cSrcweir     if ( GetCurrentViewFrame() )
343cdf0e10cSrcweir         GetCurrentViewFrame()->GetWindow().SetBorderStyle( bSet ? WINDOW_BORDER_NOBORDER : WINDOW_BORDER_NORMAL );
344cdf0e10cSrcweir 
345cdf0e10cSrcweir     Reference< com::sun::star::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
346cdf0e10cSrcweir     Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
347cdf0e10cSrcweir 
348cdf0e10cSrcweir 	if ( xPropSet.is() )
349cdf0e10cSrcweir 	{
350cdf0e10cSrcweir 		Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
351cdf0e10cSrcweir 		aValue >>= xLayoutManager;
352cdf0e10cSrcweir     }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir     if ( xLayoutManager.is() )
355cdf0e10cSrcweir         xLayoutManager->setVisible( !bSet ); // we don't want to have ui in presentation mode
356cdf0e10cSrcweir 
357cdf0e10cSrcweir     SetMenuBarOn_Impl( !bSet );
358cdf0e10cSrcweir     if ( GetWorkWindow_Impl() )
359cdf0e10cSrcweir         GetWorkWindow_Impl()->SetDockingAllowed( !bSet );
360cdf0e10cSrcweir     if ( GetCurrentViewFrame() )
361cdf0e10cSrcweir         GetCurrentViewFrame()->GetDispatcher()->Update_Impl( sal_True );
362cdf0e10cSrcweir }
363cdf0e10cSrcweir 
GetSystemWindow() const364cdf0e10cSrcweir SystemWindow* SfxFrame::GetSystemWindow() const
365cdf0e10cSrcweir {
366cdf0e10cSrcweir 	return GetTopWindow_Impl();
367cdf0e10cSrcweir }
368cdf0e10cSrcweir 
GetTopWindow_Impl() const369cdf0e10cSrcweir SystemWindow* SfxFrame::GetTopWindow_Impl() const
370cdf0e10cSrcweir {
371cdf0e10cSrcweir     if ( pImp->pExternalContainerWindow->IsSystemWindow() )
372cdf0e10cSrcweir         return (SystemWindow*) pImp->pExternalContainerWindow;
373cdf0e10cSrcweir     else
374cdf0e10cSrcweir         return NULL;
375cdf0e10cSrcweir }
376cdf0e10cSrcweir 
GetWindow() const377cdf0e10cSrcweir Window& SfxFrame::GetWindow() const
378cdf0e10cSrcweir {
379cdf0e10cSrcweir     return *pWindow;
380cdf0e10cSrcweir }
381cdf0e10cSrcweir 
Close()382cdf0e10cSrcweir sal_Bool SfxFrame::Close()
383cdf0e10cSrcweir {
384cdf0e10cSrcweir 	delete this;
385cdf0e10cSrcweir 	return sal_True;
386cdf0e10cSrcweir }
387cdf0e10cSrcweir 
LockResize_Impl(sal_Bool bLock)388cdf0e10cSrcweir void SfxFrame::LockResize_Impl( sal_Bool bLock )
389cdf0e10cSrcweir {
390cdf0e10cSrcweir     pImp->bLockResize = bLock;
391cdf0e10cSrcweir }
392cdf0e10cSrcweir 
IMPL_LINK(SfxFrameWindow_Impl,CloserHdl,void *,EMPTYARG)393cdf0e10cSrcweir IMPL_LINK( SfxFrameWindow_Impl, CloserHdl, void*, EMPTYARG )
394cdf0e10cSrcweir {
395cdf0e10cSrcweir 	if ( pFrame && !pFrame->PrepareClose_Impl( sal_True ) )
396cdf0e10cSrcweir 		return 0L;
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 	if ( pFrame )
399cdf0e10cSrcweir 		pFrame->GetCurrentViewFrame()->GetBindings().Execute( SID_CLOSEWIN, 0, 0, SFX_CALLMODE_ASYNCHRON );
400cdf0e10cSrcweir 	return 0L;
401cdf0e10cSrcweir }
402cdf0e10cSrcweir 
SetMenuBarOn_Impl(sal_Bool bOn)403cdf0e10cSrcweir void SfxFrame::SetMenuBarOn_Impl( sal_Bool bOn )
404cdf0e10cSrcweir {
405cdf0e10cSrcweir     pImp->bMenuBarOn = bOn;
406cdf0e10cSrcweir 
407cdf0e10cSrcweir     Reference< com::sun::star::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
408cdf0e10cSrcweir     Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
409cdf0e10cSrcweir 
410cdf0e10cSrcweir 	if ( xPropSet.is() )
411cdf0e10cSrcweir 	{
412cdf0e10cSrcweir 		Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
413cdf0e10cSrcweir 		aValue >>= xLayoutManager;
414cdf0e10cSrcweir     }
415cdf0e10cSrcweir 
416cdf0e10cSrcweir     if ( xLayoutManager.is() )
417cdf0e10cSrcweir     {
418cdf0e10cSrcweir         rtl::OUString aMenuBarURL( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ));
419cdf0e10cSrcweir 
420cdf0e10cSrcweir         if ( bOn )
421cdf0e10cSrcweir             xLayoutManager->showElement( aMenuBarURL );
422cdf0e10cSrcweir         else
423cdf0e10cSrcweir             xLayoutManager->hideElement( aMenuBarURL );
424cdf0e10cSrcweir     }
425cdf0e10cSrcweir }
426cdf0e10cSrcweir 
IsMenuBarOn_Impl() const427cdf0e10cSrcweir sal_Bool SfxFrame::IsMenuBarOn_Impl() const
428cdf0e10cSrcweir {
429cdf0e10cSrcweir     return pImp->bMenuBarOn;
430cdf0e10cSrcweir }
431cdf0e10cSrcweir 
PositionWindow_Impl(const Rectangle & rWinArea) const432cdf0e10cSrcweir void SfxFrame::PositionWindow_Impl( const Rectangle& rWinArea ) const
433cdf0e10cSrcweir {
434cdf0e10cSrcweir     Window *pWin = pImp->pExternalContainerWindow;
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 	// Groesse setzen
437cdf0e10cSrcweir     const Size aAppWindow( pImp->pExternalContainerWindow->GetDesktopRectPixel().GetSize() );
438cdf0e10cSrcweir 	Point aPos( rWinArea.TopLeft() );
439cdf0e10cSrcweir 	Size aSz( rWinArea.GetSize() );
440cdf0e10cSrcweir 	if ( aSz.Width() && aSz.Height() )
441cdf0e10cSrcweir 	{
442cdf0e10cSrcweir 		aPos.X() = Min(aPos.X(),
443cdf0e10cSrcweir 						long(aAppWindow.Width() - aSz.Width() + aSz.Width() / 2) );
444cdf0e10cSrcweir 		aPos.Y() = Min(aPos.Y(),
445cdf0e10cSrcweir 						long( aAppWindow.Height() - aSz.Height() + aSz.Height() / 2) );
446cdf0e10cSrcweir 		if ( aPos.X() + aSz.Width() <
447cdf0e10cSrcweir 				aAppWindow.Width() + aSz.Width() / 2 &&
448cdf0e10cSrcweir 				aPos.Y() + aSz.Height() <
449cdf0e10cSrcweir 				aAppWindow.Height() + aSz.Height() / 2 )
450cdf0e10cSrcweir 		{
451cdf0e10cSrcweir 			pWin->SetPosPixel( aPos );
452cdf0e10cSrcweir 			pWin->SetOutputSizePixel( aSz );
453cdf0e10cSrcweir 		}
454cdf0e10cSrcweir 	}
455cdf0e10cSrcweir }
456cdf0e10cSrcweir 
PrepareForDoc_Impl(SfxObjectShell & i_rDoc)457cdf0e10cSrcweir void SfxFrame::PrepareForDoc_Impl( SfxObjectShell& i_rDoc )
458cdf0e10cSrcweir {
459cdf0e10cSrcweir     const ::comphelper::NamedValueCollection aDocumentArgs( i_rDoc.GetModel()->getArgs() );
460cdf0e10cSrcweir 
461cdf0e10cSrcweir     // hidden?
462cdf0e10cSrcweir     OSL_ENSURE( !pImp->bHidden, "when does this happen?" );
463cdf0e10cSrcweir     pImp->bHidden = aDocumentArgs.getOrDefault( "Hidden", pImp->bHidden );
464cdf0e10cSrcweir 
465cdf0e10cSrcweir     // update our descriptor
466cdf0e10cSrcweir     UpdateDescriptor( &i_rDoc );
467cdf0e10cSrcweir 
468cdf0e10cSrcweir     // plugin mode
469cdf0e10cSrcweir     sal_Int16 nPluginMode = aDocumentArgs.getOrDefault( "PluginMode", sal_Int16( 0 ) );
470cdf0e10cSrcweir     if ( nPluginMode && ( nPluginMode != 2 ) )
471cdf0e10cSrcweir         SetInPlace_Impl( sal_True );
472cdf0e10cSrcweir }
473cdf0e10cSrcweir 
IsMarkedHidden_Impl() const474cdf0e10cSrcweir bool SfxFrame::IsMarkedHidden_Impl() const
475cdf0e10cSrcweir {
476cdf0e10cSrcweir     return pImp->bHidden;
477cdf0e10cSrcweir }
478