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&) {} void SAL_CALL PresenterNotesView::keyReleased (const awt::KeyEvent&) {}
sal_Int64 PresenterNotesView::getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) { 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() { 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; return mxCurrentSlide;
} }
sal_Int64 PresenterSlideShowView::getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) {
return CachablePresenterView::getSomething(aIdentifier);
}
//----- CachablePresenterView ------------------------------------------------- //----- CachablePresenterView -------------------------------------------------
void PresenterSlideShowView::ReleaseView() void PresenterSlideShowView::ReleaseView()

View File

@ -32,6 +32,7 @@
#include <com/sun/star/drawing/framework/XResourceId.hpp> #include <com/sun/star/drawing/framework/XResourceId.hpp>
#include <com/sun/star/drawing/framework/XView.hpp> #include <com/sun/star/drawing/framework/XView.hpp>
#include <com/sun/star/frame/XController.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/presentation/XSlideShowController.hpp>
#include <com/sun/star/rendering/XPolyPolygon2D.hpp> #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
#include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/uno/XComponentContext.hpp>
@ -47,7 +48,8 @@ typedef cppu::WeakComponentImplHelper<
css::awt::XMouseMotionListener, css::awt::XMouseMotionListener,
css::awt::XWindowListener, css::awt::XWindowListener,
css::drawing::framework::XView, css::drawing::framework::XView,
css::drawing::XDrawView css::drawing::XDrawView,
css::lang::XUnoTunnel
> PresenterSlideShowViewInterfaceBase; > PresenterSlideShowViewInterfaceBase;
/** Life view in a secondary window of a full screen slide show. /** 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; 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 // CachablePresenterView
virtual void ActivatePresenterView() override; 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() void PresenterSlideSorter::UpdateLayout()
{ {
if ( ! mxWindow.is()) if ( ! mxWindow.is())

View File

@ -35,6 +35,7 @@
#include <com/sun/star/drawing/framework/XResourceId.hpp> #include <com/sun/star/drawing/framework/XResourceId.hpp>
#include <com/sun/star/frame/XController.hpp> #include <com/sun/star/frame/XController.hpp>
#include <com/sun/star/geometry/RealRectangle2D.hpp> #include <com/sun/star/geometry/RealRectangle2D.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/rendering/XPolyPolygon2D.hpp> #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
namespace sdext::presenter { namespace sdext::presenter {
@ -50,7 +51,8 @@ typedef cppu::WeakComponentImplHelper<
css::drawing::XSlidePreviewCacheListener, css::drawing::XSlidePreviewCacheListener,
css::awt::XMouseListener, css::awt::XMouseListener,
css::awt::XMouseMotionListener, css::awt::XMouseMotionListener,
css::drawing::XDrawView css::drawing::XDrawView,
css::lang::XUnoTunnel
> PresenterSlideSorterInterfaceBase; > PresenterSlideSorterInterfaceBase;
/** A simple slide sorter for the presenter screen. It uses a preview cache /** 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; 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: private:
css::uno::Reference<css::uno::XComponentContext> mxComponentContext; css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
css::uno::Reference<css::drawing::framework::XResourceId> mxViewId; 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 ( void PresenterToolBar::CreateControls (
const OUString& rsConfigurationPath) const OUString& rsConfigurationPath)
{ {

View File

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

View File

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

View File

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