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_framework.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 32*cdf0e10cSrcweir // my own includes 33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 34*cdf0e10cSrcweir #include <helper/dockingareadefaultacceptor.hxx> 35*cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 38*cdf0e10cSrcweir // interface includes 39*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 40*cdf0e10cSrcweir #include <com/sun/star/awt/XDevice.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/awt/XLayoutConstrains.hpp> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 45*cdf0e10cSrcweir // includes of other projects 46*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include <vcl/svapp.hxx> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 51*cdf0e10cSrcweir // namespace 52*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir namespace framework{ 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir using namespace ::com::sun::star::container ; 57*cdf0e10cSrcweir using namespace ::com::sun::star::frame ; 58*cdf0e10cSrcweir using namespace ::com::sun::star::lang ; 59*cdf0e10cSrcweir using namespace ::com::sun::star::uno ; 60*cdf0e10cSrcweir using namespace ::cppu ; 61*cdf0e10cSrcweir using namespace ::osl ; 62*cdf0e10cSrcweir using namespace ::rtl ; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 65*cdf0e10cSrcweir // non exported const 66*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 69*cdf0e10cSrcweir // non exported definitions 70*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 73*cdf0e10cSrcweir // declarations 74*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir //***************************************************************************************************************** 77*cdf0e10cSrcweir // constructor 78*cdf0e10cSrcweir //***************************************************************************************************************** 79*cdf0e10cSrcweir DockingAreaDefaultAcceptor::DockingAreaDefaultAcceptor( const css::uno::Reference< XFrame >& xOwner ) 80*cdf0e10cSrcweir // Init baseclasses first 81*cdf0e10cSrcweir : ThreadHelpBase ( &Application::GetSolarMutex() ) 82*cdf0e10cSrcweir // Init member 83*cdf0e10cSrcweir , m_xOwner ( xOwner ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir //***************************************************************************************************************** 88*cdf0e10cSrcweir // destructor 89*cdf0e10cSrcweir //***************************************************************************************************************** 90*cdf0e10cSrcweir DockingAreaDefaultAcceptor::~DockingAreaDefaultAcceptor() 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir //***************************************************************************************************************** 95*cdf0e10cSrcweir // XDockingAreaAcceptor 96*cdf0e10cSrcweir //***************************************************************************************************************** 97*cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > SAL_CALL DockingAreaDefaultAcceptor::getContainerWindow() throw (css::uno::RuntimeException) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir // Ready for multithreading 100*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir // Try to "lock" the frame for access to taskscontainer. 103*cdf0e10cSrcweir css::uno::Reference< XFrame > xFrame( m_xOwner.get(), UNO_QUERY ); 104*cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xContainerWindow( xFrame->getContainerWindow() ); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir return xContainerWindow; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir sal_Bool SAL_CALL DockingAreaDefaultAcceptor::requestDockingAreaSpace( const css::awt::Rectangle& RequestedSpace ) throw (css::uno::RuntimeException) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir // Ready for multithreading 112*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir // Try to "lock" the frame for access to taskscontainer. 115*cdf0e10cSrcweir css::uno::Reference< XFrame > xFrame( m_xOwner.get(), UNO_QUERY ); 116*cdf0e10cSrcweir aGuard.unlock(); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir if ( xFrame.is() == sal_True ) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xContainerWindow( xFrame->getContainerWindow() ); 121*cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xComponentWindow( xFrame->getComponentWindow() ); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir if (( xContainerWindow.is() == sal_True ) && 124*cdf0e10cSrcweir ( xComponentWindow.is() == sal_True ) ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir css::uno::Reference< css::awt::XDevice > xDevice( xContainerWindow, css::uno::UNO_QUERY ); 127*cdf0e10cSrcweir // Convert relativ size to output size. 128*cdf0e10cSrcweir css::awt::Rectangle aRectangle = xContainerWindow->getPosSize(); 129*cdf0e10cSrcweir css::awt::DeviceInfo aInfo = xDevice->getInfo(); 130*cdf0e10cSrcweir css::awt::Size aSize ( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset , 131*cdf0e10cSrcweir aRectangle.Height - aInfo.TopInset - aInfo.BottomInset ); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir // client size of container window 134*cdf0e10cSrcweir // css::uno::Reference< css::awt::XLayoutConstrains > xLayoutContrains( xComponentWindow, css::uno::UNO_QUERY ); 135*cdf0e10cSrcweir css::awt::Size aMinSize( 0, 0 ); // = xLayoutContrains->getMinimumSize(); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir // Check if request border space would decrease component window size below minimum size 138*cdf0e10cSrcweir if ((( aSize.Width - RequestedSpace.X - RequestedSpace.Width ) < aMinSize.Width ) || 139*cdf0e10cSrcweir (( aSize.Height - RequestedSpace.Y - RequestedSpace.Height ) < aMinSize.Height ) ) 140*cdf0e10cSrcweir return sal_False; 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir return sal_True; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir return sal_False; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir void SAL_CALL DockingAreaDefaultAcceptor::setDockingAreaSpace( const css::awt::Rectangle& BorderSpace ) throw (css::uno::RuntimeException) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir // Ready for multithreading 152*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir // Try to "lock" the frame for access to taskscontainer. 155*cdf0e10cSrcweir css::uno::Reference< XFrame > xFrame( m_xOwner.get(), UNO_QUERY ); 156*cdf0e10cSrcweir if ( xFrame.is() == sal_True ) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xContainerWindow( xFrame->getContainerWindow() ); 159*cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xComponentWindow( xFrame->getComponentWindow() ); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir if (( xContainerWindow.is() == sal_True ) && 162*cdf0e10cSrcweir ( xComponentWindow.is() == sal_True ) ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir css::uno::Reference< css::awt::XDevice > xDevice( xContainerWindow, css::uno::UNO_QUERY ); 165*cdf0e10cSrcweir // Convert relativ size to output size. 166*cdf0e10cSrcweir css::awt::Rectangle aRectangle = xContainerWindow->getPosSize(); 167*cdf0e10cSrcweir css::awt::DeviceInfo aInfo = xDevice->getInfo(); 168*cdf0e10cSrcweir css::awt::Size aSize ( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset , 169*cdf0e10cSrcweir aRectangle.Height - aInfo.TopInset - aInfo.BottomInset ); 170*cdf0e10cSrcweir // client size of container window 171*cdf0e10cSrcweir // css::uno::Reference< css::awt::XLayoutConstrains > xLayoutContrains( xComponentWindow, css::uno::UNO_QUERY ); 172*cdf0e10cSrcweir css::awt::Size aMinSize( 0, 0 );// = xLayoutContrains->getMinimumSize(); 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir // Check if request border space would decrease component window size below minimum size 175*cdf0e10cSrcweir sal_Int32 nWidth = aSize.Width - BorderSpace.X - BorderSpace.Width; 176*cdf0e10cSrcweir sal_Int32 nHeight = aSize.Height - BorderSpace.Y - BorderSpace.Height; 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir if (( nWidth > aMinSize.Width ) && ( nHeight > aMinSize.Height )) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir // Resize our component window. 181*cdf0e10cSrcweir xComponentWindow->setPosSize( BorderSpace.X, BorderSpace.Y, nWidth, nHeight, css::awt::PosSize::POSSIZE ); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir } // namespace framework 188