]> git.saurik.com Git - wxWidgets.git/blob - src/os2/slider.cpp
cf5d9798f5fd2ed4d92704b2bdf7096eb198d790
[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::DoGetSize(
776 int* pnWidth
777 , int* pnHeight
778 ) const
779 {
780 GetSize( pnWidth
781 ,pnHeight
782 );
783 } // end of wxSlider::DoGetSize
784
785 void wxSlider::GetSize(
786 int* pnWidth
787 , int* pnHeight
788 ) const
789 {
790 RECTL vRect;
791
792 vRect.xLeft = -1;
793 vRect.xRight = -1;
794 vRect.yTop = -1;
795 vRect.yBottom = -1;
796
797 wxFindMaxSize( GetHWND()
798 ,&vRect
799 );
800
801 if (m_hStaticMin)
802 wxFindMaxSize( m_hStaticMin
803 ,&vRect
804 );
805 if (m_hStaticMax)
806 wxFindMaxSize( m_hStaticMax
807 ,&vRect
808 );
809 if (m_hStaticValue)
810 wxFindMaxSize( m_hStaticValue
811 ,&vRect
812 );
813 *pnWidth = vRect.xRight - vRect.xLeft;
814 *pnHeight = vRect.yBottom - vRect.yTop;
815 } // end of wxSlider::GetSize
816
817 int wxSlider::GetThumbLength() const
818 {
819 return m_nThumbLength;
820 } // end of wxSlider::GetThumbLength
821
822 int wxSlider::GetValue() const
823 {
824 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
825 ,SLM_QUERYSLIDERINFO
826 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
827 ,SMA_RANGEVALUE
828 )
829 ,(MPARAM)0
830 )
831 );
832 double dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
833 int nNewPos = 0;
834 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
835 ,SLM_QUERYSLIDERINFO
836 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
837 ,SMA_RANGEVALUE
838 )
839 ,(MPARAM)0
840 )
841 );
842 nNewPos = (int)(nPixelPos/dPixelToRange);
843 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
844 nNewPos++;
845 return nNewPos;
846 } // end of wxSlider::GetValue
847
848 WXHBRUSH wxSlider::OnCtlColor(
849 WXHDC hDC
850 , WXHWND hWnd
851 , WXUINT uCtlColor
852 , WXUINT uMessage
853 , WXWPARAM wParam
854 , WXLPARAM lParam
855 )
856 {
857 return (wxControl::OnCtlColor( hDC
858 ,hWnd
859 ,uCtlColor
860 ,uMessage
861 ,wParam
862 ,lParam
863 )
864 );
865 } // end of wxSlider::OnCtlColor
866
867 bool wxSlider::OS2OnScroll(
868 int WXUNUSED(nOrientation)
869 , WXWORD wParam
870 , WXWORD wPos
871 , WXHWND hControl
872 )
873 {
874 wxEventType eScrollEvent = wxEVT_NULL;
875
876 switch (wParam)
877 {
878 case SLN_CHANGE:
879 if (m_windowStyle & wxSL_TOP)
880 eScrollEvent = wxEVT_SCROLL_TOP;
881 else if (m_windowStyle & wxSL_BOTTOM)
882 eScrollEvent = wxEVT_SCROLL_BOTTOM;
883 break;
884
885 case SLN_SLIDERTRACK:
886 eScrollEvent = wxEVT_SCROLL_THUMBTRACK;
887 break;
888
889 default:
890 return FALSE;
891 }
892
893 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
894 ,SLM_QUERYSLIDERINFO
895 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
896 ,SMA_RANGEVALUE
897 )
898 ,(MPARAM)0
899 )
900 );
901 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
902 int nNewPos = 0;
903 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
904 ,SLM_QUERYSLIDERINFO
905 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
906 ,SMA_RANGEVALUE
907 )
908 ,(MPARAM)0
909 )
910 );
911 nNewPos = (nPixelPos/m_dPixelToRange);
912 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
913 nNewPos++;
914 if ((nNewPos < GetMin()) || (nNewPos > GetMax()))
915 {
916 //
917 // Out of range - but we did process it
918 //
919 return TRUE;
920 }
921 SetValue(nNewPos);
922
923 wxScrollEvent vEvent( eScrollEvent
924 ,m_windowId
925 );
926
927 vEvent.SetPosition(nNewPos);
928 vEvent.SetEventObject(this);
929 GetEventHandler()->ProcessEvent(vEvent);
930
931 wxCommandEvent vCevent( wxEVT_COMMAND_SLIDER_UPDATED
932 ,GetId()
933 );
934
935 vCevent.SetInt(nNewPos);
936 vCevent.SetEventObject(this);
937 return (GetEventHandler()->ProcessEvent(vCevent));
938 } // end of wxSlider::OS2OnScroll
939
940 void wxSlider::SetLineSize(
941 int nLineSize
942 )
943 {
944 m_nLineSize = nLineSize;
945 } // end of wxSlider::SetLineSize
946
947
948 void wxSlider::SetPageSize(
949 int nPageSize
950 )
951 {
952 m_nPageSize = nPageSize;
953 } // end of wxSlider::SetPageSize
954
955 void wxSlider::SetRange(
956 int nMinValue
957 , int nMaxValue
958 )
959 {
960 wxChar zBuf[10];
961
962 m_nRangeMin = nMinValue;
963 m_nRangeMax = nMaxValue;
964
965 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
966 ,SLM_QUERYSLIDERINFO
967 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
968 ,SMA_RANGEVALUE
969 )
970 ,(MPARAM)0
971 )
972 );
973 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
974 if (m_hStaticMin)
975 {
976 wxSprintf(zBuf, wxT("%d"), m_nRangeMin);
977 ::WinSetWindowText((HWND)m_hStaticMin, zBuf);
978 }
979
980 if (m_hStaticMax)
981 {
982 wxSprintf(zBuf, wxT("%d"), m_nRangeMax);
983 ::WinSetWindowText((HWND)m_hStaticMax, zBuf);
984 }
985 } // end of wxSlider::SetRange
986
987 void wxSlider::SetSelection(
988 int WXUNUSED(nMinPos)
989 , int WXUNUSED(nMaxPos)
990 )
991 {
992 } // end of wxSlider::SetSelection
993
994 void wxSlider::SetThumbLength(
995 int nLen
996 )
997 {
998 int nBreadth;
999
1000 m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1001 ,SLM_QUERYSLIDERINFO
1002 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1003 ,SMA_RANGEVALUE
1004 )
1005 ,(MPARAM)0
1006 )
1007 ) + 4; // for bordersizes
1008 nBreadth = SHORT2FROMMR(::WinSendMsg( GetHwnd()
1009 ,SLM_QUERYSLIDERINFO
1010 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1011 ,SMA_RANGEVALUE
1012 )
1013 ,(MPARAM)0
1014 )
1015 );
1016 ::WinSendMsg( GetHwnd()
1017 ,SLM_SETSLIDERINFO
1018 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1019 ,SMA_RANGEVALUE
1020 )
1021 ,MPFROM2SHORT(nLen, nBreadth)
1022 );
1023 m_nThumbLength = nLen + 4; // Borders
1024 } // end of wxSlider::SetThumbLength
1025
1026 void wxSlider::SetTick(
1027 int nTickPos
1028 )
1029 {
1030 nTickPos *= m_dPixelToRange;
1031 ::WinSendMsg( GetHwnd()
1032 ,SLM_ADDDETENT
1033 ,MPFROMSHORT(nTickPos)
1034 ,NULL
1035 );
1036 } // end of wxSlider::SetTick
1037
1038 // For trackbars only
1039 void wxSlider::SetTickFreq(
1040 int n
1041 , int nPos
1042 )
1043 {
1044 SLDCDATA vSlData;
1045 WNDPARAMS vWndParams;
1046 int nPixelPos;
1047 int i;
1048
1049 vSlData.cbSize = sizeof(SLDCDATA);
1050 if (m_windowStyle & wxSL_AUTOTICKS)
1051 {
1052 vSlData.usScale1Spacing = 0;
1053 vSlData.usScale2Spacing = 0;
1054 }
1055 vSlData.usScale1Increments = (m_nRangeMax - m_nRangeMin)/n;
1056 vSlData.usScale2Increments = (m_nRangeMax - m_nRangeMin)/n;
1057
1058 vWndParams.fsStatus = WPM_CTLDATA;
1059 vWndParams.cchText = 0L;
1060 vWndParams.pszText = NULL;
1061 vWndParams.cbPresParams = 0L;
1062 vWndParams.pPresParams = NULL;
1063 vWndParams.cbCtlData = vSlData.cbSize;
1064 vWndParams.pCtlData = (PVOID)&vSlData;
1065 ::WinSendMsg(GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vWndParams, (MPARAM)0);
1066 for (i = 1; i < (m_nRangeMax - m_nRangeMin)/n; i++)
1067 {
1068 nPixelPos = i * n * m_dPixelToRange;
1069 ::WinSendMsg( GetHwnd()
1070 ,SLM_ADDDETENT
1071 ,MPFROMSHORT(nPixelPos)
1072 ,NULL
1073 );
1074 }
1075 } // end of wxSlider::SetTickFreq
1076
1077 void wxSlider::SetValue(
1078 int nValue
1079 )
1080 {
1081 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1082 ,SLM_QUERYSLIDERINFO
1083 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
1084 ,SMA_RANGEVALUE
1085 )
1086 ,(MPARAM)0
1087 )
1088 );
1089 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1090 ,SLM_QUERYSLIDERINFO
1091 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1092 ,SMA_RANGEVALUE
1093 )
1094 ,(MPARAM)0
1095 )
1096 );
1097 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1098 int nNewPos = (int)(nValue * m_dPixelToRange);
1099
1100 ::WinSendMsg( GetHwnd()
1101 ,SLM_SETSLIDERINFO
1102 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
1103 ,SMA_RANGEVALUE
1104 )
1105 ,(MPARAM)nNewPos
1106 );
1107 if (m_hStaticValue)
1108 {
1109 wxSprintf(wxBuffer, wxT("%d"), nValue);
1110 ::WinSetWindowText((HWND)m_hStaticValue, wxBuffer);
1111 }
1112 } // end of wxSlider::SetValue
1113
1114 bool wxSlider::Show(
1115 bool bShow
1116 )
1117 {
1118 wxWindowOS2::Show(bShow);
1119 if(m_hStaticValue)
1120 ::WinShowWindow((HWND)m_hStaticValue, bShow);
1121 if(m_hStaticMin)
1122 ::WinShowWindow((HWND)m_hStaticMin, bShow);
1123 if(m_hStaticMax)
1124 ::WinShowWindow((HWND)m_hStaticMax, bShow);
1125 return TRUE;
1126 } // end of wxSlider::Show
1127