1*6d739b60SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*6d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6d739b60SAndrew Rist * distributed with this work for additional information 6*6d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6d739b60SAndrew Rist * "License"); you may not use this file except in compliance 9*6d739b60SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*6d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*6d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6d739b60SAndrew Rist * software distributed under the License is distributed on an 15*6d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6d739b60SAndrew Rist * KIND, either express or implied. See the License for the 17*6d739b60SAndrew Rist * specific language governing permissions and limitations 18*6d739b60SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*6d739b60SAndrew Rist *************************************************************/ 21*6d739b60SAndrew Rist 22*6d739b60SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_framework.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 28cdf0e10cSrcweir // my own includes 29cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 30cdf0e10cSrcweir #include <helper/dockingareadefaultacceptor.hxx> 31cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 34cdf0e10cSrcweir // interface includes 35cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 36cdf0e10cSrcweir #include <com/sun/star/awt/XDevice.hpp> 37cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp> 38cdf0e10cSrcweir #include <com/sun/star/awt/XLayoutConstrains.hpp> 39cdf0e10cSrcweir 40cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 41cdf0e10cSrcweir // includes of other projects 42cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 43cdf0e10cSrcweir 44cdf0e10cSrcweir #include <vcl/svapp.hxx> 45cdf0e10cSrcweir 46cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 47cdf0e10cSrcweir // namespace 48cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 49cdf0e10cSrcweir 50cdf0e10cSrcweir namespace framework{ 51cdf0e10cSrcweir 52cdf0e10cSrcweir using namespace ::com::sun::star::container ; 53cdf0e10cSrcweir using namespace ::com::sun::star::frame ; 54cdf0e10cSrcweir using namespace ::com::sun::star::lang ; 55cdf0e10cSrcweir using namespace ::com::sun::star::uno ; 56cdf0e10cSrcweir using namespace ::cppu ; 57cdf0e10cSrcweir using namespace ::osl ; 58cdf0e10cSrcweir using namespace ::rtl ; 59cdf0e10cSrcweir 60cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 61cdf0e10cSrcweir // non exported const 62cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 63cdf0e10cSrcweir 64cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 65cdf0e10cSrcweir // non exported definitions 66cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 67cdf0e10cSrcweir 68cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 69cdf0e10cSrcweir // declarations 70cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 71cdf0e10cSrcweir 72cdf0e10cSrcweir //***************************************************************************************************************** 73cdf0e10cSrcweir // constructor 74cdf0e10cSrcweir //***************************************************************************************************************** 75cdf0e10cSrcweir DockingAreaDefaultAcceptor::DockingAreaDefaultAcceptor( const css::uno::Reference< XFrame >& xOwner ) 76cdf0e10cSrcweir // Init baseclasses first 77cdf0e10cSrcweir : ThreadHelpBase ( &Application::GetSolarMutex() ) 78cdf0e10cSrcweir // Init member 79cdf0e10cSrcweir , m_xOwner ( xOwner ) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir //***************************************************************************************************************** 84cdf0e10cSrcweir // destructor 85cdf0e10cSrcweir //***************************************************************************************************************** 86cdf0e10cSrcweir DockingAreaDefaultAcceptor::~DockingAreaDefaultAcceptor() 87cdf0e10cSrcweir { 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir //***************************************************************************************************************** 91cdf0e10cSrcweir // XDockingAreaAcceptor 92cdf0e10cSrcweir //***************************************************************************************************************** 93cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > SAL_CALL DockingAreaDefaultAcceptor::getContainerWindow() throw (css::uno::RuntimeException) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir // Ready for multithreading 96cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 97cdf0e10cSrcweir 98cdf0e10cSrcweir // Try to "lock" the frame for access to taskscontainer. 99cdf0e10cSrcweir css::uno::Reference< XFrame > xFrame( m_xOwner.get(), UNO_QUERY ); 100cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xContainerWindow( xFrame->getContainerWindow() ); 101cdf0e10cSrcweir 102cdf0e10cSrcweir return xContainerWindow; 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir sal_Bool SAL_CALL DockingAreaDefaultAcceptor::requestDockingAreaSpace( const css::awt::Rectangle& RequestedSpace ) throw (css::uno::RuntimeException) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir // Ready for multithreading 108cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 109cdf0e10cSrcweir 110cdf0e10cSrcweir // Try to "lock" the frame for access to taskscontainer. 111cdf0e10cSrcweir css::uno::Reference< XFrame > xFrame( m_xOwner.get(), UNO_QUERY ); 112cdf0e10cSrcweir aGuard.unlock(); 113cdf0e10cSrcweir 114cdf0e10cSrcweir if ( xFrame.is() == sal_True ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xContainerWindow( xFrame->getContainerWindow() ); 117cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xComponentWindow( xFrame->getComponentWindow() ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir if (( xContainerWindow.is() == sal_True ) && 120cdf0e10cSrcweir ( xComponentWindow.is() == sal_True ) ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir css::uno::Reference< css::awt::XDevice > xDevice( xContainerWindow, css::uno::UNO_QUERY ); 123cdf0e10cSrcweir // Convert relativ size to output size. 124cdf0e10cSrcweir css::awt::Rectangle aRectangle = xContainerWindow->getPosSize(); 125cdf0e10cSrcweir css::awt::DeviceInfo aInfo = xDevice->getInfo(); 126cdf0e10cSrcweir css::awt::Size aSize ( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset , 127cdf0e10cSrcweir aRectangle.Height - aInfo.TopInset - aInfo.BottomInset ); 128cdf0e10cSrcweir 129cdf0e10cSrcweir // client size of container window 130cdf0e10cSrcweir // css::uno::Reference< css::awt::XLayoutConstrains > xLayoutContrains( xComponentWindow, css::uno::UNO_QUERY ); 131cdf0e10cSrcweir css::awt::Size aMinSize( 0, 0 ); // = xLayoutContrains->getMinimumSize(); 132cdf0e10cSrcweir 133cdf0e10cSrcweir // Check if request border space would decrease component window size below minimum size 134cdf0e10cSrcweir if ((( aSize.Width - RequestedSpace.X - RequestedSpace.Width ) < aMinSize.Width ) || 135cdf0e10cSrcweir (( aSize.Height - RequestedSpace.Y - RequestedSpace.Height ) < aMinSize.Height ) ) 136cdf0e10cSrcweir return sal_False; 137cdf0e10cSrcweir 138cdf0e10cSrcweir return sal_True; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir return sal_False; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir void SAL_CALL DockingAreaDefaultAcceptor::setDockingAreaSpace( const css::awt::Rectangle& BorderSpace ) throw (css::uno::RuntimeException) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir // Ready for multithreading 148cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 149cdf0e10cSrcweir 150cdf0e10cSrcweir // Try to "lock" the frame for access to taskscontainer. 151cdf0e10cSrcweir css::uno::Reference< XFrame > xFrame( m_xOwner.get(), UNO_QUERY ); 152cdf0e10cSrcweir if ( xFrame.is() == sal_True ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xContainerWindow( xFrame->getContainerWindow() ); 155cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xComponentWindow( xFrame->getComponentWindow() ); 156cdf0e10cSrcweir 157cdf0e10cSrcweir if (( xContainerWindow.is() == sal_True ) && 158cdf0e10cSrcweir ( xComponentWindow.is() == sal_True ) ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir css::uno::Reference< css::awt::XDevice > xDevice( xContainerWindow, css::uno::UNO_QUERY ); 161cdf0e10cSrcweir // Convert relativ size to output size. 162cdf0e10cSrcweir css::awt::Rectangle aRectangle = xContainerWindow->getPosSize(); 163cdf0e10cSrcweir css::awt::DeviceInfo aInfo = xDevice->getInfo(); 164cdf0e10cSrcweir css::awt::Size aSize ( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset , 165cdf0e10cSrcweir aRectangle.Height - aInfo.TopInset - aInfo.BottomInset ); 166cdf0e10cSrcweir // client size of container window 167cdf0e10cSrcweir // css::uno::Reference< css::awt::XLayoutConstrains > xLayoutContrains( xComponentWindow, css::uno::UNO_QUERY ); 168cdf0e10cSrcweir css::awt::Size aMinSize( 0, 0 );// = xLayoutContrains->getMinimumSize(); 169cdf0e10cSrcweir 170cdf0e10cSrcweir // Check if request border space would decrease component window size below minimum size 171cdf0e10cSrcweir sal_Int32 nWidth = aSize.Width - BorderSpace.X - BorderSpace.Width; 172cdf0e10cSrcweir sal_Int32 nHeight = aSize.Height - BorderSpace.Y - BorderSpace.Height; 173cdf0e10cSrcweir 174cdf0e10cSrcweir if (( nWidth > aMinSize.Width ) && ( nHeight > aMinSize.Height )) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir // Resize our component window. 177cdf0e10cSrcweir xComponentWindow->setPosSize( BorderSpace.X, BorderSpace.Y, nWidth, nHeight, css::awt::PosSize::POSSIZE ); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir } 180cdf0e10cSrcweir } 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir } // namespace framework 184