Dialogs and slider updates
[wxWidgets.git] / src / os2 / slider.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: slider.cpp
3 // Purpose: wxSlider
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/15/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include <stdio.h>
21 #include <wx/utils.h>
22 #include <wx/brush.h>
23 #include <wx/scrolwin.h>
24 #endif
25
26 #include "wx/slider.h"
27 #include "wx/os2/private.h"
28
29 IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
30
31 wxSlider::wxSlider()
32 {
33 m_hStaticValue = 0L;
34 m_hStaticMin = 0L;
35 m_hStaticMax = 0L;
36 m_nPageSize = 1;
37 m_nLineSize = 1;
38 m_nRangeMax = 0;
39 m_nRangeMin = 0;
40 m_nTickFreq = 0;
41 } // end of wxSlider::wxSlider
42
43 wxSlider::~wxSlider()
44 {
45 if (m_hStaticMin)
46 ::WinDestroyWindow((HWND)m_hStaticMin);
47 if (m_hStaticMax)
48 ::WinDestroyWindow((HWND)m_hStaticMax);
49 if (m_hStaticValue)
50 ::WinDestroyWindow((HWND)m_hStaticValue);
51 } // end of wxSlider::~wxSlider
52
53 void wxSlider::AdjustSubControls(
54 int nX
55 , int nY
56 , int nWidth
57 , int nHeight
58 , int nSizeFlags
59 )
60 {
61 SWP vSwp;
62 int nXOffset = nX;
63 int nYOffset = nY;
64 int nCx; // slider,min,max sizes
65 int nCy;
66 int nCyf;
67 char zBuf[300];
68
69 wxGetCharSize( GetHWND()
70 ,&nCx
71 ,&nCy
72 ,&this->GetFont()
73 );
74
75 if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL)
76 {
77 if (m_windowStyle & wxSL_LABELS )
78 {
79 int nMinLen = 0;
80 int nMaxLen = 0;
81
82 ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf);
83 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont());
84
85 ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
86 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont());
87
88 if (m_hStaticValue)
89 {
90 int nNewWidth = wxMax(nMinLen, nMaxLen);
91 int nValueHeight = nCyf;
92
93 ::WinSetWindowPos( (HWND)m_hStaticValue
94 ,HWND_TOP
95 ,(LONG)nXOffset - (nNewWidth + nCx + nMinLen + nCx)
96 ,(LONG)nYOffset
97 ,(LONG)nNewWidth
98 ,(LONG)nValueHeight
99 ,SWP_SIZE | SWP_MOVE
100 );
101 }
102 ::WinSetWindowPos( (HWND)m_hStaticMin
103 ,HWND_TOP
104 ,(LONG)nXOffset - (nMinLen + nCx)
105 ,(LONG)nYOffset
106 ,(LONG)nMinLen
107 ,(LONG)nCy
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)nCy
118 ,SWP_ZORDER | SWP_SHOW
119 );
120 }
121 }
122 else
123 {
124 //
125 // Now deal with a vertical slider
126 //
127
128 if (m_lWindowStyle & winSL_LABELS )
129 {
130 int nMinLen = 0;
131 int nMaxLen = 0;
132
133 ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf);
134 GetTextExtent(zBuf, &lMinLen, &nCyf, NULL, NULL, &this->GetFont());
135
136 ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
137 GetTextExtent(zBuf, &lMaxLen, &nCyf, NULL, NULL, &this->GetFont());
138
139 if (m_hStaticValue)
140 {
141 int nNewWidth = (DAWUTL_MAX(nMinLen, nMaxLen));
142
143 ::WinSetWindowPos( (HWND)m_hStaticValue
144 ,HWND_TOP
145 ,(LONG)nXOffset
146 ,(LONG)nYOffset + nHeight + nCyf
147 ,(LONG)nNewWidth
148 ,(LONG)nCyf
149 ,SWP_SIZE | SWP_MOVE
150 );
151 }
152 ::WinSetWindowPos( (HWND)m_hStaticMax
153 ,HWND_TOP
154 ,(LONG)nXOffset
155 ,(LONG)nYOffset + nHeight
156 ,(LONG)nMaxLen
157 ,(LONG)nCyf
158 ,SWP_SIZE | SWP_MOVE
159 );
160 ::WinSetWindowPos( (HWND)m_hStaticMin
161 ,HWND_TOP
162 ,(LONG)nXOffset
163 ,(LONG)nYOffset - nCyf
164 ,(LONG)nMinLen
165 ,(LONG)nCyf
166 ,SWP_SIZE | SWP_MOVE
167 );
168 }
169 }
170 } // end of wxSlider::AdjustSubControls
171
172 void wxSlider::ClearSel()
173 {
174 } // end of wxSlider::ClearSel
175
176 void wxSlider::ClearTicks()
177 {
178 } // end of wxSlider::ClearTicks
179
180 void wxSlider::Command (
181 wxCommandEvent& rEvent
182 )
183 {
184 SetValue(rEvent.GetInt());
185 ProcessCommand(rEvent);
186 } // end of wxSlider::Command
187
188 bool wxSlider::ContainsHWND(
189 WXHWND hWnd
190 ) const
191 {
192 return ( hWnd == GetStaticMin() ||
193 hWnd == GetStaticMax() ||
194 hWnd == GetEditValue()
195 );
196 } // end of wxSlider::ContainsHWND
197
198 bool wxSlider::Create(
199 wxWindow* pParent
200 , wxWindowID vId
201 , int nValue
202 , int nMinValue
203 , int nMaxValue
204 , const wxPoint& rPos
205 , const wxSize& rSize
206 , long lStyle
207 #if wxUSE_VALIDATORS
208 , const wxValidator& rValidator
209 #endif
210 , const wxString& rsName
211 )
212 {
213 int nX = rPos.x;
214 int nY = rPos.y;
215 int nWidth = rSize.x;
216 int nHeight = rSize.y;
217 long lMsStyle = 0L;
218 long lWstyle = 0L;
219
220 SetName(rsName);
221 #if wxUSE_VALIDATORS
222 SetValidator(rValidator);
223 #endif
224 if (pParent)
225 pParent->AddChild(this);
226 SetBackgroundColour(pParent->GetBackgroundColour()) ;
227 SetForegroundColour(pParent->GetForegroundColour()) ;
228
229 m_hStaticValue = 0L;
230 m_hStaticMin = 0L;
231 m_hStaticMax = 0L;
232 m_nPageSize = 1;
233 m_nLineSize = 1;
234 m_windowStyle = lStyle;
235 m_nTickFreq = 0;
236
237 if (vId == -1)
238 m_windowId = (int)NewControlId();
239 else
240 m_windowId = vId;
241
242 if (m_windowStyle & wxCLIP_SIBLINGS )
243 lMsStyle |= WS_CLIPSIBLINGS;
244
245 if (m_windowStyle & wxSL_LABELS)
246 {
247 lMsStyle |= WS_VISIBLE | SS_TEXT | DT_VCENTER;
248
249 m_hStaticValue = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
250 ,WC_STATIC // Window class
251 ,(PSZ)NULL // Initial Text
252 ,(ULONG)lMsStyle // Style flags
253 ,0L, 0L, 0L, 0L // Origin -- 0 size
254 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
255 ,HWND_TOP // initial z position
256 ,(ULONG)NewControlId() // Window identifier
257 ,NULL // no control data
258 ,NULL // no Presentation parameters
259 );
260
261 //
262 // Now create min static control
263 //
264 sprintf(wxBuffer, "%d", nMinValue);
265 lWstyle = SS_TEXT|DT_LEFT|WS_VISIBLE;
266 if (m_windowStyle & wxCLIP_SIBLINGS)
267 lWstyle |= WS_CLIPSIBLINGS;
268
269 m_hStaticMin = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
270 ,WC_STATIC // Window class
271 ,(PSZ)wxBuffer // Initial Text
272 ,(ULONG)lWstyle // Style flags
273 ,0L, 0L, 0L, 0L // Origin -- 0 size
274 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
275 ,HWND_TOP // initial z position
276 ,(ULONG)NewControlId() // Window identifier
277 ,NULL // no control data
278 ,NULL // no Presentation parameters
279 );
280 }
281 lMsStyle = 0;
282
283 SLDCDATA vSlData;
284
285 vSlData.cbSize = sizeof(SLDCDATA);
286 if (m_windowStyle & wxSL_VERTICAL)
287 lMsStyle = SLS_VERTICAL | SLS_HOMEBOTTOM | WS_VISIBLE | WS_TABSTOP;
288 else
289 lMsStyle = SLS_HORIZONTAL | SLS_HOMELEFT| WS_VISIBLE | WS_TABSTOP;
290
291 if (m_windowStyle & wxCLIP_SIBLINGS)
292 lMsStyle |= WS_CLIPSIBLINGS;
293
294 if (m_windowStyle & wxSL_AUTOTICKS)
295 {
296 vSlData.usScale1Spacing = 0;
297 vSlData.usScale2Spacing = 0;
298 }
299
300 if (m_windowStyle & wxSL_LEFT)
301 lMsStyle |= SLS_PRIMARYSCALE2; // if SLS_VERTICAL then SCALE2 is to the left
302 else if (m_windowStyle & wxSL_RIGHT)
303 lMsStyle |= SLS_PRIMARYSCALE1; // if SLS_VERTICAL then SCALE2 is to the right
304 else if (m_windowStyle & wxSL_TOP)
305 lMsStyle |= SLS_PRIMARYSCALE1; // if SLS_HORIZONTAL then SCALE1 is to the top
306 else if (m_windowStyle & wxSL_BOTTOM )
307 lMsStyle |= SLS_PRIMARYSCALE2; // if SLS_HORIZONTAL then SCALE1 is to the bottom
308 else if ( m_windowStyle & wxSL_BOTH )
309 lMsStyle |= SLS_PRIMARYSCALE1 | SLS_PRIMARYSCALE2;
310 else
311 lMsStyle |= SLS_PRIMARYSCALE2;
312 lMsStyle |= SLS_RIBBONSTRIP;
313
314 m_nPageSize = ((nMaxValue - nMinValue)/10);
315 vSlData.usScale1Increments = m_nPageSize;
316 vSlData.usScale2Increments = m_nPageSize;
317
318 HWND hScrollBar = ::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
319 ,WC_SLIDER // Window class
320 ,(PSZ)wxBuffer // Initial Text
321 ,(ULONG)lMsStyle // Style flags
322 ,0L, 0L, 0L, 0L // Origin -- 0 size
323 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
324 ,HWND_TOP // initial z position
325 ,(HMENU)m_windowId // Window identifier
326 ,&vSlData // Slider control data
327 ,NULL // no Presentation parameters
328 );
329 m_nRangeMax = nMaxValue;
330 m_nRangeMin = nMinValue;
331
332 //
333 // Set the size of the ticks ... default to 6 pixels
334 //
335 ::WinSendMsg( hScrollBar
336 ,SLM_SETTICKSIZE
337 ,MPFROM2SHORT(SMA_SETALLTICKS, (USHORT)12)
338 ,NULL
339 );
340 //
341 // Set the position to the initial value
342 //
343 ::WinSendMsg( hScrollBar
344 ,SLM_SETSLIDERINFO
345 ,MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE)
346 ,(MPARAM)nValue
347 );
348
349 m_hWnd = (WXHWND)hScrollBar;
350 SubclassWin(GetHWND());
351 ::WinSetWindowText((HWND)m_hWnd, "");
352
353 SetFont(*wxSMALL_FONT);
354 if (m_windowStyle & wxSL_LABELS)
355 {
356 //
357 // Finally, create max value static item
358 //
359 sprintf(wxBuffer, "%d", nMaxValue);
360 lWstyle = SS_TEXT|DT_LEFT|WS_VISIBLE;
361 if (m_windowStyle & wxCLIP_SIBLINGS)
362 lMsStyle |= WS_CLIPSIBLINGS;
363
364 m_hStaticMax = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
365 ,WC_STATIC // Window class
366 ,(PSZ)wxBuffer // Initial Text
367 ,(ULONG)lWstyle // Style flags
368 ,0L, 0L, 0L, 0L // Origin -- 0 size
369 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
370 ,HWND_TOP // initial z position
371 ,(ULONG)NewControlId() // Window identifier
372 ,NULL // no control data
373 ,NULL // no Presentation parameters
374 );
375 if (GetFont().Ok())
376 {
377 if (GetFont().GetResourceHandle())
378 {
379 if (m_hStaticMin)
380 wxOS2SetFont( m_hStaticMin
381 ,GetFont()
382 );
383 if (m_hStaticMax)
384 wxOS2SetFont( m_hStaticMax
385 ,GetFont()
386 );
387 if (m_hStaticValue)
388 wxOS2SetFont( m_hStaticValue
389 ,GetFont()
390 );
391 }
392 }
393 }
394
395 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("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("BLUE"));
457 lColor = (LONG)vColour.GetPixel();
458 ::WinSetPresParam( m_hWnd
459 ,PP_HILITEBACKGROUNDCOLOR
460 ,sizeof(LONG)
461 ,(PVOID)&lColor
462 );
463 SetValue(nValue);
464 delete pTextFont;
465 return TRUE;
466 } // end of wxSlider::Create
467
468 void wxSlider::DoSetSize(
469 int nX
470 , int nY
471 , int nWidth
472 , int nHeight
473 , int nSizeFlags
474 )
475 {
476 int nX1 = nX;
477 int nY1 = nY;
478 int nWidth1 = nWidth;
479 int nHeight1 = nHeight;
480 int nXOffset = nX;
481 int nYOffset = nY;
482 int nCx; // slider,min,max sizes
483 int nCy;
484 int nCyf;
485 int nCurrentX;
486 int nCurrentY;
487 char zBuf[300];
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 ,&this->GetFont()
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, zBuf);
544 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont());
545 ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
546 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont());
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 - (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 - (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 nXOffset += nSliderLength + nCx;
594
595 ::WinSetWindowPos( (HWND)m_hStaticMax
596 ,HWND_TOP
597 ,(LONG)nXOffset
598 ,(LONG)nYOffset - (nCyf * 1.2)
599 ,(LONG)nMaxLen
600 ,(LONG)nCy
601 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
602 );
603 }
604 else
605 {
606 //
607 // No labels
608 // If we're prepared to use the existing size, then...
609 //
610 if (nWidth == -1 && nHeight == -1 &&
611 ((nSizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
612 {
613 GetSize( &nWidth1
614 ,&nHeight1
615 );
616 }
617 if (nWidth1 < 0)
618 nWidth1 = 200;
619 if (nHeight1 < 0)
620 nHeight1 = 20;
621 ::WinSetWindowPos( GetHwnd()
622 ,HWND_TOP
623 ,(LONG)nX1
624 ,(LONG)nY1
625 ,(LONG)nWidth1
626 ,(LONG)nHeight1
627 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
628 );
629 }
630 }
631
632 //
633 // Now deal with a vertical slider
634 //
635 else
636 {
637 if (m_windowStyle & wxSL_LABELS )
638 {
639 int nMinLen;
640 int nMaxLen;
641
642 ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf);
643 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont());
644 ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
645 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont());
646 if (m_hStaticValue)
647 {
648 int nNewWidth = wxMax(nMinLen, nMaxLen);
649 int nValueHeight = nCyf;
650
651 nNewWidth += nCx;
652
653 //
654 // The height needs to be a bit bigger under Win95 if using native
655 // 3D effects.
656 //
657 ::WinSetWindowPos( (HWND)m_hStaticValue
658 ,HWND_TOP
659 ,(LONG)nXOffset
660 ,(LONG)nYOffset + lHeight
661 ,(LONG)nNewWidth
662 ,(LONG)nValueHeight
663 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
664 );
665 nUsedHeight += nCy;
666 }
667 ::WinSetWindowPos( (HWND)m_hStaticMin
668 ,HWND_TOP
669 ,(LONG)nXOffset
670 ,(LONG)nYOffset + lHeight -lCyf
671 ,(LONG)nMinLen
672 ,(LONG)nCy
673 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
674 );
675 nUsedHeight += nCy;
676
677 int nSliderLength = nHeight1 - (nUsedHeight + (2 * nCy));
678 int nSliderWidth = nWidth1;
679
680 if (nSliderWidth < 0)
681 nSliderWidth = 20;
682
683 //
684 // Slider must have a minimum/default length
685 //
686 if (nSliderLength < 100)
687 nSliderLength = 100;
688
689 ::WinSetWindowPos( GetHwnd()
690 ,HWND_TOP
691 ,(LONG)nXOffset
692 ,(LONG)nYOffset
693 ,(LONG)nSliderWidth
694 ,(LONG)nSliderLength
695 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
696 );
697 nUsedHeight += nSliderLength;
698 ::WinSetWindowPos( (HWND)m_hStaticMax
699 ,HWND_TOP
700 ,(LONG)nXOffset
701 ,(LONG)nYOffset
702 ,(LONG)nMaxLen
703 ,(LONG)nCy
704 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
705 );
706 }
707 else
708 {
709 //
710 // No labels
711 // If we're prepared to use the existing size, then...
712 //
713 if (nWidth == -1 && nHeight == -1 &&
714 ((nSizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
715 {
716 GetSize( &nWidth1
717 ,&nHeight1
718 );
719 }
720 if (nWidth1 < 0)
721 nWidth1 = 20;
722 if (nHeight1 < 0)
723 nHeight1 = 200;
724 ::WinSetWindowPos( GetHwnd()
725 ,HWND_TOP
726 ,(LONG)nX1
727 ,(LONG)nY1
728 ,(LONG)nWidth1
729 ,(LONG)nHeight1
730 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
731 );
732 }
733 }
734 } // end of void wxSlider::DoSetSize
735
736 int wxSlider::GetLineSize() const
737 {
738 return 1;
739 } // end of wxSlider::GetLineSize
740
741 int wxSlider::GetPageSize() const
742 {
743 return m_nPageSize;
744 } // end of wxSlider::GetPageSize
745
746 void wxSlider::GetPosition(
747 int* pnX
748 , int* pnY
749 ) const
750 {
751 wxWindowOS2* pParent = GetParent();
752 RECTL vRect;
753
754 vRect.xLeft = -1;
755 vRect.xRight = -1;
756 vRect.yTop = -1;
757 vRect.yBottom = -1;
758 wxFindMaxSize( GetHWND()
759 ,&vRect
760 );
761
762 if (m_hStaticMin)
763 wxFindMaxSize( m_hStaticMin
764 ,&vRect
765 );
766 if (m_hStaticMax)
767 wxFindMaxSize( m_hStaticMax
768 ,&vRect
769 );
770 if (m_hStaticValue)
771 wxFindMaxSize( m_hStaticValue
772 ,&vRect
773 );
774
775 //
776 // Since we now have the absolute screen coords,
777 // if there's a parent we must subtract its top left corner
778 //
779 POINTL vPoint;
780
781 vPoint.x = vRect.xLeft;
782 vPoint.y = vRect.yTop;
783
784 if (pParent)
785 {
786 SWP vSwp;
787
788 ::WinQueryWindowPos((HWND)pParent->GetHWND(), &vSwp);
789 vPoint.x = vSwp.x;
790 vPoint.y = vSwp.y;
791 }
792
793 //
794 // We may be faking the client origin.
795 // So a window that's really at (0, 30) may appear
796 // (to wxWin apps) to be at (0, 0).
797 //
798 if (GetParent())
799 {
800 wxPoint vPt(GetParent()->GetClientAreaOrigin());
801
802 vPoint.x -= vPt.x;
803 vPoint.y -= vPt.y;
804 }
805 *pnX = vPoint.x;
806 *pnY = vPoint.y;
807 } // end of wxSlider::GetPosition
808
809 int wxSlider::GetSelEnd() const
810 {
811 return 0;
812 } // end of wxSlider::GetSelEnd
813
814 int wxSlider::GetSelStart() const
815 {
816 return 0;
817 } // end of wxSlider::GetSelStart
818
819 void wxSlider::DoGetSize(
820 int* pnWidth
821 , int* pnHeight
822 ) const
823 {
824 GetSize( pnWidth
825 ,pnHeight
826 );
827 } // end of wxSlider::DoGetSize
828
829 void wxSlider::GetSize(
830 int* pnWidth
831 , int* pnHeight
832 ) const
833 {
834 RECTL vRect;
835
836 vRect.xLeft = -1;
837 vRect.xRight = -1;
838 vRect.yTop = -1;
839 vRect.yBottom = -1;
840
841 wxFindMaxSize( GetHWND()
842 ,&vRect
843 );
844
845 if (m_hStaticMin)
846 wxFindMaxSize( m_hStaticMin
847 ,&vRect
848 );
849 if (m_hStaticMax)
850 wxFindMaxSize( m_hStaticMax
851 ,&vRect
852 );
853 if (m_hStaticValue)
854 wxFindMaxSize( m_hStaticValue
855 ,&vRect
856 );
857 *pnWidth = vRect.xRight - vRect.xLeft;
858 *pnHeight = vRect.yBottom - vRect.yTop;
859 } // end of wxSlider::GetSize
860
861 int wxSlider::GetThumbLength() const
862 {
863 return m_nThumbLength;
864 } // end of wxSlider::GetThumbLength
865
866 int wxSlider::GetValue() const
867 {
868 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
869 ,SLM_QUERYSLIDERINFO
870 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
871 ,SMA_RANGEVALUE
872 )
873 ,(MPARAM)0
874 )
875 );
876 double dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
877 int nNewPos = 0;
878 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
879 ,SLM_QUERYSLIDERINFO
880 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
881 ,SMA_RANGEVALUE
882 )
883 ,(MPARAM)0
884 )
885 );
886 nNewPos = (int)(nPixelPos/dPixelToRange);
887 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
888 nNewPos++;
889 return nNewPos;
890 } // end of wxSlider::GetValue
891
892 WXHBRUSH wxSlider::OnCtlColor(
893 WXHDC hDC
894 , WXHWND hWnd
895 , WXUINT uCtlColor
896 , WXUINT uMessage
897 , WXWPARAM wParam
898 , WXLPARAM lParam
899 )
900 {
901 return (wxControl::OnCtlColor( hDC
902 ,hWnd
903 ,uCtlColor
904 ,uMessage
905 ,wParam
906 ,lParam
907 )
908 );
909 } // end of wxSlider::OnCtlColor
910
911 bool wxSlider::OS2OnScroll(
912 int WXUNUSED(nOrientation)
913 , WXWORD wParam
914 , WXWORD wPos
915 , WXHWND hControl
916 )
917 {
918 wxEventType eScrollEvent = wxEVT_NULL;
919
920 switch (wParam)
921 {
922 case SLN_CHANGE:
923 if (m_windowStyle & wxSL_TOP)
924 eScrollEvent = wxEVT_SCROLL_TOP;
925 else if (m_windowStyle & wxSL_BOTTOM)
926 eScrollEvent = wxEVT_SCROLL_BOTTOM;
927 break;
928
929 case SLN_SLIDERTRACK:
930 eScrollEvent = wxEVT_SCROLL_THUMBTRACK;
931 break;
932
933 default:
934 return FALSE;
935 }
936
937 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
938 ,SLM_QUERYSLIDERINFO
939 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
940 ,SMA_RANGEVALUE
941 )
942 ,(MPARAM)0
943 )
944 );
945 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
946 int nNewPos = 0;
947 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
948 ,SLM_QUERYSLIDERINFO
949 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
950 ,SMA_RANGEVALUE
951 )
952 ,(MPARAM)0
953 )
954 );
955 nNewPos = (nPixelPos/m_dPixelToRange);
956 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
957 nNewPos++;
958 if ((nNewPos < GetMin()) || (nNewPos > GetMax()))
959 {
960 //
961 // Out of range - but we did process it
962 //
963 return TRUE;
964 }
965 SetValue(nNewPos);
966
967 wxScrollEvent vEvent( eScrollEvent
968 ,m_windowId
969 );
970
971 vEvent.SetPosition(nNewPos);
972 vEvent.SetEventObject(this);
973 GetEventHandler()->ProcessEvent(vEvent);
974
975 wxCommandEvent vCevent( wxEVT_COMMAND_SLIDER_UPDATED
976 ,GetId()
977 );
978
979 vCevent.SetInt(nNewPos);
980 vCevent.SetEventObject(this);
981 return (GetEventHandler()->ProcessEvent(vCevent));
982 } // end of wxSlider::OS2OnScroll
983
984 void wxSlider::SetLineSize(
985 int nLineSize
986 )
987 {
988 m_nLineSize = nLineSize;
989 } // end of wxSlider::SetLineSize
990
991
992 void wxSlider::SetPageSize(
993 int nPageSize
994 )
995 {
996 m_nPageSize = nPageSize;
997 } // end of wxSlider::SetPageSize
998
999 void wxSlider::SetRange(
1000 int nMinValue
1001 , int nMaxValue
1002 )
1003 {
1004 wxChar zBuf[10];
1005
1006 m_nRangeMin = nMinValue;
1007 m_nRangeMax = nMaxValue;
1008
1009 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1010 ,SLM_QUERYSLIDERINFO
1011 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1012 ,SMA_RANGEVALUE
1013 )
1014 ,(MPARAM)0
1015 )
1016 );
1017 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1018 if (m_hStaticMin)
1019 {
1020 wxSprintf(zBuf, wxT("%d"), m_nRangeMin);
1021 ::WinSetWindowText((HWND)m_hStaticMin, zBuf);
1022 }
1023
1024 if (m_hStaticMax)
1025 {
1026 wxSprintf(zBuf, wxT("%d"), m_nRangeMax);
1027 ::WinSetWindowText((HWND)m_hStaticMax, zBuf);
1028 }
1029 } // end of wxSlider::SetRange
1030
1031 void wxSlider::SetSelection(
1032 int WXUNUSED(nMinPos)
1033 , int WXUNUSED(nMaxPos)
1034 )
1035 {
1036 } // end of wxSlider::SetSelection
1037
1038 void wxSlider::SetThumbLength(
1039 int nLen
1040 )
1041 {
1042 int nBreadth;
1043
1044 m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1045 ,SLM_QUERYSLIDERINFO
1046 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1047 ,SMA_RANGEVALUE
1048 )
1049 ,(MPARAM)0
1050 )
1051 ) + 4; // for bordersizes
1052 nBreadth = SHORT2FROMMR(::WinSendMsg( GetHwnd()
1053 ,SLM_QUERYSLIDERINFO
1054 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1055 ,SMA_RANGEVALUE
1056 )
1057 ,(MPARAM)0
1058 )
1059 );
1060 ::WinSendMsg( GetHwnd()
1061 ,SLM_SETSLIDERINFO
1062 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1063 ,SMA_RANGEVALUE
1064 )
1065 ,MPFROM2SHORT(nLen, nBreadth)
1066 );
1067 m_nThumbLength = nLen + 4; // Borders
1068 } // end of wxSlider::SetThumbLength
1069
1070 void wxSlider::SetTick(
1071 int nTickPos
1072 )
1073 {
1074 nTickPos *= m_dPixelToRange;
1075 ::WinSendMsg( GetHwnd()
1076 ,SLM_ADDDETENT
1077 ,MPFROMSHORT(nTickPos)
1078 ,NULL
1079 );
1080 } // end of wxSlider::SetTick
1081
1082 // For trackbars only
1083 void wxSlider::SetTickFreq(
1084 int n
1085 , int nPos
1086 )
1087 {
1088 SLDCDATA vSlData;
1089 WNDPARAMS vWndParams;
1090 int nPixelPos;
1091 int i;
1092
1093 vSlData.cbSize = sizeof(SLDCDATA);
1094 if (m_windowStyle & wxSL_AUTOTICKS)
1095 {
1096 vSlData.usScale1Spacing = 0;
1097 vSlData.usScale2Spacing = 0;
1098 }
1099 vSlData.usScale1Increments = (m_nRangeMax - m_nRangeMin)/n;
1100 vSlData.usScale2Increments = (m_nRangeMax - m_nRangeMin)/n;
1101
1102 vWndParams.fsStatus = WPM_CTLDATA;
1103 vWndParams.cchText = 0L;
1104 vWndParams.pszText = NULL;
1105 vWndParams.cbPresParams = 0L;
1106 vWndParams.pPresParams = NULL;
1107 vWndParams.cbCtlData = vSlData.cbSize;
1108 vWndParams.pCtlData = (PVOID)&vSlData;
1109 ::WinSendMsg(GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vWndParams, (MPARAM)0);
1110 for (i = 1; i < (m_nRangeMax - m_nRangeMin)/n; i++)
1111 {
1112 nPixelPos = i * n * m_dPixelToRange;
1113 ::WinSendMsg( GetHwnd()
1114 ,SLM_ADDDETENT
1115 ,MPFROMSHORT(nPixelPos)
1116 ,NULL
1117 );
1118 }
1119 } // end of wxSlider::SetTickFreq
1120
1121 void wxSlider::SetValue(
1122 int nValue
1123 )
1124 {
1125 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1126 ,SLM_QUERYSLIDERINFO
1127 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
1128 ,SMA_RANGEVALUE
1129 )
1130 ,(MPARAM)0
1131 )
1132 );
1133 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1134 ,SLM_QUERYSLIDERINFO
1135 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1136 ,SMA_RANGEVALUE
1137 )
1138 ,(MPARAM)0
1139 )
1140 );
1141 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1142 int nNewPos = (int)(nValue * m_dPixelToRange);
1143
1144 ::WinSendMsg( GetHwnd()
1145 ,SLM_SETSLIDERINFO
1146 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
1147 ,SMA_RANGEVALUE
1148 )
1149 ,(MPARAM)nNewPos
1150 );
1151 if (m_hStaticValue)
1152 {
1153 wxSprintf(wxBuffer, wxT("%d"), nValue);
1154 ::WinSetWindowText((HWND)m_hStaticValue, wxBuffer);
1155 }
1156 } // end of wxSlider::SetValue
1157
1158 bool wxSlider::Show(
1159 bool bShow
1160 )
1161 {
1162 wxWindowOS2::Show(bShow);
1163 if(m_hStaticValue)
1164 ::WinShowWindow((HWND)m_hStaticValue, bShow);
1165 if(m_hStaticMin)
1166 ::WinShowWindow((HWND)m_hStaticMin, bShow);
1167 if(m_hStaticMax)
1168 ::WinShowWindow((HWND)m_hStaticMax, bShow);
1169 return TRUE;
1170 } // end of wxSlider::Show
1171