1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sbunoobj.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include <basic/sbxobj.hxx>
34 #include <basic/sbxmeth.hxx>
35 #include <basic/sbxprop.hxx>
36 #include <basic/sbxfac.hxx>
37 #ifndef __SBX_SBX_HXX //autogen
38 #include <basic/sbx.hxx>
40 #include <com/sun/star/beans/XMaterialHolder.hpp>
41 #include <com/sun/star/beans/XExactName.hpp>
42 #include <com/sun/star/beans/XIntrospectionAccess.hpp>
43 #include <com/sun/star/beans/XIntrospection.hpp>
44 #include <com/sun/star/script/XInvocation.hpp>
45 #include <com/sun/star/reflection/XIdlClass.hpp>
46 #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
47 #include <rtl/ustring.hxx>
50 class SbUnoObject
: public SbxObject
52 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XIntrospectionAccess
> mxUnoAccess
;
53 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XMaterialHolder
> mxMaterialHolder
;
54 ::com::sun::star::uno::Reference
< ::com::sun::star::script::XInvocation
> mxInvocation
;
55 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XExactName
> mxExactName
;
56 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XExactName
> mxExactNameInvocation
;
57 BOOL bNeedIntrospection
;
58 ::com::sun::star::uno::Any maTmpUnoObj
; // Only to save obj for doIntrospection!
60 // Hilfs-Methode zum Anlegen der dbg_-Properties
61 void implCreateDbgProperties( void );
63 // Hilfs-Methode zum Anlegen aller Properties und Methoden
64 // (Beim on-demand-Mechanismus erforderlich fuer die dbg_-Properties)
65 void implCreateAll( void );
68 static bool getDefaultPropName( SbUnoObject
* pUnoObj
, String
& sDfltProp
);
70 SbUnoObject( const String
& aName_
, const ::com::sun::star::uno::Any
& aUnoObj_
);
73 // #76470 Introspection on Demand durchfuehren
74 void doIntrospection( void );
76 // Find ueberladen, um z.B. NameAccess zu unterstuetzen
77 virtual SbxVariable
* Find( const String
&, SbxClassType
);
79 // Force creation of all properties for debugging
80 void createAllProperties( void )
84 ::com::sun::star::uno::Any
getUnoAny( void );
85 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XIntrospectionAccess
> getIntrospectionAccess( void ) { return mxUnoAccess
; }
86 ::com::sun::star::uno::Reference
< ::com::sun::star::script::XInvocation
> getInvocation( void ) { return mxInvocation
; }
88 void SFX_NOTIFY( SfxBroadcaster
&, const TypeId
&, const SfxHint
& rHint
, const TypeId
& );
90 SV_DECL_IMPL_REF(SbUnoObject
);
93 // #67781 Rueckgabewerte der Uno-Methoden loeschen
94 void clearUnoMethods( void );
96 class SbUnoMethod
: public SbxMethod
98 friend class SbUnoObject
;
99 friend void clearUnoMethods( void );
101 ::com::sun::star::uno::Reference
< ::com::sun::star::reflection::XIdlMethod
> m_xUnoMethod
;
102 ::com::sun::star::uno::Sequence
< ::com::sun::star::reflection::ParamInfo
>* pParamInfoSeq
;
104 // #67781 Verweis auf vorige und naechste Methode in der Methoden-Liste
108 bool mbInvocation
; // Method is based on invocation
113 SbUnoMethod( const String
& aName_
, SbxDataType eSbxType
, ::com::sun::star::uno::Reference
< ::com::sun::star::reflection::XIdlMethod
> xUnoMethod_
,
115 virtual ~SbUnoMethod();
116 virtual SbxInfo
* GetInfo();
118 const ::com::sun::star::uno::Sequence
< ::com::sun::star::reflection::ParamInfo
>& getParamInfos( void );
120 bool isInvocationBased( void )
121 { return mbInvocation
; }
125 class SbUnoProperty
: public SbxProperty
127 friend class SbUnoObject
;
129 // Daten der Uno-Property
130 ::com::sun::star::beans::Property aUnoProp
;
133 bool mbInvocation
; // Property is based on invocation
135 virtual ~SbUnoProperty();
138 SbUnoProperty( const String
& aName_
, SbxDataType eSbxType
,
139 const ::com::sun::star::beans::Property
& aUnoProp_
, INT32 nId_
, bool bInvocation
);
141 bool isInvocationBased( void )
142 { return mbInvocation
; }
145 // Factory-Klasse fuer das Anlegen von Uno-Structs per DIM AS NEW
146 class SbUnoFactory
: public SbxFactory
149 virtual SbxBase
* Create( UINT16 nSbxId
, UINT32
= SBXCR_SBX
);
150 virtual SbxObject
* CreateObject( const String
& );
153 // Wrapper fuer eine Uno-Klasse
154 class SbUnoClass
: public SbxObject
156 const ::com::sun::star::uno::Reference
< ::com::sun::star::reflection::XIdlClass
> m_xClass
;
160 SbUnoClass( const String
& aName_
)
161 : SbxObject( aName_
)
163 SbUnoClass( const String
& aName_
, const ::com::sun::star::uno::Reference
< ::com::sun::star::reflection::XIdlClass
>& xClass_
)
164 : SbxObject( aName_
)
165 , m_xClass( xClass_
)
169 // Find ueberladen, um Elemente on Demand anzulegen
170 virtual SbxVariable
* Find( const String
&, SbxClassType
);
173 const ::com::sun::star::uno::Reference
< ::com::sun::star::reflection::XIdlClass
>& getUnoClass( void ) { return m_xClass
; }
175 //void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& );
177 SV_DECL_IMPL_REF(SbUnoClass
);
180 // Funktion, um einen globalen Bezeichner im
181 // UnoScope zu suchen und fuer Sbx zu wrappen
182 SbUnoClass
* findUnoClass( const String
& rName
);
185 // Wrapper for UNO Service
186 class SbUnoService
: public SbxObject
188 const ::com::sun::star::uno::Reference
< ::com::sun::star::reflection::XServiceTypeDescription2
> m_xServiceTypeDesc
;
193 SbUnoService( const String
& aName_
,
194 const ::com::sun::star::uno::Reference
< ::com::sun::star::reflection::XServiceTypeDescription2
>& xServiceTypeDesc
)
195 : SbxObject( aName_
)
196 , m_xServiceTypeDesc( xServiceTypeDesc
)
197 , m_bNeedsInit( true )
200 virtual SbxVariable
* Find( const String
&, SbxClassType
);
202 void SFX_NOTIFY( SfxBroadcaster
&, const TypeId
&, const SfxHint
& rHint
, const TypeId
& );
204 SV_DECL_IMPL_REF(SbUnoService
);
206 SbUnoService
* findUnoService( const String
& rName
);
209 void clearUnoServiceCtors( void );
211 class SbUnoServiceCtor
: public SbxMethod
213 friend class SbUnoService
;
214 friend void clearUnoServiceCtors( void );
216 ::com::sun::star::uno::Reference
< ::com::sun::star::reflection::XServiceConstructorDescription
> m_xServiceCtorDesc
;
218 SbUnoServiceCtor
* pPrev
;
219 SbUnoServiceCtor
* pNext
;
224 SbUnoServiceCtor( const String
& aName_
, ::com::sun::star::uno::Reference
< ::com::sun::star::reflection::XServiceConstructorDescription
> xServiceCtorDesc
);
225 virtual ~SbUnoServiceCtor();
226 virtual SbxInfo
* GetInfo();
228 ::com::sun::star::uno::Reference
< ::com::sun::star::reflection::XServiceConstructorDescription
> getServiceCtorDesc( void )
229 { return m_xServiceCtorDesc
; }
233 // #105565 Special Object to wrap a strongly typed Uno Any
234 class SbUnoAnyObject
: public SbxObject
236 ::com::sun::star::uno::Any mVal
;
239 SbUnoAnyObject( const ::com::sun::star::uno::Any
& rVal
)
240 : SbxObject( String() )
244 const ::com::sun::star::uno::Any
& getValue( void )
251 // #112509 Special SbxArray to transport named parameters for calls
252 // to OLEAutomation objects through the UNO OLE automation bridge
254 class AutomationNamedArgsSbxArray
: public SbxArray
256 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> maNameSeq
;
259 AutomationNamedArgsSbxArray( sal_Int32 nSeqSize
)
260 : maNameSeq( nSeqSize
)
263 ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& getNames( void )
264 { return maNameSeq
; }
270 // Impl-Methoden fuer RTL
271 void RTL_Impl_CreateUnoStruct( StarBASIC
* pBasic
, SbxArray
& rPar
, BOOL bWrite
);
272 void RTL_Impl_CreateUnoService( StarBASIC
* pBasic
, SbxArray
& rPar
, BOOL bWrite
);
273 void RTL_Impl_CreateUnoServiceWithArguments( StarBASIC
* pBasic
, SbxArray
& rPar
, BOOL bWrite
);
274 void RTL_Impl_CreateUnoValue( StarBASIC
* pBasic
, SbxArray
& rPar
, BOOL bWrite
);
275 void RTL_Impl_GetProcessServiceManager( StarBASIC
* pBasic
, SbxArray
& rPar
, BOOL bWrite
);
276 void RTL_Impl_HasInterfaces( StarBASIC
* pBasic
, SbxArray
& rPar
, BOOL bWrite
);
277 void RTL_Impl_IsUnoStruct( StarBASIC
* pBasic
, SbxArray
& rPar
, BOOL bWrite
);
278 void RTL_Impl_EqualUnoObjects( StarBASIC
* pBasic
, SbxArray
& rPar
, BOOL bWrite
);
279 void RTL_Impl_GetDefaultContext( StarBASIC
* pBasic
, SbxArray
& rPar
, BOOL bWrite
);
282 //========================================================================
283 // #118116 Collection object
285 class BasicCollection
: public SbxObject
287 friend class SbiRuntime
;
288 SbxArrayRef xItemArray
;
289 static SbxInfoRef xAddInfo
;
290 static SbxInfoRef xItemInfo
;
293 virtual ~BasicCollection();
294 virtual void SFX_NOTIFY( SfxBroadcaster
& rBC
, const TypeId
& rBCType
,
295 const SfxHint
& rHint
, const TypeId
& rHintType
);
296 INT32
implGetIndex( SbxVariable
* pIndexVar
);
297 INT32
implGetIndexForName( const String
& rName
);
298 void CollAdd( SbxArray
* pPar_
);
299 void CollItem( SbxArray
* pPar_
);
300 void CollRemove( SbxArray
* pPar_
);
304 BasicCollection( const String
& rClassname
);
305 virtual SbxVariable
* Find( const String
&, SbxClassType
);
306 virtual void Clear();
309 typedef std::hash_map
< ::rtl::OUString
, ::com::sun::star::uno::Any
, ::rtl::OUStringHash
, ::std::equal_to
< ::rtl::OUString
> > VBAConstantsHash
;
311 typedef std::vector
< rtl::OUString
> VBAConstantsVector
;
313 class VBAConstantHelper
317 VBAConstantsVector aConstCache
;
318 VBAConstantsHash aConstHash
;
320 VBAConstantHelper():isInited( false ) {}
321 VBAConstantHelper(const VBAConstantHelper
&);
324 static VBAConstantHelper
& instance();
325 SbxVariable
* getVBAConstant( const String
& rName
);
326 bool isVBAConstantType( const String
& rName
);