include/xmloff/settingsstore.hxx            |   12 ++++++++++--
 sd/Library_sd.mk                            |    1 +
 sd/source/ui/unoidl/UnoDocumentSettings.cxx |   13 +++++++------
 xmloff/Library_xo.mk                        |    1 +
 xmloff/source/draw/sdxmlexp.cxx             |    4 +++-
 xmloff/source/draw/sdxmlimp.cxx             |    3 ++-
 xmloff/source/draw/settingsstore.cxx        |   28 ++++++++++++++++++++++++++++
 7 files changed, 52 insertions(+), 10 deletions(-)

New commits:
commit f481f036deb1b1b46f3038074c4659f3a91b9c6c
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Thu Dec 8 11:10:50 2022 +0100
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Thu Dec 22 14:19:22 2022 +0000

    loplugin:unocast (DocumentSettingsSerializer)
    
    (See the upcoming commit introducing that loplugin:unocast on why such
    dynamic_casts from UNO types are dangerous.)
    
    Change-Id: I803f62085264511976ed9bb0744ee301de2a7dab
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144754
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/include/xmloff/settingsstore.hxx b/include/xmloff/settingsstore.hxx
index 339e71bbd1a7..8f83a8a0e20a 100644
--- a/include/xmloff/settingsstore.hxx
+++ b/include/xmloff/settingsstore.hxx
@@ -12,7 +12,10 @@
 #ifndef INCLUDED_XMLOFF_SETTINGSSTORE_HXX
 #define INCLUDED_XMLOFF_SETTINGSSTORE_HXX
 
+#include <com/sun/star/lang/XUnoTunnel.hpp>
 #include <com/sun/star/uno/Sequence.hxx>
+#include <cppuhelper/implbase.hxx>
+#include <xmloff/dllapi.h>
 
 namespace com::sun::star::beans { struct PropertyValue; }
 namespace com::sun::star::embed { class XStorage; }
@@ -20,7 +23,9 @@ namespace com::sun::star::uno { template <typename > class 
Reference; }
 
 // Scans list of properties for certain URL properties that could refer
 // to internal objects, and initializes from these.
-class SAL_DLLPUBLIC_RTTI SAL_LOPLUGIN_ANNOTATE("crosscast") 
DocumentSettingsSerializer {
+class XMLOFF_DLLPUBLIC DocumentSettingsSerializer:
+    public cppu::WeakImplHelper<css::lang::XUnoTunnel>
+{
 public:
   // Import objects and update properties (eliding URLs)
   virtual css::uno::Sequence<css::beans::PropertyValue>
@@ -34,8 +39,11 @@ public:
         const css::uno::Reference< css::embed::XStorage > &xStorage,
         const css::uno::Sequence<css::beans::PropertyValue>& aConfigProps ) = 
0;
 
+    sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & 
aIdentifier) override;
+    static css::uno::Sequence<sal_Int8> const & getUnoTunnelId();
+
 protected:
-    ~DocumentSettingsSerializer() {}
+    ~DocumentSettingsSerializer() override;
 };
 
 #endif // INCLUDED_XMLOFF_SETTINGSSTORE_HXX
diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk
index 1a3a87174098..2b907d35bbff 100644
--- a/sd/Library_sd.mk
+++ b/sd/Library_sd.mk
@@ -97,6 +97,7 @@ $(eval $(call gb_Library_use_libraries,sd,\
        ucbhelper \
        utl \
        vcl \
+       xo \
        $(if $(ENABLE_NSS),xmlsecurity) \
 ))
 
