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