[Libreoffice-commits] core.git: basctl/source cui/source include/sfx2 include/tools sc/inc sc/source sd/inc sd/qa sd/source sfx2/source starmath/inc starmath/source sw/CppunitTest_sw_htmlexport.mk sw/inc sw/qa sw/source tools/Library_tl.mk tools/source

Mark Page aptitude at btconnect.com
Wed Jul 13 06:33:11 UTC 2016


 basctl/source/basicide/basicmod.hxx    |    3 -
 basctl/source/basicide/iderdll.cxx     |   12 +---
 cui/source/options/treeopt.cxx         |    9 +--
 cui/source/tabpages/autocdlg.cxx       |    3 -
 include/sfx2/app.hxx                   |   13 ++++
 include/sfx2/module.hxx                |    2 
 include/tools/shl.hxx                  |   87 ---------------------------------
 sc/inc/scmod.hxx                       |    3 -
 sc/source/ui/app/scdll.cxx             |    9 +--
 sd/inc/sddll.hxx                       |    6 +-
 sd/inc/sdmod.hxx                       |    3 -
 sd/qa/unit/misc-tests.cxx              |    1 
 sd/source/core/drawdoc4.cxx            |    1 
 sd/source/ui/app/sddll.cxx             |   31 +++--------
 sd/source/ui/app/sdmod.cxx             |    5 -
 sfx2/source/appl/app.cxx               |   17 ++++++
 sfx2/source/appl/module.cxx            |   40 ---------------
 sfx2/source/inc/appdata.hxx            |    4 +
 starmath/inc/smmod.hxx                 |    3 -
 starmath/source/smdll.cxx              |   17 ++----
 sw/CppunitTest_sw_htmlexport.mk        |    1 
 sw/inc/swmodule.hxx                    |    3 -
 sw/qa/extras/htmlexport/htmlexport.cxx |    1 
 sw/source/uibase/app/swdll.cxx         |   11 +---
 tools/Library_tl.mk                    |    1 
 tools/source/misc/toolsdll.cxx         |   33 ------------
 26 files changed, 76 insertions(+), 243 deletions(-)

New commits:
commit f7b1cd66167050afecf487e3d89ea12de74200b5
Author: Mark Page <aptitude at btconnect.com>
Date:   Mon Jul 4 17:30:42 2016 +0100

    Moved SfxModule owner to SfxApplication
    
    ::GetAppData replaced with SfxApplication::GetModule
    that now returns SfxModule*
    
    SfxModule no longer registers self for ownership
    instead it is now registered using SfxApplication::SetModule
    
    Change-Id: Ifbbe1b2b4c5122da8e643b7926d47878d116c6c8
    Reviewed-on: https://gerrit.libreoffice.org/26914
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/basctl/source/basicide/basicmod.hxx b/basctl/source/basicide/basicmod.hxx
index 3bed4f2..ffc960c 100644
--- a/basctl/source/basicide/basicmod.hxx
+++ b/basctl/source/basicide/basicmod.hxx
@@ -28,13 +28,10 @@ namespace basctl
 
 class Module : public SfxModule
 {
-    static Module* mpModule;
 public:
     Module ( ResMgr *pMgr, SfxObjectFactory *pObjFact) :
         SfxModule( pMgr, {pObjFact} )
     { }
-public:
-    static Module*& Get () { return mpModule; }
 };
 
 } // namespace basctl
diff --git a/basctl/source/basicide/iderdll.cxx b/basctl/source/basicide/iderdll.cxx
index 19d5961..2ea8a29 100644
--- a/basctl/source/basicide/iderdll.cxx
+++ b/basctl/source/basicide/iderdll.cxx
@@ -32,7 +32,7 @@
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
 #include <vcl/settings.hxx>
