]> git.saurik.com Git - wxWidgets.git/blob - include/wx/timer.h
wxTreeCtrl has colours and fonts too now
[wxWidgets.git] / include / wx / timer.h
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/object.h"
20
21 // ----------------------------------------------------------------------------
22 // wxTimer
23 // ----------------------------------------------------------------------------
24
25 // the interface of wxTimer class
26 class WXDLLEXPORT wxTimerBase : public wxObject
27 {
28 public:
29 wxTimerBase() { m_oneShot = FALSE; m_milli = 0; }
30
31 // working with the timer
32 // ----------------------
33
34 // start the timer: if milliseconds == -1, use the same value as for the
35 // last Start()
36 virtual bool Start(int milliseconds = -1, bool oneShot = FALSE)
37 {
38 if ( milliseconds != -1 )
39 {
40 m_milli = milliseconds;
41 }
42
43 m_oneShot = oneShot;
44
45 return TRUE;
46 }
47
48
49 // stop the timer
50 virtual void Stop() = 0;
51
52 // override this in your wxTimer-derived class
53 virtual void Notify() = 0;
54
55 // getting info
56 // ------------
57
58 // return TRUE if the timer is running
59 virtual bool IsRunning() const = 0;
60
61 // get the (last) timer interval in the milliseconds
62 int GetInterval() const { return m_milli; }
63
64 // return TRUE if the timer is one shot
65 bool IsOneShot() const { return m_oneShot; }
66
67 #if WXWIN_COMPATIBILITY_2
68 // deprecated functions
69 int Interval() const { return GetInterval(); };
70 bool OneShot() const { return IsOneShot(); }
71 #endif // WXWIN_COMPATIBILITY_2
72
73 protected:
74 int m_milli; // the timer interval
75 bool m_oneShot; // TRUE if one shot
76 };
77
78 #if defined(__WXMSW__)
79 #include "wx/msw/timer.h"
80 #elif defined(__WXMOTIF__)
81 #include "wx/motif/timer.h"
82 #elif defined(__WXGTK__)
83 #include "wx/gtk/timer.h"
84 #elif defined(__WXQT__)
85 #include "wx/qt/timer.h"
86 #elif defined(__WXMAC__)
87 #include "wx/mac/timer.h"
88 #elif defined(__WXPM__)
89 #include "wx/os2/timer.h"
90 #elif defined(__WXSTUBS__)
91 #include "wx/stubs/timer.h"
92 #endif
93
94 // ----------------------------------------------------------------------------
95 // wxStopWatch
96 // ----------------------------------------------------------------------------
97
98 class WXDLLEXPORT wxStopWatch
99 {
100 public:
101 // ctor starts the stop watch
102 wxStopWatch() { Start(); }
103
104 void Start(long t = 0); // (re)start it t milliseconds ago
105 inline void Pause();
106 void Resume() { Start(m_pause); }
107
108 // get the elapsed time since the last Start() or Pause() in milliseconds
109 long Time() const;
110
111 protected:
112 // returns the elapsed time since t0
113 inline long GetElapsedTime() const;
114
115 private:
116 long m_t0; // the time of the last Start()
117 long m_pause; // the time of the last Pause() or 0
118 };
119
120 // the old name
121 #ifdef WXWIN_COMPATIBILITY_2
122 typedef wxStopWatch wxChrono;
123 #endif // WXWIN_COMPATIBILITY_2
124
125 // ----------------------------------------------------------------------------
126 // global time functions
127 // ----------------------------------------------------------------------------
128
129 // Timer functions (milliseconds) -- use wxStopWatch instead
130 void WXDLLEXPORT wxStartTimer();
131
132 // Gets time since last wxStartTimer or wxGetElapsedTime -- use wxStopWatch
133 // instead
134 long WXDLLEXPORT wxGetElapsedTime(bool resetTimer = TRUE);
135
136 // Get the local time
137 bool WXDLLEXPORT wxGetLocalTime(long *timeZone, int *dstObserved);
138
139 // Get number of seconds since 00:00:00 GMT, Jan 1st 1970.
140 long WXDLLEXPORT wxGetCurrentTime();
141
142 // Get number of milliseconds since 00:00:00 GMT, Jan 1st 1970.
143 long WXDLLEXPORT wxGetCurrentMTime();
144
145 // ----------------------------------------------------------------------------
146 // inline functions
147 // ----------------------------------------------------------------------------
148
149 inline long wxStopWatch::GetElapsedTime() const
150 {
151 return wxGetCurrentMTime() - m_t0;
152 }
153
154 inline void wxStopWatch::Pause()
155 {
156 m_pause = GetElapsedTime();
157 }
158
159 #endif
160 // _WX_TIMER_H_BASE_