1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSpinButton
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/spinbutt.h"
17 #include "wx/osx/private.h"
19 @interface wxNSStepper : NSStepper
24 @implementation wxNSStepper
28 static BOOL initialized = NO;
32 wxOSXCocoaClassAddWXMethods(self);
38 class wxSpinButtonCocoaImpl : public wxWidgetCocoaImpl
41 wxSpinButtonCocoaImpl(wxWindowMac* peer , WXWidget w) :
42 wxWidgetCocoaImpl(peer, w)
47 ~wxSpinButtonCocoaImpl()
51 virtual void controlAction(WXWidget slf, void* _cmd, void *sender);
52 virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
57 void wxSpinButtonCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
60 // send a release event in case we've been tracking the thumb
61 if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
63 m_formerValue = [(NSStepper*)m_osxView intValue];
66 wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
69 void wxSpinButtonCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
71 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
74 // because wx expects to be able to veto
75 // a change we must revert the value change
77 int currentValue = [(NSStepper*)m_osxView intValue];
78 [(NSStepper*)m_osxView setIntValue:m_formerValue];
79 int inc = currentValue-m_formerValue;
81 // adjust for wrap arounds
88 wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEUP);
90 wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEDOWN);
92 m_formerValue = [(NSStepper*)m_osxView intValue];
96 wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer,
97 wxWindowMac* WXUNUSED(parent),
98 wxWindowID WXUNUSED(id),
105 long WXUNUSED(extraStyle))
107 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
108 wxNSStepper* v = [[wxNSStepper alloc] initWithFrame:r];
110 [v setMinValue: minimum];
111 [v setMaxValue: maximum];
112 [v setIntValue: value];
114 if ( style & wxSP_WRAP )
115 [v setValueWraps:YES];
117 wxWidgetCocoaImpl* c = new wxSpinButtonCocoaImpl( wxpeer, v );
121 #endif // wxUSE_SPINBTN