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