]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/module.h
Make storing non-trivial data in wxThreadSpecificInfo possible.
[wxWidgets.git] / interface / wx / module.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: module.h
e54c96f1 3// Purpose: interface of wxModule
23324ae1 4// Author: wxWidgets team
526954c5 5// Licence: wxWindows licence
23324ae1
FM
6/////////////////////////////////////////////////////////////////////////////
7
8/**
9 @class wxModule
7c913512 10
23324ae1
FM
11 The module system is a very simple mechanism to allow applications (and parts
12 of wxWidgets itself) to define initialization and cleanup functions that are
13 automatically called on wxWidgets startup and exit.
7c913512 14
23324ae1 15 To define a new kind of module, derive a class from wxModule, override the
ba1d7a6c 16 wxModule::OnInit and wxModule::OnExit functions, and add the
b19b28c8 17 wxDECLARE_DYNAMIC_CLASS and wxIMPLEMENT_DYNAMIC_CLASS to header and implementation
ba1d7a6c
FM
18 files (which can be the same file).
19 On initialization, wxWidgets will find all classes derived from wxModule, create
20 an instance of each, and call each wxModule::OnInit function. On exit, wxWidgets
21 will call the wxModule::OnExit function for each module instance.
7c913512 22
23324ae1 23 Note that your module class does not have to be in a header file.
7c913512 24
23324ae1 25 For example:
7c913512 26
23324ae1 27 @code
ba1d7a6c 28 // A module to allow DDE initialization/cleanup
23324ae1
FM
29 // without calling these functions from app.cpp or from
30 // the user's application.
31 class wxDDEModule: public wxModule
32 {
33 public:
34 wxDDEModule() { }
6bfc18d0 35 virtual bool OnInit() { wxDDEInitialize(); return true; };
23324ae1 36 virtual void OnExit() { wxDDECleanUp(); };
7c913512 37
23324ae1 38 private:
b19b28c8 39 wxDECLARE_DYNAMIC_CLASS(wxDDEModule);
23324ae1 40 };
7c913512 41
b19b28c8 42 wxIMPLEMENT_DYNAMIC_CLASS(wxDDEModule, wxModule);
7c913512 43
23324ae1
FM
44 // Another module which uses DDE in its OnInit()
45 class MyModule: public wxModule
46 {
47 public:
b19b28c8 48 MyModule() { AddDependency(wxCLASSINFO(wxDDEModule)); }
23324ae1
FM
49 virtual bool OnInit() { ... code using DDE ... }
50 virtual void OnExit() { ... }
7c913512 51
23324ae1 52 private:
b19b28c8 53 wxDECLARE_DYNAMIC_CLASS(MyModule);
23324ae1 54 };
7c913512 55
b19b28c8 56 wxIMPLEMENT_DYNAMIC_CLASS(MyModule, wxModule);
7c913512 57
23324ae1
FM
58 // Another module which uses DDE in its OnInit()
59 // but uses a named dependency
60 class MyModule2: public wxModule
61 {
62 public:
63 MyModule2() { AddDependency("wxDDEModule"); }
64 virtual bool OnInit() { ... code using DDE ... }
65 virtual void OnExit() { ... }
7c913512 66
23324ae1 67 private:
b19b28c8 68 wxDECLARE_DYNAMIC_CLASS(MyModule2)
23324ae1 69 };
7c913512 70
b19b28c8 71 wxIMPLEMENT_DYNAMIC_CLASS(MyModule2, wxModule)
23324ae1 72 @endcode
7c913512 73
23324ae1 74 @library{wxbase}
3c99e2fd 75 @category{appmanagement}
23324ae1
FM
76*/
77class wxModule : public wxObject
78{
79public:
80 /**
81 Constructs a wxModule object.
82 */
83 wxModule();
84
85 /**
86 Destructor.
87 */
adaaa686 88 virtual ~wxModule();
23324ae1 89
5e6e278d
FM
90 /**
91 Provide this function with appropriate cleanup for your module.
92 */
93 virtual void OnExit() = 0;
94
95 /**
96 Provide this function with appropriate initialization for your module.
97 If the function returns @false, wxWidgets will exit immediately.
98 */
99 virtual bool OnInit() = 0;
100
101protected:
102
23324ae1 103 /**
ba1d7a6c
FM
104 Call this function from the constructor of the derived class.
105
b19b28c8 106 @a dep must be the wxCLASSINFO() of a wxModule-derived class and the
ba1d7a6c 107 corresponding module will be loaded before and unloaded after this module.
3c4f71cc 108
7c913512 109 @param dep
4cc4bfaf 110 The class information object for the dependent module.
ba1d7a6c
FM
111 */
112 void AddDependency(wxClassInfo* dep);
113
114 /**
115 Call this function from the constructor of the derived class.
116
117 This overload allows a dependency to be added by name without access to
118 the class info.
119
120 This is useful when a module is declared entirely in a source file and
b19b28c8 121 there is no header for the declaration of the module needed by wxCLASSINFO(),
ba1d7a6c
FM
122 however errors are not detected until run-time, instead of compile-time, then.
123 Note that circular dependencies are detected and result in a fatal error.
124
7c913512 125 @param classname
4cc4bfaf 126 The class name of the dependent module.
23324ae1 127 */
4cc4bfaf 128 void AddDependency(const char* classname);
23324ae1 129};
e54c96f1 130