chart2/source/controller/sidebar/ChartLinePanel.cxx | 3 ++- include/svx/linectrl.hxx | 8 +++++++- sdext/source/presenter/PresenterController.cxx | 8 ++------ sdext/source/presenter/PresenterController.hxx | 6 ++++-- sdext/source/presenter/PresenterScreen.cxx | 2 +- svx/source/sidebar/line/LinePropertyPanelBase.cxx | 3 ++- svx/source/tbxctrls/linectrl.cxx | 13 ++++++++++++- 7 files changed, 30 insertions(+), 13 deletions(-)
New commits: commit f1b7a69b280aefe2f1b3b0f32193494fd765f2bd Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Thu Dec 15 20:45:53 2022 +0100 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Fri Dec 16 20:17:17 2022 +0000 loplugin:unocast (SvxLineStyleToolBoxControl) (See the upcoming commit introducing that loplugin:unocast on why such dynamic_casts from UNO types are dangerous.) Change-Id: I13f71f717a8661e0889ab7acf6fe7c7ebbe3dbe6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144332 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/chart2/source/controller/sidebar/ChartLinePanel.cxx b/chart2/source/controller/sidebar/ChartLinePanel.cxx index d9da9a2985ef..bc905c9d9900 100644 --- a/chart2/source/controller/sidebar/ChartLinePanel.cxx +++ b/chart2/source/controller/sidebar/ChartLinePanel.cxx @@ -25,6 +25,7 @@ #include <com/sun/star/chart2/XDiagram.hpp> #include <comphelper/lok.hxx> +#include <comphelper/servicehelper.hxx> #include <sfx2/viewsh.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> @@ -35,7 +36,7 @@ namespace { SvxLineStyleToolBoxControl* getLineStyleToolBoxControl(const ToolbarUnoDispatcher& rToolBoxColor) { css::uno::Reference<css::frame::XToolbarController> xController = rToolBoxColor.GetControllerForCommand(".uno:XLineStyle"); - SvxLineStyleToolBoxControl* pToolBoxLineStyleControl = dynamic_cast<SvxLineStyleToolBoxControl*>(xController.get()); + SvxLineStyleToolBoxControl* pToolBoxLineStyleControl = comphelper::getFromUnoTunnel<SvxLineStyleToolBoxControl>(xController); return pToolBoxLineStyleControl; } diff --git a/include/svx/linectrl.hxx b/include/svx/linectrl.hxx index e2cd9e6c8852..983242b776d2 100644 --- a/include/svx/linectrl.hxx +++ b/include/svx/linectrl.hxx @@ -19,6 +19,8 @@ #ifndef INCLUDED_SVX_LINECTRL_HXX #define INCLUDED_SVX_LINECTRL_HXX +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <cppuhelper/implbase.hxx> #include <sfx2/tbxctrl.hxx> #include <svtools/popupwindowcontroller.hxx> #include <svx/svxdllapi.h> @@ -35,7 +37,8 @@ typedef std::function<bool(const OUString&, const css::uno::Any&)> LineStyleSele typedef std::function<void(bool)> LineStyleIsNoneFunction; // SvxLineStyleController: -class SVXCORE_DLLPUBLIC SvxLineStyleToolBoxControl final : public svt::PopupWindowController +class SVXCORE_DLLPUBLIC SvxLineStyleToolBoxControl final : + public cppu::ImplInheritanceHelper<svt::PopupWindowController, css::lang::XUnoTunnel> { private: std::unique_ptr<svx::ToolboxButtonLineStyleUpdater> m_xBtnUpdater; @@ -53,6 +56,9 @@ public: virtual OUString SAL_CALL getImplementationName() override; virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; + sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) override; + static css::uno::Sequence<sal_Int8> const & getUnoTunnelId(); + virtual void SAL_CALL execute(sal_Int16 nKeyModifier) override; virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& rEvent) override; diff --git a/svx/source/sidebar/line/LinePropertyPanelBase.cxx b/svx/source/sidebar/line/LinePropertyPanelBase.cxx index 454e16a335f8..d04b16103e6b 100644 --- a/svx/source/sidebar/line/LinePropertyPanelBase.cxx +++ b/svx/source/sidebar/line/LinePropertyPanelBase.cxx @@ -18,6 +18,7 @@ */ #include <memory> +#include <comphelper/servicehelper.hxx> #include <svx/sidebar/LinePropertyPanelBase.hxx> #include <sfx2/weldutils.hxx> #include <svx/linectrl.hxx> @@ -57,7 +58,7 @@ namespace SvxLineStyleToolBoxControl* getLineStyleToolBoxControl(const ToolbarUnoDispatcher& rToolBoxColor) { css::uno::Reference<css::frame::XToolbarController> xController = rToolBoxColor.GetControllerForCommand(".uno:XLineStyle"); - SvxLineStyleToolBoxControl* pToolBoxLineStyleControl = dynamic_cast<SvxLineStyleToolBoxControl*>(xController.get()); + SvxLineStyleToolBoxControl* pToolBoxLineStyleControl = comphelper::getFromUnoTunnel<SvxLineStyleToolBoxControl>(xController); return pToolBoxLineStyleControl; } } diff --git a/svx/source/tbxctrls/linectrl.cxx b/svx/source/tbxctrls/linectrl.cxx index 81f064fc78f4..b75fee2d88b0 100644 --- a/svx/source/tbxctrls/linectrl.cxx +++ b/svx/source/tbxctrls/linectrl.cxx @@ -48,6 +48,7 @@ #include <comphelper/lok.hxx> #include <comphelper/propertyvalue.hxx> +#include <comphelper/servicehelper.hxx> using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; @@ -60,7 +61,7 @@ using namespace ::com::sun::star; #define MAX_LINES 12 SvxLineStyleToolBoxControl::SvxLineStyleToolBoxControl( const css::uno::Reference<css::uno::XComponentContext>& rContext ) - : svt::PopupWindowController( rContext, nullptr, OUString() ) + : ImplInheritanceHelper( rContext, nullptr, OUString() ) { addStatusListener(".uno:LineDash"); } @@ -217,6 +218,16 @@ css::uno::Sequence<OUString> SvxLineStyleToolBoxControl::getSupportedServiceName return { "com.sun.star.frame.ToolbarController" }; } +sal_Int64 SvxLineStyleToolBoxControl::getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) +{ + return comphelper::getSomethingImpl(aIdentifier, this); +} + +css::uno::Sequence<sal_Int8> const & SvxLineStyleToolBoxControl::getUnoTunnelId() { + static comphelper::UnoIdInit const id; + return id.getSeq(); +} + extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_svx_LineStyleToolBoxControl_get_implementation( css::uno::XComponentContext* rContext, commit 32ba2102526a663440957a16e0ebee89bea9f603 Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Wed Dec 14 11:16:14 2022 +0100 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Fri Dec 16 20:17:05 2022 +0000 Use unotoosl::WeakReference to avoid a dynamic_cast Change-Id: I46c122e800c63038cf7fd650ebb6f0115c6e8c78 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144330 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/sdext/source/presenter/PresenterController.cxx b/sdext/source/presenter/PresenterController.cxx index a56071f9ec3f..e9831ac749d5 100644 --- a/sdext/source/presenter/PresenterController.cxx +++ b/sdext/source/presenter/PresenterController.cxx @@ -83,7 +83,7 @@ PresenterController::InstanceContainer PresenterController::maInstances; } PresenterController::PresenterController ( - css::uno::WeakReference<css::lang::XEventListener> xScreen, + unotools::WeakReference<PresenterScreen> xScreen, const Reference<XComponentContext>& rxContext, const Reference<frame::XController>& rxController, const Reference<presentation::XSlideShowController>& rxSlideShowController, @@ -1156,11 +1156,7 @@ void PresenterController::UpdatePendingSlideNumber (const sal_Int32 nPendingSlid void PresenterController::SwitchMonitors() { - Reference<lang::XEventListener> xScreen( mxScreen ); - if (!xScreen.is()) - return; - - PresenterScreen *pScreen = dynamic_cast<PresenterScreen *>(xScreen.get()); + rtl::Reference<PresenterScreen> pScreen( mxScreen ); if (!pScreen) return; diff --git a/sdext/source/presenter/PresenterController.hxx b/sdext/source/presenter/PresenterController.hxx index 9b7062ec89f6..f29970c6903d 100644 --- a/sdext/source/presenter/PresenterController.hxx +++ b/sdext/source/presenter/PresenterController.hxx @@ -38,6 +38,7 @@ #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/util/XURLTransformer.hpp> #include <rtl/ref.hxx> +#include <unotools/weakref.hxx> #include <map> #include <memory> @@ -48,6 +49,7 @@ class PresenterPaintManager; class PresenterPaneAnimator; class PresenterPaneContainer; class PresenterPaneBorderPainter; +class PresenterScreen; class PresenterTheme; class PresenterWindowManager; @@ -81,7 +83,7 @@ public: const css::uno::Reference<css::frame::XFrame>& rxFrame); PresenterController ( - css::uno::WeakReference<css::lang::XEventListener> xScreen, + unotools::WeakReference<PresenterScreen> xScreen, const css::uno::Reference<css::uno::XComponentContext>& rxContext, const css::uno::Reference<css::frame::XController>& rxController, const css::uno::Reference<css::presentation::XSlideShowController>& rxSlideShowController, @@ -171,7 +173,7 @@ private: typedef ::std::map<css::uno::Reference<css::frame::XFrame>,rtl::Reference<PresenterController> > InstanceContainer; static InstanceContainer maInstances; - css::uno::WeakReference<css::lang::XEventListener> mxScreen; + unotools::WeakReference<PresenterScreen> mxScreen; css::uno::Reference<css::uno::XComponentContext> mxComponentContext; css::uno::Reference<css::rendering::XSpriteCanvas> mxCanvas; css::uno::Reference<css::frame::XController> mxController; diff --git a/sdext/source/presenter/PresenterScreen.cxx b/sdext/source/presenter/PresenterScreen.cxx index cf24a26f7bf1..0f4cdedb98fa 100644 --- a/sdext/source/presenter/PresenterScreen.cxx +++ b/sdext/source/presenter/PresenterScreen.cxx @@ -364,7 +364,7 @@ void PresenterScreen::InitializePresenterScreen() SetupConfiguration(xContext, xMainPaneId); mpPresenterController = new PresenterController( - css::uno::WeakReference<css::lang::XEventListener>(this), + this, xContext, mxController, xSlideShowController,