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