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
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 #include <com/sun/star/script/BasicErrorException.hpp>
26 #include <com/sun/star/uno/Any.hxx>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/uno/RuntimeException.hpp>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include <rtl/ustring.hxx>
31 #include <sal/types.h>
32 #include <vbahelper/vbadllapi.h>
33 #include <vcl/pointr.hxx>
34 #include <vcl/ptrstyle.hxx>
36 namespace com
{ namespace sun
{ namespace 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
; }
60 css::uno::Reference
< T
> getXSomethingFromArgs( css::uno::Sequence
< css::uno::Any
> const & args
, sal_Int32 nPos
, bool bCanBeNull
= true ) throw (css::lang::IllegalArgumentException
)
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();
70 class XHelperInterface
;
72 /** Returns the VBA document implementation object representing the passed UNO document model. */
73 VBAHELPER_DLLPUBLIC
css::uno::Reference
< XHelperInterface
> getVBADocument( const css::uno::Reference
< css::frame::XModel
>& xModel
);
74 VBAHELPER_DLLPUBLIC
css::uno::Reference
< XHelperInterface
> getUnoDocModule( const OUString
& aModName
, SfxObjectShell
* pShell
);
75 VBAHELPER_DLLPUBLIC SfxObjectShell
* getSfxObjShell( const css::uno::Reference
< css::frame::XModel
>& xModel
) throw ( css::uno::RuntimeException
);
77 css::uno::Reference
< css::frame::XModel
> getCurrentDoc( const OUString
& sKey
) throw (css::uno::RuntimeException
);
78 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::frame::XModel
> getThisExcelDoc( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
) throw (css::uno::RuntimeException
);
79 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::frame::XModel
> getThisWordDoc( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
) throw (css::uno::RuntimeException
);
80 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::frame::XModel
> getCurrentExcelDoc( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
) throw (css::uno::RuntimeException
);
81 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::frame::XModel
> getCurrentWordDoc( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
) throw (css::uno::RuntimeException
);
83 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::beans::XIntrospectionAccess
> getIntrospectionAccess( const css::uno::Any
& aObject
) throw (css::uno::RuntimeException
);
84 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::script::XTypeConverter
> const & getTypeConverter( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
) throw (css::uno::RuntimeException
);
86 VBAHELPER_DLLPUBLIC
void dispatchRequests( const css::uno::Reference
< css::frame::XModel
>& xModel
, const OUString
& aUrl
);
87 VBAHELPER_DLLPUBLIC
void dispatchRequests (const css::uno::Reference
< css::frame::XModel
>& xModel
, const OUString
& aUrl
, const css::uno::Sequence
< css::beans::PropertyValue
>& sProps
);
88 VBAHELPER_DLLPUBLIC
void dispatchExecute(SfxViewShell
* pView
, sal_uInt16 nSlot
);
89 VBAHELPER_DLLPUBLIC sal_Int32
OORGBToXLRGB( sal_Int32
);
90 VBAHELPER_DLLPUBLIC sal_Int32
XLRGBToOORGB( sal_Int32
);
91 VBAHELPER_DLLPUBLIC
css::uno::Any
OORGBToXLRGB( const css::uno::Any
& );
92 VBAHELPER_DLLPUBLIC
css::uno::Any
XLRGBToOORGB( const css::uno::Any
& );
93 // provide a NULL object that can be passed as variant so that
94 // the object when passed to IsNull will return true. aNULL
95 // contains an empty object reference
96 VBAHELPER_DLLPUBLIC
const css::uno::Any
& aNULL();
97 VBAHELPER_DLLPUBLIC
void PrintOutHelper( SfxViewShell
* 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
);
98 VBAHELPER_DLLPUBLIC
void PrintPreviewHelper( const css::uno::Any
& EnableChanges
, SfxViewShell
* );
99 VBAHELPER_DLLPUBLIC
void WaitUntilPreviewIsClosed( SfxViewFrame
* );
101 /** Extracts a boolean value from the passed Any, which may contain a Boolean or an integer or floating-point value.
102 Throws, if the Any is empty or contains an incompatible type. */
103 VBAHELPER_DLLPUBLIC
bool extractBoolFromAny( const css::uno::Any
& rAny
) throw (css::uno::RuntimeException
);
105 /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string.
106 Throws, if the Any is empty or contains an incompatible type. */
107 VBAHELPER_DLLPUBLIC OUString
extractStringFromAny( const css::uno::Any
& rAny
, bool bUppercaseBool
= false ) throw (css::uno::RuntimeException
);
108 /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string.
109 Returns rDefault, if rAny is empty. Throws, if the Any contains an incompatible type. */
110 VBAHELPER_DLLPUBLIC OUString
extractStringFromAny( const css::uno::Any
& rAny
, const OUString
& rDefault
, bool bUppercaseBool
) throw (css::uno::RuntimeException
);
112 VBAHELPER_DLLPUBLIC OUString
getAnyAsString( const css::uno::Any
& pvargItem
) throw ( css::uno::RuntimeException
);
113 VBAHELPER_DLLPUBLIC OUString
VBAToRegexp(const OUString
&rIn
); // needs to be in an uno service ( already this code is duplicated in basic )
114 VBAHELPER_DLLPUBLIC
double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference
< css::awt::XDevice
>& xDevice
, bool bVertical
);
115 VBAHELPER_DLLPUBLIC
double PointsToPixels( const css::uno::Reference
< css::awt::XDevice
>& xDevice
, double fPoints
, bool bVertical
);
116 VBAHELPER_DLLPUBLIC
double PixelsToPoints( const css::uno::Reference
< css::awt::XDevice
>& xDevice
, double fPixels
, bool bVertical
);
117 VBAHELPER_DLLPUBLIC sal_Int32
PointsToHmm( double fPoints
);
118 VBAHELPER_DLLPUBLIC
double HmmToPoints( sal_Int32 nHmm
);
119 VBAHELPER_DLLPUBLIC PointerStyle
getPointerStyle( const css::uno::Reference
< css::frame::XModel
>& );
120 VBAHELPER_DLLPUBLIC
void setCursorHelper( const css::uno::Reference
< css::frame::XModel
>& xModel
, const Pointer
& rPointer
, bool bOverWrite
);
121 VBAHELPER_DLLPUBLIC
void setDefaultPropByIntrospection( const css::uno::Any
& aObj
, const css::uno::Any
& aValue
) throw ( css::uno::RuntimeException
);
122 VBAHELPER_DLLPUBLIC
css::uno::Any
getPropertyValue( const css::uno::Sequence
< css::beans::PropertyValue
>& aProp
, const OUString
& aName
);
123 VBAHELPER_DLLPUBLIC
bool setPropertyValue( css::uno::Sequence
< css::beans::PropertyValue
>& aProp
, const OUString
& aName
, const css::uno::Any
& aValue
);
124 VBAHELPER_DLLPUBLIC
void setOrAppendPropertyValue( css::uno::Sequence
< css::beans::PropertyValue
>& aProp
, const OUString
& aName
, const css::uno::Any
& aValue
);
126 class VBAHELPER_DLLPUBLIC Millimeter
128 //Factor to translate between points and hundredths of millimeters:
130 double m_nMillimeter
;
135 Millimeter(double mm
);
137 void setInPoints(double points
) ;
138 double getInHundredthsOfOneMillimeter();
139 static sal_Int32
getInHundredthsOfOneMillimeter(double points
);
140 static double getInPoints(int _hmm
);
143 class VBAHELPER_DLLPUBLIC AbstractGeometryAttributes
// probably should replace the ShapeHelper below
146 virtual ~AbstractGeometryAttributes() {}
147 virtual double getLeft() const = 0;
148 virtual void setLeft( double ) = 0;
149 virtual double getTop() const = 0;
150 virtual void setTop( double ) = 0;
151 virtual double getHeight() const = 0;
152 virtual void setHeight( double ) = 0;
153 virtual double getWidth() const = 0;
154 virtual void setWidth( double ) = 0;
156 virtual double getInnerHeight() const { return 0.0; }
157 virtual void setInnerHeight( double ) {}
158 virtual double getInnerWidth() const { return 0.0; }
159 virtual void setInnerWidth( double ) {}
160 virtual double getOffsetX() const { return 0.0; }
161 virtual double getOffsetY() const { return 0.0; }
164 class VBAHELPER_DLLPUBLIC ShapeHelper
167 css::uno::Reference
< css::drawing::XShape
> xShape
;
169 ShapeHelper( const css::uno::Reference
< css::drawing::XShape
>& _xShape
)
170 throw (css::script::BasicErrorException
, css::uno::RuntimeException
);
172 double getHeight() const;
173 void setHeight(double _fheight
);
174 double getWidth() const;
175 void setWidth(double _fWidth
);
176 double getLeft() const;
177 void setLeft(double _fLeft
);
178 double getTop() const;
179 void setTop(double _fTop
);
182 class VBAHELPER_DLLPUBLIC ConcreteXShapeGeometryAttributes
: public AbstractGeometryAttributes
184 std::unique_ptr
< ShapeHelper
> m_pShapeHelper
;
186 ConcreteXShapeGeometryAttributes( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
, const css::uno::Reference
< css::drawing::XShape
>& xShape
);
187 virtual double getLeft() const override
;
188 virtual void setLeft( double nLeft
) override
;
189 virtual double getTop() const override
;
190 virtual void setTop( double nTop
) override
;
191 virtual double getHeight() const override
;
192 virtual void setHeight( double nHeight
) override
;
193 virtual double getWidth() const override
;
194 virtual void setWidth( double nWidth
) override
;
195 virtual ~ConcreteXShapeGeometryAttributes() override
;
198 #define VBA_LEFT "PositionX"
199 #define VBA_TOP "PositionY"
200 class VBAHELPER_DLLPUBLIC UserFormGeometryHelper
: public AbstractGeometryAttributes
203 UserFormGeometryHelper(
204 const css::uno::Reference
< css::uno::XComponentContext
>& xContext
,
205 const css::uno::Reference
< css::awt::XControl
>& xControl
,
206 double fOffsetX
, double fOffsetY
);
207 virtual double getLeft() const override
;
208 virtual void setLeft( double fLeft
) override
;
209 virtual double getTop() const override
;
210 virtual void setTop( double fTop
) override
;
211 virtual double getWidth() const override
;
212 virtual void setWidth( double fWidth
) override
;
213 virtual double getHeight() const override
;
214 virtual void setHeight( double fHeight
) override
;
215 virtual double getInnerWidth() const override
;
216 virtual void setInnerWidth( double fWidth
) override
;
217 virtual double getInnerHeight() const override
;
218 virtual void setInnerHeight( double fHeight
) override
;
219 virtual double getOffsetX() const override
;
220 virtual double getOffsetY() const override
;
223 double implGetPos( bool bPosY
) const;
224 void implSetPos( double fPos
, bool bPosY
);
225 double implGetSize( bool bHeight
, bool bOuter
) const;
226 void implSetSize( double fSize
, bool bHeight
, bool bOuter
);
229 css::uno::Reference
< css::awt::XWindow
> mxWindow
;
230 css::uno::Reference
< css::beans::XPropertySet
> mxModelProps
;
231 css::uno::Reference
< css::awt::XUnitConversion
> mxUnitConv
;
237 class VBAHELPER_DLLPUBLIC ContainerUtilities
241 static OUString
getUniqueName( const css::uno::Sequence
< OUString
>& _slist
, const OUString
& _sElementName
, const OUString
& _sSuffixSeparator
);
242 static OUString
getUniqueName( const css::uno::Sequence
< OUString
>& _slist
, const OUString
& _sElementName
, const OUString
& _sSuffixSeparator
, sal_Int32 _nStartSuffix
);
244 static sal_Int32
FieldInList( const css::uno::Sequence
< OUString
>& SearchList
, const OUString
& SearchString
);
247 // really just a place holder to ease the porting pain
248 class VBAHELPER_DLLPUBLIC DebugHelper
251 static void basicexception( const OUString
& DetailedMessage
, const css::uno::Exception
& ex
, int err
, const OUString
& /*additionalArgument*/ ) throw( css::script::BasicErrorException
);
253 static void basicexception( int err
, const OUString
& additionalArgument
) throw( css::script::BasicErrorException
);
255 static void basicexception( const css::uno::Exception
& ex
) throw( css::script::BasicErrorException
);
257 static void runtimeexception( int err
, const OUString
& additionalArgument
) throw( css::uno::RuntimeException
);
263 namespace ov
= ooo::vba
;
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */