]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/slider.mm
Set the menu itself as event object for EVT_MENU_{OPEN,CLOSED} in wxMSW.
[wxWidgets.git] / src / osx / cocoa / slider.mm
CommitLineData
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
a9a4f229 7// RCS-ID: $Id$
dbeddfb9
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{
dbeddfb9 21}
dbeddfb9
SC
22@end
23
24@implementation wxNSSlider
25
4dd9fdf8 26+ (void)initialize
dbeddfb9 27{
4dd9fdf8 28 static BOOL initialized = NO;
03647350 29 if (!initialized)
4dd9fdf8
SC
30 {
31 initialized = YES;
32 wxOSXCocoaClassAddWXMethods(self);
33 }
dbeddfb9
SC
34}
35
4dd9fdf8
SC
36@end
37
38class wxSliderCocoaImpl : public wxWidgetCocoaImpl
39{
40public :
41 wxSliderCocoaImpl(wxWindowMac* peer , WXWidget w) :
42 wxWidgetCocoaImpl(peer, w)
43 {
44 }
03647350 45
4dd9fdf8
SC
46 ~wxSliderCocoaImpl()
47 {
48 }
49
e32090ba 50 virtual void controlAction(WXWidget slf, void* _cmd, void *sender);
4dd9fdf8
SC
51 virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
52};
19c7ac3d 53
03647350 54// we will have a mouseDown, then in the native
19c7ac3d
SC
55// implementation of mouseDown the tracking code
56// is calling clickedAction, therefore we wire this
03647350 57// to thumbtrack and only after super mouseDown
19c7ac3d
SC
58// returns we will call the thumbrelease
59
d8207702 60void wxSliderCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
dbeddfb9 61{
4dd9fdf8
SC
62 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
63 if ( wxpeer )
64 wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK);
dbeddfb9
SC
65}
66
4dd9fdf8 67void wxSliderCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
19c7ac3d 68{
4dd9fdf8 69 wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
03647350 70
4dd9fdf8 71 if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
19c7ac3d 72 {
4dd9fdf8 73 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
19c7ac3d 74 if ( wxpeer )
04236b74 75 wxpeer->OSXHandleClicked(0);
19c7ac3d
SC
76 }
77}
dbeddfb9 78
4dd9fdf8 79
dbeddfb9 80
03647350
VZ
81wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer,
82 wxWindowMac* WXUNUSED(parent),
83 wxWindowID WXUNUSED(id),
dbeddfb9
SC
84 wxInt32 value,
85 wxInt32 minimum,
86 wxInt32 maximum,
03647350 87 const wxPoint& pos,
dbeddfb9 88 const wxSize& size,
03647350 89 long style,
d8207702 90 long WXUNUSED(extraStyle))
dbeddfb9 91{
dbeddfb9 92 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
f599a415
SC
93 if ( size == wxDefaultSize )
94 {
95 if ( style & wxSL_VERTICAL )
96 r.size.height = r.size.width * 2;
97 else
98 r.size.width = r.size.height * 2;
99 }
dbeddfb9
SC
100 wxNSSlider* v = [[wxNSSlider alloc] initWithFrame:r];
101
102 int tickMarks = 0;
103 if ( style & wxSL_AUTOTICKS )
104 {
105 tickMarks = (maximum - minimum) + 1; // +1 for the 0 value
106
107 // keep the number of tickmarks from becoming unwieldly, therefore below it is ok to cast
108 // it to a UInt16
109 while (tickMarks > 20)
110 tickMarks /= 5;
03647350 111
dbeddfb9
SC
112 [v setNumberOfTickMarks:tickMarks];
113 [v setTickMarkPosition:NSTickMarkBelow];
114 }
115
116 [v setMinValue: minimum];
117 [v setMaxValue: maximum];
118 [v setFloatValue: (double) value];
4dd9fdf8 119 wxWidgetCocoaImpl* c = new wxSliderCocoaImpl( wxpeer, v );
dbeddfb9
SC
120 return c;
121}
122
123#endif // wxUSE_SLIDER