]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/module.tex
Typo fix
[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:
41 wxDDEModule() { AddDependency(CLASSINFO(wxDDEModule)); }
42 virtual bool OnInit() { ... code using DDE ... }
43 virtual void OnExit() { ... }
44
45 private:
46 DECLARE_DYNAMIC_CLASS(wxDDEModule)
47 };
e2a6f233
JS
48\end{verbatim}
49
a660d684
KB
50\wxheading{Derived from}
51
52\helpref{wxObject}{wxobject}
53
954b8ae6
JS
54\wxheading{Include files}
55
56<wx/module.h>
57
a7af285d
VZ
58\wxheading{Library}
59
60\helpref{wxBase}{librarieslist}
61
a660d684
KB
62\latexignore{\rtfignore{\wxheading{Members}}}
63
af266e5b 64
3e79fa75 65\membersection{wxModule::wxModule}\label{wxmodulector}
a660d684
KB
66
67\func{}{wxModule}{\void}
68
69Constructs a wxModule object.
70
af266e5b 71
3e79fa75 72\membersection{wxModule::\destruct{wxModule}}\label{wxmoduledtor}
a660d684
KB
73
74\func{}{\destruct{wxModule}}{\void}
75
76Destructor.
77
af266e5b
VZ
78
79\membersection{wxModule::AddDependency}\label{wxmoduleoninit}
80
81\func{void}{AddDependency}{\param{wxClassInfo * }{dep}}
82
83Call this function from the constructor of the derived class. \arg{dep} must be
84the \helpref{CLASSINFO}{classinfo} of a wxModule-derived class and the
85corresponding module will be loaded \emph{before} and unloaded \emph{after}
86this module.
87
88Note that circular dependencies are detected and result in a fatal error.
89
90\wxheading{Parameters}
91
92\docparam{dep}{The class information object for the dependent module.}
93
94
a660d684
KB
95\membersection{wxModule::OnExit}\label{wxmoduleonexit}
96
dfad0599 97\func{virtual void}{OnExit}{\void}
a660d684
KB
98
99Provide this function with appropriate cleanup for your module.
100
af266e5b 101
a660d684
KB
102\membersection{wxModule::OnInit}\label{wxmoduleoninit}
103
104\func{virtual bool}{OnInit}{\void}
105
106Provide this function with appropriate initialization for your module. If the function
fc2171bd 107returns false, wxWidgets will exit immediately.
b67a86d5 108