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.
|
|
|
|
|
|
|
|
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
|
|
|
|
constructor or \helpref{SetOwner}{wxtimersetowner}. Then use {\tt EVT\_TIMER}
|
|
|
|
macro to connect it to the event handler which will receive
|
|
|
|
\helpref{wxTimerEvent}{wxtimerevent} notifications.
|
|
|
|
\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
|
|
|
|
|
|
|
\wxheading{Derived from}
|
|
|
|
|
|
|
|
\helpref{wxObject}{wxobject}
|
|
|
|
|
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
|
|
|
|
|
|
|
\membersection{wxTimer::\destruct{wxTimer}}
|
|
|
|
|
|
|
|
\func{}{\destruct{wxTimer}}{\void}
|
|
|
|
|
2000-02-05 02:07:38 +00:00
|
|
|
Destructor. Stops the timer if it is running.
|
|
|
|
|
|
|
|
\membersection{wxTimer::GetInterval}{wxtimergetinterval}
|
|
|
|
|
|
|
|
\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}
|
|
|
|
|
|
|
|
Returns TRUE if the timer is one shot, i.e. if it will stop after firing the
|
|
|
|
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
|
|
|
|
2000-02-05 02:07:38 +00:00
|
|
|
Returns TRUE if the timer is running, 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}}
|
|
|
|
|
|
|
|
Associates the timer with the given {\it owner} object. When the timer is
|
|
|
|
running, the owner will receive \helpref{timer events}{wxtimerevent} with
|
|
|
|
id equal to {\it id} specified here.
|
|
|
|
|
2000-02-06 19:11:10 +00:00
|
|
|
\membersection{wxTimer::Start}\label{wxtimerstart}
|
1998-05-20 14:25:30 +00:00
|
|
|
|
|
|
|
\func{bool}{Start}{\param{int}{ milliseconds = -1}, \param{bool}{ oneShot=FALSE}}
|
|
|
|
|
2000-02-05 02:07:38 +00:00
|
|
|
(Re)starts the timer. If {\it milliseconds} parameter is -1 (value by default),
|
|
|
|
the previous value is used. Returns FALSE if the timer could not be started,
|
1998-05-20 14:25:30 +00:00
|
|
|
TRUE otherwise (in MS Windows timers are a limited resource).
|
|
|
|
|
2000-02-05 02:07:38 +00:00
|
|
|
If {\it oneShot} is FALSE (the default), the \helpref{Notify}{wxtimernotify}
|
|
|
|
function will be called repeatedly until the timer is stopped. If TRUE,
|
|
|
|
it will be called only once and the timer will stop automatically.
|
1998-05-20 14:25:30 +00:00
|
|
|
|
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}
|
|
|
|
|
|
|
|
\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.
|
|
|
|
|