1998-05-20 10:25:30 -04:00
|
|
|
\section{\class{wxTimer}}\label{wxtimer}
|
|
|
|
|
2000-02-04 21:07:38 -05:00
|
|
|
The wxTimer class allows you to execute code at specified intervals. Its
|
|
|
|
precision is platform-dependent, but in general will not be better than 1ms nor
|
|
|
|
worse than 1s.
|
|
|
|
|
|
|
|
There are two different ways to use this class:
|
|
|
|
|
|
|
|
\begin{enumerate}
|
|
|
|
\item You may derive a new class from wxTimer and override the
|
|
|
|
\helpref{Notify}{wxtimernotify} member to perform the required action.
|
|
|
|
\item Or you may redirect the notifications to any
|
|
|
|
\helpref{wxEvtHandler}{wxevthandler} derived object by using the non default
|
2003-06-16 08:31:45 -04:00
|
|
|
constructor or \helpref{SetOwner}{wxtimersetowner}. Then use the {\tt EVT\_TIMER}
|
2000-02-04 21:07:38 -05:00
|
|
|
macro to connect it to the event handler which will receive
|
|
|
|
\helpref{wxTimerEvent}{wxtimerevent} notifications.
|
2003-06-16 08:31:45 -04:00
|
|
|
\item Or you may use a derived class and the {\tt EVT\_TIMER}
|
|
|
|
macro to connect it to an event handler defined in the derived class.
|
|
|
|
If the default constructor is used, the timer object will be its
|
|
|
|
own owner object, since it is derived from wxEvtHandler.
|
2000-02-04 21:07:38 -05:00
|
|
|
\end{enumerate}
|
|
|
|
|
|
|
|
In any case, you must start the timer with \helpref{Start}{wxtimerstart}
|
|
|
|
after constructing it before it actually starts sending notifications. It can
|
|
|
|
be stopped later with \helpref{Stop}{wxtimerstop}.
|
1998-05-20 10:25:30 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
{\bf NB:} note that timer can only be used from the main thread currently.
|
|
|
|
|
1998-05-20 10:25:30 -04:00
|
|
|
\wxheading{Derived from}
|
|
|
|
|
2003-06-16 08:31:45 -04:00
|
|
|
\helpref{wxEvtHandler}{wxevthandler}
|
1998-05-20 10:25:30 -04:00
|
|
|
|
1999-02-15 15:41:29 -05:00
|
|
|
\wxheading{Include files}
|
|
|
|
|
|
|
|
<wx/timer.h>
|
|
|
|
|
1998-05-20 10:25:30 -04:00
|
|
|
\wxheading{See also}
|
|
|
|
|
1999-12-04 08:28:26 -05:00
|
|
|
\helpref{::wxStartTimer}{wxstarttimer}, \helpref{::wxGetElapsedTime}{wxgetelapsedtime}, \helpref{wxStopWatch}{wxstopwatch}
|
1998-05-20 10:25:30 -04:00
|
|
|
|
|
|
|
\latexignore{\rtfignore{\wxheading{Members}}}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
\membersection{wxTimer::wxTimer}\label{wxtimerwxtimer}
|
1998-05-20 10:25:30 -04:00
|
|
|
|
|
|
|
\func{}{wxTimer}{\void}
|
|
|
|
|
2000-02-04 21:07:38 -05:00
|
|
|
Default constructor. If you use it to construct the object and don't call
|
|
|
|
\helpref{SetOwner}{wxtimersetowner} later, you must override
|
|
|
|
\helpref{Notify}{wxtimernotify} method to process the notifications.
|
|
|
|
|
|
|
|
\func{}{wxTimer}{\param{wxEvtHandler *}{owner}, \param{int }{id = -1}}
|
|
|
|
|
|
|
|
Creates a timer and associates it with {\it owner}. Please see
|
|
|
|
\helpref{SetOwner}{wxtimersetowner} for the description of parameters.
|
1998-05-20 10:25:30 -04:00
|
|
|
|
2004-09-21 09:24:41 -04:00
|
|
|
\membersection{wxTimer::\destruct{wxTimer}}\label{wxtimerdtor}
|
1998-05-20 10:25:30 -04:00
|
|
|
|
|
|
|
\func{}{\destruct{wxTimer}}{\void}
|
|
|
|
|
2000-02-04 21:07:38 -05:00
|
|
|
Destructor. Stops the timer if it is running.
|
|
|
|
|
2003-06-08 13:49:49 -04:00
|
|
|
\membersection{wxTimer::GetInterval}\label{wxtimergetinterval}
|
2000-02-04 21:07:38 -05:00
|
|
|
|
|
|
|
\constfunc{int}{GetInterval}{\void}
|
|
|
|
|
|
|
|
Returns the current interval for the timer (in milliseconds).
|
|
|
|
|
2000-02-06 14:11:10 -05:00
|
|
|
\membersection{wxTimer::IsOneShot}\label{wxtimerisoneshot}
|
2000-02-04 21:07:38 -05:00
|
|
|
|
|
|
|
\constfunc{bool}{IsOneShot}{\void}
|
|
|
|
|
2003-01-17 19:16:34 -05:00
|
|
|
Returns {\tt true} if the timer is one shot, i.e.\ if it will stop after firing the
|
2000-02-04 21:07:38 -05:00
|
|
|
first notification automatically.
|
1998-05-20 10:25:30 -04:00
|
|
|
|
2000-02-06 14:11:10 -05:00
|
|
|
\membersection{wxTimer::IsRunning}\label{wxtimerisrunning}
|
1998-05-20 10:25:30 -04:00
|
|
|
|
2000-02-04 21:07:38 -05:00
|
|
|
\constfunc{bool}{IsRunning}{\void}
|
1998-05-20 10:25:30 -04:00
|
|
|
|
2003-01-17 19:16:34 -05:00
|
|
|
Returns {\tt true} if the timer is running, {\tt false} if it is stopped.
|
1998-05-20 10:25:30 -04:00
|
|
|
|
2000-02-06 14:11:10 -05:00
|
|
|
\membersection{wxTimer::Notify}\label{wxtimernotify}
|
1998-05-20 10:25:30 -04:00
|
|
|
|
|
|
|
\func{void}{Notify}{\void}
|
|
|
|
|
2000-02-04 21:07:38 -05:00
|
|
|
This member should be overridden by the user if the default constructor was
|
|
|
|
used and \helpref{SetOwner}{wxtimersetowner} wasn't called.
|
1998-05-20 10:25:30 -04:00
|
|
|
|
2000-02-04 21:07:38 -05:00
|
|
|
Perform whatever action which is to be taken periodically here.
|
|
|
|
|
2000-02-06 14:11:10 -05:00
|
|
|
\membersection{wxTimer::SetOwner}\label{wxtimersetowner}
|
2000-02-04 21:07:38 -05:00
|
|
|
|
|
|
|
\func{void}{SetOwner}{\param{wxEvtHandler *}{owner}, \param{int }{id = -1}}
|
|
|
|
|
2002-06-04 10:59:52 -04:00
|
|
|
Associates the timer with the given {\it owner}\/ object. When the timer is
|
2000-02-04 21:07:38 -05:00
|
|
|
running, the owner will receive \helpref{timer events}{wxtimerevent} with
|
2002-06-04 10:59:52 -04:00
|
|
|
id equal to {\it id}\/ specified here.
|
2000-02-04 21:07:38 -05:00
|
|
|
|
2000-02-06 14:11:10 -05:00
|
|
|
\membersection{wxTimer::Start}\label{wxtimerstart}
|
1998-05-20 10:25:30 -04:00
|
|
|
|
2003-01-17 19:16:34 -05:00
|
|
|
\func{bool}{Start}{\param{int}{milliseconds = -1}, \param{bool }{oneShot = {\tt false}}}
|
1998-05-20 10:25:30 -04:00
|
|
|
|
2002-06-04 10:59:52 -04:00
|
|
|
(Re)starts the timer. If {\it milliseconds}\/ parameter is -1 (value by default),
|
2003-01-17 19:16:34 -05:00
|
|
|
the previous value is used. Returns {\tt false} if the timer could not be started,
|
|
|
|
{\tt true} otherwise (in MS Windows timers are a limited resource).
|
2002-06-04 10:59:52 -04:00
|
|
|
|
2003-01-17 19:16:34 -05:00
|
|
|
If {\it oneShot}\/ is {\tt false} (the default), the \helpref{Notify}{wxtimernotify}
|
|
|
|
function will be called repeatedly until the timer is stopped. If {\tt true},
|
2002-06-04 10:59:52 -04:00
|
|
|
it will be called only once and the timer will stop automatically. To make your
|
2004-02-21 20:16:32 -05:00
|
|
|
code more readable you may also use the following symbolic constants:
|
|
|
|
|
|
|
|
\twocolwidtha{5cm}
|
2002-06-04 10:59:52 -04:00
|
|
|
\begin{twocollist}\itemsep=0pt
|
|
|
|
\twocolitem{wxTIMER\_CONTINUOUS}{Start a normal, continuously running, timer}
|
|
|
|
\twocolitem{wxTIMER\_ONE\_SHOT}{Start a one shot timer}
|
|
|
|
\end{twocollist}
|
1998-05-20 10:25:30 -04:00
|
|
|
|
2000-09-13 05:04:48 -04:00
|
|
|
If the timer was already running, it will be stopped by this method before
|
|
|
|
restarting it.
|
|
|
|
|
2000-02-06 14:11:10 -05:00
|
|
|
\membersection{wxTimer::Stop}\label{wxtimerstop}
|
1998-05-20 10:25:30 -04:00
|
|
|
|
|
|
|
\func{void}{Stop}{\void}
|
|
|
|
|
|
|
|
Stops the timer.
|
|
|
|
|
2000-02-04 21:07:38 -05:00
|
|
|
\section{\class{wxTimerEvent}}\label{wxtimerevent}
|
|
|
|
|
|
|
|
wxTimerEvent object is passed to the event handler of timer events.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
\begin{verbatim}
|
|
|
|
class MyFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
...
|
|
|
|
void OnTimer(wxTimerEvent& event);
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxTimer m_timer;
|
|
|
|
};
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|
|
|
EVT_TIMER(TIMER_ID, MyFrame::OnTimer)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
MyFrame::MyFrame()
|
|
|
|
: m_timer(this, TIMER_ID)
|
|
|
|
{
|
|
|
|
m_timer.Start(1000); // 1 second interval
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnTimer(wxTimerEvent& event)
|
|
|
|
{
|
|
|
|
// do whatever you want to do every second here
|
|
|
|
}
|
|
|
|
|
|
|
|
\end{verbatim}
|
|
|
|
|
|
|
|
\wxheading{Include files}
|
|
|
|
|
|
|
|
<wx/timer.h>
|
|
|
|
|
|
|
|
\wxheading{See also}
|
|
|
|
|
|
|
|
\helpref{wxTimer}{wxtimer}
|
|
|
|
|
|
|
|
\latexignore{\rtfignore{\wxheading{Members}}}
|
|
|
|
|
2000-02-06 14:11:10 -05:00
|
|
|
\membersection{wxTimerEvent::GetInterval}\label{wxtimereventgetinterval}
|
2000-02-04 21:07:38 -05:00
|
|
|
|
|
|
|
\constfunc{int}{GetInterval}{\void}
|
|
|
|
|
|
|
|
Returns the interval of the timer which generated this event.
|
|
|
|
|