1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/classic/timer.cpp 
   3 // Purpose:     wxTimer implementation 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // for compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  18     #include "wx/dynarray.h" 
  21 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxEvtHandler
) 
  24 #include "wx/mac/private.h" 
  30 typedef struct MacTimerInfo
 
  33     wxMacNotifierTableRef m_table 
; 
  37 static void wxProcessTimer( unsigned long event 
, void *data 
) ; 
  39 static pascal void MacTimerProc( TMTask 
* t 
) 
  41     MacTimerInfo 
* tm 
= (MacTimerInfo
*)  t 
; 
  42     wxMacAddEvent( tm
->m_table 
, wxProcessTimer
, 0 , (void*) tm
->m_timer 
, TRUE 
) ; 
  45 // we need this array to track timers that are being deleted within the Notify procedure 
  46 // adding the timer before the Notify call and checking after whether it still is in there 
  47 // as the destructor would have removed it from the array 
  49 wxArrayPtrVoid gTimersInProcess 
; 
  51 static void wxProcessTimer( unsigned long event 
, void *data 
) 
  56     wxTimer
* timer 
= (wxTimer
*) data 
; 
  58     if ( timer
->IsOneShot() ) 
  61     gTimersInProcess
.Add( timer 
) ; 
  65     int index 
= gTimersInProcess
.Index( timer 
) ; 
  67     if ( index 
!= wxNOT_FOUND 
) 
  69         gTimersInProcess
.RemoveAt( index 
) ; 
  71         if ( !timer
->IsOneShot() && timer
->m_info
->m_task
.tmAddr 
) 
  73             PrimeTime( (QElemPtr
)  &timer
->m_info
->m_task 
, timer
->GetInterval() ) ; 
  80     m_info 
= new MacTimerInfo() ; 
  81     m_info
->m_task
.tmAddr 
= NULL 
; 
  82     m_info
->m_task
.tmWakeUp 
= 0 ; 
  83     m_info
->m_task
.tmReserved 
= 0 ; 
  84     m_info
->m_task
.qType 
= 0 ; 
  85     m_info
->m_table 
= wxMacGetNotifierTable() ; 
  86     m_info
->m_timer 
= this ; 
  89 bool wxTimer::IsRunning() const 
  91     // as the qType may already indicate it is elapsed, but it 
  92     // was not handled internally yet 
  93     return ( m_info
->m_task
.tmAddr 
!= NULL 
) ; 
 103     int index 
= gTimersInProcess
.Index( this ) ; 
 104     if ( index 
!= wxNOT_FOUND 
) 
 105         gTimersInProcess
.RemoveAt( index 
) ; 
 108 bool wxTimer::Start(int milliseconds
,bool mode
) 
 110     (void)wxTimerBase::Start(milliseconds
, mode
); 
 112     wxCHECK_MSG( m_milli 
> 0, false, wxT("invalid value for timer timeout") ); 
 113     wxCHECK_MSG( m_info
->m_task
.tmAddr 
== NULL 
, false, wxT("attempting to restart a timer") ); 
 115 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) 
 116     m_info
->m_task
.tmAddr 
= NewTimerUPP( MacTimerProc 
) ; 
 118     m_info
->m_task
.tmAddr 
= NewTimerProc( MacTimerProc 
) ; 
 120     m_info
->m_task
.tmWakeUp 
= 0 ; 
 121     m_info
->m_task
.tmReserved 
= 0 ; 
 122     m_info
->m_task
.qType 
= 0 ; 
 123     m_info
->m_timer 
= this ; 
 124     InsXTime((QElemPtr
) &m_info
->m_task 
) ; 
 125     PrimeTime( (QElemPtr
) &m_info
->m_task 
, m_milli 
) ; 
 131     if ( m_info
->m_task
.tmAddr 
) 
 133         RmvTime(  (QElemPtr
) &m_info
->m_task 
) ; 
 134         DisposeTimerUPP(m_info
->m_task
.tmAddr
) ; 
 135         m_info
->m_task
.tmAddr 
= NULL 
; 
 137     wxMacRemoveAllNotifiersForData( wxMacGetNotifierTable() , this ) ;