loplugin:unocast (sdext::presenter::CachablePresenterView)

(See the upcoming commit introducing that loplugin:unocast on why such
dynamic_casts from UNO types are dangerous.)

Change-Id: Ib158190fe9059d1c6b0b002cd37f83593a494e63
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144764
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann
2022-12-14 18:18:39 +01:00
parent 40db42be1d
commit cc147f576d
9 changed files with 54 additions and 8 deletions

View File

@@ -378,7 +378,8 @@ void SAL_CALL PresenterNotesView::keyPressed (const awt::KeyEvent& rEvent)
void SAL_CALL PresenterNotesView::keyReleased (const awt::KeyEvent&) {}
sal_Int64 PresenterNotesView::getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) {
return comphelper::getSomethingImpl(aIdentifier, this);
return comphelper::getSomethingImpl(
aIdentifier, this, comphelper::FallbackToGetSomethingOf<CachablePresenterView>{});
}
css::uno::Sequence<sal_Int8> const & PresenterNotesView::getUnoTunnelId() {

View File

@@ -279,6 +279,10 @@ css::uno::Reference<css::drawing::XDrawPage> SAL_CALL PresenterSlideShowView::ge
return mxCurrentSlide;
}
sal_Int64 PresenterSlideShowView::getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) {
return CachablePresenterView::getSomething(aIdentifier);
}
//----- CachablePresenterView -------------------------------------------------
void PresenterSlideShowView::ReleaseView()

View File

