summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-12-21 16:09:49 +0100
committerStephan Bergmann <sbergman@redhat.com>2022-12-22 07:44:42 +0000
commit99009c9535dfa3e0d838989ccc7d84bfa2320ff4 (patch)
treeb962a22ca2a274c4a664f6e49500cec9e472407d
parent0c7585c5fa78887e5459885ed744e8044fd76137 (diff)
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 <sbergman@redhat.com>
-rw-r--r--sd/inc/Annotation.hxx11
-rw-r--r--sd/source/core/annotations/Annotation.cxx22
-rw-r--r--sd/source/ui/annotations/annotationtag.cxx3
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 <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())
{