]> git.saurik.com Git - wxWidgets.git/blob - src/msw/slider95.cpp
Inital fill in background, removed tabs, -1->wxID_ANY, TRUE->true, FALSE->false
[wxWidgets.git] / src / msw / slider95.cpp
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 WX_DEFINE_FLAGS( wxSliderStyle )
42
43 wxBEGIN_FLAGS( wxSliderStyle )
44 // new style border flags, we put them first to
45 // use them for streaming out
46 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
47 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
48 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
49 wxFLAGS_MEMBER(wxBORDER_RAISED)
50 wxFLAGS_MEMBER(wxBORDER_STATIC)
51 wxFLAGS_MEMBER(wxBORDER_NONE)
52
53 // old style border flags
54 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
55 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
56 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
57 wxFLAGS_MEMBER(wxRAISED_BORDER)
58 wxFLAGS_MEMBER(wxSTATIC_BORDER)
59 wxFLAGS_MEMBER(wxBORDER)
60
61 // standard window styles
62 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
63 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
64 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
65 wxFLAGS_MEMBER(wxWANTS_CHARS)
66 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
67 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
68 wxFLAGS_MEMBER(wxVSCROLL)
69 wxFLAGS_MEMBER(wxHSCROLL)
70
71 wxFLAGS_MEMBER(wxSL_HORIZONTAL)
72 wxFLAGS_MEMBER(wxSL_VERTICAL)
73 wxFLAGS_MEMBER(wxSL_AUTOTICKS)
74 wxFLAGS_MEMBER(wxSL_LABELS)
75 wxFLAGS_MEMBER(wxSL_LEFT)
76 wxFLAGS_MEMBER(wxSL_TOP)
77 wxFLAGS_MEMBER(wxSL_RIGHT)
78 wxFLAGS_MEMBER(wxSL_BOTTOM)
79 wxFLAGS_MEMBER(wxSL_BOTH)
80 wxFLAGS_MEMBER(wxSL_SELRANGE)
81
82 wxEND_FLAGS( wxSliderStyle )
83
84 IMPLEMENT_DYNAMIC_CLASS_XTI(wxSlider95, wxControl,"wx/scrolbar.h")
85
86 wxBEGIN_PROPERTIES_TABLE(wxSlider95)
87 wxEVENT_RANGE_PROPERTY( Scroll , wxEVT_SCROLL_TOP , wxEVT_SCROLL_ENDSCROLL , wxScrollEvent )
88 wxEVENT_PROPERTY( Updated , wxEVT_COMMAND_SLIDER_UPDATED , wxCommandEvent )
89
90 wxPROPERTY( Value , int , SetValue, GetValue , 0, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
91 wxPROPERTY( Minimum , int , SetMin, GetMin, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
92 wxPROPERTY( Maximum , int , SetMax, GetMax, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
93 wxPROPERTY( PageSize , int , SetPageSize, GetLineSize, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
94 wxPROPERTY( LineSize , int , SetLineSize, GetLineSize, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
95 wxPROPERTY( ThumbLength , int , SetThumbLength, GetThumbLength, 1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
96 wxPROPERTY_FLAGS( WindowStyle , wxSliderStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
97 wxEND_PROPERTIES_TABLE()
98
99 wxBEGIN_HANDLERS_TABLE(wxSlider95)
100 wxEND_HANDLERS_TABLE()
101
102 wxCONSTRUCTOR_8( wxSlider95 , wxWindow* , Parent , wxWindowID , Id , int , Value , int , Minimum , int , Maximum , wxPoint , Position , wxSize , Size , long , WindowStyle )
103 #else
104 IMPLEMENT_DYNAMIC_CLASS(wxSlider95, wxControl)
105 #endif
106
107 // Slider
108 wxSlider95::wxSlider95()
109 {
110 m_staticValue = (WXHWND) NULL;
111 m_staticMin = (WXHWND) NULL;
112 m_staticMax = (WXHWND) NULL;
113 m_pageSize = 1;
114 m_lineSize = 1;
115 m_rangeMax = 0;
116 m_rangeMin = 0;
117 m_tickFreq = 0;
118 }
119
120 bool wxSlider95::Create(wxWindow *parent, wxWindowID id,
121 int value, int minValue, int maxValue,
122 const wxPoint& pos,
123 const wxSize& size, long style,
124 const wxValidator& validator,
125 const wxString& name)
126 {
127 // default is no border
128 if ( (style & wxBORDER_MASK) == wxBORDER_DEFAULT )
129 style |= wxBORDER_NONE;
130
131 if ( !CreateBase(parent, id, pos, size, style, validator, name) )
132 return FALSE;
133
134 if (parent) parent->AddChild(this);
135
136 InheritAttributes();
137
138 m_staticValue = (WXHWND) NULL;;
139 m_staticMin = (WXHWND) NULL;;
140 m_staticMax = (WXHWND) NULL;;
141 m_pageSize = 1;
142 m_lineSize = 1;
143 m_windowStyle = style;
144 m_tickFreq = 0;
145
146 long msStyle = 0;
147 long wstyle = 0;
148
149 if ( m_windowStyle & wxSL_LABELS )
150 {
151 msStyle |= SS_CENTER;
152
153 WXDWORD exStyle = 0;
154 long valueStyle = m_windowStyle & ~wxBORDER_MASK;
155 valueStyle |= wxBORDER_SUNKEN;
156 msStyle |= MSWGetStyle(valueStyle, & exStyle) ;
157
158 m_staticValue = (WXHWND) CreateWindowEx
159 (
160 exStyle, wxT("STATIC"), NULL,
161 msStyle,
162 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(),
163 wxGetInstance(), NULL
164 );
165
166 // Now create min static control
167 wxString minLabel;
168 minLabel.Printf(wxT("%d"), minValue);
169 wstyle = STATIC_FLAGS;
170 if ( m_windowStyle & wxCLIP_SIBLINGS )
171 msStyle |= WS_CLIPSIBLINGS;
172 m_staticMin = (WXHWND) CreateWindowEx
173 (
174 0, wxT("STATIC"), minLabel,
175 wstyle,
176 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(),
177 wxGetInstance(), NULL
178 );
179 }
180
181 WXDWORD exStyle = 0;
182
183 msStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ;
184
185 if (m_windowStyle & wxSL_VERTICAL)
186 msStyle = TBS_VERT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ;
187 else
188 msStyle = TBS_HORZ | WS_CHILD | WS_VISIBLE | WS_TABSTOP ;
189
190 if ( m_windowStyle & wxSL_AUTOTICKS )
191 msStyle |= TBS_AUTOTICKS ;
192
193 if ( m_windowStyle & wxSL_LEFT )
194 msStyle |= TBS_LEFT;
195 else if ( m_windowStyle & wxSL_RIGHT )
196 msStyle |= TBS_RIGHT;
197 else if ( m_windowStyle & wxSL_TOP )
198 msStyle |= TBS_TOP;
199 else if ( m_windowStyle & wxSL_BOTTOM )
200 msStyle |= TBS_BOTTOM;
201 else if ( m_windowStyle & wxSL_BOTH )
202 msStyle |= TBS_BOTH;
203 else if ( ! (m_windowStyle & wxSL_AUTOTICKS) )
204 msStyle |= TBS_NOTICKS;
205
206 if ( m_windowStyle & wxSL_SELRANGE )
207 msStyle |= TBS_ENABLESELRANGE;
208
209 HWND scroll_bar = CreateWindowEx
210 (
211 exStyle, TRACKBAR_CLASS, wxEmptyString,
212 msStyle,
213 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
214 wxGetInstance(), NULL
215 );
216
217 m_rangeMax = maxValue;
218 m_rangeMin = minValue;
219
220 m_pageSize = (int)((maxValue-minValue)/10);
221
222 ::SendMessage(scroll_bar, TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue));
223 ::SendMessage(scroll_bar, TBM_SETPOS, TRUE, (LPARAM)value);
224 ::SendMessage(scroll_bar, TBM_SETPAGESIZE, 0, (LPARAM)m_pageSize);
225
226 m_hWnd = (WXHWND)scroll_bar;
227
228 SubclassWin(GetHWND());
229
230 ::SetWindowText((HWND) m_hWnd, wxEmptyString);
231
232 if ( m_windowStyle & wxSL_LABELS )
233 {
234 // Finally, create max value static item
235 wxString maxLabel;
236 maxLabel.Printf(wxT("%d"), maxValue);
237 wstyle = STATIC_FLAGS;
238
239 if ( m_windowStyle & wxCLIP_SIBLINGS )
240 msStyle |= WS_CLIPSIBLINGS;
241
242 m_staticMax = (WXHWND) CreateWindowEx
243 (
244 0, wxT("STATIC"), maxLabel,
245 wstyle,
246 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(),
247 wxGetInstance(), NULL
248 );
249
250
251 if (GetFont().Ok())
252 {
253 if (GetFont().GetResourceHandle())
254 {
255 if ( m_staticMin )
256 ::SendMessage((HWND) m_staticMin, WM_SETFONT,
257 (WPARAM) GetFont().GetResourceHandle(), 0L);
258
259 if ( m_staticMax )
260 ::SendMessage((HWND) m_staticMax, WM_SETFONT,
261 (WPARAM) GetFont().GetResourceHandle(), 0L);
262
263 if (m_staticValue)
264 ::SendMessage((HWND) m_staticValue, WM_SETFONT,
265 (WPARAM) GetFont().GetResourceHandle(), 0L);
266 }
267 }
268 }
269
270 SetSize(pos.x, pos.y, size.x, size.y);
271 SetValue(value);
272
273 // SetInitialBestSize is not called since we don't call MSWCreateControl
274 // for this control, so call SetBestSize here instead.
275 SetBestSize(size);
276
277 return TRUE;
278 }
279
280 bool wxSlider95::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam,
281 WXWORD WXUNUSED(pos), WXHWND control)
282 {
283 wxEventType scrollEvent;
284 switch ( wParam )
285 {
286 case SB_TOP:
287 scrollEvent = wxEVT_SCROLL_TOP;
288 break;
289
290 case SB_BOTTOM:
291 scrollEvent = wxEVT_SCROLL_BOTTOM;
292 break;
293
294 case SB_LINEUP:
295 scrollEvent = wxEVT_SCROLL_LINEUP;
296 break;
297
298 case SB_LINEDOWN:
299 scrollEvent = wxEVT_SCROLL_LINEDOWN;
300 break;
301
302 case SB_PAGEUP:
303 scrollEvent = wxEVT_SCROLL_PAGEUP;
304 break;
305
306 case SB_PAGEDOWN:
307 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
308 break;
309
310 case SB_THUMBTRACK:
311 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
312 break;
313
314 case SB_THUMBPOSITION:
315 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
316 break;
317
318 case SB_ENDSCROLL:
319 scrollEvent = wxEVT_SCROLL_ENDSCROLL;
320 break;
321
322 default:
323 // unknown scroll event?
324 return FALSE;
325 }
326
327 int newPos = (int) ::SendMessage((HWND) control, TBM_GETPOS, 0, 0);
328 if ( (newPos < GetMin()) || (newPos > GetMax()) )
329 {
330 // out of range - but we did process it
331 return TRUE;
332 }
333
334 SetValue(newPos);
335
336 wxScrollEvent event(scrollEvent, m_windowId);
337 event.SetPosition(newPos);
338 event.SetEventObject( this );
339 GetEventHandler()->ProcessEvent(event);
340
341 wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() );
342 cevent.SetInt( newPos );
343 cevent.SetEventObject( this );
344
345 return GetEventHandler()->ProcessEvent( cevent );
346 }
347
348 wxSlider95::~wxSlider95()
349 {
350 if (m_staticMin)
351 {
352 ::DestroyWindow((HWND) m_staticMin);
353 m_staticMin = (WXHWND) NULL;
354 }
355
356 if (m_staticMax)
357 {
358 ::DestroyWindow((HWND) m_staticMax);
359 m_staticMax = (WXHWND) NULL;
360 }
361
362 if (m_staticValue)
363 {
364 ::DestroyWindow((HWND) m_staticValue);
365 m_staticValue = (WXHWND) NULL;
366 }
367 }
368
369 int wxSlider95::GetValue() const
370 {
371 return ::SendMessage(GetHwnd(), TBM_GETPOS, 0, 0);
372 }
373
374 void wxSlider95::SetValue(int value)
375 {
376 ::SendMessage(GetHwnd(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value);
377
378 if (m_staticValue)
379 {
380 wxString str;
381 str.Printf(wxT("%d"), value);
382 ::SetWindowText((HWND) m_staticValue, str);
383 }
384 }
385
386 void wxSlider95::DoGetSize(int *width, int *height) const
387 {
388 RECT rect;
389 rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1;
390
391 wxFindMaxSize(GetHWND(), &rect);
392
393 if (m_staticMin)
394 wxFindMaxSize(m_staticMin, &rect);
395
396 if (m_staticMax)
397 wxFindMaxSize(m_staticMax, &rect);
398
399 if (m_staticValue)
400 wxFindMaxSize(m_staticValue, &rect);
401
402 if ( width )
403 *width = rect.right - rect.left;
404 if ( height )
405 *height = rect.bottom - rect.top;
406 }
407
408 void wxSlider95::GetPosition(int *x, int *y) const
409 {
410 wxWindow *parent = GetParent();
411 RECT rect;
412 rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1;
413
414 wxFindMaxSize(GetHWND(), &rect);
415
416 if (m_staticMin)
417 wxFindMaxSize(m_staticMin, &rect);
418 if (m_staticMax)
419 wxFindMaxSize(m_staticMax, &rect);
420 if (m_staticValue)
421 wxFindMaxSize(m_staticValue, &rect);
422
423 // Since we now have the absolute screen coords,
424 // if there's a parent we must subtract its top left corner
425 POINT point;
426 point.x = rect.left;
427 point.y = rect.top;
428 if (parent)
429 ::ScreenToClient((HWND) parent->GetHWND(), &point);
430
431 // We may be faking the client origin.
432 // So a window that's really at (0, 30) may appear
433 // (to wxWin apps) to be at (0, 0).
434 if (GetParent())
435 {
436 wxPoint pt(GetParent()->GetClientAreaOrigin());
437 point.x -= pt.x;
438 point.y -= pt.y;
439 }
440
441 *x = point.x;
442 *y = point.y;
443 }
444
445 // TODO one day, make sense of all this horros and replace it with a readable
446 // DoGetBestSize()
447 void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
448 {
449 int x1 = x;
450 int y1 = y;
451 int w1 = width;
452 int h1 = height;
453
454 int currentX, currentY;
455 GetPosition(&currentX, &currentY);
456 if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
457 x1 = currentX;
458 if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
459 y1 = currentY;
460
461 AdjustForParentClientOrigin(x1, y1, sizeFlags);
462
463 wxChar buf[300];
464
465 int x_offset = x;
466 int y_offset = y;
467
468 int cx; // slider,min,max sizes
469 int cy;
470 int cyf;
471
472 wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
473
474 if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL)
475 {
476 if ( m_windowStyle & wxSL_LABELS )
477 {
478 int min_len = 0;
479
480 ::GetWindowText((HWND) m_staticMin, buf, 300);
481 GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont());
482
483 int max_len = 0;
484
485 ::GetWindowText((HWND) m_staticMax, buf, 300);
486 GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont());
487 if (m_staticValue)
488 {
489 int new_width = (int)(wxMax(min_len, max_len));
490 int valueHeight = (int)cyf;
491 #ifdef __WIN32__
492 // For some reason, under Win95, the text edit control has
493 // a lot of space before the first character
494 new_width += 3*cx;
495 #endif
496 // The height needs to be a bit bigger under Win95 if
497 // using native 3D effects.
498 valueHeight = (int) (valueHeight * 1.5) ;
499 ::MoveWindow((HWND) m_staticValue, x_offset, y_offset,
500 new_width, valueHeight, TRUE);
501 x_offset += new_width + cx;
502 }
503
504 MoveWindow((HWND) m_staticMin, x_offset, y_offset,
505 (int) min_len, cy, TRUE);
506 x_offset += (int)(min_len + cx);
507
508 // slider_length = (total width available) - (width used so far)
509 // - (width of max label) - (border)
510 int slider_length = (int)(w1 - (x_offset-x) - max_len - cx);
511
512 int slider_height = h1;
513 if (slider_height < 0 )
514 slider_height = 20;
515
516 // Slider must have a minimum/default length/height
517 if (slider_length < 100)
518 slider_length = 100;
519
520 ::MoveWindow(GetHwnd(), x_offset, y_offset,
521 slider_length, slider_height, TRUE);
522 x_offset += slider_length + cx;
523
524 MoveWindow((HWND) m_staticMax, x_offset, y_offset,
525 (int) max_len, cy, TRUE);
526 }
527 else
528 {
529 // No labels
530 // If we're prepared to use the existing size, then...
531 if
532 (
533 width == -1
534 && height == -1
535 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)
536 )
537 {
538 GetSize(&w1, &h1);
539 }
540
541 if ( w1 < 0 )
542 w1 = 100;
543 if ( h1 < 0 )
544 h1 = 20;
545
546 ::MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
547 }
548 }
549 else
550 {
551 if ( m_windowStyle & wxSL_LABELS )
552 {
553 int min_len;
554 ::GetWindowText((HWND) m_staticMin, buf, 300);
555 GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont());
556
557 int max_len;
558 ::GetWindowText((HWND) m_staticMax, buf, 300);
559 GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont());
560
561 if (m_staticValue)
562 {
563 int new_width = (int)(wxMax(min_len, max_len));
564 int valueHeight = (int)cyf;
565 new_width += cx;
566
567 // The height needs to be a bit bigger under Win95 if
568 // using native 3D effects.
569 valueHeight = (int) (valueHeight * 1.5) ;
570
571 ::MoveWindow((HWND) m_staticValue, x_offset, y_offset,
572 new_width, valueHeight, TRUE);
573 y_offset += valueHeight;
574 }
575
576 ::MoveWindow((HWND) m_staticMin, x_offset, y_offset,
577 (int) min_len, cy, TRUE);
578 y_offset += cy;
579
580 // slider_length = (total height available) - (height used so far)
581 // - (height of max label) - (border)
582 int slider_length = (int)(h1 - (y_offset-y) - cy - cy);
583
584 int slider_width = w1;
585 if (slider_width < 0 )
586 slider_width = 20;
587
588 // Slider must have a minimum/default length
589 if (slider_length < 100)
590 slider_length = 100;
591
592 ::MoveWindow(GetHwnd(), x_offset, y_offset,
593 slider_width, slider_length, TRUE);
594 y_offset += slider_length;
595
596 ::MoveWindow((HWND) m_staticMax, x_offset, y_offset,
597 (int)max_len, cy, TRUE);
598 }
599 else
600 {
601 // No labels
602 // If we're prepared to use the existing size, then...
603 if
604 (
605 width == -1 && height == -1
606 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)
607 )
608 {
609 GetSize(&w1, &h1);
610 }
611
612 if ( w1 < 0 )
613 w1 = 20;
614 if ( h1 < 0 )
615 h1 = 100;
616
617 ::MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
618 }
619 }
620 }
621
622
623 // A reimplementaion of the mess above changed a bit to just determine the min
624 // size needed. It would certainly be nice to refactor this and DoSetSize
625 // somehow.
626 wxSize wxSlider95::DoGetBestSize() const
627 {
628 wxSize rv;
629 wxChar buf[300];
630 int cx;
631 int cy;
632 int cyf;
633 int min_len = 0;
634 int max_len = 0;
635
636 wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
637
638 if ( !HasFlag(wxSL_VERTICAL))
639 {
640 rv = wxSize(100, 20); // default size for the slider itself
641
642 if (HasFlag(wxSL_LABELS)) // do we need to add more for the labels?
643 {
644 ::GetWindowText((HWND) m_staticMin, buf, 300);
645 GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont());
646 rv.x += min_len + cx;
647
648 ::GetWindowText((HWND) m_staticMax, buf, 300);
649 GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont());
650 rv.x += max_len + cx;
651
652 if (m_staticValue)
653 {
654 int new_width = (int)(wxMax(min_len, max_len));
655 int valueHeight = (int)cyf;
656
657 #ifdef __WIN32__
658 // For some reason, under Win95, the text edit control has
659 // a lot of space before the first character
660 new_width += 3*cx;
661 #endif
662 // The height needs to be a bit bigger under Win95 if
663 // using native 3D effects.
664 valueHeight = (int) (valueHeight * 1.5) ;
665
666 rv.x += new_width + cx;
667 rv.y = wxMax(valueHeight, rv.y);
668 }
669 }
670 }
671 else // ! wxSL_HORIZONTAL
672 {
673 rv = wxSize(20, 100); // default size for the slider itself
674
675 if (HasFlag(wxSL_LABELS)) // do we need to add more for the labels?
676 {
677 ::GetWindowText((HWND) m_staticMin, buf, 300);
678 GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont());
679 rv.y += cy;
680
681 ::GetWindowText((HWND) m_staticMax, buf, 300);
682 GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont());
683 rv.y += cy;
684
685 if (m_staticValue)
686 {
687 int new_width = (int)(wxMax(min_len, max_len));
688 int valueHeight = (int)cyf;
689 new_width += cx;
690
691 // The height needs to be a bit bigger under Win95 if
692 // using native 3D effects.
693 valueHeight = (int) (valueHeight * 1.5) ;
694 rv.y += valueHeight;
695 rv.x = wxMax(new_width, rv.x);
696 }
697 }
698 }
699 return rv;
700 }
701
702
703 void wxSlider95::SetRange(int minValue, int maxValue)
704 {
705 m_rangeMin = minValue;
706 m_rangeMax = maxValue;
707
708 ::SendMessage(GetHwnd(), TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue));
709
710 wxChar buf[40];
711 if ( m_staticMin )
712 {
713 wxSprintf(buf, wxT("%d"), m_rangeMin);
714 ::SetWindowText((HWND) m_staticMin, buf);
715 }
716
717 if ( m_staticMax )
718 {
719 wxSprintf(buf, wxT("%d"), m_rangeMax);
720 ::SetWindowText((HWND) m_staticMax, buf);
721 }
722 }
723
724 WXHBRUSH wxSlider95::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
725 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
726 {
727 #ifndef __WXWINCE__
728 if ( nCtlColor == CTLCOLOR_SCROLLBAR )
729 return 0;
730 #else
731 if ( nCtlColor != CTLCOLOR_STATIC )
732 return 0;
733 #endif
734 // Otherwise, it's a static
735 return wxControl::OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
736 }
737
738 // For trackbars only
739 void wxSlider95::SetTickFreq(int n, int pos)
740 {
741 m_tickFreq = n;
742 ::SendMessage( GetHwnd(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos );
743 }
744
745 void wxSlider95::SetPageSize(int pageSize)
746 {
747 ::SendMessage( GetHwnd(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize );
748 m_pageSize = pageSize;
749 }
750
751 int wxSlider95::GetPageSize() const
752 {
753 return m_pageSize;
754 }
755
756 void wxSlider95::ClearSel()
757 {
758 ::SendMessage( GetHwnd(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0 );
759 }
760
761 void wxSlider95::ClearTicks()
762 {
763 ::SendMessage( GetHwnd(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0 );
764 }
765
766 void wxSlider95::SetLineSize(int lineSize)
767 {
768 m_lineSize = lineSize;
769 ::SendMessage( GetHwnd(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize );
770 }
771
772 int wxSlider95::GetLineSize() const
773 {
774 return (int) ::SendMessage( GetHwnd(), TBM_GETLINESIZE,
775 (WPARAM) 0, (LPARAM) 0 );
776 }
777
778 int wxSlider95::GetSelEnd() const
779 {
780 return (int) ::SendMessage( GetHwnd(), TBM_SETSELEND,
781 (WPARAM) 0, (LPARAM) 0 );
782 }
783
784 int wxSlider95::GetSelStart() const
785 {
786 return (int) ::SendMessage( GetHwnd(), TBM_GETSELSTART,
787 (WPARAM) 0, (LPARAM) 0 );
788 }
789
790 void wxSlider95::SetSelection(int minPos, int maxPos)
791 {
792 ::SendMessage(GetHwnd(), TBM_SETSEL,
793 (WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) );
794 }
795
796 void wxSlider95::SetThumbLength(int len)
797 {
798 ::SendMessage( GetHwnd(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0 );
799 }
800
801 int wxSlider95::GetThumbLength() const
802 {
803 return (int) ::SendMessage( GetHwnd(), TBM_GETTHUMBLENGTH,
804 (WPARAM) 0, (LPARAM) 0 );
805 }
806
807 void wxSlider95::SetTick(int tickPos)
808 {
809 ::SendMessage( GetHwnd(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos );
810 }
811
812 bool wxSlider95::ContainsHWND(WXHWND hWnd) const
813 {
814 return
815 (
816 hWnd == GetStaticMin()
817 || hWnd == GetStaticMax()
818 || hWnd == GetEditValue()
819 );
820 }
821
822 void wxSlider95::Command (wxCommandEvent & event)
823 {
824 SetValue (event.GetInt());
825 ProcessCommand (event);
826 }
827
828 bool wxSlider95::Show(bool show)
829 {
830 wxWindow::Show(show);
831
832 int cshow;
833 if (show)
834 cshow = SW_SHOW;
835 else
836 cshow = SW_HIDE;
837
838 if(m_staticValue)
839 ShowWindow((HWND) m_staticValue, (BOOL)cshow);
840
841 if(m_staticMin)
842 ShowWindow((HWND) m_staticMin, (BOOL)cshow);
843
844 if(m_staticMax)
845 ShowWindow((HWND) m_staticMax, (BOOL)cshow);
846
847 return TRUE;
848 }
849
850 #endif
851 // __WIN95__
852
853 #endif // wxUSE_SLIDER