From 99009c9535dfa3e0d838989ccc7d84bfa2320ff4 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 21 Dec 2022 16:09:49 +0100 Subject: loplugin:unocast (sd::Annotation) (See the upcoming commit introducing that loplugin:unocast on why such dynamic_casts from UNO types are dangerous.) Change-Id: Id600e83ae94409914b20a2a2620031ce340a9390 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144698 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- sd/inc/Annotation.hxx | 11 ++++++++--- sd/source/core/annotations/Annotation.cxx | 22 ++++++++++++++++------ sd/source/ui/annotations/annotationtag.cxx | 3 ++- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/sd/inc/Annotation.hxx b/sd/inc/Annotation.hxx index 707f2cdc8e78..b23cd2503bb3 100644 --- a/sd/inc/Annotation.hxx +++ b/sd/inc/Annotation.hxx @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -74,7 +75,8 @@ struct SD_DLLPUBLIC CustomAnnotationMarker }; class Annotation final : private ::cppu::BaseMutex, - public ::cppu::WeakComponentImplHelper, + public ::cppu::WeakComponentImplHelper< + css::office::XAnnotation, css::lang::XUnoTunnel>, public ::cppu::PropertySetMixin { public: @@ -90,8 +92,8 @@ public: // XInterface: virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type) override; - virtual void SAL_CALL acquire() noexcept override { ::cppu::WeakComponentImplHelper::acquire(); } - virtual void SAL_CALL release() noexcept override { ::cppu::WeakComponentImplHelper::release(); } + virtual void SAL_CALL acquire() noexcept override { WeakComponentImplHelper::acquire(); } + virtual void SAL_CALL release() noexcept override { WeakComponentImplHelper::release(); } // css::beans::XPropertySet: virtual css::uno::Reference SAL_CALL getPropertySetInfo() override; @@ -116,6 +118,9 @@ public: virtual void SAL_CALL setDateTime(const css::util::DateTime & the_value) override; virtual css::uno::Reference SAL_CALL getTextRange() override; + sal_Int64 SAL_CALL getSomething(css::uno::Sequence const & aIdentifier) override; + static css::uno::Sequence const & getUnoTunnelId(); + void createChangeUndo(); void createCustomAnnotationMarker() diff --git a/sd/source/core/annotations/Annotation.cxx b/sd/source/core/annotations/Annotation.cxx index 991412f063d5..1cd608c69e00 100644 --- a/sd/source/core/annotations/Annotation.cxx +++ b/sd/source/core/annotations/Annotation.cxx @@ -26,6 +26,7 @@ #include #include +#include #include @@ -118,7 +119,7 @@ void createAnnotation(uno::Reference& xAnnotation, SdPage* sal_uInt32 Annotation::m_nLastId = 1; Annotation::Annotation( const uno::Reference& context, SdPage* pPage ) -: ::cppu::WeakComponentImplHelper(m_aMutex) +: WeakComponentImplHelper(m_aMutex) , ::cppu::PropertySetMixin(context, IMPLEMENTS_PROPERTY_SET, uno::Sequence()) , m_nId( m_nLastId++ ) , mpPage( pPage ) @@ -141,7 +142,7 @@ void SAL_CALL Annotation::disposing() uno::Any Annotation::queryInterface(css::uno::Type const & type) { - return ::cppu::WeakComponentImplHelper::queryInterface(type); + return WeakComponentImplHelper::queryInterface(type); } // com.sun.star.beans.XPropertySet: @@ -301,9 +302,18 @@ uno::Reference SAL_CALL Annotation::getTextRange() return m_TextRange; } +sal_Int64 Annotation::getSomething(css::uno::Sequence const & aIdentifier) { + return comphelper::getSomethingImpl(aIdentifier, this); +} + +css::uno::Sequence const & Annotation::getUnoTunnelId() { + static comphelper::UnoIdInit const id; + return id.getSeq(); +} + std::unique_ptr CreateUndoInsertOrRemoveAnnotation( const uno::Reference& xAnnotation, bool bInsert ) { - Annotation* pAnnotation = dynamic_cast< Annotation* >( xAnnotation.get() ); + Annotation* pAnnotation = comphelper::getFromUnoTunnel< Annotation >( xAnnotation ); if( pAnnotation ) { return std::make_unique< UndoInsertOrRemoveAnnotation >( *pAnnotation, bInsert ); @@ -316,14 +326,14 @@ std::unique_ptr CreateUndoInsertOrRemoveAnnotation( const uno::Re void CreateChangeUndo(const uno::Reference& xAnnotation) { - Annotation* pAnnotation = dynamic_cast(xAnnotation.get()); + Annotation* pAnnotation = comphelper::getFromUnoTunnel(xAnnotation); if (pAnnotation) pAnnotation->createChangeUndo(); } sal_uInt32 getAnnotationId(const uno::Reference& xAnnotation) { - Annotation* pAnnotation = dynamic_cast(xAnnotation.get()); + Annotation* pAnnotation = comphelper::getFromUnoTunnel(xAnnotation); sal_uInt32 nId = 0; if (pAnnotation) nId = pAnnotation->GetId(); @@ -332,7 +342,7 @@ sal_uInt32 getAnnotationId(const uno::Reference& xAnnotatio const SdPage* getAnnotationPage(const uno::Reference& xAnnotation) { - Annotation* pAnnotation = dynamic_cast(xAnnotation.get()); + Annotation* pAnnotation = comphelper::getFromUnoTunnel(xAnnotation); if (pAnnotation) return pAnnotation->GetPage(); return nullptr; diff --git a/sd/source/ui/annotations/annotationtag.cxx b/sd/source/ui/annotations/annotationtag.cxx index 7afe26ee54b0..f79f91a8d7c0 100644 --- a/sd/source/ui/annotations/annotationtag.cxx +++ b/sd/source/ui/annotations/annotationtag.cxx @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -225,7 +226,7 @@ void AnnotationHdl::CreateB2dIAObject() { std::unique_ptr pOverlayObject; - auto* pAnnotation = dynamic_cast(mxAnnotation.get()); + auto* pAnnotation = comphelper::getFromUnoTunnel(mxAnnotation); if (pAnnotation && pAnnotation->hasCustomAnnotationMarker()) { -- cgit