]>
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 
   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/os2/private/timer.h" 
  19     #include "wx/window.h" 
  26 #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, wxOS2TimerImpl 
*, 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 // ---------------------------------------------------------------------------- 
  65 // ---------------------------------------------------------------------------- 
  67 bool wxOS2TimerImpl::Start( int nMilliseconds
, bool bOneShot 
) 
  69     if ( !wxTimerImpl::Start( nMilliseconds
, bOneShot 
) ) 
  72     wxWindow
* pWin 
= NULL
; 
  76         pWin 
= (wxWindow
*)m_owner
; 
  77         m_ulId 
= ::WinStartTimer( m_Hab
 
  85         m_ulId 
= ::WinStartTimer( m_Hab
 
  94         // check that SetTimer() didn't reuse an existing id: according to 
  95         // the MSDN this can happen and this would be catastrophic to us as 
  96         // we rely on ids uniquely identifying the timers because we use 
  97         // them as keys in the hash 
  98         if ( TimerMap().find(m_ulId
) != TimerMap().end() ) 
 100             wxLogError(_("Timer creation failed.")); 
 102             ::WinStopTimer(m_Hab
, pWin
?(pWin
->GetHWND()):NULL
, m_ulId
); 
 108         TimerMap()[m_ulId
] = this; 
 114         wxLogSysError(_("Couldn't create a timer")); 
 120 void wxOS2TimerImpl::Stop() 
 126             wxWindow
*                   pWin 
= (wxWindow
*)m_owner
; 
 128             ::WinStopTimer(m_Hab
, pWin
->GetHWND(), m_ulId
); 
 131             ::WinStopTimer(m_Hab
, NULLHANDLE
, m_ulId
); 
 133         TimerMap().erase(m_ulId
); 
 138 // ---------------------------------------------------------------------------- 
 140 // ---------------------------------------------------------------------------- 
 143   wxOS2TimerImpl
&                          rTimer
 
 147     // Avoid to process spurious timer events 
 149     if (rTimer
.m_ulId 
== 0L) 
 152     if (rTimer
.IsOneShot()) 
 165     wxTimerMap::iterator node 
= TimerMap().find((ULONG
)nIdTimer
); 
 167     wxCHECK_MSG(node 
!= TimerMap().end(), 0, 
 168                 wxT("bogus timer id in wxTimerProc") ); 
 169     wxProcessTimer(*(node
->second
));