1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/timer.mm
3 // Purpose: wxTimer for wxCocoa
5 // Modified by: David Elliott
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/cocoa/autorelease.h"
32 #import <Foundation/NSTimer.h>
34 // ============================================================================
36 // ============================================================================
38 IMPLEMENT_CLASS(wxTimer, wxTimerBase)
40 // ========================================================================
42 // ========================================================================
43 @interface wxNSTimerData : NSObject
49 - (id)initWithWxTimer:(wxTimer*)theTimer;
51 - (void)onNotify:(NSTimer *)theTimer;
52 @end // interface wxNSTimerData : NSObject
54 @implementation wxNSTimerData : NSObject
57 if(!(self = [super init]))
63 - (id)initWithWxTimer:(wxTimer*)theTimer;
65 if(!(self = [super init]))
76 - (void)onNotify:(NSTimer *)theTimer
78 m_timer->Notify(); //wxTimerBase method
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
93 m_cocoaNSTimer = NULL;
96 bool wxTimer::Start(int millisecs, bool oneShot)
100 wxAutoNSAutoreleasePool thePool;
102 wxNSTimerData *timerData = [[wxNSTimerData alloc] initWithWxTimer:this];
103 m_cocoaNSTimer = [[NSTimer
104 scheduledTimerWithTimeInterval: millisecs / 1000.0 //seconds
106 selector: @selector(onNotify:)
108 repeats: oneShot == false] retain];
118 // FIXME: Is this safe to do if !isValid ?
119 [m_cocoaNSTimer invalidate];
120 [m_cocoaNSTimer release];
121 m_cocoaNSTimer = NULL;
125 bool wxTimer::IsRunning() const
127 return m_cocoaNSTimer != NULL && [m_cocoaNSTimer isValid];
130 #endif // wxUSE_TIMER