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
; }
59 /// @throws css::lang::IllegalArgumentException
61 css::uno::Reference
< T
> getXSomethingFromArgs( css::uno::Sequence
< css::uno::Any
> const & args
, sal_Int32 nPos
, bool bCanBeNull
= true )
63 if ( args
.getLength() < ( nPos
+ 1) )
64 throw css::lang::IllegalArgumentException();
65 css::uno::Reference
< T
> aSomething( args
[ nPos
], css::uno::UNO_QUERY
);
66 if ( !bCanBeNull
&& !aSomething
.is() )
67 throw css::lang::IllegalArgumentException();
71 class XHelperInterface
;
73 /** Returns the VBA document implementation object representing the passed UNO document model. */
74 VBAHELPER_DLLPUBLIC
css::uno::Reference
< XHelperInterface
> getVBADocument( const css::uno::Reference
< css::frame::XModel
>& xModel
);
75 VBAHELPER_DLLPUBLIC
css::uno::Reference
< XHelperInterface
> getUnoDocModule( const OUString
& aModName
, SfxObjectShell
* pShell
);
76 /// @throws css::uno::RuntimeException
77 VBAHELPER_DLLPUBLIC SfxObjectShell
* getSfxObjShell( const css::uno::Reference
< css::frame::XModel
>& xModel
);
79 /// @throws css::uno::RuntimeException
80 css::uno::Reference
< css::frame::XModel
> getCurrentDoc( const OUString
& sKey
);
81 /// @throws css::uno::RuntimeException
82 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::frame::XModel
> getThisExcelDoc( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
83 /// @throws css::uno::RuntimeException
84 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::frame::XModel
> getThisWordDoc( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
85 /// @throws css::uno::RuntimeException
86 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::frame::XModel
> getCurrentExcelDoc( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
87 /// @throws css::uno::RuntimeException
88 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::frame::XModel
> getCurrentWordDoc( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
90 /// @throws css::uno::RuntimeException
91 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::beans::XIntrospectionAccess
> getIntrospectionAccess( const css::uno::Any
& aObject
);
92 /// @throws css::uno::RuntimeException
93 VBAHELPER_DLLPUBLIC
css::uno::Reference
< css::script::XTypeConverter
> const & getTypeConverter( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
95 VBAHELPER_DLLPUBLIC
void dispatchRequests( const css::uno::Reference
< css::frame::XModel
>& xModel
, const OUString
& aUrl
);
96 VBAHELPER_DLLPUBLIC
void dispatchRequests (const css::uno::Reference
< css::frame::XModel
>& xModel
, const OUString
& aUrl
, const css::uno::Sequence
< css::beans::PropertyValue
>& sProps
);
97 VBAHELPER_DLLPUBLIC
void dispatchExecute(SfxViewShell
* pView
, sal_uInt16 nSlot
);
98 VBAHELPER_DLLPUBLIC sal_Int32
OORGBToXLRGB( sal_Int32
);
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
* 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
* );
108 VBAHELPER_DLLPUBLIC
void WaitUntilPreviewIsClosed( SfxViewFrame
* );
110 /** Extracts a boolean value from the passed Any, which may contain a Boolean or an integer or floating-point value.
111 @throws css::uno::RuntimeException if the Any is empty or contains an incompatible type. */
112 VBAHELPER_DLLPUBLIC
bool extractBoolFromAny( const css::uno::Any
& rAny
);
114 /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string.
115 @throws css::uno::RuntimeException if the Any is empty or contains an incompatible type. */
116 VBAHELPER_DLLPUBLIC OUString
extractStringFromAny( const css::uno::Any
& rAny
, bool bUppercaseBool
= false );
117 /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string.
118 Returns rDefault, if rAny is empty.
119 @throws css::uno::RuntimeException if the Any contains an incompatible type. */
120 VBAHELPER_DLLPUBLIC OUString
extractStringFromAny( const css::uno::Any
& rAny
, const OUString
& rDefault
, bool bUppercaseBool
);
122 /// @throws css::uno::RuntimeException
123 VBAHELPER_DLLPUBLIC OUString
getAnyAsString( const css::uno::Any
& pvargItem
);
124 VBAHELPER_DLLPUBLIC OUString
VBAToRegexp(const OUString
&rIn
); // needs to be in an uno service ( already this code is duplicated in basic )
125 VBAHELPER_DLLPUBLIC
double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference
< css::awt::XDevice
>& xDevice
, bool bVertical
);
126 VBAHELPER_DLLPUBLIC
double PointsToPixels( const css::uno::Reference
< css::awt::XDevice
>& xDevice
, double fPoints
, bool bVertical
);
127 VBAHELPER_DLLPUBLIC
double PixelsToPoints( const css::uno::Reference
< css::awt::XDevice
>& xDevice
, double fPixels
, bool bVertical
);
128 VBAHELPER_DLLPUBLIC sal_Int32
PointsToHmm( double fPoints
);
129 VBAHELPER_DLLPUBLIC
double HmmToPoints( sal_Int32 nHmm
);
130 VBAHELPER_DLLPUBLIC PointerStyle
getPointerStyle( const css::uno::Reference
< css::frame::XModel
>& );
131 VBAHELPER_DLLPUBLIC
void setCursorHelper( const css::uno::Reference
< css::frame::XModel
>& xModel
, const Pointer
& rPointer
, bool bOverWrite
);
132 /// @throws css::uno::RuntimeException
133 VBAHELPER_DLLPUBLIC
void setDefaultPropByIntrospection( const css::uno::Any
& aObj
, const css::uno::Any
& aValue
);
134 VBAHELPER_DLLPUBLIC
css::uno::Any
getPropertyValue( const css::uno::Sequence
< css::beans::PropertyValue
>& aProp
, const OUString
& aName
);
135 VBAHELPER_DLLPUBLIC
bool setPropertyValue( css::uno::Sequence
< css::beans::PropertyValue
>& aProp
, const OUString
& aName
, const css::uno::Any
& aValue
);
136 VBAHELPER_DLLPUBLIC
void setOrAppendPropertyValue( css::uno::Sequence
< css::beans::PropertyValue
>& aProp
, const OUString
& aName
, const css::uno::Any
& aValue
);
138 class VBAHELPER_DLLPUBLIC Millimeter
140 //Factor to translate between points and hundredths of millimeters:
142 double m_nMillimeter
;
147 Millimeter(double mm
);
149 void setInPoints(double points
) ;
150 double getInHundredthsOfOneMillimeter();
151 static sal_Int32
getInHundredthsOfOneMillimeter(double points
);
152 static double getInPoints(int _hmm
);
155 class VBAHELPER_DLLPUBLIC AbstractGeometryAttributes
// probably should replace the ShapeHelper below
158 virtual ~AbstractGeometryAttributes() {}
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;
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; }
176 class VBAHELPER_DLLPUBLIC ShapeHelper
179 css::uno::Reference
< css::drawing::XShape
> xShape
;
181 /// @throws css::script::BasicErrorException
182 /// @throws css::uno::RuntimeException
183 ShapeHelper( const css::uno::Reference
< css::drawing::XShape
>& _xShape
);
185 double getHeight() const;
186 void setHeight(double _fheight
);
187 double getWidth() const;
188 void setWidth(double _fWidth
);
189 double getLeft() const;
190 void setLeft(double _fLeft
);
191 double getTop() const;
192 void setTop(double _fTop
);
195 class VBAHELPER_DLLPUBLIC ConcreteXShapeGeometryAttributes
: public AbstractGeometryAttributes
197 std::unique_ptr
< ShapeHelper
> m_pShapeHelper
;
199 ConcreteXShapeGeometryAttributes( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
, const css::uno::Reference
< css::drawing::XShape
>& xShape
);
200 virtual double getLeft() const override
;
201 virtual void setLeft( double nLeft
) override
;
202 virtual double getTop() const override
;
203 virtual void setTop( double nTop
) override
;
204 virtual double getHeight() const override
;
205 virtual void setHeight( double nHeight
) override
;
206 virtual double getWidth() const override
;
207 virtual void setWidth( double nWidth
) override
;
208 virtual ~ConcreteXShapeGeometryAttributes() override
;
211 #define VBA_LEFT "PositionX"
212 #define VBA_TOP "PositionY"
213 class VBAHELPER_DLLPUBLIC UserFormGeometryHelper
: public AbstractGeometryAttributes
216 UserFormGeometryHelper(
217 const css::uno::Reference
< css::uno::XComponentContext
>& xContext
,
218 const css::uno::Reference
< css::awt::XControl
>& xControl
,
219 double fOffsetX
, double fOffsetY
);
220 virtual double getLeft() const override
;
221 virtual void setLeft( double fLeft
) override
;
222 virtual double getTop() const override
;
223 virtual void setTop( double fTop
) override
;
224 virtual double getWidth() const override
;
225 virtual void setWidth( double fWidth
) override
;
226 virtual double getHeight() const override
;
227 virtual void setHeight( double fHeight
) override
;
228 virtual double getInnerWidth() const override
;
229 virtual void setInnerWidth( double fWidth
) override
;
230 virtual double getInnerHeight() const override
;
231 virtual void setInnerHeight( double fHeight
) override
;
232 virtual double getOffsetX() const override
;
233 virtual double getOffsetY() const override
;
236 double implGetPos( bool bPosY
) const;
237 void implSetPos( double fPos
, bool bPosY
);
238 double implGetSize( bool bHeight
, bool bOuter
) const;
239 void implSetSize( double fSize
, bool bHeight
, bool bOuter
);
242 css::uno::Reference
< css::awt::XWindow
> mxWindow
;
243 css::uno::Reference
< css::beans::XPropertySet
> mxModelProps
;
244 css::uno::Reference
< css::awt::XUnitConversion
> mxUnitConv
;
250 class VBAHELPER_DLLPUBLIC ContainerUtilities
254 static OUString
getUniqueName( const css::uno::Sequence
< OUString
>& _slist
, const OUString
& _sElementName
, const OUString
& _sSuffixSeparator
);
255 static OUString
getUniqueName( const css::uno::Sequence
< OUString
>& _slist
, const OUString
& _sElementName
, const OUString
& _sSuffixSeparator
, sal_Int32 _nStartSuffix
);
257 static sal_Int32
FieldInList( const css::uno::Sequence
< OUString
>& SearchList
, const OUString
& SearchString
);
260 // really just a place holder to ease the porting pain
261 class VBAHELPER_DLLPUBLIC DebugHelper
264 /// @throws css::script::BasicErrorException
265 static void basicexception( const css::uno::Exception
& ex
, int err
, const OUString
& /*additionalArgument*/ );
267 /// @throws css::script::BasicErrorException
268 static void basicexception( int err
, const OUString
& additionalArgument
);
270 /// @throws css::script::BasicErrorException
271 static void basicexception( const css::uno::Exception
& ex
);
273 /// @throws css::script::BasicErrorException
274 static void runtimeexception( int err
);
280 namespace ov
= ooo::vba
;
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */