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