]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/timer.h | |
3 | // Purpose: wxTimer class and global time-related functions | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_TIMER_H_BASE_ | |
13 | #define _WX_TIMER_H_BASE_ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "timerbase.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/setup.h" | |
20 | #include "wx/object.h" | |
21 | #include "wx/longlong.h" | |
22 | ||
23 | // ---------------------------------------------------------------------------- | |
24 | // wxTimer | |
25 | // ---------------------------------------------------------------------------- | |
26 | ||
27 | // the interface of wxTimer class | |
28 | class WXDLLEXPORT wxTimerBase : public wxObject | |
29 | { | |
30 | public: | |
31 | wxTimerBase() { m_oneShot = FALSE; m_milli = 0; } | |
32 | ||
33 | // working with the timer | |
34 | // ---------------------- | |
35 | ||
36 | // start the timer: if milliseconds == -1, use the same value as for the | |
37 | // last Start() | |
38 | virtual bool Start(int milliseconds = -1, bool oneShot = FALSE) | |
39 | { | |
40 | if ( milliseconds != -1 ) | |
41 | { | |
42 | m_milli = milliseconds; | |
43 | } | |
44 | ||
45 | m_oneShot = oneShot; | |
46 | ||
47 | return TRUE; | |
48 | } | |
49 | ||
50 | ||
51 | // stop the timer | |
52 | virtual void Stop() = 0; | |
53 | ||
54 | // override this in your wxTimer-derived class | |
55 | virtual void Notify() = 0; | |
56 | ||
57 | // getting info | |
58 | // ------------ | |
59 | ||
60 | // return TRUE if the timer is running | |
61 | virtual bool IsRunning() const = 0; | |
62 | ||
63 | // get the (last) timer interval in the milliseconds | |
64 | int GetInterval() const { return m_milli; } | |
65 | ||
66 | // return TRUE if the timer is one shot | |
67 | bool IsOneShot() const { return m_oneShot; } | |
68 | ||
69 | #if WXWIN_COMPATIBILITY_2 | |
70 | // deprecated functions | |
71 | int Interval() const { return GetInterval(); }; | |
72 | bool OneShot() const { return IsOneShot(); } | |
73 | #endif // WXWIN_COMPATIBILITY_2 | |
74 | ||
75 | protected: | |
76 | int m_milli; // the timer interval | |
77 | bool m_oneShot; // TRUE if one shot | |
78 | }; | |
79 | ||
80 | #if defined(__WXMSW__) | |
81 | #include "wx/msw/timer.h" | |
82 | #elif defined(__WXMOTIF__) | |
83 | #include "wx/motif/timer.h" | |
84 | #elif defined(__WXGTK__) | |
85 | #include "wx/gtk/timer.h" | |
86 | #elif defined(__WXQT__) | |
87 | #include "wx/qt/timer.h" | |
88 | #elif defined(__WXMAC__) | |
89 | #include "wx/mac/timer.h" | |
90 | #elif defined(__WXPM__) | |
91 | #include "wx/os2/timer.h" | |
92 | #elif defined(__WXSTUBS__) | |
93 | #include "wx/stubs/timer.h" | |
94 | #endif | |
95 | ||
96 | // ---------------------------------------------------------------------------- | |
97 | // wxStopWatch | |
98 | // ---------------------------------------------------------------------------- | |
99 | ||
100 | class WXDLLEXPORT wxStopWatch | |
101 | { | |
102 | public: | |
103 | // ctor starts the stop watch | |
104 | wxStopWatch() { Start(); } | |
105 | void Start(long t = 0); | |
106 | inline void Pause() { m_pause = GetElapsedTime(); } | |
107 | inline void Resume() { Start(m_pause); } | |
108 | ||
109 | // get elapsed time since the last Start() or Pause() in milliseconds | |
110 | long Time() const; | |
111 | ||
112 | protected: | |
113 | // returns the elapsed time since t0 | |
114 | long GetElapsedTime() const; | |
115 | ||
116 | private: | |
117 | wxLongLong m_t0; // the time of the last Start() | |
118 | long m_pause; // the time of the last Pause() or 0 | |
119 | }; | |
120 | ||
121 | ||
122 | // Starts a global timer | |
123 | // -- DEPRECATED: use wxStopWatch instead | |
124 | void WXDLLEXPORT wxStartTimer(); | |
125 | ||
126 | // Gets elapsed milliseconds since last wxStartTimer or wxGetElapsedTime | |
127 | // -- DEPRECATED: use wxStopWatch instead | |
128 | long WXDLLEXPORT wxGetElapsedTime(bool resetTimer = TRUE); | |
129 | ||
130 | ||
131 | // ---------------------------------------------------------------------------- | |
132 | // global time functions | |
133 | // ---------------------------------------------------------------------------- | |
134 | ||
135 | // Get number of seconds since local time 00:00:00 Jan 1st 1970. | |
136 | long WXDLLEXPORT wxGetLocalTime(); | |
137 | ||
138 | // Get number of seconds since GMT 00:00:00, Jan 1st 1970. | |
139 | long WXDLLEXPORT wxGetUTCTime(); | |
140 | ||
141 | #define wxGetCurrentTime() wxGetLocalTime() | |
142 | ||
143 | #endif | |
144 | // _WX_TIMER_H_BASE_ |