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