]> git.saurik.com Git - wxWidgets.git/blame - include/wx/module.h
Better name for wxXmlResource::GetDirection() argument.
[wxWidgets.git] / include / wx / module.h
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
02761f6c 2// Name: wx/module.h
c801d85f
KB
3// Purpose: Modules handling
4// Author: Wolfram Gloger/adapted by Guilhem Lavaux
5// Modified by:
6// Created: 04/11/98
c801d85f 7// Copyright: (c) Wolfram Gloger and Guilhem Lavaux
65571936 8// Licence: wxWindows licence
c801d85f
KB
9/////////////////////////////////////////////////////////////////////////////
10
9945c703
DS
11#ifndef _WX_MODULE_H_
12#define _WX_MODULE_H_
c801d85f 13
c801d85f
KB
14#include "wx/object.h"
15#include "wx/list.h"
9a2534df 16#include "wx/arrstr.h"
af266e5b 17#include "wx/dynarray.h"
c801d85f 18
8aa4edd2 19// declare a linked list of modules
b5dbe15d 20class WXDLLIMPEXP_FWD_BASE wxModule;
4460b6c4 21WX_DECLARE_USER_EXPORTED_LIST(wxModule, wxModuleList, WXDLLIMPEXP_BASE);
8aa4edd2 22
af266e5b
VZ
23// and an array of class info objects
24WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxClassInfo *, wxArrayClassInfo,
25 class WXDLLIMPEXP_BASE);
26
27
8aa4edd2
VZ
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)
bddd7a8d 31class WXDLLIMPEXP_BASE wxModule : public wxObject
c801d85f
KB
32{
33public:
8aa4edd2
VZ
34 wxModule() {}
35 virtual ~wxModule() {}
c801d85f 36
9945c703
DS
37 // if module init routine returns false the application
38 // will fail to startup
0b9ab0bd 39
8aa4edd2
VZ
40 bool Init() { return OnInit(); }
41 void Exit() { OnExit(); }
c801d85f 42
9945c703
DS
43 // Override both of these
44
8aa4edd2 45 // called on program startup
0b9ab0bd 46
8aa4edd2 47 virtual bool OnInit() = 0;
0b9ab0bd 48
9945c703 49 // called just before program termination, but only if OnInit()
8aa4edd2 50 // succeeded
9945c703 51
8aa4edd2 52 virtual void OnExit() = 0;
c801d85f 53
9945c703 54 static void RegisterModule(wxModule *module);
8aa4edd2
VZ
55 static void RegisterModules();
56 static bool InitializeModules();
af266e5b 57 static void CleanUpModules() { DoCleanUpModules(m_modules); }
c801d85f 58
9945c703 59 // used by wxObjectLoader when unloading shared libs's
0b9ab0bd 60
9945c703 61 static void UnregisterModule(wxModule *module);
0b9ab0bd 62
c801d85f 63protected:
8aa4edd2 64 static wxModuleList m_modules;
c801d85f 65
af266e5b
VZ
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 {
9a83f860 71 wxCHECK_RET( dep, wxT("NULL module dependency") );
af266e5b
VZ
72
73 m_dependencies.Add(dep);
74 }
75
d04a9fdf
VZ
76 // same as the version above except it will look up wxClassInfo by name on
77 // its own
78 void AddDependency(const char *className)
79 {
80 m_namedDependencies.Add(className);
81 }
82
83
af266e5b
VZ
84private:
85 // initialize module and Append it to initializedModules list recursively
86 // calling itself to satisfy module dependencies if needed
87 static bool
88 DoInitializeModule(wxModule *module, wxModuleList &initializedModules);
89
90 // cleanup the modules in the specified list (which may not contain all
91 // modules if we're called during initialization because not all modules
92 // could be initialized) and also empty m_modules itself
93 static void DoCleanUpModules(const wxModuleList& modules);
94
d04a9fdf
VZ
95 // resolve all named dependencies and add them to the normal m_dependencies
96 bool ResolveNamedDependencies();
97
af266e5b 98
d04a9fdf
VZ
99 // module dependencies: contains wxClassInfo pointers for all modules which
100 // must be initialized before this one
af266e5b
VZ
101 wxArrayClassInfo m_dependencies;
102
d04a9fdf
VZ
103 // and the named dependencies: those will be resolved during run-time and
104 // added to m_dependencies
105 wxArrayString m_namedDependencies;
106
107 // used internally while initializing/cleaning up modules
af266e5b
VZ
108 enum
109 {
110 State_Registered, // module registered but not initialized yet
111 State_Initializing, // we're initializing this module but not done yet
112 State_Initialized // module initialized successfully
113 } m_state;
114
115
8aa4edd2 116 DECLARE_CLASS(wxModule)
c801d85f
KB
117};
118
9945c703 119#endif // _WX_MODULE_H_