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