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