@@ -32,6 +32,7 @@
#include <com/sun/star/drawing/framework/XResourceId.hpp>
#include <com/sun/star/drawing/framework/XView.hpp>
#include <com/sun/star/frame/XController.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/presentation/XSlideShowController.hpp>
#include <com/sun/star/rendering/XPolyPolygon2D.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
@@ -47,7 +48,8 @@ typedef cppu::WeakComponentImplHelper<
css::awt::XMouseMotionListener,
css::awt::XWindowListener,
css::drawing::framework::XView,
css::drawing::XDrawView
css::drawing::XDrawView,
css::lang::XUnoTunnel
> PresenterSlideShowViewInterfaceBase;
/** Life view in a secondary window of a full screen slide show.
@@ -166,6 +168,10 @@ public:
virtual css::uno::Reference<css::drawing::XDrawPage> SAL_CALL getCurrentPage() override;
// XUnoTunnel
sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) override;
// CachablePresenterView
virtual void ActivatePresenterView() override;

View File

@@ -612,6 +612,11 @@ Reference<drawing::XDrawPage> SAL_CALL PresenterSlideSorter::getCurrentPage()
}
sal_Int64 PresenterSlideSorter::getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) {
return CachablePresenterView::getSomething(aIdentifier);
}
void PresenterSlideSorter::UpdateLayout()
{
if ( ! mxWindow.is())

View File

@@ -35,6 +35,7 @@
#include <com/sun/star/drawing/framework/XResourceId.hpp>
#include <com/sun/star/frame/XController.hpp>
#include <com/sun/star/geometry/RealRectangle2D.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/rendering/XPolyPolygon2D.hpp>
namespace sdext::presenter {
@@ -50,7 +51,8 @@ typedef cppu::WeakComponentImplHelper<
css::drawing::XSlidePreviewCacheListener,
css::awt::XMouseListener,
css::awt::XMouseMotionListener,
css::drawing::XDrawView
css::drawing::XDrawView,
css::lang::XUnoTunnel
> PresenterSlideSorterInterfaceBase;
/** A simple slide sorter for the presenter screen. It uses a preview cache
@@ -129,6 +131,10 @@ public:
virtual css::uno::Reference<css::drawing::XDrawPage> SAL_CALL getCurrentPage() override;
// XUnoTunnel
sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) override;
private:
css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
css::uno::Reference<css::drawing::framework::XResourceId> mxViewId;

View File

@@ -575,6 +575,11 @@ Reference<drawing::XDrawPage> SAL_CALL PresenterToolBar::getCurrentPage()
}
sal_Int64 PresenterToolBar::getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) {
return CachablePresenterView::getSomething(aIdentifier);
}
void PresenterToolBar::CreateControls (
const OUString& rsConfigurationPath)
{

View File

@@ -34,6 +34,7 @@
#include <com/sun/star/drawing/framework/XView.hpp>
#include <com/sun/star/drawing/framework/XResourceId.hpp>
#include <com/sun/star/frame/XController.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <functional>
@@ -44,7 +45,8 @@ typedef cppu::WeakComponentImplHelper<
css::awt::XPaintListener,
css::awt::XMouseListener,
css::awt::XMouseMotionListener,
css::drawing::XDrawView
css::drawing::XDrawView,
css::lang::XUnoTunnel
> PresenterToolBarInterfaceBase;
typedef cppu::WeakComponentImplHelper<
@@ -134,6 +136,10 @@ public:
virtual css::uno::Reference<css::drawing::XDrawPage> SAL_CALL getCurrentPage() override;
// XUnoTunnel
sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) override;
class Context;
private:

View File

@@ -26,6 +26,7 @@
#include "PresenterSlideSorter.hxx"
#include "PresenterToolBar.hxx"
#include <com/sun/star/drawing/framework/XControllerManager.hpp>
#include <comphelper/servicehelper.hxx>
#include <utility>
using namespace ::com::sun::star;
@@ -215,7 +216,7 @@ void SAL_CALL PresenterViewFactory::releaseResource (const Reference<XResource>&
pDescriptor->SetActivationState(false);
// Dispose only views that we can not put into the cache.
CachablePresenterView* pView = dynamic_cast<CachablePresenterView*>(rxView.get());
CachablePresenterView* pView = comphelper::getFromUnoTunnel<CachablePresenterView>(rxView);
if (pView == nullptr || mpResourceCache == nullptr)
{
try
@@ -271,7 +272,7 @@ Reference<XResource> PresenterViewFactory::GetViewFromCache(
if (iView->second.second == rxAnchorPane)
{
CachablePresenterView* pView
= dynamic_cast<CachablePresenterView*>(iView->second.first.get());
= comphelper::getFromUnoTunnel<CachablePresenterView>(iView->second.first);
if (pView != nullptr)
pView->ActivatePresenterView();
return iView->second.first;
@@ -322,7 +323,7 @@ Reference<XResource> PresenterViewFactory::CreateView(
}
// Activate it.
CachablePresenterView* pView = dynamic_cast<CachablePresenterView*>(xView.get());
CachablePresenterView* pView = comphelper::getFromUnoTunnel<CachablePresenterView>(xView);
if (pView != nullptr)
pView->ActivatePresenterView();
}
@@ -480,6 +481,15 @@ void PresenterViewFactory::ThrowIfDisposed() const
//===== CachablePresenterView =================================================
sal_Int64 CachablePresenterView::getSomething(css::uno::Sequence<sal_Int8> const & id) {
return comphelper::getSomethingImpl(id, this);
}
css::uno::Sequence<sal_Int8> const & CachablePresenterView::getUnoTunnelId() {
static comphelper::UnoIdInit const id;
return id.getSeq();
}
CachablePresenterView::CachablePresenterView()
: mbIsPresenterViewActive(true)
{

View File

@@ -39,7 +39,7 @@ typedef ::cppu::WeakComponentImplHelper <
/** Base class for presenter views that allows the view factory to store
them in a cache and reuse deactivated views.
*/
class SAL_LOPLUGIN_ANNOTATE("crosscast") CachablePresenterView
class CachablePresenterView
{
public:
virtual void ActivatePresenterView();
@@ -55,6 +55,9 @@ public:
*/
virtual void ReleaseView();
sal_Int64 getSomething(css::uno::Sequence<sal_Int8> const & id);
static css::uno::Sequence<sal_Int8> const & getUnoTunnelId();
protected:
bool mbIsPresenterViewActive;