From 5e5f40a4a92a31b0932c690219d002fcf18598cf Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 20 Dec 2022 18:50:07 +0100 Subject: [PATCH] loplugin:unocast (ScVbaShapes) (See the upcoming commit introducing that loplugin:unocast on why such dynamic_casts from UNO types are dangerous.) Change-Id: I913565ccd93472f2a8893c4251e80d0309827c34 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144633 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- include/vbahelper/vbashapes.hxx | 6 +++++- vbahelper/source/vbahelper/vbashapes.cxx | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/vbahelper/vbashapes.hxx b/include/vbahelper/vbashapes.hxx index 7131d8118031..fabacae0732c 100644 --- a/include/vbahelper/vbashapes.hxx +++ b/include/vbahelper/vbashapes.hxx @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -50,7 +51,7 @@ namespace ooo::vba { namespace msforms { class XShapeRange; } } -typedef CollTestImplHelper< ov::msforms::XShapes > ScVbaShapes_BASE; +typedef CollTestImplHelper< ov::msforms::XShapes, css::lang::XUnoTunnel > ScVbaShapes_BASE; class VBAHELPER_DLLPUBLIC ScVbaShapes final : public ScVbaShapes_BASE { @@ -85,6 +86,9 @@ public: virtual css::uno::Type SAL_CALL getElementType() override; virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override; + sal_Int64 SAL_CALL getSomething(css::uno::Sequence const & aIdentifier) override; + static css::uno::Sequence const & getUnoTunnelId(); + virtual void SAL_CALL SelectAll() override; //helper::calc virtual css::uno::Any SAL_CALL AddLine( sal_Int32 StartX, sal_Int32 StartY, sal_Int32 endX, sal_Int32 endY ) override; diff --git a/vbahelper/source/vbahelper/vbashapes.cxx b/vbahelper/source/vbahelper/vbashapes.cxx index 02630a75c520..a61fbddfb350 100644 --- a/vbahelper/source/vbahelper/vbashapes.cxx +++ b/vbahelper/source/vbahelper/vbashapes.cxx @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -63,7 +64,7 @@ public: } virtual uno::Any SAL_CALL nextElement( ) override { - ScVbaShapes* pShapes = dynamic_cast< ScVbaShapes* >(m_xParent.get()); + ScVbaShapes* pShapes = comphelper::getFromUnoTunnel< ScVbaShapes >(m_xParent); if ( pShapes && hasMoreElements() ) return pShapes->createCollectionObject( m_xIndexAccess->getByIndex( nIndex++ ) ); throw container::NoSuchElementException(); @@ -101,6 +102,15 @@ ScVbaShapes::createEnumeration() return new VbShapeEnumHelper( this, m_xIndexAccess ); } +sal_Int64 ScVbaShapes::getSomething(css::uno::Sequence const & aIdentifier) { + return comphelper::getSomethingImpl(aIdentifier, this); +} + +css::uno::Sequence const & ScVbaShapes::getUnoTunnelId() { + static comphelper::UnoIdInit const id; + return id.getSeq(); +} + uno::Any ScVbaShapes::createCollectionObject( const css::uno::Any& aSource ) {