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