xref: /aoo42x/main/basic/source/inc/sbunoobj.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef SB_UNO_OBJ
28 #define SB_UNO_OBJ
29 
30 #include <basic/sbxobj.hxx>
31 #include <basic/sbxmeth.hxx>
32 #include <basic/sbxprop.hxx>
33 #include <basic/sbxfac.hxx>
34 #ifndef __SBX_SBX_HXX //autogen
35 #include <basic/sbx.hxx>
36 #endif
37 #include <com/sun/star/beans/XMaterialHolder.hpp>
38 #include <com/sun/star/beans/XExactName.hpp>
39 #include <com/sun/star/beans/XIntrospectionAccess.hpp>
40 #include <com/sun/star/beans/XIntrospection.hpp>
41 #include <com/sun/star/script/XInvocation.hpp>
42 #include <com/sun/star/reflection/XIdlClass.hpp>
43 #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
44 #include <com/sun/star/reflection/XSingletonTypeDescription.hpp>
45 #include <rtl/ustring.hxx>
46 
47 class SbUnoObject: public SbxObject
48 {
49 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess > mxUnoAccess;
50 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XMaterialHolder > mxMaterialHolder;
51 	::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > mxInvocation;
52 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XExactName > mxExactName;
53 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XExactName > mxExactNameInvocation;
54 	sal_Bool bNeedIntrospection;
55 	sal_Bool bNativeCOMObject;
56 	::com::sun::star::uno::Any maTmpUnoObj;	// Only to save obj for doIntrospection!
57 
58 	// Hilfs-Methode zum Anlegen der dbg_-Properties
59 	void implCreateDbgProperties( void );
60 
61 	// Hilfs-Methode zum Anlegen aller Properties und Methoden
62 	// (Beim on-demand-Mechanismus erforderlich fuer die dbg_-Properties)
63 	void implCreateAll( void );
64 
65 public:
66 	static bool getDefaultPropName( SbUnoObject* pUnoObj, String& sDfltProp );
67 	TYPEINFO();
68 	SbUnoObject( const String& aName_, const ::com::sun::star::uno::Any& aUnoObj_ );
69 	~SbUnoObject();
70 
71 	// #76470 Introspection on Demand durchfuehren
72 	void doIntrospection( void );
73 
74 	// Find ueberladen, um z.B. NameAccess zu unterstuetzen
75 	virtual SbxVariable* Find( const String&, SbxClassType );
76 
77 	// Force creation of all properties for debugging
78 	void createAllProperties( void  )
79 		{ implCreateAll(); }
80 
81 	// Wert rausgeben
82 	::com::sun::star::uno::Any getUnoAny( void );
83 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess > getIntrospectionAccess( void )	{ return mxUnoAccess; }
84 	::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > getInvocation( void )			{ return mxInvocation; }
85 
86 	void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& );
87 
88 	bool isNativeCOMObject( void )
89 		{ return bNativeCOMObject; }
90 };
91 SV_DECL_IMPL_REF(SbUnoObject);
92 
93 
94 // #67781 Rueckgabewerte der Uno-Methoden loeschen
95 void clearUnoMethods( void );
96 void clearUnoMethodsForBasic( StarBASIC* pBasic );
97 
98 class SbUnoMethod : public SbxMethod
99 {
100 	friend class SbUnoObject;
101 	friend void clearUnoMethods( void );
102     friend void clearUnoMethodsForBasic( StarBASIC* pBasic );
103 
104 	::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlMethod > m_xUnoMethod;
105 	::com::sun::star::uno::Sequence< ::com::sun::star::reflection::ParamInfo >* pParamInfoSeq;
106 
107 	// #67781 Verweis auf vorige und naechste Methode in der Methoden-Liste
108 	SbUnoMethod* pPrev;
109 	SbUnoMethod* pNext;
110 
111 	bool mbInvocation;		 // Method is based on invocation
112     bool mbDirectInvocation; // Method should be used with XDirectInvocation interface
113 
114 public:
115 	TYPEINFO();
116 
117 	SbUnoMethod( const String& aName_, SbxDataType eSbxType, ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlMethod > xUnoMethod_,
118 		bool bInvocation,
119         bool bDirect = false );
120 	virtual ~SbUnoMethod();
121 	virtual SbxInfo* GetInfo();
122 
123 	const ::com::sun::star::uno::Sequence< ::com::sun::star::reflection::ParamInfo >& getParamInfos( void );
124 
125 	bool isInvocationBased( void )
126 		{ return mbInvocation; }
127     bool needsDirectInvocation( void )
128         { return mbDirectInvocation; }
129 };
130 
131 
132 class SbUnoProperty : public SbxProperty
133 {
134 	friend class SbUnoObject;
135 
136 	// Daten der Uno-Property
137 	::com::sun::star::beans::Property aUnoProp;
138 	sal_Int32 nId;
139 
140 	bool mbInvocation;		// Property is based on invocation
141 
142 	virtual ~SbUnoProperty();
143 public:
144 	TYPEINFO();
145 	SbUnoProperty( const String& aName_, SbxDataType eSbxType,
146 		const ::com::sun::star::beans::Property& aUnoProp_, sal_Int32 nId_, bool bInvocation );
147 
148 	bool isInvocationBased( void )
149 		{ return mbInvocation; }
150 };
151 
152 // Factory-Klasse fuer das Anlegen von Uno-Structs per DIM AS NEW
153 class SbUnoFactory : public SbxFactory
154 {
155 public:
156 	virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 = SBXCR_SBX );
157 	virtual SbxObject* CreateObject( const String& );
158 };
159 
160 // Wrapper fuer eine Uno-Klasse
161 class SbUnoClass : public SbxObject
162 {
163 	const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass >	m_xClass;
164 
165 public:
166 	TYPEINFO();
167 	SbUnoClass( const String& aName_ )
168 		: SbxObject( aName_ )
169 	{}
170 	SbUnoClass( const String& aName_, const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass >& xClass_ )
171 		: SbxObject( aName_ )
172 		, m_xClass( xClass_ )
173 	{}
174 	//~SbUnoClass();
175 
176 	// Find ueberladen, um Elemente on Demand anzulegen
177 	virtual SbxVariable* Find( const String&, SbxClassType );
178 
179 	// Wert rausgeben
180 	const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass >& getUnoClass( void ) { return m_xClass; }
181 
182 	//void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& );
183 };
184 SV_DECL_IMPL_REF(SbUnoClass);
185 
186 
187 // Funktion, um einen globalen Bezeichner im
188 // UnoScope zu suchen und fuer Sbx zu wrappen
189 SbUnoClass* findUnoClass( const String& rName );
190 
191 
192 // Wrapper for UNO Service
193 class SbUnoService : public SbxObject
194 {
195 	const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceTypeDescription2 >	m_xServiceTypeDesc;
196 	bool																								m_bNeedsInit;
197 
198 public:
199 	TYPEINFO();
200 	SbUnoService( const String& aName_,
201 		const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceTypeDescription2 >& xServiceTypeDesc )
202 			: SbxObject( aName_ )
203 			, m_xServiceTypeDesc( xServiceTypeDesc )
204 			, m_bNeedsInit( true )
205 	{}
206 
207 	virtual SbxVariable* Find( const String&, SbxClassType );
208 
209 	void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& );
210 };
211 SV_DECL_IMPL_REF(SbUnoService);
212 
213 SbUnoService* findUnoService( const String& rName );
214 
215 
216 void clearUnoServiceCtors( void );
217 
218 class SbUnoServiceCtor : public SbxMethod
219 {
220 	friend class SbUnoService;
221 	friend void clearUnoServiceCtors( void );
222 
223 	::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceConstructorDescription > m_xServiceCtorDesc;
224 
225 	SbUnoServiceCtor* pPrev;
226 	SbUnoServiceCtor* pNext;
227 
228 public:
229 	TYPEINFO();
230 
231 	SbUnoServiceCtor( const String& aName_, ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceConstructorDescription > xServiceCtorDesc );
232 	virtual ~SbUnoServiceCtor();
233 	virtual SbxInfo* GetInfo();
234 
235 	::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceConstructorDescription > getServiceCtorDesc( void )
236 		{ return m_xServiceCtorDesc; }
237 };
238 
239 
240 // Wrapper for UNO Singleton
241 class SbUnoSingleton : public SbxObject
242 {
243 	const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XSingletonTypeDescription >	m_xSingletonTypeDesc;
244 
245 public:
246 	TYPEINFO();
247 	SbUnoSingleton( const String& aName_,
248 		const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XSingletonTypeDescription >& xSingletonTypeDesc );
249 
250 	void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& );
251 };
252 SV_DECL_IMPL_REF(SbUnoSingleton);
253 
254 SbUnoSingleton* findUnoSingleton( const String& rName );
255 
256 
257 // #105565 Special Object to wrap a strongly typed Uno Any
258 class SbUnoAnyObject: public SbxObject
259 {
260     ::com::sun::star::uno::Any     mVal;
261 
262 public:
263 	SbUnoAnyObject( const ::com::sun::star::uno::Any& rVal )
264     	: SbxObject( String() )
265         , mVal( rVal )
266 	{}
267 
268     const ::com::sun::star::uno::Any& getValue( void )
269         { return mVal; }
270 
271 	TYPEINFO();
272 };
273 
274 
275 // #112509 Special SbxArray to transport named parameters for calls
276 // to OLEAutomation objects through the UNO OLE automation bridge
277 
278 class AutomationNamedArgsSbxArray : public SbxArray
279 {
280 	::com::sun::star::uno::Sequence< ::rtl::OUString >		maNameSeq;
281 public:
282 	TYPEINFO();
283 	AutomationNamedArgsSbxArray( sal_Int32 nSeqSize )
284 		: maNameSeq( nSeqSize )
285 	{}
286 
287 	::com::sun::star::uno::Sequence< ::rtl::OUString >& getNames( void )
288 		{ return maNameSeq; }
289 };
290 
291 
292 class StarBASIC;
293 
294 // Impl-Methoden fuer RTL
295 void RTL_Impl_CreateUnoStruct( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
296 void RTL_Impl_CreateUnoService( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
297 void RTL_Impl_CreateUnoServiceWithArguments( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
298 void RTL_Impl_CreateUnoValue( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
299 void RTL_Impl_GetProcessServiceManager( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
300 void RTL_Impl_HasInterfaces( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
301 void RTL_Impl_IsUnoStruct( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
302 void RTL_Impl_EqualUnoObjects( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
303 void RTL_Impl_GetDefaultContext( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
304 
305 void disposeComVariablesForBasic( StarBASIC* pBasic );
306 void clearNativeObjectWrapperVector( void );
307 
308 
309 //========================================================================
310 // #118116 Collection object
311 
312 class BasicCollection : public SbxObject
313 {
314 	friend class SbiRuntime;
315 	SbxArrayRef xItemArray;
316 	static SbxInfoRef xAddInfo;
317 	static SbxInfoRef xItemInfo;
318 
319 	void Initialize();
320 	virtual ~BasicCollection();
321 	virtual void SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
322 							 const SfxHint& rHint, const TypeId& rHintType );
323 	sal_Int32 implGetIndex( SbxVariable* pIndexVar );
324 	sal_Int32 implGetIndexForName( const String& rName );
325 	void CollAdd( SbxArray* pPar_ );
326 	void CollItem( SbxArray* pPar_ );
327 	void CollRemove( SbxArray* pPar_ );
328 
329 public:
330 	TYPEINFO();
331 	BasicCollection( const String& rClassname );
332 	virtual SbxVariable* Find( const String&, SbxClassType );
333 	virtual void Clear();
334 };
335 
336 #endif
337 
338 
339