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