Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef INCLUDED_VBAHELPER_VBAHELPER_HXX
20 : #define INCLUDED_VBAHELPER_VBAHELPER_HXX
21 :
22 : #include <com/sun/star/drawing/XShape.hpp>
23 : #include <com/sun/star/beans/XIntrospectionAccess.hpp>
24 : #include <com/sun/star/beans/XPropertySet.hpp>
25 : #include <com/sun/star/script/BasicErrorException.hpp>
26 : #include <com/sun/star/script/XTypeConverter.hpp>
27 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 : #include <com/sun/star/awt/XControl.hpp>
29 : #include <com/sun/star/awt/XDevice.hpp>
30 : #include <com/sun/star/awt/XUnitConversion.hpp>
31 : #include <basic/basmgr.hxx>
32 : #include <basic/sberrors.hxx>
33 : #include <cppuhelper/implbase1.hxx>
34 : #include <com/sun/star/frame/XModel.hpp>
35 : #include <sfx2/dispatch.hxx>
36 : #include <sfx2/objsh.hxx>
37 : #include <sfx2/docfilt.hxx>
38 : #include <sfx2/docfile.hxx>
39 : #include <vcl/pointr.hxx>
40 : #include <memory>
41 : #include <vbahelper/vbaaccesshelper.hxx>
42 :
43 : namespace ooo
44 : {
45 : namespace vba
46 : {
47 : template < class T >
48 2052 : css::uno::Reference< T > getXSomethingFromArgs( css::uno::Sequence< css::uno::Any > const & args, sal_Int32 nPos, bool bCanBeNull = true ) throw (css::lang::IllegalArgumentException)
49 : {
50 2052 : if ( args.getLength() < ( nPos + 1) )
51 1 : throw css::lang::IllegalArgumentException();
52 2051 : css::uno::Reference< T > aSomething( args[ nPos ], css::uno::UNO_QUERY );
53 2051 : if ( !bCanBeNull && !aSomething.is() )
54 0 : throw css::lang::IllegalArgumentException();
55 2051 : return aSomething;
56 : }
57 :
58 : class XHelperInterface;
59 :
60 : /** Returns the VBA document implementation object representing the passed UNO document model. */
61 : VBAHELPER_DLLPUBLIC css::uno::Reference< XHelperInterface > getVBADocument( const css::uno::Reference< css::frame::XModel >& xModel );
62 : VBAHELPER_DLLPUBLIC css::uno::Reference< XHelperInterface > getUnoDocModule( const OUString& aModName, SfxObjectShell* pShell );
63 : VBAHELPER_DLLPUBLIC SfxObjectShell* getSfxObjShell( const css::uno::Reference< css::frame::XModel >& xModel ) throw ( css::uno::RuntimeException);
64 :
65 : css::uno::Reference< css::frame::XModel > getCurrentDoc( const OUString& sKey ) throw (css::uno::RuntimeException);
66 : VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getThisExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException);
67 : VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getThisWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException);
68 : VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException);
69 : VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException);
70 :
71 : VBAHELPER_DLLPUBLIC css::uno::Reference< css::beans::XIntrospectionAccess > getIntrospectionAccess( const css::uno::Any& aObject ) throw (css::uno::RuntimeException);
72 : VBAHELPER_DLLPUBLIC css::uno::Reference< css::script::XTypeConverter > getTypeConverter( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException);
73 :
74 : VBAHELPER_DLLPUBLIC void dispatchRequests( const css::uno::Reference< css::frame::XModel>& xModel, const OUString& aUrl );
75 : VBAHELPER_DLLPUBLIC void dispatchRequests (const css::uno::Reference< css::frame::XModel>& xModel, const OUString & aUrl, const css::uno::Sequence< css::beans::PropertyValue >& sProps );
76 : VBAHELPER_DLLPUBLIC void dispatchExecute(SfxViewShell* pView, sal_uInt16 nSlot, SfxCallMode nCall = SfxCallMode::SYNCHRON );
77 : VBAHELPER_DLLPUBLIC sal_Int32 OORGBToXLRGB( sal_Int32 );
78 : VBAHELPER_DLLPUBLIC sal_Int32 XLRGBToOORGB( sal_Int32 );
79 : VBAHELPER_DLLPUBLIC css::uno::Any OORGBToXLRGB( const css::uno::Any& );
80 : VBAHELPER_DLLPUBLIC css::uno::Any XLRGBToOORGB( const css::uno::Any& );
81 : // provide a NULL object that can be passed as variant so that
82 : // the object when passed to IsNull will return true. aNULL
83 : // contains an empty object reference
84 : VBAHELPER_DLLPUBLIC const css::uno::Any& aNULL();
85 : 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 );
86 : VBAHELPER_DLLPUBLIC void PrintPreviewHelper( const css::uno::Any& EnableChanges, SfxViewShell* );
87 : VBAHELPER_DLLPUBLIC void WaitUntilPreviewIsClosed( SfxViewFrame* );
88 :
89 : /** Extracts a boolean value from the passed Any, which may contain a Boolean or an integer or floating-point value.
90 : Throws, if the Any is empty or contains an incompatible type. */
91 : VBAHELPER_DLLPUBLIC bool extractBoolFromAny( const css::uno::Any& rAny ) throw (css::uno::RuntimeException);
92 :
93 : /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string.
94 : Throws, if the Any is empty or contains an incompatible type. */
95 : VBAHELPER_DLLPUBLIC OUString extractStringFromAny( const css::uno::Any& rAny, bool bUppercaseBool = false ) throw (css::uno::RuntimeException);
96 : /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string.
97 : Returns rDefault, if rAny is empty. Throws, if the Any contains an incompatible type. */
98 : VBAHELPER_DLLPUBLIC OUString extractStringFromAny( const css::uno::Any& rAny, const OUString& rDefault, bool bUppercaseBool = false ) throw (css::uno::RuntimeException);
99 :
100 : VBAHELPER_DLLPUBLIC OUString getAnyAsString( const css::uno::Any& pvargItem ) throw ( css::uno::RuntimeException );
101 : VBAHELPER_DLLPUBLIC OUString VBAToRegexp(const OUString &rIn, bool bForLike = false); // needs to be in an uno service ( already this code is duplicated in basic )
102 : VBAHELPER_DLLPUBLIC double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference< css::awt::XDevice >& xDevice, bool bVertical);
103 : VBAHELPER_DLLPUBLIC double PointsToPixels( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, bool bVertical);
104 : VBAHELPER_DLLPUBLIC double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, bool bVertical);
105 : VBAHELPER_DLLPUBLIC sal_Int32 PointsToHmm( double fPoints );
106 : VBAHELPER_DLLPUBLIC double HmmToPoints( sal_Int32 nHmm );
107 : VBAHELPER_DLLPUBLIC PointerStyle getPointerStyle( const css::uno::Reference< css::frame::XModel >& );
108 : VBAHELPER_DLLPUBLIC void setCursorHelper( const css::uno::Reference< css::frame::XModel >& xModel, const Pointer& rPointer, bool bOverWrite );
109 : VBAHELPER_DLLPUBLIC void setDefaultPropByIntrospection( const css::uno::Any& aObj, const css::uno::Any& aValue ) throw ( css::uno::RuntimeException );
110 : VBAHELPER_DLLPUBLIC css::uno::Any getPropertyValue( const css::uno::Sequence< css::beans::PropertyValue >& aProp, const OUString& aName );
111 : VBAHELPER_DLLPUBLIC bool setPropertyValue( css::uno::Sequence< css::beans::PropertyValue >& aProp, const OUString& aName, const css::uno::Any& aValue );
112 : VBAHELPER_DLLPUBLIC void setOrAppendPropertyValue( css::uno::Sequence< css::beans::PropertyValue >& aProp, const OUString& aName, const css::uno::Any& aValue );
113 :
114 : class VBAHELPER_DLLPUBLIC Millimeter
115 : {
116 : //Factor to translate between points and hundredths of millimeters:
117 : private:
118 : double m_nMillimeter;
119 :
120 : public:
121 : Millimeter();
122 :
123 : Millimeter(double mm);
124 :
125 : void setInPoints(double points) ;
126 : double getInHundredthsOfOneMillimeter();
127 : static sal_Int32 getInHundredthsOfOneMillimeter(double points);
128 : static double getInPoints(int _hmm);
129 : };
130 :
131 114 : class VBAHELPER_DLLPUBLIC AbstractGeometryAttributes // probably should replace the ShapeHelper below
132 : {
133 : public:
134 114 : virtual ~AbstractGeometryAttributes() {}
135 : virtual double getLeft() const = 0;
136 : virtual void setLeft( double ) = 0;
137 : virtual double getTop() const = 0;
138 : virtual void setTop( double ) = 0;
139 : virtual double getHeight() const = 0;
140 : virtual void setHeight( double ) = 0;
141 : virtual double getWidth() const = 0;
142 : virtual void setWidth( double ) = 0;
143 :
144 0 : virtual double getInnerHeight() const { return 0.0; }
145 0 : virtual void setInnerHeight( double ) {}
146 0 : virtual double getInnerWidth() const { return 0.0; }
147 0 : virtual void setInnerWidth( double ) {}
148 0 : virtual double getOffsetX() const { return 0.0; }
149 0 : virtual double getOffsetY() const { return 0.0; }
150 : };
151 :
152 : namespace msforms {
153 : class XShape;
154 : }
155 :
156 96 : class VBAHELPER_DLLPUBLIC ShapeHelper
157 : {
158 : protected:
159 : css::uno::Reference< css::drawing::XShape > xShape;
160 : public:
161 : ShapeHelper( const css::uno::Reference< css::drawing::XShape >& _xShape)
162 : throw (css::script::BasicErrorException, css::uno::RuntimeException);
163 :
164 : double getHeight() const;
165 : void setHeight(double _fheight);
166 : double getWidth() const;
167 : void setWidth(double _fWidth);
168 : double getLeft() const;
169 : void setLeft(double _fLeft);
170 : double getTop() const;
171 : void setTop(double _fTop);
172 : };
173 :
174 : class VBAHELPER_DLLPUBLIC ConcreteXShapeGeometryAttributes : public AbstractGeometryAttributes
175 : {
176 : std::unique_ptr< ShapeHelper > m_pShapeHelper;
177 : public:
178 : ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& xShape );
179 : virtual double getLeft() const SAL_OVERRIDE;
180 : virtual void setLeft( double nLeft ) SAL_OVERRIDE;
181 : virtual double getTop() const SAL_OVERRIDE;
182 : virtual void setTop( double nTop ) SAL_OVERRIDE;
183 : virtual double getHeight() const SAL_OVERRIDE;
184 : virtual void setHeight( double nHeight ) SAL_OVERRIDE;
185 : virtual double getWidth() const SAL_OVERRIDE;
186 : virtual void setWidth( double nWidth) SAL_OVERRIDE;
187 : virtual ~ConcreteXShapeGeometryAttributes();
188 : };
189 :
190 : #define VBA_LEFT "PositionX"
191 : #define VBA_TOP "PositionY"
192 106 : class VBAHELPER_DLLPUBLIC UserFormGeometryHelper : public AbstractGeometryAttributes
193 : {
194 : public:
195 : UserFormGeometryHelper(
196 : const css::uno::Reference< css::uno::XComponentContext >& xContext,
197 : const css::uno::Reference< css::awt::XControl >& xControl,
198 : double fOffsetX, double fOffsetY );
199 : virtual double getLeft() const SAL_OVERRIDE;
200 : virtual void setLeft( double fLeft ) SAL_OVERRIDE;
201 : virtual double getTop() const SAL_OVERRIDE;
202 : virtual void setTop( double fTop ) SAL_OVERRIDE;
203 : virtual double getWidth() const SAL_OVERRIDE;
204 : virtual void setWidth( double fWidth ) SAL_OVERRIDE;
205 : virtual double getHeight() const SAL_OVERRIDE;
206 : virtual void setHeight( double fHeight ) SAL_OVERRIDE;
207 : virtual double getInnerWidth() const SAL_OVERRIDE;
208 : virtual void setInnerWidth( double fWidth ) SAL_OVERRIDE;
209 : virtual double getInnerHeight() const SAL_OVERRIDE;
210 : virtual void setInnerHeight( double fHeight ) SAL_OVERRIDE;
211 : virtual double getOffsetX() const SAL_OVERRIDE;
212 : virtual double getOffsetY() const SAL_OVERRIDE;
213 :
214 : private:
215 : double implGetPos( bool bPosY ) const;
216 : void implSetPos( double fPos, bool bPosY );
217 : double implGetSize( bool bHeight, bool bOuter ) const;
218 : void implSetSize( double fSize, bool bHeight, bool bOuter );
219 :
220 : private:
221 : css::uno::Reference< css::awt::XWindow > mxWindow;
222 : css::uno::Reference< css::beans::XPropertySet > mxModelProps;
223 : css::uno::Reference< css::awt::XUnitConversion > mxUnitConv;
224 : double mfOffsetX;
225 : double mfOffsetY;
226 : bool mbDialog;
227 : };
228 :
229 : class VBAHELPER_DLLPUBLIC ContainerUtilities
230 : {
231 :
232 : public:
233 : static OUString getUniqueName( const css::uno::Sequence< OUString >& _slist, const OUString& _sElementName, const OUString& _sSuffixSeparator);
234 : static OUString getUniqueName( const css::uno::Sequence< OUString >& _slist, const OUString& _sElementName, const OUString& _sSuffixSeparator, sal_Int32 _nStartSuffix );
235 :
236 : static sal_Int32 FieldInList( const css::uno::Sequence< OUString >& SearchList, const OUString& SearchString );
237 : };
238 :
239 : // really just a place holder to ease the porting pain
240 : class VBAHELPER_DLLPUBLIC DebugHelper
241 : {
242 : public:
243 : static void basicexception( const OUString& DetailedMessage, const css::uno::Exception& ex, int err, const OUString& /*additionalArgument*/ ) throw( css::script::BasicErrorException );
244 :
245 : static void basicexception( int err, const OUString& additionalArgument ) throw( css::script::BasicErrorException );
246 :
247 : static void basicexception( const css::uno::Exception& ex ) throw( css::script::BasicErrorException );
248 :
249 : static void runtimeexception( const OUString& DetailedMessage, const css::uno::Exception& ex, int err, const OUString& /*additionalArgument*/ ) throw( css::uno::RuntimeException );
250 :
251 : static void runtimeexception( int err, const OUString& additionalArgument ) throw( css::uno::RuntimeException );
252 : };
253 :
254 : } // vba
255 : } // ooo
256 :
257 : namespace ov = ooo::vba;
258 :
259 : #endif
260 :
261 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|