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