1 /////////////////////////////////////////////////////////////////////////////
2 // Name: sec/mac/carbon/timer.cpp
3 // Purpose: wxTimer implementation
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
17 #include "wx/dynarray.h"
20 #include "wx/mac/private/timer.h"
23 #include "wx/mac/private.h"
28 wxCarbonTimerImpl
* m_timer
;
29 EventLoopTimerUPP m_proc
;
30 EventLoopTimerRef m_timerRef
;
33 static pascal void wxProcessTimer( EventLoopTimerRef
WXUNUSED(theTimer
), void *data
)
38 wxCarbonTimerImpl
* timer
= (wxCarbonTimerImpl
*)data
;
40 if ( timer
->IsOneShot() )
46 wxCarbonTimerImpl::wxCarbonTimerImpl(wxTimer
*timer
)
49 m_info
= new MacTimerInfo();
50 m_info
->m_timer
= this;
51 m_info
->m_proc
= NULL
;
52 m_info
->m_timerRef
= kInvalidID
;
55 bool wxCarbonTimerImpl::IsRunning() const
57 return ( m_info
->m_timerRef
!= kInvalidID
);
60 wxCarbonTimerImpl::~wxCarbonTimerImpl()
65 bool wxCarbonTimerImpl::Start( int milliseconds
, bool mode
)
67 (void)wxTimerImpl::Start(milliseconds
, mode
);
69 wxCHECK_MSG( m_milli
> 0, false, wxT("invalid value for timer timeout") );
70 wxCHECK_MSG( m_info
->m_timerRef
== NULL
, false, wxT("attempting to restart a timer") );
72 m_info
->m_timer
= this;
73 m_info
->m_proc
= NewEventLoopTimerUPP( &wxProcessTimer
);
75 OSStatus err
= InstallEventLoopTimer(
77 m_milli
*kEventDurationMillisecond
,
78 IsOneShot() ? 0 : m_milli
* kEventDurationMillisecond
,
81 &m_info
->m_timerRef
);
87 void wxCarbonTimerImpl::Stop()
89 if (m_info
->m_timerRef
)
90 RemoveEventLoopTimer( m_info
->m_timerRef
);
92 DisposeEventLoopTimerUPP( m_info
->m_proc
);
94 m_info
->m_proc
= NULL
;
95 m_info
->m_timerRef
= kInvalidID
;