]>
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 | // private functions | |
36 | // ---------------------------------------------------------------------------- | |
37 | ||
38 | wxList wxTimerList(wxKEY_INTEGER); | |
39 | ULONG wxTimerProc(HWND hwnd, ULONG, int nIdTimer, ULONG); | |
40 | ||
41 | // ---------------------------------------------------------------------------- | |
42 | // macros | |
43 | // ---------------------------------------------------------------------------- | |
44 | ||
45 | #if !USE_SHARED_LIBRARY | |
46 | IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject) | |
47 | #endif | |
48 | ||
49 | wxTimer::wxTimer() | |
50 | { | |
51 | m_ulId = 0; | |
52 | } | |
53 | ||
54 | wxTimer::~wxTimer() | |
55 | { | |
56 | Stop(); | |
57 | ||
58 | wxTimerList.DeleteObject(this); | |
59 | } | |
60 | ||
61 | bool wxTimer::Start( | |
62 | int nMilliseconds | |
63 | , bool bOneShot | |
64 | ) | |
65 | { | |
66 | (void)wxTimerBase::Start( nMilliseconds | |
67 | ,bOneShot | |
68 | ); | |
69 | ||
70 | wxCHECK_MSG( m_milli > 0L, FALSE, wxT("invalid value for timer") ); | |
71 | ||
72 | wxTimerList.DeleteObject(this); | |
73 | ||
74 | // | |
75 | // Create a windowless timer | |
76 | // | |
77 | m_ulId = ::WinStartTimer( m_Hab | |
78 | ,NULL | |
79 | ,(m_ulId ? m_ulId : 1L) | |
80 | ,(ULONG)nMilliseconds | |
81 | ); | |
82 | if (m_ulId > 0L) | |
83 | { | |
84 | wxTimerList.Append( m_ulId | |
85 | ,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 ( m_ulId ) | |
100 | { | |
101 | ::WinStopTimer(m_Hab, NULL, m_ulId); | |
102 | wxTimerList.DeleteObject(this); | |
103 | } | |
104 | m_ulId = 0L; | |
105 | } | |
106 | ||
107 | // ---------------------------------------------------------------------------- | |
108 | // private functions | |
109 | // ---------------------------------------------------------------------------- | |
110 | ||
111 | void wxProcessTimer( | |
112 | wxTimer& rTimer | |
113 | ) | |
114 | { | |
115 | // | |
116 | // Avoid to process spurious timer events | |
117 | // | |
118 | if (rTimer.m_ulId == 0L) | |
119 | return; | |
120 | ||
121 | if (rTimer.IsOneShot()) | |
122 | rTimer.Stop(); | |
123 | ||
124 | rTimer.Notify(); | |
125 | } | |
126 | ||
127 | ULONG wxTimerProc( | |
128 | HWND WXUNUSED(hwnd) | |
129 | , ULONG | |
130 | , int nIdTimer | |
131 | , ULONG | |
132 | ) | |
133 | { | |
134 | wxNode* pNode = wxTimerList.Find((ULONG)nIdTimer); | |
135 | ||
136 | wxCHECK_MSG(pNode, 0, wxT("bogus timer id in wxTimerProc") ); | |
137 | ||
138 | wxProcessTimer(*(wxTimer *)pNode->Data()); | |
139 | return 0; | |
140 | } | |
141 |