]> git.saurik.com Git - wxWidgets.git/blame - src/common/module.cpp
Hopefully fixed library names generated by wx-config for OS/2's PM port.
[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
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
c801d85f
KB
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"
f4a8c29f 24#include "wx/hash.h"
34af753d 25#include "wx/intl.h"
642c0eda
WS
26#include "wx/log.h"
27#include "wx/listimpl.cpp"
8aa4edd2
VZ
28
29WX_DEFINE_LIST(wxModuleList);
c801d85f
KB
30
31IMPLEMENT_CLASS(wxModule, wxObject)
32
8aa4edd2 33wxModuleList wxModule::m_modules;
c801d85f
KB
34
35void wxModule::RegisterModule(wxModule* module)
36{
8aa4edd2 37 m_modules.Append(module);
c801d85f
KB
38}
39
0b9ab0bd
RL
40void wxModule::UnregisterModule(wxModule* module)
41{
42 m_modules.DeleteObject(module);
df5168c4 43 delete module;
0b9ab0bd
RL
44}
45
c801d85f
KB
46// Collect up all module-derived classes, create an instance of each,
47// and register them.
8aa4edd2 48void wxModule::RegisterModules()
c801d85f 49{
df5168c4 50 wxHashTable::compatibility_iterator node;
f4a8c29f
GL
51 wxClassInfo* classInfo;
52
0c32066b
JS
53 wxClassInfo::sm_classTable->BeginFind();
54 node = wxClassInfo::sm_classTable->Next();
f4a8c29f 55 while (node)
c801d85f 56 {
b1d4dd7a 57 classInfo = (wxClassInfo *)node->GetData();
8aa4edd2 58 if ( classInfo->IsKindOf(CLASSINFO(wxModule)) &&
c0db9626 59 (classInfo != (& (wxModule::ms_classInfo))) )
c801d85f 60 {
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 {
8aa4edd2 100 node->GetData()->Exit();
c801d85f 101 }
8aa4edd2 102
df5168c4 103 WX_CLEAR_LIST(wxModuleList, m_modules);
c801d85f
KB
104}
105