]> git.saurik.com Git - wxWidgets.git/blob - src/os2/slider.cpp
assert that name, not full path, is used in RenameEntry(); fixed RenameGroup() which...
[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 #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(
56 int nX
57 , int nY
58 , int nWidth
59 , int nHeight
60 , int nSizeFlags
61 )
62 {
63 int nXOffset = nX;
64 int nYOffset = nY;
65 int nCx; // slider,min,max sizes
66 int nCy;
67 int nCyf;
68 char zBuf[300];
69
70 wxGetCharSize( GetHWND()
71 ,&nCx
72 ,&nCy
73 ,&this->GetFont()
74 );
75
76 if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL)
77 {
78 if (m_windowStyle & wxSL_LABELS )
79 {
80 int nMinLen = 0;
81 int nMaxLen = 0;
82
83 ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf);
84 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont());
85
86 ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
87 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont());
88
89 if (m_hStaticValue)
90 {
91 int nNewWidth = wxMax(nMinLen, nMaxLen);
92 int nValueHeight = nCyf;
93
94 ::WinSetWindowPos( (HWND)m_hStaticValue
95 ,HWND_TOP
96 ,(LONG)nXOffset - (nNewWidth + nCx + nMinLen + nCx)
97 ,(LONG)nYOffset
98 ,(LONG)nNewWidth
99 ,(LONG)nValueHeight
100 ,SWP_SIZE | SWP_MOVE
101 );
102 }
103 ::WinSetWindowPos( (HWND)m_hStaticMin
104 ,HWND_TOP
105 ,(LONG)nXOffset - (nMinLen + nCx)
106 ,(LONG)nYOffset
107 ,(LONG)nMinLen
108 ,(LONG)nCyf
109 ,SWP_SIZE | SWP_MOVE
110 );
111 nXOffset += nWidth + nCx;
112
113 ::WinSetWindowPos( (HWND)m_hStaticMax
114 ,HWND_TOP
115 ,(LONG)nXOffset
116 ,(LONG)nYOffset
117 ,(LONG)nMaxLen
118 ,(LONG)nCyf
119 ,SWP_ZORDER | SWP_SHOW
120 );
121 }
122 }
123 else
124 {
125 //
126 // Now deal with a vertical slider
127 //
128
129 if (m_windowStyle & wxSL_LABELS )
130 {
131 int nMinLen = 0;
132 int nMaxLen = 0;
133
134 ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf);
135 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont());
136
137 ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
138 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont());
139
140 if (m_hStaticValue)
141 {
142 int nNewWidth = (wxMax(nMinLen, nMaxLen));
143
144 ::WinSetWindowPos( (HWND)m_hStaticValue
145 ,HWND_TOP
146 ,(LONG)nXOffset
147 ,(LONG)nYOffset + nHeight + nCyf
148 ,(LONG)nNewWidth
149 ,(LONG)nCyf
150 ,SWP_SIZE | SWP_MOVE
151 );
152 }
153 ::WinSetWindowPos( (HWND)m_hStaticMax
154 ,HWND_TOP
155 ,(LONG)nXOffset
156 ,(LONG)nYOffset + nHeight
157 ,(LONG)nMaxLen
158 ,(LONG)nCyf
159 ,SWP_SIZE | SWP_MOVE
160 );
161 ::WinSetWindowPos( (HWND)m_hStaticMin
162 ,HWND_TOP
163 ,(LONG)nXOffset
164 ,(LONG)nYOffset - nCyf
165 ,(LONG)nMinLen
166 ,(LONG)nCyf
167 ,SWP_SIZE | SWP_MOVE
168 );
169 }
170 }
171 } // end of wxSlider::AdjustSubControls
172
173 void wxSlider::ClearSel()
174 {
175 } // end of wxSlider::ClearSel
176
177 void wxSlider::ClearTicks()
178 {
179 } // end of wxSlider::ClearTicks
180
181 void wxSlider::Command (
182 wxCommandEvent& rEvent
183 )
184 {
185 SetValue(rEvent.GetInt());
186 ProcessCommand(rEvent);
187 } // end of wxSlider::Command
188
189 bool wxSlider::ContainsHWND(
190 WXHWND hWnd
191 ) const
192 {
193 return ( hWnd == GetStaticMin() ||
194 hWnd == GetStaticMax() ||
195 hWnd == GetEditValue()
196 );
197 } // end of wxSlider::ContainsHWND
198
199 bool wxSlider::Create(
200 wxWindow* pParent
201 , wxWindowID vId
202 , int nValue
203 , int nMinValue
204 , int nMaxValue
205 , const wxPoint& rPos
206 , const wxSize& rSize
207 , long lStyle
208 , const wxValidator& rValidator
209 , const wxString& rsName
210 )
211 {
212 int nX = rPos.x;
213 int nY = rPos.y;
214 int nWidth = rSize.x;
215 int nHeight = rSize.y;
216 long lMsStyle = 0L;
217 long lWstyle = 0L;
218
219 SetName(rsName);
220 #if wxUSE_VALIDATORS
221 SetValidator(rValidator);
222 #endif
223 if (pParent)
224 pParent->AddChild(this);
225 SetBackgroundColour(pParent->GetBackgroundColour()) ;
226 SetForegroundColour(pParent->GetForegroundColour()) ;
227
228 m_hStaticValue = 0L;
229 m_hStaticMin = 0L;
230 m_hStaticMax = 0L;
231 m_nPageSize = 1;
232 m_nLineSize = 1;
233 m_windowStyle = lStyle;
234 m_nTickFreq = 0;
235
236 if (vId == -1)
237 m_windowId = (int)NewControlId();
238 else
239 m_windowId = vId;
240
241 if (m_windowStyle & wxCLIP_SIBLINGS )
242 lMsStyle |= WS_CLIPSIBLINGS;
243
244 if (m_windowStyle & wxSL_LABELS)
245 {
246 lMsStyle |= WS_VISIBLE | SS_TEXT | DT_VCENTER;
247
248 m_hStaticValue = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
249 ,WC_STATIC // Window class
250 ,(PSZ)NULL // Initial Text
251 ,(ULONG)lMsStyle // Style flags
252 ,0L, 0L, 0L, 0L // Origin -- 0 size
253 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
254 ,HWND_TOP // initial z position
255 ,(ULONG)NewControlId() // Window identifier
256 ,NULL // no control data
257 ,NULL // no Presentation parameters
258 );
259
260 //
261 // Now create min static control
262 //
263 sprintf(wxBuffer, "%d", nMinValue);
264 lWstyle = SS_TEXT|DT_LEFT|WS_VISIBLE;
265 if (m_windowStyle & wxCLIP_SIBLINGS)
266 lWstyle |= WS_CLIPSIBLINGS;
267
268 m_hStaticMin = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
269 ,WC_STATIC // Window class
270 ,(PSZ)wxBuffer // Initial Text
271 ,(ULONG)lWstyle // Style flags
272 ,0L, 0L, 0L, 0L // Origin -- 0 size
273 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
274 ,HWND_TOP // initial z position
275 ,(ULONG)NewControlId() // Window identifier
276 ,NULL // no control data
277 ,NULL // no Presentation parameters
278 );
279 }
280 lMsStyle = 0;
281
282 SLDCDATA vSlData;
283
284 vSlData.cbSize = sizeof(SLDCDATA);
285 if (m_windowStyle & wxSL_VERTICAL)
286 lMsStyle = SLS_VERTICAL | SLS_HOMEBOTTOM | WS_VISIBLE | WS_TABSTOP;
287 else
288 lMsStyle = SLS_HORIZONTAL | SLS_HOMELEFT | WS_VISIBLE | WS_TABSTOP;
289
290 if (m_windowStyle & wxCLIP_SIBLINGS)
291 lMsStyle |= WS_CLIPSIBLINGS;
292
293 if (m_windowStyle & wxSL_AUTOTICKS)
294 {
295 vSlData.usScale1Spacing = 0;
296 vSlData.usScale2Spacing = 0;
297 }
298
299 if (m_windowStyle & wxSL_LEFT)
300 lMsStyle |= SLS_PRIMARYSCALE2; // if SLS_VERTICAL then SCALE2 is to the left
301 else if (m_windowStyle & wxSL_RIGHT)
302 lMsStyle |= SLS_PRIMARYSCALE1; // if SLS_VERTICAL then SCALE2 is to the right
303 else if (m_windowStyle & wxSL_TOP)
304 lMsStyle |= SLS_PRIMARYSCALE1; // if SLS_HORIZONTAL then SCALE1 is to the top
305 else if (m_windowStyle & wxSL_BOTTOM )
306 lMsStyle |= SLS_PRIMARYSCALE2; // if SLS_HORIZONTAL then SCALE1 is to the bottom
307 else if ( m_windowStyle & wxSL_BOTH )
308 lMsStyle |= SLS_PRIMARYSCALE1 | SLS_PRIMARYSCALE2;
309 else
310 lMsStyle |= SLS_PRIMARYSCALE2;
311 lMsStyle |= SLS_RIBBONSTRIP;
312
313 m_nPageSize = ((nMaxValue - nMinValue)/10);
314 vSlData.usScale1Increments = m_nPageSize;
315 vSlData.usScale2Increments = m_nPageSize;
316
317 HWND hScrollBar = ::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
318 ,WC_SLIDER // Window class
319 ,(PSZ)wxBuffer // Initial Text
320 ,(ULONG)lMsStyle // Style flags
321 ,0L, 0L, 0L, 0L // Origin -- 0 size
322 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
323 ,HWND_BOTTOM // initial z position
324 ,(HMENU)m_windowId // Window identifier
325 ,&vSlData // Slider control data
326 ,NULL // no Presentation parameters
327 );
328 m_nRangeMax = nMaxValue;
329 m_nRangeMin = nMinValue;
330
331 //
332 // Set the size of the ticks ... default to 6 pixels
333 //
334 ::WinSendMsg( hScrollBar
335 ,SLM_SETTICKSIZE
336 ,MPFROM2SHORT(SMA_SETALLTICKS, (USHORT)12)
337 ,NULL
338 );
339 //
340 // Set the position to the initial value
341 //
342 ::WinSendMsg( hScrollBar
343 ,SLM_SETSLIDERINFO
344 ,MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE)
345 ,(MPARAM)nValue
346 );
347
348 m_hWnd = (WXHWND)hScrollBar;
349 SubclassWin(GetHWND());
350 ::WinSetWindowText((HWND)m_hWnd, "");
351
352 SetFont(*wxSMALL_FONT);
353 if (m_windowStyle & wxSL_LABELS)
354 {
355 //
356 // Finally, create max value static item
357 //
358 sprintf(wxBuffer, "%d", nMaxValue);
359 lWstyle = SS_TEXT|DT_LEFT|WS_VISIBLE;
360 if (m_windowStyle & wxCLIP_SIBLINGS)
361 lMsStyle |= WS_CLIPSIBLINGS;
362
363 m_hStaticMax = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
364 ,WC_STATIC // Window class
365 ,(PSZ)wxBuffer // Initial Text
366 ,(ULONG)lWstyle // Style flags
367 ,0L, 0L, 0L, 0L // Origin -- 0 size
368 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
369 ,HWND_TOP // initial z position
370 ,(ULONG)NewControlId() // Window identifier
371 ,NULL // no control data
372 ,NULL // no Presentation parameters
373 );
374 if (GetFont().Ok())
375 {
376 if (GetFont().GetResourceHandle())
377 {
378 if (m_hStaticMin)
379 wxOS2SetFont( m_hStaticMin
380 ,GetFont()
381 );
382 if (m_hStaticMax)
383 wxOS2SetFont( m_hStaticMax
384 ,GetFont()
385 );
386 if (m_hStaticValue)
387 wxOS2SetFont( m_hStaticValue
388 ,GetFont()
389 );
390 }
391 }
392 }
393
394 SetXComp(0);
395 SetYComp(0);
396 SetSize( nX
397 ,nY
398 ,nWidth
399 ,nHeight
400 );
401 m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd()
402 ,SLM_QUERYSLIDERINFO
403 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
404 ,SMA_RANGEVALUE
405 )
406 ,(MPARAM)0
407 )
408 ) + 4; // for bordersizes
409
410 wxColour vColour;
411
412 vColour.Set(wxString("BLACK"));
413
414 LONG lColor = (LONG)vColour.GetPixel();
415
416 ::WinSetPresParam( m_hStaticMin
417 ,PP_FOREGROUNDCOLOR
418 ,sizeof(LONG)
419 ,(PVOID)&lColor
420 );
421 ::WinSetPresParam( m_hStaticMax
422 ,PP_FOREGROUNDCOLOR
423 ,sizeof(LONG)
424 ,(PVOID)&lColor
425 );
426 ::WinSetPresParam( m_hStaticValue
427 ,PP_FOREGROUNDCOLOR
428 ,sizeof(LONG)
429 ,(PVOID)&lColor
430 );
431 ::WinSetPresParam( m_hWnd
432 ,PP_FOREGROUNDCOLOR
433 ,sizeof(LONG)
434 ,(PVOID)&lColor
435 );
436 lColor = (LONG)m_backgroundColour.GetPixel();
437 ::WinSetPresParam( m_hStaticMin
438 ,PP_BACKGROUNDCOLOR
439 ,sizeof(LONG)
440 ,(PVOID)&lColor
441 );
442 ::WinSetPresParam( m_hStaticMax
443 ,PP_BACKGROUNDCOLOR
444 ,sizeof(LONG)
445 ,(PVOID)&lColor
446 );
447 ::WinSetPresParam( m_hStaticValue
448 ,PP_BACKGROUNDCOLOR
449 ,sizeof(LONG)
450 ,(PVOID)&lColor
451 );
452 ::WinSetPresParam( m_hWnd
453 ,PP_BACKGROUNDCOLOR
454 ,sizeof(LONG)
455 ,(PVOID)&lColor
456 );
457 vColour.Set(wxString("BLUE"));
458 lColor = (LONG)vColour.GetPixel();
459 ::WinSetPresParam( m_hWnd
460 ,PP_HILITEBACKGROUNDCOLOR
461 ,sizeof(LONG)
462 ,(PVOID)&lColor
463 );
464 SetValue(nValue);
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 - (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, zBuf);
651 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont());
652 ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
653 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont());
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 *pnX = vPoint.x;
816 *pnY = vPoint.y;
817 } // end of wxSlider::GetPosition
818
819 int wxSlider::GetSelEnd() const
820 {
821 return 0;
822 } // end of wxSlider::GetSelEnd
823
824 int wxSlider::GetSelStart() const
825 {
826 return 0;
827 } // end of wxSlider::GetSelStart
828
829 void wxSlider::DoGetSize(
830 int* pnWidth
831 , int* pnHeight
832 ) const
833 {
834 GetSize( pnWidth
835 ,pnHeight
836 );
837 } // end of wxSlider::DoGetSize
838
839 void wxSlider::GetSize(
840 int* pnWidth
841 , int* pnHeight
842 ) const
843 {
844 RECTL vRect;
845
846 vRect.xLeft = -1;
847 vRect.xRight = -1;
848 vRect.yTop = -1;
849 vRect.yBottom = -1;
850
851 wxFindMaxSize( GetHWND()
852 ,&vRect
853 );
854
855 if (m_hStaticMin)
856 wxFindMaxSize( m_hStaticMin
857 ,&vRect
858 );
859 if (m_hStaticMax)
860 wxFindMaxSize( m_hStaticMax
861 ,&vRect
862 );
863 if (m_hStaticValue)
864 wxFindMaxSize( m_hStaticValue
865 ,&vRect
866 );
867 if (pnWidth)
868 *pnWidth = vRect.xRight - vRect.xLeft;
869 if (pnHeight)
870 *pnHeight = vRect.yTop - vRect.yBottom;
871 } // end of wxSlider::GetSize
872
873 int wxSlider::GetThumbLength() const
874 {
875 return m_nThumbLength;
876 } // end of wxSlider::GetThumbLength
877
878 int wxSlider::GetValue() const
879 {
880 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
881 ,SLM_QUERYSLIDERINFO
882 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
883 ,SMA_RANGEVALUE
884 )
885 ,(MPARAM)0
886 )
887 );
888 double dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
889 int nNewPos = 0;
890 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
891 ,SLM_QUERYSLIDERINFO
892 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
893 ,SMA_RANGEVALUE
894 )
895 ,(MPARAM)0
896 )
897 );
898 nNewPos = (int)(nPixelPos/dPixelToRange);
899 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
900 nNewPos++;
901 return nNewPos;
902 } // end of wxSlider::GetValue
903
904 WXHBRUSH wxSlider::OnCtlColor(
905 WXHDC hDC
906 , WXHWND hWnd
907 , WXUINT uCtlColor
908 , WXUINT uMessage
909 , WXWPARAM wParam
910 , WXLPARAM lParam
911 )
912 {
913 return (wxControl::OnCtlColor( hDC
914 ,hWnd
915 ,uCtlColor
916 ,uMessage
917 ,wParam
918 ,lParam
919 )
920 );
921 } // end of wxSlider::OnCtlColor
922
923 bool wxSlider::OS2OnScroll(
924 int WXUNUSED(nOrientation)
925 , WXWORD wParam
926 , WXWORD wPos
927 , WXHWND hControl
928 )
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
952 ,SMA_RANGEVALUE
953 )
954 ,(MPARAM)0
955 )
956 );
957 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
958 int nNewPos = 0;
959 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
960 ,SLM_QUERYSLIDERINFO
961 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
962 ,SMA_RANGEVALUE
963 )
964 ,(MPARAM)0
965 )
966 );
967 nNewPos = (int)(nPixelPos/m_dPixelToRange);
968 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
969 nNewPos++;
970 if ((nNewPos < GetMin()) || (nNewPos > GetMax()))
971 {
972 //
973 // Out of range - but we did process it
974 //
975 return true;
976 }
977 SetValue(nNewPos);
978
979 wxScrollEvent vEvent( eScrollEvent
980 ,m_windowId
981 );
982
983 vEvent.SetPosition(nNewPos);
984 vEvent.SetEventObject(this);
985 GetEventHandler()->ProcessEvent(vEvent);
986
987 wxCommandEvent vCevent( wxEVT_COMMAND_SLIDER_UPDATED
988 ,GetId()
989 );
990
991 vCevent.SetInt(nNewPos);
992 vCevent.SetEventObject(this);
993 return (GetEventHandler()->ProcessEvent(vCevent));
994 } // end of wxSlider::OS2OnScroll
995
996 void wxSlider::SetLineSize(
997 int nLineSize
998 )
999 {
1000 m_nLineSize = nLineSize;
1001 } // end of wxSlider::SetLineSize
1002
1003
1004 void wxSlider::SetPageSize(
1005 int nPageSize
1006 )
1007 {
1008 m_nPageSize = nPageSize;
1009 } // end of wxSlider::SetPageSize
1010
1011 void wxSlider::SetRange(
1012 int nMinValue
1013 , int nMaxValue
1014 )
1015 {
1016 wxChar zBuf[10];
1017
1018 m_nRangeMin = nMinValue;
1019 m_nRangeMax = nMaxValue;
1020
1021 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1022 ,SLM_QUERYSLIDERINFO
1023 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1024 ,SMA_RANGEVALUE
1025 )
1026 ,(MPARAM)0
1027 )
1028 );
1029 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1030 if (m_hStaticMin)
1031 {
1032 wxSprintf(zBuf, wxT("%d"), m_nRangeMin);
1033 ::WinSetWindowText((HWND)m_hStaticMin, zBuf);
1034 }
1035
1036 if (m_hStaticMax)
1037 {
1038 wxSprintf(zBuf, wxT("%d"), m_nRangeMax);
1039 ::WinSetWindowText((HWND)m_hStaticMax, zBuf);
1040 }
1041 } // end of wxSlider::SetRange
1042
1043 void wxSlider::SetSelection(
1044 int WXUNUSED(nMinPos)
1045 , int WXUNUSED(nMaxPos)
1046 )
1047 {
1048 } // end of wxSlider::SetSelection
1049
1050 void wxSlider::SetThumbLength(
1051 int nLen
1052 )
1053 {
1054 int nBreadth;
1055
1056 m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1057 ,SLM_QUERYSLIDERINFO
1058 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1059 ,SMA_RANGEVALUE
1060 )
1061 ,(MPARAM)0
1062 )
1063 ) + 4; // for bordersizes
1064 nBreadth = SHORT2FROMMR(::WinSendMsg( GetHwnd()
1065 ,SLM_QUERYSLIDERINFO
1066 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1067 ,SMA_RANGEVALUE
1068 )
1069 ,(MPARAM)0
1070 )
1071 );
1072 ::WinSendMsg( GetHwnd()
1073 ,SLM_SETSLIDERINFO
1074 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1075 ,SMA_RANGEVALUE
1076 )
1077 ,MPFROM2SHORT(nLen, nBreadth)
1078 );
1079 m_nThumbLength = nLen + 4; // Borders
1080 } // end of wxSlider::SetThumbLength
1081
1082 void wxSlider::SetTick(
1083 int nTickPos
1084 )
1085 {
1086 nTickPos = (int)(nTickPos * m_dPixelToRange);
1087 ::WinSendMsg( GetHwnd()
1088 ,SLM_ADDDETENT
1089 ,MPFROMSHORT(nTickPos)
1090 ,NULL
1091 );
1092 } // end of wxSlider::SetTick
1093
1094 // For trackbars only
1095 void wxSlider::SetTickFreq(
1096 int n
1097 , int nPos
1098 )
1099 {
1100 SLDCDATA vSlData;
1101 WNDPARAMS vWndParams;
1102 int nPixelPos;
1103 int i;
1104
1105 vSlData.cbSize = sizeof(SLDCDATA);
1106 if (m_windowStyle & wxSL_AUTOTICKS)
1107 {
1108 vSlData.usScale1Spacing = 0;
1109 vSlData.usScale2Spacing = 0;
1110 }
1111 vSlData.usScale1Increments = (m_nRangeMax - m_nRangeMin)/n;
1112 vSlData.usScale2Increments = (m_nRangeMax - m_nRangeMin)/n;
1113
1114 vWndParams.fsStatus = WPM_CTLDATA;
1115 vWndParams.cchText = 0L;
1116 vWndParams.pszText = NULL;
1117 vWndParams.cbPresParams = 0L;
1118 vWndParams.pPresParams = NULL;
1119 vWndParams.cbCtlData = vSlData.cbSize;
1120 vWndParams.pCtlData = (PVOID)&vSlData;
1121 ::WinSendMsg(GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vWndParams, (MPARAM)0);
1122 for (i = 1; i < (m_nRangeMax - m_nRangeMin)/n; i++)
1123 {
1124 nPixelPos = (int)(i * n * m_dPixelToRange);
1125 ::WinSendMsg( GetHwnd()
1126 ,SLM_ADDDETENT
1127 ,MPFROMSHORT(nPixelPos)
1128 ,NULL
1129 );
1130 }
1131 } // end of wxSlider::SetTickFreq
1132
1133 void wxSlider::SetValue(
1134 int nValue
1135 )
1136 {
1137 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1138 ,SLM_QUERYSLIDERINFO
1139 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1140 ,SMA_RANGEVALUE
1141 )
1142 ,(MPARAM)0
1143 )
1144 );
1145 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1146 int nNewPos = (int)(nValue * m_dPixelToRange);
1147
1148 ::WinSendMsg( GetHwnd()
1149 ,SLM_SETSLIDERINFO
1150 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
1151 ,SMA_RANGEVALUE
1152 )
1153 ,(MPARAM)nNewPos
1154 );
1155 if (m_hStaticValue)
1156 {
1157 wxSprintf(wxBuffer, wxT("%d"), nValue);
1158 ::WinSetWindowText((HWND)m_hStaticValue, wxBuffer);
1159 }
1160 } // end of wxSlider::SetValue
1161
1162 bool wxSlider::Show(
1163 bool bShow
1164 )
1165 {
1166 wxWindowOS2::Show(bShow);
1167 if(m_hStaticValue)
1168 ::WinShowWindow((HWND)m_hStaticValue, bShow);
1169 if(m_hStaticMin)
1170 ::WinShowWindow((HWND)m_hStaticMin, bShow);
1171 if(m_hStaticMax)
1172 ::WinShowWindow((HWND)m_hStaticMax, bShow);
1173 return true;
1174 } // end of wxSlider::Show
1175
1176 #endif // wxUSE_SLIDER