]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/timer.cpp
8c322fbb384f7c17df68f2b0fe5ead8ac9a3f406
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/timer.cpp
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"
16 #include "wx/window.h"
22 #include "wx/os2/private.h"
29 #include <sys/types.h>
31 #include <sys/timeb.h>
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 // define a hash containing all the timers: it is indexed by timer id and
38 // contains the corresponding timer
39 WX_DECLARE_HASH_MAP(unsigned long, wxTimer
*, wxIntegerHash
, wxIntegerEqual
,
42 // instead of using a global here, wrap it in a static function as otherwise it
43 // could have been used before being initialized if a timer object were created
45 static wxTimerMap
& TimerMap()
47 static wxTimerMap s_timerMap
;
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 // timer callback used for all timers
57 ULONG
wxTimerProc(HWND hwnd
, ULONG
, int nIdTimer
, ULONG
);
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxEvtHandler
)
65 // ============================================================================
67 // ============================================================================
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
83 void wxTimer::Notify()
86 // The base class version generates an event if it has owner - which it
87 // should because otherwise nobody can process timer events, but it does
88 // not use the OS's ID, which OS/2 must have to figure out which timer fired
90 wxCHECK_RET( m_owner
, _T("wxTimer::Notify() should be overridden.") );
92 wxTimerEvent
vEvent( m_idTimer
96 (void)m_owner
->ProcessEvent(vEvent
);
97 } // end of wxTimer::Notify
104 (void)wxTimerBase::Start( nMilliseconds
108 wxCHECK_MSG( m_milli
> 0L, FALSE
, wxT("invalid value for timer") );
110 wxWindow
* pWin
= NULL
;
114 pWin
= (wxWindow
*)m_owner
;
115 m_ulId
= ::WinStartTimer( m_Hab
118 ,(ULONG
)nMilliseconds
122 m_ulId
= ::WinStartTimer( m_Hab
125 ,(ULONG
)nMilliseconds
129 // check that SetTimer() didn't reuse an existing id: according to
130 // the MSDN this can happen and this would be catastrophic to us as
131 // we rely on ids uniquely identifying the timers because we use
132 // them as keys in the hash
133 if ( TimerMap().find(m_ulId
) != TimerMap().end() )
135 wxLogError(_("Timer creation failed."));
137 ::WinStopTimer(m_Hab
, pWin
?(pWin
->GetHWND()):NULL
, m_ulId
);
143 TimerMap()[m_ulId
] = this;
149 wxLogSysError(_("Couldn't create a timer"));
161 wxWindow
* pWin
= (wxWindow
*)m_owner
;
163 ::WinStopTimer(m_Hab
, pWin
->GetHWND(), m_ulId
);
166 ::WinStopTimer(m_Hab
, NULLHANDLE
, m_ulId
);
168 TimerMap().erase(m_ulId
);
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
182 // Avoid to process spurious timer events
184 if (rTimer
.m_ulId
== 0L)
187 if (rTimer
.IsOneShot())
200 wxTimerMap::iterator node
= TimerMap().find((ULONG
)nIdTimer
);
202 wxCHECK_MSG(node
!= TimerMap().end(), 0,
203 wxT("bogus timer id in wxTimerProc") );
204 wxProcessTimer(*(node
->second
));