sfx2/Library_sfx.mk                    |    1 
 sfx2/source/appl/app.cxx               |   47 ++------------------------
 sfx2/source/appl/appserv.cxx           |   27 +--------------
 sfx2/source/appl/getbasctlfunction.cxx |   58 +++++++++++++++++++++++++++++++++
 sfx2/source/appl/getbasctlfunction.hxx |   31 +++++++++++++++++
 solenv/clang-format/blacklist          |    1 
 6 files changed, 98 insertions(+), 67 deletions(-)

New commits:
commit f2b3a5d28702b4085adbc30ff1431703928e7798
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Mon Apr 13 16:47:35 2020 +0200
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Mon Apr 13 17:42:44 2020 +0200

    Reuse getBasctlFunction code
    
    Change-Id: I51881c04c071a411855da1629319bfbe735f51ed
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92114
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk
index 0ca31c3d5357..e04cad7e6667 100644
--- a/sfx2/Library_sfx.mk
+++ b/sfx2/Library_sfx.mk
@@ -98,6 +98,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
     sfx2/source/appl/fileobj \
     sfx2/source/appl/flatpak \
     sfx2/source/appl/fwkhelper \
+    sfx2/source/appl/getbasctlfunction \
     sfx2/source/appl/helpdispatch \
     sfx2/source/appl/helpinterceptor \
     sfx2/source/appl/impldde \
diff --git a/sfx2/source/appl/app.cxx b/sfx2/source/appl/app.cxx
index 5bb09cce532b..d9509a4a97c0 100644
--- a/sfx2/source/appl/app.cxx
+++ b/sfx2/source/appl/app.cxx
@@ -18,9 +18,7 @@
  */
 
 #include <config_feature_desktop.h>
-#include <config_options.h>
 #include <sal/log.hxx>
-#include <osl/module.hxx>
 #include <tools/debug.hxx>
 
 #include <sfx2/app.hxx>
@@ -61,6 +59,8 @@
 #include <framework/sfxhelperfunctions.hxx>
 #include <fwkhelper.hxx>
 
+#include "getbasctlfunction.hxx"
+
 using namespace ::com::sun::star;
 
 static SfxApplication* g_pSfxApplication = nullptr;
@@ -372,8 +372,6 @@ void SfxApplication::Invalidate( sal_uInt16 nId )
 typedef long (*basicide_handle_basic_error)(void const *);
 typedef void (*basicide_macro_organizer)(void *, sal_Int16);
 
-extern "C" { static void thisModule() {} }
-
 #else
 
 extern "C" long basicide_handle_basic_error(void const*);
