]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
6181cef5 | 2 | // Name: msw/slider95.cpp |
da87a1ca | 3 | // Purpose: wxSlider95, using the Win95 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 | ||
49 | // indices of labels in wxSlider95::m_labels | |
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) | |
106 | ||
107 | wxEND_FLAGS( wxSliderStyle ) | |
bc9fb572 | 108 | |
f0a126fe SC |
109 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxSlider95, wxControl,"wx/scrolbar.h") |
110 | ||
3ff066a4 SC |
111 | wxBEGIN_PROPERTIES_TABLE(wxSlider95) |
112 | wxEVENT_RANGE_PROPERTY( Scroll , wxEVT_SCROLL_TOP , wxEVT_SCROLL_ENDSCROLL , wxScrollEvent ) | |
113 | wxEVENT_PROPERTY( Updated , wxEVT_COMMAND_SLIDER_UPDATED , wxCommandEvent ) | |
c5ca409b | 114 | |
3ff066a4 | 115 | wxPROPERTY( Value , int , SetValue, GetValue , 0, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
822e690b WS |
116 | wxPROPERTY( Minimum , int , SetMin, GetMin, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
117 | wxPROPERTY( Maximum , int , SetMax, GetMax, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
118 | wxPROPERTY( PageSize , int , SetPageSize, GetLineSize, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
119 | wxPROPERTY( LineSize , int , SetLineSize, GetLineSize, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
120 | wxPROPERTY( ThumbLength , int , SetThumbLength, GetThumbLength, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
af498247 | 121 | wxPROPERTY_FLAGS( WindowStyle , wxSliderStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
3ff066a4 | 122 | wxEND_PROPERTIES_TABLE() |
f0a126fe | 123 | |
3ff066a4 SC |
124 | wxBEGIN_HANDLERS_TABLE(wxSlider95) |
125 | wxEND_HANDLERS_TABLE() | |
f0a126fe | 126 | |
3ff066a4 | 127 | wxCONSTRUCTOR_8( wxSlider95 , wxWindow* , Parent , wxWindowID , Id , int , Value , int , Minimum , int , Maximum , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
f0a126fe | 128 | #else |
bf532053 | 129 | IMPLEMENT_DYNAMIC_CLASS(wxSlider95, wxControl) |
f0a126fe | 130 | #endif |
2bda0e17 | 131 | |
6181cef5 VZ |
132 | // ============================================================================ |
133 | // wxSlider95 implementation | |
134 | // ============================================================================ | |
135 | ||
136 | // ---------------------------------------------------------------------------- | |
137 | // construction | |
138 | // ---------------------------------------------------------------------------- | |
139 | ||
140 | void wxSlider95::Init() | |
2bda0e17 | 141 | { |
6181cef5 VZ |
142 | m_labels = NULL; |
143 | ||
5f605ccf VZ |
144 | m_pageSize = 1; |
145 | m_lineSize = 1; | |
146 | m_rangeMax = 0; | |
147 | m_rangeMin = 0; | |
148 | m_tickFreq = 0; | |
2bda0e17 KB |
149 | } |
150 | ||
6181cef5 VZ |
151 | bool |
152 | wxSlider95::Create(wxWindow *parent, | |
153 | wxWindowID id, | |
154 | int value, | |
155 | int minValue, | |
156 | int maxValue, | |
157 | const wxPoint& pos, | |
158 | const wxSize& size, | |
159 | long style, | |
160 | const wxValidator& validator, | |
161 | const wxString& name) | |
2bda0e17 | 162 | { |
6181cef5 VZ |
163 | // initialize everything |
164 | if ( !CreateControl(parent, id, pos, size, style, validator, name) ) | |
822e690b | 165 | return false; |
2bda0e17 | 166 | |
6181cef5 VZ |
167 | // ensure that we have correct values for GetLabelsSize() |
168 | m_rangeMin = minValue; | |
169 | m_rangeMax = maxValue; | |
5f605ccf | 170 | |
6181cef5 VZ |
171 | // create the labels first, so that our DoGetBestSize() could take them |
172 | // into account | |
173 | // | |
174 | // note that we could simply create 3 wxStaticTexts here but it could | |
175 | // result in some observable side effects at wx level (e.g. the parent of | |
176 | // wxSlider would have 3 more children than expected) and so we prefer not | |
177 | // to do it like this | |
5f605ccf VZ |
178 | if ( m_windowStyle & wxSL_LABELS ) |
179 | { | |
6181cef5 VZ |
180 | m_labels = new wxSubwindows(SliderLabel_Last); |
181 | ||
182 | HWND hwndParent = GetHwndOf(parent); | |
183 | for ( size_t n = 0; n < SliderLabel_Last; n++ ) | |
184 | { | |
185 | (*m_labels)[n] = ::CreateWindow | |
186 | ( | |
187 | wxT("STATIC"), | |
188 | NULL, | |
189 | WS_CHILD | WS_VISIBLE | SS_CENTER, | |
190 | 0, 0, 0, 0, | |
191 | hwndParent, | |
192 | (HMENU)NewControlId(), | |
193 | wxGetInstance(), | |
194 | NULL | |
195 | ); | |
196 | } | |
197 | ||
198 | m_labels->SetFont(GetFont()); | |
5f605ccf VZ |
199 | } |
200 | ||
6181cef5 VZ |
201 | // now create the main control too |
202 | if ( !MSWCreateControl(TRACKBAR_CLASS, wxEmptyString, pos, size) ) | |
203 | return false; | |
5f605ccf | 204 | |
6181cef5 VZ |
205 | // and initialize everything |
206 | SetRange(minValue, maxValue); | |
207 | SetValue(value); | |
208 | SetPageSize((maxValue - minValue)/10); | |
822e690b | 209 | |
6181cef5 VZ |
210 | return true; |
211 | } | |
2bda0e17 | 212 | |
6181cef5 VZ |
213 | WXDWORD wxSlider95::MSWGetStyle(long style, WXDWORD *exstyle) const |
214 | { | |
215 | WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle); | |
b0766406 | 216 | |
6181cef5 VZ |
217 | // TBS_HORZ is 0 anyhow, but do mention it explicitly for clarity |
218 | msStyle |= style & wxSL_VERTICAL ? TBS_VERT : TBS_HORZ; | |
219 | ||
220 | if ( style & wxSL_AUTOTICKS ) | |
5f605ccf | 221 | msStyle |= TBS_AUTOTICKS ; |
b0766406 | 222 | |
6181cef5 VZ |
223 | // again, TBS_RIGHT is 0 but do include it for clarity |
224 | if ( style & wxSL_LEFT ) | |
5f605ccf | 225 | msStyle |= TBS_LEFT; |
6181cef5 | 226 | else if ( style & wxSL_RIGHT ) |
5f605ccf | 227 | msStyle |= TBS_RIGHT; |
6181cef5 | 228 | else if ( style & wxSL_TOP ) |
5f605ccf | 229 | msStyle |= TBS_TOP; |
6181cef5 | 230 | else if ( style & wxSL_BOTTOM ) |
5f605ccf | 231 | msStyle |= TBS_BOTTOM; |
6181cef5 | 232 | else if ( style & wxSL_BOTH ) |
5f605ccf | 233 | msStyle |= TBS_BOTH; |
6181cef5 | 234 | else if ( !(style & wxSL_AUTOTICKS) ) |
5f605ccf | 235 | msStyle |= TBS_NOTICKS; |
2bda0e17 | 236 | |
6181cef5 | 237 | if ( style & wxSL_SELRANGE ) |
5f605ccf | 238 | msStyle |= TBS_ENABLESELRANGE; |
2bda0e17 | 239 | |
6181cef5 VZ |
240 | return msStyle; |
241 | } | |
7a5a5718 | 242 | |
6181cef5 VZ |
243 | wxSlider95::~wxSlider95() |
244 | { | |
245 | delete m_labels; | |
2bda0e17 KB |
246 | } |
247 | ||
6181cef5 VZ |
248 | // ---------------------------------------------------------------------------- |
249 | // event handling | |
250 | // ---------------------------------------------------------------------------- | |
251 | ||
252 | bool wxSlider95::MSWOnScroll(int WXUNUSED(orientation), | |
253 | WXWORD wParam, | |
254 | WXWORD WXUNUSED(pos), | |
255 | WXHWND control) | |
2bda0e17 | 256 | { |
1e6feb95 | 257 | wxEventType scrollEvent; |
2bda0e17 KB |
258 | switch ( wParam ) |
259 | { | |
a23fd0e1 | 260 | case SB_TOP: |
a23fd0e1 VZ |
261 | scrollEvent = wxEVT_SCROLL_TOP; |
262 | break; | |
263 | ||
264 | case SB_BOTTOM: | |
a23fd0e1 VZ |
265 | scrollEvent = wxEVT_SCROLL_BOTTOM; |
266 | break; | |
267 | ||
268 | case SB_LINEUP: | |
a23fd0e1 VZ |
269 | scrollEvent = wxEVT_SCROLL_LINEUP; |
270 | break; | |
271 | ||
272 | case SB_LINEDOWN: | |
a23fd0e1 VZ |
273 | scrollEvent = wxEVT_SCROLL_LINEDOWN; |
274 | break; | |
275 | ||
276 | case SB_PAGEUP: | |
a23fd0e1 VZ |
277 | scrollEvent = wxEVT_SCROLL_PAGEUP; |
278 | break; | |
279 | ||
280 | case SB_PAGEDOWN: | |
a23fd0e1 VZ |
281 | scrollEvent = wxEVT_SCROLL_PAGEDOWN; |
282 | break; | |
283 | ||
284 | case SB_THUMBTRACK: | |
a23fd0e1 VZ |
285 | scrollEvent = wxEVT_SCROLL_THUMBTRACK; |
286 | break; | |
287 | ||
e8b669d3 VZ |
288 | case SB_THUMBPOSITION: |
289 | scrollEvent = wxEVT_SCROLL_THUMBRELEASE; | |
290 | break; | |
291 | ||
292 | case SB_ENDSCROLL: | |
293 | scrollEvent = wxEVT_SCROLL_ENDSCROLL; | |
294 | break; | |
295 | ||
a23fd0e1 | 296 | default: |
1e6feb95 | 297 | // unknown scroll event? |
822e690b | 298 | return false; |
2bda0e17 KB |
299 | } |
300 | ||
5f605ccf | 301 | int newPos = (int) ::SendMessage((HWND) control, TBM_GETPOS, 0, 0); |
a23fd0e1 | 302 | if ( (newPos < GetMin()) || (newPos > GetMax()) ) |
2bda0e17 | 303 | { |
a23fd0e1 | 304 | // out of range - but we did process it |
822e690b | 305 | return true; |
a23fd0e1 | 306 | } |
2bda0e17 | 307 | |
a23fd0e1 | 308 | SetValue(newPos); |
2bda0e17 | 309 | |
a23fd0e1 VZ |
310 | wxScrollEvent event(scrollEvent, m_windowId); |
311 | event.SetPosition(newPos); | |
312 | event.SetEventObject( this ); | |
313 | GetEventHandler()->ProcessEvent(event); | |
f3a65071 | 314 | |
a23fd0e1 | 315 | wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() ); |
f6bcfd97 | 316 | cevent.SetInt( newPos ); |
a23fd0e1 | 317 | cevent.SetEventObject( this ); |
f3a65071 | 318 | |
a23fd0e1 | 319 | return GetEventHandler()->ProcessEvent( cevent ); |
2bda0e17 KB |
320 | } |
321 | ||
6181cef5 | 322 | void wxSlider95::Command (wxCommandEvent & event) |
2bda0e17 | 323 | { |
6181cef5 VZ |
324 | SetValue (event.GetInt()); |
325 | ProcessCommand (event); | |
2bda0e17 KB |
326 | } |
327 | ||
6181cef5 VZ |
328 | // ---------------------------------------------------------------------------- |
329 | // geometry stuff | |
330 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 331 | |
6181cef5 | 332 | wxRect wxSlider95::GetBoundingBox() const |
2bda0e17 | 333 | { |
6181cef5 VZ |
334 | // take care not to call our own functions which would call us recursively |
335 | int x, y, w, h; | |
336 | wxSliderBase::DoGetPosition(&x, &y); | |
337 | wxSliderBase::DoGetSize(&w, &h); | |
5f605ccf | 338 | |
6181cef5 VZ |
339 | wxRect rect(x, y, w, h); |
340 | if ( m_labels ) | |
341 | rect.Union(m_labels->GetBoundingBox()); | |
342 | ||
343 | return rect; | |
5f605ccf VZ |
344 | } |
345 | ||
346 | void wxSlider95::DoGetSize(int *width, int *height) const | |
2bda0e17 | 347 | { |
6181cef5 | 348 | wxRect rect = GetBoundingBox(); |
5f605ccf | 349 | |
6819fb9b | 350 | if ( width ) |
6181cef5 | 351 | *width = rect.width; |
6819fb9b | 352 | if ( height ) |
6181cef5 | 353 | *height = rect.height; |
2bda0e17 KB |
354 | } |
355 | ||
6181cef5 | 356 | void wxSlider95::DoGetPosition(int *x, int *y) const |
2bda0e17 | 357 | { |
6181cef5 | 358 | wxRect rect = GetBoundingBox(); |
5f605ccf | 359 | |
6181cef5 VZ |
360 | if ( x ) |
361 | *x = rect.x; | |
362 | if ( y ) | |
363 | *y = rect.y; | |
364 | } | |
5f605ccf | 365 | |
6181cef5 VZ |
366 | int wxSlider95::GetLabelsSize(int *width) const |
367 | { | |
368 | int cy; | |
5f605ccf | 369 | |
6181cef5 VZ |
370 | if ( width ) |
371 | { | |
372 | // find the max label width | |
373 | int wLabelMin, wLabelMax; | |
374 | GetTextExtent(Format(m_rangeMin), &wLabelMin, &cy); | |
375 | GetTextExtent(Format(m_rangeMax), &wLabelMax, &cy); | |
5f605ccf | 376 | |
6181cef5 VZ |
377 | *width = wxMax(wLabelMin, wLabelMax); |
378 | } | |
379 | else | |
5f605ccf | 380 | { |
6181cef5 | 381 | cy = GetCharHeight(); |
5f605ccf VZ |
382 | } |
383 | ||
6181cef5 | 384 | return EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); |
2bda0e17 KB |
385 | } |
386 | ||
6181cef5 | 387 | void wxSlider95::DoMoveWindow(int x, int y, int width, int height) |
2bda0e17 | 388 | { |
6181cef5 VZ |
389 | // all complications below are because we need to position the labels, |
390 | // without them everything is easy | |
391 | if ( !m_labels ) | |
392 | { | |
393 | wxSliderBase::DoMoveWindow(x, y, width, height); | |
394 | return; | |
395 | } | |
2bda0e17 | 396 | |
6181cef5 VZ |
397 | if ( HasFlag(wxSL_VERTICAL) ) |
398 | { | |
399 | int wLabel; | |
400 | int hLabel = GetLabelsSize(&wLabel); | |
81d66cf3 | 401 | |
6181cef5 | 402 | int xLabel = HasFlag(wxSL_LEFT) ? x + width - wLabel : x; |
2bda0e17 | 403 | |
6181cef5 VZ |
404 | // position the slider itself along the left/right edge |
405 | ::MoveWindow(GetHwnd(), | |
406 | HasFlag(wxSL_LEFT) ? x : x + wLabel + HGAP, | |
407 | y + hLabel/2, | |
408 | width - wLabel - HGAP, | |
409 | height - hLabel, | |
410 | TRUE); | |
2bda0e17 | 411 | |
6181cef5 VZ |
412 | // position all labels: min at the top, value in the middle and max at |
413 | // the bottom | |
414 | ::MoveWindow((*m_labels)[SliderLabel_Min], | |
415 | xLabel, y, wLabel, hLabel, TRUE); | |
2bda0e17 | 416 | |
6181cef5 VZ |
417 | ::MoveWindow((*m_labels)[SliderLabel_Value], |
418 | xLabel, y + (height - hLabel)/2, wLabel, hLabel, TRUE); | |
2bda0e17 | 419 | |
6181cef5 VZ |
420 | ::MoveWindow((*m_labels)[SliderLabel_Max], |
421 | xLabel, y + height - hLabel, wLabel, hLabel, TRUE); | |
a23fd0e1 | 422 | } |
6181cef5 | 423 | else // horizontal |
2bda0e17 | 424 | { |
6181cef5 VZ |
425 | int wLabel; |
426 | int hLabel = GetLabelsSize(&wLabel); | |
427 | ||
428 | int yLabel = HasFlag(wxSL_TOP) ? y + height - hLabel : y; | |
429 | ||
430 | // position the slider itself along the top/bottom edge | |
431 | ::MoveWindow(GetHwnd(), | |
432 | x, | |
433 | HasFlag(wxSL_TOP) ? y : y + hLabel, | |
434 | width, | |
435 | height - hLabel, | |
436 | TRUE); | |
437 | ||
438 | // position all labels: min on the left, value in the middle and max to | |
439 | // the right | |
440 | ::MoveWindow((*m_labels)[SliderLabel_Min], | |
441 | x, yLabel, wLabel, hLabel, TRUE); | |
442 | ||
443 | ::MoveWindow((*m_labels)[SliderLabel_Value], | |
444 | x + (width - wLabel)/2, yLabel, wLabel, hLabel, TRUE); | |
445 | ||
446 | ::MoveWindow((*m_labels)[SliderLabel_Max], | |
447 | x + width - wLabel, yLabel, wLabel, hLabel, TRUE); | |
a23fd0e1 | 448 | } |
2bda0e17 KB |
449 | } |
450 | ||
7bdfb981 RD |
451 | wxSize wxSlider95::DoGetBestSize() const |
452 | { | |
6181cef5 VZ |
453 | // these values are arbitrary |
454 | static const int length = 100; | |
455 | static const int thickness = 26; | |
57f4f925 | 456 | |
6181cef5 VZ |
457 | wxSize size; |
458 | if ( HasFlag(wxSL_VERTICAL) ) | |
7bdfb981 | 459 | { |
6181cef5 VZ |
460 | size.x = thickness; |
461 | size.y = length; | |
57f4f925 | 462 | |
6181cef5 | 463 | if ( m_labels ) |
7bdfb981 | 464 | { |
6181cef5 VZ |
465 | int wLabel; |
466 | int hLabel = GetLabelsSize(&wLabel); | |
7bdfb981 | 467 | |
6181cef5 VZ |
468 | // account for the labels |
469 | size.x += HGAP + wLabel; | |
470 | ||
471 | // labels are indented relative to the slider itself | |
472 | size.y += hLabel; | |
7bdfb981 RD |
473 | } |
474 | } | |
6181cef5 | 475 | else // horizontal |
7bdfb981 | 476 | { |
6181cef5 VZ |
477 | size.x = length; |
478 | size.y = thickness; | |
7bdfb981 | 479 | |
6181cef5 | 480 | if ( m_labels ) |
7bdfb981 | 481 | { |
6181cef5 VZ |
482 | // labels add extra height |
483 | size.y += GetLabelsSize(); | |
7bdfb981 RD |
484 | } |
485 | } | |
6181cef5 VZ |
486 | |
487 | return size; | |
7bdfb981 RD |
488 | } |
489 | ||
6181cef5 VZ |
490 | // ---------------------------------------------------------------------------- |
491 | // slider-specific methods | |
492 | // ---------------------------------------------------------------------------- | |
493 | ||
494 | int wxSlider95::GetValue() const | |
495 | { | |
496 | return ::SendMessage(GetHwnd(), TBM_GETPOS, 0, 0); | |
497 | } | |
498 | ||
499 | void wxSlider95::SetValue(int value) | |
500 | { | |
501 | ::SendMessage(GetHwnd(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value); | |
502 | ||
503 | if ( m_labels ) | |
504 | { | |
505 | ::SetWindowText((*m_labels)[SliderLabel_Value], Format(value)); | |
506 | } | |
507 | } | |
7bdfb981 | 508 | |
debe6624 | 509 | void wxSlider95::SetRange(int minValue, int maxValue) |
2bda0e17 | 510 | { |
5f605ccf VZ |
511 | m_rangeMin = minValue; |
512 | m_rangeMax = maxValue; | |
513 | ||
514 | ::SendMessage(GetHwnd(), TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue)); | |
515 | ||
6181cef5 | 516 | if ( m_labels ) |
5f605ccf | 517 | { |
6181cef5 VZ |
518 | ::SetWindowText((*m_labels)[SliderLabel_Min], Format(m_rangeMin)); |
519 | ::SetWindowText((*m_labels)[SliderLabel_Max], Format(m_rangeMax)); | |
5f605ccf | 520 | } |
2bda0e17 KB |
521 | } |
522 | ||
debe6624 | 523 | void wxSlider95::SetTickFreq(int n, int pos) |
2bda0e17 | 524 | { |
6181cef5 VZ |
525 | m_tickFreq = n; |
526 | ::SendMessage( GetHwnd(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos ); | |
2bda0e17 KB |
527 | } |
528 | ||
debe6624 | 529 | void wxSlider95::SetPageSize(int pageSize) |
2bda0e17 | 530 | { |
6181cef5 VZ |
531 | ::SendMessage( GetHwnd(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize ); |
532 | m_pageSize = pageSize; | |
2bda0e17 KB |
533 | } |
534 | ||
bfc6fde4 | 535 | int wxSlider95::GetPageSize() const |
2bda0e17 | 536 | { |
6181cef5 | 537 | return m_pageSize; |
2bda0e17 KB |
538 | } |
539 | ||
bfc6fde4 | 540 | void wxSlider95::ClearSel() |
2bda0e17 | 541 | { |
6181cef5 | 542 | ::SendMessage(GetHwnd(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0); |
2bda0e17 KB |
543 | } |
544 | ||
bfc6fde4 | 545 | void wxSlider95::ClearTicks() |
2bda0e17 | 546 | { |
6181cef5 | 547 | ::SendMessage(GetHwnd(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0); |
2bda0e17 KB |
548 | } |
549 | ||
debe6624 | 550 | void wxSlider95::SetLineSize(int lineSize) |
2bda0e17 | 551 | { |
5f605ccf | 552 | m_lineSize = lineSize; |
6181cef5 | 553 | ::SendMessage(GetHwnd(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize); |
2bda0e17 KB |
554 | } |
555 | ||
bfc6fde4 | 556 | int wxSlider95::GetLineSize() const |
2bda0e17 | 557 | { |
6181cef5 | 558 | return (int)::SendMessage(GetHwnd(), TBM_GETLINESIZE, 0, 0); |
2bda0e17 KB |
559 | } |
560 | ||
bfc6fde4 | 561 | int wxSlider95::GetSelEnd() const |
2bda0e17 | 562 | { |
6181cef5 | 563 | return (int)::SendMessage(GetHwnd(), TBM_SETSELEND, 0, 0); |
2bda0e17 KB |
564 | } |
565 | ||
bfc6fde4 | 566 | int wxSlider95::GetSelStart() const |
2bda0e17 | 567 | { |
6181cef5 | 568 | return (int)::SendMessage(GetHwnd(), TBM_GETSELSTART, 0, 0); |
2bda0e17 KB |
569 | } |
570 | ||
debe6624 | 571 | void wxSlider95::SetSelection(int minPos, int maxPos) |
2bda0e17 | 572 | { |
5f605ccf | 573 | ::SendMessage(GetHwnd(), TBM_SETSEL, |
6181cef5 VZ |
574 | (WPARAM) TRUE /* redraw */, |
575 | (LPARAM) MAKELONG( minPos, maxPos) ); | |
2bda0e17 KB |
576 | } |
577 | ||
debe6624 | 578 | void wxSlider95::SetThumbLength(int len) |
2bda0e17 | 579 | { |
6181cef5 | 580 | ::SendMessage(GetHwnd(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0); |
2bda0e17 KB |
581 | } |
582 | ||
bfc6fde4 | 583 | int wxSlider95::GetThumbLength() const |
2bda0e17 | 584 | { |
6181cef5 | 585 | return (int)::SendMessage( GetHwnd(), TBM_GETTHUMBLENGTH, 0, 0); |
2bda0e17 KB |
586 | } |
587 | ||
debe6624 | 588 | void wxSlider95::SetTick(int tickPos) |
2bda0e17 | 589 | { |
4438caf4 | 590 | ::SendMessage( GetHwnd(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos ); |
2bda0e17 KB |
591 | } |
592 | ||
6181cef5 VZ |
593 | // ---------------------------------------------------------------------------- |
594 | // composite control methods | |
595 | // ---------------------------------------------------------------------------- | |
596 | ||
597 | WXHWND wxSlider95::GetStaticMin() const | |
2bda0e17 | 598 | { |
6181cef5 | 599 | return m_labels ? (WXHWND)(*m_labels)[SliderLabel_Min] : NULL; |
2bda0e17 KB |
600 | } |
601 | ||
6181cef5 | 602 | WXHWND wxSlider95::GetStaticMax() const |
2bda0e17 | 603 | { |
6181cef5 | 604 | return m_labels ? (WXHWND)(*m_labels)[SliderLabel_Max] : NULL; |
2bda0e17 KB |
605 | } |
606 | ||
6181cef5 | 607 | WXHWND wxSlider95::GetEditValue() const |
2bda0e17 | 608 | { |
6181cef5 VZ |
609 | return m_labels ? (WXHWND)(*m_labels)[SliderLabel_Value] : NULL; |
610 | } | |
2bda0e17 | 611 | |
6181cef5 VZ |
612 | bool wxSlider95::ContainsHWND(WXHWND hWnd) const |
613 | { | |
614 | return m_labels && m_labels->HasWindow((HWND)hWnd); | |
615 | } | |
5f605ccf | 616 | |
6181cef5 VZ |
617 | bool wxSlider95::Show(bool show) |
618 | { | |
619 | if ( !wxSliderBase::Show(show) ) | |
620 | return false; | |
5f605ccf | 621 | |
6181cef5 VZ |
622 | if ( m_labels ) |
623 | m_labels->Show(show); | |
5f605ccf | 624 | |
822e690b | 625 | return true; |
2bda0e17 KB |
626 | } |
627 | ||
1e6feb95 | 628 | #endif // wxUSE_SLIDER |