]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/module.tex
better documentation for wxWindow::SetSizerAndFit()
[wxWidgets.git] / docs / latex / wx / module.tex
1 \section{\class{wxModule}}\label{wxmodule}
2
3 The module system is a very simple mechanism to allow applications (and parts
4 of wxWidgets itself) to define initialization and cleanup functions that are
5 automatically called on wxWidgets startup and exit.
6
7 To define a new kind of module, derive a class from wxModule, override the
8 \helpref{OnInit}{wxmoduleoninit} and \helpref{OnExit}{wxmoduleonexit}
9 functions, and add the DECLARE\_DYNAMIC\_CLASS and IMPLEMENT\_DYNAMIC\_CLASS to
10 header and implementation files (which can be the same file). On
11 initialization, wxWidgets will find all classes derived from wxModule, create
12 an instance of each, and call each OnInit function. On exit, wxWidgets will
13 call the OnExit function for each module instance.
14
15 Note that your module class does not have to be in a header file.
16
17 For example:
18
19 \begin{verbatim}
20 // A module to allow DDE initialization/cleanup
21 // without calling these functions from app.cpp or from
22 // the user's application.
23 class wxDDEModule: public wxModule
24 {
25 public:
26 wxDDEModule() { }
27 virtual bool OnInit() { wxDDEInitialize(); return true; };
28 virtual void OnExit() { wxDDECleanUp(); };
29
30 private:
31 DECLARE_DYNAMIC_CLASS(wxDDEModule)
32 };
33
34 IMPLEMENT_DYNAMIC_CLASS(wxDDEModule, wxModule)
35
36
37 // Another module which uses DDE in its OnInit()
38 class MyModule: public wxModule
39 {
40 public:
41 MyModule() { AddDependency(CLASSINFO(wxDDEModule)); }
42 virtual bool OnInit() { ... code using DDE ... }
43 virtual void OnExit() { ... }
44
45 private:
46 DECLARE_DYNAMIC_CLASS(MyModule)
47 };
48
49 IMPLEMENT_DYNAMIC_CLASS(MyModule, wxModule)
50
51 // Another module which uses DDE in its OnInit()
52 // but uses a named dependency
53 class MyModule2: public wxModule
54 {
55 public:
56 MyModule2() { AddDependency("wxDDEModule"); }
57 virtual bool OnInit() { ... code using DDE ... }
58 virtual void OnExit() { ... }
59
60 private:
61 DECLARE_DYNAMIC_CLASS(MyModule2)
62 };
63
64 IMPLEMENT_DYNAMIC_CLASS(MyModule2, wxModule)
65 \end{verbatim}
66
67 \wxheading{Derived from}
68
69 \helpref{wxObject}{wxobject}
70
71 \wxheading{Include files}
72
73 <wx/module.h>
74
75 \wxheading{Library}
76
77 \helpref{wxBase}{librarieslist}
78
79 \latexignore{\rtfignore{\wxheading{Members}}}
80
81
82 \membersection{wxModule::wxModule}\label{wxmodulector}
83
84 \func{}{wxModule}{\void}
85
86 Constructs a wxModule object.
87
88
89 \membersection{wxModule::\destruct{wxModule}}\label{wxmoduledtor}
90
91 \func{}{\destruct{wxModule}}{\void}
92
93 Destructor.
94
95
96 \membersection{wxModule::AddDependency}\label{wxmoduleadddependency}
97
98 \func{void}{AddDependency}{\param{wxClassInfo * }{dep}}
99
100 \func{void}{AddDependency}{\param{const char * }{classname}}
101
102 Call this function from the constructor of the derived class. \arg{dep} must be
103 the \helpref{CLASSINFO}{classinfo} of a wxModule-derived class and the
104 corresponding module will be loaded \emph{before} and unloaded \emph{after}
105 this module.
106
107 The second version of this function allows a dependency to be added by
108 name without access to the class info. This is useful when a module is
109 declared entirely in a source file and there is no header for the declaration
110 of the module needed by \helpref{CLASSINFO}{classinfo}, however errors are
111 not detected until run-time, instead of compile-time, then.
112
113 Note that circular dependencies are detected and result in a fatal error.
114
115 \wxheading{Parameters}
116
117 \docparam{dep}{The class information object for the dependent module.}
118
119 \docparam{classname}{The class name of the dependent module.}
120
121
122 \membersection{wxModule::OnExit}\label{wxmoduleonexit}
123
124 \func{virtual void}{OnExit}{\void}
125
126 Provide this function with appropriate cleanup for your module.
127
128
129 \membersection{wxModule::OnInit}\label{wxmoduleoninit}
130
131 \func{virtual bool}{OnInit}{\void}
132
133 Provide this function with appropriate initialization for your module. If the function
134 returns false, wxWidgets will exit immediately.
135