1998-05-20 14:25:30 +00:00
|
|
|
\section{\class{wxTimer}}\label{wxtimer}
|
|
|
|
|
2000-02-05 02:07:38 +00: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.
|
|
|
|
|
2005-10-28 16:01:24 +00:00
|
|
|
There are three different ways to use this class:
|
2000-02-05 02:07:38 +00:00
|
|
|
|
|
|
|
\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 12:31:45 +00:00
|
|
|
constructor or \helpref{SetOwner}{wxtimersetowner}. Then use the {\tt EVT\_TIMER}
|
2000-02-05 02:07:38 +00:00
|
|
|
macro to connect it to the event handler which will receive
|
|
|
|
\helpref{wxTimerEvent}{wxtimerevent} notifications.
|
2003-06-16 12:31:45 +00: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-05 02:07:38 +00: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 14:25:30 +00:00
|
|
|
|
2005-10-28 16:01:24 +00:00
|
|
|
{\bf Note:} A timer can only be used from the main thread.
|
2002-12-04 14:11:26 +00:00
|
|
|
|
1998-05-20 14:25:30 +00:00
|
|
|
\wxheading{Derived from}
|
|
|
|
|
2003-06-16 12:31:45 +00:00
|
|
|
\helpref{wxEvtHandler}{wxevthandler}
|
1998-05-20 14:25:30 +00:00
|
|
|
|
1999-02-15 20:41:29 +00:00
|
|
|
\wxheading{Include files}
|
|
|
|
|
|
|
|
<wx/timer.h>
|
|
|
|
|
1998-05-20 14:25:30 +00:00
|
|
|
\wxheading{See also}
|
|
|
|
|
1999-12-04 13:28:26 +00:00
|
|
|
\helpref{::wxStartTimer}{wxstarttimer}, \helpref{::wxGetElapsedTime}{wxgetelapsedtime}, \helpref{wxStopWatch}{wxstopwatch}
|
1998-05-20 14:25:30 +00:00
|
|
|
|
|
|
|
\latexignore{\rtfignore{\wxheading{Members}}}
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
\membersection{wxTimer::wxTimer}\label{wxtimerwxtimer}
|
1998-05-20 14:25:30 +00:00
|
|
|
|
|
|
|
\func{}{wxTimer}{\void}
|
|
|
|
|
2000-02-05 02:07:38 +00: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 14:25:30 +00:00
|
|
|
|
2004-09-21 13:24:41 +00:00
|
|
|
\membersection{wxTimer::\destruct{wxTimer}}\label{wxtimerdtor}
|
1998-05-20 14:25:30 +00:00
|
|
|
|
|
|
|
\func{}{\destruct{wxTimer}}{\void}
|
|
|
|
|
2000-02-05 02:07:38 +00:00
|
|
|
Destructor. Stops the timer if it is running.
|
|
|
|
|
2003-06-08 17:49:49 +00:00
|
|
|
\membersection{wxTimer::GetInterval}\label{wxtimergetinterval}
|
2000-02-05 02:07:38 +00:00
|
|
|
|
|
|
|
\constfunc{int}{GetInterval}{\void}
|
|
|
|
|
|
|
|
Returns the current interval for the timer (in milliseconds).
|
|
|
|
|
2000-02-06 19:11:10 +00:00
|
|
|
\membersection{wxTimer::IsOneShot}\label{wxtimerisoneshot}
|
2000-02-05 02:07:38 +00:00
|
|
|
|
|
|
|
\constfunc{bool}{IsOneShot}{\void}
|
|
|
|
|
2003-01-18 00:16:34 +00:00
|
|
|
Returns {\tt true} if the timer is one shot, i.e.\ if it will stop after firing the
|
2000-02-05 02:07:38 +00:00
|
|
|
first notification automatically.
|
1998-05-20 14:25:30 +00:00
|
|
|
|
2000-02-06 19:11:10 +00:00
|
|
|
\membersection{wxTimer::IsRunning}\label{wxtimerisrunning}
|
1998-05-20 14:25:30 +00:00
|
|
|
|
2000-02-05 02:07:38 +00:00
|
|
|
\constfunc{bool}{IsRunning}{\void}
|
1998-05-20 14:25:30 +00:00
|
|
|
|
2003-01-18 00:16:34 +00:00
|
|
|
Returns {\tt true} if the timer is running, {\tt false} if it is stopped.
|
1998-05-20 14:25:30 +00:00
|
|
|
|
2000-02-06 19:11:10 +00:00
|
|
|
\membersection{wxTimer::Notify}\label{wxtimernotify}
|
1998-05-20 14:25:30 +00:00
|
|
|
|
|
|
|
\func{void}{Notify}{\void}
|
|
|
|
|
2000-02-05 02:07:38 +00: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 14:25:30 +00:00
|
|
|
|
2000-02-05 02:07:38 +00:00
|
|
|
Perform whatever action which is to be taken periodically here.
|
|
|
|
|
2000-02-06 19:11:10 +00:00
|
|
|
\membersection{wxTimer::SetOwner}\label{wxtimersetowner}
|
2000-02-05 02:07:38 +00:00
|
|
|
|
|
|
|
\func{void}{SetOwner}{\param{wxEvtHandler *}{owner}, \param{int }{id = -1}}
|
|
|
|
|
2002-06-04 14:59:52 +00:00
|
|
|
Associates the timer with the given {\it owner}\/ object. When the timer is
|
2000-02-05 02:07:38 +00:00
|
|
|
running, the owner will receive \helpref{timer events}{wxtimerevent} with
|
2002-06-04 14:59:52 +00:00
|
|
|
id equal to {\it id}\/ specified here.
|
2000-02-05 02:07:38 +00:00
|
|
|
|
2000-02-06 19:11:10 +00:00
|
|
|
\membersection{wxTimer::Start}\label{wxtimerstart}
|
1998-05-20 14:25:30 +00:00
|
|
|
|
2005-09-09 14:33:41 +00:00
|
|
|
\func{bool}{Start}{\param{int }{milliseconds = -1}, \param{bool }{oneShot = {\tt false}}}
|
1998-05-20 14:25:30 +00:00
|
|
|
|
2002-06-04 14:59:52 +00:00
|
|
|
(Re)starts the timer. If {\it milliseconds}\/ parameter is -1 (value by default),
|
2003-01-18 00:16:34 +00: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 14:59:52 +00:00
|
|
|
|
2003-01-18 00:16:34 +00: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 14:59:52 +00:00
|
|
|
it will be called only once and the timer will stop automatically. To make your
|
2004-02-22 01:16:32 +00:00
|
|
|
code more readable you may also use the following symbolic constants:
|
|
|
|
|
|
|
|
\twocolwidtha{5cm}
|
2002-06-04 14:59:52 +00: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 14:25:30 +00:00
|
|
|
|
2000-09-13 09:04:48 +00:00
|
|
|
If the timer was already running, it will be stopped by this method before
|
|
|
|
restarting it.
|
|
|
|
|
2000-02-06 19:11:10 +00:00
|
|
|
\membersection{wxTimer::Stop}\label{wxtimerstop}
|
1998-05-20 14:25:30 +00:00
|
|
|
|
|
|
|
\func{void}{Stop}{\void}
|
|
|
|
|
|
|
|
Stops the timer.
|
|
|
|
|
2000-02-05 02:07:38 +00: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}
|
|
|
|
|
2005-12-19 00:34:13 +00:00
|
|
|
\wxheading{Derived from}
|
|
|
|
|
|
|
|
\helpref{wxEvent}{wxevent}
|
|
|
|
|
2000-02-05 02:07:38 +00:00
|
|
|
\wxheading{Include files}
|
|
|
|
|
|
|
|
<wx/timer.h>
|
|
|
|
|
|
|
|
\wxheading{See also}
|
|
|
|
|
|
|
|
\helpref{wxTimer}{wxtimer}
|
|
|
|
|
|
|
|
\latexignore{\rtfignore{\wxheading{Members}}}
|
|
|
|
|
2000-02-06 19:11:10 +00:00
|
|
|
\membersection{wxTimerEvent::GetInterval}\label{wxtimereventgetinterval}
|
2000-02-05 02:07:38 +00:00
|
|
|
|
|
|
|
\constfunc{int}{GetInterval}{\void}
|
|
|
|
|
|
|
|
Returns the interval of the timer which generated this event.
|
|
|
|
|