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