]>
Commit | Line | Data |
---|---|---|
768d9ec8 DE |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: 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 | |
526954c5 | 9 | // Licence: wxWindows licence |
768d9ec8 DE |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
449c5673 | 12 | #include "wx/wxprec.h" |
768d9ec8 DE |
13 | #if wxUSE_SPINBTN |
14 | ||
449c5673 DE |
15 | #ifndef WX_PRECOMP |
16 | #include "wx/app.h" | |
17 | #endif //WX_PRECOMP | |
768d9ec8 DE |
18 | #include "wx/spinbutt.h" |
19 | ||
20 | #import <AppKit/NSStepper.h> | |
21 | ||
7cc28452 DE |
22 | IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent) |
23 | ||
768d9ec8 DE |
24 | IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) |
25 | BEGIN_EVENT_TABLE(wxSpinButton, wxSpinButtonBase) | |
26 | END_EVENT_TABLE() | |
27 | // WX_IMPLEMENT_COCOA_OWNER(wxSpinButton,NSStepper,NSControl,NSView) | |
28 | ||
29 | bool wxSpinButton::Create(wxWindow *parent, wxWindowID winid, | |
30 | const wxPoint& pos, const wxSize& size, long style, | |
31 | const wxString& name) | |
32 | { | |
571b0b13 RN |
33 | //bad flag checking |
34 | wxASSERT_MSG( !(style & wxSP_HORIZONTAL), wxT("Horizontal wxSpinButton not supported in cocoa")); | |
768d9ec8 DE |
35 | if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name)) |
36 | return false; | |
8d656ea9 | 37 | SetNSControl([[NSStepper alloc] initWithFrame: MakeDefaultNSRect(size)]); |
768d9ec8 | 38 | [m_cocoaNSView release]; |
519fa773 | 39 | |
571b0b13 | 40 | //flag handling |
519fa773 RN |
41 | [(NSStepper*)m_cocoaNSView setValueWraps:style & wxSP_WRAP]; //default == true, evidently |
42 | ||
43 | //final setup | |
11573ad8 DE |
44 | [(NSStepper*)m_cocoaNSView setTarget: sm_cocoaTarget]; |
45 | [(NSStepper*)m_cocoaNSView setAction:@selector(wxNSControlAction:)]; | |
768d9ec8 DE |
46 | if(m_parent) |
47 | m_parent->CocoaAddChild(this); | |
8d656ea9 DE |
48 | SetInitialFrameRect(pos,size); |
49 | ||
768d9ec8 DE |
50 | return true; |
51 | } | |
52 | ||
53 | wxSpinButton::~wxSpinButton() | |
54 | { | |
11573ad8 DE |
55 | [(NSStepper*)m_cocoaNSView setTarget: nil]; |
56 | [(NSStepper*)m_cocoaNSView setAction: nil]; | |
57 | } | |
58 | ||
59 | int wxSpinButton::GetValue() const | |
60 | { | |
61 | return [(NSStepper*)m_cocoaNSView intValue]; | |
62 | } | |
63 | ||
64 | void wxSpinButton::SetValue(int value) | |
65 | { | |
c041438d | 66 | [(NSStepper*)m_cocoaNSView setIntValue:value]; |
11573ad8 DE |
67 | } |
68 | ||
69 | void wxSpinButton::SetRange(int minValue, int maxValue) | |
70 | { | |
71 | [(NSStepper*)m_cocoaNSView setMinValue:minValue]; | |
72 | [(NSStepper*)m_cocoaNSView setMaxValue:maxValue]; | |
73 | wxSpinButtonBase::SetRange(minValue,maxValue); | |
74 | } | |
75 | ||
76 | void wxSpinButton::CocoaTarget_action() | |
77 | { | |
78 | /* TODO: up/down events */ | |
79 | /* This sends the changed event (not specific on up or down) */ | |
80 | wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, GetId()); | |
81 | event.SetPosition(GetValue()); | |
82 | event.SetEventObject(this); | |
937013e0 | 83 | HandleWindowEvent(event); |
768d9ec8 DE |
84 | } |
85 | ||
86 | #endif // wxUSE_SPINBTN |