merge the formfield patch from ooo-build
[ooovba.git] / extensions / source / ole / oleobjw.hxx
blobfa2627975d1b941adaa734ffb6a3b3e01e9da9a8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: oleobjw.hxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __OLEOBJW_HXX
32 #define __OLEOBJW_HXX
33 #include "ole2uno.hxx"
35 #ifdef _MSC_VER
36 #pragma warning (push,1)
37 #pragma warning (disable:4548)
38 #endif
40 #include <tools/presys.h>
41 #define _WIN32_WINNT 0x0400
43 #if defined(_MSC_VER) && (_MSC_VER >= 1300)
44 #undef _DEBUG
45 #endif
46 #include <atlbase.h>
47 #include <vector>
48 #include <hash_map>
49 #include <tools/postsys.h>
51 #ifdef _MSC_VER
52 #pragma warning (pop)
53 #endif
54 #include <cppuhelper/implbase3.hxx>
55 #include <cppuhelper/implbase4.hxx>
56 #include <cppuhelper/implbase6.hxx>
58 #include <com/sun/star/lang/XInitialization.hpp>
59 #include <com/sun/star/bridge/oleautomation/XAutomationObject.hpp>
60 #include <rtl/ustring.hxx>
62 #include <com/sun/star/script/XDefaultProperty.hpp>
63 #include <com/sun/star/script/XDefaultMethod.hpp>
65 #include <typelib/typedescription.hxx>
66 #include "unoconversionutilities.hxx"
67 #include "windata.hxx"
68 using namespace cppu;
69 using namespace rtl;
70 using namespace std;
71 using namespace com::sun::star::lang;
72 using namespace com::sun::star::bridge;
73 using namespace com::sun::star::bridge::oleautomation;
75 namespace ole_adapter
80 typedef hash_map<OUString, pair<DISPID, unsigned short>, hashOUString_Impl, equalOUString_Impl> DispIdMap;
82 typedef hash_multimap<OUString, unsigned int, hashOUString_Impl, equalOUString_Impl> TLBFuncIndexMap;
84 // This class wraps an IDispatch and maps XInvocation calls to IDispatch calls on the wrapped object.
85 // If m_TypeDescription is set then this class represents an UNO interface implemented in a COM component.
86 // The interface is not a real interface in terms of an abstract class but is realized through IDispatch.
87 class IUnknownWrapper_Impl : public WeakImplHelper6<XInvocation, XBridgeSupplier2, XInitialization, XAutomationObject, XDefaultProperty, XDefaultMethod>,
89 public UnoConversionUtilities<IUnknownWrapper_Impl>
92 public:
93 IUnknownWrapper_Impl(Reference<XMultiServiceFactory> &xFactory,
94 sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass);
96 ~IUnknownWrapper_Impl();
98 //XInterface
99 Any SAL_CALL queryInterface(const Type& t)
100 throw (RuntimeException);
102 // XInvokation
103 virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection( )
104 throw(RuntimeException);
105 virtual Any SAL_CALL invoke( const OUString& aFunctionName,
106 const Sequence< Any >& aParams,
107 Sequence< sal_Int16 >& aOutParamIndex,
108 Sequence< Any >& aOutParam )
109 throw(IllegalArgumentException, CannotConvertException,
110 InvocationTargetException, RuntimeException);
111 virtual void SAL_CALL setValue( const OUString& aPropertyName,
112 const Any& aValue )
113 throw(UnknownPropertyException, CannotConvertException,
114 InvocationTargetException, RuntimeException);
115 virtual Any SAL_CALL getValue( const OUString& aPropertyName )
116 throw(UnknownPropertyException, RuntimeException);
117 virtual sal_Bool SAL_CALL hasMethod( const OUString& aName )
118 throw(RuntimeException);
119 virtual sal_Bool SAL_CALL hasProperty( const OUString& aName )
120 throw(RuntimeException);
122 // XBridgeSupplier2
123 // This interface is implemented to provide a safe way to obtain the original
124 // IUnknown or IDispatch within the function anyToVariant. The function asks
125 // every UNO object for its XBridgeSupplier2 and if it is available uses it to convert
126 // the object with its own supplier.
127 virtual Any SAL_CALL createBridge( const Any& modelDepObject,
128 const Sequence< sal_Int8 >& aProcessId,
129 sal_Int16 sourceModelType,
130 sal_Int16 destModelType )
131 throw(IllegalArgumentException, RuntimeException);
133 // XInitialization
134 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments )
135 throw(Exception, RuntimeException);
136 virtual ::rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (::com::sun::star::uno::RuntimeException) { return m_sDefaultMember; }
137 protected:
138 virtual ::rtl::OUString SAL_CALL getDefaultMethodName( ) throw (::com::sun::star::uno::RuntimeException) { return m_sDefaultMember; }
140 // ----------------------------------------------------------------------------
141 virtual Any invokeWithDispIdUnoTlb(const OUString& sFunctionName,
142 const Sequence< Any >& Params,
143 Sequence<sal_Int16 >& OutParamIndex,
144 Sequence< Any >& OutParam);
145 // Is used for OleObjectFactory service
146 virtual Any invokeWithDispIdComTlb(const OUString& sFuncName,
147 const Sequence< Any >& Params,
148 Sequence< sal_Int16 >& OutParamIndex,
149 Sequence< Any >& OutParam);
151 // virtual void setValueWithDispId(DISPID dispID, const Any& Value);
153 // virtual Any getValueWithDispId(const OUString& sName, DISPID dispID);
156 // UnoConversionUtilities -------------------------------------------------------------------------------
157 virtual Reference<XInterface> createUnoWrapperInstance();
158 virtual Reference<XInterface> createComWrapperInstance();
160 /**Obtains a FUNCDESC structure for a function.
161 Fills the FUNCDESC structure if ITypeInfo provides information for
162 the function of name sFuncName or pFuncDesc will not be filled in.
163 May throw a BridgeRuntimeError.
165 void getFuncDesc(const OUString & sFuncName, FUNCDESC ** pFuncDesc);
166 /**Obtains a FUNCDESC structures or a VARDESC structure
167 for a property. pFuncDescPut may also contain
168 a structure for a "propertyputref" operation. If pFuncDesc contains a
169 "put ref" or "put" FUNCDESC depends on what was found first in the type
170 description.
171 Fills the FUNCDESC structure if ITypeInfo provides information for
172 the respective property functions or the structures will not be filled in.
173 May throw a BridgeRuntimeError.
175 void getPropDesc(const OUString & sFuncName, FUNCDESC ** pFuncDescGet,
176 FUNCDESC** pFuncDescPut, VARDESC ** pVarDesc);
177 // These functions are for the case if an object of this class wraps an IDispatch
178 // object that implements UNO interfaces. In that case the member m_seqTypes
179 // is set through XInitialization::initialize.
180 void getMethodInfo(const OUString& sName, TypeDescription& methodDescription);
181 // After return attributInfo contains typelib_InterfaceAttributeTypeDescription::pAttributeTypeRef
182 void getAttributeInfo(const OUString& sName, TypeDescription& attributeInfo);
183 // used by get MethodInfo
184 TypeDescription getInterfaceMemberDescOfCurrentCall(const OUString& sName);
185 /** Returns alway a valid ITypeInfo interface or throws a BridgeRuntimeError.
186 The returned interface does not need to be AddRef'ed as long as it is locally
187 used. The interface is kept in the instance of this class.
189 ITypeInfo* getTypeInfo();
191 /** Returns the DISPID for a function or property name. If true is returned then
192 id contains a valid DISPID.
194 bool getDispid(const OUString& sFuncName, DISPID * id);
196 /** Gets the element type in a VARIANT like style. E.g. if desc->lptdesc contains
197 a VT_PTR than it is replaced by VT_BYREF and VT_SAFEARRAY is replaced by VT_ARRAY
198 If the TYPEDESC describes an SAFEARRAY then varType is a combination of VT_ARRAY
199 and the element type.
200 The argument desc must be obtained from FUNCDESC::lprgelemdescParam[i].tdesc where
201 FUNCDESC was obtained from the ITypeInfo belonging to wrapped IDispatch.
203 VARTYPE getElementTypeDesc( const TYPEDESC *desc);
204 /** Iterates over all functions and put the names and indices into the map
205 m_mapComFunc of type TLBFuncIndexMap.
206 Call the function every time before accessing the map.
207 Throws a BridgeRuntimeError on failure.
209 void buildComTlbIndex();
211 /** Returns a FUNCDESC structure which contains type information about the
212 current XInvocation::invoke call. The FUNCDESC either describes a method,
213 a property put or a property get operation.
214 It uses the types com.sun.star.bridge.oleautomation.PropertyPutArgument
215 which can be
216 contained in the sequence of in-arguments of invoke to determine if the call is
217 a property put or property get operation.
218 If no adequate FUNCDESC was found, an IllegalArgumentException is thrown.
219 Therefore it is safe to assume that the returned FUNCDESC* is not NULL.
221 @exception IllegalArgumentException
222 Thrown if no adequate FUNCDESC could be found.
224 void getFuncDescForInvoke(const OUString & sFuncName,
225 const Sequence<Any> & seqArgs, FUNCDESC** pFuncDesc);
227 // Finds out wheter the wrapped IDispatch is an JScript Object. This is is
228 // done by
229 // asking for the property "_environment". If it has the value "JScript"
230 // (case insensitive) then the IDispatch is considered a JScript object.
231 sal_Bool isJScriptObject();
232 // -------------------------------------------------------------------------------
234 // If UNO interfaces are implemented in JScript objects, VB or C++ COM objects
235 // and those are passed as parameter to a UNO interface function, then
236 // the IDispatch* are wrapped by objects of this class. Assuming that the functions
237 // implemented by the IDispatch object returns another UNO interface then
238 // it has to be wrapped to this type. But this is only possible if an object of this
239 // wrapper class knows what type it is represting. The member m_TypeDescription holds this
240 // information.
241 // m_TypeDescription is only useful when an object wraps an IDispatch object that implements
242 // an UNO interface. The value is set during a call to XInitialization::initialize.
243 Sequence<Type> m_seqTypes;
244 CComPtr<IUnknown> m_spUnknown;
245 CComPtr<IDispatch> m_spDispatch;
246 rtl::OUString m_sTypeName; // is "" ( not initialised ), "IDispatch" ( we have no idea ) or "SomeLibrary.SomeTypeName" if we managed to get a type
247 /** This value is set dureing XInitialization::initialize. It indicates that the COM interface
248 was transported as VT_DISPATCH in a VARIANT rather then a VT_UNKNOWN
250 sal_Bool m_bOriginalDispatch;
251 DispIdMap m_dispIdMap;
252 Reference<XIdlClass>* m_pxIdlClass;
255 // used by isJScriptObject
256 enum JScriptDetermination{ JScriptUndefined=0, NoJScript, IsJScript};
257 JScriptDetermination m_eJScript;
258 // The map is filled by buildComTlbIndex
259 // It maps Uno Function names to an index which is used in ITypeInfo::GetFuncDesc
260 TLBFuncIndexMap m_mapComFunc;
261 // used for synchroizing the computation of the content for m_mapComFunc
262 bool m_bComTlbIndexInit;
263 // Keeps the ITypeInfo obtained from IDispatch::GetTypeInfo
264 CComPtr< ITypeInfo > m_spTypeInfo;
265 rtl::OUString m_sDefaultMember;
266 bool m_bHasDfltMethod;
267 bool m_bHasDfltProperty;
270 } // end namespace
271 #endif