]> git.saurik.com Git - wxWidgets.git/blob - src/os2/slider.cpp
correct painting of the items with custom colours in TVIS_DROPHILITED state (patch...
[wxWidgets.git] / src / os2 / slider.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/slider.cpp
3 // Purpose: wxSlider
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/15/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include <stdio.h>
21 #include "wx/utils.h"
22 #include "wx/brush.h"
23 #include "wx/scrolwin.h"
24 #endif
25
26 #if wxUSE_SLIDER
27
28 #include "wx/slider.h"
29 #include "wx/os2/private.h"
30
31 IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
32
33 wxSlider::wxSlider()
34 {
35 m_hStaticValue = 0L;
36 m_hStaticMin = 0L;
37 m_hStaticMax = 0L;
38 m_nPageSize = 1;
39 m_nLineSize = 1;
40 m_nRangeMax = 0;
41 m_nRangeMin = 0;
42 m_nTickFreq = 0;
43 } // end of wxSlider::wxSlider
44
45 wxSlider::~wxSlider()
46 {
47 if (m_hStaticMin)
48 ::WinDestroyWindow((HWND)m_hStaticMin);
49 if (m_hStaticMax)
50 ::WinDestroyWindow((HWND)m_hStaticMax);
51 if (m_hStaticValue)
52 ::WinDestroyWindow((HWND)m_hStaticValue);
53 } // end of wxSlider::~wxSlider
54
55 void wxSlider::AdjustSubControls( int nX,
56 int nY,
57 int nWidth,
58 int nHeight,
59 int WXUNUSED(nSizeFlags) )
60 {
61 int nXOffset = nX;
62 int nYOffset = nY;
63 int nCx; // slider,min,max sizes
64 int nCy;
65 int nCyf;
66 wxChar zBuf[300];
67 wxFont vFont = this->GetFont();
68
69 wxGetCharSize( GetHWND()
70 ,&nCx
71 ,&nCy
72 ,&vFont
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, (PSZ)zBuf);
83 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &vFont);
84
85 ::WinQueryWindowText((HWND)m_hStaticMax, 300, (PSZ)zBuf);
86 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &vFont);
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, (PSZ)zBuf);
134 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &vFont);
135
136 ::WinQueryWindowText((HWND)m_hStaticMax, 300, (PSZ)zBuf);
137 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &vFont);
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 , const wxValidator& rValidator
208 , const wxString& rsName
209 )
210 {
211 int nX = rPos.x;
212 int nY = rPos.y;
213 int nWidth = rSize.x;
214 int nHeight = rSize.y;
215 long lMsStyle = 0L;
216 long lWstyle = 0L;
217
218 SetName(rsName);
219 #if wxUSE_VALIDATORS
220 SetValidator(rValidator);
221 #endif
222 if (pParent)
223 pParent->AddChild(this);
224 SetBackgroundColour(pParent->GetBackgroundColour()) ;
225 SetForegroundColour(pParent->GetForegroundColour()) ;
226
227 m_hStaticValue = 0L;
228 m_hStaticMin = 0L;
229 m_hStaticMax = 0L;
230 m_nPageSize = 1;
231 m_nLineSize = 1;
232 m_windowStyle = lStyle;
233 m_nTickFreq = 0;
234
235 if (vId == -1)
236 m_windowId = (int)NewControlId();
237 else
238 m_windowId = vId;
239
240 if (m_windowStyle & wxCLIP_SIBLINGS )
241 lMsStyle |= WS_CLIPSIBLINGS;
242
243 if (m_windowStyle & wxSL_LABELS)
244 {
245 lMsStyle |= WS_VISIBLE | SS_TEXT | DT_VCENTER;
246
247 m_hStaticValue = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
248 ,WC_STATIC // Window class
249 ,(PSZ)NULL // Initial Text
250 ,(ULONG)lMsStyle // Style flags
251 ,0L, 0L, 0L, 0L // Origin -- 0 size
252 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
253 ,HWND_TOP // initial z position
254 ,(ULONG)NewControlId() // Window identifier
255 ,NULL // no control data
256 ,NULL // no Presentation parameters
257 );
258
259 //
260 // Now create min static control
261 //
262 wxSprintf(wxBuffer, wxT("%d"), nMinValue);
263 lWstyle = SS_TEXT|DT_LEFT|WS_VISIBLE;
264 if (m_windowStyle & wxCLIP_SIBLINGS)
265 lWstyle |= WS_CLIPSIBLINGS;
266
267 m_hStaticMin = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
268 ,WC_STATIC // Window class
269 ,(PSZ)wxBuffer // Initial Text
270 ,(ULONG)lWstyle // Style flags
271 ,0L, 0L, 0L, 0L // Origin -- 0 size
272 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
273 ,HWND_TOP // initial z position
274 ,(ULONG)NewControlId() // Window identifier
275 ,NULL // no control data
276 ,NULL // no Presentation parameters
277 );
278 }
279 lMsStyle = 0;
280
281 SLDCDATA vSlData;
282
283 vSlData.cbSize = sizeof(SLDCDATA);
284 if (m_windowStyle & wxSL_VERTICAL)
285 lMsStyle = SLS_VERTICAL | SLS_HOMEBOTTOM | WS_VISIBLE | WS_TABSTOP;
286 else
287 lMsStyle = SLS_HORIZONTAL | SLS_HOMELEFT | WS_VISIBLE | WS_TABSTOP;
288
289 if (m_windowStyle & wxCLIP_SIBLINGS)
290 lMsStyle |= WS_CLIPSIBLINGS;
291
292 if (m_windowStyle & wxSL_AUTOTICKS)
293 {
294 vSlData.usScale1Spacing = 0;
295 vSlData.usScale2Spacing = 0;
296 }
297
298 if (m_windowStyle & wxSL_LEFT)
299 lMsStyle |= SLS_PRIMARYSCALE2; // if SLS_VERTICAL then SCALE2 is to the left
300 else if (m_windowStyle & wxSL_RIGHT)
301 lMsStyle |= SLS_PRIMARYSCALE1; // if SLS_VERTICAL then SCALE2 is to the right
302 else if (m_windowStyle & wxSL_TOP)
303 lMsStyle |= SLS_PRIMARYSCALE1; // if SLS_HORIZONTAL then SCALE1 is to the top
304 else if (m_windowStyle & wxSL_BOTTOM )
305 lMsStyle |= SLS_PRIMARYSCALE2; // if SLS_HORIZONTAL then SCALE1 is to the bottom
306 else if ( m_windowStyle & wxSL_BOTH )
307 lMsStyle |= SLS_PRIMARYSCALE1 | SLS_PRIMARYSCALE2;
308 else
309 lMsStyle |= SLS_PRIMARYSCALE2;
310 lMsStyle |= SLS_RIBBONSTRIP;
311
312 m_nPageSize = ((nMaxValue - nMinValue)/10);
313 vSlData.usScale1Increments = (USHORT)m_nPageSize;
314 vSlData.usScale2Increments = (USHORT)m_nPageSize;
315
316 HWND hScrollBar = ::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
317 ,WC_SLIDER // Window class
318 ,(PSZ)wxBuffer // Initial Text
319 ,(ULONG)lMsStyle // Style flags
320 ,0L, 0L, 0L, 0L // Origin -- 0 size
321 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
322 ,HWND_BOTTOM // initial z position
323 ,(HMENU)m_windowId // Window identifier
324 ,&vSlData // Slider control data
325 ,NULL // no Presentation parameters
326 );
327 m_nRangeMax = nMaxValue;
328 m_nRangeMin = nMinValue;
329
330 //
331 // Set the size of the ticks ... default to 6 pixels
332 //
333 ::WinSendMsg( hScrollBar
334 ,SLM_SETTICKSIZE
335 ,MPFROM2SHORT(SMA_SETALLTICKS, (USHORT)12)
336 ,NULL
337 );
338 //
339 // Set the position to the initial value
340 //
341 ::WinSendMsg( hScrollBar
342 ,SLM_SETSLIDERINFO
343 ,MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE)
344 ,(MPARAM)nValue
345 );
346
347 m_hWnd = (WXHWND)hScrollBar;
348 SubclassWin(GetHWND());
349 ::WinSetWindowText((HWND)m_hWnd, "");
350
351 SetFont(*wxSMALL_FONT);
352 if (m_windowStyle & wxSL_LABELS)
353 {
354 //
355 // Finally, create max value static item
356 //
357 wxSprintf(wxBuffer, wxT("%d"), nMaxValue);
358 lWstyle = SS_TEXT|DT_LEFT|WS_VISIBLE;
359 if (m_windowStyle & wxCLIP_SIBLINGS)
360 lMsStyle |= WS_CLIPSIBLINGS;
361
362 m_hStaticMax = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
363 ,WC_STATIC // Window class
364 ,(PSZ)wxBuffer // Initial Text
365 ,(ULONG)lWstyle // Style flags
366 ,0L, 0L, 0L, 0L // Origin -- 0 size
367 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
368 ,HWND_TOP // initial z position
369 ,(ULONG)NewControlId() // Window identifier
370 ,NULL // no control data
371 ,NULL // no Presentation parameters
372 );
373 if (GetFont().Ok())
374 {
375 if (GetFont().GetResourceHandle())
376 {
377 if (m_hStaticMin)
378 wxOS2SetFont( m_hStaticMin
379 ,GetFont()
380 );
381 if (m_hStaticMax)
382 wxOS2SetFont( m_hStaticMax
383 ,GetFont()
384 );
385 if (m_hStaticValue)
386 wxOS2SetFont( m_hStaticValue
387 ,GetFont()
388 );
389 }
390 }
391 }
392
393 SetXComp(0);
394 SetYComp(0);
395 SetSize( nX
396 ,nY
397 ,nWidth
398 ,nHeight
399 );
400 m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd()
401 ,SLM_QUERYSLIDERINFO
402 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
403 ,SMA_RANGEVALUE
404 )
405 ,(MPARAM)0
406 )
407 ) + 4; // for bordersizes
408
409 wxColour vColour;
410
411 vColour.Set(wxString(wxT("BLACK")));
412
413 LONG lColor = (LONG)vColour.GetPixel();
414
415 ::WinSetPresParam( m_hStaticMin
416 ,PP_FOREGROUNDCOLOR
417 ,sizeof(LONG)
418 ,(PVOID)&lColor
419 );
420 ::WinSetPresParam( m_hStaticMax
421 ,PP_FOREGROUNDCOLOR
422 ,sizeof(LONG)
423 ,(PVOID)&lColor
424 );
425 ::WinSetPresParam( m_hStaticValue
426 ,PP_FOREGROUNDCOLOR
427 ,sizeof(LONG)
428 ,(PVOID)&lColor
429 );
430 ::WinSetPresParam( m_hWnd
431 ,PP_FOREGROUNDCOLOR
432 ,sizeof(LONG)
433 ,(PVOID)&lColor
434 );
435 lColor = (LONG)m_backgroundColour.GetPixel();
436 ::WinSetPresParam( m_hStaticMin
437 ,PP_BACKGROUNDCOLOR
438 ,sizeof(LONG)
439 ,(PVOID)&lColor
440 );
441 ::WinSetPresParam( m_hStaticMax
442 ,PP_BACKGROUNDCOLOR
443 ,sizeof(LONG)
444 ,(PVOID)&lColor
445 );
446 ::WinSetPresParam( m_hStaticValue
447 ,PP_BACKGROUNDCOLOR
448 ,sizeof(LONG)
449 ,(PVOID)&lColor
450 );
451 ::WinSetPresParam( m_hWnd
452 ,PP_BACKGROUNDCOLOR
453 ,sizeof(LONG)
454 ,(PVOID)&lColor
455 );
456 vColour.Set(wxString(wxT("BLUE")));
457 lColor = (LONG)vColour.GetPixel();
458 ::WinSetPresParam( m_hWnd
459 ,PP_HILITEBACKGROUNDCOLOR
460 ,sizeof(LONG)
461 ,(PVOID)&lColor
462 );
463 SetValue(nValue);
464 return true;
465 } // end of wxSlider::Create
466
467 void wxSlider::DoSetSize(
468 int nX
469 , int nY
470 , int nWidth
471 , int nHeight
472 , int nSizeFlags
473 )
474 {
475 int nX1 = nX;
476 int nY1 = nY;
477 int nWidth1 = nWidth;
478 int nHeight1 = nHeight;
479 int nXOffset = nX;
480 int nYOffset = nY;
481 int nCx; // slider,min,max sizes
482 int nCy;
483 int nCyf;
484 int nCurrentX;
485 int nCurrentY;
486 wxChar zBuf[300];
487 wxFont vFont = this->GetFont();
488
489 //
490 // Adjust for OS/2's reverse coordinate system
491 //
492 wxWindowOS2* pParent = (wxWindowOS2*)GetParent();
493 int nUsedHeight = 0;
494 int nOS2Height = nHeight;
495
496 if (nOS2Height < 0)
497 nOS2Height = 20;
498 CacheBestSize(wxSize(nWidth,nOS2Height));
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 ,&vFont
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, (PSZ)zBuf);
545 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &vFont);
546 ::WinQueryWindowText((HWND)m_hStaticMax, 300, (PSZ)zBuf);
547 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &vFont);
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 - (LONG)(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 - (LONG)(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 - (LONG)(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, (PSZ)zBuf);
652 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &vFont);
653 ::WinQueryWindowText((HWND)m_hStaticMax, 300, (PSZ)zBuf);
654 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &vFont);
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 if (pnX)
817 *pnX = vPoint.x;
818 if (pnY)
819 *pnY = vPoint.y;
820 } // end of wxSlider::GetPosition
821
822 int wxSlider::GetSelEnd() const
823 {
824 return 0;
825 } // end of wxSlider::GetSelEnd
826
827 int wxSlider::GetSelStart() const
828 {
829 return 0;
830 } // end of wxSlider::GetSelStart
831
832 void wxSlider::DoGetSize(
833 int* pnWidth
834 , int* pnHeight
835 ) const
836 {
837 GetSize( pnWidth
838 ,pnHeight
839 );
840 } // end of wxSlider::DoGetSize
841
842 void wxSlider::GetSize(
843 int* pnWidth
844 , int* pnHeight
845 ) const
846 {
847 RECTL vRect;
848
849 vRect.xLeft = -1;
850 vRect.xRight = -1;
851 vRect.yTop = -1;
852 vRect.yBottom = -1;
853
854 wxFindMaxSize( GetHWND()
855 ,&vRect
856 );
857
858 if (m_hStaticMin)
859 wxFindMaxSize( m_hStaticMin
860 ,&vRect
861 );
862 if (m_hStaticMax)
863 wxFindMaxSize( m_hStaticMax
864 ,&vRect
865 );
866 if (m_hStaticValue)
867 wxFindMaxSize( m_hStaticValue
868 ,&vRect
869 );
870 if (pnWidth)
871 *pnWidth = vRect.xRight - vRect.xLeft;
872 if (pnHeight)
873 *pnHeight = vRect.yTop - vRect.yBottom;
874 } // end of wxSlider::GetSize
875
876 int wxSlider::GetThumbLength() const
877 {
878 return m_nThumbLength;
879 } // end of wxSlider::GetThumbLength
880
881 int wxSlider::GetValue() const
882 {
883 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
884 ,SLM_QUERYSLIDERINFO
885 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
886 ,SMA_RANGEVALUE
887 )
888 ,(MPARAM)0
889 )
890 );
891 double dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
892 int nNewPos = 0;
893 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
894 ,SLM_QUERYSLIDERINFO
895 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
896 ,SMA_RANGEVALUE
897 )
898 ,(MPARAM)0
899 )
900 );
901 nNewPos = (int)(nPixelPos/dPixelToRange);
902 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
903 nNewPos++;
904 return nNewPos;
905 } // end of wxSlider::GetValue
906
907 WXHBRUSH wxSlider::OnCtlColor(
908 WXHDC hDC
909 , WXHWND hWnd
910 , WXUINT uCtlColor
911 , WXUINT uMessage
912 , WXWPARAM wParam
913 , WXLPARAM lParam
914 )
915 {
916 return (wxControl::OnCtlColor( hDC
917 ,hWnd
918 ,uCtlColor
919 ,uMessage
920 ,wParam
921 ,lParam
922 )
923 );
924 } // end of wxSlider::OnCtlColor
925
926 bool wxSlider::OS2OnScroll( int WXUNUSED(nOrientation),
927 WXWORD wParam,
928 WXWORD WXUNUSED(wPos),
929 WXHWND WXUNUSED(hControl) )
930 {
931 wxEventType eScrollEvent = wxEVT_NULL;
932
933 switch (wParam)
934 {
935 case SLN_CHANGE:
936 if (m_windowStyle & wxSL_TOP)
937 eScrollEvent = wxEVT_SCROLL_TOP;
938 else if (m_windowStyle & wxSL_BOTTOM)
939 eScrollEvent = wxEVT_SCROLL_BOTTOM;
940 break;
941
942 case SLN_SLIDERTRACK:
943 eScrollEvent = wxEVT_SCROLL_THUMBTRACK;
944 break;
945
946 default:
947 return false;
948 }
949
950 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
951 , SLM_QUERYSLIDERINFO
952 , MPFROM2SHORT( SMA_SHAFTDIMENSIONS, SMA_RANGEVALUE )
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, SMA_RANGEVALUE )
961 , (MPARAM)0
962 )
963 );
964
965 nNewPos = (int)(nPixelPos/m_dPixelToRange);
966 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
967 nNewPos++;
968 if ((nNewPos < GetMin()) || (nNewPos > GetMax()))
969 {
970 //
971 // Out of range - but we did process it
972 //
973 return true;
974 }
975 SetValue(nNewPos);
976
977 wxScrollEvent vEvent( eScrollEvent, m_windowId );
978
979 vEvent.SetPosition(nNewPos);
980 vEvent.SetEventObject(this);
981 GetEventHandler()->ProcessEvent(vEvent);
982
983 wxCommandEvent vCevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() );
984
985 vCevent.SetInt(nNewPos);
986 vCevent.SetEventObject(this);
987 return (GetEventHandler()->ProcessEvent(vCevent));
988 } // end of wxSlider::OS2OnScroll
989
990 void wxSlider::SetLineSize( int nLineSize )
991 {
992 m_nLineSize = nLineSize;
993 } // end of wxSlider::SetLineSize
994
995
996 void wxSlider::SetPageSize( int nPageSize )
997 {
998 m_nPageSize = nPageSize;
999 } // end of wxSlider::SetPageSize
1000
1001 void wxSlider::SetRange(
1002 int nMinValue
1003 , int nMaxValue
1004 )
1005 {
1006 wxChar zBuf[10];
1007
1008 m_nRangeMin = nMinValue;
1009 m_nRangeMax = nMaxValue;
1010
1011 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1012 ,SLM_QUERYSLIDERINFO
1013 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1014 ,SMA_RANGEVALUE
1015 )
1016 ,(MPARAM)0
1017 )
1018 );
1019 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1020 if (m_hStaticMin)
1021 {
1022 wxSprintf(zBuf, wxT("%d"), m_nRangeMin);
1023 ::WinSetWindowText((HWND)m_hStaticMin, (PSZ)zBuf);
1024 }
1025
1026 if (m_hStaticMax)
1027 {
1028 wxSprintf(zBuf, wxT("%d"), m_nRangeMax);
1029 ::WinSetWindowText((HWND)m_hStaticMax, (PSZ)zBuf);
1030 }
1031 } // end of wxSlider::SetRange
1032
1033 void wxSlider::SetSelection(
1034 int WXUNUSED(nMinPos)
1035 , int WXUNUSED(nMaxPos)
1036 )
1037 {
1038 } // end of wxSlider::SetSelection
1039
1040 void wxSlider::SetThumbLength(
1041 int nLen
1042 )
1043 {
1044 int nBreadth;
1045
1046 m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1047 ,SLM_QUERYSLIDERINFO
1048 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1049 ,SMA_RANGEVALUE
1050 )
1051 ,(MPARAM)0
1052 )
1053 ) + 4; // for bordersizes
1054 nBreadth = SHORT2FROMMR(::WinSendMsg( GetHwnd()
1055 ,SLM_QUERYSLIDERINFO
1056 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1057 ,SMA_RANGEVALUE
1058 )
1059 ,(MPARAM)0
1060 )
1061 );
1062 ::WinSendMsg( GetHwnd()
1063 ,SLM_SETSLIDERINFO
1064 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1065 ,SMA_RANGEVALUE
1066 )
1067 ,MPFROM2SHORT(nLen, nBreadth)
1068 );
1069 m_nThumbLength = nLen + 4; // Borders
1070 } // end of wxSlider::SetThumbLength
1071
1072 void wxSlider::SetTick(
1073 int nTickPos
1074 )
1075 {
1076 nTickPos = (int)(nTickPos * m_dPixelToRange);
1077 ::WinSendMsg( GetHwnd()
1078 ,SLM_ADDDETENT
1079 ,MPFROMSHORT(nTickPos)
1080 ,NULL
1081 );
1082 } // end of wxSlider::SetTick
1083
1084 // For trackbars only
1085 void wxSlider::SetTickFreq( int n, int WXUNUSED(nPos) )
1086 {
1087 SLDCDATA vSlData;
1088 WNDPARAMS vWndParams;
1089 int nPixelPos;
1090 int i;
1091
1092 vSlData.cbSize = sizeof(SLDCDATA);
1093 if (m_windowStyle & wxSL_AUTOTICKS)
1094 {
1095 vSlData.usScale1Spacing = 0;
1096 vSlData.usScale2Spacing = 0;
1097 }
1098 vSlData.usScale1Increments = (USHORT)((m_nRangeMax - m_nRangeMin)/n);
1099 vSlData.usScale2Increments = (USHORT)((m_nRangeMax - m_nRangeMin)/n);
1100
1101 vWndParams.fsStatus = WPM_CTLDATA;
1102 vWndParams.cchText = 0L;
1103 vWndParams.pszText = NULL;
1104 vWndParams.cbPresParams = 0L;
1105 vWndParams.pPresParams = NULL;
1106 vWndParams.cbCtlData = vSlData.cbSize;
1107 vWndParams.pCtlData = (PVOID)&vSlData;
1108 ::WinSendMsg(GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vWndParams, (MPARAM)0);
1109 for (i = 1; i < (m_nRangeMax - m_nRangeMin)/n; i++)
1110 {
1111 nPixelPos = (int)(i * n * m_dPixelToRange);
1112 ::WinSendMsg( GetHwnd()
1113 ,SLM_ADDDETENT
1114 ,MPFROMSHORT(nPixelPos)
1115 ,NULL
1116 );
1117 }
1118 } // end of wxSlider::SetTickFreq
1119
1120 void wxSlider::SetValue(
1121 int nValue
1122 )
1123 {
1124 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1125 ,SLM_QUERYSLIDERINFO
1126 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1127 ,SMA_RANGEVALUE
1128 )
1129 ,(MPARAM)0
1130 )
1131 );
1132 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1133 int nNewPos = (int)(nValue * m_dPixelToRange);
1134
1135 ::WinSendMsg( GetHwnd()
1136 ,SLM_SETSLIDERINFO
1137 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
1138 ,SMA_RANGEVALUE
1139 )
1140 ,(MPARAM)nNewPos
1141 );
1142 if (m_hStaticValue)
1143 {
1144 wxSprintf(wxBuffer, wxT("%d"), nValue);
1145 ::WinSetWindowText((HWND)m_hStaticValue, (PSZ)wxBuffer);
1146 }
1147 } // end of wxSlider::SetValue
1148
1149 bool wxSlider::Show(
1150 bool bShow
1151 )
1152 {
1153 wxWindowOS2::Show(bShow);
1154 if(m_hStaticValue)
1155 ::WinShowWindow((HWND)m_hStaticValue, bShow);
1156 if(m_hStaticMin)
1157 ::WinShowWindow((HWND)m_hStaticMin, bShow);
1158 if(m_hStaticMax)
1159 ::WinShowWindow((HWND)m_hStaticMax, bShow);
1160 return true;
1161 } // end of wxSlider::Show
1162
1163 #endif // wxUSE_SLIDER