loplugin:unocast (vclcanvas::RepaintTarget)

(The overall inheritance hierarchies of the classes deriving from RepaintTarget
are so over-engineered that it looks easier to make each of those classes derive
from css::uno::XUnoTunnel individually, rather than deriving RepaintTarget from
something like cppu::WeakImplHelper<css::uno::XUnoTunnel>.  And see the upcoming
commit introducing that loplugin:unocast on why such dynamic_casts from UNO
types are dangerous.)

Change-Id: I4bcfad4049a2fb366768602a432c1282c2bf477e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144140
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann
2022-12-14 08:54:15 +00:00
parent cbb3f69724
commit 276e3ccbdd
10 changed files with 56 additions and 6 deletions
+2 -1
View File
@@ -23,6 +23,7 @@
#include <com/sun/star/rendering/RepaintResult.hpp>
#include <utility>
#include <comphelper/diagnose_ex.hxx>
#include <comphelper/servicehelper.hxx>
#include "cachedbitmap.hxx"
#include "repainttarget.hxx"
@@ -70,7 +71,7 @@ namespace vclcanvas
if( rNewState.Clip != rOldState.Clip )
return rendering::RepaintResult::FAILED;
RepaintTarget* pTarget = dynamic_cast< RepaintTarget* >(rTargetCanvas.get());
RepaintTarget* pTarget = comphelper::getFromUnoTunnel< RepaintTarget >(rTargetCanvas);
ENSURE_OR_THROW( pTarget,
"CachedBitmap::redraw(): cannot cast target to RepaintTarget" );
+5
View File
@@ -24,6 +24,7 @@
#include <com/sun/star/lang/NoSupportException.hpp>
#include <sal/log.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <comphelper/servicehelper.hxx>
#include <vcl/outdev.hxx>
#include "outdevholder.hxx"
@@ -96,6 +97,10 @@ namespace vclcanvas
return "com.sun.star.rendering.Canvas.VCL";
}
sal_Int64 Canvas::getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) {
return comphelper::getSomethingImpl(aIdentifier, static_cast<RepaintTarget *>(this));
}
bool Canvas::repaint( const GraphicObjectSharedPtr& rGrf,
const rendering::ViewState& viewState,
const rendering::RenderState& renderState,
+6 -1
View File
@@ -22,6 +22,7 @@
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/lang/XServiceName.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/util/XUpdatable.hpp>
#include <com/sun/star/rendering/XBitmapCanvas.hpp>
#include <com/sun/star/rendering/XIntegerBitmap.hpp>
@@ -48,7 +49,8 @@ namespace vclcanvas
css::lang::XMultiServiceFactory,
css::util::XUpdatable,
css::beans::XPropertySet,
css::lang::XServiceName > GraphicDeviceBase_Base;
css::lang::XServiceName,
css::lang::XUnoTunnel> GraphicDeviceBase_Base;
typedef ::canvas::GraphicDeviceBase< ::canvas::BaseMutexHelper< GraphicDeviceBase_Base >,
DeviceHelper,
tools::LocalGuard,
@@ -96,6 +98,9 @@ namespace vclcanvas
// XServiceName
virtual OUString SAL_CALL getServiceName( ) override;
// XUnoTunnel
sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) override;
// RepaintTarget
virtual bool repaint( const GraphicObjectSharedPtr& rGrf,
const css::rendering::ViewState& viewState,
+5
View File
@@ -19,6 +19,7 @@
#include <sal/config.h>
#include <comphelper/servicehelper.hxx>
#include <cppuhelper/supportsservice.hxx>
#include "canvasbitmap.hxx"
@@ -84,6 +85,10 @@ namespace vclcanvas
return { "com.sun.star.rendering.CanvasBitmap" };
}
sal_Int64 CanvasBitmap::getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) {
return comphelper::getSomethingImpl(aIdentifier, static_cast<RepaintTarget *>(this));
}
BitmapEx CanvasBitmap::getBitmap() const
{
SolarMutexGuard aGuard;
+6 -1
View File
@@ -22,6 +22,7 @@
#include <cppuhelper/compbase.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/rendering/XBitmapCanvas.hpp>
#include <com/sun/star/rendering/XIntegerBitmap.hpp>
#include <com/sun/star/beans/XFastPropertySet.hpp>
@@ -44,7 +45,8 @@ namespace vclcanvas
typedef ::cppu::WeakComponentImplHelper< css::rendering::XBitmapCanvas,
css::rendering::XIntegerBitmap,
css::lang::XServiceInfo,
css::beans::XFastPropertySet > CanvasBitmapBase_Base;
css::beans::XFastPropertySet,
css::lang::XUnoTunnel> CanvasBitmapBase_Base;
typedef ::canvas::IntegerBitmapBase<
canvas::BitmapCanvasBase2<
::canvas::BaseMutexHelper< CanvasBitmapBase_Base >,
@@ -82,6 +84,9 @@ namespace vclcanvas
virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
// XUnoTunnel
sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) override;
// RepaintTarget interface
virtual bool repaint( const GraphicObjectSharedPtr& rGrf,
const css::rendering::ViewState& viewState,
+5
View File
@@ -23,6 +23,7 @@
#include <basegfx/point/b2dpoint.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <comphelper/servicehelper.hxx>
#include <vcl/outdev.hxx>
#include "canvascustomsprite.hxx"
@@ -116,6 +117,10 @@ namespace vclcanvas
return { "com.sun.star.rendering.CanvasCustomSprite" };
}
sal_Int64 CanvasCustomSprite::getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) {
return comphelper::getSomethingImpl(aIdentifier, static_cast<RepaintTarget *>(this));
}
// Sprite
void CanvasCustomSprite::redraw( OutputDevice& rOutDev,
bool bBufferedUpdate ) const
+6 -1
View File
@@ -23,6 +23,7 @@
#include <comphelper/uno3.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/rendering/XBitmapCanvas.hpp>
#include <com/sun/star/rendering/XCustomSprite.hpp>
#include <com/sun/star/rendering/XIntegerBitmap.hpp>
@@ -43,7 +44,8 @@ namespace vclcanvas
typedef ::cppu::WeakComponentImplHelper< css::rendering::XCustomSprite,
css::rendering::XBitmapCanvas,
css::rendering::XIntegerBitmap,
css::lang::XServiceInfo > CanvasCustomSpriteBase_Base;
css::lang::XServiceInfo,
css::lang::XUnoTunnel> CanvasCustomSpriteBase_Base;
/** Mixin Sprite
Have to mixin the Sprite interface before deriving from
@@ -96,6 +98,9 @@ namespace vclcanvas
virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
// XUnoTunnel
sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) override;
// Sprite
virtual void redraw( OutputDevice& rOutDev,
bool bBufferedUpdate ) const override;
+10 -1
View File
@@ -19,6 +19,10 @@
#pragma once
#include <com/sun/star/uno/Sequence.hxx>
#include <comphelper/servicehelper.hxx>
#include <sal/types.h>
#include "cachedbitmap.hxx"
class Point;
@@ -34,7 +38,7 @@ namespace vclcanvas
This interface must be implemented on all canvas
implementations that hand out XCachedPrimitives
*/
class SAL_LOPLUGIN_ANNOTATE("crosscast") RepaintTarget
class RepaintTarget
{
public:
virtual ~RepaintTarget() {}
@@ -46,6 +50,11 @@ namespace vclcanvas
const ::Point& rPt,
const ::Size& rSz,
const GraphicAttr& rAttr ) const = 0;
static css::uno::Sequence<sal_Int8> const & getUnoTunnelId() {
static comphelper::UnoIdInit const id;
return id.getSeq();
}
};
}
+5
View File
@@ -24,6 +24,7 @@
#include <com/sun/star/lang/NoSupportException.hpp>
#include <cppuhelper/supportsservice.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <comphelper/servicehelper.hxx>
#include "spritecanvas.hxx"
#include "outdevholder.hxx"
@@ -161,6 +162,10 @@ namespace vclcanvas
return cppu::supportsService(this, sServiceName);
}
sal_Int64 SpriteCanvas::getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) {
return comphelper::getSomethingImpl(aIdentifier, static_cast<RepaintTarget *>(this));
}
bool SpriteCanvas::repaint( const GraphicObjectSharedPtr& rGrf,
const rendering::ViewState& viewState,
const rendering::RenderState& renderState,
+6 -1
View File
@@ -25,6 +25,7 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XServiceName.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/awt/XWindowListener.hpp>
#include <com/sun/star/util/XUpdatable.hpp>
#include <com/sun/star/rendering/XSpriteCanvas.hpp>
@@ -57,7 +58,8 @@ namespace vclcanvas
css::util::XUpdatable,
css::beans::XPropertySet,
css::lang::XServiceName,
css::lang::XServiceInfo > WindowGraphicDeviceBase_Base;
css::lang::XServiceInfo,
css::lang::XUnoTunnel > WindowGraphicDeviceBase_Base;
typedef ::canvas::BufferedGraphicDeviceBase< ::canvas::DisambiguationHelper< WindowGraphicDeviceBase_Base >,
SpriteDeviceHelper,
tools::LocalGuard,
@@ -138,6 +140,9 @@ namespace vclcanvas
virtual OUString SAL_CALL getImplementationName() override;
virtual sal_Bool SAL_CALL supportsService(const OUString&) override;
// XUnoTunnel
sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) override;
// RepaintTarget
virtual bool repaint( const GraphicObjectSharedPtr& rGrf,
const css::rendering::ViewState& viewState,