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