-
+#include <o3tl/make_unique.hxx>
 
 namespace basctl
 {
@@ -40,8 +40,6 @@ namespace basctl
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
 
-Module* Module::mpModule = nullptr;
-
 namespace
 {
 
@@ -106,7 +104,7 @@ ExtraData* GetExtraData()
 
 
 IDEResId::IDEResId( sal_uInt16 nId ):
-    ResId(nId, *Module::Get()->GetResMgr())
+    ResId(nId, *SfxApplication::GetModule(SfxToolsModule::Basic)->GetResMgr())
 { }
 
 namespace
@@ -121,12 +119,12 @@ Dll::Dll () :
     ResMgr* pMgr = ResMgr::CreateResMgr(
         "basctl", Application::GetSettings().GetUILanguageTag());
 
-    Module::Get() = new Module( pMgr, &DocShell::Factory() );
+    auto pModule = o3tl::make_unique<Module>( pMgr, &DocShell::Factory() );
+    SfxModule* pMod = pModule.get();
+    SfxApplication::SetModule(SfxToolsModule::Basic, std::move(pModule));
 
     GetExtraData(); // to cause GlobalErrorHdl to be set
 
-    SfxModule* pMod = Module::Get();
-
     SfxObjectFactory& rFactory = DocShell::Factory();
     rFactory.SetDocumentServiceName( "com.sun.star.script.BasicIDE" );
 
diff --git a/cui/source/options/treeopt.cxx b/cui/source/options/treeopt.cxx
index 3b3e52c..d61a661 100644
--- a/cui/source/options/treeopt.cxx
+++ b/cui/source/options/treeopt.cxx
@@ -89,7 +89,6 @@
 #include <svx/xtable.hxx>
 #include <svx/xpool.hxx>
 #include <toolkit/helper/vclunohelper.hxx>
-#include <tools/shl.hxx>
 #include <tools/urlobj.hxx>
 #include <unotools/linguprops.hxx>
 #include <unotools/misccfg.hxx>
@@ -1586,7 +1585,7 @@ void OfaTreeOptionsDialog::Initialize( const Reference< XFrame >& _xFrame )
             || aFactory == "com.sun.star.text.WebDocument"
             || aFactory == "com.sun.star.text.GlobalDocument" )
         {
-            SfxModule* pSwMod = *reinterpret_cast<SfxModule**>(GetAppData(SHL_WRITER));
+            SfxModule* pSwMod = SfxApplication::GetModule(SfxToolsModule::Writer);
             if ( !lcl_isOptionHidden( SID_SW_EDITOPTIONS, aOptionsDlgOpt ) )
             {
                 if ( aFactory == "com.sun.star.text.WebDocument" )
@@ -1635,7 +1634,7 @@ void OfaTreeOptionsDialog::Initialize( const Reference< XFrame >& _xFrame )
             if ( !lcl_isOptionHidden( SID_SC_EDITOPTIONS, aOptionsDlgOpt ) )
             {
                 ResStringArray& rCalcArray = aDlgResource.GetCalcArray();
-                SfxModule* pScMod = *reinterpret_cast<SfxModule**>(GetAppData( SHL_CALC ));
+                SfxModule* pScMod = SfxApplication::GetModule( SfxToolsModule::Calc );
                 setGroupName( "Calc", rCalcArray.GetString(0) );
                 nGroup = AddGroup( rCalcArray.GetString( 0 ), pScMod, pScMod, SID_SC_EDITOPTIONS );
                 const sal_uInt16 nCount = static_cast< const sal_uInt16 >( rCalcArray.Count() );
@@ -1652,7 +1651,7 @@ void OfaTreeOptionsDialog::Initialize( const Reference< XFrame >& _xFrame )
     }
 
     // Impress options
-    SfxModule* pSdMod = *reinterpret_cast<SfxModule**>(GetAppData( SHL_DRAW ));
+    SfxModule* pSdMod = SfxApplication::GetModule( SfxToolsModule::Draw );
     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::IMPRESS ) )
     {
         if ( aFactory == "com.sun.star.presentation.PresentationDocument" )
@@ -1706,7 +1705,7 @@ void OfaTreeOptionsDialog::Initialize( const Reference< XFrame >& _xFrame )
             if ( !lcl_isOptionHidden( SID_SM_EDITOPTIONS, aOptionsDlgOpt ) )
             {
                 ResStringArray& rStarMathArray = aDlgResource.GetStarMathArray();
-                SfxModule* pSmMod = *reinterpret_cast<SfxModule**>(GetAppData(SHL_SM));
+                SfxModule* pSmMod = SfxApplication::GetModule(SfxToolsModule::Math);
                 setGroupName( "Math", rStarMathArray.GetString(0) );
                 nGroup = AddGroup(rStarMathArray.GetString(0), pSmMod, pSmMod, SID_SM_EDITOPTIONS );
                 for ( i = 1; i < rStarMathArray.Count(); ++i )
diff --git a/cui/source/tabpages/autocdlg.cxx b/cui/source/tabpages/autocdlg.cxx
index fed51d3..f442306 100644
--- a/cui/source/tabpages/autocdlg.cxx
+++ b/cui/source/tabpages/autocdlg.cxx
@@ -25,7 +25,6 @@
 #include <vcl/settings.hxx>
 #include <sot/exchange.hxx>
 #include <svtools/transfer.hxx>
-#include <tools/shl.hxx>
 #include <unotools/syslocale.hxx>
 #include <sfx2/objsh.hxx>
 #include <sfx2/viewsh.hxx>
@@ -882,7 +881,7 @@ OfaAutocorrReplacePage::OfaAutocorrReplacePage( vcl::Window* pParent,
     get(m_pReplaceTLB, "tabview");
     m_pReplaceTLB->set_height_request(16 * GetTextHeight());
 
-    SfxModule *pMod = *reinterpret_cast<SfxModule**>(GetAppData(SHL_WRITER));
+    SfxModule *pMod = SfxApplication::GetModule(SfxToolsModule::Writer);
     bSWriter = pMod == SfxModule::GetActiveModule();
 
     LanguageTag aLanguageTag( eLastDialogLanguage );
diff --git a/include/sfx2/app.hxx b/include/sfx2/app.hxx
index 2b02ed1..afeb501 100644
--- a/include/sfx2/app.hxx
+++ b/include/sfx2/app.hxx
@@ -88,6 +88,16 @@ namespace sfx2
     }
 }
 
+enum class SfxToolsModule
+{
+    Math = 0,
+    Calc = 1,
+    Draw = 2,
+    Writer = 3,
+    Basic = 4,
+    LAST = Basic
+};
+
 class SfxLinkItem : public SfxPoolItem
 {
     Link<SfxPoolItem*, void> aLink;
@@ -224,6 +234,9 @@ public:
     SAL_DLLPRIVATE SfxSlotPool& GetAppSlotPool_Impl() const;
     SAL_DLLPRIVATE SfxModule*   GetModule_Impl();
 
+    static void                 SetModule(SfxToolsModule nSharedLib, std::unique_ptr<SfxModule> pModule);
+    static SfxModule*           GetModule(SfxToolsModule nSharedLib);
+
     static bool loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWidth);
 
     /** loads the application logo as used in the impress slideshow pause screen */
diff --git a/include/sfx2/module.hxx b/include/sfx2/module.hxx
index 2761cce..1296740 100644
--- a/include/sfx2/module.hxx
+++ b/include/sfx2/module.hxx
@@ -96,8 +96,6 @@ public:
     static FieldUnit            GetModuleFieldUnit( css::uno::Reference< css::frame::XFrame > const & i_frame );
     FieldUnit                   GetFieldUnit() const;
 
-    SAL_DLLPRIVATE static std::vector<SfxModule*>& GetModules_Impl();
-    SAL_DLLPRIVATE static void DestroyModules_Impl();
     SAL_DLLPRIVATE SfxTbxCtrlFactArr_Impl* GetTbxCtrlFactories_Impl() const;
     SAL_DLLPRIVATE SfxStbCtrlFactArr_Impl* GetStbCtrlFactories_Impl() const;
     SAL_DLLPRIVATE SfxChildWinFactArr_Impl* GetChildWinFactories_Impl() const;
diff --git a/include/tools/shl.hxx b/include/tools/shl.hxx
deleted file mode 100644
index 85a4242..0000000
--- a/include/tools/shl.hxx
+++ /dev/null
@@ -1,87 +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_TOOLS_SHL_HXX
-#define INCLUDED_TOOLS_SHL_HXX
-
-#include <tools/toolsdllapi.h>
-
-// GetAppData()
-
-// 0 (SHL_SHL1) removed
-// 1 (SHL_SHL2) removed
-// 2 (SHL_SHL3) removed
-// 3 (SHL_APP1) removed
-// 4 (SHL_APP2) removed
-// 5 (SHL_APP3) removed
-// 6 (SHL_TOOLS) removed
-// 7 (SHL_SV) removed
-// 8 (SHL_SVT) removed
-// 9 (SHL_SVDDE) removed
-// 10 (SHL_ERR) removed
-//11 (SHL_IPC) removed
-//12 (SHL_SVX) removed
-//13 (SHL_ITEM) removed
-//14 (SHL_SVD) removed
-//15 (SHL_SI) removed
-//16 (SHL_SFC) removed
-//17 (SHL_SFX) removed
-//18 (SHL_SO2) removed
-//19 (SHL_IDL) removed
-//20 (SHL_IDE) removed
-//21 (SHL_EDIT) removed
-//22 (SHL_VCED) removed
-//23 (SHL_BASIC) removed
-//24 (SHL_HELP) removed
-//25 (SHL_LNKCCH) removed
-//26 (SHL_CHANNEL) removed
-//27 (SHL_SBX) removed
-//28 (SHL_SBC) removed
-//29 (SHL_SDB) removed
-//30 (SHL_SBA) removed
-//31 (SHL_SBA2) removed
-//32 (SHL_SCH) removed
-//33 (SHL_SIM) removed
-#define SHL_SM          34
-//35 (SHL_SGA) removed
-//36 (SHL_DOCMGR) removed
-//37 removed
-//38 (SHL_MAIL) removed
-//39 (SHL_NEWS) removed
-//40 (SHL_OFFAPP) removed
-//41 (SHL_INET) removed
-//43 (SHL_CHAOS) removed
-//43 (SHL_HISTORY) removed
-//44 (SHL_SJ) removed
-#define SHL_CALC        45
-#define SHL_DRAW        46
-#define SHL_WRITER      47
-//48 (SHL_MONEY) removed
-//49 (SHL_HBCI) removed
-//50 (SHL_BASE3D) removed
-//51 (SHL_BRUSHITEM) removed
-//52 (SHL_SFONTITEM) removed
-
-#define SHL_COUNT        53
-
-TOOLS_DLLPUBLIC void** GetAppData( sal_uInt16 nSharedLib );
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/scmod.hxx b/sc/inc/scmod.hxx
index c80b0ba..e6fa352 100644
--- a/sc/inc/scmod.hxx
+++ b/sc/inc/scmod.hxx
@@ -28,7 +28,6 @@
 #include "global.hxx"
 #include "shellids.hxx"
 #include <unotools/options.hxx>
-#include <tools/shl.hxx>
 
 #include <map>
 #include <list>
@@ -255,7 +254,7 @@ public:
     SC_DLLPUBLIC vcl::Window * Find1RefWindow( sal_uInt16 nSlotId, vcl::Window *pWndAncestor );
 };
 
-#define SC_MOD() ( *reinterpret_cast<ScModule**>(GetAppData(SHL_CALC)) )
+#define SC_MOD() ( static_cast<ScModule*>(SfxApplication::GetModule(SfxToolsModule::Calc)) )
 
 void global_InitAppOptions();
 
diff --git a/sc/source/ui/app/scdll.cxx b/sc/source/ui/app/scdll.cxx
index 9a14c78..2e3ba3a 100644
--- a/sc/source/ui/app/scdll.cxx
+++ b/sc/source/ui/app/scdll.cxx
@@ -102,6 +102,7 @@
 
 #include "dwfunctr.hxx"
 #include "acredlin.hxx"
+#include <o3tl/make_unique.hxx>
 
 ScResId::ScResId( sal_uInt16 nId ) :
     ResId( nId, *SC_MOD()->GetResMgr() )
@@ -110,14 +111,14 @@ ScResId::ScResId( sal_uInt16 nId ) :
 
 void ScDLL::Init()
 {
-    ScModule **ppShlPtr = reinterpret_cast<ScModule**>(GetAppData(SHL_CALC));
-    if ( *ppShlPtr )
+    if ( SfxApplication::GetModule(SfxToolsModule::Calc) )    // Module already active
         return;
 
     ScDocumentPool::InitVersionMaps(); // Is needed in the ScModule ctor
 
-    ScModule* pMod = new ScModule( &ScDocShell::Factory() );
-    (*ppShlPtr) = pMod;
+    auto pUniqueModule = o3tl::make_unique<ScModule>(&ScDocShell::Factory());
+    ScModule* pMod = pUniqueModule.get();
+    SfxApplication::SetModule(SfxToolsModule::Calc, std::move(pUniqueModule));
 
     ScDocShell::Factory().SetDocumentServiceName( "com.sun.star.sheet.SpreadsheetDocument" );
 
diff --git a/sd/inc/sddll.hxx b/sd/inc/sddll.hxx
index 6f8a049..8b05dc5 100644
--- a/sd/inc/sddll.hxx
+++ b/sd/inc/sddll.hxx
@@ -23,6 +23,8 @@
 #include <sfx2/module.hxx>
 #include "sddllapi.h"
 
+class SdModule;
+
 /*************************************************************************
 |*
 |* This class is a wrapper for a Load-On-Demand-DLL. One instance
@@ -40,8 +42,8 @@ protected:
     static void     RegisterRemotes();
 #endif
     static void     RegisterFactorys();
-    static void     RegisterInterfaces();
-    static void     RegisterControllers();
+    static void     RegisterInterfaces(SdModule* pMod);
+    static void     RegisterControllers(SdModule* pMod);
 
 public:
                     // Ctor/Dtor must be linked to the application
diff --git a/sd/inc/sdmod.hxx b/sd/inc/sdmod.hxx
index 7293b65..cb5f2c3 100644
--- a/sd/inc/sdmod.hxx
+++ b/sd/inc/sdmod.hxx
@@ -24,7 +24,6 @@
 #include "pres.hxx"
 
 #include <sot/storage.hxx>
-#include <tools/shl.hxx>
 #include "sddllapi.h"
 #include <svl/itemprop.hxx>
 #include <svl/lstner.hxx>
@@ -192,7 +191,7 @@ private:
 
 };
 
-#define SD_MOD() ( *reinterpret_cast<SdModule**>(GetAppData(SHL_DRAW)) )
+#define SD_MOD() ( static_cast<SdModule*>(SfxApplication::GetModule(SfxToolsModule::Draw)) )
 
 #endif // INCLUDED_SD_INC_SDMOD_HXX
 
diff --git a/sd/qa/unit/misc-tests.cxx b/sd/qa/unit/misc-tests.cxx
index bc73b5f..c25abc6 100644
--- a/sd/qa/unit/misc-tests.cxx
+++ b/sd/qa/unit/misc-tests.cxx
@@ -23,7 +23,6 @@
 #include <osl/thread.hxx>
 #include <FactoryIds.hxx>
 #include <sdmod.hxx>
-#include <tools/shl.hxx>
 #include <svx/sdr/table/tablecontroller.hxx>
 #include <sfx2/request.hxx>
 #include <svx/svxids.hrc>
diff --git a/sd/source/core/drawdoc4.cxx b/sd/source/core/drawdoc4.cxx
index c19c670..ed0c55b 100644
--- a/sd/source/core/drawdoc4.cxx
+++ b/sd/source/core/drawdoc4.cxx
@@ -85,7 +85,6 @@
 #include <svx/svditer.hxx>
 #include <svx/svdogrp.hxx>
 #include <svx/svdlayer.hxx>
-#include <tools/shl.hxx>
 #include <editeng/numitem.hxx>
 #include <editeng/editeng.hxx>
 #include <editeng/unolingu.hxx>
diff --git a/sd/source/ui/app/sddll.cxx b/sd/source/ui/app/sddll.cxx
index 9576391..6a27583 100644
--- a/sd/source/ui/app/sddll.cxx
+++ b/sd/source/ui/app/sddll.cxx
@@ -94,6 +94,7 @@
 #include <sfx2/sidebar/SidebarChildWindow.hxx>
 #include <vcl/FilterConfigItem.hxx>
 #include <comphelper/processfactory.hxx>
+#include <o3tl/make_unique.hxx>
 
 using namespace ::com::sun::star;
 
@@ -119,10 +120,9 @@ void SdDLL::RegisterFactorys()
 
 // Register all Interfaces
 
-void SdDLL::RegisterInterfaces()
+void SdDLL::RegisterInterfaces(SdModule* pMod)
 {
     // Module
-    SfxModule* pMod = SD_MOD();
     SdModule::RegisterInterface(pMod);
 
     // View shell base.
@@ -157,10 +157,8 @@ void SdDLL::RegisterInterfaces()
 
 // Register all Controllers
 
-void SdDLL::RegisterControllers()
+void SdDLL::RegisterControllers(SdModule* pMod)
 {
-    SfxModule* pMod = SD_MOD();
-
     SdTbxCtlDiaPages::RegisterControl( SID_PAGES_PER_ROW, pMod );
     SdTbxCtlGlueEscDir::RegisterControl( SID_GLUE_ESCDIR, pMod );
 
@@ -244,7 +242,7 @@ void SdDLL::RegisterControllers()
 
 void SdDLL::Init()
 {
-    if ( SD_MOD() )
+    if ( SfxApplication::GetModule(SfxToolsModule::Draw) )    // Module already active
         return;
 
     SfxObjectFactory* pDrawFact = nullptr;
@@ -256,20 +254,9 @@ void SdDLL::Init()
     if (!utl::ConfigManager::IsAvoidConfig() && SvtModuleOptions().IsDraw())
         pDrawFact = &::sd::GraphicDocShell::Factory();
 
-    // the SdModule must be created
-     SdModule** ppShlPtr = reinterpret_cast<SdModule**>(GetAppData(SHL_DRAW));
-
-     // #i46427#
-     // The SfxModule::SfxModule stops when the first given factory
-     // is 0, so we must not give a 0 as first factory
-     if( pImpressFact )
-     {
-        (*ppShlPtr) = new SdModule( pImpressFact, pDrawFact );
-     }
-     else
-     {
-        (*ppShlPtr) = new SdModule( pDrawFact, pImpressFact );
-     }
+    auto pUniqueModule = o3tl::make_unique<SdModule>(pImpressFact, pDrawFact);
+    SdModule* pModule = pUniqueModule.get();
+    SfxApplication::SetModule(SfxToolsModule::Draw, std::move(pUniqueModule));
 
     if (!utl::ConfigManager::IsAvoidConfig() && SvtModuleOptions().IsImpress())
     {
@@ -287,10 +274,10 @@ void SdDLL::Init()
     RegisterFactorys();
 
     // register your shell-interfaces here
-    RegisterInterfaces();
+    RegisterInterfaces(pModule);
 
     // register your controllers here
-    RegisterControllers();
+    RegisterControllers(pModule);
 
     // register SvDraw-Fields
     SdrRegisterFieldClasses();
diff --git a/sd/source/ui/app/sdmod.cxx b/sd/source/ui/app/sdmod.cxx
index 1f821f0..f665d7f 100644
--- a/sd/source/ui/app/sdmod.cxx
+++ b/sd/source/ui/app/sdmod.cxx
@@ -110,11 +110,6 @@ SdModule::~SdModule()
 
     mpResourceContainer.reset();
 
-    // Mark the module in the global AppData structure as deleted.
-    SdModule** ppShellPointer = reinterpret_cast<SdModule**>(GetAppData(SHL_DRAW));
-    if (ppShellPointer != nullptr)
-        (*ppShellPointer) = nullptr;
-
     delete mpErrorHdl;
     mpVirtualRefDevice.disposeAndClear();
 }
diff --git a/sfx2/source/appl/app.cxx b/sfx2/source/appl/app.cxx
index 6dab36f..f5c5725 100644
--- a/sfx2/source/appl/app.cxx
+++ b/sfx2/source/appl/app.cxx
@@ -128,6 +128,20 @@ SfxApplication* SfxApplication::Get()
     return g_pSfxApplication;
 }
 
+void SfxApplication::SetModule(SfxToolsModule nSharedLib, std::unique_ptr<SfxModule> pModule)
+{
+    assert(g_pSfxApplication != nullptr);
+
+    g_pSfxApplication->pImpl->aModules[nSharedLib] = std::move(pModule);
+}
+
+SfxModule* SfxApplication::GetModule(SfxToolsModule nSharedLib)
+{
+    if (!g_pSfxApplication) // It is possible GetModule is called before SfxApplication is initialised via GetOrCreate()
+        return nullptr;
+    return g_pSfxApplication->pImpl->aModules[nSharedLib].get();
+}
+
 SfxApplication* SfxApplication::GetOrCreate()
 {
     // SFX on demand
@@ -207,7 +221,8 @@ SfxApplication::~SfxApplication()
 
     Broadcast( SfxSimpleHint(SFX_HINT_DYING) );
 
-    SfxModule::DestroyModules_Impl();
+    for (auto &module : pImpl->aModules)    // Clear modules
+        module.reset();
 
 #if HAVE_FEATURE_DESKTOP
     delete pSfxHelp;
diff --git a/sfx2/source/appl/module.cxx b/sfx2/source/appl/module.cxx
index 7ea9e34..a6465c5 100644
--- a/sfx2/source/appl/module.cxx
+++ b/sfx2/source/appl/module.cxx
@@ -42,8 +42,6 @@
 #include "childwinimpl.hxx"
 #include <ctrlfactoryimpl.hxx>
 
-static std::vector<SfxModule*>* pModules=nullptr;
-
 class SfxModule_Impl
 {
 public:
@@ -117,8 +115,6 @@ SfxModule::SfxModule( ResMgr* pMgrP, std::initializer_list<SfxObjectFactory*> pF
 void SfxModule::Construct_Impl()
 {
     SfxApplication *pApp = SfxGetpApp();
-    std::vector<SfxModule*> &rArr = GetModules_Impl();
-    rArr.push_back( this );
     pImpl = new SfxModule_Impl;
     pImpl->pSlotPool = new SfxSlotPool(&pApp->GetAppSlotPool_Impl());
 
@@ -134,21 +130,6 @@ void SfxModule::Construct_Impl()
 
 SfxModule::~SfxModule()
 {
-    if ( SfxGetpApp()->Get_Impl() )
-    {
-        // The module will be destroyed before the Deinitialize,
-        // so remove from the array
-        std::vector<SfxModule*>& rArr = GetModules_Impl();
-        for( sal_uInt16 nPos = rArr.size(); nPos--; )
-        {
-            if( rArr[ nPos ] == this )
-            {
-                rArr.erase( rArr.begin() + nPos );
-                break;
-            }
-        }
-    }
-
     delete pImpl;
     delete pResMgr;
 }
@@ -249,27 +230,6 @@ VclPtr<SfxTabPage> SfxModule::CreateTabPage( sal_uInt16, vcl::Window*, const Sfx
     return VclPtr<SfxTabPage>();
 }
 
-std::vector<SfxModule*>& SfxModule::GetModules_Impl()
-{
-    if( !pModules )
-        pModules = new std::vector<SfxModule*>;
-    return *pModules;
-};
-
-void SfxModule::DestroyModules_Impl()
-{
-    if ( pModules )
-    {
-        for( sal_uInt16 nPos = pModules->size(); nPos--; )
-        {
-            SfxModule* pMod = (*pModules)[nPos];
-            delete pMod;
-        }
-        delete pModules;
-        pModules = nullptr;
-    }
-}
-
 void SfxModule::Invalidate( sal_uInt16 nId )
 {
     for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst(); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame ) )
diff --git a/sfx2/source/inc/appdata.hxx b/sfx2/source/inc/appdata.hxx
index 71fabc3..bc98e98 100644
--- a/sfx2/source/inc/appdata.hxx
+++ b/sfx2/source/inc/appdata.hxx
@@ -27,7 +27,7 @@
 #include <svtools/ehdl.hxx>
 #include <vcl/timer.hxx>
 #include <sfx2/app.hxx>
-
+#include <o3tl/enumarray.hxx>
 #include <com/sun/star/frame/XModel.hpp>
 
 #include "bitset.hxx"
@@ -133,6 +133,8 @@ public:
     SfxDocumentTemplates*       GetDocumentTemplates();
     void                        DeInitDDE();
 
+    o3tl::enumarray<SfxToolsModule, std::unique_ptr<SfxModule>> aModules;
+
     /** called when the Application's BasicManager has been created. This can happen
         explicitly in SfxApplication::GetBasicManager, or implicitly if a document's
         BasicManager is created before the application's BasicManager exists.
diff --git a/starmath/inc/smmod.hxx b/starmath/inc/smmod.hxx
index 6810c19..fe60207 100644
--- a/starmath/inc/smmod.hxx
+++ b/starmath/inc/smmod.hxx
@@ -24,7 +24,6 @@
 #include <svl/lstner.hxx>
 #include <svtools/colorcfg.hxx>
 
-#include <tools/shl.hxx>
 #include "tools/rc.hxx"
 #include <sfx2/module.hxx>
 
@@ -125,7 +124,7 @@ public:
     virtual VclPtr<SfxTabPage> CreateTabPage( sal_uInt16 nId, vcl::Window* pParent, const SfxItemSet& rSet ) override;
 };
 
-#define SM_MOD() ( *reinterpret_cast<SmModule**>(GetAppData(SHL_SM)) )
+#define SM_MOD() ( static_cast<SmModule*>(SfxApplication::GetModule(SfxToolsModule::Math)) )
 
 #endif // INCLUDED_STARMATH_INC_SMMOD_HXX
 
diff --git a/starmath/source/smdll.cxx b/starmath/source/smdll.cxx
index 738a6c5..64e16de 100644
--- a/starmath/source/smdll.cxx
+++ b/starmath/source/smdll.cxx
@@ -38,6 +38,7 @@
 #include <starmath.hrc>
 
 #include <svx/xmlsecctrl.hxx>
+#include <o3tl/make_unique.hxx>
 
 namespace
 {
@@ -50,13 +51,14 @@ namespace
 
     SmDLL::SmDLL()
     {
-        SmModule** ppShlPtr = reinterpret_cast<SmModule**>(GetAppData(SHL_SM));
-        if ( *ppShlPtr )
+        if ( SfxApplication::GetModule(SfxToolsModule::Math) )    // Module already active
             return;
 
         SfxObjectFactory& rFactory = SmDocShell::Factory();
-        SmModule *pModule = new SmModule( &rFactory );
-        *ppShlPtr = pModule;
+
+        auto pUniqueModule = o3tl::make_unique<SmModule>(&rFactory);
+        SmModule* pModule = pUniqueModule.get();
+        SfxApplication::SetModule(SfxToolsModule::Math, std::move(pUniqueModule));
 
         rFactory.SetDocumentServiceName( "com.sun.star.formula.FormulaProperties" );
 
@@ -79,13 +81,6 @@ namespace
 
     SmDLL::~SmDLL()
     {
-#if 0
-        // the SdModule must be destroyed
-        SmModule** ppShlPtr = (SmModule**) GetAppData(SHL_SM);
-        delete (*ppShlPtr);
-        (*ppShlPtr) = NULL;
-        *GetAppData(SHL_SM) = 0;
-#endif
     }
 
     struct theSmDLLInstance : public rtl::Static<SmDLL, theSmDLLInstance> {};
diff --git a/sw/CppunitTest_sw_htmlexport.mk b/sw/CppunitTest_sw_htmlexport.mk
index a0dc5c1..7a9e076 100644
--- a/sw/CppunitTest_sw_htmlexport.mk
+++ b/sw/CppunitTest_sw_htmlexport.mk
@@ -21,6 +21,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_htmlexport, \
 	cppuhelper \
 	i18nlangtag \
     sal \
+    sfx \
     sw \
     test \
 	tl \
diff --git a/sw/inc/swmodule.hxx b/sw/inc/swmodule.hxx
index eb5607e..2d08802 100644
--- a/sw/inc/swmodule.hxx
+++ b/sw/inc/swmodule.hxx
@@ -23,7 +23,6 @@
 #include <unotools/options.hxx>
 #include <sfx2/module.hxx>
 
-#include <tools/shl.hxx>
 #include "swdllapi.h"
 #include "shellid.hxx"
 #include <fldupde.hxx>
@@ -248,7 +247,7 @@ inline const css::uno::Reference< css::linguistic2::XLinguServiceEventListener >
 
 //    Access to SwModule, the View and the shell.
 
-#define SW_MOD() ( *reinterpret_cast<SwModule**>(GetAppData(SHL_WRITER)))
+#define SW_MOD() ( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule::Writer)))
 
 SW_DLLPUBLIC SwView*    GetActiveView();
 SW_DLLPUBLIC SwWrtShell* GetActiveWrtShell();
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 69b6b7d..d6453aa 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -50,7 +50,6 @@ private:
 
         if (OString(filename) == "charborder.odt")
         {
-
             // FIXME if padding-top gets exported as inches, not cms, we get rounding errors.
             SwGlobals::ensure(); // make sure that SW_MOD() is not 0
             std::unique_ptr<Resetter> pResetter(new Resetter(
diff --git a/sw/source/uibase/app/swdll.cxx b/sw/source/uibase/app/swdll.cxx
index 803c2b8..e9fa7f1 100644
--- a/sw/source/uibase/app/swdll.cxx
+++ b/sw/source/uibase/app/swdll.cxx
@@ -48,7 +48,7 @@
 #include <unomid.h>
 
 #include "swdllimpl.hxx"
-
+#include <o3tl/make_unique.hxx>
 using namespace com::sun::star;
 
 namespace
@@ -81,9 +81,7 @@ namespace SwGlobals
 
 SwDLL::SwDLL()
 {
-    // the SdModule must be created
-    SwModule** ppShlPtr = reinterpret_cast<SwModule**>(GetAppData(SHL_WRITER));
-    if ( *ppShlPtr )
+    if ( SfxApplication::GetModule(SfxToolsModule::Writer) )    // Module already active
         return;
 
     std::unique_ptr<SvtModuleOptions> xOpt;
@@ -99,8 +97,9 @@ SwDLL::SwDLL()
 
     SfxObjectFactory* pWDocFact = &SwWebDocShell::Factory();
 
-    SwModule* pModule = new SwModule( pWDocFact, pDocFact, pGlobDocFact );
-    *ppShlPtr = pModule;
+    auto pUniqueModule = o3tl::make_unique<SwModule>(pWDocFact, pDocFact, pGlobDocFact);
+    SwModule* pModule = pUniqueModule.get();
+    SfxApplication::SetModule(SfxToolsModule::Writer, std::move(pUniqueModule));
 
     pWDocFact->SetDocumentServiceName("com.sun.star.text.WebDocument");
 
diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk
index 2916ad3..6ebf57e 100644
--- a/tools/Library_tl.mk
+++ b/tools/Library_tl.mk
@@ -71,7 +71,6 @@ $(eval $(call gb_Library_add_exception_objects,tl,\
     tools/source/misc/cpuid \
     tools/source/misc/extendapplicationenvironment \
     tools/source/misc/getprocessworkingdir \
-    tools/source/misc/toolsdll \
     tools/source/rc/rc \
     tools/source/rc/resary \
     tools/source/rc/resmgr \
diff --git a/tools/source/misc/toolsdll.cxx b/tools/source/misc/toolsdll.cxx
deleted file mode 100644
index 414c7d2..0000000
--- a/tools/source/misc/toolsdll.cxx
+++ /dev/null
@@ -1,33 +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 <tools/shl.hxx>
-
-static void* aAppData[SHL_COUNT];
-
-/*
- * Query data for other libraries
- */
-
-void** GetAppData( sal_uInt16 nSharedLib )
-{
-    return &(aAppData[nSharedLib]);
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list