]> git.saurik.com Git - wxWidgets.git/blame - src/os2/slider.cpp
Added debug unicode config
[wxWidgets.git] / src / os2 / slider.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: slider.cpp
3// Purpose: wxSlider
409c9842 4// Author: David Webster
0e320a79 5// Modified by:
409c9842 6// Created: 10/15/99
0e320a79 7// RCS-ID: $Id$
409c9842
DW
8// Copyright: (c) David Webster
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
20#include <stdio.h>
21#include <wx/utils.h>
22#include <wx/brush.h>
a4a16252 23#include <wx/scrolwin.h>
0e320a79
DW
24#endif
25
26#include "wx/slider.h"
409c9842 27#include "wx/os2/private.h"
0e320a79 28
0e320a79
DW
29IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
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
d8a3f66c
DW
53void wxSlider::AdjustSubControls(
54 int nX
55, int nY
56, int nWidth
57, int nHeight
58, int nSizeFlags
59)
60{
61 SWP vSwp;
62 int nXOffset = nX;
63 int nYOffset = nY;
64 int nCx; // slider,min,max sizes
65 int nCy;
66 int nCyf;
67 char zBuf[300];
68
69 wxGetCharSize( GetHWND()
70 ,&nCx
71 ,&nCy
72 ,&this->GetFont()
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
82 ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf);
83 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont());
84
85 ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
86 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont());
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
133 ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf);
31833fd7 134 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont());
70a2c656
DW
135
136 ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
31833fd7 137 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont());
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
235 if (vId == -1)
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 //
262 sprintf(wxBuffer, "%d", nMinValue);
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);
313 vSlData.usScale1Increments = m_nPageSize;
314 vSlData.usScale2Increments = 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
757cc9de 322 ,HWND_BOTTOM // initial z position
3c299c3a
DW
323 ,(HMENU)m_windowId // Window identifier
324 ,&vSlData // Slider control data
325 ,NULL // no Presentation parameters
326 );
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 //
357 sprintf(wxBuffer, "%d", nMaxValue);
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
409 wxColour vColour;
410
411 vColour.Set(wxString("BLACK"));
412
413 LONG lColor = (LONG)vColour.GetPixel();
414
415 ::WinSetPresParam( m_hStaticMin
416 ,PP_FOREGROUNDCOLOR
417 ,sizeof(LONG)
418 ,(PVOID)&lColor
419 );
420 ::WinSetPresParam( m_hStaticMax
421 ,PP_FOREGROUNDCOLOR
422 ,sizeof(LONG)
423 ,(PVOID)&lColor
424 );
425 ::WinSetPresParam( m_hStaticValue
426 ,PP_FOREGROUNDCOLOR
427 ,sizeof(LONG)
428 ,(PVOID)&lColor
429 );
430 ::WinSetPresParam( m_hWnd
431 ,PP_FOREGROUNDCOLOR
432 ,sizeof(LONG)
433 ,(PVOID)&lColor
434 );
7993e67c
DW
435 lColor = (LONG)m_backgroundColour.GetPixel();
436 ::WinSetPresParam( m_hStaticMin
437 ,PP_BACKGROUNDCOLOR
438 ,sizeof(LONG)
439 ,(PVOID)&lColor
440 );
441 ::WinSetPresParam( m_hStaticMax
442 ,PP_BACKGROUNDCOLOR
443 ,sizeof(LONG)
444 ,(PVOID)&lColor
445 );
446 ::WinSetPresParam( m_hStaticValue
447 ,PP_BACKGROUNDCOLOR
448 ,sizeof(LONG)
449 ,(PVOID)&lColor
450 );
451 ::WinSetPresParam( m_hWnd
452 ,PP_BACKGROUNDCOLOR
453 ,sizeof(LONG)
454 ,(PVOID)&lColor
455 );
70a2c656
DW
456 vColour.Set(wxString("BLUE"));
457 lColor = (LONG)vColour.GetPixel();
458 ::WinSetPresParam( m_hWnd
459 ,PP_HILITEBACKGROUNDCOLOR
460 ,sizeof(LONG)
461 ,(PVOID)&lColor
462 );
3c299c3a
DW
463 SetValue(nValue);
464 return TRUE;
465} // end of wxSlider::Create
466
467void wxSlider::DoSetSize(
468 int nX
469, int nY
470, int nWidth
471, int nHeight
472, int nSizeFlags
473)
474{
475 int nX1 = nX;
476 int nY1 = nY;
477 int nWidth1 = nWidth;
478 int nHeight1 = nHeight;
479 int nXOffset = nX;
480 int nYOffset = nY;
481 int nCx; // slider,min,max sizes
482 int nCy;
483 int nCyf;
484 int nCurrentX;
485 int nCurrentY;
486 char zBuf[300];
487
488 //
489 // Adjust for OS/2's reverse coordinate system
490 //
491 wxWindowOS2* pParent = (wxWindowOS2*)GetParent();
492 int nUsedHeight = 0;
493 int nOS2Height = nHeight;
494
495 if (nOS2Height < 0)
496 nOS2Height = 20;
497
498 if (pParent)
409c9842 499 {
d8a3f66c
DW
500 int nOS2ParentHeight = GetOS2ParentHeight(pParent);
501
502 nYOffset = nOS2ParentHeight - (nYOffset + nOS2Height);
503 if (nY != -1)
504 nY1 = nOS2ParentHeight - (nY1 + nOS2Height);
409c9842 505 }
3c299c3a 506 else
409c9842 507 {
3c299c3a 508 RECTL vRect;
409c9842 509
3c299c3a
DW
510 ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
511 nYOffset = vRect.yTop - (nYOffset + nOS2Height);
512 if (nY != -1)
513 nY1 = vRect.yTop - (nY1 + nOS2Height);
514 }
d8a3f66c 515 m_nSizeFlags = nSizeFlags;
409c9842 516
3c299c3a
DW
517 GetPosition( &nCurrentX
518 ,&nCurrentY
519 );
520 if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
521 nX1 = nCurrentX;
522 if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
523 nY1 = nCurrentY;
524
525 AdjustForParentClientOrigin( nX1
526 ,nY1
527 ,nSizeFlags
528 );
529 wxGetCharSize( GetHWND()
530 ,&nCx
531 ,&nCy
532 ,&this->GetFont()
533 );
534
535 if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL)
409c9842 536 {
3c299c3a
DW
537 if (m_windowStyle & wxSL_LABELS )
538 {
539 int nMinLen = 0;
540 int nMaxLen = 0;
541
542 ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf);
543 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont());
544 ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
545 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont());
546
547 if (m_hStaticValue)
548 {
549 int nNewWidth = (wxMax(nMinLen, nMaxLen));
550 int nValueHeight = nCyf;
551
552 ::WinSetWindowPos( (HWND)m_hStaticValue
553 ,HWND_TOP
554 ,(LONG)nXOffset
555 ,(LONG)nYOffset - (nCyf * 1.2)
556 ,(LONG)nNewWidth
557 ,(LONG)nValueHeight
558 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
559 );
560 nXOffset += nNewWidth + nCx;
561 }
562 ::WinSetWindowPos( (HWND)m_hStaticMin
563 ,HWND_TOP
564 ,(LONG)nXOffset
70a2c656 565 ,(LONG)nYOffset - (nCyf * 1.2)
3c299c3a
DW
566 ,(LONG)nMinLen
567 ,(LONG)nCy
568 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
569 );
570 nXOffset += nMinLen + nCx;
571
572 int nSliderLength = nWidth1 - nXOffset - nMaxLen - nCx;
573 int nSliderHeight = nHeight1;
574
575 if (nSliderHeight < 0)
576 nSliderHeight = 20;
577
578 //
579 // Slider must have a minimum/default length/height
580 //
581 if (nSliderLength < 100)
582 nSliderLength = 100;
583
584 ::WinSetWindowPos( GetHwnd()
585 ,HWND_TOP
586 ,(LONG)nXOffset
587 ,(LONG)nYOffset
588 ,(LONG)nSliderLength
589 ,(LONG)nSliderHeight
590 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
591 );
31833fd7
DW
592 ::WinQueryWindowPos(GetHwnd(), GetSwp());
593 ::WinSendMsg( GetHwnd()
594 ,SLM_SETSLIDERINFO
595 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
596 ,0
597 )
598 ,MPFROMLONG((ULONG)(nSliderHeight/2))
599 );
3c299c3a
DW
600 nXOffset += nSliderLength + nCx;
601
602 ::WinSetWindowPos( (HWND)m_hStaticMax
603 ,HWND_TOP
604 ,(LONG)nXOffset
70a2c656 605 ,(LONG)nYOffset - (nCyf * 1.2)
3c299c3a
DW
606 ,(LONG)nMaxLen
607 ,(LONG)nCy
608 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
609 );
610 }
611 else
612 {
613 //
614 // No labels
615 // If we're prepared to use the existing size, then...
616 //
617 if (nWidth == -1 && nHeight == -1 &&
618 ((nSizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
619 {
620 GetSize( &nWidth1
621 ,&nHeight1
622 );
623 }
624 if (nWidth1 < 0)
625 nWidth1 = 200;
626 if (nHeight1 < 0)
627 nHeight1 = 20;
628 ::WinSetWindowPos( GetHwnd()
629 ,HWND_TOP
630 ,(LONG)nX1
631 ,(LONG)nY1
632 ,(LONG)nWidth1
633 ,(LONG)nHeight1
634 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
635 );
636 }
409c9842
DW
637 }
638
3c299c3a
DW
639 //
640 // Now deal with a vertical slider
641 //
409c9842
DW
642 else
643 {
3c299c3a 644 if (m_windowStyle & wxSL_LABELS )
409c9842 645 {
3c299c3a
DW
646 int nMinLen;
647 int nMaxLen;
648
649 ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf);
650 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont());
651 ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
652 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont());
653 if (m_hStaticValue)
654 {
655 int nNewWidth = wxMax(nMinLen, nMaxLen);
656 int nValueHeight = nCyf;
657
3c299c3a
DW
658 ::WinSetWindowPos( (HWND)m_hStaticValue
659 ,HWND_TOP
660 ,(LONG)nXOffset
31833fd7 661 ,(LONG)nYOffset + nHeight
3c299c3a
DW
662 ,(LONG)nNewWidth
663 ,(LONG)nValueHeight
664 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
665 );
31833fd7 666 nUsedHeight += nCyf;
3c299c3a
DW
667 }
668 ::WinSetWindowPos( (HWND)m_hStaticMin
669 ,HWND_TOP
670 ,(LONG)nXOffset
31833fd7 671 ,(LONG)nYOffset + nHeight - nCyf
3c299c3a
DW
672 ,(LONG)nMinLen
673 ,(LONG)nCy
674 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
675 );
3c299c3a
DW
676 nUsedHeight += nCy;
677
678 int nSliderLength = nHeight1 - (nUsedHeight + (2 * nCy));
679 int nSliderWidth = nWidth1;
680
681 if (nSliderWidth < 0)
682 nSliderWidth = 20;
683
684 //
685 // Slider must have a minimum/default length
686 //
687 if (nSliderLength < 100)
688 nSliderLength = 100;
689
70a2c656 690 ::WinSetWindowPos( GetHwnd()
3c299c3a
DW
691 ,HWND_TOP
692 ,(LONG)nXOffset
31833fd7 693 ,(LONG)nYOffset + nCyf
3c299c3a
DW
694 ,(LONG)nSliderWidth
695 ,(LONG)nSliderLength
696 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
697 );
31833fd7
DW
698 ::WinQueryWindowPos(GetHwnd(), GetSwp());
699 ::WinSendMsg( GetHwnd()
700 ,SLM_SETSLIDERINFO
701 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
702 ,0
703 )
704 ,MPFROMLONG((ULONG)(nSliderWidth/2))
705 );
3c299c3a
DW
706 nUsedHeight += nSliderLength;
707 ::WinSetWindowPos( (HWND)m_hStaticMax
708 ,HWND_TOP
709 ,(LONG)nXOffset
31833fd7 710 ,(LONG)nYOffset - nCyf
3c299c3a
DW
711 ,(LONG)nMaxLen
712 ,(LONG)nCy
713 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
714 );
715 }
716 else
717 {
718 //
719 // No labels
720 // If we're prepared to use the existing size, then...
721 //
722 if (nWidth == -1 && nHeight == -1 &&
723 ((nSizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
724 {
725 GetSize( &nWidth1
726 ,&nHeight1
727 );
728 }
729 if (nWidth1 < 0)
730 nWidth1 = 20;
731 if (nHeight1 < 0)
732 nHeight1 = 200;
733 ::WinSetWindowPos( GetHwnd()
734 ,HWND_TOP
735 ,(LONG)nX1
736 ,(LONG)nY1
737 ,(LONG)nWidth1
738 ,(LONG)nHeight1
739 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
740 );
409c9842 741 }
409c9842 742 }
3c299c3a 743} // end of void wxSlider::DoSetSize
0e320a79 744
3c299c3a 745int wxSlider::GetLineSize() const
0e320a79 746{
3c299c3a
DW
747 return 1;
748} // end of wxSlider::GetLineSize
0e320a79 749
3c299c3a
DW
750int wxSlider::GetPageSize() const
751{
752 return m_nPageSize;
753} // end of wxSlider::GetPageSize
0e320a79 754
3c299c3a
DW
755void wxSlider::GetPosition(
756 int* pnX
757, int* pnY
758) const
409c9842 759{
3c299c3a
DW
760 wxWindowOS2* pParent = GetParent();
761 RECTL vRect;
762
763 vRect.xLeft = -1;
764 vRect.xRight = -1;
765 vRect.yTop = -1;
766 vRect.yBottom = -1;
767 wxFindMaxSize( GetHWND()
768 ,&vRect
769 );
770
771 if (m_hStaticMin)
772 wxFindMaxSize( m_hStaticMin
773 ,&vRect
774 );
775 if (m_hStaticMax)
776 wxFindMaxSize( m_hStaticMax
777 ,&vRect
778 );
779 if (m_hStaticValue)
780 wxFindMaxSize( m_hStaticValue
781 ,&vRect
782 );
783
784 //
785 // Since we now have the absolute screen coords,
786 // if there's a parent we must subtract its top left corner
787 //
788 POINTL vPoint;
789
790 vPoint.x = vRect.xLeft;
791 vPoint.y = vRect.yTop;
792
793 if (pParent)
794 {
795 SWP vSwp;
409c9842 796
3c299c3a
DW
797 ::WinQueryWindowPos((HWND)pParent->GetHWND(), &vSwp);
798 vPoint.x = vSwp.x;
799 vPoint.y = vSwp.y;
800 }
409c9842 801
3c299c3a
DW
802 //
803 // We may be faking the client origin.
804 // So a window that's really at (0, 30) may appear
805 // (to wxWin apps) to be at (0, 0).
806 //
807 if (GetParent())
808 {
809 wxPoint vPt(GetParent()->GetClientAreaOrigin());
409c9842 810
3c299c3a
DW
811 vPoint.x -= vPt.x;
812 vPoint.y -= vPt.y;
813 }
814 *pnX = vPoint.x;
815 *pnY = vPoint.y;
816} // end of wxSlider::GetPosition
409c9842 817
3c299c3a 818int wxSlider::GetSelEnd() const
0e320a79 819{
3c299c3a
DW
820 return 0;
821} // end of wxSlider::GetSelEnd
0e320a79 822
3c299c3a 823int wxSlider::GetSelStart() const
0e320a79 824{
3c299c3a
DW
825 return 0;
826} // end of wxSlider::GetSelStart
0e320a79 827
1cee3f60
DW
828void wxSlider::DoGetSize(
829 int* pnWidth
830, int* pnHeight
831) const
832{
833 GetSize( pnWidth
834 ,pnHeight
835 );
836} // end of wxSlider::DoGetSize
837
3c299c3a
DW
838void wxSlider::GetSize(
839 int* pnWidth
840, int* pnHeight
841) const
0e320a79 842{
3c299c3a
DW
843 RECTL vRect;
844
845 vRect.xLeft = -1;
846 vRect.xRight = -1;
847 vRect.yTop = -1;
848 vRect.yBottom = -1;
849
850 wxFindMaxSize( GetHWND()
851 ,&vRect
852 );
853
854 if (m_hStaticMin)
855 wxFindMaxSize( m_hStaticMin
856 ,&vRect
857 );
858 if (m_hStaticMax)
859 wxFindMaxSize( m_hStaticMax
860 ,&vRect
861 );
862 if (m_hStaticValue)
863 wxFindMaxSize( m_hStaticValue
864 ,&vRect
865 );
866 *pnWidth = vRect.xRight - vRect.xLeft;
867 *pnHeight = vRect.yBottom - vRect.yTop;
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
920bool wxSlider::OS2OnScroll(
921 int WXUNUSED(nOrientation)
922, WXWORD wParam
923, WXWORD wPos
924, WXHWND hControl
925)
0e320a79 926{
3c299c3a 927 wxEventType eScrollEvent = wxEVT_NULL;
0e320a79 928
3c299c3a
DW
929 switch (wParam)
930 {
931 case SLN_CHANGE:
932 if (m_windowStyle & wxSL_TOP)
933 eScrollEvent = wxEVT_SCROLL_TOP;
934 else if (m_windowStyle & wxSL_BOTTOM)
935 eScrollEvent = wxEVT_SCROLL_BOTTOM;
936 break;
0e320a79 937
3c299c3a
DW
938 case SLN_SLIDERTRACK:
939 eScrollEvent = wxEVT_SCROLL_THUMBTRACK;
940 break;
941
942 default:
943 return FALSE;
944 }
945
946 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
947 ,SLM_QUERYSLIDERINFO
948 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
949 ,SMA_RANGEVALUE
950 )
951 ,(MPARAM)0
952 )
953 );
954 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
955 int nNewPos = 0;
956 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
957 ,SLM_QUERYSLIDERINFO
958 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
959 ,SMA_RANGEVALUE
960 )
961 ,(MPARAM)0
962 )
963 );
964 nNewPos = (nPixelPos/m_dPixelToRange);
965 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
966 nNewPos++;
967 if ((nNewPos < GetMin()) || (nNewPos > GetMax()))
968 {
969 //
970 // Out of range - but we did process it
971 //
972 return TRUE;
973 }
974 SetValue(nNewPos);
975
976 wxScrollEvent vEvent( eScrollEvent
977 ,m_windowId
978 );
979
980 vEvent.SetPosition(nNewPos);
981 vEvent.SetEventObject(this);
982 GetEventHandler()->ProcessEvent(vEvent);
983
984 wxCommandEvent vCevent( wxEVT_COMMAND_SLIDER_UPDATED
985 ,GetId()
986 );
987
988 vCevent.SetInt(nNewPos);
989 vCevent.SetEventObject(this);
990 return (GetEventHandler()->ProcessEvent(vCevent));
991} // end of wxSlider::OS2OnScroll
992
993void wxSlider::SetLineSize(
994 int nLineSize
995)
0e320a79 996{
3c299c3a
DW
997 m_nLineSize = nLineSize;
998} // end of wxSlider::SetLineSize
999
0e320a79 1000
3c299c3a
DW
1001void wxSlider::SetPageSize(
1002 int nPageSize
1003)
0e320a79 1004{
3c299c3a
DW
1005 m_nPageSize = nPageSize;
1006} // end of wxSlider::SetPageSize
0e320a79 1007
3c299c3a
DW
1008void wxSlider::SetRange(
1009 int nMinValue
1010, int nMaxValue
1011)
0e320a79 1012{
3c299c3a
DW
1013 wxChar zBuf[10];
1014
1015 m_nRangeMin = nMinValue;
1016 m_nRangeMax = nMaxValue;
1017
1018 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1019 ,SLM_QUERYSLIDERINFO
1020 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1021 ,SMA_RANGEVALUE
1022 )
1023 ,(MPARAM)0
1024 )
1025 );
1026 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1027 if (m_hStaticMin)
1028 {
1029 wxSprintf(zBuf, wxT("%d"), m_nRangeMin);
1030 ::WinSetWindowText((HWND)m_hStaticMin, zBuf);
1031 }
0e320a79 1032
3c299c3a
DW
1033 if (m_hStaticMax)
1034 {
1035 wxSprintf(zBuf, wxT("%d"), m_nRangeMax);
1036 ::WinSetWindowText((HWND)m_hStaticMax, zBuf);
1037 }
1038} // end of wxSlider::SetRange
1039
1040void wxSlider::SetSelection(
1041 int WXUNUSED(nMinPos)
1042, int WXUNUSED(nMaxPos)
1043)
0e320a79 1044{
3c299c3a 1045} // end of wxSlider::SetSelection
0e320a79 1046
3c299c3a
DW
1047void wxSlider::SetThumbLength(
1048 int nLen
1049)
0e320a79 1050{
3c299c3a
DW
1051 int nBreadth;
1052
1053 m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1054 ,SLM_QUERYSLIDERINFO
1055 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1056 ,SMA_RANGEVALUE
1057 )
1058 ,(MPARAM)0
1059 )
1060 ) + 4; // for bordersizes
1061 nBreadth = SHORT2FROMMR(::WinSendMsg( GetHwnd()
1062 ,SLM_QUERYSLIDERINFO
1063 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1064 ,SMA_RANGEVALUE
1065 )
1066 ,(MPARAM)0
1067 )
1068 );
1069 ::WinSendMsg( GetHwnd()
1070 ,SLM_SETSLIDERINFO
1071 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1072 ,SMA_RANGEVALUE
1073 )
1074 ,MPFROM2SHORT(nLen, nBreadth)
1075 );
1076 m_nThumbLength = nLen + 4; // Borders
1077} // end of wxSlider::SetThumbLength
1078
1079void wxSlider::SetTick(
1080 int nTickPos
1081)
1082{
1083 nTickPos *= m_dPixelToRange;
1084 ::WinSendMsg( GetHwnd()
1085 ,SLM_ADDDETENT
1086 ,MPFROMSHORT(nTickPos)
1087 ,NULL
1088 );
1089} // end of wxSlider::SetTick
0e320a79 1090
3c299c3a
DW
1091// For trackbars only
1092void wxSlider::SetTickFreq(
1093 int n
1094, int nPos
1095)
409c9842 1096{
3c299c3a
DW
1097 SLDCDATA vSlData;
1098 WNDPARAMS vWndParams;
1099 int nPixelPos;
1100 int i;
409c9842 1101
3c299c3a
DW
1102 vSlData.cbSize = sizeof(SLDCDATA);
1103 if (m_windowStyle & wxSL_AUTOTICKS)
1104 {
1105 vSlData.usScale1Spacing = 0;
1106 vSlData.usScale2Spacing = 0;
1107 }
1108 vSlData.usScale1Increments = (m_nRangeMax - m_nRangeMin)/n;
1109 vSlData.usScale2Increments = (m_nRangeMax - m_nRangeMin)/n;
1110
1111 vWndParams.fsStatus = WPM_CTLDATA;
1112 vWndParams.cchText = 0L;
1113 vWndParams.pszText = NULL;
1114 vWndParams.cbPresParams = 0L;
1115 vWndParams.pPresParams = NULL;
1116 vWndParams.cbCtlData = vSlData.cbSize;
1117 vWndParams.pCtlData = (PVOID)&vSlData;
1118 ::WinSendMsg(GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vWndParams, (MPARAM)0);
1119 for (i = 1; i < (m_nRangeMax - m_nRangeMin)/n; i++)
1120 {
1121 nPixelPos = i * n * m_dPixelToRange;
1122 ::WinSendMsg( GetHwnd()
1123 ,SLM_ADDDETENT
1124 ,MPFROMSHORT(nPixelPos)
1125 ,NULL
1126 );
1127 }
1128} // end of wxSlider::SetTickFreq
1129
1130void wxSlider::SetValue(
1131 int nValue
1132)
0e320a79 1133{
3c299c3a
DW
1134 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1135 ,SLM_QUERYSLIDERINFO
1136 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
1137 ,SMA_RANGEVALUE
1138 )
1139 ,(MPARAM)0
1140 )
1141 );
1142 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1143 ,SLM_QUERYSLIDERINFO
1144 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1145 ,SMA_RANGEVALUE
1146 )
1147 ,(MPARAM)0
1148 )
1149 );
1150 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1151 int nNewPos = (int)(nValue * m_dPixelToRange);
1152
1153 ::WinSendMsg( GetHwnd()
1154 ,SLM_SETSLIDERINFO
1155 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
1156 ,SMA_RANGEVALUE
1157 )
1158 ,(MPARAM)nNewPos
1159 );
1160 if (m_hStaticValue)
1161 {
1162 wxSprintf(wxBuffer, wxT("%d"), nValue);
1163 ::WinSetWindowText((HWND)m_hStaticValue, wxBuffer);
1164 }
1165} // end of wxSlider::SetValue
0e320a79 1166
3c299c3a
DW
1167bool wxSlider::Show(
1168 bool bShow
1169)
0e320a79 1170{
3c299c3a
DW
1171 wxWindowOS2::Show(bShow);
1172 if(m_hStaticValue)
1173 ::WinShowWindow((HWND)m_hStaticValue, bShow);
1174 if(m_hStaticMin)
1175 ::WinShowWindow((HWND)m_hStaticMin, bShow);
1176 if(m_hStaticMax)
1177 ::WinShowWindow((HWND)m_hStaticMax, bShow);
0e320a79 1178 return TRUE;
3c299c3a 1179} // end of wxSlider::Show
0e320a79 1180