#if wxUSE_TIMER
+#include "wx/timer.h"
+
#ifndef WX_PRECOMP
- #include "wx/timer.h"
#endif
#include "wx/cocoa/autorelease.h"
IMPLEMENT_CLASS(wxTimer, wxTimerBase)
-// ========================================================================
-// wxNSTimerDelegate
-// ========================================================================
-@interface wxNSTimerDelegate : NSObject
-{
-}
-
-- (void)onNotify:(NSTimer *)theTimer;
-@end // interface wxNSTimerDelegate : NSObject
-
// ========================================================================
// wxNSTimerData
// ========================================================================
- (id)init;
- (id)initWithWxTimer:(wxTimer*)theTimer;
- (wxTimer*)timer;
+- (void)onNotify:(NSTimer *)theTimer;
@end // interface wxNSTimerData : NSObject
@implementation wxNSTimerData : NSObject
{
return m_timer;
}
-@end
-@implementation wxNSTimerDelegate : NSObject
- (void)onNotify:(NSTimer *)theTimer
{
- wxNSTimerData* theData = [theTimer userInfo];
- [theData timer]->Notify(); //wxTimerBase method
+ m_timer->Notify(); //wxTimerBase method
}
-@end
+@end
// ----------------------------------------------------------------------------
// wxTimer
// ----------------------------------------------------------------------------
-const wxObjcAutoRefFromAlloc<struct objc_object*> wxTimer::sm_cocoaDelegate = [[wxNSTimerDelegate alloc] init];
-
wxTimer::~wxTimer()
{
Stop();
bool wxTimer::Start(int millisecs, bool oneShot)
{
Stop();
-
+
wxAutoNSAutoreleasePool thePool;
- wxNSTimerData *userInfo = [[wxNSTimerData alloc] initWithWxTimer:this];
- m_cocoaNSTimer = [[NSTimer
+ wxNSTimerData *timerData = [[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();
}