]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: spinbutt.cpp | |
3 | // Purpose: wxSpinButton | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
e9576ca5 | 13 | #pragma implementation "spinbutt.h" |
03e11df5 | 14 | #pragma implementation "spinbuttbase.h" |
e9576ca5 SC |
15 | #endif |
16 | ||
3d1a4878 | 17 | #include "wx/wxprec.h" |
312ebad4 WS |
18 | |
19 | #if wxUSE_SPINBTN | |
20 | ||
e9576ca5 | 21 | #include "wx/spinbutt.h" |
519cb848 | 22 | #include "wx/mac/uma.h" |
e9576ca5 | 23 | |
e7549107 SC |
24 | // ============================================================================ |
25 | // implementation | |
26 | // ============================================================================ | |
27 | ||
28 | // ---------------------------------------------------------------------------- | |
29 | // wxWin macros | |
30 | // ---------------------------------------------------------------------------- | |
31 | ||
2f1ae414 | 32 | #if !USE_SHARED_LIBRARY |
e7549107 | 33 | IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) |
d84afea9 | 34 | IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent) |
2f1ae414 | 35 | #endif |
e9576ca5 | 36 | |
03e11df5 GD |
37 | wxSpinButton::wxSpinButton() |
38 | : wxSpinButtonBase() | |
39 | { | |
40 | } | |
41 | ||
e9576ca5 | 42 | bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, |
e40298d5 | 43 | long style, const wxString& name) |
e9576ca5 | 44 | { |
312ebad4 WS |
45 | m_macIsUserPane = false ; |
46 | ||
b45ed7a2 VZ |
47 | if ( !wxSpinButtonBase::Create(parent, id, pos, size, |
48 | style, wxDefaultValidator, name) ) | |
49 | return false; | |
50 | ||
e9576ca5 SC |
51 | m_min = 0; |
52 | m_max = 100; | |
312ebad4 | 53 | |
e40298d5 | 54 | if (!parent) |
312ebad4 WS |
55 | return false; |
56 | ||
facd6764 | 57 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; |
312ebad4 | 58 | |
b905d6cc | 59 | m_peer = new wxMacControl(this) ; |
4c37f124 | 60 | verify_noerr ( CreateLittleArrowsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , 0 , m_min , m_max , 1 , |
5ca0d812 | 61 | m_peer->GetControlRefAddr() ) ); |
312ebad4 | 62 | |
cd780027 | 63 | m_peer->SetActionProc( GetwxMacLiveScrollbarActionProc() ) ; |
facd6764 | 64 | MacPostControlCreate(pos,size) ; |
312ebad4 WS |
65 | |
66 | return true; | |
e9576ca5 | 67 | } |
312ebad4 | 68 | |
e9576ca5 SC |
69 | wxSpinButton::~wxSpinButton() |
70 | { | |
71 | } | |
72 | ||
73 | // Attributes | |
74 | //////////////////////////////////////////////////////////////////////////// | |
75 | ||
03e11df5 GD |
76 | int wxSpinButton::GetMin() const |
77 | { | |
e40298d5 | 78 | return m_min; |
03e11df5 GD |
79 | } |
80 | ||
81 | int wxSpinButton::GetMax() const | |
82 | { | |
e40298d5 | 83 | return m_max; |
03e11df5 GD |
84 | } |
85 | ||
e9576ca5 SC |
86 | int wxSpinButton::GetValue() const |
87 | { | |
6511d307 RR |
88 | int n = m_value; |
89 | ||
90 | if (n < m_min) n = m_min; | |
91 | if (n > m_max) n = m_max; | |
92 | ||
93 | return n; | |
e9576ca5 SC |
94 | } |
95 | ||
96 | void wxSpinButton::SetValue(int val) | |
97 | { | |
e40298d5 | 98 | m_value = val ; |
e9576ca5 SC |
99 | } |
100 | ||
101 | void wxSpinButton::SetRange(int minVal, int maxVal) | |
102 | { | |
e40298d5 JS |
103 | m_min = minVal; |
104 | m_max = maxVal; | |
5ca0d812 SC |
105 | m_peer->SetMaximum( maxVal ) ; |
106 | m_peer->SetMinimum( minVal ) ; | |
e9576ca5 SC |
107 | } |
108 | ||
a54b0880 | 109 | void wxSpinButton::MacHandleValueChanged( int inc ) |
519cb848 | 110 | { |
312ebad4 | 111 | |
a54b0880 | 112 | wxEventType scrollEvent = wxEVT_NULL; |
e40298d5 | 113 | int oldValue = m_value ; |
312ebad4 | 114 | |
a54b0880 | 115 | m_value = oldValue + inc; |
312ebad4 | 116 | |
a54b0880 SC |
117 | if (m_value < m_min) |
118 | { | |
e40298d5 JS |
119 | if ( m_windowStyle & wxSP_WRAP ) |
120 | m_value = m_max; | |
121 | else | |
122 | m_value = m_min; | |
a54b0880 | 123 | } |
312ebad4 | 124 | |
a54b0880 SC |
125 | if (m_value > m_max) |
126 | { | |
e40298d5 JS |
127 | if ( m_windowStyle & wxSP_WRAP ) |
128 | m_value = m_min; | |
129 | else | |
130 | m_value = m_max; | |
a54b0880 | 131 | } |
312ebad4 | 132 | |
92432aa1 | 133 | if ( m_value - oldValue == -1 ) |
a54b0880 | 134 | scrollEvent = wxEVT_SCROLL_LINEDOWN ; |
92432aa1 | 135 | else if ( m_value - oldValue == 1 ) |
a54b0880 SC |
136 | scrollEvent = wxEVT_SCROLL_LINEUP ; |
137 | else | |
138 | scrollEvent = wxEVT_SCROLL_THUMBTRACK ; | |
312ebad4 | 139 | |
a54b0880 | 140 | wxSpinEvent event(scrollEvent, m_windowId); |
312ebad4 | 141 | |
a54b0880 SC |
142 | event.SetPosition(m_value); |
143 | event.SetEventObject( this ); | |
144 | if ((GetEventHandler()->ProcessEvent( event )) && | |
72d750d4 | 145 | !event.IsAllowed() ) |
a54b0880 SC |
146 | { |
147 | m_value = oldValue ; | |
148 | } | |
5ca0d812 | 149 | m_peer->SetValue( m_value ) ; |
312ebad4 | 150 | |
72d750d4 SC |
151 | /* always send a thumbtrack event */ |
152 | if (scrollEvent != wxEVT_SCROLL_THUMBTRACK) | |
153 | { | |
154 | scrollEvent = wxEVT_SCROLL_THUMBTRACK; | |
155 | wxSpinEvent event2( scrollEvent, GetId()); | |
156 | event2.SetPosition( m_value ); | |
157 | event2.SetEventObject( this ); | |
158 | GetEventHandler()->ProcessEvent( event2 ); | |
159 | } | |
519cb848 SC |
160 | } |
161 | ||
312ebad4 | 162 | void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) |
64be92e2 SC |
163 | { |
164 | int nScrollInc = 0; | |
312ebad4 | 165 | |
64be92e2 SC |
166 | switch( controlpart ) |
167 | { | |
168 | case kControlUpButtonPart : | |
169 | nScrollInc = 1; | |
170 | break ; | |
171 | case kControlDownButtonPart : | |
172 | nScrollInc = -1; | |
173 | break ; | |
174 | } | |
175 | MacHandleValueChanged( nScrollInc ) ; | |
176 | } | |
177 | ||
312ebad4 | 178 | wxInt32 wxSpinButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event ) |
a54b0880 | 179 | { |
64be92e2 SC |
180 | /* |
181 | // these have been handled by the live action proc already | |
e40298d5 | 182 | int nScrollInc = 0; |
4c37f124 | 183 | wxMacCarbonEvent cEvent( (EventRef) event ) ; |
312ebad4 | 184 | |
4c37f124 | 185 | switch( cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) ) |
e40298d5 JS |
186 | { |
187 | case kControlUpButtonPart : | |
188 | nScrollInc = 1; | |
189 | break ; | |
190 | case kControlDownButtonPart : | |
191 | nScrollInc = -1; | |
192 | break ; | |
193 | } | |
194 | MacHandleValueChanged( nScrollInc ) ; | |
64be92e2 | 195 | */ |
4c37f124 | 196 | return noErr ; |
a54b0880 SC |
197 | } |
198 | ||
51abe921 SC |
199 | // ---------------------------------------------------------------------------- |
200 | // size calculation | |
201 | // ---------------------------------------------------------------------------- | |
202 | ||
37e2cb08 | 203 | wxSize wxSpinButton::DoGetBestSize() const |
51abe921 | 204 | { |
e40298d5 | 205 | return wxSize(16,24); |
51abe921 | 206 | } |
519cb848 | 207 | |
312ebad4 | 208 | #endif // wxUSE_SPINBTN |