Commit | Line | Data |
---|---|---|
dbeddfb9 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/osx/cocoa/slider.mm | |
3 | // Purpose: wxSlider | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id: slider.cpp 54129 2008-06-11 19:30:52Z SC $ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #if wxUSE_SLIDER | |
15 | ||
16 | #include "wx/slider.h" | |
17 | #include "wx/osx/private.h" | |
18 | ||
19 | @interface wxNSSlider : NSSlider | |
20 | { | |
b466e85a | 21 | WXCOCOAIMPL_COMMON_MEMBERS |
dbeddfb9 SC |
22 | } |
23 | ||
b466e85a SC |
24 | WXCOCOAIMPL_COMMON_INTERFACE |
25 | ||
dbeddfb9 SC |
26 | - (void) clickedAction: (id) sender; |
27 | ||
28 | @end | |
29 | ||
30 | @implementation wxNSSlider | |
31 | ||
32 | - (id)initWithFrame:(NSRect)frame | |
33 | { | |
34 | [super initWithFrame:frame]; | |
35 | impl = NULL; | |
36 | [self setTarget: self]; | |
37 | [self setAction: @selector(clickedAction:)]; | |
38 | return self; | |
39 | } | |
40 | ||
19c7ac3d SC |
41 | WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN |
42 | ||
43 | // we will have a mouseDown, then in the native | |
44 | // implementation of mouseDown the tracking code | |
45 | // is calling clickedAction, therefore we wire this | |
46 | // to thumbtrack and only after super mouseDown | |
47 | // returns we will call the thumbrelease | |
48 | ||
dbeddfb9 SC |
49 | - (void) clickedAction: (id) sender |
50 | { | |
51 | if ( impl ) | |
52 | { | |
53 | wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); | |
54 | if ( wxpeer ) | |
19c7ac3d | 55 | wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK); |
dbeddfb9 SC |
56 | } |
57 | } | |
58 | ||
19c7ac3d SC |
59 | -(void)mouseDown:(NSEvent *)event |
60 | { | |
61 | if ( !impl->DoHandleMouseEvent(event) ) | |
62 | [super mouseDown:event]; | |
63 | ||
64 | if ( impl ) | |
65 | { | |
66 | wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); | |
67 | if ( wxpeer ) | |
04236b74 | 68 | wxpeer->OSXHandleClicked(0); |
19c7ac3d SC |
69 | } |
70 | } | |
dbeddfb9 SC |
71 | |
72 | @end | |
73 | ||
74 | wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer, | |
75 | wxWindowMac* parent, | |
76 | wxWindowID id, | |
77 | wxInt32 value, | |
78 | wxInt32 minimum, | |
79 | wxInt32 maximum, | |
80 | const wxPoint& pos, | |
81 | const wxSize& size, | |
82 | long style, | |
83 | long extraStyle) | |
84 | { | |
dbeddfb9 SC |
85 | NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; |
86 | wxNSSlider* v = [[wxNSSlider alloc] initWithFrame:r]; | |
87 | ||
88 | int tickMarks = 0; | |
89 | if ( style & wxSL_AUTOTICKS ) | |
90 | { | |
91 | tickMarks = (maximum - minimum) + 1; // +1 for the 0 value | |
92 | ||
93 | // keep the number of tickmarks from becoming unwieldly, therefore below it is ok to cast | |
94 | // it to a UInt16 | |
95 | while (tickMarks > 20) | |
96 | tickMarks /= 5; | |
97 | ||
98 | [v setNumberOfTickMarks:tickMarks]; | |
99 | [v setTickMarkPosition:NSTickMarkBelow]; | |
100 | } | |
101 | ||
102 | [v setMinValue: minimum]; | |
103 | [v setMaxValue: maximum]; | |
104 | [v setFloatValue: (double) value]; | |
dbeddfb9 SC |
105 | wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); |
106 | [v setImplementation:c]; | |
107 | return c; | |
108 | } | |
109 | ||
110 | #endif // wxUSE_SLIDER |