diff options
author | Daniel Rentz [dr] <daniel.rentz@oracle.com> | 2011-03-25 10:40:25 +0100 |
---|---|---|
committer | Daniel Rentz [dr] <daniel.rentz@oracle.com> | 2011-03-25 10:40:25 +0100 |
commit | b46dab973c91c3a94bcda188a9888fef3fd16426 (patch) | |
tree | ecf2283bed35cbd42e3fb5fb541194d70179e51d /basic/source/classes/sbunoobj.cxx | |
parent | 61879c218dd0e6e94884e7c6e06e3c5c18540b4a (diff) |
calcvba: #164410# improve VBA compatibility implementation in various areas: Excel symbols, MSForms symbols, document and forms event handling
Diffstat (limited to 'basic/source/classes/sbunoobj.cxx')
-rwxr-xr-x | basic/source/classes/sbunoobj.cxx | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index 13ae406cb305..6f20a68a274f 100755 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -1722,8 +1722,7 @@ String getBasicObjectTypeName( SbxObject* pObj ) return aName; } -bool checkUnoObjectType( SbUnoObject* pUnoObj, - const String& aClass ) +bool checkUnoObjectType( SbUnoObject* pUnoObj, const ::rtl::OUString& rClass ) { Any aToInspectObj = pUnoObj->getUnoAny(); TypeClass eType = aToInspectObj.getValueType().getTypeClass(); @@ -1740,6 +1739,21 @@ bool checkUnoObjectType( SbUnoObject* pUnoObj, Reference< XTypeProvider > xTypeProvider( x, UNO_QUERY ); if( xTypeProvider.is() ) { + /* Although interfaces in the ooo.vba namespace obey the IDL rules and + have a leading 'X', in Basic we want to be able to do something + like 'Dim wb As Workbooks' or 'Dim lb As MSForms.Label'. Here we + add a leading 'X' to the class name and a leading dot to the entire + type name. This results e.g. in '.XWorkbooks' or '.MSForms.XLabel' + which matches the interface names 'ooo.vba.excel.XWorkbooks' or + 'ooo.vba.msforms.XLabel'. + */ + ::rtl::OUString aClassName( sal_Unicode( '.' ) ); + sal_Int32 nClassNameDot = rClass.lastIndexOf( '.' ); + if( nClassNameDot >= 0 ) + aClassName += rClass.copy( 0, nClassNameDot + 1 ) + ::rtl::OUString( sal_Unicode( 'X' ) ) + rClass.copy( nClassNameDot + 1 ); + else + aClassName += ::rtl::OUString( sal_Unicode( 'X' ) ) + rClass; + Sequence< Type > aTypeSeq = xTypeProvider->getTypes(); const Type* pTypeArray = aTypeSeq.getConstArray(); sal_uInt32 nIfaceCount = aTypeSeq.getLength(); @@ -1753,8 +1767,8 @@ bool checkUnoObjectType( SbUnoObject* pUnoObj, DBG_ERROR("failed to get XIdlClass for type"); break; } - ::rtl::OUString sClassName = xClass->getName(); - if ( sClassName.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.XAutomationObject" ) ) ) ) + ::rtl::OUString aInterfaceName = xClass->getName(); + if ( aInterfaceName.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.XAutomationObject" ) ) ) ) { // there is a hack in the extensions/source/ole/oleobj.cxx to return the typename of the automation object, lets check if it // matches @@ -1767,20 +1781,15 @@ bool checkUnoObjectType( SbUnoObject* pUnoObj, // can't check type, leave it pass result = true; else - result = sTypeName.equals( aClass ); + result = sTypeName.equals( rClass ); } break; // finished checking automation object } - OSL_TRACE("Checking if object implements %s", - OUStringToOString( defaultNameSpace + aClass, - RTL_TEXTENCODING_UTF8 ).getStr() ); - // although interfaces in the ooo.vba.vba namespace - // obey the idl rules and have a leading X, in basic we - // want to be able to do something like - // 'dim wrkbooks as WorkBooks' - // so test assumes the 'X' has been dropped - sal_Int32 indexLastDot = sClassName.lastIndexOf('.'); - if ( indexLastDot > -1 && sClassName.copy( indexLastDot + 1).equalsIgnoreAsciiCase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("X") ) + aClass ) ) + + // match interface name with passed class name + OSL_TRACE("Checking if object implements %s", OUStringToOString( aClassName, RTL_TEXTENCODING_UTF8 ).getStr() ); + if ( (aClassName.getLength() < aInterfaceName.getLength()) && + aInterfaceName.matchIgnoreAsciiCase( aClassName, aInterfaceName.getLength() - aClassName.getLength() ) ) { result = true; break; |