LibreOffice Module vbahelper (master) 1
vbahelper.hxx
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#ifndef INCLUDED_VBAHELPER_VBAHELPER_HXX
20#define INCLUDED_VBAHELPER_VBAHELPER_HXX
21
22#include <memory>
23#include <string_view>
24
25#include <com/sun/star/lang/IllegalArgumentException.hpp>
26#include <com/sun/star/uno/Any.hxx>
27#include <com/sun/star/uno/Reference.hxx>
28#include <com/sun/star/uno/Sequence.hxx>
29#include <basic/sbxmeth.hxx>
30#include <rtl/ustring.hxx>
31#include <sal/types.h>
32#include <tools/color.hxx>
33#include <vbahelper/vbadllapi.h>
34#include <vcl/ptrstyle.hxx>
36
37namespace com::sun::star {
38 namespace awt { class XControl; }
39 namespace awt { class XDevice; }
40 namespace awt { class XUnitConversion; }
41 namespace awt { class XWindow; }
42 namespace beans { class XIntrospectionAccess; }
43 namespace beans { class XPropertySet; }
44 namespace beans { struct PropertyValue; }
45 namespace drawing { class XShape; }
46 namespace frame { class XModel; }
47 namespace script { class XTypeConverter; }
48 namespace uno { class Exception; }
49 namespace uno { class XComponentContext; }
50}
51
52class SfxObjectShell;
53class SfxViewFrame;
54class SfxViewShell;
55
56namespace ooo::vba
57 {
59 template < class T >
60 css::uno::Reference< T > getXSomethingFromArgs( css::uno::Sequence< css::uno::Any > const & args, sal_Int32 nPos, bool bCanBeNull = true )
61 {
62 if ( args.getLength() < ( nPos + 1) )
63 throw css::lang::IllegalArgumentException();
64 css::uno::Reference< T > aSomething( args[ nPos ], css::uno::UNO_QUERY );
65 if ( !bCanBeNull && !aSomething.is() )
66 throw css::lang::IllegalArgumentException();
67 return aSomething;
68 }
69
70 class XHelperInterface;
71
73 VBAHELPER_DLLPUBLIC css::uno::Reference< XHelperInterface > getVBADocument( const css::uno::Reference< css::frame::XModel >& xModel );
74 VBAHELPER_DLLPUBLIC css::uno::Reference< XHelperInterface > getUnoDocModule( std::u16string_view aModName, SfxObjectShell const * pShell );
76 VBAHELPER_DLLPUBLIC SfxObjectShell* getSfxObjShell( const css::uno::Reference< css::frame::XModel >& xModel );
77
79 css::uno::Reference< css::frame::XModel > getCurrentDoc( const OUString& sKey );
81 VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getThisExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext );
83 VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getThisWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext );
85 VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext );
87 VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext );
88
90 VBAHELPER_DLLPUBLIC css::uno::Reference< css::beans::XIntrospectionAccess > getIntrospectionAccess( const css::uno::Any& aObject );
92 VBAHELPER_DLLPUBLIC css::uno::Reference< css::script::XTypeConverter > const & getTypeConverter( const css::uno::Reference< css::uno::XComponentContext >& xContext );
93
94 VBAHELPER_DLLPUBLIC void dispatchRequests( const css::uno::Reference< css::frame::XModel>& xModel, const OUString& aUrl );
95 VBAHELPER_DLLPUBLIC void dispatchRequests (const css::uno::Reference< css::frame::XModel>& xModel, const OUString & aUrl, const css::uno::Sequence< css::beans::PropertyValue >& sProps );
96 VBAHELPER_DLLPUBLIC void dispatchExecute(SfxViewShell const * pView, sal_uInt16 nSlot );
97 VBAHELPER_DLLPUBLIC sal_Int32 OORGBToXLRGB( sal_Int32 );
98 inline sal_Int32 OORGBToXLRGB( ::Color n ) { return OORGBToXLRGB(sal_Int32(n)); }
99 VBAHELPER_DLLPUBLIC sal_Int32 XLRGBToOORGB( sal_Int32 );
100 VBAHELPER_DLLPUBLIC css::uno::Any OORGBToXLRGB( const css::uno::Any& );
101 VBAHELPER_DLLPUBLIC css::uno::Any XLRGBToOORGB( const css::uno::Any& );
102 // provide a NULL object that can be passed as variant so that
103 // the object when passed to IsNull will return true. aNULL
104 // contains an empty object reference
105 VBAHELPER_DLLPUBLIC const css::uno::Any& aNULL();
106 VBAHELPER_DLLPUBLIC void PrintOutHelper( SfxViewShell const * pViewShell, const css::uno::Any& From, const css::uno::Any& To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName, bool bSelection );
107 VBAHELPER_DLLPUBLIC void PrintPreviewHelper( const css::uno::Any& EnableChanges, SfxViewShell const * );
109
112 VBAHELPER_DLLPUBLIC bool extractBoolFromAny( const css::uno::Any& rAny );
113
116 VBAHELPER_DLLPUBLIC OUString extractStringFromAny( const css::uno::Any& rAny, bool bUppercaseBool = false );
120 VBAHELPER_DLLPUBLIC OUString extractStringFromAny( const css::uno::Any& rAny, const OUString& rDefault, bool bUppercaseBool );
121
123 VBAHELPER_DLLPUBLIC OUString getAnyAsString( const css::uno::Any& pvargItem );
124 VBAHELPER_DLLPUBLIC OUString VBAToRegexp(const OUString &rIn); // needs to be in a uno service ( already this code is duplicated in basic )
125 VBAHELPER_DLLPUBLIC double PointsToPixels( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, bool bVertical);
126 VBAHELPER_DLLPUBLIC double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, bool bVertical);
127 VBAHELPER_DLLPUBLIC PointerStyle getPointerStyle( const css::uno::Reference< css::frame::XModel >& );
128 VBAHELPER_DLLPUBLIC void setCursorHelper( const css::uno::Reference< css::frame::XModel >& xModel, PointerStyle nPointer, bool bOverWrite );
130 VBAHELPER_DLLPUBLIC void setDefaultPropByIntrospection( const css::uno::Any& aObj, const css::uno::Any& aValue );
131 VBAHELPER_DLLPUBLIC css::uno::Any getPropertyValue( const css::uno::Sequence< css::beans::PropertyValue >& aProp, const OUString& aName );
132 VBAHELPER_DLLPUBLIC bool setPropertyValue( css::uno::Sequence< css::beans::PropertyValue >& aProp, const OUString& aName, const css::uno::Any& aValue );
133 VBAHELPER_DLLPUBLIC void setOrAppendPropertyValue( css::uno::Sequence< css::beans::PropertyValue >& aProp, const OUString& aName, const css::uno::Any& aValue );
134
135 VBAHELPER_DLLPUBLIC bool executeRunTimeLibrary(const std::u16string_view& rSbRtl_command,
136 SbxArray* pParameters);
137
139{
140//Factor to translate between points and hundredths of millimeters:
141private:
143
144public:
145 Millimeter();
146
147 Millimeter(double mm);
148
149 void setInPoints(double points) ;
150 double getInHundredthsOfOneMillimeter() const;
151 static sal_Int32 getInHundredthsOfOneMillimeter(double points);
152 static double getInPoints(int _hmm);
153};
154
155class VBAHELPER_DLLPUBLIC AbstractGeometryAttributes // probably should replace the ShapeHelper below
156{
157public:
159 virtual double getLeft() const = 0;
160 virtual void setLeft( double ) = 0;
161 virtual double getTop() const = 0;
162 virtual void setTop( double ) = 0;
163 virtual double getHeight() const = 0;
164 virtual void setHeight( double ) = 0;
165 virtual double getWidth() const = 0;
166 virtual void setWidth( double ) = 0;
167
168 virtual double getInnerHeight() const { return 0.0; }
169 virtual void setInnerHeight( double ) {}
170 virtual double getInnerWidth() const { return 0.0; }
171 virtual void setInnerWidth( double ) {}
172 virtual double getOffsetX() const { return 0.0; }
173 virtual double getOffsetY() const { return 0.0; }
174};
175
177{
178 css::uno::Reference< css::drawing::XShape > xShape;
179public:
182 ShapeHelper( css::uno::Reference< css::drawing::XShape > _xShape);
183
184 double getHeight() const;
185 void setHeight(double _fheight);
186 double getWidth() const;
187 void setWidth(double _fWidth);
188 double getLeft() const;
189 void setLeft(double _fLeft);
190 double getTop() const;
191 void setTop(double _fTop);
192};
193
195{
197public:
198 ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::drawing::XShape >& xShape );
199 virtual double getLeft() const override;
200 virtual void setLeft( double nLeft ) override;
201 virtual double getTop() const override;
202 virtual void setTop( double nTop ) override;
203 virtual double getHeight() const override;
204 virtual void setHeight( double nHeight ) override;
205 virtual double getWidth() const override;
206 virtual void setWidth( double nWidth) override;
207 virtual ~ConcreteXShapeGeometryAttributes() override;
208};
209
210#define VBA_LEFT "PositionX"
211#define VBA_TOP "PositionY"
212
214{
215public:
217 const css::uno::Reference< css::awt::XControl >& xControl,
218 double fOffsetX, double fOffsetY );
219 virtual double getLeft() const override;
220 virtual void setLeft( double fLeft ) override;
221 virtual double getTop() const override;
222 virtual void setTop( double fTop ) override;
223 virtual double getWidth() const override;
224 virtual void setWidth( double fWidth ) override;
225 virtual double getHeight() const override;
226 virtual void setHeight( double fHeight ) override;
227 virtual double getInnerWidth() const override;
228 virtual void setInnerWidth( double fWidth ) override;
229 virtual double getInnerHeight() const override;
230 virtual void setInnerHeight( double fHeight ) override;
231 virtual double getOffsetX() const override;
232 virtual double getOffsetY() const override;
233
234private:
235 double implGetPos( bool bPosY ) const;
236 void implSetPos( double fPos, bool bPosY );
237 double implGetSize( bool bHeight, bool bOuter ) const;
238 void implSetSize( double fSize, bool bHeight, bool bOuter );
239
240private:
241 css::uno::Reference< css::awt::XWindow > mxWindow;
242 css::uno::Reference< css::beans::XPropertySet > mxModelProps;
243 css::uno::Reference< css::awt::XUnitConversion > mxUnitConv;
244 double mfOffsetX;
245 double mfOffsetY;
247};
248
250{
251
252public:
253 static OUString getUniqueName( const css::uno::Sequence< OUString >& _slist, const OUString& _sElementName, std::u16string_view _sSuffixSeparator);
254 static OUString getUniqueName( const css::uno::Sequence< OUString >& _slist, const OUString& _sElementName, std::u16string_view _sSuffixSeparator, sal_Int32 _nStartSuffix );
255
256 static sal_Int32 FieldInList( const css::uno::Sequence< OUString >& SearchList, const OUString& SearchString );
257};
258
259// really just a place holder to ease the porting pain
261{
262public:
264 static void basicexception( const css::uno::Exception& ex, ErrCode err, std::u16string_view /*additionalArgument*/ );
265
267 static void basicexception( ErrCode err, std::u16string_view additionalArgument );
268
270 static void basicexception( const css::uno::Exception& ex );
271
273 static void runtimeexception( ErrCode err );
274};
275
276} // ooo::vba
277
278namespace ov = ooo::vba;
279
280#endif
281
282/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int16 script
virtual double getLeft() const =0
virtual void setLeft(double)=0
virtual void setInnerHeight(double)
Definition: vbahelper.hxx:169
virtual double getOffsetX() const
Definition: vbahelper.hxx:172
virtual void setInnerWidth(double)
Definition: vbahelper.hxx:171
virtual double getOffsetY() const
Definition: vbahelper.hxx:173
virtual double getTop() const =0
virtual double getInnerWidth() const
Definition: vbahelper.hxx:170
virtual void setHeight(double)=0
virtual double getHeight() const =0
virtual double getInnerHeight() const
Definition: vbahelper.hxx:168
virtual void setWidth(double)=0
virtual double getWidth() const =0
static OUString getUniqueName(const css::uno::Sequence< OUString > &_slist, const OUString &_sElementName, std::u16string_view _sSuffixSeparator)
static OUString getUniqueName(const css::uno::Sequence< OUString > &_slist, const OUString &_sElementName, std::u16string_view _sSuffixSeparator, sal_Int32 _nStartSuffix)
css::uno::Reference< css::drawing::XShape > xShape
Definition: vbahelper.hxx:178
css::uno::Reference< css::awt::XWindow > mxWindow
Definition: vbahelper.hxx:241
css::uno::Reference< css::awt::XUnitConversion > mxUnitConv
Definition: vbahelper.hxx:243
css::uno::Reference< css::beans::XPropertySet > mxModelProps
Definition: vbahelper.hxx:242
sal_Int64 n
sal_uInt16 nPos
err
@ Exception
class SAL_NO_VTABLE XPropertySet
double PixelsToPoints(const css::uno::Reference< css::awt::XDevice > &xDevice, double fPixels, bool bVertical)
Definition: vbahelper.cxx:621
bool extractBoolFromAny(const uno::Any &rAny)
Definition: vbahelper.cxx:444
css::uno::Reference< T > getXSomethingFromArgs(css::uno::Sequence< css::uno::Any > const &args, sal_Int32 nPos, bool bCanBeNull=true)
Definition: vbahelper.hxx:60
sal_Int32 XLRGBToOORGB(sal_Int32 nCol)
Definition: vbahelper.cxx:306
void PrintOutHelper(SfxViewShell const *pViewShell, const uno::Any &From, const uno::Any &To, const uno::Any &Copies, const uno::Any &Preview, const uno::Any &, const uno::Any &, const uno::Any &Collate, const uno::Any &PrToFileName, bool bUseSelection)
Definition: vbahelper.cxx:339
uno::Reference< script::XTypeConverter > const & getTypeConverter(const uno::Reference< uno::XComponentContext > &xContext)
Definition: vbahelper.cxx:108
void PrintPreviewHelper(const css::uno::Any &, SfxViewShell const *pViewShell)
Definition: vbahelper.cxx:423
const uno::Any & aNULL()
Definition: vbahelper.cxx:114
uno::Any getPropertyValue(const uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName)
Definition: vbahelper.cxx:714
void WaitUntilPreviewIsClosed(SfxViewFrame *pViewFrame)
Definition: vbahelper.cxx:438
void setCursorHelper(const uno::Reference< frame::XModel > &xModel, PointerStyle nPointer, bool bOverWrite)
Definition: vbahelper.cxx:659
uno::Reference< frame::XModel > getCurrentDoc(const OUString &sKey)
Definition: vbahelper.cxx:179
uno::Reference< frame::XModel > getCurrentExcelDoc(const uno::Reference< uno::XComponentContext > &xContext)
Definition: vbahelper.cxx:247
OUString VBAToRegexp(const OUString &rIn)
Definition: vbahelper.cxx:538
uno::Reference< XHelperInterface > getUnoDocModule(std::u16string_view aModName, SfxObjectShell const *pShell)
Definition: vbahelper.cxx:1091
uno::Reference< frame::XModel > getThisWordDoc(const uno::Reference< uno::XComponentContext > &xContext)
Definition: vbahelper.cxx:241
uno::Reference< beans::XIntrospectionAccess > getIntrospectionAccess(const uno::Any &aObject)
Definition: vbahelper.cxx:101
void setOrAppendPropertyValue(uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName, const uno::Any &aValue)
Definition: vbahelper.cxx:736
OUString extractStringFromAny(const uno::Any &rAny, bool bUppercaseBool)
Definition: vbahelper.cxx:465
void dispatchExecute(SfxViewShell const *pViewShell, sal_uInt16 nSlot)
Definition: vbahelper.cxx:120
SfxObjectShell * getSfxObjShell(const uno::Reference< frame::XModel > &xModel)
Definition: vbahelper.cxx:1113
double PointsToPixels(const css::uno::Reference< css::awt::XDevice > &xDevice, double fPoints, bool bVertical)
Definition: vbahelper.cxx:616
uno::Reference< XHelperInterface > getVBADocument(const uno::Reference< frame::XModel > &xModel)
Definition: vbahelper.cxx:1075
PointerStyle getPointerStyle(const uno::Reference< frame::XModel > &xModel)
Definition: vbahelper.cxx:635
bool setPropertyValue(uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName, const uno::Any &aValue)
Definition: vbahelper.cxx:723
OUString getAnyAsString(const uno::Any &pvargItem)
Definition: vbahelper.cxx:495
void setDefaultPropByIntrospection(const uno::Any &aObj, const uno::Any &aValue)
Definition: vbahelper.cxx:697
uno::Reference< frame::XModel > getCurrentWordDoc(const uno::Reference< uno::XComponentContext > &xContext)
Definition: vbahelper.cxx:268
void dispatchRequests(const uno::Reference< frame::XModel > &xModel, const OUString &aUrl, const uno::Sequence< beans::PropertyValue > &sProps)
Definition: vbahelper.cxx:136
sal_Int32 OORGBToXLRGB(sal_Int32 nCol)
Definition: vbahelper.cxx:289
bool executeRunTimeLibrary(const std::u16string_view &rSbRtl_command, SbxArray *pParameters)
Definition: vbahelper.cxx:749
uno::Reference< frame::XModel > getThisExcelDoc(const uno::Reference< uno::XComponentContext > &xContext)
Definition: vbahelper.cxx:235
args
PointerStyle
#define VBAHELPER_DLLPUBLIC
Definition: vbadllapi.h:28