]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/spinbutt.mm
Suppress error output from Unix system information functions.
[wxWidgets.git] / src / cocoa / spinbutt.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/spinbutt.mm
3 // Purpose: wxSpinButton
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2003/07/14
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13 #if wxUSE_SPINBTN
14
15 #ifndef WX_PRECOMP
16 #include "wx/app.h"
17 #endif //WX_PRECOMP
18 #include "wx/spinbutt.h"
19
20 #import <AppKit/NSStepper.h>
21
22 BEGIN_EVENT_TABLE(wxSpinButton, wxSpinButtonBase)
23 END_EVENT_TABLE()
24 // WX_IMPLEMENT_COCOA_OWNER(wxSpinButton,NSStepper,NSControl,NSView)
25
26 bool wxSpinButton::Create(wxWindow *parent, wxWindowID winid,
27 const wxPoint& pos, const wxSize& size, long style,
28 const wxString& name)
29 {
30 //bad flag checking
31 wxASSERT_MSG( !(style & wxSP_HORIZONTAL), wxT("Horizontal wxSpinButton not supported in cocoa"));
32 if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name))
33 return false;
34 SetNSControl([[NSStepper alloc] initWithFrame: MakeDefaultNSRect(size)]);
35 [m_cocoaNSView release];
36
37 //flag handling
38 [(NSStepper*)m_cocoaNSView setValueWraps:style & wxSP_WRAP]; //default == true, evidently
39
40 //final setup
41 [(NSStepper*)m_cocoaNSView setTarget: sm_cocoaTarget];
42 [(NSStepper*)m_cocoaNSView setAction:@selector(wxNSControlAction:)];
43 if(m_parent)
44 m_parent->CocoaAddChild(this);
45 SetInitialFrameRect(pos,size);
46
47 return true;
48 }
49
50 wxSpinButton::~wxSpinButton()
51 {
52 [(NSStepper*)m_cocoaNSView setTarget: nil];
53 [(NSStepper*)m_cocoaNSView setAction: nil];
54 }
55
56 int wxSpinButton::GetValue() const
57 {
58 return [(NSStepper*)m_cocoaNSView intValue];
59 }
60
61 void wxSpinButton::SetValue(int value)
62 {
63 [(NSStepper*)m_cocoaNSView setIntValue:value];
64 }
65
66 void wxSpinButton::SetRange(int minValue, int maxValue)
67 {
68 [(NSStepper*)m_cocoaNSView setMinValue:minValue];
69 [(NSStepper*)m_cocoaNSView setMaxValue:maxValue];
70 wxSpinButtonBase::SetRange(minValue,maxValue);
71 }
72
73 void wxSpinButton::CocoaTarget_action()
74 {
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);
81 }
82
83 #endif // wxUSE_SPINBTN