X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0c32066b58849e52e4d76e30982414d9f4daae6a..745e6cb9151321982f68ce37c11bbb7e8ad990a6:/src/common/module.cpp diff --git a/src/common/module.cpp b/src/common/module.cpp index b18af89b14..0853642073 100644 --- a/src/common/module.cpp +++ b/src/common/module.cpp @@ -22,19 +22,34 @@ #include "wx/module.h" #include "wx/hash.h" +#include "wx/listimpl.cpp" + +#ifdef __SALFORDC__ +void wxwxModuleListNode::DeleteData() +{ + delete (_WX_LIST_ITEM_TYPE_wxModuleList *)GetData(); +} +#else +WX_DEFINE_LIST(wxModuleList); +#endif 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); } // Collect up all module-derived classes, create an instance of each, // and register them. -bool wxModule::RegisterModules(void) +void wxModule::RegisterModules() { wxNode *node; wxClassInfo* classInfo; @@ -44,36 +59,48 @@ bool wxModule::RegisterModules(void) while (node) { classInfo = (wxClassInfo *)node->Data(); - if ((classInfo != (& (wxModule::sm_classwxModule))) && - classInfo->IsKindOf(CLASSINFO(wxModule))) + if ( classInfo->IsKindOf(CLASSINFO(wxModule)) && + (classInfo != (& (wxModule::sm_classwxModule))) ) { - wxModule* module = (wxModule*) classInfo->CreateObject(); + wxModule* module = (wxModule *)classInfo->CreateObject(); RegisterModule(module); } 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::Node *node; + for ( node = m_modules.GetFirst(); node; node = node->GetNext() ) { - if (!((wxModule*)(node->Data()))->Init()) - return FALSE; + if ( !node->GetData()->Init() ) + { + // clean up already initialized modules - process in reverse order + wxModuleList::Node *n; + for ( n = node->GetPrevious(); n; n = n->GetPrevious() ) + { + n->GetData()->OnExit(); + } + + return FALSE; + } } + 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::Node *node; + for ( node = m_modules.GetFirst(); node; node = node->GetNext() ) { - ((wxModule*)(node->Data()))->Exit(); - delete (wxModule*)(node->Data()); + node->GetData()->Exit(); } + + m_modules.DeleteContents(TRUE); m_modules.Clear(); }