[Libreoffice-commits] core.git: include/sfx2 sfx2/source solenv/bin starmath/Library_sm.mk starmath/source starmath/util

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Sun Jul 26 08:42:28 UTC 2020


 include/sfx2/sfxmodelfactory.hxx    |   12 ++++++
 sfx2/source/doc/sfxmodelfactory.cxx |   28 +++++++++++++-
 solenv/bin/native-code.py           |   13 ++++++
 starmath/Library_sm.mk              |    1 
 starmath/source/register.cxx        |   72 ------------------------------------
 starmath/source/register.hxx        |   37 ------------------
 starmath/source/unodoc.cxx          |   26 +++++--------
 starmath/util/sm.component          |    5 +-
 8 files changed, 64 insertions(+), 130 deletions(-)

New commits:
commit 8a05c64a5bbf9b6ad7af8e94e7b970f1323a22c5
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Sat Jul 25 18:19:20 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Jul 26 10:41:52 2020 +0200

    starmath: create instances with uno constructors
    
    See tdf#74608 for motivation.
    
    And adjust the sfx2 model factory code to cope with UNO
    constructor functions.
    
    Change-Id: I7e57fb3136ad0b3caadd511ea63cf98d3c03ab3d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99446
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/sfx2/sfxmodelfactory.hxx b/include/sfx2/sfxmodelfactory.hxx
index 1010fc0e3453..1096eca788b1 100644
--- a/include/sfx2/sfxmodelfactory.hxx
+++ b/include/sfx2/sfxmodelfactory.hxx
@@ -24,10 +24,12 @@
 
 #include <com/sun/star/uno/Reference.hxx>
 #include <o3tl/typed_flags_set.hxx>
+#include <functional>
 
 namespace com::sun::star::lang { class XMultiServiceFactory; }
 namespace com::sun::star::lang { class XSingleServiceFactory; }
 namespace com::sun::star::uno { class XInterface; }
+namespace com::sun::star::uno { class XComponentContext; }
 namespace com::sun::star::uno { template <class E> class Sequence; }
 
 enum class SfxModelFlags
@@ -68,6 +70,16 @@ namespace sfx2
             const css::uno::Sequence< OUString >& _rServiceNames
         );
 
+    /**
+     * Intended to be called from UNO constructor functions
+     * This evaluates certain creation arguments (passed to createInstanceWithArguments)
+     * and passes them to the factory function of the derived class.
+     */
+    css::uno::Reference<css::uno::XInterface>
+        SFX2_DLLPUBLIC createSfxModelInstance(
+            const css::uno::Sequence<css::uno::Any> & rxArgs,
+            std::function<css::uno::Reference<css::uno::XInterface>( SfxModelFlags )> creationFunc
+        );
 
 } // namespace sfx2
 
diff --git a/sfx2/source/doc/sfxmodelfactory.cxx b/sfx2/source/doc/sfxmodelfactory.cxx
index 354df9db5450..fbb1b24382de 100644
--- a/sfx2/source/doc/sfxmodelfactory.cxx
+++ b/sfx2/source/doc/sfxmodelfactory.cxx
@@ -23,6 +23,8 @@
 #include <com/sun/star/beans/NamedValue.hpp>
 #include <com/sun/star/lang/XInitialization.hpp>
 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
 
 #include <comphelper/namedvaluecollection.hxx>
 #include <cppuhelper/implbase.hxx>
@@ -79,6 +81,10 @@ namespace sfx2
         virtual Reference< XInterface > SAL_CALL createInstance(  ) override;
         virtual Reference< XInterface > SAL_CALL createInstanceWithArguments( const Sequence< Any >& aArguments ) override;
 
+        static css::uno::Reference<css::uno::XInterface> create(
+            const css::uno::Sequence<css::uno::Any> & rxArgs,
+            std::function<css::uno::Reference<css::uno::XInterface>(SfxModelFlags)> creationFunc);
+
         // XServiceInfo
         virtual OUString SAL_CALL getImplementationName(  ) override;
         virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
@@ -142,7 +148,18 @@ namespace sfx2
     }
 
 
