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