@@ -391,25 +389,7 @@ IMPL_STATIC_LINK( SfxApplication, 
GlobalBasicErrorHdl_Impl, StarBASIC*, pStarBas
 #else
 
 #ifndef DISABLE_DYNLOADING
-    osl::Module aMod;
-    // load basctl module
-    if (!aMod.loadRelative(
-            &thisModule,
-#if ENABLE_MERGELIBS
-            SVLIBRARY("merged")
-#else
-            SVLIBRARY("basctl")
-#endif
-        ))
-    {
-        SAL_WARN("sfx.appl", "cannot load basctl");
-        return false;
-    }
-
-    // get symbol
-    basicide_handle_basic_error pSymbol = 
reinterpret_cast<basicide_handle_basic_error>(aMod.getFunctionSymbol("basicide_handle_basic_error"));
-
-    aMod.release();
+    basicide_handle_basic_error pSymbol = 
reinterpret_cast<basicide_handle_basic_error>(sfx2::getBasctlFunction("basicide_handle_basic_error"));
 
     // call basicide_handle_basic_error in basctl
     bool bRet = pSymbol && pSymbol( pStarBasic );
@@ -495,27 +475,8 @@ void SfxApplication::MacroOrganizer(weld::Window* pParent, 
sal_Int16 nTabId)
 #else
 
 #ifndef DISABLE_DYNLOADING
-    osl::Module aMod;
-    // load basctl module
-    if (!aMod.loadRelative(
-            &thisModule,
-#if ENABLE_MERGELIBS
-            SVLIBRARY("merged")
-#else
-            SVLIBRARY("basctl")
-#endif
-        ))
-    {
-        SAL_WARN("sfx.appl", "cannot load basctl");
-        return;
-    }
-
-    // get symbol
-    basicide_macro_organizer pSymbol = 
reinterpret_cast<basicide_macro_organizer>(aMod.getFunctionSymbol("basicide_macro_organizer"));
-
-    aMod.release();
+    basicide_macro_organizer pSymbol = 
reinterpret_cast<basicide_macro_organizer>(sfx2::getBasctlFunction("basicide_macro_organizer"));
 
-    SAL_WARN_IF(!pSymbol, "sfx.appl", "SfxApplication::MacroOrganizer, no 
symbol!");
     if (!pSymbol)
         return;
 
diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx
index 77896317eb5a..3658bb82cf08 100644
--- a/sfx2/source/appl/appserv.cxx
+++ b/sfx2/source/appl/appserv.cxx
@@ -18,7 +18,6 @@
  */
 
 #include <config_features.h>
-#include <config_options.h>
 #include <com/sun/star/document/XEmbeddedScripts.hpp>
 #include <com/sun/star/drawing/ModuleDispatcher.hpp>
 #include <com/sun/star/frame/Desktop.hpp>
@@ -68,7 +67,6 @@
 #include <rtl/ustrbuf.hxx>
 #include <sal/log.hxx>
 #include <osl/file.hxx>
-#include <osl/module.hxx>
 #include <vcl/EnumContext.hxx>
 
 #include <unotools/moduleoptions.hxx>
@@ -111,6 +109,8 @@
 
 #include <openuriexternally.hxx>
 
+#include "getbasctlfunction.hxx"
+
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::uno;
@@ -1206,8 +1206,6 @@ void SfxApplication::MiscState_Impl(SfxItemSet &rSet)
 
 typedef rtl_uString* (*basicide_choose_macro)(void*, void*, void*, sal_Bool);
 
-extern "C" { static void thisModule() {} }
-
 #else
 
 extern "C" rtl_uString* basicide_choose_macro(void*, void*, void*, sal_Bool);
@@ -1217,28 +1215,9 @@ extern "C" rtl_uString* basicide_choose_macro(void*, 
void*, void*, sal_Bool);
 static OUString ChooseMacro(weld::Window* pParent, const Reference<XModel>& 
rxLimitToDocument, const Reference<XFrame>& xDocFrame, bool bChooseOnly)
 {
 #ifndef DISABLE_DYNLOADING
-    osl::Module aMod;
-
-    // load basctl module
-    if (!aMod.loadRelative(
-            &thisModule,
-#if ENABLE_MERGELIBS
-            SVLIBRARY("merged")
-#else
-            SVLIBRARY("basctl")
-#endif
-        ))
-    {
-        SAL_WARN("sfx.appl", "cannot load basctl");
-        return "";
-    }
-
-    // get symbol
-    basicide_choose_macro pSymbol = 
reinterpret_cast<basicide_choose_macro>(aMod.getFunctionSymbol("basicide_choose_macro"));
-    SAL_WARN_IF(!pSymbol, "sfx.appl", "SfxApplication::MacroOrganizer, no 
symbol!");
+    basicide_choose_macro pSymbol = 
reinterpret_cast<basicide_choose_macro>(sfx2::getBasctlFunction("basicide_choose_macro"));
     if (!pSymbol)
         return OUString();
-    aMod.release();
 #else
 #define pSymbol basicide_choose_macro
 #endif
diff --git a/sfx2/source/appl/getbasctlfunction.cxx 
b/sfx2/source/appl/getbasctlfunction.cxx
new file mode 100644
index 000000000000..93c79df57177
--- /dev/null
+++ b/sfx2/source/appl/getbasctlfunction.cxx
@@ -0,0 +1,58 @@
+/* -*- 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/.
+ *
+ * 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 <sal/config.h>
+
+#include <config_options.h>
+#include <osl/module.h>
+#include <osl/module.hxx>
+#include <sal/log.hxx>
+#include <tools/svlibrary.h>
+
+#include "getbasctlfunction.hxx"
+
+extern "C" { static void thisModule() {} }
+
+oslGenericFunction sfx2::getBasctlFunction(char const* name)
+{
+    osl::Module aMod;
+
+    // load basctl module
+    if (!aMod.loadRelative(
+            &thisModule,
+#if ENABLE_MERGELIBS
+            SVLIBRARY("merged")
+#else
+            SVLIBRARY("basctl")
+#endif
+        ))
+    {
+        SAL_WARN("sfx.appl", "cannot load basctl");
+        return nullptr;
+    }
+
+    // get symbol
+    auto pSymbol = aMod.getFunctionSymbol(name);
+    SAL_WARN_IF(!pSymbol, "sfx.appl", "cannot get basctl function " << name);
+    aMod.release();
+
+    return pSymbol;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sfx2/source/appl/getbasctlfunction.hxx 
b/sfx2/source/appl/getbasctlfunction.hxx
new file mode 100644
index 000000000000..26918309f6b0
--- /dev/null
+++ b/sfx2/source/appl/getbasctlfunction.hxx
@@ -0,0 +1,31 @@
+/* -*- 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/.
+ *
+ * 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 .
+ */
+
+#pragma once
+
+#include <sal/config.h>
+
+#include <osl/module.h>
+
+namespace sfx2
+{
+oslGenericFunction getBasctlFunction(char const* name);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/solenv/clang-format/blacklist b/solenv/clang-format/blacklist
index 9c3867222c7a..58eb54478155 100644
--- a/solenv/clang-format/blacklist
+++ b/solenv/clang-format/blacklist
@@ -12067,6 +12067,7 @@ sfx2/source/appl/fileobj.cxx
 sfx2/source/appl/fileobj.hxx
 sfx2/source/appl/flatpak.cxx
 sfx2/source/appl/fwkhelper.cxx
+sfx2/source/appl/getbasctlfunction.cxx
 sfx2/source/appl/helpdispatch.cxx
 sfx2/source/appl/helpdispatch.hxx
 sfx2/source/appl/helpinterceptor.cxx
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to