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