]> git.saurik.com Git - wxWidgets.git/blob - src/msw/timer.cpp
compilation fixes
[wxWidgets.git] / src / msw / timer.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: timer.cpp
3 // Purpose: wxTimer implementation
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 #ifdef __GNUG__
13 #pragma implementation "timer.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/setup.h"
25 #include "wx/list.h"
26 #include "wx/event.h"
27 #include "wx/app.h"
28 #endif
29
30 #include "wx/intl.h"
31 #include "wx/log.h"
32
33 #include "wx/timer.h"
34 #include "wx/msw/private.h"
35
36 #include <time.h>
37 #include <sys/types.h>
38
39 #if !defined(__SC__) && !defined(__GNUWIN32__) && !defined(__MWERKS__)
40 #include <sys/timeb.h>
41 #endif
42
43 // ----------------------------------------------------------------------------
44 // private functions
45 // ----------------------------------------------------------------------------
46
47 wxList wxTimerList(wxKEY_INTEGER);
48 UINT WINAPI _EXPORT wxTimerProc(HWND hwnd, WORD, int idTimer, DWORD);
49
50 // ----------------------------------------------------------------------------
51 // macros
52 // ----------------------------------------------------------------------------
53
54 #ifdef __WIN32__
55 #define _EXPORT /**/
56 #else
57 #define _EXPORT _export
58 #endif
59
60 #if !USE_SHARED_LIBRARY
61 IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
62 #endif
63
64 // ============================================================================
65 // implementation
66 // ============================================================================
67
68 // ----------------------------------------------------------------------------
69 // wxTimer class
70 // ----------------------------------------------------------------------------
71 wxTimer::wxTimer(void)
72 {
73 milli = 0 ;
74 lastMilli = -1 ;
75 id = 0;
76 }
77
78 wxTimer::~wxTimer(void)
79 {
80 Stop();
81
82 wxTimerList.DeleteObject(this);
83 }
84
85 bool wxTimer::Start(int milliseconds, bool mode)
86 {
87 oneShot = mode ;
88 if (milliseconds < 0)
89 milliseconds = lastMilli;
90
91 wxCHECK_MSG( milliseconds > 0, FALSE, "invalid value for timer timeour" );
92
93 lastMilli = milli = milliseconds;
94
95 wxTimerList.DeleteObject(this);
96 TIMERPROC wxTimerProcInst = (TIMERPROC)
97 MakeProcInstance((FARPROC)wxTimerProc, wxGetInstance());
98
99 id = SetTimer(NULL, (UINT)(id ? id : 1),
100 (UINT)milliseconds, wxTimerProcInst);
101 if (id > 0)
102 {
103 wxTimerList.Append(id, this);
104
105 return TRUE;
106 }
107 else
108 {
109 wxLogSysError(_("Couldn't create a timer"));
110
111 return FALSE;
112 }
113 }
114
115 void wxTimer::Stop(void)
116 {
117 if (id) {
118 KillTimer(NULL, (UINT)id);
119 wxTimerList.DeleteObject(this); /* @@@@ */
120 }
121 id = 0 ;
122 milli = 0 ;
123 }
124
125 // ----------------------------------------------------------------------------
126 // private functions
127 // ----------------------------------------------------------------------------
128 void wxProcessTimer(wxTimer& timer)
129 {
130 // Avoid to process spurious timer events
131 if ( timer.id == 0)
132 return;
133
134 if ( timer.oneShot )
135 timer.Stop();
136
137 timer.Notify();
138 }
139
140 UINT WINAPI _EXPORT wxTimerProc(HWND WXUNUSED(hwnd), WORD, int idTimer, DWORD)
141 {
142 wxNode *node = wxTimerList.Find((long)idTimer);
143
144 wxCHECK_MSG( node, 0, "bogus timer id in wxTimerProc" );
145
146 wxProcessTimer(*(wxTimer *)node->Data());
147
148 return 0;
149 }