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