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"
29 #include "wx/cocoa/autorelease.h"
31 #import <Foundation/NSTimer.h>
33 // ============================================================================
35 // ============================================================================
37 IMPLEMENT_CLASS(wxTimer, wxTimerBase)
39 // ========================================================================
41 // ========================================================================
42 @interface wxNSTimerData : NSObject
48 - (id)initWithWxTimer:(wxTimer*)theTimer;
50 - (void)onNotify:(NSTimer *)theTimer;
51 @end // interface wxNSTimerData : NSObject
53 @implementation wxNSTimerData : NSObject
56 if(!(self = [super init]))
62 - (id)initWithWxTimer:(wxTimer*)theTimer;
64 if(!(self = [super init]))
75 - (void)onNotify:(NSTimer *)theTimer
77 m_timer->Notify(); //wxTimerBase method
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
92 m_cocoaNSTimer = NULL;
95 bool wxTimer::Start(int millisecs, bool oneShot)
99 wxAutoNSAutoreleasePool thePool;
101 wxNSTimerData *timerData = [[wxNSTimerData alloc] initWithWxTimer:this];
102 m_cocoaNSTimer = [[NSTimer
103 scheduledTimerWithTimeInterval: millisecs / 1000.0 //seconds
105 selector: @selector(onNotify:)
107 repeats: oneShot == false] retain];
117 // FIXME: Is this safe to do if !isValid ?
118 [m_cocoaNSTimer invalidate];
119 [m_cocoaNSTimer release];
120 m_cocoaNSTimer = NULL;
124 bool wxTimer::IsRunning() const
126 return m_cocoaNSTimer != NULL && [m_cocoaNSTimer isValid];
129 #endif // wxUSE_TIMER