X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c801d85f158c4cba50b588807daabdcbd0ed3853..9f542367b72dd900a914c163df7f23ca5e79a60c:/src/common/module.cpp diff --git a/src/common/module.cpp b/src/common/module.cpp index bd2b82d782..2d5df44954 100644 --- a/src/common/module.cpp +++ b/src/common/module.cpp @@ -9,10 +9,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "module.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -21,53 +17,91 @@ #endif #include "wx/module.h" +#include "wx/hash.h" +#include "wx/intl.h" +#include "wx/log.h" +#include "wx/listimpl.cpp" + +#define TRACE_MODULE _T("module") + +WX_DEFINE_LIST(wxModuleList) IMPLEMENT_CLASS(wxModule, wxObject) -wxList wxModule::m_modules; +wxModuleList wxModule::m_modules; void wxModule::RegisterModule(wxModule* module) { - m_modules.Append(module); + m_modules.Append(module); +} + +void wxModule::UnregisterModule(wxModule* module) +{ + m_modules.DeleteObject(module); + delete module; } // Collect up all module-derived classes, create an instance of each, // and register them. -bool wxModule::RegisterModules(void) +void wxModule::RegisterModules() { - wxClassInfo* classInfo = wxClassInfo::first; - while (classInfo) + wxHashTable::compatibility_iterator node; + wxClassInfo* classInfo; + + wxClassInfo::sm_classTable->BeginFind(); + node = wxClassInfo::sm_classTable->Next(); + while (node) { - if ((classInfo != (& (wxModule::classwxModule))) && - classInfo->IsKindOf(CLASSINFO(wxModule))) + classInfo = (wxClassInfo *)node->GetData(); + if ( classInfo->IsKindOf(CLASSINFO(wxModule)) && + (classInfo != (& (wxModule::ms_classInfo))) ) { - wxModule* module = (wxModule*) classInfo->CreateObject(); + wxLogTrace(TRACE_MODULE, wxT("Registering module %s"), + classInfo->GetClassName()); + wxModule* module = (wxModule *)classInfo->CreateObject(); RegisterModule(module); } - classInfo = classInfo->next; + node = wxClassInfo::sm_classTable->Next(); } - return TRUE; } -bool wxModule::InitializeModules(void) +bool wxModule::InitializeModules() { - // Initialize user-defined modules - for (wxNode *node = m_modules.First(); node; node = node->Next()) + // Initialize user-defined modules + wxModuleList::compatibility_iterator node; + for ( node = m_modules.GetFirst(); node; node = node->GetNext() ) { - if (!((wxModule*)(node->Data()))->Init()) - return FALSE; + wxModule *module = node->GetData(); + if ( !module->Init() ) + { + wxLogError(_("Module \"%s\" initialization failed"), + module->GetClassInfo()->GetClassName()); + + // clean up already initialized modules - process in reverse order + wxModuleList::compatibility_iterator n; + for ( n = node->GetPrevious(); n; n = n->GetPrevious() ) + { + n->GetData()->OnExit(); + } + + return false; + } } - return TRUE; + + return true; } -void wxModule::CleanUpModules(void) +void wxModule::CleanUpModules() { - // Cleanup user-defined modules - for(wxNode* node = m_modules.Last(); node; node = node->Previous()) + // Cleanup user-defined modules + wxModuleList::compatibility_iterator node; + for ( node = m_modules.GetFirst(); node; node = node->GetNext() ) { - ((wxModule*)(node->Data()))->Exit(); - delete (wxModule*)(node->Data()); + wxLogTrace(TRACE_MODULE, wxT("Cleanup module %s"), + node->GetData()->GetClassInfo()->GetClassName()); + node->GetData()->Exit(); } - m_modules.Clear(); + + WX_CLEAR_LIST(wxModuleList, m_modules); }