X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/06c2bab0852eea898770b124bed58f024f9b7cb0..12bb29f5432174ecbd65549bda832d70d34a98ae:/src/cocoa/timer.mm diff --git a/src/cocoa/timer.mm b/src/cocoa/timer.mm index 8f112e17e7..259011013d 100644 --- a/src/cocoa/timer.mm +++ b/src/cocoa/timer.mm @@ -22,42 +22,27 @@ #if wxUSE_TIMER -#ifndef WX_PRECOMP - #include "wx/timer.h" -#endif - +#include "wx/cocoa/private/timer.h" #include "wx/cocoa/autorelease.h" -#import - -// ============================================================================ -// implementation -// ============================================================================ +#include "wx/cocoa/objc/objc_uniquifying.h" -IMPLEMENT_CLASS(wxTimer, wxTimerBase) - -// ======================================================================== -// wxNSTimerDelegate -// ======================================================================== -@interface wxNSTimerDelegate : NSObject -{ -} - -- (void)onNotify:(NSTimer *)theTimer; -@end // interface wxNSTimerDelegate : NSObject +#import // ======================================================================== // wxNSTimerData // ======================================================================== @interface wxNSTimerData : NSObject { - wxTimer* m_timer; + wxCocoaTimerImpl* m_timer; } - (id)init; -- (id)initWithWxTimer:(wxTimer*)theTimer; -- (wxTimer*)timer; +- (id)initWithWxTimer:(wxCocoaTimerImpl*)theTimer; +- (wxCocoaTimerImpl*)timer; +- (void)onNotify:(NSTimer *)theTimer; @end // interface wxNSTimerData : NSObject +WX_DECLARE_GET_OBJC_CLASS(wxNSTimerData,NSObject) @implementation wxNSTimerData : NSObject - (id)init @@ -68,7 +53,7 @@ IMPLEMENT_CLASS(wxTimer, wxTimerBase) return self; } -- (id)initWithWxTimer:(wxTimer*)theTimer; +- (id)initWithWxTimer:(wxCocoaTimerImpl*)theTimer; { if(!(self = [super init])) return nil; @@ -76,55 +61,51 @@ IMPLEMENT_CLASS(wxTimer, wxTimerBase) return self; } -- (wxTimer*)timer +- (wxCocoaTimerImpl*)timer { return m_timer; } -@end -@implementation wxNSTimerDelegate : NSObject - (void)onNotify:(NSTimer *)theTimer { - wxNSTimerData* theData = [theTimer userInfo]; - [theData timer]->Notify(); //wxTimerBase method + m_timer->Notify(); } -@end +@end +WX_IMPLEMENT_GET_OBJC_CLASS(wxNSTimerData,NSObject) // ---------------------------------------------------------------------------- -// wxTimer +// wxCocoaTimerImpl // ---------------------------------------------------------------------------- -const wxObjcAutoRefFromAlloc wxTimer::sm_cocoaDelegate = [[wxNSTimerDelegate alloc] init]; - -wxTimer::~wxTimer() +wxCocoaTimerImpl::~wxCocoaTimerImpl() { Stop(); } -void wxTimer::Init() +void wxCocoaTimerImpl::Init() { m_cocoaNSTimer = NULL; } -bool wxTimer::Start(int millisecs, bool oneShot) +bool wxCocoaTimerImpl::Start(int millisecs, bool oneShot) { Stop(); - + wxAutoNSAutoreleasePool thePool; - wxNSTimerData *userInfo = [[wxNSTimerData alloc] initWithWxTimer:this]; - m_cocoaNSTimer = [[NSTimer + wxNSTimerData *timerData = [[WX_GET_OBJC_CLASS(wxNSTimerData) alloc] initWithWxTimer:this]; + m_cocoaNSTimer = [[NSTimer scheduledTimerWithTimeInterval: millisecs / 1000.0 //seconds - target: wxTimer::sm_cocoaDelegate - selector: @selector(onNotify:) - userInfo: userInfo - repeats: oneShot == false] retain]; - [userInfo release]; - + target: timerData + selector: @selector(onNotify:) + userInfo: nil + repeats: oneShot == false] retain]; + [timerData release]; + return IsRunning(); } -void wxTimer::Stop() +void wxCocoaTimerImpl::Stop() { if (m_cocoaNSTimer) { @@ -135,7 +116,7 @@ void wxTimer::Stop() } } -bool wxTimer::IsRunning() const +bool wxCocoaTimerImpl::IsRunning() const { return m_cocoaNSTimer != NULL && [m_cocoaNSTimer isValid]; }