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