1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/NSSlider.mm
3 // Purpose: wxCocoaNSSlider class
4 // Author: Mark Oxenham
5 // Modified by: David Elliott
7 // Copyright: (c) 2007 Software 2000 Ltd. All rights reserved.
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
17 #include "wx/cocoa/NSSlider.h"
19 #import <Foundation/NSNotification.h>
20 #import <Foundation/NSString.h>
21 #import <AppKit/NSEvent.h>
22 #include "wx/cocoa/objc/NSSlider.h"
24 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSSlider)
26 class wxCocoaNSSliderLastSelectorChanger
29 wxCocoaNSSliderLastSelectorChanger(SEL newSelector)
31 m_savedResponderSelector = wxCocoaNSSlider::sm_lastResponderSelector;
32 wxCocoaNSSlider::sm_lastResponderSelector = newSelector;
34 ~wxCocoaNSSliderLastSelectorChanger()
36 wxCocoaNSSlider::sm_lastResponderSelector = m_savedResponderSelector;
39 SEL m_savedResponderSelector;
40 // Don't allow any default or copy construction
41 wxCocoaNSSliderLastSelectorChanger();
42 wxCocoaNSSliderLastSelectorChanger(const wxCocoaNSSliderLastSelectorChanger&);
43 void operator=(const wxCocoaNSSliderLastSelectorChanger&);
46 // ============================================================================
48 // ============================================================================
50 @implementation WXNSSlider : NSSlider
52 // Override to ensure that WXNSSlider gets created with a WXNSSliderCell
55 return [WX_GET_OBJC_CLASS(WXNSSliderCell) class];
58 // The following methods are all NSResponder methods which NSSlider responds
59 // to in order to change its state and send the action message. We override
60 // them simply to record which one was called. This allows code listening
61 // only for the action message to determine what caused the action.
62 // Note that this is perfectly fine being a global because Cocoa processes
63 // events synchronously and only in the main thread.
65 - (void)keyDown:(NSEvent *)theEvent
67 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
68 [super keyDown:theEvent];
71 - (void)moveUp:(id)sender
73 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
74 [super moveUp:sender];
77 - (void)moveDown:(id)sender
79 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
80 [super moveDown:sender];
83 - (void)moveLeft:(id)sender
85 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
86 [super moveLeft:sender];
89 - (void)moveRight:(id)sender
91 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
92 [super moveRight:sender];
95 - (void)pageUp:(id)sender
97 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
98 [super pageUp:sender];
101 - (void)pageDown:(id)sender
103 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
104 [super pageDown:sender];
108 WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSlider,NSSlider)
110 // ============================================================================
111 // @class WXNSSliderCell
112 // ============================================================================
114 @implementation WXNSSliderCell : NSSliderCell
115 - (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
117 BOOL result = [super startTrackingAt:startPoint inView:controlView];
119 wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView);
121 slider->CocoaNotification_startTracking(NULL);
126 - (BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)controlView
128 BOOL result = [super continueTracking:lastPoint at:currentPoint inView:controlView];
130 wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView);
132 slider->CocoaNotification_continueTracking(NULL);
137 - (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)controlView mouseIsUp:(BOOL)flag
139 [super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag];
141 wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView);
143 slider->CocoaNotification_stopTracking(NULL);
146 WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSliderCell,NSSliderCell)
148 // ============================================================================
149 // class wxCocoaNSSlider
150 // ============================================================================
152 SEL wxCocoaNSSlider::sm_lastResponderSelector;
154 void wxCocoaNSSlider::AssociateNSSlider(WX_NSSlider cocoaNSSlider)
158 sm_cocoaHash.insert(wxCocoaNSSliderHash::value_type(cocoaNSSlider,this));
162 void wxCocoaNSSlider::DisassociateNSSlider(WX_NSSlider cocoaNSSlider)
166 sm_cocoaHash.erase(cocoaNSSlider);