]>
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> | |
d90895ac DW |
34 | // ---------------------------------------------------------------------------- |
35 | // private functions | |
36 | // ---------------------------------------------------------------------------- | |
37 | ||
38 | wxList wxTimerList(wxKEY_INTEGER); | |
9ed0fac8 | 39 | ULONG wxTimerProc(HWND hwnd, ULONG, int nIdTimer, ULONG); |
d90895ac DW |
40 | |
41 | // ---------------------------------------------------------------------------- | |
42 | // macros | |
43 | // ---------------------------------------------------------------------------- | |
44 | ||
0e320a79 | 45 | IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject) |
0e320a79 | 46 | |
496fd9fb | 47 | void wxTimer::Init() |
0e320a79 | 48 | { |
9ed0fac8 | 49 | m_ulId = 0; |
0e320a79 DW |
50 | } |
51 | ||
52 | wxTimer::~wxTimer() | |
53 | { | |
54 | Stop(); | |
05a8bfed | 55 | wxTimer::Stop(); |
d90895ac | 56 | wxTimerList.DeleteObject(this); |
0e320a79 DW |
57 | } |
58 | ||
233d6db5 DW |
59 | void wxTimer::Notify() |
60 | { | |
61 | // | |
62 | // The base class version generates an event if it has owner - which it | |
63 | // should because otherwise nobody can process timer events, but it does | |
64 | // not use the OS's ID, which OS/2 must have to figure out which timer fired | |
65 | // | |
66 | wxCHECK_RET( m_owner, _T("wxTimer::Notify() should be overridden.") ); | |
67 | ||
68 | wxTimerEvent vEvent( m_ulId | |
69 | ,m_milli | |
70 | ); | |
71 | ||
72 | (void)m_owner->ProcessEvent(vEvent); | |
73 | } // end of wxTimer::Notify | |
74 | ||
9ed0fac8 DW |
75 | bool wxTimer::Start( |
76 | int nMilliseconds | |
77 | , bool bOneShot | |
78 | ) | |
0e320a79 | 79 | { |
9ed0fac8 DW |
80 | (void)wxTimerBase::Start( nMilliseconds |
81 | ,bOneShot | |
82 | ); | |
d90895ac | 83 | |
9ed0fac8 | 84 | wxCHECK_MSG( m_milli > 0L, FALSE, wxT("invalid value for timer") ); |
d90895ac DW |
85 | |
86 | wxTimerList.DeleteObject(this); | |
0e320a79 | 87 | |
9ed0fac8 DW |
88 | // |
89 | // Create a windowless timer | |
90 | // | |
91 | m_ulId = ::WinStartTimer( m_Hab | |
92 | ,NULL | |
93 | ,(m_ulId ? m_ulId : 1L) | |
94 | ,(ULONG)nMilliseconds | |
95 | ); | |
96 | if (m_ulId > 0L) | |
97 | { | |
98 | wxTimerList.Append( m_ulId | |
99 | ,this | |
100 | ); | |
101 | return(TRUE); | |
d90895ac DW |
102 | } |
103 | else | |
104 | { | |
105 | wxLogSysError(_("Couldn't create a timer")); | |
106 | ||
9ed0fac8 | 107 | return(FALSE); |
d90895ac | 108 | } |
0e320a79 DW |
109 | } |
110 | ||
111 | void wxTimer::Stop() | |
112 | { | |
9ed0fac8 | 113 | if ( m_ulId ) |
d90895ac | 114 | { |
9ed0fac8 | 115 | ::WinStopTimer(m_Hab, NULL, m_ulId); |
d90895ac DW |
116 | wxTimerList.DeleteObject(this); |
117 | } | |
9ed0fac8 | 118 | m_ulId = 0L; |
0e320a79 DW |
119 | } |
120 | ||
d90895ac DW |
121 | // ---------------------------------------------------------------------------- |
122 | // private functions | |
123 | // ---------------------------------------------------------------------------- | |
124 | ||
9ed0fac8 DW |
125 | void wxProcessTimer( |
126 | wxTimer& rTimer | |
127 | ) | |
d90895ac | 128 | { |
9ed0fac8 | 129 | // |
d90895ac | 130 | // Avoid to process spurious timer events |
9ed0fac8 DW |
131 | // |
132 | if (rTimer.m_ulId == 0L) | |
d90895ac DW |
133 | return; |
134 | ||
9ed0fac8 DW |
135 | if (rTimer.IsOneShot()) |
136 | rTimer.Stop(); | |
d90895ac | 137 | |
9ed0fac8 | 138 | rTimer.Notify(); |
d90895ac DW |
139 | } |
140 | ||
9ed0fac8 DW |
141 | ULONG wxTimerProc( |
142 | HWND WXUNUSED(hwnd) | |
143 | , ULONG | |
144 | , int nIdTimer | |
145 | , ULONG | |
146 | ) | |
d90895ac | 147 | { |
9ed0fac8 | 148 | wxNode* pNode = wxTimerList.Find((ULONG)nIdTimer); |
d90895ac | 149 | |
9ed0fac8 | 150 | wxCHECK_MSG(pNode, 0, wxT("bogus timer id in wxTimerProc") ); |
d90895ac | 151 | |
9ed0fac8 | 152 | wxProcessTimer(*(wxTimer *)pNode->Data()); |
d90895ac DW |
153 | return 0; |
154 | } | |
0e320a79 | 155 |