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