Update ooo320-m1
[ooovba.git] / extensions / source / ole / unoobjw.hxx
blob1b1a1dbcf935399743f086b1e4e931a426d51fe8
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: unoobjw.hxx,v $
10 * $Revision: 1.12 $
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 _UNOOBJW_HXX
32 #define _UNOOBJW_HXX
34 #include <com/sun/star/bridge/XBridgeSupplier2.hpp>
35 #include <com/sun/star/beans/XExactName.hpp>
36 #include <com/sun/star/lang/XInitialization.hpp>
37 #include <com/sun/star/script/InvocationInfo.hpp>
38 #include <vos/refernce.hxx>
40 #include <tools/presys.h>
41 #include "comifaces.hxx"
42 #include <tools/postsys.h>
44 #include "ole2uno.hxx"
45 #include "unoconversionutilities.hxx"
47 //#define INVOCATION_SERVICE L"com.sun.star.script.Invocation"
48 #define JSCRIPT_VALUE_FUNC L"_GetValueObject"
49 #define GET_STRUCT_FUNC L"_GetStruct"
50 #define BRIDGE_VALUE_FUNC L"Bridge_GetValueObject"
51 #define BRIDGE_GET_STRUCT_FUNC L"Bridge_GetStruct"
52 #define BRIDGE_CREATE_TYPE_FUNC L"Bridge_CreateType"
54 #define DISPID_JSCRIPT_VALUE_FUNC -10l
55 #define DISPID_GET_STRUCT_FUNC -102
56 #define DISPID_CREATE_TYPE_FUNC -103
58 using namespace std;
59 using namespace cppu;
60 using namespace com::sun::star::bridge;
61 using namespace com::sun::star::script;
62 namespace ole_adapter
67 struct hash_IUnknown_Impl
69 size_t operator()(const IUnknown* p) const
71 return (size_t)p;
75 struct equal_to_IUnknown_Impl
77 bool operator()(const IUnknown* s1, const IUnknown* s2) const
79 return s1 == s2;
85 struct MemberInfo
87 MemberInfo() : flags(0), name() {}
88 MemberInfo(WORD f, const OUString& n) : flags(f), name(n) {}
90 WORD flags;
91 OUString name;
94 typedef hash_map
96 OUString,
97 DISPID,
98 hashOUString_Impl,
99 equalOUString_Impl
100 > NameToIdMap;
102 typedef hash_map
104 OUString,
105 sal_Bool,
106 hashOUString_Impl,
107 equalOUString_Impl
108 > BadNameMap;
110 typedef hash_map
112 DISPID,
113 MemberInfo
114 > IdToMemberInfoMap;
116 /*****************************************************************************
118 class declaration: InterfaceOleWrapper_Impl
120 *****************************************************************************/
122 class InterfaceOleWrapper_Impl : public WeakImplHelper2<XBridgeSupplier2, XInitialization>,
123 public IDispatchEx,
124 public UnoConversionUtilities<InterfaceOleWrapper_Impl>,
125 public IUnoObjectWrapper
127 public:
130 InterfaceOleWrapper_Impl(Reference<XMultiServiceFactory>& xFactory, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass);
131 ~InterfaceOleWrapper_Impl();
133 /* IUnknown methods */
134 STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj);
135 STDMETHOD_(ULONG, AddRef)();
136 STDMETHOD_(ULONG, Release)();
138 /* IDispatch methods */
139 STDMETHOD( GetTypeInfoCount )( unsigned int * pctinfo );
140 STDMETHOD( GetTypeInfo )( unsigned int itinfo, LCID lcid, ITypeInfo ** pptinfo );
141 STDMETHOD( GetIDsOfNames )( REFIID riid, OLECHAR ** rgszNames, unsigned int cNames,
142 LCID lcid, DISPID * rgdispid );
143 STDMETHOD( Invoke )( DISPID dispidMember, REFIID riid, LCID lcid, unsigned short wFlags,
144 DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo,
145 unsigned int * puArgErr );
147 /* IDispatchEx methods */
149 virtual HRESULT STDMETHODCALLTYPE GetDispID(
150 /* [in] */ BSTR bstrName,
151 /* [in] */ DWORD grfdex,
152 /* [out] */ DISPID __RPC_FAR *pid);
154 virtual /* [local] */ HRESULT STDMETHODCALLTYPE InvokeEx(
155 /* [in] */ DISPID id,
156 /* [in] */ LCID lcid,
157 /* [in] */ WORD wFlags,
158 /* [in] */ DISPPARAMS __RPC_FAR *pdp,
159 /* [out] */ VARIANT __RPC_FAR *pvarRes,
160 /* [out] */ EXCEPINFO __RPC_FAR *pei,
161 /* [unique][in] */ IServiceProvider __RPC_FAR *pspCaller);
163 virtual HRESULT STDMETHODCALLTYPE DeleteMemberByName(
164 /* [in] */ BSTR bstr,
165 /* [in] */ DWORD grfdex);
167 virtual HRESULT STDMETHODCALLTYPE DeleteMemberByDispID(
168 /* [in] */ DISPID id);
170 virtual HRESULT STDMETHODCALLTYPE GetMemberProperties(
171 /* [in] */ DISPID id,
172 /* [in] */ DWORD grfdexFetch,
173 /* [out] */ DWORD __RPC_FAR *pgrfdex);
175 virtual HRESULT STDMETHODCALLTYPE GetMemberName(
176 /* [in] */ DISPID id,
177 /* [out] */ BSTR __RPC_FAR *pbstrName);
179 virtual HRESULT STDMETHODCALLTYPE GetNextDispID(
180 /* [in] */ DWORD grfdex,
181 /* [in] */ DISPID id,
182 /* [out] */ DISPID __RPC_FAR *pid);
184 virtual HRESULT STDMETHODCALLTYPE GetNameSpaceParent(
185 /* [out] */ IUnknown __RPC_FAR *__RPC_FAR *ppunk);
187 // XBridgeSupplier2 ---------------------------------------------------
188 virtual Any SAL_CALL createBridge(const Any& modelDepObject,
189 const Sequence<sal_Int8>& ProcessId,
190 sal_Int16 sourceModelType,
191 sal_Int16 destModelType)
192 throw (IllegalArgumentException, RuntimeException);
194 //XInitialization -----------------------------------------------------
195 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException);
197 // IUnoObjectWrapper
198 STDMETHOD( getWrapperXInterface)( Reference<XInterface>* pXInt);
199 STDMETHOD( getOriginalUnoObject)( Reference<XInterface>* pXInt);
200 STDMETHOD( getOriginalUnoStruct)( Any * pStruct);
202 // UnoConversionUtility
203 virtual Reference< XInterface > createUnoWrapperInstance();
204 virtual Reference< XInterface > createComWrapperInstance();
207 protected:
208 virtual HRESULT doInvoke( DISPPARAMS * pdispparams, VARIANT * pvarResult,
209 EXCEPINFO * pexcepinfo, unsigned int * puArgErr, OUString & name, Sequence<Any>& params);
211 virtual HRESULT doGetProperty( DISPPARAMS * pdispparams, VARIANT * pvarResult,
212 EXCEPINFO * pexcepinfo, OUString & name );
214 virtual HRESULT doSetProperty( DISPPARAMS * pdispparams, VARIANT * pvarResult,
215 EXCEPINFO * pexcepinfo, unsigned int * puArgErr, OUString & name, Sequence<Any> params);
217 virtual HRESULT InvokeGeneral( DISPID dispidMember, unsigned short wFlags,
218 DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo,
219 unsigned int * puArgErr, sal_Bool& bHandled);
221 void convertDispparamsArgs( DISPID id, unsigned short wFlags, DISPPARAMS* pdispparams,
222 Sequence<Any>& rSeq);
224 sal_Bool getInvocationInfoForCall(DISPID id, InvocationInfo& info);
226 // vos::ORefCount m_refCount;
227 Reference<XInvocation> m_xInvocation;
228 Reference<XExactName> m_xExactName;
229 Reference<XInterface> m_xOrigin;
230 NameToIdMap m_nameToDispIdMap;
231 vector<MemberInfo> m_MemberInfos;
232 // This member is used to determine the default value
233 // denoted by DISPID_VALUE (0). For proper results in JavaScript
234 // we have to return the default value when we write an object
235 // as out parameter. That is, we get an JScript Array as parameter
236 // and put a wrapped object on index null. The array object tries
237 // to detect the default value. The wrapped object must then return
238 // its own IDispatch* otherwise we cannot access it within the script.
239 // see InterfaceOleWrapper_Impl::Invoke
240 VARTYPE m_defaultValueType;
244 /*****************************************************************************
246 class declaration: UnoObjectWrapperRemoteOpt
247 ( Uno Object Wrapper Remote Optimized)
248 This is the UNO wrapper used in the service com.sun.star.bridge.OleBridgeSupplierVar1.
249 Key features:
250 DISPIDs are passed out blindly. That is in GetIDsOfNames is no name checking carried out.
251 Only if Invoke fails the name is being checked. Moreover Invoke tries to figure out
252 if a call is made to a property or method if the flags are DISPATCH_METHOD | DISPATCH_PROPERTYPUT.
253 If something has been found out about a property or member than it is saved
254 in a MemberInfo structure hold by a IdToMemberInfoMap stl map.
256 *****************************************************************************/
257 class UnoObjectWrapperRemoteOpt: public InterfaceOleWrapper_Impl
259 public:
260 UnoObjectWrapperRemoteOpt( Reference<XMultiServiceFactory>& aFactory, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass);
261 ~UnoObjectWrapperRemoteOpt();
263 STDMETHOD( GetIDsOfNames )( REFIID riid, OLECHAR ** rgszNames, unsigned int cNames,
264 LCID lcid, DISPID * rgdispid );
265 STDMETHOD( Invoke )( DISPID dispidMember, REFIID riid, LCID lcid, unsigned short wFlags,
266 DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo,
267 unsigned int * puArgErr );
269 // UnoConversionUtility
270 // If UNO interfaces are converted in methods of this class then
271 // they are always wrapped with instances of this class
272 virtual Reference< XInterface > createUnoWrapperInstance();
274 protected:
276 HRESULT methodInvoke( DISPID dispidMember, DISPPARAMS * pdispparams, VARIANT * pvarResult,
277 EXCEPINFO * pexcepinfo, unsigned int * puArgErr, Sequence<Any> params);
278 // In GetIDsOfNames are blindly passed out, that is without verifying
279 // the name. If two names are passed in during different calls to
280 // GetIDsOfNames and the names differ only in their cases then different
281 // id's are passed out ( e.g. "doSomethingMethod" or "dosomethingmethod").
282 // In Invoke the DISPID is remapped to the name passed to GetIDsOfNames
283 // and the name is used as parameter for XInvocation::invoke. If invoke
284 // fails because of a wrong name, then m_xExactName ( XExactName) is used
285 // to verify the name. The correct name is then inserted to m_MemberInfos
286 // ( vector<MemberInfo> ). During the next call to Invoke the right name
287 // is used. .
290 BadNameMap m_badNameMap;
292 IdToMemberInfoMap m_idToMemberInfoMap;
294 DISPID m_currentId;
301 } // end namespace
303 #endif