]> git.saurik.com Git - wxWidgets.git/blob - src/common/module.cpp
Include wx/hash.h according to precompiled headers of wx/wx.h (with other minor clean...
[wxWidgets.git] / src / common / module.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
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 #ifndef WX_PRECOMP
20 #include "wx/hash.h"
21 #endif
22
23 #include "wx/module.h"
24 #include "wx/intl.h"
25 #include "wx/log.h"
26 #include "wx/listimpl.cpp"
27
28 #define TRACE_MODULE _T("module")
29
30 WX_DEFINE_LIST(wxModuleList)
31
32 IMPLEMENT_CLASS(wxModule, wxObject)
33
34 wxModuleList wxModule::m_modules;
35
36 void wxModule::RegisterModule(wxModule* module)
37 {
38 m_modules.Append(module);
39 }
40
41 void wxModule::UnregisterModule(wxModule* module)
42 {
43 m_modules.DeleteObject(module);
44 delete module;
45 }
46
47 // Collect up all module-derived classes, create an instance of each,
48 // and register them.
49 void wxModule::RegisterModules()
50 {
51 wxHashTable::compatibility_iterator node;
52 wxClassInfo* classInfo;
53
54 wxClassInfo::sm_classTable->BeginFind();
55 node = wxClassInfo::sm_classTable->Next();
56 while (node)
57 {
58 classInfo = (wxClassInfo *)node->GetData();
59 if ( classInfo->IsKindOf(CLASSINFO(wxModule)) &&
60 (classInfo != (& (wxModule::ms_classInfo))) )
61 {
62 wxLogTrace(TRACE_MODULE, wxT("Registering module %s"),
63 classInfo->GetClassName());
64 wxModule* module = (wxModule *)classInfo->CreateObject();
65 RegisterModule(module);
66 }
67 node = wxClassInfo::sm_classTable->Next();
68 }
69 }
70
71 bool wxModule::InitializeModules()
72 {
73 // Initialize user-defined modules
74 wxModuleList::compatibility_iterator node;
75 for ( node = m_modules.GetFirst(); node; node = node->GetNext() )
76 {
77 wxModule *module = node->GetData();
78 if ( !module->Init() )
79 {
80 wxLogError(_("Module \"%s\" initialization failed"),
81 module->GetClassInfo()->GetClassName());
82
83 // clean up already initialized modules - process in reverse order
84 wxModuleList::compatibility_iterator n;
85 for ( n = node->GetPrevious(); n; n = n->GetPrevious() )
86 {
87 n->GetData()->OnExit();
88 }
89
90 return false;
91 }
92 }
93
94 return true;
95 }
96
97 void wxModule::CleanUpModules()
98 {
99 // Cleanup user-defined modules
100 wxModuleList::compatibility_iterator node;
101 for ( node = m_modules.GetFirst(); node; node = node->GetNext() )
102 {
103 wxLogTrace(TRACE_MODULE, wxT("Cleanup module %s"),
104 node->GetData()->GetClassInfo()->GetClassName());
105 node->GetData()->Exit();
106 }
107
108 WX_CLEAR_LIST(wxModuleList, m_modules);
109 }