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