]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/timer.cpp
Implement native OS X ComboBox for OS X Cocoa, and implement wxTextEntry methods...
[wxWidgets.git] / src / osx / carbon / timer.cpp
CommitLineData
489468fe
SC
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
1f0c8f31 20#include "wx/osx/private/timer.h"
489468fe
SC
21
22#ifdef __WXMAC__
1f0c8f31 23 #include "wx/osx/private.h"
489468fe
SC
24#endif
25
26struct MacTimerInfo
27{
28 wxCarbonTimerImpl* m_timer;
29 EventLoopTimerUPP m_proc;
30 EventLoopTimerRef m_timerRef;
31};
32
33static 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
46wxCarbonTimerImpl::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
55bool wxCarbonTimerImpl::IsRunning() const
56{
57 return ( m_info->m_timerRef != kInvalidID );
58}
59
60wxCarbonTimerImpl::~wxCarbonTimerImpl()
61{
62 delete m_info;
63}
64
65bool 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
87void 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