chart2/source/controller/main/ChartController.cxx | 4 ++-- include/sfx2/sidebar/SidebarController.hxx | 7 ++++++- sfx2/source/sidebar/SidebarController.cxx | 16 +++++++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-)
New commits: commit 88b4f966202717cd4ad38a30a8eda22c3e69ed35 Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Tue Dec 13 13:42:10 2022 +0100 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Fri Dec 16 20:17:34 2022 +0000 loplugin:unocast (sfx2::sidebar::SidebarController) (See the upcoming commit introducing that loplugin:unocast on why such dynamic_casts from UNO types are dangerous.) Change-Id: Ib681b4eaa44c65b9da5988c74c03f1829e3a1507 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144334 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/chart2/source/controller/main/ChartController.cxx b/chart2/source/controller/main/ChartController.cxx index 1a59bb161ec3..2ba57aa45d33 100644 --- a/chart2/source/controller/main/ChartController.cxx +++ b/chart2/source/controller/main/ChartController.cxx @@ -377,7 +377,7 @@ void SAL_CALL ChartController::attachFrame( uno::Reference<ui::XSidebar> xSidebar = getSidebarFromModel(getChartModel()); if (xSidebar.is()) { - auto pSidebar = dynamic_cast<sfx2::sidebar::SidebarController*>(xSidebar.get()); + auto pSidebar = comphelper::getFromUnoTunnel<sfx2::sidebar::SidebarController>(xSidebar); assert(pSidebar); pSidebar->registerSidebarForFrame(this); pSidebar->updateModel(getChartModel()); @@ -761,7 +761,7 @@ void SAL_CALL ChartController::dispose() if (getModel().is()) { uno::Reference<ui::XSidebar> xSidebar = getSidebarFromModel(getChartModel()); - if (sfx2::sidebar::SidebarController* pSidebar = dynamic_cast<sfx2::sidebar::SidebarController*>(xSidebar.get())) + if (sfx2::sidebar::SidebarController* pSidebar = comphelper::getFromUnoTunnel<sfx2::sidebar::SidebarController>(xSidebar)) { pSidebar->unregisterSidebarForFrame(this); } diff --git a/include/sfx2/sidebar/SidebarController.hxx b/include/sfx2/sidebar/SidebarController.hxx index 208af98b2fc2..be0a12b3a671 100644 --- a/include/sfx2/sidebar/SidebarController.hxx +++ b/include/sfx2/sidebar/SidebarController.hxx @@ -33,6 +33,7 @@ #include <com/sun/star/beans/XPropertyChangeListener.hpp> #include <com/sun/star/frame/XStatusListener.hpp> #include <com/sun/star/frame/XFrameActionListener.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/ui/XContextChangeEventListener.hpp> #include <com/sun/star/ui/XSidebar.hpp> @@ -48,7 +49,8 @@ typedef comphelper::WeakComponentImplHelper < css::beans::XPropertyChangeListener, css::ui::XSidebar, css::frame::XStatusListener, - css::frame::XFrameActionListener + css::frame::XFrameActionListener, + css::lang::XUnoTunnel > SidebarControllerInterfaceBase; class SfxSplitWindow; @@ -175,6 +177,9 @@ public: static SidebarController* GetSidebarControllerForView(const SfxViewShell* pViewShell); + sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) override; + static css::uno::Sequence<sal_Int8> const & getUnoTunnelId(); + private: SidebarController(SidebarDockingWindow* pParentWindow, const SfxViewFrame* pViewFrame); diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx index a35bb1f7488c..550b1e8cc5d7 100644 --- a/sfx2/source/sidebar/SidebarController.cxx +++ b/sfx2/source/sidebar/SidebarController.cxx @@ -41,6 +41,7 @@ #include <vcl/svapp.hxx> #include <splitwin.hxx> #include <comphelper/diagnose_ex.hxx> +#include <comphelper/servicehelper.hxx> #include <tools/json_writer.hxx> #include <tools/link.hxx> #include <toolkit/helper/vclunohelper.hxx> @@ -186,10 +187,10 @@ SidebarController* SidebarController::GetSidebarControllerForFrame ( ::comphelper::getProcessComponentContext(), xController, [] (uno::Reference<uno::XInterface> const& xRef) - { return nullptr != dynamic_cast<SidebarController*>(xRef.get()); } + { return nullptr != comphelper::getFromUnoTunnel<SidebarController>(xRef); } )); - return dynamic_cast<SidebarController*>(xListener.get()); + return comphelper::getFromUnoTunnel<SidebarController>(xListener); } void SidebarController::registerSidebarForFrame(const css::uno::Reference<css::frame::XController>& xController) @@ -1646,7 +1647,16 @@ sfx2::sidebar::SidebarController* SidebarController::GetSidebarControllerForView if (!xSidebar.is()) return nullptr; - return dynamic_cast<sfx2::sidebar::SidebarController*>(xSidebar.get()); + return comphelper::getFromUnoTunnel<sfx2::sidebar::SidebarController>(xSidebar); +} + +sal_Int64 SidebarController::getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) { + return comphelper::getSomethingImpl(aIdentifier, this); +} + +css::uno::Sequence<sal_Int8> const & SidebarController::getUnoTunnelId() { + static comphelper::UnoIdInit const id; + return id.getSeq(); } } // end of namespace sfx2::sidebar