]>
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 | ||
41 | - (void) clickedAction: (id) sender | |
42 | { | |
43 | if ( impl ) | |
44 | { | |
45 | wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); | |
46 | if ( wxpeer ) | |
47 | wxpeer->HandleClicked(0); | |
48 | } | |
49 | } | |
50 | ||
b466e85a | 51 | WXCOCOAIMPL_COMMON_IMPLEMENTATION |
dbeddfb9 SC |
52 | |
53 | @end | |
54 | ||
55 | wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer, | |
56 | wxWindowMac* parent, | |
57 | wxWindowID id, | |
58 | wxInt32 value, | |
59 | wxInt32 minimum, | |
60 | wxInt32 maximum, | |
61 | const wxPoint& pos, | |
62 | const wxSize& size, | |
63 | long style, | |
64 | long extraStyle) | |
65 | { | |
dbeddfb9 SC |
66 | NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; |
67 | wxNSSlider* v = [[wxNSSlider alloc] initWithFrame:r]; | |
68 | ||
69 | int tickMarks = 0; | |
70 | if ( style & wxSL_AUTOTICKS ) | |
71 | { | |
72 | tickMarks = (maximum - minimum) + 1; // +1 for the 0 value | |
73 | ||
74 | // keep the number of tickmarks from becoming unwieldly, therefore below it is ok to cast | |
75 | // it to a UInt16 | |
76 | while (tickMarks > 20) | |
77 | tickMarks /= 5; | |
78 | ||
79 | [v setNumberOfTickMarks:tickMarks]; | |
80 | [v setTickMarkPosition:NSTickMarkBelow]; | |
81 | } | |
82 | ||
83 | [v setMinValue: minimum]; | |
84 | [v setMaxValue: maximum]; | |
85 | [v setFloatValue: (double) value]; | |
dbeddfb9 SC |
86 | wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); |
87 | [v setImplementation:c]; | |
88 | return c; | |
89 | } | |
90 | ||
91 | #endif // wxUSE_SLIDER |