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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "module.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/module.h"
27 #include "wx/listimpl.cpp"
29 WX_DEFINE_LIST(wxModuleList
);
31 IMPLEMENT_CLASS(wxModule
, wxObject
)
33 wxModuleList
wxModule::m_modules
;
35 void wxModule::RegisterModule(wxModule
* module)
37 m_modules
.Append(module);
40 void wxModule::UnregisterModule(wxModule
* module)
42 m_modules
.DeleteObject(module);
46 // Collect up all module-derived classes, create an instance of each,
48 void wxModule::RegisterModules()
50 wxHashTable::compatibility_iterator node
;
51 wxClassInfo
* classInfo
;
53 wxClassInfo::sm_classTable
->BeginFind();
54 node
= wxClassInfo::sm_classTable
->Next();
57 classInfo
= (wxClassInfo
*)node
->GetData();
58 if ( classInfo
->IsKindOf(CLASSINFO(wxModule
)) &&
59 (classInfo
!= (& (wxModule::ms_classInfo
))) )
61 wxModule
* module = (wxModule
*)classInfo
->CreateObject();
62 RegisterModule(module);
64 node
= wxClassInfo::sm_classTable
->Next();
68 bool wxModule::InitializeModules()
70 // Initialize user-defined modules
71 wxModuleList::compatibility_iterator node
;
72 for ( node
= m_modules
.GetFirst(); node
; node
= node
->GetNext() )
74 wxModule
*module = node
->GetData();
75 if ( !module->Init() )
77 wxLogError(_("Module \"%s\" initialization failed"),
78 module->GetClassInfo()->GetClassName());
80 // clean up already initialized modules - process in reverse order
81 wxModuleList::compatibility_iterator n
;
82 for ( n
= node
->GetPrevious(); n
; n
= n
->GetPrevious() )
84 n
->GetData()->OnExit();
94 void wxModule::CleanUpModules()
96 // Cleanup user-defined modules
97 wxModuleList::compatibility_iterator node
;
98 for ( node
= m_modules
.GetFirst(); node
; node
= node
->GetNext() )
100 node
->GetData()->Exit();
103 WX_CLEAR_LIST(wxModuleList
, m_modules
);