]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/module.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxModule
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
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.
16 To define a new kind of module, derive a class from wxModule, override the
17 wxModule::OnInit and wxModule::OnExit functions, and add the
18 wxDECLARE_DYNAMIC_CLASS and wxIMPLEMENT_DYNAMIC_CLASS to header and implementation
19 files (which can be the same file).
20 On initialization, wxWidgets will find all classes derived from wxModule, create
21 an instance of each, and call each wxModule::OnInit function. On exit, wxWidgets
22 will call the wxModule::OnExit function for each module instance.
24 Note that your module class does not have to be in a header file.
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
36 virtual bool OnInit() { wxDDEInitialize(); return true; };
37 virtual void OnExit() { wxDDECleanUp(); };
40 wxDECLARE_DYNAMIC_CLASS(wxDDEModule);
43 wxIMPLEMENT_DYNAMIC_CLASS(wxDDEModule, wxModule);
45 // Another module which uses DDE in its OnInit()
46 class MyModule: public wxModule
49 MyModule() { AddDependency(wxCLASSINFO(wxDDEModule)); }
50 virtual bool OnInit() { ... code using DDE ... }
51 virtual void OnExit() { ... }
54 wxDECLARE_DYNAMIC_CLASS(MyModule);
57 wxIMPLEMENT_DYNAMIC_CLASS(MyModule, wxModule);
59 // Another module which uses DDE in its OnInit()
60 // but uses a named dependency
61 class MyModule2: public wxModule
64 MyModule2() { AddDependency("wxDDEModule"); }
65 virtual bool OnInit() { ... code using DDE ... }
66 virtual void OnExit() { ... }
69 wxDECLARE_DYNAMIC_CLASS(MyModule2)
72 wxIMPLEMENT_DYNAMIC_CLASS(MyModule2, wxModule)
76 @category{appmanagement}
78 class wxModule
: public wxObject
82 Constructs a wxModule object.
92 Provide this function with appropriate cleanup for your module.
94 virtual void OnExit() = 0;
97 Provide this function with appropriate initialization for your module.
98 If the function returns @false, wxWidgets will exit immediately.
100 virtual bool OnInit() = 0;
105 Call this function from the constructor of the derived class.
107 @a dep must be the wxCLASSINFO() of a wxModule-derived class and the
108 corresponding module will be loaded before and unloaded after this module.
111 The class information object for the dependent module.
113 void AddDependency(wxClassInfo
* dep
);
116 Call this function from the constructor of the derived class.
118 This overload allows a dependency to be added by name without access to
121 This is useful when a module is declared entirely in a source file and
122 there is no header for the declaration of the module needed by wxCLASSINFO(),
123 however errors are not detected until run-time, instead of compile-time, then.
124 Note that circular dependencies are detected and result in a fatal error.
127 The class name of the dependent module.
129 void AddDependency(const char* classname
);