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 <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann
2022-12-20 18:50:07 +01:00
parent 27b35b2c21
commit 5e5f40a4a9
2 changed files with 16 additions and 2 deletions

View File

@@ -23,6 +23,7 @@
#include <string_view>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/RuntimeException.hpp>
@@ -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<sal_Int8> const & aIdentifier) override;
static css::uno::Sequence<sal_Int8> 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;

View File

@@ -39,6 +39,7 @@
#include <com/sun/star/drawing/XShapes.hpp>
#include <utility>
#include <comphelper/servicehelper.hxx>
#include <vbahelper/vbahelper.hxx>
#include <vbahelper/vbashape.hxx>
#include <vbahelper/vbashapes.hxx>
@@ -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<sal_Int8> const & aIdentifier) {
return comphelper::getSomethingImpl(aIdentifier, this);
}
css::uno::Sequence<sal_Int8> const & ScVbaShapes::getUnoTunnelId() {
static comphelper::UnoIdInit const id;
return id.getSeq();
}
uno::Any
ScVbaShapes::createCollectionObject( const css::uno::Any& aSource )
{