LibreOffice Module extensions (master) 1
oleobjw.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include "ole2uno.hxx"
23#include "wincrap.hxx"
24
25#include <string_view>
26#include <unordered_map>
27#include <vector>
28
30
31#include <com/sun/star/lang/XInitialization.hpp>
32#include <com/sun/star/bridge/oleautomation/XAutomationObject.hpp>
33#include <com/sun/star/script/XAutomationInvocation.hpp>
34#include <rtl/ustring.hxx>
35
36#include <com/sun/star/script/XDefaultProperty.hpp>
37#include <com/sun/star/script/XDefaultMethod.hpp>
38#include <com/sun/star/script/XDirectInvocation.hpp>
39
40#include <typelib/typedescription.hxx>
42#include "windata.hxx"
43using namespace cppu;
44using namespace com::sun::star::lang;
45using namespace com::sun::star::bridge;
47
48typedef std::unordered_map<OUString, std::pair<DISPID, unsigned short>> DispIdMap;
49
50typedef std::unordered_multimap<OUString, unsigned int> TLBFuncIndexMap;
51
52// This class wraps an IDispatch and maps XInvocation calls to IDispatch calls on the wrapped object.
53// If m_TypeDescription is set then this class represents a UNO interface implemented in a COM component.
54// The interface is not a real interface in terms of an abstract class but is realized through IDispatch.
55class IUnknownWrapper : public WeakImplHelper< XBridgeSupplier2, XInitialization, XAutomationObject, XDefaultProperty, XDefaultMethod, XDirectInvocation, XAutomationInvocation >,
56
57 public UnoConversionUtilities<IUnknownWrapper>
58
59{
60public:
62 sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass);
63
64 ~IUnknownWrapper() override;
65
66 //XInterface
67 Any SAL_CALL queryInterface(const Type& t) override;
68
69 // XInvokation
70 virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection( ) override;
71 virtual Any SAL_CALL invoke( const OUString& aFunctionName,
72 const Sequence< Any >& aParams,
73 Sequence< sal_Int16 >& aOutParamIndex,
74 Sequence< Any >& aOutParam ) override;
75 virtual void SAL_CALL setValue( const OUString& aPropertyName,
76 const Any& aValue ) override;
77 virtual Any SAL_CALL getValue( const OUString& aPropertyName ) override;
78 virtual sal_Bool SAL_CALL hasMethod( const OUString& aName ) override;
79 virtual sal_Bool SAL_CALL hasProperty( const OUString& aName ) override;
80
81 // XBridgeSupplier2
82 // This interface is implemented to provide a safe way to obtain the original
83 // IUnknown or IDispatch within the function anyToVariant. The function asks
84 // every UNO object for its XBridgeSupplier2 and if it is available uses it to convert
85 // the object with its own supplier.
86 virtual Any SAL_CALL createBridge( const Any& modelDepObject,
87 const Sequence< sal_Int8 >& aProcessId,
88 sal_Int16 sourceModelType,
89 sal_Int16 destModelType ) override;
90
91 // XInitialization
92 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) override;
93
94 // XDefaultProperty
95 virtual OUString SAL_CALL getDefaultPropertyName( ) override { return m_sDefaultMember; }
96
97 // XDefaultMethod
98 virtual OUString SAL_CALL getDefaultMethodName( ) override { return m_sDefaultMember; }
99
100 virtual css::uno::Any SAL_CALL invokeGetProperty( const OUString& aFunctionName, const css::uno::Sequence< css::uno::Any >& aParams, css::uno::Sequence< ::sal_Int16 >& aOutParamIndex, css::uno::Sequence< css::uno::Any >& aOutParam ) override;
101 virtual css::uno::Any SAL_CALL invokePutProperty( const OUString& aFunctionName, const css::uno::Sequence< css::uno::Any >& aParams, css::uno::Sequence< ::sal_Int16 >& aOutParamIndex, css::uno::Sequence< css::uno::Any >& aOutParam ) override;
102
103 // XDirectInvocation
104 virtual css::uno::Any SAL_CALL directInvoke( const OUString& aName, const css::uno::Sequence< css::uno::Any >& aParams ) override;
105 virtual sal_Bool SAL_CALL hasMember( const OUString& aName ) override;
106
107
109 const OUString& sFuncName,
110 const Sequence< Any >& Params,
111 Sequence< sal_Int16 >& OutParamIndex,
112 Sequence< Any >& OutParam);
113
114
115protected:
116
117 virtual Any invokeWithDispIdUnoTlb(const OUString& sFunctionName,
118 const Sequence< Any >& Params,
119 Sequence<sal_Int16 >& OutParamIndex,
120 Sequence< Any >& OutParam);
121 // Is used for OleObjectFactory service
122 virtual Any invokeWithDispIdComTlb(const OUString& sFuncName,
123 const Sequence< Any >& Params,
124 Sequence< sal_Int16 >& OutParamIndex,
125 Sequence< Any >& OutParam);
126
127 // UnoConversionUtilities -------------------------------------------------------------------------------
130
136 void getFuncDesc(const OUString & sFuncName, FUNCDESC ** pFuncDesc);
146 void getPropDesc(const OUString & sFuncName, FUNCDESC ** pFuncDescGet,
147 FUNCDESC** pFuncDescPut, VARDESC ** pVarDesc);
148 // These functions are for the case if an object of this class wraps an IDispatch
149 // object that implements UNO interfaces. In that case the member m_seqTypes
150 // is set through XInitialization::initialize.
151 void getMethodInfo(std::u16string_view sName, TypeDescription& methodDescription);
152 // After return attributInfo contains typelib_InterfaceAttributeTypeDescription::pAttributeTypeRef
153 void getAttributeInfo(std::u16string_view sName, TypeDescription& attributeInfo);
154 // used by get MethodInfo
155 TypeDescription getInterfaceMemberDescOfCurrentCall(std::u16string_view sName);
160 ITypeInfo* getTypeInfo();
161
166 bool getDispid(const OUString& sFuncName, DISPID * id);
167
168 VARTYPE getUserDefinedElementType( ITypeInfo* pTypeInfo, const DWORD nHrefType );
169
177 VARTYPE getElementTypeDesc( const TYPEDESC *desc);
183 void buildComTlbIndex();
184
198 void getFuncDescForInvoke(const OUString & sFuncName,
199 const Sequence<Any> & seqArgs, FUNCDESC** pFuncDesc);
200
201 // Finds out whether the wrapped IDispatch is a JScript Object. This is
202 // done by
203 // asking for the property "_environment". If it has the value "JScript"
204 // (case insensitive) then the IDispatch is considered a JScript object.
205 bool isJScriptObject();
206
207
208 // If UNO interfaces are implemented in JScript objects, VB or C++ COM objects
209 // and those are passed as parameter to a UNO interface function, then
210 // the IDispatch* are wrapped by objects of this class. Assuming that the functions
211 // implemented by the IDispatch object returns another UNO interface then
212 // it has to be wrapped to this type. But this is only possible if an object of this
213 // wrapper class knows what type it is represting. The member m_TypeDescription holds this
214 // information.
215 // m_TypeDescription is only useful when an object wraps an IDispatch object that implements
216 // a UNO interface. The value is set during a call to XInitialization::initialize.
218 CComPtr<IUnknown> m_spUnknown;
219 CComPtr<IDispatch> m_spDispatch;
220 OUString m_sTypeName; // is "" ( not initialised ), "IDispatch" ( we have no idea ) or "SomeLibrary.SomeTypeName" if we managed to get a type
227
228
229 // used by isJScriptObject
232 // The map is filled by buildComTlbIndex
233 // It maps Uno Function names to an index which is used in ITypeInfo::GetFuncDesc
235 // used for synchronizing the computation of the content for m_mapComFunc
237 // Keeps the ITypeInfo obtained from IDispatch::GetTypeInfo
238 CComPtr< ITypeInfo > m_spTypeInfo;
242};
243
244/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
~IUnknownWrapper() override
Definition: oleobjw.cxx:91
virtual css::uno::Any SAL_CALL directInvoke(const OUString &aName, const css::uno::Sequence< css::uno::Any > &aParams) override
Definition: oleobjw.cxx:1241
virtual Reference< XInterface > createUnoWrapperInstance() override
Definition: oleobjw.cxx:1501
OUString m_sDefaultMember
Definition: oleobjw.hxx:239
bool isJScriptObject()
Definition: oleobjw.cxx:1590
TypeDescription getInterfaceMemberDescOfCurrentCall(std::u16string_view sName)
Definition: oleobjw.cxx:1549
bool m_bOriginalDispatch
This value is set during XInitialization::initialize.
Definition: oleobjw.hxx:224
DispIdMap m_dispIdMap
Definition: oleobjw.hxx:225
virtual Reference< XInterface > createComWrapperInstance() override
Definition: oleobjw.cxx:1518
Any SAL_CALL queryInterface(const Type &t) override
Definition: oleobjw.cxx:116
IUnknownWrapper(Reference< XMultiServiceFactory > const &xFactory, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass)
Definition: oleobjw.cxx:82
bool m_bHasDfltMethod
Definition: oleobjw.hxx:240
ITypeInfo * getTypeInfo()
Returns always a valid ITypeInfo interface or throws a BridgeRuntimeError.
Definition: oleobjw.cxx:2457
virtual Any invokeWithDispIdUnoTlb(const OUString &sFunctionName, const Sequence< Any > &Params, Sequence< sal_Int16 > &OutParamIndex, Sequence< Any > &OutParam)
Definition: oleobjw.cxx:725
virtual sal_Bool SAL_CALL hasProperty(const OUString &aName) override
Definition: oleobjw.cxx:627
virtual css::uno::Any SAL_CALL invokePutProperty(const OUString &aFunctionName, const css::uno::Sequence< css::uno::Any > &aParams, css::uno::Sequence< ::sal_Int16 > &aOutParamIndex, css::uno::Sequence< css::uno::Any > &aOutParam) override
Definition: oleobjw.cxx:171
virtual void SAL_CALL initialize(const Sequence< Any > &aArguments) override
Definition: oleobjw.cxx:1161
VARTYPE getUserDefinedElementType(ITypeInfo *pTypeInfo, const DWORD nHrefType)
Definition: oleobjw.cxx:2307
bool m_bComTlbIndexInit
Definition: oleobjw.hxx:236
virtual sal_Bool SAL_CALL hasMember(const OUString &aName) override
Definition: oleobjw.cxx:1486
void buildComTlbIndex()
Iterates over all functions and put the names and indices into the map m_mapComFunc of type TLBFuncIn...
Definition: oleobjw.cxx:2377
virtual void SAL_CALL setValue(const OUString &aPropertyName, const Any &aValue) override
Definition: oleobjw.cxx:264
void getMethodInfo(std::u16string_view sName, TypeDescription &methodDescription)
Definition: oleobjw.cxx:1526
bool getDispid(const OUString &sFuncName, DISPID *id)
Returns the DISPID for a function or property name.
Definition: oleobjw.cxx:2163
CComPtr< IDispatch > m_spDispatch
Definition: oleobjw.hxx:219
void getFuncDescForInvoke(const OUString &sFuncName, const Sequence< Any > &seqArgs, FUNCDESC **pFuncDesc)
Returns a FUNCDESC structure which contains type information about the current XInvocation::invoke ca...
Definition: oleobjw.cxx:2110
Sequence< Type > m_seqTypes
Definition: oleobjw.hxx:217
VARTYPE getElementTypeDesc(const TYPEDESC *desc)
Gets the element type in a VARIANT like style.
Definition: oleobjw.cxx:2351
virtual sal_Bool SAL_CALL hasMethod(const OUString &aName) override
Definition: oleobjw.cxx:577
void getPropDesc(const OUString &sFuncName, FUNCDESC **pFuncDescGet, FUNCDESC **pFuncDescPut, VARDESC **pVarDesc)
Obtains a FUNCDESC structures or a VARDESC structure for a property.
Definition: oleobjw.cxx:2237
virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection() override
Definition: oleobjw.cxx:134
virtual Any SAL_CALL createBridge(const Any &modelDepObject, const Sequence< sal_Int8 > &aProcessId, sal_Int16 sourceModelType, sal_Int16 destModelType) override
Definition: oleobjw.cxx:679
void getAttributeInfo(std::u16string_view sName, TypeDescription &attributeInfo)
Definition: oleobjw.cxx:1537
Any invokeWithDispIdComTlb(FuncDesc &aFuncDesc, const OUString &sFuncName, const Sequence< Any > &Params, Sequence< sal_Int16 > &OutParamIndex, Sequence< Any > &OutParam)
Definition: oleobjw.cxx:1640
TLBFuncIndexMap m_mapComFunc
Definition: oleobjw.hxx:234
virtual Any SAL_CALL invoke(const OUString &aFunctionName, const Sequence< Any > &aParams, Sequence< sal_Int16 > &aOutParamIndex, Sequence< Any > &aOutParam) override
Definition: oleobjw.cxx:202
virtual css::uno::Any SAL_CALL invokeGetProperty(const OUString &aFunctionName, const css::uno::Sequence< css::uno::Any > &aParams, css::uno::Sequence< ::sal_Int16 > &aOutParamIndex, css::uno::Sequence< css::uno::Any > &aOutParam) override
Definition: oleobjw.cxx:141
CComPtr< ITypeInfo > m_spTypeInfo
Definition: oleobjw.hxx:238
virtual Any SAL_CALL getValue(const OUString &aPropertyName) override
Definition: oleobjw.cxx:433
virtual OUString SAL_CALL getDefaultPropertyName() override
Definition: oleobjw.hxx:95
bool m_bHasDfltProperty
Definition: oleobjw.hxx:241
void getFuncDesc(const OUString &sFuncName, FUNCDESC **pFuncDesc)
Obtains a FUNCDESC structure for a function.
Definition: oleobjw.cxx:2170
JScriptDetermination m_eJScript
Definition: oleobjw.hxx:231
virtual OUString SAL_CALL getDefaultMethodName() override
Definition: oleobjw.hxx:98
CComPtr< IUnknown > m_spUnknown
Definition: oleobjw.hxx:218
OUString m_sTypeName
Definition: oleobjw.hxx:220
Reference< XIdlClass > * m_pxIdlClass
Definition: oleobjw.hxx:226
All methods are allowed to throw at least a BridgeRuntimeError.
Reference< XSingleServiceFactory > xFactory
Sequence< PropertyValue > aArguments
OUString aName
Type
std::unordered_multimap< OUString, unsigned int > TLBFuncIndexMap
Definition: oleobjw.hxx:50
std::unordered_map< OUString, std::pair< DISPID, unsigned short > > DispIdMap
Definition: oleobjw.hxx:48
unsigned char sal_uInt8
unsigned char sal_Bool