]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/module.h
A couple of fixes for wxChm
[wxWidgets.git] / interface / wx / module.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: module.h
e54c96f1 3// Purpose: interface of wxModule
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
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
ba1d7a6c 17 wxModule::OnInit and wxModule::OnExit functions, and add the
b19b28c8 18 wxDECLARE_DYNAMIC_CLASS and wxIMPLEMENT_DYNAMIC_CLASS to header and implementation
ba1d7a6c
FM
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.
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 28 @code
ba1d7a6c 29 // A module to allow DDE initialization/cleanup
23324ae1
FM
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 39 private:
b19b28c8 40 wxDECLARE_DYNAMIC_CLASS(wxDDEModule);
23324ae1 41 };
7c913512 42
b19b28c8 43 wxIMPLEMENT_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:
b19b28c8 49 MyModule() { AddDependency(wxCLASSINFO(wxDDEModule)); }
23324ae1
FM
50 virtual bool OnInit() { ... code using DDE ... }
51 virtual void OnExit() { ... }
7c913512 52
23324ae1 53 private:
b19b28c8 54 wxDECLARE_DYNAMIC_CLASS(MyModule);
23324ae1 55 };
7c913512 56
b19b28c8 57 wxIMPLEMENT_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 68 private:
b19b28c8 69 wxDECLARE_DYNAMIC_CLASS(MyModule2)
23324ae1 70 };
7c913512 71
b19b28c8 72 wxIMPLEMENT_DYNAMIC_CLASS(MyModule2, wxModule)
23324ae1 73 @endcode
7c913512 74
23324ae1 75 @library{wxbase}
3c99e2fd 76 @category{appmanagement}
23324ae1
FM
77*/
78class wxModule : public wxObject
79{
80public:
81 /**
82 Constructs a wxModule object.
83 */
84 wxModule();
85
86 /**
87 Destructor.
88 */
adaaa686 89 virtual ~wxModule();
23324ae1 90
5e6e278d
FM
91 /**
92 Provide this function with appropriate cleanup for your module.
93 */
94 virtual void OnExit() = 0;
95
96 /**
97 Provide this function with appropriate initialization for your module.
98 If the function returns @false, wxWidgets will exit immediately.
99 */
100 virtual bool OnInit() = 0;
101
102protected:
103
23324ae1 104 /**
ba1d7a6c
FM
105 Call this function from the constructor of the derived class.
106
b19b28c8 107 @a dep must be the wxCLASSINFO() of a wxModule-derived class and the
ba1d7a6c 108 corresponding module will be loaded before and unloaded after this module.
3c4f71cc 109
7c913512 110 @param dep
4cc4bfaf 111 The class information object for the dependent module.
ba1d7a6c
FM
112 */
113 void AddDependency(wxClassInfo* dep);
114
115 /**
116 Call this function from the constructor of the derived class.
117
118 This overload allows a dependency to be added by name without access to
119 the class info.
120
121 This is useful when a module is declared entirely in a source file and
b19b28c8 122 there is no header for the declaration of the module needed by wxCLASSINFO(),
ba1d7a6c
FM
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.
125
7c913512 126 @param classname
4cc4bfaf 127 The class name of the dependent module.
23324ae1 128 */
4cc4bfaf 129 void AddDependency(const char* classname);
23324ae1 130};
e54c96f1 131