]> git.saurik.com Git - wxWidgets.git/blame - src/os2/slider.cpp
The world should not end if a server has no peer. Let's return FALSE instead.
[wxWidgets.git] / src / os2 / slider.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: slider.cpp
3// Purpose: wxSlider
409c9842 4// Author: David Webster
0e320a79 5// Modified by:
409c9842 6// Created: 10/15/99
0e320a79 7// RCS-ID: $Id$
409c9842
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
409c9842
DW
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>
a4a16252 23#include <wx/scrolwin.h>
0e320a79
DW
24#endif
25
26#include "wx/slider.h"
409c9842 27#include "wx/os2/private.h"
0e320a79 28
0e320a79
DW
29IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
30
0e320a79
DW
31wxSlider::wxSlider()
32{
3c299c3a
DW
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
409c9842 42
0e320a79
DW
43wxSlider::~wxSlider()
44{
3c299c3a
DW
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
0e320a79 52
d8a3f66c
DW
53void 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
b3260bce 99 ,SWP_SIZE | SWP_MOVE
d8a3f66c
DW
100 );
101 }
102 ::WinSetWindowPos( (HWND)m_hStaticMin
103 ,HWND_TOP
104 ,(LONG)nXOffset - (nMinLen + nCx)
105 ,(LONG)nYOffset
106 ,(LONG)nMinLen
31833fd7 107 ,(LONG)nCyf
b3260bce 108 ,SWP_SIZE | SWP_MOVE
d8a3f66c
DW
109 );
110 nXOffset += nWidth + nCx;
111
112 ::WinSetWindowPos( (HWND)m_hStaticMax
113 ,HWND_TOP
114 ,(LONG)nXOffset
115 ,(LONG)nYOffset
116 ,(LONG)nMaxLen
31833fd7 117 ,(LONG)nCyf
70a2c656
DW
118 ,SWP_ZORDER | SWP_SHOW
119 );
120 }
121 }
122 else
123 {
124 //
125 // Now deal with a vertical slider
126 //
127
31833fd7 128 if (m_windowStyle & wxSL_LABELS )
70a2c656
DW
129 {
130 int nMinLen = 0;
131 int nMaxLen = 0;
132
133 ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf);
31833fd7 134 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont());
70a2c656
DW
135
136 ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
31833fd7 137 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont());
70a2c656
DW
138
139 if (m_hStaticValue)
140 {
31833fd7 141 int nNewWidth = (wxMax(nMinLen, nMaxLen));
70a2c656
DW
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
d8a3f66c
DW
167 );
168 }
169 }
d8a3f66c
DW
170} // end of wxSlider::AdjustSubControls
171
3c299c3a 172void wxSlider::ClearSel()
0e320a79 173{
3c299c3a 174} // end of wxSlider::ClearSel
0e320a79 175
3c299c3a 176void wxSlider::ClearTicks()
0e320a79 177{
3c299c3a 178} // end of wxSlider::ClearTicks
0e320a79 179
3c299c3a
DW
180void wxSlider::Command (
181 wxCommandEvent& rEvent
182)
0e320a79 183{
3c299c3a
DW
184 SetValue(rEvent.GetInt());
185 ProcessCommand(rEvent);
186} // end of wxSlider::Command
0e320a79 187
3c299c3a
DW
188bool wxSlider::ContainsHWND(
189 WXHWND hWnd
190) const
0e320a79 191{
3c299c3a
DW
192 return ( hWnd == GetStaticMin() ||
193 hWnd == GetStaticMax() ||
194 hWnd == GetEditValue()
195 );
196} // end of wxSlider::ContainsHWND
197
198bool 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)
0e320a79 212{
3c299c3a
DW
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;
409c9842 241
3c299c3a
DW
242 if (m_windowStyle & wxCLIP_SIBLINGS )
243 lMsStyle |= WS_CLIPSIBLINGS;
409c9842 244
3c299c3a
DW
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;
5d44b24e 268
3c299c3a
DW
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;
409c9842 282
3c299c3a 283 SLDCDATA vSlData;
409c9842 284
3c299c3a
DW
285 vSlData.cbSize = sizeof(SLDCDATA);
286 if (m_windowStyle & wxSL_VERTICAL)
70a2c656 287 lMsStyle = SLS_VERTICAL | SLS_HOMEBOTTOM | WS_VISIBLE | WS_TABSTOP;
3c299c3a 288 else
70a2c656 289 lMsStyle = SLS_HORIZONTAL | SLS_HOMELEFT| WS_VISIBLE | WS_TABSTOP;
409c9842 290
3c299c3a
DW
291 if (m_windowStyle & wxCLIP_SIBLINGS)
292 lMsStyle |= WS_CLIPSIBLINGS;
409c9842 293
3c299c3a 294 if (m_windowStyle & wxSL_AUTOTICKS)
409c9842 295 {
3c299c3a
DW
296 vSlData.usScale1Spacing = 0;
297 vSlData.usScale2Spacing = 0;
298 }
409c9842 299
3c299c3a
DW
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;
70a2c656 312 lMsStyle |= SLS_RIBBONSTRIP;
3c299c3a
DW
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
70a2c656 337 ,MPFROM2SHORT(SMA_SETALLTICKS, (USHORT)12)
3c299c3a
DW
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, "");
b3260bce 352
70a2c656 353 SetFont(*wxSMALL_FONT);
3c299c3a 354 if (m_windowStyle & wxSL_LABELS)
409c9842 355 {
3c299c3a
DW
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;
5d44b24e 363
3c299c3a
DW
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 }
409c9842
DW
393 }
394
31833fd7
DW
395 SetXComp(0);
396 SetYComp(0);
3c299c3a
DW
397 SetSize( nX
398 ,nY
399 ,nWidth
400 ,nHeight
401 );
402 m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd()
403 ,SLM_QUERYSLIDERINFO
404 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
405 ,SMA_RANGEVALUE
406 )
407 ,(MPARAM)0
408 )
409 ) + 4; // for bordersizes
410
411 wxColour vColour;
412
413 vColour.Set(wxString("BLACK"));
414
415 LONG lColor = (LONG)vColour.GetPixel();
416
417 ::WinSetPresParam( m_hStaticMin
418 ,PP_FOREGROUNDCOLOR
419 ,sizeof(LONG)
420 ,(PVOID)&lColor
421 );
422 ::WinSetPresParam( m_hStaticMax
423 ,PP_FOREGROUNDCOLOR
424 ,sizeof(LONG)
425 ,(PVOID)&lColor
426 );
427 ::WinSetPresParam( m_hStaticValue
428 ,PP_FOREGROUNDCOLOR
429 ,sizeof(LONG)
430 ,(PVOID)&lColor
431 );
432 ::WinSetPresParam( m_hWnd
433 ,PP_FOREGROUNDCOLOR
434 ,sizeof(LONG)
435 ,(PVOID)&lColor
436 );
7993e67c
DW
437 lColor = (LONG)m_backgroundColour.GetPixel();
438 ::WinSetPresParam( m_hStaticMin
439 ,PP_BACKGROUNDCOLOR
440 ,sizeof(LONG)
441 ,(PVOID)&lColor
442 );
443 ::WinSetPresParam( m_hStaticMax
444 ,PP_BACKGROUNDCOLOR
445 ,sizeof(LONG)
446 ,(PVOID)&lColor
447 );
448 ::WinSetPresParam( m_hStaticValue
449 ,PP_BACKGROUNDCOLOR
450 ,sizeof(LONG)
451 ,(PVOID)&lColor
452 );
453 ::WinSetPresParam( m_hWnd
454 ,PP_BACKGROUNDCOLOR
455 ,sizeof(LONG)
456 ,(PVOID)&lColor
457 );
70a2c656
DW
458 vColour.Set(wxString("BLUE"));
459 lColor = (LONG)vColour.GetPixel();
460 ::WinSetPresParam( m_hWnd
461 ,PP_HILITEBACKGROUNDCOLOR
462 ,sizeof(LONG)
463 ,(PVOID)&lColor
464 );
3c299c3a
DW
465 SetValue(nValue);
466 return TRUE;
467} // end of wxSlider::Create
468
469void wxSlider::DoSetSize(
470 int nX
471, int nY
472, int nWidth
473, int nHeight
474, int nSizeFlags
475)
476{
477 int nX1 = nX;
478 int nY1 = nY;
479 int nWidth1 = nWidth;
480 int nHeight1 = nHeight;
481 int nXOffset = nX;
482 int nYOffset = nY;
483 int nCx; // slider,min,max sizes
484 int nCy;
485 int nCyf;
486 int nCurrentX;
487 int nCurrentY;
488 char zBuf[300];
489
490 //
491 // Adjust for OS/2's reverse coordinate system
492 //
493 wxWindowOS2* pParent = (wxWindowOS2*)GetParent();
494 int nUsedHeight = 0;
495 int nOS2Height = nHeight;
496
497 if (nOS2Height < 0)
498 nOS2Height = 20;
499
500 if (pParent)
409c9842 501 {
d8a3f66c
DW
502 int nOS2ParentHeight = GetOS2ParentHeight(pParent);
503
504 nYOffset = nOS2ParentHeight - (nYOffset + nOS2Height);
505 if (nY != -1)
506 nY1 = nOS2ParentHeight - (nY1 + nOS2Height);
409c9842 507 }
3c299c3a 508 else
409c9842 509 {
3c299c3a 510 RECTL vRect;
409c9842 511
3c299c3a
DW
512 ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
513 nYOffset = vRect.yTop - (nYOffset + nOS2Height);
514 if (nY != -1)
515 nY1 = vRect.yTop - (nY1 + nOS2Height);
516 }
d8a3f66c 517 m_nSizeFlags = nSizeFlags;
409c9842 518
3c299c3a
DW
519 GetPosition( &nCurrentX
520 ,&nCurrentY
521 );
522 if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
523 nX1 = nCurrentX;
524 if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
525 nY1 = nCurrentY;
526
527 AdjustForParentClientOrigin( nX1
528 ,nY1
529 ,nSizeFlags
530 );
531 wxGetCharSize( GetHWND()
532 ,&nCx
533 ,&nCy
534 ,&this->GetFont()
535 );
536
537 if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL)
409c9842 538 {
3c299c3a
DW
539 if (m_windowStyle & wxSL_LABELS )
540 {
541 int nMinLen = 0;
542 int nMaxLen = 0;
543
544 ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf);
545 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont());
546 ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
547 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont());
548
549 if (m_hStaticValue)
550 {
551 int nNewWidth = (wxMax(nMinLen, nMaxLen));
552 int nValueHeight = nCyf;
553
554 ::WinSetWindowPos( (HWND)m_hStaticValue
555 ,HWND_TOP
556 ,(LONG)nXOffset
557 ,(LONG)nYOffset - (nCyf * 1.2)
558 ,(LONG)nNewWidth
559 ,(LONG)nValueHeight
560 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
561 );
562 nXOffset += nNewWidth + nCx;
563 }
564 ::WinSetWindowPos( (HWND)m_hStaticMin
565 ,HWND_TOP
566 ,(LONG)nXOffset
70a2c656 567 ,(LONG)nYOffset - (nCyf * 1.2)
3c299c3a
DW
568 ,(LONG)nMinLen
569 ,(LONG)nCy
570 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
571 );
572 nXOffset += nMinLen + nCx;
573
574 int nSliderLength = nWidth1 - nXOffset - nMaxLen - nCx;
575 int nSliderHeight = nHeight1;
576
577 if (nSliderHeight < 0)
578 nSliderHeight = 20;
579
580 //
581 // Slider must have a minimum/default length/height
582 //
583 if (nSliderLength < 100)
584 nSliderLength = 100;
585
586 ::WinSetWindowPos( GetHwnd()
587 ,HWND_TOP
588 ,(LONG)nXOffset
589 ,(LONG)nYOffset
590 ,(LONG)nSliderLength
591 ,(LONG)nSliderHeight
592 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
593 );
31833fd7
DW
594 ::WinQueryWindowPos(GetHwnd(), GetSwp());
595 ::WinSendMsg( GetHwnd()
596 ,SLM_SETSLIDERINFO
597 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
598 ,0
599 )
600 ,MPFROMLONG((ULONG)(nSliderHeight/2))
601 );
3c299c3a
DW
602 nXOffset += nSliderLength + nCx;
603
604 ::WinSetWindowPos( (HWND)m_hStaticMax
605 ,HWND_TOP
606 ,(LONG)nXOffset
70a2c656 607 ,(LONG)nYOffset - (nCyf * 1.2)
3c299c3a
DW
608 ,(LONG)nMaxLen
609 ,(LONG)nCy
610 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
611 );
612 }
613 else
614 {
615 //
616 // No labels
617 // If we're prepared to use the existing size, then...
618 //
619 if (nWidth == -1 && nHeight == -1 &&
620 ((nSizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
621 {
622 GetSize( &nWidth1
623 ,&nHeight1
624 );
625 }
626 if (nWidth1 < 0)
627 nWidth1 = 200;
628 if (nHeight1 < 0)
629 nHeight1 = 20;
630 ::WinSetWindowPos( GetHwnd()
631 ,HWND_TOP
632 ,(LONG)nX1
633 ,(LONG)nY1
634 ,(LONG)nWidth1
635 ,(LONG)nHeight1
636 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
637 );
638 }
409c9842
DW
639 }
640
3c299c3a
DW
641 //
642 // Now deal with a vertical slider
643 //
409c9842
DW
644 else
645 {
3c299c3a 646 if (m_windowStyle & wxSL_LABELS )
409c9842 647 {
3c299c3a
DW
648 int nMinLen;
649 int nMaxLen;
650
651 ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf);
652 GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont());
653 ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
654 GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont());
655 if (m_hStaticValue)
656 {
657 int nNewWidth = wxMax(nMinLen, nMaxLen);
658 int nValueHeight = nCyf;
659
3c299c3a
DW
660 //
661 // The height needs to be a bit bigger under Win95 if using native
662 // 3D effects.
663 //
3c299c3a
DW
664 ::WinSetWindowPos( (HWND)m_hStaticValue
665 ,HWND_TOP
666 ,(LONG)nXOffset
31833fd7 667 ,(LONG)nYOffset + nHeight
3c299c3a
DW
668 ,(LONG)nNewWidth
669 ,(LONG)nValueHeight
670 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
671 );
31833fd7 672 nUsedHeight += nCyf;
3c299c3a
DW
673 }
674 ::WinSetWindowPos( (HWND)m_hStaticMin
675 ,HWND_TOP
676 ,(LONG)nXOffset
31833fd7 677 ,(LONG)nYOffset + nHeight - nCyf
3c299c3a
DW
678 ,(LONG)nMinLen
679 ,(LONG)nCy
680 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
681 );
3c299c3a
DW
682 nUsedHeight += nCy;
683
684 int nSliderLength = nHeight1 - (nUsedHeight + (2 * nCy));
685 int nSliderWidth = nWidth1;
686
687 if (nSliderWidth < 0)
688 nSliderWidth = 20;
689
690 //
691 // Slider must have a minimum/default length
692 //
693 if (nSliderLength < 100)
694 nSliderLength = 100;
695
70a2c656 696 ::WinSetWindowPos( GetHwnd()
3c299c3a
DW
697 ,HWND_TOP
698 ,(LONG)nXOffset
31833fd7 699 ,(LONG)nYOffset + nCyf
3c299c3a
DW
700 ,(LONG)nSliderWidth
701 ,(LONG)nSliderLength
702 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
703 );
31833fd7
DW
704 ::WinQueryWindowPos(GetHwnd(), GetSwp());
705 ::WinSendMsg( GetHwnd()
706 ,SLM_SETSLIDERINFO
707 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
708 ,0
709 )
710 ,MPFROMLONG((ULONG)(nSliderWidth/2))
711 );
3c299c3a
DW
712 nUsedHeight += nSliderLength;
713 ::WinSetWindowPos( (HWND)m_hStaticMax
714 ,HWND_TOP
715 ,(LONG)nXOffset
31833fd7 716 ,(LONG)nYOffset - nCyf
3c299c3a
DW
717 ,(LONG)nMaxLen
718 ,(LONG)nCy
719 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
720 );
721 }
722 else
723 {
724 //
725 // No labels
726 // If we're prepared to use the existing size, then...
727 //
728 if (nWidth == -1 && nHeight == -1 &&
729 ((nSizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
730 {
731 GetSize( &nWidth1
732 ,&nHeight1
733 );
734 }
735 if (nWidth1 < 0)
736 nWidth1 = 20;
737 if (nHeight1 < 0)
738 nHeight1 = 200;
739 ::WinSetWindowPos( GetHwnd()
740 ,HWND_TOP
741 ,(LONG)nX1
742 ,(LONG)nY1
743 ,(LONG)nWidth1
744 ,(LONG)nHeight1
745 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
746 );
409c9842 747 }
409c9842 748 }
3c299c3a 749} // end of void wxSlider::DoSetSize
0e320a79 750
3c299c3a 751int wxSlider::GetLineSize() const
0e320a79 752{
3c299c3a
DW
753 return 1;
754} // end of wxSlider::GetLineSize
0e320a79 755
3c299c3a
DW
756int wxSlider::GetPageSize() const
757{
758 return m_nPageSize;
759} // end of wxSlider::GetPageSize
0e320a79 760
3c299c3a
DW
761void wxSlider::GetPosition(
762 int* pnX
763, int* pnY
764) const
409c9842 765{
3c299c3a
DW
766 wxWindowOS2* pParent = GetParent();
767 RECTL vRect;
768
769 vRect.xLeft = -1;
770 vRect.xRight = -1;
771 vRect.yTop = -1;
772 vRect.yBottom = -1;
773 wxFindMaxSize( GetHWND()
774 ,&vRect
775 );
776
777 if (m_hStaticMin)
778 wxFindMaxSize( m_hStaticMin
779 ,&vRect
780 );
781 if (m_hStaticMax)
782 wxFindMaxSize( m_hStaticMax
783 ,&vRect
784 );
785 if (m_hStaticValue)
786 wxFindMaxSize( m_hStaticValue
787 ,&vRect
788 );
789
790 //
791 // Since we now have the absolute screen coords,
792 // if there's a parent we must subtract its top left corner
793 //
794 POINTL vPoint;
795
796 vPoint.x = vRect.xLeft;
797 vPoint.y = vRect.yTop;
798
799 if (pParent)
800 {
801 SWP vSwp;
409c9842 802
3c299c3a
DW
803 ::WinQueryWindowPos((HWND)pParent->GetHWND(), &vSwp);
804 vPoint.x = vSwp.x;
805 vPoint.y = vSwp.y;
806 }
409c9842 807
3c299c3a
DW
808 //
809 // We may be faking the client origin.
810 // So a window that's really at (0, 30) may appear
811 // (to wxWin apps) to be at (0, 0).
812 //
813 if (GetParent())
814 {
815 wxPoint vPt(GetParent()->GetClientAreaOrigin());
409c9842 816
3c299c3a
DW
817 vPoint.x -= vPt.x;
818 vPoint.y -= vPt.y;
819 }
820 *pnX = vPoint.x;
821 *pnY = vPoint.y;
822} // end of wxSlider::GetPosition
409c9842 823
3c299c3a 824int wxSlider::GetSelEnd() const
0e320a79 825{
3c299c3a
DW
826 return 0;
827} // end of wxSlider::GetSelEnd
0e320a79 828
3c299c3a 829int wxSlider::GetSelStart() const
0e320a79 830{
3c299c3a
DW
831 return 0;
832} // end of wxSlider::GetSelStart
0e320a79 833
1cee3f60
DW
834void wxSlider::DoGetSize(
835 int* pnWidth
836, int* pnHeight
837) const
838{
839 GetSize( pnWidth
840 ,pnHeight
841 );
842} // end of wxSlider::DoGetSize
843
3c299c3a
DW
844void wxSlider::GetSize(
845 int* pnWidth
846, int* pnHeight
847) const
0e320a79 848{
3c299c3a
DW
849 RECTL vRect;
850
851 vRect.xLeft = -1;
852 vRect.xRight = -1;
853 vRect.yTop = -1;
854 vRect.yBottom = -1;
855
856 wxFindMaxSize( GetHWND()
857 ,&vRect
858 );
859
860 if (m_hStaticMin)
861 wxFindMaxSize( m_hStaticMin
862 ,&vRect
863 );
864 if (m_hStaticMax)
865 wxFindMaxSize( m_hStaticMax
866 ,&vRect
867 );
868 if (m_hStaticValue)
869 wxFindMaxSize( m_hStaticValue
870 ,&vRect
871 );
872 *pnWidth = vRect.xRight - vRect.xLeft;
873 *pnHeight = vRect.yBottom - vRect.yTop;
874} // end of wxSlider::GetSize
0e320a79 875
3c299c3a 876int wxSlider::GetThumbLength() const
0e320a79 877{
3c299c3a
DW
878 return m_nThumbLength;
879} // end of wxSlider::GetThumbLength
0e320a79 880
3c299c3a 881int wxSlider::GetValue() const
0e320a79 882{
3c299c3a
DW
883 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
884 ,SLM_QUERYSLIDERINFO
885 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
886 ,SMA_RANGEVALUE
887 )
888 ,(MPARAM)0
889 )
890 );
891 double dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
892 int nNewPos = 0;
893 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
894 ,SLM_QUERYSLIDERINFO
895 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
896 ,SMA_RANGEVALUE
897 )
898 ,(MPARAM)0
899 )
900 );
901 nNewPos = (int)(nPixelPos/dPixelToRange);
902 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
903 nNewPos++;
904 return nNewPos;
905} // end of wxSlider::GetValue
906
907WXHBRUSH wxSlider::OnCtlColor(
908 WXHDC hDC
909, WXHWND hWnd
910, WXUINT uCtlColor
911, WXUINT uMessage
912, WXWPARAM wParam
913, WXLPARAM lParam
914)
0e320a79 915{
3c299c3a
DW
916 return (wxControl::OnCtlColor( hDC
917 ,hWnd
918 ,uCtlColor
919 ,uMessage
920 ,wParam
921 ,lParam
922 )
923 );
924} // end of wxSlider::OnCtlColor
925
926bool wxSlider::OS2OnScroll(
927 int WXUNUSED(nOrientation)
928, WXWORD wParam
929, WXWORD wPos
930, WXHWND hControl
931)
0e320a79 932{
3c299c3a 933 wxEventType eScrollEvent = wxEVT_NULL;
0e320a79 934
3c299c3a
DW
935 switch (wParam)
936 {
937 case SLN_CHANGE:
938 if (m_windowStyle & wxSL_TOP)
939 eScrollEvent = wxEVT_SCROLL_TOP;
940 else if (m_windowStyle & wxSL_BOTTOM)
941 eScrollEvent = wxEVT_SCROLL_BOTTOM;
942 break;
0e320a79 943
3c299c3a
DW
944 case SLN_SLIDERTRACK:
945 eScrollEvent = wxEVT_SCROLL_THUMBTRACK;
946 break;
947
948 default:
949 return FALSE;
950 }
951
952 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
953 ,SLM_QUERYSLIDERINFO
954 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
955 ,SMA_RANGEVALUE
956 )
957 ,(MPARAM)0
958 )
959 );
960 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
961 int nNewPos = 0;
962 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
963 ,SLM_QUERYSLIDERINFO
964 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
965 ,SMA_RANGEVALUE
966 )
967 ,(MPARAM)0
968 )
969 );
970 nNewPos = (nPixelPos/m_dPixelToRange);
971 if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
972 nNewPos++;
973 if ((nNewPos < GetMin()) || (nNewPos > GetMax()))
974 {
975 //
976 // Out of range - but we did process it
977 //
978 return TRUE;
979 }
980 SetValue(nNewPos);
981
982 wxScrollEvent vEvent( eScrollEvent
983 ,m_windowId
984 );
985
986 vEvent.SetPosition(nNewPos);
987 vEvent.SetEventObject(this);
988 GetEventHandler()->ProcessEvent(vEvent);
989
990 wxCommandEvent vCevent( wxEVT_COMMAND_SLIDER_UPDATED
991 ,GetId()
992 );
993
994 vCevent.SetInt(nNewPos);
995 vCevent.SetEventObject(this);
996 return (GetEventHandler()->ProcessEvent(vCevent));
997} // end of wxSlider::OS2OnScroll
998
999void wxSlider::SetLineSize(
1000 int nLineSize
1001)
0e320a79 1002{
3c299c3a
DW
1003 m_nLineSize = nLineSize;
1004} // end of wxSlider::SetLineSize
1005
0e320a79 1006
3c299c3a
DW
1007void wxSlider::SetPageSize(
1008 int nPageSize
1009)
0e320a79 1010{
3c299c3a
DW
1011 m_nPageSize = nPageSize;
1012} // end of wxSlider::SetPageSize
0e320a79 1013
3c299c3a
DW
1014void wxSlider::SetRange(
1015 int nMinValue
1016, int nMaxValue
1017)
0e320a79 1018{
3c299c3a
DW
1019 wxChar zBuf[10];
1020
1021 m_nRangeMin = nMinValue;
1022 m_nRangeMax = nMaxValue;
1023
1024 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1025 ,SLM_QUERYSLIDERINFO
1026 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1027 ,SMA_RANGEVALUE
1028 )
1029 ,(MPARAM)0
1030 )
1031 );
1032 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1033 if (m_hStaticMin)
1034 {
1035 wxSprintf(zBuf, wxT("%d"), m_nRangeMin);
1036 ::WinSetWindowText((HWND)m_hStaticMin, zBuf);
1037 }
0e320a79 1038
3c299c3a
DW
1039 if (m_hStaticMax)
1040 {
1041 wxSprintf(zBuf, wxT("%d"), m_nRangeMax);
1042 ::WinSetWindowText((HWND)m_hStaticMax, zBuf);
1043 }
1044} // end of wxSlider::SetRange
1045
1046void wxSlider::SetSelection(
1047 int WXUNUSED(nMinPos)
1048, int WXUNUSED(nMaxPos)
1049)
0e320a79 1050{
3c299c3a 1051} // end of wxSlider::SetSelection
0e320a79 1052
3c299c3a
DW
1053void wxSlider::SetThumbLength(
1054 int nLen
1055)
0e320a79 1056{
3c299c3a
DW
1057 int nBreadth;
1058
1059 m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1060 ,SLM_QUERYSLIDERINFO
1061 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1062 ,SMA_RANGEVALUE
1063 )
1064 ,(MPARAM)0
1065 )
1066 ) + 4; // for bordersizes
1067 nBreadth = SHORT2FROMMR(::WinSendMsg( GetHwnd()
1068 ,SLM_QUERYSLIDERINFO
1069 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1070 ,SMA_RANGEVALUE
1071 )
1072 ,(MPARAM)0
1073 )
1074 );
1075 ::WinSendMsg( GetHwnd()
1076 ,SLM_SETSLIDERINFO
1077 ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS
1078 ,SMA_RANGEVALUE
1079 )
1080 ,MPFROM2SHORT(nLen, nBreadth)
1081 );
1082 m_nThumbLength = nLen + 4; // Borders
1083} // end of wxSlider::SetThumbLength
1084
1085void wxSlider::SetTick(
1086 int nTickPos
1087)
1088{
1089 nTickPos *= m_dPixelToRange;
1090 ::WinSendMsg( GetHwnd()
1091 ,SLM_ADDDETENT
1092 ,MPFROMSHORT(nTickPos)
1093 ,NULL
1094 );
1095} // end of wxSlider::SetTick
0e320a79 1096
3c299c3a
DW
1097// For trackbars only
1098void wxSlider::SetTickFreq(
1099 int n
1100, int nPos
1101)
409c9842 1102{
3c299c3a
DW
1103 SLDCDATA vSlData;
1104 WNDPARAMS vWndParams;
1105 int nPixelPos;
1106 int i;
409c9842 1107
3c299c3a
DW
1108 vSlData.cbSize = sizeof(SLDCDATA);
1109 if (m_windowStyle & wxSL_AUTOTICKS)
1110 {
1111 vSlData.usScale1Spacing = 0;
1112 vSlData.usScale2Spacing = 0;
1113 }
1114 vSlData.usScale1Increments = (m_nRangeMax - m_nRangeMin)/n;
1115 vSlData.usScale2Increments = (m_nRangeMax - m_nRangeMin)/n;
1116
1117 vWndParams.fsStatus = WPM_CTLDATA;
1118 vWndParams.cchText = 0L;
1119 vWndParams.pszText = NULL;
1120 vWndParams.cbPresParams = 0L;
1121 vWndParams.pPresParams = NULL;
1122 vWndParams.cbCtlData = vSlData.cbSize;
1123 vWndParams.pCtlData = (PVOID)&vSlData;
1124 ::WinSendMsg(GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vWndParams, (MPARAM)0);
1125 for (i = 1; i < (m_nRangeMax - m_nRangeMin)/n; i++)
1126 {
1127 nPixelPos = i * n * m_dPixelToRange;
1128 ::WinSendMsg( GetHwnd()
1129 ,SLM_ADDDETENT
1130 ,MPFROMSHORT(nPixelPos)
1131 ,NULL
1132 );
1133 }
1134} // end of wxSlider::SetTickFreq
1135
1136void wxSlider::SetValue(
1137 int nValue
1138)
0e320a79 1139{
3c299c3a
DW
1140 int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1141 ,SLM_QUERYSLIDERINFO
1142 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
1143 ,SMA_RANGEVALUE
1144 )
1145 ,(MPARAM)0
1146 )
1147 );
1148 int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
1149 ,SLM_QUERYSLIDERINFO
1150 ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
1151 ,SMA_RANGEVALUE
1152 )
1153 ,(MPARAM)0
1154 )
1155 );
1156 m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
1157 int nNewPos = (int)(nValue * m_dPixelToRange);
1158
1159 ::WinSendMsg( GetHwnd()
1160 ,SLM_SETSLIDERINFO
1161 ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
1162 ,SMA_RANGEVALUE
1163 )
1164 ,(MPARAM)nNewPos
1165 );
1166 if (m_hStaticValue)
1167 {
1168 wxSprintf(wxBuffer, wxT("%d"), nValue);
1169 ::WinSetWindowText((HWND)m_hStaticValue, wxBuffer);
1170 }
1171} // end of wxSlider::SetValue
0e320a79 1172
3c299c3a
DW
1173bool wxSlider::Show(
1174 bool bShow
1175)
0e320a79 1176{
3c299c3a
DW
1177 wxWindowOS2::Show(bShow);
1178 if(m_hStaticValue)
1179 ::WinShowWindow((HWND)m_hStaticValue, bShow);
1180 if(m_hStaticMin)
1181 ::WinShowWindow((HWND)m_hStaticMin, bShow);
1182 if(m_hStaticMax)
1183 ::WinShowWindow((HWND)m_hStaticMax, bShow);
0e320a79 1184 return TRUE;
3c299c3a 1185} // end of wxSlider::Show
0e320a79 1186