1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTimer implementation
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
14 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxEvtHandler
)
17 #include "wx/mac/private.h"
23 #include "wx/dynarray.h"
25 typedef struct MacTimerInfo
28 wxMacNotifierTableRef m_table
;
32 static void wxProcessTimer( unsigned long event
, void *data
) ;
34 static pascal void MacTimerProc( TMTask
* t
)
36 MacTimerInfo
* tm
= (MacTimerInfo
*) t
;
37 wxMacAddEvent( tm
->m_table
, wxProcessTimer
, 0 , (void*) tm
->m_timer
, TRUE
) ;
40 // we need this array to track timers that are being deleted within the Notify procedure
41 // adding the timer before the Notify call and checking after whether it still is in there
42 // as the destructor would have removed it from the array
44 wxArrayPtrVoid gTimersInProcess
;
46 static void wxProcessTimer( unsigned long event
, void *data
)
51 wxTimer
* timer
= (wxTimer
*) data
;
53 if ( timer
->IsOneShot() )
56 gTimersInProcess
.Add( timer
) ;
60 int index
= gTimersInProcess
.Index( timer
) ;
62 if ( index
!= wxNOT_FOUND
)
64 gTimersInProcess
.RemoveAt( index
) ;
66 if ( !timer
->IsOneShot() && timer
->m_info
->m_task
.tmAddr
)
68 PrimeTime( (QElemPtr
) &timer
->m_info
->m_task
, timer
->GetInterval() ) ;
76 m_info
= new MacTimerInfo() ;
77 m_info
->m_task
.tmAddr
= NULL
;
78 m_info
->m_task
.tmWakeUp
= 0 ;
79 m_info
->m_task
.tmReserved
= 0 ;
80 m_info
->m_task
.qType
= 0 ;
81 m_info
->m_table
= wxMacGetNotifierTable() ;
82 m_info
->m_timer
= this ;
85 bool wxTimer::IsRunning() const
87 // as the qType may already indicate it is elapsed, but it
88 // was not handled internally yet
89 return ( m_info
->m_task
.tmAddr
!= NULL
) ;
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 timeout") );
109 wxCHECK_MSG( m_info
->m_task
.tmAddr
== NULL
, FALSE
, wxT("attempting to restart a timer") );
111 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
112 m_info
->m_task
.tmAddr
= NewTimerUPP( MacTimerProc
) ;
114 m_info
->m_task
.tmAddr
= NewTimerProc( MacTimerProc
) ;
116 m_info
->m_task
.tmWakeUp
= 0 ;
117 m_info
->m_task
.tmReserved
= 0 ;
118 m_info
->m_task
.qType
= 0 ;
119 m_info
->m_timer
= this ;
120 InsXTime((QElemPtr
) &m_info
->m_task
) ;
121 PrimeTime( (QElemPtr
) &m_info
->m_task
, m_milli
) ;
127 if ( m_info
->m_task
.tmAddr
)
129 RmvTime( (QElemPtr
) &m_info
->m_task
) ;
130 DisposeTimerUPP(m_info
->m_task
.tmAddr
) ;
131 m_info
->m_task
.tmAddr
= NULL
;
133 wxMacRemoveAllNotifiersForData( wxMacGetNotifierTable() , this ) ;