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