]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/module.tex
use explicit virtual keyword with overridden virtual methods
[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
a660d684
KB
58\latexignore{\rtfignore{\wxheading{Members}}}
59
af266e5b 60
3e79fa75 61\membersection{wxModule::wxModule}\label{wxmodulector}
a660d684
KB
62
63\func{}{wxModule}{\void}
64
65Constructs a wxModule object.
66
af266e5b 67
3e79fa75 68\membersection{wxModule::\destruct{wxModule}}\label{wxmoduledtor}
a660d684
KB
69
70\func{}{\destruct{wxModule}}{\void}
71
72Destructor.
73
af266e5b
VZ
74
75\membersection{wxModule::AddDependency}\label{wxmoduleoninit}
76
77\func{void}{AddDependency}{\param{wxClassInfo * }{dep}}
78
79Call this function from the constructor of the derived class. \arg{dep} must be
80the \helpref{CLASSINFO}{classinfo} of a wxModule-derived class and the
81corresponding module will be loaded \emph{before} and unloaded \emph{after}
82this module.
83
84Note that circular dependencies are detected and result in a fatal error.
85
86\wxheading{Parameters}
87
88\docparam{dep}{The class information object for the dependent module.}
89
90
a660d684
KB
91\membersection{wxModule::OnExit}\label{wxmoduleonexit}
92
dfad0599 93\func{virtual void}{OnExit}{\void}
a660d684
KB
94
95Provide this function with appropriate cleanup for your module.
96
af266e5b 97
a660d684
KB
98\membersection{wxModule::OnInit}\label{wxmoduleoninit}
99
100\func{virtual bool}{OnInit}{\void}
101
102Provide this function with appropriate initialization for your module. If the function
fc2171bd 103returns false, wxWidgets will exit immediately.
b67a86d5 104