1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTimer, wxStopWatch and global time-related functions
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin (wxTimerBase)
6 // Guillermo Rodriguez (global clean up)
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_TIMER_H_BASE_
14 #define _WX_TIMER_H_BASE_
20 #include "wx/object.h"
21 #include "wx/longlong.h"
23 #include "wx/stopwatch.h" // for backwards compatibility
27 // more readable flags for Start():
29 // generate notifications periodically until the timer is stopped (default)
30 #define wxTIMER_CONTINUOUS false
32 // only send the notification once and then stop the timer
33 #define wxTIMER_ONE_SHOT true
35 class WXDLLIMPEXP_BASE wxTimerImpl
;
37 // the interface of wxTimer class
38 class WXDLLIMPEXP_BASE wxTimer
: public wxEvtHandler
41 // ctors and initializers
42 // ----------------------
44 // default: if you don't call SetOwner(), your only chance to get timer
45 // notifications is to override Notify() in the derived class
52 // ctor which allows to avoid having to override Notify() in the derived
53 // class: the owner will get timer notifications which can be handled with
55 wxTimer(wxEvtHandler
*owner
, int timerid
= wxID_ANY
)
58 SetOwner(owner
, timerid
);
62 void SetOwner(wxEvtHandler
*owner
, int timerid
= wxID_ANY
);
67 // working with the timer
68 // ----------------------
70 // NB: Start() and Stop() are not supposed to be overridden, they are only
71 // virtual for historical reasons, only Notify() can be overridden
73 // start the timer: if milliseconds == -1, use the same value as for the
76 // it is now valid to call Start() multiple times: this just restarts the
77 // timer if it is already running
78 virtual bool Start(int milliseconds
= -1, bool oneShot
= false);
80 // stop the timer, does nothing if the timer is not running
83 // override this in your wxTimer-derived class if you want to process timer
84 // messages in it, use non default ctor or SetOwner() otherwise
85 virtual void Notify();
91 // get the object notified about the timer events
92 wxEvtHandler
*GetOwner() const;
94 // return true if the timer is running
95 bool IsRunning() const;
97 // return the timer ID
100 // get the (last) timer interval in milliseconds
101 int GetInterval() const;
103 // return true if the timer is one shot
104 bool IsOneShot() const;
107 // common part of all ctors
112 DECLARE_NO_COPY_CLASS(wxTimer
)
115 // ----------------------------------------------------------------------------
116 // wxTimerRunner: starts the timer in its ctor, stops in the dtor
117 // ----------------------------------------------------------------------------
119 class WXDLLEXPORT wxTimerRunner
122 wxTimerRunner(wxTimer
& timer
) : m_timer(timer
) { }
123 wxTimerRunner(wxTimer
& timer
, int milli
, bool oneShot
= false)
126 m_timer
.Start(milli
, oneShot
);
129 void Start(int milli
, bool oneShot
= false)
131 m_timer
.Start(milli
, oneShot
);
136 if ( m_timer
.IsRunning() )
145 DECLARE_NO_COPY_CLASS(wxTimerRunner
)
148 // ----------------------------------------------------------------------------
150 // ----------------------------------------------------------------------------
152 class WXDLLIMPEXP_BASE wxTimerEvent
: public wxEvent
155 wxTimerEvent(int timerid
= 0, int interval
= 0) : wxEvent(timerid
)
157 m_eventType
= wxEVT_TIMER
;
159 m_interval
= interval
;
163 int GetInterval() const { return m_interval
; }
165 // implement the base class pure virtual
166 virtual wxEvent
*Clone() const { return new wxTimerEvent(*this); }
171 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxTimerEvent
)
174 typedef void (wxEvtHandler::*wxTimerEventFunction
)(wxTimerEvent
&);
176 #define wxTimerEventHandler(func) \
177 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxTimerEventFunction, &func)
179 #define EVT_TIMER(timerid, func) \
180 wx__DECLARE_EVT1(wxEVT_TIMER, timerid, wxTimerEventHandler(func))
182 #endif // wxUSE_TIMER
184 #endif // _WX_TIMER_H_BASE_