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"
25 #include "wx/listimpl.cpp"
28 WX_DEFINE_LIST(wxModuleList
);
30 IMPLEMENT_CLASS(wxModule
, wxObject
)
32 wxModuleList
wxModule::m_modules
;
34 void wxModule::RegisterModule(wxModule
* module)
36 m_modules
.Append(module);
39 void wxModule::UnregisterModule(wxModule
* module)
41 m_modules
.DeleteObject(module);
45 // Collect up all module-derived classes, create an instance of each,
47 void wxModule::RegisterModules()
49 wxHashTable::compatibility_iterator node
;
50 wxClassInfo
* classInfo
;
52 wxClassInfo::sm_classTable
->BeginFind();
53 node
= wxClassInfo::sm_classTable
->Next();
56 classInfo
= (wxClassInfo
*)node
->GetData();
57 if ( classInfo
->IsKindOf(CLASSINFO(wxModule
)) &&
58 (classInfo
!= (& (wxModule::ms_classInfo
))) )
60 wxModule
* module = (wxModule
*)classInfo
->CreateObject();
61 RegisterModule(module);
63 node
= wxClassInfo::sm_classTable
->Next();
67 bool wxModule::InitializeModules()
69 // Initialize user-defined modules
70 wxModuleList::compatibility_iterator node
;
71 for ( node
= m_modules
.GetFirst(); node
; node
= node
->GetNext() )
73 wxModule
*module = node
->GetData();
74 if ( !module->Init() )
76 wxLogError(_("Module \"%s\" initialization failed"),
77 module->GetClassInfo()->GetClassName());
79 // clean up already initialized modules - process in reverse order
80 wxModuleList::compatibility_iterator n
;
81 for ( n
= node
->GetPrevious(); n
; n
= n
->GetPrevious() )
83 n
->GetData()->OnExit();
93 void wxModule::CleanUpModules()
95 // Cleanup user-defined modules
96 wxModuleList::compatibility_iterator node
;
97 for ( node
= m_modules
.GetFirst(); node
; node
= node
->GetNext() )
99 node
->GetData()->Exit();
102 WX_CLEAR_LIST(wxModuleList
, m_modules
);