1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/spinbutt.mm
3 // Purpose: wxSpinButton
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
15 #include "wx/spinbutt.h"
16 #include "wx/osx/private.h"
18 @interface wxNSStepper : NSStepper
23 @implementation wxNSStepper
27 static BOOL initialized = NO;
31 wxOSXCocoaClassAddWXMethods(self);
37 class wxSpinButtonCocoaImpl : public wxWidgetCocoaImpl
40 wxSpinButtonCocoaImpl(wxWindowMac* peer , WXWidget w) :
41 wxWidgetCocoaImpl(peer, w)
46 ~wxSpinButtonCocoaImpl()
50 virtual void controlAction(WXWidget slf, void* _cmd, void *sender);
51 virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
56 void wxSpinButtonCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
59 // send a release event in case we've been tracking the thumb
60 if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
62 m_formerValue = [(NSStepper*)m_osxView intValue];
65 wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
68 void wxSpinButtonCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
70 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
73 // because wx expects to be able to veto
74 // a change we must revert the value change
76 int currentValue = [(NSStepper*)m_osxView intValue];
77 [(NSStepper*)m_osxView setIntValue:m_formerValue];
78 int inc = currentValue-m_formerValue;
80 // adjust for wrap arounds
87 wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEUP);
89 wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEDOWN);
91 m_formerValue = [(NSStepper*)m_osxView intValue];
95 wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer,
96 wxWindowMac* WXUNUSED(parent),
97 wxWindowID WXUNUSED(id),
104 long WXUNUSED(extraStyle))
106 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
107 wxNSStepper* v = [[wxNSStepper alloc] initWithFrame:r];
109 [v setMinValue: minimum];
110 [v setMaxValue: maximum];
111 [v setIntValue: value];
113 if ( style & wxSP_HORIZONTAL )
114 [v rotateByAngle:90.0];
117 if ( style & wxSP_WRAP )
119 [v setValueWraps:wrap];
121 wxWidgetCocoaImpl* c = new wxSpinButtonCocoaImpl( wxpeer, v );
125 #endif // wxUSE_SPINBTN