1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxTimer implementation 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:       wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "timer.h" 
  18 #if !USE_SHARED_LIBRARY 
  19 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxObject
) 
  23 #include "wx/mac/private.h" 
  29 #include "wx/dynarray.h" 
  31 typedef struct MacTimerInfo
 
  34     wxMacNotifierTableRef m_table 
; 
  38 static void wxProcessTimer( unsigned long event 
, void *data 
) ; 
  40 static pascal void MacTimerProc( TMTask 
* t 
) 
  42     MacTimerInfo 
* tm 
= (MacTimerInfo
*)  t 
; 
  43     wxMacAddEvent( tm
->m_table 
, wxProcessTimer
, 0 , (void*) tm
->m_timer 
, TRUE 
) ; 
  46 wxArrayPtrVoid gTimersInProcess 
; 
  48 static void wxProcessTimer( unsigned long event 
, void *data 
) 
  53     wxTimer
* timer 
= (wxTimer
*) data 
; 
  55     if ( timer
->IsOneShot() ) 
  58     gTimersInProcess
.Add( timer 
) ; 
  62     int index 
= gTimersInProcess
.Index( timer 
) ; 
  64     if ( index 
!= wxNOT_FOUND 
) 
  66         gTimersInProcess
.RemoveAt( index 
) ; 
  68         if ( !timer
->IsOneShot() && timer
->m_info
->m_task
.tmAddr 
) 
  70             PrimeTime( (QElemPtr
)  &timer
->m_info
->m_task 
, timer
->GetInterval() ) ; 
  78     m_info 
= new MacTimerInfo() ; 
  79     m_info
->m_task
.tmAddr 
= NULL 
; 
  80     m_info
->m_task
.tmWakeUp 
= 0 ; 
  81     m_info
->m_task
.tmReserved 
= 0 ; 
  82     m_info
->m_task
.qType 
= 0 ; 
  83     m_info
->m_table 
= wxMacGetNotifierTable() ; 
  84     m_info
->m_timer 
= this ; 
  87 bool wxTimer::IsRunning() const  
  89     return ( m_info
->m_task
.qType 
& kTMTaskActive 
) ; 
  99     int index 
= gTimersInProcess
.Index( this ) ; 
 100     if ( index 
!= wxNOT_FOUND 
) 
 101         gTimersInProcess
.RemoveAt( index 
) ;   
 104 bool wxTimer::Start(int milliseconds
,bool mode
) 
 106     (void)wxTimerBase::Start(milliseconds
, mode
); 
 108     wxCHECK_MSG( m_milli 
> 0, FALSE
, wxT("invalid value for timer timeour") ); 
 109     wxCHECK_MSG( m_info
->m_task
.tmAddr 
== NULL 
, FALSE
, wxT("attempting to restart a timer") ); 
 111     m_milli 
= milliseconds
; 
 112 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) 
 113     m_info
->m_task
.tmAddr 
= NewTimerUPP( MacTimerProc 
) ; 
 115     m_info
->m_task
.tmAddr 
= NewTimerProc( MacTimerProc 
) ; 
 117     m_info
->m_task
.tmWakeUp 
= 0 ; 
 118     m_info
->m_task
.tmReserved 
= 0 ; 
 119     m_info
->m_task
.qType 
= 0 ; 
 120     m_info
->m_timer 
= this ; 
 121     InsXTime((QElemPtr
) &m_info
->m_task 
) ; 
 122     PrimeTime( (QElemPtr
) &m_info
->m_task 
, m_milli 
) ; 
 128     if ( m_info
->m_task
.tmAddr 
) 
 130         RmvTime(  (QElemPtr
) &m_info
->m_task 
) ; 
 131         DisposeTimerUPP(m_info
->m_task
.tmAddr
) ; 
 132         m_info
->m_task
.tmAddr 
= NULL 
; 
 134     wxMacRemoveAllNotifiersForData( wxMacGetNotifierTable() , this ) ;