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