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