Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / dialog / partwnd.cxx
blobaa10a875523a3457e785e81f63fa62524fe08d21
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 // includes ******************************************************************
31 #include <com/sun/star/awt/XWindow.hpp>
32 #include <com/sun/star/task/XStatusIndicator.hpp>
33 #include <com/sun/star/uno/Reference.h>
34 #include <com/sun/star/uno/Sequence.hxx>
35 #include <com/sun/star/beans/PropertyValue.hpp>
36 #include <com/sun/star/util/URL.hpp>
37 #include <com/sun/star/frame/XFrame.hpp>
38 #include <com/sun/star/util/XCloseable.hpp>
39 #include <com/sun/star/util/CloseVetoException.hpp>
40 #include <com/sun/star/lang/XComponent.hpp>
41 #include <com/sun/star/lang/DisposedException.hpp>
42 #include <com/sun/star/frame/XController.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <com/sun/star/awt/PosSize.hpp>
45 #include <comphelper/processfactory.hxx>
47 #include <toolkit/helper/vclunohelper.hxx>
49 #include <sfx2/sfxsids.hrc>
50 #include "partwnd.hxx"
51 #include <sfx2/bindings.hxx>
52 #include <sfx2/dispatch.hxx>
53 #include <sfx2/viewfrm.hxx>
54 #include <sfx2/frame.hxx>
55 #include <sfx2/sfxuno.hxx>
57 //****************************************************************************
58 // SfxPartChildWnd_Impl
59 //****************************************************************************
61 SFX_IMPL_DOCKINGWINDOW( SfxPartChildWnd_Impl, SID_BROWSER );
63 SfxPartChildWnd_Impl::SfxPartChildWnd_Impl
65 Window* pParentWnd,
66 sal_uInt16 nId,
67 SfxBindings* pBindings,
68 SfxChildWinInfo* pInfo
70 : SfxChildWindow( pParentWnd, nId )
72 // Create Window
73 pWindow = new SfxPartDockWnd_Impl( pBindings, this, pParentWnd, WB_STDDOCKWIN | WB_CLIPCHILDREN | WB_SIZEABLE | WB_3DLOOK );
74 eChildAlignment = SFX_ALIGN_TOP;
75 if ( pInfo )
76 pInfo->nFlags |= SFX_CHILDWIN_FORCEDOCK;
78 ((SfxDockingWindow*)pWindow)->SetFloatingSize( Size( 175, 175 ) );
79 pWindow->SetSizePixel( Size( 175, 175 ) );
81 ( ( SfxDockingWindow* ) pWindow )->Initialize( pInfo );
82 SetHideNotDelete( sal_True );
85 SfxPartChildWnd_Impl::~SfxPartChildWnd_Impl()
87 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame = GetFrame();
89 // If xFrame=NULL release pMgr! Because this window lives longer then the manager!
90 // In these case we got a xFrame->dispose() call from outside ... and has release our
91 // frame reference in our own DisposingListener.
92 // But don't do it, if xFrame already exist. Then dispose() must come from inside ...
93 // and we need a valid pMgr for further operations ...
95 SfxPartDockWnd_Impl* pWin = (SfxPartDockWnd_Impl*) pWindow;
97 if ( pWin && xFrame == pWin->GetBindings().GetActiveFrame() )
98 pWin->GetBindings().SetActiveFrame( NULL );
101 sal_Bool SfxPartChildWnd_Impl::QueryClose()
103 return ( (SfxPartDockWnd_Impl*)pWindow )->QueryClose();
106 //****************************************************************************
107 // SfxPartDockWnd_Impl
108 //****************************************************************************
110 SfxPartDockWnd_Impl::SfxPartDockWnd_Impl
112 SfxBindings* pBind,
113 SfxChildWindow* pChildWin,
114 Window* pParent,
115 WinBits nBits
117 : SfxDockingWindow( pBind, pChildWin, pParent, nBits )
119 ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > xFrame(
120 ::comphelper::getProcessServiceFactory()->createInstance(
121 DEFINE_CONST_UNICODE("com.sun.star.frame.Frame") ), ::com::sun::star::uno::UNO_QUERY );
122 xFrame->initialize( VCLUnoHelper::GetInterface ( this ) );
124 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropSet(
125 xFrame, ::com::sun::star::uno::UNO_QUERY );
128 const ::rtl::OUString aLayoutManager( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ));
129 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xLMPropSet;
131 ::com::sun::star::uno::Any a = xPropSet->getPropertyValue( aLayoutManager );
132 if ( a >>= xLMPropSet )
134 const ::rtl::OUString aAutomaticToolbars( RTL_CONSTASCII_USTRINGPARAM( "AutomaticToolbars" ));
135 xLMPropSet->setPropertyValue( aAutomaticToolbars, ::com::sun::star::uno::Any( sal_False ));
138 catch( ::com::sun::star::uno::RuntimeException& )
140 throw;
142 catch( ::com::sun::star::uno::Exception& )
146 pChildWin->SetFrame( xFrame );
147 if ( pBind->GetDispatcher() )
149 ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFramesSupplier >
150 xSupp ( pBind->GetDispatcher()->GetFrame()->GetFrame().GetFrameInterface(), ::com::sun::star::uno::UNO_QUERY );
151 if ( xSupp.is() )
152 xSupp->getFrames()->append( xFrame );
154 else {
155 OSL_FAIL("Bindings without Dispatcher!");
159 //****************************************************************************
161 SfxPartDockWnd_Impl::~SfxPartDockWnd_Impl()
165 //****************************************************************************
167 void SfxPartDockWnd_Impl::Resize()
169 /* [Description]
171 Adjusting the size of the controls wrt the new window size
175 SfxDockingWindow::Resize();
178 //****************************************************************************
180 sal_Bool SfxPartDockWnd_Impl::QueryClose()
182 sal_Bool bClose = sal_True;
183 SfxChildWindow* pChild = GetChildWindow_Impl();
184 if( pChild )
186 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame = pChild->GetFrame();
187 if( xFrame.is() )
189 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > xCtrl = xFrame->getController();
190 if( xCtrl.is() )
191 bClose = xCtrl->suspend( sal_True );
195 return bClose;
198 //****************************************************************************
200 long SfxPartDockWnd_Impl::Notify( NotifyEvent& rEvt )
202 if( rEvt.GetType() == EVENT_GETFOCUS )
204 SfxChildWindow* pChild = GetChildWindow_Impl();
205 if( pChild )
207 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame = pChild->GetFrame();
208 if( xFrame.is() )
209 xFrame->activate();
213 return SfxDockingWindow::Notify( rEvt );
216 void SfxPartDockWnd_Impl::FillInfo( SfxChildWinInfo& rInfo ) const
218 SfxDockingWindow::FillInfo( rInfo );
219 rInfo.bVisible = sal_False;
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */