offapi/UnoApi_offapi.mk                           |    1 
 offapi/com/sun/star/text/DialogFactoryService.idl |   38 ++++++++++++++++++++
 sw/Library_swui.mk                                |    3 +
 sw/qa/unit/sw-dialogs-test.cxx                    |   17 +++------
 sw/qa/unit/sw-dialogs-test_2.cxx                  |   18 +++------
 sw/source/ui/dialog/swuiexp.cxx                   |   41 ++++++++++++++++++++--
 sw/source/uibase/dialog/swabstdlg.cxx             |   37 ++++---------------
 sw/util/swui.component                            |   25 +++++++++++++
 vcl/workben/docxfuzzer.cxx                        |    5 --
 vcl/workben/fodt2pdffuzzer.cxx                    |    2 -
 vcl/workben/fodtfuzzer.cxx                        |    5 --
 vcl/workben/htmlfuzzer.cxx                        |    2 -
 vcl/workben/rtffuzzer.cxx                         |    5 --
 vcl/workben/ww2fuzzer.cxx                         |    5 --
 vcl/workben/ww6fuzzer.cxx                         |    5 --
 vcl/workben/ww8fuzzer.cxx                         |    5 --
 16 files changed, 126 insertions(+), 88 deletions(-)

New commits:
commit cba736567a713fffe030d0eb76c36d0cbb83eaa0
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Mar 5 16:06:57 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Mar 6 12:34:10 2024 +0100

    Create an UNO service to do the symbol lookup in sw
    
    which means I can remove one usage of gb_Library_set_plugin_for, which
    is blocking linking the sw module into --enable-mergelibs=more
    
    Change-Id: I8c199421c66de2dcf339ccc2d5cb9340d3bea914
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164429
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index 7687ee9fd06d..0ef13a1f7372 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -3746,6 +3746,7 @@ $(eval $(call 
gb_UnoApi_add_idlfiles,offapi,com/sun/star/text,\
        ColumnSeparatorStyle \
        ControlCharacter \
        DateDisplayFormat \
+       DialogFactoryService \
        DocumentStatistic \
        FilenameDisplayFormat \
        FontEmphasis \
diff --git a/offapi/com/sun/star/text/DialogFactoryService.idl 
b/offapi/com/sun/star/text/DialogFactoryService.idl
new file mode 100644
index 000000000000..060dc7eeef2e
--- /dev/null
+++ b/offapi/com/sun/star/text/DialogFactoryService.idl
@@ -0,0 +1,38 @@
+/* -*- 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 .
+ */
+
+module com { module sun { module star { module text {
+
+/**
+  The sw module uses this to get a pointer to the  from the swui module.
+  Because we have a dependency in our modules that goes the "wrong" way.
+
+  @since LibreOffice 24.8
+
+  @internal
+
+  ATTENTION: This is marked <em>internal</em> and does not
+  have the <em>published</em> flag, which means it is subject to
+  change without notice and should not be used outside the LibreOffice core.
+*/
+service DialogFactoryService : com::sun::star::lang::XUnoTunnel;
+
+}; }; }; };
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/Library_swui.mk b/sw/Library_swui.mk
index 3a56419f7327..2c6d8512fe44 100644
--- a/sw/Library_swui.mk
+++ b/sw/Library_swui.mk
@@ -19,7 +19,7 @@
 
 $(eval $(call gb_Library_Library,swui))
 
-$(eval $(call gb_Library_set_plugin_for,swui,sw))
+$(eval $(call gb_Library_set_componentfile,swui,sw/util/swui,services))
 
 $(eval $(call gb_Library_set_include,swui,\
     -I$(SRCDIR)/sw/inc \
@@ -72,6 +72,7 @@ $(eval $(call gb_Library_use_libraries,swui,\
     svx \
     svx \
     svxcore \
+       sw \
     tk \
     tl \
     ucbhelper \
diff --git a/sw/qa/unit/sw-dialogs-test.cxx b/sw/qa/unit/sw-dialogs-test.cxx
index 48652ca1db74..0e9bd50db309 100644
--- a/sw/qa/unit/sw-dialogs-test.cxx
+++ b/sw/qa/unit/sw-dialogs-test.cxx
@@ -13,6 +13,8 @@
 #include <osl/module.hxx>
 #include <tools/svlibrary.h>
 #include <vcl/abstdlg.hxx>
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/text/DialogFactoryService.hpp>
 
 class SwAbstractDialogFactory;
 
@@ -62,16 +64,11 @@ void SwDialogsTest::setUp()
     component_ = loadFromDesktop(
         "private:factory/swriter", "com.sun.star.text.TextDocument");
     // Make sure the swui library's global pSwResMgr is initialized
-    // (alternatively to dynamically loading the library, SwCreateDialogFactory
-    // could be declared in an include file and this CppunitTest link against
-    // the swui library):
-    OUString url("${LO_LIB_DIR}/" SVLIBRARY("swui"));
-    rtl::Bootstrap::expandMacros(url); //TODO: detect failure
-    CPPUNIT_ASSERT(libSwui_.load(url, SAL_LOADMODULE_GLOBAL));
-    auto fn = reinterpret_cast<Fn>(
-        libSwui_.getFunctionSymbol("SwCreateDialogFactory"));
-    CPPUNIT_ASSERT(fn != nullptr);
-    (*fn)();
+    auto xService = 
css::text::DialogFactoryService::create(comphelper::getProcessComponentContext());
+    CPPUNIT_ASSERT(xService.is());
+    // get a factory instance
+    SwAbstractDialogFactory* pFactory = 
reinterpret_cast<SwAbstractDialogFactory*>(xService->getSomething({}));
+    CPPUNIT_ASSERT(pFactory != nullptr);
 }
 
 void SwDialogsTest::tearDown()
diff --git a/sw/qa/unit/sw-dialogs-test_2.cxx b/sw/qa/unit/sw-dialogs-test_2.cxx
index 42e8d4b786da..e0de86d276d3 100644
--- a/sw/qa/unit/sw-dialogs-test_2.cxx
+++ b/sw/qa/unit/sw-dialogs-test_2.cxx
@@ -13,7 +13,8 @@
 #include <osl/module.hxx>
 #include <tools/svlibrary.h>
 #include <vcl/abstdlg.hxx>
-
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/text/DialogFactoryService.hpp>
 #include <swdll.hxx>
 
 class SwAbstractDialogFactory;
@@ -59,16 +60,11 @@ void SwDialogsTest2::setUp()
     ScreenshotTest::setUp();
     SwGlobals::ensure();
     // Make sure the swui library's global pSwResMgr is initialized
-    // (alternatively to dynamically loading the library, SwCreateDialogFactory
-    // could be declared in an include file and this CppunitTest link against
-    // the swui library):
-    OUString url("${LO_LIB_DIR}/" SVLIBRARY("swui"));
-    rtl::Bootstrap::expandMacros(url); //TODO: detect failure
-    CPPUNIT_ASSERT(libSwui_.load(url, SAL_LOADMODULE_GLOBAL));
-    auto fn = reinterpret_cast<Fn>(
-        libSwui_.getFunctionSymbol("SwCreateDialogFactory"));
-    CPPUNIT_ASSERT(fn != nullptr);
-    (*fn)();
+    auto xService = 
css::text::DialogFactoryService::create(comphelper::getProcessComponentContext());
+    CPPUNIT_ASSERT(xService.is());
+    // get a factory instance
+    SwAbstractDialogFactory* pFactory = 
reinterpret_cast<SwAbstractDialogFactory*>(xService->getSomething({}));
+    CPPUNIT_ASSERT(pFactory != nullptr);
 }
 
 void SwDialogsTest2::registerKnownDialogsByID(mapType& /*rKnownDialogs*/)
diff --git a/sw/source/ui/dialog/swuiexp.cxx b/sw/source/ui/dialog/swuiexp.cxx
index e141dab80d0d..7f2912414b6d 100644
--- a/sw/source/ui/dialog/swuiexp.cxx
+++ b/sw/source/ui/dialog/swuiexp.cxx
@@ -18,8 +18,9 @@
  */
 
 #include "swdlgfact.hxx"
-
 #include <swuiexp.hxx>
+#include <cppuhelper/supportsservice.hxx>
+#include <com/sun/star/lang/XUnoTunnel.hpp>
 
 namespace swui
 {
@@ -30,10 +31,44 @@ SwAbstractDialogFactory& GetFactory()
 }
 }
 
+/// anonymous implementation namespace
+namespace
+{
+class DialogFactoryService
+    : public ::cppu::WeakImplHelper<css::lang::XServiceInfo, 
css::lang::XUnoTunnel>
+{
+public:
+    // css::lang::XServiceInfo:
+    virtual OUString SAL_CALL getImplementationName() override
+    {
+        return "com.sun.star.text.comp.DialogFactoryService";
+    }
+    virtual sal_Bool SAL_CALL supportsService(const OUString& serviceName) 
override
+    {
+        return cppu::supportsService(this, serviceName);
+    }
+    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() 
override
+    {
+        return { "com.sun.star.text.DialogFactoryService" };
+    }
+
+    // XUnoTunnel
+    virtual sal_Int64 SAL_CALL
+    getSomething(const ::css::uno::Sequence<::sal_Int8>& /*aIdentifier*/) 
override
+    {
+        SwAbstractDialogFactory* pFactory = &::swui::GetFactory();
+        return reinterpret_cast<sal_Int64>(pFactory);
+    }
+};
+
+} // closing anonymous implementation namespace
+
 extern "C" {
-SAL_DLLPUBLIC_EXPORT SwAbstractDialogFactory* SwCreateDialogFactory()
+SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+com_sun_star_text_DialogFactoryService_get_implementation(css::uno::XComponentContext*,
+                                                          
css::uno::Sequence<css::uno::Any> const&)
 {
-    return &::swui::GetFactory();
+    return cppu::acquire(new DialogFactoryService);
 }
 }
 
diff --git a/sw/source/uibase/dialog/swabstdlg.cxx 
b/sw/source/uibase/dialog/swabstdlg.cxx
index d5651d731cd4..fffc1a6c2a6f 100644
--- a/sw/source/uibase/dialog/swabstdlg.cxx
+++ b/sw/source/uibase/dialog/swabstdlg.cxx
@@ -18,38 +18,17 @@
  */
 
 #include <swabstdlg.hxx>
-
-#include <osl/module.hxx>
-
-typedef SwAbstractDialogFactory* (*SwFuncPtrCreateDialogFactory)();
-
-#ifndef DISABLE_DYNLOADING
-
-extern "C" { static void thisModule() {} }
-
-#else
-
-extern "C" SwAbstractDialogFactory* SwCreateDialogFactory();
-
-#endif
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/text/DialogFactoryService.hpp>
 
 SwAbstractDialogFactory* SwAbstractDialogFactory::Create()
 {
-    SwFuncPtrCreateDialogFactory fp = nullptr;
-#ifndef DISABLE_DYNLOADING
-    static ::osl::Module aDialogLibrary;
-    static constexpr OUStringLiteral sLibName(u"" SWUI_DLL_NAME);
-    if ( aDialogLibrary.is() || aDialogLibrary.loadRelative( &thisModule, 
sLibName,
-                                                             
SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_LAZY ) )
-        fp = reinterpret_cast<SwAbstractDialogFactory* (SAL_CALL*)()>(
-            aDialogLibrary.getFunctionSymbol( "SwCreateDialogFactory" ));
-#else
-    fp = SwCreateDialogFactory;
-#endif
-
-    if ( fp )
-        return fp();
-    return nullptr;
+    auto xService = 
css::text::DialogFactoryService::create(comphelper::getProcessComponentContext());
+    assert(xService);
+    // get a factory instance
+    SwAbstractDialogFactory* pFactory = 
reinterpret_cast<SwAbstractDialogFactory*>(xService->getSomething({}));
+    assert(pFactory);
+    return pFactory;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/util/swui.component b/sw/util/swui.component
new file mode 100644
index 000000000000..215b49a4dbb1
--- /dev/null
+++ b/sw/util/swui.component
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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 .
+ -->
+<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
+    xmlns="http://openoffice.org/2010/uno-components";>
+    <implementation name="com.sun.star.text.comp.DialogFactoryService"
+        
constructor="com_sun_star_text_DialogFactoryService_get_implementation">
+        <service name="com.sun.star.text.DialogFactoryService"/>
+    </implementation>
+</component>
diff --git a/vcl/workben/docxfuzzer.cxx b/vcl/workben/docxfuzzer.cxx
index 73fc198bd886..b7739d788414 100644
--- a/vcl/workben/docxfuzzer.cxx
+++ b/vcl/workben/docxfuzzer.cxx
@@ -11,11 +11,6 @@
 #include <vcl/FilterConfigItem.hxx>
 #include "commonfuzzer.hxx"
 
-extern "C" void* SwCreateDialogFactory()
-{
-    return nullptr;
-}
-
 extern "C" bool TestImportDOCX(SvStream &rStream);
 
 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
diff --git a/vcl/workben/fodt2pdffuzzer.cxx b/vcl/workben/fodt2pdffuzzer.cxx
index 91e04966c1ff..27fa83cb7203 100644
--- a/vcl/workben/fodt2pdffuzzer.cxx
+++ b/vcl/workben/fodt2pdffuzzer.cxx
@@ -15,8 +15,6 @@
 #include <libxml/parser.h>
 #include "commonfuzzer.hxx"
 
-extern "C" void* SwCreateDialogFactory() { return nullptr; }
-
 extern "C" bool TestPDFExportFODT(SvStream& rStream);
 
 static void silent_error_func(void*, const char* /*format*/, ...) {}
diff --git a/vcl/workben/fodtfuzzer.cxx b/vcl/workben/fodtfuzzer.cxx
index 71c37aa7c42d..0e95b59e979d 100644
--- a/vcl/workben/fodtfuzzer.cxx
+++ b/vcl/workben/fodtfuzzer.cxx
@@ -11,11 +11,6 @@
 #include <vcl/FilterConfigItem.hxx>
 #include "commonfuzzer.hxx"
 
-extern "C" void* SwCreateDialogFactory()
-{
-    return nullptr;
-}
-
 extern "C" bool TestImportFODT(SvStream &rStream);
 
 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
diff --git a/vcl/workben/htmlfuzzer.cxx b/vcl/workben/htmlfuzzer.cxx
index b2e89442088b..093f368b05fd 100644
--- a/vcl/workben/htmlfuzzer.cxx
+++ b/vcl/workben/htmlfuzzer.cxx
@@ -11,8 +11,6 @@
 #include <vcl/FilterConfigItem.hxx>
 #include "commonfuzzer.hxx"
 
-extern "C" void* SwCreateDialogFactory() { return nullptr; }
-
 extern "C" bool TestImportHTML(SvStream& rStream);
 
 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
diff --git a/vcl/workben/rtffuzzer.cxx b/vcl/workben/rtffuzzer.cxx
index cd68a84eda6c..34031a8e3f55 100644
--- a/vcl/workben/rtffuzzer.cxx
+++ b/vcl/workben/rtffuzzer.cxx
@@ -67,11 +67,6 @@ extern "C" void* lo_get_custom_widget_func(const char*)
     return nullptr;
 }
 
-extern "C" void* SwCreateDialogFactory()
-{
-    return nullptr;
-}
-
 extern "C" bool TestImportRTF(SvStream &rStream);
 
 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
diff --git a/vcl/workben/ww2fuzzer.cxx b/vcl/workben/ww2fuzzer.cxx
index 5ffe0445c3fb..2578b2ca855a 100644
--- a/vcl/workben/ww2fuzzer.cxx
+++ b/vcl/workben/ww2fuzzer.cxx
@@ -107,11 +107,6 @@ extern "C" void* lo_get_custom_widget_func(const char*)
     return nullptr;
 }
 
-extern "C" void* SwCreateDialogFactory()
-{
-    return nullptr;
-}
-
 extern "C" bool TestImportWW2(SvStream &rStream);
 
 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
diff --git a/vcl/workben/ww6fuzzer.cxx b/vcl/workben/ww6fuzzer.cxx
index a17be9105a06..3ce6e8ed58bc 100644
--- a/vcl/workben/ww6fuzzer.cxx
+++ b/vcl/workben/ww6fuzzer.cxx
@@ -109,11 +109,6 @@ extern "C" void* lo_get_custom_widget_func(const char*)
     return nullptr;
 }
 
-extern "C" void* SwCreateDialogFactory()
-{
-    return nullptr;
-}
-
 extern "C" bool TestImportWW6(SvStream &rStream);
 
 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
diff --git a/vcl/workben/ww8fuzzer.cxx b/vcl/workben/ww8fuzzer.cxx
index 113e798610f3..61737aa46ab2 100644
--- a/vcl/workben/ww8fuzzer.cxx
+++ b/vcl/workben/ww8fuzzer.cxx
@@ -109,11 +109,6 @@ extern "C" void* lo_get_custom_widget_func(const char*)
     return nullptr;
 }
 
-extern "C" void* SwCreateDialogFactory()
-{
-    return nullptr;
-}
-
 extern "C" bool TestImportWW8(SvStream &rStream);
 
 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)

Reply via email to