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