1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
40 #include <boost/shared_ptr.hpp>
42 void registerComponentToBeDisposedForBasic( css::uno::Reference
< css::lang::XComponent
> xComponent
, StarBASIC
* pBasic
);
46 com::sun::star::uno::Any
& maAny
;
47 css::uno::Type maType
;
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;
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
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
;
80 void implCreateDbgProperties();
81 void initMemberCache();
82 OUString
Impl_DumpProperties();
83 OUString
getDbgObjectName();
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()
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();
122 static bool getDefaultPropName( SbUnoObject
* pUnoObj
, OUString
& sDfltProp
);
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()
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
166 bool mbInvocation
; // Method is based on invocation
167 bool mbDirectInvocation
; // Method should be used with XDirectInvocation interface
172 SbUnoMethod( const OUString
& aName_
, SbxDataType eSbxType
, ::com::sun::star::uno::Reference
< ::com::sun::star::reflection::XIdlMethod
> xUnoMethod_
,
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
;
196 bool mbInvocation
; // Property is based on invocation
197 SbxDataType mRealType
;
198 virtual ~SbUnoProperty();
200 SbUnoProperty( const SbUnoProperty
&) SAL_DELETED_FUNCTION
;
201 SbUnoProperty
& operator = ( const SbUnoProperty
&) SAL_DELETED_FUNCTION
;
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
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
;
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
;
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
;
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
;
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
;
319 SbUnoAnyObject( const ::com::sun::star::uno::Any
& rVal
)
320 : SbxObject( OUString() )
324 const ::com::sun::star::uno::Any
& getValue()
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
;
339 AutomationNamedArgsSbxArray( sal_Int32 nSeqSize
)
340 : maNameSeq( nSeqSize
)
343 ::com::sun::star::uno::Sequence
< OUString
>& getNames()
344 { return maNameSeq
; }
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
;
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_
);
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
400 VBAConstantsVector aConstCache
;
401 VBAConstantsHash aConstHash
;
403 VBAConstantHelper():isInited( false ) {}
404 VBAConstantHelper(const VBAConstantHelper
&) SAL_DELETED_FUNCTION
;
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
);
430 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */