]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/timer.cpp
move wxGridCellRenderer::Draw before other derived classes implementations (no real...
[wxWidgets.git] / src / osx / carbon / timer.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: sec/mac/carbon/timer.cpp
3 // Purpose: wxTimer implementation
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #if wxUSE_TIMER
15
16 #ifndef WX_PRECOMP
17 #include "wx/dynarray.h"
18 #endif
19
20 #include "wx/osx/private/timer.h"
21
22 #ifdef __WXMAC__
23 #include "wx/osx/private.h"
24 #endif
25
26 struct MacTimerInfo
27 {
28 wxCarbonTimerImpl* m_timer;
29 EventLoopTimerUPP m_proc;
30 EventLoopTimerRef m_timerRef;
31 };
32
33 static pascal void wxProcessTimer( EventLoopTimerRef WXUNUSED(theTimer), void *data )
34 {
35 if ( data == NULL )
36 return;
37
38 wxCarbonTimerImpl* timer = (wxCarbonTimerImpl*)data;
39
40 if ( timer->IsOneShot() )
41 timer->Stop();
42
43 timer->Notify();
44 }
45
46 wxCarbonTimerImpl::wxCarbonTimerImpl(wxTimer *timer)
47 : wxTimerImpl(timer)
48 {
49 m_info = new MacTimerInfo();
50 m_info->m_timer = this;
51 m_info->m_proc = NULL;
52 m_info->m_timerRef = kInvalidID;
53 }
54
55 bool wxCarbonTimerImpl::IsRunning() const
56 {
57 return ( m_info->m_timerRef != kInvalidID );
58 }
59
60 wxCarbonTimerImpl::~wxCarbonTimerImpl()
61 {
62 delete m_info;
63 }
64
65 bool wxCarbonTimerImpl::Start( int milliseconds, bool mode )
66 {
67 (void)wxTimerImpl::Start(milliseconds, mode);
68
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") );
71
72 m_info->m_timer = this;
73 m_info->m_proc = NewEventLoopTimerUPP( &wxProcessTimer );
74
75 OSStatus err = InstallEventLoopTimer(
76 GetMainEventLoop(),
77 m_milli*kEventDurationMillisecond,
78 IsOneShot() ? 0 : m_milli * kEventDurationMillisecond,
79 m_info->m_proc,
80 this,
81 &m_info->m_timerRef );
82 verify_noerr( err );
83
84 return true;
85 }
86
87 void wxCarbonTimerImpl::Stop()
88 {
89 if (m_info->m_timerRef)
90 RemoveEventLoopTimer( m_info->m_timerRef );
91 if (m_info->m_proc)
92 DisposeEventLoopTimerUPP( m_info->m_proc );
93
94 m_info->m_proc = NULL;
95 m_info->m_timerRef = kInvalidID;
96 }
97
98 #endif // wxUSE_TIMER
99