]> git.saurik.com Git - wxWidgets.git/blame - include/wx/timer.h
fixed background colour handling in wxTreeCtrl
[wxWidgets.git] / include / wx / timer.h
CommitLineData
0470b1e6
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/timer.h
ed791986
VZ
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)
0470b1e6
VZ
7// Created: 04/01/98
8// RCS-ID: $Id$
ed791986
VZ
9// Copyright: (c) wxWindows team
10// Licence: wxWindows license
0470b1e6
VZ
11/////////////////////////////////////////////////////////////////////////////
12
34138703
JS
13#ifndef _WX_TIMER_H_BASE_
14#define _WX_TIMER_H_BASE_
c801d85f 15
0470b1e6
VZ
16#ifdef __GNUG__
17 #pragma interface "timerbase.h"
18#endif
19
d895ad7c 20#include "wx/setup.h"
0470b1e6 21#include "wx/object.h"
d895ad7c 22#include "wx/longlong.h"
ed791986 23#include "wx/event.h"
0470b1e6
VZ
24
25// ----------------------------------------------------------------------------
26// wxTimer
27// ----------------------------------------------------------------------------
28
29// the interface of wxTimer class
30class WXDLLEXPORT wxTimerBase : public wxObject
31{
32public:
ed791986
VZ
33 // ctors and initializers
34 // ----------------------
35
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); }
39
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
42 // EVT_TIMER
43 wxTimerBase(wxEvtHandler *owner, int id = -1)
06b466c7 44 { Init(); SetOwner(owner, id); }
ed791986
VZ
45
46 // same as ctor above
47 void SetOwner(wxEvtHandler *owner, int id = -1)
48 { m_owner = owner; m_idTimer = id; }
0470b1e6
VZ
49
50 // working with the timer
51 // ----------------------
52
53 // start the timer: if milliseconds == -1, use the same value as for the
54 // last Start()
55 virtual bool Start(int milliseconds = -1, bool oneShot = FALSE)
56 {
57 if ( milliseconds != -1 )
58 {
59 m_milli = milliseconds;
60 }
61
62 m_oneShot = oneShot;
63
64 return TRUE;
65 }
66
67
68 // stop the timer
69 virtual void Stop() = 0;
70
ed791986
VZ
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();
0470b1e6
VZ
74
75 // getting info
76 // ------------
77
78 // return TRUE if the timer is running
79 virtual bool IsRunning() const = 0;
80
81 // get the (last) timer interval in the milliseconds
82 int GetInterval() const { return m_milli; }
83
84 // return TRUE if the timer is one shot
85 bool IsOneShot() const { return m_oneShot; }
86
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
92
93protected:
ed791986
VZ
94 // common part of all ctors
95 void Init() { m_oneShot = FALSE; m_milli = 0; }
96
97 wxEvtHandler *m_owner;
98 int m_idTimer;
99
0470b1e6
VZ
100 int m_milli; // the timer interval
101 bool m_oneShot; // TRUE if one shot
102};
103
ed791986
VZ
104// ----------------------------------------------------------------------------
105// wxTimer itself
106// ----------------------------------------------------------------------------
107
2049ba38 108#if defined(__WXMSW__)
0470b1e6 109 #include "wx/msw/timer.h"
2049ba38 110#elif defined(__WXMOTIF__)
0470b1e6 111 #include "wx/motif/timer.h"
2049ba38 112#elif defined(__WXGTK__)
0470b1e6 113 #include "wx/gtk/timer.h"
b4e76e0d 114#elif defined(__WXQT__)
0470b1e6 115 #include "wx/qt/timer.h"
34138703 116#elif defined(__WXMAC__)
0470b1e6 117 #include "wx/mac/timer.h"
1777b9bb 118#elif defined(__WXPM__)
0470b1e6 119 #include "wx/os2/timer.h"
34138703 120#elif defined(__WXSTUBS__)
0470b1e6 121 #include "wx/stubs/timer.h"
c801d85f
KB
122#endif
123
0470b1e6 124// ----------------------------------------------------------------------------
ed791986
VZ
125// wxTimerEvent
126// ----------------------------------------------------------------------------
127
128class WXDLLEXPORT wxTimerEvent : public wxEvent
129{
130public:
131 wxTimerEvent(int id = 0, int interval = 0) : wxEvent(id)
132 {
133 m_eventType = wxEVT_TIMER;
134
135 m_interval = interval;
136 }
137
138 // accessors
139 int GetInterval() const { return m_interval; }
140
141private:
142 int m_interval;
143
144 DECLARE_DYNAMIC_CLASS(wxTimerEvent)
145};
146
147typedef void (wxEvtHandler::*wxTimerEventFunction)(wxTimerEvent&);
148
149#define EVT_TIMER(id, func) { wxEVT_TIMER, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTimerEventFunction) & func, NULL},
150
151// ----------------------------------------------------------------------------
152// wxStopWatch: measure time intervals with up to 1ms resolution
0470b1e6
VZ
153// ----------------------------------------------------------------------------
154
155class WXDLLEXPORT wxStopWatch
f0599ea9 156{
ed791986 157public:
0470b1e6 158 // ctor starts the stop watch
d895ad7c
GRG
159 wxStopWatch() { Start(); }
160 void Start(long t = 0);
92da8bde
VZ
161 void Pause() { m_pause = GetElapsedTime(); }
162 void Resume() { Start(m_pause); }
0470b1e6 163
d895ad7c 164 // get elapsed time since the last Start() or Pause() in milliseconds
0470b1e6 165 long Time() const;
f0599ea9 166
0470b1e6
VZ
167protected:
168 // returns the elapsed time since t0
d895ad7c 169 long GetElapsedTime() const;
ed791986 170
f0599ea9 171private:
d895ad7c
GRG
172 wxLongLong m_t0; // the time of the last Start()
173 long m_pause; // the time of the last Pause() or 0
f0599ea9
SB
174};
175
0470b1e6 176
ed791986 177// Starts a global timer
d895ad7c 178// -- DEPRECATED: use wxStopWatch instead
f0599ea9
SB
179void WXDLLEXPORT wxStartTimer();
180
d895ad7c
GRG
181// Gets elapsed milliseconds since last wxStartTimer or wxGetElapsedTime
182// -- DEPRECATED: use wxStopWatch instead
f0599ea9
SB
183long WXDLLEXPORT wxGetElapsedTime(bool resetTimer = TRUE);
184
0470b1e6 185// ----------------------------------------------------------------------------
d895ad7c 186// global time functions
0470b1e6
VZ
187// ----------------------------------------------------------------------------
188
d895ad7c
GRG
189// Get number of seconds since local time 00:00:00 Jan 1st 1970.
190long WXDLLEXPORT wxGetLocalTime();
191
192// Get number of seconds since GMT 00:00:00, Jan 1st 1970.
193long WXDLLEXPORT wxGetUTCTime();
194
df0c3226 195#define wxGetCurrentTime() wxGetLocalTime()
0470b1e6 196
c801d85f 197#endif
34138703 198 // _WX_TIMER_H_BASE_