-    Reference< XInterface > SAL_CALL SfxModelFactory::createInstanceWithArguments( const Sequence< Any >& _rArguments )
+    Reference< XInterface > SAL_CALL SfxModelFactory::createInstanceWithArguments( const Sequence< Any >&  _rArguments )
+    {
+        return create(_rArguments,
+            [&](SfxModelFlags _nCreationFlags)
+            {
+                return m_pComponentFactoryFunc(m_xServiceFactory, _nCreationFlags).get();
+            });
+    }
+
+    css::uno::Reference<css::uno::XInterface> SfxModelFactory::create(
+            const css::uno::Sequence<css::uno::Any> & _rArguments,
+            std::function<css::uno::Reference<css::uno::XInterface>(SfxModelFlags)> creationFunc)
     {
         ::comphelper::NamedValueCollection aArgs( _rArguments );
         const bool bEmbeddedObject = aArgs.getOrDefault( "EmbeddedObject", false );
@@ -154,7 +171,7 @@ namespace sfx2
             |   ( bScriptSupport ? SfxModelFlags::NONE : SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS )
             |   ( bDocRecoverySupport ? SfxModelFlags::NONE : SfxModelFlags::DISABLE_DOCUMENT_RECOVERY );
 
-        Reference< XInterface > xInstance( (*m_pComponentFactoryFunc)( m_xServiceFactory, nCreationFlags ) );
+        Reference< XInterface > xInstance( creationFunc(nCreationFlags ) );
 
         // to mimic the behaviour of the default factory's createInstanceWithArguments, we initialize
         // the object with the given arguments, stripped by the three special ones
@@ -194,6 +211,13 @@ namespace sfx2
         return m_aServiceNames;
     }
 
+    css::uno::Reference<css::uno::XInterface> createSfxModelInstance(
+        const css::uno::Sequence<css::uno::Any> & rxArgs,
+        std::function<css::uno::Reference<css::uno::XInterface>(SfxModelFlags)> creationFunc)
+    {
+        return SfxModelFactory::create(rxArgs, creationFunc);
+    }
+
     Reference< XSingleServiceFactory > createSfxModelFactory( const Reference< XMultiServiceFactory >& _rxServiceFactory,
             const OUString& _rImplementationName, const SfxModelFactoryFunc _pComponentFactoryFunc,
             const Sequence< OUString >& _rServiceNames )
