]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/timer.tex
fixed 2 bugs in 2 lines of wxFileSelector example code
[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
f6bcfd97 37\membersection{wxTimer::wxTimer}\label{wxtimerwxtimer}
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
2531c7e3
VZ
45\func{}{wxTimer}{\param{wxEvtHandler *}{owner}, \param{int }{id = -1}}
46
47Creates a timer and associates it with {\it owner}. Please see
48\helpref{SetOwner}{wxtimersetowner} for the description of parameters.
a660d684
KB
49
50\membersection{wxTimer::\destruct{wxTimer}}
51
52\func{}{\destruct{wxTimer}}{\void}
53
2531c7e3
VZ
54Destructor. Stops the timer if it is running.
55
56\membersection{wxTimer::GetInterval}{wxtimergetinterval}
57
58\constfunc{int}{GetInterval}{\void}
59
60Returns the current interval for the timer (in milliseconds).
61
457e6c54 62\membersection{wxTimer::IsOneShot}\label{wxtimerisoneshot}
2531c7e3
VZ
63
64\constfunc{bool}{IsOneShot}{\void}
65
b0a2d8a8 66Returns {\tt TRUE} if the timer is one shot, i.e.\ if it will stop after firing the
2531c7e3 67first notification automatically.
a660d684 68
457e6c54 69\membersection{wxTimer::IsRunning}\label{wxtimerisrunning}
a660d684 70
2531c7e3 71\constfunc{bool}{IsRunning}{\void}
a660d684 72
b0a2d8a8 73Returns {\tt TRUE} if the timer is running, {\tt FALSE} if it is stopped.
a660d684 74
457e6c54 75\membersection{wxTimer::Notify}\label{wxtimernotify}
a660d684
KB
76
77\func{void}{Notify}{\void}
78
2531c7e3
VZ
79This member should be overridden by the user if the default constructor was
80used and \helpref{SetOwner}{wxtimersetowner} wasn't called.
a660d684 81
2531c7e3
VZ
82Perform whatever action which is to be taken periodically here.
83
457e6c54 84\membersection{wxTimer::SetOwner}\label{wxtimersetowner}
2531c7e3
VZ
85
86\func{void}{SetOwner}{\param{wxEvtHandler *}{owner}, \param{int }{id = -1}}
87
b0a2d8a8 88Associates the timer with the given {\it owner}\/ object. When the timer is
2531c7e3 89running, the owner will receive \helpref{timer events}{wxtimerevent} with
b0a2d8a8 90id equal to {\it id}\/ specified here.
2531c7e3 91
457e6c54 92\membersection{wxTimer::Start}\label{wxtimerstart}
a660d684 93
b0a2d8a8 94\func{bool}{Start}{\param{int}{milliseconds = -1}, \param{bool }{oneShot = {\tt FALSE}}}
a660d684 95
b0a2d8a8
VZ
96(Re)starts the timer. If {\it milliseconds}\/ parameter is -1 (value by default),
97the previous value is used. Returns {\tt FALSE} if the timer could not be started,
98{\tt TRUE} otherwise (in MS Windows timers are a limited resource).
99
100If {\it oneShot}\/ is {\tt FALSE} (the default), the \helpref{Notify}{wxtimernotify}
101function will be called repeatedly until the timer is stopped. If {\tt TRUE},
102it will be called only once and the timer will stop automatically. To make your
103code more readable you may also use the following symbolic constants
104\twocolwidtha{5cm}%
105\begin{twocollist}\itemsep=0pt
106\twocolitem{wxTIMER\_CONTINUOUS}{Start a normal, continuously running, timer}
107\twocolitem{wxTIMER\_ONE\_SHOT}{Start a one shot timer}
108\end{twocollist}
a660d684 109
a660d684 110
99646f7e
VZ
111If the timer was already running, it will be stopped by this method before
112restarting it.
113
457e6c54 114\membersection{wxTimer::Stop}\label{wxtimerstop}
a660d684
KB
115
116\func{void}{Stop}{\void}
117
118Stops the timer.
119
2531c7e3
VZ
120\section{\class{wxTimerEvent}}\label{wxtimerevent}
121
122wxTimerEvent object is passed to the event handler of timer events.
123
124For example:
125
126\begin{verbatim}
127class MyFrame : public wxFrame
128{
129public:
130 ...
131 void OnTimer(wxTimerEvent& event);
132
133private:
134 wxTimer m_timer;
135};
136
137BEGIN_EVENT_TABLE(MyFrame, wxFrame)
138 EVT_TIMER(TIMER_ID, MyFrame::OnTimer)
139END_EVENT_TABLE()
140
141MyFrame::MyFrame()
142 : m_timer(this, TIMER_ID)
143{
144 m_timer.Start(1000); // 1 second interval
145}
146
147void MyFrame::OnTimer(wxTimerEvent& event)
148{
149 // do whatever you want to do every second here
150}
151
152\end{verbatim}
153
154\wxheading{Include files}
155
156<wx/timer.h>
157
158\wxheading{See also}
159
160\helpref{wxTimer}{wxtimer}
161
162\latexignore{\rtfignore{\wxheading{Members}}}
163
457e6c54 164\membersection{wxTimerEvent::GetInterval}\label{wxtimereventgetinterval}
2531c7e3
VZ
165
166\constfunc{int}{GetInterval}{\void}
167
168Returns the interval of the timer which generated this event.
169