diff options
author | Mark Page <aptitude@btconnect.com> | 2016-07-04 17:30:42 +0100 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-07-13 06:32:46 +0000 |
commit | f7b1cd66167050afecf487e3d89ea12de74200b5 (patch) | |
tree | 75381b63bb5dca7ed1fa2ff5602064750f46f042 /sfx2 | |
parent | 633413a37ee7442cd899db1269fd3ef404efe58a (diff) |
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@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/appl/app.cxx | 17 | ||||
-rw-r--r-- | sfx2/source/appl/module.cxx | 40 | ||||
-rw-r--r-- | sfx2/source/inc/appdata.hxx | 4 |
3 files changed, 19 insertions, 42 deletions
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<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 7ea9e345cfd7..a6465c5967f2 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 71fabc3e47b4..bc98e985dcb3 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. |