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