1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/spinbutt.mm
3 // Purpose: wxSpinButton
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
18 #include "wx/spinbutt.h"
20 #import <AppKit/NSStepper.h>
22 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent)
24 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
25 BEGIN_EVENT_TABLE(wxSpinButton, wxSpinButtonBase)
27 // WX_IMPLEMENT_COCOA_OWNER(wxSpinButton,NSStepper,NSControl,NSView)
29 bool wxSpinButton::Create(wxWindow *parent, wxWindowID winid,
30 const wxPoint& pos, const wxSize& size, long style,
33 if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name))
35 SetNSControl([[NSStepper alloc] initWithFrame: MakeDefaultNSRect(size)]);
36 [m_cocoaNSView release];
38 //flag handling (note wxSP_HORIZONTAL IS _NOT_ Supported in cocoa)
39 [(NSStepper*)m_cocoaNSView setValueWraps:style & wxSP_WRAP]; //default == true, evidently
42 [(NSStepper*)m_cocoaNSView setTarget: sm_cocoaTarget];
43 [(NSStepper*)m_cocoaNSView setAction:@selector(wxNSControlAction:)];
45 m_parent->CocoaAddChild(this);
46 SetInitialFrameRect(pos,size);
51 wxSpinButton::~wxSpinButton()
53 [(NSStepper*)m_cocoaNSView setTarget: nil];
54 [(NSStepper*)m_cocoaNSView setAction: nil];
57 int wxSpinButton::GetValue() const
59 return [(NSStepper*)m_cocoaNSView intValue];
62 void wxSpinButton::SetValue(int value)
64 [(NSStepper*)m_cocoaNSView setIntValue:value];
67 void wxSpinButton::SetRange(int minValue, int maxValue)
69 [(NSStepper*)m_cocoaNSView setMinValue:minValue];
70 [(NSStepper*)m_cocoaNSView setMaxValue:maxValue];
71 wxSpinButtonBase::SetRange(minValue,maxValue);
74 void wxSpinButton::CocoaTarget_action()
76 /* TODO: up/down events */
77 /* This sends the changed event (not specific on up or down) */
78 wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, GetId());
79 event.SetPosition(GetValue());
80 event.SetEventObject(this);
81 GetEventHandler()->ProcessEvent(event);
84 #endif // wxUSE_SPINBTN