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 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxEvtHandler
)
21 #include "wx/mac/private.h"
27 #include "wx/dynarray.h"
29 typedef struct MacTimerInfo
32 wxMacNotifierTableRef m_table
;
36 static void wxProcessTimer( unsigned long event
, void *data
) ;
38 static pascal void MacTimerProc( TMTask
* t
)
40 MacTimerInfo
* tm
= (MacTimerInfo
*) t
;
41 wxMacAddEvent( tm
->m_table
, wxProcessTimer
, 0 , (void*) tm
->m_timer
, TRUE
) ;
44 // we need this array to track timers that are being deleted within the Notify procedure
45 // adding the timer before the Notify call and checking after whether it still is in there
46 // as the destructor would have removed it from the array
48 wxArrayPtrVoid gTimersInProcess
;
50 static void wxProcessTimer( unsigned long event
, void *data
)
55 wxTimer
* timer
= (wxTimer
*) data
;
57 if ( timer
->IsOneShot() )
60 gTimersInProcess
.Add( timer
) ;
64 int index
= gTimersInProcess
.Index( timer
) ;
66 if ( index
!= wxNOT_FOUND
)
68 gTimersInProcess
.RemoveAt( index
) ;
70 if ( !timer
->IsOneShot() && timer
->m_info
->m_task
.tmAddr
)
72 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 ) ;