jsdialog: send message for weld::Menu
[LibreOffice.git] / framework / source / helper / dockingareadefaultacceptor.cxx
blob13afa6656e7fa82cdc971c895c1f904026cd3806
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <helper/dockingareadefaultacceptor.hxx>
22 #include <com/sun/star/awt/XDevice.hpp>
23 #include <com/sun/star/awt/PosSize.hpp>
25 #include <vcl/svapp.hxx>
27 namespace framework{
29 using namespace ::com::sun::star::frame;
30 using namespace ::com::sun::star::lang;
31 using namespace ::com::sun::star::uno;
32 using namespace ::cppu;
34 // constructor
36 DockingAreaDefaultAcceptor::DockingAreaDefaultAcceptor( const css::uno::Reference< XFrame >& xOwner )
37 : m_xOwner ( xOwner )
41 // destructor
43 DockingAreaDefaultAcceptor::~DockingAreaDefaultAcceptor()
47 // XDockingAreaAcceptor
48 css::uno::Reference< css::awt::XWindow > SAL_CALL DockingAreaDefaultAcceptor::getContainerWindow()
50 SolarMutexGuard g;
52 // Try to "lock" the frame for access to taskscontainer.
53 css::uno::Reference< XFrame > xFrame( m_xOwner );
54 //TODO: check xFrame for null?
55 css::uno::Reference< css::awt::XWindow > xContainerWindow( xFrame->getContainerWindow() );
57 return xContainerWindow;
60 sal_Bool SAL_CALL DockingAreaDefaultAcceptor::requestDockingAreaSpace( const css::awt::Rectangle& RequestedSpace )
62 // Try to "lock" the frame for access to taskscontainer.
63 css::uno::Reference< XFrame > xFrame( m_xOwner );
65 if ( !xFrame.is() )
66 return false;
68 css::uno::Reference< css::awt::XWindow > xContainerWindow( xFrame->getContainerWindow() );
69 css::uno::Reference< css::awt::XWindow > xComponentWindow( xFrame->getComponentWindow() );
71 if ( !xContainerWindow.is() || !xComponentWindow.is() )
72 return false;
74 css::uno::Reference< css::awt::XDevice > xDevice( xContainerWindow, css::uno::UNO_QUERY );
75 // Convert relative size to output size.
76 css::awt::Rectangle aRectangle = xContainerWindow->getPosSize();
77 css::awt::DeviceInfo aInfo = xDevice->getInfo();
78 css::awt::Size aSize ( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset ,
79 aRectangle.Height - aInfo.TopInset - aInfo.BottomInset );
81 css::awt::Size aMinSize( 0, 0 ); // = xLayoutConstraints->getMinimumSize();
83 // Check if request border space would decrease component window size below minimum size
84 if ((( aSize.Width - RequestedSpace.X - RequestedSpace.Width ) < aMinSize.Width ) ||
85 (( aSize.Height - RequestedSpace.Y - RequestedSpace.Height ) < aMinSize.Height ) )
86 return false;
88 return true;
91 void SAL_CALL DockingAreaDefaultAcceptor::setDockingAreaSpace( const css::awt::Rectangle& BorderSpace )
93 SolarMutexGuard g;
95 // Try to "lock" the frame for access to taskscontainer.
96 css::uno::Reference< XFrame > xFrame( m_xOwner );
97 if ( !xFrame.is() )
98 return;
100 css::uno::Reference< css::awt::XWindow > xContainerWindow( xFrame->getContainerWindow() );
101 css::uno::Reference< css::awt::XWindow > xComponentWindow( xFrame->getComponentWindow() );
103 if ( !(xContainerWindow.is() && xComponentWindow.is()) )
104 return;
106 css::uno::Reference< css::awt::XDevice > xDevice( xContainerWindow, css::uno::UNO_QUERY );
107 // Convert relative size to output size.
108 css::awt::Rectangle aRectangle = xContainerWindow->getPosSize();
109 css::awt::DeviceInfo aInfo = xDevice->getInfo();
110 css::awt::Size aSize ( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset ,
111 aRectangle.Height - aInfo.TopInset - aInfo.BottomInset );
112 css::awt::Size aMinSize( 0, 0 );// = xLayoutConstraints->getMinimumSize();
114 // Check if request border space would decrease component window size below minimum size
115 sal_Int32 nWidth = aSize.Width - BorderSpace.X - BorderSpace.Width;
116 sal_Int32 nHeight = aSize.Height - BorderSpace.Y - BorderSpace.Height;
118 if (( nWidth > aMinSize.Width ) && ( nHeight > aMinSize.Height ))
120 // Resize our component window.
121 xComponentWindow->setPosSize( BorderSpace.X, BorderSpace.Y, nWidth, nHeight, css::awt::PosSize::POSSIZE );
125 } // namespace framework
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */