From f7b1cd66167050afecf487e3d89ea12de74200b5 Mon Sep 17 00:00:00 2001 From: Mark Page Date: Mon, 4 Jul 2016 17:30:42 +0100 Subject: 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 Reviewed-by: Noel Grandin --- sfx2/source/appl/app.cxx | 17 ++++++++++++++++- sfx2/source/appl/module.cxx | 40 ---------------------------------------- sfx2/source/inc/appdata.hxx | 4 +++- 3 files changed, 19 insertions(+), 42 deletions(-) (limited to 'sfx2') diff --git a/sfx2/source/appl/app.cxx b/sfx2/source/appl/app.cxx index 6dab36f4b8c1..f5c5725b658c 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 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 7ea9e345cfd7..a6465c5967f2 100644 --- a/sfx2/source/appl/module.cxx +++ b/sfx2/source/appl/module.cxx @@ -42,8 +42,6 @@ #include "childwinimpl.hxx" #include -static std::vector* pModules=nullptr; - class SfxModule_Impl { public: @@ -117,8 +115,6 @@ SfxModule::SfxModule( ResMgr* pMgrP, std::initializer_list pF void SfxModule::Construct_Impl() { SfxApplication *pApp = SfxGetpApp(); - std::vector &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& 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 SfxModule::CreateTabPage( sal_uInt16, vcl::Window*, const Sfx return VclPtr(); } -std::vector& SfxModule::GetModules_Impl() -{ - if( !pModules ) - pModules = new std::vector; - 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 71fabc3e47b4..bc98e985dcb3 100644 --- a/sfx2/source/inc/appdata.hxx +++ b/sfx2/source/inc/appdata.hxx @@ -27,7 +27,7 @@ #include #include #include - +#include #include #include "bitset.hxx" @@ -133,6 +133,8 @@ public: SfxDocumentTemplates* GetDocumentTemplates(); void DeInitDDE(); + o3tl::enumarray> 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. -- cgit