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