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