]>
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 ///////////////////////////////////////////////////////////////////////////// 
  13     #pragma implementation "timer.h" 
  16 // For compilers that support precompilation, includes "wx.h". 
  17 #include "wx/wxprec.h" 
  19 #include "wx/window.h" 
  20 #include "wx/os2/private.h" 
  35 #include <sys/types.h> 
  37 #include <sys/timeb.h> 
  39 // ---------------------------------------------------------------------------- 
  41 // ---------------------------------------------------------------------------- 
  43 // define a hash containing all the timers: it is indexed by timer id and 
  44 // contains the corresponding timer 
  45 WX_DECLARE_HASH_MAP(unsigned long, wxTimer 
*, wxIntegerHash
, wxIntegerEqual
, 
  48 // instead of using a global here, wrap it in a static function as otherwise it 
  49 // could have been used before being initialized if a timer object were created 
  51 static wxTimerMap
& TimerMap() 
  53     static wxTimerMap s_timerMap
; 
  58 // ---------------------------------------------------------------------------- 
  60 // ---------------------------------------------------------------------------- 
  62 // timer callback used for all timers 
  63 ULONG 
wxTimerProc(HWND hwnd
, ULONG
, int nIdTimer
, ULONG
); 
  65 // ---------------------------------------------------------------------------- 
  67 // ---------------------------------------------------------------------------- 
  69 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxEvtHandler
) 
  71 // ============================================================================ 
  73 // ============================================================================ 
  75 // ---------------------------------------------------------------------------- 
  77 // ---------------------------------------------------------------------------- 
  89 void wxTimer::Notify() 
  92     // The base class version generates an event if it has owner - which it 
  93     // should because otherwise nobody can process timer events, but it does 
  94     // not use the OS's ID, which OS/2 must have to figure out which timer fired 
  96     wxCHECK_RET( m_owner
, _T("wxTimer::Notify() should be overridden.") ); 
  98     wxTimerEvent                    
vEvent( m_idTimer
 
 102     (void)m_owner
->ProcessEvent(vEvent
); 
 103 } // end of wxTimer::Notify 
 110     (void)wxTimerBase::Start( nMilliseconds
 
 114     wxCHECK_MSG( m_milli 
> 0L, FALSE
, wxT("invalid value for timer") ); 
 116     wxWindow
*                       pWin 
= NULL
; 
 120         pWin 
= (wxWindow
*)m_owner
; 
 121         m_ulId 
= ::WinStartTimer( m_Hab
 
 124                                  ,(ULONG
)nMilliseconds
 
 128         m_ulId 
= ::WinStartTimer( m_Hab
 
 131                                  ,(ULONG
)nMilliseconds
 
 135         // check that SetTimer() didn't reuse an existing id: according to 
 136         // the MSDN this can happen and this would be catastrophic to us as 
 137         // we rely on ids uniquely identifying the timers because we use 
 138         // them as keys in the hash 
 139         if ( TimerMap().find(m_ulId
) != TimerMap().end() ) 
 141             wxLogError(_("Timer creation failed.")); 
 143             ::WinStopTimer(m_Hab
, pWin
?(pWin
->GetHWND()):NULL
, m_ulId
); 
 149         TimerMap()[m_ulId
] = this; 
 155         wxLogSysError(_("Couldn't create a timer")); 
 167             wxWindow
*                   pWin 
= (wxWindow
*)m_owner
; 
 169             ::WinStopTimer(m_Hab
, pWin
->GetHWND(), m_ulId
); 
 172             ::WinStopTimer(m_Hab
, NULLHANDLE
, m_ulId
); 
 174         TimerMap().erase(m_ulId
); 
 179 // ---------------------------------------------------------------------------- 
 181 // ---------------------------------------------------------------------------- 
 188     // Avoid to process spurious timer events 
 190     if (rTimer
.m_ulId 
== 0L) 
 193     if (rTimer
.IsOneShot()) 
 206     wxTimerMap::iterator node 
= TimerMap().find((ULONG
)nIdTimer
); 
 208     wxCHECK_MSG(node 
!= TimerMap().end(), 0, 
 209                 wxT("bogus timer id in wxTimerProc") ); 
 210     wxProcessTimer(*(node
->second
));