]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/timer.cpp
remove old thread debugging code
[wxWidgets.git] / src / mac / carbon / timer.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
0ec80ebe 2// Name: sec/mac/carbon/timer.cpp
e9576ca5 3// Purpose: wxTimer implementation
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
ad9835c9 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878
SC
12#include "wx/wxprec.h"
13
72c1ba98
VZ
14#if wxUSE_TIMER
15
ad9835c9
WS
16#ifndef WX_PRECOMP
17 #include "wx/dynarray.h"
18#endif
19
c2ca375c 20#include "wx/mac/private/timer.h"
e9576ca5 21
76a5e5d2 22#ifdef __WXMAC__
ad9835c9 23 #include "wx/mac/private.h"
76a5e5d2 24#endif
0ec80ebe 25
d0ee33f5 26struct MacTimerInfo
514982b2 27{
c2ca375c 28 wxCarbonTimerImpl* m_timer;
0ec80ebe
DS
29 EventLoopTimerUPP m_proc;
30 EventLoopTimerRef m_timerRef;
31};
514982b2 32
89954433 33static pascal void wxProcessTimer( EventLoopTimerRef WXUNUSED(theTimer), void *data )
514982b2 34{
0ec80ebe
DS
35 if ( data == NULL )
36 return;
d0ee33f5 37
c2ca375c 38 wxCarbonTimerImpl* timer = (wxCarbonTimerImpl*)data;
d0ee33f5 39
514982b2 40 if ( timer->IsOneShot() )
0ec80ebe 41 timer->Stop();
514982b2
SC
42
43 timer->Notify();
44}
45
c2ca375c
VZ
46wxCarbonTimerImpl::wxCarbonTimerImpl(wxTimer *timer)
47 : wxTimerImpl(timer)
514982b2 48{
0ec80ebe
DS
49 m_info = new MacTimerInfo();
50 m_info->m_timer = this;
51 m_info->m_proc = NULL;
52 m_info->m_timerRef = kInvalidID;
514982b2
SC
53}
54
c2ca375c 55bool wxCarbonTimerImpl::IsRunning() const
514982b2 56{
0ec80ebe 57 return ( m_info->m_timerRef != kInvalidID );
514982b2
SC
58}
59
c2ca375c 60wxCarbonTimerImpl::~wxCarbonTimerImpl()
514982b2 61{
c2ca375c 62 delete m_info;
514982b2
SC
63}
64
c2ca375c 65bool wxCarbonTimerImpl::Start( int milliseconds, bool mode )
514982b2 66{
c2ca375c 67 (void)wxTimerImpl::Start(milliseconds, mode);
514982b2 68
d0ee33f5 69 wxCHECK_MSG( m_milli > 0, false, wxT("invalid value for timer timeout") );
0ec80ebe
DS
70 wxCHECK_MSG( m_info->m_timerRef == NULL, false, wxT("attempting to restart a timer") );
71
72 m_info->m_timer = this;
73 m_info->m_proc = NewEventLoopTimerUPP( &wxProcessTimer );
514982b2 74
0ec80ebe
DS
75 OSStatus err = InstallEventLoopTimer(
76 GetMainEventLoop(),
514982b2 77 m_milli*kEventDurationMillisecond,
0ec80ebe 78 IsOneShot() ? 0 : m_milli * kEventDurationMillisecond,
514982b2
SC
79 m_info->m_proc,
80 this,
0ec80ebe
DS
81 &m_info->m_timerRef );
82 verify_noerr( err );
83
d0ee33f5 84 return true;
514982b2
SC
85}
86
c2ca375c 87void wxCarbonTimerImpl::Stop()
514982b2
SC
88{
89 if (m_info->m_timerRef)
0ec80ebe 90 RemoveEventLoopTimer( m_info->m_timerRef );
514982b2 91 if (m_info->m_proc)
0ec80ebe
DS
92 DisposeEventLoopTimerUPP( m_info->m_proc );
93
94 m_info->m_proc = NULL;
95 m_info->m_timerRef = kInvalidID;
514982b2
SC
96}
97
72c1ba98
VZ
98#endif // wxUSE_TIMER
99