1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/NSSlider.mm
3 // Purpose: wxCocoaNSSlider class
4 // Author: Mark Oxenham
5 // Modified by: David Elliott
8 // Copyright: (c) 2007 Software 2000 Ltd. All rights reserved.
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
18 #include "wx/cocoa/NSSlider.h"
20 #import <Foundation/NSNotification.h>
21 #import <Foundation/NSString.h>
22 #import <AppKit/NSEvent.h>
23 #include "wx/cocoa/objc/NSSlider.h"
25 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSSlider)
27 class wxCocoaNSSliderLastSelectorChanger
30 wxCocoaNSSliderLastSelectorChanger(SEL newSelector)
32 m_savedResponderSelector = wxCocoaNSSlider::sm_lastResponderSelector;
33 wxCocoaNSSlider::sm_lastResponderSelector = newSelector;
35 ~wxCocoaNSSliderLastSelectorChanger()
37 wxCocoaNSSlider::sm_lastResponderSelector = m_savedResponderSelector;
40 SEL m_savedResponderSelector;
41 // Don't allow any default or copy construction
42 wxCocoaNSSliderLastSelectorChanger();
43 wxCocoaNSSliderLastSelectorChanger(const wxCocoaNSSliderLastSelectorChanger&);
44 void operator=(const wxCocoaNSSliderLastSelectorChanger&);
47 // ============================================================================
49 // ============================================================================
51 @implementation WXNSSlider : NSSlider
53 // Override to ensure that WXNSSlider gets created with a WXNSSliderCell
56 return [WX_GET_OBJC_CLASS(WXNSSliderCell) class];
59 // The following methods are all NSResponder methods which NSSlider responds
60 // to in order to change its state and send the action message. We override
61 // them simply to record which one was called. This allows code listening
62 // only for the action message to determine what caused the action.
63 // Note that this is perfectly fine being a global because Cocoa processes
64 // events synchronously and only in the main thread.
66 - (void)keyDown:(NSEvent *)theEvent
68 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
69 [super keyDown:theEvent];
72 - (void)moveUp:(id)sender
74 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
75 [super moveUp:sender];
78 - (void)moveDown:(id)sender
80 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
81 [super moveDown:sender];
84 - (void)moveLeft:(id)sender
86 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
87 [super moveLeft:sender];
90 - (void)moveRight:(id)sender
92 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
93 [super moveRight:sender];
96 - (void)pageUp:(id)sender
98 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
99 [super pageUp:sender];
102 - (void)pageDown:(id)sender
104 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
105 [super pageDown:sender];
109 WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSlider,NSSlider)
111 // ============================================================================
112 // @class WXNSSliderCell
113 // ============================================================================
115 @implementation WXNSSliderCell : NSSliderCell
116 - (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
118 BOOL result = [super startTrackingAt:startPoint inView:controlView];
120 wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView);
122 slider->CocoaNotification_startTracking(NULL);
127 - (BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)controlView
129 BOOL result = [super continueTracking:lastPoint at:currentPoint inView:controlView];
131 wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView);
133 slider->CocoaNotification_continueTracking(NULL);
138 - (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)controlView mouseIsUp:(BOOL)flag
140 [super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag];
142 wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView);
144 slider->CocoaNotification_stopTracking(NULL);
147 WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSliderCell,NSSliderCell)
149 // ============================================================================
150 // class wxCocoaNSSlider
151 // ============================================================================
153 SEL wxCocoaNSSlider::sm_lastResponderSelector;
155 void wxCocoaNSSlider::AssociateNSSlider(WX_NSSlider cocoaNSSlider)
159 sm_cocoaHash.insert(wxCocoaNSSliderHash::value_type(cocoaNSSlider,this));
163 void wxCocoaNSSlider::DisassociateNSSlider(WX_NSSlider cocoaNSSlider)
167 sm_cocoaHash.erase(cocoaNSSlider);