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