]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: slider.cpp | |
3 | // Purpose: wxSlider | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "slider.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/slider.h" | |
519cb848 | 17 | #include "wx/mac/uma.h" |
e9576ca5 | 18 | |
2f1ae414 | 19 | #if !USE_SHARED_LIBRARY |
e9576ca5 SC |
20 | IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) |
21 | ||
22 | BEGIN_EVENT_TABLE(wxSlider, wxControl) | |
23 | END_EVENT_TABLE() | |
2f1ae414 | 24 | #endif |
e9576ca5 SC |
25 | |
26 | ||
27 | ||
28 | // Slider | |
29 | wxSlider::wxSlider() | |
30 | { | |
31 | m_pageSize = 1; | |
32 | m_lineSize = 1; | |
33 | m_rangeMax = 0; | |
34 | m_rangeMin = 0; | |
35 | m_tickFreq = 0; | |
36 | } | |
37 | ||
519cb848 SC |
38 | extern ControlActionUPP wxMacLiveScrollbarActionUPP ; |
39 | ||
e9576ca5 SC |
40 | bool wxSlider::Create(wxWindow *parent, wxWindowID id, |
41 | int value, int minValue, int maxValue, | |
42 | const wxPoint& pos, | |
43 | const wxSize& size, long style, | |
44 | const wxValidator& validator, | |
45 | const wxString& name) | |
46 | { | |
03e11df5 GD |
47 | Rect bounds ; |
48 | Str255 title ; | |
49 | wxSize slsize; | |
50 | int maxtextwidth, textheight; | |
51 | ||
52 | // Is control horizontal or vertical (Can be ambigous if user selects | |
53 | // another style without also specifying horz or vert | |
54 | if (!(style & wxSL_HORIZONTAL) && !(style & wxSL_VERTICAL)) { | |
55 | // Default is horizontal so make it so | |
56 | style |= wxSL_HORIZONTAL; | |
57 | } | |
58 | slsize = size; | |
59 | // Check that size corresponds with users selection of vertical or | |
60 | // horizontal slider and insert suitable default values | |
61 | if (style & wxSL_HORIZONTAL) | |
62 | { | |
63 | slsize.y = 15; // Slider width | |
64 | if (slsize.x == -1) { | |
65 | slsize.x = 150; // Slider default length | |
66 | } | |
67 | } | |
68 | else | |
69 | { | |
70 | slsize.x = 15; // Slider width | |
71 | if (slsize.y == -1) { | |
72 | slsize.y = 150; // Slider default length | |
73 | } | |
74 | } | |
75 | /* Set the height and width for the slider control region. The actual | |
76 | * slider is set at 10 pixels across. If the slider has labels then the | |
77 | * control region must be large enough to contain these labels | |
78 | */ | |
79 | if (style & wxSL_LABELS) | |
80 | { | |
81 | wxString text; | |
82 | int ht, wd; | |
83 | ||
84 | // Get maximum text label width and height | |
85 | text.Printf("%d", minValue); | |
86 | parent->GetTextExtent(text, &maxtextwidth, &textheight); | |
87 | text.Printf("%d", maxValue); | |
88 | parent->GetTextExtent(text, &wd, &ht); | |
89 | if(ht > textheight) { | |
90 | textheight = ht; | |
91 | } | |
92 | if (wd > maxtextwidth) { | |
93 | maxtextwidth = wd; | |
94 | } | |
95 | ||
96 | if (style & wxSL_VERTICAL) { | |
97 | slsize.x = (15 + maxtextwidth + 2); // Slider wd plus mac text width | |
98 | } | |
99 | if (style & wxSL_HORIZONTAL) { | |
100 | slsize.y = (15 + textheight); // Slider ht plus text ht. | |
101 | } | |
102 | } | |
103 | ||
104 | MacPreControlCreate( parent , id , "" , pos , slsize , style, | |
105 | validator , name , &bounds , title ) ; | |
106 | ||
107 | m_macMinimumStatic = NULL ; | |
108 | m_macMaximumStatic = NULL ; | |
109 | m_macValueStatic = NULL ; | |
110 | ||
519cb848 SC |
111 | m_lineSize = 1; |
112 | m_tickFreq = 0; | |
e9576ca5 | 113 | |
519cb848 SC |
114 | m_rangeMax = maxValue; |
115 | m_rangeMin = minValue; | |
116 | ||
117 | m_pageSize = (int)((maxValue-minValue)/10); | |
03e11df5 GD |
118 | |
119 | // Must modify bounds to that of the slider dimensions from slider | |
120 | // dimensions plus text labels. | |
121 | if (style & wxSL_LABELS) | |
122 | { | |
123 | if ( style & wxSL_HORIZONTAL ) | |
519cb848 | 124 | { |
03e11df5 GD |
125 | bounds.bottom = bounds.top + 15; |
126 | bounds.right -= (5 + maxtextwidth); | |
519cb848 | 127 | } |
03e11df5 | 128 | else // Vertical slider |
519cb848 | 129 | { |
03e11df5 GD |
130 | bounds.right = bounds.left + 15; |
131 | bounds.bottom -= (5 + textheight); | |
519cb848 | 132 | } |
03e11df5 GD |
133 | } |
134 | ||
135 | m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , | |
136 | title , true , value , minValue , maxValue, | |
137 | kControlSliderProc + kControlSliderLiveFeedback + ( ( style & wxSL_AUTOTICKS ) ? kControlSliderHasTickMarks : 0 ) , (long) this ) ; | |
138 | ||
139 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; | |
140 | ||
141 | ::SetControlAction( m_macControl , wxMacLiveScrollbarActionUPP ) ; | |
142 | ||
143 | MacPostControlCreate() ; | |
144 | ||
145 | if ( style & wxSL_LABELS ) | |
146 | { | |
147 | if ( style & wxSL_HORIZONTAL ) | |
519cb848 | 148 | { |
03e11df5 GD |
149 | wxPoint leftpos( 0 , 15 ) ; |
150 | wxPoint rightpos( m_width - (maxtextwidth + 20) , 15 ) ; | |
151 | wxPoint valuepos( m_width - maxtextwidth , 0 ) ; | |
152 | wxString valuestring ; | |
153 | ||
154 | valuestring.Printf( "%d" , minValue ) ; | |
155 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , leftpos ) ; | |
156 | ||
157 | valuestring.Printf( "%d" , maxValue ) ; | |
158 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , rightpos ) ; | |
159 | ||
160 | valuestring.Printf( "%d" , value ) ; | |
161 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , valuepos ) ; | |
519cb848 | 162 | } |
03e11df5 | 163 | else // Vertical slider |
519cb848 | 164 | { |
03e11df5 GD |
165 | wxPoint toppos( 17 , 0 ) ; |
166 | wxPoint bottompos( 17 , m_height - (textheight + 15) ) ; | |
167 | wxPoint valuepos( 0 , m_height - textheight ) ; | |
168 | wxString valuestring ; | |
169 | ||
170 | valuestring.Printf( "%d" , minValue ) ; | |
171 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , bottompos ) ; | |
172 | ||
173 | valuestring.Printf( "%d" , maxValue ) ; | |
174 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , toppos ) ; | |
175 | ||
176 | valuestring.Printf( "%d" , value ) ; | |
177 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , valuepos ) ; | |
519cb848 | 178 | } |
03e11df5 GD |
179 | } |
180 | ||
181 | return true; | |
e9576ca5 SC |
182 | } |
183 | ||
184 | wxSlider::~wxSlider() | |
185 | { | |
186 | } | |
187 | ||
188 | int wxSlider::GetValue() const | |
189 | { | |
519cb848 | 190 | return GetControlValue( m_macControl) ; |
e9576ca5 SC |
191 | } |
192 | ||
193 | void wxSlider::SetValue(int value) | |
194 | { | |
519cb848 SC |
195 | wxString valuestring ; |
196 | valuestring.Printf( "%d" , value ) ; | |
03e11df5 | 197 | if ( m_macMinimumStatic ) |
519cb848 SC |
198 | m_macMinimumStatic->SetLabel( valuestring ) ; |
199 | SetControlValue( m_macControl , value ) ; | |
e9576ca5 SC |
200 | } |
201 | ||
202 | void wxSlider::SetRange(int minValue, int maxValue) | |
203 | { | |
03e11df5 | 204 | wxString value; |
e9576ca5 | 205 | |
03e11df5 GD |
206 | m_rangeMin = minValue; |
207 | m_rangeMax = maxValue; | |
208 | ||
209 | // TODO | |
210 | SetControlMinimum(m_macControl, m_rangeMin); | |
211 | SetControlMaximum(m_macControl, m_rangeMax); | |
212 | ||
213 | if(m_macMinimumStatic) { | |
214 | value.Printf("%d", m_rangeMin); | |
215 | m_macMinimumStatic->SetLabel(value); | |
216 | } | |
217 | if(m_macMaximumStatic) { | |
218 | value.Printf("%d", m_rangeMax); | |
219 | m_macMaximumStatic->SetLabel(value); | |
220 | } | |
221 | SetValue(m_rangeMin); | |
e9576ca5 SC |
222 | } |
223 | ||
224 | // For trackbars only | |
225 | void wxSlider::SetTickFreq(int n, int pos) | |
226 | { | |
227 | // TODO | |
228 | m_tickFreq = n; | |
229 | } | |
230 | ||
231 | void wxSlider::SetPageSize(int pageSize) | |
232 | { | |
233 | // TODO | |
234 | m_pageSize = pageSize; | |
235 | } | |
236 | ||
237 | int wxSlider::GetPageSize() const | |
238 | { | |
239 | return m_pageSize; | |
240 | } | |
241 | ||
242 | void wxSlider::ClearSel() | |
243 | { | |
244 | // TODO | |
245 | } | |
246 | ||
247 | void wxSlider::ClearTicks() | |
248 | { | |
249 | // TODO | |
250 | } | |
251 | ||
252 | void wxSlider::SetLineSize(int lineSize) | |
253 | { | |
254 | m_lineSize = lineSize; | |
255 | // TODO | |
256 | } | |
257 | ||
258 | int wxSlider::GetLineSize() const | |
259 | { | |
260 | // TODO | |
261 | return 0; | |
262 | } | |
263 | ||
264 | int wxSlider::GetSelEnd() const | |
265 | { | |
266 | // TODO | |
267 | return 0; | |
268 | } | |
269 | ||
270 | int wxSlider::GetSelStart() const | |
271 | { | |
272 | // TODO | |
273 | return 0; | |
274 | } | |
275 | ||
276 | void wxSlider::SetSelection(int minPos, int maxPos) | |
277 | { | |
278 | // TODO | |
279 | } | |
280 | ||
281 | void wxSlider::SetThumbLength(int len) | |
282 | { | |
283 | // TODO | |
284 | } | |
285 | ||
286 | int wxSlider::GetThumbLength() const | |
287 | { | |
288 | // TODO | |
289 | return 0; | |
290 | } | |
291 | ||
292 | void wxSlider::SetTick(int tickPos) | |
293 | { | |
294 | // TODO | |
295 | } | |
296 | ||
297 | void wxSlider::Command (wxCommandEvent & event) | |
298 | { | |
299 | SetValue (event.GetInt()); | |
300 | ProcessCommand (event); | |
301 | } | |
302 | ||
519cb848 | 303 | bool wxSlider::Show( bool show ) |
e9576ca5 | 304 | { |
519cb848 | 305 | return wxWindow::Show( show ) ; |
e9576ca5 SC |
306 | } |
307 | ||
519cb848 SC |
308 | void wxSlider::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) |
309 | { | |
310 | SInt16 value = ::GetControlValue( m_macControl ) ; | |
311 | ||
312 | SetValue( value ) ; | |
313 | ||
314 | wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId); | |
315 | event.SetPosition(GetControlValue( m_macControl) ); | |
316 | event.SetEventObject( this ); | |
317 | ||
318 | #if WXWIN_COMPATIBILITY | |
319 | ||
320 | wxEventType oldEvent = event.GetEventType(); | |
321 | event.SetEventType( wxEVT_COMMAND_SLIDER_UPDATED ); | |
322 | if ( !GetEventHandler()->ProcessEvent(event) ) | |
323 | { | |
324 | event.SetEventType( oldEvent ); | |
325 | if (!GetParent()->GetEventHandler()->ProcessEvent(event)) | |
326 | event.Skip(); | |
327 | } | |
328 | #else | |
329 | GetEventHandler()->ProcessEvent(event); | |
330 | #endif | |
331 | } |