]> git.saurik.com Git - wxWidgets.git/blob - src/os2/slider.cpp
several mac fixes (Mark Newsams patches)
[wxWidgets.git] / src / os2 / slider.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: slider.cpp
3 // Purpose: wxSlider
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/15/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include <stdio.h>
21 #include <wx/utils.h>
22 #include <wx/brush.h>
23 #endif
24
25 #include "wx/slider.h"
26 #include "wx/os2/private.h"
27
28 IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
29
30 // Slider
31 wxSlider::wxSlider()
32 {
33 m_staticValue = 0;
34 m_staticMin = 0;
35 m_staticMax = 0;
36 m_pageSize = 1;
37 m_lineSize = 1;
38 m_rangeMax = 0;
39 m_rangeMin = 0;
40 m_tickFreq = 0;
41 }
42
43 bool wxSlider::Create(wxWindow *parent, wxWindowID id,
44 int value, int minValue, int maxValue,
45 const wxPoint& pos,
46 const wxSize& size, long style,
47 #if wxUSE_VALIDATORS
48 const wxValidator& validator,
49 #endif
50 const wxString& name)
51 {
52 SetName(name);
53 #if wxUSE_VALIDATORS
54 SetValidator(validator);
55 #endif
56
57 if (parent) parent->AddChild(this);
58
59 m_lineSize = 1;
60 m_windowStyle = style;
61 m_tickFreq = 0;
62
63 if ( id == -1 )
64 m_windowId = (int)NewControlId();
65 else
66 m_windowId = id;
67
68 m_rangeMax = maxValue;
69 m_rangeMin = minValue;
70
71 m_pageSize = (int)((maxValue-minValue)/10);
72
73 // TODO create slider
74
75 return FALSE;
76 }
77
78 bool wxSlider::OS2OnScroll(int WXUNUSED(orientation), WXWORD wParam,
79 WXWORD pos, WXHWND control)
80 {
81 int position = 0; // Dummy - not used in this mode
82
83 int nScrollInc;
84 wxEventType scrollEvent = wxEVT_NULL;
85 // TODO:
86 /*
87 switch ( wParam )
88 {
89 case SB_TOP:
90 nScrollInc = m_rangeMax - position;
91 scrollEvent = wxEVT_SCROLL_TOP;
92 break;
93
94 case SB_BOTTOM:
95 nScrollInc = - position;
96 scrollEvent = wxEVT_SCROLL_BOTTOM;
97 break;
98
99 case SB_LINEUP:
100 nScrollInc = - GetLineSize();
101 scrollEvent = wxEVT_SCROLL_LINEUP;
102 break;
103
104 case SB_LINEDOWN:
105 nScrollInc = GetLineSize();
106 scrollEvent = wxEVT_SCROLL_LINEDOWN;
107 break;
108
109 case SB_PAGEUP:
110 nScrollInc = -GetPageSize();
111 scrollEvent = wxEVT_SCROLL_PAGEUP;
112 break;
113
114 case SB_PAGEDOWN:
115 nScrollInc = GetPageSize();
116 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
117 break;
118
119 case SB_THUMBTRACK:
120 case SB_THUMBPOSITION:
121 #ifdef __WIN32__
122 nScrollInc = (signed short)pos - position;
123 #else // Win16
124 nScrollInc = pos - position;
125 #endif // Win32/16
126 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
127 break;
128
129 default:
130 nScrollInc = 0;
131 }
132
133 if ( nScrollInc == 0 )
134 {
135 // no event...
136 return FALSE;
137 }
138
139 int newPos = (int)::SendMessage((HWND) control, TBM_GETPOS, 0, 0);
140 if ( (newPos < GetMin()) || (newPos > GetMax()) )
141 {
142 // out of range - but we did process it
143 return TRUE;
144 }
145 */
146 int newPos = 0; //temporary
147 SetValue(newPos);
148
149 wxScrollEvent event(scrollEvent, m_windowId);
150 event.SetPosition(newPos);
151 event.SetEventObject( this );
152 GetEventHandler()->ProcessEvent(event);
153
154 wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() );
155 cevent.SetEventObject( this );
156
157 return GetEventHandler()->ProcessEvent( cevent );
158 }
159
160 wxSlider::~wxSlider()
161 {
162 // TODO:
163 }
164
165 int wxSlider::GetValue() const
166 {
167 // TODO
168 return 0;
169 }
170
171 void wxSlider::SetValue(int value)
172 {
173 // TODO
174 }
175
176 void wxSlider::GetSize(int *width, int *height) const
177 {
178 // TODO
179 }
180
181 void wxSlider::GetPosition(int *x, int *y) const
182 {
183 // TODO
184 }
185
186 // TODO one day, make sense of all this horros and replace it with a readable
187 // DoGetBestSize()
188 void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags)
189 {
190 int x1 = x;
191 int y1 = y;
192 int w1 = width;
193 int h1 = height;
194
195 int currentX, currentY;
196 GetPosition(&currentX, &currentY);
197 if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
198 x1 = currentX;
199 if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
200 y1 = currentY;
201
202 // TODO:
203 /*
204
205 AdjustForParentClientOrigin(x1, y1, sizeFlags);
206
207 wxChar buf[300];
208
209 int x_offset = x;
210 int y_offset = y;
211
212 int cx; // slider,min,max sizes
213 int cy;
214 int cyf;
215
216 wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
217
218 if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL)
219 {
220 if ( m_windowStyle & wxSL_LABELS )
221 {
222 int min_len = 0;
223
224 GetWindowText((HWND) m_staticMin, buf, 300);
225 GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont());
226
227 int max_len = 0;
228
229 GetWindowText((HWND) m_staticMax, buf, 300);
230 GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont());
231 if (m_staticValue)
232 {
233 int new_width = (int)(wxMax(min_len, max_len));
234 int valueHeight = (int)cyf;
235 #ifdef __WIN32__
236 // For some reason, under Win95, the text edit control has
237 // a lot of space before the first character
238 new_width += 3*cx;
239 #endif
240 // The height needs to be a bit bigger under Win95 if using native
241 // 3D effects.
242 valueHeight = (int) (valueHeight * 1.5) ;
243 MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE);
244 x_offset += new_width + cx;
245 }
246
247 MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE);
248 x_offset += (int)(min_len + cx);
249
250 int slider_length = (int)(w1 - x_offset - max_len - cx);
251
252 int slider_height = h1;
253 if (slider_height < 0 )
254 slider_height = 20;
255
256 // Slider must have a minimum/default length/height
257 if (slider_length < 100)
258 slider_length = 100;
259
260 MoveWindow(GetHwnd(), x_offset, y_offset, slider_length, slider_height, TRUE);
261 x_offset += slider_length + cx;
262
263 MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE);
264 }
265 else
266 {
267 // No labels
268 // If we're prepared to use the existing size, then...
269 if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
270 {
271 GetSize(&w1, &h1);
272 }
273 if ( w1 < 0 )
274 w1 = 200;
275 if ( h1 < 0 )
276 h1 = 20;
277 MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
278 }
279 }
280 else
281 {
282 if ( m_windowStyle & wxSL_LABELS )
283 {
284 int min_len;
285 GetWindowText((HWND) m_staticMin, buf, 300);
286 GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont());
287
288 int max_len;
289 GetWindowText((HWND) m_staticMax, buf, 300);
290 GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont());
291
292 if (m_staticValue)
293 {
294 int new_width = (int)(wxMax(min_len, max_len));
295 int valueHeight = (int)cyf;
296 //// Suggested change by George Tasker - remove this block...
297 #ifdef __WIN32__
298 // For some reason, under Win95, the text edit control has
299 // a lot of space before the first character
300 new_width += 3*cx;
301 #endif
302 ... and replace with following line:
303 new_width += cx;
304
305 // The height needs to be a bit bigger under Win95 if using native
306 // 3D effects.
307 valueHeight = (int) (valueHeight * 1.5) ;
308
309 MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE);
310 y_offset += valueHeight;
311 }
312
313 MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE);
314 y_offset += cy;
315
316 int slider_length = (int)(h1 - y_offset - cy - cy);
317
318 int slider_width = w1;
319 if (slider_width < 0 )
320 slider_width = 20;
321
322 // Slider must have a minimum/default length
323 if (slider_length < 100)
324 slider_length = 100;
325
326 MoveWindow(GetHwnd(), x_offset, y_offset, slider_width, slider_length, TRUE);
327 y_offset += slider_length;
328
329 MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE);
330 }
331 else
332 {
333 // No labels
334 // If we're prepared to use the existing size, then...
335 if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
336 {
337 GetSize(&w1, &h1);
338 }
339 if ( w1 < 0 )
340 w1 = 20;
341 if ( h1 < 0 )
342 h1 = 200;
343 MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
344 }
345 }
346 */
347 }
348
349 void wxSlider::SetRange(int minValue, int maxValue)
350 {
351 m_rangeMin = minValue;
352 m_rangeMax = maxValue;
353
354 // TODO
355 }
356
357 WXHBRUSH wxSlider::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
358 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
359 {
360 // TODO:
361 /*
362 if ( nCtlColor == CTLCOLOR_SCROLLBAR )
363 return 0;
364
365 // Otherwise, it's a static
366 if (GetParent()->GetTransparentBackground())
367 SetBkMode((HDC) pDC, TRANSPARENT);
368 else
369 SetBkMode((HDC) pDC, OPAQUE);
370
371 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
372 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
373
374 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
375 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
376 */
377 return (WXHBRUSH)0;
378 }
379
380 // For trackbars only
381 void wxSlider::SetTickFreq(int n, int pos)
382 {
383 // TODO
384 m_tickFreq = n;
385 }
386
387 void wxSlider::SetPageSize(int pageSize)
388 {
389 // TODO
390 m_pageSize = pageSize;
391 }
392
393 int wxSlider::GetPageSize() const
394 {
395 return m_pageSize;
396 }
397
398 void wxSlider::ClearSel()
399 {
400 // TODO
401 }
402
403 void wxSlider::ClearTicks()
404 {
405 // TODO
406 }
407
408 void wxSlider::SetLineSize(int lineSize)
409 {
410 m_lineSize = lineSize;
411 // TODO
412 }
413
414 int wxSlider::GetLineSize() const
415 {
416 // TODO
417 return 0;
418 }
419
420 int wxSlider::GetSelEnd() const
421 {
422 // TODO
423 return 0;
424 }
425
426 int wxSlider::GetSelStart() const
427 {
428 // TODO
429 return 0;
430 }
431
432 void wxSlider::SetSelection(int minPos, int maxPos)
433 {
434 // TODO
435 }
436
437 void wxSlider::SetThumbLength(int len)
438 {
439 // TODO
440 }
441
442 int wxSlider::GetThumbLength() const
443 {
444 // TODO
445 return 0;
446 }
447
448 void wxSlider::SetTick(int tickPos)
449 {
450 // TODO
451 }
452
453 bool wxSlider::ContainsHWND(WXHWND hWnd) const
454 {
455 return ( hWnd == GetStaticMin() || hWnd == GetStaticMax() || hWnd == GetEditValue() );
456 }
457
458 void wxSlider::Command (wxCommandEvent & event)
459 {
460 SetValue (event.GetInt());
461 ProcessCommand (event);
462 }
463
464 bool wxSlider::Show(bool show)
465 {
466 // TODO
467 return TRUE;
468 }
469