]> git.saurik.com Git - wxWidgets.git/blob - src/os2/timer.cpp
Workaround for compile problem in IconizeChildFrames.
[wxWidgets.git] / src / os2 / timer.cpp
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 #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 #include "wx/window.h"
20 #include "wx/os2/private.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/setup.h"
24 #include "wx/list.h"
25 #include "wx/event.h"
26 #include "wx/app.h"
27 #endif
28
29 #include "wx/intl.h"
30 #include "wx/log.h"
31
32 #include "wx/timer.h"
33
34 #include <time.h>
35 #include <sys/types.h>
36
37 #include <sys/timeb.h>
38 // ----------------------------------------------------------------------------
39 // private functions
40 // ----------------------------------------------------------------------------
41
42 wxList wxTimerList(wxKEY_INTEGER);
43 ULONG wxTimerProc(HWND hwnd, ULONG, int nIdTimer, ULONG);
44
45 // ----------------------------------------------------------------------------
46 // macros
47 // ----------------------------------------------------------------------------
48
49 IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
50
51 void wxTimer::Init()
52 {
53 m_ulId = 0;
54 }
55
56 wxTimer::~wxTimer()
57 {
58 wxTimer::Stop();
59
60 wxTimerList.DeleteObject(this);
61 }
62
63 void wxTimer::Notify()
64 {
65 //
66 // The base class version generates an event if it has owner - which it
67 // should because otherwise nobody can process timer events, but it does
68 // not use the OS's ID, which OS/2 must have to figure out which timer fired
69 //
70 wxCHECK_RET( m_owner, _T("wxTimer::Notify() should be overridden.") );
71
72 wxTimerEvent vEvent( m_idTimer
73 ,m_milli
74 );
75
76 (void)m_owner->ProcessEvent(vEvent);
77 } // end of wxTimer::Notify
78
79 bool wxTimer::Start(
80 int nMilliseconds
81 , bool bOneShot
82 )
83 {
84 (void)wxTimerBase::Start( nMilliseconds
85 ,bOneShot
86 );
87
88 wxCHECK_MSG( m_milli > 0L, FALSE, wxT("invalid value for timer") );
89
90 wxTimerList.DeleteObject(this);
91
92 wxWindow* pWin = NULL;
93
94 if (m_owner)
95 {
96 pWin = (wxWindow*)m_owner;
97 m_ulId = ::WinStartTimer( m_Hab
98 ,pWin->GetHWND()
99 ,m_idTimer
100 ,(ULONG)nMilliseconds
101 );
102 }
103 else
104 m_ulId = ::WinStartTimer( m_Hab
105 ,NULLHANDLE
106 ,0
107 ,(ULONG)nMilliseconds
108 );
109 if (m_ulId > 0L)
110 {
111 wxTimerList.Append( m_ulId
112 ,this
113 );
114 return(TRUE);
115 }
116 else
117 {
118 wxLogSysError(_("Couldn't create a timer"));
119
120 return(FALSE);
121 }
122 }
123
124 void wxTimer::Stop()
125 {
126 if ( m_ulId )
127 {
128 if (m_owner)
129 {
130 wxWindow* pWin = (wxWindow*)m_owner;
131
132 ::WinStopTimer(m_Hab, pWin->GetHWND(), m_ulId);
133 }
134 else
135 ::WinStopTimer(m_Hab, NULLHANDLE, m_ulId);
136 wxTimerList.DeleteObject(this);
137 }
138 m_ulId = 0L;
139 }
140
141 // ----------------------------------------------------------------------------
142 // private functions
143 // ----------------------------------------------------------------------------
144
145 void wxProcessTimer(
146 wxTimer& rTimer
147 )
148 {
149 //
150 // Avoid to process spurious timer events
151 //
152 if (rTimer.m_ulId == 0L)
153 return;
154
155 if (rTimer.IsOneShot())
156 rTimer.Stop();
157
158 rTimer.Notify();
159 }
160
161 ULONG wxTimerProc(
162 HWND WXUNUSED(hwnd)
163 , ULONG
164 , int nIdTimer
165 , ULONG
166 )
167 {
168 wxNode* pNode = wxTimerList.Find((ULONG)nIdTimer);
169
170 wxCHECK_MSG(pNode, 0, wxT("bogus timer id in wxTimerProc") );
171 if (pNode)
172 wxProcessTimer(*(wxTimer *)pNode->GetData());
173 return 0;
174 }
175