// Name: src/cocoa/NSSlider.mm
// Purpose: wxCocoaNSSlider class
// Author: Mark Oxenham
-// Modified by:
+// Modified by: David Elliott
// Created: 2007/08/10
// RCS-ID: $Id$
// Copyright: (c) 2007 Software 2000 Ltd. All rights reserved.
#include "wx/log.h"
#endif // WX_PRECOMP
-#include "wx/cocoa/ObjcPose.h"
#include "wx/cocoa/NSSlider.h"
#import <Foundation/NSNotification.h>
#import <Foundation/NSString.h>
#import <AppKit/NSEvent.h>
-#import <AppKit/NSSlider.h>
+#include "wx/cocoa/objc/NSSlider.h"
WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSSlider)
@end // implementation wxNSSliderTarget
// ============================================================================
-// @class wxPoserNSSlider
+// @class WXNSSlider
// ============================================================================
-@interface wxPoserNSSlider : NSSlider
-@end
-WX_IMPLEMENT_POSER(wxPoserNSSlider);
-@implementation wxPoserNSSlider : NSSlider
+@implementation WXNSSlider : NSSlider
+
+// Override to ensure that WXNSSlider gets created with a WXNSSliderCell
++ (Class)cellClass
+{
+ return [WX_GET_OBJC_CLASS(WXNSSliderCell) class];
+}
- (void)keyDown:(NSEvent *)theEvent
{
}
@end
+WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSlider,NSSlider)
// ============================================================================
-// @class wxPoserNSSliderCell
+// @class WXNSSliderCell
// ============================================================================
#define kwxNSSliderStartTracking @"wxNSSliderStartTracking"
#define kwxNSSliderContinueTracking @"wxNSSliderContinueTracking"
#define kwxNSSliderStopTracking @"wxNSSliderStopTracking"
-@interface wxPoserNSSliderCell : NSSliderCell
-@end
-
-WX_IMPLEMENT_POSER(wxPoserNSSliderCell);
-@implementation wxPoserNSSliderCell : NSSliderCell
+@implementation WXNSSliderCell : NSSliderCell
- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
{
BOOL result = [super startTrackingAt:startPoint inView:controlView];
- [[NSNotificationCenter defaultCenter] postNotificationName:kwxNSSliderStartTracking object:controlView];
+
+ wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView);
+ if(slider)
+ slider->CocoaNotification_startTracking(NULL);
+
return result;
}
- (BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)controlView
{
BOOL result = [super continueTracking:lastPoint at:currentPoint inView:controlView];
- [[NSNotificationCenter defaultCenter] postNotificationName:kwxNSSliderContinueTracking object:controlView];
+
+ wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView);
+ if(slider)
+ slider->CocoaNotification_continueTracking(NULL);
+
return result;
}
- (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)controlView mouseIsUp:(BOOL)flag
{
[super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag];
- [[NSNotificationCenter defaultCenter] postNotificationName:kwxNSSliderStopTracking object:controlView];
-}
-@end
-// ============================================================================
-// @class wxNSSliderNotificationObserver
-// ============================================================================
-@interface wxNSSliderNotificationObserver : NSObject
-{
+ wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView);
+ if(slider)
+ slider->CocoaNotification_stopTracking(NULL);
}
-
-struct objc_object *wxCocoaNSSlider::sm_cocoaObserver = [[wxNSSliderNotificationObserver alloc] init];
-
-- (void)startTracking: (NSNotification *)notification;
-- (void)continueTracking: (NSNotification *)notification;
-- (void)stopTracking: (NSNotification *)notification;
-@end // interface wxNSSliderNotificationObserver
-
-@implementation wxNSSliderNotificationObserver : NSObject
-
-- (void)startTracking: (NSNotification *)notification;
-{
- wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa([notification object]);
- wxCHECK_RET(slider,wxT("startTracking received but no wxSlider exists"));
- slider->CocoaNotification_startTracking(notification);
-}
-
-- (void)continueTracking: (NSNotification *)notification;
-{
- wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa([notification object]);
- wxCHECK_RET(slider,wxT("continueTracking received but no wxSlider exists"));
- slider->CocoaNotification_continueTracking(notification);
-}
-
-- (void)stopTracking: (NSNotification *)notification;
-{
- wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa([notification object]);
- wxCHECK_RET(slider,wxT("stopTracking received but no wxSlider exists"));
- slider->CocoaNotification_stopTracking(notification);
-}
-
-@end // implementation wxNSSliderNotificationObserver
+@end
+WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSliderCell,NSSliderCell)
// ============================================================================
// class wxCocoaNSSlider
if(cocoaNSSlider)
{
sm_cocoaHash.insert(wxCocoaNSSliderHash::value_type(cocoaNSSlider,this));
- [[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(startTracking:) name:kwxNSSliderStartTracking object:cocoaNSSlider];
- [[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(continueTracking:) name:kwxNSSliderContinueTracking object:cocoaNSSlider];
- [[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(stopTracking:) name:kwxNSSliderStopTracking object:cocoaNSSlider];
[cocoaNSSlider setTarget:sm_cocoaTarget];
}
}
if(cocoaNSSlider)
{
sm_cocoaHash.erase(cocoaNSSlider);
- [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:kwxNSSliderStartTracking object:cocoaNSSlider];
- [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:kwxNSSliderContinueTracking object:cocoaNSSlider];
- [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:kwxNSSliderStopTracking object:cocoaNSSlider];
}
}