]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/timer.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/timer.cpp
3 // Purpose: wxTimer implementation
4 // Author: David Webster
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #include "wx/os2/private/timer.h"
18 #include "wx/window.h"
25 #include "wx/os2/private.h"
28 #include <sys/types.h>
30 #include <sys/timeb.h>
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 // define a hash containing all the timers: it is indexed by timer id and
37 // contains the corresponding timer
38 WX_DECLARE_HASH_MAP(unsigned long, wxOS2TimerImpl
*, wxIntegerHash
, wxIntegerEqual
,
41 // instead of using a global here, wrap it in a static function as otherwise it
42 // could have been used before being initialized if a timer object were created
44 static wxTimerMap
& TimerMap()
46 static wxTimerMap s_timerMap
;
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 // timer callback used for all timers
56 ULONG
wxTimerProc(HWND hwnd
, ULONG
, int nIdTimer
, ULONG
);
58 // ============================================================================
60 // ============================================================================
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 bool wxOS2TimerImpl::Start( int nMilliseconds
, bool bOneShot
)
68 if ( !wxTimerImpl::Start( nMilliseconds
, bOneShot
) )
71 wxWindow
* pWin
= NULL
;
75 pWin
= (wxWindow
*)m_owner
;
76 m_ulId
= ::WinStartTimer( m_Hab
84 m_ulId
= ::WinStartTimer( m_Hab
93 // check that SetTimer() didn't reuse an existing id: according to
94 // the MSDN this can happen and this would be catastrophic to us as
95 // we rely on ids uniquely identifying the timers because we use
96 // them as keys in the hash
97 if ( TimerMap().find(m_ulId
) != TimerMap().end() )
99 wxLogError(_("Timer creation failed."));
101 ::WinStopTimer(m_Hab
, pWin
?(pWin
->GetHWND()):NULL
, m_ulId
);
107 TimerMap()[m_ulId
] = this;
113 wxLogSysError(_("Couldn't create a timer"));
119 void wxOS2TimerImpl::Stop()
125 wxWindow
* pWin
= (wxWindow
*)m_owner
;
127 ::WinStopTimer(m_Hab
, pWin
->GetHWND(), m_ulId
);
130 ::WinStopTimer(m_Hab
, NULLHANDLE
, m_ulId
);
132 TimerMap().erase(m_ulId
);
137 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
142 wxOS2TimerImpl
& rTimer
146 // Avoid to process spurious timer events
148 if (rTimer
.m_ulId
== 0L)
151 if (rTimer
.IsOneShot())
164 wxTimerMap::iterator node
= TimerMap().find((ULONG
)nIdTimer
);
166 wxCHECK_MSG(node
!= TimerMap().end(), 0,
167 wxT("bogus timer id in wxTimerProc") );
168 wxProcessTimer(*(node
->second
));