From e31e563d728078ea564a3d398b74d3467e0ba56a Mon Sep 17 00:00:00 2001 From: Noel Power Date: Wed, 6 Oct 2010 10:16:13 +0100 Subject: initial commit for vba blob ( not including container_control stuff ) --- extensions/inc/propctrlr.hrc | 3 +- extensions/source/ole/oleobjw.cxx | 195 ++++++++++++++++----- extensions/source/ole/oleobjw.hxx | 15 +- .../source/propctrlr/defaultforminspection.cxx | 2 +- extensions/source/propctrlr/formmetadata.cxx | 1 + extensions/source/propctrlr/formmetadata.hxx | 1 + extensions/source/propctrlr/formres.src | 4 + extensions/source/propctrlr/formresid.hrc | 1 + extensions/source/propctrlr/formstrings.hxx | 1 + extensions/util/hidother.src | 1 + 10 files changed, 176 insertions(+), 48 deletions(-) (limited to 'extensions') diff --git a/extensions/inc/propctrlr.hrc b/extensions/inc/propctrlr.hrc index 6961319f4dda..477f512797ec 100644 --- a/extensions/inc/propctrlr.hrc +++ b/extensions/inc/propctrlr.hrc @@ -326,9 +326,10 @@ #define HID_FM_PROPDLG_TAB_GENERAL ( HID_PROPC_START + 294) #define HID_FM_PROPDLG_TAB_DATA ( HID_PROPC_START + 295) #define HID_FM_PROPDLG_TAB_EVT ( HID_PROPC_START + 296) +#define HID_PROP_GROUP_NAME ( HID_PROPC_START + 297) // please adjust HID_LAST_PROPC_ID if you add new ids here! -#define HID_LAST_PROPC_ID HID_FM_PROPDLG_TAB_EVT +#define HID_LAST_PROPC_ID HID_PROP_GROUP_NAME #if HID_LAST_PROPC_ID > HID_PROPC_END #error help id overflow (PROPC) diff --git a/extensions/source/ole/oleobjw.cxx b/extensions/source/ole/oleobjw.cxx index 89cb5625bca3..9a95c30ec645 100755 --- a/extensions/source/ole/oleobjw.cxx +++ b/extensions/source/ole/oleobjw.cxx @@ -49,6 +49,7 @@ #include #include #include +#include #include #include "com/sun/star/bridge/oleautomation/NamedArgument.hpp" @@ -152,10 +153,10 @@ Any IUnknownWrapper_Impl::queryInterface(const Type& t) return Any(); if (t == getCppuType(static_cast*>( 0)) && !m_bHasDfltProperty ) return Any(); - if (t == getCppuType(static_cast*>( 0)) && !m_spDispatch) + if ( ( t == getCppuType(static_cast*>( 0)) || t == getCppuType(static_cast*>( 0)) ) && !m_spDispatch) return Any(); - return WeakImplHelper6::queryInterface(t); } @@ -167,6 +168,61 @@ Reference SAL_CALL IUnknownWrapper_Impl::getIntrospection( return ret; } +Any SAL_CALL IUnknownWrapper_Impl::invokeGetProperty( const OUString& aPropertyName, const Sequence< Any >& aParams, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam ) +{ + Any aResult; + try + { + o2u_attachCurrentThread(); + ITypeInfo * pInfo = getTypeInfo(); + FuncDesc aDescGet(pInfo); + FuncDesc aDescPut(pInfo); + VarDesc aVarDesc(pInfo); + getPropDesc(aPropertyName, & aDescGet, & aDescPut, & aVarDesc); + if ( !aDescGet ) + { + OUString msg(OUSTR("[automation bridge]Property \"") + aPropertyName + + OUSTR("\" is not supported")); + throw UnknownPropertyException(msg, Reference()); + } + aResult = invokeWithDispIdComTlb( aDescGet, aPropertyName, aParams, aOutParamIndex, aOutParam ); + } + catch ( Exception& e ) + { + throw RuntimeException(OUSTR("[automation bridge] unexpected exception in " + "IUnknownWrapper_Impl::invokeGetProperty ! Message : \n") + + e.Message, Reference()); + } + return aResult; +} + +Any SAL_CALL IUnknownWrapper_Impl::invokePutProperty( const OUString& aPropertyName, const Sequence< Any >& aParams, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam ) +{ + Any aResult; + try + { + o2u_attachCurrentThread(); + ITypeInfo * pInfo = getTypeInfo(); + FuncDesc aDescGet(pInfo); + FuncDesc aDescPut(pInfo); + VarDesc aVarDesc(pInfo); + getPropDesc(aPropertyName, & aDescGet, & aDescPut, & aVarDesc); + if ( !aDescPut ) + { + OUString msg(OUSTR("[automation bridge]Property \"") + aPropertyName + + OUSTR("\" is not supported")); + throw UnknownPropertyException(msg, Reference()); + } + aResult = invokeWithDispIdComTlb( aDescPut, aPropertyName, aParams, aOutParamIndex, aOutParam ); + } + catch ( Exception& e ) + { + throw RuntimeException(OUSTR("[automation bridge] unexpected exception in " + "IUnknownWrapper_Impl::invokePutProperty ! Message : \n") + + e.Message, Reference()); + } + return aResult; +} Any SAL_CALL IUnknownWrapper_Impl::invoke( const OUString& aFunctionName, @@ -213,6 +269,10 @@ Any SAL_CALL IUnknownWrapper_Impl::invoke( const OUString& aFunctionName, { throw; } + catch (InvocationTargetException &) + { + throw; + } catch (BridgeRuntimeError & e) { throw RuntimeException(e.message, Reference()); @@ -658,12 +718,16 @@ sal_Bool SAL_CALL IUnknownWrapper_Impl::hasProperty( const OUString& aName ) FuncDesc aDescPut(pInfo); VarDesc aVarDesc(pInfo); getPropDesc(aName, & aDescGet, & aDescPut, & aVarDesc); - // Automation properties can have parameters. If so, we access them through - // XInvocation::invoke. Thas is, hasProperty must return false for such a - // property + + // we should probably just check the funckind + // basic has been modified to handle properties ( 'get' ) props at + // least with paramaters + // additionally you can call invoke(Get|Set)Property on the bridge + // you can determine if a property has parameter is hasMethod + // returns true for the name if (aVarDesc - || aDescPut && aDescPut->cParams == 0 - || aDescGet && aDescGet->cParams == 0) + || aDescPut + || aDescGet ) { ret = sal_True; } @@ -1391,6 +1455,19 @@ Any IUnknownWrapper_Impl::invokeWithDispIdComTlb(const OUString& sFuncName, const Sequence< Any >& Params, Sequence< sal_Int16 >& OutParamIndex, Sequence< Any >& OutParam) +{ + // Get type info for the call. It can be a method call or property put or + // property get operation. + FuncDesc aFuncDesc(getTypeInfo()); + getFuncDescForInvoke(sFuncName, Params, & aFuncDesc); + return invokeWithDispIdComTlb( aFuncDesc, sFuncName, Params, OutParamIndex, OutParam ); +} + +Any IUnknownWrapper_Impl::invokeWithDispIdComTlb(FuncDesc& aFuncDesc, + const OUString& sFuncName, + const Sequence< Any >& Params, + Sequence< sal_Int16 >& OutParamIndex, + Sequence< Any >& OutParam) { Any ret; HRESULT result; @@ -1410,10 +1487,6 @@ Any IUnknownWrapper_Impl::invokeWithDispIdComTlb(const OUString& sFuncName, sal_Int32 revIndex = 0; bool bVarargParam = false; - // Get type info for the call. It can be a method call or property put or - // property get operation. - FuncDesc aFuncDesc(getTypeInfo()); - getFuncDescForInvoke(sFuncName, Params, & aFuncDesc); //Set the array of DISPIDs for named args if it is a property put operation. //If there are other named arguments another array is set later on. @@ -1832,11 +1905,24 @@ Any IUnknownWrapper_Impl::invokeWithDispIdComTlb(const OUString& sFuncName, "DISP_E_BADVARTYPE."), 0); break; case DISP_E_EXCEPTION: + { message = OUSTR("[automation bridge]: "); message += OUString(reinterpret_cast(excepinfo.bstrDescription), ::SysStringLen(excepinfo.bstrDescription)); - throw InvocationTargetException(message, Reference(), Any()); + + // Add for VBA, to throw an exception with the correct error code and message. + sal_Int32 nErrorCode = excepinfo.wCode; + if ( nErrorCode == 0 ) + { + // The low 16-bit of scode describing the error or warning. + nErrorCode = ( excepinfo.scode & 0xFFFF ); + } + BasicErrorException aBasicErrExp(message, Reference(), nErrorCode, message); + throw InvocationTargetException(message, Reference(), makeAny(aBasicErrExp)); + // End add + break; + } case DISP_E_MEMBERNOTFOUND: message = OUSTR("[automation bridge]: A function with the name \"") + sFuncName + OUSTR("\" is not supported. Object returned " @@ -1969,11 +2055,17 @@ void IUnknownWrapper_Impl::getFuncDesc(const OUString & sFuncName, FUNCDESC ** p //get the associated index and add an entry to the map //with the name sFuncName which differs in the casing of the letters to //the actual name as obtained from ITypeInfo - cit itOrg = m_mapComFunc.find(OUString(reinterpret_cast(LPCOLESTR(memberName)))); + OUString sRealName(reinterpret_cast(LPCOLESTR(memberName))); + cit itOrg = m_mapComFunc.find(sRealName); OSL_ASSERT(itOrg != m_mapComFunc.end()); + // maybe this is a property, if so we need + // to store either both id's ( put/get ) or + // just the get. Storing both is more consistent + pair pItems = m_mapComFunc.equal_range( sRealName ); + for ( ;pItems.first != pItems.second; ++pItems.first ) + m_mapComFunc.insert( TLBFuncIndexMap::value_type ( make_pair(sFuncName, pItems.first->second ) )); itIndex = - m_mapComFunc.insert( TLBFuncIndexMap::value_type - ( make_pair(sFuncName, itOrg->second ) )); + m_mapComFunc.find( sFuncName ); } } } @@ -2080,56 +2172,69 @@ void IUnknownWrapper_Impl::getPropDesc(const OUString & sFuncName, FUNCDESC ** p //else no entry for sFuncName, pFuncDesc will not be filled in } -VARTYPE IUnknownWrapper_Impl::getElementTypeDesc(const TYPEDESC *desc) +VARTYPE IUnknownWrapper_Impl::getUserDefinedElementType( ITypeInfo* pTypeInfo, const DWORD nHrefType ) { VARTYPE _type( VT_NULL ); - - if (desc->vt == VT_PTR) - { - _type = getElementTypeDesc(desc->lptdesc); - _type |= VT_BYREF; - } - else if (desc->vt == VT_SAFEARRAY) - { - _type = getElementTypeDesc(desc->lptdesc); - _type |= VT_ARRAY; - } - else if (desc->vt == VT_USERDEFINED) + if ( pTypeInfo ) { - ITypeInfo* thisInfo = getTypeInfo(); //kept by this instance - CComPtr spRefInfo; - thisInfo->GetRefTypeInfo(desc->hreftype, & spRefInfo.p); - if (spRefInfo) + CComPtr spRefInfo; + pTypeInfo->GetRefTypeInfo( nHrefType, &spRefInfo.p ); + if ( spRefInfo ) { - TypeAttr attr(spRefInfo); - spRefInfo->GetTypeAttr( & attr); - if (attr->typekind == TKIND_ENUM) + TypeAttr attr( spRefInfo ); + spRefInfo->GetTypeAttr( &attr ); + if ( attr->typekind == TKIND_ENUM ) { - //We use the type of the first enum value. - if (attr->cVars == 0) + // We use the type of the first enum value. + if ( attr->cVars == 0 ) { - throw BridgeRuntimeError(OUSTR("[automation bridge] Could " - "not obtain type description")); + throw BridgeRuntimeError(OUSTR("[automation bridge] Could not obtain type description")); } - VarDesc var(spRefInfo); - spRefInfo->GetVarDesc(0, & var); + VarDesc var( spRefInfo ); + spRefInfo->GetVarDesc( 0, &var ); _type = var->lpvarValue->vt; } - else if (attr->typekind == TKIND_INTERFACE) + else if ( attr->typekind == TKIND_INTERFACE ) { _type = VT_UNKNOWN; } - else if (attr->typekind == TKIND_DISPATCH) + else if ( attr->typekind == TKIND_DISPATCH ) { _type = VT_DISPATCH; } + else if ( attr->typekind == TKIND_ALIAS ) + { + // TKIND_ALIAS is a type that is an alias for another type. So get that alias type. + _type = getUserDefinedElementType( pTypeInfo, attr->tdescAlias.hreftype ); + } else { - throw BridgeRuntimeError(OUSTR("[automation bridge] " - "Unhandled user defined type.")); + throw BridgeRuntimeError( OUSTR("[automation bridge] Unhandled user defined type.") ); } } } + return _type; +} + +VARTYPE IUnknownWrapper_Impl::getElementTypeDesc(const TYPEDESC *desc) +{ + VARTYPE _type( VT_NULL ); + + if (desc->vt == VT_PTR) + { + _type = getElementTypeDesc(desc->lptdesc); + _type |= VT_BYREF; + } + else if (desc->vt == VT_SAFEARRAY) + { + _type = getElementTypeDesc(desc->lptdesc); + _type |= VT_ARRAY; + } + else if (desc->vt == VT_USERDEFINED) + { + ITypeInfo* thisInfo = getTypeInfo(); //kept by this instance + _type = getUserDefinedElementType( thisInfo, desc->hreftype ); + } else { _type = desc->vt; diff --git a/extensions/source/ole/oleobjw.hxx b/extensions/source/ole/oleobjw.hxx index b990ac3af17d..3c184472c20f 100644 --- a/extensions/source/ole/oleobjw.hxx +++ b/extensions/source/ole/oleobjw.hxx @@ -54,6 +54,7 @@ #include #include +#include #include #include @@ -81,7 +82,7 @@ typedef hash_multimap, +class IUnknownWrapper_Impl : public WeakImplHelper6, public UnoConversionUtilities @@ -134,6 +135,9 @@ public: protected: virtual ::rtl::OUString SAL_CALL getDefaultMethodName( ) throw (::com::sun::star::uno::RuntimeException) { return m_sDefaultMember; } + virtual ::com::sun::star::uno::Any SAL_CALL invokeGetProperty( const ::rtl::OUString& aFunctionName, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aParams, ::com::sun::star::uno::Sequence< ::sal_Int16 >& aOutParamIndex, ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::script::CannotConvertException, ::com::sun::star::reflection::InvocationTargetException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL invokePutProperty( const ::rtl::OUString& aFunctionName, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aParams, ::com::sun::star::uno::Sequence< ::sal_Int16 >& aOutParamIndex, ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::script::CannotConvertException, ::com::sun::star::reflection::InvocationTargetException, ::com::sun::star::uno::RuntimeException); + // ---------------------------------------------------------------------------- virtual Any invokeWithDispIdUnoTlb(const OUString& sFunctionName, const Sequence< Any >& Params, @@ -145,6 +149,12 @@ protected: Sequence< sal_Int16 >& OutParamIndex, Sequence< Any >& OutParam); + Any IUnknownWrapper_Impl::invokeWithDispIdComTlb(FuncDesc& aFuncDesc, + const OUString& sFuncName, + const Sequence< Any >& Params, + Sequence< sal_Int16 >& OutParamIndex, + Sequence< Any >& OutParam); + // virtual void setValueWithDispId(DISPID dispID, const Any& Value); // virtual Any getValueWithDispId(const OUString& sName, DISPID dispID); @@ -188,8 +198,11 @@ protected: /** 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); + VARTYPE getUserDefinedElementType( ITypeInfo* pTypeInfo, const DWORD nHrefType ); + /** 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 diff --git a/extensions/source/propctrlr/defaultforminspection.cxx b/extensions/source/propctrlr/defaultforminspection.cxx index f477c4deaa1e..2fffb43951ce 100644 --- a/extensions/source/propctrlr/defaultforminspection.cxx +++ b/extensions/source/propctrlr/defaultforminspection.cxx @@ -149,7 +149,7 @@ namespace pcr { "com.sun.star.form.inspection.EventHandler", false }, // a handler which introduces virtual properties for binding controls to spreadsheet cells - { "com.sun.star.form.inspection.CellBindingPropertyHandler", true }, + { "com.sun.star.form.inspection.CellBindingPropertyHandler", false }, // properties related to binding to an XForms DOM node { "com.sun.star.form.inspection.XMLFormsPropertyHandler", true }, diff --git a/extensions/source/propctrlr/formmetadata.cxx b/extensions/source/propctrlr/formmetadata.cxx index 9d8becfbd923..0e63f360f9a0 100644 --- a/extensions/source/propctrlr/formmetadata.cxx +++ b/extensions/source/propctrlr/formmetadata.cxx @@ -138,6 +138,7 @@ namespace pcr DEF_INFO_3( LABEL, LABEL, LABEL, FORM_VISIBLE, DIALOG_VISIBLE, COMPOSEABLE ), DEF_INFO_2( CONTROLLABEL, LABELCONTROL, CONTROLLABEL, FORM_VISIBLE, COMPOSEABLE ), DEF_INFO_3( WRITING_MODE, WRITING_MODE, WRITING_MODE, FORM_VISIBLE, ENUM, COMPOSEABLE ), + DEF_INFO_3( GROUP_NAME, GROUP_NAME, GROUP_NAME, FORM_VISIBLE, DIALOG_VISIBLE, COMPOSEABLE ), DEF_INFO_2( TEXT, TEXT, TEXT, DIALOG_VISIBLE, COMPOSEABLE ), DEF_INFO_3( MAXTEXTLEN, MAXTEXTLEN, MAXTEXTLEN, FORM_VISIBLE, DIALOG_VISIBLE, COMPOSEABLE ), DEF_INFO_3( EDITMASK, EDITMASK, EDITMASK, FORM_VISIBLE, DIALOG_VISIBLE, COMPOSEABLE ), diff --git a/extensions/source/propctrlr/formmetadata.hxx b/extensions/source/propctrlr/formmetadata.hxx index 294a43e4a9e7..3eb7f0e29d56 100644 --- a/extensions/source/propctrlr/formmetadata.hxx +++ b/extensions/source/propctrlr/formmetadata.hxx @@ -163,6 +163,7 @@ namespace pcr #define PROPERTY_ID_ALLOWADDITIONS 20 #define PROPERTY_ID_ALLOWEDITS 21 #define PROPERTY_ID_ALLOWDELETIONS 22 + #define PROPERTY_ID_GROUP_NAME 23 #define PROPERTY_ID_NAVIGATION 24 #define PROPERTY_ID_CYCLE 25 #define PROPERTY_ID_HIDDEN_VALUE 26 diff --git a/extensions/source/propctrlr/formres.src b/extensions/source/propctrlr/formres.src index 1daadd6e0f01..a1ac9fe2c0c4 100644 --- a/extensions/source/propctrlr/formres.src +++ b/extensions/source/propctrlr/formres.src @@ -231,6 +231,10 @@ String RID_STR_NAME { Text [ en-US ] = "Name" ; }; +String RID_STR_GROUP_NAME +{ + Text [ en-US ] = "Group name" ; +}; String RID_STR_TABINDEX { Text [ en-US ] = "Tab order" ; diff --git a/extensions/source/propctrlr/formresid.hrc b/extensions/source/propctrlr/formresid.hrc index f2de0c252d8b..0aeab5306da9 100644 --- a/extensions/source/propctrlr/formresid.hrc +++ b/extensions/source/propctrlr/formresid.hrc @@ -149,6 +149,7 @@ #define RID_STR_CURSOR_TYPE ( RID_FORMBROWSER_START + 121 ) #define RID_STR_ENABLE_VISIBLE ( RID_FORMBROWSER_START + 122 ) #define RID_STR_WHEEL_BEHAVIOR ( RID_FORMBROWSER_START + 123 ) +#define RID_STR_GROUP_NAME ( RID_FORMBROWSER_START + 124 ) // FREE // FREE // FREE diff --git a/extensions/source/propctrlr/formstrings.hxx b/extensions/source/propctrlr/formstrings.hxx index 20b0dd34b2cd..aed09d4fcbf0 100644 --- a/extensions/source/propctrlr/formstrings.hxx +++ b/extensions/source/propctrlr/formstrings.hxx @@ -48,6 +48,7 @@ namespace pcr PCR_CONSTASCII_STRING( PROPERTY_WHEEL_BEHAVIOR, "MouseWheelBehavior"); PCR_CONSTASCII_STRING( PROPERTY_TAG, "Tag"); PCR_CONSTASCII_STRING( PROPERTY_NAME, "Name"); + PCR_CONSTASCII_STRING( PROPERTY_GROUP_NAME, "GroupName"); PCR_CONSTASCII_STRING( PROPERTY_VALUE, "Value"); PCR_CONSTASCII_STRING( PROPERTY_TEXT, "Text"); PCR_CONSTASCII_STRING( PROPERTY_NAVIGATION, "NavigationBarMode"); diff --git a/extensions/util/hidother.src b/extensions/util/hidother.src index 4700d3380e3f..e890400d6ad8 100644 --- a/extensions/util/hidother.src +++ b/extensions/util/hidother.src @@ -207,6 +207,7 @@ hidspecial HID_PROP_FOCUSONCLICK { HelpId = HID_PROP_FOCUSONCLICK hidspecial HID_PROP_FONT { HelpId = HID_PROP_FONT; } hidspecial HID_PROP_FORMATKEY { HelpId = HID_PROP_FORMATKEY; } hidspecial HID_PROP_GROUPBOX { HelpId = HID_PROP_GROUPBOX; } +hidspecial HID_PROP_GROUP_NAME { HelpId = HID_PROP_GROUP_NAME; } hidspecial HID_PROP_HEIGHT { HelpId = HID_PROP_HEIGHT; } hidspecial HID_PROP_HELPTEXT { HelpId = HID_PROP_HELPTEXT; } hidspecial HID_PROP_HELPURL { HelpId = HID_PROP_HELPURL; } -- cgit