]> git.saurik.com Git - wxWidgets.git/blob - include/wx/module.h
Some code renaming to avoid confusion. Test editable column in sample.
[wxWidgets.git] / include / wx / module.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/module.h
3 // Purpose: Modules handling
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 #ifndef _WX_MODULE_H_
13 #define _WX_MODULE_H_
14
15 #include "wx/object.h"
16 #include "wx/list.h"
17 #include "wx/dynarray.h"
18
19 // declare a linked list of modules
20 class WXDLLIMPEXP_FWD_BASE wxModule;
21 WX_DECLARE_USER_EXPORTED_LIST(wxModule, wxModuleList, WXDLLIMPEXP_BASE);
22
23 // and an array of class info objects
24 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxClassInfo *, wxArrayClassInfo,
25 class WXDLLIMPEXP_BASE);
26
27
28 // declaring a class derived from wxModule will automatically create an
29 // instance of this class on program startup, call its OnInit() method and call
30 // OnExit() on program termination (but only if OnInit() succeeded)
31 class WXDLLIMPEXP_BASE wxModule : public wxObject
32 {
33 public:
34 wxModule() {}
35 virtual ~wxModule() {}
36
37 // if module init routine returns false the application
38 // will fail to startup
39
40 bool Init() { return OnInit(); }
41 void Exit() { OnExit(); }
42
43 // Override both of these
44
45 // called on program startup
46
47 virtual bool OnInit() = 0;
48
49 // called just before program termination, but only if OnInit()
50 // succeeded
51
52 virtual void OnExit() = 0;
53
54 static void RegisterModule(wxModule *module);
55 static void RegisterModules();
56 static bool InitializeModules();
57 static void CleanUpModules() { DoCleanUpModules(m_modules); }
58
59 // used by wxObjectLoader when unloading shared libs's
60
61 static void UnregisterModule(wxModule *module);
62
63 protected:
64 static wxModuleList m_modules;
65
66 // the function to call from constructor of a deriving class add module
67 // dependency which will be initialized before the module and unloaded
68 // after that
69 void AddDependency(wxClassInfo *dep)
70 {
71 wxCHECK_RET( dep, _T("NULL module dependency") );
72
73 m_dependencies.Add(dep);
74 }
75
76 private:
77 // initialize module and Append it to initializedModules list recursively
78 // calling itself to satisfy module dependencies if needed
79 static bool
80 DoInitializeModule(wxModule *module, wxModuleList &initializedModules);
81
82 // cleanup the modules in the specified list (which may not contain all
83 // modules if we're called during initialization because not all modules
84 // could be initialized) and also empty m_modules itself
85 static void DoCleanUpModules(const wxModuleList& modules);
86
87
88 // module dependencies: contains
89 wxArrayClassInfo m_dependencies;
90
91 // used internally while initiliazing/cleaning up modules
92 enum
93 {
94 State_Registered, // module registered but not initialized yet
95 State_Initializing, // we're initializing this module but not done yet
96 State_Initialized // module initialized successfully
97 } m_state;
98
99
100 DECLARE_CLASS(wxModule)
101 };
102
103 #endif // _WX_MODULE_H_