Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <helper/dockingareadefaultacceptor.hxx>
21 : #include <threadhelp/resetableguard.hxx>
22 :
23 : #include <com/sun/star/awt/XDevice.hpp>
24 : #include <com/sun/star/awt/PosSize.hpp>
25 : #include <com/sun/star/awt/XLayoutConstrains.hpp>
26 :
27 : #include <vcl/svapp.hxx>
28 :
29 : namespace framework{
30 :
31 : using namespace ::com::sun::star::container ;
32 : using namespace ::com::sun::star::frame ;
33 : using namespace ::com::sun::star::lang ;
34 : using namespace ::com::sun::star::uno ;
35 : using namespace ::cppu ;
36 : using namespace ::osl ;
37 :
38 : //*****************************************************************************************************************
39 : // constructor
40 : //*****************************************************************************************************************
41 240 : DockingAreaDefaultAcceptor::DockingAreaDefaultAcceptor( const css::uno::Reference< XFrame >& xOwner )
42 : // Init baseclasses first
43 240 : : ThreadHelpBase ( &Application::GetSolarMutex() )
44 : // Init member
45 240 : , m_xOwner ( xOwner )
46 : {
47 240 : }
48 :
49 : //*****************************************************************************************************************
50 : // destructor
51 : //*****************************************************************************************************************
52 126 : DockingAreaDefaultAcceptor::~DockingAreaDefaultAcceptor()
53 : {
54 126 : }
55 :
56 : //*****************************************************************************************************************
57 : // XDockingAreaAcceptor
58 : //*****************************************************************************************************************
59 303 : css::uno::Reference< css::awt::XWindow > SAL_CALL DockingAreaDefaultAcceptor::getContainerWindow() throw (css::uno::RuntimeException)
60 : {
61 : // Ready for multithreading
62 303 : ResetableGuard aGuard( m_aLock );
63 :
64 : // Try to "lock" the frame for access to taskscontainer.
65 303 : css::uno::Reference< XFrame > xFrame( m_xOwner.get(), UNO_QUERY );
66 303 : css::uno::Reference< css::awt::XWindow > xContainerWindow( xFrame->getContainerWindow() );
67 :
68 303 : return xContainerWindow;
69 : }
70 :
71 661 : sal_Bool SAL_CALL DockingAreaDefaultAcceptor::requestDockingAreaSpace( const css::awt::Rectangle& RequestedSpace ) throw (css::uno::RuntimeException)
72 : {
73 : // Ready for multithreading
74 661 : ResetableGuard aGuard( m_aLock );
75 :
76 : // Try to "lock" the frame for access to taskscontainer.
77 661 : css::uno::Reference< XFrame > xFrame( m_xOwner.get(), UNO_QUERY );
78 661 : aGuard.unlock();
79 :
80 661 : if ( xFrame.is() == sal_True )
81 : {
82 661 : css::uno::Reference< css::awt::XWindow > xContainerWindow( xFrame->getContainerWindow() );
83 661 : css::uno::Reference< css::awt::XWindow > xComponentWindow( xFrame->getComponentWindow() );
84 :
85 1322 : if (( xContainerWindow.is() == sal_True ) &&
86 661 : ( xComponentWindow.is() == sal_True ) )
87 : {
88 661 : css::uno::Reference< css::awt::XDevice > xDevice( xContainerWindow, css::uno::UNO_QUERY );
89 : // Convert relativ size to output size.
90 661 : css::awt::Rectangle aRectangle = xContainerWindow->getPosSize();
91 661 : css::awt::DeviceInfo aInfo = xDevice->getInfo();
92 : css::awt::Size aSize ( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset ,
93 661 : aRectangle.Height - aInfo.TopInset - aInfo.BottomInset );
94 :
95 661 : css::awt::Size aMinSize( 0, 0 ); // = xLayoutContrains->getMinimumSize();
96 :
97 : // Check if request border space would decrease component window size below minimum size
98 661 : if ((( aSize.Width - RequestedSpace.X - RequestedSpace.Width ) < aMinSize.Width ) ||
99 : (( aSize.Height - RequestedSpace.Y - RequestedSpace.Height ) < aMinSize.Height ) )
100 50 : return sal_False;
101 :
102 611 : return sal_True;
103 661 : }
104 : }
105 :
106 0 : return sal_False;
107 : }
108 :
109 736 : void SAL_CALL DockingAreaDefaultAcceptor::setDockingAreaSpace( const css::awt::Rectangle& BorderSpace ) throw (css::uno::RuntimeException)
110 : {
111 : // Ready for multithreading
112 736 : ResetableGuard aGuard( m_aLock );
113 :
114 : // Try to "lock" the frame for access to taskscontainer.
115 736 : css::uno::Reference< XFrame > xFrame( m_xOwner.get(), UNO_QUERY );
116 736 : if ( xFrame.is() == sal_True )
117 : {
118 736 : css::uno::Reference< css::awt::XWindow > xContainerWindow( xFrame->getContainerWindow() );
119 736 : css::uno::Reference< css::awt::XWindow > xComponentWindow( xFrame->getComponentWindow() );
120 :
121 1472 : if (( xContainerWindow.is() == sal_True ) &&
122 736 : ( xComponentWindow.is() == sal_True ) )
123 : {
124 736 : css::uno::Reference< css::awt::XDevice > xDevice( xContainerWindow, css::uno::UNO_QUERY );
125 : // Convert relativ size to output size.
126 736 : css::awt::Rectangle aRectangle = xContainerWindow->getPosSize();
127 736 : css::awt::DeviceInfo aInfo = xDevice->getInfo();
128 : css::awt::Size aSize ( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset ,
129 736 : aRectangle.Height - aInfo.TopInset - aInfo.BottomInset );
130 736 : css::awt::Size aMinSize( 0, 0 );// = xLayoutContrains->getMinimumSize();
131 :
132 : // Check if request border space would decrease component window size below minimum size
133 736 : sal_Int32 nWidth = aSize.Width - BorderSpace.X - BorderSpace.Width;
134 736 : sal_Int32 nHeight = aSize.Height - BorderSpace.Y - BorderSpace.Height;
135 :
136 736 : if (( nWidth > aMinSize.Width ) && ( nHeight > aMinSize.Height ))
137 : {
138 : // Resize our component window.
139 736 : xComponentWindow->setPosSize( BorderSpace.X, BorderSpace.Y, nWidth, nHeight, css::awt::PosSize::POSSIZE );
140 736 : }
141 736 : }
142 736 : }
143 736 : }
144 :
145 : } // namespace framework
146 :
147 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|