]> git.saurik.com Git - wxWidgets.git/blame - src/common/module.cpp
fixed typo in wxString::swap() which was completely broken
[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
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
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
ce3ed50d
JS
27#ifdef __SALFORDC__
28void wxwxModuleListNode::DeleteData()
29{
30 delete (_WX_LIST_ITEM_TYPE_wxModuleList *)GetData();
31}
32#else
8aa4edd2 33WX_DEFINE_LIST(wxModuleList);
ce3ed50d 34#endif
c801d85f
KB
35
36IMPLEMENT_CLASS(wxModule, wxObject)
37
8aa4edd2 38wxModuleList wxModule::m_modules;
c801d85f
KB
39
40void wxModule::RegisterModule(wxModule* module)
41{
8aa4edd2 42 m_modules.Append(module);
c801d85f
KB
43}
44
0b9ab0bd
RL
45void wxModule::UnregisterModule(wxModule* module)
46{
47 m_modules.DeleteObject(module);
48}
49
c801d85f
KB
50// Collect up all module-derived classes, create an instance of each,
51// and register them.
8aa4edd2 52void wxModule::RegisterModules()
c801d85f 53{
f4a8c29f
GL
54 wxNode *node;
55 wxClassInfo* classInfo;
56
0c32066b
JS
57 wxClassInfo::sm_classTable->BeginFind();
58 node = wxClassInfo::sm_classTable->Next();
f4a8c29f 59 while (node)
c801d85f 60 {
f4a8c29f 61 classInfo = (wxClassInfo *)node->Data();
8aa4edd2
VZ
62 if ( classInfo->IsKindOf(CLASSINFO(wxModule)) &&
63 (classInfo != (& (wxModule::sm_classwxModule))) )
c801d85f 64 {
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
VZ
74 // Initialize user-defined modules
75 wxModuleList::Node *node;
76 for ( node = m_modules.GetFirst(); node; node = node->GetNext() )
c801d85f 77 {
8aa4edd2
VZ
78 if ( !node->GetData()->Init() )
79 {
80 // clean up already initialized modules - process in reverse order
81 wxModuleList::Node *n;
82 for ( n = node->GetPrevious(); n; n = n->GetPrevious() )
83 {
84 n->GetData()->OnExit();
85 }
86
87 return FALSE;
88 }
c801d85f 89 }
8aa4edd2 90
c801d85f
KB
91 return TRUE;
92}
93
8aa4edd2 94void wxModule::CleanUpModules()
c801d85f 95{
8aa4edd2
VZ
96 // Cleanup user-defined modules
97 wxModuleList::Node *node;
98 for ( node = m_modules.GetFirst(); node; node = node->GetNext() )
c801d85f 99 {
8aa4edd2 100 node->GetData()->Exit();
c801d85f 101 }
8aa4edd2
VZ
102
103 m_modules.DeleteContents(TRUE);
c801d85f
KB
104 m_modules.Clear();
105}
106