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