]>
Commit | Line | Data |
---|---|---|
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 | ULONG wxTimerProc(HWND hwnd, ULONG, int nIdTimer, ULONG); | |
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 | m_ulId = 0; | |
53 | } | |
54 | ||
55 | wxTimer::~wxTimer() | |
56 | { | |
57 | Stop(); | |
58 | ||
59 | wxTimerList.DeleteObject(this); | |
60 | } | |
61 | ||
62 | bool wxTimer::Start( | |
63 | int nMilliseconds | |
64 | , bool bOneShot | |
65 | ) | |
66 | { | |
67 | (void)wxTimerBase::Start( nMilliseconds | |
68 | ,bOneShot | |
69 | ); | |
70 | ||
71 | wxCHECK_MSG( m_milli > 0L, FALSE, wxT("invalid value for timer") ); | |
72 | ||
73 | wxTimerList.DeleteObject(this); | |
74 | ||
75 | // | |
76 | // Create a windowless timer | |
77 | // | |
78 | m_ulId = ::WinStartTimer( m_Hab | |
79 | ,NULL | |
80 | ,(m_ulId ? m_ulId : 1L) | |
81 | ,(ULONG)nMilliseconds | |
82 | ); | |
83 | if (m_ulId > 0L) | |
84 | { | |
85 | wxTimerList.Append( m_ulId | |
86 | ,this | |
87 | ); | |
88 | return(TRUE); | |
89 | } | |
90 | else | |
91 | { | |
92 | wxLogSysError(_("Couldn't create a timer")); | |
93 | ||
94 | return(FALSE); | |
95 | } | |
96 | } | |
97 | ||
98 | void wxTimer::Stop() | |
99 | { | |
100 | if ( m_ulId ) | |
101 | { | |
102 | ::WinStopTimer(m_Hab, NULL, m_ulId); | |
103 | wxTimerList.DeleteObject(this); | |
104 | } | |
105 | m_ulId = 0L; | |
106 | } | |
107 | ||
108 | // ---------------------------------------------------------------------------- | |
109 | // private functions | |
110 | // ---------------------------------------------------------------------------- | |
111 | ||
112 | void wxProcessTimer( | |
113 | wxTimer& rTimer | |
114 | ) | |
115 | { | |
116 | // | |
117 | // Avoid to process spurious timer events | |
118 | // | |
119 | if (rTimer.m_ulId == 0L) | |
120 | return; | |
121 | ||
122 | if (rTimer.IsOneShot()) | |
123 | rTimer.Stop(); | |
124 | ||
125 | rTimer.Notify(); | |
126 | } | |
127 | ||
128 | ULONG wxTimerProc( | |
129 | HWND WXUNUSED(hwnd) | |
130 | , ULONG | |
131 | , int nIdTimer | |
132 | , ULONG | |
133 | ) | |
134 | { | |
135 | wxNode* pNode = wxTimerList.Find((ULONG)nIdTimer); | |
136 | ||
137 | wxCHECK_MSG(pNode, 0, wxT("bogus timer id in wxTimerProc") ); | |
138 | ||
139 | wxProcessTimer(*(wxTimer *)pNode->Data()); | |
140 | return 0; | |
141 | } | |
142 |