]> git.saurik.com Git - wxWidgets.git/blame - src/os2/slider.cpp
Call wxThread::Create() from Run() automatically.
[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);
3c299c3a
DW
884 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
885 ,SLM_QUERYSLIDERINFO
886 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
887 ,SMA_RANGEVALUE
888 )
889 ,(MPARAM)0
890 )
891 );
bdc43642 892 int nNewPos = (int)(nPixelPos/dPixelToRange);
3c299c3a
DW
893 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
894 nNewPos++;
895 return nNewPos;
896} // end of wxSlider::GetValue
897
898WXHBRUSH wxSlider::OnCtlColor(
899 WXHDC hDC
900, WXHWND hWnd
901, WXUINT uCtlColor
902, WXUINT uMessage
903, WXWPARAM wParam
904, WXLPARAM lParam
905)
0e320a79 906{
3c299c3a
DW
907 return (wxControl::OnCtlColor( hDC
908 ,hWnd
909 ,uCtlColor
910 ,uMessage
911 ,wParam
912 ,lParam
913 )
914 );
915} // end of wxSlider::OnCtlColor
916
6670f564
WS
917bool wxSlider::OS2OnScroll( int WXUNUSED(nOrientation),
918 WXWORD wParam,
919 WXWORD WXUNUSED(wPos),
920 WXHWND WXUNUSED(hControl) )
0e320a79 921{
6670f564 922 wxEventType eScrollEvent = wxEVT_NULL;
0e320a79 923
3c299c3a
DW
924 switch (wParam)
925 {
926 case SLN_CHANGE:
927 if (m_windowStyle & wxSL_TOP)
928 eScrollEvent = wxEVT_SCROLL_TOP;
929 else if (m_windowStyle & wxSL_BOTTOM)
930 eScrollEvent = wxEVT_SCROLL_BOTTOM;
931 break;
0e320a79 932
3c299c3a
DW
933 case SLN_SLIDERTRACK:
934 eScrollEvent = wxEVT_SCROLL_THUMBTRACK;
935 break;
936
937 default:
312ebad4 938 return false;
3c299c3a
DW
939 }
940
6670f564
WS
941 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
942 , SLM_QUERYSLIDERINFO
943 , MPFROM2SHORT( SMA_SHAFTDIMENSIONS, SMA_RANGEVALUE )
944 , (MPARAM)0
945 )
946 );
3c299c3a 947 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
6670f564
WS
948 int nNewPos = 0;
949 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
950 , SLM_QUERYSLIDERINFO
951 , MPFROM2SHORT( SMA_SLIDERARMPOSITION, SMA_RANGEVALUE )
952 , (MPARAM)0
953 )
954 );
955
9923c37d 956 nNewPos = (int)(nPixelPos/m_dPixelToRange);
3c299c3a
DW
957 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
958 nNewPos++;
959 if ((nNewPos < GetMin()) || (nNewPos > GetMax()))
960 {
961 //
962 // Out of range - but we did process it
963 //
312ebad4 964 return true;
3c299c3a
DW
965 }
966 SetValue(nNewPos);
967
6670f564 968 wxScrollEvent vEvent( eScrollEvent, m_windowId );
3c299c3a
DW
969
970 vEvent.SetPosition(nNewPos);
971 vEvent.SetEventObject(this);
937013e0 972 HandleWindowEvent(vEvent);
3c299c3a 973
ce7fe42e 974 wxCommandEvent vCevent( wxEVT_SLIDER, GetId() );
3c299c3a
DW
975
976 vCevent.SetInt(nNewPos);
977 vCevent.SetEventObject(this);
937013e0 978 return (HandleWindowEvent(vCevent));
3c299c3a
DW
979} // end of wxSlider::OS2OnScroll
980
6670f564 981void wxSlider::SetLineSize( int nLineSize )
0e320a79 982{
3c299c3a
DW
983 m_nLineSize = nLineSize;
984} // end of wxSlider::SetLineSize
985
0e320a79 986
6670f564 987void wxSlider::SetPageSize( int nPageSize )
0e320a79 988{
3c299c3a
DW
989 m_nPageSize = nPageSize;
990} // end of wxSlider::SetPageSize
0e320a79 991
3c299c3a
DW
992void wxSlider::SetRange(
993 int nMinValue
994, int nMaxValue
995)
0e320a79 996{
3c299c3a
DW
997 wxChar zBuf[10];
998
999 m_nRangeMin = nMinValue;
1000 m_nRangeMax = nMaxValue;
1001
1002 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1003 ,SLM_QUERYSLIDERINFO
1004 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1005 ,SMA_RANGEVALUE
1006 )
1007 ,(MPARAM)0
1008 )
1009 );
1010 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1011 if (m_hStaticMin)
1012 {
1013 wxSprintf(zBuf, wxT("%d"), m_nRangeMin);
0fba44b4 1014 ::WinSetWindowText((HWND)m_hStaticMin, (PSZ)zBuf);
3c299c3a 1015 }
0e320a79 1016
3c299c3a
DW
1017 if (m_hStaticMax)
1018 {
1019 wxSprintf(zBuf, wxT("%d"), m_nRangeMax);
0fba44b4 1020 ::WinSetWindowText((HWND)m_hStaticMax, (PSZ)zBuf);
3c299c3a
DW
1021 }
1022} // end of wxSlider::SetRange
1023
1024void wxSlider::SetSelection(
1025 int WXUNUSED(nMinPos)
1026, int WXUNUSED(nMaxPos)
1027)
0e320a79 1028{
3c299c3a 1029} // end of wxSlider::SetSelection
0e320a79 1030
3c299c3a
DW
1031void wxSlider::SetThumbLength(
1032 int nLen
1033)
0e320a79 1034{
3c299c3a
DW
1035 int nBreadth;
1036
1037 m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1038 ,SLM_QUERYSLIDERINFO
1039 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1040 ,SMA_RANGEVALUE
1041 )
1042 ,(MPARAM)0
1043 )
1044 ) + 4; // for bordersizes
1045 nBreadth = SHORT2FROMMR(::WinSendMsg( GetHwnd()
1046 ,SLM_QUERYSLIDERINFO
1047 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1048 ,SMA_RANGEVALUE
1049 )
1050 ,(MPARAM)0
1051 )
1052 );
1053 ::WinSendMsg( GetHwnd()
1054 ,SLM_SETSLIDERINFO
1055 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1056 ,SMA_RANGEVALUE
1057 )
1058 ,MPFROM2SHORT(nLen, nBreadth)
1059 );
1060 m_nThumbLength = nLen + 4; // Borders
1061} // end of wxSlider::SetThumbLength
1062
1063void wxSlider::SetTick(
1064 int nTickPos
1065)
1066{
9923c37d 1067 nTickPos = (int)(nTickPos * m_dPixelToRange);
3c299c3a
DW
1068 ::WinSendMsg( GetHwnd()
1069 ,SLM_ADDDETENT
1070 ,MPFROMSHORT(nTickPos)
1071 ,NULL
1072 );
1073} // end of wxSlider::SetTick
0e320a79 1074
3c299c3a 1075// For trackbars only
0a12e013 1076void wxSlider::DoSetTickFreq( int n )
409c9842 1077{
6670f564
WS
1078 SLDCDATA vSlData;
1079 WNDPARAMS vWndParams;
1080 int nPixelPos;
1081 int i;
409c9842 1082
3c299c3a
DW
1083 vSlData.cbSize = sizeof(SLDCDATA);
1084 if (m_windowStyle & wxSL_AUTOTICKS)
1085 {
1086 vSlData.usScale1Spacing = 0;
1087 vSlData.usScale2Spacing = 0;
1088 }
6670f564
WS
1089 vSlData.usScale1Increments = (USHORT)((m_nRangeMax - m_nRangeMin)/n);
1090 vSlData.usScale2Increments = (USHORT)((m_nRangeMax - m_nRangeMin)/n);
3c299c3a
DW
1091
1092 vWndParams.fsStatus = WPM_CTLDATA;
1093 vWndParams.cchText = 0L;
1094 vWndParams.pszText = NULL;
1095 vWndParams.cbPresParams = 0L;
1096 vWndParams.pPresParams = NULL;
1097 vWndParams.cbCtlData = vSlData.cbSize;
1098 vWndParams.pCtlData = (PVOID)&vSlData;
1099 ::WinSendMsg(GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vWndParams, (MPARAM)0);
1100 for (i = 1; i < (m_nRangeMax - m_nRangeMin)/n; i++)
1101 {
9923c37d 1102 nPixelPos = (int)(i * n * m_dPixelToRange);
3c299c3a
DW
1103 ::WinSendMsg( GetHwnd()
1104 ,SLM_ADDDETENT
1105 ,MPFROMSHORT(nPixelPos)
1106 ,NULL
1107 );
1108 }
1109} // end of wxSlider::SetTickFreq
1110
1111void wxSlider::SetValue(
1112 int nValue
1113)
0e320a79 1114{
3c299c3a
DW
1115 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1116 ,SLM_QUERYSLIDERINFO
1117 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1118 ,SMA_RANGEVALUE
1119 )
1120 ,(MPARAM)0
1121 )
1122 );
1123 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1124 int nNewPos = (int)(nValue * m_dPixelToRange);
1125
1126 ::WinSendMsg( GetHwnd()
1127 ,SLM_SETSLIDERINFO
1128 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
1129 ,SMA_RANGEVALUE
1130 )
1131 ,(MPARAM)nNewPos
1132 );
1133 if (m_hStaticValue)
1134 {
1135 wxSprintf(wxBuffer, wxT("%d"), nValue);
0fba44b4 1136 ::WinSetWindowText((HWND)m_hStaticValue, (PSZ)wxBuffer);
3c299c3a
DW
1137 }
1138} // end of wxSlider::SetValue
0e320a79 1139
3c299c3a
DW
1140bool wxSlider::Show(
1141 bool bShow
1142)
0e320a79 1143{
3c299c3a
DW
1144 wxWindowOS2::Show(bShow);
1145 if(m_hStaticValue)
1146 ::WinShowWindow((HWND)m_hStaticValue, bShow);
1147 if(m_hStaticMin)
1148 ::WinShowWindow((HWND)m_hStaticMin, bShow);
1149 if(m_hStaticMax)
1150 ::WinShowWindow((HWND)m_hStaticMax, bShow);
312ebad4 1151 return true;
3c299c3a 1152} // end of wxSlider::Show
0e320a79 1153
312ebad4 1154#endif // wxUSE_SLIDER