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