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