]>
Commit | Line | Data |
---|---|---|
0f9b48d1 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: spinbutt.cpp | |
3 | // Purpose: wxSpinButton | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id: spinbutt.cpp 54129 2008-06-11 19:30:52Z SC $ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #if wxUSE_SPINBTN | |
15 | ||
16 | #include "wx/spinbutt.h" | |
17 | #include "wx/osx/private.h" | |
18 | ||
19 | @interface wxNSStepper : NSStepper | |
20 | { | |
0f9b48d1 | 21 | } |
0f9b48d1 SC |
22 | @end |
23 | ||
24 | @implementation wxNSStepper | |
25 | ||
4dd9fdf8 | 26 | + (void)initialize |
0f9b48d1 | 27 | { |
4dd9fdf8 SC |
28 | static BOOL initialized = NO; |
29 | if (!initialized) | |
30 | { | |
31 | initialized = YES; | |
32 | wxOSXCocoaClassAddWXMethods(self); | |
33 | } | |
0f9b48d1 SC |
34 | } |
35 | ||
4dd9fdf8 SC |
36 | @end |
37 | ||
38 | class wxSpinButtonCocoaImpl : public wxWidgetCocoaImpl | |
0f9b48d1 | 39 | { |
4dd9fdf8 SC |
40 | public : |
41 | wxSpinButtonCocoaImpl(wxWindowMac* peer , WXWidget w) : | |
42 | wxWidgetCocoaImpl(peer, w) | |
43 | { | |
44 | m_formerValue = 0; | |
45 | } | |
46 | ||
47 | ~wxSpinButtonCocoaImpl() | |
0f9b48d1 | 48 | { |
0f9b48d1 | 49 | } |
0f9b48d1 | 50 | |
e32090ba | 51 | virtual void controlAction(WXWidget slf, void* _cmd, void *sender); |
4dd9fdf8 SC |
52 | virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd); |
53 | private: | |
54 | int m_formerValue; | |
55 | }; | |
56 | ||
57 | void wxSpinButtonCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd) | |
19c7ac3d | 58 | { |
4dd9fdf8 SC |
59 | |
60 | // send a release event in case we've been tracking the thumb | |
61 | if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 ) | |
62 | { | |
63 | m_formerValue = [(NSStepper*)m_osxView intValue]; | |
64 | } | |
65 | ||
66 | wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd); | |
19c7ac3d SC |
67 | } |
68 | ||
e32090ba | 69 | void wxSpinButtonCocoaImpl::controlAction( WXWidget slf, void *_cmd, void *sender) |
4dd9fdf8 SC |
70 | { |
71 | wxWindow* wxpeer = (wxWindow*) GetWXPeer(); | |
72 | if ( wxpeer ) | |
73 | { | |
74 | // because wx expects to be able to veto | |
75 | // a change we must revert the value change | |
76 | // and expose it | |
77 | int currentValue = [(NSStepper*)m_osxView intValue]; | |
78 | [(NSStepper*)m_osxView setIntValue:m_formerValue]; | |
79 | int inc = currentValue-m_formerValue; | |
80 | ||
81 | // adjust for wrap arounds | |
82 | if ( inc > 1 ) | |
83 | inc = -1; | |
84 | else if (inc < -1 ) | |
85 | inc = 1; | |
86 | ||
87 | if ( inc == 1 ) | |
88 | wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEUP); | |
89 | else if ( inc == -1 ) | |
90 | wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEDOWN); | |
0f9b48d1 | 91 | |
4dd9fdf8 SC |
92 | m_formerValue = [(NSStepper*)m_osxView intValue]; |
93 | } | |
94 | } | |
0f9b48d1 SC |
95 | |
96 | wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer, | |
97 | wxWindowMac* parent, | |
98 | wxWindowID id, | |
99 | wxInt32 value, | |
100 | wxInt32 minimum, | |
101 | wxInt32 maximum, | |
102 | const wxPoint& pos, | |
103 | const wxSize& size, | |
104 | long style, | |
105 | long extraStyle) | |
106 | { | |
0f9b48d1 SC |
107 | NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; |
108 | wxNSStepper* v = [[wxNSStepper alloc] initWithFrame:r]; | |
109 | ||
110 | [v setMinValue: minimum]; | |
111 | [v setMaxValue: maximum]; | |
112 | [v setIntValue: value]; | |
113 | ||
114 | if ( style & wxSP_WRAP ) | |
115 | [v setValueWraps:YES]; | |
116 | ||
4dd9fdf8 | 117 | wxWidgetCocoaImpl* c = new wxSpinButtonCocoaImpl( wxpeer, v ); |
0f9b48d1 SC |
118 | return c; |
119 | } | |
120 | ||
121 | #endif // wxUSE_SPINBTN |