1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/spinbutt.mm
3 // Purpose: wxSpinButton
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
18 #include "wx/spinbutt.h"
20 #import <AppKit/NSStepper.h>
22 BEGIN_EVENT_TABLE(wxSpinButton, wxSpinButtonBase)
24 // WX_IMPLEMENT_COCOA_OWNER(wxSpinButton,NSStepper,NSControl,NSView)
26 bool wxSpinButton::Create(wxWindow *parent, wxWindowID winid,
27 const wxPoint& pos, const wxSize& size, long style,
31 wxASSERT_MSG( !(style & wxSP_HORIZONTAL), wxT("Horizontal wxSpinButton not supported in cocoa"));
32 if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name))
34 SetNSControl([[NSStepper alloc] initWithFrame: MakeDefaultNSRect(size)]);
35 [m_cocoaNSView release];
38 [(NSStepper*)m_cocoaNSView setValueWraps:style & wxSP_WRAP]; //default == true, evidently
41 [(NSStepper*)m_cocoaNSView setTarget: sm_cocoaTarget];
42 [(NSStepper*)m_cocoaNSView setAction:@selector(wxNSControlAction:)];
44 m_parent->CocoaAddChild(this);
45 SetInitialFrameRect(pos,size);
50 wxSpinButton::~wxSpinButton()
52 [(NSStepper*)m_cocoaNSView setTarget: nil];
53 [(NSStepper*)m_cocoaNSView setAction: nil];
56 int wxSpinButton::GetValue() const
58 return [(NSStepper*)m_cocoaNSView intValue];
61 void wxSpinButton::SetValue(int value)
63 [(NSStepper*)m_cocoaNSView setIntValue:value];
66 void wxSpinButton::SetRange(int minValue, int maxValue)
68 [(NSStepper*)m_cocoaNSView setMinValue:minValue];
69 [(NSStepper*)m_cocoaNSView setMaxValue:maxValue];
70 wxSpinButtonBase::SetRange(minValue,maxValue);
73 void wxSpinButton::CocoaTarget_action()
75 /* TODO: up/down events */
76 /* This sends the changed event (not specific on up or down) */
77 wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, GetId());
78 event.SetPosition(GetValue());
79 event.SetEventObject(this);
80 HandleWindowEvent(event);
83 #endif // wxUSE_SPINBTN