]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/timer.tex
documented VFS handlers
[wxWidgets.git] / docs / latex / wx / timer.tex
CommitLineData
a660d684
KB
1\section{\class{wxTimer}}\label{wxtimer}
2
2531c7e3
VZ
3The wxTimer class allows you to execute code at specified intervals. Its
4precision is platform-dependent, but in general will not be better than 1ms nor
5worse than 1s.
6
7There are two different ways to use this class:
8
9\begin{enumerate}
10\item You may derive a new class from wxTimer and override the
11\helpref{Notify}{wxtimernotify} member to perform the required action.
12\item Or you may redirect the notifications to any
13\helpref{wxEvtHandler}{wxevthandler} derived object by using the non default
14constructor or \helpref{SetOwner}{wxtimersetowner}. Then use {\tt EVT\_TIMER}
15macro to connect it to the event handler which will receive
16\helpref{wxTimerEvent}{wxtimerevent} notifications.
17\end{enumerate}
18
19In any case, you must start the timer with \helpref{Start}{wxtimerstart}
20after constructing it before it actually starts sending notifications. It can
21be stopped later with \helpref{Stop}{wxtimerstop}.
a660d684
KB
22
23\wxheading{Derived from}
24
25\helpref{wxObject}{wxobject}
26
954b8ae6
JS
27\wxheading{Include files}
28
29<wx/timer.h>
30
a660d684
KB
31\wxheading{See also}
32
5f445b31 33\helpref{::wxStartTimer}{wxstarttimer}, \helpref{::wxGetElapsedTime}{wxgetelapsedtime}, \helpref{wxStopWatch}{wxstopwatch}
a660d684
KB
34
35\latexignore{\rtfignore{\wxheading{Members}}}
36
457e6c54 37\membersection{wxTimer::wxTimer}\label{wxtimerctordef}
a660d684
KB
38
39\func{}{wxTimer}{\void}
40
2531c7e3
VZ
41Default constructor. If you use it to construct the object and don't call
42\helpref{SetOwner}{wxtimersetowner} later, you must override
43\helpref{Notify}{wxtimernotify} method to process the notifications.
44
457e6c54 45\membersection{wxTimer::wxTimer}\label{wxtimerwxtimer}
2531c7e3
VZ
46
47\func{}{wxTimer}{\param{wxEvtHandler *}{owner}, \param{int }{id = -1}}
48
49Creates a timer and associates it with {\it owner}. Please see
50\helpref{SetOwner}{wxtimersetowner} for the description of parameters.
a660d684
KB
51
52\membersection{wxTimer::\destruct{wxTimer}}
53
54\func{}{\destruct{wxTimer}}{\void}
55
2531c7e3
VZ
56Destructor. Stops the timer if it is running.
57
58\membersection{wxTimer::GetInterval}{wxtimergetinterval}
59
60\constfunc{int}{GetInterval}{\void}
61
62Returns the current interval for the timer (in milliseconds).
63
457e6c54 64\membersection{wxTimer::IsOneShot}\label{wxtimerisoneshot}
2531c7e3
VZ
65
66\constfunc{bool}{IsOneShot}{\void}
67
68Returns TRUE if the timer is one shot, i.e. if it will stop after firing the
69first notification automatically.
a660d684 70
457e6c54 71\membersection{wxTimer::IsRunning}\label{wxtimerisrunning}
a660d684 72
2531c7e3 73\constfunc{bool}{IsRunning}{\void}
a660d684 74
2531c7e3 75Returns TRUE if the timer is running, FALSE if it is stopped.
a660d684 76
457e6c54 77\membersection{wxTimer::Notify}\label{wxtimernotify}
a660d684
KB
78
79\func{void}{Notify}{\void}
80
2531c7e3
VZ
81This member should be overridden by the user if the default constructor was
82used and \helpref{SetOwner}{wxtimersetowner} wasn't called.
a660d684 83
2531c7e3
VZ
84Perform whatever action which is to be taken periodically here.
85
457e6c54 86\membersection{wxTimer::SetOwner}\label{wxtimersetowner}
2531c7e3
VZ
87
88\func{void}{SetOwner}{\param{wxEvtHandler *}{owner}, \param{int }{id = -1}}
89
90Associates the timer with the given {\it owner} object. When the timer is
91running, the owner will receive \helpref{timer events}{wxtimerevent} with
92id equal to {\it id} specified here.
93
457e6c54 94\membersection{wxTimer::Start}\label{wxtimerstart}
a660d684
KB
95
96\func{bool}{Start}{\param{int}{ milliseconds = -1}, \param{bool}{ oneShot=FALSE}}
97
2531c7e3
VZ
98(Re)starts the timer. If {\it milliseconds} parameter is -1 (value by default),
99the previous value is used. Returns FALSE if the timer could not be started,
a660d684
KB
100TRUE otherwise (in MS Windows timers are a limited resource).
101
2531c7e3
VZ
102If {\it oneShot} is FALSE (the default), the \helpref{Notify}{wxtimernotify}
103function will be called repeatedly until the timer is stopped. If TRUE,
104it will be called only once and the timer will stop automatically.
a660d684 105
457e6c54 106\membersection{wxTimer::Stop}\label{wxtimerstop}
a660d684
KB
107
108\func{void}{Stop}{\void}
109
110Stops the timer.
111
2531c7e3
VZ
112\section{\class{wxTimerEvent}}\label{wxtimerevent}
113
114wxTimerEvent object is passed to the event handler of timer events.
115
116For example:
117
118\begin{verbatim}
119class MyFrame : public wxFrame
120{
121public:
122 ...
123 void OnTimer(wxTimerEvent& event);
124
125private:
126 wxTimer m_timer;
127};
128
129BEGIN_EVENT_TABLE(MyFrame, wxFrame)
130 EVT_TIMER(TIMER_ID, MyFrame::OnTimer)
131END_EVENT_TABLE()
132
133MyFrame::MyFrame()
134 : m_timer(this, TIMER_ID)
135{
136 m_timer.Start(1000); // 1 second interval
137}
138
139void MyFrame::OnTimer(wxTimerEvent& event)
140{
141 // do whatever you want to do every second here
142}
143
144\end{verbatim}
145
146\wxheading{Include files}
147
148<wx/timer.h>
149
150\wxheading{See also}
151
152\helpref{wxTimer}{wxtimer}
153
154\latexignore{\rtfignore{\wxheading{Members}}}
155
457e6c54 156\membersection{wxTimerEvent::GetInterval}\label{wxtimereventgetinterval}
2531c7e3
VZ
157
158\constfunc{int}{GetInterval}{\void}
159
160Returns the interval of the timer which generated this event.
161
5f445b31 162\section{\class{wxStopWatch}}\label{wxstopwatch}
a660d684 163
5f445b31
RR
164The wxStopWatch class allow you to measure time intervalls.
165
166\wxheading{Include files}
167
168<wx/timer.h>
169
170\wxheading{See also}
171
172\helpref{::wxStartTimer}{wxstarttimer}, \helpref{::wxGetElapsedTime}{wxgetelapsedtime}, \helpref{wxTimer}{wxtimer}
173
174\latexignore{\rtfignore{\wxheading{Members}}}
175
176\membersection{wxStopWatch::wxStopWatch}
177
178\func{}{wxStopWatch}{\void}
179
180Constructor. This starts the stop watch.
181
182\membersection{wxStopWatch::Pause}\label{wxstopwatchpause}
183
184\func{void}{Pause}{\void}
185
186Pauses the stop watch. Call \helpref{wxStopWatch::Resume}{wxstopwatchresume} to resume
187time measuring again.
188
189\membersection{wxStopWatch::Start}
190
191\func{void}{Start}{\param{long}{ milliseconds = 0}}
192
193(Re)starts the stop watch with a given initial value.
194
195\membersection{wxStopWatch::Resume}\label{wxstopwatchresume}
196
197\func{void}{Resume}{\void}
198
199Resumes the stop watch after having been paused with \helpref{wxStopWatch::Pause}{wxstopwatchpause}.
200
201\membersection{wxStopWatch::Time}
202
203\func{long}{Time}{\void}\label{wxstopwatchtime}
204
205Returns the time in milliseconds since the start (or restart) or the last call of
206\helpref{wxStopWatch::Pause}{wxstopwatchpause}.
457e6c54 207