]>
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 | 28 | static BOOL initialized = NO; |
03647350 | 29 | if (!initialized) |
4dd9fdf8 SC |
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 | } | |
03647350 | 46 | |
4dd9fdf8 | 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 | { |
03647350 | 59 | |
4dd9fdf8 SC |
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 | ||
d8207702 | 69 | void wxSpinButtonCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender)) |
4dd9fdf8 SC |
70 | { |
71 | wxWindow* wxpeer = (wxWindow*) GetWXPeer(); | |
72 | if ( wxpeer ) | |
73 | { | |
03647350 | 74 | // because wx expects to be able to veto |
4dd9fdf8 SC |
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; | |
03647350 | 80 | |
4dd9fdf8 SC |
81 | // adjust for wrap arounds |
82 | if ( inc > 1 ) | |
83 | inc = -1; | |
84 | else if (inc < -1 ) | |
85 | inc = 1; | |
03647350 | 86 | |
4dd9fdf8 SC |
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 | 95 | |
03647350 VZ |
96 | wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer, |
97 | wxWindowMac* WXUNUSED(parent), | |
98 | wxWindowID WXUNUSED(id), | |
0f9b48d1 SC |
99 | wxInt32 value, |
100 | wxInt32 minimum, | |
101 | wxInt32 maximum, | |
03647350 | 102 | const wxPoint& pos, |
0f9b48d1 | 103 | const wxSize& size, |
03647350 | 104 | long style, |
d8207702 | 105 | long WXUNUSED(extraStyle)) |
0f9b48d1 | 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]; | |
03647350 | 113 | |
0f9b48d1 SC |
114 | if ( style & wxSP_WRAP ) |
115 | [v setValueWraps:YES]; | |
03647350 | 116 | |
4dd9fdf8 | 117 | wxWidgetCocoaImpl* c = new wxSpinButtonCocoaImpl( wxpeer, v ); |
0f9b48d1 SC |
118 | return c; |
119 | } | |
120 | ||
121 | #endif // wxUSE_SPINBTN |