]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: slider.cpp | |
3 | // Purpose: wxSlider | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "slider.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include <stdio.h> | |
25 | #include "wx/slider.h" | |
26 | #endif | |
27 | ||
28 | #include "wx/msw/private.h" | |
29 | ||
30 | // Can opt to not use track bar under Win95 if you prefer it - set to 0 | |
31 | #define USE_TRACK_BAR 1 | |
32 | ||
33 | #if defined(__WIN95__) && !defined(__GNUWIN32__) | |
34 | #include <commctrl.h> | |
35 | #endif | |
36 | ||
37 | #if !USE_SHARED_LIBRARY | |
38 | IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) | |
39 | ||
40 | #if WXWIN_COMPATIBILITY | |
41 | BEGIN_EVENT_TABLE(wxSlider, wxControl) | |
42 | EVT_SCROLL(wxSlider::OnScroll) | |
43 | END_EVENT_TABLE() | |
44 | #endif | |
45 | ||
46 | #endif | |
47 | ||
48 | // Slider | |
49 | wxSlider::wxSlider(void) | |
50 | { | |
51 | m_staticValue = 0; | |
52 | m_staticMin = 0; | |
53 | m_staticMax = 0; | |
54 | m_pageSize = 1; | |
55 | m_lineSize = 1; | |
56 | m_rangeMax = 0; | |
57 | m_rangeMin = 0; | |
58 | m_tickFreq = 0; | |
59 | } | |
60 | ||
61 | bool wxSlider::Create(wxWindow *parent, const wxWindowID id, | |
62 | const int value, const int minValue, const int maxValue, | |
63 | const wxPoint& pos, | |
64 | const wxSize& size, const long style, | |
65 | const wxValidator& validator, | |
66 | const wxString& name) | |
67 | { | |
68 | SetName(name); | |
69 | SetValidator(validator); | |
70 | ||
71 | if (parent) parent->AddChild(this); | |
72 | SetBackgroundColour(parent->GetDefaultBackgroundColour()) ; | |
73 | SetForegroundColour(parent->GetDefaultForegroundColour()) ; | |
74 | ||
75 | m_staticValue = 0; | |
76 | m_staticMin = 0; | |
77 | m_staticMax = 0; | |
78 | m_pageSize = 1; | |
79 | m_lineSize = 1; | |
80 | m_windowStyle = style; | |
81 | m_tickFreq = 0; | |
82 | ||
83 | if ( id == -1 ) | |
84 | m_windowId = (int)NewControlId(); | |
85 | else | |
86 | m_windowId = id; | |
87 | ||
88 | int x = pos.x; | |
89 | int y = pos.y; | |
90 | int width = size.x; | |
91 | int height = size.y; | |
92 | ||
93 | #if defined(__WIN95__) && USE_TRACK_BAR | |
94 | long msStyle ; | |
95 | ||
96 | if ( m_windowStyle & wxSL_LABELS ) | |
97 | { | |
98 | msStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTER; | |
99 | ||
100 | bool want3D; | |
101 | WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ; | |
102 | ||
103 | m_staticValue = (WXHWND) CreateWindowEx(exStyle, "STATIC", NULL, | |
104 | msStyle, | |
105 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), | |
106 | wxGetInstance(), NULL); | |
107 | ||
108 | // Now create min static control | |
109 | sprintf(wxBuffer, "%d", minValue); | |
110 | m_staticMin = (WXHWND) CreateWindowEx(0, "STATIC", wxBuffer, | |
111 | STATIC_FLAGS, | |
112 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), | |
113 | wxGetInstance(), NULL); | |
114 | } | |
115 | ||
116 | msStyle = 0; | |
117 | if (m_windowStyle & wxSL_VERTICAL) | |
118 | msStyle = TBS_VERT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; | |
119 | else | |
120 | msStyle = TBS_HORZ | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; | |
121 | ||
122 | if ( m_windowStyle & wxSL_AUTOTICKS ) | |
123 | msStyle |= TBS_AUTOTICKS ; | |
124 | ||
125 | if ( m_windowStyle & wxSL_LEFT ) | |
126 | msStyle |= TBS_LEFT; | |
127 | else if ( m_windowStyle & wxSL_RIGHT ) | |
128 | msStyle |= TBS_RIGHT; | |
129 | else if ( m_windowStyle & wxSL_TOP ) | |
130 | msStyle |= TBS_TOP; | |
131 | else if ( m_windowStyle & wxSL_BOTTOM ) | |
132 | msStyle |= TBS_BOTTOM; | |
133 | else if ( m_windowStyle & wxSL_BOTH ) | |
134 | msStyle |= TBS_BOTH; | |
135 | else if ( ! (m_windowStyle & wxSL_AUTOTICKS) ) | |
136 | msStyle |= TBS_NOTICKS; | |
137 | ||
138 | if ( m_windowStyle & wxSL_SELRANGE ) | |
139 | msStyle |= TBS_ENABLESELRANGE ; | |
140 | ||
141 | HWND scroll_bar = CreateWindowEx(MakeExtendedStyle(m_windowStyle), TRACKBAR_CLASS, wxBuffer, | |
142 | msStyle, | |
143 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, | |
144 | wxGetInstance(), NULL); | |
145 | ||
146 | m_rangeMax = maxValue; | |
147 | m_rangeMin = minValue; | |
148 | ||
149 | m_pageSize = (int)((maxValue-minValue)/10); | |
150 | ||
151 | ::SendMessage(scroll_bar, TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue)); | |
152 | ::SendMessage(scroll_bar, TBM_SETPOS, TRUE, (LPARAM)value); | |
153 | ::SendMessage(scroll_bar, TBM_SETPAGESIZE, 0, (LPARAM)m_pageSize); | |
154 | ||
155 | m_hWnd = (WXHWND)scroll_bar; | |
156 | ||
157 | SubclassWin(GetHWND()); | |
158 | ||
159 | if ( m_windowStyle & wxSL_LABELS ) | |
160 | { | |
161 | // Finally, create max value static item | |
162 | sprintf(wxBuffer, "%d", maxValue); | |
163 | m_staticMax = (WXHWND) CreateWindowEx(0, "STATIC", wxBuffer, | |
164 | STATIC_FLAGS, | |
165 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), | |
166 | wxGetInstance(), NULL); | |
167 | ||
168 | SetFont(parent->GetFont()); | |
169 | ||
170 | if (GetFont()) | |
171 | { | |
172 | // GetFont()->RealizeResource(); | |
173 | if (GetFont()->GetResourceHandle()) | |
174 | { | |
175 | if ( m_staticMin ) | |
176 | SendMessage((HWND)m_staticMin,WM_SETFONT, | |
177 | (WPARAM)GetFont()->GetResourceHandle(),0L); | |
178 | if ( m_staticMax ) | |
179 | SendMessage((HWND)m_staticMax,WM_SETFONT, | |
180 | (WPARAM)GetFont()->GetResourceHandle(),0L); | |
181 | if (m_staticValue) | |
182 | SendMessage((HWND)m_staticValue,WM_SETFONT, | |
183 | (WPARAM)GetFont()->GetResourceHandle(),0L); | |
184 | } | |
185 | } | |
186 | } | |
187 | #else | |
188 | // non-Win95 implementation | |
189 | ||
190 | long msStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTER; | |
191 | ||
192 | bool want3D; | |
193 | WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ; | |
194 | ||
195 | m_staticValue = (WXHWND) CreateWindowEx(exStyle, "STATIC", NULL, | |
196 | msStyle, | |
197 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), | |
198 | wxGetInstance(), NULL); | |
199 | ||
200 | // Now create min static control | |
201 | sprintf(wxBuffer, "%d", minValue); | |
202 | m_staticMin = (WXHWND) CreateWindowEx(0, "STATIC", wxBuffer, | |
203 | STATIC_FLAGS, | |
204 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), | |
205 | wxGetInstance(), NULL); | |
206 | ||
207 | // Now create slider | |
208 | m_windowId = (int)NewControlId(); | |
209 | ||
210 | msStyle = 0; | |
211 | if (m_windowStyle & wxSL_VERTICAL) | |
212 | msStyle = SBS_VERT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; | |
213 | else | |
214 | msStyle = SBS_HORZ | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; | |
215 | ||
216 | HWND scroll_bar = CreateWindowEx(MakeExtendedStyle(m_windowStyle), "SCROLLBAR", wxBuffer, | |
217 | msStyle, | |
218 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, | |
219 | wxGetInstance(), NULL); | |
220 | ||
221 | m_pageSize = (int)((maxValue-minValue)/10); | |
222 | m_rangeMax = maxValue; | |
223 | m_rangeMin = minValue; | |
224 | ||
225 | ::SetScrollRange(scroll_bar, SB_CTL, minValue, maxValue, FALSE); | |
226 | ::SetScrollPos(scroll_bar, SB_CTL, value, FALSE); | |
227 | ShowWindow(scroll_bar, SW_SHOW); | |
228 | ||
229 | m_hWnd = (WXHWND)scroll_bar; | |
230 | ||
231 | // Subclass again for purposes of dialog editing mode | |
232 | SubclassWin(GetHWND()); | |
233 | ||
234 | // Finally, create max value static item | |
235 | sprintf(wxBuffer, "%d", maxValue); | |
236 | m_staticMax = (WXHWND) CreateWindowEx(0, "STATIC", wxBuffer, | |
237 | STATIC_FLAGS, | |
238 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), | |
239 | wxGetInstance(), NULL); | |
240 | ||
241 | SetFont(* parent->GetFont()); | |
242 | ||
243 | if (GetFont()) | |
244 | { | |
245 | // GetFont()->RealizeResource(); | |
246 | if (GetFont()->GetResourceHandle()) | |
247 | { | |
248 | if ( m_staticMin ) | |
249 | SendMessage((HWND)m_staticMin,WM_SETFONT, | |
250 | (WPARAM)GetFont()->GetResourceHandle(),0L); | |
251 | if ( m_staticMax ) | |
252 | SendMessage((HWND)m_staticMax,WM_SETFONT, | |
253 | (WPARAM)GetFont()->GetResourceHandle(),0L); | |
254 | if (m_staticValue) | |
255 | SendMessage((HWND)m_staticValue,WM_SETFONT, | |
256 | (WPARAM)GetFont()->GetResourceHandle(),0L); | |
257 | } | |
258 | } | |
259 | #endif | |
260 | ||
261 | SetSize(x, y, width, height); | |
262 | SetValue(value); | |
263 | ||
264 | return TRUE; | |
265 | } | |
266 | ||
267 | void wxSlider::MSWOnVScroll(const WXWORD wParam, const WXWORD pos, const WXHWND control) | |
268 | { | |
269 | #if defined(__WIN95__) && USE_TRACK_BAR | |
270 | int position = 0; // Dummy - not used in this mode | |
271 | #else | |
272 | int position = ::GetScrollPos((HWND)control, SB_CTL); | |
273 | #endif | |
274 | ||
275 | int nScrollInc; | |
276 | int scrollEvent = 0; | |
277 | switch ( wParam ) | |
278 | { | |
279 | case SB_TOP: | |
280 | nScrollInc = m_rangeMax - position; | |
281 | scrollEvent = wxEVT_SCROLL_TOP; | |
282 | break; | |
283 | ||
284 | case SB_BOTTOM: | |
285 | nScrollInc = - position; | |
286 | scrollEvent = wxEVT_SCROLL_BOTTOM; | |
287 | break; | |
288 | ||
289 | case SB_LINEUP: | |
290 | nScrollInc = - GetLineSize(); | |
291 | scrollEvent = wxEVT_SCROLL_LINEUP; | |
292 | break; | |
293 | ||
294 | case SB_LINEDOWN: | |
295 | nScrollInc = GetLineSize(); | |
296 | scrollEvent = wxEVT_SCROLL_LINEDOWN; | |
297 | break; | |
298 | ||
299 | case SB_PAGEUP: | |
300 | nScrollInc = -GetPageSize(); | |
301 | scrollEvent = wxEVT_SCROLL_PAGEUP; | |
302 | break; | |
303 | ||
304 | case SB_PAGEDOWN: | |
305 | nScrollInc = GetPageSize(); | |
306 | scrollEvent = wxEVT_SCROLL_PAGEDOWN; | |
307 | break; | |
308 | ||
309 | case SB_THUMBTRACK: | |
310 | case SB_THUMBPOSITION: | |
311 | #ifdef __WIN32__ | |
312 | nScrollInc = (signed short)pos - position; | |
313 | #else | |
314 | nScrollInc = pos - position; | |
315 | #endif | |
316 | scrollEvent = wxEVT_SCROLL_THUMBTRACK; | |
317 | break; | |
318 | ||
319 | default: | |
320 | nScrollInc = 0; | |
321 | return; | |
322 | } | |
323 | ||
324 | #if !(WIN95 && USE_TRACK_BAR) | |
325 | if (nScrollInc != 0) | |
326 | #endif | |
327 | { | |
328 | ||
329 | #if defined(__WIN95__) && USE_TRACK_BAR | |
330 | int newPos = (int)::SendMessage((HWND) control, TBM_GETPOS, 0, 0); | |
331 | #else | |
332 | int newPos = position + nScrollInc; | |
333 | #endif | |
334 | if (!(newPos < GetMin() || newPos > GetMax())) | |
335 | { | |
336 | SetValue(newPos); | |
337 | ||
338 | wxScrollEvent event(scrollEvent, m_windowId); | |
339 | event.SetPosition(newPos); | |
340 | event.SetEventObject( this ); | |
341 | GetEventHandler()->ProcessEvent(event); | |
342 | } | |
343 | } | |
344 | } | |
345 | ||
346 | void wxSlider::MSWOnHScroll(const WXWORD wParam, const WXWORD pos, const WXHWND control) | |
347 | { | |
348 | MSWOnVScroll(wParam, pos, control); | |
349 | } | |
350 | ||
351 | wxSlider::~wxSlider(void) | |
352 | { | |
353 | if (m_staticMin) | |
354 | DestroyWindow((HWND) m_staticMin); | |
355 | if (m_staticMax) | |
356 | DestroyWindow((HWND) m_staticMax); | |
357 | if (m_staticValue) | |
358 | DestroyWindow((HWND) m_staticValue); | |
359 | } | |
360 | ||
361 | int wxSlider::GetValue(void) const | |
362 | { | |
363 | #if defined(__WIN95__) && USE_TRACK_BAR | |
364 | return ::SendMessage((HWND) GetHWND(), TBM_GETPOS, 0, 0); | |
365 | #else | |
366 | return ::GetScrollPos((HWND) GetHWND(), SB_CTL); | |
367 | #endif | |
368 | } | |
369 | ||
370 | void wxSlider::SetValue(const int value) | |
371 | { | |
372 | #if defined(__WIN95__) && USE_TRACK_BAR | |
373 | ::SendMessage((HWND) GetHWND(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value); | |
374 | #else | |
375 | ::SetScrollPos((HWND) GetHWND(), SB_CTL, value, TRUE); | |
376 | #endif | |
377 | if (m_staticValue) | |
378 | { | |
379 | sprintf(wxBuffer, "%d", value); | |
380 | SetWindowText((HWND) m_staticValue, wxBuffer); | |
381 | } | |
382 | } | |
383 | ||
384 | void wxSlider::GetSize(int *width, int *height) const | |
385 | { | |
386 | RECT rect; | |
387 | rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1; | |
388 | ||
389 | wxFindMaxSize(GetHWND(), &rect); | |
390 | ||
391 | if (m_staticMin) | |
392 | wxFindMaxSize(m_staticMin, &rect); | |
393 | if (m_staticMax) | |
394 | wxFindMaxSize(m_staticMax, &rect); | |
395 | if (m_staticValue) | |
396 | wxFindMaxSize(m_staticValue, &rect); | |
397 | ||
398 | *width = rect.right - rect.left; | |
399 | *height = rect.bottom - rect.top; | |
400 | } | |
401 | ||
402 | void wxSlider::GetPosition(int *x, int *y) const | |
403 | { | |
404 | wxWindow *parent = GetParent(); | |
405 | RECT rect; | |
406 | rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1; | |
407 | ||
408 | wxFindMaxSize(GetHWND(), &rect); | |
409 | ||
410 | if (m_staticMin) | |
411 | wxFindMaxSize(m_staticMin, &rect); | |
412 | if (m_staticMax) | |
413 | wxFindMaxSize(m_staticMax, &rect); | |
414 | if (m_staticValue) | |
415 | wxFindMaxSize(m_staticValue, &rect); | |
416 | ||
417 | // Since we now have the absolute screen coords, | |
418 | // if there's a parent we must subtract its top left corner | |
419 | POINT point; | |
420 | point.x = rect.left; | |
421 | point.y = rect.top; | |
422 | if (parent) | |
423 | ::ScreenToClient((HWND) parent->GetHWND(), &point); | |
424 | ||
425 | *x = point.x; | |
426 | *y = point.y; | |
427 | } | |
428 | ||
429 | void wxSlider::SetSize(const int x, const int y, const int width, const int height, const int sizeFlags) | |
430 | { | |
431 | int x1 = x; | |
432 | int y1 = y; | |
433 | int w1 = width; | |
434 | int h1 = height; | |
435 | ||
436 | int currentX, currentY; | |
437 | GetPosition(¤tX, ¤tY); | |
438 | if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
439 | x1 = currentX; | |
440 | if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
441 | y1 = currentY; | |
442 | ||
443 | char buf[300]; | |
444 | ||
445 | int x_offset = x; | |
446 | int y_offset = y; | |
447 | ||
448 | int cx; // slider,min,max sizes | |
449 | int cy; | |
450 | float cyf; | |
451 | ||
452 | wxGetCharSize(GetHWND(), &cx, &cy,GetFont()); | |
453 | ||
454 | if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL) | |
455 | { | |
456 | if ( m_windowStyle & wxSL_LABELS ) | |
457 | { | |
458 | float min_len = 0.0; | |
459 | ||
460 | GetWindowText((HWND) m_staticMin, buf, 300); | |
461 | GetTextExtent(buf, &min_len, &cyf,NULL,NULL, GetFont()); | |
462 | ||
463 | float max_len = 0.0; | |
464 | ||
465 | GetWindowText((HWND) m_staticMax, buf, 300); | |
466 | GetTextExtent(buf, &max_len, &cyf,NULL,NULL, GetFont()); | |
467 | if (m_staticValue) | |
468 | { | |
469 | int new_width = (int)(wxMax(min_len, max_len)); | |
470 | int valueHeight = (int)cyf; | |
471 | #ifdef __WIN32__ | |
472 | // For some reason, under Win95, the text edit control has | |
473 | // a lot of space before the first character | |
474 | new_width += 3*cx; | |
475 | #endif | |
476 | #if defined(__WIN95__) | |
477 | // The height needs to be a bit bigger under Win95 if using native | |
478 | // 3D effects. | |
479 | valueHeight = (int) (valueHeight * 1.5) ; | |
480 | #endif | |
481 | MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE); | |
482 | x_offset += new_width + cx; | |
483 | } | |
484 | ||
485 | MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE); | |
486 | x_offset += (int)(min_len + cx); | |
487 | ||
488 | int slider_length = (int)(w1 - x_offset - max_len - cx); | |
489 | ||
490 | #if defined(__WIN95__) && USE_TRACK_BAR | |
491 | int slider_height = h1; | |
492 | if (slider_height < 0 ) | |
493 | slider_height = 20; | |
494 | #else | |
495 | int slider_height = cy; | |
496 | #endif | |
497 | ||
498 | // Slider must have a minimum/default length/height | |
499 | if (slider_length < 100) | |
500 | slider_length = 100; | |
501 | ||
502 | MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_length, slider_height, TRUE); | |
503 | x_offset += slider_length + cx; | |
504 | ||
505 | MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); | |
506 | } | |
507 | else | |
508 | { | |
509 | // No labels | |
510 | if ( w1 < 0 ) | |
511 | w1 = 200; | |
512 | if ( h1 < 0 ) | |
513 | h1 = 20; | |
514 | MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); | |
515 | } | |
516 | } | |
517 | else | |
518 | { | |
519 | if ( m_windowStyle & wxSL_LABELS ) | |
520 | { | |
521 | float min_len; | |
522 | GetWindowText((HWND) m_staticMin, buf, 300); | |
523 | GetTextExtent(buf, &min_len, &cyf,NULL,NULL,GetFont()); | |
524 | ||
525 | float max_len; | |
526 | GetWindowText((HWND) m_staticMax, buf, 300); | |
527 | GetTextExtent(buf, &max_len, &cyf,NULL,NULL, GetFont()); | |
528 | ||
529 | if (m_staticValue) | |
530 | { | |
531 | int new_width = (int)(wxMax(min_len, max_len)); | |
532 | int valueHeight = (int)cyf; | |
533 | /*** Suggested change by George Tasker - remove this block... | |
534 | #ifdef __WIN32__ | |
535 | // For some reason, under Win95, the text edit control has | |
536 | // a lot of space before the first character | |
537 | new_width += 3*cx; | |
538 | #endif | |
539 | ... and replace with following line: */ | |
540 | new_width += cx; | |
541 | ||
542 | #if defined(__WIN95__) | |
543 | // The height needs to be a bit bigger under Win95 if using native | |
544 | // 3D effects. | |
545 | valueHeight = (int) (valueHeight * 1.5) ; | |
546 | #endif | |
547 | ||
548 | MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE); | |
549 | y_offset += valueHeight; | |
550 | } | |
551 | ||
552 | MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE); | |
553 | y_offset += cy; | |
554 | ||
555 | int slider_length = (int)(h1 - y_offset - cy - cy); | |
556 | #if defined(__WIN95__) && USE_TRACK_BAR | |
557 | int slider_width = w1; | |
558 | if (slider_width < 0 ) | |
559 | slider_width = 20; | |
560 | #else | |
561 | // Use character height as an estimate of slider width (yes, width) | |
562 | int slider_width = cy; | |
563 | #endif | |
564 | ||
565 | // Slider must have a minimum/default length | |
566 | if (slider_length < 100) | |
567 | slider_length = 100; | |
568 | ||
569 | MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_width, slider_length, TRUE); | |
570 | y_offset += slider_length; | |
571 | ||
572 | MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); | |
573 | } | |
574 | else | |
575 | { | |
576 | // No labels | |
577 | if ( w1 < 0 ) | |
578 | w1 = 20; | |
579 | if ( h1 < 0 ) | |
580 | h1 = 200; | |
581 | MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); | |
582 | } | |
583 | } | |
584 | ||
585 | /* | |
586 | #if WXWIN_COMPATIBILITY | |
587 | GetEventHandler()->OldOnSize(width, height); | |
588 | #else | |
589 | wxSizeEvent event(wxSize(width, height), m_windowId); | |
590 | event.eventObject = this; | |
591 | GetEventHandler()->ProcessEvent(event); | |
592 | #endif | |
593 | */ | |
594 | ||
595 | } | |
596 | ||
597 | void wxSlider::SetRange(const int minValue, const int maxValue) | |
598 | { | |
599 | m_rangeMin = minValue; | |
600 | m_rangeMax = maxValue; | |
601 | ||
602 | #if defined(__WIN95__) && USE_TRACK_BAR | |
603 | ::SendMessage((HWND) GetHWND(), TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue)); | |
604 | #else | |
605 | ::SetScrollRange((HWND) GetHWND(), SB_CTL, m_rangeMin, m_rangeMax, TRUE); | |
606 | #endif | |
607 | char buf[40]; | |
608 | if ( m_staticMin ) | |
609 | { | |
610 | sprintf(buf, "%d", m_rangeMin); | |
611 | SetWindowText((HWND) m_staticMin, buf); | |
612 | } | |
613 | ||
614 | if ( m_staticMax ) | |
615 | { | |
616 | sprintf(buf, "%d", m_rangeMax); | |
617 | SetWindowText((HWND) m_staticMax, buf); | |
618 | } | |
619 | } | |
620 | ||
621 | WXHBRUSH wxSlider::OnCtlColor(const WXHDC pDC, const WXHWND pWnd, const WXUINT nCtlColor, | |
622 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
623 | { | |
624 | if ( nCtlColor == CTLCOLOR_SCROLLBAR ) | |
625 | return 0; | |
626 | ||
627 | // Otherwise, it's a static | |
628 | if (GetParent()->GetTransparentBackground()) | |
629 | SetBkMode((HDC) pDC, TRANSPARENT); | |
630 | else | |
631 | SetBkMode((HDC) pDC, OPAQUE); | |
632 | ||
633 | ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); | |
634 | ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); | |
635 | ||
636 | wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); | |
637 | ||
638 | // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush | |
639 | // has a zero usage count. | |
640 | // backgroundBrush->RealizeResource(); | |
641 | return (WXHBRUSH) backgroundBrush->GetResourceHandle(); | |
642 | } | |
643 | ||
644 | // For trackbars only | |
645 | void wxSlider::SetTickFreq(const int n, const int pos) | |
646 | { | |
647 | #if defined(__WIN95__) && USE_TRACK_BAR | |
648 | m_tickFreq = n; | |
649 | ::SendMessage( (HWND) GetHWND(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos ); | |
650 | #endif | |
651 | } | |
652 | ||
653 | void wxSlider::SetPageSize(const int pageSize) | |
654 | { | |
655 | #if defined(__WIN95__) && USE_TRACK_BAR | |
656 | ::SendMessage( (HWND) GetHWND(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize ); | |
657 | #endif | |
658 | m_pageSize = pageSize; | |
659 | } | |
660 | ||
661 | int wxSlider::GetPageSize(void) const | |
662 | { | |
663 | return m_pageSize; | |
664 | } | |
665 | ||
666 | void wxSlider::ClearSel(void) | |
667 | { | |
668 | #if defined(__WIN95__) && USE_TRACK_BAR | |
669 | ::SendMessage( (HWND) GetHWND(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0 ); | |
670 | #endif | |
671 | } | |
672 | ||
673 | void wxSlider::ClearTicks(void) | |
674 | { | |
675 | #if defined(__WIN95__) && USE_TRACK_BAR | |
676 | ::SendMessage( (HWND) GetHWND(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0 ); | |
677 | #endif | |
678 | } | |
679 | ||
680 | void wxSlider::SetLineSize(const int lineSize) | |
681 | { | |
682 | m_lineSize = lineSize; | |
683 | #if defined(__WIN95__) && USE_TRACK_BAR | |
684 | ::SendMessage( (HWND) GetHWND(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize ); | |
685 | #endif | |
686 | } | |
687 | ||
688 | int wxSlider::GetLineSize(void) const | |
689 | { | |
690 | #if defined(__WIN95__) && USE_TRACK_BAR | |
691 | return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETLINESIZE, (WPARAM) 0, (LPARAM) 0 ); | |
692 | #else | |
693 | return m_lineSize; | |
694 | #endif | |
695 | } | |
696 | ||
697 | int wxSlider::GetSelEnd(void) const | |
698 | { | |
699 | #if defined(__WIN95__) && USE_TRACK_BAR | |
700 | return (int) ::SendMessage( (HWND) GetHWND(), TBM_SETSELEND, (WPARAM) 0, (LPARAM) 0 ); | |
701 | #else | |
702 | return 0; | |
703 | #endif | |
704 | } | |
705 | ||
706 | int wxSlider::GetSelStart(void) const | |
707 | { | |
708 | #if defined(__WIN95__) && USE_TRACK_BAR | |
709 | return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETSELSTART, (WPARAM) 0, (LPARAM) 0 ); | |
710 | #else | |
711 | return 0; | |
712 | #endif | |
713 | } | |
714 | ||
715 | void wxSlider::SetSelection(const int minPos, const int maxPos) | |
716 | { | |
717 | #if defined(__WIN95__) && USE_TRACK_BAR | |
718 | ::SendMessage( (HWND) GetHWND(), TBM_SETSEL, (WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) ); | |
719 | #endif | |
720 | } | |
721 | ||
722 | void wxSlider::SetThumbLength(const int len) | |
723 | { | |
724 | #if defined(__WIN95__) && USE_TRACK_BAR | |
725 | ::SendMessage( (HWND) GetHWND(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0 ); | |
726 | #endif | |
727 | } | |
728 | ||
729 | int wxSlider::GetThumbLength(void) const | |
730 | { | |
731 | #if defined(__WIN95__) && USE_TRACK_BAR | |
732 | return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETTHUMBLENGTH, (WPARAM) 0, (LPARAM) 0 ); | |
733 | #else | |
734 | return 0; | |
735 | #endif | |
736 | } | |
737 | ||
738 | void wxSlider::SetTick(const int tickPos) | |
739 | { | |
740 | #if defined(__WIN95__) && USE_TRACK_BAR | |
741 | ::SendMessage( (HWND) GetHWND(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos ); | |
742 | #endif | |
743 | } | |
744 | ||
745 | bool wxSlider::ContainsHWND(WXHWND hWnd) const | |
746 | { | |
747 | return ( hWnd == GetStaticMin() || hWnd == GetStaticMax() || hWnd == GetEditValue() ); | |
748 | } | |
749 | ||
750 | #if WXWIN_COMPATIBILITY | |
751 | // Backward compatibility | |
752 | void wxSlider::OnScroll(wxScrollEvent& event) | |
753 | { | |
754 | int oldEvent = event.GetEventType(); | |
755 | event.SetEventType( wxEVT_COMMAND_SLIDER_UPDATED ); | |
756 | if ( !GetEventHandler()->ProcessEvent(event) ) | |
757 | { | |
758 | event.SetEventType( oldEvent ); | |
759 | if (!GetParent()->GetEventHandler()->ProcessEvent(event)) | |
760 | event.Skip(); | |
761 | } | |
762 | } | |
763 | #endif | |
764 | ||
765 | void wxSlider::Command (wxCommandEvent & event) | |
766 | { | |
767 | SetValue (event.GetInt()); | |
768 | ProcessCommand (event); | |
769 | } | |
770 | ||
771 | bool wxSlider::Show(const bool show) | |
772 | { | |
773 | wxWindow::Show(show); | |
774 | ||
775 | int cshow; | |
776 | if (show) | |
777 | cshow = SW_SHOW; | |
778 | else | |
779 | cshow = SW_HIDE; | |
780 | ||
781 | if(m_staticValue) | |
782 | ShowWindow((HWND) m_staticValue, (BOOL)cshow); | |
783 | if(m_staticMin) | |
784 | ShowWindow((HWND) m_staticMin, (BOOL)cshow); | |
785 | if(m_staticMax) | |
786 | ShowWindow((HWND) m_staticMax, (BOOL)cshow); | |
787 | return TRUE; | |
788 | } | |
789 | ||
790 |