]> git.saurik.com Git - wxWidgets.git/blame - src/msw/slider95.cpp
Unhide problem of ambiguity in wxSoundBase::Play.
[wxWidgets.git] / src / msw / slider95.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
da87a1ca
JS
2// Name: slider95.cpp
3// Purpose: wxSlider95, using the Win95 trackbar control
2bda0e17
KB
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
da87a1ca 13#pragma implementation "slider95.h"
2bda0e17
KB
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
1e6feb95
VZ
23#if wxUSE_SLIDER
24
2bda0e17 25#ifndef WX_PRECOMP
3096bd2f
VZ
26#include "wx/utils.h"
27#include "wx/brush.h"
5438a566 28#include "wx/slider.h"
2bda0e17
KB
29#endif
30
da87a1ca 31#ifdef __WIN95__
2bda0e17 32
da87a1ca
JS
33#include "wx/msw/slider95.h"
34#include "wx/msw/private.h"
2bda0e17 35
b39dbf34 36#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
c42404a5 37 #include <commctrl.h>
2bda0e17
KB
38#endif
39
f0a126fe 40#if wxUSE_EXTENDED_RTTI
bc9fb572
JS
41WX_DEFINE_FLAGS( wxSliderStyle )
42
3ff066a4 43wxBEGIN_FLAGS( wxSliderStyle )
bc9fb572
JS
44 // new style border flags, we put them first to
45 // use them for streaming out
3ff066a4
SC
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)
bc9fb572
JS
52
53 // old style border flags
3ff066a4
SC
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)
cb0afb26 59 wxFLAGS_MEMBER(wxBORDER)
bc9fb572
JS
60
61 // standard window styles
3ff066a4
SC
62 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
63 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
64 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
65 wxFLAGS_MEMBER(wxWANTS_CHARS)
cb0afb26 66 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
3ff066a4
SC
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 )
bc9fb572 83
f0a126fe
SC
84IMPLEMENT_DYNAMIC_CLASS_XTI(wxSlider95, wxControl,"wx/scrolbar.h")
85
3ff066a4
SC
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 )
c5ca409b 89
3ff066a4
SC
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"))
af498247 96 wxPROPERTY_FLAGS( WindowStyle , wxSliderStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
3ff066a4 97wxEND_PROPERTIES_TABLE()
f0a126fe 98
3ff066a4
SC
99wxBEGIN_HANDLERS_TABLE(wxSlider95)
100wxEND_HANDLERS_TABLE()
f0a126fe 101
3ff066a4 102wxCONSTRUCTOR_8( wxSlider95 , wxWindow* , Parent , wxWindowID , Id , int , Value , int , Minimum , int , Maximum , wxPoint , Position , wxSize , Size , long , WindowStyle )
f0a126fe 103#else
bf532053 104IMPLEMENT_DYNAMIC_CLASS(wxSlider95, wxControl)
f0a126fe 105#endif
2bda0e17
KB
106
107// Slider
bfc6fde4 108wxSlider95::wxSlider95()
2bda0e17 109{
5f605ccf
VZ
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;
2bda0e17
KB
118}
119
debe6624
JS
120bool wxSlider95::Create(wxWindow *parent, wxWindowID id,
121 int value, int minValue, int maxValue,
2bda0e17 122 const wxPoint& pos,
debe6624 123 const wxSize& size, long style,
422a142b 124 const wxValidator& validator,
2bda0e17
KB
125 const wxString& name)
126{
7bdfb981 127 // default is no border
fe3d9123
JS
128 if ( (style & wxBORDER_MASK) == wxBORDER_DEFAULT )
129 style |= wxBORDER_NONE;
130
7bdfb981
RD
131 if ( !CreateBase(parent, id, pos, size, style, validator, name) )
132 return FALSE;
2bda0e17 133
5f605ccf
VZ
134 if (parent) parent->AddChild(this);
135
7bdfb981 136 InheritAttributes();
5f605ccf
VZ
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
5f605ccf
VZ
146 long msStyle = 0;
147 long wstyle = 0;
148
5f605ccf
VZ
149 if ( m_windowStyle & wxSL_LABELS )
150 {
fe3d9123 151 msStyle |= SS_CENTER;
5f605ccf 152
fe3d9123 153 WXDWORD exStyle = 0;
983d2e14
JS
154 long valueStyle = m_windowStyle & ~wxBORDER_MASK;
155 valueStyle |= wxBORDER_SUNKEN;
156 msStyle |= MSWGetStyle(valueStyle, & exStyle) ;
5f605ccf
VZ
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
2b5f62a0
VZ
167 wxString minLabel;
168 minLabel.Printf(wxT("%d"), minValue);
5f605ccf
VZ
169 wstyle = STATIC_FLAGS;
170 if ( m_windowStyle & wxCLIP_SIBLINGS )
171 msStyle |= WS_CLIPSIBLINGS;
172 m_staticMin = (WXHWND) CreateWindowEx
173 (
2b5f62a0 174 0, wxT("STATIC"), minLabel,
5f605ccf
VZ
175 wstyle,
176 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(),
177 wxGetInstance(), NULL
178 );
179 }
180
fe3d9123 181 WXDWORD exStyle = 0;
5f605ccf 182
fe3d9123 183 msStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ;
2bda0e17 184
5f605ccf
VZ
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 ;
b0766406 189
5f605ccf
VZ
190 if ( m_windowStyle & wxSL_AUTOTICKS )
191 msStyle |= TBS_AUTOTICKS ;
b0766406 192
5f605ccf
VZ
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;
2bda0e17 205
5f605ccf
VZ
206 if ( m_windowStyle & wxSL_SELRANGE )
207 msStyle |= TBS_ENABLESELRANGE;
2bda0e17 208
5f605ccf
VZ
209 HWND scroll_bar = CreateWindowEx
210 (
fda7962d 211 exStyle, TRACKBAR_CLASS, wxEmptyString,
5f605ccf
VZ
212 msStyle,
213 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
214 wxGetInstance(), NULL
215 );
2bda0e17 216
5f605ccf
VZ
217 m_rangeMax = maxValue;
218 m_rangeMin = minValue;
2bda0e17 219
5f605ccf 220 m_pageSize = (int)((maxValue-minValue)/10);
2bda0e17 221
5f605ccf
VZ
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);
2bda0e17 225
5f605ccf 226 m_hWnd = (WXHWND)scroll_bar;
2bda0e17 227
5f605ccf 228 SubclassWin(GetHWND());
2bda0e17 229
fda7962d 230 ::SetWindowText((HWND) m_hWnd, wxEmptyString);
2bda0e17 231
5f605ccf
VZ
232 if ( m_windowStyle & wxSL_LABELS )
233 {
234 // Finally, create max value static item
2b5f62a0
VZ
235 wxString maxLabel;
236 maxLabel.Printf(wxT("%d"), maxValue);
5f605ccf 237 wstyle = STATIC_FLAGS;
9c331ded 238
5f605ccf
VZ
239 if ( m_windowStyle & wxCLIP_SIBLINGS )
240 msStyle |= WS_CLIPSIBLINGS;
9c331ded 241
5f605ccf
VZ
242 m_staticMax = (WXHWND) CreateWindowEx
243 (
2b5f62a0 244 0, wxT("STATIC"), maxLabel,
5f605ccf
VZ
245 wstyle,
246 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(),
247 wxGetInstance(), NULL
248 );
2bda0e17 249
da87a1ca 250
5f605ccf 251 if (GetFont().Ok())
2bda0e17 252 {
5f605ccf
VZ
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 }
2bda0e17 267 }
5f605ccf 268 }
2bda0e17 269
7a5a5718 270 SetSize(pos.x, pos.y, size.x, size.y);
5f605ccf 271 SetValue(value);
2bda0e17 272
7a5a5718
RD
273 // SetInitialBestSize is not called since we don't call MSWCreateControl
274 // for this control, so call SetBestSize here instead.
275 SetBestSize(size);
276
5f605ccf 277 return TRUE;
2bda0e17
KB
278}
279
a23fd0e1 280bool wxSlider95::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam,
d699f48b 281 WXWORD WXUNUSED(pos), WXHWND control)
2bda0e17 282{
1e6feb95 283 wxEventType scrollEvent;
2bda0e17
KB
284 switch ( wParam )
285 {
a23fd0e1 286 case SB_TOP:
a23fd0e1
VZ
287 scrollEvent = wxEVT_SCROLL_TOP;
288 break;
289
290 case SB_BOTTOM:
a23fd0e1
VZ
291 scrollEvent = wxEVT_SCROLL_BOTTOM;
292 break;
293
294 case SB_LINEUP:
a23fd0e1
VZ
295 scrollEvent = wxEVT_SCROLL_LINEUP;
296 break;
297
298 case SB_LINEDOWN:
a23fd0e1
VZ
299 scrollEvent = wxEVT_SCROLL_LINEDOWN;
300 break;
301
302 case SB_PAGEUP:
a23fd0e1
VZ
303 scrollEvent = wxEVT_SCROLL_PAGEUP;
304 break;
305
306 case SB_PAGEDOWN:
a23fd0e1
VZ
307 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
308 break;
309
310 case SB_THUMBTRACK:
a23fd0e1
VZ
311 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
312 break;
313
e8b669d3
VZ
314 case SB_THUMBPOSITION:
315 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
316 break;
317
318 case SB_ENDSCROLL:
319 scrollEvent = wxEVT_SCROLL_ENDSCROLL;
320 break;
321
a23fd0e1 322 default:
1e6feb95
VZ
323 // unknown scroll event?
324 return FALSE;
2bda0e17
KB
325 }
326
5f605ccf 327 int newPos = (int) ::SendMessage((HWND) control, TBM_GETPOS, 0, 0);
a23fd0e1 328 if ( (newPos < GetMin()) || (newPos > GetMax()) )
2bda0e17 329 {
a23fd0e1
VZ
330 // out of range - but we did process it
331 return TRUE;
332 }
2bda0e17 333
a23fd0e1 334 SetValue(newPos);
2bda0e17 335
a23fd0e1
VZ
336 wxScrollEvent event(scrollEvent, m_windowId);
337 event.SetPosition(newPos);
338 event.SetEventObject( this );
339 GetEventHandler()->ProcessEvent(event);
f3a65071 340
a23fd0e1 341 wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() );
f6bcfd97 342 cevent.SetInt( newPos );
a23fd0e1 343 cevent.SetEventObject( this );
f3a65071 344
a23fd0e1 345 return GetEventHandler()->ProcessEvent( cevent );
2bda0e17
KB
346}
347
bfc6fde4 348wxSlider95::~wxSlider95()
2bda0e17
KB
349{
350 if (m_staticMin)
5f605ccf
VZ
351 {
352 ::DestroyWindow((HWND) m_staticMin);
353 m_staticMin = (WXHWND) NULL;
354 }
355
2bda0e17 356 if (m_staticMax)
5f605ccf
VZ
357 {
358 ::DestroyWindow((HWND) m_staticMax);
359 m_staticMax = (WXHWND) NULL;
360 }
361
2bda0e17 362 if (m_staticValue)
5f605ccf
VZ
363 {
364 ::DestroyWindow((HWND) m_staticValue);
365 m_staticValue = (WXHWND) NULL;
366 }
2bda0e17
KB
367}
368
bfc6fde4 369int wxSlider95::GetValue() const
2bda0e17 370{
5f605ccf 371 return ::SendMessage(GetHwnd(), TBM_GETPOS, 0, 0);
2bda0e17
KB
372}
373
debe6624 374void wxSlider95::SetValue(int value)
2bda0e17 375{
5f605ccf
VZ
376 ::SendMessage(GetHwnd(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value);
377
378 if (m_staticValue)
379 {
2b5f62a0
VZ
380 wxString str;
381 str.Printf(wxT("%d"), value);
382 ::SetWindowText((HWND) m_staticValue, str);
5f605ccf
VZ
383 }
384}
385
386void wxSlider95::DoGetSize(int *width, int *height) const
2bda0e17 387{
5f605ccf
VZ
388 RECT rect;
389 rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1;
390
391 wxFindMaxSize(GetHWND(), &rect);
2bda0e17 392
5f605ccf
VZ
393 if (m_staticMin)
394 wxFindMaxSize(m_staticMin, &rect);
2bda0e17 395
5f605ccf
VZ
396 if (m_staticMax)
397 wxFindMaxSize(m_staticMax, &rect);
2bda0e17 398
5f605ccf
VZ
399 if (m_staticValue)
400 wxFindMaxSize(m_staticValue, &rect);
401
6819fb9b
VZ
402 if ( width )
403 *width = rect.right - rect.left;
404 if ( height )
405 *height = rect.bottom - rect.top;
2bda0e17
KB
406}
407
da87a1ca 408void wxSlider95::GetPosition(int *x, int *y) const
2bda0e17 409{
5f605ccf
VZ
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;
2bda0e17
KB
443}
444
4438caf4
VZ
445// TODO one day, make sense of all this horros and replace it with a readable
446// DoGetBestSize()
bfc6fde4 447void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
2bda0e17 448{
5f605ccf
VZ
449 int x1 = x;
450 int y1 = y;
451 int w1 = width;
452 int h1 = height;
2bda0e17 453
5f605ccf
VZ
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;
2bda0e17 460
5f605ccf 461 AdjustForParentClientOrigin(x1, y1, sizeFlags);
81d66cf3 462
5f605ccf 463 wxChar buf[300];
2bda0e17 464
5f605ccf
VZ
465 int x_offset = x;
466 int y_offset = y;
2bda0e17 467
5f605ccf
VZ
468 int cx; // slider,min,max sizes
469 int cy;
470 int cyf;
2bda0e17 471
5f605ccf 472 wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
2bda0e17 473
5f605ccf 474 if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL)
a23fd0e1 475 {
5f605ccf
VZ
476 if ( m_windowStyle & wxSL_LABELS )
477 {
478 int min_len = 0;
2bda0e17 479
5f605ccf
VZ
480 ::GetWindowText((HWND) m_staticMin, buf, 300);
481 GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont());
2bda0e17 482
5f605ccf 483 int max_len = 0;
2bda0e17 484
5f605ccf
VZ
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;
2bda0e17 491#ifdef __WIN32__
5f605ccf
VZ
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;
2bda0e17 495#endif
5f605ccf
VZ
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
724a907c
VZ
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);
5f605ccf
VZ
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
a23fd0e1 528 {
5f605ccf
VZ
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 )
7bdfb981 542 w1 = 100;
5f605ccf
VZ
543 if ( h1 < 0 )
544 h1 = 20;
545
546 ::MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
a23fd0e1 547 }
a23fd0e1 548 }
5f605ccf 549 else
2bda0e17 550 {
5f605ccf
VZ
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;
5f605ccf 565 new_width += cx;
2bda0e17 566
5f605ccf
VZ
567 // The height needs to be a bit bigger under Win95 if
568 // using native 3D effects.
569 valueHeight = (int) (valueHeight * 1.5) ;
2bda0e17 570
5f605ccf
VZ
571 ::MoveWindow((HWND) m_staticValue, x_offset, y_offset,
572 new_width, valueHeight, TRUE);
573 y_offset += valueHeight;
574 }
2bda0e17 575
5f605ccf
VZ
576 ::MoveWindow((HWND) m_staticMin, x_offset, y_offset,
577 (int) min_len, cy, TRUE);
578 y_offset += cy;
2bda0e17 579
724a907c
VZ
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);
da87a1ca 583
5f605ccf
VZ
584 int slider_width = w1;
585 if (slider_width < 0 )
586 slider_width = 20;
2bda0e17 587
5f605ccf
VZ
588 // Slider must have a minimum/default length
589 if (slider_length < 100)
590 slider_length = 100;
2bda0e17 591
5f605ccf
VZ
592 ::MoveWindow(GetHwnd(), x_offset, y_offset,
593 slider_width, slider_length, TRUE);
594 y_offset += slider_length;
2bda0e17 595
5f605ccf
VZ
596 ::MoveWindow((HWND) m_staticMax, x_offset, y_offset,
597 (int)max_len, cy, TRUE);
598 }
599 else
a23fd0e1 600 {
5f605ccf
VZ
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 )
7bdfb981 615 h1 = 100;
5f605ccf
VZ
616
617 ::MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
a23fd0e1 618 }
a23fd0e1 619 }
2bda0e17
KB
620}
621
7bdfb981
RD
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.
626wxSize 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
debe6624 703void wxSlider95::SetRange(int minValue, int maxValue)
2bda0e17 704{
5f605ccf
VZ
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 }
2bda0e17
KB
722}
723
debe6624 724WXHBRUSH wxSlider95::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
a23fd0e1 725 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
2bda0e17 726{
4676948b 727#ifndef __WXWINCE__
5f605ccf
VZ
728 if ( nCtlColor == CTLCOLOR_SCROLLBAR )
729 return 0;
4676948b
JS
730#else
731 if ( nCtlColor != CTLCOLOR_STATIC )
732 return 0;
733#endif
5f605ccf
VZ
734 // Otherwise, it's a static
735 return wxControl::OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
2bda0e17
KB
736}
737
738// For trackbars only
debe6624 739void wxSlider95::SetTickFreq(int n, int pos)
2bda0e17 740{
2bda0e17 741 m_tickFreq = n;
4438caf4 742 ::SendMessage( GetHwnd(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos );
2bda0e17
KB
743}
744
debe6624 745void wxSlider95::SetPageSize(int pageSize)
2bda0e17 746{
4438caf4 747 ::SendMessage( GetHwnd(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize );
2bda0e17
KB
748 m_pageSize = pageSize;
749}
750
bfc6fde4 751int wxSlider95::GetPageSize() const
2bda0e17
KB
752{
753 return m_pageSize;
754}
755
bfc6fde4 756void wxSlider95::ClearSel()
2bda0e17 757{
4438caf4 758 ::SendMessage( GetHwnd(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0 );
2bda0e17
KB
759}
760
bfc6fde4 761void wxSlider95::ClearTicks()
2bda0e17 762{
4438caf4 763 ::SendMessage( GetHwnd(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0 );
2bda0e17
KB
764}
765
debe6624 766void wxSlider95::SetLineSize(int lineSize)
2bda0e17 767{
5f605ccf
VZ
768 m_lineSize = lineSize;
769 ::SendMessage( GetHwnd(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize );
2bda0e17
KB
770}
771
bfc6fde4 772int wxSlider95::GetLineSize() const
2bda0e17 773{
5f605ccf
VZ
774 return (int) ::SendMessage( GetHwnd(), TBM_GETLINESIZE,
775 (WPARAM) 0, (LPARAM) 0 );
2bda0e17
KB
776}
777
bfc6fde4 778int wxSlider95::GetSelEnd() const
2bda0e17 779{
5f605ccf
VZ
780 return (int) ::SendMessage( GetHwnd(), TBM_SETSELEND,
781 (WPARAM) 0, (LPARAM) 0 );
2bda0e17
KB
782}
783
bfc6fde4 784int wxSlider95::GetSelStart() const
2bda0e17 785{
5f605ccf
VZ
786 return (int) ::SendMessage( GetHwnd(), TBM_GETSELSTART,
787 (WPARAM) 0, (LPARAM) 0 );
2bda0e17
KB
788}
789
debe6624 790void wxSlider95::SetSelection(int minPos, int maxPos)
2bda0e17 791{
5f605ccf
VZ
792 ::SendMessage(GetHwnd(), TBM_SETSEL,
793 (WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) );
2bda0e17
KB
794}
795
debe6624 796void wxSlider95::SetThumbLength(int len)
2bda0e17 797{
5f605ccf 798 ::SendMessage( GetHwnd(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0 );
2bda0e17
KB
799}
800
bfc6fde4 801int wxSlider95::GetThumbLength() const
2bda0e17 802{
5f605ccf
VZ
803 return (int) ::SendMessage( GetHwnd(), TBM_GETTHUMBLENGTH,
804 (WPARAM) 0, (LPARAM) 0 );
2bda0e17
KB
805}
806
debe6624 807void wxSlider95::SetTick(int tickPos)
2bda0e17 808{
4438caf4 809 ::SendMessage( GetHwnd(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos );
2bda0e17
KB
810}
811
da87a1ca 812bool wxSlider95::ContainsHWND(WXHWND hWnd) const
2bda0e17 813{
5f605ccf
VZ
814 return
815 (
816 hWnd == GetStaticMin()
817 || hWnd == GetStaticMax()
818 || hWnd == GetEditValue()
819 );
2bda0e17
KB
820}
821
da87a1ca 822void wxSlider95::Command (wxCommandEvent & event)
2bda0e17 823{
5f605ccf
VZ
824 SetValue (event.GetInt());
825 ProcessCommand (event);
2bda0e17
KB
826}
827
debe6624 828bool wxSlider95::Show(bool show)
2bda0e17 829{
a23fd0e1 830 wxWindow::Show(show);
2bda0e17
KB
831
832 int cshow;
833 if (show)
834 cshow = SW_SHOW;
835 else
836 cshow = SW_HIDE;
837
838 if(m_staticValue)
a23fd0e1 839 ShowWindow((HWND) m_staticValue, (BOOL)cshow);
5f605ccf 840
2bda0e17 841 if(m_staticMin)
a23fd0e1 842 ShowWindow((HWND) m_staticMin, (BOOL)cshow);
5f605ccf 843
2bda0e17 844 if(m_staticMax)
a23fd0e1 845 ShowWindow((HWND) m_staticMax, (BOOL)cshow);
5f605ccf 846
2bda0e17
KB
847 return TRUE;
848}
849
da87a1ca
JS
850#endif
851 // __WIN95__
2bda0e17 852
1e6feb95 853#endif // wxUSE_SLIDER