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