]> git.saurik.com Git - wxWidgets.git/blob - src/os2/timer.cpp
added operator[](unsigned int) const -- testing it now on Linux/axp,
[wxWidgets.git] / src / os2 / timer.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: timer.cpp
3 // Purpose: wxTimer implementation
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/17/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #include "wx/window.h"
16 #include "wx/os2/private.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/setup.h"
20 #include "wx/list.h"
21 #include "wx/event.h"
22 #include "wx/app.h"
23 #endif
24
25 #include "wx/intl.h"
26 #include "wx/log.h"
27
28 #include "wx/timer.h"
29
30 #include <time.h>
31 #include <sys/types.h>
32
33 #include <sys/timeb.h>
34
35 // ----------------------------------------------------------------------------
36 // private functions
37 // ----------------------------------------------------------------------------
38
39 wxList wxTimerList(wxKEY_INTEGER);
40 UINT wxTimerProc(HWND hwnd, WORD, int idTimer, DWORD);
41
42 // ----------------------------------------------------------------------------
43 // macros
44 // ----------------------------------------------------------------------------
45
46 #if !USE_SHARED_LIBRARY
47 IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
48 #endif
49
50 wxTimer::wxTimer()
51 {
52 milli = 0 ;
53 id = 0;
54 oneShot = FALSE;
55 }
56
57 wxTimer::~wxTimer()
58 {
59 Stop();
60
61 wxTimerList.DeleteObject(this);
62 }
63
64 bool wxTimer::Start(int milliseconds,bool mode)
65 {
66 oneShot = mode;
67 if (milliseconds < 0)
68 milliseconds = lastMilli;
69
70 wxCHECK_MSG( milliseconds > 0, FALSE, wxT("invalid value for timer timeour") );
71
72 lastMilli = milli = milliseconds;
73
74 wxTimerList.DeleteObject(this);
75 // TODO:
76 /*
77 TIMERPROC wxTimerProcInst = (TIMERPROC)
78 MakeProcInstance((FARPROC)wxTimerProc, wxGetInstance());
79
80 id = SetTimer(NULL, (UINT)(id ? id : 1),
81 (UINT)milliseconds, wxTimerProcInst);
82 */
83 if (id > 0)
84 {
85 wxTimerList.Append(id, this);
86
87 return TRUE;
88 }
89 else
90 {
91 wxLogSysError(_("Couldn't create a timer"));
92
93 return FALSE;
94 }
95 }
96
97 void wxTimer::Stop()
98 {
99 if ( id )
100 {
101 // KillTimer(NULL, (UINT)id);
102 wxTimerList.DeleteObject(this);
103 }
104 id = 0;
105 milli = 0;
106 }
107
108 // ----------------------------------------------------------------------------
109 // private functions
110 // ----------------------------------------------------------------------------
111
112 void wxProcessTimer(wxTimer& timer)
113 {
114 // Avoid to process spurious timer events
115 if ( timer.id == 0)
116 return;
117
118 if ( timer.oneShot )
119 timer.Stop();
120
121 timer.Notify();
122 }
123
124 UINT wxTimerProc(HWND WXUNUSED(hwnd), WORD, int idTimer, DWORD)
125 {
126 wxNode *node = wxTimerList.Find((long)idTimer);
127
128 wxCHECK_MSG( node, 0, wxT("bogus timer id in wxTimerProc") );
129
130 wxProcessTimer(*(wxTimer *)node->Data());
131
132 return 0;
133 }
134