Branch data 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 SB_UNO_OBJ
20 : : #define SB_UNO_OBJ
21 : :
22 : : #include <basic/sbxobj.hxx>
23 : : #include <basic/sbxmeth.hxx>
24 : : #include <basic/sbxprop.hxx>
25 : : #include <basic/sbxfac.hxx>
26 : : #include <basic/sbx.hxx>
27 : : #include <com/sun/star/beans/XMaterialHolder.hpp>
28 : : #include <com/sun/star/beans/XExactName.hpp>
29 : : #include <com/sun/star/beans/XIntrospectionAccess.hpp>
30 : : #include <com/sun/star/beans/XIntrospection.hpp>
31 : : #include <com/sun/star/script/XInvocation.hpp>
32 : : #include <com/sun/star/reflection/XIdlClass.hpp>
33 : : #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
34 : : #include <com/sun/star/reflection/XSingletonTypeDescription.hpp>
35 : : #include <rtl/ustring.hxx>
36 : : #include <boost/unordered_map.hpp>
37 : : #include <vector>
38 : : #include <map>
39 : : #include <boost/shared_ptr.hpp>
40 : :
41 : : class StructRefInfo
42 : : {
43 : : StructRefInfo();
44 : : com::sun::star::uno::Any& maAny;
45 : : typelib_TypeDescription* mpTD;
46 : : sal_Int32 mnPos;
47 : : public:
48 : 594 : StructRefInfo( com::sun::star::uno::Any& aAny, typelib_TypeDescription* pTD, sal_Int32 nPos ) : maAny( aAny ), mpTD( pTD ), mnPos( nPos ) {}
49 : :
50 : 267 : sal_Int32 getPos() const { return mnPos; }
51 : 66 : typelib_TypeDescription* getTD() const { return mpTD; }
52 : : rtl::OUString getTypeName() const;
53 : 267 : com::sun::star::uno::Any& getRootAnyRef() { return maAny; };
54 : :
55 : : com::sun::star::uno::TypeClass getTypeClass() const;
56 : :
57 : : void* getInst();
58 : 39 : bool isEmpty() { return (mnPos == -1); }
59 : :
60 : : ::com::sun::star::uno::Any getValue();
61 : : void setValue( const ::com::sun::star::uno::Any& );
62 : : };
63 : :
64 : : class SbUnoStructRefObject: public SbxObject
65 : : {
66 : : struct caseLessComp
67 : : {
68 : 1296 : bool operator() (const ::rtl::OUString& rProp, const ::rtl::OUString& rOtherProp ) const
69 : : {
70 : 1296 : return rProp.toAsciiUpperCase().compareTo( rOtherProp.toAsciiUpperCase() ) < 0;
71 : : }
72 : : };
73 : : typedef ::std::map< rtl::OUString, StructRefInfo*, caseLessComp > StructFieldInfo;
74 : : StructFieldInfo maFields;
75 : : StructRefInfo maMemberInfo;
76 : : bool mbMemberCacheInit;
77 : : void implCreateAll();
78 : : void implCreateDbgProperties();
79 : : void initMemberCache();
80 : : rtl::OUString Impl_DumpProperties();
81 : : rtl::OUString getDbgObjectName();
82 : : public:
83 : : TYPEINFO();
84 : : StructRefInfo getStructMember( const rtl::OUString& rMember );
85 : 9 : StructRefInfo getStructInfo() { return maMemberInfo; }
86 : : SbUnoStructRefObject( const ::rtl::OUString& aName_, const StructRefInfo& rMemberInfo );
87 : : ~SbUnoStructRefObject();
88 : :
89 : : // Find overloaded to support e. g. NameAccess
90 : : virtual SbxVariable* Find( const rtl::OUString&, SbxClassType );
91 : :
92 : : // Force creation of all properties for debugging
93 : 0 : void createAllProperties( void )
94 : 0 : { implCreateAll(); }
95 : :
96 : : // give out value
97 : : ::com::sun::star::uno::Any getUnoAny();
98 : : void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& );
99 : : };
100 : : SV_DECL_IMPL_REF(SbUnoStructRefObject);
101 : :
102 : : class SbUnoObject: public SbxObject
103 : : {
104 : : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess > mxUnoAccess;
105 : : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMaterialHolder > mxMaterialHolder;
106 : : ::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > mxInvocation;
107 : : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XExactName > mxExactName;
108 : : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XExactName > mxExactNameInvocation;
109 : : bool bNeedIntrospection;
110 : : bool bNativeCOMObject;
111 : : ::com::sun::star::uno::Any maTmpUnoObj; // Only to save obj for doIntrospection!
112 : : ::boost::shared_ptr< SbUnoStructRefObject > maStructInfo;
113 : : // help method to establish the dbg_-properties
114 : : void implCreateDbgProperties( void );
115 : :
116 : : // help method to establish all properties and methods
117 : : // (on the on-demand-mechanism required for the dbg_-properties)
118 : : void implCreateAll( void );
119 : :
120 : : public:
121 : : static bool getDefaultPropName( SbUnoObject* pUnoObj, ::rtl::OUString& sDfltProp );
122 : : TYPEINFO();
123 : : SbUnoObject( const ::rtl::OUString& aName_, const ::com::sun::star::uno::Any& aUnoObj_ );
124 : : ~SbUnoObject();
125 : :
126 : : // #76470 do introspection on demand
127 : : void doIntrospection( void );
128 : :
129 : : // Find overloaded to support e. g. NameAccess
130 : : virtual SbxVariable* Find( const rtl::OUString&, SbxClassType );
131 : :
132 : : // Force creation of all properties for debugging
133 : 0 : void createAllProperties( void )
134 : 0 : { implCreateAll(); }
135 : :
136 : : // give out value
137 : : ::com::sun::star::uno::Any getUnoAny( void );
138 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess > getIntrospectionAccess( void ) { return mxUnoAccess; }
139 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > getInvocation( void ) { return mxInvocation; }
140 : :
141 : : void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& );
142 : :
143 : 0 : bool isNativeCOMObject( void )
144 : 0 : { return bNativeCOMObject; }
145 : : };
146 [ + - ][ + - ]: 718 : SV_DECL_IMPL_REF(SbUnoObject);
147 : :
148 : : // #67781 delete return values of the uno-methods
149 : : void clearUnoMethods( void );
150 : : void clearUnoMethodsForBasic( StarBASIC* pBasic );
151 : :
152 : : class SbUnoMethod : public SbxMethod
153 : : {
154 : : friend class SbUnoObject;
155 : : friend void clearUnoMethods( void );
156 : : friend void clearUnoMethodsForBasic( StarBASIC* pBasic );
157 : :
158 : : ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlMethod > m_xUnoMethod;
159 : : ::com::sun::star::uno::Sequence< ::com::sun::star::reflection::ParamInfo >* pParamInfoSeq;
160 : :
161 : : // #67781 reference to the previous and the next method in the method list
162 : : SbUnoMethod* pPrev;
163 : : SbUnoMethod* pNext;
164 : :
165 : : bool mbInvocation; // Method is based on invocation
166 : : bool mbDirectInvocation; // Method should be used with XDirectInvocation interface
167 : :
168 : : public:
169 : : TYPEINFO();
170 : :
171 : : SbUnoMethod( const rtl::OUString& aName_, SbxDataType eSbxType, ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlMethod > xUnoMethod_,
172 : : bool bInvocation,
173 : : bool bDirect = false );
174 : : virtual ~SbUnoMethod();
175 : : virtual SbxInfo* GetInfo();
176 : :
177 : : const ::com::sun::star::uno::Sequence< ::com::sun::star::reflection::ParamInfo >& getParamInfos( void );
178 : :
179 : 446 : bool isInvocationBased( void )
180 : 446 : { return mbInvocation; }
181 : : bool needsDirectInvocation( void )
182 : : { return mbDirectInvocation; }
183 : : };
184 : :
185 : :
186 : :
187 : : class SbUnoProperty : public SbxProperty
188 : : {
189 : : friend class SbUnoObject;
190 : : friend class SbUnoStructRefObject;
191 : :
192 : : ::com::sun::star::beans::Property aUnoProp;
193 : : sal_Int32 nId;
194 : :
195 : : bool mbInvocation; // Property is based on invocation
196 : : SbxDataType mRealType;
197 : : virtual ~SbUnoProperty();
198 : : bool mbUnoStruct;
199 : : SbUnoProperty( const SbUnoProperty&);
200 : : SbUnoProperty& operator = ( const SbUnoProperty&);
201 : : public:
202 : :
203 : : TYPEINFO();
204 : : SbUnoProperty( const rtl::OUString& aName_, SbxDataType eSbxType, SbxDataType eRealSbxType,
205 : : const ::com::sun::star::beans::Property& aUnoProp_, sal_Int32 nId_, bool bInvocation, bool bUnoStruct );
206 : :
207 : 141 : bool isUnoStruct() { return mbUnoStruct; }
208 : 338 : bool isInvocationBased( void )
209 : 338 : { return mbInvocation; }
210 : 0 : SbxDataType getRealType() { return mRealType; }
211 : : };
212 : :
213 : : // factory class to create uno-structs per DIM AS NEW
214 [ - + ]: 420 : class SbUnoFactory : public SbxFactory
215 : : {
216 : : public:
217 : : virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 = SBXCR_SBX );
218 : : virtual SbxObject* CreateObject( const rtl::OUString& );
219 : : };
220 : :
221 : : // wrapper for an uno-class
222 [ + - ][ + - ]: 20 : class SbUnoClass : public SbxObject
[ - + ][ # # ]
223 : : {
224 : : const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass > m_xClass;
225 : :
226 : : public:
227 : : TYPEINFO();
228 : 10 : SbUnoClass( const String& aName_ )
229 [ + - ]: 10 : : SbxObject( aName_ )
230 : 10 : {}
231 : 0 : SbUnoClass( const String& aName_, const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass >& xClass_ )
232 : : : SbxObject( aName_ )
233 [ # # ]: 0 : , m_xClass( xClass_ )
234 : 0 : {}
235 : :
236 : :
237 : : virtual SbxVariable* Find( const rtl::OUString&, SbxClassType );
238 : :
239 : :
240 : 0 : const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass >& getUnoClass( void ) { return m_xClass; }
241 : :
242 : : };
243 : : SV_DECL_IMPL_REF(SbUnoClass);
244 : :
245 : :
246 : : // function to find a global identifier in
247 : : // the UnoScope and to wrap it for Sbx
248 : : SbUnoClass* findUnoClass( const ::rtl::OUString& rName );
249 : :
250 : :
251 : : // Wrapper for UNO Service
252 [ # # ][ # # ]: 0 : class SbUnoService : public SbxObject
[ # # ][ # # ]
253 : : {
254 : : const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceTypeDescription2 > m_xServiceTypeDesc;
255 : : bool m_bNeedsInit;
256 : :
257 : : public:
258 : : TYPEINFO();
259 : 0 : SbUnoService( const String& aName_,
260 : : const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceTypeDescription2 >& xServiceTypeDesc )
261 : : : SbxObject( aName_ )
262 : : , m_xServiceTypeDesc( xServiceTypeDesc )
263 [ # # ]: 0 : , m_bNeedsInit( true )
264 : 0 : {}
265 : :
266 : : virtual SbxVariable* Find( const rtl::OUString&, SbxClassType );
267 : :
268 : : void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& );
269 : : };
270 : : SV_DECL_IMPL_REF(SbUnoService);
271 : :
272 : : SbUnoService* findUnoService( const ::rtl::OUString& rName );
273 : :
274 : :
275 : : void clearUnoServiceCtors( void );
276 : :
277 : : class SbUnoServiceCtor : public SbxMethod
278 : : {
279 : : friend class SbUnoService;
280 : : friend void clearUnoServiceCtors( void );
281 : :
282 : : ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceConstructorDescription > m_xServiceCtorDesc;
283 : :
284 : : SbUnoServiceCtor* pNext;
285 : :
286 : : public:
287 : : TYPEINFO();
288 : :
289 : : SbUnoServiceCtor( const::rtl::OUString& aName_, ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceConstructorDescription > xServiceCtorDesc );
290 : : virtual ~SbUnoServiceCtor();
291 : : virtual SbxInfo* GetInfo();
292 : :
293 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceConstructorDescription > getServiceCtorDesc( void )
294 : 0 : { return m_xServiceCtorDesc; }
295 : : };
296 : :
297 : :
298 : : // Wrapper for UNO Singleton
299 [ # # ][ # # ]: 0 : class SbUnoSingleton : public SbxObject
[ # # ][ # # ]
300 : : {
301 : : const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XSingletonTypeDescription > m_xSingletonTypeDesc;
302 : :
303 : : public:
304 : : TYPEINFO();
305 : : SbUnoSingleton( const ::rtl::OUString& aName_,
306 : : const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XSingletonTypeDescription >& xSingletonTypeDesc );
307 : :
308 : : void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& );
309 : : };
310 : : SV_DECL_IMPL_REF(SbUnoSingleton);
311 : :
312 : : SbUnoSingleton* findUnoSingleton( const ::rtl::OUString& rName );
313 : :
314 : :
315 : : // #105565 Special Object to wrap a strongly typed Uno Any
316 [ # # ][ # # ]: 0 : class SbUnoAnyObject: public SbxObject
[ # # ][ # # ]
317 : : {
318 : : ::com::sun::star::uno::Any mVal;
319 : :
320 : : public:
321 : 0 : SbUnoAnyObject( const ::com::sun::star::uno::Any& rVal )
322 : : : SbxObject( String() )
323 [ # # ][ # # ]: 0 : , mVal( rVal )
[ # # ]
324 : 0 : {}
325 : :
326 : 0 : const ::com::sun::star::uno::Any& getValue( void )
327 : 0 : { return mVal; }
328 : :
329 : : TYPEINFO();
330 : : };
331 : :
332 : :
333 : : // #112509 Special SbxArray to transport named parameters for calls
334 : : // to OLEAutomation objects through the UNO OLE automation bridge
335 : :
336 [ # # ][ # # ]: 0 : class AutomationNamedArgsSbxArray : public SbxArray
[ # # ][ # # ]
[ # # ]
337 : : {
338 : : ::com::sun::star::uno::Sequence< ::rtl::OUString > maNameSeq;
339 : : public:
340 : : TYPEINFO();
341 : 0 : AutomationNamedArgsSbxArray( sal_Int32 nSeqSize )
342 [ # # ][ # # ]: 0 : : maNameSeq( nSeqSize )
343 : 0 : {}
344 : :
345 : 0 : ::com::sun::star::uno::Sequence< ::rtl::OUString >& getNames( void )
346 : 0 : { return maNameSeq; }
347 : : };
348 : :
349 : :
350 : : class StarBASIC;
351 : :
352 : : // Impl-methods for RTL
353 : : void RTL_Impl_CreateUnoStruct( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
354 : : void RTL_Impl_CreateUnoService( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
355 : : void RTL_Impl_CreateUnoServiceWithArguments( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
356 : : void RTL_Impl_CreateUnoValue( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
357 : : void RTL_Impl_GetProcessServiceManager( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
358 : : void RTL_Impl_HasInterfaces( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
359 : : void RTL_Impl_IsUnoStruct( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
360 : : void RTL_Impl_EqualUnoObjects( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
361 : : void RTL_Impl_GetDefaultContext( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
362 : :
363 : : void disposeComVariablesForBasic( StarBASIC* pBasic );
364 : : void clearNativeObjectWrapperVector( void );
365 : :
366 : :
367 : : //========================================================================
368 : : // #118116 Collection object
369 : :
370 : : class BasicCollection : public SbxObject
371 : : {
372 : : friend class SbiRuntime;
373 : : SbxArrayRef xItemArray;
374 : : static SbxInfoRef xAddInfo;
375 : : static SbxInfoRef xItemInfo;
376 : :
377 : : void Initialize();
378 : : virtual ~BasicCollection();
379 : : virtual void SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
380 : : const SfxHint& rHint, const TypeId& rHintType );
381 : : sal_Int32 implGetIndex( SbxVariable* pIndexVar );
382 : : sal_Int32 implGetIndexForName( const String& rName );
383 : : void CollAdd( SbxArray* pPar_ );
384 : : void CollItem( SbxArray* pPar_ );
385 : : void CollRemove( SbxArray* pPar_ );
386 : :
387 : : public:
388 : : TYPEINFO();
389 : : BasicCollection( const rtl::OUString& rClassname );
390 : : virtual SbxVariable* Find( const rtl::OUString&, SbxClassType );
391 : : virtual void Clear();
392 : : };
393 : :
394 : : typedef boost::unordered_map< ::rtl::OUString, ::com::sun::star::uno::Any, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > VBAConstantsHash;
395 : :
396 : : typedef std::vector< rtl::OUString > VBAConstantsVector;
397 : :
398 [ + - ]: 5 : class VBAConstantHelper
399 : : {
400 : : private:
401 : :
402 : : VBAConstantsVector aConstCache;
403 : : VBAConstantsHash aConstHash;
404 : : bool isInited;
405 [ + - ]: 5 : VBAConstantHelper():isInited( false ) {}
406 : : VBAConstantHelper(const VBAConstantHelper&);
407 : : void init();
408 : : public:
409 : : static VBAConstantHelper& instance();
410 : : SbxVariable* getVBAConstant( const ::rtl::OUString& rName );
411 : : bool isVBAConstantType( const ::rtl::OUString& rName );
412 : : };
413 : :
414 : : #endif
415 : :
416 : :
417 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|