1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Modules initialization/destruction
4 // Author: Wolfram Gloger/adapted by Guilhem Lavaux
8 // Copyright: (c) Wolfram Gloger and Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/module.h"
23 #include "wx/listimpl.cpp"
25 WX_DEFINE_LIST(wxModuleList
)
27 IMPLEMENT_CLASS(wxModule
, wxObject
)
29 wxModuleList
wxModule::m_modules
;
31 void wxModule::RegisterModule(wxModule
* module)
33 m_modules
.Append(module);
36 void wxModule::UnregisterModule(wxModule
* module)
38 m_modules
.DeleteObject(module);
42 // Collect up all module-derived classes, create an instance of each,
44 void wxModule::RegisterModules()
46 wxHashTable::compatibility_iterator node
;
47 wxClassInfo
* classInfo
;
49 wxClassInfo::sm_classTable
->BeginFind();
50 node
= wxClassInfo::sm_classTable
->Next();
53 classInfo
= (wxClassInfo
*)node
->GetData();
54 if ( classInfo
->IsKindOf(CLASSINFO(wxModule
)) &&
55 (classInfo
!= (& (wxModule::ms_classInfo
))) )
57 wxModule
* module = (wxModule
*)classInfo
->CreateObject();
58 RegisterModule(module);
60 node
= wxClassInfo::sm_classTable
->Next();
64 bool wxModule::InitializeModules()
66 // Initialize user-defined modules
67 wxModuleList::compatibility_iterator node
;
68 for ( node
= m_modules
.GetFirst(); node
; node
= node
->GetNext() )
70 wxModule
*module = node
->GetData();
71 if ( !module->Init() )
73 wxLogError(_("Module \"%s\" initialization failed"),
74 module->GetClassInfo()->GetClassName());
76 // clean up already initialized modules - process in reverse order
77 wxModuleList::compatibility_iterator n
;
78 for ( n
= node
->GetPrevious(); n
; n
= n
->GetPrevious() )
80 n
->GetData()->OnExit();
90 void wxModule::CleanUpModules()
92 // Cleanup user-defined modules
93 wxModuleList::compatibility_iterator node
;
94 for ( node
= m_modules
.GetFirst(); node
; node
= node
->GetNext() )
96 node
->GetData()->Exit();
99 WX_CLEAR_LIST(wxModuleList
, m_modules
);