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