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