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