LibreOffice Module framework (master) 1
dockingareadefaultacceptor.cxx
Go to the documentation of this file.
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
21
22#include <com/sun/star/awt/XDevice.hpp>
23#include <com/sun/star/awt/PosSize.hpp>
24
25#include <vcl/svapp.hxx>
26
27namespace framework{
28
29using namespace ::com::sun::star::container;
30using namespace ::com::sun::star::frame;
31using namespace ::com::sun::star::lang;
32using namespace ::com::sun::star::uno;
33using namespace ::cppu;
34using namespace ::osl;
35
36// constructor
37
38DockingAreaDefaultAcceptor::DockingAreaDefaultAcceptor( const css::uno::Reference< XFrame >& xOwner )
39 : m_xOwner ( xOwner )
40{
41}
42
43// destructor
44
46{
47}
48
49// XDockingAreaAcceptor
50css::uno::Reference< css::awt::XWindow > SAL_CALL DockingAreaDefaultAcceptor::getContainerWindow()
51{
53
54 // Try to "lock" the frame for access to taskscontainer.
55 css::uno::Reference< XFrame > xFrame( m_xOwner );
56 //TODO: check xFrame for null?
57 css::uno::Reference< css::awt::XWindow > xContainerWindow( xFrame->getContainerWindow() );
58
59 return xContainerWindow;
60}
61
62sal_Bool SAL_CALL DockingAreaDefaultAcceptor::requestDockingAreaSpace( const css::awt::Rectangle& RequestedSpace )
63{
64 // Try to "lock" the frame for access to taskscontainer.
65 css::uno::Reference< XFrame > xFrame( m_xOwner );
66
67 if ( !xFrame.is() )
68 return false;
69
70 css::uno::Reference< css::awt::XWindow > xContainerWindow( xFrame->getContainerWindow() );
71 css::uno::Reference< css::awt::XWindow > xComponentWindow( xFrame->getComponentWindow() );
72
73 if ( !xContainerWindow.is() || !xComponentWindow.is() )
74 return false;
75
76 css::uno::Reference< css::awt::XDevice > xDevice( xContainerWindow, css::uno::UNO_QUERY );
77 // Convert relative size to output size.
78 css::awt::Rectangle aRectangle = xContainerWindow->getPosSize();
79 css::awt::DeviceInfo aInfo = xDevice->getInfo();
80 css::awt::Size aSize ( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset ,
81 aRectangle.Height - aInfo.TopInset - aInfo.BottomInset );
82
83 css::awt::Size aMinSize( 0, 0 ); // = xLayoutConstraints->getMinimumSize();
84
85 // Check if request border space would decrease component window size below minimum size
86 if ((( aSize.Width - RequestedSpace.X - RequestedSpace.Width ) < aMinSize.Width ) ||
87 (( aSize.Height - RequestedSpace.Y - RequestedSpace.Height ) < aMinSize.Height ) )
88 return false;
89
90 return true;
91}
92
93void SAL_CALL DockingAreaDefaultAcceptor::setDockingAreaSpace( const css::awt::Rectangle& BorderSpace )
94{
96
97 // Try to "lock" the frame for access to taskscontainer.
98 css::uno::Reference< XFrame > xFrame( m_xOwner );
99 if ( !xFrame.is() )
100 return;
101
102 css::uno::Reference< css::awt::XWindow > xContainerWindow( xFrame->getContainerWindow() );
103 css::uno::Reference< css::awt::XWindow > xComponentWindow( xFrame->getComponentWindow() );
104
105 if ( !(xContainerWindow.is() && xComponentWindow.is()) )
106 return;
107
108 css::uno::Reference< css::awt::XDevice > xDevice( xContainerWindow, css::uno::UNO_QUERY );
109 // Convert relative size to output size.
110 css::awt::Rectangle aRectangle = xContainerWindow->getPosSize();
111 css::awt::DeviceInfo aInfo = xDevice->getInfo();
112 css::awt::Size aSize ( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset ,
113 aRectangle.Height - aInfo.TopInset - aInfo.BottomInset );
114 css::awt::Size aMinSize( 0, 0 );// = xLayoutConstraints->getMinimumSize();
115
116 // Check if request border space would decrease component window size below minimum size
117 sal_Int32 nWidth = aSize.Width - BorderSpace.X - BorderSpace.Width;
118 sal_Int32 nHeight = aSize.Height - BorderSpace.Y - BorderSpace.Height;
119
120 if (( nWidth > aMinSize.Width ) && ( nHeight > aMinSize.Height ))
121 {
122 // Resize our component window.
123 xComponentWindow->setPosSize( BorderSpace.X, BorderSpace.Y, nWidth, nHeight, css::awt::PosSize::POSSIZE );
124 }
125}
126
127} // namespace framework
128
129/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL setDockingAreaSpace(const css::awt::Rectangle &BorderSpace) override
css::uno::WeakReference< css::frame::XFrame > m_xOwner
virtual sal_Bool SAL_CALL requestDockingAreaSpace(const css::awt::Rectangle &RequestedSpace) override
virtual css::uno::Reference< css::awt::XWindow > SAL_CALL getContainerWindow() override
DockingAreaDefaultAcceptor(const css::uno::Reference< css::frame::XFrame > &xOwner)
Reference< XFrame > xFrame
unsigned char sal_Bool