]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/timer.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTimer, wxStopWatch and global time-related functions
4 // Author: Julian Smart (wxTimer), Sylvain Bougnoux (wxStopWatch)
5 // Modified by: Vadim Zeitlin (wxTimerBase)
6 // Guillermo Rodriguez (global clean up)
9 // Copyright: (c) wxWindows team
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_TIMER_H_BASE_
14 #define _WX_TIMER_H_BASE_
17 #pragma interface "timerbase.h"
21 #include "wx/object.h"
22 #include "wx/longlong.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
29 // the interface of wxTimer class
30 class WXDLLEXPORT wxTimerBase
: public wxObject
33 // ctors and initializers
34 // ----------------------
36 // default: if you don't call SetOwner(), your only chance to get timer
37 // notifications is to override Notify() in the derived class
38 wxTimerBase() { Init(); SetOwner(NULL
); }
40 // ctor which allows to avoid having to override Notify() in the derived
41 // class: the owner will get timer notifications which can be handled with
43 wxTimerBase(wxEvtHandler
*owner
, int id
= -1)
44 { Init(); SetOwner(owner
, -1); }
47 void SetOwner(wxEvtHandler
*owner
, int id
= -1)
48 { m_owner
= owner
; m_idTimer
= id
; }
50 // working with the timer
51 // ----------------------
53 // start the timer: if milliseconds == -1, use the same value as for the
55 virtual bool Start(int milliseconds
= -1, bool oneShot
= FALSE
)
57 if ( milliseconds
!= -1 )
59 m_milli
= milliseconds
;
69 virtual void Stop() = 0;
71 // override this in your wxTimer-derived class if you want to process timer
72 // messages in it, use non default ctor or SetOwner() otherwise
73 virtual void Notify();
78 // return TRUE if the timer is running
79 virtual bool IsRunning() const = 0;
81 // get the (last) timer interval in the milliseconds
82 int GetInterval() const { return m_milli
; }
84 // return TRUE if the timer is one shot
85 bool IsOneShot() const { return m_oneShot
; }
87 #if WXWIN_COMPATIBILITY_2
88 // deprecated functions
89 int Interval() const { return GetInterval(); };
90 bool OneShot() const { return IsOneShot(); }
91 #endif // WXWIN_COMPATIBILITY_2
94 // common part of all ctors
95 void Init() { m_oneShot
= FALSE
; m_milli
= 0; }
97 wxEvtHandler
*m_owner
;
100 int m_milli
; // the timer interval
101 bool m_oneShot
; // TRUE if one shot
104 // ----------------------------------------------------------------------------
106 // ----------------------------------------------------------------------------
108 #if defined(__WXMSW__)
109 #include "wx/msw/timer.h"
110 #elif defined(__WXMOTIF__)
111 #include "wx/motif/timer.h"
112 #elif defined(__WXGTK__)
113 #include "wx/gtk/timer.h"
114 #elif defined(__WXQT__)
115 #include "wx/qt/timer.h"
116 #elif defined(__WXMAC__)
117 #include "wx/mac/timer.h"
118 #elif defined(__WXPM__)
119 #include "wx/os2/timer.h"
120 #elif defined(__WXSTUBS__)
121 #include "wx/stubs/timer.h"
124 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
128 class WXDLLEXPORT wxTimerEvent
: public wxEvent
131 wxTimerEvent(int id
= 0, int interval
= 0) : wxEvent(id
)
133 m_eventType
= wxEVT_TIMER
;
135 m_interval
= interval
;
139 int GetInterval() const { return m_interval
; }
144 DECLARE_DYNAMIC_CLASS(wxTimerEvent
)
147 typedef void (wxEvtHandler::*wxTimerEventFunction
)(wxTimerEvent
&);
149 #define EVT_TIMER(id, func) { wxEVT_TIMER, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTimerEventFunction) & func, NULL},
151 // ----------------------------------------------------------------------------
152 // wxStopWatch: measure time intervals with up to 1ms resolution
153 // ----------------------------------------------------------------------------
155 class WXDLLEXPORT wxStopWatch
158 // ctor starts the stop watch
159 wxStopWatch() { Start(); }
160 void Start(long t
= 0);
161 inline void Pause() { m_pause
= GetElapsedTime(); }
162 inline void Resume() { Start(m_pause
); }
164 // get elapsed time since the last Start() or Pause() in milliseconds
168 // returns the elapsed time since t0
169 long GetElapsedTime() const;
172 wxLongLong m_t0
; // the time of the last Start()
173 long m_pause
; // the time of the last Pause() or 0
177 // Starts a global timer
178 // -- DEPRECATED: use wxStopWatch instead
179 void WXDLLEXPORT
wxStartTimer();
181 // Gets elapsed milliseconds since last wxStartTimer or wxGetElapsedTime
182 // -- DEPRECATED: use wxStopWatch instead
183 long WXDLLEXPORT
wxGetElapsedTime(bool resetTimer
= TRUE
);
185 // ----------------------------------------------------------------------------
186 // global time functions
187 // ----------------------------------------------------------------------------
189 // Get number of seconds since local time 00:00:00 Jan 1st 1970.
190 long WXDLLEXPORT
wxGetLocalTime();
192 // Get number of seconds since GMT 00:00:00, Jan 1st 1970.
193 long WXDLLEXPORT
wxGetUTCTime();
195 #define wxGetCurrentTime() wxGetLocalTime()