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