office-gobmx/extensions/source/ole/oleobjw.hxx

267 lines
12 KiB
C++
Raw Normal View History

2000-09-18 10:18:56 -05:00
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 10:18:56 -05:00
*
* $RCSfile: oleobjw.hxx,v $
2000-09-18 10:18:56 -05:00
*
* $Revision: 1.8 $
2000-09-18 10:18:56 -05:00
*
* last change: $Author: rt $ $Date: 2005-09-08 19:44:23 $
2000-09-18 10:18:56 -05:00
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
2000-09-18 10:18:56 -05:00
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
2000-09-18 10:18:56 -05:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
2000-09-18 10:18:56 -05:00
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
2000-09-18 10:18:56 -05:00
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
2000-09-18 10:18:56 -05:00
*
************************************************************************/
#ifndef __OLEOBJW_HXX
#define __OLEOBJW_HXX
#include "ole2uno.hxx"
#include <tools/presys.h>
#define _WIN32_WINNT 0x0400
2003-04-11 05:22:50 -05:00
#if defined(_MSC_VER) && (_MSC_VER >= 1300)
#undef _DEBUG
#endif
#include <atlbase.h>
2000-09-18 10:18:56 -05:00
#include <vector>
#include <hash_map>
#include <tools/postsys.h>
#ifndef _CPPUHELPER_IMPLBASE3_HXX_
#include <cppuhelper/implbase3.hxx>
#endif
#ifndef _CPPUHELPER_IMPLBASE4_HXX_
#include <cppuhelper/implbase4.hxx>
#endif
2000-09-18 10:18:56 -05:00
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/bridge/oleautomation/XAutomationObject.hpp>
2000-09-18 10:18:56 -05:00
#ifndef _RTL_USTRING_
#include <rtl/ustring>
#endif
2000-09-18 10:18:56 -05:00
#include <typelib/typedescription.hxx>
#include "unoconversionutilities.hxx"
#include "windata.hxx"
2000-09-18 10:18:56 -05:00
using namespace cppu;
using namespace rtl;
using namespace std;
using namespace com::sun::star::lang;
using namespace com::sun::star::bridge;
using namespace com::sun::star::bridge::oleautomation;
2000-09-18 10:18:56 -05:00
namespace ole_adapter
{
typedef hash_map<OUString, pair<DISPID, unsigned short>, hashOUString_Impl, equalOUString_Impl> DispIdMap;
typedef hash_multimap<OUString, unsigned int, hashOUString_Impl, equalOUString_Impl> TLBFuncIndexMap;
2000-09-18 10:18:56 -05:00
// This class wraps an IDispatch and maps XInvocation calls to IDispatch calls on the wrapped object.
// If m_TypeDescription is set then this class represents an UNO interface implemented in a COM component.
// The interface is not a real interface in terms of an abstract class but is realized through IDispatch.
class IUnknownWrapper_Impl : public WeakImplHelper4<XInvocation, XBridgeSupplier2, XInitialization, XAutomationObject>,
2000-09-18 10:18:56 -05:00
public UnoConversionUtilities<IUnknownWrapper_Impl>
{
public:
IUnknownWrapper_Impl(Reference<XMultiServiceFactory> &xFactory,
sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass);
2000-09-18 10:18:56 -05:00
~IUnknownWrapper_Impl();
//XInterface
Any SAL_CALL IUnknownWrapper_Impl::queryInterface(const Type& t)
throw (RuntimeException);
2000-09-18 10:18:56 -05:00
// XInvokation
virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection( )
throw(RuntimeException);
virtual Any SAL_CALL invoke( const OUString& aFunctionName,
const Sequence< Any >& aParams,
Sequence< sal_Int16 >& aOutParamIndex,
Sequence< Any >& aOutParam )
throw(IllegalArgumentException, CannotConvertException,
InvocationTargetException, RuntimeException);
virtual void SAL_CALL setValue( const OUString& aPropertyName,
const Any& aValue )
throw(UnknownPropertyException, CannotConvertException,
InvocationTargetException, RuntimeException);
virtual Any SAL_CALL getValue( const OUString& aPropertyName )
throw(UnknownPropertyException, RuntimeException);
virtual sal_Bool SAL_CALL hasMethod( const OUString& aName )
throw(RuntimeException);
virtual sal_Bool SAL_CALL hasProperty( const OUString& aName )
throw(RuntimeException);
2000-09-18 10:18:56 -05:00
// XBridgeSupplier2
// This interface is implemented to provide a safe way to obtain the original
// IUnknown or IDispatch within the function anyToVariant. The function asks
// every UNO object for its XBridgeSupplier2 and if it is available uses it to convert
2000-09-18 10:18:56 -05:00
// the object with its own supplier.
virtual Any SAL_CALL createBridge( const Any& modelDepObject,
const Sequence< sal_Int8 >& aProcessId,
sal_Int16 sourceModelType,
sal_Int16 destModelType )
throw(IllegalArgumentException, RuntimeException);
2000-09-18 10:18:56 -05:00
// XInitialization
virtual void SAL_CALL initialize( const Sequence< Any >& aArguments )
throw(Exception, RuntimeException);
protected:
2000-09-18 10:18:56 -05:00
// ----------------------------------------------------------------------------
virtual Any invokeWithDispIdUnoTlb(const OUString& sFunctionName,
const Sequence< Any >& Params,
Sequence<sal_Int16 >& OutParamIndex,
Sequence< Any >& OutParam);
// Is used for OleObjectFactory service
virtual Any invokeWithDispIdComTlb(const OUString& sFuncName,
const Sequence< Any >& Params,
Sequence< sal_Int16 >& OutParamIndex,
Sequence< Any >& OutParam);
2000-09-18 10:18:56 -05:00
// virtual void setValueWithDispId(DISPID dispID, const Any& Value);
// virtual Any getValueWithDispId(const OUString& sName, DISPID dispID);
2000-09-18 10:18:56 -05:00
// UnoConversionUtilities -------------------------------------------------------------------------------
virtual Reference<XInterface> createUnoWrapperInstance();
virtual Reference<XInterface> createComWrapperInstance();
/**Obtains a FUNCDESC structure for a function.
Fills the FUNCDESC structure if ITypeInfo provides information for
the function of name sFuncName or pFuncDesc will not be filled in.
May throw a BridgeRuntimeError.
*/
void getFuncDesc(const OUString & sFuncName, FUNCDESC ** pFuncDesc);
/**Obtains a FUNCDESC structures or a VARDESC structure
for a property. pFuncDescPut may also contain
a structure for a "propertyputref" operation. If pFuncDesc contains a
"put ref" or "put" FUNCDESC depends on what was found first in the type
description.
Fills the FUNCDESC structure if ITypeInfo provides information for
the respective property functions or the structures will not be filled in.
May throw a BridgeRuntimeError.
*/
void getPropDesc(const OUString & sFuncName, FUNCDESC ** pFuncDescGet,
FUNCDESC** pFuncDescPut, VARDESC ** pVarDesc);
2000-09-18 10:18:56 -05:00
// These functions are for the case if an object of this class wraps an IDispatch
// object that implements UNO interfaces. In that case the member m_seqTypes
// is set through XInitialization::initialize.
void getMethodInfo(const OUString& sName, TypeDescription& methodDescription);
// After return attributInfo contains typelib_InterfaceAttributeTypeDescription::pAttributeTypeRef
void getAttributeInfo(const OUString& sName, TypeDescription& attributeInfo);
2000-09-18 10:18:56 -05:00
// used by get MethodInfo
TypeDescription getInterfaceMemberDescOfCurrentCall(const OUString& sName);
/** Returns alway a valid ITypeInfo interface or throws a BridgeRuntimeError.
The returned interface does not need to be AddRef'ed as long as it is locally
used. The interface is kept in the instance of this class.
*/
2000-09-18 10:18:56 -05:00
ITypeInfo* getTypeInfo();
/** Returns the DISPID for a function or property name. If true is returned then
id contains a valid DISPID.
*/
bool getDispid(const OUString& sFuncName, DISPID * id);
/** Gets the element type in a VARIANT like style. E.g. if desc->lptdesc contains
a VT_PTR than it is replaced by VT_BYREF and VT_SAFEARRAY is replaced by VT_ARRAY
If the TYPEDESC describes an SAFEARRAY then varType is a combination of VT_ARRAY
and the element type.
The argument desc must be obtained from FUNCDESC::lprgelemdescParam[i].tdesc where
FUNCDESC was obtained from the ITypeInfo belonging to wrapped IDispatch.
*/
VARTYPE getElementTypeDesc( const TYPEDESC *desc);
/** Iterates over all functions and put the names and indices into the map
m_mapComFunc of type TLBFuncIndexMap.
Call the function every time before accessing the map.
Throws a BridgeRuntimeError on failure.
*/
void buildComTlbIndex();
/** Returns a FUNCDESC structure which contains type information about the
current XInvocation::invoke call. The FUNCDESC either describes a method,
a property put or a property get operation.
It uses the types com.sun.star.bridge.oleautomation.PropertyPutArgument
which can be
contained in the sequence of in-arguments of invoke to determine if the call is
a property put or property get operation.
If no adequate FUNCDESC was found, an IllegalArgumentException is thrown.
Therefore it is safe to assume that the returned FUNCDESC* is not NULL.
@exception IllegalArgumentException
Thrown if no adequate FUNCDESC could be found.
*/
void getFuncDescForInvoke(const OUString & sFuncName,
const Sequence<Any> & seqArgs, FUNCDESC** pFuncDesc);
// Finds out wheter the wrapped IDispatch is an JScript Object. This is is
// done by
// asking for the property "_environment". If it has the value "JScript"
// (case insensitive) then the IDispatch is considered a JScript object.
2000-09-18 10:18:56 -05:00
sal_Bool isJScriptObject();
// -------------------------------------------------------------------------------
// If UNO interfaces are implemented in JScript objects, VB or C++ COM objects
2000-09-18 10:18:56 -05:00
// and those are passed as parameter to a UNO interface function, then
// the IDispatch* are wrapped by objects of this class. Assuming that the functions
// implemented by the IDispatch object returns another UNO interface then
// it has to be wrapped to this type. But this is only possible if an object of this
// wrapper class knows what type it is represting. The member m_TypeDescription holds this
// information.
// m_TypeDescription is only useful when an object wraps an IDispatch object that implements
2000-09-18 10:18:56 -05:00
// an UNO interface. The value is set during a call to XInitialization::initialize.
Sequence<Type> m_seqTypes;
CComPtr<IUnknown> m_spUnknown;
CComPtr<IDispatch> m_spDispatch;
/** This value is set dureing XInitialization::initialize. It indicates that the COM interface
was transported as VT_DISPATCH in a VARIANT rather then a VT_UNKNOWN
*/
sal_Bool m_bOriginalDispatch;
2000-09-18 10:18:56 -05:00
DispIdMap m_dispIdMap;
Reference<XIdlClass>* m_pxIdlClass;
2000-09-18 10:18:56 -05:00
// used by isJScriptObject
enum JScriptDetermination{ JScriptUndefined=0, NoJScript, IsJScript};
JScriptDetermination m_eJScript;
// The map is filled by buildComTlbIndex
// It maps Uno Function names to an index which is used in ITypeInfo::GetFuncDesc
2000-09-18 10:18:56 -05:00
TLBFuncIndexMap m_mapComFunc;
// used for synchroizing the computation of the content for m_mapComFunc
bool m_bComTlbIndexInit;
2000-09-18 10:18:56 -05:00
// Keeps the ITypeInfo obtained from IDispatch::GetTypeInfo
CComPtr< ITypeInfo > m_spTypeInfo;
};
} // end namespace
#endif