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