]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/timer.tex
add wxSYS_DCLICK_TIME system metric constant; use it for the generic list control...
[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
2cb94e7a 7There are three different ways to use this class:
2531c7e3
VZ
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
154b6b0f 13\helpref{wxEvtHandler}{wxevthandler} derived object by using the non-default
01ebf752 14constructor or \helpref{SetOwner}{wxtimersetowner}. Then use the {\tt EVT\_TIMER}
2531c7e3
VZ
15macro to connect it to the event handler which will receive
16\helpref{wxTimerEvent}{wxtimerevent} notifications.
01ebf752
JS
17\item Or you may use a derived class and the {\tt EVT\_TIMER}
18macro to connect it to an event handler defined in the derived class.
19If the default constructor is used, the timer object will be its
20own owner object, since it is derived from wxEvtHandler.
2531c7e3
VZ
21\end{enumerate}
22
23In any case, you must start the timer with \helpref{Start}{wxtimerstart}
24after constructing it before it actually starts sending notifications. It can
25be stopped later with \helpref{Stop}{wxtimerstop}.
a660d684 26
2cb94e7a 27{\bf Note:} A timer can only be used from the main thread.
2b5f62a0 28
a660d684
KB
29\wxheading{Derived from}
30
01ebf752 31\helpref{wxEvtHandler}{wxevthandler}
641d44ae 32\helpref{wxObject}{wxobject}
a660d684 33
954b8ae6
JS
34\wxheading{Include files}
35
36<wx/timer.h>
37
a7af285d
VZ
38\wxheading{Library}
39
40\helpref{wxBase}{librarieslist}
41
a660d684
KB
42\wxheading{See also}
43
659f4d76 44\helpref{wxStopWatch}{wxstopwatch}
a660d684
KB
45
46\latexignore{\rtfignore{\wxheading{Members}}}
47
f6bcfd97 48\membersection{wxTimer::wxTimer}\label{wxtimerwxtimer}
a660d684
KB
49
50\func{}{wxTimer}{\void}
51
2531c7e3
VZ
52Default constructor. If you use it to construct the object and don't call
53\helpref{SetOwner}{wxtimersetowner} later, you must override
54\helpref{Notify}{wxtimernotify} method to process the notifications.
55
2531c7e3
VZ
56\func{}{wxTimer}{\param{wxEvtHandler *}{owner}, \param{int }{id = -1}}
57
58Creates a timer and associates it with {\it owner}. Please see
59\helpref{SetOwner}{wxtimersetowner} for the description of parameters.
a660d684 60
6d06e061 61\membersection{wxTimer::\destruct{wxTimer}}\label{wxtimerdtor}
a660d684
KB
62
63\func{}{\destruct{wxTimer}}{\void}
64
2531c7e3
VZ
65Destructor. Stops the timer if it is running.
66
44cf9b50 67\membersection{wxTimer::GetInterval}\label{wxtimergetinterval}
2531c7e3
VZ
68
69\constfunc{int}{GetInterval}{\void}
70
71Returns the current interval for the timer (in milliseconds).
72
f70f1f25
VZ
73\membersection{wxTimer::GetOwner}\label{wxtimergetowner}
74
75\constfunc{wxEvtHandler}{GetOwner}{\void}
76
77Returns the current {\it owner} of the timer.
78If non-\NULL this is the event handler which will receive the
79\helpref{timer events}{wxtimerevent} when the timer is running.
80
81\membersection{wxTimer::GetId}\label{wxtimergetid}
82
83\constfunc{int}{GetId}{\void}
84
85Returns the ID of the events generated by this timer.
86
457e6c54 87\membersection{wxTimer::IsOneShot}\label{wxtimerisoneshot}
2531c7e3
VZ
88
89\constfunc{bool}{IsOneShot}{\void}
90
cc81d32f 91Returns {\tt true} if the timer is one shot, i.e.\ if it will stop after firing the
2531c7e3 92first notification automatically.
a660d684 93
457e6c54 94\membersection{wxTimer::IsRunning}\label{wxtimerisrunning}
a660d684 95
2531c7e3 96\constfunc{bool}{IsRunning}{\void}
a660d684 97
cc81d32f 98Returns {\tt true} if the timer is running, {\tt false} if it is stopped.
a660d684 99
457e6c54 100\membersection{wxTimer::Notify}\label{wxtimernotify}
a660d684
KB
101
102\func{void}{Notify}{\void}
103
2531c7e3
VZ
104This member should be overridden by the user if the default constructor was
105used and \helpref{SetOwner}{wxtimersetowner} wasn't called.
a660d684 106
2531c7e3
VZ
107Perform whatever action which is to be taken periodically here.
108
457e6c54 109\membersection{wxTimer::SetOwner}\label{wxtimersetowner}
2531c7e3
VZ
110
111\func{void}{SetOwner}{\param{wxEvtHandler *}{owner}, \param{int }{id = -1}}
112
b0a2d8a8 113Associates the timer with the given {\it owner}\/ object. When the timer is
2531c7e3 114running, the owner will receive \helpref{timer events}{wxtimerevent} with
b0a2d8a8 115id equal to {\it id}\/ specified here.
2531c7e3 116
457e6c54 117\membersection{wxTimer::Start}\label{wxtimerstart}
a660d684 118
e7dfcb8e 119\func{bool}{Start}{\param{int }{milliseconds = -1}, \param{bool }{oneShot = {\tt false}}}
a660d684 120
b0a2d8a8 121(Re)starts the timer. If {\it milliseconds}\/ parameter is -1 (value by default),
cc81d32f
VS
122the previous value is used. Returns {\tt false} if the timer could not be started,
123{\tt true} otherwise (in MS Windows timers are a limited resource).
b0a2d8a8 124
cc81d32f
VS
125If {\it oneShot}\/ is {\tt false} (the default), the \helpref{Notify}{wxtimernotify}
126function will be called repeatedly until the timer is stopped. If {\tt true},
b0a2d8a8 127it will be called only once and the timer will stop automatically. To make your
d2c2afc9
JS
128code more readable you may also use the following symbolic constants:
129
130\twocolwidtha{5cm}
b0a2d8a8
VZ
131\begin{twocollist}\itemsep=0pt
132\twocolitem{wxTIMER\_CONTINUOUS}{Start a normal, continuously running, timer}
133\twocolitem{wxTIMER\_ONE\_SHOT}{Start a one shot timer}
134\end{twocollist}
a660d684 135
99646f7e
VZ
136If the timer was already running, it will be stopped by this method before
137restarting it.
138
457e6c54 139\membersection{wxTimer::Stop}\label{wxtimerstop}
a660d684
KB
140
141\func{void}{Stop}{\void}
142
143Stops the timer.
144
f70f1f25
VZ
145
146
147
148
149%% wxTimerEvent
150
151
2531c7e3
VZ
152\section{\class{wxTimerEvent}}\label{wxtimerevent}
153
154wxTimerEvent object is passed to the event handler of timer events.
155
156For example:
157
158\begin{verbatim}
159class MyFrame : public wxFrame
160{
161public:
162 ...
163 void OnTimer(wxTimerEvent& event);
164
165private:
166 wxTimer m_timer;
167};
168
169BEGIN_EVENT_TABLE(MyFrame, wxFrame)
170 EVT_TIMER(TIMER_ID, MyFrame::OnTimer)
171END_EVENT_TABLE()
172
173MyFrame::MyFrame()
174 : m_timer(this, TIMER_ID)
175{
176 m_timer.Start(1000); // 1 second interval
177}
178
179void MyFrame::OnTimer(wxTimerEvent& event)
180{
181 // do whatever you want to do every second here
182}
183
184\end{verbatim}
185
b19d9289
MR
186\wxheading{Derived from}
187
7376079d
VZ
188\helpref{wxEvent}{wxevent}\\
189\helpref{wxObject}{wxobject}
b19d9289 190
2531c7e3
VZ
191\wxheading{Include files}
192
193<wx/timer.h>
194
a7af285d
VZ
195\wxheading{Library}
196
197\helpref{wxBase}{librarieslist}
198
2531c7e3
VZ
199\wxheading{See also}
200
201\helpref{wxTimer}{wxtimer}
202
203\latexignore{\rtfignore{\wxheading{Members}}}
204
457e6c54 205\membersection{wxTimerEvent::GetInterval}\label{wxtimereventgetinterval}
2531c7e3
VZ
206
207\constfunc{int}{GetInterval}{\void}
208
209Returns the interval of the timer which generated this event.
210
2cd78b2a
VZ
211
212\membersection{wxTimerEvent::GetTimer}\label{wxtimereventgettimer}
213
214\constfunc{wxTimer\&}{GetTimer}{\void}
215
216Returns the timer object which generated this event.
217