bump product version to 5.0.4.1
[LibreOffice.git] / basic / source / inc / sbunoobj.hxx
blob12b9cd73ef96c9273a24fac05d03161fd65ba089
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_BASIC_SOURCE_INC_SBUNOOBJ_HXX
20 #define INCLUDED_BASIC_SOURCE_INC_SBUNOOBJ_HXX
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/lang/XComponent.hpp>
32 #include <com/sun/star/script/XInvocation.hpp>
33 #include <com/sun/star/reflection/XIdlClass.hpp>
34 #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
35 #include <com/sun/star/reflection/XSingletonTypeDescription.hpp>
36 #include <rtl/ustring.hxx>
37 #include <unordered_map>
38 #include <vector>
39 #include <map>
40 #include <boost/shared_ptr.hpp>
42 void registerComponentToBeDisposedForBasic( css::uno::Reference< css::lang::XComponent > xComponent, StarBASIC* pBasic );
44 class StructRefInfo
46 com::sun::star::uno::Any& maAny;
47 css::uno::Type maType;
48 sal_Int32 mnPos;
49 public:
50 StructRefInfo( com::sun::star::uno::Any& aAny, css::uno::Type const & rType, sal_Int32 nPos ) : maAny( aAny ), maType( rType ), mnPos( nPos ) {}
52 sal_Int32 getPos() const { return mnPos; }
53 css::uno::Type getType() const { return maType; }
54 OUString getTypeName() const;
55 com::sun::star::uno::Any& getRootAnyRef() { return maAny; };
57 com::sun::star::uno::TypeClass getTypeClass() const;
59 void* getInst();
60 bool isEmpty() { return (mnPos == -1); }
62 ::com::sun::star::uno::Any getValue();
63 bool setValue( const ::com::sun::star::uno::Any& );
66 class SbUnoStructRefObject: public SbxObject
68 struct caseLessComp
70 bool operator() (const OUString& rProp, const OUString& rOtherProp ) const
72 return rProp.toAsciiUpperCase().compareTo( rOtherProp.toAsciiUpperCase() ) < 0;
75 typedef ::std::map< OUString, StructRefInfo*, caseLessComp > StructFieldInfo;
76 StructFieldInfo maFields;
77 StructRefInfo maMemberInfo;
78 bool mbMemberCacheInit;
79 void implCreateAll();
80 void implCreateDbgProperties();
81 void initMemberCache();
82 OUString Impl_DumpProperties();
83 OUString getDbgObjectName();
84 public:
85 TYPEINFO_OVERRIDE();
86 StructRefInfo getStructMember( const OUString& rMember );
87 StructRefInfo getStructInfo() { return maMemberInfo; }
88 SbUnoStructRefObject( const OUString& aName_, const StructRefInfo& rMemberInfo );
89 virtual ~SbUnoStructRefObject();
91 // override Find to support e. g. NameAccess
92 virtual SbxVariable* Find( const OUString&, SbxClassType ) SAL_OVERRIDE;
94 // Force creation of all properties for debugging
95 void createAllProperties()
96 { implCreateAll(); }
98 // give out value
99 ::com::sun::star::uno::Any getUnoAny();
100 void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& ) SAL_OVERRIDE;
103 class SbUnoObject: public SbxObject
105 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess > mxUnoAccess;
106 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMaterialHolder > mxMaterialHolder;
107 ::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > mxInvocation;
108 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XExactName > mxExactName;
109 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XExactName > mxExactNameInvocation;
110 bool bNeedIntrospection;
111 bool bNativeCOMObject;
112 ::com::sun::star::uno::Any maTmpUnoObj; // Only to save obj for doIntrospection!
113 ::boost::shared_ptr< SbUnoStructRefObject > maStructInfo;
114 // help method to establish the dbg_-properties
115 void implCreateDbgProperties();
117 // help method to establish all properties and methods
118 // (on the on-demand-mechanism required for the dbg_-properties)
119 void implCreateAll();
121 public:
122 static bool getDefaultPropName( SbUnoObject* pUnoObj, OUString& sDfltProp );
123 TYPEINFO_OVERRIDE();
124 SbUnoObject( const OUString& aName_, const ::com::sun::star::uno::Any& aUnoObj_ );
125 virtual ~SbUnoObject();
127 // #76470 do introspection on demand
128 void doIntrospection();
130 // override Find to support e. g. NameAccess
131 virtual SbxVariable* Find( const OUString&, SbxClassType ) SAL_OVERRIDE;
133 // Force creation of all properties for debugging
134 void createAllProperties()
135 { implCreateAll(); }
137 // give out value
138 ::com::sun::star::uno::Any getUnoAny();
139 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess > getIntrospectionAccess() { return mxUnoAccess; }
140 ::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > getInvocation() { return mxInvocation; }
142 void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& ) SAL_OVERRIDE;
144 bool isNativeCOMObject()
145 { return bNativeCOMObject; }
147 typedef tools::SvRef<SbUnoObject> SbUnoObjectRef;
149 // #67781 delete return values of the uno-methods
150 void clearUnoMethods();
151 void clearUnoMethodsForBasic( StarBASIC* pBasic );
153 class SbUnoMethod : public SbxMethod
155 friend class SbUnoObject;
156 friend void clearUnoMethods();
157 friend void clearUnoMethodsForBasic( StarBASIC* pBasic );
159 ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlMethod > m_xUnoMethod;
160 ::com::sun::star::uno::Sequence< ::com::sun::star::reflection::ParamInfo >* pParamInfoSeq;
162 // #67781 reference to the previous and the next method in the method list
163 SbUnoMethod* pPrev;
164 SbUnoMethod* pNext;
166 bool mbInvocation; // Method is based on invocation
167 bool mbDirectInvocation; // Method should be used with XDirectInvocation interface
169 public:
170 TYPEINFO_OVERRIDE();
172 SbUnoMethod( const OUString& aName_, SbxDataType eSbxType, ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlMethod > xUnoMethod_,
173 bool bInvocation,
174 bool bDirect = false );
175 virtual ~SbUnoMethod();
176 virtual SbxInfo* GetInfo() SAL_OVERRIDE;
178 const ::com::sun::star::uno::Sequence< ::com::sun::star::reflection::ParamInfo >& getParamInfos();
180 bool isInvocationBased()
181 { return mbInvocation; }
182 bool needsDirectInvocation()
183 { return mbDirectInvocation; }
188 class SbUnoProperty : public SbxProperty
190 friend class SbUnoObject;
191 friend class SbUnoStructRefObject;
193 ::com::sun::star::beans::Property aUnoProp;
194 sal_Int32 nId;
196 bool mbInvocation; // Property is based on invocation
197 SbxDataType mRealType;
198 virtual ~SbUnoProperty();
199 bool mbUnoStruct;
200 SbUnoProperty( const SbUnoProperty&) SAL_DELETED_FUNCTION;
201 SbUnoProperty& operator = ( const SbUnoProperty&) SAL_DELETED_FUNCTION;
202 public:
204 TYPEINFO_OVERRIDE();
205 SbUnoProperty( const OUString& aName_, SbxDataType eSbxType, SbxDataType eRealSbxType,
206 const ::com::sun::star::beans::Property& aUnoProp_, sal_Int32 nId_, bool bInvocation, bool bUnoStruct );
208 bool isUnoStruct() { return mbUnoStruct; }
209 bool isInvocationBased()
210 { return mbInvocation; }
211 SbxDataType getRealType() { return mRealType; }
214 // factory class to create uno-structs per DIM AS NEW
215 class SbUnoFactory : public SbxFactory
217 public:
218 virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 = SBXCR_SBX ) SAL_OVERRIDE;
219 virtual SbxObject* CreateObject( const OUString& ) SAL_OVERRIDE;
222 // wrapper for an uno-class
223 class SbUnoClass : public SbxObject
225 const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass > m_xClass;
227 public:
228 TYPEINFO_OVERRIDE();
229 SbUnoClass( const OUString& aName_ )
230 : SbxObject( aName_ )
232 SbUnoClass( const OUString& aName_, const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass >& xClass_ )
233 : SbxObject( aName_ )
234 , m_xClass( xClass_ )
238 virtual SbxVariable* Find( const OUString&, SbxClassType ) SAL_OVERRIDE;
241 const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass >& getUnoClass() { return m_xClass; }
246 // function to find a global identifier in
247 // the UnoScope and to wrap it for Sbx
248 SbUnoClass* findUnoClass( const OUString& rName );
251 // Wrapper for UNO Service
252 class SbUnoService : public SbxObject
254 const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceTypeDescription2 > m_xServiceTypeDesc;
255 bool m_bNeedsInit;
257 public:
258 TYPEINFO_OVERRIDE();
259 SbUnoService( const OUString& aName_,
260 const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceTypeDescription2 >& xServiceTypeDesc )
261 : SbxObject( aName_ )
262 , m_xServiceTypeDesc( xServiceTypeDesc )
263 , m_bNeedsInit( true )
266 virtual SbxVariable* Find( const OUString&, SbxClassType ) SAL_OVERRIDE;
268 void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& ) SAL_OVERRIDE;
271 SbUnoService* findUnoService( const OUString& rName );
274 void clearUnoServiceCtors();
276 class SbUnoServiceCtor : public SbxMethod
278 friend class SbUnoService;
279 friend void clearUnoServiceCtors();
281 ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceConstructorDescription > m_xServiceCtorDesc;
283 SbUnoServiceCtor* pNext;
285 public:
286 TYPEINFO_OVERRIDE();
288 SbUnoServiceCtor( const OUString& aName_, ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceConstructorDescription > xServiceCtorDesc );
289 virtual ~SbUnoServiceCtor();
290 virtual SbxInfo* GetInfo() SAL_OVERRIDE;
292 ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceConstructorDescription > getServiceCtorDesc()
293 { return m_xServiceCtorDesc; }
297 // Wrapper for UNO Singleton
298 class SbUnoSingleton : public SbxObject
300 const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XSingletonTypeDescription > m_xSingletonTypeDesc;
302 public:
303 TYPEINFO_OVERRIDE();
304 SbUnoSingleton( const OUString& aName_,
305 const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XSingletonTypeDescription >& xSingletonTypeDesc );
307 void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& ) SAL_OVERRIDE;
310 SbUnoSingleton* findUnoSingleton( const OUString& rName );
313 // #105565 Special Object to wrap a strongly typed Uno Any
314 class SbUnoAnyObject: public SbxObject
316 ::com::sun::star::uno::Any mVal;
318 public:
319 SbUnoAnyObject( const ::com::sun::star::uno::Any& rVal )
320 : SbxObject( OUString() )
321 , mVal( rVal )
324 const ::com::sun::star::uno::Any& getValue()
325 { return mVal; }
327 TYPEINFO_OVERRIDE();
331 // #112509 Special SbxArray to transport named parameters for calls
332 // to OLEAutomation objects through the UNO OLE automation bridge
334 class AutomationNamedArgsSbxArray : public SbxArray
336 ::com::sun::star::uno::Sequence< OUString > maNameSeq;
337 public:
338 TYPEINFO_OVERRIDE();
339 AutomationNamedArgsSbxArray( sal_Int32 nSeqSize )
340 : maNameSeq( nSeqSize )
343 ::com::sun::star::uno::Sequence< OUString >& getNames()
344 { return maNameSeq; }
348 class StarBASIC;
350 // Impl-methods for RTL
351 void RTL_Impl_CreateUnoStruct( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
352 void RTL_Impl_CreateUnoService( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
353 void RTL_Impl_CreateUnoServiceWithArguments( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
354 void RTL_Impl_CreateUnoValue( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
355 void RTL_Impl_GetProcessServiceManager( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
356 void RTL_Impl_HasInterfaces( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
357 void RTL_Impl_IsUnoStruct( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
358 void RTL_Impl_EqualUnoObjects( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
359 void RTL_Impl_GetDefaultContext( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
361 void disposeComVariablesForBasic( StarBASIC* pBasic );
362 void clearNativeObjectWrapperVector();
366 // #118116 Collection object
368 class BasicCollection : public SbxObject
370 friend class SbiRuntime;
371 SbxArrayRef xItemArray;
372 static SbxInfoRef xAddInfo;
373 static SbxInfoRef xItemInfo;
375 void Initialize();
376 virtual ~BasicCollection();
377 virtual void SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
378 const SfxHint& rHint, const TypeId& rHintType ) SAL_OVERRIDE;
379 sal_Int32 implGetIndex( SbxVariable* pIndexVar );
380 sal_Int32 implGetIndexForName( const OUString& rName );
381 void CollAdd( SbxArray* pPar_ );
382 void CollItem( SbxArray* pPar_ );
383 void CollRemove( SbxArray* pPar_ );
385 public:
386 TYPEINFO_OVERRIDE();
387 BasicCollection( const OUString& rClassname );
388 virtual SbxVariable* Find( const OUString&, SbxClassType ) SAL_OVERRIDE;
389 virtual void Clear() SAL_OVERRIDE;
392 typedef std::unordered_map< OUString, ::com::sun::star::uno::Any, OUStringHash, ::std::equal_to< OUString > > VBAConstantsHash;
394 typedef std::vector< OUString > VBAConstantsVector;
396 class VBAConstantHelper
398 private:
400 VBAConstantsVector aConstCache;
401 VBAConstantsHash aConstHash;
402 bool isInited;
403 VBAConstantHelper():isInited( false ) {}
404 VBAConstantHelper(const VBAConstantHelper&) SAL_DELETED_FUNCTION;
405 void init();
406 public:
407 static VBAConstantHelper& instance();
408 SbxVariable* getVBAConstant( const OUString& rName );
409 bool isVBAConstantType( const OUString& rName );
412 SbxVariable* getDefaultProp( SbxVariable* pRef );
414 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createComListener( const ::com::sun::star::uno::Any& aControlAny,
415 const OUString& aVBAType,
416 const OUString& aPrefix,
417 SbxObjectRef xScopeObj );
419 bool checkUnoObjectType( SbUnoObject* refVal, const OUString& aClass );
421 SbUnoObject* createOLEObject_Impl( const OUString& aType );
423 // #55226 ship additional information
424 bool handleToStringForCOMObjects( SbxObject* pObj, SbxValue* pVal );
426 void registerComListenerVariableForBasic( SbxVariable* pVar, StarBASIC* pBasic );
428 #endif
430 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */