]> git.saurik.com Git - wxWidgets.git/blame - src/os2/slider.cpp
miscellaneous small enhancements
[wxWidgets.git] / src / os2 / slider.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
7ec69821 2// Name: src/os2/slider.cpp
0e320a79 3// Purpose: wxSlider
409c9842 4// Author: David Webster
0e320a79 5// Modified by:
409c9842 6// Created: 10/15/99
0e320a79 7// RCS-ID: $Id$
409c9842 8// Copyright: (c) David Webster
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
409c9842
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
1ab440bc
WS
20 #include <stdio.h>
21 #include "wx/utils.h"
22 #include "wx/brush.h"
23 #include "wx/scrolwin.h"
0e320a79
DW
24#endif
25
312ebad4
WS
26#if wxUSE_SLIDER
27
0e320a79 28#include "wx/slider.h"
409c9842 29#include "wx/os2/private.h"
0e320a79 30
0e320a79
DW
31IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
32
0e320a79
DW
33wxSlider::wxSlider()
34{
3c299c3a
DW
35 m_hStaticValue = 0L;
36 m_hStaticMin = 0L;
37 m_hStaticMax = 0L;
38 m_nPageSize = 1;
39 m_nLineSize = 1;
40 m_nRangeMax = 0;
41 m_nRangeMin = 0;
42 m_nTickFreq = 0;
43} // end of wxSlider::wxSlider
409c9842 44
0e320a79
DW
45wxSlider::~wxSlider()
46{
3c299c3a
DW
47 if (m_hStaticMin)
48 ::WinDestroyWindow((HWND)m_hStaticMin);
49 if (m_hStaticMax)
50 ::WinDestroyWindow((HWND)m_hStaticMax);
51 if (m_hStaticValue)
52 ::WinDestroyWindow((HWND)m_hStaticValue);
53} // end of wxSlider::~wxSlider
0e320a79 54
6670f564
WS
55void wxSlider::AdjustSubControls( int nX,
56 int nY,
57 int nWidth,
58 int nHeight,
59 int WXUNUSED(nSizeFlags) )
d8a3f66c 60{
d8a3f66c
DW
61 int nXOffset = nX;
62 int nYOffset = nY;
63 int nCx; // slider,min,max sizes
64 int nCy;
65 int nCyf;
0fba44b4 66 wxChar zBuf[300];
7804d121 67 wxFont vFont = this->GetFont();
d8a3f66c
DW
68
69 wxGetCharSize( GetHWND()
70 ,&nCx
71 ,&nCy
7804d121 72 ,&vFont
d8a3f66c
DW
73 );
74
75 if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL)
76 {
77 if (m_windowStyle & wxSL_LABELS )
78 {
79 int nMinLen = 0;
80 int nMaxLen = 0;
81
0fba44b4 82 ::WinQueryWindowText((HWND)m_hStaticMin, 300, (PSZ)zBuf);
7804d121 83 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &vFont);
d8a3f66c 84
0fba44b4 85 ::WinQueryWindowText((HWND)m_hStaticMax, 300, (PSZ)zBuf);
7804d121 86 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &vFont);
d8a3f66c
DW
87
88 if (m_hStaticValue)
89 {
90 int nNewWidth = wxMax(nMinLen, nMaxLen);
91 int nValueHeight = nCyf;
92
93 ::WinSetWindowPos( (HWND)m_hStaticValue
94 ,HWND_TOP
95 ,(LONG)nXOffset - (nNewWidth + nCx + nMinLen + nCx)
96 ,(LONG)nYOffset
97 ,(LONG)nNewWidth
98 ,(LONG)nValueHeight
b3260bce 99 ,SWP_SIZE | SWP_MOVE
d8a3f66c
DW
100 );
101 }
102 ::WinSetWindowPos( (HWND)m_hStaticMin
103 ,HWND_TOP
104 ,(LONG)nXOffset - (nMinLen + nCx)
105 ,(LONG)nYOffset
106 ,(LONG)nMinLen
31833fd7 107 ,(LONG)nCyf
b3260bce 108 ,SWP_SIZE | SWP_MOVE
d8a3f66c
DW
109 );
110 nXOffset += nWidth + nCx;
111
112 ::WinSetWindowPos( (HWND)m_hStaticMax
113 ,HWND_TOP
114 ,(LONG)nXOffset
115 ,(LONG)nYOffset
116 ,(LONG)nMaxLen
31833fd7 117 ,(LONG)nCyf
70a2c656
DW
118 ,SWP_ZORDER | SWP_SHOW
119 );
120 }
121 }
122 else
123 {
124 //
125 // Now deal with a vertical slider
126 //
127
31833fd7 128 if (m_windowStyle & wxSL_LABELS )
70a2c656
DW
129 {
130 int nMinLen = 0;
131 int nMaxLen = 0;
132
0fba44b4 133 ::WinQueryWindowText((HWND)m_hStaticMin, 300, (PSZ)zBuf);
7804d121 134 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &vFont);
70a2c656 135
0fba44b4 136 ::WinQueryWindowText((HWND)m_hStaticMax, 300, (PSZ)zBuf);
7804d121 137 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &vFont);
70a2c656
DW
138
139 if (m_hStaticValue)
140 {
31833fd7 141 int nNewWidth = (wxMax(nMinLen, nMaxLen));
70a2c656
DW
142
143 ::WinSetWindowPos( (HWND)m_hStaticValue
144 ,HWND_TOP
145 ,(LONG)nXOffset
146 ,(LONG)nYOffset + nHeight + nCyf
147 ,(LONG)nNewWidth
148 ,(LONG)nCyf
149 ,SWP_SIZE | SWP_MOVE
150 );
151 }
152 ::WinSetWindowPos( (HWND)m_hStaticMax
153 ,HWND_TOP
154 ,(LONG)nXOffset
155 ,(LONG)nYOffset + nHeight
156 ,(LONG)nMaxLen
157 ,(LONG)nCyf
158 ,SWP_SIZE | SWP_MOVE
159 );
160 ::WinSetWindowPos( (HWND)m_hStaticMin
161 ,HWND_TOP
162 ,(LONG)nXOffset
163 ,(LONG)nYOffset - nCyf
164 ,(LONG)nMinLen
165 ,(LONG)nCyf
166 ,SWP_SIZE | SWP_MOVE
d8a3f66c
DW
167 );
168 }
169 }
d8a3f66c
DW
170} // end of wxSlider::AdjustSubControls
171
3c299c3a 172void wxSlider::ClearSel()
0e320a79 173{
3c299c3a 174} // end of wxSlider::ClearSel
0e320a79 175
3c299c3a 176void wxSlider::ClearTicks()
0e320a79 177{
3c299c3a 178} // end of wxSlider::ClearTicks
0e320a79 179
3c299c3a
DW
180void wxSlider::Command (
181 wxCommandEvent& rEvent
182)
0e320a79 183{
3c299c3a
DW
184 SetValue(rEvent.GetInt());
185 ProcessCommand(rEvent);
186} // end of wxSlider::Command
0e320a79 187
3c299c3a
DW
188bool wxSlider::ContainsHWND(
189 WXHWND hWnd
190) const
0e320a79 191{
3c299c3a
DW
192 return ( hWnd == GetStaticMin() ||
193 hWnd == GetStaticMax() ||
194 hWnd == GetEditValue()
195 );
196} // end of wxSlider::ContainsHWND
197
198bool wxSlider::Create(
199 wxWindow* pParent
200, wxWindowID vId
201, int nValue
202, int nMinValue
203, int nMaxValue
204, const wxPoint& rPos
205, const wxSize& rSize
206, long lStyle
3c299c3a 207, const wxValidator& rValidator
3c299c3a
DW
208, const wxString& rsName
209)
0e320a79 210{
3c299c3a
DW
211 int nX = rPos.x;
212 int nY = rPos.y;
213 int nWidth = rSize.x;
214 int nHeight = rSize.y;
215 long lMsStyle = 0L;
216 long lWstyle = 0L;
217
218 SetName(rsName);
219#if wxUSE_VALIDATORS
220 SetValidator(rValidator);
221#endif
222 if (pParent)
223 pParent->AddChild(this);
224 SetBackgroundColour(pParent->GetBackgroundColour()) ;
225 SetForegroundColour(pParent->GetForegroundColour()) ;
226
227 m_hStaticValue = 0L;
228 m_hStaticMin = 0L;
229 m_hStaticMax = 0L;
230 m_nPageSize = 1;
231 m_nLineSize = 1;
232 m_windowStyle = lStyle;
233 m_nTickFreq = 0;
234
1ab440bc 235 if (vId == wxID_ANY)
3c299c3a
DW
236 m_windowId = (int)NewControlId();
237 else
238 m_windowId = vId;
409c9842 239
3c299c3a
DW
240 if (m_windowStyle & wxCLIP_SIBLINGS )
241 lMsStyle |= WS_CLIPSIBLINGS;
409c9842 242
3c299c3a
DW
243 if (m_windowStyle & wxSL_LABELS)
244 {
245 lMsStyle |= WS_VISIBLE | SS_TEXT | DT_VCENTER;
246
247 m_hStaticValue = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
248 ,WC_STATIC // Window class
249 ,(PSZ)NULL // Initial Text
250 ,(ULONG)lMsStyle // Style flags
251 ,0L, 0L, 0L, 0L // Origin -- 0 size
252 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
253 ,HWND_TOP // initial z position
254 ,(ULONG)NewControlId() // Window identifier
255 ,NULL // no control data
256 ,NULL // no Presentation parameters
257 );
258
259 //
260 // Now create min static control
261 //
0fba44b4 262 wxSprintf(wxBuffer, wxT("%d"), nMinValue);
3c299c3a
DW
263 lWstyle = SS_TEXT|DT_LEFT|WS_VISIBLE;
264 if (m_windowStyle & wxCLIP_SIBLINGS)
265 lWstyle |= WS_CLIPSIBLINGS;
5d44b24e 266
3c299c3a
DW
267 m_hStaticMin = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
268 ,WC_STATIC // Window class
269 ,(PSZ)wxBuffer // Initial Text
270 ,(ULONG)lWstyle // Style flags
271 ,0L, 0L, 0L, 0L // Origin -- 0 size
272 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
273 ,HWND_TOP // initial z position
274 ,(ULONG)NewControlId() // Window identifier
275 ,NULL // no control data
276 ,NULL // no Presentation parameters
277 );
278 }
279 lMsStyle = 0;
409c9842 280
3c299c3a 281 SLDCDATA vSlData;
409c9842 282
3c299c3a
DW
283 vSlData.cbSize = sizeof(SLDCDATA);
284 if (m_windowStyle & wxSL_VERTICAL)
70a2c656 285 lMsStyle = SLS_VERTICAL | SLS_HOMEBOTTOM | WS_VISIBLE | WS_TABSTOP;
3c299c3a 286 else
9e25f509 287 lMsStyle = SLS_HORIZONTAL | SLS_HOMELEFT | WS_VISIBLE | WS_TABSTOP;
409c9842 288
3c299c3a
DW
289 if (m_windowStyle & wxCLIP_SIBLINGS)
290 lMsStyle |= WS_CLIPSIBLINGS;
409c9842 291
3c299c3a 292 if (m_windowStyle & wxSL_AUTOTICKS)
409c9842 293 {
3c299c3a
DW
294 vSlData.usScale1Spacing = 0;
295 vSlData.usScale2Spacing = 0;
296 }
409c9842 297
3c299c3a
DW
298 if (m_windowStyle & wxSL_LEFT)
299 lMsStyle |= SLS_PRIMARYSCALE2; // if SLS_VERTICAL then SCALE2 is to the left
300 else if (m_windowStyle & wxSL_RIGHT)
301 lMsStyle |= SLS_PRIMARYSCALE1; // if SLS_VERTICAL then SCALE2 is to the right
302 else if (m_windowStyle & wxSL_TOP)
303 lMsStyle |= SLS_PRIMARYSCALE1; // if SLS_HORIZONTAL then SCALE1 is to the top
304 else if (m_windowStyle & wxSL_BOTTOM )
305 lMsStyle |= SLS_PRIMARYSCALE2; // if SLS_HORIZONTAL then SCALE1 is to the bottom
306 else if ( m_windowStyle & wxSL_BOTH )
307 lMsStyle |= SLS_PRIMARYSCALE1 | SLS_PRIMARYSCALE2;
308 else
309 lMsStyle |= SLS_PRIMARYSCALE2;
70a2c656 310 lMsStyle |= SLS_RIBBONSTRIP;
3c299c3a
DW
311
312 m_nPageSize = ((nMaxValue - nMinValue)/10);
6670f564
WS
313 vSlData.usScale1Increments = (USHORT)m_nPageSize;
314 vSlData.usScale2Increments = (USHORT)m_nPageSize;
315
316 HWND hScrollBar = ::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
317 ,WC_SLIDER // Window class
318 ,(PSZ)wxBuffer // Initial Text
319 ,(ULONG)lMsStyle // Style flags
320 ,0L, 0L, 0L, 0L // Origin -- 0 size
321 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
322 ,HWND_BOTTOM // initial z position
323 ,(HMENU)m_windowId // Window identifier
324 ,&vSlData // Slider control data
325 ,NULL // no Presentation parameters
326 );
3c299c3a
DW
327 m_nRangeMax = nMaxValue;
328 m_nRangeMin = nMinValue;
329
330 //
331 // Set the size of the ticks ... default to 6 pixels
332 //
333 ::WinSendMsg( hScrollBar
334 ,SLM_SETTICKSIZE
70a2c656 335 ,MPFROM2SHORT(SMA_SETALLTICKS, (USHORT)12)
3c299c3a
DW
336 ,NULL
337 );
338 //
339 // Set the position to the initial value
340 //
341 ::WinSendMsg( hScrollBar
342 ,SLM_SETSLIDERINFO
343 ,MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE)
344 ,(MPARAM)nValue
345 );
346
347 m_hWnd = (WXHWND)hScrollBar;
348 SubclassWin(GetHWND());
349 ::WinSetWindowText((HWND)m_hWnd, "");
b3260bce 350
70a2c656 351 SetFont(*wxSMALL_FONT);
3c299c3a 352 if (m_windowStyle & wxSL_LABELS)
409c9842 353 {
3c299c3a
DW
354 //
355 // Finally, create max value static item
356 //
0fba44b4 357 wxSprintf(wxBuffer, wxT("%d"), nMaxValue);
3c299c3a
DW
358 lWstyle = SS_TEXT|DT_LEFT|WS_VISIBLE;
359 if (m_windowStyle & wxCLIP_SIBLINGS)
360 lMsStyle |= WS_CLIPSIBLINGS;
5d44b24e 361
3c299c3a
DW
362 m_hStaticMax = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
363 ,WC_STATIC // Window class
364 ,(PSZ)wxBuffer // Initial Text
365 ,(ULONG)lWstyle // Style flags
366 ,0L, 0L, 0L, 0L // Origin -- 0 size
367 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
368 ,HWND_TOP // initial z position
369 ,(ULONG)NewControlId() // Window identifier
370 ,NULL // no control data
371 ,NULL // no Presentation parameters
372 );
373 if (GetFont().Ok())
374 {
375 if (GetFont().GetResourceHandle())
376 {
377 if (m_hStaticMin)
378 wxOS2SetFont( m_hStaticMin
379 ,GetFont()
380 );
381 if (m_hStaticMax)
382 wxOS2SetFont( m_hStaticMax
383 ,GetFont()
384 );
385 if (m_hStaticValue)
386 wxOS2SetFont( m_hStaticValue
387 ,GetFont()
388 );
389 }
390 }
409c9842
DW
391 }
392
31833fd7
DW
393 SetXComp(0);
394 SetYComp(0);
3c299c3a
DW
395 SetSize( nX
396 ,nY
397 ,nWidth
398 ,nHeight
399 );
400 m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd()
401 ,SLM_QUERYSLIDERINFO
402 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
403 ,SMA_RANGEVALUE
404 )
405 ,(MPARAM)0
406 )
407 ) + 4; // for bordersizes
408
19bc1514 409 wxColour vColour(*wxBLACK);
3c299c3a 410
19bc1514 411 LONG lColor = (LONG)vColour.GetPixel();
3c299c3a
DW
412
413 ::WinSetPresParam( m_hStaticMin
414 ,PP_FOREGROUNDCOLOR
415 ,sizeof(LONG)
416 ,(PVOID)&lColor
417 );
418 ::WinSetPresParam( m_hStaticMax
419 ,PP_FOREGROUNDCOLOR
420 ,sizeof(LONG)
421 ,(PVOID)&lColor
422 );
423 ::WinSetPresParam( m_hStaticValue
424 ,PP_FOREGROUNDCOLOR
425 ,sizeof(LONG)
426 ,(PVOID)&lColor
427 );
428 ::WinSetPresParam( m_hWnd
429 ,PP_FOREGROUNDCOLOR
430 ,sizeof(LONG)
431 ,(PVOID)&lColor
432 );
7993e67c
DW
433 lColor = (LONG)m_backgroundColour.GetPixel();
434 ::WinSetPresParam( m_hStaticMin
435 ,PP_BACKGROUNDCOLOR
436 ,sizeof(LONG)
437 ,(PVOID)&lColor
438 );
439 ::WinSetPresParam( m_hStaticMax
440 ,PP_BACKGROUNDCOLOR
441 ,sizeof(LONG)
442 ,(PVOID)&lColor
443 );
444 ::WinSetPresParam( m_hStaticValue
445 ,PP_BACKGROUNDCOLOR
446 ,sizeof(LONG)
447 ,(PVOID)&lColor
448 );
449 ::WinSetPresParam( m_hWnd
450 ,PP_BACKGROUNDCOLOR
451 ,sizeof(LONG)
452 ,(PVOID)&lColor
453 );
0fba44b4 454 vColour.Set(wxString(wxT("BLUE")));
70a2c656
DW
455 lColor = (LONG)vColour.GetPixel();
456 ::WinSetPresParam( m_hWnd
457 ,PP_HILITEBACKGROUNDCOLOR
458 ,sizeof(LONG)
459 ,(PVOID)&lColor
460 );
3c299c3a 461 SetValue(nValue);
312ebad4 462 return true;
3c299c3a
DW
463} // end of wxSlider::Create
464
1ab440bc
WS
465void wxSlider::DoSetSize( int nX,
466 int nY,
467 int nWidth,
468 int nHeight,
469 int nSizeFlags )
3c299c3a 470{
1ab440bc
WS
471 int nX1 = nX;
472 int nY1 = nY;
473 int nWidth1 = nWidth;
474 int nHeight1 = nHeight;
475 int nXOffset = nX;
476 int nYOffset = nY;
477 int nCx; // slider,min,max sizes
478 int nCy;
479 int nCyf;
480 int nCurrentX;
481 int nCurrentY;
482 wxChar zBuf[300];
483 wxFont vFont = this->GetFont();
3c299c3a
DW
484
485 //
486 // Adjust for OS/2's reverse coordinate system
487 //
488 wxWindowOS2* pParent = (wxWindowOS2*)GetParent();
489 int nUsedHeight = 0;
490 int nOS2Height = nHeight;
491
492 if (nOS2Height < 0)
493 nOS2Height = 20;
3a339c0d 494 CacheBestSize(wxSize(nWidth,nOS2Height));
3c299c3a
DW
495
496 if (pParent)
409c9842 497 {
1ab440bc 498 int nOS2ParentHeight = GetOS2ParentHeight(pParent);
d8a3f66c
DW
499
500 nYOffset = nOS2ParentHeight - (nYOffset + nOS2Height);
1ab440bc 501 if (nY != wxDefaultCoord)
d8a3f66c 502 nY1 = nOS2ParentHeight - (nY1 + nOS2Height);
409c9842 503 }
3c299c3a 504 else
409c9842 505 {
1ab440bc 506 RECTL vRect;
409c9842 507
3c299c3a
DW
508 ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
509 nYOffset = vRect.yTop - (nYOffset + nOS2Height);
1ab440bc 510 if (nY != wxDefaultCoord)
3c299c3a
DW
511 nY1 = vRect.yTop - (nY1 + nOS2Height);
512 }
d8a3f66c 513 m_nSizeFlags = nSizeFlags;
409c9842 514
1ab440bc 515 GetPosition( &nCurrentX, &nCurrentY );
3c299c3a
DW
516 if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
517 nX1 = nCurrentX;
518 if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
519 nY1 = nCurrentY;
520
521 AdjustForParentClientOrigin( nX1
522 ,nY1
523 ,nSizeFlags
524 );
525 wxGetCharSize( GetHWND()
526 ,&nCx
527 ,&nCy
7804d121 528 ,&vFont
3c299c3a
DW
529 );
530
531 if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL)
409c9842 532 {
3c299c3a
DW
533 if (m_windowStyle & wxSL_LABELS )
534 {
535 int nMinLen = 0;
536 int nMaxLen = 0;
537
0fba44b4 538 ::WinQueryWindowText((HWND)m_hStaticMin, 300, (PSZ)zBuf);
7804d121 539 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &vFont);
0fba44b4 540 ::WinQueryWindowText((HWND)m_hStaticMax, 300, (PSZ)zBuf);
7804d121 541 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &vFont);
3c299c3a
DW
542
543 if (m_hStaticValue)
544 {
545 int nNewWidth = (wxMax(nMinLen, nMaxLen));
546 int nValueHeight = nCyf;
547
548 ::WinSetWindowPos( (HWND)m_hStaticValue
549 ,HWND_TOP
550 ,(LONG)nXOffset
9923c37d 551 ,(LONG)nYOffset - (LONG)(nCyf * 1.2)
3c299c3a
DW
552 ,(LONG)nNewWidth
553 ,(LONG)nValueHeight
554 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
555 );
556 nXOffset += nNewWidth + nCx;
557 }
558 ::WinSetWindowPos( (HWND)m_hStaticMin
559 ,HWND_TOP
560 ,(LONG)nXOffset
9923c37d 561 ,(LONG)nYOffset - (LONG)(nCyf * 1.2)
3c299c3a
DW
562 ,(LONG)nMinLen
563 ,(LONG)nCy
564 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
565 );
566 nXOffset += nMinLen + nCx;
567
568 int nSliderLength = nWidth1 - nXOffset - nMaxLen - nCx;
569 int nSliderHeight = nHeight1;
570
571 if (nSliderHeight < 0)
572 nSliderHeight = 20;
573
574 //
575 // Slider must have a minimum/default length/height
576 //
577 if (nSliderLength < 100)
578 nSliderLength = 100;
579
580 ::WinSetWindowPos( GetHwnd()
581 ,HWND_TOP
582 ,(LONG)nXOffset
583 ,(LONG)nYOffset
584 ,(LONG)nSliderLength
585 ,(LONG)nSliderHeight
586 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
587 );
31833fd7
DW
588 ::WinQueryWindowPos(GetHwnd(), GetSwp());
589 ::WinSendMsg( GetHwnd()
590 ,SLM_SETSLIDERINFO
591 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
592 ,0
593 )
594 ,MPFROMLONG((ULONG)(nSliderHeight/2))
595 );
3c299c3a
DW
596 nXOffset += nSliderLength + nCx;
597
598 ::WinSetWindowPos( (HWND)m_hStaticMax
599 ,HWND_TOP
600 ,(LONG)nXOffset
9923c37d 601 ,(LONG)nYOffset - (LONG)(nCyf * 1.2)
3c299c3a
DW
602 ,(LONG)nMaxLen
603 ,(LONG)nCy
604 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
605 );
606 }
607 else
608 {
609 //
610 // No labels
611 // If we're prepared to use the existing size, then...
612 //
613 if (nWidth == -1 && nHeight == -1 &&
614 ((nSizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
615 {
616 GetSize( &nWidth1
617 ,&nHeight1
618 );
619 }
620 if (nWidth1 < 0)
621 nWidth1 = 200;
622 if (nHeight1 < 0)
623 nHeight1 = 20;
624 ::WinSetWindowPos( GetHwnd()
625 ,HWND_TOP
626 ,(LONG)nX1
627 ,(LONG)nY1
628 ,(LONG)nWidth1
629 ,(LONG)nHeight1
630 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
631 );
632 }
409c9842
DW
633 }
634
3c299c3a
DW
635 //
636 // Now deal with a vertical slider
637 //
409c9842
DW
638 else
639 {
3c299c3a 640 if (m_windowStyle & wxSL_LABELS )
409c9842 641 {
3c299c3a
DW
642 int nMinLen;
643 int nMaxLen;
644
0fba44b4 645 ::WinQueryWindowText((HWND)m_hStaticMin, 300, (PSZ)zBuf);
7804d121 646 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &vFont);
0fba44b4 647 ::WinQueryWindowText((HWND)m_hStaticMax, 300, (PSZ)zBuf);
7804d121 648 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &vFont);
3c299c3a
DW
649 if (m_hStaticValue)
650 {
651 int nNewWidth = wxMax(nMinLen, nMaxLen);
652 int nValueHeight = nCyf;
653
3c299c3a
DW
654 ::WinSetWindowPos( (HWND)m_hStaticValue
655 ,HWND_TOP
656 ,(LONG)nXOffset
31833fd7 657 ,(LONG)nYOffset + nHeight
3c299c3a
DW
658 ,(LONG)nNewWidth
659 ,(LONG)nValueHeight
660 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
661 );
31833fd7 662 nUsedHeight += nCyf;
3c299c3a
DW
663 }
664 ::WinSetWindowPos( (HWND)m_hStaticMin
665 ,HWND_TOP
666 ,(LONG)nXOffset
31833fd7 667 ,(LONG)nYOffset + nHeight - nCyf
3c299c3a
DW
668 ,(LONG)nMinLen
669 ,(LONG)nCy
670 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
671 );
3c299c3a
DW
672 nUsedHeight += nCy;
673
674 int nSliderLength = nHeight1 - (nUsedHeight + (2 * nCy));
675 int nSliderWidth = nWidth1;
676
677 if (nSliderWidth < 0)
678 nSliderWidth = 20;
679
680 //
681 // Slider must have a minimum/default length
682 //
683 if (nSliderLength < 100)
684 nSliderLength = 100;
685
70a2c656 686 ::WinSetWindowPos( GetHwnd()
3c299c3a
DW
687 ,HWND_TOP
688 ,(LONG)nXOffset
31833fd7 689 ,(LONG)nYOffset + nCyf
3c299c3a
DW
690 ,(LONG)nSliderWidth
691 ,(LONG)nSliderLength
692 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
693 );
31833fd7
DW
694 ::WinQueryWindowPos(GetHwnd(), GetSwp());
695 ::WinSendMsg( GetHwnd()
696 ,SLM_SETSLIDERINFO
697 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
698 ,0
699 )
700 ,MPFROMLONG((ULONG)(nSliderWidth/2))
701 );
3c299c3a
DW
702 nUsedHeight += nSliderLength;
703 ::WinSetWindowPos( (HWND)m_hStaticMax
704 ,HWND_TOP
705 ,(LONG)nXOffset
31833fd7 706 ,(LONG)nYOffset - nCyf
3c299c3a
DW
707 ,(LONG)nMaxLen
708 ,(LONG)nCy
709 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
710 );
711 }
712 else
713 {
714 //
715 // No labels
716 // If we're prepared to use the existing size, then...
717 //
718 if (nWidth == -1 && nHeight == -1 &&
719 ((nSizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
720 {
721 GetSize( &nWidth1
722 ,&nHeight1
723 );
724 }
725 if (nWidth1 < 0)
726 nWidth1 = 20;
727 if (nHeight1 < 0)
728 nHeight1 = 200;
729 ::WinSetWindowPos( GetHwnd()
730 ,HWND_TOP
731 ,(LONG)nX1
732 ,(LONG)nY1
733 ,(LONG)nWidth1
734 ,(LONG)nHeight1
735 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
736 );
409c9842 737 }
409c9842 738 }
3c299c3a 739} // end of void wxSlider::DoSetSize
0e320a79 740
3c299c3a 741int wxSlider::GetLineSize() const
0e320a79 742{
3c299c3a
DW
743 return 1;
744} // end of wxSlider::GetLineSize
0e320a79 745
3c299c3a
DW
746int wxSlider::GetPageSize() const
747{
748 return m_nPageSize;
749} // end of wxSlider::GetPageSize
0e320a79 750
3c299c3a
DW
751void wxSlider::GetPosition(
752 int* pnX
753, int* pnY
754) const
409c9842 755{
3c299c3a
DW
756 wxWindowOS2* pParent = GetParent();
757 RECTL vRect;
758
759 vRect.xLeft = -1;
760 vRect.xRight = -1;
761 vRect.yTop = -1;
762 vRect.yBottom = -1;
763 wxFindMaxSize( GetHWND()
764 ,&vRect
765 );
766
767 if (m_hStaticMin)
768 wxFindMaxSize( m_hStaticMin
769 ,&vRect
770 );
771 if (m_hStaticMax)
772 wxFindMaxSize( m_hStaticMax
773 ,&vRect
774 );
775 if (m_hStaticValue)
776 wxFindMaxSize( m_hStaticValue
777 ,&vRect
778 );
779
780 //
781 // Since we now have the absolute screen coords,
782 // if there's a parent we must subtract its top left corner
783 //
784 POINTL vPoint;
785
786 vPoint.x = vRect.xLeft;
787 vPoint.y = vRect.yTop;
788
789 if (pParent)
790 {
791 SWP vSwp;
409c9842 792
3c299c3a
DW
793 ::WinQueryWindowPos((HWND)pParent->GetHWND(), &vSwp);
794 vPoint.x = vSwp.x;
795 vPoint.y = vSwp.y;
796 }
409c9842 797
3c299c3a
DW
798 //
799 // We may be faking the client origin.
800 // So a window that's really at (0, 30) may appear
801 // (to wxWin apps) to be at (0, 0).
802 //
803 if (GetParent())
804 {
805 wxPoint vPt(GetParent()->GetClientAreaOrigin());
409c9842 806
3c299c3a
DW
807 vPoint.x -= vPt.x;
808 vPoint.y -= vPt.y;
809 }
42782237
SN
810 if (pnX)
811 *pnX = vPoint.x;
812 if (pnY)
813 *pnY = vPoint.y;
3c299c3a 814} // end of wxSlider::GetPosition
409c9842 815
3c299c3a 816int wxSlider::GetSelEnd() const
0e320a79 817{
3c299c3a
DW
818 return 0;
819} // end of wxSlider::GetSelEnd
0e320a79 820
3c299c3a 821int wxSlider::GetSelStart() const
0e320a79 822{
3c299c3a
DW
823 return 0;
824} // end of wxSlider::GetSelStart
0e320a79 825
1cee3f60
DW
826void wxSlider::DoGetSize(
827 int* pnWidth
828, int* pnHeight
829) const
830{
831 GetSize( pnWidth
832 ,pnHeight
833 );
834} // end of wxSlider::DoGetSize
835
3c299c3a
DW
836void wxSlider::GetSize(
837 int* pnWidth
838, int* pnHeight
839) const
0e320a79 840{
3c299c3a
DW
841 RECTL vRect;
842
843 vRect.xLeft = -1;
844 vRect.xRight = -1;
845 vRect.yTop = -1;
846 vRect.yBottom = -1;
847
848 wxFindMaxSize( GetHWND()
849 ,&vRect
850 );
851
852 if (m_hStaticMin)
853 wxFindMaxSize( m_hStaticMin
854 ,&vRect
855 );
856 if (m_hStaticMax)
857 wxFindMaxSize( m_hStaticMax
858 ,&vRect
859 );
860 if (m_hStaticValue)
861 wxFindMaxSize( m_hStaticValue
862 ,&vRect
863 );
2da36bfe
SN
864 if (pnWidth)
865 *pnWidth = vRect.xRight - vRect.xLeft;
866 if (pnHeight)
867 *pnHeight = vRect.yTop - vRect.yBottom;
3c299c3a 868} // end of wxSlider::GetSize
0e320a79 869
3c299c3a 870int wxSlider::GetThumbLength() const
0e320a79 871{
3c299c3a
DW
872 return m_nThumbLength;
873} // end of wxSlider::GetThumbLength
0e320a79 874
3c299c3a 875int wxSlider::GetValue() const
0e320a79 876{
3c299c3a
DW
877 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
878 ,SLM_QUERYSLIDERINFO
879 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
880 ,SMA_RANGEVALUE
881 )
882 ,(MPARAM)0
883 )
884 );
885 double dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
886 int nNewPos = 0;
887 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
888 ,SLM_QUERYSLIDERINFO
889 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
890 ,SMA_RANGEVALUE
891 )
892 ,(MPARAM)0
893 )
894 );
895 nNewPos = (int)(nPixelPos/dPixelToRange);
896 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
897 nNewPos++;
898 return nNewPos;
899} // end of wxSlider::GetValue
900
901WXHBRUSH wxSlider::OnCtlColor(
902 WXHDC hDC
903, WXHWND hWnd
904, WXUINT uCtlColor
905, WXUINT uMessage
906, WXWPARAM wParam
907, WXLPARAM lParam
908)
0e320a79 909{
3c299c3a
DW
910 return (wxControl::OnCtlColor( hDC
911 ,hWnd
912 ,uCtlColor
913 ,uMessage
914 ,wParam
915 ,lParam
916 )
917 );
918} // end of wxSlider::OnCtlColor
919
6670f564
WS
920bool wxSlider::OS2OnScroll( int WXUNUSED(nOrientation),
921 WXWORD wParam,
922 WXWORD WXUNUSED(wPos),
923 WXHWND WXUNUSED(hControl) )
0e320a79 924{
6670f564 925 wxEventType eScrollEvent = wxEVT_NULL;
0e320a79 926
3c299c3a
DW
927 switch (wParam)
928 {
929 case SLN_CHANGE:
930 if (m_windowStyle & wxSL_TOP)
931 eScrollEvent = wxEVT_SCROLL_TOP;
932 else if (m_windowStyle & wxSL_BOTTOM)
933 eScrollEvent = wxEVT_SCROLL_BOTTOM;
934 break;
0e320a79 935
3c299c3a
DW
936 case SLN_SLIDERTRACK:
937 eScrollEvent = wxEVT_SCROLL_THUMBTRACK;
938 break;
939
940 default:
312ebad4 941 return false;
3c299c3a
DW
942 }
943
6670f564
WS
944 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
945 , SLM_QUERYSLIDERINFO
946 , MPFROM2SHORT( SMA_SHAFTDIMENSIONS, SMA_RANGEVALUE )
947 , (MPARAM)0
948 )
949 );
3c299c3a 950 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
6670f564
WS
951 int nNewPos = 0;
952 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
953 , SLM_QUERYSLIDERINFO
954 , MPFROM2SHORT( SMA_SLIDERARMPOSITION, SMA_RANGEVALUE )
955 , (MPARAM)0
956 )
957 );
958
9923c37d 959 nNewPos = (int)(nPixelPos/m_dPixelToRange);
3c299c3a
DW
960 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
961 nNewPos++;
962 if ((nNewPos < GetMin()) || (nNewPos > GetMax()))
963 {
964 //
965 // Out of range - but we did process it
966 //
312ebad4 967 return true;
3c299c3a
DW
968 }
969 SetValue(nNewPos);
970
6670f564 971 wxScrollEvent vEvent( eScrollEvent, m_windowId );
3c299c3a
DW
972
973 vEvent.SetPosition(nNewPos);
974 vEvent.SetEventObject(this);
937013e0 975 HandleWindowEvent(vEvent);
3c299c3a 976
6670f564 977 wxCommandEvent vCevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() );
3c299c3a
DW
978
979 vCevent.SetInt(nNewPos);
980 vCevent.SetEventObject(this);
937013e0 981 return (HandleWindowEvent(vCevent));
3c299c3a
DW
982} // end of wxSlider::OS2OnScroll
983
6670f564 984void wxSlider::SetLineSize( int nLineSize )
0e320a79 985{
3c299c3a
DW
986 m_nLineSize = nLineSize;
987} // end of wxSlider::SetLineSize
988
0e320a79 989
6670f564 990void wxSlider::SetPageSize( int nPageSize )
0e320a79 991{
3c299c3a
DW
992 m_nPageSize = nPageSize;
993} // end of wxSlider::SetPageSize
0e320a79 994
3c299c3a
DW
995void wxSlider::SetRange(
996 int nMinValue
997, int nMaxValue
998)
0e320a79 999{
3c299c3a
DW
1000 wxChar zBuf[10];
1001
1002 m_nRangeMin = nMinValue;
1003 m_nRangeMax = nMaxValue;
1004
1005 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1006 ,SLM_QUERYSLIDERINFO
1007 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1008 ,SMA_RANGEVALUE
1009 )
1010 ,(MPARAM)0
1011 )
1012 );
1013 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1014 if (m_hStaticMin)
1015 {
1016 wxSprintf(zBuf, wxT("%d"), m_nRangeMin);
0fba44b4 1017 ::WinSetWindowText((HWND)m_hStaticMin, (PSZ)zBuf);
3c299c3a 1018 }
0e320a79 1019
3c299c3a
DW
1020 if (m_hStaticMax)
1021 {
1022 wxSprintf(zBuf, wxT("%d"), m_nRangeMax);
0fba44b4 1023 ::WinSetWindowText((HWND)m_hStaticMax, (PSZ)zBuf);
3c299c3a
DW
1024 }
1025} // end of wxSlider::SetRange
1026
1027void wxSlider::SetSelection(
1028 int WXUNUSED(nMinPos)
1029, int WXUNUSED(nMaxPos)
1030)
0e320a79 1031{
3c299c3a 1032} // end of wxSlider::SetSelection
0e320a79 1033
3c299c3a
DW
1034void wxSlider::SetThumbLength(
1035 int nLen
1036)
0e320a79 1037{
3c299c3a
DW
1038 int nBreadth;
1039
1040 m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1041 ,SLM_QUERYSLIDERINFO
1042 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1043 ,SMA_RANGEVALUE
1044 )
1045 ,(MPARAM)0
1046 )
1047 ) + 4; // for bordersizes
1048 nBreadth = SHORT2FROMMR(::WinSendMsg( GetHwnd()
1049 ,SLM_QUERYSLIDERINFO
1050 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1051 ,SMA_RANGEVALUE
1052 )
1053 ,(MPARAM)0
1054 )
1055 );
1056 ::WinSendMsg( GetHwnd()
1057 ,SLM_SETSLIDERINFO
1058 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1059 ,SMA_RANGEVALUE
1060 )
1061 ,MPFROM2SHORT(nLen, nBreadth)
1062 );
1063 m_nThumbLength = nLen + 4; // Borders
1064} // end of wxSlider::SetThumbLength
1065
1066void wxSlider::SetTick(
1067 int nTickPos
1068)
1069{
9923c37d 1070 nTickPos = (int)(nTickPos * m_dPixelToRange);
3c299c3a
DW
1071 ::WinSendMsg( GetHwnd()
1072 ,SLM_ADDDETENT
1073 ,MPFROMSHORT(nTickPos)
1074 ,NULL
1075 );
1076} // end of wxSlider::SetTick
0e320a79 1077
3c299c3a 1078// For trackbars only
6670f564 1079void wxSlider::SetTickFreq( int n, int WXUNUSED(nPos) )
409c9842 1080{
6670f564
WS
1081 SLDCDATA vSlData;
1082 WNDPARAMS vWndParams;
1083 int nPixelPos;
1084 int i;
409c9842 1085
3c299c3a
DW
1086 vSlData.cbSize = sizeof(SLDCDATA);
1087 if (m_windowStyle & wxSL_AUTOTICKS)
1088 {
1089 vSlData.usScale1Spacing = 0;
1090 vSlData.usScale2Spacing = 0;
1091 }
6670f564
WS
1092 vSlData.usScale1Increments = (USHORT)((m_nRangeMax - m_nRangeMin)/n);
1093 vSlData.usScale2Increments = (USHORT)((m_nRangeMax - m_nRangeMin)/n);
3c299c3a
DW
1094
1095 vWndParams.fsStatus = WPM_CTLDATA;
1096 vWndParams.cchText = 0L;
1097 vWndParams.pszText = NULL;
1098 vWndParams.cbPresParams = 0L;
1099 vWndParams.pPresParams = NULL;
1100 vWndParams.cbCtlData = vSlData.cbSize;
1101 vWndParams.pCtlData = (PVOID)&vSlData;
1102 ::WinSendMsg(GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vWndParams, (MPARAM)0);
1103 for (i = 1; i < (m_nRangeMax - m_nRangeMin)/n; i++)
1104 {
9923c37d 1105 nPixelPos = (int)(i * n * m_dPixelToRange);
3c299c3a
DW
1106 ::WinSendMsg( GetHwnd()
1107 ,SLM_ADDDETENT
1108 ,MPFROMSHORT(nPixelPos)
1109 ,NULL
1110 );
1111 }
1112} // end of wxSlider::SetTickFreq
1113
1114void wxSlider::SetValue(
1115 int nValue
1116)
0e320a79 1117{
3c299c3a
DW
1118 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1119 ,SLM_QUERYSLIDERINFO
1120 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1121 ,SMA_RANGEVALUE
1122 )
1123 ,(MPARAM)0
1124 )
1125 );
1126 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1127 int nNewPos = (int)(nValue * m_dPixelToRange);
1128
1129 ::WinSendMsg( GetHwnd()
1130 ,SLM_SETSLIDERINFO
1131 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
1132 ,SMA_RANGEVALUE
1133 )
1134 ,(MPARAM)nNewPos
1135 );
1136 if (m_hStaticValue)
1137 {
1138 wxSprintf(wxBuffer, wxT("%d"), nValue);
0fba44b4 1139 ::WinSetWindowText((HWND)m_hStaticValue, (PSZ)wxBuffer);
3c299c3a
DW
1140 }
1141} // end of wxSlider::SetValue
0e320a79 1142
3c299c3a
DW
1143bool wxSlider::Show(
1144 bool bShow
1145)
0e320a79 1146{
3c299c3a
DW
1147 wxWindowOS2::Show(bShow);
1148 if(m_hStaticValue)
1149 ::WinShowWindow((HWND)m_hStaticValue, bShow);
1150 if(m_hStaticMin)
1151 ::WinShowWindow((HWND)m_hStaticMin, bShow);
1152 if(m_hStaticMax)
1153 ::WinShowWindow((HWND)m_hStaticMax, bShow);
312ebad4 1154 return true;
3c299c3a 1155} // end of wxSlider::Show
0e320a79 1156
312ebad4 1157#endif // wxUSE_SLIDER