]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/timer.tex
corrected order of parameters in ctor (closes 1304320)
[wxWidgets.git] / docs / latex / wx / timer.tex
... / ...
CommitLineData
1\section{\class{wxTimer}}\label{wxtimer}
2
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 three 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 the {\tt EVT\_TIMER}
15macro to connect it to the event handler which will receive
16\helpref{wxTimerEvent}{wxtimerevent} notifications.
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.
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}.
26
27{\bf Note:} A timer can only be used from the main thread.
28
29\wxheading{Derived from}
30
31\helpref{wxEvtHandler}{wxevthandler}
32\helpref{wxObject}{wxobject}
33
34\wxheading{Include files}
35
36<wx/timer.h>
37
38\wxheading{See also}
39
40\helpref{::wxStartTimer}{wxstarttimer}, \helpref{::wxGetElapsedTime}{wxgetelapsedtime}, \helpref{wxStopWatch}{wxstopwatch}
41
42\latexignore{\rtfignore{\wxheading{Members}}}
43
44\membersection{wxTimer::wxTimer}\label{wxtimerwxtimer}
45
46\func{}{wxTimer}{\void}
47
48Default constructor. If you use it to construct the object and don't call
49\helpref{SetOwner}{wxtimersetowner} later, you must override
50\helpref{Notify}{wxtimernotify} method to process the notifications.
51
52\func{}{wxTimer}{\param{wxEvtHandler *}{owner}, \param{int }{id = -1}}
53
54Creates a timer and associates it with {\it owner}. Please see
55\helpref{SetOwner}{wxtimersetowner} for the description of parameters.
56
57\membersection{wxTimer::\destruct{wxTimer}}\label{wxtimerdtor}
58
59\func{}{\destruct{wxTimer}}{\void}
60
61Destructor. Stops the timer if it is running.
62
63\membersection{wxTimer::GetInterval}\label{wxtimergetinterval}
64
65\constfunc{int}{GetInterval}{\void}
66
67Returns the current interval for the timer (in milliseconds).
68
69\membersection{wxTimer::IsOneShot}\label{wxtimerisoneshot}
70
71\constfunc{bool}{IsOneShot}{\void}
72
73Returns {\tt true} if the timer is one shot, i.e.\ if it will stop after firing the
74first notification automatically.
75
76\membersection{wxTimer::IsRunning}\label{wxtimerisrunning}
77
78\constfunc{bool}{IsRunning}{\void}
79
80Returns {\tt true} if the timer is running, {\tt false} if it is stopped.
81
82\membersection{wxTimer::Notify}\label{wxtimernotify}
83
84\func{void}{Notify}{\void}
85
86This member should be overridden by the user if the default constructor was
87used and \helpref{SetOwner}{wxtimersetowner} wasn't called.
88
89Perform whatever action which is to be taken periodically here.
90
91\membersection{wxTimer::SetOwner}\label{wxtimersetowner}
92
93\func{void}{SetOwner}{\param{wxEvtHandler *}{owner}, \param{int }{id = -1}}
94
95Associates the timer with the given {\it owner}\/ object. When the timer is
96running, the owner will receive \helpref{timer events}{wxtimerevent} with
97id equal to {\it id}\/ specified here.
98
99\membersection{wxTimer::Start}\label{wxtimerstart}
100
101\func{bool}{Start}{\param{int }{milliseconds = -1}, \param{bool }{oneShot = {\tt false}}}
102
103(Re)starts the timer. If {\it milliseconds}\/ parameter is -1 (value by default),
104the previous value is used. Returns {\tt false} if the timer could not be started,
105{\tt true} otherwise (in MS Windows timers are a limited resource).
106
107If {\it oneShot}\/ is {\tt false} (the default), the \helpref{Notify}{wxtimernotify}
108function will be called repeatedly until the timer is stopped. If {\tt true},
109it will be called only once and the timer will stop automatically. To make your
110code more readable you may also use the following symbolic constants:
111
112\twocolwidtha{5cm}
113\begin{twocollist}\itemsep=0pt
114\twocolitem{wxTIMER\_CONTINUOUS}{Start a normal, continuously running, timer}
115\twocolitem{wxTIMER\_ONE\_SHOT}{Start a one shot timer}
116\end{twocollist}
117
118If the timer was already running, it will be stopped by this method before
119restarting it.
120
121\membersection{wxTimer::Stop}\label{wxtimerstop}
122
123\func{void}{Stop}{\void}
124
125Stops the timer.
126
127\section{\class{wxTimerEvent}}\label{wxtimerevent}
128
129wxTimerEvent object is passed to the event handler of timer events.
130
131For example:
132
133\begin{verbatim}
134class MyFrame : public wxFrame
135{
136public:
137 ...
138 void OnTimer(wxTimerEvent& event);
139
140private:
141 wxTimer m_timer;
142};
143
144BEGIN_EVENT_TABLE(MyFrame, wxFrame)
145 EVT_TIMER(TIMER_ID, MyFrame::OnTimer)
146END_EVENT_TABLE()
147
148MyFrame::MyFrame()
149 : m_timer(this, TIMER_ID)
150{
151 m_timer.Start(1000); // 1 second interval
152}
153
154void MyFrame::OnTimer(wxTimerEvent& event)
155{
156 // do whatever you want to do every second here
157}
158
159\end{verbatim}
160
161\wxheading{Derived from}
162
163\helpref{wxEvent}{wxevent}
164
165\wxheading{Include files}
166
167<wx/timer.h>
168
169\wxheading{See also}
170
171\helpref{wxTimer}{wxtimer}
172
173\latexignore{\rtfignore{\wxheading{Members}}}
174
175\membersection{wxTimerEvent::GetInterval}\label{wxtimereventgetinterval}
176
177\constfunc{int}{GetInterval}{\void}
178
179Returns the interval of the timer which generated this event.
180