]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
da87a1ca JS |
2 | // Name: slider95.cpp |
3 | // Purpose: wxSlider95, using the Win95 trackbar control | |
2bda0e17 KB |
4 | // Author: Julian Smart |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
c42404a5 | 9 | // Licence: wxWindows license |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
da87a1ca | 13 | #pragma implementation "slider95.h" |
2bda0e17 KB |
14 | #endif |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
1e6feb95 VZ |
23 | #if wxUSE_SLIDER |
24 | ||
2bda0e17 | 25 | #ifndef WX_PRECOMP |
3096bd2f VZ |
26 | #include "wx/utils.h" |
27 | #include "wx/brush.h" | |
2bda0e17 KB |
28 | #endif |
29 | ||
da87a1ca | 30 | #ifdef __WIN95__ |
2bda0e17 | 31 | |
da87a1ca JS |
32 | #include "wx/msw/slider95.h" |
33 | #include "wx/msw/private.h" | |
2bda0e17 | 34 | |
ae090fdb | 35 | #if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__)) |
c42404a5 | 36 | #include <commctrl.h> |
2bda0e17 KB |
37 | #endif |
38 | ||
da87a1ca | 39 | IMPLEMENT_DYNAMIC_CLASS(wxSlider95, wxControl) |
2bda0e17 KB |
40 | |
41 | // Slider | |
bfc6fde4 | 42 | wxSlider95::wxSlider95() |
2bda0e17 KB |
43 | { |
44 | m_staticValue = 0; | |
45 | m_staticMin = 0; | |
46 | m_staticMax = 0; | |
47 | m_pageSize = 1; | |
48 | m_lineSize = 1; | |
49 | m_rangeMax = 0; | |
50 | m_rangeMin = 0; | |
51 | m_tickFreq = 0; | |
52 | } | |
53 | ||
debe6624 JS |
54 | bool wxSlider95::Create(wxWindow *parent, wxWindowID id, |
55 | int value, int minValue, int maxValue, | |
2bda0e17 | 56 | const wxPoint& pos, |
debe6624 | 57 | const wxSize& size, long style, |
2bda0e17 KB |
58 | const wxValidator& validator, |
59 | const wxString& name) | |
60 | { | |
61 | SetName(name); | |
11b6a93b | 62 | #if wxUSE_VALIDATORS |
2bda0e17 | 63 | SetValidator(validator); |
11b6a93b | 64 | #endif // wxUSE_VALIDATORS |
2bda0e17 KB |
65 | |
66 | if (parent) parent->AddChild(this); | |
fd71308f JS |
67 | SetBackgroundColour(parent->GetBackgroundColour()) ; |
68 | SetForegroundColour(parent->GetForegroundColour()) ; | |
2bda0e17 KB |
69 | |
70 | m_staticValue = 0; | |
71 | m_staticMin = 0; | |
72 | m_staticMax = 0; | |
73 | m_pageSize = 1; | |
74 | m_lineSize = 1; | |
75 | m_windowStyle = style; | |
76 | m_tickFreq = 0; | |
77 | ||
78 | if ( id == -1 ) | |
a23fd0e1 | 79 | m_windowId = (int)NewControlId(); |
2bda0e17 | 80 | else |
a23fd0e1 | 81 | m_windowId = id; |
2bda0e17 KB |
82 | |
83 | int x = pos.x; | |
84 | int y = pos.y; | |
85 | int width = size.x; | |
86 | int height = size.y; | |
87 | ||
b0766406 JS |
88 | long msStyle=0 ; |
89 | long wstyle=0 ; | |
90 | ||
91 | if ( m_windowStyle & wxCLIP_SIBLINGS ) | |
92 | msStyle |= WS_CLIPSIBLINGS; | |
2bda0e17 KB |
93 | |
94 | if ( m_windowStyle & wxSL_LABELS ) | |
95 | { | |
b0766406 | 96 | msStyle |= WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTER; |
2bda0e17 KB |
97 | |
98 | bool want3D; | |
99 | WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ; | |
100 | ||
223d09f6 | 101 | m_staticValue = (WXHWND) CreateWindowEx(exStyle, wxT("STATIC"), NULL, |
2bda0e17 KB |
102 | msStyle, |
103 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), | |
104 | wxGetInstance(), NULL); | |
105 | ||
106 | // Now create min static control | |
223d09f6 | 107 | wxSprintf(wxBuffer, wxT("%d"), minValue); |
b0766406 JS |
108 | wstyle = STATIC_FLAGS; |
109 | if ( m_windowStyle & wxCLIP_SIBLINGS ) | |
110 | msStyle |= WS_CLIPSIBLINGS; | |
223d09f6 | 111 | m_staticMin = (WXHWND) CreateWindowEx(0, wxT("STATIC"), wxBuffer, |
b0766406 | 112 | wstyle, |
2bda0e17 KB |
113 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), |
114 | wxGetInstance(), NULL); | |
115 | } | |
116 | ||
117 | msStyle = 0; | |
b0766406 JS |
118 | |
119 | if ( m_windowStyle & wxCLIP_SIBLINGS ) | |
120 | msStyle |= WS_CLIPSIBLINGS; | |
121 | ||
2bda0e17 KB |
122 | if (m_windowStyle & wxSL_VERTICAL) |
123 | msStyle = TBS_VERT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; | |
124 | else | |
125 | msStyle = TBS_HORZ | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; | |
126 | ||
127 | if ( m_windowStyle & wxSL_AUTOTICKS ) | |
a23fd0e1 | 128 | msStyle |= TBS_AUTOTICKS ; |
2bda0e17 KB |
129 | |
130 | if ( m_windowStyle & wxSL_LEFT ) | |
a23fd0e1 | 131 | msStyle |= TBS_LEFT; |
2bda0e17 | 132 | else if ( m_windowStyle & wxSL_RIGHT ) |
a23fd0e1 | 133 | msStyle |= TBS_RIGHT; |
2bda0e17 | 134 | else if ( m_windowStyle & wxSL_TOP ) |
a23fd0e1 | 135 | msStyle |= TBS_TOP; |
2bda0e17 | 136 | else if ( m_windowStyle & wxSL_BOTTOM ) |
a23fd0e1 | 137 | msStyle |= TBS_BOTTOM; |
2bda0e17 | 138 | else if ( m_windowStyle & wxSL_BOTH ) |
a23fd0e1 | 139 | msStyle |= TBS_BOTH; |
2bda0e17 | 140 | else if ( ! (m_windowStyle & wxSL_AUTOTICKS) ) |
a23fd0e1 | 141 | msStyle |= TBS_NOTICKS; |
2bda0e17 KB |
142 | |
143 | if ( m_windowStyle & wxSL_SELRANGE ) | |
a23fd0e1 | 144 | msStyle |= TBS_ENABLESELRANGE ; |
2bda0e17 KB |
145 | |
146 | HWND scroll_bar = CreateWindowEx(MakeExtendedStyle(m_windowStyle), TRACKBAR_CLASS, wxBuffer, | |
147 | msStyle, | |
148 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, | |
149 | wxGetInstance(), NULL); | |
150 | ||
151 | m_rangeMax = maxValue; | |
152 | m_rangeMin = minValue; | |
153 | ||
154 | m_pageSize = (int)((maxValue-minValue)/10); | |
155 | ||
156 | ::SendMessage(scroll_bar, TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue)); | |
157 | ::SendMessage(scroll_bar, TBM_SETPOS, TRUE, (LPARAM)value); | |
158 | ::SendMessage(scroll_bar, TBM_SETPAGESIZE, 0, (LPARAM)m_pageSize); | |
159 | ||
160 | m_hWnd = (WXHWND)scroll_bar; | |
161 | ||
162 | SubclassWin(GetHWND()); | |
163 | ||
223d09f6 | 164 | SetWindowText((HWND) m_hWnd, wxT("")); |
9c331ded | 165 | |
c0ed460c | 166 | SetFont(parent->GetFont()); |
9c331ded | 167 | |
2bda0e17 KB |
168 | if ( m_windowStyle & wxSL_LABELS ) |
169 | { | |
170 | // Finally, create max value static item | |
223d09f6 | 171 | wxSprintf(wxBuffer, wxT("%d"), maxValue); |
b0766406 JS |
172 | wstyle = STATIC_FLAGS; |
173 | if ( m_windowStyle & wxCLIP_SIBLINGS ) | |
174 | msStyle |= WS_CLIPSIBLINGS; | |
223d09f6 | 175 | m_staticMax = (WXHWND) CreateWindowEx(0, wxT("STATIC"), wxBuffer, |
b0766406 | 176 | wstyle, |
2bda0e17 KB |
177 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), |
178 | wxGetInstance(), NULL); | |
179 | ||
da87a1ca | 180 | |
c0ed460c | 181 | if (GetFont().Ok()) |
2bda0e17 | 182 | { |
c0ed460c | 183 | if (GetFont().GetResourceHandle()) |
2bda0e17 | 184 | { |
a23fd0e1 VZ |
185 | if ( m_staticMin ) |
186 | SendMessage((HWND)m_staticMin,WM_SETFONT, | |
187 | (WPARAM)GetFont().GetResourceHandle(),0L); | |
188 | if ( m_staticMax ) | |
189 | SendMessage((HWND)m_staticMax,WM_SETFONT, | |
c0ed460c | 190 | (WPARAM)GetFont().GetResourceHandle(),0L); |
a23fd0e1 VZ |
191 | if (m_staticValue) |
192 | SendMessage((HWND)m_staticValue,WM_SETFONT, | |
c0ed460c | 193 | (WPARAM)GetFont().GetResourceHandle(),0L); |
2bda0e17 KB |
194 | } |
195 | } | |
196 | } | |
2bda0e17 KB |
197 | |
198 | SetSize(x, y, width, height); | |
199 | SetValue(value); | |
200 | ||
201 | return TRUE; | |
202 | } | |
203 | ||
a23fd0e1 VZ |
204 | bool wxSlider95::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam, |
205 | WXWORD pos, WXHWND control) | |
2bda0e17 | 206 | { |
1e6feb95 | 207 | wxEventType scrollEvent; |
2bda0e17 KB |
208 | switch ( wParam ) |
209 | { | |
a23fd0e1 | 210 | case SB_TOP: |
a23fd0e1 VZ |
211 | scrollEvent = wxEVT_SCROLL_TOP; |
212 | break; | |
213 | ||
214 | case SB_BOTTOM: | |
a23fd0e1 VZ |
215 | scrollEvent = wxEVT_SCROLL_BOTTOM; |
216 | break; | |
217 | ||
218 | case SB_LINEUP: | |
a23fd0e1 VZ |
219 | scrollEvent = wxEVT_SCROLL_LINEUP; |
220 | break; | |
221 | ||
222 | case SB_LINEDOWN: | |
a23fd0e1 VZ |
223 | scrollEvent = wxEVT_SCROLL_LINEDOWN; |
224 | break; | |
225 | ||
226 | case SB_PAGEUP: | |
a23fd0e1 VZ |
227 | scrollEvent = wxEVT_SCROLL_PAGEUP; |
228 | break; | |
229 | ||
230 | case SB_PAGEDOWN: | |
a23fd0e1 VZ |
231 | scrollEvent = wxEVT_SCROLL_PAGEDOWN; |
232 | break; | |
233 | ||
234 | case SB_THUMBTRACK: | |
235 | case SB_THUMBPOSITION: | |
a23fd0e1 VZ |
236 | scrollEvent = wxEVT_SCROLL_THUMBTRACK; |
237 | break; | |
238 | ||
239 | default: | |
1e6feb95 VZ |
240 | // unknown scroll event? |
241 | return FALSE; | |
2bda0e17 KB |
242 | } |
243 | ||
a23fd0e1 VZ |
244 | int newPos = (int)::SendMessage((HWND) control, TBM_GETPOS, 0, 0); |
245 | if ( (newPos < GetMin()) || (newPos > GetMax()) ) | |
2bda0e17 | 246 | { |
a23fd0e1 VZ |
247 | // out of range - but we did process it |
248 | return TRUE; | |
249 | } | |
2bda0e17 | 250 | |
a23fd0e1 | 251 | SetValue(newPos); |
2bda0e17 | 252 | |
a23fd0e1 VZ |
253 | wxScrollEvent event(scrollEvent, m_windowId); |
254 | event.SetPosition(newPos); | |
255 | event.SetEventObject( this ); | |
256 | GetEventHandler()->ProcessEvent(event); | |
f3a65071 | 257 | |
a23fd0e1 | 258 | wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() ); |
f6bcfd97 | 259 | cevent.SetInt( newPos ); |
a23fd0e1 | 260 | cevent.SetEventObject( this ); |
f3a65071 | 261 | |
a23fd0e1 | 262 | return GetEventHandler()->ProcessEvent( cevent ); |
2bda0e17 KB |
263 | } |
264 | ||
bfc6fde4 | 265 | wxSlider95::~wxSlider95() |
2bda0e17 KB |
266 | { |
267 | if (m_staticMin) | |
268 | DestroyWindow((HWND) m_staticMin); | |
269 | if (m_staticMax) | |
270 | DestroyWindow((HWND) m_staticMax); | |
271 | if (m_staticValue) | |
272 | DestroyWindow((HWND) m_staticValue); | |
273 | } | |
274 | ||
bfc6fde4 | 275 | int wxSlider95::GetValue() const |
2bda0e17 | 276 | { |
4438caf4 | 277 | return ::SendMessage(GetHwnd(), TBM_GETPOS, 0, 0); |
2bda0e17 KB |
278 | } |
279 | ||
debe6624 | 280 | void wxSlider95::SetValue(int value) |
2bda0e17 | 281 | { |
4438caf4 | 282 | ::SendMessage(GetHwnd(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value); |
2bda0e17 KB |
283 | if (m_staticValue) |
284 | { | |
223d09f6 | 285 | wxSprintf(wxBuffer, wxT("%d"), value); |
2bda0e17 KB |
286 | SetWindowText((HWND) m_staticValue, wxBuffer); |
287 | } | |
288 | } | |
289 | ||
da87a1ca | 290 | void wxSlider95::GetSize(int *width, int *height) const |
2bda0e17 KB |
291 | { |
292 | RECT rect; | |
293 | rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1; | |
294 | ||
295 | wxFindMaxSize(GetHWND(), &rect); | |
296 | ||
297 | if (m_staticMin) | |
298 | wxFindMaxSize(m_staticMin, &rect); | |
299 | if (m_staticMax) | |
300 | wxFindMaxSize(m_staticMax, &rect); | |
301 | if (m_staticValue) | |
302 | wxFindMaxSize(m_staticValue, &rect); | |
303 | ||
304 | *width = rect.right - rect.left; | |
305 | *height = rect.bottom - rect.top; | |
306 | } | |
307 | ||
da87a1ca | 308 | void wxSlider95::GetPosition(int *x, int *y) const |
2bda0e17 KB |
309 | { |
310 | wxWindow *parent = GetParent(); | |
311 | RECT rect; | |
312 | rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1; | |
313 | ||
314 | wxFindMaxSize(GetHWND(), &rect); | |
315 | ||
316 | if (m_staticMin) | |
317 | wxFindMaxSize(m_staticMin, &rect); | |
318 | if (m_staticMax) | |
319 | wxFindMaxSize(m_staticMax, &rect); | |
320 | if (m_staticValue) | |
321 | wxFindMaxSize(m_staticValue, &rect); | |
322 | ||
323 | // Since we now have the absolute screen coords, | |
324 | // if there's a parent we must subtract its top left corner | |
325 | POINT point; | |
326 | point.x = rect.left; | |
327 | point.y = rect.top; | |
328 | if (parent) | |
329 | ::ScreenToClient((HWND) parent->GetHWND(), &point); | |
330 | ||
81d66cf3 JS |
331 | // We may be faking the client origin. |
332 | // So a window that's really at (0, 30) may appear | |
333 | // (to wxWin apps) to be at (0, 0). | |
334 | if (GetParent()) | |
335 | { | |
336 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
337 | point.x -= pt.x; | |
338 | point.y -= pt.y; | |
339 | } | |
2bda0e17 KB |
340 | *x = point.x; |
341 | *y = point.y; | |
342 | } | |
343 | ||
4438caf4 VZ |
344 | // TODO one day, make sense of all this horros and replace it with a readable |
345 | // DoGetBestSize() | |
bfc6fde4 | 346 | void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
2bda0e17 KB |
347 | { |
348 | int x1 = x; | |
349 | int y1 = y; | |
350 | int w1 = width; | |
351 | int h1 = height; | |
352 | ||
353 | int currentX, currentY; | |
354 | GetPosition(¤tX, ¤tY); | |
ce96b7a0 | 355 | if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
2bda0e17 | 356 | x1 = currentX; |
ce96b7a0 | 357 | if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
2bda0e17 KB |
358 | y1 = currentY; |
359 | ||
81d66cf3 JS |
360 | AdjustForParentClientOrigin(x1, y1, sizeFlags); |
361 | ||
837e5743 | 362 | wxChar buf[300]; |
2bda0e17 KB |
363 | |
364 | int x_offset = x; | |
365 | int y_offset = y; | |
366 | ||
367 | int cx; // slider,min,max sizes | |
368 | int cy; | |
debe6624 | 369 | int cyf; |
2bda0e17 | 370 | |
ce3ed50d | 371 | wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont()); |
2bda0e17 KB |
372 | |
373 | if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL) | |
374 | { | |
a23fd0e1 VZ |
375 | if ( m_windowStyle & wxSL_LABELS ) |
376 | { | |
debe6624 | 377 | int min_len = 0; |
2bda0e17 KB |
378 | |
379 | GetWindowText((HWND) m_staticMin, buf, 300); | |
ce3ed50d | 380 | GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont()); |
2bda0e17 | 381 | |
debe6624 | 382 | int max_len = 0; |
2bda0e17 KB |
383 | |
384 | GetWindowText((HWND) m_staticMax, buf, 300); | |
ce3ed50d | 385 | GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont()); |
2bda0e17 KB |
386 | if (m_staticValue) |
387 | { | |
388 | int new_width = (int)(wxMax(min_len, max_len)); | |
a23fd0e1 | 389 | int valueHeight = (int)cyf; |
2bda0e17 KB |
390 | #ifdef __WIN32__ |
391 | // For some reason, under Win95, the text edit control has | |
392 | // a lot of space before the first character | |
393 | new_width += 3*cx; | |
394 | #endif | |
2bda0e17 | 395 | // The height needs to be a bit bigger under Win95 if using native |
a23fd0e1 VZ |
396 | // 3D effects. |
397 | valueHeight = (int) (valueHeight * 1.5) ; | |
2bda0e17 KB |
398 | MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE); |
399 | x_offset += new_width + cx; | |
400 | } | |
401 | ||
402 | MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE); | |
403 | x_offset += (int)(min_len + cx); | |
404 | ||
405 | int slider_length = (int)(w1 - x_offset - max_len - cx); | |
406 | ||
2bda0e17 | 407 | int slider_height = h1; |
a23fd0e1 VZ |
408 | if (slider_height < 0 ) |
409 | slider_height = 20; | |
2bda0e17 KB |
410 | |
411 | // Slider must have a minimum/default length/height | |
412 | if (slider_length < 100) | |
413 | slider_length = 100; | |
414 | ||
4438caf4 | 415 | MoveWindow(GetHwnd(), x_offset, y_offset, slider_length, slider_height, TRUE); |
2bda0e17 KB |
416 | x_offset += slider_length + cx; |
417 | ||
418 | MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); | |
419 | } | |
a23fd0e1 VZ |
420 | else |
421 | { | |
422 | // No labels | |
423 | // If we're prepared to use the existing size, then... | |
424 | if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) | |
425 | { | |
426 | GetSize(&w1, &h1); | |
427 | } | |
428 | if ( w1 < 0 ) | |
429 | w1 = 200; | |
430 | if ( h1 < 0 ) | |
431 | h1 = 20; | |
4438caf4 | 432 | MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE); |
a23fd0e1 | 433 | } |
2bda0e17 KB |
434 | } |
435 | else | |
436 | { | |
a23fd0e1 VZ |
437 | if ( m_windowStyle & wxSL_LABELS ) |
438 | { | |
debe6624 | 439 | int min_len; |
2bda0e17 | 440 | GetWindowText((HWND) m_staticMin, buf, 300); |
ce3ed50d | 441 | GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont()); |
2bda0e17 | 442 | |
debe6624 | 443 | int max_len; |
2bda0e17 | 444 | GetWindowText((HWND) m_staticMax, buf, 300); |
ce3ed50d | 445 | GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont()); |
2bda0e17 KB |
446 | |
447 | if (m_staticValue) | |
448 | { | |
449 | int new_width = (int)(wxMax(min_len, max_len)); | |
a23fd0e1 | 450 | int valueHeight = (int)cyf; |
2bda0e17 KB |
451 | /*** Suggested change by George Tasker - remove this block... |
452 | #ifdef __WIN32__ | |
453 | // For some reason, under Win95, the text edit control has | |
454 | // a lot of space before the first character | |
455 | new_width += 3*cx; | |
456 | #endif | |
457 | ... and replace with following line: */ | |
458 | new_width += cx; | |
459 | ||
2bda0e17 | 460 | // The height needs to be a bit bigger under Win95 if using native |
a23fd0e1 VZ |
461 | // 3D effects. |
462 | valueHeight = (int) (valueHeight * 1.5) ; | |
2bda0e17 KB |
463 | |
464 | MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE); | |
465 | y_offset += valueHeight; | |
466 | } | |
467 | ||
468 | MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE); | |
469 | y_offset += cy; | |
470 | ||
471 | int slider_length = (int)(h1 - y_offset - cy - cy); | |
da87a1ca | 472 | |
2bda0e17 | 473 | int slider_width = w1; |
a23fd0e1 VZ |
474 | if (slider_width < 0 ) |
475 | slider_width = 20; | |
2bda0e17 KB |
476 | |
477 | // Slider must have a minimum/default length | |
478 | if (slider_length < 100) | |
479 | slider_length = 100; | |
480 | ||
4438caf4 | 481 | MoveWindow(GetHwnd(), x_offset, y_offset, slider_width, slider_length, TRUE); |
2bda0e17 KB |
482 | y_offset += slider_length; |
483 | ||
484 | MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); | |
485 | } | |
a23fd0e1 VZ |
486 | else |
487 | { | |
488 | // No labels | |
489 | // If we're prepared to use the existing size, then... | |
490 | if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) | |
491 | { | |
492 | GetSize(&w1, &h1); | |
493 | } | |
494 | if ( w1 < 0 ) | |
495 | w1 = 20; | |
496 | if ( h1 < 0 ) | |
497 | h1 = 200; | |
4438caf4 | 498 | MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE); |
a23fd0e1 | 499 | } |
2bda0e17 | 500 | } |
2bda0e17 KB |
501 | } |
502 | ||
debe6624 | 503 | void wxSlider95::SetRange(int minValue, int maxValue) |
2bda0e17 KB |
504 | { |
505 | m_rangeMin = minValue; | |
506 | m_rangeMax = maxValue; | |
507 | ||
4438caf4 | 508 | ::SendMessage(GetHwnd(), TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue)); |
da87a1ca | 509 | |
837e5743 | 510 | wxChar buf[40]; |
2bda0e17 KB |
511 | if ( m_staticMin ) |
512 | { | |
223d09f6 | 513 | wxSprintf(buf, wxT("%d"), m_rangeMin); |
a23fd0e1 | 514 | SetWindowText((HWND) m_staticMin, buf); |
2bda0e17 KB |
515 | } |
516 | ||
517 | if ( m_staticMax ) | |
518 | { | |
223d09f6 | 519 | wxSprintf(buf, wxT("%d"), m_rangeMax); |
2bda0e17 KB |
520 | SetWindowText((HWND) m_staticMax, buf); |
521 | } | |
522 | } | |
523 | ||
debe6624 | 524 | WXHBRUSH wxSlider95::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, |
a23fd0e1 | 525 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 KB |
526 | { |
527 | if ( nCtlColor == CTLCOLOR_SCROLLBAR ) | |
a23fd0e1 | 528 | return 0; |
2bda0e17 KB |
529 | |
530 | // Otherwise, it's a static | |
f048e32f | 531 | return wxControl::OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam); |
2bda0e17 KB |
532 | } |
533 | ||
534 | // For trackbars only | |
debe6624 | 535 | void wxSlider95::SetTickFreq(int n, int pos) |
2bda0e17 | 536 | { |
2bda0e17 | 537 | m_tickFreq = n; |
4438caf4 | 538 | ::SendMessage( GetHwnd(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos ); |
2bda0e17 KB |
539 | } |
540 | ||
debe6624 | 541 | void wxSlider95::SetPageSize(int pageSize) |
2bda0e17 | 542 | { |
4438caf4 | 543 | ::SendMessage( GetHwnd(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize ); |
2bda0e17 KB |
544 | m_pageSize = pageSize; |
545 | } | |
546 | ||
bfc6fde4 | 547 | int wxSlider95::GetPageSize() const |
2bda0e17 KB |
548 | { |
549 | return m_pageSize; | |
550 | } | |
551 | ||
bfc6fde4 | 552 | void wxSlider95::ClearSel() |
2bda0e17 | 553 | { |
4438caf4 | 554 | ::SendMessage( GetHwnd(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0 ); |
2bda0e17 KB |
555 | } |
556 | ||
bfc6fde4 | 557 | void wxSlider95::ClearTicks() |
2bda0e17 | 558 | { |
4438caf4 | 559 | ::SendMessage( GetHwnd(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0 ); |
2bda0e17 KB |
560 | } |
561 | ||
debe6624 | 562 | void wxSlider95::SetLineSize(int lineSize) |
2bda0e17 KB |
563 | { |
564 | m_lineSize = lineSize; | |
4438caf4 | 565 | ::SendMessage( GetHwnd(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize ); |
2bda0e17 KB |
566 | } |
567 | ||
bfc6fde4 | 568 | int wxSlider95::GetLineSize() const |
2bda0e17 | 569 | { |
4438caf4 | 570 | return (int) ::SendMessage( GetHwnd(), TBM_GETLINESIZE, (WPARAM) 0, (LPARAM) 0 ); |
2bda0e17 KB |
571 | } |
572 | ||
bfc6fde4 | 573 | int wxSlider95::GetSelEnd() const |
2bda0e17 | 574 | { |
4438caf4 | 575 | return (int) ::SendMessage( GetHwnd(), TBM_SETSELEND, (WPARAM) 0, (LPARAM) 0 ); |
2bda0e17 KB |
576 | } |
577 | ||
bfc6fde4 | 578 | int wxSlider95::GetSelStart() const |
2bda0e17 | 579 | { |
4438caf4 | 580 | return (int) ::SendMessage( GetHwnd(), TBM_GETSELSTART, (WPARAM) 0, (LPARAM) 0 ); |
2bda0e17 KB |
581 | } |
582 | ||
debe6624 | 583 | void wxSlider95::SetSelection(int minPos, int maxPos) |
2bda0e17 | 584 | { |
4438caf4 | 585 | ::SendMessage( GetHwnd(), TBM_SETSEL, (WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) ); |
2bda0e17 KB |
586 | } |
587 | ||
debe6624 | 588 | void wxSlider95::SetThumbLength(int len) |
2bda0e17 | 589 | { |
4438caf4 | 590 | ::SendMessage( GetHwnd(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0 ); |
2bda0e17 KB |
591 | } |
592 | ||
bfc6fde4 | 593 | int wxSlider95::GetThumbLength() const |
2bda0e17 | 594 | { |
4438caf4 | 595 | return (int) ::SendMessage( GetHwnd(), TBM_GETTHUMBLENGTH, (WPARAM) 0, (LPARAM) 0 ); |
2bda0e17 KB |
596 | } |
597 | ||
debe6624 | 598 | void wxSlider95::SetTick(int tickPos) |
2bda0e17 | 599 | { |
4438caf4 | 600 | ::SendMessage( GetHwnd(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos ); |
2bda0e17 KB |
601 | } |
602 | ||
da87a1ca | 603 | bool wxSlider95::ContainsHWND(WXHWND hWnd) const |
2bda0e17 | 604 | { |
a23fd0e1 | 605 | return ( hWnd == GetStaticMin() || hWnd == GetStaticMax() || hWnd == GetEditValue() ); |
2bda0e17 KB |
606 | } |
607 | ||
da87a1ca | 608 | void wxSlider95::Command (wxCommandEvent & event) |
2bda0e17 KB |
609 | { |
610 | SetValue (event.GetInt()); | |
611 | ProcessCommand (event); | |
612 | } | |
613 | ||
debe6624 | 614 | bool wxSlider95::Show(bool show) |
2bda0e17 | 615 | { |
a23fd0e1 | 616 | wxWindow::Show(show); |
2bda0e17 KB |
617 | |
618 | int cshow; | |
619 | if (show) | |
620 | cshow = SW_SHOW; | |
621 | else | |
622 | cshow = SW_HIDE; | |
623 | ||
624 | if(m_staticValue) | |
a23fd0e1 | 625 | ShowWindow((HWND) m_staticValue, (BOOL)cshow); |
2bda0e17 | 626 | if(m_staticMin) |
a23fd0e1 | 627 | ShowWindow((HWND) m_staticMin, (BOOL)cshow); |
2bda0e17 | 628 | if(m_staticMax) |
a23fd0e1 | 629 | ShowWindow((HWND) m_staticMax, (BOOL)cshow); |
2bda0e17 KB |
630 | return TRUE; |
631 | } | |
632 | ||
da87a1ca JS |
633 | #endif |
634 | // __WIN95__ | |
2bda0e17 | 635 | |
1e6feb95 | 636 | #endif // wxUSE_SLIDER |