]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/spinbutt.mm
Update OpenVMS compile support
[wxWidgets.git] / src / osx / cocoa / spinbutt.mm
CommitLineData
0f9b48d1 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/osx/cocoa/spinbutt.mm
0f9b48d1
SC
3// Purpose: wxSpinButton
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
0f9b48d1
SC
7// Copyright: (c) Stefan Csomor
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#include "wx/wxprec.h"
12
13#if wxUSE_SPINBTN
14
15#include "wx/spinbutt.h"
16#include "wx/osx/private.h"
17
18@interface wxNSStepper : NSStepper
19{
0f9b48d1 20}
0f9b48d1
SC
21@end
22
23@implementation wxNSStepper
24
4dd9fdf8 25+ (void)initialize
0f9b48d1 26{
4dd9fdf8 27 static BOOL initialized = NO;
03647350 28 if (!initialized)
4dd9fdf8
SC
29 {
30 initialized = YES;
31 wxOSXCocoaClassAddWXMethods(self);
32 }
0f9b48d1
SC
33}
34
4dd9fdf8
SC
35@end
36
37class wxSpinButtonCocoaImpl : public wxWidgetCocoaImpl
0f9b48d1 38{
4dd9fdf8
SC
39public :
40 wxSpinButtonCocoaImpl(wxWindowMac* peer , WXWidget w) :
41 wxWidgetCocoaImpl(peer, w)
42 {
43 m_formerValue = 0;
44 }
03647350 45
4dd9fdf8 46 ~wxSpinButtonCocoaImpl()
0f9b48d1 47 {
0f9b48d1 48 }
0f9b48d1 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);
52private:
53 int m_formerValue;
54};
55
56void wxSpinButtonCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
19c7ac3d 57{
03647350 58
4dd9fdf8
SC
59 // send a release event in case we've been tracking the thumb
60 if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
61 {
62 m_formerValue = [(NSStepper*)m_osxView intValue];
63 }
64
65 wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
19c7ac3d
SC
66}
67
d8207702 68void wxSpinButtonCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
4dd9fdf8
SC
69{
70 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
71 if ( wxpeer )
72 {
03647350 73 // because wx expects to be able to veto
4dd9fdf8
SC
74 // a change we must revert the value change
75 // and expose it
76 int currentValue = [(NSStepper*)m_osxView intValue];
77 [(NSStepper*)m_osxView setIntValue:m_formerValue];
78 int inc = currentValue-m_formerValue;
03647350 79
4dd9fdf8
SC
80 // adjust for wrap arounds
81 if ( inc > 1 )
82 inc = -1;
83 else if (inc < -1 )
84 inc = 1;
03647350 85
4dd9fdf8
SC
86 if ( inc == 1 )
87 wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEUP);
88 else if ( inc == -1 )
89 wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEDOWN);
0f9b48d1 90
4dd9fdf8
SC
91 m_formerValue = [(NSStepper*)m_osxView intValue];
92 }
93}
0f9b48d1 94
03647350
VZ
95wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer,
96 wxWindowMac* WXUNUSED(parent),
97 wxWindowID WXUNUSED(id),
0f9b48d1
SC
98 wxInt32 value,
99 wxInt32 minimum,
100 wxInt32 maximum,
03647350 101 const wxPoint& pos,
0f9b48d1 102 const wxSize& size,
03647350 103 long style,
d8207702 104 long WXUNUSED(extraStyle))
0f9b48d1 105{
0f9b48d1
SC
106 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
107 wxNSStepper* v = [[wxNSStepper alloc] initWithFrame:r];
108
109 [v setMinValue: minimum];
110 [v setMaxValue: maximum];
111 [v setIntValue: value];
03647350 112
916a96c9
SC
113 if ( style & wxSP_HORIZONTAL )
114 [v rotateByAngle:90.0];
03647350 115
916a96c9
SC
116 BOOL wrap = NO;
117 if ( style & wxSP_WRAP )
118 wrap = YES;
119 [v setValueWraps:wrap];
120
4dd9fdf8 121 wxWidgetCocoaImpl* c = new wxSpinButtonCocoaImpl( wxpeer, v );
0f9b48d1
SC
122 return c;
123}
124
125#endif // wxUSE_SPINBTN