From 73df933f5fa5932f94e5a1b338a3eda00a9ce354 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 12 Dec 2022 13:23:05 +0100 Subject: [PATCH] loplugin:unocast (css::embed::EmbeddedUpdate) (See the upcoming commit introducing that loplugin:unocast on why such dynamic_casts from UNO types are dangerous.) Change-Id: Ia0f628be9adf749ffdd9ad36ca9b1e8c98e29936 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144755 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- .../source/commonembedding/miscobj.cxx | 7 ++++++ embeddedobj/source/inc/commonembobj.hxx | 7 +++++- .../embeddedupdate.hxx | 8 +++++-- svtools/Library_svt.mk | 1 + svtools/source/misc/embeddedupdate.cxx | 22 +++++++++++++++++++ svtools/source/misc/embedhlp.cxx | 5 +++-- 6 files changed, 45 insertions(+), 5 deletions(-) rename include/{embeddedobj => svtools}/embeddedupdate.hxx (87%) create mode 100644 svtools/source/misc/embeddedupdate.cxx diff --git a/embeddedobj/source/commonembedding/miscobj.cxx b/embeddedobj/source/commonembedding/miscobj.cxx index ecd149b8bb17..a0cce3c6f34b 100644 --- a/embeddedobj/source/commonembedding/miscobj.cxx +++ b/embeddedobj/source/commonembedding/miscobj.cxx @@ -25,11 +25,13 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -762,6 +764,7 @@ uno::Sequence SAL_CALL OCommonEmbeddedObject::getTypes() cppu::UnoType::get(), cppu::UnoType::get(), cppu::UnoType::get(), + cppu::UnoType::get(), }; return aTypes; } @@ -771,6 +774,10 @@ uno::Sequence SAL_CALL OCommonEmbeddedObject::getImplementationId() return uno::Sequence(); } +sal_Int64 OCommonEmbeddedObject::getSomething(css::uno::Sequence const & aIdentifier) { + return comphelper::getSomethingImpl(aIdentifier, static_cast(this)); +} + void SAL_CALL OCommonEmbeddedObject::initialize(const uno::Sequence& rArguments) { if (!rArguments.hasElements()) diff --git a/embeddedobj/source/inc/commonembobj.hxx b/embeddedobj/source/inc/commonembobj.hxx index 8f0a685c22c3..330dbe7ad829 100644 --- a/embeddedobj/source/inc/commonembobj.hxx +++ b/embeddedobj/source/inc/commonembobj.hxx @@ -35,11 +35,12 @@ #include #include #include +#include #include -#include #include #include #include +#include #include namespace com::sun::star { @@ -87,6 +88,7 @@ class OCommonEmbeddedObject : public css::embed::XEmbeddedObject , public css::lang::XServiceInfo , public css::lang::XInitialization , public css::lang::XTypeProvider + , public css::lang::XUnoTunnel , public ::cppu::OWeakObject { protected: @@ -434,6 +436,9 @@ public: // XTypeProvider css::uno::Sequence SAL_CALL getTypes() override; css::uno::Sequence SAL_CALL getImplementationId() override; + + // XUnoTunnel + sal_Int64 SAL_CALL getSomething(css::uno::Sequence const & aIdentifier) override; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/embeddedobj/embeddedupdate.hxx b/include/svtools/embeddedupdate.hxx similarity index 87% rename from include/embeddedobj/embeddedupdate.hxx rename to include/svtools/embeddedupdate.hxx index 63e7bf4464c8..95d49d35764a 100644 --- a/include/embeddedobj/embeddedupdate.hxx +++ b/include/svtools/embeddedupdate.hxx @@ -9,7 +9,9 @@ #pragma once -#include +#include +#include +#include namespace com { @@ -24,7 +26,7 @@ namespace embed @since LibreOffice 7.4 */ -class EMBOBJ_DLLPUBLIC SAL_LOPLUGIN_ANNOTATE("crosscast") EmbeddedUpdate +class SVT_DLLPUBLIC EmbeddedUpdate { /** By "Refresh all" is used to perform an OLE update and a link update. In the case of a link update, the class OCommonEmbeddedObject is @@ -40,6 +42,8 @@ public: EmbeddedUpdate() = default; virtual ~EmbeddedUpdate() = default; + static css::uno::Sequence const& getUnoTunnelId(); + private: EmbeddedUpdate(const EmbeddedUpdate&) = delete; EmbeddedUpdate& operator=(const EmbeddedUpdate&) = delete; diff --git a/svtools/Library_svt.mk b/svtools/Library_svt.mk index ec2405d65636..94c34808d3df 100644 --- a/svtools/Library_svt.mk +++ b/svtools/Library_svt.mk @@ -125,6 +125,7 @@ $(eval $(call gb_Library_add_exception_objects,svt,\ svtools/source/misc/cliplistener \ svtools/source/misc/dialogclosedlistener \ svtools/source/misc/ehdl \ + svtools/source/misc/embeddedupdate \ svtools/source/misc/embedhlp \ svtools/source/misc/embedtransfer \ svtools/source/misc/filechangedchecker \ diff --git a/svtools/source/misc/embeddedupdate.cxx b/svtools/source/misc/embeddedupdate.cxx new file mode 100644 index 000000000000..e763ef08e7fd --- /dev/null +++ b/svtools/source/misc/embeddedupdate.cxx @@ -0,0 +1,22 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include +#include + +css::uno::Sequence const& css::embed::EmbeddedUpdate::getUnoTunnelId() +{ + static comphelper::UnoIdInit const id; + return id.getSeq(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/svtools/source/misc/embedhlp.cxx b/svtools/source/misc/embedhlp.cxx index d784b20a4a39..17808b2892a3 100644 --- a/svtools/source/misc/embedhlp.cxx +++ b/svtools/source/misc/embedhlp.cxx @@ -19,6 +19,7 @@ #include +#include #include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -52,7 +54,6 @@ #include #include #include -#include #include #include #include @@ -933,7 +934,7 @@ void EmbeddedObjectRef::UpdateReplacement( bool bUpdateOle ) void EmbeddedObjectRef::UpdateOleObject( bool bUpdateOle ) { - embed::EmbeddedUpdate* pObj = dynamic_cast (GetObject().get()); + embed::EmbeddedUpdate* pObj = comphelper::getFromUnoTunnel (GetObject()); if( pObj ) pObj->SetOleState( bUpdateOle ); }