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