X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2531c7e393e87dabaf6ae20301044ad893cb3ece..5a20d2ced0a0779b5d8b1cc8064f8404b2727e92:/docs/latex/wx/timer.tex?ds=inline diff --git a/docs/latex/wx/timer.tex b/docs/latex/wx/timer.tex index 05e5f0e1c7..dc7ba28b18 100644 --- a/docs/latex/wx/timer.tex +++ b/docs/latex/wx/timer.tex @@ -4,24 +4,31 @@ 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: +There are three 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} +\helpref{wxEvtHandler}{wxevthandler} derived object by using the non-default +constructor or \helpref{SetOwner}{wxtimersetowner}. Then use the {\tt EVT\_TIMER} macro to connect it to the event handler which will receive \helpref{wxTimerEvent}{wxtimerevent} notifications. +\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. \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}. +{\bf Note:} A timer can only be used from the main thread. + \wxheading{Derived from} +\helpref{wxEvtHandler}{wxevthandler} \helpref{wxObject}{wxobject} \wxheading{Include files} @@ -30,11 +37,11 @@ be stopped later with \helpref{Stop}{wxtimerstop}. \wxheading{See also} -\helpref{::wxStartTimer}{wxstarttimer}, \helpref{::wxGetElapsedTime}{wxgetelapsedtime}, \helpref{wxStopWatch}{wxstopwatch} +\helpref{wxStopWatch}{wxstopwatch} \latexignore{\rtfignore{\wxheading{Members}}} -\membersection{wxTimer::wxTimer}{wxtimerctordef} +\membersection{wxTimer::wxTimer}\label{wxtimerwxtimer} \func{}{wxTimer}{\void} @@ -42,39 +49,51 @@ 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. -\membersection{wxTimer::wxTimer}{wxtimerwxtimer} - \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. -\membersection{wxTimer::\destruct{wxTimer}} +\membersection{wxTimer::\destruct{wxTimer}}\label{wxtimerdtor} \func{}{\destruct{wxTimer}}{\void} Destructor. Stops the timer if it is running. -\membersection{wxTimer::GetInterval}{wxtimergetinterval} +\membersection{wxTimer::GetInterval}\label{wxtimergetinterval} \constfunc{int}{GetInterval}{\void} Returns the current interval for the timer (in milliseconds). -\membersection{wxTimer::IsOneShot}{wxtimerisoneshot} +\membersection{wxTimer::GetOwner}\label{wxtimergetowner} + +\constfunc{wxEvtHandler}{GetOwner}{\void} + +Returns the current {\it owner} of the timer. +If non-\NULL this is the event handler which will receive the +\helpref{timer events}{wxtimerevent} when the timer is running. + +\membersection{wxTimer::GetId}\label{wxtimergetid} + +\constfunc{int}{GetId}{\void} + +Returns the ID of the events generated by this timer. + +\membersection{wxTimer::IsOneShot}\label{wxtimerisoneshot} \constfunc{bool}{IsOneShot}{\void} -Returns TRUE if the timer is one shot, i.e. if it will stop after firing the +Returns {\tt true} if the timer is one shot, i.e.\ if it will stop after firing the first notification automatically. -\membersection{wxTimer::IsRunning}{wxtimerisrunning} +\membersection{wxTimer::IsRunning}\label{wxtimerisrunning} \constfunc{bool}{IsRunning}{\void} -Returns TRUE if the timer is running, FALSE if it is stopped. +Returns {\tt true} if the timer is running, {\tt false} if it is stopped. -\membersection{wxTimer::Notify}{wxtimernotify} +\membersection{wxTimer::Notify}\label{wxtimernotify} \func{void}{Notify}{\void} @@ -83,32 +102,49 @@ used and \helpref{SetOwner}{wxtimersetowner} wasn't called. Perform whatever action which is to be taken periodically here. -\membersection{wxTimer::SetOwner}{wxtimersetowner} +\membersection{wxTimer::SetOwner}\label{wxtimersetowner} \func{void}{SetOwner}{\param{wxEvtHandler *}{owner}, \param{int }{id = -1}} -Associates the timer with the given {\it owner} object. When the timer is +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. +id equal to {\it id}\/ specified here. + +\membersection{wxTimer::Start}\label{wxtimerstart} + +\func{bool}{Start}{\param{int }{milliseconds = -1}, \param{bool }{oneShot = {\tt false}}} -\membersection{wxTimer::Start}{wxtimerstart} +(Re)starts the timer. If {\it milliseconds}\/ parameter is -1 (value by default), +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). -\func{bool}{Start}{\param{int}{ milliseconds = -1}, \param{bool}{ oneShot=FALSE}} +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}, +it will be called only once and the timer will stop automatically. To make your +code more readable you may also use the following symbolic constants: -(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, -TRUE otherwise (in MS Windows timers are a limited resource). +\twocolwidtha{5cm} +\begin{twocollist}\itemsep=0pt +\twocolitem{wxTIMER\_CONTINUOUS}{Start a normal, continuously running, timer} +\twocolitem{wxTIMER\_ONE\_SHOT}{Start a one shot timer} +\end{twocollist} -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. +If the timer was already running, it will be stopped by this method before +restarting it. -\membersection{wxTimer::Stop}{wxtimerstop} +\membersection{wxTimer::Stop}\label{wxtimerstop} \func{void}{Stop}{\void} Stops the timer. + + + + +%% wxTimerEvent + + \section{\class{wxTimerEvent}}\label{wxtimerevent} wxTimerEvent object is passed to the event handler of timer events. @@ -143,6 +179,10 @@ void MyFrame::OnTimer(wxTimerEvent& event) \end{verbatim} +\wxheading{Derived from} + +\helpref{wxEvent}{wxevent} + \wxheading{Include files} @@ -153,54 +193,16 @@ void MyFrame::OnTimer(wxTimerEvent& event) \latexignore{\rtfignore{\wxheading{Members}}} -\membersection{wxTimerEvent::GetInterval}{wxtimereventgetinterval} +\membersection{wxTimerEvent::GetInterval}\label{wxtimereventgetinterval} \constfunc{int}{GetInterval}{\void} Returns the interval of the timer which generated this event. -\section{\class{wxStopWatch}}\label{wxstopwatch} - -The wxStopWatch class allow you to measure time intervalls. - -\wxheading{Include files} - - - -\wxheading{See also} - -\helpref{::wxStartTimer}{wxstarttimer}, \helpref{::wxGetElapsedTime}{wxgetelapsedtime}, \helpref{wxTimer}{wxtimer} - -\latexignore{\rtfignore{\wxheading{Members}}} - -\membersection{wxStopWatch::wxStopWatch} - -\func{}{wxStopWatch}{\void} - -Constructor. This starts the stop watch. - -\membersection{wxStopWatch::Pause}\label{wxstopwatchpause} - -\func{void}{Pause}{\void} - -Pauses the stop watch. Call \helpref{wxStopWatch::Resume}{wxstopwatchresume} to resume -time measuring again. - -\membersection{wxStopWatch::Start} - -\func{void}{Start}{\param{long}{ milliseconds = 0}} - -(Re)starts the stop watch with a given initial value. - -\membersection{wxStopWatch::Resume}\label{wxstopwatchresume} - -\func{void}{Resume}{\void} -Resumes the stop watch after having been paused with \helpref{wxStopWatch::Pause}{wxstopwatchpause}. +\membersection{wxTimerEvent::GetTimer}\label{wxtimereventgettimer} -\membersection{wxStopWatch::Time} +\constfunc{wxTimer\&}{GetTimer}{\void} -\func{long}{Time}{\void}\label{wxstopwatchtime} +Returns the timer object which generated this event. -Returns the time in milliseconds since the start (or restart) or the last call of -\helpref{wxStopWatch::Pause}{wxstopwatchpause}.