]> git.saurik.com Git - wxWidgets.git/blame - src/msw/slider.cpp
move SendSizeEvent() down to wxWindow from wxFrame; added SendSizeEventToParent(...
[wxWidgets.git] / src / msw / slider.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 {
52ca4ec4
VZ
211 wxWindowIDRef lblid = NewControlId();
212
213 HWND wnd = ::CreateWindow
214 (
215 wxT("STATIC"),
216 NULL,
217 WS_CHILD | WS_VISIBLE | SS_CENTER,
218 0, 0, 0, 0,
219 hwndParent,
dca0f651 220 (HMENU)wxUIntToPtr(lblid.GetValue()),
52ca4ec4
VZ
221 wxGetInstance(),
222 NULL
223 );
224
225 m_labels->Set(n, wnd, lblid);
6181cef5
VZ
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 328 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
3c96417a 329 m_isDragging = true;
a23fd0e1
VZ
330 break;
331
e8b669d3 332 case SB_THUMBPOSITION:
3c96417a
VZ
333 if ( m_isDragging )
334 {
335 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
336 m_isDragging = false;
337 }
338 else
339 {
340 // this seems to only happen when the mouse wheel is used: in
341 // this case, as it might be unexpected to get THUMBRELEASE
342 // without preceding THUMBTRACKs, we don't generate it at all
343 // but generate CHANGED event because the control itself does
344 // not send us SB_ENDSCROLL for whatever reason when mouse
345 // wheel is used
346 scrollEvent = wxEVT_SCROLL_CHANGED;
347 }
e8b669d3
VZ
348 break;
349
350 case SB_ENDSCROLL:
cbc85508 351 scrollEvent = wxEVT_SCROLL_CHANGED;
e8b669d3
VZ
352 break;
353
a23fd0e1 354 default:
1e6feb95 355 // unknown scroll event?
822e690b 356 return false;
2bda0e17
KB
357 }
358
01526d4f 359 int newPos = ValueInvertOrNot((int) ::SendMessage((HWND) control, TBM_GETPOS, 0, 0));
a23fd0e1 360 if ( (newPos < GetMin()) || (newPos > GetMax()) )
2bda0e17 361 {
a23fd0e1 362 // out of range - but we did process it
822e690b 363 return true;
a23fd0e1 364 }
2bda0e17 365
a23fd0e1 366 SetValue(newPos);
2bda0e17 367
a23fd0e1
VZ
368 wxScrollEvent event(scrollEvent, m_windowId);
369 event.SetPosition(newPos);
370 event.SetEventObject( this );
937013e0 371 HandleWindowEvent(event);
f3a65071 372
a23fd0e1 373 wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() );
f6bcfd97 374 cevent.SetInt( newPos );
a23fd0e1 375 cevent.SetEventObject( this );
f3a65071 376
937013e0 377 return HandleWindowEvent( cevent );
2bda0e17
KB
378}
379
7d0d80bd 380void wxSlider::Command (wxCommandEvent & event)
2bda0e17 381{
6181cef5
VZ
382 SetValue (event.GetInt());
383 ProcessCommand (event);
2bda0e17
KB
384}
385
6181cef5
VZ
386// ----------------------------------------------------------------------------
387// geometry stuff
388// ----------------------------------------------------------------------------
2bda0e17 389
7d0d80bd 390wxRect wxSlider::GetBoundingBox() const
2bda0e17 391{
6181cef5
VZ
392 // take care not to call our own functions which would call us recursively
393 int x, y, w, h;
394 wxSliderBase::DoGetPosition(&x, &y);
395 wxSliderBase::DoGetSize(&w, &h);
5f605ccf 396
6181cef5
VZ
397 wxRect rect(x, y, w, h);
398 if ( m_labels )
b5c45059
RD
399 {
400 wxRect lrect = m_labels->GetBoundingBox();
401 GetParent()->ScreenToClient(&lrect.x, &lrect.y);
402 rect.Union(lrect);
403 }
6181cef5
VZ
404
405 return rect;
5f605ccf
VZ
406}
407
7d0d80bd 408void wxSlider::DoGetSize(int *width, int *height) const
2bda0e17 409{
6181cef5 410 wxRect rect = GetBoundingBox();
5f605ccf 411
6819fb9b 412 if ( width )
6181cef5 413 *width = rect.width;
6819fb9b 414 if ( height )
6181cef5 415 *height = rect.height;
2bda0e17
KB
416}
417
7d0d80bd 418void wxSlider::DoGetPosition(int *x, int *y) const
2bda0e17 419{
6181cef5 420 wxRect rect = GetBoundingBox();
5f605ccf 421
6181cef5
VZ
422 if ( x )
423 *x = rect.x;
424 if ( y )
425 *y = rect.y;
426}
5f605ccf 427
7d0d80bd 428int wxSlider::GetLabelsSize(int *width) const
6181cef5
VZ
429{
430 int cy;
5f605ccf 431
6181cef5
VZ
432 if ( width )
433 {
434 // find the max label width
435 int wLabelMin, wLabelMax;
436 GetTextExtent(Format(m_rangeMin), &wLabelMin, &cy);
437 GetTextExtent(Format(m_rangeMax), &wLabelMax, &cy);
5f605ccf 438
6181cef5
VZ
439 *width = wxMax(wLabelMin, wLabelMax);
440 }
441 else
5f605ccf 442 {
6181cef5 443 cy = GetCharHeight();
5f605ccf
VZ
444 }
445
6181cef5 446 return EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
2bda0e17
KB
447}
448
7d0d80bd 449void wxSlider::DoMoveWindow(int x, int y, int width, int height)
2bda0e17 450{
6181cef5
VZ
451 // all complications below are because we need to position the labels,
452 // without them everything is easy
453 if ( !m_labels )
454 {
455 wxSliderBase::DoMoveWindow(x, y, width, height);
456 return;
457 }
2bda0e17 458
8a8dcc34
VZ
459 // be careful to position the slider itself after moving the labels as
460 // otherwise our GetBoundingBox(), which is called from WM_SIZE handler,
461 // would return a wrong result and wrong size would be cached internally
6181cef5
VZ
462 if ( HasFlag(wxSL_VERTICAL) )
463 {
464 int wLabel;
465 int hLabel = GetLabelsSize(&wLabel);
81d66cf3 466
6181cef5 467 int xLabel = HasFlag(wxSL_LEFT) ? x + width - wLabel : x;
2bda0e17 468
6181cef5
VZ
469 // position all labels: min at the top, value in the middle and max at
470 // the bottom
7d86a2d4 471 DoMoveSibling((HWND)(*m_labels)[SliderLabel_Min],
8e44f3ca 472 xLabel, y, wLabel, hLabel);
2bda0e17 473
7d86a2d4 474 DoMoveSibling((HWND)(*m_labels)[SliderLabel_Value],
8e44f3ca 475 xLabel, y + (height - hLabel)/2, wLabel, hLabel);
2bda0e17 476
7d86a2d4
VZ
477 DoMoveSibling((HWND)(*m_labels)[SliderLabel_Max],
478 xLabel, y + height - hLabel, wLabel, hLabel);
8a8dcc34
VZ
479
480 // position the slider itself along the left/right edge
7d86a2d4
VZ
481 wxSliderBase::DoMoveWindow(HasFlag(wxSL_LEFT) ? x : x + wLabel + HGAP,
482 y + hLabel/2,
483 width - wLabel - HGAP,
484 height - hLabel);
a23fd0e1 485 }
6181cef5 486 else // horizontal
2bda0e17 487 {
6181cef5
VZ
488 int wLabel;
489 int hLabel = GetLabelsSize(&wLabel);
490
491 int yLabel = HasFlag(wxSL_TOP) ? y + height - hLabel : y;
492
6181cef5
VZ
493 // position all labels: min on the left, value in the middle and max to
494 // the right
7d86a2d4
VZ
495 DoMoveSibling((HWND)(*m_labels)[SliderLabel_Min],
496 x, yLabel, wLabel, hLabel);
6181cef5 497
7d86a2d4
VZ
498 DoMoveSibling((HWND)(*m_labels)[SliderLabel_Value],
499 x + (width - wLabel)/2, yLabel, wLabel, hLabel);
6181cef5 500
7d86a2d4
VZ
501 DoMoveSibling((HWND)(*m_labels)[SliderLabel_Max],
502 x + width - wLabel, yLabel, wLabel, hLabel);
8a8dcc34
VZ
503
504 // position the slider itself along the top/bottom edge
7d86a2d4
VZ
505 wxSliderBase::DoMoveWindow(x,
506 HasFlag(wxSL_TOP) ? y : y + hLabel,
507 width,
508 height - hLabel);
8e44f3ca 509 }
2bda0e17
KB
510}
511
7d0d80bd 512wxSize wxSlider::DoGetBestSize() const
7bdfb981 513{
6181cef5
VZ
514 // these values are arbitrary
515 static const int length = 100;
cbc6af74
VZ
516 static const int thumb = 24;
517 static const int ticks = 8;
57f4f925 518
cbc6af74 519 int *width;
6181cef5
VZ
520 wxSize size;
521 if ( HasFlag(wxSL_VERTICAL) )
7bdfb981 522 {
cbc6af74 523 size.x = thumb;
6181cef5 524 size.y = length;
cbc6af74 525 width = &size.x;
57f4f925 526
6181cef5 527 if ( m_labels )
7bdfb981 528 {
6181cef5
VZ
529 int wLabel;
530 int hLabel = GetLabelsSize(&wLabel);
7bdfb981 531
6181cef5
VZ
532 // account for the labels
533 size.x += HGAP + wLabel;
534
535 // labels are indented relative to the slider itself
536 size.y += hLabel;
7bdfb981
RD
537 }
538 }
6181cef5 539 else // horizontal
7bdfb981 540 {
6181cef5 541 size.x = length;
cbc6af74
VZ
542 size.y = thumb;
543 width = &size.y;
7bdfb981 544
6181cef5 545 if ( m_labels )
7bdfb981 546 {
6181cef5
VZ
547 // labels add extra height
548 size.y += GetLabelsSize();
7bdfb981
RD
549 }
550 }
6181cef5 551
cbc6af74
VZ
552 // need extra space to show ticks
553 if ( HasFlag(wxSL_TICKS) )
554 {
555 *width += ticks;
556
557 // and maybe twice as much if we show them on both sides
558 if ( HasFlag(wxSL_BOTH) )
559 *width += ticks;
560 }
561
6181cef5 562 return size;
7bdfb981
RD
563}
564
6181cef5
VZ
565// ----------------------------------------------------------------------------
566// slider-specific methods
567// ----------------------------------------------------------------------------
568
7d0d80bd 569int wxSlider::GetValue() const
6181cef5 570{
01526d4f 571 return ValueInvertOrNot(::SendMessage(GetHwnd(), TBM_GETPOS, 0, 0));
6181cef5
VZ
572}
573
7d0d80bd 574void wxSlider::SetValue(int value)
6181cef5 575{
01526d4f 576 ::SendMessage(GetHwnd(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)ValueInvertOrNot(value));
6181cef5
VZ
577
578 if ( m_labels )
579 {
e0a050e3 580 ::SetWindowText((*m_labels)[SliderLabel_Value], Format(value).wx_str());
6181cef5
VZ
581 }
582}
7bdfb981 583
7d0d80bd 584void wxSlider::SetRange(int minValue, int maxValue)
2bda0e17 585{
5f605ccf
VZ
586 m_rangeMin = minValue;
587 m_rangeMax = maxValue;
588
b552060a
WS
589 ::SendMessage(GetHwnd(), TBM_SETRANGEMIN, TRUE, m_rangeMin);
590 ::SendMessage(GetHwnd(), TBM_SETRANGEMAX, TRUE, m_rangeMax);
5f605ccf 591
6181cef5 592 if ( m_labels )
5f605ccf 593 {
e0a050e3
VS
594 ::SetWindowText((*m_labels)[SliderLabel_Min],
595 Format(ValueInvertOrNot(m_rangeMin)).wx_str());
596 ::SetWindowText((*m_labels)[SliderLabel_Max],
597 Format(ValueInvertOrNot(m_rangeMax)).wx_str());
5f605ccf 598 }
2bda0e17
KB
599}
600
7d0d80bd 601void wxSlider::SetTickFreq(int n, int pos)
2bda0e17 602{
6181cef5
VZ
603 m_tickFreq = n;
604 ::SendMessage( GetHwnd(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos );
2bda0e17
KB
605}
606
7d0d80bd 607void wxSlider::SetPageSize(int pageSize)
2bda0e17 608{
6181cef5
VZ
609 ::SendMessage( GetHwnd(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize );
610 m_pageSize = pageSize;
2bda0e17
KB
611}
612
7d0d80bd 613int wxSlider::GetPageSize() const
2bda0e17 614{
6181cef5 615 return m_pageSize;
2bda0e17
KB
616}
617
7d0d80bd 618void wxSlider::ClearSel()
2bda0e17 619{
6181cef5 620 ::SendMessage(GetHwnd(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0);
2bda0e17
KB
621}
622
7d0d80bd 623void wxSlider::ClearTicks()
2bda0e17 624{
6181cef5 625 ::SendMessage(GetHwnd(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0);
2bda0e17
KB
626}
627
7d0d80bd 628void wxSlider::SetLineSize(int lineSize)
2bda0e17 629{
5f605ccf 630 m_lineSize = lineSize;
6181cef5 631 ::SendMessage(GetHwnd(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize);
2bda0e17
KB
632}
633
7d0d80bd 634int wxSlider::GetLineSize() const
2bda0e17 635{
6181cef5 636 return (int)::SendMessage(GetHwnd(), TBM_GETLINESIZE, 0, 0);
2bda0e17
KB
637}
638
7d0d80bd 639int wxSlider::GetSelEnd() const
2bda0e17 640{
0a936028 641 return (int)::SendMessage(GetHwnd(), TBM_GETSELEND, 0, 0);
2bda0e17
KB
642}
643
7d0d80bd 644int wxSlider::GetSelStart() const
2bda0e17 645{
6181cef5 646 return (int)::SendMessage(GetHwnd(), TBM_GETSELSTART, 0, 0);
2bda0e17
KB
647}
648
7d0d80bd 649void wxSlider::SetSelection(int minPos, int maxPos)
2bda0e17 650{
5f605ccf 651 ::SendMessage(GetHwnd(), TBM_SETSEL,
6181cef5
VZ
652 (WPARAM) TRUE /* redraw */,
653 (LPARAM) MAKELONG( minPos, maxPos) );
2bda0e17
KB
654}
655
7d0d80bd 656void wxSlider::SetThumbLength(int len)
2bda0e17 657{
6181cef5 658 ::SendMessage(GetHwnd(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0);
2bda0e17
KB
659}
660
7d0d80bd 661int wxSlider::GetThumbLength() const
2bda0e17 662{
6bee5ffb 663 return (int)::SendMessage( GetHwnd(), TBM_GETTHUMBLENGTH, 0, 0);
2bda0e17
KB
664}
665
7d0d80bd 666void wxSlider::SetTick(int tickPos)
2bda0e17 667{
6bee5ffb 668 ::SendMessage( GetHwnd(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos );
2bda0e17
KB
669}
670
6181cef5
VZ
671// ----------------------------------------------------------------------------
672// composite control methods
673// ----------------------------------------------------------------------------
674
7d0d80bd 675WXHWND wxSlider::GetStaticMin() const
2bda0e17 676{
6181cef5 677 return m_labels ? (WXHWND)(*m_labels)[SliderLabel_Min] : NULL;
2bda0e17
KB
678}
679
7d0d80bd 680WXHWND wxSlider::GetStaticMax() const
2bda0e17 681{
6181cef5 682 return m_labels ? (WXHWND)(*m_labels)[SliderLabel_Max] : NULL;
2bda0e17
KB
683}
684
7d0d80bd 685WXHWND wxSlider::GetEditValue() const
2bda0e17 686{
6181cef5
VZ
687 return m_labels ? (WXHWND)(*m_labels)[SliderLabel_Value] : NULL;
688}
2bda0e17 689
7d0d80bd 690WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxSlider, wxSliderBase, m_labels)
8a8dcc34 691
1e6feb95 692#endif // wxUSE_SLIDER