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