LibreOffice Module vbahelper (master) 1
vbawindowbase.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#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
27using namespace ::com::sun::star;
28using namespace ::ooo::vba;
29
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
41VbaWindowBase::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
49sal_Bool SAL_CALL
51{
52 return getWindow2()->isVisible();
53}
54
55void SAL_CALL
57{
58 getWindow2()->setVisible( _visible );
59}
60
61static 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
83sal_Int32 SAL_CALL
85{
86 return getWindow()->getPosSize().Height;
87}
88
89void SAL_CALL
90VbaWindowBase::setHeight( sal_Int32 _height )
91{
92 setPosSize( getWindow(), _height, css::awt::PosSize::HEIGHT );
93}
94
95sal_Int32 SAL_CALL
97{
98 return getWindow()->getPosSize().X;
99}
100
101void SAL_CALL
102VbaWindowBase::setLeft( sal_Int32 _left )
103{
104 setPosSize( getWindow(), _left, css::awt::PosSize::X );
105}
106
107sal_Int32 SAL_CALL
109{
110 return getWindow()->getPosSize().Y;
111}
112
113void SAL_CALL
114VbaWindowBase::setTop( sal_Int32 _top )
115{
116 setPosSize( getWindow(), _top, css::awt::PosSize::Y );
117}
118
119sal_Int32 SAL_CALL
121{
122 return getWindow()->getPosSize().Width;
123}
124
125void SAL_CALL
126VbaWindowBase::setWidth( sal_Int32 _width )
127{
128 setPosSize( getWindow(), _width, css::awt::PosSize::WIDTH );
129}
130
131OUString
133{
134 return "VbaWindowBase";
135}
136
137uno::Sequence< OUString >
139{
140 static uno::Sequence< OUString > const aServiceNames
141 {
142 "ooo.vba.VbaWindowBase"
143 };
144 return aServiceNames;
145}
146
147uno::Reference< frame::XController > VbaWindowBase::getController() const
148{
149 return uno::Reference< frame::XController >( m_xController, uno::UNO_SET_THROW );
150}
151
152uno::Reference< awt::XWindow > VbaWindowBase::getWindow() const
153{
154 return uno::Reference< awt::XWindow >( m_xWindow, uno::UNO_SET_THROW );
155}
156
157uno::Reference< awt::XWindow2 > VbaWindowBase::getWindow2() const
158{
159 return uno::Reference< awt::XWindow2 >( getWindow(), uno::UNO_QUERY_THROW );
160}
161
162void 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 );
168 m_xWindow = xWindow;
169}
170
171/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL setHeight(sal_Int32 _height) override
css::uno::Reference< css::awt::XWindow2 > getWindow2() const
virtual OUString getServiceImplName() override
virtual sal_Int32 SAL_CALL getTop() override
virtual void SAL_CALL setWidth(sal_Int32 _width) override
VbaWindowBase(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Reference< css::frame::XController > &xController)
void construct(const css::uno::Reference< css::frame::XController > &xController)
virtual sal_Int32 SAL_CALL getHeight() override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual void SAL_CALL setVisible(sal_Bool _visible) override
css::uno::WeakReference< css::awt::XWindow > m_xWindow
css::uno::Reference< css::awt::XWindow > getWindow() const
virtual sal_Int32 SAL_CALL getLeft() override
virtual sal_Bool SAL_CALL getVisible() override
css::uno::WeakReference< css::frame::XController > m_xController
virtual sal_Int32 SAL_CALL getWidth() override
virtual void SAL_CALL setLeft(sal_Int32 _left) override
virtual void SAL_CALL setTop(sal_Int32 _top) override
css::uno::Reference< css::frame::XController > getController() const
Reference< frame::XModel > m_xModel
Sequence< OUString > aServiceNames
sal_Int16 nValue
css::uno::Reference< T > getXSomethingFromArgs(css::uno::Sequence< css::uno::Any > const &args, sal_Int32 nPos, bool bCanBeNull=true)
Definition: vbahelper.hxx:60
args
Reference< XController > xController
Reference< XFrame > xFrame
Reference< XModel > xModel
unsigned char sal_Bool
static void setPosSize(const uno::Reference< awt::XWindow > &xWindow, sal_Int32 nValue, sal_Int16 nFlag)