From 1efe1f82fabb3b8566c0beca2ba5df21c54fa6d5 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 23 Oct 2019 15:16:32 +0200 Subject: In checkUnoObjectType, check for derived-from types too As discussed in the mail thread starting at "[libreoffice-users] Experimental macro features: How to determine object types?", it is confusing if a variable dim'ed as com.sun.star.util.XSearchDescriptor cannot hold an object whose css.lang.XTypeProvider::getTypes only reports css.util.XReplaceDescriptor (which is derived from XSearchDescriptor) but not XSearchDescriptor itself. At least for now, keep the odd endsWithIgnoreAsciiCase check intact (instead of checking for strict equality). Change-Id: Idd8ae8cb11b0f2e9c6369842629fc5a21e1c5cc5 Reviewed-on: https://gerrit.libreoffice.org/81386 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- basic/source/classes/sbunoobj.cxx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'basic') diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index 0c938d6c475e..af5a3aab3da2 100644 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -84,6 +84,7 @@ #include #include +#include #include #include #include @@ -1621,6 +1622,22 @@ OUString getBasicObjectTypeName( SbxObject* pObj ) return OUString(); } +namespace { + +bool matchesBasicTypeName( + css::uno::Reference const & unoType, OUString const & basicTypeName) +{ + if (unoType->getName().endsWithIgnoreAsciiCase(basicTypeName)) { + return true; + } + auto const sups = unoType->getSuperclasses(); + return std::any_of( + sups.begin(), sups.end(), + [&basicTypeName](auto const & t) { return matchesBasicTypeName(t, basicTypeName); }); +} + +} + bool checkUnoObjectType(SbUnoObject& rUnoObj, const OUString& rClass) { Any aToInspectObj = rUnoObj.getUnoAny(); @@ -1697,8 +1714,7 @@ bool checkUnoObjectType(SbUnoObject& rUnoObj, const OUString& rClass) break; // finished checking automation object } - // match interface name with passed class name - if ( aInterfaceName.endsWithIgnoreAsciiCase( aClassName ) ) + if ( matchesBasicTypeName(xClass, aClassName) ) { bResult = true; break; -- cgit