]>
Commit | Line | Data |
---|---|---|
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 | 8 | // Copyright: (c) David Webster |
65571936 | 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 | ||
312ebad4 WS |
26 | #if wxUSE_SLIDER |
27 | ||
0e320a79 | 28 | #include "wx/slider.h" |
409c9842 | 29 | #include "wx/os2/private.h" |
0e320a79 | 30 | |
0e320a79 DW |
31 | IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) |
32 | ||
0e320a79 DW |
33 | wxSlider::wxSlider() |
34 | { | |
3c299c3a DW |
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 | |
409c9842 | 44 | |
0e320a79 DW |
45 | wxSlider::~wxSlider() |
46 | { | |
3c299c3a DW |
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 | |
0e320a79 | 54 | |
d8a3f66c DW |
55 | void wxSlider::AdjustSubControls( |
56 | int nX | |
57 | , int nY | |
58 | , int nWidth | |
59 | , int nHeight | |
60 | , int nSizeFlags | |
61 | ) | |
62 | { | |
d8a3f66c DW |
63 | int nXOffset = nX; |
64 | int nYOffset = nY; | |
65 | int nCx; // slider,min,max sizes | |
66 | int nCy; | |
67 | int nCyf; | |
0fba44b4 | 68 | wxChar zBuf[300]; |
7804d121 | 69 | wxFont vFont = this->GetFont(); |
d8a3f66c DW |
70 | |
71 | wxGetCharSize( GetHWND() | |
72 | ,&nCx | |
73 | ,&nCy | |
7804d121 | 74 | ,&vFont |
d8a3f66c DW |
75 | ); |
76 | ||
77 | if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL) | |
78 | { | |
79 | if (m_windowStyle & wxSL_LABELS ) | |
80 | { | |
81 | int nMinLen = 0; | |
82 | int nMaxLen = 0; | |
83 | ||
0fba44b4 | 84 | ::WinQueryWindowText((HWND)m_hStaticMin, 300, (PSZ)zBuf); |
7804d121 | 85 | GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &vFont); |
d8a3f66c | 86 | |
0fba44b4 | 87 | ::WinQueryWindowText((HWND)m_hStaticMax, 300, (PSZ)zBuf); |
7804d121 | 88 | GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &vFont); |
d8a3f66c DW |
89 | |
90 | if (m_hStaticValue) | |
91 | { | |
92 | int nNewWidth = wxMax(nMinLen, nMaxLen); | |
93 | int nValueHeight = nCyf; | |
94 | ||
95 | ::WinSetWindowPos( (HWND)m_hStaticValue | |
96 | ,HWND_TOP | |
97 | ,(LONG)nXOffset - (nNewWidth + nCx + nMinLen + nCx) | |
98 | ,(LONG)nYOffset | |
99 | ,(LONG)nNewWidth | |
100 | ,(LONG)nValueHeight | |
b3260bce | 101 | ,SWP_SIZE | SWP_MOVE |
d8a3f66c DW |
102 | ); |
103 | } | |
104 | ::WinSetWindowPos( (HWND)m_hStaticMin | |
105 | ,HWND_TOP | |
106 | ,(LONG)nXOffset - (nMinLen + nCx) | |
107 | ,(LONG)nYOffset | |
108 | ,(LONG)nMinLen | |
31833fd7 | 109 | ,(LONG)nCyf |
b3260bce | 110 | ,SWP_SIZE | SWP_MOVE |
d8a3f66c DW |
111 | ); |
112 | nXOffset += nWidth + nCx; | |
113 | ||
114 | ::WinSetWindowPos( (HWND)m_hStaticMax | |
115 | ,HWND_TOP | |
116 | ,(LONG)nXOffset | |
117 | ,(LONG)nYOffset | |
118 | ,(LONG)nMaxLen | |
31833fd7 | 119 | ,(LONG)nCyf |
70a2c656 DW |
120 | ,SWP_ZORDER | SWP_SHOW |
121 | ); | |
122 | } | |
123 | } | |
124 | else | |
125 | { | |
126 | // | |
127 | // Now deal with a vertical slider | |
128 | // | |
129 | ||
31833fd7 | 130 | if (m_windowStyle & wxSL_LABELS ) |
70a2c656 DW |
131 | { |
132 | int nMinLen = 0; | |
133 | int nMaxLen = 0; | |
134 | ||
0fba44b4 | 135 | ::WinQueryWindowText((HWND)m_hStaticMin, 300, (PSZ)zBuf); |
7804d121 | 136 | GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &vFont); |
70a2c656 | 137 | |
0fba44b4 | 138 | ::WinQueryWindowText((HWND)m_hStaticMax, 300, (PSZ)zBuf); |
7804d121 | 139 | GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &vFont); |
70a2c656 DW |
140 | |
141 | if (m_hStaticValue) | |
142 | { | |
31833fd7 | 143 | int nNewWidth = (wxMax(nMinLen, nMaxLen)); |
70a2c656 DW |
144 | |
145 | ::WinSetWindowPos( (HWND)m_hStaticValue | |
146 | ,HWND_TOP | |
147 | ,(LONG)nXOffset | |
148 | ,(LONG)nYOffset + nHeight + nCyf | |
149 | ,(LONG)nNewWidth | |
150 | ,(LONG)nCyf | |
151 | ,SWP_SIZE | SWP_MOVE | |
152 | ); | |
153 | } | |
154 | ::WinSetWindowPos( (HWND)m_hStaticMax | |
155 | ,HWND_TOP | |
156 | ,(LONG)nXOffset | |
157 | ,(LONG)nYOffset + nHeight | |
158 | ,(LONG)nMaxLen | |
159 | ,(LONG)nCyf | |
160 | ,SWP_SIZE | SWP_MOVE | |
161 | ); | |
162 | ::WinSetWindowPos( (HWND)m_hStaticMin | |
163 | ,HWND_TOP | |
164 | ,(LONG)nXOffset | |
165 | ,(LONG)nYOffset - nCyf | |
166 | ,(LONG)nMinLen | |
167 | ,(LONG)nCyf | |
168 | ,SWP_SIZE | SWP_MOVE | |
d8a3f66c DW |
169 | ); |
170 | } | |
171 | } | |
d8a3f66c DW |
172 | } // end of wxSlider::AdjustSubControls |
173 | ||
3c299c3a | 174 | void wxSlider::ClearSel() |
0e320a79 | 175 | { |
3c299c3a | 176 | } // end of wxSlider::ClearSel |
0e320a79 | 177 | |
3c299c3a | 178 | void wxSlider::ClearTicks() |
0e320a79 | 179 | { |
3c299c3a | 180 | } // end of wxSlider::ClearTicks |
0e320a79 | 181 | |
3c299c3a DW |
182 | void wxSlider::Command ( |
183 | wxCommandEvent& rEvent | |
184 | ) | |
0e320a79 | 185 | { |
3c299c3a DW |
186 | SetValue(rEvent.GetInt()); |
187 | ProcessCommand(rEvent); | |
188 | } // end of wxSlider::Command | |
0e320a79 | 189 | |
3c299c3a DW |
190 | bool wxSlider::ContainsHWND( |
191 | WXHWND hWnd | |
192 | ) const | |
0e320a79 | 193 | { |
3c299c3a DW |
194 | return ( hWnd == GetStaticMin() || |
195 | hWnd == GetStaticMax() || | |
196 | hWnd == GetEditValue() | |
197 | ); | |
198 | } // end of wxSlider::ContainsHWND | |
199 | ||
200 | bool wxSlider::Create( | |
201 | wxWindow* pParent | |
202 | , wxWindowID vId | |
203 | , int nValue | |
204 | , int nMinValue | |
205 | , int nMaxValue | |
206 | , const wxPoint& rPos | |
207 | , const wxSize& rSize | |
208 | , long lStyle | |
3c299c3a | 209 | , const wxValidator& rValidator |
3c299c3a DW |
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 | // | |
0fba44b4 | 264 | wxSprintf(wxBuffer, wxT("%d"), nMinValue); |
3c299c3a DW |
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 |
9e25f509 | 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 | |
757cc9de | 324 | ,HWND_BOTTOM // initial z position |
3c299c3a DW |
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 | // | |
0fba44b4 | 359 | wxSprintf(wxBuffer, wxT("%d"), nMaxValue); |
3c299c3a DW |
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 | ||
0fba44b4 | 413 | vColour.Set(wxString(wxT("BLACK"))); |
3c299c3a DW |
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 | ); | |
0fba44b4 | 458 | vColour.Set(wxString(wxT("BLUE"))); |
70a2c656 DW |
459 | lColor = (LONG)vColour.GetPixel(); |
460 | ::WinSetPresParam( m_hWnd | |
461 | ,PP_HILITEBACKGROUNDCOLOR | |
462 | ,sizeof(LONG) | |
463 | ,(PVOID)&lColor | |
464 | ); | |
3c299c3a | 465 | SetValue(nValue); |
312ebad4 | 466 | return true; |
3c299c3a DW |
467 | } // end of wxSlider::Create |
468 | ||
469 | void 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; | |
0fba44b4 | 488 | wxChar zBuf[300]; |
7804d121 | 489 | wxFont vFont = this->GetFont(); |
3c299c3a DW |
490 | |
491 | // | |
492 | // Adjust for OS/2's reverse coordinate system | |
493 | // | |
494 | wxWindowOS2* pParent = (wxWindowOS2*)GetParent(); | |
495 | int nUsedHeight = 0; | |
496 | int nOS2Height = nHeight; | |
497 | ||
498 | if (nOS2Height < 0) | |
499 | nOS2Height = 20; | |
500 | ||
501 | if (pParent) | |
409c9842 | 502 | { |
d8a3f66c DW |
503 | int nOS2ParentHeight = GetOS2ParentHeight(pParent); |
504 | ||
505 | nYOffset = nOS2ParentHeight - (nYOffset + nOS2Height); | |
506 | if (nY != -1) | |
507 | nY1 = nOS2ParentHeight - (nY1 + nOS2Height); | |
409c9842 | 508 | } |
3c299c3a | 509 | else |
409c9842 | 510 | { |
3c299c3a | 511 | RECTL vRect; |
409c9842 | 512 | |
3c299c3a DW |
513 | ::WinQueryWindowRect(HWND_DESKTOP, &vRect); |
514 | nYOffset = vRect.yTop - (nYOffset + nOS2Height); | |
515 | if (nY != -1) | |
516 | nY1 = vRect.yTop - (nY1 + nOS2Height); | |
517 | } | |
d8a3f66c | 518 | m_nSizeFlags = nSizeFlags; |
409c9842 | 519 | |
3c299c3a DW |
520 | GetPosition( &nCurrentX |
521 | ,&nCurrentY | |
522 | ); | |
523 | if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
524 | nX1 = nCurrentX; | |
525 | if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
526 | nY1 = nCurrentY; | |
527 | ||
528 | AdjustForParentClientOrigin( nX1 | |
529 | ,nY1 | |
530 | ,nSizeFlags | |
531 | ); | |
532 | wxGetCharSize( GetHWND() | |
533 | ,&nCx | |
534 | ,&nCy | |
7804d121 | 535 | ,&vFont |
3c299c3a DW |
536 | ); |
537 | ||
538 | if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL) | |
409c9842 | 539 | { |
3c299c3a DW |
540 | if (m_windowStyle & wxSL_LABELS ) |
541 | { | |
542 | int nMinLen = 0; | |
543 | int nMaxLen = 0; | |
544 | ||
0fba44b4 | 545 | ::WinQueryWindowText((HWND)m_hStaticMin, 300, (PSZ)zBuf); |
7804d121 | 546 | GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &vFont); |
0fba44b4 | 547 | ::WinQueryWindowText((HWND)m_hStaticMax, 300, (PSZ)zBuf); |
7804d121 | 548 | GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &vFont); |
3c299c3a DW |
549 | |
550 | if (m_hStaticValue) | |
551 | { | |
552 | int nNewWidth = (wxMax(nMinLen, nMaxLen)); | |
553 | int nValueHeight = nCyf; | |
554 | ||
555 | ::WinSetWindowPos( (HWND)m_hStaticValue | |
556 | ,HWND_TOP | |
557 | ,(LONG)nXOffset | |
9923c37d | 558 | ,(LONG)nYOffset - (LONG)(nCyf * 1.2) |
3c299c3a DW |
559 | ,(LONG)nNewWidth |
560 | ,(LONG)nValueHeight | |
561 | ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW | |
562 | ); | |
563 | nXOffset += nNewWidth + nCx; | |
564 | } | |
565 | ::WinSetWindowPos( (HWND)m_hStaticMin | |
566 | ,HWND_TOP | |
567 | ,(LONG)nXOffset | |
9923c37d | 568 | ,(LONG)nYOffset - (LONG)(nCyf * 1.2) |
3c299c3a DW |
569 | ,(LONG)nMinLen |
570 | ,(LONG)nCy | |
571 | ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW | |
572 | ); | |
573 | nXOffset += nMinLen + nCx; | |
574 | ||
575 | int nSliderLength = nWidth1 - nXOffset - nMaxLen - nCx; | |
576 | int nSliderHeight = nHeight1; | |
577 | ||
578 | if (nSliderHeight < 0) | |
579 | nSliderHeight = 20; | |
580 | ||
581 | // | |
582 | // Slider must have a minimum/default length/height | |
583 | // | |
584 | if (nSliderLength < 100) | |
585 | nSliderLength = 100; | |
586 | ||
587 | ::WinSetWindowPos( GetHwnd() | |
588 | ,HWND_TOP | |
589 | ,(LONG)nXOffset | |
590 | ,(LONG)nYOffset | |
591 | ,(LONG)nSliderLength | |
592 | ,(LONG)nSliderHeight | |
593 | ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW | |
594 | ); | |
31833fd7 DW |
595 | ::WinQueryWindowPos(GetHwnd(), GetSwp()); |
596 | ::WinSendMsg( GetHwnd() | |
597 | ,SLM_SETSLIDERINFO | |
598 | ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS | |
599 | ,0 | |
600 | ) | |
601 | ,MPFROMLONG((ULONG)(nSliderHeight/2)) | |
602 | ); | |
3c299c3a DW |
603 | nXOffset += nSliderLength + nCx; |
604 | ||
605 | ::WinSetWindowPos( (HWND)m_hStaticMax | |
606 | ,HWND_TOP | |
607 | ,(LONG)nXOffset | |
9923c37d | 608 | ,(LONG)nYOffset - (LONG)(nCyf * 1.2) |
3c299c3a DW |
609 | ,(LONG)nMaxLen |
610 | ,(LONG)nCy | |
611 | ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW | |
612 | ); | |
613 | } | |
614 | else | |
615 | { | |
616 | // | |
617 | // No labels | |
618 | // If we're prepared to use the existing size, then... | |
619 | // | |
620 | if (nWidth == -1 && nHeight == -1 && | |
621 | ((nSizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) | |
622 | { | |
623 | GetSize( &nWidth1 | |
624 | ,&nHeight1 | |
625 | ); | |
626 | } | |
627 | if (nWidth1 < 0) | |
628 | nWidth1 = 200; | |
629 | if (nHeight1 < 0) | |
630 | nHeight1 = 20; | |
631 | ::WinSetWindowPos( GetHwnd() | |
632 | ,HWND_TOP | |
633 | ,(LONG)nX1 | |
634 | ,(LONG)nY1 | |
635 | ,(LONG)nWidth1 | |
636 | ,(LONG)nHeight1 | |
637 | ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW | |
638 | ); | |
639 | } | |
409c9842 DW |
640 | } |
641 | ||
3c299c3a DW |
642 | // |
643 | // Now deal with a vertical slider | |
644 | // | |
409c9842 DW |
645 | else |
646 | { | |
3c299c3a | 647 | if (m_windowStyle & wxSL_LABELS ) |
409c9842 | 648 | { |
3c299c3a DW |
649 | int nMinLen; |
650 | int nMaxLen; | |
651 | ||
0fba44b4 | 652 | ::WinQueryWindowText((HWND)m_hStaticMin, 300, (PSZ)zBuf); |
7804d121 | 653 | GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &vFont); |
0fba44b4 | 654 | ::WinQueryWindowText((HWND)m_hStaticMax, 300, (PSZ)zBuf); |
7804d121 | 655 | GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &vFont); |
3c299c3a DW |
656 | if (m_hStaticValue) |
657 | { | |
658 | int nNewWidth = wxMax(nMinLen, nMaxLen); | |
659 | int nValueHeight = nCyf; | |
660 | ||
3c299c3a DW |
661 | ::WinSetWindowPos( (HWND)m_hStaticValue |
662 | ,HWND_TOP | |
663 | ,(LONG)nXOffset | |
31833fd7 | 664 | ,(LONG)nYOffset + nHeight |
3c299c3a DW |
665 | ,(LONG)nNewWidth |
666 | ,(LONG)nValueHeight | |
667 | ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW | |
668 | ); | |
31833fd7 | 669 | nUsedHeight += nCyf; |
3c299c3a DW |
670 | } |
671 | ::WinSetWindowPos( (HWND)m_hStaticMin | |
672 | ,HWND_TOP | |
673 | ,(LONG)nXOffset | |
31833fd7 | 674 | ,(LONG)nYOffset + nHeight - nCyf |
3c299c3a DW |
675 | ,(LONG)nMinLen |
676 | ,(LONG)nCy | |
677 | ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW | |
678 | ); | |
3c299c3a DW |
679 | nUsedHeight += nCy; |
680 | ||
681 | int nSliderLength = nHeight1 - (nUsedHeight + (2 * nCy)); | |
682 | int nSliderWidth = nWidth1; | |
683 | ||
684 | if (nSliderWidth < 0) | |
685 | nSliderWidth = 20; | |
686 | ||
687 | // | |
688 | // Slider must have a minimum/default length | |
689 | // | |
690 | if (nSliderLength < 100) | |
691 | nSliderLength = 100; | |
692 | ||
70a2c656 | 693 | ::WinSetWindowPos( GetHwnd() |
3c299c3a DW |
694 | ,HWND_TOP |
695 | ,(LONG)nXOffset | |
31833fd7 | 696 | ,(LONG)nYOffset + nCyf |
3c299c3a DW |
697 | ,(LONG)nSliderWidth |
698 | ,(LONG)nSliderLength | |
699 | ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW | |
700 | ); | |
31833fd7 DW |
701 | ::WinQueryWindowPos(GetHwnd(), GetSwp()); |
702 | ::WinSendMsg( GetHwnd() | |
703 | ,SLM_SETSLIDERINFO | |
704 | ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS | |
705 | ,0 | |
706 | ) | |
707 | ,MPFROMLONG((ULONG)(nSliderWidth/2)) | |
708 | ); | |
3c299c3a DW |
709 | nUsedHeight += nSliderLength; |
710 | ::WinSetWindowPos( (HWND)m_hStaticMax | |
711 | ,HWND_TOP | |
712 | ,(LONG)nXOffset | |
31833fd7 | 713 | ,(LONG)nYOffset - nCyf |
3c299c3a DW |
714 | ,(LONG)nMaxLen |
715 | ,(LONG)nCy | |
716 | ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW | |
717 | ); | |
718 | } | |
719 | else | |
720 | { | |
721 | // | |
722 | // No labels | |
723 | // If we're prepared to use the existing size, then... | |
724 | // | |
725 | if (nWidth == -1 && nHeight == -1 && | |
726 | ((nSizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) | |
727 | { | |
728 | GetSize( &nWidth1 | |
729 | ,&nHeight1 | |
730 | ); | |
731 | } | |
732 | if (nWidth1 < 0) | |
733 | nWidth1 = 20; | |
734 | if (nHeight1 < 0) | |
735 | nHeight1 = 200; | |
736 | ::WinSetWindowPos( GetHwnd() | |
737 | ,HWND_TOP | |
738 | ,(LONG)nX1 | |
739 | ,(LONG)nY1 | |
740 | ,(LONG)nWidth1 | |
741 | ,(LONG)nHeight1 | |
742 | ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW | |
743 | ); | |
409c9842 | 744 | } |
409c9842 | 745 | } |
3c299c3a | 746 | } // end of void wxSlider::DoSetSize |
0e320a79 | 747 | |
3c299c3a | 748 | int wxSlider::GetLineSize() const |
0e320a79 | 749 | { |
3c299c3a DW |
750 | return 1; |
751 | } // end of wxSlider::GetLineSize | |
0e320a79 | 752 | |
3c299c3a DW |
753 | int wxSlider::GetPageSize() const |
754 | { | |
755 | return m_nPageSize; | |
756 | } // end of wxSlider::GetPageSize | |
0e320a79 | 757 | |
3c299c3a DW |
758 | void wxSlider::GetPosition( |
759 | int* pnX | |
760 | , int* pnY | |
761 | ) const | |
409c9842 | 762 | { |
3c299c3a DW |
763 | wxWindowOS2* pParent = GetParent(); |
764 | RECTL vRect; | |
765 | ||
766 | vRect.xLeft = -1; | |
767 | vRect.xRight = -1; | |
768 | vRect.yTop = -1; | |
769 | vRect.yBottom = -1; | |
770 | wxFindMaxSize( GetHWND() | |
771 | ,&vRect | |
772 | ); | |
773 | ||
774 | if (m_hStaticMin) | |
775 | wxFindMaxSize( m_hStaticMin | |
776 | ,&vRect | |
777 | ); | |
778 | if (m_hStaticMax) | |
779 | wxFindMaxSize( m_hStaticMax | |
780 | ,&vRect | |
781 | ); | |
782 | if (m_hStaticValue) | |
783 | wxFindMaxSize( m_hStaticValue | |
784 | ,&vRect | |
785 | ); | |
786 | ||
787 | // | |
788 | // Since we now have the absolute screen coords, | |
789 | // if there's a parent we must subtract its top left corner | |
790 | // | |
791 | POINTL vPoint; | |
792 | ||
793 | vPoint.x = vRect.xLeft; | |
794 | vPoint.y = vRect.yTop; | |
795 | ||
796 | if (pParent) | |
797 | { | |
798 | SWP vSwp; | |
409c9842 | 799 | |
3c299c3a DW |
800 | ::WinQueryWindowPos((HWND)pParent->GetHWND(), &vSwp); |
801 | vPoint.x = vSwp.x; | |
802 | vPoint.y = vSwp.y; | |
803 | } | |
409c9842 | 804 | |
3c299c3a DW |
805 | // |
806 | // We may be faking the client origin. | |
807 | // So a window that's really at (0, 30) may appear | |
808 | // (to wxWin apps) to be at (0, 0). | |
809 | // | |
810 | if (GetParent()) | |
811 | { | |
812 | wxPoint vPt(GetParent()->GetClientAreaOrigin()); | |
409c9842 | 813 | |
3c299c3a DW |
814 | vPoint.x -= vPt.x; |
815 | vPoint.y -= vPt.y; | |
816 | } | |
817 | *pnX = vPoint.x; | |
818 | *pnY = vPoint.y; | |
819 | } // end of wxSlider::GetPosition | |
409c9842 | 820 | |
3c299c3a | 821 | int wxSlider::GetSelEnd() const |
0e320a79 | 822 | { |
3c299c3a DW |
823 | return 0; |
824 | } // end of wxSlider::GetSelEnd | |
0e320a79 | 825 | |
3c299c3a | 826 | int wxSlider::GetSelStart() const |
0e320a79 | 827 | { |
3c299c3a DW |
828 | return 0; |
829 | } // end of wxSlider::GetSelStart | |
0e320a79 | 830 | |
1cee3f60 DW |
831 | void wxSlider::DoGetSize( |
832 | int* pnWidth | |
833 | , int* pnHeight | |
834 | ) const | |
835 | { | |
836 | GetSize( pnWidth | |
837 | ,pnHeight | |
838 | ); | |
839 | } // end of wxSlider::DoGetSize | |
840 | ||
3c299c3a DW |
841 | void wxSlider::GetSize( |
842 | int* pnWidth | |
843 | , int* pnHeight | |
844 | ) const | |
0e320a79 | 845 | { |
3c299c3a DW |
846 | RECTL vRect; |
847 | ||
848 | vRect.xLeft = -1; | |
849 | vRect.xRight = -1; | |
850 | vRect.yTop = -1; | |
851 | vRect.yBottom = -1; | |
852 | ||
853 | wxFindMaxSize( GetHWND() | |
854 | ,&vRect | |
855 | ); | |
856 | ||
857 | if (m_hStaticMin) | |
858 | wxFindMaxSize( m_hStaticMin | |
859 | ,&vRect | |
860 | ); | |
861 | if (m_hStaticMax) | |
862 | wxFindMaxSize( m_hStaticMax | |
863 | ,&vRect | |
864 | ); | |
865 | if (m_hStaticValue) | |
866 | wxFindMaxSize( m_hStaticValue | |
867 | ,&vRect | |
868 | ); | |
2da36bfe SN |
869 | if (pnWidth) |
870 | *pnWidth = vRect.xRight - vRect.xLeft; | |
871 | if (pnHeight) | |
872 | *pnHeight = vRect.yTop - vRect.yBottom; | |
3c299c3a | 873 | } // end of wxSlider::GetSize |
0e320a79 | 874 | |
3c299c3a | 875 | int wxSlider::GetThumbLength() const |
0e320a79 | 876 | { |
3c299c3a DW |
877 | return m_nThumbLength; |
878 | } // end of wxSlider::GetThumbLength | |
0e320a79 | 879 | |
3c299c3a | 880 | int wxSlider::GetValue() const |
0e320a79 | 881 | { |
3c299c3a DW |
882 | int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd() |
883 | ,SLM_QUERYSLIDERINFO | |
884 | ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS | |
885 | ,SMA_RANGEVALUE | |
886 | ) | |
887 | ,(MPARAM)0 | |
888 | ) | |
889 | ); | |
890 | double dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin); | |
891 | int nNewPos = 0; | |
892 | int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd() | |
893 | ,SLM_QUERYSLIDERINFO | |
894 | ,MPFROM2SHORT( SMA_SLIDERARMPOSITION | |
895 | ,SMA_RANGEVALUE | |
896 | ) | |
897 | ,(MPARAM)0 | |
898 | ) | |
899 | ); | |
900 | nNewPos = (int)(nPixelPos/dPixelToRange); | |
901 | if (nNewPos > (m_nRangeMax - m_nRangeMin)/2) | |
902 | nNewPos++; | |
903 | return nNewPos; | |
904 | } // end of wxSlider::GetValue | |
905 | ||
906 | WXHBRUSH wxSlider::OnCtlColor( | |
907 | WXHDC hDC | |
908 | , WXHWND hWnd | |
909 | , WXUINT uCtlColor | |
910 | , WXUINT uMessage | |
911 | , WXWPARAM wParam | |
912 | , WXLPARAM lParam | |
913 | ) | |
0e320a79 | 914 | { |
3c299c3a DW |
915 | return (wxControl::OnCtlColor( hDC |
916 | ,hWnd | |
917 | ,uCtlColor | |
918 | ,uMessage | |
919 | ,wParam | |
920 | ,lParam | |
921 | ) | |
922 | ); | |
923 | } // end of wxSlider::OnCtlColor | |
924 | ||
925 | bool wxSlider::OS2OnScroll( | |
926 | int WXUNUSED(nOrientation) | |
927 | , WXWORD wParam | |
928 | , WXWORD wPos | |
929 | , WXHWND hControl | |
930 | ) | |
0e320a79 | 931 | { |
3c299c3a | 932 | wxEventType eScrollEvent = wxEVT_NULL; |
0e320a79 | 933 | |
3c299c3a DW |
934 | switch (wParam) |
935 | { | |
936 | case SLN_CHANGE: | |
937 | if (m_windowStyle & wxSL_TOP) | |
938 | eScrollEvent = wxEVT_SCROLL_TOP; | |
939 | else if (m_windowStyle & wxSL_BOTTOM) | |
940 | eScrollEvent = wxEVT_SCROLL_BOTTOM; | |
941 | break; | |
0e320a79 | 942 | |
3c299c3a DW |
943 | case SLN_SLIDERTRACK: |
944 | eScrollEvent = wxEVT_SCROLL_THUMBTRACK; | |
945 | break; | |
946 | ||
947 | default: | |
312ebad4 | 948 | return false; |
3c299c3a DW |
949 | } |
950 | ||
951 | int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd() | |
952 | ,SLM_QUERYSLIDERINFO | |
953 | ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS | |
954 | ,SMA_RANGEVALUE | |
955 | ) | |
956 | ,(MPARAM)0 | |
957 | ) | |
958 | ); | |
959 | m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin); | |
960 | int nNewPos = 0; | |
961 | int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd() | |
962 | ,SLM_QUERYSLIDERINFO | |
963 | ,MPFROM2SHORT( SMA_SLIDERARMPOSITION | |
964 | ,SMA_RANGEVALUE | |
965 | ) | |
966 | ,(MPARAM)0 | |
967 | ) | |
968 | ); | |
9923c37d | 969 | nNewPos = (int)(nPixelPos/m_dPixelToRange); |
3c299c3a DW |
970 | if (nNewPos > (m_nRangeMax - m_nRangeMin)/2) |
971 | nNewPos++; | |
972 | if ((nNewPos < GetMin()) || (nNewPos > GetMax())) | |
973 | { | |
974 | // | |
975 | // Out of range - but we did process it | |
976 | // | |
312ebad4 | 977 | return true; |
3c299c3a DW |
978 | } |
979 | SetValue(nNewPos); | |
980 | ||
981 | wxScrollEvent vEvent( eScrollEvent | |
982 | ,m_windowId | |
983 | ); | |
984 | ||
985 | vEvent.SetPosition(nNewPos); | |
986 | vEvent.SetEventObject(this); | |
987 | GetEventHandler()->ProcessEvent(vEvent); | |
988 | ||
989 | wxCommandEvent vCevent( wxEVT_COMMAND_SLIDER_UPDATED | |
990 | ,GetId() | |
991 | ); | |
992 | ||
993 | vCevent.SetInt(nNewPos); | |
994 | vCevent.SetEventObject(this); | |
995 | return (GetEventHandler()->ProcessEvent(vCevent)); | |
996 | } // end of wxSlider::OS2OnScroll | |
997 | ||
998 | void wxSlider::SetLineSize( | |
999 | int nLineSize | |
1000 | ) | |
0e320a79 | 1001 | { |
3c299c3a DW |
1002 | m_nLineSize = nLineSize; |
1003 | } // end of wxSlider::SetLineSize | |
1004 | ||
0e320a79 | 1005 | |
3c299c3a DW |
1006 | void wxSlider::SetPageSize( |
1007 | int nPageSize | |
1008 | ) | |
0e320a79 | 1009 | { |
3c299c3a DW |
1010 | m_nPageSize = nPageSize; |
1011 | } // end of wxSlider::SetPageSize | |
0e320a79 | 1012 | |
3c299c3a DW |
1013 | void wxSlider::SetRange( |
1014 | int nMinValue | |
1015 | , int nMaxValue | |
1016 | ) | |
0e320a79 | 1017 | { |
3c299c3a DW |
1018 | wxChar zBuf[10]; |
1019 | ||
1020 | m_nRangeMin = nMinValue; | |
1021 | m_nRangeMax = nMaxValue; | |
1022 | ||
1023 | int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd() | |
1024 | ,SLM_QUERYSLIDERINFO | |
1025 | ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS | |
1026 | ,SMA_RANGEVALUE | |
1027 | ) | |
1028 | ,(MPARAM)0 | |
1029 | ) | |
1030 | ); | |
1031 | m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin); | |
1032 | if (m_hStaticMin) | |
1033 | { | |
1034 | wxSprintf(zBuf, wxT("%d"), m_nRangeMin); | |
0fba44b4 | 1035 | ::WinSetWindowText((HWND)m_hStaticMin, (PSZ)zBuf); |
3c299c3a | 1036 | } |
0e320a79 | 1037 | |
3c299c3a DW |
1038 | if (m_hStaticMax) |
1039 | { | |
1040 | wxSprintf(zBuf, wxT("%d"), m_nRangeMax); | |
0fba44b4 | 1041 | ::WinSetWindowText((HWND)m_hStaticMax, (PSZ)zBuf); |
3c299c3a DW |
1042 | } |
1043 | } // end of wxSlider::SetRange | |
1044 | ||
1045 | void wxSlider::SetSelection( | |
1046 | int WXUNUSED(nMinPos) | |
1047 | , int WXUNUSED(nMaxPos) | |
1048 | ) | |
0e320a79 | 1049 | { |
3c299c3a | 1050 | } // end of wxSlider::SetSelection |
0e320a79 | 1051 | |
3c299c3a DW |
1052 | void wxSlider::SetThumbLength( |
1053 | int nLen | |
1054 | ) | |
0e320a79 | 1055 | { |
3c299c3a DW |
1056 | int nBreadth; |
1057 | ||
1058 | m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd() | |
1059 | ,SLM_QUERYSLIDERINFO | |
1060 | ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS | |
1061 | ,SMA_RANGEVALUE | |
1062 | ) | |
1063 | ,(MPARAM)0 | |
1064 | ) | |
1065 | ) + 4; // for bordersizes | |
1066 | nBreadth = SHORT2FROMMR(::WinSendMsg( GetHwnd() | |
1067 | ,SLM_QUERYSLIDERINFO | |
1068 | ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS | |
1069 | ,SMA_RANGEVALUE | |
1070 | ) | |
1071 | ,(MPARAM)0 | |
1072 | ) | |
1073 | ); | |
1074 | ::WinSendMsg( GetHwnd() | |
1075 | ,SLM_SETSLIDERINFO | |
1076 | ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS | |
1077 | ,SMA_RANGEVALUE | |
1078 | ) | |
1079 | ,MPFROM2SHORT(nLen, nBreadth) | |
1080 | ); | |
1081 | m_nThumbLength = nLen + 4; // Borders | |
1082 | } // end of wxSlider::SetThumbLength | |
1083 | ||
1084 | void wxSlider::SetTick( | |
1085 | int nTickPos | |
1086 | ) | |
1087 | { | |
9923c37d | 1088 | nTickPos = (int)(nTickPos * m_dPixelToRange); |
3c299c3a DW |
1089 | ::WinSendMsg( GetHwnd() |
1090 | ,SLM_ADDDETENT | |
1091 | ,MPFROMSHORT(nTickPos) | |
1092 | ,NULL | |
1093 | ); | |
1094 | } // end of wxSlider::SetTick | |
0e320a79 | 1095 | |
3c299c3a DW |
1096 | // For trackbars only |
1097 | void wxSlider::SetTickFreq( | |
1098 | int n | |
1099 | , int nPos | |
1100 | ) | |
409c9842 | 1101 | { |
3c299c3a DW |
1102 | SLDCDATA vSlData; |
1103 | WNDPARAMS vWndParams; | |
1104 | int nPixelPos; | |
1105 | int i; | |
409c9842 | 1106 | |
3c299c3a DW |
1107 | vSlData.cbSize = sizeof(SLDCDATA); |
1108 | if (m_windowStyle & wxSL_AUTOTICKS) | |
1109 | { | |
1110 | vSlData.usScale1Spacing = 0; | |
1111 | vSlData.usScale2Spacing = 0; | |
1112 | } | |
1113 | vSlData.usScale1Increments = (m_nRangeMax - m_nRangeMin)/n; | |
1114 | vSlData.usScale2Increments = (m_nRangeMax - m_nRangeMin)/n; | |
1115 | ||
1116 | vWndParams.fsStatus = WPM_CTLDATA; | |
1117 | vWndParams.cchText = 0L; | |
1118 | vWndParams.pszText = NULL; | |
1119 | vWndParams.cbPresParams = 0L; | |
1120 | vWndParams.pPresParams = NULL; | |
1121 | vWndParams.cbCtlData = vSlData.cbSize; | |
1122 | vWndParams.pCtlData = (PVOID)&vSlData; | |
1123 | ::WinSendMsg(GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vWndParams, (MPARAM)0); | |
1124 | for (i = 1; i < (m_nRangeMax - m_nRangeMin)/n; i++) | |
1125 | { | |
9923c37d | 1126 | nPixelPos = (int)(i * n * m_dPixelToRange); |
3c299c3a DW |
1127 | ::WinSendMsg( GetHwnd() |
1128 | ,SLM_ADDDETENT | |
1129 | ,MPFROMSHORT(nPixelPos) | |
1130 | ,NULL | |
1131 | ); | |
1132 | } | |
1133 | } // end of wxSlider::SetTickFreq | |
1134 | ||
1135 | void wxSlider::SetValue( | |
1136 | int nValue | |
1137 | ) | |
0e320a79 | 1138 | { |
3c299c3a DW |
1139 | int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd() |
1140 | ,SLM_QUERYSLIDERINFO | |
1141 | ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS | |
1142 | ,SMA_RANGEVALUE | |
1143 | ) | |
1144 | ,(MPARAM)0 | |
1145 | ) | |
1146 | ); | |
1147 | m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin); | |
1148 | int nNewPos = (int)(nValue * m_dPixelToRange); | |
1149 | ||
1150 | ::WinSendMsg( GetHwnd() | |
1151 | ,SLM_SETSLIDERINFO | |
1152 | ,MPFROM2SHORT( SMA_SLIDERARMPOSITION | |
1153 | ,SMA_RANGEVALUE | |
1154 | ) | |
1155 | ,(MPARAM)nNewPos | |
1156 | ); | |
1157 | if (m_hStaticValue) | |
1158 | { | |
1159 | wxSprintf(wxBuffer, wxT("%d"), nValue); | |
0fba44b4 | 1160 | ::WinSetWindowText((HWND)m_hStaticValue, (PSZ)wxBuffer); |
3c299c3a DW |
1161 | } |
1162 | } // end of wxSlider::SetValue | |
0e320a79 | 1163 | |
3c299c3a DW |
1164 | bool wxSlider::Show( |
1165 | bool bShow | |
1166 | ) | |
0e320a79 | 1167 | { |
3c299c3a DW |
1168 | wxWindowOS2::Show(bShow); |
1169 | if(m_hStaticValue) | |
1170 | ::WinShowWindow((HWND)m_hStaticValue, bShow); | |
1171 | if(m_hStaticMin) | |
1172 | ::WinShowWindow((HWND)m_hStaticMin, bShow); | |
1173 | if(m_hStaticMax) | |
1174 | ::WinShowWindow((HWND)m_hStaticMax, bShow); | |
312ebad4 | 1175 | return true; |
3c299c3a | 1176 | } // end of wxSlider::Show |
0e320a79 | 1177 | |
312ebad4 | 1178 | #endif // wxUSE_SLIDER |