1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/spinbutt.mm
3 // Purpose: wxSpinButton
4 // Author: David Elliott
7 // Copyright: (c) 2003 David Elliott
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
17 #include "wx/spinbutt.h"
19 #import <AppKit/NSStepper.h>
21 BEGIN_EVENT_TABLE(wxSpinButton, wxSpinButtonBase)
23 // WX_IMPLEMENT_COCOA_OWNER(wxSpinButton,NSStepper,NSControl,NSView)
25 bool wxSpinButton::Create(wxWindow *parent, wxWindowID winid,
26 const wxPoint& pos, const wxSize& size, long style,
30 wxASSERT_MSG( !(style & wxSP_HORIZONTAL), wxT("Horizontal wxSpinButton not supported in cocoa"));
31 if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name))
33 SetNSControl([[NSStepper alloc] initWithFrame: MakeDefaultNSRect(size)]);
34 [m_cocoaNSView release];
37 [(NSStepper*)m_cocoaNSView setValueWraps:style & wxSP_WRAP]; //default == true, evidently
40 [(NSStepper*)m_cocoaNSView setTarget: sm_cocoaTarget];
41 [(NSStepper*)m_cocoaNSView setAction:@selector(wxNSControlAction:)];
43 m_parent->CocoaAddChild(this);
44 SetInitialFrameRect(pos,size);
49 wxSpinButton::~wxSpinButton()
51 [(NSStepper*)m_cocoaNSView setTarget: nil];
52 [(NSStepper*)m_cocoaNSView setAction: nil];
55 int wxSpinButton::GetValue() const
57 return [(NSStepper*)m_cocoaNSView intValue];
60 void wxSpinButton::SetValue(int value)
62 [(NSStepper*)m_cocoaNSView setIntValue:value];
65 void wxSpinButton::SetRange(int minValue, int maxValue)
67 [(NSStepper*)m_cocoaNSView setMinValue:minValue];
68 [(NSStepper*)m_cocoaNSView setMaxValue:maxValue];
69 wxSpinButtonBase::SetRange(minValue,maxValue);
72 void wxSpinButton::CocoaTarget_action()
74 /* TODO: up/down events */
75 /* This sends the changed event (not specific on up or down) */
76 wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, GetId());
77 event.SetPosition(GetValue());
78 event.SetEventObject(this);
79 HandleWindowEvent(event);
82 #endif // wxUSE_SPINBTN