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