]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: module.cpp | |
3 | // Purpose: Modules initialization/destruction | |
4 | // Author: Wolfram Gloger/adapted by Guilhem Lavaux | |
5 | // Modified by: | |
6 | // Created: 04/11/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Wolfram Gloger and Guilhem Lavaux | |
65571936 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
c801d85f KB |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #include "wx/module.h" | |
f4a8c29f | 20 | #include "wx/hash.h" |
34af753d | 21 | #include "wx/intl.h" |
642c0eda WS |
22 | #include "wx/log.h" |
23 | #include "wx/listimpl.cpp" | |
8aa4edd2 | 24 | |
4115960d | 25 | WX_DEFINE_LIST(wxModuleList) |
c801d85f KB |
26 | |
27 | IMPLEMENT_CLASS(wxModule, wxObject) | |
28 | ||
8aa4edd2 | 29 | wxModuleList wxModule::m_modules; |
c801d85f KB |
30 | |
31 | void wxModule::RegisterModule(wxModule* module) | |
32 | { | |
8aa4edd2 | 33 | m_modules.Append(module); |
c801d85f KB |
34 | } |
35 | ||
0b9ab0bd RL |
36 | void wxModule::UnregisterModule(wxModule* module) |
37 | { | |
38 | m_modules.DeleteObject(module); | |
df5168c4 | 39 | delete module; |
0b9ab0bd RL |
40 | } |
41 | ||
c801d85f KB |
42 | // Collect up all module-derived classes, create an instance of each, |
43 | // and register them. | |
8aa4edd2 | 44 | void wxModule::RegisterModules() |
c801d85f | 45 | { |
df5168c4 | 46 | wxHashTable::compatibility_iterator node; |
f4a8c29f GL |
47 | wxClassInfo* classInfo; |
48 | ||
0c32066b JS |
49 | wxClassInfo::sm_classTable->BeginFind(); |
50 | node = wxClassInfo::sm_classTable->Next(); | |
f4a8c29f | 51 | while (node) |
c801d85f | 52 | { |
b1d4dd7a | 53 | classInfo = (wxClassInfo *)node->GetData(); |
8aa4edd2 | 54 | if ( classInfo->IsKindOf(CLASSINFO(wxModule)) && |
c0db9626 | 55 | (classInfo != (& (wxModule::ms_classInfo))) ) |
c801d85f | 56 | { |
8aa4edd2 | 57 | wxModule* module = (wxModule *)classInfo->CreateObject(); |
c801d85f KB |
58 | RegisterModule(module); |
59 | } | |
0c32066b | 60 | node = wxClassInfo::sm_classTable->Next(); |
c801d85f | 61 | } |
c801d85f KB |
62 | } |
63 | ||
8aa4edd2 | 64 | bool wxModule::InitializeModules() |
c801d85f | 65 | { |
8aa4edd2 | 66 | // Initialize user-defined modules |
df5168c4 | 67 | wxModuleList::compatibility_iterator node; |
8aa4edd2 | 68 | for ( node = m_modules.GetFirst(); node; node = node->GetNext() ) |
c801d85f | 69 | { |
8c18c674 VZ |
70 | wxModule *module = node->GetData(); |
71 | if ( !module->Init() ) | |
8aa4edd2 | 72 | { |
8c18c674 VZ |
73 | wxLogError(_("Module \"%s\" initialization failed"), |
74 | module->GetClassInfo()->GetClassName()); | |
75 | ||
8aa4edd2 | 76 | // clean up already initialized modules - process in reverse order |
df5168c4 | 77 | wxModuleList::compatibility_iterator n; |
8aa4edd2 VZ |
78 | for ( n = node->GetPrevious(); n; n = n->GetPrevious() ) |
79 | { | |
80 | n->GetData()->OnExit(); | |
81 | } | |
82 | ||
4e32eea1 | 83 | return false; |
8aa4edd2 | 84 | } |
c801d85f | 85 | } |
8aa4edd2 | 86 | |
4e32eea1 | 87 | return true; |
c801d85f KB |
88 | } |
89 | ||
8aa4edd2 | 90 | void wxModule::CleanUpModules() |
c801d85f | 91 | { |
8aa4edd2 | 92 | // Cleanup user-defined modules |
df5168c4 | 93 | wxModuleList::compatibility_iterator node; |
8aa4edd2 | 94 | for ( node = m_modules.GetFirst(); node; node = node->GetNext() ) |
c801d85f | 95 | { |
8aa4edd2 | 96 | node->GetData()->Exit(); |
c801d85f | 97 | } |
8aa4edd2 | 98 | |
df5168c4 | 99 | WX_CLEAR_LIST(wxModuleList, m_modules); |
c801d85f KB |
100 | } |
101 |