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