]> git.saurik.com Git - wxWidgets.git/blame - include/wx/timer.h
TIFF code 1.
[wxWidgets.git] / include / wx / timer.h
CommitLineData
0470b1e6
VZ
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
34138703
JS
12#ifndef _WX_TIMER_H_BASE_
13#define _WX_TIMER_H_BASE_
c801d85f 14
0470b1e6
VZ
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
26class WXDLLEXPORT wxTimerBase : public wxObject
27{
28public:
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
73protected:
74 int m_milli; // the timer interval
75 bool m_oneShot; // TRUE if one shot
76};
77
2049ba38 78#if defined(__WXMSW__)
0470b1e6 79 #include "wx/msw/timer.h"
2049ba38 80#elif defined(__WXMOTIF__)
0470b1e6 81 #include "wx/motif/timer.h"
2049ba38 82#elif defined(__WXGTK__)
0470b1e6 83 #include "wx/gtk/timer.h"
b4e76e0d 84#elif defined(__WXQT__)
0470b1e6 85 #include "wx/qt/timer.h"
34138703 86#elif defined(__WXMAC__)
0470b1e6 87 #include "wx/mac/timer.h"
1777b9bb 88#elif defined(__WXPM__)
0470b1e6 89 #include "wx/os2/timer.h"
34138703 90#elif defined(__WXSTUBS__)
0470b1e6 91 #include "wx/stubs/timer.h"
c801d85f
KB
92#endif
93
0470b1e6
VZ
94// ----------------------------------------------------------------------------
95// wxStopWatch
96// ----------------------------------------------------------------------------
97
98class WXDLLEXPORT wxStopWatch
f0599ea9
SB
99{
100public:
0470b1e6
VZ
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); }
f0599ea9 107
0470b1e6
VZ
108 // get the elapsed time since the last Start() or Pause() in milliseconds
109 long Time() const;
f0599ea9 110
0470b1e6
VZ
111protected:
112 // returns the elapsed time since t0
113 inline long GetElapsedTime() const;
114
f0599ea9 115private:
0470b1e6
VZ
116 long m_t0; // the time of the last Start()
117 long m_pause; // the time of the last Pause() or 0
f0599ea9
SB
118};
119
0470b1e6
VZ
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
f0599ea9
SB
130void WXDLLEXPORT wxStartTimer();
131
0470b1e6
VZ
132// Gets time since last wxStartTimer or wxGetElapsedTime -- use wxStopWatch
133// instead
f0599ea9
SB
134long WXDLLEXPORT wxGetElapsedTime(bool resetTimer = TRUE);
135
0470b1e6 136// Get the local time
f0599ea9
SB
137bool WXDLLEXPORT wxGetLocalTime(long *timeZone, int *dstObserved);
138
139// Get number of seconds since 00:00:00 GMT, Jan 1st 1970.
140long WXDLLEXPORT wxGetCurrentTime();
141
142// Get number of milliseconds since 00:00:00 GMT, Jan 1st 1970.
4f3ac409 143long WXDLLEXPORT wxGetCurrentMTime();
f0599ea9 144
0470b1e6
VZ
145// ----------------------------------------------------------------------------
146// inline functions
147// ----------------------------------------------------------------------------
148
149inline long wxStopWatch::GetElapsedTime() const
150{
151 return wxGetCurrentMTime() - m_t0;
152}
153
154inline void wxStopWatch::Pause()
155{
156 m_pause = GetElapsedTime();
157}
158
c801d85f 159#endif
34138703 160 // _WX_TIMER_H_BASE_