bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / vbahelper / vbahelper.hxx
blob83d627b543511377a3ca148b8e11492f1f8e25cd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <memory>
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 <tools/color.hxx>
33 #include <vbahelper/vbadllapi.h>
34 #include <vcl/ptrstyle.hxx>
35 #include <vcl/errcode.hxx>
37 namespace com { namespace sun { namespace 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 } } }
52 class SfxObjectShell;
53 class SfxViewFrame;
54 class SfxViewShell;
56 namespace ooo
58 namespace vba
60 /// @throws css::lang::IllegalArgumentException
61 template < class T >
62 css::uno::Reference< T > getXSomethingFromArgs( css::uno::Sequence< css::uno::Any > const & args, sal_Int32 nPos, bool bCanBeNull = true )
64 if ( args.getLength() < ( nPos + 1) )
65 throw css::lang::IllegalArgumentException();
66 css::uno::Reference< T > aSomething( args[ nPos ], css::uno::UNO_QUERY );
67 if ( !bCanBeNull && !aSomething.is() )
68 throw css::lang::IllegalArgumentException();
69 return aSomething;
72 class XHelperInterface;
74 /** Returns the VBA document implementation object representing the passed UNO document model. */
75 VBAHELPER_DLLPUBLIC css::uno::Reference< XHelperInterface > getVBADocument( const css::uno::Reference< css::frame::XModel >& xModel );
76 VBAHELPER_DLLPUBLIC css::uno::Reference< XHelperInterface > getUnoDocModule( const OUString& aModName, SfxObjectShell const * pShell );
77 /// @throws css::uno::RuntimeException
78 VBAHELPER_DLLPUBLIC SfxObjectShell* getSfxObjShell( const css::uno::Reference< css::frame::XModel >& xModel );
80 /// @throws css::uno::RuntimeException
81 css::uno::Reference< css::frame::XModel > getCurrentDoc( const OUString& sKey );
82 /// @throws css::uno::RuntimeException
83 VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getThisExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext );
84 /// @throws css::uno::RuntimeException
85 VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getThisWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext );
86 /// @throws css::uno::RuntimeException
87 VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext );
88 /// @throws css::uno::RuntimeException
89 VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext );
91 /// @throws css::uno::RuntimeException
92 VBAHELPER_DLLPUBLIC css::uno::Reference< css::beans::XIntrospectionAccess > getIntrospectionAccess( const css::uno::Any& aObject );
93 /// @throws css::uno::RuntimeException
94 VBAHELPER_DLLPUBLIC css::uno::Reference< css::script::XTypeConverter > const & getTypeConverter( const css::uno::Reference< css::uno::XComponentContext >& xContext );
96 VBAHELPER_DLLPUBLIC void dispatchRequests( const css::uno::Reference< css::frame::XModel>& xModel, const OUString& aUrl );
97 VBAHELPER_DLLPUBLIC void dispatchRequests (const css::uno::Reference< css::frame::XModel>& xModel, const OUString & aUrl, const css::uno::Sequence< css::beans::PropertyValue >& sProps );
98 VBAHELPER_DLLPUBLIC void dispatchExecute(SfxViewShell const * pView, sal_uInt16 nSlot );
99 VBAHELPER_DLLPUBLIC sal_Int32 OORGBToXLRGB( sal_Int32 );
100 inline sal_Int32 OORGBToXLRGB( ::Color n ) { return OORGBToXLRGB(sal_Int32(n)); }
101 VBAHELPER_DLLPUBLIC sal_Int32 XLRGBToOORGB( sal_Int32 );
102 VBAHELPER_DLLPUBLIC css::uno::Any OORGBToXLRGB( const css::uno::Any& );
103 VBAHELPER_DLLPUBLIC css::uno::Any XLRGBToOORGB( const css::uno::Any& );
104 // provide a NULL object that can be passed as variant so that
105 // the object when passed to IsNull will return true. aNULL
106 // contains an empty object reference
107 VBAHELPER_DLLPUBLIC const css::uno::Any& aNULL();
108 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 );
109 VBAHELPER_DLLPUBLIC void PrintPreviewHelper( const css::uno::Any& EnableChanges, SfxViewShell const * );
110 VBAHELPER_DLLPUBLIC void WaitUntilPreviewIsClosed( SfxViewFrame* );
112 /** Extracts a boolean value from the passed Any, which may contain a Boolean or an integer or floating-point value.
113 @throws css::uno::RuntimeException if the Any is empty or contains an incompatible type. */
114 VBAHELPER_DLLPUBLIC bool extractBoolFromAny( const css::uno::Any& rAny );
116 /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string.
117 @throws css::uno::RuntimeException if the Any is empty or contains an incompatible type. */
118 VBAHELPER_DLLPUBLIC OUString extractStringFromAny( const css::uno::Any& rAny, bool bUppercaseBool = false );
119 /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string.
120 Returns rDefault, if rAny is empty.
121 @throws css::uno::RuntimeException if the Any contains an incompatible type. */
122 VBAHELPER_DLLPUBLIC OUString extractStringFromAny( const css::uno::Any& rAny, const OUString& rDefault, bool bUppercaseBool );
124 /// @throws css::uno::RuntimeException
125 VBAHELPER_DLLPUBLIC OUString getAnyAsString( const css::uno::Any& pvargItem );
126 VBAHELPER_DLLPUBLIC OUString VBAToRegexp(const OUString &rIn); // needs to be in a uno service ( already this code is duplicated in basic )
127 VBAHELPER_DLLPUBLIC double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference< css::awt::XDevice >& xDevice, bool bVertical);
128 VBAHELPER_DLLPUBLIC double PointsToPixels( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, bool bVertical);
129 VBAHELPER_DLLPUBLIC double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, bool bVertical);
130 VBAHELPER_DLLPUBLIC sal_Int32 PointsToHmm( double fPoints );
131 VBAHELPER_DLLPUBLIC double HmmToPoints( sal_Int32 nHmm );
132 VBAHELPER_DLLPUBLIC PointerStyle getPointerStyle( const css::uno::Reference< css::frame::XModel >& );
133 VBAHELPER_DLLPUBLIC void setCursorHelper( const css::uno::Reference< css::frame::XModel >& xModel, PointerStyle nPointer, bool bOverWrite );
134 /// @throws css::uno::RuntimeException
135 VBAHELPER_DLLPUBLIC void setDefaultPropByIntrospection( const css::uno::Any& aObj, const css::uno::Any& aValue );
136 VBAHELPER_DLLPUBLIC css::uno::Any getPropertyValue( const css::uno::Sequence< css::beans::PropertyValue >& aProp, const OUString& aName );
137 VBAHELPER_DLLPUBLIC bool setPropertyValue( css::uno::Sequence< css::beans::PropertyValue >& aProp, const OUString& aName, const css::uno::Any& aValue );
138 VBAHELPER_DLLPUBLIC void setOrAppendPropertyValue( css::uno::Sequence< css::beans::PropertyValue >& aProp, const OUString& aName, const css::uno::Any& aValue );
140 class VBAHELPER_DLLPUBLIC Millimeter
142 //Factor to translate between points and hundredths of millimeters:
143 private:
144 double m_nMillimeter;
146 public:
147 Millimeter();
149 Millimeter(double mm);
151 void setInPoints(double points) ;
152 double getInHundredthsOfOneMillimeter();
153 static sal_Int32 getInHundredthsOfOneMillimeter(double points);
154 static double getInPoints(int _hmm);
157 class VBAHELPER_DLLPUBLIC AbstractGeometryAttributes // probably should replace the ShapeHelper below
159 public:
160 virtual ~AbstractGeometryAttributes() {}
161 virtual double getLeft() const = 0;
162 virtual void setLeft( double ) = 0;
163 virtual double getTop() const = 0;
164 virtual void setTop( double ) = 0;
165 virtual double getHeight() const = 0;
166 virtual void setHeight( double ) = 0;
167 virtual double getWidth() const = 0;
168 virtual void setWidth( double ) = 0;
170 virtual double getInnerHeight() const { return 0.0; }
171 virtual void setInnerHeight( double ) {}
172 virtual double getInnerWidth() const { return 0.0; }
173 virtual void setInnerWidth( double ) {}
174 virtual double getOffsetX() const { return 0.0; }
175 virtual double getOffsetY() const { return 0.0; }
178 class VBAHELPER_DLLPUBLIC ShapeHelper
180 css::uno::Reference< css::drawing::XShape > xShape;
181 public:
182 /// @throws css::script::BasicErrorException
183 /// @throws css::uno::RuntimeException
184 ShapeHelper( const css::uno::Reference< css::drawing::XShape >& _xShape);
186 double getHeight() const;
187 void setHeight(double _fheight);
188 double getWidth() const;
189 void setWidth(double _fWidth);
190 double getLeft() const;
191 void setLeft(double _fLeft);
192 double getTop() const;
193 void setTop(double _fTop);
196 class VBAHELPER_DLLPUBLIC ConcreteXShapeGeometryAttributes : public AbstractGeometryAttributes
198 std::unique_ptr< ShapeHelper > m_pShapeHelper;
199 public:
200 ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::drawing::XShape >& xShape );
201 virtual double getLeft() const override;
202 virtual void setLeft( double nLeft ) override;
203 virtual double getTop() const override;
204 virtual void setTop( double nTop ) override;
205 virtual double getHeight() const override;
206 virtual void setHeight( double nHeight ) override;
207 virtual double getWidth() const override;
208 virtual void setWidth( double nWidth) override;
209 virtual ~ConcreteXShapeGeometryAttributes() override;
212 #define VBA_LEFT "PositionX"
213 #define VBA_TOP "PositionY"
214 class VBAHELPER_DLLPUBLIC UserFormGeometryHelper : public AbstractGeometryAttributes
216 public:
217 UserFormGeometryHelper(
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;
235 private:
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 );
241 private:
242 css::uno::Reference< css::awt::XWindow > mxWindow;
243 css::uno::Reference< css::beans::XPropertySet > mxModelProps;
244 css::uno::Reference< css::awt::XUnitConversion > mxUnitConv;
245 double const mfOffsetX;
246 double const mfOffsetY;
247 bool const mbDialog;
250 class VBAHELPER_DLLPUBLIC ContainerUtilities
253 public:
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
263 public:
264 /// @throws css::script::BasicErrorException
265 static void basicexception( const css::uno::Exception& ex, ErrCode err, const OUString& /*additionalArgument*/ );
267 /// @throws css::script::BasicErrorException
268 static void basicexception( ErrCode 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( ErrCode err );
277 } // vba
278 } // ooo
280 namespace ov = ooo::vba;
282 #endif
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */