1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/timer.cpp
3 // Purpose: wxTimer implementation
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
16 #include "wx/dynarray.h"
19 #include "wx/osx/private/timer.h"
22 #include "wx/osx/private.h"
27 wxCarbonTimerImpl
* m_timer
;
28 EventLoopTimerUPP m_proc
;
29 EventLoopTimerRef m_timerRef
;
32 static pascal void wxProcessTimer( EventLoopTimerRef
WXUNUSED(theTimer
), void *data
)
37 wxCarbonTimerImpl
* timer
= (wxCarbonTimerImpl
*)data
;
39 if ( timer
->IsOneShot() )
45 wxCarbonTimerImpl::wxCarbonTimerImpl(wxTimer
*timer
)
48 m_info
= new MacTimerInfo();
49 m_info
->m_timer
= this;
50 m_info
->m_proc
= NULL
;
51 m_info
->m_timerRef
= kInvalidID
;
54 bool wxCarbonTimerImpl::IsRunning() const
56 return ( m_info
->m_timerRef
!= kInvalidID
);
59 wxCarbonTimerImpl::~wxCarbonTimerImpl()
64 bool wxCarbonTimerImpl::Start( int milliseconds
, bool mode
)
66 (void)wxTimerImpl::Start(milliseconds
, mode
);
68 wxCHECK_MSG( m_milli
> 0, false, wxT("invalid value for timer timeout") );
69 wxCHECK_MSG( m_info
->m_timerRef
== NULL
, false, wxT("attempting to restart a timer") );
71 m_info
->m_timer
= this;
72 m_info
->m_proc
= NewEventLoopTimerUPP( &wxProcessTimer
);
74 OSStatus err
= InstallEventLoopTimer(
76 m_milli
*kEventDurationMillisecond
,
77 IsOneShot() ? 0 : m_milli
* kEventDurationMillisecond
,
80 &m_info
->m_timerRef
);
86 void wxCarbonTimerImpl::Stop()
88 if (m_info
->m_timerRef
)
89 RemoveEventLoopTimer( m_info
->m_timerRef
);
91 DisposeEventLoopTimerUPP( m_info
->m_proc
);
93 m_info
->m_proc
= NULL
;
94 m_info
->m_timerRef
= kInvalidID
;