xref: /aoo41x/main/basic/source/classes/sbunoobj.cxx (revision 0848378b)
1e1f63238SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3e1f63238SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4e1f63238SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5e1f63238SAndrew Rist  * distributed with this work for additional information
6e1f63238SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7e1f63238SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8e1f63238SAndrew Rist  * "License"); you may not use this file except in compliance
9e1f63238SAndrew Rist  * with the License.  You may obtain a copy of the License at
10e1f63238SAndrew Rist  *
11e1f63238SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12e1f63238SAndrew Rist  *
13e1f63238SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14e1f63238SAndrew Rist  * software distributed under the License is distributed on an
15e1f63238SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16e1f63238SAndrew Rist  * KIND, either express or implied.  See the License for the
17e1f63238SAndrew Rist  * specific language governing permissions and limitations
18e1f63238SAndrew Rist  * under the License.
19e1f63238SAndrew Rist  *
20e1f63238SAndrew Rist  *************************************************************/
21e1f63238SAndrew Rist 
22e1f63238SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_basic.hxx"
26cdf0e10cSrcweir //#include <stl_queue.h>
27cdf0e10cSrcweir #include <vos/mutex.hxx>
28cdf0e10cSrcweir #include <vcl/svapp.hxx>
29cdf0e10cSrcweir #ifndef _TOOLERR_HXX //autogen
30cdf0e10cSrcweir #include <tools/errcode.hxx>
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #include <svl/hint.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
35cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
36cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
37cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
38cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
39cdf0e10cSrcweir #include <comphelper/extract.hxx>
40cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
43cdf0e10cSrcweir #include <rtl/strbuf.hxx>
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include <com/sun/star/script/ArrayWrapper.hpp>
46cdf0e10cSrcweir #include <com/sun/star/script/NativeObjectWrapper.hpp>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
49cdf0e10cSrcweir #include <com/sun/star/uno/DeploymentException.hpp>
50cdf0e10cSrcweir #include <com/sun/star/lang/XTypeProvider.hpp>
51cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
52cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
53cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
54cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
55cdf0e10cSrcweir #include <com/sun/star/beans/PropertyConcept.hpp>
56cdf0e10cSrcweir #include <com/sun/star/beans/MethodConcept.hpp>
57cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
58cdf0e10cSrcweir #include <com/sun/star/script/BasicErrorException.hpp>
59cdf0e10cSrcweir #include <com/sun/star/script/XAllListener.hpp>
60cdf0e10cSrcweir #include <com/sun/star/script/XInvocationAdapterFactory.hpp>
61cdf0e10cSrcweir #include <com/sun/star/script/XTypeConverter.hpp>
62cdf0e10cSrcweir #include <com/sun/star/script/XDefaultProperty.hpp>
63cdf0e10cSrcweir #include <com/sun/star/script/XDirectInvocation.hpp>
64cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
65cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
66cdf0e10cSrcweir #include <com/sun/star/reflection/XIdlArray.hpp>
67cdf0e10cSrcweir #include <com/sun/star/reflection/XIdlReflection.hpp>
68cdf0e10cSrcweir #include <com/sun/star/reflection/XIdlClassProvider.hpp>
69cdf0e10cSrcweir #include <com/sun/star/reflection/XServiceConstructorDescription.hpp>
70cdf0e10cSrcweir #include <com/sun/star/bridge/oleautomation/NamedArgument.hpp>
71cdf0e10cSrcweir #include <com/sun/star/bridge/oleautomation/Date.hpp>
72cdf0e10cSrcweir #include <com/sun/star/bridge/oleautomation/Decimal.hpp>
73cdf0e10cSrcweir #include <com/sun/star/bridge/oleautomation/Currency.hpp>
74cdf0e10cSrcweir #include <com/sun/star/bridge/oleautomation/XAutomationObject.hpp>
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 
77cdf0e10cSrcweir using com::sun::star::uno::Reference;
78cdf0e10cSrcweir using namespace com::sun::star::uno;
79cdf0e10cSrcweir using namespace com::sun::star::lang;
80cdf0e10cSrcweir using namespace com::sun::star::reflection;
81cdf0e10cSrcweir using namespace com::sun::star::beans;
82cdf0e10cSrcweir using namespace com::sun::star::script;
83cdf0e10cSrcweir using namespace com::sun::star::container;
84cdf0e10cSrcweir using namespace com::sun::star::bridge;
85cdf0e10cSrcweir using namespace cppu;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 
88cdf0e10cSrcweir #include<basic/sbstar.hxx>
89cdf0e10cSrcweir #include<basic/sbuno.hxx>
90cdf0e10cSrcweir #include<basic/sberrors.hxx>
91cdf0e10cSrcweir #include<sbunoobj.hxx>
92cdf0e10cSrcweir #include"sbjsmod.hxx"
93cdf0e10cSrcweir #include<basic/basmgr.hxx>
94cdf0e10cSrcweir #include<sbintern.hxx>
95cdf0e10cSrcweir #include<runtime.hxx>
96cdf0e10cSrcweir 
97cdf0e10cSrcweir #include<math.h>
98cdf0e10cSrcweir #include <hash_map>
99cdf0e10cSrcweir #include <com/sun/star/reflection/XTypeDescriptionEnumerationAccess.hpp>
100cdf0e10cSrcweir #include <com/sun/star/reflection/XConstantsTypeDescription.hpp>
101cdf0e10cSrcweir 
102cdf0e10cSrcweir TYPEINIT1(SbUnoMethod,SbxMethod)
103cdf0e10cSrcweir TYPEINIT1(SbUnoProperty,SbxProperty)
104cdf0e10cSrcweir TYPEINIT1(SbUnoObject,SbxObject)
105cdf0e10cSrcweir TYPEINIT1(SbUnoClass,SbxObject)
106cdf0e10cSrcweir TYPEINIT1(SbUnoService,SbxObject)
107cdf0e10cSrcweir TYPEINIT1(SbUnoServiceCtor,SbxMethod)
108cdf0e10cSrcweir TYPEINIT1(SbUnoSingleton,SbxObject)
109cdf0e10cSrcweir 
110cdf0e10cSrcweir typedef WeakImplHelper1< XAllListener > BasicAllListenerHelper;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir // Flag, um immer ueber Invocation zu gehen
113cdf0e10cSrcweir //#define INVOCATION_ONLY
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 
116cdf0e10cSrcweir // Identifier fuer die dbg_-Properies als Strings anlegen
117cdf0e10cSrcweir static char const ID_DBG_SUPPORTEDINTERFACES[] = "Dbg_SupportedInterfaces";
118cdf0e10cSrcweir static char const ID_DBG_PROPERTIES[] = "Dbg_Properties";
119cdf0e10cSrcweir static char const ID_DBG_METHODS[] = "Dbg_Methods";
120cdf0e10cSrcweir 
121cdf0e10cSrcweir static ::rtl::OUString aSeqLevelStr( RTL_CONSTASCII_USTRINGPARAM("[]") );
122cdf0e10cSrcweir static ::rtl::OUString defaultNameSpace( RTL_CONSTASCII_USTRINGPARAM("ooo.vba") );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir // Gets the default property for an uno object. Note: There is some
125cdf0e10cSrcweir // redirection built in. The property name specifies the name
126cdf0e10cSrcweir // of the default property.
127cdf0e10cSrcweir 
getDefaultPropName(SbUnoObject * pUnoObj,String & sDfltProp)128cdf0e10cSrcweir bool SbUnoObject::getDefaultPropName( SbUnoObject* pUnoObj, String& sDfltProp )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir 	bool result = false;
131cdf0e10cSrcweir 	Reference< XDefaultProperty> xDefaultProp( pUnoObj->maTmpUnoObj, UNO_QUERY );
132cdf0e10cSrcweir 	if ( xDefaultProp.is() )
133cdf0e10cSrcweir 	{
134cdf0e10cSrcweir 		sDfltProp = xDefaultProp->getDefaultPropertyName();
135cdf0e10cSrcweir 		if ( sDfltProp.Len() )
136cdf0e10cSrcweir 			result = true;
137cdf0e10cSrcweir 	}
138cdf0e10cSrcweir 	return result;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
getDefaultProp(SbxVariable * pRef)141cdf0e10cSrcweir SbxVariable* getDefaultProp( SbxVariable* pRef )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir 	SbxVariable* pDefaultProp = NULL;
144cdf0e10cSrcweir 	if ( pRef->GetType() == SbxOBJECT )
145cdf0e10cSrcweir 	{
146cdf0e10cSrcweir   		SbxObject* pObj = PTR_CAST(SbxObject,(SbxVariable*) pRef);
147cdf0e10cSrcweir 		if ( !pObj )
148cdf0e10cSrcweir 		{
149cdf0e10cSrcweir 			SbxBase* pObjVarObj = pRef->GetObject();
150cdf0e10cSrcweir 			pObj = PTR_CAST(SbxObject,pObjVarObj);
151cdf0e10cSrcweir 		}
152cdf0e10cSrcweir 		if ( pObj && pObj->ISA(SbUnoObject) )
153cdf0e10cSrcweir 		{
154cdf0e10cSrcweir 			SbUnoObject* pUnoObj = PTR_CAST(SbUnoObject,(SbxObject*)pObj);
155cdf0e10cSrcweir 			pDefaultProp = pUnoObj->GetDfltProperty();
156cdf0e10cSrcweir 		}
157cdf0e10cSrcweir 	}
158cdf0e10cSrcweir 	return pDefaultProp;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
getComponentContext_Impl(void)161cdf0e10cSrcweir Reference< XComponentContext > getComponentContext_Impl( void )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir     static Reference< XComponentContext > xContext;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	// Haben wir schon CoreReflection, sonst besorgen
166cdf0e10cSrcweir 	if( !xContext.is() )
167cdf0e10cSrcweir 	{
168cdf0e10cSrcweir 		Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
169cdf0e10cSrcweir         Reference< XPropertySet > xProps( xFactory, UNO_QUERY );
170cdf0e10cSrcweir         OSL_ASSERT( xProps.is() );
171cdf0e10cSrcweir         if (xProps.is())
172cdf0e10cSrcweir         {
173cdf0e10cSrcweir             xProps->getPropertyValue(
174cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xContext;
175cdf0e10cSrcweir             OSL_ASSERT( xContext.is() );
176cdf0e10cSrcweir         }
177cdf0e10cSrcweir 	}
178cdf0e10cSrcweir 	return xContext;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir // CoreReflection statisch speichern
getCoreReflection_Impl(void)182cdf0e10cSrcweir Reference< XIdlReflection > getCoreReflection_Impl( void )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir 	static Reference< XIdlReflection > xCoreReflection;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 	// Haben wir schon CoreReflection, sonst besorgen
187cdf0e10cSrcweir 	if( !xCoreReflection.is() )
188cdf0e10cSrcweir 	{
189cdf0e10cSrcweir         Reference< XComponentContext > xContext = getComponentContext_Impl();
190cdf0e10cSrcweir         if( xContext.is() )
191cdf0e10cSrcweir         {
192cdf0e10cSrcweir             xContext->getValueByName(
193cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theCoreReflection") ) )
194cdf0e10cSrcweir                     >>= xCoreReflection;
195cdf0e10cSrcweir             OSL_ENSURE( xCoreReflection.is(), "### CoreReflection singleton not accessable!?" );
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir         if( !xCoreReflection.is() )
198cdf0e10cSrcweir         {
199cdf0e10cSrcweir             throw DeploymentException(
200cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theCoreReflection singleton not accessable") ),
201cdf0e10cSrcweir                 Reference< XInterface >() );
202cdf0e10cSrcweir         }
203cdf0e10cSrcweir 	}
204cdf0e10cSrcweir 	return xCoreReflection;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir // CoreReflection statisch speichern
getCoreReflection_HierarchicalNameAccess_Impl(void)208cdf0e10cSrcweir Reference< XHierarchicalNameAccess > getCoreReflection_HierarchicalNameAccess_Impl( void )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir 	static Reference< XHierarchicalNameAccess > xCoreReflection_HierarchicalNameAccess;
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 	if( !xCoreReflection_HierarchicalNameAccess.is() )
213cdf0e10cSrcweir 	{
214cdf0e10cSrcweir 		Reference< XIdlReflection > xCoreReflection = getCoreReflection_Impl();
215cdf0e10cSrcweir 		if( xCoreReflection.is() )
216cdf0e10cSrcweir 		{
217cdf0e10cSrcweir 			xCoreReflection_HierarchicalNameAccess =
218cdf0e10cSrcweir 				Reference< XHierarchicalNameAccess >( xCoreReflection, UNO_QUERY );
219cdf0e10cSrcweir 		}
220cdf0e10cSrcweir 	}
221cdf0e10cSrcweir 	return xCoreReflection_HierarchicalNameAccess;
222cdf0e10cSrcweir }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir // Hold TypeProvider statically
getTypeProvider_Impl(void)225cdf0e10cSrcweir Reference< XHierarchicalNameAccess > getTypeProvider_Impl( void )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir 	static Reference< XHierarchicalNameAccess > xAccess;
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 	// Haben wir schon CoreReflection, sonst besorgen
230cdf0e10cSrcweir 	if( !xAccess.is() )
231cdf0e10cSrcweir 	{
232cdf0e10cSrcweir         Reference< XComponentContext > xContext = getComponentContext_Impl();
233cdf0e10cSrcweir         if( xContext.is() )
234cdf0e10cSrcweir         {
235cdf0e10cSrcweir             xContext->getValueByName(
236cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theTypeDescriptionManager") ) )
237cdf0e10cSrcweir                     >>= xAccess;
238cdf0e10cSrcweir             OSL_ENSURE( xAccess.is(), "### TypeDescriptionManager singleton not accessable!?" );
239cdf0e10cSrcweir         }
240cdf0e10cSrcweir         if( !xAccess.is() )
241cdf0e10cSrcweir         {
242cdf0e10cSrcweir             throw DeploymentException(
243cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM
244cdf0e10cSrcweir                     ("/singletons/com.sun.star.reflection.theTypeDescriptionManager singleton not accessable") ),
245cdf0e10cSrcweir                 Reference< XInterface >() );
246cdf0e10cSrcweir         }
247cdf0e10cSrcweir 	}
248cdf0e10cSrcweir 	return xAccess;
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir // Hold TypeConverter statically
getTypeConverter_Impl(void)252cdf0e10cSrcweir Reference< XTypeConverter > getTypeConverter_Impl( void )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir 	static Reference< XTypeConverter > xTypeConverter;
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 	// Haben wir schon CoreReflection, sonst besorgen
257cdf0e10cSrcweir 	if( !xTypeConverter.is() )
258cdf0e10cSrcweir 	{
259cdf0e10cSrcweir         Reference< XComponentContext > xContext = getComponentContext_Impl();
260cdf0e10cSrcweir         if( xContext.is() )
261cdf0e10cSrcweir         {
262cdf0e10cSrcweir             Reference<XMultiComponentFactory> xSMgr = xContext->getServiceManager();
263cdf0e10cSrcweir 	        xTypeConverter = Reference<XTypeConverter>(
264cdf0e10cSrcweir 		        xSMgr->createInstanceWithContext(
265cdf0e10cSrcweir 			        ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter")),
266cdf0e10cSrcweir 			            xContext ), UNO_QUERY );
267cdf0e10cSrcweir         }
268cdf0e10cSrcweir         if( !xTypeConverter.is() )
269cdf0e10cSrcweir         {
270cdf0e10cSrcweir             throw DeploymentException(
271cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM
272cdf0e10cSrcweir                     ("com.sun.star.script.Converter service not accessable") ),
273cdf0e10cSrcweir                 Reference< XInterface >() );
274cdf0e10cSrcweir         }
275cdf0e10cSrcweir 	}
276cdf0e10cSrcweir 	return xTypeConverter;
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 
280cdf0e10cSrcweir // #111851 factory function to create an OLE object
createOLEObject_Impl(const String & aType)281cdf0e10cSrcweir SbUnoObject* createOLEObject_Impl( const String& aType )
282cdf0e10cSrcweir {
283cdf0e10cSrcweir 	static Reference< XMultiServiceFactory > xOLEFactory;
284cdf0e10cSrcweir 	static bool bNeedsInit = true;
285cdf0e10cSrcweir 
286cdf0e10cSrcweir 	if( bNeedsInit )
287cdf0e10cSrcweir 	{
288cdf0e10cSrcweir 		bNeedsInit = false;
289cdf0e10cSrcweir 
290cdf0e10cSrcweir         Reference< XComponentContext > xContext = getComponentContext_Impl();
291cdf0e10cSrcweir         if( xContext.is() )
292cdf0e10cSrcweir         {
293cdf0e10cSrcweir             Reference<XMultiComponentFactory> xSMgr = xContext->getServiceManager();
294cdf0e10cSrcweir 	        xOLEFactory = Reference<XMultiServiceFactory>(
295cdf0e10cSrcweir 		        xSMgr->createInstanceWithContext(
296cdf0e10cSrcweir 			        ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.OleObjectFactory")),
297cdf0e10cSrcweir 			            xContext ), UNO_QUERY );
298cdf0e10cSrcweir         }
299cdf0e10cSrcweir 	}
300cdf0e10cSrcweir 
301cdf0e10cSrcweir 	SbUnoObject* pUnoObj = NULL;
302cdf0e10cSrcweir 	if( xOLEFactory.is() )
303cdf0e10cSrcweir 	{
304cdf0e10cSrcweir         // some type names available in VBA can not be directly used in COM
305cdf0e10cSrcweir         ::rtl::OUString aOLEType = aType;
306cdf0e10cSrcweir         if ( aOLEType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SAXXMLReader30" ) ) ) )
307cdf0e10cSrcweir             aOLEType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Msxml2.SAXXMLReader.3.0" ) );
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 		Reference< XInterface > xOLEObject = xOLEFactory->createInstance( aOLEType );
310cdf0e10cSrcweir 		if( xOLEObject.is() )
311cdf0e10cSrcweir 		{
312cdf0e10cSrcweir 			Any aAny;
313cdf0e10cSrcweir 			aAny <<= xOLEObject;
314cdf0e10cSrcweir 			pUnoObj = new SbUnoObject( aType, aAny );
315cdf0e10cSrcweir 		}
316cdf0e10cSrcweir 	}
317cdf0e10cSrcweir 	return pUnoObj;
318cdf0e10cSrcweir }
319cdf0e10cSrcweir 
320cdf0e10cSrcweir 
321cdf0e10cSrcweir namespace
322cdf0e10cSrcweir {
lcl_indent(::rtl::OUStringBuffer & _inout_rBuffer,sal_Int32 _nLevel)323cdf0e10cSrcweir     void lcl_indent( ::rtl::OUStringBuffer& _inout_rBuffer, sal_Int32 _nLevel )
324cdf0e10cSrcweir     {
325cdf0e10cSrcweir         while ( _nLevel-- > 0 )
326cdf0e10cSrcweir             _inout_rBuffer.appendAscii( "  " );
327cdf0e10cSrcweir     }
328cdf0e10cSrcweir }
329cdf0e10cSrcweir 
implAppendExceptionMsg(::rtl::OUStringBuffer & _inout_rBuffer,const Exception & _e,const::rtl::OUString & _rExceptionType,sal_Int32 _nLevel)330cdf0e10cSrcweir void implAppendExceptionMsg( ::rtl::OUStringBuffer& _inout_rBuffer, const Exception& _e, const ::rtl::OUString& _rExceptionType, sal_Int32 _nLevel )
331cdf0e10cSrcweir {
332cdf0e10cSrcweir     _inout_rBuffer.appendAscii( "\n" );
333cdf0e10cSrcweir     lcl_indent( _inout_rBuffer, _nLevel );
334cdf0e10cSrcweir     _inout_rBuffer.appendAscii( "Type: " );
335cdf0e10cSrcweir 
336*0848378bSHerbert Dürr     if ( _rExceptionType.isEmpty() )
337cdf0e10cSrcweir         _inout_rBuffer.appendAscii( "Unknown" );
338cdf0e10cSrcweir     else
339cdf0e10cSrcweir         _inout_rBuffer.append( _rExceptionType );
340cdf0e10cSrcweir 
341cdf0e10cSrcweir     _inout_rBuffer.appendAscii( "\n" );
342cdf0e10cSrcweir     lcl_indent( _inout_rBuffer, _nLevel );
343cdf0e10cSrcweir     _inout_rBuffer.appendAscii( "Message: " );
344cdf0e10cSrcweir     _inout_rBuffer.append( _e.Message );
345cdf0e10cSrcweir 
346cdf0e10cSrcweir }
347cdf0e10cSrcweir 
348cdf0e10cSrcweir // Fehlermeldungs-Message bei Exception zusammenbauen
implGetExceptionMsg(const Exception & e,const::rtl::OUString & aExceptionType_)349cdf0e10cSrcweir ::rtl::OUString implGetExceptionMsg( const Exception& e, const ::rtl::OUString& aExceptionType_ )
350cdf0e10cSrcweir {
351cdf0e10cSrcweir     ::rtl::OUStringBuffer aMessageBuf;
352cdf0e10cSrcweir     implAppendExceptionMsg( aMessageBuf, e, aExceptionType_, 0 );
353cdf0e10cSrcweir     return aMessageBuf.makeStringAndClear();
354cdf0e10cSrcweir }
355cdf0e10cSrcweir 
implGetExceptionMsg(const Any & _rCaughtException)356cdf0e10cSrcweir String implGetExceptionMsg( const Any& _rCaughtException )
357cdf0e10cSrcweir {
358cdf0e10cSrcweir     OSL_PRECOND( _rCaughtException.getValueTypeClass() == TypeClass_EXCEPTION, "implGetExceptionMsg: illegal argument!" );
359cdf0e10cSrcweir     if ( _rCaughtException.getValueTypeClass() != TypeClass_EXCEPTION )
360cdf0e10cSrcweir         return String();
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     return implGetExceptionMsg( *static_cast< const Exception* >( _rCaughtException.getValue() ), _rCaughtException.getValueTypeName() );
363cdf0e10cSrcweir }
364cdf0e10cSrcweir 
convertAny(const Any & rVal,const Type & aDestType)365cdf0e10cSrcweir Any convertAny( const Any& rVal, const Type& aDestType )
366cdf0e10cSrcweir {
367cdf0e10cSrcweir     Any aConvertedVal;
368cdf0e10cSrcweir     Reference< XTypeConverter > xConverter = getTypeConverter_Impl();
369cdf0e10cSrcweir 	try
370cdf0e10cSrcweir 	{
371cdf0e10cSrcweir         aConvertedVal = xConverter->convertTo( rVal, aDestType );
372cdf0e10cSrcweir 	}
373cdf0e10cSrcweir 	catch( const IllegalArgumentException& )
374cdf0e10cSrcweir 	{
375cdf0e10cSrcweir 		StarBASIC::Error( ERRCODE_BASIC_EXCEPTION,
376cdf0e10cSrcweir             implGetExceptionMsg( ::cppu::getCaughtException() ) );
377cdf0e10cSrcweir 		return aConvertedVal;
378cdf0e10cSrcweir 	}
379cdf0e10cSrcweir 	catch( CannotConvertException& e2 )
380cdf0e10cSrcweir 	{
381cdf0e10cSrcweir         String aCannotConvertExceptionName
382cdf0e10cSrcweir             ( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.IllegalArgumentException" ) );
383cdf0e10cSrcweir 		StarBASIC::Error( ERRCODE_BASIC_EXCEPTION,
384cdf0e10cSrcweir             implGetExceptionMsg( e2, aCannotConvertExceptionName ) );
385cdf0e10cSrcweir 		return aConvertedVal;
386cdf0e10cSrcweir 	}
387cdf0e10cSrcweir     return aConvertedVal;
388cdf0e10cSrcweir }
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 
391cdf0e10cSrcweir // #105565 Special Object to wrap a strongly typed Uno Any
TYPEINIT1(SbUnoAnyObject,SbxObject)392cdf0e10cSrcweir TYPEINIT1(SbUnoAnyObject,SbxObject)
393cdf0e10cSrcweir 
394cdf0e10cSrcweir 
395cdf0e10cSrcweir // TODO: Spaeter auslagern
396cdf0e10cSrcweir Reference<XIdlClass> TypeToIdlClass( const Type& rType )
397cdf0e10cSrcweir {
398cdf0e10cSrcweir 	// void als Default-Klasse eintragen
399cdf0e10cSrcweir 	Reference<XIdlClass> xRetClass;
400cdf0e10cSrcweir 	typelib_TypeDescription * pTD = 0;
401cdf0e10cSrcweir 	rType.getDescription( &pTD );
402cdf0e10cSrcweir 
403cdf0e10cSrcweir 	if( pTD )
404cdf0e10cSrcweir 	{
405cdf0e10cSrcweir 		::rtl::OUString sOWName( pTD->pTypeName );
406cdf0e10cSrcweir 		Reference< XIdlReflection > xRefl = getCoreReflection_Impl();
407cdf0e10cSrcweir 		xRetClass = xRefl->forName( sOWName );
408cdf0e10cSrcweir 	}
409cdf0e10cSrcweir 	return xRetClass;
410cdf0e10cSrcweir }
411cdf0e10cSrcweir 
412cdf0e10cSrcweir // Exception type unknown
413cdf0e10cSrcweir template< class EXCEPTION >
implGetExceptionMsg(const EXCEPTION & e)414cdf0e10cSrcweir String implGetExceptionMsg( const EXCEPTION& e )
415cdf0e10cSrcweir {
416cdf0e10cSrcweir     return implGetExceptionMsg( e, ::getCppuType( &e ).getTypeName() );
417cdf0e10cSrcweir }
418cdf0e10cSrcweir 
419cdf0e10cSrcweir // Error-Message fuer WrappedTargetExceptions
implGetWrappedMsg(const WrappedTargetException & e)420cdf0e10cSrcweir String implGetWrappedMsg( const WrappedTargetException& e )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir     String aMsg;
423cdf0e10cSrcweir 	Any aWrappedAny = e.TargetException;
424cdf0e10cSrcweir     Type aExceptionType = aWrappedAny.getValueType();
425cdf0e10cSrcweir 
426cdf0e10cSrcweir 	// Really an Exception?
427cdf0e10cSrcweir 	if( aExceptionType.getTypeClass() == TypeClass_EXCEPTION )
428cdf0e10cSrcweir 	{
429cdf0e10cSrcweir 		Exception& e_ = *( (Exception*)aWrappedAny.getValue() );
430cdf0e10cSrcweir 		aMsg = implGetExceptionMsg( e_, String( aExceptionType.getTypeName() ) );
431cdf0e10cSrcweir 	}
432cdf0e10cSrcweir 	// Otherwise use WrappedTargetException itself
433cdf0e10cSrcweir 	else
434cdf0e10cSrcweir 	{
435cdf0e10cSrcweir         aMsg = implGetExceptionMsg( e );
436cdf0e10cSrcweir 	}
437cdf0e10cSrcweir 
438cdf0e10cSrcweir 	return aMsg;
439cdf0e10cSrcweir }
440cdf0e10cSrcweir 
implHandleBasicErrorException(BasicErrorException & e)441cdf0e10cSrcweir void implHandleBasicErrorException( BasicErrorException& e )
442cdf0e10cSrcweir {
443cdf0e10cSrcweir     SbError nError = StarBASIC::GetSfxFromVBError( (sal_uInt16)e.ErrorCode );
444cdf0e10cSrcweir     StarBASIC::Error( nError, e.ErrorMessageArgument );
445cdf0e10cSrcweir }
446cdf0e10cSrcweir 
implHandleWrappedTargetException(const Any & _rWrappedTargetException)447cdf0e10cSrcweir void implHandleWrappedTargetException( const Any& _rWrappedTargetException )
448cdf0e10cSrcweir {
449cdf0e10cSrcweir     Any aExamine( _rWrappedTargetException );
450cdf0e10cSrcweir 
451cdf0e10cSrcweir     // completely strip the first InvocationTargetException, its error message isn't of any
452cdf0e10cSrcweir     // interest to the user, it just says something like "invoking the UNO method went wrong.".
453cdf0e10cSrcweir     InvocationTargetException aInvocationError;
454cdf0e10cSrcweir     if ( aExamine >>= aInvocationError )
455cdf0e10cSrcweir         aExamine = aInvocationError.TargetException;
456cdf0e10cSrcweir 
457cdf0e10cSrcweir     BasicErrorException aBasicError;
458cdf0e10cSrcweir 
459cdf0e10cSrcweir     SbError nError( ERRCODE_BASIC_EXCEPTION );
460cdf0e10cSrcweir     ::rtl::OUStringBuffer aMessageBuf;
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     // strip any other WrappedTargetException instances, but this time preserve the error messages.
463cdf0e10cSrcweir     WrappedTargetException aWrapped;
464cdf0e10cSrcweir     sal_Int32 nLevel = 0;
465cdf0e10cSrcweir     while ( aExamine >>= aWrapped )
466cdf0e10cSrcweir     {
467cdf0e10cSrcweir         // special handling for BasicErrorException errors
468cdf0e10cSrcweir         if ( aWrapped.TargetException >>= aBasicError )
469cdf0e10cSrcweir         {
470cdf0e10cSrcweir             nError = StarBASIC::GetSfxFromVBError( (sal_uInt16)aBasicError.ErrorCode );
471cdf0e10cSrcweir             aMessageBuf.append( aBasicError.ErrorMessageArgument );
472cdf0e10cSrcweir             aExamine.clear();
473cdf0e10cSrcweir             break;
474cdf0e10cSrcweir         }
475cdf0e10cSrcweir 
476cdf0e10cSrcweir         // append this round's message
477cdf0e10cSrcweir         implAppendExceptionMsg( aMessageBuf, aWrapped, aExamine.getValueTypeName(), nLevel );
478cdf0e10cSrcweir         if ( aWrapped.TargetException.getValueTypeClass() == TypeClass_EXCEPTION )
479cdf0e10cSrcweir             // there is a next chain element
480cdf0e10cSrcweir             aMessageBuf.appendAscii( "\nTargetException:" );
481cdf0e10cSrcweir 
482cdf0e10cSrcweir         // next round
483cdf0e10cSrcweir         aExamine = aWrapped.TargetException;
484cdf0e10cSrcweir         ++nLevel;
485cdf0e10cSrcweir     }
486cdf0e10cSrcweir 
487cdf0e10cSrcweir     if ( aExamine.getValueTypeClass() == TypeClass_EXCEPTION )
488cdf0e10cSrcweir     {
489cdf0e10cSrcweir         // the last element in the chain is still an exception, but no WrappedTargetException
490cdf0e10cSrcweir         implAppendExceptionMsg( aMessageBuf, *static_cast< const Exception* >( aExamine.getValue() ), aExamine.getValueTypeName(), nLevel );
491cdf0e10cSrcweir     }
492cdf0e10cSrcweir 
493cdf0e10cSrcweir     StarBASIC::Error( nError, aMessageBuf.makeStringAndClear() );
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
implHandleAnyException(const Any & _rCaughtException)496cdf0e10cSrcweir static void implHandleAnyException( const Any& _rCaughtException )
497cdf0e10cSrcweir {
498cdf0e10cSrcweir     BasicErrorException aBasicError;
499cdf0e10cSrcweir     WrappedTargetException aWrappedError;
500cdf0e10cSrcweir 
501cdf0e10cSrcweir     if ( _rCaughtException >>= aBasicError )
502cdf0e10cSrcweir 	{
503cdf0e10cSrcweir 		implHandleBasicErrorException( aBasicError );
504cdf0e10cSrcweir 	}
505cdf0e10cSrcweir     else if ( _rCaughtException >>= aWrappedError )
506cdf0e10cSrcweir 	{
507cdf0e10cSrcweir         implHandleWrappedTargetException( _rCaughtException );
508cdf0e10cSrcweir 	}
509cdf0e10cSrcweir     else
510cdf0e10cSrcweir 	{
511cdf0e10cSrcweir 		StarBASIC::Error( ERRCODE_BASIC_EXCEPTION, implGetExceptionMsg( _rCaughtException ) );
512cdf0e10cSrcweir 	}
513cdf0e10cSrcweir }
514cdf0e10cSrcweir 
515cdf0e10cSrcweir 
516cdf0e10cSrcweir // NativeObjectWrapper handling
517cdf0e10cSrcweir struct ObjectItem
518cdf0e10cSrcweir {
519cdf0e10cSrcweir 	SbxObjectRef	m_xNativeObj;
520cdf0e10cSrcweir 
ObjectItemObjectItem521cdf0e10cSrcweir 	ObjectItem( void )
522cdf0e10cSrcweir 	{}
ObjectItemObjectItem523cdf0e10cSrcweir 	ObjectItem( SbxObject* pNativeObj )
524cdf0e10cSrcweir 		: m_xNativeObj( pNativeObj )
525cdf0e10cSrcweir 	{}
526cdf0e10cSrcweir };
527cdf0e10cSrcweir static std::vector< ObjectItem >	GaNativeObjectWrapperVector;
528cdf0e10cSrcweir 
clearNativeObjectWrapperVector(void)529cdf0e10cSrcweir void clearNativeObjectWrapperVector( void )
530cdf0e10cSrcweir {
531cdf0e10cSrcweir 	GaNativeObjectWrapperVector.clear();
532cdf0e10cSrcweir }
533cdf0e10cSrcweir 
lcl_registerNativeObjectWrapper(SbxObject * pNativeObj)534cdf0e10cSrcweir sal_uInt32 lcl_registerNativeObjectWrapper( SbxObject* pNativeObj )
535cdf0e10cSrcweir {
536cdf0e10cSrcweir 	sal_uInt32 nIndex = GaNativeObjectWrapperVector.size();
537cdf0e10cSrcweir 	GaNativeObjectWrapperVector.push_back( ObjectItem( pNativeObj ) );
538cdf0e10cSrcweir 	return nIndex;
539cdf0e10cSrcweir }
540cdf0e10cSrcweir 
lcl_getNativeObject(sal_uInt32 nIndex)541cdf0e10cSrcweir SbxObject* lcl_getNativeObject( sal_uInt32 nIndex )
542cdf0e10cSrcweir {
543cdf0e10cSrcweir 	SbxObjectRef xRetObj;
544cdf0e10cSrcweir 	if( nIndex < GaNativeObjectWrapperVector.size() )
545cdf0e10cSrcweir 	{
546cdf0e10cSrcweir 		ObjectItem& rItem = GaNativeObjectWrapperVector[ nIndex ];
547cdf0e10cSrcweir 		xRetObj = rItem.m_xNativeObj;
548cdf0e10cSrcweir 	}
549cdf0e10cSrcweir 	return xRetObj;
550cdf0e10cSrcweir }
551cdf0e10cSrcweir 
552cdf0e10cSrcweir 
553cdf0e10cSrcweir // Von Uno nach Sbx wandeln
unoToSbxType(TypeClass eType)554cdf0e10cSrcweir SbxDataType unoToSbxType( TypeClass eType )
555cdf0e10cSrcweir {
556cdf0e10cSrcweir 	SbxDataType eRetType = SbxVOID;
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 	switch( eType )
559cdf0e10cSrcweir 	{
560cdf0e10cSrcweir 		case TypeClass_INTERFACE:
561cdf0e10cSrcweir 		case TypeClass_TYPE:
562cdf0e10cSrcweir 		case TypeClass_STRUCT:
563cdf0e10cSrcweir 		case TypeClass_EXCEPTION:		eRetType = SbxOBJECT;	break;
564cdf0e10cSrcweir 
565cdf0e10cSrcweir 		/* folgende Typen lassen wir erstmal weg
566cdf0e10cSrcweir 		case TypeClass_SERVICE:			break;
567cdf0e10cSrcweir 		case TypeClass_CLASS:			break;
568cdf0e10cSrcweir 		case TypeClass_TYPEDEF:			break;
569cdf0e10cSrcweir 		case TypeClass_UNION:			break;
570cdf0e10cSrcweir 		case TypeClass_ARRAY:			break;
571cdf0e10cSrcweir 		*/
572cdf0e10cSrcweir 		case TypeClass_ENUM:			eRetType = SbxLONG;		break;
573cdf0e10cSrcweir 		case TypeClass_SEQUENCE:
574cdf0e10cSrcweir 			eRetType = (SbxDataType) ( SbxOBJECT | SbxARRAY );
575cdf0e10cSrcweir 			break;
576cdf0e10cSrcweir 
577cdf0e10cSrcweir 		/*
578cdf0e10cSrcweir 		case TypeClass_VOID:			break;
579cdf0e10cSrcweir 		case TypeClass_UNKNOWN:			break;
580cdf0e10cSrcweir 		*/
581cdf0e10cSrcweir 
582cdf0e10cSrcweir 		case TypeClass_ANY:				eRetType = SbxVARIANT;	break;
583cdf0e10cSrcweir 		case TypeClass_BOOLEAN:			eRetType = SbxBOOL;		break;
584cdf0e10cSrcweir 		case TypeClass_CHAR:			eRetType = SbxCHAR;		break;
585cdf0e10cSrcweir 		case TypeClass_STRING:			eRetType = SbxSTRING;	break;
586cdf0e10cSrcweir 		case TypeClass_FLOAT:			eRetType = SbxSINGLE;	break;
587cdf0e10cSrcweir 		case TypeClass_DOUBLE:			eRetType = SbxDOUBLE;	break;
588cdf0e10cSrcweir 		//case TypeClass_OCTET:									break;
589cdf0e10cSrcweir 		case TypeClass_BYTE:			eRetType = SbxINTEGER;  break;
590cdf0e10cSrcweir 		//case TypeClass_INT:				eRetType = SbxINT;	break;
591cdf0e10cSrcweir 		case TypeClass_SHORT:			eRetType = SbxINTEGER;	break;
592cdf0e10cSrcweir 		case TypeClass_LONG:			eRetType = SbxLONG;		break;
593cdf0e10cSrcweir 		case TypeClass_HYPER:			eRetType = SbxSALINT64;	break;
594cdf0e10cSrcweir 		//case TypeClass_UNSIGNED_OCTET:						break;
595cdf0e10cSrcweir 		case TypeClass_UNSIGNED_SHORT:	eRetType = SbxUSHORT;	break;
596cdf0e10cSrcweir 		case TypeClass_UNSIGNED_LONG:	eRetType = SbxULONG;	break;
597cdf0e10cSrcweir 		case TypeClass_UNSIGNED_HYPER:  eRetType = SbxSALUINT64;break;
598cdf0e10cSrcweir 		//case TypeClass_UNSIGNED_INT:	eRetType = SbxUINT;		break;
599cdf0e10cSrcweir 		//case TypeClass_UNSIGNED_BYTE:	eRetType = SbxUSHORT;	break;
600cdf0e10cSrcweir 		default: break;
601cdf0e10cSrcweir 	}
602cdf0e10cSrcweir 	return eRetType;
603cdf0e10cSrcweir }
604cdf0e10cSrcweir 
unoToSbxType(const Reference<XIdlClass> & xIdlClass)605cdf0e10cSrcweir SbxDataType unoToSbxType( const Reference< XIdlClass >& xIdlClass )
606cdf0e10cSrcweir {
607cdf0e10cSrcweir 	SbxDataType eRetType = SbxVOID;
608cdf0e10cSrcweir 	if( xIdlClass.is() )
609cdf0e10cSrcweir 	{
610cdf0e10cSrcweir 		TypeClass eType = xIdlClass->getTypeClass();
611cdf0e10cSrcweir         eRetType = unoToSbxType( eType );
612cdf0e10cSrcweir     }
613cdf0e10cSrcweir 	return eRetType;
614cdf0e10cSrcweir }
615cdf0e10cSrcweir 
implSequenceToMultiDimArray(SbxDimArray * & pArray,Sequence<sal_Int32> & indices,Sequence<sal_Int32> & sizes,const Any & aValue,sal_Int32 & dimension,sal_Bool bIsZeroIndex,Type * pType=NULL)616cdf0e10cSrcweir static void implSequenceToMultiDimArray( SbxDimArray*& pArray, Sequence< sal_Int32 >& indices, Sequence< sal_Int32 >& sizes, const Any& aValue, sal_Int32& dimension, sal_Bool bIsZeroIndex, Type* pType = NULL )
617cdf0e10cSrcweir {
618cdf0e10cSrcweir 	Type aType = aValue.getValueType();
619cdf0e10cSrcweir 	TypeClass eTypeClass = aType.getTypeClass();
620cdf0e10cSrcweir 
621cdf0e10cSrcweir 	sal_Int32 indicesIndex = indices.getLength() -1;
622cdf0e10cSrcweir 	sal_Int32 dimCopy = dimension;
623cdf0e10cSrcweir 
624cdf0e10cSrcweir 	if ( eTypeClass == TypeClass_SEQUENCE )
625cdf0e10cSrcweir 	{
626cdf0e10cSrcweir 		Reference< XIdlClass > xIdlTargetClass = TypeToIdlClass( aType );
627cdf0e10cSrcweir 		Reference< XIdlArray > xIdlArray = xIdlTargetClass->getArray();
628cdf0e10cSrcweir 		typelib_TypeDescription * pTD = 0;
629cdf0e10cSrcweir         aType.getDescription( &pTD );
630cdf0e10cSrcweir 		Type aElementType( ((typelib_IndirectTypeDescription *)pTD)->pType );
631cdf0e10cSrcweir 		::typelib_typedescription_release( pTD );
632cdf0e10cSrcweir 
633cdf0e10cSrcweir 		sal_Int32 nLen = xIdlArray->getLen( aValue );
634cdf0e10cSrcweir 		for ( sal_Int32 index = 0; index < nLen; ++index )
635cdf0e10cSrcweir 		{
636cdf0e10cSrcweir 			Any aElementAny = xIdlArray->get( aValue, (sal_uInt32)index );
637cdf0e10cSrcweir 			// This detects the dimension were currently processing
638cdf0e10cSrcweir 			if ( dimCopy == dimension )
639cdf0e10cSrcweir 			{
640cdf0e10cSrcweir 				++dimCopy;
641cdf0e10cSrcweir 				if ( sizes.getLength() < dimCopy )
642cdf0e10cSrcweir 				{
643cdf0e10cSrcweir 					sizes.realloc( sizes.getLength() + 1 );
644cdf0e10cSrcweir 					sizes[ sizes.getLength() - 1 ] = nLen;
645cdf0e10cSrcweir 					indices.realloc( indices.getLength() + 1 );
646cdf0e10cSrcweir 					indicesIndex = indices.getLength() - 1;
647cdf0e10cSrcweir 				}
648cdf0e10cSrcweir 			}
649cdf0e10cSrcweir 
650cdf0e10cSrcweir 			if ( bIsZeroIndex )
651cdf0e10cSrcweir 				indices[ dimCopy - 1 ] = index;
652cdf0e10cSrcweir 			else
653cdf0e10cSrcweir 				indices[ dimCopy - 1] = index + 1;
654cdf0e10cSrcweir 
655cdf0e10cSrcweir 			implSequenceToMultiDimArray( pArray, indices, sizes, aElementAny, dimCopy, bIsZeroIndex, &aElementType );
656cdf0e10cSrcweir 		}
657cdf0e10cSrcweir 
658cdf0e10cSrcweir 	}
659cdf0e10cSrcweir 	else
660cdf0e10cSrcweir 	{
661cdf0e10cSrcweir 		if ( indices.getLength() < 1 )
662cdf0e10cSrcweir 		{
663cdf0e10cSrcweir 			// Should never ever get here ( indices.getLength()
664cdf0e10cSrcweir 			// should equal number of dimensions in the array )
665cdf0e10cSrcweir 			// And that should at least be 1 !
666cdf0e10cSrcweir 			// #QUESTION is there a better error?
667cdf0e10cSrcweir 			StarBASIC::Error( SbERR_INVALID_OBJECT );
668cdf0e10cSrcweir 			return;
669cdf0e10cSrcweir 		}
670cdf0e10cSrcweir 
671cdf0e10cSrcweir 		SbxDataType eSbxElementType = unoToSbxType( pType ? pType->getTypeClass() : aValue.getValueTypeClass() );
672cdf0e10cSrcweir 		if ( !pArray )
673cdf0e10cSrcweir 		{
674cdf0e10cSrcweir 			pArray = new SbxDimArray( eSbxElementType );
675cdf0e10cSrcweir 			sal_Int32 nIndexLen = indices.getLength();
676cdf0e10cSrcweir 
677cdf0e10cSrcweir 			// Dimension the array
678cdf0e10cSrcweir 			for ( sal_Int32 index = 0; index < nIndexLen; ++index )
679cdf0e10cSrcweir 			{
680cdf0e10cSrcweir 				if ( bIsZeroIndex )
681cdf0e10cSrcweir 					pArray->unoAddDim32( 0, sizes[ index ] - 1);
682cdf0e10cSrcweir 				else
683cdf0e10cSrcweir 					pArray->unoAddDim32( 1, sizes[ index ] );
684cdf0e10cSrcweir 
685cdf0e10cSrcweir 			}
686cdf0e10cSrcweir 		}
687cdf0e10cSrcweir 
688cdf0e10cSrcweir 		if ( pArray )
689cdf0e10cSrcweir 		{
690cdf0e10cSrcweir 			SbxVariableRef xVar = new SbxVariable( eSbxElementType );
691cdf0e10cSrcweir 			unoToSbxValue( (SbxVariable*)xVar, aValue );
692cdf0e10cSrcweir 
693cdf0e10cSrcweir 			sal_Int32* pIndices = indices.getArray();
694cdf0e10cSrcweir 			pArray->Put32( 	(SbxVariable*)xVar, pIndices );
695cdf0e10cSrcweir 
696cdf0e10cSrcweir 		}
697cdf0e10cSrcweir 	}
698cdf0e10cSrcweir }
699cdf0e10cSrcweir 
unoToSbxValue(SbxVariable * pVar,const Any & aValue)700cdf0e10cSrcweir void unoToSbxValue( SbxVariable* pVar, const Any& aValue )
701cdf0e10cSrcweir {
702cdf0e10cSrcweir 	Type aType = aValue.getValueType();
703cdf0e10cSrcweir 	TypeClass eTypeClass = aType.getTypeClass();
704cdf0e10cSrcweir 	switch( eTypeClass )
705cdf0e10cSrcweir 	{
706cdf0e10cSrcweir 		case TypeClass_TYPE:
707cdf0e10cSrcweir 		{
708cdf0e10cSrcweir 			// Map Type to IdlClass
709cdf0e10cSrcweir 			Type aType_;
710cdf0e10cSrcweir 			aValue >>= aType_;
711cdf0e10cSrcweir 			Reference<XIdlClass> xClass = TypeToIdlClass( aType_ );
712cdf0e10cSrcweir 			Any aClassAny;
713cdf0e10cSrcweir 			aClassAny <<= xClass;
714cdf0e10cSrcweir 
715cdf0e10cSrcweir 			// SbUnoObject instanzieren
716cdf0e10cSrcweir 			String aName;
717cdf0e10cSrcweir 			SbUnoObject* pSbUnoObject = new SbUnoObject( aName, aClassAny );
718cdf0e10cSrcweir 			SbxObjectRef xWrapper = (SbxObject*)pSbUnoObject;
719cdf0e10cSrcweir 
720cdf0e10cSrcweir 			// #51475 Wenn das Objekt ungueltig ist null liefern
721cdf0e10cSrcweir 			if( pSbUnoObject->getUnoAny().getValueType().getTypeClass() == TypeClass_VOID )
722cdf0e10cSrcweir 			{
723cdf0e10cSrcweir 				pVar->PutObject( NULL );
724cdf0e10cSrcweir 			}
725cdf0e10cSrcweir 			else
726cdf0e10cSrcweir 			{
727cdf0e10cSrcweir 				pVar->PutObject( xWrapper );
728cdf0e10cSrcweir 			}
729cdf0e10cSrcweir 		}
730cdf0e10cSrcweir 		break;
731cdf0e10cSrcweir 		// Interfaces und Structs muessen in ein SbUnoObject gewrappt werden
732cdf0e10cSrcweir 		case TypeClass_INTERFACE:
733cdf0e10cSrcweir 		case TypeClass_STRUCT:
734cdf0e10cSrcweir 		case TypeClass_EXCEPTION:
735cdf0e10cSrcweir 		{
736cdf0e10cSrcweir 			if( eTypeClass == TypeClass_STRUCT )
737cdf0e10cSrcweir 			{
738cdf0e10cSrcweir 				ArrayWrapper aWrap;
739cdf0e10cSrcweir 				NativeObjectWrapper aNativeObjectWrapper;
740cdf0e10cSrcweir 				if ( (aValue >>= aWrap) )
741cdf0e10cSrcweir 				{
742cdf0e10cSrcweir 					SbxDimArray* pArray = NULL;
743cdf0e10cSrcweir 					Sequence< sal_Int32 > indices;
744cdf0e10cSrcweir 					Sequence< sal_Int32 > sizes;
745cdf0e10cSrcweir 					sal_Int32 dimension = 0;
746cdf0e10cSrcweir 					implSequenceToMultiDimArray( pArray, indices, sizes, aWrap.Array, dimension, aWrap.IsZeroIndex );
747cdf0e10cSrcweir 					if ( pArray )
748cdf0e10cSrcweir 					{
749cdf0e10cSrcweir 						SbxDimArrayRef xArray = pArray;
750cdf0e10cSrcweir 						sal_uInt16 nFlags = pVar->GetFlags();
751cdf0e10cSrcweir 						pVar->ResetFlag( SBX_FIXED );
752cdf0e10cSrcweir 						pVar->PutObject( (SbxDimArray*)xArray );
753cdf0e10cSrcweir 						pVar->SetFlags( nFlags );
754cdf0e10cSrcweir 					}
755cdf0e10cSrcweir 					else
756cdf0e10cSrcweir 						pVar->PutEmpty();
757cdf0e10cSrcweir 					break;
758cdf0e10cSrcweir 				}
759cdf0e10cSrcweir 				else if ( (aValue >>= aNativeObjectWrapper) )
760cdf0e10cSrcweir 				{
761cdf0e10cSrcweir 					sal_uInt32 nIndex = 0;
762cdf0e10cSrcweir 					if( (aNativeObjectWrapper.ObjectId >>= nIndex) )
763cdf0e10cSrcweir 					{
764cdf0e10cSrcweir 						SbxObject* pObj = lcl_getNativeObject( nIndex );
765cdf0e10cSrcweir 						pVar->PutObject( pObj );
766cdf0e10cSrcweir 					}
767cdf0e10cSrcweir 					else
768cdf0e10cSrcweir 						pVar->PutEmpty();
769cdf0e10cSrcweir 					break;
770cdf0e10cSrcweir 				}
771cdf0e10cSrcweir 				else
772cdf0e10cSrcweir 				{
773cdf0e10cSrcweir 					SbiInstance* pInst = pINST;
774cdf0e10cSrcweir 					if( pInst && pInst->IsCompatibility() )
775cdf0e10cSrcweir 					{
776cdf0e10cSrcweir 						oleautomation::Date aDate;
777cdf0e10cSrcweir 						if( (aValue >>= aDate) )
778cdf0e10cSrcweir 						{
779cdf0e10cSrcweir 							pVar->PutDate( aDate.Value );
780cdf0e10cSrcweir 							break;
781cdf0e10cSrcweir 						}
782cdf0e10cSrcweir 						else
783cdf0e10cSrcweir 						{
784cdf0e10cSrcweir 							oleautomation::Decimal aDecimal;
785cdf0e10cSrcweir 							if( (aValue >>= aDecimal) )
786cdf0e10cSrcweir 							{
787cdf0e10cSrcweir 								pVar->PutDecimal( aDecimal );
788cdf0e10cSrcweir 								break;
789cdf0e10cSrcweir 							}
790cdf0e10cSrcweir 							else
791cdf0e10cSrcweir 							{
792cdf0e10cSrcweir 								oleautomation::Currency aCurrency;
793cdf0e10cSrcweir 								if( (aValue >>= aCurrency) )
794cdf0e10cSrcweir 								{
795cdf0e10cSrcweir 									sal_Int64 nValue64 = aCurrency.Value;
796cdf0e10cSrcweir 									SbxINT64 aInt64;
797cdf0e10cSrcweir 									aInt64.nHigh =
798cdf0e10cSrcweir                                         sal::static_int_cast< sal_Int32 >(
799cdf0e10cSrcweir                                             nValue64 >> 32);
800cdf0e10cSrcweir 									aInt64.nLow = (sal_uInt32)( nValue64 & 0xffffffff );
801cdf0e10cSrcweir 									pVar->PutCurrency( aInt64 );
802cdf0e10cSrcweir 									break;
803cdf0e10cSrcweir 								}
804cdf0e10cSrcweir 							}
805cdf0e10cSrcweir 						}
806cdf0e10cSrcweir 					}
807cdf0e10cSrcweir 				}
808cdf0e10cSrcweir 			}
809cdf0e10cSrcweir 			// SbUnoObject instanzieren
810cdf0e10cSrcweir 			String aName;
811cdf0e10cSrcweir 			SbUnoObject* pSbUnoObject = new SbUnoObject( aName, aValue );
812cdf0e10cSrcweir 			//If this is called externally e.g. from the scripting
813cdf0e10cSrcweir 			//framework then there is no 'active' runtime the default property will not be set up
814cdf0e10cSrcweir 			//only a vba object will have XDefaultProp set anyway so... this
815cdf0e10cSrcweir 			//test seems a bit of overkill
816cdf0e10cSrcweir 			//if ( SbiRuntime::isVBAEnabled() )
817cdf0e10cSrcweir 			{
818cdf0e10cSrcweir 				String sDfltPropName;
819cdf0e10cSrcweir 
820cdf0e10cSrcweir 				if ( SbUnoObject::getDefaultPropName( pSbUnoObject, sDfltPropName ) )
821cdf0e10cSrcweir 						pSbUnoObject->SetDfltProperty( sDfltPropName );
822cdf0e10cSrcweir 			}
823cdf0e10cSrcweir 			SbxObjectRef xWrapper = (SbxObject*)pSbUnoObject;
824cdf0e10cSrcweir 
825cdf0e10cSrcweir 			// #51475 Wenn das Objekt ungueltig ist null liefern
826cdf0e10cSrcweir 			if( pSbUnoObject->getUnoAny().getValueType().getTypeClass() == TypeClass_VOID )
827cdf0e10cSrcweir 			{
828cdf0e10cSrcweir 				pVar->PutObject( NULL );
829cdf0e10cSrcweir 			}
830cdf0e10cSrcweir 			else
831cdf0e10cSrcweir 			{
832cdf0e10cSrcweir 				pVar->PutObject( xWrapper );
833cdf0e10cSrcweir 			}
834cdf0e10cSrcweir 		}
835cdf0e10cSrcweir 		break;
836cdf0e10cSrcweir 
837cdf0e10cSrcweir 		/* folgende Typen lassen wir erstmal weg
838cdf0e10cSrcweir 		case TypeClass_SERVICE:			break;
839cdf0e10cSrcweir 		case TypeClass_CLASS:			break;
840cdf0e10cSrcweir 		case TypeClass_TYPEDEF:			break;
841cdf0e10cSrcweir 		case TypeClass_UNION:			break;
842cdf0e10cSrcweir 		case TypeClass_ENUM:			break;
843cdf0e10cSrcweir 		case TypeClass_ARRAY:			break;
844cdf0e10cSrcweir 		*/
845cdf0e10cSrcweir 
846cdf0e10cSrcweir 		case TypeClass_ENUM:
847cdf0e10cSrcweir 		{
848cdf0e10cSrcweir 			sal_Int32 nEnum = 0;
849cdf0e10cSrcweir 			enum2int( nEnum, aValue );
850cdf0e10cSrcweir 			pVar->PutLong( nEnum );
851cdf0e10cSrcweir 		}
852cdf0e10cSrcweir 			break;
853cdf0e10cSrcweir 
854cdf0e10cSrcweir 		case TypeClass_SEQUENCE:
855cdf0e10cSrcweir 		{
856cdf0e10cSrcweir 			Reference< XIdlClass > xIdlTargetClass = TypeToIdlClass( aType );
857cdf0e10cSrcweir 			Reference< XIdlArray > xIdlArray = xIdlTargetClass->getArray();
858cdf0e10cSrcweir 			sal_Int32 i, nLen = xIdlArray->getLen( aValue );
859cdf0e10cSrcweir 
860cdf0e10cSrcweir             typelib_TypeDescription * pTD = 0;
861cdf0e10cSrcweir             aType.getDescription( &pTD );
862cdf0e10cSrcweir             OSL_ASSERT( pTD && pTD->eTypeClass == typelib_TypeClass_SEQUENCE );
863cdf0e10cSrcweir             Type aElementType( ((typelib_IndirectTypeDescription *)pTD)->pType );
864cdf0e10cSrcweir             ::typelib_typedescription_release( pTD );
865cdf0e10cSrcweir 
866cdf0e10cSrcweir 			// In Basic Array anlegen
867cdf0e10cSrcweir 			SbxDimArrayRef xArray;
868cdf0e10cSrcweir             SbxDataType eSbxElementType = unoToSbxType( aElementType.getTypeClass() );
869cdf0e10cSrcweir     		xArray = new SbxDimArray( eSbxElementType );
870cdf0e10cSrcweir 			if( nLen > 0 )
871cdf0e10cSrcweir             {
872cdf0e10cSrcweir 				xArray->unoAddDim32( 0, nLen - 1 );
873cdf0e10cSrcweir 
874cdf0e10cSrcweir 			    // Elemente als Variablen eintragen
875cdf0e10cSrcweir 			    for( i = 0 ; i < nLen ; i++ )
876cdf0e10cSrcweir 			    {
877cdf0e10cSrcweir 				    // Elemente wandeln
878cdf0e10cSrcweir 				    Any aElementAny = xIdlArray->get( aValue, (sal_uInt32)i );
879cdf0e10cSrcweir 				    SbxVariableRef xVar = new SbxVariable( eSbxElementType );
880cdf0e10cSrcweir 				    unoToSbxValue( (SbxVariable*)xVar, aElementAny );
881cdf0e10cSrcweir 
882cdf0e10cSrcweir 				    // Ins Array braten
883cdf0e10cSrcweir 				    xArray->Put32( (SbxVariable*)xVar, &i );
884cdf0e10cSrcweir 			    }
885cdf0e10cSrcweir             }
886cdf0e10cSrcweir             else
887cdf0e10cSrcweir             {
888cdf0e10cSrcweir     			xArray->unoAddDim( 0, -1 );
889cdf0e10cSrcweir             }
890cdf0e10cSrcweir 
891cdf0e10cSrcweir 			// Array zurueckliefern
892cdf0e10cSrcweir 			sal_uInt16 nFlags = pVar->GetFlags();
893cdf0e10cSrcweir 			pVar->ResetFlag( SBX_FIXED );
894cdf0e10cSrcweir 			pVar->PutObject( (SbxDimArray*)xArray );
895cdf0e10cSrcweir 			pVar->SetFlags( nFlags );
896cdf0e10cSrcweir 
897cdf0e10cSrcweir 			// #54548, Die Parameter duerfen hier nicht weggehauen werden
898cdf0e10cSrcweir 			//pVar->SetParameters( NULL );
899cdf0e10cSrcweir 		}
900cdf0e10cSrcweir 		break;
901cdf0e10cSrcweir 
902cdf0e10cSrcweir 		/*
903cdf0e10cSrcweir 		case TypeClass_VOID:			break;
904cdf0e10cSrcweir 		case TypeClass_UNKNOWN:			break;
905cdf0e10cSrcweir 
906cdf0e10cSrcweir 		case TypeClass_ANY:
907cdf0e10cSrcweir 		{
908cdf0e10cSrcweir 			// Any rausholen und konvertieren
909cdf0e10cSrcweir 			//Any* pAny = (Any*)aValue.get();
910cdf0e10cSrcweir 			//if( pAny )
911cdf0e10cSrcweir 				//unoToSbxValue( pVar, *pAny );
912cdf0e10cSrcweir 		}
913cdf0e10cSrcweir 		break;
914cdf0e10cSrcweir 		*/
915cdf0e10cSrcweir 
916cdf0e10cSrcweir 		case TypeClass_BOOLEAN:			pVar->PutBool( *(sal_Bool*)aValue.getValue() );	break;
917cdf0e10cSrcweir 		case TypeClass_CHAR:
918cdf0e10cSrcweir 		{
919cdf0e10cSrcweir 			pVar->PutChar( *(sal_Unicode*)aValue.getValue() );
920cdf0e10cSrcweir 			break;
921cdf0e10cSrcweir 		}
922cdf0e10cSrcweir 		case TypeClass_STRING:			{ ::rtl::OUString val; aValue >>= val; pVar->PutString( String( val ) ); }	break;
923cdf0e10cSrcweir 		case TypeClass_FLOAT:			{ float val = 0; aValue >>= val; pVar->PutSingle( val ); } break;
924cdf0e10cSrcweir 		case TypeClass_DOUBLE:			{ double val = 0; aValue >>= val; pVar->PutDouble( val ); } break;
925cdf0e10cSrcweir 		//case TypeClass_OCTET:			break;
926cdf0e10cSrcweir 		case TypeClass_BYTE:			{ sal_Int8 val = 0; aValue >>= val; pVar->PutInteger( val ); } break;
927cdf0e10cSrcweir 		//case TypeClass_INT:			break;
928cdf0e10cSrcweir 		case TypeClass_SHORT:			{ sal_Int16 val = 0; aValue >>= val; pVar->PutInteger( val ); } break;
929cdf0e10cSrcweir 		case TypeClass_LONG:			{ sal_Int32 val = 0; aValue >>= val; pVar->PutLong( val ); } break;
930cdf0e10cSrcweir 		case TypeClass_HYPER:			{ sal_Int64 val = 0; aValue >>= val; pVar->PutInt64( val ); } break;
931cdf0e10cSrcweir 		//case TypeClass_UNSIGNED_OCTET:break;
932cdf0e10cSrcweir 		case TypeClass_UNSIGNED_SHORT:	{ sal_uInt16 val = 0; aValue >>= val; pVar->PutUShort( val ); } break;
933cdf0e10cSrcweir 		case TypeClass_UNSIGNED_LONG:	{ sal_uInt32 val = 0; aValue >>= val; pVar->PutULong( val ); } break;
934cdf0e10cSrcweir 		case TypeClass_UNSIGNED_HYPER:	{ sal_uInt64 val = 0; aValue >>= val; pVar->PutUInt64( val ); } break;
935cdf0e10cSrcweir 		//case TypeClass_UNSIGNED_INT:	break;
936cdf0e10cSrcweir 		//case TypeClass_UNSIGNED_BYTE:	break;
937cdf0e10cSrcweir 		default:						pVar->PutEmpty();						break;
938cdf0e10cSrcweir 	}
939cdf0e10cSrcweir }
940cdf0e10cSrcweir 
941cdf0e10cSrcweir // Reflection fuer Sbx-Typen liefern
getUnoTypeForSbxBaseType(SbxDataType eType)942cdf0e10cSrcweir Type getUnoTypeForSbxBaseType( SbxDataType eType )
943cdf0e10cSrcweir {
944cdf0e10cSrcweir 	Type aRetType = getCppuVoidType();
945cdf0e10cSrcweir 	switch( eType )
946cdf0e10cSrcweir 	{
947cdf0e10cSrcweir 		//case SbxEMPTY:		eRet = TypeClass_VOID; break;
948cdf0e10cSrcweir 		case SbxNULL:		aRetType = ::getCppuType( (const Reference< XInterface > *)0 ); break;
949cdf0e10cSrcweir 		case SbxINTEGER:	aRetType = ::getCppuType( (sal_Int16*)0 ); break;
950cdf0e10cSrcweir 		case SbxLONG:		aRetType = ::getCppuType( (sal_Int32*)0 ); break;
951cdf0e10cSrcweir 		case SbxSINGLE:		aRetType = ::getCppuType( (float*)0 ); break;
952cdf0e10cSrcweir 		case SbxDOUBLE:		aRetType = ::getCppuType( (double*)0 ); break;
953cdf0e10cSrcweir 		case SbxCURRENCY:	aRetType = ::getCppuType( (oleautomation::Currency*)0 ); break;
954cdf0e10cSrcweir 		case SbxDECIMAL:	aRetType = ::getCppuType( (oleautomation::Decimal*)0 ); break;
955cdf0e10cSrcweir 		case SbxDATE:		{
956cdf0e10cSrcweir 							SbiInstance* pInst = pINST;
957cdf0e10cSrcweir 							if( pInst && pInst->IsCompatibility() )
958cdf0e10cSrcweir 								aRetType = ::getCppuType( (double*)0 );
959cdf0e10cSrcweir 							else
960cdf0e10cSrcweir 								aRetType = ::getCppuType( (oleautomation::Date*)0 );
961cdf0e10cSrcweir 							}
962cdf0e10cSrcweir 							break;
963cdf0e10cSrcweir 		// case SbxDATE:		aRetType = ::getCppuType( (double*)0 ); break;
964cdf0e10cSrcweir 		case SbxSTRING:		aRetType = ::getCppuType( (::rtl::OUString*)0 ); break;
965cdf0e10cSrcweir 		//case SbxOBJECT:	break;
966cdf0e10cSrcweir 		//case SbxERROR:	break;
967cdf0e10cSrcweir 		case SbxBOOL:		aRetType = ::getCppuType( (sal_Bool*)0 ); break;
968cdf0e10cSrcweir 		case SbxVARIANT:	aRetType = ::getCppuType( (Any*)0 ); break;
969cdf0e10cSrcweir 		//case SbxDATAOBJECT: break;
970cdf0e10cSrcweir 		case SbxCHAR:		aRetType = ::getCppuType( (sal_Unicode*)0 ); break;
971cdf0e10cSrcweir 		case SbxBYTE:		aRetType = ::getCppuType( (sal_Int8*)0 ); break;
972cdf0e10cSrcweir 		case SbxUSHORT:		aRetType = ::getCppuType( (sal_uInt16*)0 ); break;
973cdf0e10cSrcweir 		case SbxULONG:		aRetType = ::getCppuType( (sal_uInt32*)0 ); break;
974cdf0e10cSrcweir 		//case SbxLONG64:	break;
975cdf0e10cSrcweir 		//case SbxULONG64:	break;
976cdf0e10cSrcweir 		// Maschinenabhaengige zur Sicherheit auf Hyper abbilden
977cdf0e10cSrcweir 		case SbxINT:		aRetType = ::getCppuType( (sal_Int32*)0 ); break;
978cdf0e10cSrcweir 		case SbxUINT:		aRetType = ::getCppuType( (sal_uInt32*)0 ); break;
979cdf0e10cSrcweir 		//case SbxVOID:		break;
980cdf0e10cSrcweir 		//case SbxHRESULT:	break;
981cdf0e10cSrcweir 		//case SbxPOINTER:	break;
982cdf0e10cSrcweir 		//case SbxDIMARRAY:	break;
983cdf0e10cSrcweir 		//case SbxCARRAY:	break;
984cdf0e10cSrcweir 		//case SbxUSERDEF:	break;
985cdf0e10cSrcweir 		//case SbxLPSTR:	break;
986cdf0e10cSrcweir 		//case SbxLPWSTR:	break;
987cdf0e10cSrcweir 		//case SbxCoreSTRING: break;
988cdf0e10cSrcweir 		default: break;
989cdf0e10cSrcweir 	}
990cdf0e10cSrcweir 	return aRetType;
991cdf0e10cSrcweir }
992cdf0e10cSrcweir 
993cdf0e10cSrcweir // Konvertierung von Sbx nach Uno ohne bekannte Zielklasse fuer TypeClass_ANY
getUnoTypeForSbxValue(SbxValue * pVal)994cdf0e10cSrcweir Type getUnoTypeForSbxValue( SbxValue* pVal )
995cdf0e10cSrcweir {
996cdf0e10cSrcweir 	Type aRetType = getCppuVoidType();
997cdf0e10cSrcweir 	if( !pVal )
998cdf0e10cSrcweir 		return aRetType;
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir 	// SbxType nach Uno wandeln
1001cdf0e10cSrcweir 	SbxDataType eBaseType = pVal->SbxValue::GetType();
1002cdf0e10cSrcweir 	if( eBaseType == SbxOBJECT )
1003cdf0e10cSrcweir 	{
1004cdf0e10cSrcweir 		SbxBaseRef xObj = (SbxBase*)pVal->GetObject();
1005cdf0e10cSrcweir 		if( !xObj )
1006cdf0e10cSrcweir 		{
1007cdf0e10cSrcweir 			// #109936 No error any more
1008cdf0e10cSrcweir 			// StarBASIC::Error( SbERR_INVALID_OBJECT );
1009cdf0e10cSrcweir 			aRetType = getCppuType( static_cast<Reference<XInterface> *>(0) );
1010cdf0e10cSrcweir 			return aRetType;
1011cdf0e10cSrcweir 		}
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir 		if( xObj->ISA(SbxDimArray) )
1014cdf0e10cSrcweir 		{
1015cdf0e10cSrcweir 			SbxBase* pObj = (SbxBase*)xObj;
1016cdf0e10cSrcweir 			SbxDimArray* pArray = (SbxDimArray*)pObj;
1017cdf0e10cSrcweir 
1018cdf0e10cSrcweir 			short nDims = pArray->GetDims();
1019cdf0e10cSrcweir 			Type aElementType = getUnoTypeForSbxBaseType( (SbxDataType)(pArray->GetType() & 0xfff) );
1020cdf0e10cSrcweir 			TypeClass eElementTypeClass = aElementType.getTypeClass();
1021cdf0e10cSrcweir 
1022cdf0e10cSrcweir 			// Normal case: One dimensional array
1023cdf0e10cSrcweir 			sal_Int32 nLower, nUpper;
1024cdf0e10cSrcweir 			if( nDims == 1 && pArray->GetDim32( 1, nLower, nUpper ) )
1025cdf0e10cSrcweir 			{
1026cdf0e10cSrcweir 				if( eElementTypeClass == TypeClass_VOID || eElementTypeClass == TypeClass_ANY )
1027cdf0e10cSrcweir 				{
1028cdf0e10cSrcweir 					// Wenn alle Elemente des Arrays vom gleichen Typ sind, wird
1029cdf0e10cSrcweir 					// der genommen, sonst wird das ganze als Any-Sequence betrachtet
1030cdf0e10cSrcweir 					sal_Bool bNeedsInit = sal_True;
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir     				sal_Int32 nSize = nUpper - nLower + 1;
1033cdf0e10cSrcweir 					sal_Int32 nIdx = nLower;
1034cdf0e10cSrcweir 					for( sal_Int32 i = 0 ; i < nSize ; i++,nIdx++ )
1035cdf0e10cSrcweir 					{
1036cdf0e10cSrcweir 						SbxVariableRef xVar = pArray->Get32( &nIdx );
1037cdf0e10cSrcweir 						Type aType = getUnoTypeForSbxValue( (SbxVariable*)xVar );
1038cdf0e10cSrcweir 						if( bNeedsInit )
1039cdf0e10cSrcweir 						{
1040cdf0e10cSrcweir 							if( aType.getTypeClass() == TypeClass_VOID )
1041cdf0e10cSrcweir 							{
1042cdf0e10cSrcweir 								// #88522
1043cdf0e10cSrcweir 								// if only first element is void: different types  -> []any
1044cdf0e10cSrcweir 								// if all elements are void: []void is not allowed -> []any
1045cdf0e10cSrcweir 								aElementType = getCppuType( (Any*)0 );
1046cdf0e10cSrcweir 								break;
1047cdf0e10cSrcweir 							}
1048cdf0e10cSrcweir 							aElementType = aType;
1049cdf0e10cSrcweir 							bNeedsInit = sal_False;
1050cdf0e10cSrcweir 						}
1051cdf0e10cSrcweir 						else if( aElementType != aType )
1052cdf0e10cSrcweir 						{
1053cdf0e10cSrcweir 							// Verschiedene Typen -> AnySequence
1054cdf0e10cSrcweir 							aElementType = getCppuType( (Any*)0 );
1055cdf0e10cSrcweir 							break;
1056cdf0e10cSrcweir 						}
1057cdf0e10cSrcweir 					}
1058cdf0e10cSrcweir 				}
1059cdf0e10cSrcweir 
1060cdf0e10cSrcweir 				::rtl::OUString aSeqTypeName( aSeqLevelStr );
1061cdf0e10cSrcweir 				aSeqTypeName += aElementType.getTypeName();
1062cdf0e10cSrcweir 				aRetType = Type( TypeClass_SEQUENCE, aSeqTypeName );
1063cdf0e10cSrcweir 			}
1064cdf0e10cSrcweir 			// #i33795 Map also multi dimensional arrays to corresponding sequences
1065cdf0e10cSrcweir 			else if( nDims > 1 )
1066cdf0e10cSrcweir 			{
1067cdf0e10cSrcweir 				if( eElementTypeClass == TypeClass_VOID || eElementTypeClass == TypeClass_ANY )
1068cdf0e10cSrcweir 				{
1069cdf0e10cSrcweir 					// For this check the array's dim structure does not matter
1070cdf0e10cSrcweir 					sal_uInt32 nFlatArraySize = pArray->Count32();
1071cdf0e10cSrcweir 
1072cdf0e10cSrcweir 					sal_Bool bNeedsInit = sal_True;
1073cdf0e10cSrcweir 					for( sal_uInt32 i = 0 ; i < nFlatArraySize ; i++ )
1074cdf0e10cSrcweir 					{
1075cdf0e10cSrcweir 						SbxVariableRef xVar = pArray->SbxArray::Get32( i );
1076cdf0e10cSrcweir 						Type aType = getUnoTypeForSbxValue( (SbxVariable*)xVar );
1077cdf0e10cSrcweir 						if( bNeedsInit )
1078cdf0e10cSrcweir 						{
1079cdf0e10cSrcweir 							if( aType.getTypeClass() == TypeClass_VOID )
1080cdf0e10cSrcweir 							{
1081cdf0e10cSrcweir 								// if only first element is void: different types  -> []any
1082cdf0e10cSrcweir 								// if all elements are void: []void is not allowed -> []any
1083cdf0e10cSrcweir 								aElementType = getCppuType( (Any*)0 );
1084cdf0e10cSrcweir 								break;
1085cdf0e10cSrcweir 							}
1086cdf0e10cSrcweir 							aElementType = aType;
1087cdf0e10cSrcweir 							bNeedsInit = sal_False;
1088cdf0e10cSrcweir 						}
1089cdf0e10cSrcweir 						else if( aElementType != aType )
1090cdf0e10cSrcweir 						{
1091cdf0e10cSrcweir 							// Verschiedene Typen -> AnySequence
1092cdf0e10cSrcweir 							aElementType = getCppuType( (Any*)0 );
1093cdf0e10cSrcweir 							break;
1094cdf0e10cSrcweir 						}
1095cdf0e10cSrcweir 					}
1096cdf0e10cSrcweir 				}
1097cdf0e10cSrcweir 
1098cdf0e10cSrcweir 				::rtl::OUString aSeqTypeName;
1099cdf0e10cSrcweir 				for( short iDim = 0 ; iDim < nDims ; iDim++ )
1100cdf0e10cSrcweir 					aSeqTypeName += aSeqLevelStr;
1101cdf0e10cSrcweir 				aSeqTypeName += aElementType.getTypeName();
1102cdf0e10cSrcweir 				aRetType = Type( TypeClass_SEQUENCE, aSeqTypeName );
1103cdf0e10cSrcweir 			}
1104cdf0e10cSrcweir 		}
1105cdf0e10cSrcweir 		// Kein Array, sondern...
1106cdf0e10cSrcweir 		else if( xObj->ISA(SbUnoObject) )
1107cdf0e10cSrcweir 		{
1108cdf0e10cSrcweir 			aRetType = ((SbUnoObject*)(SbxBase*)xObj)->getUnoAny().getValueType();
1109cdf0e10cSrcweir 		}
1110cdf0e10cSrcweir 		// SbUnoAnyObject?
1111cdf0e10cSrcweir 		else if( xObj->ISA(SbUnoAnyObject) )
1112cdf0e10cSrcweir 		{
1113cdf0e10cSrcweir 			aRetType = ((SbUnoAnyObject*)(SbxBase*)xObj)->getValue().getValueType();
1114cdf0e10cSrcweir 		}
1115cdf0e10cSrcweir 		// Sonst ist es ein Nicht-Uno-Basic-Objekt -> default==void liefern
1116cdf0e10cSrcweir 	}
1117cdf0e10cSrcweir 	// Kein Objekt, Basistyp konvertieren
1118cdf0e10cSrcweir 	else
1119cdf0e10cSrcweir 	{
1120cdf0e10cSrcweir 		aRetType = getUnoTypeForSbxBaseType( eBaseType );
1121cdf0e10cSrcweir 	}
1122cdf0e10cSrcweir 	return aRetType;
1123cdf0e10cSrcweir }
1124cdf0e10cSrcweir 
1125cdf0e10cSrcweir // Deklaration Konvertierung von Sbx nach Uno mit bekannter Zielklasse
1126cdf0e10cSrcweir Any sbxToUnoValue( SbxVariable* pVar, const Type& rType, Property* pUnoProperty = NULL );
1127cdf0e10cSrcweir 
1128cdf0e10cSrcweir // Konvertierung von Sbx nach Uno ohne bekannte Zielklasse fuer TypeClass_ANY
sbxToUnoValueImpl(SbxVariable * pVar,bool bBlockConversionToSmallestType=false)1129cdf0e10cSrcweir Any sbxToUnoValueImpl( SbxVariable* pVar, bool bBlockConversionToSmallestType = false )
1130cdf0e10cSrcweir {
1131cdf0e10cSrcweir 	SbxDataType eBaseType = pVar->SbxValue::GetType();
1132cdf0e10cSrcweir 	if( eBaseType == SbxOBJECT )
1133cdf0e10cSrcweir     {
1134cdf0e10cSrcweir 		SbxBaseRef xObj = (SbxBase*)pVar->GetObject();
1135cdf0e10cSrcweir 		if( xObj.Is() )
1136cdf0e10cSrcweir 		{
1137cdf0e10cSrcweir 			if( xObj->ISA(SbUnoAnyObject) )
1138cdf0e10cSrcweir 				return ((SbUnoAnyObject*)(SbxBase*)xObj)->getValue();
1139cdf0e10cSrcweir 			if( xObj->ISA(SbClassModuleObject) )
1140cdf0e10cSrcweir 			{
1141cdf0e10cSrcweir 				Any aRetAny;
1142cdf0e10cSrcweir 				SbClassModuleObject* pClassModuleObj = (SbClassModuleObject*)(SbxBase*)xObj;
1143cdf0e10cSrcweir 				SbModule* pClassModule = pClassModuleObj->getClassModule();
1144cdf0e10cSrcweir 				if( pClassModule->createCOMWrapperForIface( aRetAny, pClassModuleObj ) )
1145cdf0e10cSrcweir 					return aRetAny;
1146cdf0e10cSrcweir 			}
1147cdf0e10cSrcweir 			if( !xObj->ISA(SbUnoObject) )
1148cdf0e10cSrcweir 			{
1149cdf0e10cSrcweir 				// Create NativeObjectWrapper to identify object in case of callbacks
1150cdf0e10cSrcweir 				SbxObject* pObj = PTR_CAST(SbxObject,pVar->GetObject());
1151cdf0e10cSrcweir 				if( pObj != NULL )
1152cdf0e10cSrcweir 				{
1153cdf0e10cSrcweir 					NativeObjectWrapper aNativeObjectWrapper;
1154cdf0e10cSrcweir 					sal_uInt32 nIndex = lcl_registerNativeObjectWrapper( pObj );
1155cdf0e10cSrcweir 					aNativeObjectWrapper.ObjectId <<= nIndex;
1156cdf0e10cSrcweir 					Any aRetAny;
1157cdf0e10cSrcweir 					aRetAny <<= aNativeObjectWrapper;
1158cdf0e10cSrcweir 					return aRetAny;
1159cdf0e10cSrcweir 				}
1160cdf0e10cSrcweir 			}
1161cdf0e10cSrcweir 		}
1162cdf0e10cSrcweir     }
1163cdf0e10cSrcweir 
1164cdf0e10cSrcweir 	Type aType = getUnoTypeForSbxValue( pVar );
1165cdf0e10cSrcweir     TypeClass eType = aType.getTypeClass();
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir 	if( !bBlockConversionToSmallestType )
1168cdf0e10cSrcweir 	{
1169cdf0e10cSrcweir 		// #79615 Choose "smallest" represention for int values
1170cdf0e10cSrcweir 		// because up cast is allowed, downcast not
1171cdf0e10cSrcweir 		switch( eType )
1172cdf0e10cSrcweir 		{
1173cdf0e10cSrcweir 			case TypeClass_FLOAT:
1174cdf0e10cSrcweir 			case TypeClass_DOUBLE:
1175cdf0e10cSrcweir 			{
1176cdf0e10cSrcweir 				double d = pVar->GetDouble();
1177cdf0e10cSrcweir 				if( d == floor( d ) )
1178cdf0e10cSrcweir 				{
1179cdf0e10cSrcweir 					if( d >= -128 && d <= 127 )
1180cdf0e10cSrcweir 						aType = ::getCppuType( (sal_Int8*)0 );
1181cdf0e10cSrcweir 					else if( d >= SbxMININT && d <= SbxMAXINT )
1182cdf0e10cSrcweir 						aType = ::getCppuType( (sal_Int16*)0 );
1183cdf0e10cSrcweir 					else if( d >= -SbxMAXLNG && d <= SbxMAXLNG )
1184cdf0e10cSrcweir 						aType = ::getCppuType( (sal_Int32*)0 );
1185cdf0e10cSrcweir 				}
1186cdf0e10cSrcweir 				break;
1187cdf0e10cSrcweir 			}
1188cdf0e10cSrcweir 			case TypeClass_SHORT:
1189cdf0e10cSrcweir 			{
1190cdf0e10cSrcweir 				sal_Int16 n = pVar->GetInteger();
1191cdf0e10cSrcweir 				if( n >= -128 && n <= 127 )
1192cdf0e10cSrcweir 					aType = ::getCppuType( (sal_Int8*)0 );
1193cdf0e10cSrcweir 				break;
1194cdf0e10cSrcweir 			}
1195cdf0e10cSrcweir 			case TypeClass_LONG:
1196cdf0e10cSrcweir 			{
1197cdf0e10cSrcweir 				sal_Int32 n = pVar->GetLong();
1198cdf0e10cSrcweir 				if( n >= -128 && n <= 127 )
1199cdf0e10cSrcweir 					aType = ::getCppuType( (sal_Int8*)0 );
1200cdf0e10cSrcweir 				else if( n >= SbxMININT && n <= SbxMAXINT )
1201cdf0e10cSrcweir 					aType = ::getCppuType( (sal_Int16*)0 );
1202cdf0e10cSrcweir 				break;
1203cdf0e10cSrcweir 			}
1204cdf0e10cSrcweir 			case TypeClass_UNSIGNED_SHORT:
1205cdf0e10cSrcweir 			{
1206cdf0e10cSrcweir 				sal_uInt16 n = pVar->GetUShort();
1207cdf0e10cSrcweir 				if( n <= 255 )
1208cdf0e10cSrcweir 					aType = ::getCppuType( (sal_uInt8*)0 );
1209cdf0e10cSrcweir 				break;
1210cdf0e10cSrcweir 			}
1211cdf0e10cSrcweir 			case TypeClass_UNSIGNED_LONG:
1212cdf0e10cSrcweir 			{
1213cdf0e10cSrcweir 				sal_uInt32 n = pVar->GetLong();
1214cdf0e10cSrcweir 				if( n <= 255 )
1215cdf0e10cSrcweir 					aType = ::getCppuType( (sal_uInt8*)0 );
1216cdf0e10cSrcweir 				else if( n <= SbxMAXUINT )
1217cdf0e10cSrcweir 					aType = ::getCppuType( (sal_uInt16*)0 );
1218cdf0e10cSrcweir 				break;
1219cdf0e10cSrcweir 			}
1220cdf0e10cSrcweir 			default: break;
1221cdf0e10cSrcweir 		}
1222cdf0e10cSrcweir 	}
1223cdf0e10cSrcweir 
1224cdf0e10cSrcweir 	return sbxToUnoValue( pVar, aType );
1225cdf0e10cSrcweir }
1226cdf0e10cSrcweir 
1227cdf0e10cSrcweir 
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir // Helper function for StepREDIMP
implRekMultiDimArrayToSequence(SbxDimArray * pArray,const Type & aElemType,short nMaxDimIndex,short nActualDim,sal_Int32 * pActualIndices,sal_Int32 * pLowerBounds,sal_Int32 * pUpperBounds)1230cdf0e10cSrcweir static Any implRekMultiDimArrayToSequence( SbxDimArray* pArray,
1231cdf0e10cSrcweir 	const Type& aElemType, short nMaxDimIndex, short nActualDim,
1232cdf0e10cSrcweir 	sal_Int32* pActualIndices, sal_Int32* pLowerBounds, sal_Int32* pUpperBounds )
1233cdf0e10cSrcweir {
1234cdf0e10cSrcweir 	sal_Int32 nSeqLevel = nMaxDimIndex - nActualDim + 1;
1235cdf0e10cSrcweir 	::rtl::OUString aSeqTypeName;
1236cdf0e10cSrcweir 	sal_Int32 i;
1237cdf0e10cSrcweir 	for( i = 0 ; i < nSeqLevel ; i++ )
1238cdf0e10cSrcweir 		aSeqTypeName += aSeqLevelStr;
1239cdf0e10cSrcweir 
1240cdf0e10cSrcweir 	aSeqTypeName += aElemType.getTypeName();
1241cdf0e10cSrcweir 	Type aSeqType( TypeClass_SEQUENCE, aSeqTypeName );
1242cdf0e10cSrcweir 
1243cdf0e10cSrcweir 	// Create Sequence instance
1244cdf0e10cSrcweir 	Any aRetVal;
1245cdf0e10cSrcweir 	Reference< XIdlClass > xIdlTargetClass = TypeToIdlClass( aSeqType );
1246cdf0e10cSrcweir 	xIdlTargetClass->createObject( aRetVal );
1247cdf0e10cSrcweir 
1248cdf0e10cSrcweir 	// Alloc sequence according to array bounds
1249cdf0e10cSrcweir 	sal_Int32 nUpper = pUpperBounds[nActualDim];
1250cdf0e10cSrcweir 	sal_Int32 nLower = pLowerBounds[nActualDim];
1251cdf0e10cSrcweir 	sal_Int32 nSeqSize = nUpper - nLower + 1;
1252cdf0e10cSrcweir 	Reference< XIdlArray > xArray = xIdlTargetClass->getArray();
1253cdf0e10cSrcweir 	xArray->realloc( aRetVal, nSeqSize );
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir 	sal_Int32& ri = pActualIndices[nActualDim];
1256cdf0e10cSrcweir 
1257cdf0e10cSrcweir 	for( ri = nLower,i = 0 ; ri <= nUpper ; ri++,i++ )
1258cdf0e10cSrcweir 	{
1259cdf0e10cSrcweir 		Any aElementVal;
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir 		if( nActualDim < nMaxDimIndex )
1262cdf0e10cSrcweir 		{
1263cdf0e10cSrcweir 			aElementVal = implRekMultiDimArrayToSequence( pArray, aElemType,
1264cdf0e10cSrcweir 				nMaxDimIndex, nActualDim + 1, pActualIndices, pLowerBounds, pUpperBounds );
1265cdf0e10cSrcweir 		}
1266cdf0e10cSrcweir 		else
1267cdf0e10cSrcweir 		{
1268cdf0e10cSrcweir 			SbxVariable* pSource = pArray->Get32( pActualIndices );
1269cdf0e10cSrcweir 			aElementVal = sbxToUnoValue( pSource, aElemType );
1270cdf0e10cSrcweir 		}
1271cdf0e10cSrcweir 
1272cdf0e10cSrcweir 		try
1273cdf0e10cSrcweir 		{
1274cdf0e10cSrcweir 			// In die Sequence uebernehmen
1275cdf0e10cSrcweir 			xArray->set( aRetVal, i, aElementVal );
1276cdf0e10cSrcweir 		}
1277cdf0e10cSrcweir 		catch( const IllegalArgumentException& )
1278cdf0e10cSrcweir 		{
1279cdf0e10cSrcweir 			StarBASIC::Error( ERRCODE_BASIC_EXCEPTION,
1280cdf0e10cSrcweir 				implGetExceptionMsg( ::cppu::getCaughtException() ) );
1281cdf0e10cSrcweir 		}
1282cdf0e10cSrcweir 		catch (IndexOutOfBoundsException&)
1283cdf0e10cSrcweir 		{
1284cdf0e10cSrcweir 			StarBASIC::Error( SbERR_OUT_OF_RANGE );
1285cdf0e10cSrcweir 		}
1286cdf0e10cSrcweir 	}
1287cdf0e10cSrcweir 	return aRetVal;
1288cdf0e10cSrcweir }
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir // Map old interface
sbxToUnoValue(SbxVariable * pVar)1291cdf0e10cSrcweir Any sbxToUnoValue( SbxVariable* pVar )
1292cdf0e10cSrcweir {
1293cdf0e10cSrcweir 	return sbxToUnoValueImpl( pVar );
1294cdf0e10cSrcweir }
1295cdf0e10cSrcweir 
1296cdf0e10cSrcweir 
1297cdf0e10cSrcweir // Funktion, um einen globalen Bezeichner im
1298cdf0e10cSrcweir // UnoScope zu suchen und fuer Sbx zu wrappen
implGetTypeByName(const String & rName,Type & rRetType)1299cdf0e10cSrcweir static bool implGetTypeByName( const String& rName, Type& rRetType )
1300cdf0e10cSrcweir {
1301cdf0e10cSrcweir 	bool bSuccess = false;
1302cdf0e10cSrcweir 
1303cdf0e10cSrcweir     Reference< XHierarchicalNameAccess > xTypeAccess = getTypeProvider_Impl();
1304cdf0e10cSrcweir     if( xTypeAccess->hasByHierarchicalName( rName ) )
1305cdf0e10cSrcweir     {
1306cdf0e10cSrcweir         Any aRet = xTypeAccess->getByHierarchicalName( rName );
1307cdf0e10cSrcweir 		Reference< XTypeDescription > xTypeDesc;
1308cdf0e10cSrcweir 		aRet >>= xTypeDesc;
1309cdf0e10cSrcweir 
1310cdf0e10cSrcweir         if( xTypeDesc.is() )
1311cdf0e10cSrcweir         {
1312cdf0e10cSrcweir 			rRetType = Type( xTypeDesc->getTypeClass(), xTypeDesc->getName() );
1313cdf0e10cSrcweir 			bSuccess = true;
1314cdf0e10cSrcweir         }
1315cdf0e10cSrcweir     }
1316cdf0e10cSrcweir 	return bSuccess;
1317cdf0e10cSrcweir }
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir 
1320cdf0e10cSrcweir // Konvertierung von Sbx nach Uno mit bekannter Zielklasse
sbxToUnoValue(SbxVariable * pVar,const Type & rType,Property * pUnoProperty)1321cdf0e10cSrcweir Any sbxToUnoValue( SbxVariable* pVar, const Type& rType, Property* pUnoProperty )
1322cdf0e10cSrcweir {
1323cdf0e10cSrcweir 	Any aRetVal;
1324cdf0e10cSrcweir 
1325cdf0e10cSrcweir 	// #94560 No conversion of empty/void for MAYBE_VOID properties
1326cdf0e10cSrcweir 	if( pUnoProperty && pUnoProperty->Attributes & PropertyAttribute::MAYBEVOID )
1327cdf0e10cSrcweir 	{
1328cdf0e10cSrcweir 		if( pVar->IsEmpty() )
1329cdf0e10cSrcweir 			return aRetVal;
1330cdf0e10cSrcweir 	}
1331cdf0e10cSrcweir 
1332cdf0e10cSrcweir 	SbxDataType eBaseType = pVar->SbxValue::GetType();
1333cdf0e10cSrcweir 	if( eBaseType == SbxOBJECT )
1334cdf0e10cSrcweir     {
1335cdf0e10cSrcweir 		SbxBaseRef xObj = (SbxBase*)pVar->GetObject();
1336cdf0e10cSrcweir 		if( xObj.Is() && xObj->ISA(SbUnoAnyObject) )
1337cdf0e10cSrcweir         {
1338cdf0e10cSrcweir             return ((SbUnoAnyObject*)(SbxBase*)xObj)->getValue();
1339cdf0e10cSrcweir         }
1340cdf0e10cSrcweir     }
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir     TypeClass eType = rType.getTypeClass();
1343cdf0e10cSrcweir 	switch( eType )
1344cdf0e10cSrcweir 	{
1345cdf0e10cSrcweir 		case TypeClass_INTERFACE:
1346cdf0e10cSrcweir 		case TypeClass_STRUCT:
1347cdf0e10cSrcweir 		case TypeClass_EXCEPTION:
1348cdf0e10cSrcweir 		{
1349cdf0e10cSrcweir 			Reference< XIdlClass > xIdlTargetClass = TypeToIdlClass( rType );
1350cdf0e10cSrcweir 
1351cdf0e10cSrcweir 			// Null-Referenz?
1352cdf0e10cSrcweir 			if( pVar->IsNull() && eType == TypeClass_INTERFACE )
1353cdf0e10cSrcweir 			{
1354cdf0e10cSrcweir 				Reference< XInterface > xRef;
1355cdf0e10cSrcweir 				::rtl::OUString aClassName = xIdlTargetClass->getName();
1356cdf0e10cSrcweir 				Type aClassType( xIdlTargetClass->getTypeClass(), aClassName.getStr() );
1357cdf0e10cSrcweir 				aRetVal.setValue( &xRef, aClassType );
1358cdf0e10cSrcweir 			}
1359cdf0e10cSrcweir 			else
1360cdf0e10cSrcweir 			{
1361cdf0e10cSrcweir 				// #112368 Special conversion for Decimal, Currency and Date
1362cdf0e10cSrcweir 				if( eType == TypeClass_STRUCT )
1363cdf0e10cSrcweir 				{
1364cdf0e10cSrcweir 					SbiInstance* pInst = pINST;
1365cdf0e10cSrcweir 					if( pInst && pInst->IsCompatibility() )
1366cdf0e10cSrcweir 					{
1367cdf0e10cSrcweir 						if( rType == ::getCppuType( (oleautomation::Decimal*)0 ) )
1368cdf0e10cSrcweir 						{
1369cdf0e10cSrcweir 							oleautomation::Decimal aDecimal;
1370cdf0e10cSrcweir 							pVar->fillAutomationDecimal( aDecimal );
1371cdf0e10cSrcweir 							aRetVal <<= aDecimal;
1372cdf0e10cSrcweir 							break;
1373cdf0e10cSrcweir 						}
1374cdf0e10cSrcweir 						else if( rType == ::getCppuType( (oleautomation::Currency*)0 ) )
1375cdf0e10cSrcweir 						{
1376cdf0e10cSrcweir 							SbxINT64 aInt64 = pVar->GetCurrency();
1377cdf0e10cSrcweir 							oleautomation::Currency aCurrency;
1378cdf0e10cSrcweir 							sal_Int64& rnValue64 = aCurrency.Value;
1379cdf0e10cSrcweir 							rnValue64 = aInt64.nHigh;
1380cdf0e10cSrcweir 							rnValue64 <<= 32;
1381cdf0e10cSrcweir 							rnValue64 |= aInt64.nLow;
1382cdf0e10cSrcweir 							aRetVal <<= aCurrency;
1383cdf0e10cSrcweir 							break;
1384cdf0e10cSrcweir 						}
1385cdf0e10cSrcweir 						else if( rType == ::getCppuType( (oleautomation::Date*)0 ) )
1386cdf0e10cSrcweir 						{
1387cdf0e10cSrcweir 							oleautomation::Date aDate;
1388cdf0e10cSrcweir 							aDate.Value = pVar->GetDate();
1389cdf0e10cSrcweir 							aRetVal <<= aDate;
1390cdf0e10cSrcweir 							break;
1391cdf0e10cSrcweir 						}
1392cdf0e10cSrcweir 					}
1393cdf0e10cSrcweir 				}
1394cdf0e10cSrcweir 
1395cdf0e10cSrcweir 				SbxBaseRef pObj = (SbxBase*)pVar->GetObject();
1396cdf0e10cSrcweir 				if( pObj && pObj->ISA(SbUnoObject) )
1397cdf0e10cSrcweir 				{
1398cdf0e10cSrcweir 					aRetVal = ((SbUnoObject*)(SbxBase*)pObj)->getUnoAny();
1399cdf0e10cSrcweir 				}
1400cdf0e10cSrcweir 				else
1401cdf0e10cSrcweir 				{
1402cdf0e10cSrcweir 					// #109936 NULL object -> NULL XInterface
1403cdf0e10cSrcweir 					Reference<XInterface> xInt;
1404cdf0e10cSrcweir 					aRetVal <<= xInt;
1405cdf0e10cSrcweir 				}
1406cdf0e10cSrcweir 			}
1407cdf0e10cSrcweir 		}
1408cdf0e10cSrcweir 		break;
1409cdf0e10cSrcweir 
1410cdf0e10cSrcweir 		case TypeClass_TYPE:
1411cdf0e10cSrcweir 		{
1412cdf0e10cSrcweir 			if( eBaseType == SbxOBJECT )
1413cdf0e10cSrcweir 			{
1414cdf0e10cSrcweir 				// XIdlClass?
1415cdf0e10cSrcweir 				Reference< XIdlClass > xIdlClass;
1416cdf0e10cSrcweir 
1417cdf0e10cSrcweir 				SbxBaseRef pObj = (SbxBase*)pVar->GetObject();
1418cdf0e10cSrcweir 				if( pObj && pObj->ISA(SbUnoObject) )
1419cdf0e10cSrcweir 				{
1420cdf0e10cSrcweir 					Any aUnoAny = ((SbUnoObject*)(SbxBase*)pObj)->getUnoAny();
1421cdf0e10cSrcweir 					aUnoAny >>= xIdlClass;
1422cdf0e10cSrcweir 				}
1423cdf0e10cSrcweir 
1424cdf0e10cSrcweir 				if( xIdlClass.is() )
1425cdf0e10cSrcweir 				{
1426cdf0e10cSrcweir 					::rtl::OUString aClassName = xIdlClass->getName();
1427cdf0e10cSrcweir 					Type aType( xIdlClass->getTypeClass(), aClassName.getStr() );
1428cdf0e10cSrcweir 					aRetVal <<= aType;
1429cdf0e10cSrcweir 				}
1430cdf0e10cSrcweir 			}
1431cdf0e10cSrcweir 			else if( eBaseType == SbxSTRING )
1432cdf0e10cSrcweir 			{
1433cdf0e10cSrcweir 				// String representing type?
1434cdf0e10cSrcweir 				String aTypeName = pVar->GetString();
1435cdf0e10cSrcweir 				Type aType;
1436cdf0e10cSrcweir 				bool bSuccess = implGetTypeByName( aTypeName, aType );
1437cdf0e10cSrcweir 				if( bSuccess )
1438cdf0e10cSrcweir 					aRetVal <<= aType;
1439cdf0e10cSrcweir 			}
1440cdf0e10cSrcweir 		}
1441cdf0e10cSrcweir 		break;
1442cdf0e10cSrcweir 
1443cdf0e10cSrcweir 		/* folgende Typen lassen wir erstmal weg
1444cdf0e10cSrcweir 		case TypeClass_SERVICE:			break;
1445cdf0e10cSrcweir 		case TypeClass_CLASS:			break;
1446cdf0e10cSrcweir 		case TypeClass_TYPEDEF:			break;
1447cdf0e10cSrcweir 		case TypeClass_UNION:			break;
1448cdf0e10cSrcweir 		case TypeClass_ENUM:			break;
1449cdf0e10cSrcweir 		case TypeClass_ARRAY:			break;
1450cdf0e10cSrcweir 		*/
1451cdf0e10cSrcweir 
1452cdf0e10cSrcweir 		// Array -> Sequence
1453cdf0e10cSrcweir 		case TypeClass_ENUM:
1454cdf0e10cSrcweir 		{
1455cdf0e10cSrcweir 			aRetVal = int2enum( pVar->GetLong(), rType );
1456cdf0e10cSrcweir 		}
1457cdf0e10cSrcweir 		break;
1458cdf0e10cSrcweir 
1459cdf0e10cSrcweir 		case TypeClass_SEQUENCE:
1460cdf0e10cSrcweir 		{
1461cdf0e10cSrcweir 			SbxBaseRef xObj = (SbxBase*)pVar->GetObject();
1462cdf0e10cSrcweir 			if( xObj && xObj->ISA(SbxDimArray) )
1463cdf0e10cSrcweir 			{
1464cdf0e10cSrcweir 				SbxBase* pObj = (SbxBase*)xObj;
1465cdf0e10cSrcweir 				SbxDimArray* pArray = (SbxDimArray*)pObj;
1466cdf0e10cSrcweir 
1467cdf0e10cSrcweir 				short nDims = pArray->GetDims();
1468cdf0e10cSrcweir 
1469cdf0e10cSrcweir 				// Normal case: One dimensional array
1470cdf0e10cSrcweir 				sal_Int32 nLower, nUpper;
1471cdf0e10cSrcweir 				if( nDims == 1 && pArray->GetDim32( 1, nLower, nUpper ) )
1472cdf0e10cSrcweir 				{
1473cdf0e10cSrcweir 					sal_Int32 nSeqSize = nUpper - nLower + 1;
1474cdf0e10cSrcweir 
1475cdf0e10cSrcweir 					// Instanz der geforderten Sequence erzeugen
1476cdf0e10cSrcweir 					Reference< XIdlClass > xIdlTargetClass = TypeToIdlClass( rType );
1477cdf0e10cSrcweir 					xIdlTargetClass->createObject( aRetVal );
1478cdf0e10cSrcweir 					Reference< XIdlArray > xArray = xIdlTargetClass->getArray();
1479cdf0e10cSrcweir 					xArray->realloc( aRetVal, nSeqSize );
1480cdf0e10cSrcweir 
1481cdf0e10cSrcweir 					// Element-Type
1482cdf0e10cSrcweir 					::rtl::OUString aClassName = xIdlTargetClass->getName();
1483cdf0e10cSrcweir 					typelib_TypeDescription * pSeqTD = 0;
1484cdf0e10cSrcweir 					typelib_typedescription_getByName( &pSeqTD, aClassName.pData );
1485cdf0e10cSrcweir 					OSL_ASSERT( pSeqTD );
1486cdf0e10cSrcweir 					Type aElemType( ((typelib_IndirectTypeDescription *)pSeqTD)->pType );
1487cdf0e10cSrcweir 					// Reference< XIdlClass > xElementClass = TypeToIdlClass( aElemType );
1488cdf0e10cSrcweir 
1489cdf0e10cSrcweir 					// Alle Array-Member umwandeln und eintragen
1490cdf0e10cSrcweir 					sal_Int32 nIdx = nLower;
1491cdf0e10cSrcweir 					for( sal_Int32 i = 0 ; i < nSeqSize ; i++,nIdx++ )
1492cdf0e10cSrcweir 					{
1493cdf0e10cSrcweir 						SbxVariableRef xVar = pArray->Get32( &nIdx );
1494cdf0e10cSrcweir 
1495cdf0e10cSrcweir 						// Wert von Sbx nach Uno wandeln
1496cdf0e10cSrcweir 						Any aAnyValue = sbxToUnoValue( (SbxVariable*)xVar, aElemType );
1497cdf0e10cSrcweir 
1498cdf0e10cSrcweir 						try
1499cdf0e10cSrcweir 						{
1500cdf0e10cSrcweir 							// In die Sequence uebernehmen
1501cdf0e10cSrcweir 							xArray->set( aRetVal, i, aAnyValue );
1502cdf0e10cSrcweir 						}
1503cdf0e10cSrcweir 						catch( const IllegalArgumentException& )
1504cdf0e10cSrcweir 						{
1505cdf0e10cSrcweir 							StarBASIC::Error( ERRCODE_BASIC_EXCEPTION,
1506cdf0e10cSrcweir                                 implGetExceptionMsg( ::cppu::getCaughtException() ) );
1507cdf0e10cSrcweir 						}
1508cdf0e10cSrcweir 						catch (IndexOutOfBoundsException&)
1509cdf0e10cSrcweir 						{
1510cdf0e10cSrcweir 							StarBASIC::Error( SbERR_OUT_OF_RANGE );
1511cdf0e10cSrcweir 						}
1512cdf0e10cSrcweir 					}
1513cdf0e10cSrcweir 				}
1514cdf0e10cSrcweir 				// #i33795 Map also multi dimensional arrays to corresponding sequences
1515cdf0e10cSrcweir 				else if( nDims > 1 )
1516cdf0e10cSrcweir 				{
1517cdf0e10cSrcweir 					// Element-Type
1518cdf0e10cSrcweir 					typelib_TypeDescription * pSeqTD = 0;
1519cdf0e10cSrcweir 					Type aCurType( rType );
1520cdf0e10cSrcweir 					sal_Int32 nSeqLevel = 0;
1521cdf0e10cSrcweir 					Type aElemType;
1522cdf0e10cSrcweir 					do
1523cdf0e10cSrcweir 					{
1524cdf0e10cSrcweir 						::rtl::OUString aTypeName = aCurType.getTypeName();
1525cdf0e10cSrcweir 						typelib_typedescription_getByName( &pSeqTD, aTypeName.pData );
1526cdf0e10cSrcweir 						OSL_ASSERT( pSeqTD );
1527cdf0e10cSrcweir 						if( pSeqTD->eTypeClass == typelib_TypeClass_SEQUENCE )
1528cdf0e10cSrcweir 						{
1529cdf0e10cSrcweir 							aCurType = Type( ((typelib_IndirectTypeDescription *)pSeqTD)->pType );
1530cdf0e10cSrcweir 							nSeqLevel++;
1531cdf0e10cSrcweir 						}
1532cdf0e10cSrcweir 						else
1533cdf0e10cSrcweir 						{
1534cdf0e10cSrcweir 							aElemType = aCurType;
1535cdf0e10cSrcweir 							break;
1536cdf0e10cSrcweir 						}
1537cdf0e10cSrcweir 					}
1538cdf0e10cSrcweir 					while( true );
1539cdf0e10cSrcweir 
1540cdf0e10cSrcweir 					if( nSeqLevel == nDims )
1541cdf0e10cSrcweir 					{
1542cdf0e10cSrcweir 						sal_Int32* pLowerBounds = new sal_Int32[nDims];
1543cdf0e10cSrcweir 						sal_Int32* pUpperBounds = new sal_Int32[nDims];
1544cdf0e10cSrcweir 						sal_Int32* pActualIndices = new sal_Int32[nDims];
1545cdf0e10cSrcweir 						for( short i = 1 ; i <= nDims ; i++ )
1546cdf0e10cSrcweir 						{
1547cdf0e10cSrcweir 							sal_Int32 lBound, uBound;
1548cdf0e10cSrcweir 							pArray->GetDim32( i, lBound, uBound );
1549cdf0e10cSrcweir 
1550cdf0e10cSrcweir 							short j = i - 1;
1551cdf0e10cSrcweir 							pActualIndices[j] = pLowerBounds[j] = lBound;
1552cdf0e10cSrcweir 							pUpperBounds[j] = uBound;
1553cdf0e10cSrcweir 						}
1554cdf0e10cSrcweir 
1555cdf0e10cSrcweir 						aRetVal = implRekMultiDimArrayToSequence( pArray, aElemType,
1556cdf0e10cSrcweir 							nDims - 1, 0, pActualIndices, pLowerBounds, pUpperBounds );
1557cdf0e10cSrcweir 
1558cdf0e10cSrcweir 						delete[] pUpperBounds;
1559cdf0e10cSrcweir 						delete[] pLowerBounds;
1560cdf0e10cSrcweir 						delete[] pActualIndices;
1561cdf0e10cSrcweir 					}
1562cdf0e10cSrcweir 				}
1563cdf0e10cSrcweir 			}
1564cdf0e10cSrcweir 		}
1565cdf0e10cSrcweir 		break;
1566cdf0e10cSrcweir 
1567cdf0e10cSrcweir 		/*
1568cdf0e10cSrcweir 		case TypeClass_VOID:			break;
1569cdf0e10cSrcweir 		case TypeClass_UNKNOWN:			break;
1570cdf0e10cSrcweir 		*/
1571cdf0e10cSrcweir 
1572cdf0e10cSrcweir 		// Bei Any die Klassen-unabhaengige Konvertierungs-Routine nutzen
1573cdf0e10cSrcweir 		case TypeClass_ANY:
1574cdf0e10cSrcweir 		{
1575cdf0e10cSrcweir 			aRetVal = sbxToUnoValueImpl( pVar );
1576cdf0e10cSrcweir 		}
1577cdf0e10cSrcweir 		break;
1578cdf0e10cSrcweir 
1579cdf0e10cSrcweir 		case TypeClass_BOOLEAN:
1580cdf0e10cSrcweir 		{
1581cdf0e10cSrcweir 			sal_Bool b = pVar->GetBool();
1582cdf0e10cSrcweir 			aRetVal.setValue( &b, getBooleanCppuType() );
1583cdf0e10cSrcweir 			break;
1584cdf0e10cSrcweir 		}
1585cdf0e10cSrcweir 		case TypeClass_CHAR:
1586cdf0e10cSrcweir 		{
1587cdf0e10cSrcweir 			sal_Unicode c = pVar->GetChar();
1588cdf0e10cSrcweir 			aRetVal.setValue( &c , getCharCppuType() );
1589cdf0e10cSrcweir 			break;
1590cdf0e10cSrcweir 		}
1591cdf0e10cSrcweir 		case TypeClass_STRING:			aRetVal <<= pVar->GetOUString(); break;
1592cdf0e10cSrcweir 		case TypeClass_FLOAT:			aRetVal <<= pVar->GetSingle(); break;
1593cdf0e10cSrcweir 		case TypeClass_DOUBLE:			aRetVal <<= pVar->GetDouble(); break;
1594cdf0e10cSrcweir 		//case TypeClass_OCTET:			break;
1595cdf0e10cSrcweir 
1596cdf0e10cSrcweir 		case TypeClass_BYTE:
1597cdf0e10cSrcweir         {
1598cdf0e10cSrcweir             sal_Int16 nVal = pVar->GetInteger();
1599cdf0e10cSrcweir             sal_Bool bOverflow = sal_False;
1600cdf0e10cSrcweir             if( nVal < -128 )
1601cdf0e10cSrcweir             {
1602cdf0e10cSrcweir                 bOverflow = sal_True;
1603cdf0e10cSrcweir                 nVal = -128;
1604cdf0e10cSrcweir             }
1605cdf0e10cSrcweir             else if( nVal > 127 )
1606cdf0e10cSrcweir             {
1607cdf0e10cSrcweir                 bOverflow = sal_True;
1608cdf0e10cSrcweir                 nVal = 127;
1609cdf0e10cSrcweir             }
1610cdf0e10cSrcweir             if( bOverflow )
1611cdf0e10cSrcweir            		StarBASIC::Error( ERRCODE_BASIC_MATH_OVERFLOW );
1612cdf0e10cSrcweir 
1613cdf0e10cSrcweir             sal_Int8 nByteVal = (sal_Int8)nVal;
1614cdf0e10cSrcweir             aRetVal <<= nByteVal;
1615cdf0e10cSrcweir             break;
1616cdf0e10cSrcweir         }
1617cdf0e10cSrcweir 		//case TypeClass_INT:			break;
1618cdf0e10cSrcweir 		case TypeClass_SHORT:			aRetVal <<= (sal_Int16)( pVar->GetInteger() );	break;
1619cdf0e10cSrcweir 		case TypeClass_LONG:			aRetVal <<= (sal_Int32)( pVar->GetLong() );     break;
1620cdf0e10cSrcweir 		case TypeClass_HYPER:			aRetVal <<= (sal_Int64)( pVar->GetInt64() );    break;
1621cdf0e10cSrcweir 		//case TypeClass_UNSIGNED_OCTET:break;
1622cdf0e10cSrcweir 		case TypeClass_UNSIGNED_SHORT:	aRetVal <<= (sal_uInt16)( pVar->GetUShort() );	break;
1623cdf0e10cSrcweir 		case TypeClass_UNSIGNED_LONG:	aRetVal <<= (sal_uInt32)( pVar->GetULong() );	break;
1624cdf0e10cSrcweir 		case TypeClass_UNSIGNED_HYPER:  aRetVal <<= (sal_uInt64)( pVar->GetUInt64() );  break;
1625cdf0e10cSrcweir 		//case TypeClass_UNSIGNED_INT:	break;
1626cdf0e10cSrcweir 		//case TypeClass_UNSIGNED_BYTE:	break;
1627cdf0e10cSrcweir 		default: break;
1628cdf0e10cSrcweir 	}
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir 	return aRetVal;
1631cdf0e10cSrcweir }
1632cdf0e10cSrcweir 
1633cdf0e10cSrcweir // Dbg-Hilfsmethode zum Auslesen der in einem Object implementierten Interfaces
Impl_GetInterfaceInfo(const Reference<XInterface> & x,const Reference<XIdlClass> & xClass,sal_uInt16 nRekLevel)1634cdf0e10cSrcweir String Impl_GetInterfaceInfo( const Reference< XInterface >& x, const Reference< XIdlClass >& xClass, sal_uInt16 nRekLevel )
1635cdf0e10cSrcweir {
1636cdf0e10cSrcweir 	Type aIfaceType = ::getCppuType( (const Reference< XInterface > *)0 );
1637cdf0e10cSrcweir 	static Reference< XIdlClass > xIfaceClass = TypeToIdlClass( aIfaceType );
1638cdf0e10cSrcweir 
1639cdf0e10cSrcweir 	String aRetStr;
1640cdf0e10cSrcweir 	for( sal_uInt16 i = 0 ; i < nRekLevel ; i++ )
1641cdf0e10cSrcweir 		aRetStr.AppendAscii( "    " );
1642cdf0e10cSrcweir 	aRetStr += String( xClass->getName() );
1643cdf0e10cSrcweir 	::rtl::OUString aClassName = xClass->getName();
1644cdf0e10cSrcweir 	Type aClassType( xClass->getTypeClass(), aClassName.getStr() );
1645cdf0e10cSrcweir 
1646cdf0e10cSrcweir 	// Pruefen, ob das Interface wirklich unterstuetzt wird
1647cdf0e10cSrcweir 	if( !x->queryInterface( aClassType ).hasValue() )
1648cdf0e10cSrcweir 	{
1649cdf0e10cSrcweir 		aRetStr.AppendAscii( " (ERROR: Not really supported!)\n" );
1650cdf0e10cSrcweir 	}
1651cdf0e10cSrcweir 	// Gibt es Super-Interfaces
1652cdf0e10cSrcweir 	else
1653cdf0e10cSrcweir 	{
1654cdf0e10cSrcweir 		aRetStr.AppendAscii( "\n" );
1655cdf0e10cSrcweir 
1656cdf0e10cSrcweir 		// Super-Interfaces holen
1657cdf0e10cSrcweir 		Sequence< Reference< XIdlClass > > aSuperClassSeq = xClass->getSuperclasses();
1658cdf0e10cSrcweir 		const Reference< XIdlClass >* pClasses = aSuperClassSeq.getConstArray();
1659cdf0e10cSrcweir 		sal_uInt32 nSuperIfaceCount = aSuperClassSeq.getLength();
1660cdf0e10cSrcweir 		for( sal_uInt32 j = 0 ; j < nSuperIfaceCount ; j++ )
1661cdf0e10cSrcweir 		{
1662cdf0e10cSrcweir 			const Reference< XIdlClass >& rxIfaceClass = pClasses[j];
1663cdf0e10cSrcweir 			if( !rxIfaceClass->equals( xIfaceClass ) )
1664cdf0e10cSrcweir 				aRetStr += Impl_GetInterfaceInfo( x, rxIfaceClass, nRekLevel + 1 );
1665cdf0e10cSrcweir 		}
1666cdf0e10cSrcweir 	}
1667cdf0e10cSrcweir 	return aRetStr;
1668cdf0e10cSrcweir }
1669cdf0e10cSrcweir 
getDbgObjectNameImpl(SbUnoObject * pUnoObj)1670cdf0e10cSrcweir String getDbgObjectNameImpl( SbUnoObject* pUnoObj )
1671cdf0e10cSrcweir {
1672cdf0e10cSrcweir 	String aName;
1673cdf0e10cSrcweir 	if( pUnoObj )
1674cdf0e10cSrcweir 	{
1675cdf0e10cSrcweir 		aName = pUnoObj->GetClassName();
1676cdf0e10cSrcweir 		if( !aName.Len() )
1677cdf0e10cSrcweir 		{
1678cdf0e10cSrcweir 			Any aToInspectObj = pUnoObj->getUnoAny();
1679cdf0e10cSrcweir 			TypeClass eType = aToInspectObj.getValueType().getTypeClass();
1680cdf0e10cSrcweir 			Reference< XInterface > xObj;
1681cdf0e10cSrcweir 			if( eType == TypeClass_INTERFACE )
1682cdf0e10cSrcweir 				xObj = *(Reference< XInterface >*)aToInspectObj.getValue();
1683cdf0e10cSrcweir 			if( xObj.is() )
1684cdf0e10cSrcweir 			{
1685cdf0e10cSrcweir 				Reference< XServiceInfo > xServiceInfo( xObj, UNO_QUERY );
1686cdf0e10cSrcweir 				if( xServiceInfo.is() )
1687cdf0e10cSrcweir 					aName = xServiceInfo->getImplementationName();
1688cdf0e10cSrcweir 			}
1689cdf0e10cSrcweir 		}
1690cdf0e10cSrcweir 	}
1691cdf0e10cSrcweir 	return aName;
1692cdf0e10cSrcweir }
1693cdf0e10cSrcweir 
getDbgObjectName(SbUnoObject * pUnoObj)1694cdf0e10cSrcweir String getDbgObjectName( SbUnoObject* pUnoObj )
1695cdf0e10cSrcweir {
1696cdf0e10cSrcweir 	String aName = getDbgObjectNameImpl( pUnoObj );
1697cdf0e10cSrcweir 	if( !aName.Len() )
1698cdf0e10cSrcweir 		aName.AppendAscii( "Unknown" );
1699cdf0e10cSrcweir 
1700cdf0e10cSrcweir 	String aRet;
1701cdf0e10cSrcweir 	if( aName.Len() > 20 )
1702cdf0e10cSrcweir 		aRet.AppendAscii( "\n" );
1703cdf0e10cSrcweir 	aRet.AppendAscii( "\"" );
1704cdf0e10cSrcweir 	aRet += aName;
1705cdf0e10cSrcweir 	aRet.AppendAscii( "\":" );
1706cdf0e10cSrcweir 	return aRet;
1707cdf0e10cSrcweir }
1708cdf0e10cSrcweir 
getBasicObjectTypeName(SbxObject * pObj)1709cdf0e10cSrcweir String getBasicObjectTypeName( SbxObject* pObj )
1710cdf0e10cSrcweir {
1711cdf0e10cSrcweir 	String aName;
1712cdf0e10cSrcweir 	if( pObj )
1713cdf0e10cSrcweir 	{
1714cdf0e10cSrcweir 		SbUnoObject* pUnoObj = PTR_CAST(SbUnoObject,pObj);
1715cdf0e10cSrcweir 		if( pUnoObj )
1716cdf0e10cSrcweir 			aName = getDbgObjectNameImpl( pUnoObj );
1717cdf0e10cSrcweir 	}
1718cdf0e10cSrcweir 	return aName;
1719cdf0e10cSrcweir }
1720cdf0e10cSrcweir 
checkUnoObjectType(SbUnoObject * pUnoObj,const::rtl::OUString & rClass)1721cdf0e10cSrcweir bool checkUnoObjectType( SbUnoObject* pUnoObj, const ::rtl::OUString& rClass )
1722cdf0e10cSrcweir {
1723cdf0e10cSrcweir 	Any aToInspectObj = pUnoObj->getUnoAny();
1724cdf0e10cSrcweir 	TypeClass eType = aToInspectObj.getValueType().getTypeClass();
1725cdf0e10cSrcweir 	if( eType != TypeClass_INTERFACE )
1726cdf0e10cSrcweir 		return false;
1727cdf0e10cSrcweir 	const Reference< XInterface > x = *(Reference< XInterface >*)aToInspectObj.getValue();
1728cdf0e10cSrcweir 
1729cdf0e10cSrcweir 	// Return true for XInvocation based objects as interface type names don't count then
1730cdf0e10cSrcweir 	Reference< XInvocation > xInvocation( x, UNO_QUERY );
1731cdf0e10cSrcweir 	if( xInvocation.is() )
1732cdf0e10cSrcweir 		return true;
1733cdf0e10cSrcweir 
1734cdf0e10cSrcweir 	bool result = false;
1735cdf0e10cSrcweir 	Reference< XTypeProvider > xTypeProvider( x, UNO_QUERY );
1736cdf0e10cSrcweir 	if( xTypeProvider.is() )
1737cdf0e10cSrcweir 	{
1738cdf0e10cSrcweir         /*  Although interfaces in the ooo.vba namespace obey the IDL rules and
1739cdf0e10cSrcweir             have a leading 'X', in Basic we want to be able to do something
1740cdf0e10cSrcweir             like 'Dim wb As Workbooks' or 'Dim lb As MSForms.Label'. Here we
1741cdf0e10cSrcweir             add a leading 'X' to the class name and a leading dot to the entire
1742cdf0e10cSrcweir             type name. This results e.g. in '.XWorkbooks' or '.MSForms.XLabel'
1743cdf0e10cSrcweir             which matches the interface names 'ooo.vba.excel.XWorkbooks' or
1744cdf0e10cSrcweir             'ooo.vba.msforms.XLabel'.
1745cdf0e10cSrcweir          */
1746cdf0e10cSrcweir         ::rtl::OUString aClassName( sal_Unicode( '.' ) );
1747cdf0e10cSrcweir         sal_Int32 nClassNameDot = rClass.lastIndexOf( '.' );
1748cdf0e10cSrcweir         if( nClassNameDot >= 0 )
1749cdf0e10cSrcweir             aClassName += rClass.copy( 0, nClassNameDot + 1 ) + ::rtl::OUString( sal_Unicode( 'X' ) ) + rClass.copy( nClassNameDot + 1 );
1750cdf0e10cSrcweir         else
1751cdf0e10cSrcweir             aClassName += ::rtl::OUString( sal_Unicode( 'X' ) ) + rClass;
1752cdf0e10cSrcweir 
1753cdf0e10cSrcweir 		Sequence< Type > aTypeSeq = xTypeProvider->getTypes();
1754cdf0e10cSrcweir 		const Type* pTypeArray = aTypeSeq.getConstArray();
1755cdf0e10cSrcweir 		sal_uInt32 nIfaceCount = aTypeSeq.getLength();
1756cdf0e10cSrcweir 		for( sal_uInt32 j = 0 ; j < nIfaceCount ; j++ )
1757cdf0e10cSrcweir 		{
1758cdf0e10cSrcweir 			const Type& rType = pTypeArray[j];
1759cdf0e10cSrcweir 
1760cdf0e10cSrcweir 			Reference<XIdlClass> xClass = TypeToIdlClass( rType );
1761cdf0e10cSrcweir 			if( !xClass.is() )
1762cdf0e10cSrcweir 			{
1763cdf0e10cSrcweir 				DBG_ERROR("failed to get XIdlClass for type");
1764cdf0e10cSrcweir 				break;
1765cdf0e10cSrcweir 			}
1766cdf0e10cSrcweir 			::rtl::OUString aInterfaceName = xClass->getName();
1767cdf0e10cSrcweir 			if ( aInterfaceName.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.XAutomationObject" ) ) ) )
1768cdf0e10cSrcweir 			{
1769cdf0e10cSrcweir 				// there is a hack in the extensions/source/ole/oleobj.cxx  to return the typename of the automation object, lets check if it
1770cdf0e10cSrcweir 				// matches
1771cdf0e10cSrcweir 				Reference< XInvocation > xInv( aToInspectObj, UNO_QUERY );
1772cdf0e10cSrcweir 				if ( xInv.is() )
1773cdf0e10cSrcweir 				{
1774cdf0e10cSrcweir 					rtl::OUString sTypeName;
1775cdf0e10cSrcweir 					xInv->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("$GetTypeName") ) ) >>= sTypeName;
1776*0848378bSHerbert Dürr 					if ( sTypeName.isEmpty() || sTypeName.equals(  rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IDispatch") ) ) )
1777cdf0e10cSrcweir 						// can't check type, leave it pass
1778cdf0e10cSrcweir 						result = true;
1779cdf0e10cSrcweir 					else
1780cdf0e10cSrcweir 						result = sTypeName.equals( rClass );
1781cdf0e10cSrcweir 				}
1782cdf0e10cSrcweir 				break; // finished checking automation object
1783cdf0e10cSrcweir 			}
1784cdf0e10cSrcweir 
1785cdf0e10cSrcweir             // match interface name with passed class name
1786cdf0e10cSrcweir 			OSL_TRACE("Checking if object implements %s", OUStringToOString( aClassName, RTL_TEXTENCODING_UTF8 ).getStr() );
1787cdf0e10cSrcweir 			if ( (aClassName.getLength() < aInterfaceName.getLength()) &&
1788cdf0e10cSrcweir                     aInterfaceName.matchIgnoreAsciiCase( aClassName, aInterfaceName.getLength() - aClassName.getLength() ) )
1789cdf0e10cSrcweir 			{
1790cdf0e10cSrcweir 				result = true;
1791cdf0e10cSrcweir 				break;
1792cdf0e10cSrcweir 			}
1793cdf0e10cSrcweir 		}
1794cdf0e10cSrcweir 	}
1795cdf0e10cSrcweir 	return result;
1796cdf0e10cSrcweir }
1797cdf0e10cSrcweir 
1798cdf0e10cSrcweir // Dbg-Hilfsmethode zum Auslesen der in einem Object implementierten Interfaces
Impl_GetSupportedInterfaces(SbUnoObject * pUnoObj)1799cdf0e10cSrcweir String Impl_GetSupportedInterfaces( SbUnoObject* pUnoObj )
1800cdf0e10cSrcweir {
1801cdf0e10cSrcweir 	Any aToInspectObj = pUnoObj->getUnoAny();
1802cdf0e10cSrcweir 
1803cdf0e10cSrcweir 	// #54898: Nur TypeClass Interface zulasssen
1804cdf0e10cSrcweir 	TypeClass eType = aToInspectObj.getValueType().getTypeClass();
1805cdf0e10cSrcweir 	String aRet;
1806cdf0e10cSrcweir 	if( eType != TypeClass_INTERFACE )
1807cdf0e10cSrcweir 	{
1808cdf0e10cSrcweir 		aRet.AppendAscii( RTL_CONSTASCII_STRINGPARAM(ID_DBG_SUPPORTEDINTERFACES) );
1809cdf0e10cSrcweir 		aRet.AppendAscii( " not available.\n(TypeClass is not TypeClass_INTERFACE)\n" );
1810cdf0e10cSrcweir 	}
1811cdf0e10cSrcweir 	else
1812cdf0e10cSrcweir 	{
1813cdf0e10cSrcweir 		// Interface aus dem Any besorgen
1814cdf0e10cSrcweir 		const Reference< XInterface > x = *(Reference< XInterface >*)aToInspectObj.getValue();
1815cdf0e10cSrcweir 
1816cdf0e10cSrcweir 		// XIdlClassProvider-Interface ansprechen
1817cdf0e10cSrcweir 		Reference< XIdlClassProvider > xClassProvider( x, UNO_QUERY );
1818cdf0e10cSrcweir 		Reference< XTypeProvider > xTypeProvider( x, UNO_QUERY );
1819cdf0e10cSrcweir 
1820cdf0e10cSrcweir 		aRet.AssignAscii( "Supported interfaces by object " );
1821cdf0e10cSrcweir 		String aObjName = getDbgObjectName( pUnoObj );
1822cdf0e10cSrcweir 		aRet += aObjName;
1823cdf0e10cSrcweir 		aRet.AppendAscii( "\n" );
1824cdf0e10cSrcweir 		if( xTypeProvider.is() )
1825cdf0e10cSrcweir 		{
1826cdf0e10cSrcweir 			// Interfaces der Implementation holen
1827cdf0e10cSrcweir 			Sequence< Type > aTypeSeq = xTypeProvider->getTypes();
1828cdf0e10cSrcweir 			const Type* pTypeArray = aTypeSeq.getConstArray();
1829cdf0e10cSrcweir 			sal_uInt32 nIfaceCount = aTypeSeq.getLength();
1830cdf0e10cSrcweir 			for( sal_uInt32 j = 0 ; j < nIfaceCount ; j++ )
1831cdf0e10cSrcweir 			{
1832cdf0e10cSrcweir 				const Type& rType = pTypeArray[j];
1833cdf0e10cSrcweir 
1834cdf0e10cSrcweir                 Reference<XIdlClass> xClass = TypeToIdlClass( rType );
1835cdf0e10cSrcweir                 if( xClass.is() )
1836cdf0e10cSrcweir                 {
1837cdf0e10cSrcweir 				    aRet += Impl_GetInterfaceInfo( x, xClass, 1 );
1838cdf0e10cSrcweir                 }
1839cdf0e10cSrcweir                 else
1840cdf0e10cSrcweir                 {
1841cdf0e10cSrcweir 	                typelib_TypeDescription * pTD = 0;
1842cdf0e10cSrcweir 	                rType.getDescription( &pTD );
1843cdf0e10cSrcweir 	                String TypeName( ::rtl::OUString( pTD->pTypeName ) );
1844cdf0e10cSrcweir 
1845cdf0e10cSrcweir                     aRet.AppendAscii( "*** ERROR: No IdlClass for type \"" );
1846cdf0e10cSrcweir                     aRet += TypeName;
1847cdf0e10cSrcweir                     aRet.AppendAscii( "\"\n*** Please check type library\n" );
1848cdf0e10cSrcweir                 }
1849cdf0e10cSrcweir 			}
1850cdf0e10cSrcweir 		}
1851cdf0e10cSrcweir 		else if( xClassProvider.is() )
1852cdf0e10cSrcweir 		{
1853cdf0e10cSrcweir 
1854cdf0e10cSrcweir 			DBG_ERROR( "XClassProvider not supported in UNO3" );
1855cdf0e10cSrcweir 		}
1856cdf0e10cSrcweir 	}
1857cdf0e10cSrcweir 	return aRet;
1858cdf0e10cSrcweir }
1859cdf0e10cSrcweir 
1860cdf0e10cSrcweir 
1861cdf0e10cSrcweir 
1862cdf0e10cSrcweir // Dbg-Hilfsmethode SbxDataType -> String
Dbg_SbxDataType2String(SbxDataType eType)1863cdf0e10cSrcweir String Dbg_SbxDataType2String( SbxDataType eType )
1864cdf0e10cSrcweir {
1865cdf0e10cSrcweir 	String aRet( RTL_CONSTASCII_USTRINGPARAM("Unknown Sbx-Type!") );
1866cdf0e10cSrcweir 	switch( +eType )
1867cdf0e10cSrcweir 	{
1868cdf0e10cSrcweir 		case SbxEMPTY:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxEMPTY") ); break;
1869cdf0e10cSrcweir 		case SbxNULL:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxNULL") ); break;
1870cdf0e10cSrcweir 		case SbxINTEGER:	aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxINTEGER") ); break;
1871cdf0e10cSrcweir 		case SbxLONG:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxLONG") ); break;
1872cdf0e10cSrcweir 		case SbxSINGLE:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxSINGLE") ); break;
1873cdf0e10cSrcweir 		case SbxDOUBLE:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxDOUBLE") ); break;
1874cdf0e10cSrcweir 		case SbxCURRENCY:	aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxCURRENCY") ); break;
1875cdf0e10cSrcweir 		case SbxDECIMAL:	aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxDECIMAL") ); break;
1876cdf0e10cSrcweir 		case SbxDATE:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxDATE") ); break;
1877cdf0e10cSrcweir 		case SbxSTRING:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxSTRING") ); break;
1878cdf0e10cSrcweir 		case SbxOBJECT:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxOBJECT") ); break;
1879cdf0e10cSrcweir 		case SbxERROR:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxERROR") ); break;
1880cdf0e10cSrcweir 		case SbxBOOL:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxBOOL") ); break;
1881cdf0e10cSrcweir 		case SbxVARIANT:	aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxVARIANT") ); break;
1882cdf0e10cSrcweir 		case SbxDATAOBJECT: aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxDATAOBJECT") ); break;
1883cdf0e10cSrcweir 		case SbxCHAR:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxCHAR") ); break;
1884cdf0e10cSrcweir 		case SbxBYTE:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxBYTE") ); break;
1885cdf0e10cSrcweir 		case SbxUSHORT:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxUSHORT") ); break;
1886cdf0e10cSrcweir 		case SbxULONG:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxULONG") ); break;
1887cdf0e10cSrcweir 		case SbxLONG64:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxLONG64") ); break;
1888cdf0e10cSrcweir 		case SbxULONG64:	aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxULONG64") ); break;
1889cdf0e10cSrcweir 		case SbxSALINT64:	aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxINT64") ); break;
1890cdf0e10cSrcweir 		case SbxSALUINT64:	aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxUINT64") ); break;
1891cdf0e10cSrcweir 		case SbxINT:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxINT") ); break;
1892cdf0e10cSrcweir 		case SbxUINT:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxUINT") ); break;
1893cdf0e10cSrcweir 		case SbxVOID:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxVOID") ); break;
1894cdf0e10cSrcweir 		case SbxHRESULT:	aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxHRESULT") ); break;
1895cdf0e10cSrcweir 		case SbxPOINTER:	aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxPOINTER") ); break;
1896cdf0e10cSrcweir 		case SbxDIMARRAY:	aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxDIMARRAY") ); break;
1897cdf0e10cSrcweir 		case SbxCARRAY:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxCARRAY") ); break;
1898cdf0e10cSrcweir 		case SbxUSERDEF:	aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxUSERDEF") ); break;
1899cdf0e10cSrcweir 		case SbxLPSTR:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxLPSTR") ); break;
1900cdf0e10cSrcweir 		case SbxLPWSTR:		aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxLPWSTR") ); break;
1901cdf0e10cSrcweir 		case SbxCoreSTRING: aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxCoreSTRING" ) ); break;
1902cdf0e10cSrcweir 		case SbxOBJECT | SbxARRAY: aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxARRAY") ); break;
1903cdf0e10cSrcweir 		default: break;
1904cdf0e10cSrcweir 	}
1905cdf0e10cSrcweir 	return aRet;
1906cdf0e10cSrcweir }
1907cdf0e10cSrcweir 
1908cdf0e10cSrcweir // Dbg-Hilfsmethode zum Anzeigen der Properties eines SbUnoObjects
Impl_DumpProperties(SbUnoObject * pUnoObj)1909cdf0e10cSrcweir String Impl_DumpProperties( SbUnoObject* pUnoObj )
1910cdf0e10cSrcweir {
1911cdf0e10cSrcweir 	String aRet( RTL_CONSTASCII_USTRINGPARAM("Properties of object ") );
1912cdf0e10cSrcweir 	String aObjName = getDbgObjectName( pUnoObj );
1913cdf0e10cSrcweir 	aRet += aObjName;
1914cdf0e10cSrcweir 
1915cdf0e10cSrcweir 	// Uno-Infos auswerten, um Arrays zu erkennen
1916cdf0e10cSrcweir 	Reference< XIntrospectionAccess > xAccess = pUnoObj->getIntrospectionAccess();
1917cdf0e10cSrcweir 	if( !xAccess.is() )
1918cdf0e10cSrcweir 	{
1919cdf0e10cSrcweir 		Reference< XInvocation > xInvok = pUnoObj->getInvocation();
1920cdf0e10cSrcweir 		if( xInvok.is() )
1921cdf0e10cSrcweir 			xAccess = xInvok->getIntrospection();
1922cdf0e10cSrcweir 	}
1923cdf0e10cSrcweir 	if( !xAccess.is() )
1924cdf0e10cSrcweir 	{
1925cdf0e10cSrcweir 		aRet.AppendAscii( "\nUnknown, no introspection available\n" );
1926cdf0e10cSrcweir 		return aRet;
1927cdf0e10cSrcweir 	}
1928cdf0e10cSrcweir 
1929cdf0e10cSrcweir 	Sequence<Property> props = xAccess->getProperties( PropertyConcept::ALL - PropertyConcept::DANGEROUS );
1930cdf0e10cSrcweir 	sal_uInt32 nUnoPropCount = props.getLength();
1931cdf0e10cSrcweir 	const Property* pUnoProps = props.getConstArray();
1932cdf0e10cSrcweir 
1933cdf0e10cSrcweir 	SbxArray* pProps = pUnoObj->GetProperties();
1934cdf0e10cSrcweir 	sal_uInt16 nPropCount = pProps->Count();
1935cdf0e10cSrcweir 	sal_uInt16 nPropsPerLine = 1 + nPropCount / 30;
1936cdf0e10cSrcweir 	for( sal_uInt16 i = 0; i < nPropCount; i++ )
1937cdf0e10cSrcweir 	{
1938cdf0e10cSrcweir 		SbxVariable* pVar = pProps->Get( i );
1939cdf0e10cSrcweir 		if( pVar )
1940cdf0e10cSrcweir 		{
1941cdf0e10cSrcweir 			String aPropStr;
1942cdf0e10cSrcweir 			if( (i % nPropsPerLine) == 0 )
1943cdf0e10cSrcweir 				aPropStr.AppendAscii( "\n" );
1944cdf0e10cSrcweir 
1945cdf0e10cSrcweir 			// Typ und Namen ausgeben
1946cdf0e10cSrcweir 			// Ist es in Uno eine Sequence?
1947cdf0e10cSrcweir 			SbxDataType eType = pVar->GetFullType();
1948cdf0e10cSrcweir 
1949cdf0e10cSrcweir 			sal_Bool bMaybeVoid = sal_False;
1950cdf0e10cSrcweir 			if( i < nUnoPropCount )
1951cdf0e10cSrcweir 			{
1952cdf0e10cSrcweir 				const Property& rProp = pUnoProps[ i ];
1953cdf0e10cSrcweir 
1954cdf0e10cSrcweir 				// #63133: Bei MAYBEVOID Typ aus Uno neu konvertieren,
1955cdf0e10cSrcweir 				// damit nicht immer nur SbxEMPTY ausgegben wird.
1956cdf0e10cSrcweir 				if( rProp.Attributes & PropertyAttribute::MAYBEVOID )
1957cdf0e10cSrcweir 				{
1958cdf0e10cSrcweir 					eType = unoToSbxType( rProp.Type.getTypeClass() );
1959cdf0e10cSrcweir 					bMaybeVoid = sal_True;
1960cdf0e10cSrcweir 				}
1961cdf0e10cSrcweir 				if( eType == SbxOBJECT )
1962cdf0e10cSrcweir 				{
1963cdf0e10cSrcweir 					Type aType = rProp.Type;
1964cdf0e10cSrcweir 					if( aType.getTypeClass() == TypeClass_SEQUENCE )
1965cdf0e10cSrcweir 						eType = (SbxDataType) ( SbxOBJECT | SbxARRAY );
1966cdf0e10cSrcweir 				}
1967cdf0e10cSrcweir 			}
1968cdf0e10cSrcweir 			aPropStr += Dbg_SbxDataType2String( eType );
1969cdf0e10cSrcweir 			if( bMaybeVoid )
1970cdf0e10cSrcweir 				aPropStr.AppendAscii( "/void" );
1971cdf0e10cSrcweir 			aPropStr.AppendAscii( " " );
1972cdf0e10cSrcweir 			aPropStr += pVar->GetName();
1973cdf0e10cSrcweir 
1974cdf0e10cSrcweir 			if( i == nPropCount - 1 )
1975cdf0e10cSrcweir 				aPropStr.AppendAscii( "\n" );
1976cdf0e10cSrcweir 			else
1977cdf0e10cSrcweir 				aPropStr.AppendAscii( "; " );
1978cdf0e10cSrcweir 
1979cdf0e10cSrcweir 			aRet += aPropStr;
1980cdf0e10cSrcweir 		}
1981cdf0e10cSrcweir 	}
1982cdf0e10cSrcweir 	return aRet;
1983cdf0e10cSrcweir }
1984cdf0e10cSrcweir 
1985cdf0e10cSrcweir // Dbg-Hilfsmethode zum Anzeigen der Methoden eines SbUnoObjects
Impl_DumpMethods(SbUnoObject * pUnoObj)1986cdf0e10cSrcweir String Impl_DumpMethods( SbUnoObject* pUnoObj )
1987cdf0e10cSrcweir {
1988cdf0e10cSrcweir 	String aRet( RTL_CONSTASCII_USTRINGPARAM("Methods of object ") );
1989cdf0e10cSrcweir 	String aObjName = getDbgObjectName( pUnoObj );
1990cdf0e10cSrcweir 	aRet += aObjName;
1991cdf0e10cSrcweir 
1992cdf0e10cSrcweir 	// XIntrospectionAccess, um die Typen der Parameter auch ausgeben zu koennen
1993cdf0e10cSrcweir 	Reference< XIntrospectionAccess > xAccess = pUnoObj->getIntrospectionAccess();
1994cdf0e10cSrcweir 	if( !xAccess.is() )
1995cdf0e10cSrcweir 	{
1996cdf0e10cSrcweir 		Reference< XInvocation > xInvok = pUnoObj->getInvocation();
1997cdf0e10cSrcweir 		if( xInvok.is() )
1998cdf0e10cSrcweir 			xAccess = xInvok->getIntrospection();
1999cdf0e10cSrcweir 	}
2000cdf0e10cSrcweir 	if( !xAccess.is() )
2001cdf0e10cSrcweir 	{
2002cdf0e10cSrcweir 		aRet.AppendAscii( "\nUnknown, no introspection available\n" );
2003cdf0e10cSrcweir 		return aRet;
2004cdf0e10cSrcweir 	}
2005cdf0e10cSrcweir 	Sequence< Reference< XIdlMethod > > methods = xAccess->getMethods
2006cdf0e10cSrcweir 		( MethodConcept::ALL - MethodConcept::DANGEROUS );
2007cdf0e10cSrcweir 	const Reference< XIdlMethod >* pUnoMethods = methods.getConstArray();
2008cdf0e10cSrcweir 
2009cdf0e10cSrcweir 	SbxArray* pMethods = pUnoObj->GetMethods();
2010cdf0e10cSrcweir 	sal_uInt16 nMethodCount = pMethods->Count();
2011cdf0e10cSrcweir 	if( !nMethodCount )
2012cdf0e10cSrcweir 	{
2013cdf0e10cSrcweir 		aRet.AppendAscii( "\nNo methods found\n" );
2014cdf0e10cSrcweir 		return aRet;
2015cdf0e10cSrcweir 	}
2016cdf0e10cSrcweir 	sal_uInt16 nPropsPerLine = 1 + nMethodCount / 30;
2017cdf0e10cSrcweir 	for( sal_uInt16 i = 0; i < nMethodCount; i++ )
2018cdf0e10cSrcweir 	{
2019cdf0e10cSrcweir 		SbxVariable* pVar = pMethods->Get( i );
2020cdf0e10cSrcweir 		if( pVar )
2021cdf0e10cSrcweir 		{
2022cdf0e10cSrcweir 			String aPropStr;
2023cdf0e10cSrcweir 			if( (i % nPropsPerLine) == 0 )
2024cdf0e10cSrcweir 				aPropStr.AppendAscii( "\n" );
2025cdf0e10cSrcweir 
2026cdf0e10cSrcweir 			// Methode ansprechen
2027cdf0e10cSrcweir 			const Reference< XIdlMethod >& rxMethod = pUnoMethods[i];
2028cdf0e10cSrcweir 
2029cdf0e10cSrcweir 			// Ist es in Uno eine Sequence?
2030cdf0e10cSrcweir 			SbxDataType eType = pVar->GetFullType();
2031cdf0e10cSrcweir 			if( eType == SbxOBJECT )
2032cdf0e10cSrcweir 			{
2033cdf0e10cSrcweir 				Reference< XIdlClass > xClass = rxMethod->getReturnType();
2034cdf0e10cSrcweir 				if( xClass.is() && xClass->getTypeClass() == TypeClass_SEQUENCE )
2035cdf0e10cSrcweir 					eType = (SbxDataType) ( SbxOBJECT | SbxARRAY );
2036cdf0e10cSrcweir 			}
2037cdf0e10cSrcweir 			// Name und Typ ausgeben
2038cdf0e10cSrcweir 			aPropStr += Dbg_SbxDataType2String( eType );
2039cdf0e10cSrcweir 			aPropStr.AppendAscii( " " );
2040cdf0e10cSrcweir 			aPropStr += pVar->GetName();
2041cdf0e10cSrcweir 			aPropStr.AppendAscii( " ( " );
2042cdf0e10cSrcweir 
2043cdf0e10cSrcweir 			// get-Methode darf keinen Parameter haben
2044cdf0e10cSrcweir 			Sequence< Reference< XIdlClass > > aParamsSeq = rxMethod->getParameterTypes();
2045cdf0e10cSrcweir 			sal_uInt32 nParamCount = aParamsSeq.getLength();
2046cdf0e10cSrcweir 			const Reference< XIdlClass >* pParams = aParamsSeq.getConstArray();
2047cdf0e10cSrcweir 
2048cdf0e10cSrcweir 			if( nParamCount > 0 )
2049cdf0e10cSrcweir 			{
2050cdf0e10cSrcweir 				for( sal_uInt16 j = 0; j < nParamCount; j++ )
2051cdf0e10cSrcweir 				{
2052cdf0e10cSrcweir 					String aTypeStr = Dbg_SbxDataType2String( unoToSbxType( pParams[ j ] ) );
2053cdf0e10cSrcweir 					aPropStr += aTypeStr;
2054cdf0e10cSrcweir 
2055cdf0e10cSrcweir 					if( j < nParamCount - 1 )
2056cdf0e10cSrcweir 						aPropStr.AppendAscii( ", " );
2057cdf0e10cSrcweir 				}
2058cdf0e10cSrcweir 			}
2059cdf0e10cSrcweir 			else
2060cdf0e10cSrcweir 				aPropStr.AppendAscii( "void" );
2061cdf0e10cSrcweir 
2062cdf0e10cSrcweir 			aPropStr.AppendAscii( " ) " );
2063cdf0e10cSrcweir 
2064cdf0e10cSrcweir 			if( i == nMethodCount - 1 )
2065cdf0e10cSrcweir 				aPropStr.AppendAscii( "\n" );
2066cdf0e10cSrcweir 			else
2067cdf0e10cSrcweir 				aPropStr.AppendAscii( "; " );
2068cdf0e10cSrcweir 
2069cdf0e10cSrcweir 			aRet += aPropStr;
2070cdf0e10cSrcweir 		}
2071cdf0e10cSrcweir 	}
2072cdf0e10cSrcweir 	return aRet;
2073cdf0e10cSrcweir }
2074cdf0e10cSrcweir 
TYPEINIT1(AutomationNamedArgsSbxArray,SbxArray)2075cdf0e10cSrcweir TYPEINIT1(AutomationNamedArgsSbxArray,SbxArray)
2076cdf0e10cSrcweir 
2077cdf0e10cSrcweir // Implementation SbUnoObject
2078cdf0e10cSrcweir void SbUnoObject::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
2079cdf0e10cSrcweir 						   const SfxHint& rHint, const TypeId& rHintType )
2080cdf0e10cSrcweir {
2081cdf0e10cSrcweir 	if( bNeedIntrospection )
2082cdf0e10cSrcweir 		doIntrospection();
2083cdf0e10cSrcweir 
2084cdf0e10cSrcweir 	const SbxHint* pHint = PTR_CAST(SbxHint,&rHint);
2085cdf0e10cSrcweir 	if( pHint )
2086cdf0e10cSrcweir 	{
2087cdf0e10cSrcweir 		SbxVariable* pVar = pHint->GetVar();
2088cdf0e10cSrcweir 		SbxArray* pParams = pVar->GetParameters();
2089cdf0e10cSrcweir 		SbUnoProperty* pProp = PTR_CAST(SbUnoProperty,pVar);
2090cdf0e10cSrcweir 		SbUnoMethod* pMeth = PTR_CAST(SbUnoMethod,pVar);
2091cdf0e10cSrcweir 		if( pProp )
2092cdf0e10cSrcweir 		{
2093cdf0e10cSrcweir 			bool bInvocation = pProp->isInvocationBased();
2094cdf0e10cSrcweir 			if( pHint->GetId() == SBX_HINT_DATAWANTED )
2095cdf0e10cSrcweir 			{
2096cdf0e10cSrcweir 				// Test-Properties
2097cdf0e10cSrcweir 				sal_Int32 nId = pProp->nId;
2098cdf0e10cSrcweir 				if( nId < 0 )
2099cdf0e10cSrcweir 				{
2100cdf0e10cSrcweir 					// Id == -1: Implementierte Interfaces gemaess ClassProvider anzeigen
2101cdf0e10cSrcweir 					if( nId == -1 )		// Property ID_DBG_SUPPORTEDINTERFACES"
2102cdf0e10cSrcweir 					{
2103cdf0e10cSrcweir 						String aRetStr = Impl_GetSupportedInterfaces( this );
2104cdf0e10cSrcweir 						pVar->PutString( aRetStr );
2105cdf0e10cSrcweir 					}
2106cdf0e10cSrcweir 					// Id == -2: Properties ausgeben
2107cdf0e10cSrcweir 					else if( nId == -2 )		// Property ID_DBG_PROPERTIES
2108cdf0e10cSrcweir 					{
2109cdf0e10cSrcweir 						// Jetzt muessen alle Properties angelegt werden
2110cdf0e10cSrcweir 						implCreateAll();
2111cdf0e10cSrcweir 						String aRetStr = Impl_DumpProperties( this );
2112cdf0e10cSrcweir 						pVar->PutString( aRetStr );
2113cdf0e10cSrcweir 					}
2114cdf0e10cSrcweir 					// Id == -3: Methoden ausgeben
2115cdf0e10cSrcweir 					else if( nId == -3 )		// Property ID_DBG_METHODS
2116cdf0e10cSrcweir 					{
2117cdf0e10cSrcweir 						// Jetzt muessen alle Properties angelegt werden
2118cdf0e10cSrcweir 						implCreateAll();
2119cdf0e10cSrcweir 						String aRetStr = Impl_DumpMethods( this );
2120cdf0e10cSrcweir 						pVar->PutString( aRetStr );
2121cdf0e10cSrcweir 					}
2122cdf0e10cSrcweir 					return;
2123cdf0e10cSrcweir 				}
2124cdf0e10cSrcweir 
2125cdf0e10cSrcweir 				if( !bInvocation && mxUnoAccess.is() )
2126cdf0e10cSrcweir 				{
2127cdf0e10cSrcweir 					try
2128cdf0e10cSrcweir 					{
2129cdf0e10cSrcweir 						// Wert holen
2130cdf0e10cSrcweir 						Reference< XPropertySet > xPropSet( mxUnoAccess->queryAdapter( ::getCppuType( (const Reference< XPropertySet > *)0 ) ), UNO_QUERY );
2131cdf0e10cSrcweir 						Any aRetAny = xPropSet->getPropertyValue( pProp->GetName() );
2132cdf0e10cSrcweir 						// Die Nutzung von getPropertyValue (statt ueber den Index zu gehen) ist
2133cdf0e10cSrcweir 						// nicht optimal, aber die Umstellung auf XInvocation steht ja ohnehin an
2134cdf0e10cSrcweir 						// Ansonsten kann auch FastPropertySet genutzt werden
2135cdf0e10cSrcweir 
2136cdf0e10cSrcweir 						// Wert von Uno nach Sbx uebernehmen
2137cdf0e10cSrcweir 						unoToSbxValue( pVar, aRetAny );
2138cdf0e10cSrcweir 					}
2139cdf0e10cSrcweir 					catch( const Exception& )
2140cdf0e10cSrcweir 					{
2141cdf0e10cSrcweir                         implHandleAnyException( ::cppu::getCaughtException() );
2142cdf0e10cSrcweir 					}
2143cdf0e10cSrcweir 				}
2144cdf0e10cSrcweir 				else if( bInvocation && mxInvocation.is() )
2145cdf0e10cSrcweir 				{
2146cdf0e10cSrcweir 					try
2147cdf0e10cSrcweir 					{
2148cdf0e10cSrcweir 						// Wert holen
2149cdf0e10cSrcweir 						Any aRetAny = mxInvocation->getValue( pProp->GetName() );
2150cdf0e10cSrcweir 
2151cdf0e10cSrcweir 						// Wert von Uno nach Sbx uebernehmen
2152cdf0e10cSrcweir 						unoToSbxValue( pVar, aRetAny );
2153cdf0e10cSrcweir 					}
2154cdf0e10cSrcweir 					catch( const Exception& )
2155cdf0e10cSrcweir 					{
2156cdf0e10cSrcweir                         implHandleAnyException( ::cppu::getCaughtException() );
2157cdf0e10cSrcweir 					}
2158cdf0e10cSrcweir 				}
2159cdf0e10cSrcweir 			}
2160cdf0e10cSrcweir 			else if( pHint->GetId() == SBX_HINT_DATACHANGED )
2161cdf0e10cSrcweir 			{
2162cdf0e10cSrcweir 				if( !bInvocation && mxUnoAccess.is() )
2163cdf0e10cSrcweir 				{
2164cdf0e10cSrcweir 					if( pProp->aUnoProp.Attributes & PropertyAttribute::READONLY )
2165cdf0e10cSrcweir 					{
2166cdf0e10cSrcweir 						StarBASIC::Error( SbERR_PROP_READONLY );
2167cdf0e10cSrcweir 						return;
2168cdf0e10cSrcweir 					}
2169cdf0e10cSrcweir 
2170cdf0e10cSrcweir 					// Wert von Uno nach Sbx uebernehmen
2171cdf0e10cSrcweir 					Any aAnyValue = sbxToUnoValue( pVar, pProp->aUnoProp.Type, &pProp->aUnoProp );
2172cdf0e10cSrcweir 					try
2173cdf0e10cSrcweir 					{
2174cdf0e10cSrcweir 						// Wert setzen
2175cdf0e10cSrcweir 						Reference< XPropertySet > xPropSet( mxUnoAccess->queryAdapter( ::getCppuType( (const Reference< XPropertySet > *)0 ) ), UNO_QUERY );
2176cdf0e10cSrcweir 						xPropSet->setPropertyValue( pProp->GetName(), aAnyValue );
2177cdf0e10cSrcweir 						// Die Nutzung von getPropertyValue (statt ueber den Index zu gehen) ist
2178cdf0e10cSrcweir 						// nicht optimal, aber die Umstellung auf XInvocation steht ja ohnehin an
2179cdf0e10cSrcweir 						// Ansonsten kann auch FastPropertySet genutzt werden
2180cdf0e10cSrcweir 					}
2181cdf0e10cSrcweir 					catch( const Exception& )
2182cdf0e10cSrcweir 					{
2183cdf0e10cSrcweir                         implHandleAnyException( ::cppu::getCaughtException() );
2184cdf0e10cSrcweir 					}
2185cdf0e10cSrcweir 				}
2186cdf0e10cSrcweir 				else if( bInvocation && mxInvocation.is() )
2187cdf0e10cSrcweir 				{
2188cdf0e10cSrcweir 					// Wert von Uno nach Sbx uebernehmen
2189cdf0e10cSrcweir 					Any aAnyValue = sbxToUnoValueImpl( pVar );
2190cdf0e10cSrcweir 					try
2191cdf0e10cSrcweir 					{
2192cdf0e10cSrcweir 						// Wert setzen
2193cdf0e10cSrcweir 						mxInvocation->setValue( pProp->GetName(), aAnyValue );
2194cdf0e10cSrcweir 					}
2195cdf0e10cSrcweir 					catch( const Exception& )
2196cdf0e10cSrcweir 					{
2197cdf0e10cSrcweir                         implHandleAnyException( ::cppu::getCaughtException() );
2198cdf0e10cSrcweir 					}
2199cdf0e10cSrcweir 				}
2200cdf0e10cSrcweir 			}
2201cdf0e10cSrcweir 		}
2202cdf0e10cSrcweir 		else if( pMeth )
2203cdf0e10cSrcweir 		{
2204cdf0e10cSrcweir 			bool bInvocation = pMeth->isInvocationBased();
2205cdf0e10cSrcweir 			if( pHint->GetId() == SBX_HINT_DATAWANTED )
2206cdf0e10cSrcweir 			{
2207cdf0e10cSrcweir 				// Anzahl Parameter -1 wegen Param0 == this
2208cdf0e10cSrcweir 				sal_uInt32 nParamCount = pParams ? ((sal_uInt32)pParams->Count() - 1) : 0;
2209cdf0e10cSrcweir 				Sequence<Any> args;
2210cdf0e10cSrcweir 				sal_Bool bOutParams = sal_False;
2211cdf0e10cSrcweir 				sal_uInt32 i;
2212cdf0e10cSrcweir 
2213cdf0e10cSrcweir 				if( !bInvocation && mxUnoAccess.is() )
2214cdf0e10cSrcweir 				{
2215cdf0e10cSrcweir 					// Infos holen
2216cdf0e10cSrcweir 					const Sequence<ParamInfo>& rInfoSeq = pMeth->getParamInfos();
2217cdf0e10cSrcweir 					const ParamInfo* pParamInfos = rInfoSeq.getConstArray();
2218cdf0e10cSrcweir 					sal_uInt32 nUnoParamCount = rInfoSeq.getLength();
2219cdf0e10cSrcweir 					sal_uInt32 nAllocParamCount = nParamCount;
2220cdf0e10cSrcweir 
2221cdf0e10cSrcweir 					// Ueberschuessige Parameter ignorieren, Alternative: Error schmeissen
2222cdf0e10cSrcweir 					if( nParamCount > nUnoParamCount )
2223cdf0e10cSrcweir 					{
2224cdf0e10cSrcweir 						nParamCount = nUnoParamCount;
2225cdf0e10cSrcweir 						nAllocParamCount = nParamCount;
2226cdf0e10cSrcweir 					}
2227cdf0e10cSrcweir 					else if( nParamCount < nUnoParamCount )
2228cdf0e10cSrcweir 					{
2229cdf0e10cSrcweir 						SbiInstance* pInst = pINST;
2230cdf0e10cSrcweir 						if( pInst && pInst->IsCompatibility() )
2231cdf0e10cSrcweir 						{
2232cdf0e10cSrcweir 							// Check types
2233cdf0e10cSrcweir 							bool bError = false;
2234cdf0e10cSrcweir 							for( i = nParamCount ; i < nUnoParamCount ; i++ )
2235cdf0e10cSrcweir 							{
2236cdf0e10cSrcweir 								const ParamInfo& rInfo = pParamInfos[i];
2237cdf0e10cSrcweir 								const Reference< XIdlClass >& rxClass = rInfo.aType;
2238cdf0e10cSrcweir 								if( rxClass->getTypeClass() != TypeClass_ANY )
2239cdf0e10cSrcweir 								{
2240cdf0e10cSrcweir 									bError = true;
2241cdf0e10cSrcweir 									StarBASIC::Error( SbERR_NOT_OPTIONAL );
2242cdf0e10cSrcweir 								}
2243cdf0e10cSrcweir 							}
2244cdf0e10cSrcweir 							if( !bError )
2245cdf0e10cSrcweir 								nAllocParamCount = nUnoParamCount;
2246cdf0e10cSrcweir 						}
2247cdf0e10cSrcweir 					}
2248cdf0e10cSrcweir 
2249cdf0e10cSrcweir 					if( nAllocParamCount > 0 )
2250cdf0e10cSrcweir 					{
2251cdf0e10cSrcweir 						args.realloc( nAllocParamCount );
2252cdf0e10cSrcweir 						Any* pAnyArgs = args.getArray();
2253cdf0e10cSrcweir 						for( i = 0 ; i < nParamCount ; i++ )
2254cdf0e10cSrcweir 						{
2255cdf0e10cSrcweir 							const ParamInfo& rInfo = pParamInfos[i];
2256cdf0e10cSrcweir 							const Reference< XIdlClass >& rxClass = rInfo.aType;
2257cdf0e10cSrcweir 							//const XIdlClassRef& rxClass = pUnoParams[i];
2258cdf0e10cSrcweir 
2259cdf0e10cSrcweir 							com::sun::star::uno::Type aType( rxClass->getTypeClass(), rxClass->getName() );
2260cdf0e10cSrcweir 
2261cdf0e10cSrcweir 							// ACHTUNG: Bei den Sbx-Parametern den Offset nicht vergessen!
2262cdf0e10cSrcweir 							pAnyArgs[i] = sbxToUnoValue( pParams->Get( (sal_uInt16)(i+1) ), aType );
2263cdf0e10cSrcweir 
2264cdf0e10cSrcweir 							// Wenn es nicht schon feststeht pruefen, ob Out-Parameter vorliegen
2265cdf0e10cSrcweir 							if( !bOutParams )
2266cdf0e10cSrcweir 							{
2267cdf0e10cSrcweir 								ParamMode aParamMode = rInfo.aMode;
2268cdf0e10cSrcweir 								if( aParamMode != ParamMode_IN )
2269cdf0e10cSrcweir 									bOutParams = sal_True;
2270cdf0e10cSrcweir 							}
2271cdf0e10cSrcweir 						}
2272cdf0e10cSrcweir 					}
2273cdf0e10cSrcweir 				}
2274cdf0e10cSrcweir 				else if( bInvocation && pParams && mxInvocation.is() )
2275cdf0e10cSrcweir 				{
2276cdf0e10cSrcweir 					bool bOLEAutomation = true;
2277cdf0e10cSrcweir 					// TODO: bOLEAutomation = xOLEAutomation.is()
2278cdf0e10cSrcweir 
2279cdf0e10cSrcweir 					AutomationNamedArgsSbxArray* pArgNamesArray = NULL;
2280cdf0e10cSrcweir 					if( bOLEAutomation )
2281cdf0e10cSrcweir 						pArgNamesArray = PTR_CAST(AutomationNamedArgsSbxArray,pParams);
2282cdf0e10cSrcweir 
2283cdf0e10cSrcweir 					args.realloc( nParamCount );
2284cdf0e10cSrcweir 					Any* pAnyArgs = args.getArray();
2285cdf0e10cSrcweir 					bool bBlockConversionToSmallestType = pINST->IsCompatibility();
2286cdf0e10cSrcweir 					if( pArgNamesArray )
2287cdf0e10cSrcweir 					{
2288cdf0e10cSrcweir 						Sequence< ::rtl::OUString >& rNameSeq = pArgNamesArray->getNames();
2289cdf0e10cSrcweir 						::rtl::OUString* pNames = rNameSeq.getArray();
2290cdf0e10cSrcweir 
2291cdf0e10cSrcweir 						Any aValAny;
2292cdf0e10cSrcweir 						for( i = 0 ; i < nParamCount ; i++ )
2293cdf0e10cSrcweir 						{
2294cdf0e10cSrcweir 							sal_uInt16 iSbx = (sal_uInt16)(i+1);
2295cdf0e10cSrcweir 
2296cdf0e10cSrcweir 							// ACHTUNG: Bei den Sbx-Parametern den Offset nicht vergessen!
2297cdf0e10cSrcweir 							aValAny = sbxToUnoValueImpl( pParams->Get( iSbx ),
2298cdf0e10cSrcweir 														bBlockConversionToSmallestType );
2299cdf0e10cSrcweir 
2300cdf0e10cSrcweir 							::rtl::OUString aParamName = pNames[iSbx];
2301*0848378bSHerbert Dürr 							if( !aParamName.isEmpty() )
2302cdf0e10cSrcweir 							{
2303cdf0e10cSrcweir 								oleautomation::NamedArgument aNamedArgument;
2304cdf0e10cSrcweir 								aNamedArgument.Name = aParamName;
2305cdf0e10cSrcweir 								aNamedArgument.Value = aValAny;
2306cdf0e10cSrcweir 								pAnyArgs[i] <<= aNamedArgument;
2307cdf0e10cSrcweir 							}
2308cdf0e10cSrcweir 							else
2309cdf0e10cSrcweir 							{
2310cdf0e10cSrcweir 								pAnyArgs[i] = aValAny;
2311cdf0e10cSrcweir 							}
2312cdf0e10cSrcweir 						}
2313cdf0e10cSrcweir 					}
2314cdf0e10cSrcweir 					else
2315cdf0e10cSrcweir 					{
2316cdf0e10cSrcweir 						for( i = 0 ; i < nParamCount ; i++ )
2317cdf0e10cSrcweir 						{
2318cdf0e10cSrcweir 							// ACHTUNG: Bei den Sbx-Parametern den Offset nicht vergessen!
2319cdf0e10cSrcweir 							pAnyArgs[i] = sbxToUnoValueImpl( pParams->Get( (sal_uInt16)(i+1) ),
2320cdf0e10cSrcweir 															bBlockConversionToSmallestType );
2321cdf0e10cSrcweir 						}
2322cdf0e10cSrcweir 					}
2323cdf0e10cSrcweir 				}
2324cdf0e10cSrcweir 
2325cdf0e10cSrcweir 				// Methode callen
2326cdf0e10cSrcweir                 GetSbData()->bBlockCompilerError = sal_True;  // #106433 Block compiler errors for API calls
2327cdf0e10cSrcweir 				try
2328cdf0e10cSrcweir 				{
2329cdf0e10cSrcweir 					if( !bInvocation && mxUnoAccess.is() )
2330cdf0e10cSrcweir 					{
2331cdf0e10cSrcweir 						Any aRetAny = pMeth->m_xUnoMethod->invoke( getUnoAny(), args );
2332cdf0e10cSrcweir 
2333cdf0e10cSrcweir 						// Wert von Uno nach Sbx uebernehmen
2334cdf0e10cSrcweir 						unoToSbxValue( pVar, aRetAny );
2335cdf0e10cSrcweir 
2336cdf0e10cSrcweir 						// Muessen wir Out-Parameter zurueckkopieren?
2337cdf0e10cSrcweir 						if( bOutParams )
2338cdf0e10cSrcweir 						{
2339cdf0e10cSrcweir 							const Any* pAnyArgs = args.getConstArray();
2340cdf0e10cSrcweir 
2341cdf0e10cSrcweir 							// Infos holen
2342cdf0e10cSrcweir 							const Sequence<ParamInfo>& rInfoSeq = pMeth->getParamInfos();
2343cdf0e10cSrcweir 							const ParamInfo* pParamInfos = rInfoSeq.getConstArray();
2344cdf0e10cSrcweir 
2345cdf0e10cSrcweir 							sal_uInt32 j;
2346cdf0e10cSrcweir 							for( j = 0 ; j < nParamCount ; j++ )
2347cdf0e10cSrcweir 							{
2348cdf0e10cSrcweir 								const ParamInfo& rInfo = pParamInfos[j];
2349cdf0e10cSrcweir 								ParamMode aParamMode = rInfo.aMode;
2350cdf0e10cSrcweir 								if( aParamMode != ParamMode_IN )
2351cdf0e10cSrcweir 									unoToSbxValue( (SbxVariable*)pParams->Get( (sal_uInt16)(j+1) ), pAnyArgs[ j ] );
2352cdf0e10cSrcweir 							}
2353cdf0e10cSrcweir 						}
2354cdf0e10cSrcweir 					}
2355cdf0e10cSrcweir 					else if( bInvocation && mxInvocation.is() )
2356cdf0e10cSrcweir 					{
2357cdf0e10cSrcweir                         Reference< XDirectInvocation > xDirectInvoke;
2358cdf0e10cSrcweir                         if ( pMeth->needsDirectInvocation() )
2359cdf0e10cSrcweir                             xDirectInvoke.set( mxInvocation, UNO_QUERY );
2360cdf0e10cSrcweir 
2361cdf0e10cSrcweir                         Any aRetAny;
2362cdf0e10cSrcweir                         if ( xDirectInvoke.is() )
2363cdf0e10cSrcweir                             aRetAny = xDirectInvoke->directInvoke( pMeth->GetName(), args );
2364cdf0e10cSrcweir                         else
2365cdf0e10cSrcweir                         {
2366cdf0e10cSrcweir                             Sequence< sal_Int16 > OutParamIndex;
2367cdf0e10cSrcweir                             Sequence< Any > OutParam;
2368cdf0e10cSrcweir                             aRetAny = mxInvocation->invoke( pMeth->GetName(), args, OutParamIndex, OutParam );
2369cdf0e10cSrcweir 
2370cdf0e10cSrcweir                             const sal_Int16* pIndices = OutParamIndex.getConstArray();
2371cdf0e10cSrcweir                             sal_uInt32 nLen = OutParamIndex.getLength();
2372cdf0e10cSrcweir                             if( nLen )
2373cdf0e10cSrcweir                             {
2374cdf0e10cSrcweir                                 const Any* pNewValues = OutParam.getConstArray();
2375cdf0e10cSrcweir                                 for( sal_uInt32 j = 0 ; j < nLen ; j++ )
2376cdf0e10cSrcweir                                 {
2377cdf0e10cSrcweir                                     sal_Int16 iTarget = pIndices[ j ];
2378cdf0e10cSrcweir                                     if( iTarget >= (sal_Int16)nParamCount )
2379cdf0e10cSrcweir                                         break;
2380cdf0e10cSrcweir                                     unoToSbxValue( (SbxVariable*)pParams->Get( (sal_uInt16)(j+1) ), pNewValues[ j ] );
2381cdf0e10cSrcweir                                 }
2382cdf0e10cSrcweir                             }
2383cdf0e10cSrcweir                         }
2384cdf0e10cSrcweir 
2385cdf0e10cSrcweir                         // Wert von Uno nach Sbx uebernehmen
2386cdf0e10cSrcweir                         unoToSbxValue( pVar, aRetAny );
2387cdf0e10cSrcweir 					}
2388cdf0e10cSrcweir 
2389cdf0e10cSrcweir 					// #55460, Parameter hier weghauen, da das in unoToSbxValue()
2390cdf0e10cSrcweir 					// bei Arrays wegen #54548 nicht mehr gemacht wird
2391cdf0e10cSrcweir 					if( pParams )
2392cdf0e10cSrcweir 						pVar->SetParameters( NULL );
2393cdf0e10cSrcweir 				}
2394cdf0e10cSrcweir 				catch( const Exception& )
2395cdf0e10cSrcweir 				{
2396cdf0e10cSrcweir                     implHandleAnyException( ::cppu::getCaughtException() );
2397cdf0e10cSrcweir 				}
2398cdf0e10cSrcweir                 GetSbData()->bBlockCompilerError = sal_False;  // #106433 Unblock compiler errors
2399cdf0e10cSrcweir 			}
2400cdf0e10cSrcweir 		}
2401cdf0e10cSrcweir 		else
2402cdf0e10cSrcweir 			SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
2403cdf0e10cSrcweir 	}
2404cdf0e10cSrcweir }
2405cdf0e10cSrcweir 
2406cdf0e10cSrcweir 
2407cdf0e10cSrcweir #ifdef INVOCATION_ONLY
2408cdf0e10cSrcweir // Aus USR
2409cdf0e10cSrcweir Reference< XInvocation > createDynamicInvocationFor( const Any& aAny );
2410cdf0e10cSrcweir #endif
2411cdf0e10cSrcweir 
SbUnoObject(const String & aName_,const Any & aUnoObj_)2412cdf0e10cSrcweir SbUnoObject::SbUnoObject( const String& aName_, const Any& aUnoObj_ )
2413cdf0e10cSrcweir 	: SbxObject( aName_ )
2414cdf0e10cSrcweir 	, bNeedIntrospection( sal_True )
2415cdf0e10cSrcweir 	, bNativeCOMObject( sal_False )
2416cdf0e10cSrcweir {
2417cdf0e10cSrcweir 	static Reference< XIntrospection > xIntrospection;
2418cdf0e10cSrcweir 
2419cdf0e10cSrcweir 	// Default-Properties von Sbx wieder rauspruegeln
2420cdf0e10cSrcweir 	Remove( XubString( RTL_CONSTASCII_USTRINGPARAM("Name") ), SbxCLASS_DONTCARE );
2421cdf0e10cSrcweir 	Remove( XubString( RTL_CONSTASCII_USTRINGPARAM("Parent") ), SbxCLASS_DONTCARE );
2422cdf0e10cSrcweir 
2423cdf0e10cSrcweir 	// Typ des Objekts pruefen
2424cdf0e10cSrcweir 	TypeClass eType = aUnoObj_.getValueType().getTypeClass();
2425cdf0e10cSrcweir 	Reference< XInterface > x;
2426cdf0e10cSrcweir 	if( eType == TypeClass_INTERFACE )
2427cdf0e10cSrcweir 	{
2428cdf0e10cSrcweir 		// Interface aus dem Any besorgen
2429cdf0e10cSrcweir 		x = *(Reference< XInterface >*)aUnoObj_.getValue();
2430cdf0e10cSrcweir 		if( !x.is() )
2431cdf0e10cSrcweir 			return;
2432cdf0e10cSrcweir 	}
2433cdf0e10cSrcweir 
2434cdf0e10cSrcweir 	Reference< XTypeProvider > xTypeProvider;
2435cdf0e10cSrcweir #ifdef INVOCATION_ONLY
2436cdf0e10cSrcweir 	// Invocation besorgen
2437cdf0e10cSrcweir 	mxInvocation = createDynamicInvocationFor( aUnoObj_ );
2438cdf0e10cSrcweir #else
2439cdf0e10cSrcweir 	// Hat das Object selbst eine Invocation?
2440cdf0e10cSrcweir 	mxInvocation = Reference< XInvocation >( x, UNO_QUERY );
2441cdf0e10cSrcweir 
2442cdf0e10cSrcweir 	xTypeProvider = Reference< XTypeProvider >( x, UNO_QUERY );
2443cdf0e10cSrcweir #endif
2444cdf0e10cSrcweir 
2445cdf0e10cSrcweir 	if( mxInvocation.is() )
2446cdf0e10cSrcweir 	{
2447cdf0e10cSrcweir 		// #94670: This is WRONG because then the MaterialHolder doesn't refer
2448cdf0e10cSrcweir 		// to the object implementing XInvocation but to the object passed to
2449cdf0e10cSrcweir 		// the invocation service!!!
2450cdf0e10cSrcweir 		// mxMaterialHolder = Reference< XMaterialHolder >::query( mxInvocation );
2451cdf0e10cSrcweir 
2452cdf0e10cSrcweir 		// ExactName holen
2453cdf0e10cSrcweir 		mxExactNameInvocation = Reference< XExactName >::query( mxInvocation );
2454cdf0e10cSrcweir 
2455cdf0e10cSrcweir 		// Rest bezieht sich nur auf Introspection
2456cdf0e10cSrcweir 		if( !xTypeProvider.is() )
2457cdf0e10cSrcweir 		{
2458cdf0e10cSrcweir 			bNeedIntrospection = sal_False;
2459cdf0e10cSrcweir 			return;
2460cdf0e10cSrcweir 		}
2461cdf0e10cSrcweir 
2462cdf0e10cSrcweir 		// Ignore introspection based members for COM objects to avoid
2463cdf0e10cSrcweir 		// hiding of equally named COM symbols, e.g. XInvocation::getValue
2464cdf0e10cSrcweir 		Reference< oleautomation::XAutomationObject > xAutomationObject( aUnoObj_, UNO_QUERY );
2465cdf0e10cSrcweir 		if( xAutomationObject.is() )
2466cdf0e10cSrcweir 			bNativeCOMObject = sal_True;
2467cdf0e10cSrcweir 	}
2468cdf0e10cSrcweir 
2469cdf0e10cSrcweir 	maTmpUnoObj = aUnoObj_;
2470cdf0e10cSrcweir 
2471cdf0e10cSrcweir 
2472cdf0e10cSrcweir 	//*** Namen bestimmen ***
2473cdf0e10cSrcweir 	sal_Bool bFatalError = sal_True;
2474cdf0e10cSrcweir 
2475cdf0e10cSrcweir 	// Ist es ein Interface oder eine struct?
2476cdf0e10cSrcweir 	sal_Bool bSetClassName = sal_False;
2477cdf0e10cSrcweir 	String aClassName_;
2478cdf0e10cSrcweir 	if( eType == TypeClass_STRUCT || eType == TypeClass_EXCEPTION )
2479cdf0e10cSrcweir 	{
2480cdf0e10cSrcweir 		// Struct ist Ok
2481cdf0e10cSrcweir 		bFatalError = sal_False;
2482cdf0e10cSrcweir 
2483cdf0e10cSrcweir 		// #67173 Echten Klassen-Namen eintragen
2484cdf0e10cSrcweir 		if( aName_.Len() == 0 )
2485cdf0e10cSrcweir 		{
2486cdf0e10cSrcweir 			aClassName_ = String( aUnoObj_.getValueType().getTypeName() );
2487cdf0e10cSrcweir 			bSetClassName = sal_True;
2488cdf0e10cSrcweir 		}
2489cdf0e10cSrcweir 	}
2490cdf0e10cSrcweir 	else if( eType == TypeClass_INTERFACE )
2491cdf0e10cSrcweir 	{
2492cdf0e10cSrcweir 		// #70197 Interface geht immer durch Typ im Any
2493cdf0e10cSrcweir 		bFatalError = sal_False;
2494cdf0e10cSrcweir 
2495cdf0e10cSrcweir 		// Nach XIdlClassProvider-Interface fragen
2496cdf0e10cSrcweir 		Reference< XIdlClassProvider > xClassProvider( x, UNO_QUERY );
2497cdf0e10cSrcweir 		if( xClassProvider.is() )
2498cdf0e10cSrcweir 		{
2499cdf0e10cSrcweir 			// #67173 Echten Klassen-Namen eintragen
2500cdf0e10cSrcweir 			if( aName_.Len() == 0 )
2501cdf0e10cSrcweir 			{
2502cdf0e10cSrcweir 				Sequence< Reference< XIdlClass > > szClasses = xClassProvider->getIdlClasses();
2503cdf0e10cSrcweir 				sal_uInt32 nLen = szClasses.getLength();
2504cdf0e10cSrcweir 				if( nLen )
2505cdf0e10cSrcweir 				{
2506cdf0e10cSrcweir 					const Reference< XIdlClass > xImplClass = szClasses.getConstArray()[ 0 ];
2507cdf0e10cSrcweir 					if( xImplClass.is() )
2508cdf0e10cSrcweir 					{
2509cdf0e10cSrcweir 						aClassName_ = String( xImplClass->getName() );
2510cdf0e10cSrcweir 						bSetClassName = sal_True;
2511cdf0e10cSrcweir 					}
2512cdf0e10cSrcweir 				}
2513cdf0e10cSrcweir 			}
2514cdf0e10cSrcweir 		}
2515cdf0e10cSrcweir 	}
2516cdf0e10cSrcweir 	if( bSetClassName )
2517cdf0e10cSrcweir 		SetClassName( aClassName_ );
2518cdf0e10cSrcweir 
2519cdf0e10cSrcweir 	// Weder Interface noch Struct -> FatalError
2520cdf0e10cSrcweir 	if( bFatalError )
2521cdf0e10cSrcweir 	{
2522cdf0e10cSrcweir 		StarBASIC::FatalError( ERRCODE_BASIC_EXCEPTION );
2523cdf0e10cSrcweir 		return;
2524cdf0e10cSrcweir 	}
2525cdf0e10cSrcweir 
2526cdf0e10cSrcweir 	// #67781 Introspection erst on demand durchfuehren
2527cdf0e10cSrcweir }
2528cdf0e10cSrcweir 
~SbUnoObject()2529cdf0e10cSrcweir SbUnoObject::~SbUnoObject()
2530cdf0e10cSrcweir {
2531cdf0e10cSrcweir }
2532cdf0e10cSrcweir 
2533cdf0e10cSrcweir 
2534cdf0e10cSrcweir // #76470 Introspection on Demand durchfuehren
doIntrospection(void)2535cdf0e10cSrcweir void SbUnoObject::doIntrospection( void )
2536cdf0e10cSrcweir {
2537cdf0e10cSrcweir 	static Reference< XIntrospection > xIntrospection;
2538cdf0e10cSrcweir 
2539cdf0e10cSrcweir 	if( !bNeedIntrospection )
2540cdf0e10cSrcweir 		return;
2541cdf0e10cSrcweir 	bNeedIntrospection = sal_False;
2542cdf0e10cSrcweir 
2543cdf0e10cSrcweir 	if( !xIntrospection.is() )
2544cdf0e10cSrcweir 	{
2545cdf0e10cSrcweir 		// Introspection-Service holen
2546cdf0e10cSrcweir 		Reference< XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory() );
2547cdf0e10cSrcweir 		if ( xFactory.is() )
2548cdf0e10cSrcweir 		{
2549cdf0e10cSrcweir 			Reference< XInterface > xI = xFactory->createInstance( rtl::OUString::createFromAscii("com.sun.star.beans.Introspection") );
2550cdf0e10cSrcweir 			if (xI.is())
2551cdf0e10cSrcweir 				xIntrospection = Reference< XIntrospection >::query( xI );
2552cdf0e10cSrcweir 				//xI->queryInterface( ::getCppuType( (const Reference< XIntrospection > *)0 ), xIntrospection );
2553cdf0e10cSrcweir 		}
2554cdf0e10cSrcweir 	}
2555cdf0e10cSrcweir 	if( !xIntrospection.is() )
2556cdf0e10cSrcweir 	{
2557cdf0e10cSrcweir 		StarBASIC::FatalError( ERRCODE_BASIC_EXCEPTION );
2558cdf0e10cSrcweir 		return;
2559cdf0e10cSrcweir 	}
2560cdf0e10cSrcweir 
2561cdf0e10cSrcweir 	// Introspection durchfuehren
2562cdf0e10cSrcweir 	try
2563cdf0e10cSrcweir 	{
2564cdf0e10cSrcweir 		mxUnoAccess = xIntrospection->inspect( maTmpUnoObj );
2565cdf0e10cSrcweir 	}
2566cdf0e10cSrcweir 	catch( RuntimeException& e )
2567cdf0e10cSrcweir 	{
2568cdf0e10cSrcweir         StarBASIC::Error( ERRCODE_BASIC_EXCEPTION, implGetExceptionMsg( e ) );
2569cdf0e10cSrcweir 	}
2570cdf0e10cSrcweir 
2571cdf0e10cSrcweir 	if( !mxUnoAccess.is() )
2572cdf0e10cSrcweir 	{
2573cdf0e10cSrcweir 		// #51475 Ungueltiges Objekt kennzeichnen (kein mxMaterialHolder)
2574cdf0e10cSrcweir 		return;
2575cdf0e10cSrcweir 	}
2576cdf0e10cSrcweir 
2577cdf0e10cSrcweir 	// MaterialHolder vom Access holen
2578cdf0e10cSrcweir 	mxMaterialHolder = Reference< XMaterialHolder >::query( mxUnoAccess );
2579cdf0e10cSrcweir 
2580cdf0e10cSrcweir 	// ExactName vom Access holen
2581cdf0e10cSrcweir 	mxExactName = Reference< XExactName >::query( mxUnoAccess );
2582cdf0e10cSrcweir }
2583cdf0e10cSrcweir 
2584cdf0e10cSrcweir 
2585cdf0e10cSrcweir 
2586cdf0e10cSrcweir 
2587cdf0e10cSrcweir // #67781 Start einer Liste aller SbUnoMethod-Instanzen
2588cdf0e10cSrcweir static SbUnoMethod* pFirst = NULL;
2589cdf0e10cSrcweir 
clearUnoMethodsForBasic(StarBASIC * pBasic)2590cdf0e10cSrcweir void clearUnoMethodsForBasic( StarBASIC* pBasic )
2591cdf0e10cSrcweir {
2592cdf0e10cSrcweir 	SbUnoMethod* pMeth = pFirst;
2593cdf0e10cSrcweir 	while( pMeth )
2594cdf0e10cSrcweir 	{
2595cdf0e10cSrcweir         SbxObject* pObject = dynamic_cast< SbxObject* >( pMeth->GetParent() );
2596cdf0e10cSrcweir         if ( pObject )
2597cdf0e10cSrcweir         {
2598cdf0e10cSrcweir             StarBASIC* pModBasic = dynamic_cast< StarBASIC* >( pObject->GetParent() );
2599cdf0e10cSrcweir             if ( pModBasic == pBasic )
2600cdf0e10cSrcweir             {
2601cdf0e10cSrcweir                 // for now the solution is to remove the method from the list and to clear it,
2602cdf0e10cSrcweir                 // but in case the element should be correctly transfered to another StarBASIC,
2603cdf0e10cSrcweir                 // we should either set module parent to NULL without clearing it, or even
2604cdf0e10cSrcweir                 // set the new StarBASIC as the parent of the module
2605cdf0e10cSrcweir                 // pObject->SetParent( NULL );
2606cdf0e10cSrcweir 
2607cdf0e10cSrcweir                 if( pMeth == pFirst )
2608cdf0e10cSrcweir                     pFirst = pMeth->pNext;
2609cdf0e10cSrcweir                 else if( pMeth->pPrev )
2610cdf0e10cSrcweir                     pMeth->pPrev->pNext = pMeth->pNext;
2611cdf0e10cSrcweir                 if( pMeth->pNext )
2612cdf0e10cSrcweir                     pMeth->pNext->pPrev = pMeth->pPrev;
2613cdf0e10cSrcweir 
2614cdf0e10cSrcweir                 pMeth->pPrev = NULL;
2615cdf0e10cSrcweir                 pMeth->pNext = NULL;
2616cdf0e10cSrcweir 
2617cdf0e10cSrcweir                 pMeth->SbxValue::Clear();
2618cdf0e10cSrcweir                 pObject->SbxValue::Clear();
2619cdf0e10cSrcweir 
2620cdf0e10cSrcweir                 // start from the beginning after object clearing, the cycle will end since the method is removed each time
2621cdf0e10cSrcweir                 pMeth = pFirst;
2622cdf0e10cSrcweir             }
2623cdf0e10cSrcweir             else
2624cdf0e10cSrcweir                 pMeth = pMeth->pNext;
2625cdf0e10cSrcweir         }
2626cdf0e10cSrcweir         else
2627cdf0e10cSrcweir             pMeth = pMeth->pNext;
2628cdf0e10cSrcweir 	}
2629cdf0e10cSrcweir }
2630cdf0e10cSrcweir 
clearUnoMethods(void)2631cdf0e10cSrcweir void clearUnoMethods( void )
2632cdf0e10cSrcweir {
2633cdf0e10cSrcweir 	SbUnoMethod* pMeth = pFirst;
2634cdf0e10cSrcweir 	while( pMeth )
2635cdf0e10cSrcweir 	{
2636cdf0e10cSrcweir 		pMeth->SbxValue::Clear();
2637cdf0e10cSrcweir 		pMeth = pMeth->pNext;
2638cdf0e10cSrcweir 	}
2639cdf0e10cSrcweir }
2640cdf0e10cSrcweir 
2641cdf0e10cSrcweir 
SbUnoMethod(const String & aName_,SbxDataType eSbxType,Reference<XIdlMethod> xUnoMethod_,bool bInvocation,bool bDirect)2642cdf0e10cSrcweir SbUnoMethod::SbUnoMethod
2643cdf0e10cSrcweir (
2644cdf0e10cSrcweir 	const String& aName_,
2645cdf0e10cSrcweir 	SbxDataType eSbxType,
2646cdf0e10cSrcweir 	Reference< XIdlMethod > xUnoMethod_,
2647cdf0e10cSrcweir 	bool bInvocation,
2648cdf0e10cSrcweir     bool bDirect
2649cdf0e10cSrcweir )
2650cdf0e10cSrcweir 	: SbxMethod( aName_, eSbxType )
2651cdf0e10cSrcweir 	, mbInvocation( bInvocation )
2652cdf0e10cSrcweir     , mbDirectInvocation( bDirect )
2653cdf0e10cSrcweir {
2654cdf0e10cSrcweir 	m_xUnoMethod = xUnoMethod_;
2655cdf0e10cSrcweir 	pParamInfoSeq = NULL;
2656cdf0e10cSrcweir 
2657cdf0e10cSrcweir 	// #67781 Methode in Liste eintragen
2658cdf0e10cSrcweir 	pNext = pFirst;
2659cdf0e10cSrcweir 	pPrev = NULL;
2660cdf0e10cSrcweir 	pFirst = this;
2661cdf0e10cSrcweir 	if( pNext )
2662cdf0e10cSrcweir 		pNext->pPrev = this;
2663cdf0e10cSrcweir }
2664cdf0e10cSrcweir 
~SbUnoMethod()2665cdf0e10cSrcweir SbUnoMethod::~SbUnoMethod()
2666cdf0e10cSrcweir {
2667cdf0e10cSrcweir 	delete pParamInfoSeq;
2668cdf0e10cSrcweir 
2669cdf0e10cSrcweir 	if( this == pFirst )
2670cdf0e10cSrcweir 		pFirst = pNext;
2671cdf0e10cSrcweir 	else if( pPrev )
2672cdf0e10cSrcweir 		pPrev->pNext = pNext;
2673cdf0e10cSrcweir 	if( pNext )
2674cdf0e10cSrcweir 		pNext->pPrev = pPrev;
2675cdf0e10cSrcweir }
2676cdf0e10cSrcweir 
GetInfo()2677cdf0e10cSrcweir SbxInfo* SbUnoMethod::GetInfo()
2678cdf0e10cSrcweir {
2679cdf0e10cSrcweir 	if( !pInfo && m_xUnoMethod.is() )
2680cdf0e10cSrcweir 	{
2681cdf0e10cSrcweir 		SbiInstance* pInst = pINST;
2682cdf0e10cSrcweir 		if( pInst && pInst->IsCompatibility() )
2683cdf0e10cSrcweir 		{
2684cdf0e10cSrcweir 			pInfo = new SbxInfo();
2685cdf0e10cSrcweir 
2686cdf0e10cSrcweir 			const Sequence<ParamInfo>& rInfoSeq = getParamInfos();
2687cdf0e10cSrcweir 			const ParamInfo* pParamInfos = rInfoSeq.getConstArray();
2688cdf0e10cSrcweir 			sal_uInt32 nParamCount = rInfoSeq.getLength();
2689cdf0e10cSrcweir 
2690cdf0e10cSrcweir 			for( sal_uInt32 i = 0 ; i < nParamCount ; i++ )
2691cdf0e10cSrcweir 			{
2692cdf0e10cSrcweir 				const ParamInfo& rInfo = pParamInfos[i];
2693cdf0e10cSrcweir 				::rtl::OUString aParamName = rInfo.aName;
2694cdf0e10cSrcweir 
2695cdf0e10cSrcweir 				// const Reference< XIdlClass >& rxClass = rInfo.aType;
2696cdf0e10cSrcweir 				SbxDataType t = SbxVARIANT;
2697cdf0e10cSrcweir 				sal_uInt16 nFlags_ = SBX_READ;
2698cdf0e10cSrcweir 				pInfo->AddParam( aParamName, t, nFlags_ );
2699cdf0e10cSrcweir 			}
2700cdf0e10cSrcweir 		}
2701cdf0e10cSrcweir 	}
2702cdf0e10cSrcweir 	return pInfo;
2703cdf0e10cSrcweir }
2704cdf0e10cSrcweir 
getParamInfos(void)2705cdf0e10cSrcweir const Sequence<ParamInfo>& SbUnoMethod::getParamInfos( void )
2706cdf0e10cSrcweir {
2707cdf0e10cSrcweir 	if( !pParamInfoSeq && m_xUnoMethod.is() )
2708cdf0e10cSrcweir 	{
2709cdf0e10cSrcweir 		Sequence<ParamInfo> aTmp = m_xUnoMethod->getParameterInfos() ;
2710cdf0e10cSrcweir 		pParamInfoSeq = new Sequence<ParamInfo>( aTmp );
2711cdf0e10cSrcweir 	}
2712cdf0e10cSrcweir 	return *pParamInfoSeq;
2713cdf0e10cSrcweir }
2714cdf0e10cSrcweir 
SbUnoProperty(const String & aName_,SbxDataType eSbxType,const Property & aUnoProp_,sal_Int32 nId_,bool bInvocation)2715cdf0e10cSrcweir SbUnoProperty::SbUnoProperty
2716cdf0e10cSrcweir (
2717cdf0e10cSrcweir 	const String& aName_,
2718cdf0e10cSrcweir 	SbxDataType eSbxType,
2719cdf0e10cSrcweir 	const Property& aUnoProp_,
2720cdf0e10cSrcweir 	sal_Int32 nId_,
2721cdf0e10cSrcweir 	bool bInvocation
2722cdf0e10cSrcweir )
2723cdf0e10cSrcweir 	: SbxProperty( aName_, eSbxType )
2724cdf0e10cSrcweir 	, aUnoProp( aUnoProp_ )
2725cdf0e10cSrcweir 	, nId( nId_ )
2726cdf0e10cSrcweir 	, mbInvocation( bInvocation )
2727cdf0e10cSrcweir {
2728cdf0e10cSrcweir 	// #54548, bei bedarf Dummy-Array einsetzen, damit SbiRuntime::CheckArray() geht
2729cdf0e10cSrcweir 	static SbxArrayRef xDummyArray = new SbxArray( SbxVARIANT );
2730cdf0e10cSrcweir 	if( eSbxType & SbxARRAY )
2731cdf0e10cSrcweir 		PutObject( xDummyArray );
2732cdf0e10cSrcweir }
2733cdf0e10cSrcweir 
~SbUnoProperty()2734cdf0e10cSrcweir SbUnoProperty::~SbUnoProperty()
2735cdf0e10cSrcweir {}
2736cdf0e10cSrcweir 
2737cdf0e10cSrcweir 
Find(const String & rName,SbxClassType t)2738cdf0e10cSrcweir SbxVariable* SbUnoObject::Find( const String& rName, SbxClassType t )
2739cdf0e10cSrcweir {
2740cdf0e10cSrcweir 	static Reference< XIdlMethod > xDummyMethod;
2741cdf0e10cSrcweir 	static Property aDummyProp;
2742cdf0e10cSrcweir 
2743cdf0e10cSrcweir 	SbxVariable* pRes = SbxObject::Find( rName, t );
2744cdf0e10cSrcweir 
2745cdf0e10cSrcweir 	if( bNeedIntrospection )
2746cdf0e10cSrcweir 		doIntrospection();
2747cdf0e10cSrcweir 
2748cdf0e10cSrcweir 	// Neu 4.3.1999: Properties on Demand anlegen, daher jetzt perIntrospectionAccess
2749cdf0e10cSrcweir 	// suchen, ob doch eine Property oder Methode des geforderten Namens existiert
2750cdf0e10cSrcweir 	if( !pRes )
2751cdf0e10cSrcweir 	{
2752cdf0e10cSrcweir 		::rtl::OUString aUName( rName );
2753cdf0e10cSrcweir 		if( mxUnoAccess.is() && !bNativeCOMObject )
2754cdf0e10cSrcweir 		{
2755cdf0e10cSrcweir 			if( mxExactName.is() )
2756cdf0e10cSrcweir 			{
2757cdf0e10cSrcweir 				::rtl::OUString aUExactName = mxExactName->getExactName( aUName );
2758*0848378bSHerbert Dürr 				if( !aUExactName.isEmpty() )
2759cdf0e10cSrcweir 					aUName = aUExactName;
2760cdf0e10cSrcweir 			}
2761cdf0e10cSrcweir 			if( mxUnoAccess->hasProperty( aUName, PropertyConcept::ALL - PropertyConcept::DANGEROUS ) )
2762cdf0e10cSrcweir 			{
2763cdf0e10cSrcweir 				const Property& rProp = mxUnoAccess->
2764cdf0e10cSrcweir 					getProperty( aUName, PropertyConcept::ALL - PropertyConcept::DANGEROUS );
2765cdf0e10cSrcweir 
2766cdf0e10cSrcweir 				// #58455 Wenn die Property void sein kann, muss als Typ Variant gesetzt werden
2767cdf0e10cSrcweir 				SbxDataType eSbxType;
2768cdf0e10cSrcweir 				if( rProp.Attributes & PropertyAttribute::MAYBEVOID )
2769cdf0e10cSrcweir 					eSbxType = SbxVARIANT;
2770cdf0e10cSrcweir 				else
2771cdf0e10cSrcweir 					eSbxType = unoToSbxType( rProp.Type.getTypeClass() );
2772cdf0e10cSrcweir 
2773cdf0e10cSrcweir 				// Property anlegen und reinbraten
2774cdf0e10cSrcweir 				SbxVariableRef xVarRef = new SbUnoProperty( rProp.Name, eSbxType, rProp, 0, false );
2775cdf0e10cSrcweir 				QuickInsert( (SbxVariable*)xVarRef );
2776cdf0e10cSrcweir 				pRes = xVarRef;
2777cdf0e10cSrcweir 			}
2778cdf0e10cSrcweir 			else if( mxUnoAccess->hasMethod( aUName,
2779cdf0e10cSrcweir 				MethodConcept::ALL - MethodConcept::DANGEROUS ) )
2780cdf0e10cSrcweir 			{
2781cdf0e10cSrcweir 				// Methode ansprechen
2782cdf0e10cSrcweir 				const Reference< XIdlMethod >& rxMethod = mxUnoAccess->
2783cdf0e10cSrcweir 					getMethod( aUName, MethodConcept::ALL - MethodConcept::DANGEROUS );
2784cdf0e10cSrcweir 
2785cdf0e10cSrcweir 				// SbUnoMethode anlegen und reinbraten
2786cdf0e10cSrcweir 				SbxVariableRef xMethRef = new SbUnoMethod( rxMethod->getName(),
2787cdf0e10cSrcweir 					unoToSbxType( rxMethod->getReturnType() ), rxMethod, false );
2788cdf0e10cSrcweir 				QuickInsert( (SbxVariable*)xMethRef );
2789cdf0e10cSrcweir 				pRes = xMethRef;
2790cdf0e10cSrcweir 			}
2791cdf0e10cSrcweir 
2792cdf0e10cSrcweir 			// Wenn immer noch nichts gefunden wurde, muss geprueft werden, ob NameAccess vorliegt
2793cdf0e10cSrcweir 			if( !pRes )
2794cdf0e10cSrcweir 			{
2795cdf0e10cSrcweir 				try
2796cdf0e10cSrcweir 				{
2797cdf0e10cSrcweir 					Reference< XNameAccess > xNameAccess( mxUnoAccess->queryAdapter( ::getCppuType( (const Reference< XPropertySet > *)0 ) ), UNO_QUERY );
2798cdf0e10cSrcweir 					::rtl::OUString aUName2( rName );
2799cdf0e10cSrcweir 
2800cdf0e10cSrcweir 					if( xNameAccess.is() && xNameAccess->hasByName( aUName2 ) )
2801cdf0e10cSrcweir 					{
2802cdf0e10cSrcweir 						Any aAny = xNameAccess->getByName( aUName2 );
2803cdf0e10cSrcweir 
2804cdf0e10cSrcweir 						// ACHTUNG: Die hier erzeugte Variable darf wegen bei XNameAccess
2805cdf0e10cSrcweir 						// nicht als feste Property in das Object aufgenommen werden und
2806cdf0e10cSrcweir 						// wird daher nirgendwo gehalten.
2807cdf0e10cSrcweir 						// Wenn das Probleme gibt, muss das kuenstlich gemacht werden oder
2808cdf0e10cSrcweir 						// es muss eine Klasse SbUnoNameAccessProperty geschaffen werden,
2809cdf0e10cSrcweir 						// bei der die Existenz staendig neu ueberprueft und die ggf. weg-
2810cdf0e10cSrcweir 						// geworfen wird, wenn der Name nicht mehr gefunden wird.
2811cdf0e10cSrcweir 						pRes = new SbxVariable( SbxVARIANT );
2812cdf0e10cSrcweir 						unoToSbxValue( pRes, aAny );
2813cdf0e10cSrcweir 					}
2814cdf0e10cSrcweir 				}
2815cdf0e10cSrcweir 				catch( NoSuchElementException& e )
2816cdf0e10cSrcweir 				{
2817cdf0e10cSrcweir 					StarBASIC::Error( ERRCODE_BASIC_EXCEPTION, implGetExceptionMsg( e ) );
2818cdf0e10cSrcweir 				}
2819cdf0e10cSrcweir 				catch( const Exception& )
2820cdf0e10cSrcweir 				{
2821cdf0e10cSrcweir 					// Anlegen, damit der Exception-Fehler nicht ueberschrieben wird
2822cdf0e10cSrcweir 					if( !pRes )
2823cdf0e10cSrcweir 						pRes = new SbxVariable( SbxVARIANT );
2824cdf0e10cSrcweir 
2825cdf0e10cSrcweir                     implHandleAnyException( ::cppu::getCaughtException() );
2826cdf0e10cSrcweir 				}
2827cdf0e10cSrcweir 			}
2828cdf0e10cSrcweir 		}
2829cdf0e10cSrcweir 		if( !pRes && mxInvocation.is() )
2830cdf0e10cSrcweir 		{
2831cdf0e10cSrcweir 			if( mxExactNameInvocation.is() )
2832cdf0e10cSrcweir 			{
2833cdf0e10cSrcweir 				::rtl::OUString aUExactName = mxExactNameInvocation->getExactName( aUName );
2834*0848378bSHerbert Dürr 				if( !aUExactName.isEmpty() )
2835cdf0e10cSrcweir 					aUName = aUExactName;
2836cdf0e10cSrcweir 			}
2837cdf0e10cSrcweir 
2838cdf0e10cSrcweir 			try
2839cdf0e10cSrcweir 			{
2840cdf0e10cSrcweir 				if( mxInvocation->hasProperty( aUName ) )
2841cdf0e10cSrcweir 				{
2842cdf0e10cSrcweir 					// Property anlegen und reinbraten
2843cdf0e10cSrcweir 					SbxVariableRef xVarRef = new SbUnoProperty( aUName, SbxVARIANT, aDummyProp, 0, true );
2844cdf0e10cSrcweir 					QuickInsert( (SbxVariable*)xVarRef );
2845cdf0e10cSrcweir 					pRes = xVarRef;
2846cdf0e10cSrcweir 				}
2847cdf0e10cSrcweir 				else if( mxInvocation->hasMethod( aUName ) )
2848cdf0e10cSrcweir 				{
2849cdf0e10cSrcweir 					// SbUnoMethode anlegen und reinbraten
2850cdf0e10cSrcweir 					SbxVariableRef xMethRef = new SbUnoMethod( aUName, SbxVARIANT, xDummyMethod, true );
2851cdf0e10cSrcweir 					QuickInsert( (SbxVariable*)xMethRef );
2852cdf0e10cSrcweir 					pRes = xMethRef;
2853cdf0e10cSrcweir 				}
2854cdf0e10cSrcweir                 else
2855cdf0e10cSrcweir                 {
2856cdf0e10cSrcweir                     Reference< XDirectInvocation > xDirectInvoke( mxInvocation, UNO_QUERY );
2857cdf0e10cSrcweir                     if ( xDirectInvoke.is() && xDirectInvoke->hasMember( aUName ) )
2858cdf0e10cSrcweir                     {
2859cdf0e10cSrcweir                         SbxVariableRef xMethRef = new SbUnoMethod( aUName, SbxVARIANT, xDummyMethod, true, true );
2860cdf0e10cSrcweir                         QuickInsert( (SbxVariable*)xMethRef );
2861cdf0e10cSrcweir                         pRes = xMethRef;
2862cdf0e10cSrcweir                     }
2863cdf0e10cSrcweir 
2864cdf0e10cSrcweir                 }
2865cdf0e10cSrcweir 			}
2866cdf0e10cSrcweir 			catch( RuntimeException& e )
2867cdf0e10cSrcweir 			{
2868cdf0e10cSrcweir 				// Anlegen, damit der Exception-Fehler nicht ueberschrieben wird
2869cdf0e10cSrcweir 				if( !pRes )
2870cdf0e10cSrcweir 					pRes = new SbxVariable( SbxVARIANT );
2871cdf0e10cSrcweir 
2872cdf0e10cSrcweir 				StarBASIC::Error( ERRCODE_BASIC_EXCEPTION, implGetExceptionMsg( e ) );
2873cdf0e10cSrcweir 			}
2874cdf0e10cSrcweir 		}
2875cdf0e10cSrcweir 	}
2876cdf0e10cSrcweir 
2877cdf0e10cSrcweir 	// Ganz am Schluss noch pruefen, ob die Dbg_-Properties gemeint sind
2878cdf0e10cSrcweir 
2879cdf0e10cSrcweir 	if( !pRes )
2880cdf0e10cSrcweir 	{
2881cdf0e10cSrcweir 		if( rName.EqualsIgnoreCaseAscii( ID_DBG_SUPPORTEDINTERFACES ) ||
2882cdf0e10cSrcweir 			rName.EqualsIgnoreCaseAscii( ID_DBG_PROPERTIES ) ||
2883cdf0e10cSrcweir 			rName.EqualsIgnoreCaseAscii( ID_DBG_METHODS ) )
2884cdf0e10cSrcweir 		{
2885cdf0e10cSrcweir 			// Anlegen
2886cdf0e10cSrcweir 			implCreateDbgProperties();
2887cdf0e10cSrcweir 
2888cdf0e10cSrcweir 			// Jetzt muessen sie regulaer gefunden werden
2889cdf0e10cSrcweir 			pRes = SbxObject::Find( rName, SbxCLASS_DONTCARE );
2890cdf0e10cSrcweir 		}
2891cdf0e10cSrcweir 	}
2892cdf0e10cSrcweir 	return pRes;
2893cdf0e10cSrcweir }
2894cdf0e10cSrcweir 
2895cdf0e10cSrcweir 
2896cdf0e10cSrcweir // Hilfs-Methode zum Anlegen der dbg_-Properties
implCreateDbgProperties(void)2897cdf0e10cSrcweir void SbUnoObject::implCreateDbgProperties( void )
2898cdf0e10cSrcweir {
2899cdf0e10cSrcweir 	Property aProp;
2900cdf0e10cSrcweir 
2901cdf0e10cSrcweir 	// Id == -1: Implementierte Interfaces gemaess ClassProvider anzeigen
2902cdf0e10cSrcweir 	SbxVariableRef xVarRef = new SbUnoProperty( String(RTL_CONSTASCII_USTRINGPARAM(ID_DBG_SUPPORTEDINTERFACES)), SbxSTRING, aProp, -1, false );
2903cdf0e10cSrcweir 	QuickInsert( (SbxVariable*)xVarRef );
2904cdf0e10cSrcweir 
2905cdf0e10cSrcweir 	// Id == -2: Properties ausgeben
2906cdf0e10cSrcweir 	xVarRef = new SbUnoProperty( String(RTL_CONSTASCII_USTRINGPARAM(ID_DBG_PROPERTIES)), SbxSTRING, aProp, -2, false );
2907cdf0e10cSrcweir 	QuickInsert( (SbxVariable*)xVarRef );
2908cdf0e10cSrcweir 
2909cdf0e10cSrcweir 	// Id == -3: Methoden ausgeben
2910cdf0e10cSrcweir 	xVarRef = new SbUnoProperty( String(RTL_CONSTASCII_USTRINGPARAM(ID_DBG_METHODS)), SbxSTRING, aProp, -3, false );
2911cdf0e10cSrcweir 	QuickInsert( (SbxVariable*)xVarRef );
2912cdf0e10cSrcweir }
2913cdf0e10cSrcweir 
implCreateAll(void)2914cdf0e10cSrcweir void SbUnoObject::implCreateAll( void )
2915cdf0e10cSrcweir {
2916cdf0e10cSrcweir 	// Bestehende Methoden und Properties alle wieder wegwerfen
2917cdf0e10cSrcweir 	pMethods   = new SbxArray;
2918cdf0e10cSrcweir 	pProps     = new SbxArray;
2919cdf0e10cSrcweir 
2920cdf0e10cSrcweir 	if( bNeedIntrospection ) doIntrospection();
2921cdf0e10cSrcweir 
2922cdf0e10cSrcweir 	// Instrospection besorgen
2923cdf0e10cSrcweir 	Reference< XIntrospectionAccess > xAccess = mxUnoAccess;
2924cdf0e10cSrcweir 	if( !xAccess.is() || bNativeCOMObject )
2925cdf0e10cSrcweir 	{
2926cdf0e10cSrcweir 		if( mxInvocation.is() )
2927cdf0e10cSrcweir 			xAccess = mxInvocation->getIntrospection();
2928cdf0e10cSrcweir 		else if( bNativeCOMObject )
2929cdf0e10cSrcweir 			return;
2930cdf0e10cSrcweir 	}
2931cdf0e10cSrcweir 	if( !xAccess.is() )
2932cdf0e10cSrcweir 		return;
2933cdf0e10cSrcweir 
2934cdf0e10cSrcweir 	// Properties anlegen
2935cdf0e10cSrcweir 	Sequence<Property> props = xAccess->getProperties( PropertyConcept::ALL - PropertyConcept::DANGEROUS );
2936cdf0e10cSrcweir 	sal_uInt32 nPropCount = props.getLength();
2937cdf0e10cSrcweir 	const Property* pProps_ = props.getConstArray();
2938cdf0e10cSrcweir 
2939cdf0e10cSrcweir 	sal_uInt32 i;
2940cdf0e10cSrcweir 	for( i = 0 ; i < nPropCount ; i++ )
2941cdf0e10cSrcweir 	{
2942cdf0e10cSrcweir 		const Property& rProp = pProps_[ i ];
2943cdf0e10cSrcweir 
2944cdf0e10cSrcweir 		// #58455 Wenn die Property void sein kann, muss als Typ Variant gesetzt werden
2945cdf0e10cSrcweir 		SbxDataType eSbxType;
2946cdf0e10cSrcweir 		if( rProp.Attributes & PropertyAttribute::MAYBEVOID )
2947cdf0e10cSrcweir 			eSbxType = SbxVARIANT;
2948cdf0e10cSrcweir 		else
2949cdf0e10cSrcweir 			eSbxType = unoToSbxType( rProp.Type.getTypeClass() );
2950cdf0e10cSrcweir 
2951cdf0e10cSrcweir 		// Property anlegen und reinbraten
2952cdf0e10cSrcweir 		SbxVariableRef xVarRef = new SbUnoProperty( rProp.Name, eSbxType, rProp, i, false );
2953cdf0e10cSrcweir 		QuickInsert( (SbxVariable*)xVarRef );
2954cdf0e10cSrcweir 	}
2955cdf0e10cSrcweir 
2956cdf0e10cSrcweir 	// Dbg_-Properties anlegen
2957cdf0e10cSrcweir 	implCreateDbgProperties();
2958cdf0e10cSrcweir 
2959cdf0e10cSrcweir 	// Methoden anlegen
2960cdf0e10cSrcweir 	Sequence< Reference< XIdlMethod > > aMethodSeq = xAccess->getMethods
2961cdf0e10cSrcweir 		( MethodConcept::ALL - MethodConcept::DANGEROUS );
2962cdf0e10cSrcweir 	sal_uInt32 nMethCount = aMethodSeq.getLength();
2963cdf0e10cSrcweir 	const Reference< XIdlMethod >* pMethods_ = aMethodSeq.getConstArray();
2964cdf0e10cSrcweir 	for( i = 0 ; i < nMethCount ; i++ )
2965cdf0e10cSrcweir 	{
2966cdf0e10cSrcweir 		// Methode ansprechen
2967cdf0e10cSrcweir 		const Reference< XIdlMethod >& rxMethod = pMethods_[i];
2968cdf0e10cSrcweir 
2969cdf0e10cSrcweir 		// SbUnoMethode anlegen und reinbraten
2970cdf0e10cSrcweir 		SbxVariableRef xMethRef = new SbUnoMethod
2971cdf0e10cSrcweir 			( rxMethod->getName(), unoToSbxType( rxMethod->getReturnType() ), rxMethod, false );
2972cdf0e10cSrcweir 		QuickInsert( (SbxVariable*)xMethRef );
2973cdf0e10cSrcweir 	}
2974cdf0e10cSrcweir }
2975cdf0e10cSrcweir 
2976cdf0e10cSrcweir 
2977cdf0e10cSrcweir // Wert rausgeben
getUnoAny(void)2978cdf0e10cSrcweir Any SbUnoObject::getUnoAny( void )
2979cdf0e10cSrcweir {
2980cdf0e10cSrcweir 	Any aRetAny;
2981cdf0e10cSrcweir 	if( bNeedIntrospection ) doIntrospection();
2982cdf0e10cSrcweir 	if( mxMaterialHolder.is() )
2983cdf0e10cSrcweir 		aRetAny = mxMaterialHolder->getMaterial();
2984cdf0e10cSrcweir 	else if( mxInvocation.is() )
2985cdf0e10cSrcweir 		aRetAny <<= mxInvocation;
2986cdf0e10cSrcweir 	return aRetAny;
2987cdf0e10cSrcweir }
2988cdf0e10cSrcweir 
2989cdf0e10cSrcweir // Hilfsmethode zum Anlegen einer Uno-Struct per CoreReflection
Impl_CreateUnoStruct(const String & aClassName)2990cdf0e10cSrcweir SbUnoObject* Impl_CreateUnoStruct( const String& aClassName )
2991cdf0e10cSrcweir {
2992cdf0e10cSrcweir 	// CoreReflection holen
2993cdf0e10cSrcweir 	Reference< XIdlReflection > xCoreReflection = getCoreReflection_Impl();
2994cdf0e10cSrcweir 	if( !xCoreReflection.is() )
2995cdf0e10cSrcweir 		return NULL;
2996cdf0e10cSrcweir 
2997cdf0e10cSrcweir 	// Klasse suchen
2998cdf0e10cSrcweir 	Reference< XIdlClass > xClass;
2999cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess > xHarryName =
3000cdf0e10cSrcweir 		getCoreReflection_HierarchicalNameAccess_Impl();
3001cdf0e10cSrcweir 	if( xHarryName.is() && xHarryName->hasByHierarchicalName( aClassName ) )
3002cdf0e10cSrcweir 		xClass = xCoreReflection->forName( aClassName );
3003cdf0e10cSrcweir 	if( !xClass.is() )
3004cdf0e10cSrcweir 		return NULL;
3005cdf0e10cSrcweir 
3006cdf0e10cSrcweir 	// Ist es ueberhaupt ein struct?
3007cdf0e10cSrcweir 	TypeClass eType = xClass->getTypeClass();
3008cdf0e10cSrcweir 	if ( ( eType != TypeClass_STRUCT ) && ( eType != TypeClass_EXCEPTION ) )
3009cdf0e10cSrcweir 		return NULL;
3010cdf0e10cSrcweir 
3011cdf0e10cSrcweir 	// Instanz erzeugen
3012cdf0e10cSrcweir 	Any aNewAny;
3013cdf0e10cSrcweir 	xClass->createObject( aNewAny );
3014cdf0e10cSrcweir 
3015cdf0e10cSrcweir 	// SbUnoObject daraus basteln
3016cdf0e10cSrcweir 	SbUnoObject* pUnoObj = new SbUnoObject( aClassName, aNewAny );
3017cdf0e10cSrcweir 	return pUnoObj;
3018cdf0e10cSrcweir }
3019cdf0e10cSrcweir 
3020cdf0e10cSrcweir 
3021cdf0e10cSrcweir // Factory-Klasse fuer das Anlegen von Uno-Structs per DIM AS NEW
Create(sal_uInt16,sal_uInt32)3022cdf0e10cSrcweir SbxBase* SbUnoFactory::Create( sal_uInt16, sal_uInt32 )
3023cdf0e10cSrcweir {
3024cdf0e10cSrcweir 	// Ueber SbxId laeuft in Uno nix
3025cdf0e10cSrcweir 	return NULL;
3026cdf0e10cSrcweir }
3027cdf0e10cSrcweir 
CreateObject(const String & rClassName)3028cdf0e10cSrcweir SbxObject* SbUnoFactory::CreateObject( const String& rClassName )
3029cdf0e10cSrcweir {
3030cdf0e10cSrcweir 	return Impl_CreateUnoStruct( rClassName );
3031cdf0e10cSrcweir }
3032cdf0e10cSrcweir 
3033cdf0e10cSrcweir 
3034cdf0e10cSrcweir // Provisorische Schnittstelle fuer UNO-Anbindung
3035cdf0e10cSrcweir // Liefert ein SbxObject, das ein Uno-Interface wrappt
GetSbUnoObject(const String & aName,const Any & aUnoObj_)3036cdf0e10cSrcweir SbxObjectRef GetSbUnoObject( const String& aName, const Any& aUnoObj_ )
3037cdf0e10cSrcweir {
3038cdf0e10cSrcweir 	return new SbUnoObject( aName, aUnoObj_ );
3039cdf0e10cSrcweir }
3040cdf0e10cSrcweir 
3041cdf0e10cSrcweir // Force creation of all properties for debugging
createAllObjectProperties(SbxObject * pObj)3042cdf0e10cSrcweir void createAllObjectProperties( SbxObject* pObj )
3043cdf0e10cSrcweir {
3044cdf0e10cSrcweir 	if( !pObj )
3045cdf0e10cSrcweir 		return;
3046cdf0e10cSrcweir 
3047cdf0e10cSrcweir 	SbUnoObject* pUnoObj = PTR_CAST(SbUnoObject,pObj);
3048cdf0e10cSrcweir 	if( pUnoObj )
3049cdf0e10cSrcweir 		pUnoObj->createAllProperties();
3050cdf0e10cSrcweir 	else
3051cdf0e10cSrcweir 		pObj->GetAll( SbxCLASS_DONTCARE );
3052cdf0e10cSrcweir }
3053cdf0e10cSrcweir 
3054cdf0e10cSrcweir 
RTL_Impl_CreateUnoStruct(StarBASIC * pBasic,SbxArray & rPar,sal_Bool bWrite)3055cdf0e10cSrcweir void RTL_Impl_CreateUnoStruct( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite )
3056cdf0e10cSrcweir {
3057cdf0e10cSrcweir     (void)pBasic;
3058cdf0e10cSrcweir     (void)bWrite;
3059cdf0e10cSrcweir 
3060cdf0e10cSrcweir 	// Wir brauchen mindestens 1 Parameter
3061cdf0e10cSrcweir 	if ( rPar.Count() < 2 )
3062cdf0e10cSrcweir 	{
3063cdf0e10cSrcweir 		StarBASIC::Error( SbERR_BAD_ARGUMENT );
3064cdf0e10cSrcweir 		return;
3065cdf0e10cSrcweir 	}
3066cdf0e10cSrcweir 
3067cdf0e10cSrcweir 	// Klassen-Name der struct holen
3068cdf0e10cSrcweir 	String aClassName = rPar.Get(1)->GetString();
3069cdf0e10cSrcweir 
3070cdf0e10cSrcweir 	// Versuchen, gleichnamige Struct zu erzeugen
3071cdf0e10cSrcweir 	SbUnoObjectRef xUnoObj = Impl_CreateUnoStruct( aClassName );
3072cdf0e10cSrcweir 	if( !xUnoObj )
3073cdf0e10cSrcweir 		return;
3074cdf0e10cSrcweir 
3075cdf0e10cSrcweir 	// Objekt zurueckliefern
3076cdf0e10cSrcweir 	SbxVariableRef refVar = rPar.Get(0);
3077cdf0e10cSrcweir 	refVar->PutObject( (SbUnoObject*)xUnoObj );
3078cdf0e10cSrcweir }
3079cdf0e10cSrcweir 
RTL_Impl_CreateUnoService(StarBASIC * pBasic,SbxArray & rPar,sal_Bool bWrite)3080cdf0e10cSrcweir void RTL_Impl_CreateUnoService( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite )
3081cdf0e10cSrcweir {
3082cdf0e10cSrcweir     (void)pBasic;
3083cdf0e10cSrcweir     (void)bWrite;
3084cdf0e10cSrcweir 
3085cdf0e10cSrcweir 	// Wir brauchen mindestens 1 Parameter
3086cdf0e10cSrcweir 	if ( rPar.Count() < 2 )
3087cdf0e10cSrcweir 	{
3088cdf0e10cSrcweir 		StarBASIC::Error( SbERR_BAD_ARGUMENT );
3089cdf0e10cSrcweir 		return;
3090cdf0e10cSrcweir 	}
3091cdf0e10cSrcweir 
3092cdf0e10cSrcweir 	// Klassen-Name der struct holen
3093cdf0e10cSrcweir 	String aServiceName = rPar.Get(1)->GetString();
3094cdf0e10cSrcweir 
3095cdf0e10cSrcweir 	// Service suchen und instanzieren
3096cdf0e10cSrcweir 	Reference< XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory() );
3097cdf0e10cSrcweir 	Reference< XInterface > xInterface;
3098cdf0e10cSrcweir 	if ( xFactory.is() )
3099cdf0e10cSrcweir 	{
3100cdf0e10cSrcweir 		try
3101cdf0e10cSrcweir 		{
3102cdf0e10cSrcweir 			xInterface = xFactory->createInstance( aServiceName );
3103cdf0e10cSrcweir 		}
3104cdf0e10cSrcweir 		catch( const Exception& )
3105cdf0e10cSrcweir 		{
3106cdf0e10cSrcweir             implHandleAnyException( ::cppu::getCaughtException() );
3107cdf0e10cSrcweir 		}
3108cdf0e10cSrcweir 	}
3109cdf0e10cSrcweir 
3110cdf0e10cSrcweir 	SbxVariableRef refVar = rPar.Get(0);
3111cdf0e10cSrcweir 	if( xInterface.is() )
3112cdf0e10cSrcweir 	{
3113cdf0e10cSrcweir 		Any aAny;
3114cdf0e10cSrcweir 		aAny <<= xInterface;
3115cdf0e10cSrcweir 
3116cdf0e10cSrcweir 		// SbUnoObject daraus basteln und zurueckliefern
3117cdf0e10cSrcweir 		SbUnoObjectRef xUnoObj = new SbUnoObject( aServiceName, aAny );
3118cdf0e10cSrcweir 		if( xUnoObj->getUnoAny().getValueType().getTypeClass() != TypeClass_VOID )
3119cdf0e10cSrcweir 		{
3120cdf0e10cSrcweir 			// Objekt zurueckliefern
3121cdf0e10cSrcweir 			refVar->PutObject( (SbUnoObject*)xUnoObj );
3122cdf0e10cSrcweir 		}
3123cdf0e10cSrcweir 		else
3124cdf0e10cSrcweir 		{
3125cdf0e10cSrcweir 			refVar->PutObject( NULL );
3126cdf0e10cSrcweir 		}
3127cdf0e10cSrcweir 	}
3128cdf0e10cSrcweir 	else
3129cdf0e10cSrcweir 	{
3130cdf0e10cSrcweir 		refVar->PutObject( NULL );
3131cdf0e10cSrcweir 	}
3132cdf0e10cSrcweir }
3133cdf0e10cSrcweir 
RTL_Impl_CreateUnoServiceWithArguments(StarBASIC * pBasic,SbxArray & rPar,sal_Bool bWrite)3134cdf0e10cSrcweir void RTL_Impl_CreateUnoServiceWithArguments( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite )
3135cdf0e10cSrcweir {
3136cdf0e10cSrcweir     (void)pBasic;
3137cdf0e10cSrcweir     (void)bWrite;
3138cdf0e10cSrcweir 
3139cdf0e10cSrcweir 	// Wir brauchen mindestens 2 Parameter
3140cdf0e10cSrcweir 	if ( rPar.Count() < 3 )
3141cdf0e10cSrcweir 	{
3142cdf0e10cSrcweir 		StarBASIC::Error( SbERR_BAD_ARGUMENT );
3143cdf0e10cSrcweir 		return;
3144cdf0e10cSrcweir 	}
3145cdf0e10cSrcweir 
3146cdf0e10cSrcweir 	// Klassen-Name der struct holen
3147cdf0e10cSrcweir 	String aServiceName = rPar.Get(1)->GetString();
3148cdf0e10cSrcweir 	Any aArgAsAny = sbxToUnoValue( rPar.Get(2),
3149cdf0e10cSrcweir 				getCppuType( (Sequence<Any>*)0 ) );
3150cdf0e10cSrcweir 	Sequence< Any > aArgs;
3151cdf0e10cSrcweir 	aArgAsAny >>= aArgs;
3152cdf0e10cSrcweir 
3153cdf0e10cSrcweir 	// Service suchen und instanzieren
3154cdf0e10cSrcweir 	Reference< XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory() );
3155cdf0e10cSrcweir 	Reference< XInterface > xInterface;
3156cdf0e10cSrcweir 	if ( xFactory.is() )
3157cdf0e10cSrcweir 	{
3158cdf0e10cSrcweir 		try
3159cdf0e10cSrcweir 		{
3160cdf0e10cSrcweir 			xInterface = xFactory->createInstanceWithArguments( aServiceName, aArgs );
3161cdf0e10cSrcweir 		}
3162cdf0e10cSrcweir 		catch( const Exception& )
3163cdf0e10cSrcweir 		{
3164cdf0e10cSrcweir             implHandleAnyException( ::cppu::getCaughtException() );
3165cdf0e10cSrcweir 		}
3166cdf0e10cSrcweir 	}
3167cdf0e10cSrcweir 
3168cdf0e10cSrcweir 	SbxVariableRef refVar = rPar.Get(0);
3169cdf0e10cSrcweir 	if( xInterface.is() )
3170cdf0e10cSrcweir 	{
3171cdf0e10cSrcweir 		Any aAny;
3172cdf0e10cSrcweir 		aAny <<= xInterface;
3173cdf0e10cSrcweir 
3174cdf0e10cSrcweir 		// SbUnoObject daraus basteln und zurueckliefern
3175cdf0e10cSrcweir 		SbUnoObjectRef xUnoObj = new SbUnoObject( aServiceName, aAny );
3176cdf0e10cSrcweir 		if( xUnoObj->getUnoAny().getValueType().getTypeClass() != TypeClass_VOID )
3177cdf0e10cSrcweir 		{
3178cdf0e10cSrcweir 			// Objekt zurueckliefern
3179cdf0e10cSrcweir 			refVar->PutObject( (SbUnoObject*)xUnoObj );
3180cdf0e10cSrcweir 		}
3181cdf0e10cSrcweir 		else
3182cdf0e10cSrcweir 		{
3183cdf0e10cSrcweir 			refVar->PutObject( NULL );
3184cdf0e10cSrcweir 		}
3185cdf0e10cSrcweir 	}
3186cdf0e10cSrcweir 	else
3187cdf0e10cSrcweir 	{
3188cdf0e10cSrcweir 		refVar->PutObject( NULL );
3189cdf0e10cSrcweir 	}
3190cdf0e10cSrcweir }
3191cdf0e10cSrcweir 
RTL_Impl_GetProcessServiceManager(StarBASIC * pBasic,SbxArray & rPar,sal_Bool bWrite)3192cdf0e10cSrcweir void RTL_Impl_GetProcessServiceManager( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite )
3193cdf0e10cSrcweir {
3194cdf0e10cSrcweir     (void)pBasic;
3195cdf0e10cSrcweir     (void)bWrite;
3196cdf0e10cSrcweir 
3197cdf0e10cSrcweir 	SbxVariableRef refVar = rPar.Get(0);
3198cdf0e10cSrcweir 
3199cdf0e10cSrcweir 	// Globalen Service-Manager holen
3200cdf0e10cSrcweir 	Reference< XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory() );
3201cdf0e10cSrcweir 	if( xFactory.is() )
3202cdf0e10cSrcweir 	{
3203cdf0e10cSrcweir 		Any aAny;
3204cdf0e10cSrcweir 		aAny <<= xFactory;
3205cdf0e10cSrcweir 
3206cdf0e10cSrcweir 		// SbUnoObject daraus basteln und zurueckliefern
3207cdf0e10cSrcweir 		SbUnoObjectRef xUnoObj = new SbUnoObject( String( RTL_CONSTASCII_USTRINGPARAM("ProcessServiceManager") ), aAny );
3208cdf0e10cSrcweir 		refVar->PutObject( (SbUnoObject*)xUnoObj );
3209cdf0e10cSrcweir 	}
3210cdf0e10cSrcweir 	else
3211cdf0e10cSrcweir 	{
3212cdf0e10cSrcweir 		refVar->PutObject( NULL );
3213cdf0e10cSrcweir 	}
3214cdf0e10cSrcweir }
3215cdf0e10cSrcweir 
RTL_Impl_HasInterfaces(StarBASIC * pBasic,SbxArray & rPar,sal_Bool bWrite)3216cdf0e10cSrcweir void RTL_Impl_HasInterfaces( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite )
3217cdf0e10cSrcweir {
3218cdf0e10cSrcweir     (void)pBasic;
3219cdf0e10cSrcweir     (void)bWrite;
3220cdf0e10cSrcweir 
3221cdf0e10cSrcweir 	// Wir brauchen mindestens 2 Parameter
3222cdf0e10cSrcweir 	sal_uInt16 nParCount = rPar.Count();
3223cdf0e10cSrcweir 	if( nParCount < 3 )
3224cdf0e10cSrcweir 	{
3225cdf0e10cSrcweir 		StarBASIC::Error( SbERR_BAD_ARGUMENT );
3226cdf0e10cSrcweir 		return;
3227cdf0e10cSrcweir 	}
3228cdf0e10cSrcweir 
3229cdf0e10cSrcweir 	// Variable fuer Rueckgabewert
3230cdf0e10cSrcweir 	SbxVariableRef refVar = rPar.Get(0);
3231cdf0e10cSrcweir 	refVar->PutBool( sal_False );
3232cdf0e10cSrcweir 
3233cdf0e10cSrcweir 	// Uno-Objekt holen
3234cdf0e10cSrcweir 	SbxBaseRef pObj = (SbxBase*)rPar.Get( 1 )->GetObject();
3235cdf0e10cSrcweir 	if( !(pObj && pObj->ISA(SbUnoObject)) )
3236cdf0e10cSrcweir 		return;
3237cdf0e10cSrcweir 	Any aAny = ((SbUnoObject*)(SbxBase*)pObj)->getUnoAny();
3238cdf0e10cSrcweir 	TypeClass eType = aAny.getValueType().getTypeClass();
3239cdf0e10cSrcweir 	if( eType != TypeClass_INTERFACE )
3240cdf0e10cSrcweir 		return;
3241cdf0e10cSrcweir 
3242cdf0e10cSrcweir 	// Interface aus dem Any besorgen
3243cdf0e10cSrcweir 	Reference< XInterface > x = *(Reference< XInterface >*)aAny.getValue();
3244cdf0e10cSrcweir 
3245cdf0e10cSrcweir 	// CoreReflection holen
3246cdf0e10cSrcweir 	Reference< XIdlReflection > xCoreReflection = getCoreReflection_Impl();
3247cdf0e10cSrcweir 	if( !xCoreReflection.is() )
3248cdf0e10cSrcweir 		return;
3249cdf0e10cSrcweir 
3250cdf0e10cSrcweir 	for( sal_uInt16 i = 2 ; i < nParCount ; i++ )
3251cdf0e10cSrcweir 	{
3252cdf0e10cSrcweir 		// Interface-Name der struct holen
3253cdf0e10cSrcweir 		String aIfaceName = rPar.Get( i )->GetString();
3254cdf0e10cSrcweir 
3255cdf0e10cSrcweir 		// Klasse suchen
3256cdf0e10cSrcweir 		Reference< XIdlClass > xClass = xCoreReflection->forName( aIfaceName );
3257cdf0e10cSrcweir 		if( !xClass.is() )
3258cdf0e10cSrcweir 			return;
3259cdf0e10cSrcweir 
3260cdf0e10cSrcweir 		// Pruefen, ob das Interface unterstuetzt wird
3261cdf0e10cSrcweir 		::rtl::OUString aClassName = xClass->getName();
3262cdf0e10cSrcweir 		Type aClassType( xClass->getTypeClass(), aClassName.getStr() );
3263cdf0e10cSrcweir 		if( !x->queryInterface( aClassType ).hasValue() )
3264cdf0e10cSrcweir 			return;
3265cdf0e10cSrcweir 	}
3266cdf0e10cSrcweir 
3267cdf0e10cSrcweir 	// Alles hat geklappt, dann sal_True liefern
3268cdf0e10cSrcweir 	refVar->PutBool( sal_True );
3269cdf0e10cSrcweir }
3270cdf0e10cSrcweir 
RTL_Impl_IsUnoStruct(StarBASIC * pBasic,SbxArray & rPar,sal_Bool bWrite)3271cdf0e10cSrcweir void RTL_Impl_IsUnoStruct( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite )
3272cdf0e10cSrcweir {
3273cdf0e10cSrcweir     (void)pBasic;
3274cdf0e10cSrcweir     (void)bWrite;
3275cdf0e10cSrcweir 
3276cdf0e10cSrcweir 	// Wir brauchen mindestens 1 Parameter
3277cdf0e10cSrcweir 	if ( rPar.Count() < 2 )
3278cdf0e10cSrcweir 	{
3279cdf0e10cSrcweir 		StarBASIC::Error( SbERR_BAD_ARGUMENT );
3280cdf0e10cSrcweir 		return;
3281cdf0e10cSrcweir 	}
3282cdf0e10cSrcweir 
3283cdf0e10cSrcweir 	// Variable fuer Rueckgabewert
3284cdf0e10cSrcweir 	SbxVariableRef refVar = rPar.Get(0);
3285cdf0e10cSrcweir 	refVar->PutBool( sal_False );
3286cdf0e10cSrcweir 
3287cdf0e10cSrcweir 	// Uno-Objekt holen
3288cdf0e10cSrcweir 	SbxVariableRef xParam = rPar.Get( 1 );
3289cdf0e10cSrcweir 	if( !xParam->IsObject() )
3290cdf0e10cSrcweir 		return;
3291cdf0e10cSrcweir 	SbxBaseRef pObj = (SbxBase*)rPar.Get( 1 )->GetObject();
3292cdf0e10cSrcweir 	if( !(pObj && pObj->ISA(SbUnoObject)) )
3293cdf0e10cSrcweir 		return;
3294cdf0e10cSrcweir 	Any aAny = ((SbUnoObject*)(SbxBase*)pObj)->getUnoAny();
3295cdf0e10cSrcweir 	TypeClass eType = aAny.getValueType().getTypeClass();
3296cdf0e10cSrcweir 	if( eType == TypeClass_STRUCT )
3297cdf0e10cSrcweir 		refVar->PutBool( sal_True );
3298cdf0e10cSrcweir }
3299cdf0e10cSrcweir 
3300cdf0e10cSrcweir 
RTL_Impl_EqualUnoObjects(StarBASIC * pBasic,SbxArray & rPar,sal_Bool bWrite)3301cdf0e10cSrcweir void RTL_Impl_EqualUnoObjects( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite )
3302cdf0e10cSrcweir {
3303cdf0e10cSrcweir     (void)pBasic;
3304cdf0e10cSrcweir     (void)bWrite;
3305cdf0e10cSrcweir 
3306cdf0e10cSrcweir 	if ( rPar.Count() < 3 )
3307cdf0e10cSrcweir 	{
3308cdf0e10cSrcweir 		StarBASIC::Error( SbERR_BAD_ARGUMENT );
3309cdf0e10cSrcweir 		return;
3310cdf0e10cSrcweir 	}
3311cdf0e10cSrcweir 
3312cdf0e10cSrcweir 	// Variable fuer Rueckgabewert
3313cdf0e10cSrcweir 	SbxVariableRef refVar = rPar.Get(0);
3314cdf0e10cSrcweir 	refVar->PutBool( sal_False );
3315cdf0e10cSrcweir 
3316cdf0e10cSrcweir 	// Uno-Objekte holen
3317cdf0e10cSrcweir 	SbxVariableRef xParam1 = rPar.Get( 1 );
3318cdf0e10cSrcweir 	if( !xParam1->IsObject() )
3319cdf0e10cSrcweir 		return;
3320cdf0e10cSrcweir 	SbxBaseRef pObj1 = (SbxBase*)xParam1->GetObject();
3321cdf0e10cSrcweir 	if( !(pObj1 && pObj1->ISA(SbUnoObject)) )
3322cdf0e10cSrcweir 		return;
3323cdf0e10cSrcweir 	Any aAny1 = ((SbUnoObject*)(SbxBase*)pObj1)->getUnoAny();
3324cdf0e10cSrcweir 	TypeClass eType1 = aAny1.getValueType().getTypeClass();
3325cdf0e10cSrcweir 	if( eType1 != TypeClass_INTERFACE )
3326cdf0e10cSrcweir 		return;
3327cdf0e10cSrcweir 	Reference< XInterface > x1;
3328cdf0e10cSrcweir 	aAny1 >>= x1;
3329cdf0e10cSrcweir 	//XInterfaceRef x1 = *(XInterfaceRef*)aAny1.get();
3330cdf0e10cSrcweir 
3331cdf0e10cSrcweir 	SbxVariableRef xParam2 = rPar.Get( 2 );
3332cdf0e10cSrcweir 	if( !xParam2->IsObject() )
3333cdf0e10cSrcweir 		return;
3334cdf0e10cSrcweir 	SbxBaseRef pObj2 = (SbxBase*)xParam2->GetObject();
3335cdf0e10cSrcweir 	if( !(pObj2 && pObj2->ISA(SbUnoObject)) )
3336cdf0e10cSrcweir 		return;
3337cdf0e10cSrcweir 	Any aAny2 = ((SbUnoObject*)(SbxBase*)pObj2)->getUnoAny();
3338cdf0e10cSrcweir 	TypeClass eType2 = aAny2.getValueType().getTypeClass();
3339cdf0e10cSrcweir 	if( eType2 != TypeClass_INTERFACE )
3340cdf0e10cSrcweir 		return;
3341cdf0e10cSrcweir 	Reference< XInterface > x2;
3342cdf0e10cSrcweir 	aAny2 >>= x2;
3343cdf0e10cSrcweir 	//XInterfaceRef x2 = *(XInterfaceRef*)aAny2.get();
3344cdf0e10cSrcweir 
3345cdf0e10cSrcweir 	if( x1 == x2 )
3346cdf0e10cSrcweir 		refVar->PutBool( sal_True );
3347cdf0e10cSrcweir }
3348cdf0e10cSrcweir 
3349cdf0e10cSrcweir typedef std::hash_map< ::rtl::OUString, std::vector< ::rtl::OUString >, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > ModuleHash;
3350cdf0e10cSrcweir 
3351cdf0e10cSrcweir 
3352cdf0e10cSrcweir // helper wrapper function to interact with TypeProvider and
3353cdf0e10cSrcweir // XTypeDescriptionEnumerationAccess.
3354cdf0e10cSrcweir // if it fails for whatever reason
3355cdf0e10cSrcweir // returned Reference<> be null e.g. .is() will be false
3356cdf0e10cSrcweir 
3357cdf0e10cSrcweir Reference< XTypeDescriptionEnumeration >
getTypeDescriptorEnumeration(const::rtl::OUString & sSearchRoot,const Sequence<TypeClass> & types,TypeDescriptionSearchDepth depth)3358cdf0e10cSrcweir getTypeDescriptorEnumeration( const ::rtl::OUString& sSearchRoot,
3359cdf0e10cSrcweir 	const Sequence< TypeClass >& types, TypeDescriptionSearchDepth depth )
3360cdf0e10cSrcweir {
3361cdf0e10cSrcweir 	Reference< XTypeDescriptionEnumeration > xEnum;
3362cdf0e10cSrcweir 	Reference< XTypeDescriptionEnumerationAccess> xTypeEnumAccess( getTypeProvider_Impl(), UNO_QUERY );
3363cdf0e10cSrcweir 	if ( xTypeEnumAccess.is() )
3364cdf0e10cSrcweir 	{
3365cdf0e10cSrcweir 		try
3366cdf0e10cSrcweir 		{
3367cdf0e10cSrcweir 			xEnum = xTypeEnumAccess->createTypeDescriptionEnumeration(
3368cdf0e10cSrcweir 				sSearchRoot, types, depth );
3369cdf0e10cSrcweir 		}
3370cdf0e10cSrcweir 		catch( NoSuchTypeNameException& /*nstne*/ ) {}
3371cdf0e10cSrcweir 		catch( InvalidTypeNameException& /*nstne*/ ) {}
3372cdf0e10cSrcweir 	}
3373cdf0e10cSrcweir 	return xEnum;
3374cdf0e10cSrcweir }
3375cdf0e10cSrcweir 
3376cdf0e10cSrcweir typedef std::hash_map< ::rtl::OUString, Any, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > VBAConstantsHash;
3377cdf0e10cSrcweir 
getVBAConstant(const String & rName)3378cdf0e10cSrcweir SbxVariable* getVBAConstant( const String& rName )
3379cdf0e10cSrcweir {
3380cdf0e10cSrcweir 	SbxVariable* pConst = NULL;
3381cdf0e10cSrcweir 	static VBAConstantsHash aConstCache;
3382cdf0e10cSrcweir 	static bool isInited = false;
3383cdf0e10cSrcweir 	if ( !isInited )
3384cdf0e10cSrcweir 	{
3385cdf0e10cSrcweir 		Sequence< TypeClass > types(1);
3386cdf0e10cSrcweir 		types[ 0 ] = TypeClass_CONSTANTS;
3387cdf0e10cSrcweir 		Reference< XTypeDescriptionEnumeration > xEnum = getTypeDescriptorEnumeration( defaultNameSpace, types, TypeDescriptionSearchDepth_INFINITE  );
3388cdf0e10cSrcweir 
3389cdf0e10cSrcweir 		if ( !xEnum.is() )
3390cdf0e10cSrcweir 			return NULL;
3391cdf0e10cSrcweir 
3392cdf0e10cSrcweir 		while ( xEnum->hasMoreElements() )
3393cdf0e10cSrcweir 		{
3394cdf0e10cSrcweir 			Reference< XConstantsTypeDescription > xConstants( xEnum->nextElement(), UNO_QUERY );
3395cdf0e10cSrcweir 			if ( xConstants.is() )
3396cdf0e10cSrcweir 			{
3397cdf0e10cSrcweir 				Sequence< Reference< XConstantTypeDescription > > aConsts = xConstants->getConstants();
3398cdf0e10cSrcweir 				Reference< XConstantTypeDescription >* pSrc = aConsts.getArray();
3399cdf0e10cSrcweir 				sal_Int32 nLen = aConsts.getLength();
3400cdf0e10cSrcweir 				for ( sal_Int32 index =0;  index<nLen; ++pSrc, ++index )
3401cdf0e10cSrcweir 				{
3402cdf0e10cSrcweir 					Reference< XConstantTypeDescription >& rXConst =
3403cdf0e10cSrcweir 						*pSrc;
3404cdf0e10cSrcweir 					::rtl::OUString sFullName = rXConst->getName();
3405cdf0e10cSrcweir 					sal_Int32 indexLastDot = sFullName.lastIndexOf('.');
3406cdf0e10cSrcweir 					::rtl::OUString sLeafName;
3407cdf0e10cSrcweir 					if ( indexLastDot > -1 )
3408cdf0e10cSrcweir 						sLeafName = sFullName.copy( indexLastDot + 1);
3409cdf0e10cSrcweir 					aConstCache[ sLeafName.toAsciiLowerCase() ] = rXConst->getConstantValue();
3410cdf0e10cSrcweir 				}
3411cdf0e10cSrcweir 			}
3412cdf0e10cSrcweir 		}
3413cdf0e10cSrcweir 		isInited = true;
3414cdf0e10cSrcweir 	}
3415cdf0e10cSrcweir 	::rtl::OUString sKey( rName );
3416cdf0e10cSrcweir 	VBAConstantsHash::const_iterator it = aConstCache.find( sKey.toAsciiLowerCase() );
3417cdf0e10cSrcweir 	if ( it != aConstCache.end() )
3418cdf0e10cSrcweir 	{
3419cdf0e10cSrcweir 		pConst = new SbxVariable( SbxVARIANT );
3420cdf0e10cSrcweir 		pConst->SetName( rName );
3421cdf0e10cSrcweir 		unoToSbxValue( pConst, it->second );
3422cdf0e10cSrcweir 	}
3423cdf0e10cSrcweir 	return pConst;
3424cdf0e10cSrcweir }
3425cdf0e10cSrcweir 
3426cdf0e10cSrcweir // Funktion, um einen globalen Bezeichner im
3427cdf0e10cSrcweir // UnoScope zu suchen und fuer Sbx zu wrappen
findUnoClass(const String & rName)3428cdf0e10cSrcweir SbUnoClass* findUnoClass( const String& rName )
3429cdf0e10cSrcweir {
3430cdf0e10cSrcweir     // #105550 Check if module exists
3431cdf0e10cSrcweir 	SbUnoClass* pUnoClass = NULL;
3432cdf0e10cSrcweir 
3433cdf0e10cSrcweir     Reference< XHierarchicalNameAccess > xTypeAccess = getTypeProvider_Impl();
3434cdf0e10cSrcweir     if( xTypeAccess->hasByHierarchicalName( rName ) )
3435cdf0e10cSrcweir     {
3436cdf0e10cSrcweir         Any aRet = xTypeAccess->getByHierarchicalName( rName );
3437cdf0e10cSrcweir 		Reference< XTypeDescription > xTypeDesc;
3438cdf0e10cSrcweir 		aRet >>= xTypeDesc;
3439cdf0e10cSrcweir 
3440cdf0e10cSrcweir         if( xTypeDesc.is() )
3441cdf0e10cSrcweir         {
3442cdf0e10cSrcweir             TypeClass eTypeClass = xTypeDesc->getTypeClass();
3443cdf0e10cSrcweir             if( eTypeClass == TypeClass_MODULE || eTypeClass == TypeClass_CONSTANTS )
3444cdf0e10cSrcweir         		pUnoClass = new SbUnoClass( rName );
3445cdf0e10cSrcweir         }
3446cdf0e10cSrcweir     }
3447cdf0e10cSrcweir 	return pUnoClass;
3448cdf0e10cSrcweir }
3449cdf0e10cSrcweir 
Find(const XubString & rName,SbxClassType t)3450cdf0e10cSrcweir SbxVariable* SbUnoClass::Find( const XubString& rName, SbxClassType t )
3451cdf0e10cSrcweir {
3452cdf0e10cSrcweir     (void)t;
3453cdf0e10cSrcweir 
3454cdf0e10cSrcweir 	SbxVariable* pRes = SbxObject::Find( rName, SbxCLASS_VARIABLE );
3455cdf0e10cSrcweir 
3456cdf0e10cSrcweir 	// Wenn nichts gefunden wird, ist das Sub-Modul noch nicht bekannt
3457cdf0e10cSrcweir 	if( !pRes )
3458cdf0e10cSrcweir 	{
3459cdf0e10cSrcweir 		// Wenn es schon eine Klasse ist, nach einen Feld fragen
3460cdf0e10cSrcweir 		if( m_xClass.is() )
3461cdf0e10cSrcweir 		{
3462cdf0e10cSrcweir 			// Ist es ein Field
3463cdf0e10cSrcweir 			::rtl::OUString aUStr( rName );
3464cdf0e10cSrcweir 			Reference< XIdlField > xField = m_xClass->getField( aUStr );
3465cdf0e10cSrcweir 			Reference< XIdlClass > xClass;
3466cdf0e10cSrcweir 			if( xField.is() )
3467cdf0e10cSrcweir 			{
3468cdf0e10cSrcweir 				try
3469cdf0e10cSrcweir 				{
3470cdf0e10cSrcweir 					Any aAny;
3471cdf0e10cSrcweir 					aAny = xField->get( aAny );
3472cdf0e10cSrcweir 
3473cdf0e10cSrcweir 					// Nach Sbx wandeln
3474cdf0e10cSrcweir 					pRes = new SbxVariable( SbxVARIANT );
3475cdf0e10cSrcweir 					pRes->SetName( rName );
3476cdf0e10cSrcweir 					unoToSbxValue( pRes, aAny );
3477cdf0e10cSrcweir 				}
3478cdf0e10cSrcweir 		        catch( const Exception& )
3479cdf0e10cSrcweir 		        {
3480cdf0e10cSrcweir                     implHandleAnyException( ::cppu::getCaughtException() );
3481cdf0e10cSrcweir 		        }
3482cdf0e10cSrcweir 			}
3483cdf0e10cSrcweir 		}
3484cdf0e10cSrcweir 		else
3485cdf0e10cSrcweir 		{
3486cdf0e10cSrcweir 			// Vollqualifizierten Namen erweitern
3487cdf0e10cSrcweir 			String aNewName = GetName();
3488cdf0e10cSrcweir 			aNewName.AppendAscii( "." );
3489cdf0e10cSrcweir 			aNewName += rName;
3490cdf0e10cSrcweir 
3491cdf0e10cSrcweir 			// CoreReflection holen
3492cdf0e10cSrcweir 			Reference< XIdlReflection > xCoreReflection = getCoreReflection_Impl();
3493cdf0e10cSrcweir 			if( xCoreReflection.is() )
3494cdf0e10cSrcweir 			{
3495cdf0e10cSrcweir 				// Ist es eine Konstante?
3496cdf0e10cSrcweir 				Reference< XHierarchicalNameAccess > xHarryName( xCoreReflection, UNO_QUERY );
3497cdf0e10cSrcweir 				if( xHarryName.is() )
3498cdf0e10cSrcweir 				{
3499cdf0e10cSrcweir 					try
3500cdf0e10cSrcweir 					{
3501cdf0e10cSrcweir 						Any aValue = xHarryName->getByHierarchicalName( aNewName );
3502cdf0e10cSrcweir 						TypeClass eType = aValue.getValueType().getTypeClass();
3503cdf0e10cSrcweir 
3504cdf0e10cSrcweir 						// Interface gefunden? Dann ist es eine Klasse
3505cdf0e10cSrcweir 						if( eType == TypeClass_INTERFACE )
3506cdf0e10cSrcweir 						{
3507cdf0e10cSrcweir 							Reference< XInterface > xIface = *(Reference< XInterface >*)aValue.getValue();
3508cdf0e10cSrcweir 							Reference< XIdlClass > xClass( xIface, UNO_QUERY );
3509cdf0e10cSrcweir 							if( xClass.is() )
3510cdf0e10cSrcweir 							{
3511cdf0e10cSrcweir 								pRes = new SbxVariable( SbxVARIANT );
3512cdf0e10cSrcweir 								SbxObjectRef xWrapper = (SbxObject*)new SbUnoClass( aNewName, xClass );
3513cdf0e10cSrcweir 								pRes->PutObject( xWrapper );
3514cdf0e10cSrcweir 							}
3515cdf0e10cSrcweir 						}
3516cdf0e10cSrcweir 						else
3517cdf0e10cSrcweir 						{
3518cdf0e10cSrcweir 							pRes = new SbxVariable( SbxVARIANT );
3519cdf0e10cSrcweir 							unoToSbxValue( pRes, aValue );
3520cdf0e10cSrcweir 						}
3521cdf0e10cSrcweir 					}
3522cdf0e10cSrcweir 					catch( NoSuchElementException& e1 )
3523cdf0e10cSrcweir 					{
3524cdf0e10cSrcweir 						String aMsg = implGetExceptionMsg( e1 );
3525cdf0e10cSrcweir 					}
3526cdf0e10cSrcweir 				}
3527cdf0e10cSrcweir 
3528cdf0e10cSrcweir 				// Sonst wieder als Klasse annehmen
3529cdf0e10cSrcweir 				if( !pRes )
3530cdf0e10cSrcweir 				{
3531cdf0e10cSrcweir                     SbUnoClass* pNewClass = findUnoClass( aNewName );
3532cdf0e10cSrcweir 					if( pNewClass )
3533cdf0e10cSrcweir 					{
3534cdf0e10cSrcweir 						pRes = new SbxVariable( SbxVARIANT );
3535cdf0e10cSrcweir 						SbxObjectRef xWrapper = (SbxObject*)pNewClass;
3536cdf0e10cSrcweir 						pRes->PutObject( xWrapper );
3537cdf0e10cSrcweir 					}
3538cdf0e10cSrcweir 				}
3539cdf0e10cSrcweir 
3540cdf0e10cSrcweir 				// An UNO service?
3541cdf0e10cSrcweir 				if( !pRes )
3542cdf0e10cSrcweir 				{
3543cdf0e10cSrcweir 					SbUnoService* pUnoService = findUnoService( aNewName );
3544cdf0e10cSrcweir 					if( pUnoService )
3545cdf0e10cSrcweir 					{
3546cdf0e10cSrcweir 						pRes = new SbxVariable( SbxVARIANT );
3547cdf0e10cSrcweir 						SbxObjectRef xWrapper = (SbxObject*)pUnoService;
3548cdf0e10cSrcweir 						pRes->PutObject( xWrapper );
3549cdf0e10cSrcweir 					}
3550cdf0e10cSrcweir 				}
3551cdf0e10cSrcweir 
3552cdf0e10cSrcweir 				// An UNO singleton?
3553cdf0e10cSrcweir 				if( !pRes )
3554cdf0e10cSrcweir 				{
3555cdf0e10cSrcweir 					SbUnoSingleton* pUnoSingleton = findUnoSingleton( aNewName );
3556cdf0e10cSrcweir 					if( pUnoSingleton )
3557cdf0e10cSrcweir 					{
3558cdf0e10cSrcweir 						pRes = new SbxVariable( SbxVARIANT );
3559cdf0e10cSrcweir 						SbxObjectRef xWrapper = (SbxObject*)pUnoSingleton;
3560cdf0e10cSrcweir 						pRes->PutObject( xWrapper );
3561cdf0e10cSrcweir 					}
3562cdf0e10cSrcweir 				}
3563cdf0e10cSrcweir 			}
3564cdf0e10cSrcweir 		}
3565cdf0e10cSrcweir 
3566cdf0e10cSrcweir 		if( pRes )
3567cdf0e10cSrcweir 		{
3568cdf0e10cSrcweir 			pRes->SetName( rName );
3569cdf0e10cSrcweir 
3570cdf0e10cSrcweir 			// Variable einfuegen, damit sie spaeter im Find gefunden wird
3571cdf0e10cSrcweir 			QuickInsert( pRes );
3572cdf0e10cSrcweir 
3573cdf0e10cSrcweir 			// Uns selbst gleich wieder als Listener rausnehmen,
3574cdf0e10cSrcweir 			// die Werte sind alle konstant
3575cdf0e10cSrcweir 			if( pRes->IsBroadcaster() )
3576cdf0e10cSrcweir 				EndListening( pRes->GetBroadcaster(), sal_True );
3577cdf0e10cSrcweir 		}
3578cdf0e10cSrcweir 	}
3579cdf0e10cSrcweir 	return pRes;
3580cdf0e10cSrcweir }
3581cdf0e10cSrcweir 
3582cdf0e10cSrcweir 
findUnoService(const String & rName)3583cdf0e10cSrcweir SbUnoService* findUnoService( const String& rName )
3584cdf0e10cSrcweir {
3585cdf0e10cSrcweir 	SbUnoService* pSbUnoService = NULL;
3586cdf0e10cSrcweir 
3587cdf0e10cSrcweir     Reference< XHierarchicalNameAccess > xTypeAccess = getTypeProvider_Impl();
3588cdf0e10cSrcweir     if( xTypeAccess->hasByHierarchicalName( rName ) )
3589cdf0e10cSrcweir     {
3590cdf0e10cSrcweir         Any aRet = xTypeAccess->getByHierarchicalName( rName );
3591cdf0e10cSrcweir 	    Reference< XTypeDescription > xTypeDesc;
3592cdf0e10cSrcweir         aRet >>= xTypeDesc;
3593cdf0e10cSrcweir 
3594cdf0e10cSrcweir         if( xTypeDesc.is() )
3595cdf0e10cSrcweir         {
3596cdf0e10cSrcweir             TypeClass eTypeClass = xTypeDesc->getTypeClass();
3597cdf0e10cSrcweir             if( eTypeClass == TypeClass_SERVICE )
3598cdf0e10cSrcweir 			{
3599cdf0e10cSrcweir 				Reference< XServiceTypeDescription2 > xServiceTypeDesc( xTypeDesc, UNO_QUERY );
3600cdf0e10cSrcweir 				if( xServiceTypeDesc.is() )
3601cdf0e10cSrcweir         			pSbUnoService = new SbUnoService( rName, xServiceTypeDesc );
3602cdf0e10cSrcweir 			}
3603cdf0e10cSrcweir         }
3604cdf0e10cSrcweir     }
3605cdf0e10cSrcweir 	return pSbUnoService;
3606cdf0e10cSrcweir }
3607cdf0e10cSrcweir 
Find(const String & rName,SbxClassType)3608cdf0e10cSrcweir SbxVariable* SbUnoService::Find( const String& rName, SbxClassType )
3609cdf0e10cSrcweir {
3610cdf0e10cSrcweir 	SbxVariable* pRes = SbxObject::Find( rName, SbxCLASS_METHOD );
3611cdf0e10cSrcweir 
3612cdf0e10cSrcweir 	if( !pRes )
3613cdf0e10cSrcweir 	{
3614cdf0e10cSrcweir 		// Wenn es schon eine Klasse ist, nach einen Feld fragen
3615cdf0e10cSrcweir 		if( m_bNeedsInit && m_xServiceTypeDesc.is() )
3616cdf0e10cSrcweir 		{
3617cdf0e10cSrcweir 			m_bNeedsInit = false;
3618cdf0e10cSrcweir 
3619cdf0e10cSrcweir 			Sequence< Reference< XServiceConstructorDescription > > aSCDSeq = m_xServiceTypeDesc->getConstructors();
3620cdf0e10cSrcweir 			const Reference< XServiceConstructorDescription >* pCtorSeq = aSCDSeq.getConstArray();
3621cdf0e10cSrcweir 			int nCtorCount = aSCDSeq.getLength();
3622cdf0e10cSrcweir 			for( int i = 0 ; i < nCtorCount ; ++i )
3623cdf0e10cSrcweir 			{
3624cdf0e10cSrcweir 				Reference< XServiceConstructorDescription > xCtor = pCtorSeq[i];
3625cdf0e10cSrcweir 
3626cdf0e10cSrcweir 				String aName( xCtor->getName() );
3627cdf0e10cSrcweir 				if( !aName.Len() )
3628cdf0e10cSrcweir 				{
3629cdf0e10cSrcweir 					if( xCtor->isDefaultConstructor() )
3630cdf0e10cSrcweir 						aName = String::CreateFromAscii( "create" );
3631cdf0e10cSrcweir 				}
3632cdf0e10cSrcweir 
3633cdf0e10cSrcweir 				if( aName.Len() )
3634cdf0e10cSrcweir 				{
3635cdf0e10cSrcweir 					// Create and insert SbUnoServiceCtor
3636cdf0e10cSrcweir 					SbxVariableRef xSbCtorRef = new SbUnoServiceCtor( aName, xCtor );
3637cdf0e10cSrcweir 					QuickInsert( (SbxVariable*)xSbCtorRef );
3638cdf0e10cSrcweir 				}
3639cdf0e10cSrcweir 			}
3640cdf0e10cSrcweir 
3641cdf0e10cSrcweir 			pRes = SbxObject::Find( rName, SbxCLASS_METHOD );
3642cdf0e10cSrcweir 		}
3643cdf0e10cSrcweir 	}
3644cdf0e10cSrcweir 
3645cdf0e10cSrcweir 	return pRes;
3646cdf0e10cSrcweir }
3647cdf0e10cSrcweir 
SFX_NOTIFY(SfxBroadcaster & rBC,const TypeId & rBCType,const SfxHint & rHint,const TypeId & rHintType)3648cdf0e10cSrcweir void SbUnoService::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
3649cdf0e10cSrcweir 						   const SfxHint& rHint, const TypeId& rHintType )
3650cdf0e10cSrcweir {
3651cdf0e10cSrcweir 	const SbxHint* pHint = PTR_CAST(SbxHint,&rHint);
3652cdf0e10cSrcweir 	if( pHint )
3653cdf0e10cSrcweir 	{
3654cdf0e10cSrcweir 		SbxVariable* pVar = pHint->GetVar();
3655cdf0e10cSrcweir 		SbxArray* pParams = pVar->GetParameters();
3656cdf0e10cSrcweir 		SbUnoServiceCtor* pUnoCtor = PTR_CAST(SbUnoServiceCtor,pVar);
3657cdf0e10cSrcweir 		if( pUnoCtor && pHint->GetId() == SBX_HINT_DATAWANTED )
3658cdf0e10cSrcweir 		{
3659cdf0e10cSrcweir 			// Parameter count -1 because of Param0 == this
3660cdf0e10cSrcweir 			sal_uInt32 nParamCount = pParams ? ((sal_uInt32)pParams->Count() - 1) : 0;
3661cdf0e10cSrcweir 			Sequence<Any> args;
3662cdf0e10cSrcweir 			sal_Bool bOutParams = sal_False;
3663cdf0e10cSrcweir 
3664cdf0e10cSrcweir 			Reference< XServiceConstructorDescription > xCtor = pUnoCtor->getServiceCtorDesc();
3665cdf0e10cSrcweir 			Sequence< Reference< XParameter > > aParameterSeq = xCtor->getParameters();
3666cdf0e10cSrcweir 			const Reference< XParameter >* pParameterSeq = aParameterSeq.getConstArray();
3667cdf0e10cSrcweir 			sal_uInt32 nUnoParamCount = aParameterSeq.getLength();
3668cdf0e10cSrcweir 
3669cdf0e10cSrcweir 			// Default: Ignore not needed parameters
3670cdf0e10cSrcweir 			bool bParameterError = false;
3671cdf0e10cSrcweir 
3672cdf0e10cSrcweir 			// Is the last parameter a rest parameter?
3673cdf0e10cSrcweir 			bool bRestParameterMode = false;
3674cdf0e10cSrcweir 			if( nUnoParamCount > 0 )
3675cdf0e10cSrcweir 			{
3676cdf0e10cSrcweir 				Reference< XParameter > xLastParam = pParameterSeq[ nUnoParamCount - 1 ];
3677cdf0e10cSrcweir 				if( xLastParam.is() )
3678cdf0e10cSrcweir 				{
3679cdf0e10cSrcweir 					if( xLastParam->isRestParameter() )
3680cdf0e10cSrcweir 						bRestParameterMode = true;
3681cdf0e10cSrcweir 				}
3682cdf0e10cSrcweir 			}
3683cdf0e10cSrcweir 
3684cdf0e10cSrcweir 			// Too many parameters with context as first parameter?
3685cdf0e10cSrcweir 			sal_uInt16 nSbxParameterOffset = 1;
3686cdf0e10cSrcweir 			sal_uInt16 nParameterOffsetByContext = 0;
3687cdf0e10cSrcweir 			Reference < XComponentContext > xFirstParamContext;
3688cdf0e10cSrcweir 			if( nParamCount > nUnoParamCount )
3689cdf0e10cSrcweir 			{
3690cdf0e10cSrcweir 				// Check if first parameter is a context and use it
3691cdf0e10cSrcweir 				// then in createInstanceWithArgumentsAndContext
3692cdf0e10cSrcweir 				Any aArg0 = sbxToUnoValue( pParams->Get( nSbxParameterOffset ) );
3693cdf0e10cSrcweir 				if( (aArg0 >>= xFirstParamContext) && xFirstParamContext.is() )
3694cdf0e10cSrcweir 					nParameterOffsetByContext = 1;
3695cdf0e10cSrcweir 			}
3696cdf0e10cSrcweir 
3697cdf0e10cSrcweir 			sal_uInt32 nEffectiveParamCount = nParamCount - nParameterOffsetByContext;
3698cdf0e10cSrcweir 			sal_uInt32 nAllocParamCount = nEffectiveParamCount;
3699cdf0e10cSrcweir 			if( nEffectiveParamCount > nUnoParamCount )
3700cdf0e10cSrcweir 			{
3701cdf0e10cSrcweir 				if( !bRestParameterMode )
3702cdf0e10cSrcweir 				{
3703cdf0e10cSrcweir 					nEffectiveParamCount = nUnoParamCount;
3704cdf0e10cSrcweir 					nAllocParamCount = nUnoParamCount;
3705cdf0e10cSrcweir 				}
3706cdf0e10cSrcweir 			}
3707cdf0e10cSrcweir 			// Not enough parameters?
3708cdf0e10cSrcweir 			else if( nUnoParamCount > nEffectiveParamCount )
3709cdf0e10cSrcweir 			{
3710cdf0e10cSrcweir 				// RestParameterMode only helps if one (the last) parameter is missing
3711cdf0e10cSrcweir 				int nDiff = nUnoParamCount - nEffectiveParamCount;
3712cdf0e10cSrcweir 				if( !bRestParameterMode || nDiff > 1 )
3713cdf0e10cSrcweir 				{
3714cdf0e10cSrcweir 					bParameterError = true;
3715cdf0e10cSrcweir 					StarBASIC::Error( SbERR_NOT_OPTIONAL );
3716cdf0e10cSrcweir 				}
3717cdf0e10cSrcweir 			}
3718cdf0e10cSrcweir 
3719cdf0e10cSrcweir 			if( !bParameterError )
3720cdf0e10cSrcweir 			{
3721cdf0e10cSrcweir 				if( nAllocParamCount > 0 )
3722cdf0e10cSrcweir 				{
3723cdf0e10cSrcweir 					args.realloc( nAllocParamCount );
3724cdf0e10cSrcweir 					Any* pAnyArgs = args.getArray();
3725cdf0e10cSrcweir 					for( sal_uInt32 i = 0 ; i < nEffectiveParamCount ; i++ )
3726cdf0e10cSrcweir 					{
3727cdf0e10cSrcweir 						sal_uInt16 iSbx = (sal_uInt16)(i + nSbxParameterOffset + nParameterOffsetByContext);
3728cdf0e10cSrcweir 
3729cdf0e10cSrcweir 						// bRestParameterMode allows nEffectiveParamCount > nUnoParamCount
3730cdf0e10cSrcweir 						Reference< XParameter > xParam;
3731cdf0e10cSrcweir 						if( i < nUnoParamCount )
3732cdf0e10cSrcweir 						{
3733cdf0e10cSrcweir 							xParam = pParameterSeq[i];
3734cdf0e10cSrcweir 							if( !xParam.is() )
3735cdf0e10cSrcweir 								continue;
3736cdf0e10cSrcweir 
3737cdf0e10cSrcweir 							Reference< XTypeDescription > xParamTypeDesc = xParam->getType();
3738cdf0e10cSrcweir 							if( !xParamTypeDesc.is() )
3739cdf0e10cSrcweir 								continue;
3740cdf0e10cSrcweir 							com::sun::star::uno::Type aType( xParamTypeDesc->getTypeClass(), xParamTypeDesc->getName() );
3741cdf0e10cSrcweir 
3742cdf0e10cSrcweir 							// sbx paramter needs offset 1
3743cdf0e10cSrcweir 							pAnyArgs[i] = sbxToUnoValue( pParams->Get( iSbx ), aType );
3744cdf0e10cSrcweir 
3745cdf0e10cSrcweir 							// Check for out parameter if not already done
3746cdf0e10cSrcweir 							if( !bOutParams )
3747cdf0e10cSrcweir 							{
3748cdf0e10cSrcweir 								if( xParam->isOut() )
3749cdf0e10cSrcweir 									bOutParams = sal_True;
3750cdf0e10cSrcweir 							}
3751cdf0e10cSrcweir 						}
3752cdf0e10cSrcweir 						else
3753cdf0e10cSrcweir 						{
3754cdf0e10cSrcweir 							pAnyArgs[i] = sbxToUnoValue( pParams->Get( iSbx ) );
3755cdf0e10cSrcweir 						}
3756cdf0e10cSrcweir 					}
3757cdf0e10cSrcweir 				}
3758cdf0e10cSrcweir 
3759cdf0e10cSrcweir 				// "Call" ctor using createInstanceWithArgumentsAndContext
3760cdf0e10cSrcweir 				Reference < XComponentContext > xContext;
3761cdf0e10cSrcweir 				if( xFirstParamContext.is() )
3762cdf0e10cSrcweir 				{
3763cdf0e10cSrcweir 					xContext = xFirstParamContext;
3764cdf0e10cSrcweir 				}
3765cdf0e10cSrcweir 				else
3766cdf0e10cSrcweir 				{
3767cdf0e10cSrcweir 					Reference < XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
3768cdf0e10cSrcweir 					xContext.set( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" )) ), UNO_QUERY_THROW );
3769cdf0e10cSrcweir 				}
3770cdf0e10cSrcweir 				Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() );
3771cdf0e10cSrcweir 
3772cdf0e10cSrcweir 				Any aRetAny;
3773cdf0e10cSrcweir 				if( xServiceMgr.is() )
3774cdf0e10cSrcweir 				{
3775cdf0e10cSrcweir 					String aServiceName = GetName();
3776cdf0e10cSrcweir 					Reference < XInterface > xRet;
3777cdf0e10cSrcweir 					try
3778cdf0e10cSrcweir 					{
3779cdf0e10cSrcweir 						xRet = xServiceMgr->createInstanceWithArgumentsAndContext( aServiceName, args, xContext );
3780cdf0e10cSrcweir 					}
3781cdf0e10cSrcweir 					catch( const Exception& )
3782cdf0e10cSrcweir 					{
3783cdf0e10cSrcweir 						implHandleAnyException( ::cppu::getCaughtException() );
3784cdf0e10cSrcweir 					}
3785cdf0e10cSrcweir 					aRetAny <<= xRet;
3786cdf0e10cSrcweir 				}
3787cdf0e10cSrcweir 				unoToSbxValue( pVar, aRetAny );
3788cdf0e10cSrcweir 
3789cdf0e10cSrcweir 				// Copy back out parameters?
3790cdf0e10cSrcweir 				if( bOutParams )
3791cdf0e10cSrcweir 				{
3792cdf0e10cSrcweir 					const Any* pAnyArgs = args.getConstArray();
3793cdf0e10cSrcweir 
3794cdf0e10cSrcweir 					for( sal_uInt32 j = 0 ; j < nUnoParamCount ; j++ )
3795cdf0e10cSrcweir 					{
3796cdf0e10cSrcweir 						Reference< XParameter > xParam = pParameterSeq[j];
3797cdf0e10cSrcweir 						if( !xParam.is() )
3798cdf0e10cSrcweir 							continue;
3799cdf0e10cSrcweir 
3800cdf0e10cSrcweir 						if( xParam->isOut() )
3801cdf0e10cSrcweir 							unoToSbxValue( (SbxVariable*)pParams->Get( (sal_uInt16)(j+1) ), pAnyArgs[ j ] );
3802cdf0e10cSrcweir 					}
3803cdf0e10cSrcweir 				}
3804cdf0e10cSrcweir 			}
3805cdf0e10cSrcweir 		}
3806cdf0e10cSrcweir 		else
3807cdf0e10cSrcweir 			SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
3808cdf0e10cSrcweir 	}
3809cdf0e10cSrcweir }
3810cdf0e10cSrcweir 
3811cdf0e10cSrcweir 
3812cdf0e10cSrcweir 
3813cdf0e10cSrcweir static SbUnoServiceCtor* pFirstCtor = NULL;
3814cdf0e10cSrcweir 
clearUnoServiceCtors(void)3815cdf0e10cSrcweir void clearUnoServiceCtors( void )
3816cdf0e10cSrcweir {
3817cdf0e10cSrcweir 	SbUnoServiceCtor* pCtor = pFirstCtor;
3818cdf0e10cSrcweir 	while( pCtor )
3819cdf0e10cSrcweir 	{
3820cdf0e10cSrcweir 		pCtor->SbxValue::Clear();
3821cdf0e10cSrcweir 		pCtor = pCtor->pNext;
3822cdf0e10cSrcweir 	}
3823cdf0e10cSrcweir }
3824cdf0e10cSrcweir 
SbUnoServiceCtor(const String & aName_,Reference<XServiceConstructorDescription> xServiceCtorDesc)3825cdf0e10cSrcweir SbUnoServiceCtor::SbUnoServiceCtor( const String& aName_, Reference< XServiceConstructorDescription > xServiceCtorDesc )
3826cdf0e10cSrcweir 	: SbxMethod( aName_, SbxOBJECT )
3827cdf0e10cSrcweir 	, m_xServiceCtorDesc( xServiceCtorDesc )
3828cdf0e10cSrcweir {
3829cdf0e10cSrcweir }
3830cdf0e10cSrcweir 
~SbUnoServiceCtor()3831cdf0e10cSrcweir SbUnoServiceCtor::~SbUnoServiceCtor()
3832cdf0e10cSrcweir {
3833cdf0e10cSrcweir }
3834cdf0e10cSrcweir 
GetInfo()3835cdf0e10cSrcweir SbxInfo* SbUnoServiceCtor::GetInfo()
3836cdf0e10cSrcweir {
3837cdf0e10cSrcweir 	SbxInfo* pRet = NULL;
3838cdf0e10cSrcweir 
3839cdf0e10cSrcweir 	return pRet;
3840cdf0e10cSrcweir }
3841cdf0e10cSrcweir 
3842cdf0e10cSrcweir 
findUnoSingleton(const String & rName)3843cdf0e10cSrcweir SbUnoSingleton* findUnoSingleton( const String& rName )
3844cdf0e10cSrcweir {
3845cdf0e10cSrcweir 	SbUnoSingleton* pSbUnoSingleton = NULL;
3846cdf0e10cSrcweir 
3847cdf0e10cSrcweir     Reference< XHierarchicalNameAccess > xTypeAccess = getTypeProvider_Impl();
3848cdf0e10cSrcweir     if( xTypeAccess->hasByHierarchicalName( rName ) )
3849cdf0e10cSrcweir     {
3850cdf0e10cSrcweir         Any aRet = xTypeAccess->getByHierarchicalName( rName );
3851cdf0e10cSrcweir 	    Reference< XTypeDescription > xTypeDesc;
3852cdf0e10cSrcweir         aRet >>= xTypeDesc;
3853cdf0e10cSrcweir 
3854cdf0e10cSrcweir         if( xTypeDesc.is() )
3855cdf0e10cSrcweir         {
3856cdf0e10cSrcweir             TypeClass eTypeClass = xTypeDesc->getTypeClass();
3857cdf0e10cSrcweir             if( eTypeClass == TypeClass_SINGLETON )
3858cdf0e10cSrcweir 			{
3859cdf0e10cSrcweir 				Reference< XSingletonTypeDescription > xSingletonTypeDesc( xTypeDesc, UNO_QUERY );
3860cdf0e10cSrcweir 				if( xSingletonTypeDesc.is() )
3861cdf0e10cSrcweir         			pSbUnoSingleton = new SbUnoSingleton( rName, xSingletonTypeDesc );
3862cdf0e10cSrcweir 			}
3863cdf0e10cSrcweir         }
3864cdf0e10cSrcweir     }
3865cdf0e10cSrcweir 	return pSbUnoSingleton;
3866cdf0e10cSrcweir }
3867cdf0e10cSrcweir 
SbUnoSingleton(const String & aName_,const Reference<XSingletonTypeDescription> & xSingletonTypeDesc)3868cdf0e10cSrcweir SbUnoSingleton::SbUnoSingleton( const String& aName_,
3869cdf0e10cSrcweir 	const Reference< XSingletonTypeDescription >& xSingletonTypeDesc )
3870cdf0e10cSrcweir 		: SbxObject( aName_ )
3871cdf0e10cSrcweir 		, m_xSingletonTypeDesc( xSingletonTypeDesc )
3872cdf0e10cSrcweir {
3873cdf0e10cSrcweir 	SbxVariableRef xGetMethodRef =
3874cdf0e10cSrcweir 		new SbxMethod( String( RTL_CONSTASCII_USTRINGPARAM( "get" ) ), SbxOBJECT );
3875cdf0e10cSrcweir 	QuickInsert( (SbxVariable*)xGetMethodRef );
3876cdf0e10cSrcweir }
3877cdf0e10cSrcweir 
SFX_NOTIFY(SfxBroadcaster & rBC,const TypeId & rBCType,const SfxHint & rHint,const TypeId & rHintType)3878cdf0e10cSrcweir void SbUnoSingleton::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
3879cdf0e10cSrcweir 						   const SfxHint& rHint, const TypeId& rHintType )
3880cdf0e10cSrcweir {
3881cdf0e10cSrcweir 	const SbxHint* pHint = PTR_CAST(SbxHint,&rHint);
3882cdf0e10cSrcweir 	if( pHint )
3883cdf0e10cSrcweir 	{
3884cdf0e10cSrcweir 		SbxVariable* pVar = pHint->GetVar();
3885cdf0e10cSrcweir 		SbxArray* pParams = pVar->GetParameters();
3886cdf0e10cSrcweir 		sal_uInt32 nParamCount = pParams ? ((sal_uInt32)pParams->Count() - 1) : 0;
3887cdf0e10cSrcweir 		sal_uInt32 nAllowedParamCount = 1;
3888cdf0e10cSrcweir 
3889cdf0e10cSrcweir 		Reference < XComponentContext > xContextToUse;
3890cdf0e10cSrcweir 		if( nParamCount > 0 )
3891cdf0e10cSrcweir 		{
3892cdf0e10cSrcweir 			// Check if first parameter is a context and use it then
3893cdf0e10cSrcweir 			Reference < XComponentContext > xFirstParamContext;
3894cdf0e10cSrcweir 			Any aArg1 = sbxToUnoValue( pParams->Get( 1 ) );
3895cdf0e10cSrcweir 			if( (aArg1 >>= xFirstParamContext) && xFirstParamContext.is() )
3896cdf0e10cSrcweir 				xContextToUse = xFirstParamContext;
3897cdf0e10cSrcweir 		}
3898cdf0e10cSrcweir 
3899cdf0e10cSrcweir 		if( !xContextToUse.is() )
3900cdf0e10cSrcweir 		{
3901cdf0e10cSrcweir 			Reference < XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
3902cdf0e10cSrcweir 			xContextToUse.set( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" )) ), UNO_QUERY_THROW );
3903cdf0e10cSrcweir 			--nAllowedParamCount;
3904cdf0e10cSrcweir 		}
3905cdf0e10cSrcweir 
3906cdf0e10cSrcweir 		if( nParamCount > nAllowedParamCount )
3907cdf0e10cSrcweir 		{
3908cdf0e10cSrcweir 			StarBASIC::Error( SbERR_BAD_ARGUMENT );
3909cdf0e10cSrcweir 			return;
3910cdf0e10cSrcweir 		}
3911cdf0e10cSrcweir 
3912cdf0e10cSrcweir 		Any aRetAny;
3913cdf0e10cSrcweir 		if( xContextToUse.is() )
3914cdf0e10cSrcweir 		{
3915cdf0e10cSrcweir 			String aSingletonName( RTL_CONSTASCII_USTRINGPARAM("/singletons/") );
3916cdf0e10cSrcweir 			aSingletonName += GetName();
3917cdf0e10cSrcweir 			Reference < XInterface > xRet;
3918cdf0e10cSrcweir 			xContextToUse->getValueByName( aSingletonName ) >>= xRet;
3919cdf0e10cSrcweir 			aRetAny <<= xRet;
3920cdf0e10cSrcweir 		}
3921cdf0e10cSrcweir 		unoToSbxValue( pVar, aRetAny );
3922cdf0e10cSrcweir 	}
3923cdf0e10cSrcweir 	else
3924cdf0e10cSrcweir 		SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
3925cdf0e10cSrcweir }
3926cdf0e10cSrcweir 
3927cdf0e10cSrcweir 
3928cdf0e10cSrcweir //========================================================================
3929cdf0e10cSrcweir //========================================================================
3930cdf0e10cSrcweir //========================================================================
3931cdf0e10cSrcweir 
3932cdf0e10cSrcweir // Implementation eines EventAttacher-bezogenen AllListeners, der
3933cdf0e10cSrcweir // nur einzelne Events an einen allgemeinen AllListener weiterleitet
3934cdf0e10cSrcweir class BasicAllListener_Impl : public BasicAllListenerHelper
3935cdf0e10cSrcweir {
3936cdf0e10cSrcweir 	virtual void firing_impl(const AllEventObject& Event, Any* pRet);
3937cdf0e10cSrcweir 
3938cdf0e10cSrcweir public:
3939cdf0e10cSrcweir 	SbxObjectRef	xSbxObj;
3940cdf0e10cSrcweir 	::rtl::OUString		aPrefixName;
3941cdf0e10cSrcweir 
3942cdf0e10cSrcweir 	BasicAllListener_Impl( const ::rtl::OUString& aPrefixName );
3943cdf0e10cSrcweir 	~BasicAllListener_Impl();
3944cdf0e10cSrcweir 
3945cdf0e10cSrcweir 	// Methoden von XInterface
3946cdf0e10cSrcweir 	//virtual sal_Bool queryInterface( Uik aUik, Reference< XInterface > & rOut );
3947cdf0e10cSrcweir 
3948cdf0e10cSrcweir 	// Methoden von XAllListener
3949cdf0e10cSrcweir 	virtual void SAL_CALL firing(const AllEventObject& Event) throw ( RuntimeException );
3950cdf0e10cSrcweir 	virtual Any SAL_CALL approveFiring(const AllEventObject& Event) throw ( RuntimeException );
3951cdf0e10cSrcweir 
3952cdf0e10cSrcweir 	// Methoden von XEventListener
3953cdf0e10cSrcweir 	virtual void SAL_CALL disposing(const EventObject& Source) throw ( RuntimeException );
3954cdf0e10cSrcweir };
3955cdf0e10cSrcweir 
3956cdf0e10cSrcweir 
3957cdf0e10cSrcweir //========================================================================
BasicAllListener_Impl(const::rtl::OUString & aPrefixName_)3958cdf0e10cSrcweir BasicAllListener_Impl::BasicAllListener_Impl
3959cdf0e10cSrcweir (
3960cdf0e10cSrcweir 	const ::rtl::OUString	& aPrefixName_
3961cdf0e10cSrcweir )
3962cdf0e10cSrcweir 	: aPrefixName( aPrefixName_ )
3963cdf0e10cSrcweir {
3964cdf0e10cSrcweir }
3965cdf0e10cSrcweir 
3966cdf0e10cSrcweir //========================================================================
~BasicAllListener_Impl()3967cdf0e10cSrcweir BasicAllListener_Impl::~BasicAllListener_Impl()
3968cdf0e10cSrcweir {
3969cdf0e10cSrcweir }
3970cdf0e10cSrcweir 
3971cdf0e10cSrcweir //========================================================================
3972cdf0e10cSrcweir 
firing_impl(const AllEventObject & Event,Any * pRet)3973cdf0e10cSrcweir void BasicAllListener_Impl::firing_impl( const AllEventObject& Event, Any* pRet )
3974cdf0e10cSrcweir {
3975cdf0e10cSrcweir 	vos::OGuard guard( Application::GetSolarMutex() );
3976cdf0e10cSrcweir 
3977cdf0e10cSrcweir 	if( xSbxObj.Is() )
3978cdf0e10cSrcweir 	{
3979cdf0e10cSrcweir 		::rtl::OUString aMethodName = aPrefixName;
3980cdf0e10cSrcweir 		aMethodName = aMethodName + Event.MethodName;
3981cdf0e10cSrcweir 
3982cdf0e10cSrcweir 		SbxVariable * pP = xSbxObj;
3983cdf0e10cSrcweir 		while( pP->GetParent() )
3984cdf0e10cSrcweir 		{
3985cdf0e10cSrcweir 			pP = pP->GetParent();
3986cdf0e10cSrcweir 			StarBASIC * pLib = PTR_CAST(StarBASIC,pP);
3987cdf0e10cSrcweir 			if( pLib )
3988cdf0e10cSrcweir 			{
3989cdf0e10cSrcweir 				// In Basic Array anlegen
3990cdf0e10cSrcweir 				SbxArrayRef xSbxArray = new SbxArray( SbxVARIANT );
3991cdf0e10cSrcweir 				const Any * pArgs = Event.Arguments.getConstArray();
3992cdf0e10cSrcweir 				sal_Int32 nCount = Event.Arguments.getLength();
3993cdf0e10cSrcweir 				for( sal_Int32 i = 0; i < nCount; i++ )
3994cdf0e10cSrcweir 				{
3995cdf0e10cSrcweir 					// Elemente wandeln
3996cdf0e10cSrcweir 					SbxVariableRef xVar = new SbxVariable( SbxVARIANT );
3997cdf0e10cSrcweir 					unoToSbxValue( (SbxVariable*)xVar, pArgs[i] );
3998cdf0e10cSrcweir 					xSbxArray->Put( xVar, sal::static_int_cast< sal_uInt16 >(i+1) );
3999cdf0e10cSrcweir 				}
4000cdf0e10cSrcweir 
4001cdf0e10cSrcweir 				pLib->Call( aMethodName, xSbxArray );
4002cdf0e10cSrcweir 
4003cdf0e10cSrcweir 				// Return-Wert aus dem Param-Array holen, wenn verlangt
4004cdf0e10cSrcweir 				if( pRet )
4005cdf0e10cSrcweir 				{
4006cdf0e10cSrcweir 					SbxVariable* pVar = xSbxArray->Get( 0 );
4007cdf0e10cSrcweir 					if( pVar )
4008cdf0e10cSrcweir 					{
4009cdf0e10cSrcweir 						// #95792 Avoid a second call
4010cdf0e10cSrcweir 						sal_uInt16 nFlags = pVar->GetFlags();
4011cdf0e10cSrcweir 						pVar->SetFlag( SBX_NO_BROADCAST );
4012cdf0e10cSrcweir 						*pRet = sbxToUnoValueImpl( pVar );
4013cdf0e10cSrcweir 						pVar->SetFlags( nFlags );
4014cdf0e10cSrcweir 					}
4015cdf0e10cSrcweir 				}
4016cdf0e10cSrcweir 				break;
4017cdf0e10cSrcweir 			}
4018cdf0e10cSrcweir 		}
4019cdf0e10cSrcweir 	}
4020cdf0e10cSrcweir }
4021cdf0e10cSrcweir 
4022cdf0e10cSrcweir 
4023cdf0e10cSrcweir // Methoden von XAllListener
firing(const AllEventObject & Event)4024cdf0e10cSrcweir void BasicAllListener_Impl::firing( const AllEventObject& Event ) throw ( RuntimeException )
4025cdf0e10cSrcweir {
4026cdf0e10cSrcweir 	firing_impl( Event, NULL );
4027cdf0e10cSrcweir }
4028cdf0e10cSrcweir 
approveFiring(const AllEventObject & Event)4029cdf0e10cSrcweir Any BasicAllListener_Impl::approveFiring( const AllEventObject& Event ) throw ( RuntimeException )
4030cdf0e10cSrcweir {
4031cdf0e10cSrcweir 	Any aRetAny;
4032cdf0e10cSrcweir 	firing_impl( Event, &aRetAny );
4033cdf0e10cSrcweir 	return aRetAny;
4034cdf0e10cSrcweir }
4035cdf0e10cSrcweir 
4036cdf0e10cSrcweir //========================================================================
4037cdf0e10cSrcweir // Methoden von XEventListener
disposing(const EventObject &)4038cdf0e10cSrcweir void BasicAllListener_Impl ::disposing(const EventObject& ) throw ( RuntimeException )
4039cdf0e10cSrcweir {
4040cdf0e10cSrcweir 	vos::OGuard guard( Application::GetSolarMutex() );
4041cdf0e10cSrcweir 
4042cdf0e10cSrcweir 	xSbxObj.Clear();
4043cdf0e10cSrcweir }
4044cdf0e10cSrcweir 
4045cdf0e10cSrcweir 
4046cdf0e10cSrcweir 
4047cdf0e10cSrcweir //*************************************************************************
4048cdf0e10cSrcweir //  class InvocationToAllListenerMapper
4049cdf0e10cSrcweir //  helper class to map XInvocation to XAllListener (also in project eventattacher!)
4050cdf0e10cSrcweir //*************************************************************************
4051cdf0e10cSrcweir class InvocationToAllListenerMapper : public WeakImplHelper1< XInvocation >
4052cdf0e10cSrcweir {
4053cdf0e10cSrcweir public:
4054cdf0e10cSrcweir 	InvocationToAllListenerMapper( const Reference< XIdlClass >& ListenerType,
4055cdf0e10cSrcweir 		const Reference< XAllListener >& AllListener, const Any& Helper );
4056cdf0e10cSrcweir 
4057cdf0e10cSrcweir 	// XInvocation
4058cdf0e10cSrcweir     virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection(void) throw( RuntimeException );
4059cdf0e10cSrcweir     virtual Any SAL_CALL invoke(const ::rtl::OUString& FunctionName, const Sequence< Any >& Params, Sequence< sal_Int16 >& OutParamIndex, Sequence< Any >& OutParam)
4060cdf0e10cSrcweir 		throw( IllegalArgumentException, CannotConvertException, InvocationTargetException, RuntimeException );
4061cdf0e10cSrcweir     virtual void SAL_CALL setValue(const ::rtl::OUString& PropertyName, const Any& Value)
4062cdf0e10cSrcweir 		throw( UnknownPropertyException, CannotConvertException, InvocationTargetException, RuntimeException );
4063cdf0e10cSrcweir     virtual Any SAL_CALL getValue(const ::rtl::OUString& PropertyName) throw( UnknownPropertyException, RuntimeException );
4064cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasMethod(const ::rtl::OUString& Name) throw( RuntimeException );
4065cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasProperty(const ::rtl::OUString& Name) throw( RuntimeException );
4066cdf0e10cSrcweir 
4067cdf0e10cSrcweir private:
4068cdf0e10cSrcweir 	Reference< XIdlReflection >  m_xCoreReflection;
4069cdf0e10cSrcweir 	Reference< XAllListener >	 m_xAllListener;
4070cdf0e10cSrcweir 	Reference< XIdlClass >  	 m_xListenerType;
4071cdf0e10cSrcweir 	Any 						 m_Helper;
4072cdf0e10cSrcweir };
4073cdf0e10cSrcweir 
4074cdf0e10cSrcweir 
4075cdf0e10cSrcweir // Function to replace AllListenerAdapterService::createAllListerAdapter
createAllListenerAdapter(const Reference<XInvocationAdapterFactory> & xInvocationAdapterFactory,const Reference<XIdlClass> & xListenerType,const Reference<XAllListener> & xListener,const Any & Helper)4076cdf0e10cSrcweir Reference< XInterface > createAllListenerAdapter
4077cdf0e10cSrcweir (
4078cdf0e10cSrcweir 	const Reference< XInvocationAdapterFactory >& xInvocationAdapterFactory,
4079cdf0e10cSrcweir 	const Reference< XIdlClass >& xListenerType,
4080cdf0e10cSrcweir 	const Reference< XAllListener >& xListener,
4081cdf0e10cSrcweir 	const Any& Helper
4082cdf0e10cSrcweir )
4083cdf0e10cSrcweir {
4084cdf0e10cSrcweir 	Reference< XInterface > xAdapter;
4085cdf0e10cSrcweir 	if( xInvocationAdapterFactory.is() && xListenerType.is() && xListener.is() )
4086cdf0e10cSrcweir 	{
4087cdf0e10cSrcweir 	   Reference< XInvocation >	xInvocationToAllListenerMapper =
4088cdf0e10cSrcweir 			(XInvocation*)new InvocationToAllListenerMapper( xListenerType, xListener, Helper );
4089cdf0e10cSrcweir 		Type aListenerType( xListenerType->getTypeClass(), xListenerType->getName() );
4090cdf0e10cSrcweir 		xAdapter = xInvocationAdapterFactory->createAdapter( xInvocationToAllListenerMapper, aListenerType );
4091cdf0e10cSrcweir 	}
4092cdf0e10cSrcweir 	return xAdapter;
4093cdf0e10cSrcweir }
4094cdf0e10cSrcweir 
4095cdf0e10cSrcweir 
4096cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
4097cdf0e10cSrcweir // InvocationToAllListenerMapper
InvocationToAllListenerMapper(const Reference<XIdlClass> & ListenerType,const Reference<XAllListener> & AllListener,const Any & Helper)4098cdf0e10cSrcweir InvocationToAllListenerMapper::InvocationToAllListenerMapper
4099cdf0e10cSrcweir 	( const Reference< XIdlClass >& ListenerType, const Reference< XAllListener >& AllListener, const Any& Helper )
4100cdf0e10cSrcweir 		: m_xAllListener( AllListener )
4101cdf0e10cSrcweir 		, m_xListenerType( ListenerType )
4102cdf0e10cSrcweir 		, m_Helper( Helper )
4103cdf0e10cSrcweir {
4104cdf0e10cSrcweir }
4105cdf0e10cSrcweir 
4106cdf0e10cSrcweir //*************************************************************************
getIntrospection(void)4107cdf0e10cSrcweir Reference< XIntrospectionAccess > SAL_CALL InvocationToAllListenerMapper::getIntrospection(void)
4108cdf0e10cSrcweir 	throw( RuntimeException )
4109cdf0e10cSrcweir {
4110cdf0e10cSrcweir 	return Reference< XIntrospectionAccess >();
4111cdf0e10cSrcweir }
4112cdf0e10cSrcweir 
4113cdf0e10cSrcweir //*************************************************************************
invoke(const::rtl::OUString & FunctionName,const Sequence<Any> & Params,Sequence<sal_Int16> & OutParamIndex,Sequence<Any> & OutParam)4114cdf0e10cSrcweir Any SAL_CALL InvocationToAllListenerMapper::invoke(const ::rtl::OUString& FunctionName, const Sequence< Any >& Params,
4115cdf0e10cSrcweir 	Sequence< sal_Int16 >& OutParamIndex, Sequence< Any >& OutParam)
4116cdf0e10cSrcweir 		throw( IllegalArgumentException, CannotConvertException,
4117cdf0e10cSrcweir 		InvocationTargetException, RuntimeException )
4118cdf0e10cSrcweir {
4119cdf0e10cSrcweir     (void)OutParamIndex;
4120cdf0e10cSrcweir     (void)OutParam     ;
4121cdf0e10cSrcweir 
4122cdf0e10cSrcweir 	Any aRet;
4123cdf0e10cSrcweir 
4124cdf0e10cSrcweir 	// Check if to firing or approveFiring has to be called
4125cdf0e10cSrcweir 	Reference< XIdlMethod > xMethod = m_xListenerType->getMethod( FunctionName );
4126cdf0e10cSrcweir 	sal_Bool bApproveFiring = sal_False;
4127cdf0e10cSrcweir 	if( !xMethod.is() )
4128cdf0e10cSrcweir 		return aRet;
4129cdf0e10cSrcweir     Reference< XIdlClass > xReturnType = xMethod->getReturnType();
4130cdf0e10cSrcweir     Sequence< Reference< XIdlClass > > aExceptionSeq = xMethod->getExceptionTypes();
4131cdf0e10cSrcweir 	if( ( xReturnType.is() && xReturnType->getTypeClass() != TypeClass_VOID ) ||
4132cdf0e10cSrcweir 		aExceptionSeq.getLength() > 0 )
4133cdf0e10cSrcweir 	{
4134cdf0e10cSrcweir 		bApproveFiring = sal_True;
4135cdf0e10cSrcweir 	}
4136cdf0e10cSrcweir 	else
4137cdf0e10cSrcweir 	{
4138cdf0e10cSrcweir 	    Sequence< ParamInfo > aParamSeq = xMethod->getParameterInfos();
4139cdf0e10cSrcweir 		sal_uInt32 nParamCount = aParamSeq.getLength();
4140cdf0e10cSrcweir 		if( nParamCount > 1 )
4141cdf0e10cSrcweir 		{
4142cdf0e10cSrcweir 			const ParamInfo* pInfos = aParamSeq.getConstArray();
4143cdf0e10cSrcweir 			for( sal_uInt32 i = 0 ; i < nParamCount ; i++ )
4144cdf0e10cSrcweir 			{
4145cdf0e10cSrcweir 				if( pInfos[ i ].aMode != ParamMode_IN )
4146cdf0e10cSrcweir 				{
4147cdf0e10cSrcweir 					bApproveFiring = sal_True;
4148cdf0e10cSrcweir 					break;
4149cdf0e10cSrcweir 				}
4150cdf0e10cSrcweir 			}
4151cdf0e10cSrcweir 		}
4152cdf0e10cSrcweir 	}
4153cdf0e10cSrcweir 
4154cdf0e10cSrcweir     AllEventObject aAllEvent;
4155cdf0e10cSrcweir     aAllEvent.Source = (OWeakObject*) this;
4156cdf0e10cSrcweir     aAllEvent.Helper = m_Helper;
4157cdf0e10cSrcweir     aAllEvent.ListenerType = Type(m_xListenerType->getTypeClass(), m_xListenerType->getName() );
4158cdf0e10cSrcweir     aAllEvent.MethodName = FunctionName;
4159cdf0e10cSrcweir     aAllEvent.Arguments = Params;
4160cdf0e10cSrcweir 	if( bApproveFiring )
4161cdf0e10cSrcweir 		aRet = m_xAllListener->approveFiring( aAllEvent );
4162cdf0e10cSrcweir 	else
4163cdf0e10cSrcweir 		m_xAllListener->firing( aAllEvent );
4164cdf0e10cSrcweir 	return aRet;
4165cdf0e10cSrcweir }
4166cdf0e10cSrcweir 
4167cdf0e10cSrcweir //*************************************************************************
setValue(const::rtl::OUString & PropertyName,const Any & Value)4168cdf0e10cSrcweir void SAL_CALL InvocationToAllListenerMapper::setValue(const ::rtl::OUString& PropertyName, const Any& Value)
4169cdf0e10cSrcweir 	throw( UnknownPropertyException, CannotConvertException,
4170cdf0e10cSrcweir 		   InvocationTargetException, RuntimeException )
4171cdf0e10cSrcweir {
4172cdf0e10cSrcweir     (void)PropertyName;
4173cdf0e10cSrcweir     (void)Value;
4174cdf0e10cSrcweir }
4175cdf0e10cSrcweir 
4176cdf0e10cSrcweir //*************************************************************************
getValue(const::rtl::OUString & PropertyName)4177cdf0e10cSrcweir Any SAL_CALL InvocationToAllListenerMapper::getValue(const ::rtl::OUString& PropertyName)
4178cdf0e10cSrcweir 	throw( UnknownPropertyException, RuntimeException )
4179cdf0e10cSrcweir {
4180cdf0e10cSrcweir     (void)PropertyName;
4181cdf0e10cSrcweir 
4182cdf0e10cSrcweir 	return Any();
4183cdf0e10cSrcweir }
4184cdf0e10cSrcweir 
4185cdf0e10cSrcweir //*************************************************************************
hasMethod(const::rtl::OUString & Name)4186cdf0e10cSrcweir sal_Bool SAL_CALL InvocationToAllListenerMapper::hasMethod(const ::rtl::OUString& Name)
4187cdf0e10cSrcweir 	throw( RuntimeException )
4188cdf0e10cSrcweir {
4189cdf0e10cSrcweir 	Reference< XIdlMethod > xMethod = m_xListenerType->getMethod( Name );
4190cdf0e10cSrcweir 	return xMethod.is();
4191cdf0e10cSrcweir }
4192cdf0e10cSrcweir 
4193cdf0e10cSrcweir //*************************************************************************
hasProperty(const::rtl::OUString & Name)4194cdf0e10cSrcweir sal_Bool SAL_CALL InvocationToAllListenerMapper::hasProperty(const ::rtl::OUString& Name)
4195cdf0e10cSrcweir 	throw( RuntimeException )
4196cdf0e10cSrcweir {
4197cdf0e10cSrcweir 	Reference< XIdlField > xField = m_xListenerType->getField( Name );
4198cdf0e10cSrcweir 	return xField.is();
4199cdf0e10cSrcweir }
4200cdf0e10cSrcweir 
4201cdf0e10cSrcweir //========================================================================
4202cdf0e10cSrcweir // Uno-Service erzeugen
4203cdf0e10cSrcweir // 1. Parameter == Prefix-Name der Makros
4204cdf0e10cSrcweir // 2. Parameter == voll qualifizierter Name des Listeners
SbRtl_CreateUnoListener(StarBASIC * pBasic,SbxArray & rPar,sal_Bool bWrite)4205cdf0e10cSrcweir void SbRtl_CreateUnoListener( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite )
4206cdf0e10cSrcweir //RTLFUNC(CreateUnoListener)
4207cdf0e10cSrcweir {
4208cdf0e10cSrcweir     (void)bWrite;
4209cdf0e10cSrcweir 
4210cdf0e10cSrcweir 	// Wir brauchen 2 Parameter
4211cdf0e10cSrcweir 	if ( rPar.Count() != 3 )
4212cdf0e10cSrcweir 	{
4213cdf0e10cSrcweir 		StarBASIC::Error( SbERR_BAD_ARGUMENT );
4214cdf0e10cSrcweir 		return;
4215cdf0e10cSrcweir 	}
4216cdf0e10cSrcweir 
4217cdf0e10cSrcweir 	// Klassen-Name der struct holen
4218cdf0e10cSrcweir 	String aPrefixName = rPar.Get(1)->GetString();
4219cdf0e10cSrcweir 	String aListenerClassName = rPar.Get(2)->GetString();
4220cdf0e10cSrcweir 
4221cdf0e10cSrcweir 	// CoreReflection holen
4222cdf0e10cSrcweir 	Reference< XIdlReflection > xCoreReflection = getCoreReflection_Impl();
4223cdf0e10cSrcweir 	if( !xCoreReflection.is() )
4224cdf0e10cSrcweir 		return;
4225cdf0e10cSrcweir 
4226cdf0e10cSrcweir 	// AllListenerAdapterService holen
4227cdf0e10cSrcweir 	Reference< XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory() );
4228cdf0e10cSrcweir 	if( !xFactory.is() )
4229cdf0e10cSrcweir 		return;
4230cdf0e10cSrcweir 
4231cdf0e10cSrcweir 	// Klasse suchen
4232cdf0e10cSrcweir 	Reference< XIdlClass > xClass = xCoreReflection->forName( aListenerClassName );
4233cdf0e10cSrcweir 	if( !xClass.is() )
4234cdf0e10cSrcweir 		return;
4235cdf0e10cSrcweir 
4236cdf0e10cSrcweir 	// AB, 30.11.1999 InvocationAdapterFactory holen
4237cdf0e10cSrcweir 	Reference< XInvocationAdapterFactory > xInvocationAdapterFactory = Reference< XInvocationAdapterFactory >(
4238cdf0e10cSrcweir 		xFactory->createInstance( rtl::OUString::createFromAscii("com.sun.star.script.InvocationAdapterFactory") ), UNO_QUERY );
4239cdf0e10cSrcweir 
4240cdf0e10cSrcweir 	BasicAllListener_Impl * p;
4241cdf0e10cSrcweir 	Reference< XAllListener > xAllLst = p = new BasicAllListener_Impl( aPrefixName );
4242cdf0e10cSrcweir 	Any aTmp;
4243cdf0e10cSrcweir 	Reference< XInterface > xLst = createAllListenerAdapter( xInvocationAdapterFactory, xClass, xAllLst, aTmp );
4244cdf0e10cSrcweir 	if( !xLst.is() )
4245cdf0e10cSrcweir 		return;
4246cdf0e10cSrcweir 
4247cdf0e10cSrcweir 	::rtl::OUString aClassName = xClass->getName();
4248cdf0e10cSrcweir 	Type aClassType( xClass->getTypeClass(), aClassName.getStr() );
4249cdf0e10cSrcweir 	aTmp = xLst->queryInterface( aClassType );
4250cdf0e10cSrcweir 	if( !aTmp.hasValue() )
4251cdf0e10cSrcweir 		return;
4252cdf0e10cSrcweir 
4253cdf0e10cSrcweir 	SbUnoObject* pUnoObj = new SbUnoObject( aListenerClassName, aTmp );
4254cdf0e10cSrcweir     p->xSbxObj = pUnoObj;
4255cdf0e10cSrcweir 	p->xSbxObj->SetParent( pBasic );
4256cdf0e10cSrcweir 
4257cdf0e10cSrcweir     // #100326 Register listener object to set Parent NULL in Dtor
4258cdf0e10cSrcweir     SbxArrayRef xBasicUnoListeners = pBasic->getUnoListeners();
4259cdf0e10cSrcweir 	xBasicUnoListeners->Insert( pUnoObj, xBasicUnoListeners->Count() );
4260cdf0e10cSrcweir 
4261cdf0e10cSrcweir 	// Objekt zurueckliefern
4262cdf0e10cSrcweir 	SbxVariableRef refVar = rPar.Get(0);
4263cdf0e10cSrcweir 	refVar->PutObject( p->xSbxObj );
4264cdf0e10cSrcweir }
4265cdf0e10cSrcweir 
4266cdf0e10cSrcweir //========================================================================
4267cdf0e10cSrcweir // Represents the DefaultContext property of the ProcessServiceManager
4268cdf0e10cSrcweir // in the Basic runtime system.
RTL_Impl_GetDefaultContext(StarBASIC * pBasic,SbxArray & rPar,sal_Bool bWrite)4269cdf0e10cSrcweir void RTL_Impl_GetDefaultContext( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite )
4270cdf0e10cSrcweir {
4271cdf0e10cSrcweir     (void)pBasic;
4272cdf0e10cSrcweir     (void)bWrite;
4273cdf0e10cSrcweir 
4274cdf0e10cSrcweir 	SbxVariableRef refVar = rPar.Get(0);
4275cdf0e10cSrcweir 
4276cdf0e10cSrcweir 	Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
4277cdf0e10cSrcweir 	Reference< XPropertySet> xPSMPropertySet( xFactory, UNO_QUERY );
4278cdf0e10cSrcweir 	if( xPSMPropertySet.is() )
4279cdf0e10cSrcweir 	{
4280cdf0e10cSrcweir 		Any aContextAny = xPSMPropertySet->getPropertyValue(
4281cdf0e10cSrcweir 			String( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) );
4282cdf0e10cSrcweir 
4283cdf0e10cSrcweir 		SbUnoObjectRef xUnoObj = new SbUnoObject
4284cdf0e10cSrcweir 			( String( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ),
4285cdf0e10cSrcweir 			  aContextAny );
4286cdf0e10cSrcweir 		refVar->PutObject( (SbUnoObject*)xUnoObj );
4287cdf0e10cSrcweir 	}
4288cdf0e10cSrcweir 	else
4289cdf0e10cSrcweir 	{
4290cdf0e10cSrcweir 		refVar->PutObject( NULL );
4291cdf0e10cSrcweir 	}
4292cdf0e10cSrcweir }
4293cdf0e10cSrcweir 
4294cdf0e10cSrcweir //========================================================================
4295cdf0e10cSrcweir // Creates a Basic wrapper object for a strongly typed Uno value
4296cdf0e10cSrcweir // 1. parameter: Uno type as full qualified type name, e.g. "byte[]"
RTL_Impl_CreateUnoValue(StarBASIC * pBasic,SbxArray & rPar,sal_Bool bWrite)4297cdf0e10cSrcweir void RTL_Impl_CreateUnoValue( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite )
4298cdf0e10cSrcweir {
4299cdf0e10cSrcweir     (void)pBasic;
4300cdf0e10cSrcweir     (void)bWrite;
4301cdf0e10cSrcweir 
4302cdf0e10cSrcweir 	static String aTypeTypeString( RTL_CONSTASCII_USTRINGPARAM("type") );
4303cdf0e10cSrcweir 
4304cdf0e10cSrcweir 	// 2 parameters needed
4305cdf0e10cSrcweir 	if ( rPar.Count() != 3 )
4306cdf0e10cSrcweir 	{
4307cdf0e10cSrcweir 		StarBASIC::Error( SbERR_BAD_ARGUMENT );
4308cdf0e10cSrcweir 		return;
4309cdf0e10cSrcweir 	}
4310cdf0e10cSrcweir 
4311cdf0e10cSrcweir 	// Klassen-Name der struct holen
4312cdf0e10cSrcweir 	String aTypeName = rPar.Get(1)->GetString();
4313cdf0e10cSrcweir     SbxVariable* pVal = rPar.Get(2);
4314cdf0e10cSrcweir 
4315cdf0e10cSrcweir 	if( aTypeName == aTypeTypeString )
4316cdf0e10cSrcweir 	{
4317cdf0e10cSrcweir 		SbxDataType eBaseType = pVal->SbxValue::GetType();
4318cdf0e10cSrcweir 		String aValTypeName;
4319cdf0e10cSrcweir 		if( eBaseType == SbxSTRING )
4320cdf0e10cSrcweir 		{
4321cdf0e10cSrcweir 			aValTypeName = pVal->GetString();
4322cdf0e10cSrcweir 		}
4323cdf0e10cSrcweir 		else if( eBaseType == SbxOBJECT )
4324cdf0e10cSrcweir 		{
4325cdf0e10cSrcweir 			// XIdlClass?
4326cdf0e10cSrcweir 			Reference< XIdlClass > xIdlClass;
4327cdf0e10cSrcweir 
4328cdf0e10cSrcweir 			SbxBaseRef pObj = (SbxBase*)pVal->GetObject();
4329cdf0e10cSrcweir 			if( pObj && pObj->ISA(SbUnoObject) )
4330cdf0e10cSrcweir 			{
4331cdf0e10cSrcweir 				Any aUnoAny = ((SbUnoObject*)(SbxBase*)pObj)->getUnoAny();
4332cdf0e10cSrcweir 				aUnoAny >>= xIdlClass;
4333cdf0e10cSrcweir 			}
4334cdf0e10cSrcweir 
4335cdf0e10cSrcweir 			if( xIdlClass.is() )
4336cdf0e10cSrcweir 				aValTypeName = xIdlClass->getName();
4337cdf0e10cSrcweir 		}
4338cdf0e10cSrcweir 		Type aType;
4339cdf0e10cSrcweir 		bool bSuccess = implGetTypeByName( aValTypeName, aType );
4340cdf0e10cSrcweir 		if( bSuccess )
4341cdf0e10cSrcweir 		{
4342cdf0e10cSrcweir 			Any aTypeAny( aType );
4343cdf0e10cSrcweir 			SbxVariableRef refVar = rPar.Get(0);
4344cdf0e10cSrcweir 			SbxObjectRef xUnoAnyObject = new SbUnoAnyObject( aTypeAny );
4345cdf0e10cSrcweir 			refVar->PutObject( xUnoAnyObject );
4346cdf0e10cSrcweir 		}
4347cdf0e10cSrcweir 		return;
4348cdf0e10cSrcweir 	}
4349cdf0e10cSrcweir 
4350cdf0e10cSrcweir     // Check the type
4351cdf0e10cSrcweir     Reference< XHierarchicalNameAccess > xTypeAccess = getTypeProvider_Impl();
4352cdf0e10cSrcweir     Any aRet;
4353cdf0e10cSrcweir 	try
4354cdf0e10cSrcweir 	{
4355cdf0e10cSrcweir         aRet = xTypeAccess->getByHierarchicalName( aTypeName );
4356cdf0e10cSrcweir 	}
4357cdf0e10cSrcweir 	catch( NoSuchElementException& e1 )
4358cdf0e10cSrcweir 	{
4359cdf0e10cSrcweir         String aNoSuchElementExceptionName
4360cdf0e10cSrcweir             ( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.container.NoSuchElementException" ) );
4361cdf0e10cSrcweir 		StarBASIC::Error( ERRCODE_BASIC_EXCEPTION,
4362cdf0e10cSrcweir             implGetExceptionMsg( e1, aNoSuchElementExceptionName ) );
4363cdf0e10cSrcweir 		return;
4364cdf0e10cSrcweir 	}
4365cdf0e10cSrcweir     Reference< XTypeDescription > xTypeDesc;
4366cdf0e10cSrcweir     aRet >>= xTypeDesc;
4367cdf0e10cSrcweir     TypeClass eTypeClass = xTypeDesc->getTypeClass();
4368cdf0e10cSrcweir 	Type aDestType( eTypeClass, aTypeName );
4369cdf0e10cSrcweir 
4370cdf0e10cSrcweir 
4371cdf0e10cSrcweir     // Preconvert value
4372cdf0e10cSrcweir 	Any aVal = sbxToUnoValueImpl( pVal );
4373cdf0e10cSrcweir     Any aConvertedVal = convertAny( aVal, aDestType );
4374cdf0e10cSrcweir 
4375cdf0e10cSrcweir     /*
4376cdf0e10cSrcweir     // Convert
4377cdf0e10cSrcweir     Reference< XTypeConverter > xConverter = getTypeConverter_Impl();
4378cdf0e10cSrcweir 	try
4379cdf0e10cSrcweir 	{
4380cdf0e10cSrcweir         aConvertedVal = xConverter->convertTo( aVal, aDestType );
4381cdf0e10cSrcweir 	}
4382cdf0e10cSrcweir 	catch( IllegalArgumentException& e1 )
4383cdf0e10cSrcweir 	{
4384cdf0e10cSrcweir 		StarBASIC::Error( ERRCODE_BASIC_EXCEPTION,
4385cdf0e10cSrcweir             implGetExceptionMsg( ::cppu::getCaughtException() ) );
4386cdf0e10cSrcweir 		return;
4387cdf0e10cSrcweir 	}
4388cdf0e10cSrcweir 	catch( CannotConvertException& e2 )
4389cdf0e10cSrcweir 	{
4390cdf0e10cSrcweir         String aCannotConvertExceptionName
4391cdf0e10cSrcweir             ( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.IllegalArgumentException" ) );
4392cdf0e10cSrcweir 		StarBASIC::Error( ERRCODE_BASIC_EXCEPTION,
4393cdf0e10cSrcweir             implGetExceptionMsg( e2, aCannotConvertExceptionName ) );
4394cdf0e10cSrcweir 		return;
4395cdf0e10cSrcweir 	}
4396cdf0e10cSrcweir     */
4397cdf0e10cSrcweir 
4398cdf0e10cSrcweir 	SbxVariableRef refVar = rPar.Get(0);
4399cdf0e10cSrcweir 	SbxObjectRef xUnoAnyObject = new SbUnoAnyObject( aConvertedVal );
4400cdf0e10cSrcweir 	refVar->PutObject( xUnoAnyObject );
4401cdf0e10cSrcweir }
4402cdf0e10cSrcweir 
4403cdf0e10cSrcweir //==========================================================================
4404cdf0e10cSrcweir 
4405cdf0e10cSrcweir namespace {
4406cdf0e10cSrcweir class OMutexBasis
4407cdf0e10cSrcweir {
4408cdf0e10cSrcweir protected:
4409cdf0e10cSrcweir     // this mutex is necessary for OInterfaceContainerHelper
4410cdf0e10cSrcweir     ::osl::Mutex m_aMutex;
4411cdf0e10cSrcweir };
4412cdf0e10cSrcweir } // namespace
4413cdf0e10cSrcweir 
4414cdf0e10cSrcweir typedef WeakImplHelper2< XInvocation, XComponent > ModuleInvocationProxyHelper;
4415cdf0e10cSrcweir 
4416cdf0e10cSrcweir class ModuleInvocationProxy : public OMutexBasis,
4417cdf0e10cSrcweir                               public ModuleInvocationProxyHelper
4418cdf0e10cSrcweir {
4419cdf0e10cSrcweir 	::rtl::OUString		m_aPrefix;
4420cdf0e10cSrcweir 	SbxObjectRef		m_xScopeObj;
4421cdf0e10cSrcweir 	bool				m_bProxyIsClassModuleObject;
4422cdf0e10cSrcweir 
4423cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper m_aListeners;
4424cdf0e10cSrcweir 
4425cdf0e10cSrcweir public:
4426cdf0e10cSrcweir 	ModuleInvocationProxy( const ::rtl::OUString& aPrefix, SbxObjectRef xScopeObj );
~ModuleInvocationProxy()4427cdf0e10cSrcweir 	~ModuleInvocationProxy()
4428cdf0e10cSrcweir 	{}
4429cdf0e10cSrcweir 
4430cdf0e10cSrcweir 	// XInvocation
4431cdf0e10cSrcweir     virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection() throw();
4432cdf0e10cSrcweir     virtual void SAL_CALL setValue( const ::rtl::OUString& rProperty, const Any& rValue )
4433cdf0e10cSrcweir         throw( UnknownPropertyException );
4434cdf0e10cSrcweir     virtual Any SAL_CALL getValue( const ::rtl::OUString& rProperty )
4435cdf0e10cSrcweir         throw( UnknownPropertyException );
4436cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasMethod( const ::rtl::OUString& rName ) throw();
4437cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasProperty( const ::rtl::OUString& rProp ) throw();
4438cdf0e10cSrcweir 
4439cdf0e10cSrcweir     virtual Any SAL_CALL invoke( const ::rtl::OUString& rFunction,
4440cdf0e10cSrcweir                                  const Sequence< Any >& rParams,
4441cdf0e10cSrcweir                                  Sequence< sal_Int16 >& rOutParamIndex,
4442cdf0e10cSrcweir                                  Sequence< Any >& rOutParam )
4443cdf0e10cSrcweir         throw( CannotConvertException, InvocationTargetException );
4444cdf0e10cSrcweir 
4445cdf0e10cSrcweir     // XComponent
4446cdf0e10cSrcweir     virtual void SAL_CALL dispose() throw(RuntimeException);
4447cdf0e10cSrcweir     virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException);
4448cdf0e10cSrcweir     virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& aListener ) throw (RuntimeException);
4449cdf0e10cSrcweir };
4450cdf0e10cSrcweir 
ModuleInvocationProxy(const::rtl::OUString & aPrefix,SbxObjectRef xScopeObj)4451cdf0e10cSrcweir ModuleInvocationProxy::ModuleInvocationProxy( const ::rtl::OUString& aPrefix, SbxObjectRef xScopeObj )
4452cdf0e10cSrcweir 	: m_aPrefix( aPrefix + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("_") ) )
4453cdf0e10cSrcweir 	, m_xScopeObj( xScopeObj )
4454cdf0e10cSrcweir     , m_aListeners( m_aMutex )
4455cdf0e10cSrcweir {
4456cdf0e10cSrcweir 	m_bProxyIsClassModuleObject = xScopeObj.Is() ? xScopeObj->ISA(SbClassModuleObject) : false;
4457cdf0e10cSrcweir }
4458cdf0e10cSrcweir 
getIntrospection()4459cdf0e10cSrcweir Reference< XIntrospectionAccess > SAL_CALL ModuleInvocationProxy::getIntrospection() throw()
4460cdf0e10cSrcweir {
4461cdf0e10cSrcweir     return Reference< XIntrospectionAccess >();
4462cdf0e10cSrcweir }
4463cdf0e10cSrcweir 
setValue(const::rtl::OUString & rProperty,const Any & rValue)4464cdf0e10cSrcweir void SAL_CALL ModuleInvocationProxy::setValue( const ::rtl::OUString& rProperty, const Any& rValue ) throw( UnknownPropertyException )
4465cdf0e10cSrcweir {
4466cdf0e10cSrcweir 	if( !m_bProxyIsClassModuleObject )
4467cdf0e10cSrcweir 		throw UnknownPropertyException();
4468cdf0e10cSrcweir 
4469cdf0e10cSrcweir 	vos::OGuard guard( Application::GetSolarMutex() );
4470cdf0e10cSrcweir 
4471cdf0e10cSrcweir 	::rtl::OUString aPropertyFunctionName( RTL_CONSTASCII_USTRINGPARAM( "Property Set ") );
4472cdf0e10cSrcweir 	aPropertyFunctionName += m_aPrefix;
4473cdf0e10cSrcweir 	aPropertyFunctionName += rProperty;
4474cdf0e10cSrcweir 
4475cdf0e10cSrcweir 	SbxVariable* p = m_xScopeObj->Find( aPropertyFunctionName, SbxCLASS_METHOD );
4476cdf0e10cSrcweir 	SbMethod* pMeth = p != NULL ? PTR_CAST(SbMethod,p) : NULL;
4477cdf0e10cSrcweir 	if( pMeth == NULL )
4478cdf0e10cSrcweir 	{
4479cdf0e10cSrcweir 		// TODO: Check vba behavior concernig missing function
4480cdf0e10cSrcweir 		//StarBASIC::Error( SbERR_NO_METHOD, aFunctionName );
4481cdf0e10cSrcweir 		throw UnknownPropertyException();
4482cdf0e10cSrcweir 	}
4483cdf0e10cSrcweir 
4484cdf0e10cSrcweir 	// Setup parameter
4485cdf0e10cSrcweir 	SbxArrayRef xArray = new SbxArray;
4486cdf0e10cSrcweir 	SbxVariableRef xVar = new SbxVariable( SbxVARIANT );
4487cdf0e10cSrcweir 	unoToSbxValue( (SbxVariable*)xVar, rValue );
4488cdf0e10cSrcweir 	xArray->Put( xVar, 1 );
4489cdf0e10cSrcweir 
4490cdf0e10cSrcweir 	// Call property method
4491cdf0e10cSrcweir 	SbxVariableRef xValue = new SbxVariable;
4492cdf0e10cSrcweir 	pMeth->SetParameters( xArray );
4493cdf0e10cSrcweir 	pMeth->Call( xValue );
4494cdf0e10cSrcweir 	//aRet = sbxToUnoValue( xValue );
4495cdf0e10cSrcweir 	pMeth->SetParameters( NULL );
4496cdf0e10cSrcweir 
4497cdf0e10cSrcweir 	// TODO: OutParameter?
4498cdf0e10cSrcweir 
4499cdf0e10cSrcweir 	// throw InvocationTargetException();
4500cdf0e10cSrcweir 
4501cdf0e10cSrcweir     //return aRet;
4502cdf0e10cSrcweir 
4503cdf0e10cSrcweir }
4504cdf0e10cSrcweir 
getValue(const::rtl::OUString & rProperty)4505cdf0e10cSrcweir Any SAL_CALL ModuleInvocationProxy::getValue( const ::rtl::OUString& rProperty ) throw( UnknownPropertyException )
4506cdf0e10cSrcweir {
4507cdf0e10cSrcweir 	if( !m_bProxyIsClassModuleObject )
4508cdf0e10cSrcweir 	    throw UnknownPropertyException();
4509cdf0e10cSrcweir 
4510cdf0e10cSrcweir 	vos::OGuard guard( Application::GetSolarMutex() );
4511cdf0e10cSrcweir 
4512cdf0e10cSrcweir 	::rtl::OUString aPropertyFunctionName( RTL_CONSTASCII_USTRINGPARAM( "Property Get ") );
4513cdf0e10cSrcweir 	aPropertyFunctionName += m_aPrefix;
4514cdf0e10cSrcweir 	aPropertyFunctionName += rProperty;
4515cdf0e10cSrcweir 
4516cdf0e10cSrcweir 	SbxVariable* p = m_xScopeObj->Find( aPropertyFunctionName, SbxCLASS_METHOD );
4517cdf0e10cSrcweir 	SbMethod* pMeth = p != NULL ? PTR_CAST(SbMethod,p) : NULL;
4518cdf0e10cSrcweir 	if( pMeth == NULL )
4519cdf0e10cSrcweir 	{
4520cdf0e10cSrcweir 		// TODO: Check vba behavior concernig missing function
4521cdf0e10cSrcweir 		//StarBASIC::Error( SbERR_NO_METHOD, aFunctionName );
4522cdf0e10cSrcweir 	    throw UnknownPropertyException();
4523cdf0e10cSrcweir 	}
4524cdf0e10cSrcweir 
4525cdf0e10cSrcweir 	// Call method
4526cdf0e10cSrcweir 	SbxVariableRef xValue = new SbxVariable;
4527cdf0e10cSrcweir 	pMeth->Call( xValue );
4528cdf0e10cSrcweir 	Any aRet = sbxToUnoValue( xValue );
4529cdf0e10cSrcweir     return aRet;
4530cdf0e10cSrcweir }
4531cdf0e10cSrcweir 
hasMethod(const::rtl::OUString &)4532cdf0e10cSrcweir sal_Bool SAL_CALL ModuleInvocationProxy::hasMethod( const ::rtl::OUString& ) throw()
4533cdf0e10cSrcweir {
4534cdf0e10cSrcweir     return sal_False;
4535cdf0e10cSrcweir }
4536cdf0e10cSrcweir 
hasProperty(const::rtl::OUString &)4537cdf0e10cSrcweir sal_Bool SAL_CALL ModuleInvocationProxy::hasProperty( const ::rtl::OUString& ) throw()
4538cdf0e10cSrcweir {
4539cdf0e10cSrcweir     return sal_False;
4540cdf0e10cSrcweir }
4541cdf0e10cSrcweir 
invoke(const::rtl::OUString & rFunction,const Sequence<Any> & rParams,Sequence<sal_Int16> &,Sequence<Any> &)4542cdf0e10cSrcweir Any SAL_CALL ModuleInvocationProxy::invoke( const ::rtl::OUString& rFunction,
4543cdf0e10cSrcweir 											const Sequence< Any >& rParams,
4544cdf0e10cSrcweir 											Sequence< sal_Int16 >&,
4545cdf0e10cSrcweir 											Sequence< Any >& )
4546cdf0e10cSrcweir     throw( CannotConvertException, InvocationTargetException )
4547cdf0e10cSrcweir {
4548cdf0e10cSrcweir 	vos::OGuard guard( Application::GetSolarMutex() );
4549cdf0e10cSrcweir 
4550cdf0e10cSrcweir     Any aRet;
4551cdf0e10cSrcweir 	SbxObjectRef xScopeObj = m_xScopeObj;
4552cdf0e10cSrcweir 	if( !xScopeObj.Is() )
4553cdf0e10cSrcweir 		return aRet;
4554cdf0e10cSrcweir 
4555cdf0e10cSrcweir 	::rtl::OUString aFunctionName = m_aPrefix;
4556cdf0e10cSrcweir 	aFunctionName += rFunction;
4557cdf0e10cSrcweir 
4558cdf0e10cSrcweir     sal_Bool bSetRescheduleBack = sal_False;
4559cdf0e10cSrcweir     sal_Bool bOldReschedule = sal_True;
4560cdf0e10cSrcweir     SbiInstance* pInst = pINST;
4561cdf0e10cSrcweir     if( pInst && pInst->IsCompatibility() )
4562cdf0e10cSrcweir     {
4563cdf0e10cSrcweir         bOldReschedule = pInst->IsReschedule();
4564cdf0e10cSrcweir         if ( bOldReschedule )
4565cdf0e10cSrcweir         {
4566cdf0e10cSrcweir             pInst->EnableReschedule( sal_False );
4567cdf0e10cSrcweir             bSetRescheduleBack = sal_True;
4568cdf0e10cSrcweir         }
4569cdf0e10cSrcweir     }
4570cdf0e10cSrcweir 
4571cdf0e10cSrcweir 	SbxVariable* p = xScopeObj->Find( aFunctionName, SbxCLASS_METHOD );
4572cdf0e10cSrcweir 	SbMethod* pMeth = p != NULL ? PTR_CAST(SbMethod,p) : NULL;
4573cdf0e10cSrcweir 	if( pMeth == NULL )
4574cdf0e10cSrcweir 	{
4575cdf0e10cSrcweir 		// TODO: Check vba behavior concernig missing function
4576cdf0e10cSrcweir 		//StarBASIC::Error( SbERR_NO_METHOD, aFunctionName );
4577cdf0e10cSrcweir 		return aRet;
4578cdf0e10cSrcweir 	}
4579cdf0e10cSrcweir 
4580cdf0e10cSrcweir 	// Setup parameters
4581cdf0e10cSrcweir 	SbxArrayRef xArray;
4582cdf0e10cSrcweir 	sal_Int32 nParamCount = rParams.getLength();
4583cdf0e10cSrcweir 	if( nParamCount )
4584cdf0e10cSrcweir 	{
4585cdf0e10cSrcweir 		xArray = new SbxArray;
4586cdf0e10cSrcweir 		const Any *pArgs = rParams.getConstArray();
4587cdf0e10cSrcweir 		for( sal_Int32 i = 0 ; i < nParamCount ; i++ )
4588cdf0e10cSrcweir 		{
4589cdf0e10cSrcweir 			SbxVariableRef xVar = new SbxVariable( SbxVARIANT );
4590cdf0e10cSrcweir 			unoToSbxValue( (SbxVariable*)xVar, pArgs[i] );
4591cdf0e10cSrcweir 			xArray->Put( xVar, sal::static_int_cast< sal_uInt16 >(i+1) );
4592cdf0e10cSrcweir 		}
4593cdf0e10cSrcweir 	}
4594cdf0e10cSrcweir 
4595cdf0e10cSrcweir 	// Call method
4596cdf0e10cSrcweir 	SbxVariableRef xValue = new SbxVariable;
4597cdf0e10cSrcweir 	if( xArray.Is() )
4598cdf0e10cSrcweir 		pMeth->SetParameters( xArray );
4599cdf0e10cSrcweir 	pMeth->Call( xValue );
4600cdf0e10cSrcweir 	aRet = sbxToUnoValue( xValue );
4601cdf0e10cSrcweir 	pMeth->SetParameters( NULL );
4602cdf0e10cSrcweir 
4603cdf0e10cSrcweir     if( bSetRescheduleBack )
4604cdf0e10cSrcweir         pInst->EnableReschedule( bOldReschedule );
4605cdf0e10cSrcweir 
4606cdf0e10cSrcweir 	// TODO: OutParameter?
4607cdf0e10cSrcweir 
4608cdf0e10cSrcweir     return aRet;
4609cdf0e10cSrcweir }
4610cdf0e10cSrcweir 
dispose()4611cdf0e10cSrcweir void SAL_CALL ModuleInvocationProxy::dispose()
4612cdf0e10cSrcweir     throw(RuntimeException)
4613cdf0e10cSrcweir {
4614cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
4615cdf0e10cSrcweir 
4616cdf0e10cSrcweir     EventObject aEvent( (XComponent*)this );
4617cdf0e10cSrcweir     m_aListeners.disposeAndClear( aEvent );
4618cdf0e10cSrcweir 
4619cdf0e10cSrcweir     m_xScopeObj = NULL;
4620cdf0e10cSrcweir }
4621cdf0e10cSrcweir 
addEventListener(const Reference<XEventListener> & xListener)4622cdf0e10cSrcweir void SAL_CALL ModuleInvocationProxy::addEventListener( const Reference< XEventListener >& xListener )
4623cdf0e10cSrcweir     throw (RuntimeException)
4624cdf0e10cSrcweir {
4625cdf0e10cSrcweir     m_aListeners.addInterface( xListener );
4626cdf0e10cSrcweir }
4627cdf0e10cSrcweir 
removeEventListener(const Reference<XEventListener> & xListener)4628cdf0e10cSrcweir void SAL_CALL ModuleInvocationProxy::removeEventListener( const Reference< XEventListener >& xListener )
4629cdf0e10cSrcweir     throw (RuntimeException)
4630cdf0e10cSrcweir {
4631cdf0e10cSrcweir     m_aListeners.removeInterface( xListener );
4632cdf0e10cSrcweir }
4633cdf0e10cSrcweir 
4634cdf0e10cSrcweir 
createComListener(const Any & aControlAny,const::rtl::OUString & aVBAType,const::rtl::OUString & aPrefix,SbxObjectRef xScopeObj)4635cdf0e10cSrcweir Reference< XInterface > createComListener( const Any& aControlAny, const ::rtl::OUString& aVBAType,
4636cdf0e10cSrcweir 										   const ::rtl::OUString& aPrefix, SbxObjectRef xScopeObj )
4637cdf0e10cSrcweir {
4638cdf0e10cSrcweir 	Reference< XInterface > xRet;
4639cdf0e10cSrcweir 
4640cdf0e10cSrcweir 	Reference< XComponentContext > xContext = getComponentContext_Impl();
4641cdf0e10cSrcweir 	Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() );
4642cdf0e10cSrcweir 
4643cdf0e10cSrcweir 	Reference< XInvocation > xProxy = new ModuleInvocationProxy( aPrefix, xScopeObj );
4644cdf0e10cSrcweir 
4645cdf0e10cSrcweir 	Sequence<Any> args( 3 );
4646cdf0e10cSrcweir 	args[0] <<= aControlAny;
4647cdf0e10cSrcweir 	args[1] <<= aVBAType;
4648cdf0e10cSrcweir 	args[2] <<= xProxy;
4649cdf0e10cSrcweir 
4650cdf0e10cSrcweir 	try
4651cdf0e10cSrcweir 	{
4652cdf0e10cSrcweir 		xRet = xServiceMgr->createInstanceWithArgumentsAndContext(
4653cdf0e10cSrcweir 			::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.custom.UnoComListener")),
4654cdf0e10cSrcweir 			args, xContext );
4655cdf0e10cSrcweir 	}
4656cdf0e10cSrcweir 	catch( const Exception& )
4657cdf0e10cSrcweir 	{
4658cdf0e10cSrcweir 		implHandleAnyException( ::cppu::getCaughtException() );
4659cdf0e10cSrcweir 	}
4660cdf0e10cSrcweir 
4661cdf0e10cSrcweir 	return xRet;
4662cdf0e10cSrcweir }
4663cdf0e10cSrcweir 
4664cdf0e10cSrcweir typedef std::vector< WeakReference< XComponent > >	ComponentRefVector;
4665cdf0e10cSrcweir 
4666cdf0e10cSrcweir struct StarBasicDisposeItem
4667cdf0e10cSrcweir {
4668cdf0e10cSrcweir 	StarBASIC*				m_pBasic;
4669cdf0e10cSrcweir 	SbxArrayRef				m_pRegisteredVariables;
4670cdf0e10cSrcweir 	ComponentRefVector		m_vComImplementsObjects;
4671cdf0e10cSrcweir 
StarBasicDisposeItemStarBasicDisposeItem4672cdf0e10cSrcweir 	StarBasicDisposeItem( StarBASIC* pBasic )
4673cdf0e10cSrcweir 		: m_pBasic( pBasic )
4674cdf0e10cSrcweir 	{
4675cdf0e10cSrcweir 		m_pRegisteredVariables = new SbxArray();
4676cdf0e10cSrcweir 	}
4677cdf0e10cSrcweir };
4678cdf0e10cSrcweir 
4679cdf0e10cSrcweir typedef std::vector< StarBasicDisposeItem* > DisposeItemVector;
4680cdf0e10cSrcweir 
4681cdf0e10cSrcweir static DisposeItemVector GaDisposeItemVector;
4682cdf0e10cSrcweir 
lcl_findItemForBasic(StarBASIC * pBasic)4683cdf0e10cSrcweir DisposeItemVector::iterator lcl_findItemForBasic( StarBASIC* pBasic )
4684cdf0e10cSrcweir {
4685cdf0e10cSrcweir 	DisposeItemVector::iterator it;
4686cdf0e10cSrcweir 	for( it = GaDisposeItemVector.begin() ; it != GaDisposeItemVector.end() ; ++it )
4687cdf0e10cSrcweir 	{
4688cdf0e10cSrcweir 		StarBasicDisposeItem* pItem = *it;
4689cdf0e10cSrcweir 		if( pItem->m_pBasic == pBasic )
4690cdf0e10cSrcweir 			return it;
4691cdf0e10cSrcweir 	}
4692cdf0e10cSrcweir 	return GaDisposeItemVector.end();
4693cdf0e10cSrcweir }
4694cdf0e10cSrcweir 
lcl_getOrCreateItemForBasic(StarBASIC * pBasic)4695cdf0e10cSrcweir StarBasicDisposeItem* lcl_getOrCreateItemForBasic( StarBASIC* pBasic )
4696cdf0e10cSrcweir {
4697cdf0e10cSrcweir 	DisposeItemVector::iterator it = lcl_findItemForBasic( pBasic );
4698cdf0e10cSrcweir 	StarBasicDisposeItem* pItem = (it != GaDisposeItemVector.end()) ? *it : NULL;
4699cdf0e10cSrcweir 	if( pItem == NULL )
4700cdf0e10cSrcweir 	{
4701cdf0e10cSrcweir 		pItem = new StarBasicDisposeItem( pBasic );
4702cdf0e10cSrcweir 		GaDisposeItemVector.push_back( pItem );
4703cdf0e10cSrcweir 	}
4704cdf0e10cSrcweir 	return pItem;
4705cdf0e10cSrcweir }
4706cdf0e10cSrcweir 
registerComponentToBeDisposedForBasic(Reference<XComponent> xComponent,StarBASIC * pBasic)4707cdf0e10cSrcweir void registerComponentToBeDisposedForBasic
4708cdf0e10cSrcweir 	( Reference< XComponent > xComponent, StarBASIC* pBasic )
4709cdf0e10cSrcweir {
4710cdf0e10cSrcweir 	StarBasicDisposeItem* pItem = lcl_getOrCreateItemForBasic( pBasic );
4711cdf0e10cSrcweir 	pItem->m_vComImplementsObjects.push_back( xComponent );
4712cdf0e10cSrcweir }
4713cdf0e10cSrcweir 
registerComListenerVariableForBasic(SbxVariable * pVar,StarBASIC * pBasic)4714cdf0e10cSrcweir void registerComListenerVariableForBasic( SbxVariable* pVar, StarBASIC* pBasic )
4715cdf0e10cSrcweir {
4716cdf0e10cSrcweir 	StarBasicDisposeItem* pItem = lcl_getOrCreateItemForBasic( pBasic );
4717cdf0e10cSrcweir 	SbxArray* pArray = pItem->m_pRegisteredVariables;
4718cdf0e10cSrcweir 	pArray->Put( pVar, pArray->Count() );
4719cdf0e10cSrcweir }
4720cdf0e10cSrcweir 
disposeComVariablesForBasic(StarBASIC * pBasic)4721cdf0e10cSrcweir void disposeComVariablesForBasic( StarBASIC* pBasic )
4722cdf0e10cSrcweir {
4723cdf0e10cSrcweir 	DisposeItemVector::iterator it = lcl_findItemForBasic( pBasic );
4724cdf0e10cSrcweir 	if( it != GaDisposeItemVector.end() )
4725cdf0e10cSrcweir 	{
4726cdf0e10cSrcweir 		StarBasicDisposeItem* pItem = *it;
4727cdf0e10cSrcweir 
4728cdf0e10cSrcweir 		SbxArray* pArray = pItem->m_pRegisteredVariables;
4729cdf0e10cSrcweir 		sal_uInt16 nCount = pArray->Count();
4730cdf0e10cSrcweir 		for( sal_uInt16 i = 0 ; i < nCount ; ++i )
4731cdf0e10cSrcweir 		{
4732cdf0e10cSrcweir 			SbxVariable* pVar = pArray->Get( i );
4733cdf0e10cSrcweir 			pVar->ClearComListener();
4734cdf0e10cSrcweir 		}
4735cdf0e10cSrcweir 
4736cdf0e10cSrcweir 		ComponentRefVector& rv = pItem->m_vComImplementsObjects;
4737cdf0e10cSrcweir 		ComponentRefVector::iterator itCRV;
4738cdf0e10cSrcweir 		for( itCRV = rv.begin() ; itCRV != rv.end() ; ++itCRV )
4739cdf0e10cSrcweir 		{
4740cdf0e10cSrcweir             try
4741cdf0e10cSrcweir             {
4742cdf0e10cSrcweir                 Reference< XComponent > xComponent( (*itCRV).get(), UNO_QUERY_THROW );
4743cdf0e10cSrcweir                 xComponent->dispose();
4744cdf0e10cSrcweir             }
4745cdf0e10cSrcweir             catch( Exception& )
4746cdf0e10cSrcweir             {}
4747cdf0e10cSrcweir 		}
4748cdf0e10cSrcweir 
4749cdf0e10cSrcweir 		delete pItem;
4750cdf0e10cSrcweir 		GaDisposeItemVector.erase( it );
4751cdf0e10cSrcweir 	}
4752cdf0e10cSrcweir }
4753cdf0e10cSrcweir 
4754cdf0e10cSrcweir 
4755cdf0e10cSrcweir // Handle module implements mechanism for OLE types
createCOMWrapperForIface(Any & o_rRetAny,SbClassModuleObject * pProxyClassModuleObject)4756cdf0e10cSrcweir bool SbModule::createCOMWrapperForIface( Any& o_rRetAny, SbClassModuleObject* pProxyClassModuleObject )
4757cdf0e10cSrcweir {
4758cdf0e10cSrcweir 	// For now: Take first interface that allows to instantiate COM wrapper
4759cdf0e10cSrcweir 	// TODO: Check if support for multiple interfaces is needed
4760cdf0e10cSrcweir 
4761cdf0e10cSrcweir 	Reference< XComponentContext > xContext = getComponentContext_Impl();
4762cdf0e10cSrcweir 	Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() );
4763cdf0e10cSrcweir 	Reference< XSingleServiceFactory > xComImplementsFactory
4764cdf0e10cSrcweir 	(
4765cdf0e10cSrcweir         xServiceMgr->createInstanceWithContext(
4766cdf0e10cSrcweir 	        ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.custom.ComImplementsFactory")), xContext ),
4767cdf0e10cSrcweir 		UNO_QUERY
4768cdf0e10cSrcweir 	);
4769cdf0e10cSrcweir 	if( !xComImplementsFactory.is() )
4770cdf0e10cSrcweir 		return false;
4771cdf0e10cSrcweir 
4772cdf0e10cSrcweir 	bool bSuccess = false;
4773cdf0e10cSrcweir 
4774cdf0e10cSrcweir 	SbxArray* pModIfaces = pClassData->mxIfaces;
4775cdf0e10cSrcweir 	sal_uInt16 nCount = pModIfaces->Count();
4776cdf0e10cSrcweir 	for( sal_uInt16 i = 0 ; i < nCount ; ++i )
4777cdf0e10cSrcweir 	{
4778cdf0e10cSrcweir 		SbxVariable* pVar = pModIfaces->Get( i );
4779cdf0e10cSrcweir 		::rtl::OUString aIfaceName = pVar->GetName();
4780cdf0e10cSrcweir 
4781*0848378bSHerbert Dürr 		if( !aIfaceName.isEmpty() )
4782cdf0e10cSrcweir 		{
4783cdf0e10cSrcweir 			::rtl::OUString aPureIfaceName = aIfaceName;
4784cdf0e10cSrcweir 			sal_Int32 indexLastDot = aIfaceName.lastIndexOf('.');
4785cdf0e10cSrcweir 			if ( indexLastDot > -1 )
4786cdf0e10cSrcweir 				aPureIfaceName = aIfaceName.copy( indexLastDot + 1 );
4787cdf0e10cSrcweir 
4788cdf0e10cSrcweir 			Reference< XInvocation > xProxy = new ModuleInvocationProxy( aPureIfaceName, pProxyClassModuleObject );
4789cdf0e10cSrcweir 
4790cdf0e10cSrcweir 			Sequence<Any> args( 2 );
4791cdf0e10cSrcweir 			args[0] <<= aIfaceName;
4792cdf0e10cSrcweir 			args[1] <<= xProxy;
4793cdf0e10cSrcweir 
4794cdf0e10cSrcweir 			Reference< XInterface > xRet;
4795cdf0e10cSrcweir 			bSuccess = false;
4796cdf0e10cSrcweir 			try
4797cdf0e10cSrcweir 			{
4798cdf0e10cSrcweir 				xRet = xComImplementsFactory->createInstanceWithArguments( args );
4799cdf0e10cSrcweir 				bSuccess = true;
4800cdf0e10cSrcweir 			}
4801cdf0e10cSrcweir 			catch( const Exception& )
4802cdf0e10cSrcweir 			{
4803cdf0e10cSrcweir 				implHandleAnyException( ::cppu::getCaughtException() );
4804cdf0e10cSrcweir 			}
4805cdf0e10cSrcweir 
4806cdf0e10cSrcweir 			if( bSuccess )
4807cdf0e10cSrcweir 			{
4808cdf0e10cSrcweir 				Reference< XComponent > xComponent( xProxy, UNO_QUERY );
4809cdf0e10cSrcweir 				if( xComponent.is() )
4810cdf0e10cSrcweir 				{
4811cdf0e10cSrcweir 					StarBASIC* pParentBasic = NULL;
4812cdf0e10cSrcweir 					SbxObject* pCurObject = this;
4813cdf0e10cSrcweir 					do
4814cdf0e10cSrcweir 					{
4815cdf0e10cSrcweir 						SbxObject* pObjParent = pCurObject->GetParent();
4816cdf0e10cSrcweir 						pParentBasic = PTR_CAST( StarBASIC, pObjParent );
4817cdf0e10cSrcweir 						pCurObject = pObjParent;
4818cdf0e10cSrcweir 					}
4819cdf0e10cSrcweir 					while( pParentBasic == NULL && pCurObject != NULL );
4820cdf0e10cSrcweir 
4821cdf0e10cSrcweir 					OSL_ASSERT( pParentBasic != NULL );
4822cdf0e10cSrcweir 					registerComponentToBeDisposedForBasic( xComponent, pParentBasic );
4823cdf0e10cSrcweir 				}
4824cdf0e10cSrcweir 
4825cdf0e10cSrcweir 				o_rRetAny <<= xRet;
4826cdf0e10cSrcweir 				break;
4827cdf0e10cSrcweir 			}
4828cdf0e10cSrcweir 		}
4829cdf0e10cSrcweir  	}
4830cdf0e10cSrcweir 
4831cdf0e10cSrcweir 	return bSuccess;
4832cdf0e10cSrcweir }
4833cdf0e10cSrcweir 
4834cdf0e10cSrcweir 
4835cdf0e10cSrcweir // Due to an incorrect behavior IE returns an object instead of a string
4836cdf0e10cSrcweir // in some scenarios. Calling toString at the object may correct this.
4837cdf0e10cSrcweir // Helper function used in sbxvalue.cxx
handleToStringForCOMObjects(SbxObject * pObj,SbxValue * pVal)4838cdf0e10cSrcweir bool handleToStringForCOMObjects( SbxObject* pObj, SbxValue* pVal )
4839cdf0e10cSrcweir {
4840cdf0e10cSrcweir 	bool bSuccess = false;
4841cdf0e10cSrcweir 
4842cdf0e10cSrcweir 	SbUnoObject* pUnoObj = NULL;
4843cdf0e10cSrcweir 	if( pObj != NULL && (pUnoObj = PTR_CAST(SbUnoObject,(SbxObject*)pObj)) != NULL )
4844cdf0e10cSrcweir 	{
4845cdf0e10cSrcweir 		// Only for native COM objects
4846cdf0e10cSrcweir 		if( pUnoObj->isNativeCOMObject() )
4847cdf0e10cSrcweir 		{
4848cdf0e10cSrcweir 			SbxVariableRef pMeth = pObj->Find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "toString" ) ), SbxCLASS_METHOD );
4849cdf0e10cSrcweir 			if ( pMeth.Is() )
4850cdf0e10cSrcweir 			{
4851cdf0e10cSrcweir 				SbxValues aRes;
4852cdf0e10cSrcweir 				pMeth->Get( aRes );
4853cdf0e10cSrcweir 				pVal->Put( aRes );
4854cdf0e10cSrcweir                 bSuccess = true;
4855cdf0e10cSrcweir 			}
4856cdf0e10cSrcweir 		}
4857cdf0e10cSrcweir 	}
4858cdf0e10cSrcweir 	return bSuccess;
4859cdf0e10cSrcweir }
4860cdf0e10cSrcweir 
4861