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
, wxEvtHandler
)
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 // we need this array to track timers that are being deleted within the Notify procedure
47 // adding the timer before the Notify call and checking after whether it still is in there
48 // as the destructor would have removed it from the array
50 wxArrayPtrVoid gTimersInProcess
;
52 static void wxProcessTimer( unsigned long event
, void *data
)
57 wxTimer
* timer
= (wxTimer
*) data
;
59 if ( timer
->IsOneShot() )
62 gTimersInProcess
.Add( timer
) ;
66 int index
= gTimersInProcess
.Index( timer
) ;
68 if ( index
!= wxNOT_FOUND
)
70 gTimersInProcess
.RemoveAt( index
) ;
72 if ( !timer
->IsOneShot() && timer
->m_info
->m_task
.tmAddr
)
74 PrimeTime( (QElemPtr
) &timer
->m_info
->m_task
, timer
->GetInterval() ) ;
82 m_info
= new MacTimerInfo() ;
83 m_info
->m_task
.tmAddr
= NULL
;
84 m_info
->m_task
.tmWakeUp
= 0 ;
85 m_info
->m_task
.tmReserved
= 0 ;
86 m_info
->m_task
.qType
= 0 ;
87 m_info
->m_table
= wxMacGetNotifierTable() ;
88 m_info
->m_timer
= this ;
91 bool wxTimer::IsRunning() const
93 // as the qType may already indicate it is elapsed, but it
94 // was not handled internally yet
95 return ( m_info
->m_task
.tmAddr
!= NULL
) ;
101 if (m_info
!= NULL
) {
105 int index
= gTimersInProcess
.Index( this ) ;
106 if ( index
!= wxNOT_FOUND
)
107 gTimersInProcess
.RemoveAt( index
) ;
110 bool wxTimer::Start(int milliseconds
,bool mode
)
112 (void)wxTimerBase::Start(milliseconds
, mode
);
114 wxCHECK_MSG( m_milli
> 0, FALSE
, wxT("invalid value for timer timeout") );
115 wxCHECK_MSG( m_info
->m_task
.tmAddr
== NULL
, FALSE
, wxT("attempting to restart a timer") );
117 m_info
->m_task
.tmAddr
= NewTimerUPP( MacTimerProc
) ;
118 m_info
->m_task
.tmWakeUp
= 0 ;
119 m_info
->m_task
.tmReserved
= 0 ;
120 m_info
->m_task
.qType
= 0 ;
121 m_info
->m_timer
= this ;
122 InsXTime((QElemPtr
) &m_info
->m_task
) ;
123 PrimeTime( (QElemPtr
) &m_info
->m_task
, m_milli
) ;
129 if ( m_info
->m_task
.tmAddr
)
131 RmvTime( (QElemPtr
) &m_info
->m_task
) ;
132 DisposeTimerUPP(m_info
->m_task
.tmAddr
) ;
133 m_info
->m_task
.tmAddr
= NULL
;
135 wxMacRemoveAllNotifiersForData( wxMacGetNotifierTable() , this ) ;