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 <vbahelper/vbawindowbase.hxx>
21 #include <com/sun/star/awt/PosSize.hpp>
22 #include <com/sun/star/awt/XWindow.hpp>
23 #include <com/sun/star/awt/XWindow2.hpp>
24 #include <com/sun/star/frame/XFrame.hpp>
25 #include <com/sun/star/frame/XModel.hpp>
26
27 using namespace ::com::sun::star;
28 using namespace ::ooo::vba;
29
VbaWindowBase(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const css::uno::Reference<css::frame::XModel> & xModel,const uno::Reference<frame::XController> & xController)30 VbaWindowBase::VbaWindowBase(
31 const uno::Reference< XHelperInterface >& xParent,
32 const uno::Reference< uno::XComponentContext >& xContext,
33 const css::uno::Reference< css::frame::XModel >& xModel,
34 const uno::Reference< frame::XController >& xController ) :
35 WindowBaseImpl_BASE( xParent, xContext ),
36 m_xModel( xModel, uno::UNO_SET_THROW )
37 {
38 construct( xController );
39 }
40
VbaWindowBase(uno::Sequence<uno::Any> const & args,uno::Reference<uno::XComponentContext> const & xContext)41 VbaWindowBase::VbaWindowBase( uno::Sequence< uno::Any > const & args,
42 uno::Reference< uno::XComponentContext > const & xContext ) :
43 WindowBaseImpl_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0, false ), xContext ),
44 m_xModel( getXSomethingFromArgs< frame::XModel >( args, 1, false ) )
45 {
46 construct( getXSomethingFromArgs< frame::XController >( args, 2 ) );
47 }
48
49 sal_Bool SAL_CALL
getVisible()50 VbaWindowBase::getVisible()
51 {
52 return getWindow2()->isVisible();
53 }
54
55 void SAL_CALL
setVisible(sal_Bool _visible)56 VbaWindowBase::setVisible( sal_Bool _visible )
57 {
58 getWindow2()->setVisible( _visible );
59 }
60
setPosSize(const uno::Reference<awt::XWindow> & xWindow,sal_Int32 nValue,sal_Int16 nFlag)61 static void setPosSize( const uno::Reference< awt::XWindow >& xWindow, sal_Int32 nValue, sal_Int16 nFlag )
62 {
63 css::awt::Rectangle aRect = xWindow->getPosSize();
64 switch( nFlag )
65 {
66 case css::awt::PosSize::X:
67 xWindow->setPosSize( nValue, aRect.Y, 0, 0, css::awt::PosSize::X );
68 break;
69 case css::awt::PosSize::Y:
70 xWindow->setPosSize( aRect.X, nValue, 0, 0, css::awt::PosSize::Y );
71 break;
72 case css::awt::PosSize::WIDTH:
73 xWindow->setPosSize( 0, 0, nValue, aRect.Height, css::awt::PosSize::WIDTH );
74 break;
75 case css::awt::PosSize::HEIGHT:
76 xWindow->setPosSize( 0, 0, aRect.Width, nValue, css::awt::PosSize::HEIGHT );
77 break;
78 default:
79 break;
80 }
81 }
82
83 sal_Int32 SAL_CALL
getHeight()84 VbaWindowBase::getHeight()
85 {
86 return getWindow()->getPosSize().Height;
87 }
88
89 void SAL_CALL
setHeight(sal_Int32 _height)90 VbaWindowBase::setHeight( sal_Int32 _height )
91 {
92 setPosSize( getWindow(), _height, css::awt::PosSize::HEIGHT );
93 }
94
95 sal_Int32 SAL_CALL
getLeft()96 VbaWindowBase::getLeft()
97 {
98 return getWindow()->getPosSize().X;
99 }
100
101 void SAL_CALL
setLeft(sal_Int32 _left)102 VbaWindowBase::setLeft( sal_Int32 _left )
103 {
104 setPosSize( getWindow(), _left, css::awt::PosSize::X );
105 }
106
107 sal_Int32 SAL_CALL
getTop()108 VbaWindowBase::getTop()
109 {
110 return getWindow()->getPosSize().Y;
111 }
112
113 void SAL_CALL
setTop(sal_Int32 _top)114 VbaWindowBase::setTop( sal_Int32 _top )
115 {
116 setPosSize( getWindow(), _top, css::awt::PosSize::Y );
117 }
118
119 sal_Int32 SAL_CALL
getWidth()120 VbaWindowBase::getWidth()
121 {
122 return getWindow()->getPosSize().Width;
123 }
124
125 void SAL_CALL
setWidth(sal_Int32 _width)126 VbaWindowBase::setWidth( sal_Int32 _width )
127 {
128 setPosSize( getWindow(), _width, css::awt::PosSize::WIDTH );
129 }
130
131 OUString
getServiceImplName()132 VbaWindowBase::getServiceImplName()
133 {
134 return "VbaWindowBase";
135 }
136
137 uno::Sequence< OUString >
getServiceNames()138 VbaWindowBase::getServiceNames()
139 {
140 static uno::Sequence< OUString > const aServiceNames
141 {
142 "ooo.vba.VbaWindowBase"
143 };
144 return aServiceNames;
145 }
146
getController() const147 uno::Reference< frame::XController > VbaWindowBase::getController() const
148 {
149 return uno::Reference< frame::XController >( m_xController, uno::UNO_SET_THROW );
150 }
151
getWindow() const152 uno::Reference< awt::XWindow > VbaWindowBase::getWindow() const
153 {
154 return uno::Reference< awt::XWindow >( m_xWindow, uno::UNO_SET_THROW );
155 }
156
getWindow2() const157 uno::Reference< awt::XWindow2 > VbaWindowBase::getWindow2() const
158 {
159 return uno::Reference< awt::XWindow2 >( getWindow(), uno::UNO_QUERY_THROW );
160 }
161
construct(const uno::Reference<frame::XController> & xController)162 void VbaWindowBase::construct( const uno::Reference< frame::XController >& xController )
163 {
164 if( !xController.is() ) throw uno::RuntimeException();
165 uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_SET_THROW );
166 uno::Reference< awt::XWindow > xWindow( xFrame->getContainerWindow(), uno::UNO_SET_THROW );
167 m_xController = xController;
168 m_xWindow = xWindow;
169 }
170
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
172