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