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