]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: timer.cpp | |
3 | // Purpose: wxTimer implementation | |
d90895ac | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
d90895ac | 6 | // Created: 10/17/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
d90895ac DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
d90895ac DW |
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" | |
0e320a79 DW |
23 | #endif |
24 | ||
d90895ac DW |
25 | #include "wx/intl.h" |
26 | #include "wx/log.h" | |
27 | ||
0e320a79 DW |
28 | #include "wx/timer.h" |
29 | ||
d90895ac DW |
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); | |
9ed0fac8 | 40 | ULONG wxTimerProc(HWND hwnd, ULONG, int nIdTimer, ULONG); |
d90895ac DW |
41 | |
42 | // ---------------------------------------------------------------------------- | |
43 | // macros | |
44 | // ---------------------------------------------------------------------------- | |
45 | ||
0e320a79 DW |
46 | #if !USE_SHARED_LIBRARY |
47 | IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject) | |
48 | #endif | |
49 | ||
50 | wxTimer::wxTimer() | |
51 | { | |
9ed0fac8 | 52 | m_ulId = 0; |
0e320a79 DW |
53 | } |
54 | ||
55 | wxTimer::~wxTimer() | |
56 | { | |
57 | Stop(); | |
d90895ac DW |
58 | |
59 | wxTimerList.DeleteObject(this); | |
0e320a79 DW |
60 | } |
61 | ||
9ed0fac8 DW |
62 | bool wxTimer::Start( |
63 | int nMilliseconds | |
64 | , bool bOneShot | |
65 | ) | |
0e320a79 | 66 | { |
9ed0fac8 DW |
67 | (void)wxTimerBase::Start( nMilliseconds |
68 | ,bOneShot | |
69 | ); | |
d90895ac | 70 | |
9ed0fac8 | 71 | wxCHECK_MSG( m_milli > 0L, FALSE, wxT("invalid value for timer") ); |
d90895ac DW |
72 | |
73 | wxTimerList.DeleteObject(this); | |
0e320a79 | 74 | |
9ed0fac8 DW |
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); | |
d90895ac DW |
89 | } |
90 | else | |
91 | { | |
92 | wxLogSysError(_("Couldn't create a timer")); | |
93 | ||
9ed0fac8 | 94 | return(FALSE); |
d90895ac | 95 | } |
0e320a79 DW |
96 | } |
97 | ||
98 | void wxTimer::Stop() | |
99 | { | |
9ed0fac8 | 100 | if ( m_ulId ) |
d90895ac | 101 | { |
9ed0fac8 | 102 | ::WinStopTimer(m_Hab, NULL, m_ulId); |
d90895ac DW |
103 | wxTimerList.DeleteObject(this); |
104 | } | |
9ed0fac8 | 105 | m_ulId = 0L; |
0e320a79 DW |
106 | } |
107 | ||
d90895ac DW |
108 | // ---------------------------------------------------------------------------- |
109 | // private functions | |
110 | // ---------------------------------------------------------------------------- | |
111 | ||
9ed0fac8 DW |
112 | void wxProcessTimer( |
113 | wxTimer& rTimer | |
114 | ) | |
d90895ac | 115 | { |
9ed0fac8 | 116 | // |
d90895ac | 117 | // Avoid to process spurious timer events |
9ed0fac8 DW |
118 | // |
119 | if (rTimer.m_ulId == 0L) | |
d90895ac DW |
120 | return; |
121 | ||
9ed0fac8 DW |
122 | if (rTimer.IsOneShot()) |
123 | rTimer.Stop(); | |
d90895ac | 124 | |
9ed0fac8 | 125 | rTimer.Notify(); |
d90895ac DW |
126 | } |
127 | ||
9ed0fac8 DW |
128 | ULONG wxTimerProc( |
129 | HWND WXUNUSED(hwnd) | |
130 | , ULONG | |
131 | , int nIdTimer | |
132 | , ULONG | |
133 | ) | |
d90895ac | 134 | { |
9ed0fac8 | 135 | wxNode* pNode = wxTimerList.Find((ULONG)nIdTimer); |
d90895ac | 136 | |
9ed0fac8 | 137 | wxCHECK_MSG(pNode, 0, wxT("bogus timer id in wxTimerProc") ); |
d90895ac | 138 | |
9ed0fac8 | 139 | wxProcessTimer(*(wxTimer *)pNode->Data()); |
d90895ac DW |
140 | return 0; |
141 | } | |
0e320a79 | 142 |