]> git.saurik.com Git - wxWidgets.git/blame - src/msw/slider95.cpp
xti additions / changes, trying to reduce dependencies
[wxWidgets.git] / src / msw / slider95.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
da87a1ca
JS
2// Name: slider95.cpp
3// Purpose: wxSlider95, using the Win95 trackbar control
2bda0e17
KB
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
da87a1ca 13#pragma implementation "slider95.h"
2bda0e17
KB
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
1e6feb95
VZ
23#if wxUSE_SLIDER
24
2bda0e17 25#ifndef WX_PRECOMP
3096bd2f
VZ
26#include "wx/utils.h"
27#include "wx/brush.h"
5438a566 28#include "wx/slider.h"
2bda0e17
KB
29#endif
30
da87a1ca 31#ifdef __WIN95__
2bda0e17 32
da87a1ca
JS
33#include "wx/msw/slider95.h"
34#include "wx/msw/private.h"
2bda0e17 35
b39dbf34 36#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
c42404a5 37 #include <commctrl.h>
2bda0e17
KB
38#endif
39
f0a126fe
SC
40#if wxUSE_EXTENDED_RTTI
41IMPLEMENT_DYNAMIC_CLASS_XTI(wxSlider95, wxControl,"wx/scrolbar.h")
42
43WX_BEGIN_PROPERTIES_TABLE(wxSlider95)
44 WX_PROPERTY( Value , int , SetValue, GetValue , 0)
45 WX_PROPERTY( Minimum , int , SetMin, GetMin, 0 )
46 WX_PROPERTY( Maximum , int , SetMax, GetMax, 0 )
47 WX_PROPERTY( PageSize , int , SetPageSize, GetLineSize, 1 )
48 WX_PROPERTY( LineSize , int , SetLineSize, GetLineSize, 1 )
49 WX_PROPERTY( ThumbLength , int , SetThumbLength, GetThumbLength, 1 )
50WX_END_PROPERTIES_TABLE()
51
52WX_BEGIN_HANDLERS_TABLE(wxSlider95)
53WX_END_HANDLERS_TABLE()
54
55WX_CONSTRUCTOR_8( wxSlider95 , wxWindow* , Parent , wxWindowID , Id , int , Value , int , Minimum , int , Maximum , wxPoint , Position , wxSize , Size , long , WindowStyle )
56#else
bf532053 57IMPLEMENT_DYNAMIC_CLASS(wxSlider95, wxControl)
f0a126fe 58#endif
2bda0e17
KB
59
60// Slider
bfc6fde4 61wxSlider95::wxSlider95()
2bda0e17 62{
5f605ccf
VZ
63 m_staticValue = (WXHWND) NULL;
64 m_staticMin = (WXHWND) NULL;
65 m_staticMax = (WXHWND) NULL;
66 m_pageSize = 1;
67 m_lineSize = 1;
68 m_rangeMax = 0;
69 m_rangeMin = 0;
70 m_tickFreq = 0;
2bda0e17
KB
71}
72
debe6624
JS
73bool wxSlider95::Create(wxWindow *parent, wxWindowID id,
74 int value, int minValue, int maxValue,
2bda0e17 75 const wxPoint& pos,
debe6624 76 const wxSize& size, long style,
2bda0e17
KB
77 const wxValidator& validator,
78 const wxString& name)
79{
fe3d9123
JS
80 if ( (style & wxBORDER_MASK) == wxBORDER_DEFAULT )
81 style |= wxBORDER_NONE;
82
5f605ccf 83 SetName(name);
11b6a93b 84#if wxUSE_VALIDATORS
5f605ccf 85 SetValidator(validator);
11b6a93b 86#endif // wxUSE_VALIDATORS
2bda0e17 87
5f605ccf
VZ
88 if (parent) parent->AddChild(this);
89
90 SetBackgroundColour(parent->GetBackgroundColour()) ;
91 SetForegroundColour(parent->GetForegroundColour()) ;
92
93 m_staticValue = (WXHWND) NULL;;
94 m_staticMin = (WXHWND) NULL;;
95 m_staticMax = (WXHWND) NULL;;
96 m_pageSize = 1;
97 m_lineSize = 1;
98 m_windowStyle = style;
99 m_tickFreq = 0;
100
101 if ( id == -1 )
102 m_windowId = (int)NewControlId();
103 else
104 m_windowId = id;
105
106 int x = pos.x;
107 int y = pos.y;
108 int width = size.x;
109 int height = size.y;
110
111 long msStyle = 0;
112 long wstyle = 0;
113
5f605ccf
VZ
114 if ( m_windowStyle & wxSL_LABELS )
115 {
fe3d9123 116 msStyle |= SS_CENTER;
5f605ccf 117
fe3d9123 118 WXDWORD exStyle = 0;
983d2e14
JS
119 long valueStyle = m_windowStyle & ~wxBORDER_MASK;
120 valueStyle |= wxBORDER_SUNKEN;
121 msStyle |= MSWGetStyle(valueStyle, & exStyle) ;
5f605ccf
VZ
122
123 m_staticValue = (WXHWND) CreateWindowEx
124 (
125 exStyle, wxT("STATIC"), NULL,
126 msStyle,
127 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(),
128 wxGetInstance(), NULL
129 );
130
131 // Now create min static control
2b5f62a0
VZ
132 wxString minLabel;
133 minLabel.Printf(wxT("%d"), minValue);
5f605ccf
VZ
134 wstyle = STATIC_FLAGS;
135 if ( m_windowStyle & wxCLIP_SIBLINGS )
136 msStyle |= WS_CLIPSIBLINGS;
137 m_staticMin = (WXHWND) CreateWindowEx
138 (
2b5f62a0 139 0, wxT("STATIC"), minLabel,
5f605ccf
VZ
140 wstyle,
141 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(),
142 wxGetInstance(), NULL
143 );
144 }
145
fe3d9123 146 WXDWORD exStyle = 0;
5f605ccf 147
fe3d9123 148 msStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ;
2bda0e17 149
5f605ccf
VZ
150 if (m_windowStyle & wxSL_VERTICAL)
151 msStyle = TBS_VERT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ;
152 else
153 msStyle = TBS_HORZ | WS_CHILD | WS_VISIBLE | WS_TABSTOP ;
b0766406 154
5f605ccf
VZ
155 if ( m_windowStyle & wxSL_AUTOTICKS )
156 msStyle |= TBS_AUTOTICKS ;
b0766406 157
5f605ccf
VZ
158 if ( m_windowStyle & wxSL_LEFT )
159 msStyle |= TBS_LEFT;
160 else if ( m_windowStyle & wxSL_RIGHT )
161 msStyle |= TBS_RIGHT;
162 else if ( m_windowStyle & wxSL_TOP )
163 msStyle |= TBS_TOP;
164 else if ( m_windowStyle & wxSL_BOTTOM )
165 msStyle |= TBS_BOTTOM;
166 else if ( m_windowStyle & wxSL_BOTH )
167 msStyle |= TBS_BOTH;
168 else if ( ! (m_windowStyle & wxSL_AUTOTICKS) )
169 msStyle |= TBS_NOTICKS;
2bda0e17 170
5f605ccf
VZ
171 if ( m_windowStyle & wxSL_SELRANGE )
172 msStyle |= TBS_ENABLESELRANGE;
2bda0e17 173
5f605ccf
VZ
174 HWND scroll_bar = CreateWindowEx
175 (
fda7962d 176 exStyle, TRACKBAR_CLASS, wxEmptyString,
5f605ccf
VZ
177 msStyle,
178 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
179 wxGetInstance(), NULL
180 );
2bda0e17 181
5f605ccf
VZ
182 m_rangeMax = maxValue;
183 m_rangeMin = minValue;
2bda0e17 184
5f605ccf 185 m_pageSize = (int)((maxValue-minValue)/10);
2bda0e17 186
5f605ccf
VZ
187 ::SendMessage(scroll_bar, TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue));
188 ::SendMessage(scroll_bar, TBM_SETPOS, TRUE, (LPARAM)value);
189 ::SendMessage(scroll_bar, TBM_SETPAGESIZE, 0, (LPARAM)m_pageSize);
2bda0e17 190
5f605ccf 191 m_hWnd = (WXHWND)scroll_bar;
2bda0e17 192
5f605ccf 193 SubclassWin(GetHWND());
2bda0e17 194
fda7962d 195 ::SetWindowText((HWND) m_hWnd, wxEmptyString);
2bda0e17 196
5f605ccf 197 SetFont(parent->GetFont());
2bda0e17 198
5f605ccf
VZ
199 if ( m_windowStyle & wxSL_LABELS )
200 {
201 // Finally, create max value static item
2b5f62a0
VZ
202 wxString maxLabel;
203 maxLabel.Printf(wxT("%d"), maxValue);
5f605ccf 204 wstyle = STATIC_FLAGS;
9c331ded 205
5f605ccf
VZ
206 if ( m_windowStyle & wxCLIP_SIBLINGS )
207 msStyle |= WS_CLIPSIBLINGS;
9c331ded 208
5f605ccf
VZ
209 m_staticMax = (WXHWND) CreateWindowEx
210 (
2b5f62a0 211 0, wxT("STATIC"), maxLabel,
5f605ccf
VZ
212 wstyle,
213 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(),
214 wxGetInstance(), NULL
215 );
2bda0e17 216
da87a1ca 217
5f605ccf 218 if (GetFont().Ok())
2bda0e17 219 {
5f605ccf
VZ
220 if (GetFont().GetResourceHandle())
221 {
222 if ( m_staticMin )
223 ::SendMessage((HWND) m_staticMin, WM_SETFONT,
224 (WPARAM) GetFont().GetResourceHandle(), 0L);
225
226 if ( m_staticMax )
227 ::SendMessage((HWND) m_staticMax, WM_SETFONT,
228 (WPARAM) GetFont().GetResourceHandle(), 0L);
229
230 if (m_staticValue)
231 ::SendMessage((HWND) m_staticValue, WM_SETFONT,
232 (WPARAM) GetFont().GetResourceHandle(), 0L);
233 }
2bda0e17 234 }
5f605ccf 235 }
2bda0e17 236
5f605ccf
VZ
237 SetSize(x, y, width, height);
238 SetValue(value);
2bda0e17 239
5f605ccf 240 return TRUE;
2bda0e17
KB
241}
242
a23fd0e1 243bool wxSlider95::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam,
d699f48b 244 WXWORD WXUNUSED(pos), WXHWND control)
2bda0e17 245{
1e6feb95 246 wxEventType scrollEvent;
2bda0e17
KB
247 switch ( wParam )
248 {
a23fd0e1 249 case SB_TOP:
a23fd0e1
VZ
250 scrollEvent = wxEVT_SCROLL_TOP;
251 break;
252
253 case SB_BOTTOM:
a23fd0e1
VZ
254 scrollEvent = wxEVT_SCROLL_BOTTOM;
255 break;
256
257 case SB_LINEUP:
a23fd0e1
VZ
258 scrollEvent = wxEVT_SCROLL_LINEUP;
259 break;
260
261 case SB_LINEDOWN:
a23fd0e1
VZ
262 scrollEvent = wxEVT_SCROLL_LINEDOWN;
263 break;
264
265 case SB_PAGEUP:
a23fd0e1
VZ
266 scrollEvent = wxEVT_SCROLL_PAGEUP;
267 break;
268
269 case SB_PAGEDOWN:
a23fd0e1
VZ
270 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
271 break;
272
273 case SB_THUMBTRACK:
a23fd0e1
VZ
274 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
275 break;
276
e8b669d3
VZ
277 case SB_THUMBPOSITION:
278 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
279 break;
280
281 case SB_ENDSCROLL:
282 scrollEvent = wxEVT_SCROLL_ENDSCROLL;
283 break;
284
a23fd0e1 285 default:
1e6feb95
VZ
286 // unknown scroll event?
287 return FALSE;
2bda0e17
KB
288 }
289
5f605ccf 290 int newPos = (int) ::SendMessage((HWND) control, TBM_GETPOS, 0, 0);
a23fd0e1 291 if ( (newPos < GetMin()) || (newPos > GetMax()) )
2bda0e17 292 {
a23fd0e1
VZ
293 // out of range - but we did process it
294 return TRUE;
295 }
2bda0e17 296
a23fd0e1 297 SetValue(newPos);
2bda0e17 298
a23fd0e1
VZ
299 wxScrollEvent event(scrollEvent, m_windowId);
300 event.SetPosition(newPos);
301 event.SetEventObject( this );
302 GetEventHandler()->ProcessEvent(event);
f3a65071 303
a23fd0e1 304 wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() );
f6bcfd97 305 cevent.SetInt( newPos );
a23fd0e1 306 cevent.SetEventObject( this );
f3a65071 307
a23fd0e1 308 return GetEventHandler()->ProcessEvent( cevent );
2bda0e17
KB
309}
310
bfc6fde4 311wxSlider95::~wxSlider95()
2bda0e17
KB
312{
313 if (m_staticMin)
5f605ccf
VZ
314 {
315 ::DestroyWindow((HWND) m_staticMin);
316 m_staticMin = (WXHWND) NULL;
317 }
318
2bda0e17 319 if (m_staticMax)
5f605ccf
VZ
320 {
321 ::DestroyWindow((HWND) m_staticMax);
322 m_staticMax = (WXHWND) NULL;
323 }
324
2bda0e17 325 if (m_staticValue)
5f605ccf
VZ
326 {
327 ::DestroyWindow((HWND) m_staticValue);
328 m_staticValue = (WXHWND) NULL;
329 }
2bda0e17
KB
330}
331
bfc6fde4 332int wxSlider95::GetValue() const
2bda0e17 333{
5f605ccf 334 return ::SendMessage(GetHwnd(), TBM_GETPOS, 0, 0);
2bda0e17
KB
335}
336
debe6624 337void wxSlider95::SetValue(int value)
2bda0e17 338{
5f605ccf
VZ
339 ::SendMessage(GetHwnd(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value);
340
341 if (m_staticValue)
342 {
2b5f62a0
VZ
343 wxString str;
344 str.Printf(wxT("%d"), value);
345 ::SetWindowText((HWND) m_staticValue, str);
5f605ccf
VZ
346 }
347}
348
349void wxSlider95::DoGetSize(int *width, int *height) const
350{
351 GetSize(width, height);
2bda0e17
KB
352}
353
da87a1ca 354void wxSlider95::GetSize(int *width, int *height) const
2bda0e17 355{
5f605ccf
VZ
356 RECT rect;
357 rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1;
358
359 wxFindMaxSize(GetHWND(), &rect);
2bda0e17 360
5f605ccf
VZ
361 if (m_staticMin)
362 wxFindMaxSize(m_staticMin, &rect);
2bda0e17 363
5f605ccf
VZ
364 if (m_staticMax)
365 wxFindMaxSize(m_staticMax, &rect);
2bda0e17 366
5f605ccf
VZ
367 if (m_staticValue)
368 wxFindMaxSize(m_staticValue, &rect);
369
370 *width = rect.right - rect.left;
371 *height = rect.bottom - rect.top;
2bda0e17
KB
372}
373
da87a1ca 374void wxSlider95::GetPosition(int *x, int *y) const
2bda0e17 375{
5f605ccf
VZ
376 wxWindow *parent = GetParent();
377 RECT rect;
378 rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1;
379
380 wxFindMaxSize(GetHWND(), &rect);
381
382 if (m_staticMin)
383 wxFindMaxSize(m_staticMin, &rect);
384 if (m_staticMax)
385 wxFindMaxSize(m_staticMax, &rect);
386 if (m_staticValue)
387 wxFindMaxSize(m_staticValue, &rect);
388
389 // Since we now have the absolute screen coords,
390 // if there's a parent we must subtract its top left corner
391 POINT point;
392 point.x = rect.left;
393 point.y = rect.top;
394 if (parent)
395 ::ScreenToClient((HWND) parent->GetHWND(), &point);
396
397 // We may be faking the client origin.
398 // So a window that's really at (0, 30) may appear
399 // (to wxWin apps) to be at (0, 0).
400 if (GetParent())
401 {
402 wxPoint pt(GetParent()->GetClientAreaOrigin());
403 point.x -= pt.x;
404 point.y -= pt.y;
405 }
406
407 *x = point.x;
408 *y = point.y;
2bda0e17
KB
409}
410
4438caf4
VZ
411// TODO one day, make sense of all this horros and replace it with a readable
412// DoGetBestSize()
bfc6fde4 413void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
2bda0e17 414{
5f605ccf
VZ
415 int x1 = x;
416 int y1 = y;
417 int w1 = width;
418 int h1 = height;
2bda0e17 419
5f605ccf
VZ
420 int currentX, currentY;
421 GetPosition(&currentX, &currentY);
422 if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
423 x1 = currentX;
424 if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
425 y1 = currentY;
2bda0e17 426
5f605ccf 427 AdjustForParentClientOrigin(x1, y1, sizeFlags);
81d66cf3 428
5f605ccf 429 wxChar buf[300];
2bda0e17 430
5f605ccf
VZ
431 int x_offset = x;
432 int y_offset = y;
2bda0e17 433
5f605ccf
VZ
434 int cx; // slider,min,max sizes
435 int cy;
436 int cyf;
2bda0e17 437
5f605ccf 438 wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
2bda0e17 439
5f605ccf 440 if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL)
a23fd0e1 441 {
5f605ccf
VZ
442 if ( m_windowStyle & wxSL_LABELS )
443 {
444 int min_len = 0;
2bda0e17 445
5f605ccf
VZ
446 ::GetWindowText((HWND) m_staticMin, buf, 300);
447 GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont());
2bda0e17 448
5f605ccf 449 int max_len = 0;
2bda0e17 450
5f605ccf
VZ
451 ::GetWindowText((HWND) m_staticMax, buf, 300);
452 GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont());
453 if (m_staticValue)
454 {
455 int new_width = (int)(wxMax(min_len, max_len));
456 int valueHeight = (int)cyf;
2bda0e17 457#ifdef __WIN32__
5f605ccf
VZ
458 // For some reason, under Win95, the text edit control has
459 // a lot of space before the first character
460 new_width += 3*cx;
2bda0e17 461#endif
5f605ccf
VZ
462 // The height needs to be a bit bigger under Win95 if
463 // using native 3D effects.
464 valueHeight = (int) (valueHeight * 1.5) ;
465 ::MoveWindow((HWND) m_staticValue, x_offset, y_offset,
466 new_width, valueHeight, TRUE);
467 x_offset += new_width + cx;
468 }
469
470 MoveWindow((HWND) m_staticMin, x_offset, y_offset,
471 (int) min_len, cy, TRUE);
472 x_offset += (int)(min_len + cx);
473
474 int slider_length = (int)(w1 - x_offset - max_len - cx);
475
476 int slider_height = h1;
477 if (slider_height < 0 )
478 slider_height = 20;
479
480 // Slider must have a minimum/default length/height
481 if (slider_length < 100)
482 slider_length = 100;
483
484 ::MoveWindow(GetHwnd(), x_offset, y_offset,
485 slider_length, slider_height, TRUE);
486 x_offset += slider_length + cx;
487
488 MoveWindow((HWND) m_staticMax, x_offset, y_offset,
489 (int) max_len, cy, TRUE);
490 }
491 else
a23fd0e1 492 {
5f605ccf
VZ
493 // No labels
494 // If we're prepared to use the existing size, then...
495 if
496 (
497 width == -1
498 && height == -1
499 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)
500 )
501 {
502 GetSize(&w1, &h1);
503 }
504
505 if ( w1 < 0 )
506 w1 = 200;
507 if ( h1 < 0 )
508 h1 = 20;
509
510 ::MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
a23fd0e1 511 }
a23fd0e1 512 }
5f605ccf 513 else
2bda0e17 514 {
5f605ccf
VZ
515 if ( m_windowStyle & wxSL_LABELS )
516 {
517 int min_len;
518 ::GetWindowText((HWND) m_staticMin, buf, 300);
519 GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont());
520
521 int max_len;
522 ::GetWindowText((HWND) m_staticMax, buf, 300);
523 GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont());
524
525 if (m_staticValue)
526 {
527 int new_width = (int)(wxMax(min_len, max_len));
528 int valueHeight = (int)cyf;
2bda0e17
KB
529/*** Suggested change by George Tasker - remove this block...
530#ifdef __WIN32__
531 // For some reason, under Win95, the text edit control has
532 // a lot of space before the first character
533 new_width += 3*cx;
534#endif
535 ... and replace with following line: */
5f605ccf 536 new_width += cx;
2bda0e17 537
5f605ccf
VZ
538 // The height needs to be a bit bigger under Win95 if
539 // using native 3D effects.
540 valueHeight = (int) (valueHeight * 1.5) ;
2bda0e17 541
5f605ccf
VZ
542 ::MoveWindow((HWND) m_staticValue, x_offset, y_offset,
543 new_width, valueHeight, TRUE);
544 y_offset += valueHeight;
545 }
2bda0e17 546
5f605ccf
VZ
547 ::MoveWindow((HWND) m_staticMin, x_offset, y_offset,
548 (int) min_len, cy, TRUE);
549 y_offset += cy;
2bda0e17 550
5f605ccf 551 int slider_length = (int)(h1 - y_offset - cy - cy);
da87a1ca 552
5f605ccf
VZ
553 int slider_width = w1;
554 if (slider_width < 0 )
555 slider_width = 20;
2bda0e17 556
5f605ccf
VZ
557 // Slider must have a minimum/default length
558 if (slider_length < 100)
559 slider_length = 100;
2bda0e17 560
5f605ccf
VZ
561 ::MoveWindow(GetHwnd(), x_offset, y_offset,
562 slider_width, slider_length, TRUE);
563 y_offset += slider_length;
2bda0e17 564
5f605ccf
VZ
565 ::MoveWindow((HWND) m_staticMax, x_offset, y_offset,
566 (int)max_len, cy, TRUE);
567 }
568 else
a23fd0e1 569 {
5f605ccf
VZ
570 // No labels
571 // If we're prepared to use the existing size, then...
572 if
573 (
574 width == -1 && height == -1
575 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)
576 )
577 {
578 GetSize(&w1, &h1);
579 }
580
581 if ( w1 < 0 )
582 w1 = 20;
583 if ( h1 < 0 )
584 h1 = 200;
585
586 ::MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
a23fd0e1 587 }
a23fd0e1 588 }
2bda0e17
KB
589}
590
debe6624 591void wxSlider95::SetRange(int minValue, int maxValue)
2bda0e17 592{
5f605ccf
VZ
593 m_rangeMin = minValue;
594 m_rangeMax = maxValue;
595
596 ::SendMessage(GetHwnd(), TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue));
597
598 wxChar buf[40];
599 if ( m_staticMin )
600 {
601 wxSprintf(buf, wxT("%d"), m_rangeMin);
602 ::SetWindowText((HWND) m_staticMin, buf);
603 }
604
605 if ( m_staticMax )
606 {
607 wxSprintf(buf, wxT("%d"), m_rangeMax);
608 ::SetWindowText((HWND) m_staticMax, buf);
609 }
2bda0e17
KB
610}
611
debe6624 612WXHBRUSH wxSlider95::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
a23fd0e1 613 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
2bda0e17 614{
4676948b 615#ifndef __WXWINCE__
5f605ccf
VZ
616 if ( nCtlColor == CTLCOLOR_SCROLLBAR )
617 return 0;
4676948b
JS
618#else
619 if ( nCtlColor != CTLCOLOR_STATIC )
620 return 0;
621#endif
5f605ccf
VZ
622 // Otherwise, it's a static
623 return wxControl::OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
2bda0e17
KB
624}
625
626// For trackbars only
debe6624 627void wxSlider95::SetTickFreq(int n, int pos)
2bda0e17 628{
2bda0e17 629 m_tickFreq = n;
4438caf4 630 ::SendMessage( GetHwnd(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos );
2bda0e17
KB
631}
632
debe6624 633void wxSlider95::SetPageSize(int pageSize)
2bda0e17 634{
4438caf4 635 ::SendMessage( GetHwnd(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize );
2bda0e17
KB
636 m_pageSize = pageSize;
637}
638
bfc6fde4 639int wxSlider95::GetPageSize() const
2bda0e17
KB
640{
641 return m_pageSize;
642}
643
bfc6fde4 644void wxSlider95::ClearSel()
2bda0e17 645{
4438caf4 646 ::SendMessage( GetHwnd(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0 );
2bda0e17
KB
647}
648
bfc6fde4 649void wxSlider95::ClearTicks()
2bda0e17 650{
4438caf4 651 ::SendMessage( GetHwnd(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0 );
2bda0e17
KB
652}
653
debe6624 654void wxSlider95::SetLineSize(int lineSize)
2bda0e17 655{
5f605ccf
VZ
656 m_lineSize = lineSize;
657 ::SendMessage( GetHwnd(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize );
2bda0e17
KB
658}
659
bfc6fde4 660int wxSlider95::GetLineSize() const
2bda0e17 661{
5f605ccf
VZ
662 return (int) ::SendMessage( GetHwnd(), TBM_GETLINESIZE,
663 (WPARAM) 0, (LPARAM) 0 );
2bda0e17
KB
664}
665
bfc6fde4 666int wxSlider95::GetSelEnd() const
2bda0e17 667{
5f605ccf
VZ
668 return (int) ::SendMessage( GetHwnd(), TBM_SETSELEND,
669 (WPARAM) 0, (LPARAM) 0 );
2bda0e17
KB
670}
671
bfc6fde4 672int wxSlider95::GetSelStart() const
2bda0e17 673{
5f605ccf
VZ
674 return (int) ::SendMessage( GetHwnd(), TBM_GETSELSTART,
675 (WPARAM) 0, (LPARAM) 0 );
2bda0e17
KB
676}
677
debe6624 678void wxSlider95::SetSelection(int minPos, int maxPos)
2bda0e17 679{
5f605ccf
VZ
680 ::SendMessage(GetHwnd(), TBM_SETSEL,
681 (WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) );
2bda0e17
KB
682}
683
debe6624 684void wxSlider95::SetThumbLength(int len)
2bda0e17 685{
5f605ccf 686 ::SendMessage( GetHwnd(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0 );
2bda0e17
KB
687}
688
bfc6fde4 689int wxSlider95::GetThumbLength() const
2bda0e17 690{
5f605ccf
VZ
691 return (int) ::SendMessage( GetHwnd(), TBM_GETTHUMBLENGTH,
692 (WPARAM) 0, (LPARAM) 0 );
2bda0e17
KB
693}
694
debe6624 695void wxSlider95::SetTick(int tickPos)
2bda0e17 696{
4438caf4 697 ::SendMessage( GetHwnd(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos );
2bda0e17
KB
698}
699
da87a1ca 700bool wxSlider95::ContainsHWND(WXHWND hWnd) const
2bda0e17 701{
5f605ccf
VZ
702 return
703 (
704 hWnd == GetStaticMin()
705 || hWnd == GetStaticMax()
706 || hWnd == GetEditValue()
707 );
2bda0e17
KB
708}
709
da87a1ca 710void wxSlider95::Command (wxCommandEvent & event)
2bda0e17 711{
5f605ccf
VZ
712 SetValue (event.GetInt());
713 ProcessCommand (event);
2bda0e17
KB
714}
715
debe6624 716bool wxSlider95::Show(bool show)
2bda0e17 717{
a23fd0e1 718 wxWindow::Show(show);
2bda0e17
KB
719
720 int cshow;
721 if (show)
722 cshow = SW_SHOW;
723 else
724 cshow = SW_HIDE;
725
726 if(m_staticValue)
a23fd0e1 727 ShowWindow((HWND) m_staticValue, (BOOL)cshow);
5f605ccf 728
2bda0e17 729 if(m_staticMin)
a23fd0e1 730 ShowWindow((HWND) m_staticMin, (BOOL)cshow);
5f605ccf 731
2bda0e17 732 if(m_staticMax)
a23fd0e1 733 ShowWindow((HWND) m_staticMax, (BOOL)cshow);
5f605ccf 734
2bda0e17
KB
735 return TRUE;
736}
737
da87a1ca
JS
738#endif
739 // __WIN95__
2bda0e17 740
1e6feb95 741#endif // wxUSE_SLIDER