]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/NSSlider.mm
cleanup
[wxWidgets.git] / src / cocoa / NSSlider.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/NSSlider.mm
3 // Purpose: wxCocoaNSSlider class
4 // Author: Mark Oxenham
5 // Modified by: David Elliott
6 // Created: 2007/08/10
7 // RCS-ID: $Id$
8 // Copyright: (c) 2007 Software 2000 Ltd. All rights reserved.
9 // Licence: wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #ifndef WX_PRECOMP
15 #include "wx/log.h"
16 #endif // WX_PRECOMP
17
18 #include "wx/cocoa/NSSlider.h"
19
20 #import <Foundation/NSNotification.h>
21 #import <Foundation/NSString.h>
22 #import <AppKit/NSEvent.h>
23 #include "wx/cocoa/objc/NSSlider.h"
24
25 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSSlider)
26
27 class wxCocoaNSSliderLastSelectorChanger
28 {
29 public:
30 wxCocoaNSSliderLastSelectorChanger(SEL newSelector)
31 {
32 m_savedResponderSelector = wxCocoaNSSlider::sm_lastResponderSelector;
33 wxCocoaNSSlider::sm_lastResponderSelector = newSelector;
34 }
35 ~wxCocoaNSSliderLastSelectorChanger()
36 {
37 wxCocoaNSSlider::sm_lastResponderSelector = m_savedResponderSelector;
38 }
39 private:
40 SEL m_savedResponderSelector;
41 // Don't allow any default or copy construction
42 wxCocoaNSSliderLastSelectorChanger();
43 wxCocoaNSSliderLastSelectorChanger(const wxCocoaNSSliderLastSelectorChanger&);
44 void operator=(const wxCocoaNSSliderLastSelectorChanger&);
45 };
46
47 // ============================================================================
48 // @class WXNSSlider
49 // ============================================================================
50
51 @implementation WXNSSlider : NSSlider
52
53 // Override to ensure that WXNSSlider gets created with a WXNSSliderCell
54 + (Class)cellClass
55 {
56 return [WX_GET_OBJC_CLASS(WXNSSliderCell) class];
57 }
58
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.
65
66 - (void)keyDown:(NSEvent *)theEvent
67 {
68 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
69 [super keyDown:theEvent];
70 }
71
72 - (void)moveUp:(id)sender
73 {
74 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
75 [super moveUp:sender];
76 }
77
78 - (void)moveDown:(id)sender
79 {
80 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
81 [super moveDown:sender];
82 }
83
84 - (void)moveLeft:(id)sender
85 {
86 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
87 [super moveLeft:sender];
88 }
89
90 - (void)moveRight:(id)sender
91 {
92 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
93 [super moveRight:sender];
94 }
95
96 - (void)pageUp:(id)sender
97 {
98 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
99 [super pageUp:sender];
100 }
101
102 - (void)pageDown:(id)sender
103 {
104 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
105 [super pageDown:sender];
106 }
107
108 @end
109 WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSlider,NSSlider)
110
111 // ============================================================================
112 // @class WXNSSliderCell
113 // ============================================================================
114
115 @implementation WXNSSliderCell : NSSliderCell
116 - (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
117 {
118 BOOL result = [super startTrackingAt:startPoint inView:controlView];
119
120 wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView);
121 if(slider)
122 slider->CocoaNotification_startTracking(NULL);
123
124 return result;
125 }
126
127 - (BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)controlView
128 {
129 BOOL result = [super continueTracking:lastPoint at:currentPoint inView:controlView];
130
131 wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView);
132 if(slider)
133 slider->CocoaNotification_continueTracking(NULL);
134
135 return result;
136 }
137
138 - (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)controlView mouseIsUp:(BOOL)flag
139 {
140 [super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag];
141
142 wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView);
143 if(slider)
144 slider->CocoaNotification_stopTracking(NULL);
145 }
146 @end
147 WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSliderCell,NSSliderCell)
148
149 // ============================================================================
150 // class wxCocoaNSSlider
151 // ============================================================================
152
153 SEL wxCocoaNSSlider::sm_lastResponderSelector;
154
155 void wxCocoaNSSlider::AssociateNSSlider(WX_NSSlider cocoaNSSlider)
156 {
157 if(cocoaNSSlider)
158 {
159 sm_cocoaHash.insert(wxCocoaNSSliderHash::value_type(cocoaNSSlider,this));
160 }
161 }
162
163 void wxCocoaNSSlider::DisassociateNSSlider(WX_NSSlider cocoaNSSlider)
164 {
165 if(cocoaNSSlider)
166 {
167 sm_cocoaHash.erase(cocoaNSSlider);
168 }
169 }