update dev300-m57
[ooovba.git] / sfx2 / source / dialog / partwnd.cxx
blob7625e781672229c835fb0136f5e6344da20e96ff
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: partwnd.cxx,v $
10 * $Revision: 1.22 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 // includes ******************************************************************
35 #include <com/sun/star/awt/XWindow.hpp>
36 #include <com/sun/star/task/XStatusIndicator.hpp>
37 #include <com/sun/star/uno/Reference.h>
38 #include <com/sun/star/uno/Sequence.hxx>
39 #include <com/sun/star/beans/PropertyValue.hpp>
40 #include <com/sun/star/util/URL.hpp>
41 #include <com/sun/star/frame/XFrame.hpp>
42 #include <com/sun/star/util/XCloseable.hpp>
43 #include <com/sun/star/util/CloseVetoException.hpp>
44 #include <com/sun/star/lang/XComponent.hpp>
45 #include <com/sun/star/lang/DisposedException.hpp>
46 #include <com/sun/star/frame/XController.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/awt/PosSize.hpp>
49 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
50 #include <comphelper/processfactory.hxx>
51 #endif
53 #include <toolkit/helper/vclunohelper.hxx>
55 #include <sfx2/sfxsids.hrc>
56 #include "partwnd.hxx"
57 #include <sfx2/bindings.hxx>
58 #include <sfx2/dispatch.hxx>
59 #include <sfx2/viewfrm.hxx>
60 #include <sfx2/frame.hxx>
61 #include <sfx2/sfxuno.hxx>
63 //****************************************************************************
64 // SfxPartChildWnd_Impl
65 //****************************************************************************
67 SFX_IMPL_DOCKINGWINDOW( SfxPartChildWnd_Impl, SID_BROWSER );
69 SfxPartChildWnd_Impl::SfxPartChildWnd_Impl
71 Window* pParentWnd,
72 sal_uInt16 nId,
73 SfxBindings* pBindings,
74 SfxChildWinInfo* pInfo
76 : SfxChildWindow( pParentWnd, nId )
78 // Window erzeugen
79 pWindow = new SfxPartDockWnd_Impl( pBindings, this, pParentWnd, WB_STDDOCKWIN | WB_CLIPCHILDREN | WB_SIZEABLE | WB_3DLOOK );
80 eChildAlignment = SFX_ALIGN_TOP;
81 if ( pInfo )
82 pInfo->nFlags |= SFX_CHILDWIN_FORCEDOCK;
84 ((SfxDockingWindow*)pWindow)->SetFloatingSize( Size( 175, 175 ) );
85 pWindow->SetSizePixel( Size( 175, 175 ) );
87 ( ( SfxDockingWindow* ) pWindow )->Initialize( pInfo );
88 SetHideNotDelete( TRUE );
91 SfxPartChildWnd_Impl::~SfxPartChildWnd_Impl()
93 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame = GetFrame();
95 // If xFrame=NULL release pMgr! Because this window lives longer then the manager!
96 // In these case we got a xFrame->dispose() call from outside ... and has release our
97 // frame reference in our own DisposingListener.
98 // But don't do it, if xFrame already exist. Then dispose() must come from inside ...
99 // and we need a valid pMgr for further operations ...
101 SfxPartDockWnd_Impl* pWin = (SfxPartDockWnd_Impl*) pWindow;
102 // if( pWin != NULL && !xFrame.is() )
103 // pWin->ReleaseChildWindow_Impl();
105 // Release frame and window.
106 // If frame reference is valid here ... start dieing from inside by calling dispose().
107 SetFrame( NULL );
108 pWindow = NULL;
110 if ( pWin && xFrame == pWin->GetBindings().GetActiveFrame() )
111 pWin->GetBindings().SetActiveFrame( NULL );
113 if( xFrame.is() )
117 ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable > xCloseable ( xFrame, ::com::sun::star::uno::UNO_QUERY );
118 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xDisposeable( xFrame, ::com::sun::star::uno::UNO_QUERY );
119 if (xCloseable.is())
120 xCloseable->close(sal_True);
121 else
122 if (xDisposeable.is())
123 xDisposeable->dispose();
125 catch( ::com::sun::star::util::CloseVetoException& )
128 catch( ::com::sun::star::lang::DisposedException& )
135 sal_Bool SfxPartChildWnd_Impl::QueryClose()
137 return ( (SfxPartDockWnd_Impl*)pWindow )->QueryClose();
140 //****************************************************************************
141 // SfxPartDockWnd_Impl
142 //****************************************************************************
144 SfxPartDockWnd_Impl::SfxPartDockWnd_Impl
146 SfxBindings* pBind,
147 SfxChildWindow* pChildWin,
148 Window* pParent,
149 WinBits nBits
151 : SfxDockingWindow( pBind, pChildWin, pParent, nBits )
153 ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > xFrame(
154 ::comphelper::getProcessServiceFactory()->createInstance(
155 DEFINE_CONST_UNICODE("com.sun.star.frame.Frame") ), ::com::sun::star::uno::UNO_QUERY );
156 xFrame->initialize( VCLUnoHelper::GetInterface ( this ) );
158 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropSet(
159 xFrame, ::com::sun::star::uno::UNO_QUERY );
162 const ::rtl::OUString aLayoutManager( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ));
163 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xLMPropSet;
165 ::com::sun::star::uno::Any a = xPropSet->getPropertyValue( aLayoutManager );
166 if ( a >>= xLMPropSet )
168 const ::rtl::OUString aAutomaticToolbars( RTL_CONSTASCII_USTRINGPARAM( "AutomaticToolbars" ));
169 xLMPropSet->setPropertyValue( aAutomaticToolbars, ::com::sun::star::uno::Any( sal_False ));
172 catch( ::com::sun::star::uno::RuntimeException& )
174 throw;
176 catch( ::com::sun::star::uno::Exception& )
180 pChildWin->SetFrame( xFrame );
181 if ( pBind->GetDispatcher() )
183 ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFramesSupplier >
184 xSupp ( pBind->GetDispatcher()->GetFrame()->GetFrame()->GetFrameInterface(), ::com::sun::star::uno::UNO_QUERY );
185 if ( xSupp.is() )
186 xSupp->getFrames()->append( xFrame );
188 else {
189 DBG_ERROR("Bindings without Dispatcher!");
193 //****************************************************************************
195 SfxPartDockWnd_Impl::~SfxPartDockWnd_Impl()
199 //****************************************************************************
201 Rectangle impl_Rectangle_Struct2Object( const ::com::sun::star::awt::Rectangle& aRectangleStruct )
203 return Rectangle(aRectangleStruct.X,aRectangleStruct.Y,aRectangleStruct.Width,aRectangleStruct.Height);
206 void SfxPartDockWnd_Impl::Resize()
208 /* [Beschreibung]
209 Anpassung der Gr"osse der Controls an die neue Windowgr"osse
213 SfxDockingWindow::Resize();
216 //****************************************************************************
218 sal_Bool SfxPartDockWnd_Impl::QueryClose()
220 sal_Bool bClose = sal_True;
221 SfxChildWindow* pChild = GetChildWindow_Impl();
222 if( pChild )
224 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame = pChild->GetFrame();
225 if( xFrame.is() )
227 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > xCtrl = xFrame->getController();
228 if( xCtrl.is() )
229 bClose = xCtrl->suspend( sal_True );
233 return bClose;
236 //****************************************************************************
238 long SfxPartDockWnd_Impl::Notify( NotifyEvent& rEvt )
240 if( rEvt.GetType() == EVENT_GETFOCUS )
242 SfxChildWindow* pChild = GetChildWindow_Impl();
243 if( pChild )
245 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame = pChild->GetFrame();
246 if( xFrame.is() )
247 xFrame->activate();
251 return SfxDockingWindow::Notify( rEvt );
254 void SfxPartDockWnd_Impl::FillInfo( SfxChildWinInfo& rInfo ) const
256 SfxDockingWindow::FillInfo( rInfo );
257 rInfo.bVisible = sal_False;