diff --git a/include/wx/module.h b/include/wx/module.h index 41ef501e7e..1f107029aa 100644 --- a/include/wx/module.h +++ b/include/wx/module.h @@ -47,7 +47,8 @@ public: static void RegisterModule(wxModule *module); static void RegisterModules(); static bool InitializeModules(); - static void CleanUpModules() { DoCleanUpModules(ms_modules); } + static void CleanUpModules(); + static bool AreInitialized() { return ms_areInitialized; } // used by wxObjectLoader when unloading shared libs's @@ -56,6 +57,8 @@ public: protected: static wxModuleList ms_modules; + static bool ms_areInitialized; + // the function to call from constructor of a deriving class add module // dependency which will be initialized before the module and unloaded // after that diff --git a/src/common/module.cpp b/src/common/module.cpp index f72956cf6d..7344cfbd96 100644 --- a/src/common/module.cpp +++ b/src/common/module.cpp @@ -25,6 +25,7 @@ wxIMPLEMENT_ABSTRACT_CLASS(wxModule, wxObject) wxModuleList wxModule::ms_modules; +bool wxModule::ms_areInitialized = false; void wxModule::RegisterModule(wxModule* module) { @@ -178,9 +179,18 @@ bool wxModule::InitializeModules() // remember the real initialisation order ms_modules = initializedModules; + ms_areInitialized = true; + return true; } +void wxModule::CleanUpModules() +{ + DoCleanUpModules(ms_modules); + + ms_areInitialized = false; +} + // Clean up all currently initialized modules void wxModule::DoCleanUpModules(const wxModuleList& modules) { diff --git a/tests/misc/module.cpp b/tests/misc/module.cpp index d05b85ec82..24ee867e28 100644 --- a/tests/misc/module.cpp +++ b/tests/misc/module.cpp @@ -15,6 +15,8 @@ #include "wx/module.h" #include "wx/wxcrt.h" // for wxStrcat() +static bool gs_wasInitialized = wxModule::AreInitialized(); + // ---------------------------------------------------------------------------- // test classes derived from wxModule // ---------------------------------------------------------------------------- @@ -89,6 +91,12 @@ ModuleD::ModuleD() // tests themselves // ---------------------------------------------------------------------------- +TEST_CASE("wxModule::Initialized", "[module]") +{ + CHECK( !gs_wasInitialized ); + CHECK( wxModule::AreInitialized() ); +} + TEST_CASE("wxModule::LoadOrder", "[module]") { // module D is the only one with no dependencies and so should load as first (and so on):