]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
32d4c30a | 2 | // Name: src/common/module.cpp |
c801d85f KB |
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__ | |
32d4c30a WS |
16 | #pragma hdrstop |
17 | #endif | |
18 | ||
19 | #ifndef WX_PRECOMP | |
20 | #include "wx/hash.h" | |
c801d85f KB |
21 | #endif |
22 | ||
23 | #include "wx/module.h" | |
34af753d | 24 | #include "wx/intl.h" |
642c0eda WS |
25 | #include "wx/log.h" |
26 | #include "wx/listimpl.cpp" | |
8aa4edd2 | 27 | |
3b96fc2f MB |
28 | #define TRACE_MODULE _T("module") |
29 | ||
4115960d | 30 | WX_DEFINE_LIST(wxModuleList) |
c801d85f KB |
31 | |
32 | IMPLEMENT_CLASS(wxModule, wxObject) | |
33 | ||
8aa4edd2 | 34 | wxModuleList wxModule::m_modules; |
c801d85f KB |
35 | |
36 | void wxModule::RegisterModule(wxModule* module) | |
37 | { | |
8aa4edd2 | 38 | m_modules.Append(module); |
c801d85f KB |
39 | } |
40 | ||
0b9ab0bd RL |
41 | void wxModule::UnregisterModule(wxModule* module) |
42 | { | |
43 | m_modules.DeleteObject(module); | |
df5168c4 | 44 | delete module; |
0b9ab0bd RL |
45 | } |
46 | ||
c801d85f KB |
47 | // Collect up all module-derived classes, create an instance of each, |
48 | // and register them. | |
8aa4edd2 | 49 | void wxModule::RegisterModules() |
c801d85f | 50 | { |
df5168c4 | 51 | wxHashTable::compatibility_iterator node; |
f4a8c29f GL |
52 | wxClassInfo* classInfo; |
53 | ||
0c32066b JS |
54 | wxClassInfo::sm_classTable->BeginFind(); |
55 | node = wxClassInfo::sm_classTable->Next(); | |
f4a8c29f | 56 | while (node) |
c801d85f | 57 | { |
b1d4dd7a | 58 | classInfo = (wxClassInfo *)node->GetData(); |
8aa4edd2 | 59 | if ( classInfo->IsKindOf(CLASSINFO(wxModule)) && |
c0db9626 | 60 | (classInfo != (& (wxModule::ms_classInfo))) ) |
c801d85f | 61 | { |
3b96fc2f MB |
62 | wxLogTrace(TRACE_MODULE, wxT("Registering module %s"), |
63 | classInfo->GetClassName()); | |
8aa4edd2 | 64 | wxModule* module = (wxModule *)classInfo->CreateObject(); |
c801d85f KB |
65 | RegisterModule(module); |
66 | } | |
0c32066b | 67 | node = wxClassInfo::sm_classTable->Next(); |
c801d85f | 68 | } |
c801d85f KB |
69 | } |
70 | ||
8aa4edd2 | 71 | bool wxModule::InitializeModules() |
c801d85f | 72 | { |
8aa4edd2 | 73 | // Initialize user-defined modules |
df5168c4 | 74 | wxModuleList::compatibility_iterator node; |
8aa4edd2 | 75 | for ( node = m_modules.GetFirst(); node; node = node->GetNext() ) |
c801d85f | 76 | { |
8c18c674 VZ |
77 | wxModule *module = node->GetData(); |
78 | if ( !module->Init() ) | |
8aa4edd2 | 79 | { |
8c18c674 VZ |
80 | wxLogError(_("Module \"%s\" initialization failed"), |
81 | module->GetClassInfo()->GetClassName()); | |
82 | ||
8aa4edd2 | 83 | // clean up already initialized modules - process in reverse order |
df5168c4 | 84 | wxModuleList::compatibility_iterator n; |
8aa4edd2 VZ |
85 | for ( n = node->GetPrevious(); n; n = n->GetPrevious() ) |
86 | { | |
87 | n->GetData()->OnExit(); | |
88 | } | |
89 | ||
4e32eea1 | 90 | return false; |
8aa4edd2 | 91 | } |
c801d85f | 92 | } |
8aa4edd2 | 93 | |
4e32eea1 | 94 | return true; |
c801d85f KB |
95 | } |
96 | ||
8aa4edd2 | 97 | void wxModule::CleanUpModules() |
c801d85f | 98 | { |
8aa4edd2 | 99 | // Cleanup user-defined modules |
df5168c4 | 100 | wxModuleList::compatibility_iterator node; |
8aa4edd2 | 101 | for ( node = m_modules.GetFirst(); node; node = node->GetNext() ) |
c801d85f | 102 | { |
3b96fc2f MB |
103 | wxLogTrace(TRACE_MODULE, wxT("Cleanup module %s"), |
104 | node->GetData()->GetClassInfo()->GetClassName()); | |
8aa4edd2 | 105 | node->GetData()->Exit(); |
c801d85f | 106 | } |
8aa4edd2 | 107 | |
df5168c4 | 108 | WX_CLEAR_LIST(wxModuleList, m_modules); |
c801d85f | 109 | } |