1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
19 #ifndef INCLUDED_VBAHELPER_VBAHELPER_HXX
20 #define INCLUDED_VBAHELPER_VBAHELPER_HXX
22 #include <string_view>
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <basic/sbxvar.hxx>
29 #include <rtl/ustring.hxx>
30 #include <sal/types.h>
31 #include <tools/color.hxx>
32 #include <vbahelper/vbadllapi.h>
33 #include <vcl/ptrstyle.hxx>
34 #include <comphelper/errcode.hxx>
36 namespace com::sun::star
{
37 namespace awt
{ class XControl
; }
38 namespace awt
{ class XDevice
; }
39 namespace awt
{ class XUnitConversion
; }
40 namespace awt
{ class XWindow
; }
41 namespace beans
{ class XIntrospectionAccess
; }
42 namespace beans
{ class XPropertySet
; }
43 namespace beans
{ struct PropertyValue
; }
44 namespace drawing
{ class XShape
; }
45 namespace frame
{ class XModel
; }
46 namespace script
{ class XTypeConverter
; }
47 namespace uno
{ class Exception
; }
48 namespace uno
{ class XComponentContext
; }
57 /// @throws css::lang::IllegalArgumentException
59 css::uno::Reference
< T
> getXSomethingFromArgs( css::uno::Sequence
< css::uno::Any
> const & args
, sal_Int32 nPos
, bool bCanBeNull
= true )
61 if ( args
.getLength() < ( nPos
+ 1) )
62 throw css::lang::IllegalArgumentException();
63 css::uno::Reference
< T
> aSomething( args
[ nPos
], css::uno::UNO_QUERY
);
64 if ( !bCanBeNull
&& !aSomething
.is() )
65 throw css::lang::IllegalArgumentException();
69 class XHelperInterface
;
71 /** Returns the VBA document implementation object representing the passed UNO document model. */
72 VBAHELPER_DLLPUBLIC
css::uno::Reference
< XHelperInterface
> getVBADocument( const css::uno::Reference
< css::frame::XModel
>& xModel
);
73 VBAHELPER_DLLPUBLIC
css::uno::Reference
< XHelperInterface
> getUnoDocModule( std::u16string_view aModName
, SfxObjectShell
const * pShell
);
74 /// @throws css::uno::RuntimeException
75 VBAHELPER_DLLPUBLIC SfxObjectShell
* getSfxObjShell( const css::uno::Reference
< css::frame::XModel
>& xModel
);
77 /// @throws css::uno::RuntimeException
78 css::uno::Reference
< css::frame::XModel
> getCurrentDoc( const OUString
& sKey
);
79 /// @throws css::uno::RuntimeException
80 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::frame::XModel
> getThisExcelDoc( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
81 /// @throws css::uno::RuntimeException
82 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::frame::XModel
> getThisWordDoc( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
83 /// @throws css::uno::RuntimeException
84 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::frame::XModel
> getCurrentExcelDoc( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
85 /// @throws css::uno::RuntimeException
86 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::frame::XModel
> getCurrentWordDoc( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
88 /// @throws css::uno::RuntimeException
89 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::beans::XIntrospectionAccess
> getIntrospectionAccess( const css::uno::Any
& aObject
);
90 /// @throws css::uno::RuntimeException
91 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::script::XTypeConverter
> const & getTypeConverter( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
93 VBAHELPER_DLLPUBLIC
void dispatchRequests( const css::uno::Reference
< css::frame::XModel
>& xModel
, const OUString
& aUrl
);
94 VBAHELPER_DLLPUBLIC
void dispatchRequests (const css::uno::Reference
< css::frame::XModel
>& xModel
, const OUString
& aUrl
, const css::uno::Sequence
< css::beans::PropertyValue
>& sProps
);
95 VBAHELPER_DLLPUBLIC
void dispatchExecute(SfxViewShell
const * pView
, sal_uInt16 nSlot
);
96 VBAHELPER_DLLPUBLIC sal_Int32
OORGBToXLRGB( sal_Int32
);
97 inline sal_Int32
OORGBToXLRGB( ::Color n
) { return OORGBToXLRGB(sal_Int32(n
)); }
98 VBAHELPER_DLLPUBLIC sal_Int32
XLRGBToOORGB( sal_Int32
);
99 VBAHELPER_DLLPUBLIC
css::uno::Any
OORGBToXLRGB( const css::uno::Any
& );
100 VBAHELPER_DLLPUBLIC
css::uno::Any
XLRGBToOORGB( const css::uno::Any
& );
101 // provide a NULL object that can be passed as variant so that
102 // the object when passed to IsNull will return true. aNULL
103 // contains an empty object reference
104 VBAHELPER_DLLPUBLIC
const css::uno::Any
& aNULL();
105 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
);
106 VBAHELPER_DLLPUBLIC
void PrintPreviewHelper( const css::uno::Any
& EnableChanges
, SfxViewShell
const * );
107 VBAHELPER_DLLPUBLIC
void WaitUntilPreviewIsClosed( SfxViewFrame
* );
109 /** Extracts a boolean value from the passed Any, which may contain a Boolean or an integer or floating-point value.
110 @throws css::uno::RuntimeException if the Any is empty or contains an incompatible type. */
111 VBAHELPER_DLLPUBLIC
bool extractBoolFromAny( const css::uno::Any
& rAny
);
113 /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string.
114 @throws css::uno::RuntimeException if the Any is empty or contains an incompatible type. */
115 VBAHELPER_DLLPUBLIC OUString
extractStringFromAny( const css::uno::Any
& rAny
, bool bUppercaseBool
= false );
116 /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string.
117 Returns rDefault, if rAny is empty.
118 @throws css::uno::RuntimeException if the Any contains an incompatible type. */
119 VBAHELPER_DLLPUBLIC OUString
extractStringFromAny( const css::uno::Any
& rAny
, const OUString
& rDefault
, bool bUppercaseBool
);
121 /// @throws css::uno::RuntimeException
122 VBAHELPER_DLLPUBLIC OUString
getAnyAsString( const css::uno::Any
& pvargItem
);
123 VBAHELPER_DLLPUBLIC OUString
VBAToRegexp(const OUString
&rIn
); // needs to be in a uno service ( already this code is duplicated in basic )
124 VBAHELPER_DLLPUBLIC
double PointsToPixels( const css::uno::Reference
< css::awt::XDevice
>& xDevice
, double fPoints
, bool bVertical
);
125 VBAHELPER_DLLPUBLIC
double PixelsToPoints( const css::uno::Reference
< css::awt::XDevice
>& xDevice
, double fPixels
, bool bVertical
);
126 VBAHELPER_DLLPUBLIC PointerStyle
getPointerStyle( const css::uno::Reference
< css::frame::XModel
>& );
127 VBAHELPER_DLLPUBLIC
void setCursorHelper( const css::uno::Reference
< css::frame::XModel
>& xModel
, PointerStyle nPointer
, bool bOverWrite
);
128 /// @throws css::uno::RuntimeException
129 VBAHELPER_DLLPUBLIC
void setDefaultPropByIntrospection( const css::uno::Any
& aObj
, const css::uno::Any
& aValue
);
130 VBAHELPER_DLLPUBLIC
css::uno::Any
getPropertyValue( const css::uno::Sequence
< css::beans::PropertyValue
>& aProp
, const OUString
& aName
);
131 VBAHELPER_DLLPUBLIC
bool setPropertyValue( css::uno::Sequence
< css::beans::PropertyValue
>& aProp
, const OUString
& aName
, const css::uno::Any
& aValue
);
132 VBAHELPER_DLLPUBLIC
void setOrAppendPropertyValue( css::uno::Sequence
< css::beans::PropertyValue
>& aProp
, const OUString
& aName
, const css::uno::Any
& aValue
);
134 VBAHELPER_DLLPUBLIC
bool executeRunTimeLibrary(const std::u16string_view
& rSbRtl_command
,
135 SbxArray
* pParameters
);
137 class VBAHELPER_DLLPUBLIC Millimeter
139 //Factor to translate between points and hundredths of millimeters:
141 double m_nMillimeter
;
146 Millimeter(double mm
);
148 void setInPoints(double points
) ;
149 double getInHundredthsOfOneMillimeter() const;
150 static sal_Int32
getInHundredthsOfOneMillimeter(double points
);
151 static double getInPoints(int _hmm
);
154 class VBAHELPER_DLLPUBLIC AbstractGeometryAttributes
// probably should replace the ShapeHelper below
157 virtual ~AbstractGeometryAttributes() {}
158 virtual double getLeft() const = 0;
159 virtual void setLeft( double ) = 0;
160 virtual double getTop() const = 0;
161 virtual void setTop( double ) = 0;
162 virtual double getHeight() const = 0;
163 virtual void setHeight( double ) = 0;
164 virtual double getWidth() const = 0;
165 virtual void setWidth( double ) = 0;
167 virtual double getInnerHeight() const { return 0.0; }
168 virtual void setInnerHeight( double ) {}
169 virtual double getInnerWidth() const { return 0.0; }
170 virtual void setInnerWidth( double ) {}
171 virtual double getOffsetX() const { return 0.0; }
172 virtual double getOffsetY() const { return 0.0; }
175 class VBAHELPER_DLLPUBLIC ShapeHelper
177 css::uno::Reference
< css::drawing::XShape
> xShape
;
179 /// @throws css::script::BasicErrorException
180 /// @throws css::uno::RuntimeException
181 ShapeHelper( css::uno::Reference
< css::drawing::XShape
> _xShape
);
183 double getHeight() const;
184 void setHeight(double _fheight
);
185 double getWidth() const;
186 void setWidth(double _fWidth
);
187 double getLeft() const;
188 void setLeft(double _fLeft
);
189 double getTop() const;
190 void setTop(double _fTop
);
193 class VBAHELPER_DLLPUBLIC ConcreteXShapeGeometryAttributes final
: public AbstractGeometryAttributes
195 ShapeHelper m_aShapeHelper
;
197 ConcreteXShapeGeometryAttributes( const css::uno::Reference
< css::drawing::XShape
>& xShape
);
198 virtual double getLeft() const override
;
199 virtual void setLeft( double nLeft
) override
;
200 virtual double getTop() const override
;
201 virtual void setTop( double nTop
) override
;
202 virtual double getHeight() const override
;
203 virtual void setHeight( double nHeight
) override
;
204 virtual double getWidth() const override
;
205 virtual void setWidth( double nWidth
) override
;
206 virtual ~ConcreteXShapeGeometryAttributes() override
;
209 #define VBA_LEFT "PositionX"
210 #define VBA_TOP "PositionY"
212 class VBAHELPER_DLLPUBLIC UserFormGeometryHelper final
: public AbstractGeometryAttributes
215 UserFormGeometryHelper(
216 const css::uno::Reference
< css::awt::XControl
>& xControl
,
217 double fOffsetX
, double fOffsetY
);
218 virtual double getLeft() const override
;
219 virtual void setLeft( double fLeft
) override
;
220 virtual double getTop() const override
;
221 virtual void setTop( double fTop
) override
;
222 virtual double getWidth() const override
;
223 virtual void setWidth( double fWidth
) override
;
224 virtual double getHeight() const override
;
225 virtual void setHeight( double fHeight
) override
;
226 virtual double getInnerWidth() const override
;
227 virtual void setInnerWidth( double fWidth
) override
;
228 virtual double getInnerHeight() const override
;
229 virtual void setInnerHeight( double fHeight
) override
;
230 virtual double getOffsetX() const override
;
231 virtual double getOffsetY() const override
;
234 double implGetPos( bool bPosY
) const;
235 void implSetPos( double fPos
, bool bPosY
);
236 double implGetSize( bool bHeight
, bool bOuter
) const;
237 void implSetSize( double fSize
, bool bHeight
, bool bOuter
);
240 css::uno::Reference
< css::awt::XWindow
> mxWindow
;
241 css::uno::Reference
< css::beans::XPropertySet
> mxModelProps
;
242 css::uno::Reference
< css::awt::XUnitConversion
> mxUnitConv
;
248 class VBAHELPER_DLLPUBLIC ContainerUtilities
252 static OUString
getUniqueName( const css::uno::Sequence
< OUString
>& _slist
, const OUString
& _sElementName
, std::u16string_view _sSuffixSeparator
);
253 static OUString
getUniqueName( const css::uno::Sequence
< OUString
>& _slist
, const OUString
& _sElementName
, std::u16string_view _sSuffixSeparator
, sal_Int32 _nStartSuffix
);
255 static sal_Int32
FieldInList( const css::uno::Sequence
< OUString
>& SearchList
, const OUString
& SearchString
);
258 // really just a place holder to ease the porting pain
259 class VBAHELPER_DLLPUBLIC DebugHelper
262 /// @throws css::script::BasicErrorException
263 static void basicexception( const css::uno::Exception
& ex
, ErrCode err
, std::u16string_view
/*additionalArgument*/ );
265 /// @throws css::script::BasicErrorException
266 static void basicexception( ErrCode err
, std::u16string_view additionalArgument
);
268 /// @throws css::script::BasicErrorException
269 static void basicexception( const css::uno::Exception
& ex
);
271 /// @throws css::script::BasicErrorException
272 static void runtimeexception( ErrCode err
);
277 namespace ov
= ooo::vba
;
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */