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