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