]>
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 | { | |
b466e85a | 21 | WXCOCOAIMPL_COMMON_MEMBERS |
19c7ac3d | 22 | int formerValue; |
0f9b48d1 SC |
23 | } |
24 | ||
b466e85a SC |
25 | WXCOCOAIMPL_COMMON_INTERFACE |
26 | ||
0f9b48d1 SC |
27 | - (void) clickedAction: (id) sender; |
28 | ||
29 | @end | |
30 | ||
31 | @implementation wxNSStepper | |
32 | ||
33 | - (id)initWithFrame:(NSRect)frame | |
34 | { | |
35 | [super initWithFrame:frame]; | |
36 | impl = NULL; | |
19c7ac3d | 37 | formerValue = 0; |
0f9b48d1 SC |
38 | [self setTarget: self]; |
39 | [self setAction: @selector(clickedAction:)]; | |
40 | return self; | |
41 | } | |
42 | ||
43 | - (void) clickedAction: (id) sender | |
44 | { | |
45 | if ( impl ) | |
46 | { | |
47 | wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); | |
48 | if ( wxpeer ) | |
19c7ac3d SC |
49 | { |
50 | // because wx expects to be able to veto | |
51 | // a change we must revert the value change | |
52 | // and expose it | |
53 | int currentValue = [self intValue]; | |
54 | [self setIntValue:formerValue]; | |
55 | int inc = currentValue-formerValue; | |
56 | ||
57 | // adjust for wrap arounds | |
58 | if ( inc > 1 ) | |
59 | inc = -1; | |
60 | else if (inc < -1 ) | |
61 | inc = 1; | |
62 | ||
63 | if ( inc == 1 ) | |
64 | wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEUP); | |
65 | else if ( inc == -1 ) | |
66 | wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEDOWN); | |
67 | ||
68 | formerValue = [self intValue]; | |
69 | } | |
0f9b48d1 SC |
70 | } |
71 | } | |
72 | ||
19c7ac3d SC |
73 | -(void)mouseDown:(NSEvent *)event |
74 | { | |
75 | formerValue = [self intValue]; | |
76 | if ( !impl->DoHandleMouseEvent(event) ) | |
77 | [super mouseDown:event]; | |
78 | } | |
79 | ||
80 | WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN | |
0f9b48d1 SC |
81 | |
82 | @end | |
83 | ||
84 | wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer, | |
85 | wxWindowMac* parent, | |
86 | wxWindowID id, | |
87 | wxInt32 value, | |
88 | wxInt32 minimum, | |
89 | wxInt32 maximum, | |
90 | const wxPoint& pos, | |
91 | const wxSize& size, | |
92 | long style, | |
93 | long extraStyle) | |
94 | { | |
0f9b48d1 SC |
95 | NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; |
96 | wxNSStepper* v = [[wxNSStepper alloc] initWithFrame:r]; | |
97 | ||
98 | [v setMinValue: minimum]; | |
99 | [v setMaxValue: maximum]; | |
100 | [v setIntValue: value]; | |
101 | ||
102 | if ( style & wxSP_WRAP ) | |
103 | [v setValueWraps:YES]; | |
104 | ||
0f9b48d1 SC |
105 | wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); |
106 | [v setImplementation:c]; | |
107 | return c; | |
108 | } | |
109 | ||
110 | #endif // wxUSE_SPINBTN |