diff --git a/sd/source/ui/unoidl/UnoDocumentSettings.cxx 
b/sd/source/ui/unoidl/UnoDocumentSettings.cxx
index 331f90b53a50..b4b4baf74ce8 100644
--- a/sd/source/ui/unoidl/UnoDocumentSettings.cxx
+++ b/sd/source/ui/unoidl/UnoDocumentSettings.cxx
@@ -69,9 +69,10 @@ namespace sd
 {
     namespace {
 
-    class DocumentSettings : public WeakImplHelper< XPropertySet, 
XMultiPropertySet, XServiceInfo >,
-                             public comphelper::PropertySetHelper,
-                             public DocumentSettingsSerializer
+    class DocumentSettings : public ImplInheritanceHelper<
+                                 DocumentSettingsSerializer, XPropertySet, 
XMultiPropertySet,
+                                 XServiceInfo >,
+                             public comphelper::PropertySetHelper
     {
     public:
         explicit DocumentSettings( SdXImpressDocument* pModel );
@@ -1336,17 +1337,17 @@ DocumentSettings::_getPropertyValues(
 // XInterface
 Any SAL_CALL DocumentSettings::queryInterface( const Type& aType )
 {
-    return WeakImplHelper< XPropertySet, XMultiPropertySet, XServiceInfo 
>::queryInterface( aType );
+    return ImplInheritanceHelper::queryInterface( aType );
 }
 
 void SAL_CALL DocumentSettings::acquire(  ) noexcept
 {
-    WeakImplHelper< XPropertySet, XMultiPropertySet, XServiceInfo >::acquire();
+    ImplInheritanceHelper::acquire();
 }
 
 void SAL_CALL DocumentSettings::release(  ) noexcept
 {
-    WeakImplHelper< XPropertySet, XMultiPropertySet, XServiceInfo >::release();
+    ImplInheritanceHelper::release();
 }
 
 // XPropertySet
diff --git a/xmloff/Library_xo.mk b/xmloff/Library_xo.mk
index 14401f9eea8f..4450b0031c26 100644
--- a/xmloff/Library_xo.mk
+++ b/xmloff/Library_xo.mk
@@ -154,6 +154,7 @@ $(eval $(call gb_Library_add_exception_objects,xo,\
     xmloff/source/draw/sdpropls \
     xmloff/source/draw/sdxmlexp \
     xmloff/source/draw/sdxmlimp \
+    xmloff/source/draw/settingsstore \
     xmloff/source/draw/shapeexport \
     xmloff/source/draw/shapeimport \
     xmloff/source/draw/SignatureLineContext \
diff --git a/xmloff/source/draw/sdxmlexp.cxx b/xmloff/source/draw/sdxmlexp.cxx
index 7c336989496b..ac6719868b85 100644
--- a/xmloff/source/draw/sdxmlexp.cxx
+++ b/xmloff/source/draw/sdxmlexp.cxx
@@ -52,6 +52,7 @@
 #include <rtl/ustrbuf.hxx>
 #include <sal/log.hxx>
 #include <comphelper/diagnose_ex.hxx>
+#include <comphelper/servicehelper.hxx>
 #include <tools/gen.hxx>
 #include <sax/tools/converter.hxx>
 #include <xmloff/xmlaustp.hxx>
@@ -2473,7 +2474,8 @@ void 
SdXMLExport::GetConfigurationSettings(uno::Sequence<beans::PropertyValue>&
     Reference< beans::XPropertySet > xProps( 
xFac->createInstance("com.sun.star.document.Settings"), UNO_QUERY );
     if( xProps.is() )
         SvXMLUnitConverter::convertPropertySet( rProps, xProps );
-    DocumentSettingsSerializer 
*pFilter(dynamic_cast<DocumentSettingsSerializer *>(xProps.get()));
+    DocumentSettingsSerializer *pFilter(
+        comphelper::getFromUnoTunnel<DocumentSettingsSerializer>(xProps));
     if (!pFilter)
         return;
     const uno::Reference< embed::XStorage > xStorage(GetTargetStorage());
diff --git a/xmloff/source/draw/sdxmlimp.cxx b/xmloff/source/draw/sdxmlimp.cxx
index 6e556ac84a31..dbdb910775b1 100644
--- a/xmloff/source/draw/sdxmlimp.cxx
+++ b/xmloff/source/draw/sdxmlimp.cxx
@@ -21,6 +21,7 @@
 #include <sal/log.hxx>
 #include <comphelper/processfactory.hxx>
 #include <comphelper/sequence.hxx>
+#include <comphelper/servicehelper.hxx>
 
 #include <xmloff/xmlscripti.hxx>
 #include "sdxmlimp_impl.hxx"
@@ -552,7 +553,7 @@ void SdXMLImport::SetConfigurationSettings(const 
css::uno::Sequence<css::beans::
     const uno::Sequence<beans::PropertyValue>* pValues = &aConfigProps;
 
     DocumentSettingsSerializer *pFilter;
-    pFilter = dynamic_cast<DocumentSettingsSerializer *>(xProps.get());
+    pFilter = comphelper::getFromUnoTunnel<DocumentSettingsSerializer>(xProps);
     uno::Sequence<beans::PropertyValue> aFiltered;
     if( pFilter )
     {
diff --git a/xmloff/source/draw/settingsstore.cxx 
b/xmloff/source/draw/settingsstore.cxx
new file mode 100644
index 000000000000..0b41473ea211
--- /dev/null
+++ b/xmloff/source/draw/settingsstore.cxx
@@ -0,0 +1,28 @@
+/* -*- 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 <sal/config.h>
+
+#include <comphelper/servicehelper.hxx>
+#include <xmloff/settingsstore.hxx>
+
+sal_Int64 
DocumentSettingsSerializer::getSomething(css::uno::Sequence<sal_Int8> const& 
aIdentifier)
+{
+    return comphelper::getSomethingImpl(aIdentifier, this);
+}
+
+css::uno::Sequence<sal_Int8> const& 
DocumentSettingsSerializer::getUnoTunnelId()
+{
+    static comphelper::UnoIdInit const id;
+    return id.getSeq();
+}
+
+DocumentSettingsSerializer::~DocumentSettingsSerializer() {}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to