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