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