]>
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; | |
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 | |
b3260bce | 100 | ,SWP_SIZE | SWP_MOVE |
d8a3f66c DW |
101 | ); |
102 | } | |
103 | ::WinSetWindowPos( (HWND)m_hStaticMin | |
104 | ,HWND_TOP | |
105 | ,(LONG)nXOffset - (nMinLen + nCx) | |
106 | ,(LONG)nYOffset | |
107 | ,(LONG)nMinLen | |
31833fd7 | 108 | ,(LONG)nCyf |
b3260bce | 109 | ,SWP_SIZE | SWP_MOVE |
d8a3f66c DW |
110 | ); |
111 | nXOffset += nWidth + nCx; | |
112 | ||
113 | ::WinSetWindowPos( (HWND)m_hStaticMax | |
114 | ,HWND_TOP | |
115 | ,(LONG)nXOffset | |
116 | ,(LONG)nYOffset | |
117 | ,(LONG)nMaxLen | |
31833fd7 | 118 | ,(LONG)nCyf |
70a2c656 DW |
119 | ,SWP_ZORDER | SWP_SHOW |
120 | ); | |
121 | } | |
122 | } | |
123 | else | |
124 | { | |
125 | // | |
126 | // Now deal with a vertical slider | |
127 | // | |
128 | ||
31833fd7 | 129 | if (m_windowStyle & wxSL_LABELS ) |
70a2c656 DW |
130 | { |
131 | int nMinLen = 0; | |
132 | int nMaxLen = 0; | |
133 | ||
134 | ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf); | |
31833fd7 | 135 | GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont()); |
70a2c656 DW |
136 | |
137 | ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf); | |
31833fd7 | 138 | GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont()); |
70a2c656 DW |
139 | |
140 | if (m_hStaticValue) | |
141 | { | |
31833fd7 | 142 | int nNewWidth = (wxMax(nMinLen, nMaxLen)); |
70a2c656 DW |
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 | |
d8a3f66c DW |
168 | ); |
169 | } | |
170 | } | |
d8a3f66c DW |
171 | } // end of wxSlider::AdjustSubControls |
172 | ||
3c299c3a | 173 | void wxSlider::ClearSel() |
0e320a79 | 174 | { |
3c299c3a | 175 | } // end of wxSlider::ClearSel |
0e320a79 | 176 | |
3c299c3a | 177 | void wxSlider::ClearTicks() |
0e320a79 | 178 | { |
3c299c3a | 179 | } // end of wxSlider::ClearTicks |
0e320a79 | 180 | |
3c299c3a DW |
181 | void wxSlider::Command ( |
182 | wxCommandEvent& rEvent | |
183 | ) | |
0e320a79 | 184 | { |
3c299c3a DW |
185 | SetValue(rEvent.GetInt()); |
186 | ProcessCommand(rEvent); | |
187 | } // end of wxSlider::Command | |
0e320a79 | 188 | |
3c299c3a DW |
189 | bool wxSlider::ContainsHWND( |
190 | WXHWND hWnd | |
191 | ) const | |
0e320a79 | 192 | { |
3c299c3a DW |
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 | |
3c299c3a | 208 | , const wxValidator& rValidator |
3c299c3a DW |
209 | , const wxString& rsName |
210 | ) | |
0e320a79 | 211 | { |
3c299c3a DW |
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; | |
409c9842 | 240 | |
3c299c3a DW |
241 | if (m_windowStyle & wxCLIP_SIBLINGS ) |
242 | lMsStyle |= WS_CLIPSIBLINGS; | |
409c9842 | 243 | |
3c299c3a DW |
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; | |
5d44b24e | 267 | |
3c299c3a DW |
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; | |
409c9842 | 281 | |
3c299c3a | 282 | SLDCDATA vSlData; |
409c9842 | 283 | |
3c299c3a DW |
284 | vSlData.cbSize = sizeof(SLDCDATA); |
285 | if (m_windowStyle & wxSL_VERTICAL) | |
70a2c656 | 286 | lMsStyle = SLS_VERTICAL | SLS_HOMEBOTTOM | WS_VISIBLE | WS_TABSTOP; |
3c299c3a | 287 | else |
9e25f509 | 288 | lMsStyle = SLS_HORIZONTAL | SLS_HOMELEFT | WS_VISIBLE | WS_TABSTOP; |
409c9842 | 289 | |
3c299c3a DW |
290 | if (m_windowStyle & wxCLIP_SIBLINGS) |
291 | lMsStyle |= WS_CLIPSIBLINGS; | |
409c9842 | 292 | |
3c299c3a | 293 | if (m_windowStyle & wxSL_AUTOTICKS) |
409c9842 | 294 | { |
3c299c3a DW |
295 | vSlData.usScale1Spacing = 0; |
296 | vSlData.usScale2Spacing = 0; | |
297 | } | |
409c9842 | 298 | |
3c299c3a DW |
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; | |
70a2c656 | 311 | lMsStyle |= SLS_RIBBONSTRIP; |
3c299c3a DW |
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 | |
757cc9de | 323 | ,HWND_BOTTOM // initial z position |
3c299c3a DW |
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 | |
70a2c656 | 336 | ,MPFROM2SHORT(SMA_SETALLTICKS, (USHORT)12) |
3c299c3a DW |
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, ""); | |
b3260bce | 351 | |
70a2c656 | 352 | SetFont(*wxSMALL_FONT); |
3c299c3a | 353 | if (m_windowStyle & wxSL_LABELS) |
409c9842 | 354 | { |
3c299c3a DW |
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; | |
5d44b24e | 362 | |
3c299c3a DW |
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 | } | |
409c9842 DW |
392 | } |
393 | ||
31833fd7 DW |
394 | SetXComp(0); |
395 | SetYComp(0); | |
3c299c3a DW |
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 | ); | |
7993e67c DW |
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 | ); | |
70a2c656 DW |
457 | vColour.Set(wxString("BLUE")); |
458 | lColor = (LONG)vColour.GetPixel(); | |
459 | ::WinSetPresParam( m_hWnd | |
460 | ,PP_HILITEBACKGROUNDCOLOR | |
461 | ,sizeof(LONG) | |
462 | ,(PVOID)&lColor | |
463 | ); | |
3c299c3a | 464 | SetValue(nValue); |
312ebad4 | 465 | return true; |
3c299c3a DW |
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) | |
409c9842 | 500 | { |
d8a3f66c DW |
501 | int nOS2ParentHeight = GetOS2ParentHeight(pParent); |
502 | ||
503 | nYOffset = nOS2ParentHeight - (nYOffset + nOS2Height); | |
504 | if (nY != -1) | |
505 | nY1 = nOS2ParentHeight - (nY1 + nOS2Height); | |
409c9842 | 506 | } |
3c299c3a | 507 | else |
409c9842 | 508 | { |
3c299c3a | 509 | RECTL vRect; |
409c9842 | 510 | |
3c299c3a DW |
511 | ::WinQueryWindowRect(HWND_DESKTOP, &vRect); |
512 | nYOffset = vRect.yTop - (nYOffset + nOS2Height); | |
513 | if (nY != -1) | |
514 | nY1 = vRect.yTop - (nY1 + nOS2Height); | |
515 | } | |
d8a3f66c | 516 | m_nSizeFlags = nSizeFlags; |
409c9842 | 517 | |
3c299c3a DW |
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) | |
409c9842 | 537 | { |
3c299c3a DW |
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 | |
9923c37d | 556 | ,(LONG)nYOffset - (LONG)(nCyf * 1.2) |
3c299c3a DW |
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 | |
9923c37d | 566 | ,(LONG)nYOffset - (LONG)(nCyf * 1.2) |
3c299c3a DW |
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 | ); | |
31833fd7 DW |
593 | ::WinQueryWindowPos(GetHwnd(), GetSwp()); |
594 | ::WinSendMsg( GetHwnd() | |
595 | ,SLM_SETSLIDERINFO | |
596 | ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS | |
597 | ,0 | |
598 | ) | |
599 | ,MPFROMLONG((ULONG)(nSliderHeight/2)) | |
600 | ); | |
3c299c3a DW |
601 | nXOffset += nSliderLength + nCx; |
602 | ||
603 | ::WinSetWindowPos( (HWND)m_hStaticMax | |
604 | ,HWND_TOP | |
605 | ,(LONG)nXOffset | |
9923c37d | 606 | ,(LONG)nYOffset - (LONG)(nCyf * 1.2) |
3c299c3a DW |
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 | } | |
409c9842 DW |
638 | } |
639 | ||
3c299c3a DW |
640 | // |
641 | // Now deal with a vertical slider | |
642 | // | |
409c9842 DW |
643 | else |
644 | { | |
3c299c3a | 645 | if (m_windowStyle & wxSL_LABELS ) |
409c9842 | 646 | { |
3c299c3a DW |
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 | ||
3c299c3a DW |
659 | ::WinSetWindowPos( (HWND)m_hStaticValue |
660 | ,HWND_TOP | |
661 | ,(LONG)nXOffset | |
31833fd7 | 662 | ,(LONG)nYOffset + nHeight |
3c299c3a DW |
663 | ,(LONG)nNewWidth |
664 | ,(LONG)nValueHeight | |
665 | ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW | |
666 | ); | |
31833fd7 | 667 | nUsedHeight += nCyf; |
3c299c3a DW |
668 | } |
669 | ::WinSetWindowPos( (HWND)m_hStaticMin | |
670 | ,HWND_TOP | |
671 | ,(LONG)nXOffset | |
31833fd7 | 672 | ,(LONG)nYOffset + nHeight - nCyf |
3c299c3a DW |
673 | ,(LONG)nMinLen |
674 | ,(LONG)nCy | |
675 | ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW | |
676 | ); | |
3c299c3a DW |
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 | ||
70a2c656 | 691 | ::WinSetWindowPos( GetHwnd() |
3c299c3a DW |
692 | ,HWND_TOP |
693 | ,(LONG)nXOffset | |
31833fd7 | 694 | ,(LONG)nYOffset + nCyf |
3c299c3a DW |
695 | ,(LONG)nSliderWidth |
696 | ,(LONG)nSliderLength | |
697 | ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW | |
698 | ); | |
31833fd7 DW |
699 | ::WinQueryWindowPos(GetHwnd(), GetSwp()); |
700 | ::WinSendMsg( GetHwnd() | |
701 | ,SLM_SETSLIDERINFO | |
702 | ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS | |
703 | ,0 | |
704 | ) | |
705 | ,MPFROMLONG((ULONG)(nSliderWidth/2)) | |
706 | ); | |
3c299c3a DW |
707 | nUsedHeight += nSliderLength; |
708 | ::WinSetWindowPos( (HWND)m_hStaticMax | |
709 | ,HWND_TOP | |
710 | ,(LONG)nXOffset | |
31833fd7 | 711 | ,(LONG)nYOffset - nCyf |
3c299c3a DW |
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 | ); | |
409c9842 | 742 | } |
409c9842 | 743 | } |
3c299c3a | 744 | } // end of void wxSlider::DoSetSize |
0e320a79 | 745 | |
3c299c3a | 746 | int wxSlider::GetLineSize() const |
0e320a79 | 747 | { |
3c299c3a DW |
748 | return 1; |
749 | } // end of wxSlider::GetLineSize | |
0e320a79 | 750 | |
3c299c3a DW |
751 | int wxSlider::GetPageSize() const |
752 | { | |
753 | return m_nPageSize; | |
754 | } // end of wxSlider::GetPageSize | |
0e320a79 | 755 | |
3c299c3a DW |
756 | void wxSlider::GetPosition( |
757 | int* pnX | |
758 | , int* pnY | |
759 | ) const | |
409c9842 | 760 | { |
3c299c3a DW |
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; | |
409c9842 | 797 | |
3c299c3a DW |
798 | ::WinQueryWindowPos((HWND)pParent->GetHWND(), &vSwp); |
799 | vPoint.x = vSwp.x; | |
800 | vPoint.y = vSwp.y; | |
801 | } | |
409c9842 | 802 | |
3c299c3a DW |
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()); | |
409c9842 | 811 | |
3c299c3a DW |
812 | vPoint.x -= vPt.x; |
813 | vPoint.y -= vPt.y; | |
814 | } | |
815 | *pnX = vPoint.x; | |
816 | *pnY = vPoint.y; | |
817 | } // end of wxSlider::GetPosition | |
409c9842 | 818 | |
3c299c3a | 819 | int wxSlider::GetSelEnd() const |
0e320a79 | 820 | { |
3c299c3a DW |
821 | return 0; |
822 | } // end of wxSlider::GetSelEnd | |
0e320a79 | 823 | |
3c299c3a | 824 | int wxSlider::GetSelStart() const |
0e320a79 | 825 | { |
3c299c3a DW |
826 | return 0; |
827 | } // end of wxSlider::GetSelStart | |
0e320a79 | 828 | |
1cee3f60 DW |
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 | ||
3c299c3a DW |
839 | void wxSlider::GetSize( |
840 | int* pnWidth | |
841 | , int* pnHeight | |
842 | ) const | |
0e320a79 | 843 | { |
3c299c3a DW |
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 | ); | |
2da36bfe SN |
867 | if (pnWidth) |
868 | *pnWidth = vRect.xRight - vRect.xLeft; | |
869 | if (pnHeight) | |
870 | *pnHeight = vRect.yTop - vRect.yBottom; | |
3c299c3a | 871 | } // end of wxSlider::GetSize |
0e320a79 | 872 | |
3c299c3a | 873 | int wxSlider::GetThumbLength() const |
0e320a79 | 874 | { |
3c299c3a DW |
875 | return m_nThumbLength; |
876 | } // end of wxSlider::GetThumbLength | |
0e320a79 | 877 | |
3c299c3a | 878 | int wxSlider::GetValue() const |
0e320a79 | 879 | { |
3c299c3a DW |
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 | ) | |
0e320a79 | 912 | { |
3c299c3a DW |
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 | ) | |
0e320a79 | 929 | { |
3c299c3a | 930 | wxEventType eScrollEvent = wxEVT_NULL; |
0e320a79 | 931 | |
3c299c3a DW |
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; | |
0e320a79 | 940 | |
3c299c3a DW |
941 | case SLN_SLIDERTRACK: |
942 | eScrollEvent = wxEVT_SCROLL_THUMBTRACK; | |
943 | break; | |
944 | ||
945 | default: | |
312ebad4 | 946 | return false; |
3c299c3a DW |
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 | ); | |
9923c37d | 967 | nNewPos = (int)(nPixelPos/m_dPixelToRange); |
3c299c3a DW |
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 | // | |
312ebad4 | 975 | return true; |
3c299c3a DW |
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 | ) | |
0e320a79 | 999 | { |
3c299c3a DW |
1000 | m_nLineSize = nLineSize; |
1001 | } // end of wxSlider::SetLineSize | |
1002 | ||
0e320a79 | 1003 | |
3c299c3a DW |
1004 | void wxSlider::SetPageSize( |
1005 | int nPageSize | |
1006 | ) | |
0e320a79 | 1007 | { |
3c299c3a DW |
1008 | m_nPageSize = nPageSize; |
1009 | } // end of wxSlider::SetPageSize | |
0e320a79 | 1010 | |
3c299c3a DW |
1011 | void wxSlider::SetRange( |
1012 | int nMinValue | |
1013 | , int nMaxValue | |
1014 | ) | |
0e320a79 | 1015 | { |
3c299c3a DW |
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 | } | |
0e320a79 | 1035 | |
3c299c3a DW |
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 | ) | |
0e320a79 | 1047 | { |
3c299c3a | 1048 | } // end of wxSlider::SetSelection |
0e320a79 | 1049 | |
3c299c3a DW |
1050 | void wxSlider::SetThumbLength( |
1051 | int nLen | |
1052 | ) | |
0e320a79 | 1053 | { |
3c299c3a DW |
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 | { | |
9923c37d | 1086 | nTickPos = (int)(nTickPos * m_dPixelToRange); |
3c299c3a DW |
1087 | ::WinSendMsg( GetHwnd() |
1088 | ,SLM_ADDDETENT | |
1089 | ,MPFROMSHORT(nTickPos) | |
1090 | ,NULL | |
1091 | ); | |
1092 | } // end of wxSlider::SetTick | |
0e320a79 | 1093 | |
3c299c3a DW |
1094 | // For trackbars only |
1095 | void wxSlider::SetTickFreq( | |
1096 | int n | |
1097 | , int nPos | |
1098 | ) | |
409c9842 | 1099 | { |
3c299c3a DW |
1100 | SLDCDATA vSlData; |
1101 | WNDPARAMS vWndParams; | |
1102 | int nPixelPos; | |
1103 | int i; | |
409c9842 | 1104 | |
3c299c3a DW |
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 | { | |
9923c37d | 1124 | nPixelPos = (int)(i * n * m_dPixelToRange); |
3c299c3a DW |
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 | ) | |
0e320a79 | 1136 | { |
3c299c3a DW |
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 | |
0e320a79 | 1161 | |
3c299c3a DW |
1162 | bool wxSlider::Show( |
1163 | bool bShow | |
1164 | ) | |
0e320a79 | 1165 | { |
3c299c3a DW |
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); | |
312ebad4 | 1173 | return true; |
3c299c3a | 1174 | } // end of wxSlider::Show |
0e320a79 | 1175 | |
312ebad4 | 1176 | #endif // wxUSE_SLIDER |