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