cool#6580 sw: fix infinite loop when changing document language
[LibreOffice.git] / include / vbahelper / vbahelper.hxx
blobd130c4e6ea1c3c62e07963b4f5ed7e83b0914c1b
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/uno/Any.hxx>
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <rtl/ustring.hxx>
29 #include <sal/types.h>
30 #include <tools/color.hxx>
31 #include <vbahelper/vbadllapi.h>
32 #include <vcl/ptrstyle.hxx>
33 #include <vcl/errcode.hxx>
35 namespace com { namespace sun { namespace star {
36 namespace awt { class XControl; }
37 namespace awt { class XDevice; }
38 namespace awt { class XUnitConversion; }
39 namespace awt { class XWindow; }
40 namespace beans { class XIntrospectionAccess; }
41 namespace beans { class XPropertySet; }
42 namespace beans { struct PropertyValue; }
43 namespace drawing { class XShape; }
44 namespace frame { class XModel; }
45 namespace script { class XTypeConverter; }
46 namespace uno { class Exception; }
47 namespace uno { class XComponentContext; }
48 } } }
50 class SfxObjectShell;
51 class SfxViewFrame;
52 class SfxViewShell;
54 namespace ooo
56 namespace vba
58 /// @throws css::lang::IllegalArgumentException
59 template < class T >
60 css::uno::Reference< T > getXSomethingFromArgs( css::uno::Sequence< css::uno::Any > const & args, sal_Int32 nPos, bool bCanBeNull = true )
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;
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 const * pShell );
75 /// @throws css::uno::RuntimeException
76 VBAHELPER_DLLPUBLIC SfxObjectShell* getSfxObjShell( const css::uno::Reference< css::frame::XModel >& xModel );
78 /// @throws css::uno::RuntimeException
79 css::uno::Reference< css::frame::XModel > getCurrentDoc( const OUString& sKey );
80 /// @throws css::uno::RuntimeException
81 VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getThisExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext );
82 /// @throws css::uno::RuntimeException
83 VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getThisWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext );
84 /// @throws css::uno::RuntimeException
85 VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext );
86 /// @throws css::uno::RuntimeException
87 VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext );
89 /// @throws css::uno::RuntimeException
90 VBAHELPER_DLLPUBLIC css::uno::Reference< css::beans::XIntrospectionAccess > getIntrospectionAccess( const css::uno::Any& aObject );
91 /// @throws css::uno::RuntimeException
92 VBAHELPER_DLLPUBLIC css::uno::Reference< css::script::XTypeConverter > const & getTypeConverter( const css::uno::Reference< css::uno::XComponentContext >& xContext );
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 * );
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 a 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, PointerStyle nPointer, 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:
141 private:
142 double m_nMillimeter;
144 public:
145 Millimeter();
147 Millimeter(double mm);
149 void setInPoints(double points) ;
150 double getInHundredthsOfOneMillimeter() const;
151 static sal_Int32 getInHundredthsOfOneMillimeter(double points);
152 static double getInPoints(int _hmm);
155 class VBAHELPER_DLLPUBLIC AbstractGeometryAttributes // probably should replace the ShapeHelper below
157 public:
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
178 css::uno::Reference< css::drawing::XShape > xShape;
179 public:
180 /// @throws css::script::BasicErrorException
181 /// @throws css::uno::RuntimeException
182 ShapeHelper( const css::uno::Reference< css::drawing::XShape >& _xShape);
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);
194 class VBAHELPER_DLLPUBLIC ConcreteXShapeGeometryAttributes final : public AbstractGeometryAttributes
196 std::unique_ptr< ShapeHelper > m_pShapeHelper;
197 public:
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;
210 #define VBA_LEFT "PositionX"
211 #define VBA_TOP "PositionY"
213 class VBAHELPER_DLLPUBLIC UserFormGeometryHelper final : public AbstractGeometryAttributes
215 public:
216 UserFormGeometryHelper(
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;
234 private:
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 );
240 private:
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 const mfOffsetX;
245 double const mfOffsetY;
246 bool const mbDialog;
249 class VBAHELPER_DLLPUBLIC ContainerUtilities
252 public:
253 static OUString getUniqueName( const css::uno::Sequence< OUString >& _slist, const OUString& _sElementName, const OUString& _sSuffixSeparator);
254 static OUString getUniqueName( const css::uno::Sequence< OUString >& _slist, const OUString& _sElementName, const OUString& _sSuffixSeparator, sal_Int32 _nStartSuffix );
256 static sal_Int32 FieldInList( const css::uno::Sequence< OUString >& SearchList, const OUString& SearchString );
259 // really just a place holder to ease the porting pain
260 class VBAHELPER_DLLPUBLIC DebugHelper
262 public:
263 /// @throws css::script::BasicErrorException
264 static void basicexception( const css::uno::Exception& ex, ErrCode err, const OUString& /*additionalArgument*/ );
266 /// @throws css::script::BasicErrorException
267 static void basicexception( ErrCode err, const OUString& additionalArgument );
269 /// @throws css::script::BasicErrorException
270 static void basicexception( const css::uno::Exception& ex );
272 /// @throws css::script::BasicErrorException
273 static void runtimeexception( ErrCode err );
276 } // vba
277 } // ooo
279 namespace ov = ooo::vba;
281 #endif
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */