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