]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/NSSlider.mm
Add missing WXK constants for the control keys
[wxWidgets.git] / src / cocoa / NSSlider.mm
CommitLineData
ddac39da
DE
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/cocoa/NSSlider.mm
3// Purpose: wxCocoaNSSlider class
4// Author: Mark Oxenham
90f6792f 5// Modified by: David Elliott
ddac39da 6// Created: 2007/08/10
8d18e365 7// RCS-ID: $Id$
ddac39da 8// Copyright: (c) 2007 Software 2000 Ltd. All rights reserved.
526954c5 9// Licence: wxWindows licence
ddac39da
DE
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#ifndef WX_PRECOMP
15 #include "wx/log.h"
16#endif // WX_PRECOMP
17
ddac39da
DE
18#include "wx/cocoa/NSSlider.h"
19
20#import <Foundation/NSNotification.h>
21#import <Foundation/NSString.h>
22#import <AppKit/NSEvent.h>
90f6792f 23#include "wx/cocoa/objc/NSSlider.h"
ddac39da
DE
24
25WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSSlider)
26
4f46c20b 27class wxCocoaNSSliderLastSelectorChanger
ddac39da 28{
4f46c20b
DE
29public:
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 }
39private:
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};
ddac39da
DE
46
47// ============================================================================
90f6792f 48// @class WXNSSlider
ddac39da
DE
49// ============================================================================
50
90f6792f
DE
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}
ddac39da 58
4f46c20b
DE
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
ddac39da
DE
66- (void)keyDown:(NSEvent *)theEvent
67{
4f46c20b 68 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
ddac39da 69 [super keyDown:theEvent];
ddac39da
DE
70}
71
72- (void)moveUp:(id)sender
73{
4f46c20b 74 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
ddac39da 75 [super moveUp:sender];
ddac39da
DE
76}
77
78- (void)moveDown:(id)sender
79{
4f46c20b 80 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
ddac39da 81 [super moveDown:sender];
ddac39da
DE
82}
83
84- (void)moveLeft:(id)sender
85{
4f46c20b 86 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
ddac39da 87 [super moveLeft:sender];
ddac39da
DE
88}
89
90- (void)moveRight:(id)sender
91{
4f46c20b 92 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
ddac39da 93 [super moveRight:sender];
ddac39da
DE
94}
95
96- (void)pageUp:(id)sender
97{
4f46c20b 98 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
ddac39da 99 [super pageUp:sender];
ddac39da
DE
100}
101
102- (void)pageDown:(id)sender
103{
4f46c20b 104 wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd);
ddac39da 105 [super pageDown:sender];
ddac39da
DE
106}
107
108@end
90f6792f 109WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSlider,NSSlider)
ddac39da
DE
110
111// ============================================================================
90f6792f 112// @class WXNSSliderCell
ddac39da
DE
113// ============================================================================
114
90f6792f 115@implementation WXNSSliderCell : NSSliderCell
ddac39da
DE
116- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
117{
118 BOOL result = [super startTrackingAt:startPoint inView:controlView];
72ee73c1
DE
119
120 wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView);
121 if(slider)
122 slider->CocoaNotification_startTracking(NULL);
123
ddac39da
DE
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];
72ee73c1
DE
130
131 wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView);
132 if(slider)
133 slider->CocoaNotification_continueTracking(NULL);
134
ddac39da
DE
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];
72ee73c1
DE
141
142 wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView);
143 if(slider)
144 slider->CocoaNotification_stopTracking(NULL);
ddac39da
DE
145}
146@end
90f6792f 147WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSliderCell,NSSliderCell)
ddac39da 148
ddac39da
DE
149// ============================================================================
150// class wxCocoaNSSlider
151// ============================================================================
ddac39da 152
4f46c20b 153SEL wxCocoaNSSlider::sm_lastResponderSelector;
ddac39da
DE
154
155void wxCocoaNSSlider::AssociateNSSlider(WX_NSSlider cocoaNSSlider)
156{
157 if(cocoaNSSlider)
158 {
159 sm_cocoaHash.insert(wxCocoaNSSliderHash::value_type(cocoaNSSlider,this));
ddac39da
DE
160 }
161}
162
163void wxCocoaNSSlider::DisassociateNSSlider(WX_NSSlider cocoaNSSlider)
164{
165 if(cocoaNSSlider)
166 {
167 sm_cocoaHash.erase(cocoaNSSlider);
ddac39da
DE
168 }
169}