]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/timer.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTimer implementation
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
15 #include "wx/window.h"
16 #include "wx/os2/private.h"
31 #include <sys/types.h>
33 #include <sys/timeb.h>
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // define a hash containing all the timers: it is indexed by timer id and
40 // contains the corresponding timer
41 WX_DECLARE_HASH_MAP(unsigned long, wxTimer
*, wxIntegerHash
, wxIntegerEqual
,
44 // instead of using a global here, wrap it in a static function as otherwise it
45 // could have been used before being initialized if a timer object were created
47 static wxTimerMap
& TimerMap()
49 static wxTimerMap s_timerMap
;
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 // timer callback used for all timers
59 ULONG
wxTimerProc(HWND hwnd
, ULONG
, int nIdTimer
, ULONG
);
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxEvtHandler
)
67 // ============================================================================
69 // ============================================================================
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
85 void wxTimer::Notify()
88 // The base class version generates an event if it has owner - which it
89 // should because otherwise nobody can process timer events, but it does
90 // not use the OS's ID, which OS/2 must have to figure out which timer fired
92 wxCHECK_RET( m_owner
, _T("wxTimer::Notify() should be overridden.") );
94 wxTimerEvent
vEvent( m_idTimer
98 (void)m_owner
->ProcessEvent(vEvent
);
99 } // end of wxTimer::Notify
106 (void)wxTimerBase::Start( nMilliseconds
110 wxCHECK_MSG( m_milli
> 0L, FALSE
, wxT("invalid value for timer") );
112 wxWindow
* pWin
= NULL
;
116 pWin
= (wxWindow
*)m_owner
;
117 m_ulId
= ::WinStartTimer( m_Hab
120 ,(ULONG
)nMilliseconds
124 m_ulId
= ::WinStartTimer( m_Hab
127 ,(ULONG
)nMilliseconds
131 // check that SetTimer() didn't reuse an existing id: according to
132 // the MSDN this can happen and this would be catastrophic to us as
133 // we rely on ids uniquely identifying the timers because we use
134 // them as keys in the hash
135 if ( TimerMap().find(m_ulId
) != TimerMap().end() )
137 wxLogError(_("Timer creation failed."));
139 ::WinStopTimer(m_Hab
, pWin
?(pWin
->GetHWND()):NULL
, m_ulId
);
145 TimerMap()[m_ulId
] = this;
151 wxLogSysError(_("Couldn't create a timer"));
163 wxWindow
* pWin
= (wxWindow
*)m_owner
;
165 ::WinStopTimer(m_Hab
, pWin
->GetHWND(), m_ulId
);
168 ::WinStopTimer(m_Hab
, NULLHANDLE
, m_ulId
);
170 TimerMap().erase(m_ulId
);
175 // ----------------------------------------------------------------------------
177 // ----------------------------------------------------------------------------
184 // Avoid to process spurious timer events
186 if (rTimer
.m_ulId
== 0L)
189 if (rTimer
.IsOneShot())
202 wxTimerMap::iterator node
= TimerMap().find((ULONG
)nIdTimer
);
204 wxCHECK_MSG(node
!= TimerMap().end(), 0,
205 wxT("bogus timer id in wxTimerProc") );
206 wxProcessTimer(*(node
->second
));