]>
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 | ||
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 | ||
6181cef5 VZ |
45 | // ---------------------------------------------------------------------------- |
46 | // constants | |
47 | // ---------------------------------------------------------------------------- | |
48 | ||
7d0d80bd | 49 | // indices of labels in wxSlider::m_labels |
6181cef5 VZ |
50 | enum |
51 | { | |
52 | SliderLabel_Min, | |
53 | SliderLabel_Max, | |
54 | SliderLabel_Value, | |
55 | SliderLabel_Last | |
56 | }; | |
57 | ||
58 | // the gap between the slider and the labels, in pixels | |
59 | static const int HGAP = 5; | |
60 | ||
61 | // ---------------------------------------------------------------------------- | |
62 | // XTI | |
63 | // ---------------------------------------------------------------------------- | |
64 | ||
f0a126fe | 65 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
66 | WX_DEFINE_FLAGS( wxSliderStyle ) |
67 | ||
3ff066a4 | 68 | wxBEGIN_FLAGS( wxSliderStyle ) |
bc9fb572 JS |
69 | // new style border flags, we put them first to |
70 | // use them for streaming out | |
3ff066a4 SC |
71 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
72 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
73 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
74 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
75 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
76 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
57f4f925 | 77 | |
bc9fb572 | 78 | // old style border flags |
3ff066a4 SC |
79 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
80 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
81 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
82 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
83 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 84 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
85 | |
86 | // standard window styles | |
3ff066a4 SC |
87 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
88 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
89 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
90 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 91 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
92 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
93 | wxFLAGS_MEMBER(wxVSCROLL) | |
94 | wxFLAGS_MEMBER(wxHSCROLL) | |
95 | ||
96 | wxFLAGS_MEMBER(wxSL_HORIZONTAL) | |
97 | wxFLAGS_MEMBER(wxSL_VERTICAL) | |
98 | wxFLAGS_MEMBER(wxSL_AUTOTICKS) | |
99 | wxFLAGS_MEMBER(wxSL_LABELS) | |
100 | wxFLAGS_MEMBER(wxSL_LEFT) | |
101 | wxFLAGS_MEMBER(wxSL_TOP) | |
102 | wxFLAGS_MEMBER(wxSL_RIGHT) | |
103 | wxFLAGS_MEMBER(wxSL_BOTTOM) | |
104 | wxFLAGS_MEMBER(wxSL_BOTH) | |
105 | wxFLAGS_MEMBER(wxSL_SELRANGE) | |
6bee5ffb | 106 | wxFLAGS_MEMBER(wxSL_INVERSE) |
3ff066a4 SC |
107 | |
108 | wxEND_FLAGS( wxSliderStyle ) | |
bc9fb572 | 109 | |
7d0d80bd | 110 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxSlider, wxControl,"wx/scrolbar.h") |
f0a126fe | 111 | |
7d0d80bd | 112 | wxBEGIN_PROPERTIES_TABLE(wxSlider) |
cbc85508 | 113 | wxEVENT_RANGE_PROPERTY( Scroll , wxEVT_SCROLL_TOP , wxEVT_SCROLL_CHANGED , wxScrollEvent ) |
3ff066a4 | 114 | wxEVENT_PROPERTY( Updated , wxEVT_COMMAND_SLIDER_UPDATED , wxCommandEvent ) |
c5ca409b | 115 | |
3ff066a4 | 116 | wxPROPERTY( Value , int , SetValue, GetValue , 0, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
822e690b WS |
117 | wxPROPERTY( Minimum , int , SetMin, GetMin, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
118 | wxPROPERTY( Maximum , int , SetMax, GetMax, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
119 | wxPROPERTY( PageSize , int , SetPageSize, GetLineSize, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
120 | wxPROPERTY( LineSize , int , SetLineSize, GetLineSize, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
121 | wxPROPERTY( ThumbLength , int , SetThumbLength, GetThumbLength, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
af498247 | 122 | wxPROPERTY_FLAGS( WindowStyle , wxSliderStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
3ff066a4 | 123 | wxEND_PROPERTIES_TABLE() |
f0a126fe | 124 | |
7d0d80bd | 125 | wxBEGIN_HANDLERS_TABLE(wxSlider) |
3ff066a4 | 126 | wxEND_HANDLERS_TABLE() |
f0a126fe | 127 | |
7d0d80bd | 128 | wxCONSTRUCTOR_8( wxSlider , wxWindow* , Parent , wxWindowID , Id , int , Value , int , Minimum , int , Maximum , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
f0a126fe | 129 | #else |
7d0d80bd | 130 | IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) |
f0a126fe | 131 | #endif |
2bda0e17 | 132 | |
6181cef5 | 133 | // ============================================================================ |
7d0d80bd | 134 | // wxSlider implementation |
6181cef5 VZ |
135 | // ============================================================================ |
136 | ||
137 | // ---------------------------------------------------------------------------- | |
138 | // construction | |
139 | // ---------------------------------------------------------------------------- | |
140 | ||
7d0d80bd | 141 | void wxSlider::Init() |
2bda0e17 | 142 | { |
6181cef5 VZ |
143 | m_labels = NULL; |
144 | ||
5f605ccf VZ |
145 | m_pageSize = 1; |
146 | m_lineSize = 1; | |
147 | m_rangeMax = 0; | |
148 | m_rangeMin = 0; | |
149 | m_tickFreq = 0; | |
3c96417a VZ |
150 | |
151 | m_isDragging = false; | |
2bda0e17 KB |
152 | } |
153 | ||
6181cef5 | 154 | bool |
7d0d80bd WS |
155 | wxSlider::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 | 253 | WXDWORD 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 | 288 | wxSlider::~wxSlider() |
6181cef5 VZ |
289 | { |
290 | delete m_labels; | |
2bda0e17 KB |
291 | } |
292 | ||
6181cef5 VZ |
293 | // ---------------------------------------------------------------------------- |
294 | // event handling | |
295 | // ---------------------------------------------------------------------------- | |
296 | ||
7d0d80bd WS |
297 | bool 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 | 330 | scrollEvent = wxEVT_SCROLL_THUMBTRACK; |
3c96417a | 331 | m_isDragging = true; |
a23fd0e1 VZ |
332 | break; |
333 | ||
e8b669d3 | 334 | case SB_THUMBPOSITION: |
3c96417a VZ |
335 | if ( m_isDragging ) |
336 | { | |
337 | scrollEvent = wxEVT_SCROLL_THUMBRELEASE; | |
338 | m_isDragging = false; | |
339 | } | |
340 | else | |
341 | { | |
342 | // this seems to only happen when the mouse wheel is used: in | |
343 | // this case, as it might be unexpected to get THUMBRELEASE | |
344 | // without preceding THUMBTRACKs, we don't generate it at all | |
345 | // but generate CHANGED event because the control itself does | |
346 | // not send us SB_ENDSCROLL for whatever reason when mouse | |
347 | // wheel is used | |
348 | scrollEvent = wxEVT_SCROLL_CHANGED; | |
349 | } | |
e8b669d3 VZ |
350 | break; |
351 | ||
352 | case SB_ENDSCROLL: | |
cbc85508 | 353 | scrollEvent = wxEVT_SCROLL_CHANGED; |
e8b669d3 VZ |
354 | break; |
355 | ||
a23fd0e1 | 356 | default: |
1e6feb95 | 357 | // unknown scroll event? |
822e690b | 358 | return false; |
2bda0e17 KB |
359 | } |
360 | ||
01526d4f | 361 | int newPos = ValueInvertOrNot((int) ::SendMessage((HWND) control, TBM_GETPOS, 0, 0)); |
a23fd0e1 | 362 | if ( (newPos < GetMin()) || (newPos > GetMax()) ) |
2bda0e17 | 363 | { |
a23fd0e1 | 364 | // out of range - but we did process it |
822e690b | 365 | return true; |
a23fd0e1 | 366 | } |
2bda0e17 | 367 | |
a23fd0e1 | 368 | SetValue(newPos); |
2bda0e17 | 369 | |
a23fd0e1 VZ |
370 | wxScrollEvent event(scrollEvent, m_windowId); |
371 | event.SetPosition(newPos); | |
372 | event.SetEventObject( this ); | |
373 | GetEventHandler()->ProcessEvent(event); | |
f3a65071 | 374 | |
a23fd0e1 | 375 | wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() ); |
f6bcfd97 | 376 | cevent.SetInt( newPos ); |
a23fd0e1 | 377 | cevent.SetEventObject( this ); |
f3a65071 | 378 | |
a23fd0e1 | 379 | return GetEventHandler()->ProcessEvent( cevent ); |
2bda0e17 KB |
380 | } |
381 | ||
7d0d80bd | 382 | void wxSlider::Command (wxCommandEvent & event) |
2bda0e17 | 383 | { |
6181cef5 VZ |
384 | SetValue (event.GetInt()); |
385 | ProcessCommand (event); | |
2bda0e17 KB |
386 | } |
387 | ||
6181cef5 VZ |
388 | // ---------------------------------------------------------------------------- |
389 | // geometry stuff | |
390 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 391 | |
7d0d80bd | 392 | wxRect wxSlider::GetBoundingBox() const |
2bda0e17 | 393 | { |
6181cef5 VZ |
394 | // take care not to call our own functions which would call us recursively |
395 | int x, y, w, h; | |
396 | wxSliderBase::DoGetPosition(&x, &y); | |
397 | wxSliderBase::DoGetSize(&w, &h); | |
5f605ccf | 398 | |
6181cef5 VZ |
399 | wxRect rect(x, y, w, h); |
400 | if ( m_labels ) | |
b5c45059 RD |
401 | { |
402 | wxRect lrect = m_labels->GetBoundingBox(); | |
403 | GetParent()->ScreenToClient(&lrect.x, &lrect.y); | |
404 | rect.Union(lrect); | |
405 | } | |
6181cef5 VZ |
406 | |
407 | return rect; | |
5f605ccf VZ |
408 | } |
409 | ||
7d0d80bd | 410 | void wxSlider::DoGetSize(int *width, int *height) const |
2bda0e17 | 411 | { |
6181cef5 | 412 | wxRect rect = GetBoundingBox(); |
5f605ccf | 413 | |
6819fb9b | 414 | if ( width ) |
6181cef5 | 415 | *width = rect.width; |
6819fb9b | 416 | if ( height ) |
6181cef5 | 417 | *height = rect.height; |
2bda0e17 KB |
418 | } |
419 | ||
7d0d80bd | 420 | void wxSlider::DoGetPosition(int *x, int *y) const |
2bda0e17 | 421 | { |
6181cef5 | 422 | wxRect rect = GetBoundingBox(); |
5f605ccf | 423 | |
6181cef5 VZ |
424 | if ( x ) |
425 | *x = rect.x; | |
426 | if ( y ) | |
427 | *y = rect.y; | |
428 | } | |
5f605ccf | 429 | |
7d0d80bd | 430 | int wxSlider::GetLabelsSize(int *width) const |
6181cef5 VZ |
431 | { |
432 | int cy; | |
5f605ccf | 433 | |
6181cef5 VZ |
434 | if ( width ) |
435 | { | |
436 | // find the max label width | |
437 | int wLabelMin, wLabelMax; | |
438 | GetTextExtent(Format(m_rangeMin), &wLabelMin, &cy); | |
439 | GetTextExtent(Format(m_rangeMax), &wLabelMax, &cy); | |
5f605ccf | 440 | |
6181cef5 VZ |
441 | *width = wxMax(wLabelMin, wLabelMax); |
442 | } | |
443 | else | |
5f605ccf | 444 | { |
6181cef5 | 445 | cy = GetCharHeight(); |
5f605ccf VZ |
446 | } |
447 | ||
6181cef5 | 448 | return EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); |
2bda0e17 KB |
449 | } |
450 | ||
7d0d80bd | 451 | void wxSlider::DoMoveWindow(int x, int y, int width, int height) |
2bda0e17 | 452 | { |
6181cef5 VZ |
453 | // all complications below are because we need to position the labels, |
454 | // without them everything is easy | |
455 | if ( !m_labels ) | |
456 | { | |
457 | wxSliderBase::DoMoveWindow(x, y, width, height); | |
458 | return; | |
459 | } | |
2bda0e17 | 460 | |
8a8dcc34 VZ |
461 | // be careful to position the slider itself after moving the labels as |
462 | // otherwise our GetBoundingBox(), which is called from WM_SIZE handler, | |
463 | // would return a wrong result and wrong size would be cached internally | |
6181cef5 VZ |
464 | if ( HasFlag(wxSL_VERTICAL) ) |
465 | { | |
466 | int wLabel; | |
467 | int hLabel = GetLabelsSize(&wLabel); | |
81d66cf3 | 468 | |
6181cef5 | 469 | int xLabel = HasFlag(wxSL_LEFT) ? x + width - wLabel : x; |
2bda0e17 | 470 | |
6181cef5 VZ |
471 | // position all labels: min at the top, value in the middle and max at |
472 | // the bottom | |
7d86a2d4 | 473 | DoMoveSibling((HWND)(*m_labels)[SliderLabel_Min], |
8e44f3ca | 474 | xLabel, y, wLabel, hLabel); |
2bda0e17 | 475 | |
7d86a2d4 | 476 | DoMoveSibling((HWND)(*m_labels)[SliderLabel_Value], |
8e44f3ca | 477 | xLabel, y + (height - hLabel)/2, wLabel, hLabel); |
2bda0e17 | 478 | |
7d86a2d4 VZ |
479 | DoMoveSibling((HWND)(*m_labels)[SliderLabel_Max], |
480 | xLabel, y + height - hLabel, wLabel, hLabel); | |
8a8dcc34 VZ |
481 | |
482 | // position the slider itself along the left/right edge | |
7d86a2d4 VZ |
483 | wxSliderBase::DoMoveWindow(HasFlag(wxSL_LEFT) ? x : x + wLabel + HGAP, |
484 | y + hLabel/2, | |
485 | width - wLabel - HGAP, | |
486 | height - hLabel); | |
a23fd0e1 | 487 | } |
6181cef5 | 488 | else // horizontal |
2bda0e17 | 489 | { |
6181cef5 VZ |
490 | int wLabel; |
491 | int hLabel = GetLabelsSize(&wLabel); | |
492 | ||
493 | int yLabel = HasFlag(wxSL_TOP) ? y + height - hLabel : y; | |
494 | ||
6181cef5 VZ |
495 | // position all labels: min on the left, value in the middle and max to |
496 | // the right | |
7d86a2d4 VZ |
497 | DoMoveSibling((HWND)(*m_labels)[SliderLabel_Min], |
498 | x, yLabel, wLabel, hLabel); | |
6181cef5 | 499 | |
7d86a2d4 VZ |
500 | DoMoveSibling((HWND)(*m_labels)[SliderLabel_Value], |
501 | x + (width - wLabel)/2, yLabel, wLabel, hLabel); | |
6181cef5 | 502 | |
7d86a2d4 VZ |
503 | DoMoveSibling((HWND)(*m_labels)[SliderLabel_Max], |
504 | x + width - wLabel, yLabel, wLabel, hLabel); | |
8a8dcc34 VZ |
505 | |
506 | // position the slider itself along the top/bottom edge | |
7d86a2d4 VZ |
507 | wxSliderBase::DoMoveWindow(x, |
508 | HasFlag(wxSL_TOP) ? y : y + hLabel, | |
509 | width, | |
510 | height - hLabel); | |
8e44f3ca | 511 | } |
2bda0e17 KB |
512 | } |
513 | ||
7d0d80bd | 514 | wxSize wxSlider::DoGetBestSize() const |
7bdfb981 | 515 | { |
6181cef5 VZ |
516 | // these values are arbitrary |
517 | static const int length = 100; | |
cbc6af74 VZ |
518 | static const int thumb = 24; |
519 | static const int ticks = 8; | |
57f4f925 | 520 | |
cbc6af74 | 521 | int *width; |
6181cef5 VZ |
522 | wxSize size; |
523 | if ( HasFlag(wxSL_VERTICAL) ) | |
7bdfb981 | 524 | { |
cbc6af74 | 525 | size.x = thumb; |
6181cef5 | 526 | size.y = length; |
cbc6af74 | 527 | width = &size.x; |
57f4f925 | 528 | |
6181cef5 | 529 | if ( m_labels ) |
7bdfb981 | 530 | { |
6181cef5 VZ |
531 | int wLabel; |
532 | int hLabel = GetLabelsSize(&wLabel); | |
7bdfb981 | 533 | |
6181cef5 VZ |
534 | // account for the labels |
535 | size.x += HGAP + wLabel; | |
536 | ||
537 | // labels are indented relative to the slider itself | |
538 | size.y += hLabel; | |
7bdfb981 RD |
539 | } |
540 | } | |
6181cef5 | 541 | else // horizontal |
7bdfb981 | 542 | { |
6181cef5 | 543 | size.x = length; |
cbc6af74 VZ |
544 | size.y = thumb; |
545 | width = &size.y; | |
7bdfb981 | 546 | |
6181cef5 | 547 | if ( m_labels ) |
7bdfb981 | 548 | { |
6181cef5 VZ |
549 | // labels add extra height |
550 | size.y += GetLabelsSize(); | |
7bdfb981 RD |
551 | } |
552 | } | |
6181cef5 | 553 | |
cbc6af74 VZ |
554 | // need extra space to show ticks |
555 | if ( HasFlag(wxSL_TICKS) ) | |
556 | { | |
557 | *width += ticks; | |
558 | ||
559 | // and maybe twice as much if we show them on both sides | |
560 | if ( HasFlag(wxSL_BOTH) ) | |
561 | *width += ticks; | |
562 | } | |
563 | ||
6181cef5 | 564 | return size; |
7bdfb981 RD |
565 | } |
566 | ||
6181cef5 VZ |
567 | // ---------------------------------------------------------------------------- |
568 | // slider-specific methods | |
569 | // ---------------------------------------------------------------------------- | |
570 | ||
7d0d80bd | 571 | int wxSlider::GetValue() const |
6181cef5 | 572 | { |
01526d4f | 573 | return ValueInvertOrNot(::SendMessage(GetHwnd(), TBM_GETPOS, 0, 0)); |
6181cef5 VZ |
574 | } |
575 | ||
7d0d80bd | 576 | void wxSlider::SetValue(int value) |
6181cef5 | 577 | { |
01526d4f | 578 | ::SendMessage(GetHwnd(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)ValueInvertOrNot(value)); |
6181cef5 VZ |
579 | |
580 | if ( m_labels ) | |
581 | { | |
582 | ::SetWindowText((*m_labels)[SliderLabel_Value], Format(value)); | |
583 | } | |
584 | } | |
7bdfb981 | 585 | |
7d0d80bd | 586 | void wxSlider::SetRange(int minValue, int maxValue) |
2bda0e17 | 587 | { |
5f605ccf VZ |
588 | m_rangeMin = minValue; |
589 | m_rangeMax = maxValue; | |
590 | ||
b552060a WS |
591 | ::SendMessage(GetHwnd(), TBM_SETRANGEMIN, TRUE, m_rangeMin); |
592 | ::SendMessage(GetHwnd(), TBM_SETRANGEMAX, TRUE, m_rangeMax); | |
5f605ccf | 593 | |
6181cef5 | 594 | if ( m_labels ) |
5f605ccf | 595 | { |
01526d4f WS |
596 | ::SetWindowText((*m_labels)[SliderLabel_Min], Format(ValueInvertOrNot(m_rangeMin))); |
597 | ::SetWindowText((*m_labels)[SliderLabel_Max], Format(ValueInvertOrNot(m_rangeMax))); | |
5f605ccf | 598 | } |
2bda0e17 KB |
599 | } |
600 | ||
7d0d80bd | 601 | void wxSlider::SetTickFreq(int n, int pos) |
2bda0e17 | 602 | { |
6181cef5 VZ |
603 | m_tickFreq = n; |
604 | ::SendMessage( GetHwnd(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos ); | |
2bda0e17 KB |
605 | } |
606 | ||
7d0d80bd | 607 | void wxSlider::SetPageSize(int pageSize) |
2bda0e17 | 608 | { |
6181cef5 VZ |
609 | ::SendMessage( GetHwnd(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize ); |
610 | m_pageSize = pageSize; | |
2bda0e17 KB |
611 | } |
612 | ||
7d0d80bd | 613 | int wxSlider::GetPageSize() const |
2bda0e17 | 614 | { |
6181cef5 | 615 | return m_pageSize; |
2bda0e17 KB |
616 | } |
617 | ||
7d0d80bd | 618 | void wxSlider::ClearSel() |
2bda0e17 | 619 | { |
6181cef5 | 620 | ::SendMessage(GetHwnd(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0); |
2bda0e17 KB |
621 | } |
622 | ||
7d0d80bd | 623 | void wxSlider::ClearTicks() |
2bda0e17 | 624 | { |
6181cef5 | 625 | ::SendMessage(GetHwnd(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0); |
2bda0e17 KB |
626 | } |
627 | ||
7d0d80bd | 628 | void wxSlider::SetLineSize(int lineSize) |
2bda0e17 | 629 | { |
5f605ccf | 630 | m_lineSize = lineSize; |
6181cef5 | 631 | ::SendMessage(GetHwnd(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize); |
2bda0e17 KB |
632 | } |
633 | ||
7d0d80bd | 634 | int wxSlider::GetLineSize() const |
2bda0e17 | 635 | { |
6181cef5 | 636 | return (int)::SendMessage(GetHwnd(), TBM_GETLINESIZE, 0, 0); |
2bda0e17 KB |
637 | } |
638 | ||
7d0d80bd | 639 | int wxSlider::GetSelEnd() const |
2bda0e17 | 640 | { |
0a936028 | 641 | return (int)::SendMessage(GetHwnd(), TBM_GETSELEND, 0, 0); |
2bda0e17 KB |
642 | } |
643 | ||
7d0d80bd | 644 | int wxSlider::GetSelStart() const |
2bda0e17 | 645 | { |
6181cef5 | 646 | return (int)::SendMessage(GetHwnd(), TBM_GETSELSTART, 0, 0); |
2bda0e17 KB |
647 | } |
648 | ||
7d0d80bd | 649 | void wxSlider::SetSelection(int minPos, int maxPos) |
2bda0e17 | 650 | { |
5f605ccf | 651 | ::SendMessage(GetHwnd(), TBM_SETSEL, |
6181cef5 VZ |
652 | (WPARAM) TRUE /* redraw */, |
653 | (LPARAM) MAKELONG( minPos, maxPos) ); | |
2bda0e17 KB |
654 | } |
655 | ||
7d0d80bd | 656 | void wxSlider::SetThumbLength(int len) |
2bda0e17 | 657 | { |
6181cef5 | 658 | ::SendMessage(GetHwnd(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0); |
2bda0e17 KB |
659 | } |
660 | ||
7d0d80bd | 661 | int wxSlider::GetThumbLength() const |
2bda0e17 | 662 | { |
6bee5ffb | 663 | return (int)::SendMessage( GetHwnd(), TBM_GETTHUMBLENGTH, 0, 0); |
2bda0e17 KB |
664 | } |
665 | ||
7d0d80bd | 666 | void wxSlider::SetTick(int tickPos) |
2bda0e17 | 667 | { |
6bee5ffb | 668 | ::SendMessage( GetHwnd(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos ); |
2bda0e17 KB |
669 | } |
670 | ||
6181cef5 VZ |
671 | // ---------------------------------------------------------------------------- |
672 | // composite control methods | |
673 | // ---------------------------------------------------------------------------- | |
674 | ||
7d0d80bd | 675 | WXHWND wxSlider::GetStaticMin() const |
2bda0e17 | 676 | { |
6181cef5 | 677 | return m_labels ? (WXHWND)(*m_labels)[SliderLabel_Min] : NULL; |
2bda0e17 KB |
678 | } |
679 | ||
7d0d80bd | 680 | WXHWND wxSlider::GetStaticMax() const |
2bda0e17 | 681 | { |
6181cef5 | 682 | return m_labels ? (WXHWND)(*m_labels)[SliderLabel_Max] : NULL; |
2bda0e17 KB |
683 | } |
684 | ||
7d0d80bd | 685 | WXHWND wxSlider::GetEditValue() const |
2bda0e17 | 686 | { |
6181cef5 VZ |
687 | return m_labels ? (WXHWND)(*m_labels)[SliderLabel_Value] : NULL; |
688 | } | |
2bda0e17 | 689 | |
7d0d80bd | 690 | WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxSlider, wxSliderBase, m_labels) |
8a8dcc34 | 691 | |
1e6feb95 | 692 | #endif // wxUSE_SLIDER |