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