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(-)

New commits:
commit 99009c9535dfa3e0d838989ccc7d84bfa2320ff4
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Wed Dec 21 16:09:49 2022 +0100
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Thu Dec 22 07:44:42 2022 +0000

    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 <sberg...@redhat.com>

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 <sal/types.h>
 #include <memory>
 
+#include <com/sun/star/lang/XUnoTunnel.hpp>
 #include <com/sun/star/office/XAnnotation.hpp>
 #include <cppuhelper/basemutex.hxx>
 #include <cppuhelper/compbase.hxx>
@@ -74,7 +75,8 @@ struct SD_DLLPUBLIC CustomAnnotationMarker
 };
 
 class Annotation final : private ::cppu::BaseMutex,
-                   public 
::cppu::WeakComponentImplHelper<css::office::XAnnotation>,
+                   public ::cppu::WeakComponentImplHelper<
+                       css::office::XAnnotation, css::lang::XUnoTunnel>,
                    public ::cppu::PropertySetMixin<css::office::XAnnotation>
 {
 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<css::office::XAnnotation>::acquire(); }
-    virtual void SAL_CALL release() noexcept override { 
::cppu::WeakComponentImplHelper<css::office::XAnnotation>::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<css::beans::XPropertySetInfo> 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<css::text::XText> SAL_CALL getTextRange() 
override;
 
+    sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & 
aIdentifier) override;
+    static css::uno::Sequence<sal_Int8> 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 <comphelper/processfactory.hxx>
 #include <comphelper/lok.hxx>
+#include <comphelper/servicehelper.hxx>
 
 #include <unotools/datetime.hxx>
 
@@ -118,7 +119,7 @@ void createAnnotation(uno::Reference<office::XAnnotation>& 
xAnnotation, SdPage*
 sal_uInt32 Annotation::m_nLastId = 1;
 
 Annotation::Annotation( const uno::Reference<uno::XComponentContext>& context, 
SdPage* pPage )
-: ::cppu::WeakComponentImplHelper<office::XAnnotation>(m_aMutex)
+: WeakComponentImplHelper(m_aMutex)
 , ::cppu::PropertySetMixin<office::XAnnotation>(context, 
IMPLEMENTS_PROPERTY_SET, uno::Sequence<OUString>())
 , 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<office::XAnnotation>::queryInterface(type);
+    return WeakComponentImplHelper::queryInterface(type);
 }
 
 // com.sun.star.beans.XPropertySet:
@@ -301,9 +302,18 @@ uno::Reference<text::XText> SAL_CALL 
Annotation::getTextRange()
     return m_TextRange;
 }
 
+sal_Int64 Annotation::getSomething(css::uno::Sequence<sal_Int8> const & 
aIdentifier) {
+    return comphelper::getSomethingImpl(aIdentifier, this);
+}
+
+css::uno::Sequence<sal_Int8> const & Annotation::getUnoTunnelId() {
+    static comphelper::UnoIdInit const id;
+    return id.getSeq();
+}
+
 std::unique_ptr<SdrUndoAction> CreateUndoInsertOrRemoveAnnotation( const 
uno::Reference<office::XAnnotation>& 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<SdrUndoAction> 
CreateUndoInsertOrRemoveAnnotation( const uno::Re
 
 void CreateChangeUndo(const uno::Reference<office::XAnnotation>& xAnnotation)
 {
-    Annotation* pAnnotation = dynamic_cast<Annotation*>(xAnnotation.get());
+    Annotation* pAnnotation = 
comphelper::getFromUnoTunnel<Annotation>(xAnnotation);
     if (pAnnotation)
         pAnnotation->createChangeUndo();
 }
 
 sal_uInt32 getAnnotationId(const uno::Reference<office::XAnnotation>& 
xAnnotation)
 {
-    Annotation* pAnnotation = dynamic_cast<Annotation*>(xAnnotation.get());
+    Annotation* pAnnotation = 
comphelper::getFromUnoTunnel<Annotation>(xAnnotation);
     sal_uInt32 nId = 0;
     if (pAnnotation)
         nId = pAnnotation->GetId();
@@ -332,7 +342,7 @@ sal_uInt32 getAnnotationId(const 
uno::Reference<office::XAnnotation>& xAnnotatio
 
 const SdPage* getAnnotationPage(const uno::Reference<office::XAnnotation>& 
xAnnotation)
 {
-    Annotation* pAnnotation = dynamic_cast<Annotation*>(xAnnotation.get());
+    Annotation* pAnnotation = 
comphelper::getFromUnoTunnel<Annotation>(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 <vcl/settings.hxx>
 #include <vcl/weldutils.hxx>
 
+#include <comphelper/servicehelper.hxx>
 #include <svx/sdr/overlay/overlayanimatedbitmapex.hxx>
 #include <svx/sdr/overlay/overlaybitmapex.hxx>
 #include <svx/sdr/overlay/overlaypolypolygon.hxx>
@@ -225,7 +226,7 @@ void AnnotationHdl::CreateB2dIAObject()
         {
             std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject;
 
-            auto* pAnnotation = 
dynamic_cast<sd::Annotation*>(mxAnnotation.get());
+            auto* pAnnotation = 
comphelper::getFromUnoTunnel<sd::Annotation>(mxAnnotation);
 
             if (pAnnotation && pAnnotation->hasCustomAnnotationMarker())
             {

Reply via email to