]> git.saurik.com Git - wxWidgets.git/blob - src/os2/slider.cpp
starting blend modes for Core Graphics
[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
499 if (pParent)
500 {
501 int nOS2ParentHeight = GetOS2ParentHeight(pParent);
502
503 nYOffset = nOS2ParentHeight - (nYOffset + nOS2Height);
504 if (nY != -1)
505 nY1 = nOS2ParentHeight - (nY1 + nOS2Height);
506 }
507 else
508 {
509 RECTL vRect;
510
511 ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
512 nYOffset = vRect.yTop - (nYOffset + nOS2Height);
513 if (nY != -1)
514 nY1 = vRect.yTop - (nY1 + nOS2Height);
515 }
516 m_nSizeFlags = nSizeFlags;
517
518 GetPosition( &nCurrentX
519 ,&nCurrentY
520 );
521 if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
522 nX1 = nCurrentX;
523 if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
524 nY1 = nCurrentY;
525
526 AdjustForParentClientOrigin( nX1
527 ,nY1
528 ,nSizeFlags
529 );
530 wxGetCharSize( GetHWND()
531 ,&nCx
532 ,&nCy
533 ,&vFont
534 );
535
536 if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL)
537 {
538 if (m_windowStyle & wxSL_LABELS )
539 {
540 int nMinLen = 0;
541 int nMaxLen = 0;
542
543 ::WinQueryWindowText((HWND)m_hStaticMin, 300, (PSZ)zBuf);
544 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &vFont);
545 ::WinQueryWindowText((HWND)m_hStaticMax, 300, (PSZ)zBuf);
546 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &vFont);
547
548 if (m_hStaticValue)
549 {
550 int nNewWidth = (wxMax(nMinLen, nMaxLen));
551 int nValueHeight = nCyf;
552
553 ::WinSetWindowPos( (HWND)m_hStaticValue
554 ,HWND_TOP
555 ,(LONG)nXOffset
556 ,(LONG)nYOffset - (LONG)(nCyf * 1.2)
557 ,(LONG)nNewWidth
558 ,(LONG)nValueHeight
559 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
560 );
561 nXOffset += nNewWidth + nCx;
562 }
563 ::WinSetWindowPos( (HWND)m_hStaticMin
564 ,HWND_TOP
565 ,(LONG)nXOffset
566 ,(LONG)nYOffset - (LONG)(nCyf * 1.2)
567 ,(LONG)nMinLen
568 ,(LONG)nCy
569 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
570 );
571 nXOffset += nMinLen + nCx;
572
573 int nSliderLength = nWidth1 - nXOffset - nMaxLen - nCx;
574 int nSliderHeight = nHeight1;
575
576 if (nSliderHeight < 0)
577 nSliderHeight = 20;
578
579 //
580 // Slider must have a minimum/default length/height
581 //
582 if (nSliderLength < 100)
583 nSliderLength = 100;
584
585 ::WinSetWindowPos( GetHwnd()
586 ,HWND_TOP
587 ,(LONG)nXOffset
588 ,(LONG)nYOffset
589 ,(LONG)nSliderLength
590 ,(LONG)nSliderHeight
591 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
592 );
593 ::WinQueryWindowPos(GetHwnd(), GetSwp());
594 ::WinSendMsg( GetHwnd()
595 ,SLM_SETSLIDERINFO
596 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
597 ,0
598 )
599 ,MPFROMLONG((ULONG)(nSliderHeight/2))
600 );
601 nXOffset += nSliderLength + nCx;
602
603 ::WinSetWindowPos( (HWND)m_hStaticMax
604 ,HWND_TOP
605 ,(LONG)nXOffset
606 ,(LONG)nYOffset - (LONG)(nCyf * 1.2)
607 ,(LONG)nMaxLen
608 ,(LONG)nCy
609 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
610 );
611 }
612 else
613 {
614 //
615 // No labels
616 // If we're prepared to use the existing size, then...
617 //
618 if (nWidth == -1 && nHeight == -1 &&
619 ((nSizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
620 {
621 GetSize( &nWidth1
622 ,&nHeight1
623 );
624 }
625 if (nWidth1 < 0)
626 nWidth1 = 200;
627 if (nHeight1 < 0)
628 nHeight1 = 20;
629 ::WinSetWindowPos( GetHwnd()
630 ,HWND_TOP
631 ,(LONG)nX1
632 ,(LONG)nY1
633 ,(LONG)nWidth1
634 ,(LONG)nHeight1
635 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
636 );
637 }
638 }
639
640 //
641 // Now deal with a vertical slider
642 //
643 else
644 {
645 if (m_windowStyle & wxSL_LABELS )
646 {
647 int nMinLen;
648 int nMaxLen;
649
650 ::WinQueryWindowText((HWND)m_hStaticMin, 300, (PSZ)zBuf);
651 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &vFont);
652 ::WinQueryWindowText((HWND)m_hStaticMax, 300, (PSZ)zBuf);
653 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &vFont);
654 if (m_hStaticValue)
655 {
656 int nNewWidth = wxMax(nMinLen, nMaxLen);
657 int nValueHeight = nCyf;
658
659 ::WinSetWindowPos( (HWND)m_hStaticValue
660 ,HWND_TOP
661 ,(LONG)nXOffset
662 ,(LONG)nYOffset + nHeight
663 ,(LONG)nNewWidth
664 ,(LONG)nValueHeight
665 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
666 );
667 nUsedHeight += nCyf;
668 }
669 ::WinSetWindowPos( (HWND)m_hStaticMin
670 ,HWND_TOP
671 ,(LONG)nXOffset
672 ,(LONG)nYOffset + nHeight - nCyf
673 ,(LONG)nMinLen
674 ,(LONG)nCy
675 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
676 );
677 nUsedHeight += nCy;
678
679 int nSliderLength = nHeight1 - (nUsedHeight + (2 * nCy));
680 int nSliderWidth = nWidth1;
681
682 if (nSliderWidth < 0)
683 nSliderWidth = 20;
684
685 //
686 // Slider must have a minimum/default length
687 //
688 if (nSliderLength < 100)
689 nSliderLength = 100;
690
691 ::WinSetWindowPos( GetHwnd()
692 ,HWND_TOP
693 ,(LONG)nXOffset
694 ,(LONG)nYOffset + nCyf
695 ,(LONG)nSliderWidth
696 ,(LONG)nSliderLength
697 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
698 );
699 ::WinQueryWindowPos(GetHwnd(), GetSwp());
700 ::WinSendMsg( GetHwnd()
701 ,SLM_SETSLIDERINFO
702 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
703 ,0
704 )
705 ,MPFROMLONG((ULONG)(nSliderWidth/2))
706 );
707 nUsedHeight += nSliderLength;
708 ::WinSetWindowPos( (HWND)m_hStaticMax
709 ,HWND_TOP
710 ,(LONG)nXOffset
711 ,(LONG)nYOffset - nCyf
712 ,(LONG)nMaxLen
713 ,(LONG)nCy
714 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
715 );
716 }
717 else
718 {
719 //
720 // No labels
721 // If we're prepared to use the existing size, then...
722 //
723 if (nWidth == -1 && nHeight == -1 &&
724 ((nSizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
725 {
726 GetSize( &nWidth1
727 ,&nHeight1
728 );
729 }
730 if (nWidth1 < 0)
731 nWidth1 = 20;
732 if (nHeight1 < 0)
733 nHeight1 = 200;
734 ::WinSetWindowPos( GetHwnd()
735 ,HWND_TOP
736 ,(LONG)nX1
737 ,(LONG)nY1
738 ,(LONG)nWidth1
739 ,(LONG)nHeight1
740 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
741 );
742 }
743 }
744 } // end of void wxSlider::DoSetSize
745
746 int wxSlider::GetLineSize() const
747 {
748 return 1;
749 } // end of wxSlider::GetLineSize
750
751 int wxSlider::GetPageSize() const
752 {
753 return m_nPageSize;
754 } // end of wxSlider::GetPageSize
755
756 void wxSlider::GetPosition(
757 int* pnX
758 , int* pnY
759 ) const
760 {
761 wxWindowOS2* pParent = GetParent();
762 RECTL vRect;
763
764 vRect.xLeft = -1;
765 vRect.xRight = -1;
766 vRect.yTop = -1;
767 vRect.yBottom = -1;
768 wxFindMaxSize( GetHWND()
769 ,&vRect
770 );
771
772 if (m_hStaticMin)
773 wxFindMaxSize( m_hStaticMin
774 ,&vRect
775 );
776 if (m_hStaticMax)
777 wxFindMaxSize( m_hStaticMax
778 ,&vRect
779 );
780 if (m_hStaticValue)
781 wxFindMaxSize( m_hStaticValue
782 ,&vRect
783 );
784
785 //
786 // Since we now have the absolute screen coords,
787 // if there's a parent we must subtract its top left corner
788 //
789 POINTL vPoint;
790
791 vPoint.x = vRect.xLeft;
792 vPoint.y = vRect.yTop;
793
794 if (pParent)
795 {
796 SWP vSwp;
797
798 ::WinQueryWindowPos((HWND)pParent->GetHWND(), &vSwp);
799 vPoint.x = vSwp.x;
800 vPoint.y = vSwp.y;
801 }
802
803 //
804 // We may be faking the client origin.
805 // So a window that's really at (0, 30) may appear
806 // (to wxWin apps) to be at (0, 0).
807 //
808 if (GetParent())
809 {
810 wxPoint vPt(GetParent()->GetClientAreaOrigin());
811
812 vPoint.x -= vPt.x;
813 vPoint.y -= vPt.y;
814 }
815 if (pnX)
816 *pnX = vPoint.x;
817 if (pnY)
818 *pnY = vPoint.y;
819 } // end of wxSlider::GetPosition
820
821 int wxSlider::GetSelEnd() const
822 {
823 return 0;
824 } // end of wxSlider::GetSelEnd
825
826 int wxSlider::GetSelStart() const
827 {
828 return 0;
829 } // end of wxSlider::GetSelStart
830
831 void wxSlider::DoGetSize(
832 int* pnWidth
833 , int* pnHeight
834 ) const
835 {
836 GetSize( pnWidth
837 ,pnHeight
838 );
839 } // end of wxSlider::DoGetSize
840
841 void wxSlider::GetSize(
842 int* pnWidth
843 , int* pnHeight
844 ) const
845 {
846 RECTL vRect;
847
848 vRect.xLeft = -1;
849 vRect.xRight = -1;
850 vRect.yTop = -1;
851 vRect.yBottom = -1;
852
853 wxFindMaxSize( GetHWND()
854 ,&vRect
855 );
856
857 if (m_hStaticMin)
858 wxFindMaxSize( m_hStaticMin
859 ,&vRect
860 );
861 if (m_hStaticMax)
862 wxFindMaxSize( m_hStaticMax
863 ,&vRect
864 );
865 if (m_hStaticValue)
866 wxFindMaxSize( m_hStaticValue
867 ,&vRect
868 );
869 if (pnWidth)
870 *pnWidth = vRect.xRight - vRect.xLeft;
871 if (pnHeight)
872 *pnHeight = vRect.yTop - vRect.yBottom;
873 } // end of wxSlider::GetSize
874
875 int wxSlider::GetThumbLength() const
876 {
877 return m_nThumbLength;
878 } // end of wxSlider::GetThumbLength
879
880 int wxSlider::GetValue() const
881 {
882 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
883 ,SLM_QUERYSLIDERINFO
884 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
885 ,SMA_RANGEVALUE
886 )
887 ,(MPARAM)0
888 )
889 );
890 double dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
891 int nNewPos = 0;
892 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
893 ,SLM_QUERYSLIDERINFO
894 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
895 ,SMA_RANGEVALUE
896 )
897 ,(MPARAM)0
898 )
899 );
900 nNewPos = (int)(nPixelPos/dPixelToRange);
901 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
902 nNewPos++;
903 return nNewPos;
904 } // end of wxSlider::GetValue
905
906 WXHBRUSH wxSlider::OnCtlColor(
907 WXHDC hDC
908 , WXHWND hWnd
909 , WXUINT uCtlColor
910 , WXUINT uMessage
911 , WXWPARAM wParam
912 , WXLPARAM lParam
913 )
914 {
915 return (wxControl::OnCtlColor( hDC
916 ,hWnd
917 ,uCtlColor
918 ,uMessage
919 ,wParam
920 ,lParam
921 )
922 );
923 } // end of wxSlider::OnCtlColor
924
925 bool wxSlider::OS2OnScroll( int WXUNUSED(nOrientation),
926 WXWORD wParam,
927 WXWORD WXUNUSED(wPos),
928 WXHWND WXUNUSED(hControl) )
929 {
930 wxEventType eScrollEvent = wxEVT_NULL;
931
932 switch (wParam)
933 {
934 case SLN_CHANGE:
935 if (m_windowStyle & wxSL_TOP)
936 eScrollEvent = wxEVT_SCROLL_TOP;
937 else if (m_windowStyle & wxSL_BOTTOM)
938 eScrollEvent = wxEVT_SCROLL_BOTTOM;
939 break;
940
941 case SLN_SLIDERTRACK:
942 eScrollEvent = wxEVT_SCROLL_THUMBTRACK;
943 break;
944
945 default:
946 return false;
947 }
948
949 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
950 , SLM_QUERYSLIDERINFO
951 , MPFROM2SHORT( SMA_SHAFTDIMENSIONS, SMA_RANGEVALUE )
952 , (MPARAM)0
953 )
954 );
955 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
956 int nNewPos = 0;
957 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
958 , SLM_QUERYSLIDERINFO
959 , MPFROM2SHORT( SMA_SLIDERARMPOSITION, SMA_RANGEVALUE )
960 , (MPARAM)0
961 )
962 );
963
964 nNewPos = (int)(nPixelPos/m_dPixelToRange);
965 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
966 nNewPos++;
967 if ((nNewPos < GetMin()) || (nNewPos > GetMax()))
968 {
969 //
970 // Out of range - but we did process it
971 //
972 return true;
973 }
974 SetValue(nNewPos);
975
976 wxScrollEvent vEvent( eScrollEvent, m_windowId );
977
978 vEvent.SetPosition(nNewPos);
979 vEvent.SetEventObject(this);
980 GetEventHandler()->ProcessEvent(vEvent);
981
982 wxCommandEvent vCevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() );
983
984 vCevent.SetInt(nNewPos);
985 vCevent.SetEventObject(this);
986 return (GetEventHandler()->ProcessEvent(vCevent));
987 } // end of wxSlider::OS2OnScroll
988
989 void wxSlider::SetLineSize( int nLineSize )
990 {
991 m_nLineSize = nLineSize;
992 } // end of wxSlider::SetLineSize
993
994
995 void wxSlider::SetPageSize( int nPageSize )
996 {
997 m_nPageSize = nPageSize;
998 } // end of wxSlider::SetPageSize
999
1000 void wxSlider::SetRange(
1001 int nMinValue
1002 , int nMaxValue
1003 )
1004 {
1005 wxChar zBuf[10];
1006
1007 m_nRangeMin = nMinValue;
1008 m_nRangeMax = nMaxValue;
1009
1010 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1011 ,SLM_QUERYSLIDERINFO
1012 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1013 ,SMA_RANGEVALUE
1014 )
1015 ,(MPARAM)0
1016 )
1017 );
1018 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1019 if (m_hStaticMin)
1020 {
1021 wxSprintf(zBuf, wxT("%d"), m_nRangeMin);
1022 ::WinSetWindowText((HWND)m_hStaticMin, (PSZ)zBuf);
1023 }
1024
1025 if (m_hStaticMax)
1026 {
1027 wxSprintf(zBuf, wxT("%d"), m_nRangeMax);
1028 ::WinSetWindowText((HWND)m_hStaticMax, (PSZ)zBuf);
1029 }
1030 } // end of wxSlider::SetRange
1031
1032 void wxSlider::SetSelection(
1033 int WXUNUSED(nMinPos)
1034 , int WXUNUSED(nMaxPos)
1035 )
1036 {
1037 } // end of wxSlider::SetSelection
1038
1039 void wxSlider::SetThumbLength(
1040 int nLen
1041 )
1042 {
1043 int nBreadth;
1044
1045 m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1046 ,SLM_QUERYSLIDERINFO
1047 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1048 ,SMA_RANGEVALUE
1049 )
1050 ,(MPARAM)0
1051 )
1052 ) + 4; // for bordersizes
1053 nBreadth = SHORT2FROMMR(::WinSendMsg( GetHwnd()
1054 ,SLM_QUERYSLIDERINFO
1055 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1056 ,SMA_RANGEVALUE
1057 )
1058 ,(MPARAM)0
1059 )
1060 );
1061 ::WinSendMsg( GetHwnd()
1062 ,SLM_SETSLIDERINFO
1063 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1064 ,SMA_RANGEVALUE
1065 )
1066 ,MPFROM2SHORT(nLen, nBreadth)
1067 );
1068 m_nThumbLength = nLen + 4; // Borders
1069 } // end of wxSlider::SetThumbLength
1070
1071 void wxSlider::SetTick(
1072 int nTickPos
1073 )
1074 {
1075 nTickPos = (int)(nTickPos * m_dPixelToRange);
1076 ::WinSendMsg( GetHwnd()
1077 ,SLM_ADDDETENT
1078 ,MPFROMSHORT(nTickPos)
1079 ,NULL
1080 );
1081 } // end of wxSlider::SetTick
1082
1083 // For trackbars only
1084 void wxSlider::SetTickFreq( int n, int WXUNUSED(nPos) )
1085 {
1086 SLDCDATA vSlData;
1087 WNDPARAMS vWndParams;
1088 int nPixelPos;
1089 int i;
1090
1091 vSlData.cbSize = sizeof(SLDCDATA);
1092 if (m_windowStyle & wxSL_AUTOTICKS)
1093 {
1094 vSlData.usScale1Spacing = 0;
1095 vSlData.usScale2Spacing = 0;
1096 }
1097 vSlData.usScale1Increments = (USHORT)((m_nRangeMax - m_nRangeMin)/n);
1098 vSlData.usScale2Increments = (USHORT)((m_nRangeMax - m_nRangeMin)/n);
1099
1100 vWndParams.fsStatus = WPM_CTLDATA;
1101 vWndParams.cchText = 0L;
1102 vWndParams.pszText = NULL;
1103 vWndParams.cbPresParams = 0L;
1104 vWndParams.pPresParams = NULL;
1105 vWndParams.cbCtlData = vSlData.cbSize;
1106 vWndParams.pCtlData = (PVOID)&vSlData;
1107 ::WinSendMsg(GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vWndParams, (MPARAM)0);
1108 for (i = 1; i < (m_nRangeMax - m_nRangeMin)/n; i++)
1109 {
1110 nPixelPos = (int)(i * n * m_dPixelToRange);
1111 ::WinSendMsg( GetHwnd()
1112 ,SLM_ADDDETENT
1113 ,MPFROMSHORT(nPixelPos)
1114 ,NULL
1115 );
1116 }
1117 } // end of wxSlider::SetTickFreq
1118
1119 void wxSlider::SetValue(
1120 int nValue
1121 )
1122 {
1123 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1124 ,SLM_QUERYSLIDERINFO
1125 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1126 ,SMA_RANGEVALUE
1127 )
1128 ,(MPARAM)0
1129 )
1130 );
1131 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1132 int nNewPos = (int)(nValue * m_dPixelToRange);
1133
1134 ::WinSendMsg( GetHwnd()
1135 ,SLM_SETSLIDERINFO
1136 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
1137 ,SMA_RANGEVALUE
1138 )
1139 ,(MPARAM)nNewPos
1140 );
1141 if (m_hStaticValue)
1142 {
1143 wxSprintf(wxBuffer, wxT("%d"), nValue);
1144 ::WinSetWindowText((HWND)m_hStaticValue, (PSZ)wxBuffer);
1145 }
1146 } // end of wxSlider::SetValue
1147
1148 bool wxSlider::Show(
1149 bool bShow
1150 )
1151 {
1152 wxWindowOS2::Show(bShow);
1153 if(m_hStaticValue)
1154 ::WinShowWindow((HWND)m_hStaticValue, bShow);
1155 if(m_hStaticMin)
1156 ::WinShowWindow((HWND)m_hStaticMin, bShow);
1157 if(m_hStaticMax)
1158 ::WinShowWindow((HWND)m_hStaticMax, bShow);
1159 return true;
1160 } // end of wxSlider::Show
1161
1162 #endif // wxUSE_SLIDER