include/comphelper/servicehelper.hxx | 20 ++++++++++++++++++ include/oox/mathml/imexport.hxx | 5 ++++ oox/source/drawingml/shape.cxx | 3 +- oox/source/export/shapes.cxx | 3 +- oox/source/mathml/imexport.cxx | 10 +++++++++ starmath/source/unomodel.cxx | 1 sw/source/filter/ww8/docxattributeoutput.cxx | 3 +- sw/source/filter/ww8/rtfattributeoutput.cxx | 3 +- writerfilter/source/dmapper/DomainMapper_Impl.cxx | 3 +- writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 3 +- writerfilter/source/rtftok/rtfdocumentimpl.cxx | 3 +- 11 files changed, 50 insertions(+), 7 deletions(-)
New commits: commit 4d6c23216559eb48f9943bb49d6e475a6d64ba15 Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Fri Dec 16 23:02:08 2022 +0100 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Mon Dec 19 12:57:29 2022 +0000 loplugin:unocast (oox::ForumlaImExportBase) (See the upcoming commit introducing that loplugin:unocast on why such dynamic_casts from UNO types are dangerous.) Change-Id: I11bc363447c44319bc47f7eebb7084f64ea85511 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144400 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/include/comphelper/servicehelper.hxx b/include/comphelper/servicehelper.hxx index 1d157cbf1482..286108bd2568 100644 --- a/include/comphelper/servicehelper.hxx +++ b/include/comphelper/servicehelper.hxx @@ -137,6 +137,26 @@ namespace comphelper { return FallbackToGetSomethingOf<Base>::get(rId, pThis); } +#if defined _MSC_VER && _MSC_VER < 1930 && !defined __clang__ + // Without this additional overload, at least VS 2019 16.11.21 has sometimes issues deducing the + // Base template argument in calls to the "full" getSomethingImpl overload with zero arguments + // substituted for the variadic Mixins parameter: + template <class T, class Mixin, class Base> + sal_Int64 getSomethingImpl(const css::uno::Sequence<sal_Int8>& rId, T* pThis, + MixinToGetSomethingOf<Mixin>, + FallbackToGetSomethingOf<Base>) + { + sal_Int64 res; + if (MixinToGetSomethingOf<T>::get(rId, pThis, &res) + || MixinToGetSomethingOf<Mixin>::get(rId, pThis, &res)) + { + return res; + } + + return FallbackToGetSomethingOf<Base>::get(rId, pThis); + } +#endif + template <class T, class Mixin, class... Mixins, class Base> sal_Int64 getSomethingImpl(const css::uno::Sequence<sal_Int8>& rId, T* pThis, MixinToGetSomethingOf<Mixin>, MixinToGetSomethingOf<Mixins>..., diff --git a/include/oox/mathml/imexport.hxx b/include/oox/mathml/imexport.hxx index a93216fb1199..5a0ac1313f18 100644 --- a/include/oox/mathml/imexport.hxx +++ b/include/oox/mathml/imexport.hxx @@ -9,12 +9,14 @@ #ifndef INCLUDED_OOX_MATHML_IMEXPORT_HXX #define INCLUDED_OOX_MATHML_IMEXPORT_HXX +#include <com/sun/star/uno/Sequence.hxx> #include <oox/core/filterbase.hxx> #include <oox/dllapi.h> #include <oox/export/utils.hxx> #include <rtl/ref.hxx> #include <rtl/strbuf.hxx> #include <rtl/textenc.h> +#include <sal/types.h> #include <sax/fshelper.hxx> #include <tools/gen.hxx> @@ -43,6 +45,9 @@ public: virtual void writeFormulaRtf( OStringBuffer& rBuffer, rtl_TextEncoding nEncoding ) = 0; enum eFormulaAlign { INLINE, CENTER, GROUPEDCENTER, LEFT, RIGHT }; + sal_Int64 getSomething(css::uno::Sequence<sal_Int8> const & id); + static css::uno::Sequence<sal_Int8> const & getUnoTunnelId(); + protected: FormulaImExportBase(); diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index d5b02455ab35..7c2920eabcbf 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -56,6 +56,7 @@ #include <comphelper/propertysequence.hxx> #include <comphelper/propertyvalue.hxx> #include <comphelper/sequence.hxx> +#include <comphelper/servicehelper.hxx> #include <comphelper/diagnose_ex.hxx> #include <tools/gen.hxx> #include <tools/globname.hxx> @@ -1295,7 +1296,7 @@ Reference< XShape > const & Shape::createAndInsert( { uno::Reference<uno::XInterface> const xMathModel(xObj->getComponent()); oox::FormulaImExportBase *const pMagic( - dynamic_cast<oox::FormulaImExportBase*>(xMathModel.get())); + comphelper::getFromUnoTunnel<oox::FormulaImExportBase>(xMathModel)); assert(pMagic); pMagic->readFormulaOoxml(*pMathXml); } diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx index 137c69fe7c33..ce3787069adb 100644 --- a/oox/source/export/shapes.cxx +++ b/oox/source/export/shapes.cxx @@ -71,6 +71,7 @@ #include <tools/globname.hxx> #include <comphelper/classids.hxx> #include <comphelper/propertysequence.hxx> +#include <comphelper/servicehelper.hxx> #include <comphelper/storagehelper.hxx> #include <sot/exchange.hxx> #include <utility> @@ -2473,7 +2474,7 @@ void ShapeExport::WriteMathShape(Reference<XShape> const& xShape) mpFS->startElementNS(XML_a14, XML_m); oox::FormulaImExportBase *const pMagic( - dynamic_cast<oox::FormulaImExportBase*>(xMathModel.get())); + comphelper::getFromUnoTunnel<oox::FormulaImExportBase>(xMathModel)); assert(pMagic); pMagic->writeFormulaOoxml(GetFS(), GetFB()->getVersion(), GetDocumentType(), FormulaImExportBase::eFormulaAlign::INLINE); diff --git a/oox/source/mathml/imexport.cxx b/oox/source/mathml/imexport.cxx index 2b5990679bea..ad0389051b42 100644 --- a/oox/source/mathml/imexport.cxx +++ b/oox/source/mathml/imexport.cxx @@ -13,6 +13,7 @@ #include <oox/core/contexthandler.hxx> #include <oox/token/namespaces.hxx> +#include <comphelper/servicehelper.hxx> #include <drawingml/textparagraph.hxx> @@ -21,6 +22,15 @@ using namespace ::com::sun::star; namespace oox { +sal_Int64 FormulaImExportBase::getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) { + return comphelper::getSomethingImpl(aIdentifier, this); +} + +css::uno::Sequence<sal_Int8> const & FormulaImExportBase::getUnoTunnelId() { + static comphelper::UnoIdInit const id; + return id.getSeq(); +} + FormulaImExportBase::FormulaImExportBase() { } diff --git a/starmath/source/unomodel.cxx b/starmath/source/unomodel.cxx index b7a92567fe25..a4b14671b63d 100644 --- a/starmath/source/unomodel.cxx +++ b/starmath/source/unomodel.cxx @@ -361,6 +361,7 @@ const uno::Sequence< sal_Int8 > & SmModel::getUnoTunnelId() sal_Int64 SAL_CALL SmModel::getSomething( const uno::Sequence< sal_Int8 >& rId ) { return comphelper::getSomethingImpl(rId, this, + comphelper::MixinToGetSomethingOf<FormulaImExportBase>{}, comphelper::FallbackToGetSomethingOf<SfxBaseModel>{}); } diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index fac7d3aa42c4..3e4bca89472d 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -45,6 +45,7 @@ #include <comphelper/string.hxx> #include <comphelper/flagguard.hxx> #include <comphelper/sequence.hxx> +#include <comphelper/servicehelper.hxx> #include <oox/token/namespaces.hxx> #include <oox/token/tokens.hxx> #include <oox/export/utils.hxx> @@ -5985,7 +5986,7 @@ void DocxAttributeOutput::WritePostponedMath(const SwOLENode* pPostponedMath, sa SAL_WARN("sw.ww8", "Broken math object"); return; } - if( oox::FormulaImExportBase* formulaexport = dynamic_cast< oox::FormulaImExportBase* >( xInterface.get())) + if( oox::FormulaImExportBase* formulaexport = comphelper::getFromUnoTunnel< oox::FormulaImExportBase >( xInterface)) formulaexport->writeFormulaOoxml( m_pSerializer, GetExport().GetFilter().getVersion(), oox::drawingml::DOCUMENT_DOCX, nAlign); else diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx index 8131b981c0e8..6f777b148407 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.cxx +++ b/sw/source/filter/ww8/rtfattributeoutput.cxx @@ -24,6 +24,7 @@ #include "writerwordglue.hxx" #include "ww8par.hxx" #include <fmtcntnt.hxx> +#include <comphelper/servicehelper.hxx> #include <rtl/tencinfo.h> #include <sal/log.hxx> #include <sot/exchange.hxx> @@ -4187,7 +4188,7 @@ bool RtfAttributeOutput::FlyFrameOLEMath(const SwFlyFrameFormat* pFlyFrameFormat uno::Reference<util::XCloseable> xClosable = xObj->getComponent(); if (!xClosable.is()) return false; - auto pBase = dynamic_cast<oox::FormulaImExportBase*>(xClosable.get()); + auto pBase = comphelper::getFromUnoTunnel<oox::FormulaImExportBase>(xClosable); SAL_WARN_IF(!pBase, "sw.rtf", "Math OLE object cannot write out RTF"); if (pBase) { diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 09b1ba422aec..fe7374848d72 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -82,6 +82,7 @@ #include <com/sun/star/document/XImporter.hpp> #include <com/sun/star/document/XFilter.hpp> #include <comphelper/indexedpropertyvalues.hxx> +#include <comphelper/servicehelper.hxx> #include <editeng/flditem.hxx> #include <editeng/unotext.hxx> #include <o3tl/safeint.hxx> @@ -3011,7 +3012,7 @@ void DomainMapper_Impl::appendStarMath( const Value& val ) xComponentProperties->setPropertyValue(getPropertyName( PROP_BOTTOM_MARGIN ), uno::Any(sal_Int32(0))); Size size( 1000, 1000 ); - if( oox::FormulaImExportBase* formulaimport = dynamic_cast< oox::FormulaImExportBase* >( xInterface.get())) + if( oox::FormulaImExportBase* formulaimport = comphelper::getFromUnoTunnel< oox::FormulaImExportBase >( xInterface)) size = formulaimport->getFormulaSize(); xStarMathProperties->setPropertyValue(getPropertyName( PROP_WIDTH ), uno::Any( sal_Int32(size.Width()))); diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index 2563956bf97a..32e0aa403867 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -28,6 +28,7 @@ #include <sal/log.hxx> #include <comphelper/embeddedobjectcontainer.hxx> #include <comphelper/propertyvalue.hxx> +#include <comphelper/servicehelper.hxx> #include <cppuhelper/exc_hlp.hxx> #include <tools/globname.hxx> #include <comphelper/classids.hxx> @@ -2283,7 +2284,7 @@ void OOXMLFastContextHandlerMath::process() return; uno::Reference< uno::XInterface > component(ref->getComponent(), uno::UNO_QUERY_THROW); if( oox::FormulaImExportBase* import - = dynamic_cast< oox::FormulaImExportBase* >( component.get())) + = comphelper::getFromUnoTunnel< oox::FormulaImExportBase >( component)) import->readFormulaOoxml( buffer ); if (!isForwardEvents()) return; diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index ac5bbfb042f2..c61721ff484e 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -26,6 +26,7 @@ #include <filter/msfilter/rtfutil.hxx> #include <comphelper/string.hxx> #include <comphelper/diagnose_ex.hxx> +#include <comphelper/servicehelper.hxx> #include <tools/globname.hxx> #include <tools/datetimeutils.hxx> #include <comphelper/classids.hxx> @@ -2968,7 +2969,7 @@ RTFError RTFDocumentImpl::beforePopState(RTFParserState& rState) uno::Reference<util::XCloseable> xComponent(xObject->getComponent(), uno::UNO_SET_THROW); if (oox::FormulaImExportBase* pImport - = dynamic_cast<oox::FormulaImExportBase*>(xComponent.get())) + = comphelper::getFromUnoTunnel<oox::FormulaImExportBase>(xComponent)) pImport->readFormulaOoxml(m_aMathBuffer); auto pValue = new RTFValue(xObject);