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