]> git.saurik.com Git - wxWidgets.git/blame - src/common/module.cpp
using separate imaglist on mac
[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"
8aa4edd2
VZ
25#include "wx/listimpl.cpp"
26
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 {
8aa4edd2 59 wxModule* module = (wxModule *)classInfo->CreateObject();
c801d85f
KB
60 RegisterModule(module);
61 }
0c32066b 62 node = wxClassInfo::sm_classTable->Next();
c801d85f 63 }
c801d85f
KB
64}
65
8aa4edd2 66bool wxModule::InitializeModules()
c801d85f 67{
8aa4edd2 68 // Initialize user-defined modules
df5168c4 69 wxModuleList::compatibility_iterator node;
8aa4edd2 70 for ( node = m_modules.GetFirst(); node; node = node->GetNext() )
c801d85f 71 {
8aa4edd2
VZ
72 if ( !node->GetData()->Init() )
73 {
74 // clean up already initialized modules - process in reverse order
df5168c4 75 wxModuleList::compatibility_iterator n;
8aa4edd2
VZ
76 for ( n = node->GetPrevious(); n; n = n->GetPrevious() )
77 {
78 n->GetData()->OnExit();
79 }
80
4e32eea1 81 return false;
8aa4edd2 82 }
c801d85f 83 }
8aa4edd2 84
4e32eea1 85 return true;
c801d85f
KB
86}
87
8aa4edd2 88void wxModule::CleanUpModules()
c801d85f 89{
8aa4edd2 90 // Cleanup user-defined modules
df5168c4 91 wxModuleList::compatibility_iterator node;
8aa4edd2 92 for ( node = m_modules.GetFirst(); node; node = node->GetNext() )
c801d85f 93 {
8aa4edd2 94 node->GetData()->Exit();
c801d85f 95 }
8aa4edd2 96
df5168c4 97 WX_CLEAR_LIST(wxModuleList, m_modules);
c801d85f
KB
98}
99