diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-03-05 16:06:57 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-03-06 12:34:10 +0100 |
commit | cba736567a713fffe030d0eb76c36d0cbb83eaa0 (patch) | |
tree | 16ceb916df51d6448901ae0f6fb94e751e077d5b /sw | |
parent | 06d8c1e9d8ba1d04914d1c48c94732cdb5c68846 (diff) |
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.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/Library_swui.mk | 3 | ||||
-rw-r--r-- | sw/qa/unit/sw-dialogs-test.cxx | 17 | ||||
-rw-r--r-- | sw/qa/unit/sw-dialogs-test_2.cxx | 18 | ||||
-rw-r--r-- | sw/source/ui/dialog/swuiexp.cxx | 41 | ||||
-rw-r--r-- | sw/source/uibase/dialog/swabstdlg.cxx | 37 | ||||
-rw-r--r-- | sw/util/swui.component | 25 |
6 files changed, 87 insertions, 54 deletions
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> |