diff --git a/solenv/bin/native-code.py b/solenv/bin/native-code.py
index fe98b0032674..b7176dfd93cd 100755
--- a/solenv/bin/native-code.py
+++ b/solenv/bin/native-code.py
@@ -21,7 +21,6 @@ import xml.etree.ElementTree as ET
 
 core_factory_list = [
     ("libi18npoollo.a", "i18npool_component_getFactory"),
-    ("libsmlo.a", "sm_component_getFactory"),
     ("libucb1.a", "ucb_component_getFactory"),
     ("libvcllo.a", "vcl_component_getFactory"),
     ("libsvtlo.a", "svt_component_getFactory"),
@@ -280,6 +279,18 @@ core_constructor_list = [
     "com_sun_star_comp_uri_UriReferenceFactory_get_implementation",
     "com_sun_star_comp_uri_UriSchemeParser_vndDOTsunDOTstarDOTexpand_get_implementation",
     "com_sun_star_comp_uri_UriSchemeParser_vndDOTsunDOTstarDOTscript_get_implementation",
+# starmath/util/sm.component
+    "Math_FormulaDocument_get_implementation",
+    "Math_XMLContentExporter_get_implementation",
+    "Math_XMLExporter_get_implementation",
+    "Math_XMLImporter_get_implementation",
+    "Math_XMLMetaExporter_get_implementation",
+    "Math_XMLOasisMetaExporter_get_implementation",
+    "Math_XMLOasisMetaImporter_get_implementation",
+    "Math_XMLOasisSettingsExporter_get_implementation",
+    "Math_XMLOasisSettingsImporter_get_implementation",
+    "Math_XMLSettingsExporter_get_implementation",
+    "com_sun_star_comp_Math_MathTypeFilter_get_implementation",
 # svl/source/fsstor/fsstorage.component
     "svl_FSStorageFactory_get_implementation",
 # svtools/util/svt.component
diff --git a/starmath/Library_sm.mk b/starmath/Library_sm.mk
index d4b22f4d6623..33fb7525bba0 100644
--- a/starmath/Library_sm.mk
+++ b/starmath/Library_sm.mk
@@ -84,7 +84,6 @@ $(eval $(call gb_Library_add_exception_objects,sm,\
         starmath/source/rtfexport \
         starmath/source/parse \
         starmath/source/rect \
-        starmath/source/register \
         starmath/source/smdll \
         starmath/source/smmod \
         starmath/source/symbol \
diff --git a/starmath/source/register.cxx b/starmath/source/register.cxx
deleted file mode 100644
index 89f7c2dd325a..000000000000
--- a/starmath/source/register.cxx
+++ /dev/null
@@ -1,72 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * 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/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <rtl/ustring.hxx>
-
-#include <sfx2/sfxmodelfactory.hxx>
-
-#include <com/sun/star/lang/XSingleServiceFactory.hpp>
-
-#include "register.hxx"
-
-using namespace ::com::sun::star;
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::lang;
-
-extern "C" {
-
-SAL_DLLPUBLIC_EXPORT void* sm_component_getFactory( const char* pImplementationName,
-                                     void* pServiceManager,
-                                     void* /*pRegistryKey*/ )
-{
-    // Set default return value for this operation - if it failed.
-    void* pReturn = nullptr ;
-
-    if  (
-            ( pImplementationName   !=  nullptr ) &&
-            ( pServiceManager       !=  nullptr )
-        )
-    {
-        // Define variables which are used in following macros.
-        Reference< XSingleServiceFactory >   xFactory                                                                                                ;
-        Reference< XMultiServiceFactory >    xServiceManager( static_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
-
-        if (SmDocument_getImplementationName().equalsAscii(pImplementationName))
-        {
-            xFactory = ::sfx2::createSfxModelFactory( xServiceManager,
-            SmDocument_getImplementationName(),
-            SmDocument_createInstance,
-            SmDocument_getSupportedServiceNames() );
-        }
-
-        // Factory is valid - service was found.
-        if ( xFactory.is() )
-        {
-            xFactory->acquire();
-            pReturn = xFactory.get();
-        }
-    }
-
-    // Return with result of this operation.
-    return pReturn ;
-}
-} // extern "C"
-
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/register.hxx b/starmath/source/register.hxx
deleted file mode 100644
index be875fbeccb0..000000000000
--- a/starmath/source/register.hxx
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * 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/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#ifndef INCLUDED_STARMATH_SOURCE_REGISTER_HXX
-#define INCLUDED_STARMATH_SOURCE_REGISTER_HXX
-
-#include <sal/config.h>
-#include <sfx2/sfxmodelfactory.hxx>
-
-//Math document
-css::uno::Sequence< OUString >
-        SmDocument_getSupportedServiceNames() throw();
-OUString
-        SmDocument_getImplementationName() throw();
-/// @throws css::uno::Exception
-css::uno::Reference< css::uno::XInterface >
-        SmDocument_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory > & rSMgr, SfxModelFlags _nCreationFlags);
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/unodoc.cxx b/starmath/source/unodoc.cxx
index ac7a364390de..32c9692edd0d 100644
--- a/starmath/source/unodoc.cxx
+++ b/starmath/source/unodoc.cxx
@@ -19,7 +19,6 @@
 
 #include <sfx2/sfxmodelfactory.hxx>
 
-#include "register.hxx"
 #include <smdll.hxx>
 #include <document.hxx>
 #include <com/sun/star/frame/XModel.hpp>
@@ -27,23 +26,20 @@
 
 using namespace ::com::sun::star;
 
-OUString SmDocument_getImplementationName() throw()
-{
-    return "com.sun.star.comp.Math.FormulaDocument";
-}
-
-uno::Sequence< OUString > SmDocument_getSupportedServiceNames() throw()
-{
-    return uno::Sequence<OUString>{ "com.sun.star.formula.FormulaProperties" };
-}
-
-uno::Reference< uno::XInterface > SmDocument_createInstance(
-                const uno::Reference< lang::XMultiServiceFactory > & /*rSMgr*/, SfxModelFlags _nCreationFlags )
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+Math_FormulaDocument_get_implementation(
+    css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const& args)
 {
     SolarMutexGuard aGuard;
     SmGlobals::ensure();
-    SfxObjectShell* pShell = new SmDocShell( _nCreationFlags );
-    return uno::Reference< uno::XInterface >( pShell->GetModel() );
+    css::uno::Reference<css::uno::XInterface> xInterface = sfx2::createSfxModelInstance(args,
+        [&](SfxModelFlags _nCreationFlags)
+        {
+            SfxObjectShell* pShell = new SmDocShell( _nCreationFlags );
+            return pShell->GetModel();
+        });
+    xInterface->acquire();
+    return xInterface.get();
 }
 
 
diff --git a/starmath/util/sm.component b/starmath/util/sm.component
index 775b41100a97..4f354df4acb0 100644
--- a/starmath/util/sm.component
+++ b/starmath/util/sm.component
@@ -18,8 +18,9 @@
  -->
 
 <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
-    prefix="sm" xmlns="http://openoffice.org/2010/uno-components">
-  <implementation name="com.sun.star.comp.Math.FormulaDocument">
+    xmlns="http://openoffice.org/2010/uno-components">
+  <implementation name="com.sun.star.comp.Math.FormulaDocument"
+    constructor="Math_FormulaDocument_get_implementation">
     <service name="com.sun.star.formula.FormulaProperties"/>
   </implementation>
   <implementation name="com.sun.star.comp.Math.XMLContentExporter"


More information about the Libreoffice-commits mailing list