]> git.saurik.com Git - wxWidgets.git/blame - src/msw/slider95.cpp
extended wxWindow::MSWGetBgBrush() and wxControl::MSWControlColor() to work for arbit...
[wxWidgets.git] / src / msw / slider95.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
7d0d80bd
WS
2// Name: msw/slider.cpp
3// Purpose: wxSlider, using the Win95 (and later) trackbar control
2bda0e17
KB
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6181cef5
VZ
8// Copyright: (c) Julian Smart 1998
9// Vadim Zeitlin 2004
65571936 10// Licence: wxWindows licence
2bda0e17
KB
11/////////////////////////////////////////////////////////////////////////////
12
6181cef5
VZ
13// ============================================================================
14// declarations
15// ============================================================================
16
14f355c2 17#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
da87a1ca 18#pragma implementation "slider95.h"
2bda0e17
KB
19#endif
20
6181cef5
VZ
21// ----------------------------------------------------------------------------
22// headers
23// ----------------------------------------------------------------------------
24
2bda0e17
KB
25// For compilers that support precompilation, includes "wx.h".
26#include "wx/wxprec.h"
27
28#ifdef __BORLANDC__
6181cef5 29 #pragma hdrstop
2bda0e17
KB
30#endif
31
1e6feb95
VZ
32#if wxUSE_SLIDER
33
2bda0e17 34#ifndef WX_PRECOMP
6181cef5 35 #include "wx/brush.h"
2bda0e17
KB
36#endif
37
6181cef5
VZ
38#include "wx/slider.h"
39#include "wx/msw/subwin.h"
2bda0e17 40
6181cef5 41#if !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
c42404a5 42 #include <commctrl.h>
2bda0e17
KB
43#endif
44
6181cef5
VZ
45// ----------------------------------------------------------------------------
46// constants
47// ----------------------------------------------------------------------------
48
7d0d80bd 49// indices of labels in wxSlider::m_labels
6181cef5
VZ
50enum
51{
52 SliderLabel_Min,
53 SliderLabel_Max,
54 SliderLabel_Value,
55 SliderLabel_Last
56};
57
58// the gap between the slider and the labels, in pixels
59static const int HGAP = 5;
60
61// ----------------------------------------------------------------------------
62// XTI
63// ----------------------------------------------------------------------------
64
f0a126fe 65#if wxUSE_EXTENDED_RTTI
bc9fb572
JS
66WX_DEFINE_FLAGS( wxSliderStyle )
67
3ff066a4 68wxBEGIN_FLAGS( wxSliderStyle )
bc9fb572
JS
69 // new style border flags, we put them first to
70 // use them for streaming out
3ff066a4
SC
71 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
72 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
73 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
74 wxFLAGS_MEMBER(wxBORDER_RAISED)
75 wxFLAGS_MEMBER(wxBORDER_STATIC)
76 wxFLAGS_MEMBER(wxBORDER_NONE)
57f4f925 77
bc9fb572 78 // old style border flags
3ff066a4
SC
79 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
80 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
81 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
82 wxFLAGS_MEMBER(wxRAISED_BORDER)
83 wxFLAGS_MEMBER(wxSTATIC_BORDER)
cb0afb26 84 wxFLAGS_MEMBER(wxBORDER)
bc9fb572
JS
85
86 // standard window styles
3ff066a4
SC
87 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
88 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
89 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
90 wxFLAGS_MEMBER(wxWANTS_CHARS)
cb0afb26 91 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
3ff066a4
SC
92 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
93 wxFLAGS_MEMBER(wxVSCROLL)
94 wxFLAGS_MEMBER(wxHSCROLL)
95
96 wxFLAGS_MEMBER(wxSL_HORIZONTAL)
97 wxFLAGS_MEMBER(wxSL_VERTICAL)
98 wxFLAGS_MEMBER(wxSL_AUTOTICKS)
99 wxFLAGS_MEMBER(wxSL_LABELS)
100 wxFLAGS_MEMBER(wxSL_LEFT)
101 wxFLAGS_MEMBER(wxSL_TOP)
102 wxFLAGS_MEMBER(wxSL_RIGHT)
103 wxFLAGS_MEMBER(wxSL_BOTTOM)
104 wxFLAGS_MEMBER(wxSL_BOTH)
105 wxFLAGS_MEMBER(wxSL_SELRANGE)
6bee5ffb 106 wxFLAGS_MEMBER(wxSL_INVERSE)
3ff066a4
SC
107
108wxEND_FLAGS( wxSliderStyle )
bc9fb572 109
7d0d80bd 110IMPLEMENT_DYNAMIC_CLASS_XTI(wxSlider, wxControl,"wx/scrolbar.h")
f0a126fe 111
7d0d80bd 112wxBEGIN_PROPERTIES_TABLE(wxSlider)
3ff066a4
SC
113 wxEVENT_RANGE_PROPERTY( Scroll , wxEVT_SCROLL_TOP , wxEVT_SCROLL_ENDSCROLL , wxScrollEvent )
114 wxEVENT_PROPERTY( Updated , wxEVT_COMMAND_SLIDER_UPDATED , wxCommandEvent )
c5ca409b 115
3ff066a4 116 wxPROPERTY( Value , int , SetValue, GetValue , 0, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
822e690b
WS
117 wxPROPERTY( Minimum , int , SetMin, GetMin, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
118 wxPROPERTY( Maximum , int , SetMax, GetMax, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
119 wxPROPERTY( PageSize , int , SetPageSize, GetLineSize, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
120 wxPROPERTY( LineSize , int , SetLineSize, GetLineSize, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
121 wxPROPERTY( ThumbLength , int , SetThumbLength, GetThumbLength, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
af498247 122 wxPROPERTY_FLAGS( WindowStyle , wxSliderStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
3ff066a4 123wxEND_PROPERTIES_TABLE()
f0a126fe 124
7d0d80bd 125wxBEGIN_HANDLERS_TABLE(wxSlider)
3ff066a4 126wxEND_HANDLERS_TABLE()
f0a126fe 127
7d0d80bd 128wxCONSTRUCTOR_8( wxSlider , wxWindow* , Parent , wxWindowID , Id , int , Value , int , Minimum , int , Maximum , wxPoint , Position , wxSize , Size , long , WindowStyle )
f0a126fe 129#else
7d0d80bd 130IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
f0a126fe 131#endif
2bda0e17 132
6181cef5 133// ============================================================================
7d0d80bd 134// wxSlider implementation
6181cef5
VZ
135// ============================================================================
136
137// ----------------------------------------------------------------------------
138// construction
139// ----------------------------------------------------------------------------
140
7d0d80bd 141void wxSlider::Init()
2bda0e17 142{
6181cef5
VZ
143 m_labels = NULL;
144
5f605ccf
VZ
145 m_pageSize = 1;
146 m_lineSize = 1;
147 m_rangeMax = 0;
148 m_rangeMin = 0;
149 m_tickFreq = 0;
2bda0e17
KB
150}
151
6181cef5 152bool
7d0d80bd
WS
153wxSlider::Create(wxWindow *parent,
154 wxWindowID id,
155 int value,
156 int minValue,
157 int maxValue,
158 const wxPoint& pos,
159 const wxSize& size,
160 long style,
161 const wxValidator& validator,
162 const wxString& name)
2bda0e17 163{
10f80f9b
VZ
164 // our styles are redundant: wxSL_LEFT/RIGHT imply wxSL_VERTICAL and
165 // wxSL_TOP/BOTTOM imply wxSL_HORIZONTAL, but for backwards compatibility
166 // reasons we can't really change it, instead try to infer the orientation
167 // from the flags given to us here
168 switch ( style & (wxSL_LEFT | wxSL_RIGHT | wxSL_TOP | wxSL_BOTTOM) )
169 {
170 case wxSL_LEFT:
171 case wxSL_RIGHT:
172 style |= wxSL_VERTICAL;
173 break;
174
175 case wxSL_TOP:
176 case wxSL_BOTTOM:
177 style |= wxSL_HORIZONTAL;
178 break;
179
180 case 0:
181 // no specific direction, do we have at least the orientation?
182 if ( !(style & (wxSL_HORIZONTAL | wxSL_VERTICAL)) )
183 {
184 // no, choose default
185 style |= wxSL_BOTTOM | wxSL_HORIZONTAL;
186 }
187 };
188
189 wxASSERT_MSG( !(style & wxSL_VERTICAL) | !(style & wxSL_HORIZONTAL),
190 _T("incompatible slider direction and orientation") );
191
192
6181cef5
VZ
193 // initialize everything
194 if ( !CreateControl(parent, id, pos, size, style, validator, name) )
822e690b 195 return false;
2bda0e17 196
6181cef5
VZ
197 // ensure that we have correct values for GetLabelsSize()
198 m_rangeMin = minValue;
199 m_rangeMax = maxValue;
5f605ccf 200
6181cef5
VZ
201 // create the labels first, so that our DoGetBestSize() could take them
202 // into account
203 //
204 // note that we could simply create 3 wxStaticTexts here but it could
205 // result in some observable side effects at wx level (e.g. the parent of
206 // wxSlider would have 3 more children than expected) and so we prefer not
207 // to do it like this
5f605ccf
VZ
208 if ( m_windowStyle & wxSL_LABELS )
209 {
6181cef5
VZ
210 m_labels = new wxSubwindows(SliderLabel_Last);
211
212 HWND hwndParent = GetHwndOf(parent);
213 for ( size_t n = 0; n < SliderLabel_Last; n++ )
214 {
215 (*m_labels)[n] = ::CreateWindow
216 (
217 wxT("STATIC"),
218 NULL,
219 WS_CHILD | WS_VISIBLE | SS_CENTER,
220 0, 0, 0, 0,
221 hwndParent,
222 (HMENU)NewControlId(),
223 wxGetInstance(),
224 NULL
225 );
226 }
227
228 m_labels->SetFont(GetFont());
5f605ccf
VZ
229 }
230
6181cef5
VZ
231 // now create the main control too
232 if ( !MSWCreateControl(TRACKBAR_CLASS, wxEmptyString, pos, size) )
233 return false;
5f605ccf 234
6181cef5
VZ
235 // and initialize everything
236 SetRange(minValue, maxValue);
237 SetValue(value);
238 SetPageSize((maxValue - minValue)/10);
822e690b 239
8a8dcc34
VZ
240 // we need to position the labels correctly if we have them and if
241 // SetSize() hadn't been called before (when best size was determined by
242 // MSWCreateControl()) as in this case they haven't been put in place yet
243 if ( m_labels && size.x != wxDefaultCoord && size.y != wxDefaultCoord )
244 {
245 SetSize(size);
246 }
247
6181cef5
VZ
248 return true;
249}
2bda0e17 250
7d0d80bd 251WXDWORD wxSlider::MSWGetStyle(long style, WXDWORD *exstyle) const
6181cef5
VZ
252{
253 WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
b0766406 254
10f80f9b 255 // TBS_HORZ, TBS_RIGHT and TBS_BOTTOM are 0 but do include them for clarity
6181cef5
VZ
256 msStyle |= style & wxSL_VERTICAL ? TBS_VERT : TBS_HORZ;
257
10f80f9b 258 if ( style & wxSL_BOTH )
cbc6af74
VZ
259 {
260 // this fully specifies the style combined with TBS_VERT/HORZ above
5f605ccf 261 msStyle |= TBS_BOTH;
cbc6af74
VZ
262 }
263 else // choose one direction
264 {
265 if ( style & wxSL_LEFT )
266 msStyle |= TBS_LEFT;
267 else if ( style & wxSL_RIGHT )
268 msStyle |= TBS_RIGHT;
269 else if ( style & wxSL_TOP )
270 msStyle |= TBS_TOP;
271 else if ( style & wxSL_BOTTOM )
272 msStyle |= TBS_BOTTOM;
273 }
10f80f9b
VZ
274
275 if ( style & wxSL_AUTOTICKS )
276 msStyle |= TBS_AUTOTICKS;
277 else
5f605ccf 278 msStyle |= TBS_NOTICKS;
2bda0e17 279
6181cef5 280 if ( style & wxSL_SELRANGE )
5f605ccf 281 msStyle |= TBS_ENABLESELRANGE;
2bda0e17 282
6181cef5
VZ
283 return msStyle;
284}
7a5a5718 285
7d0d80bd 286wxSlider::~wxSlider()
6181cef5
VZ
287{
288 delete m_labels;
2bda0e17
KB
289}
290
6181cef5
VZ
291// ----------------------------------------------------------------------------
292// event handling
293// ----------------------------------------------------------------------------
294
7d0d80bd
WS
295bool wxSlider::MSWOnScroll(int WXUNUSED(orientation),
296 WXWORD wParam,
297 WXWORD WXUNUSED(pos),
298 WXHWND control)
2bda0e17 299{
1e6feb95 300 wxEventType scrollEvent;
2bda0e17
KB
301 switch ( wParam )
302 {
a23fd0e1 303 case SB_TOP:
a23fd0e1
VZ
304 scrollEvent = wxEVT_SCROLL_TOP;
305 break;
306
307 case SB_BOTTOM:
a23fd0e1
VZ
308 scrollEvent = wxEVT_SCROLL_BOTTOM;
309 break;
310
311 case SB_LINEUP:
a23fd0e1
VZ
312 scrollEvent = wxEVT_SCROLL_LINEUP;
313 break;
314
315 case SB_LINEDOWN:
a23fd0e1
VZ
316 scrollEvent = wxEVT_SCROLL_LINEDOWN;
317 break;
318
319 case SB_PAGEUP:
a23fd0e1
VZ
320 scrollEvent = wxEVT_SCROLL_PAGEUP;
321 break;
322
323 case SB_PAGEDOWN:
a23fd0e1
VZ
324 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
325 break;
326
327 case SB_THUMBTRACK:
a23fd0e1
VZ
328 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
329 break;
330
e8b669d3
VZ
331 case SB_THUMBPOSITION:
332 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
333 break;
334
335 case SB_ENDSCROLL:
336 scrollEvent = wxEVT_SCROLL_ENDSCROLL;
337 break;
338
a23fd0e1 339 default:
1e6feb95 340 // unknown scroll event?
822e690b 341 return false;
2bda0e17
KB
342 }
343
01526d4f 344 int newPos = ValueInvertOrNot((int) ::SendMessage((HWND) control, TBM_GETPOS, 0, 0));
a23fd0e1 345 if ( (newPos < GetMin()) || (newPos > GetMax()) )
2bda0e17 346 {
a23fd0e1 347 // out of range - but we did process it
822e690b 348 return true;
a23fd0e1 349 }
2bda0e17 350
a23fd0e1 351 SetValue(newPos);
2bda0e17 352
a23fd0e1
VZ
353 wxScrollEvent event(scrollEvent, m_windowId);
354 event.SetPosition(newPos);
355 event.SetEventObject( this );
356 GetEventHandler()->ProcessEvent(event);
f3a65071 357
a23fd0e1 358 wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() );
f6bcfd97 359 cevent.SetInt( newPos );
a23fd0e1 360 cevent.SetEventObject( this );
f3a65071 361
a23fd0e1 362 return GetEventHandler()->ProcessEvent( cevent );
2bda0e17
KB
363}
364
7d0d80bd 365void wxSlider::Command (wxCommandEvent & event)
2bda0e17 366{
6181cef5
VZ
367 SetValue (event.GetInt());
368 ProcessCommand (event);
2bda0e17
KB
369}
370
6181cef5
VZ
371// ----------------------------------------------------------------------------
372// geometry stuff
373// ----------------------------------------------------------------------------
2bda0e17 374
7d0d80bd 375wxRect wxSlider::GetBoundingBox() const
2bda0e17 376{
6181cef5
VZ
377 // take care not to call our own functions which would call us recursively
378 int x, y, w, h;
379 wxSliderBase::DoGetPosition(&x, &y);
380 wxSliderBase::DoGetSize(&w, &h);
5f605ccf 381
6181cef5
VZ
382 wxRect rect(x, y, w, h);
383 if ( m_labels )
b5c45059
RD
384 {
385 wxRect lrect = m_labels->GetBoundingBox();
386 GetParent()->ScreenToClient(&lrect.x, &lrect.y);
387 rect.Union(lrect);
388 }
6181cef5
VZ
389
390 return rect;
5f605ccf
VZ
391}
392
7d0d80bd 393void wxSlider::DoGetSize(int *width, int *height) const
2bda0e17 394{
6181cef5 395 wxRect rect = GetBoundingBox();
5f605ccf 396
6819fb9b 397 if ( width )
6181cef5 398 *width = rect.width;
6819fb9b 399 if ( height )
6181cef5 400 *height = rect.height;
2bda0e17
KB
401}
402
7d0d80bd 403void wxSlider::DoGetPosition(int *x, int *y) const
2bda0e17 404{
6181cef5 405 wxRect rect = GetBoundingBox();
5f605ccf 406
6181cef5
VZ
407 if ( x )
408 *x = rect.x;
409 if ( y )
410 *y = rect.y;
411}
5f605ccf 412
7d0d80bd 413int wxSlider::GetLabelsSize(int *width) const
6181cef5
VZ
414{
415 int cy;
5f605ccf 416
6181cef5
VZ
417 if ( width )
418 {
419 // find the max label width
420 int wLabelMin, wLabelMax;
421 GetTextExtent(Format(m_rangeMin), &wLabelMin, &cy);
422 GetTextExtent(Format(m_rangeMax), &wLabelMax, &cy);
5f605ccf 423
6181cef5
VZ
424 *width = wxMax(wLabelMin, wLabelMax);
425 }
426 else
5f605ccf 427 {
6181cef5 428 cy = GetCharHeight();
5f605ccf
VZ
429 }
430
6181cef5 431 return EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
2bda0e17
KB
432}
433
7d0d80bd 434void wxSlider::DoMoveWindow(int x, int y, int width, int height)
2bda0e17 435{
6181cef5
VZ
436 // all complications below are because we need to position the labels,
437 // without them everything is easy
438 if ( !m_labels )
439 {
440 wxSliderBase::DoMoveWindow(x, y, width, height);
441 return;
442 }
2bda0e17 443
8a8dcc34
VZ
444 // be careful to position the slider itself after moving the labels as
445 // otherwise our GetBoundingBox(), which is called from WM_SIZE handler,
446 // would return a wrong result and wrong size would be cached internally
6181cef5
VZ
447 if ( HasFlag(wxSL_VERTICAL) )
448 {
449 int wLabel;
450 int hLabel = GetLabelsSize(&wLabel);
81d66cf3 451
6181cef5 452 int xLabel = HasFlag(wxSL_LEFT) ? x + width - wLabel : x;
2bda0e17 453
6181cef5
VZ
454 // position all labels: min at the top, value in the middle and max at
455 // the bottom
456 ::MoveWindow((*m_labels)[SliderLabel_Min],
457 xLabel, y, wLabel, hLabel, TRUE);
2bda0e17 458
6181cef5
VZ
459 ::MoveWindow((*m_labels)[SliderLabel_Value],
460 xLabel, y + (height - hLabel)/2, wLabel, hLabel, TRUE);
2bda0e17 461
6181cef5
VZ
462 ::MoveWindow((*m_labels)[SliderLabel_Max],
463 xLabel, y + height - hLabel, wLabel, hLabel, TRUE);
8a8dcc34
VZ
464
465 // position the slider itself along the left/right edge
466 ::MoveWindow(GetHwnd(),
467 HasFlag(wxSL_LEFT) ? x : x + wLabel + HGAP,
468 y + hLabel/2,
469 width - wLabel - HGAP,
470 height - hLabel,
471 TRUE);
a23fd0e1 472 }
6181cef5 473 else // horizontal
2bda0e17 474 {
6181cef5
VZ
475 int wLabel;
476 int hLabel = GetLabelsSize(&wLabel);
477
478 int yLabel = HasFlag(wxSL_TOP) ? y + height - hLabel : y;
479
6181cef5
VZ
480 // position all labels: min on the left, value in the middle and max to
481 // the right
482 ::MoveWindow((*m_labels)[SliderLabel_Min],
483 x, yLabel, wLabel, hLabel, TRUE);
484
485 ::MoveWindow((*m_labels)[SliderLabel_Value],
486 x + (width - wLabel)/2, yLabel, wLabel, hLabel, TRUE);
487
488 ::MoveWindow((*m_labels)[SliderLabel_Max],
489 x + width - wLabel, yLabel, wLabel, hLabel, TRUE);
8a8dcc34
VZ
490
491 // position the slider itself along the top/bottom edge
492 ::MoveWindow(GetHwnd(),
493 x,
494 HasFlag(wxSL_TOP) ? y : y + hLabel,
495 width,
496 height - hLabel,
497 TRUE);
a23fd0e1 498 }
2bda0e17
KB
499}
500
7d0d80bd 501wxSize wxSlider::DoGetBestSize() const
7bdfb981 502{
6181cef5
VZ
503 // these values are arbitrary
504 static const int length = 100;
cbc6af74
VZ
505 static const int thumb = 24;
506 static const int ticks = 8;
57f4f925 507
cbc6af74 508 int *width;
6181cef5
VZ
509 wxSize size;
510 if ( HasFlag(wxSL_VERTICAL) )
7bdfb981 511 {
cbc6af74 512 size.x = thumb;
6181cef5 513 size.y = length;
cbc6af74 514 width = &size.x;
57f4f925 515
6181cef5 516 if ( m_labels )
7bdfb981 517 {
6181cef5
VZ
518 int wLabel;
519 int hLabel = GetLabelsSize(&wLabel);
7bdfb981 520
6181cef5
VZ
521 // account for the labels
522 size.x += HGAP + wLabel;
523
524 // labels are indented relative to the slider itself
525 size.y += hLabel;
7bdfb981
RD
526 }
527 }
6181cef5 528 else // horizontal
7bdfb981 529 {
6181cef5 530 size.x = length;
cbc6af74
VZ
531 size.y = thumb;
532 width = &size.y;
7bdfb981 533
6181cef5 534 if ( m_labels )
7bdfb981 535 {
6181cef5
VZ
536 // labels add extra height
537 size.y += GetLabelsSize();
7bdfb981
RD
538 }
539 }
6181cef5 540
cbc6af74
VZ
541 // need extra space to show ticks
542 if ( HasFlag(wxSL_TICKS) )
543 {
544 *width += ticks;
545
546 // and maybe twice as much if we show them on both sides
547 if ( HasFlag(wxSL_BOTH) )
548 *width += ticks;
549 }
550
6181cef5 551 return size;
7bdfb981
RD
552}
553
6181cef5
VZ
554// ----------------------------------------------------------------------------
555// slider-specific methods
556// ----------------------------------------------------------------------------
557
7d0d80bd 558int wxSlider::GetValue() const
6181cef5 559{
01526d4f 560 return ValueInvertOrNot(::SendMessage(GetHwnd(), TBM_GETPOS, 0, 0));
6181cef5
VZ
561}
562
7d0d80bd 563void wxSlider::SetValue(int value)
6181cef5 564{
01526d4f 565 ::SendMessage(GetHwnd(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)ValueInvertOrNot(value));
6181cef5
VZ
566
567 if ( m_labels )
568 {
569 ::SetWindowText((*m_labels)[SliderLabel_Value], Format(value));
570 }
571}
7bdfb981 572
7d0d80bd 573void wxSlider::SetRange(int minValue, int maxValue)
2bda0e17 574{
5f605ccf
VZ
575 m_rangeMin = minValue;
576 m_rangeMax = maxValue;
577
b552060a
WS
578 ::SendMessage(GetHwnd(), TBM_SETRANGEMIN, TRUE, m_rangeMin);
579 ::SendMessage(GetHwnd(), TBM_SETRANGEMAX, TRUE, m_rangeMax);
5f605ccf 580
6181cef5 581 if ( m_labels )
5f605ccf 582 {
01526d4f
WS
583 ::SetWindowText((*m_labels)[SliderLabel_Min], Format(ValueInvertOrNot(m_rangeMin)));
584 ::SetWindowText((*m_labels)[SliderLabel_Max], Format(ValueInvertOrNot(m_rangeMax)));
5f605ccf 585 }
2bda0e17
KB
586}
587
7d0d80bd 588void wxSlider::SetTickFreq(int n, int pos)
2bda0e17 589{
6181cef5
VZ
590 m_tickFreq = n;
591 ::SendMessage( GetHwnd(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos );
2bda0e17
KB
592}
593
7d0d80bd 594void wxSlider::SetPageSize(int pageSize)
2bda0e17 595{
6181cef5
VZ
596 ::SendMessage( GetHwnd(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize );
597 m_pageSize = pageSize;
2bda0e17
KB
598}
599
7d0d80bd 600int wxSlider::GetPageSize() const
2bda0e17 601{
6181cef5 602 return m_pageSize;
2bda0e17
KB
603}
604
7d0d80bd 605void wxSlider::ClearSel()
2bda0e17 606{
6181cef5 607 ::SendMessage(GetHwnd(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0);
2bda0e17
KB
608}
609
7d0d80bd 610void wxSlider::ClearTicks()
2bda0e17 611{
6181cef5 612 ::SendMessage(GetHwnd(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0);
2bda0e17
KB
613}
614
7d0d80bd 615void wxSlider::SetLineSize(int lineSize)
2bda0e17 616{
5f605ccf 617 m_lineSize = lineSize;
6181cef5 618 ::SendMessage(GetHwnd(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize);
2bda0e17
KB
619}
620
7d0d80bd 621int wxSlider::GetLineSize() const
2bda0e17 622{
6181cef5 623 return (int)::SendMessage(GetHwnd(), TBM_GETLINESIZE, 0, 0);
2bda0e17
KB
624}
625
7d0d80bd 626int wxSlider::GetSelEnd() const
2bda0e17 627{
6181cef5 628 return (int)::SendMessage(GetHwnd(), TBM_SETSELEND, 0, 0);
2bda0e17
KB
629}
630
7d0d80bd 631int wxSlider::GetSelStart() const
2bda0e17 632{
6181cef5 633 return (int)::SendMessage(GetHwnd(), TBM_GETSELSTART, 0, 0);
2bda0e17
KB
634}
635
7d0d80bd 636void wxSlider::SetSelection(int minPos, int maxPos)
2bda0e17 637{
5f605ccf 638 ::SendMessage(GetHwnd(), TBM_SETSEL,
6181cef5
VZ
639 (WPARAM) TRUE /* redraw */,
640 (LPARAM) MAKELONG( minPos, maxPos) );
2bda0e17
KB
641}
642
7d0d80bd 643void wxSlider::SetThumbLength(int len)
2bda0e17 644{
6181cef5 645 ::SendMessage(GetHwnd(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0);
2bda0e17
KB
646}
647
7d0d80bd 648int wxSlider::GetThumbLength() const
2bda0e17 649{
6bee5ffb 650 return (int)::SendMessage( GetHwnd(), TBM_GETTHUMBLENGTH, 0, 0);
2bda0e17
KB
651}
652
7d0d80bd 653void wxSlider::SetTick(int tickPos)
2bda0e17 654{
6bee5ffb 655 ::SendMessage( GetHwnd(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos );
2bda0e17
KB
656}
657
6181cef5
VZ
658// ----------------------------------------------------------------------------
659// composite control methods
660// ----------------------------------------------------------------------------
661
7d0d80bd 662WXHWND wxSlider::GetStaticMin() const
2bda0e17 663{
6181cef5 664 return m_labels ? (WXHWND)(*m_labels)[SliderLabel_Min] : NULL;
2bda0e17
KB
665}
666
7d0d80bd 667WXHWND wxSlider::GetStaticMax() const
2bda0e17 668{
6181cef5 669 return m_labels ? (WXHWND)(*m_labels)[SliderLabel_Max] : NULL;
2bda0e17
KB
670}
671
7d0d80bd 672WXHWND wxSlider::GetEditValue() const
2bda0e17 673{
6181cef5
VZ
674 return m_labels ? (WXHWND)(*m_labels)[SliderLabel_Value] : NULL;
675}
2bda0e17 676
7d0d80bd 677WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxSlider, wxSliderBase, m_labels)
8a8dcc34 678
1e6feb95 679#endif // wxUSE_SLIDER