]>
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 | 8 | // Copyright: (c) Julian Smart |
65571936 | 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) | |
57f4f925 | 52 | |
bc9fb572 | 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) | |
cb0afb26 | 59 | wxFLAGS_MEMBER(wxBORDER) |
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) | |
cb0afb26 | 66 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
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 | 90 | wxPROPERTY( Value , int , SetValue, GetValue , 0, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
822e690b WS |
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")) | |
af498247 | 96 | wxPROPERTY_FLAGS( WindowStyle , wxSliderStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
3ff066a4 | 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, |
422a142b | 124 | const wxValidator& validator, |
2bda0e17 KB |
125 | const wxString& name) |
126 | { | |
7bdfb981 | 127 | // default is no border |
fe3d9123 JS |
128 | if ( (style & wxBORDER_MASK) == wxBORDER_DEFAULT ) |
129 | style |= wxBORDER_NONE; | |
130 | ||
7bdfb981 | 131 | if ( !CreateBase(parent, id, pos, size, style, validator, name) ) |
822e690b | 132 | return false; |
2bda0e17 | 133 | |
5f605ccf VZ |
134 | if (parent) parent->AddChild(this); |
135 | ||
7bdfb981 | 136 | InheritAttributes(); |
5f605ccf VZ |
137 | |
138 | m_staticValue = (WXHWND) NULL;; | |
139 | m_staticMin = (WXHWND) NULL;; | |
140 | m_staticMax = (WXHWND) NULL;; | |
141 | m_pageSize = 1; | |
142 | m_lineSize = 1; | |
143 | m_windowStyle = style; | |
144 | m_tickFreq = 0; | |
145 | ||
5f605ccf | 146 | long msStyle = 0; |
5f605ccf | 147 | |
5f605ccf VZ |
148 | if ( m_windowStyle & wxSL_LABELS ) |
149 | { | |
fe3d9123 | 150 | msStyle |= SS_CENTER; |
5f605ccf | 151 | |
fe3d9123 | 152 | WXDWORD exStyle = 0; |
983d2e14 JS |
153 | long valueStyle = m_windowStyle & ~wxBORDER_MASK; |
154 | valueStyle |= wxBORDER_SUNKEN; | |
155 | msStyle |= MSWGetStyle(valueStyle, & exStyle) ; | |
5f605ccf VZ |
156 | |
157 | m_staticValue = (WXHWND) CreateWindowEx | |
158 | ( | |
159 | exStyle, wxT("STATIC"), NULL, | |
160 | msStyle, | |
161 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), | |
162 | wxGetInstance(), NULL | |
163 | ); | |
164 | ||
165 | // Now create min static control | |
2b5f62a0 VZ |
166 | wxString minLabel; |
167 | minLabel.Printf(wxT("%d"), minValue); | |
822e690b | 168 | long wstyle = STATIC_FLAGS; |
5f605ccf | 169 | if ( m_windowStyle & wxCLIP_SIBLINGS ) |
5cb598ae | 170 | wstyle |= WS_CLIPSIBLINGS; |
5f605ccf VZ |
171 | m_staticMin = (WXHWND) CreateWindowEx |
172 | ( | |
2b5f62a0 | 173 | 0, wxT("STATIC"), minLabel, |
5f605ccf VZ |
174 | wstyle, |
175 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), | |
176 | wxGetInstance(), NULL | |
177 | ); | |
178 | } | |
179 | ||
fe3d9123 | 180 | WXDWORD exStyle = 0; |
5f605ccf | 181 | |
822e690b WS |
182 | msStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ; |
183 | ||
184 | wxUnusedVar(msStyle); | |
2bda0e17 | 185 | |
5f605ccf VZ |
186 | if (m_windowStyle & wxSL_VERTICAL) |
187 | msStyle = TBS_VERT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; | |
188 | else | |
189 | msStyle = TBS_HORZ | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; | |
b0766406 | 190 | |
5f605ccf VZ |
191 | if ( m_windowStyle & wxSL_AUTOTICKS ) |
192 | msStyle |= TBS_AUTOTICKS ; | |
b0766406 | 193 | |
5f605ccf VZ |
194 | if ( m_windowStyle & wxSL_LEFT ) |
195 | msStyle |= TBS_LEFT; | |
196 | else if ( m_windowStyle & wxSL_RIGHT ) | |
197 | msStyle |= TBS_RIGHT; | |
198 | else if ( m_windowStyle & wxSL_TOP ) | |
199 | msStyle |= TBS_TOP; | |
200 | else if ( m_windowStyle & wxSL_BOTTOM ) | |
201 | msStyle |= TBS_BOTTOM; | |
202 | else if ( m_windowStyle & wxSL_BOTH ) | |
203 | msStyle |= TBS_BOTH; | |
204 | else if ( ! (m_windowStyle & wxSL_AUTOTICKS) ) | |
205 | msStyle |= TBS_NOTICKS; | |
2bda0e17 | 206 | |
5f605ccf VZ |
207 | if ( m_windowStyle & wxSL_SELRANGE ) |
208 | msStyle |= TBS_ENABLESELRANGE; | |
2bda0e17 | 209 | |
5f605ccf VZ |
210 | HWND scroll_bar = CreateWindowEx |
211 | ( | |
fda7962d | 212 | exStyle, TRACKBAR_CLASS, wxEmptyString, |
5f605ccf VZ |
213 | msStyle, |
214 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, | |
215 | wxGetInstance(), NULL | |
216 | ); | |
2bda0e17 | 217 | |
5f605ccf VZ |
218 | m_rangeMax = maxValue; |
219 | m_rangeMin = minValue; | |
2bda0e17 | 220 | |
5f605ccf | 221 | m_pageSize = (int)((maxValue-minValue)/10); |
2bda0e17 | 222 | |
5f605ccf VZ |
223 | ::SendMessage(scroll_bar, TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue)); |
224 | ::SendMessage(scroll_bar, TBM_SETPOS, TRUE, (LPARAM)value); | |
225 | ::SendMessage(scroll_bar, TBM_SETPAGESIZE, 0, (LPARAM)m_pageSize); | |
2bda0e17 | 226 | |
5f605ccf | 227 | m_hWnd = (WXHWND)scroll_bar; |
2bda0e17 | 228 | |
5f605ccf | 229 | SubclassWin(GetHWND()); |
2bda0e17 | 230 | |
fda7962d | 231 | ::SetWindowText((HWND) m_hWnd, wxEmptyString); |
2bda0e17 | 232 | |
5f605ccf VZ |
233 | if ( m_windowStyle & wxSL_LABELS ) |
234 | { | |
235 | // Finally, create max value static item | |
2b5f62a0 VZ |
236 | wxString maxLabel; |
237 | maxLabel.Printf(wxT("%d"), maxValue); | |
822e690b | 238 | long wstyle = STATIC_FLAGS; |
9c331ded | 239 | |
5f605ccf | 240 | if ( m_windowStyle & wxCLIP_SIBLINGS ) |
5cb598ae | 241 | wstyle |= WS_CLIPSIBLINGS; |
9c331ded | 242 | |
5f605ccf VZ |
243 | m_staticMax = (WXHWND) CreateWindowEx |
244 | ( | |
2b5f62a0 | 245 | 0, wxT("STATIC"), maxLabel, |
5f605ccf VZ |
246 | wstyle, |
247 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), | |
248 | wxGetInstance(), NULL | |
249 | ); | |
2bda0e17 | 250 | |
da87a1ca | 251 | |
5f605ccf | 252 | if (GetFont().Ok()) |
2bda0e17 | 253 | { |
5f605ccf VZ |
254 | if (GetFont().GetResourceHandle()) |
255 | { | |
256 | if ( m_staticMin ) | |
257 | ::SendMessage((HWND) m_staticMin, WM_SETFONT, | |
258 | (WPARAM) GetFont().GetResourceHandle(), 0L); | |
259 | ||
260 | if ( m_staticMax ) | |
261 | ::SendMessage((HWND) m_staticMax, WM_SETFONT, | |
262 | (WPARAM) GetFont().GetResourceHandle(), 0L); | |
263 | ||
264 | if (m_staticValue) | |
265 | ::SendMessage((HWND) m_staticValue, WM_SETFONT, | |
266 | (WPARAM) GetFont().GetResourceHandle(), 0L); | |
267 | } | |
2bda0e17 | 268 | } |
5f605ccf | 269 | } |
2bda0e17 | 270 | |
7a5a5718 | 271 | SetSize(pos.x, pos.y, size.x, size.y); |
5f605ccf | 272 | SetValue(value); |
2bda0e17 | 273 | |
7a5a5718 RD |
274 | // SetInitialBestSize is not called since we don't call MSWCreateControl |
275 | // for this control, so call SetBestSize here instead. | |
276 | SetBestSize(size); | |
277 | ||
822e690b | 278 | return true; |
2bda0e17 KB |
279 | } |
280 | ||
a23fd0e1 | 281 | bool wxSlider95::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam, |
d699f48b | 282 | WXWORD WXUNUSED(pos), WXHWND control) |
2bda0e17 | 283 | { |
1e6feb95 | 284 | wxEventType scrollEvent; |
2bda0e17 KB |
285 | switch ( wParam ) |
286 | { | |
a23fd0e1 | 287 | case SB_TOP: |
a23fd0e1 VZ |
288 | scrollEvent = wxEVT_SCROLL_TOP; |
289 | break; | |
290 | ||
291 | case SB_BOTTOM: | |
a23fd0e1 VZ |
292 | scrollEvent = wxEVT_SCROLL_BOTTOM; |
293 | break; | |
294 | ||
295 | case SB_LINEUP: | |
a23fd0e1 VZ |
296 | scrollEvent = wxEVT_SCROLL_LINEUP; |
297 | break; | |
298 | ||
299 | case SB_LINEDOWN: | |
a23fd0e1 VZ |
300 | scrollEvent = wxEVT_SCROLL_LINEDOWN; |
301 | break; | |
302 | ||
303 | case SB_PAGEUP: | |
a23fd0e1 VZ |
304 | scrollEvent = wxEVT_SCROLL_PAGEUP; |
305 | break; | |
306 | ||
307 | case SB_PAGEDOWN: | |
a23fd0e1 VZ |
308 | scrollEvent = wxEVT_SCROLL_PAGEDOWN; |
309 | break; | |
310 | ||
311 | case SB_THUMBTRACK: | |
a23fd0e1 VZ |
312 | scrollEvent = wxEVT_SCROLL_THUMBTRACK; |
313 | break; | |
314 | ||
e8b669d3 VZ |
315 | case SB_THUMBPOSITION: |
316 | scrollEvent = wxEVT_SCROLL_THUMBRELEASE; | |
317 | break; | |
318 | ||
319 | case SB_ENDSCROLL: | |
320 | scrollEvent = wxEVT_SCROLL_ENDSCROLL; | |
321 | break; | |
322 | ||
a23fd0e1 | 323 | default: |
1e6feb95 | 324 | // unknown scroll event? |
822e690b | 325 | return false; |
2bda0e17 KB |
326 | } |
327 | ||
5f605ccf | 328 | int newPos = (int) ::SendMessage((HWND) control, TBM_GETPOS, 0, 0); |
a23fd0e1 | 329 | if ( (newPos < GetMin()) || (newPos > GetMax()) ) |
2bda0e17 | 330 | { |
a23fd0e1 | 331 | // out of range - but we did process it |
822e690b | 332 | return true; |
a23fd0e1 | 333 | } |
2bda0e17 | 334 | |
a23fd0e1 | 335 | SetValue(newPos); |
2bda0e17 | 336 | |
a23fd0e1 VZ |
337 | wxScrollEvent event(scrollEvent, m_windowId); |
338 | event.SetPosition(newPos); | |
339 | event.SetEventObject( this ); | |
340 | GetEventHandler()->ProcessEvent(event); | |
f3a65071 | 341 | |
a23fd0e1 | 342 | wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() ); |
f6bcfd97 | 343 | cevent.SetInt( newPos ); |
a23fd0e1 | 344 | cevent.SetEventObject( this ); |
f3a65071 | 345 | |
a23fd0e1 | 346 | return GetEventHandler()->ProcessEvent( cevent ); |
2bda0e17 KB |
347 | } |
348 | ||
bfc6fde4 | 349 | wxSlider95::~wxSlider95() |
2bda0e17 KB |
350 | { |
351 | if (m_staticMin) | |
5f605ccf VZ |
352 | { |
353 | ::DestroyWindow((HWND) m_staticMin); | |
354 | m_staticMin = (WXHWND) NULL; | |
355 | } | |
356 | ||
2bda0e17 | 357 | if (m_staticMax) |
5f605ccf VZ |
358 | { |
359 | ::DestroyWindow((HWND) m_staticMax); | |
360 | m_staticMax = (WXHWND) NULL; | |
361 | } | |
362 | ||
2bda0e17 | 363 | if (m_staticValue) |
5f605ccf VZ |
364 | { |
365 | ::DestroyWindow((HWND) m_staticValue); | |
366 | m_staticValue = (WXHWND) NULL; | |
367 | } | |
2bda0e17 KB |
368 | } |
369 | ||
bfc6fde4 | 370 | int wxSlider95::GetValue() const |
2bda0e17 | 371 | { |
5f605ccf | 372 | return ::SendMessage(GetHwnd(), TBM_GETPOS, 0, 0); |
2bda0e17 KB |
373 | } |
374 | ||
debe6624 | 375 | void wxSlider95::SetValue(int value) |
2bda0e17 | 376 | { |
5f605ccf VZ |
377 | ::SendMessage(GetHwnd(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value); |
378 | ||
379 | if (m_staticValue) | |
380 | { | |
2b5f62a0 VZ |
381 | wxString str; |
382 | str.Printf(wxT("%d"), value); | |
383 | ::SetWindowText((HWND) m_staticValue, str); | |
5f605ccf VZ |
384 | } |
385 | } | |
386 | ||
387 | void wxSlider95::DoGetSize(int *width, int *height) const | |
2bda0e17 | 388 | { |
5f605ccf VZ |
389 | RECT rect; |
390 | rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1; | |
391 | ||
392 | wxFindMaxSize(GetHWND(), &rect); | |
2bda0e17 | 393 | |
5f605ccf VZ |
394 | if (m_staticMin) |
395 | wxFindMaxSize(m_staticMin, &rect); | |
2bda0e17 | 396 | |
5f605ccf VZ |
397 | if (m_staticMax) |
398 | wxFindMaxSize(m_staticMax, &rect); | |
2bda0e17 | 399 | |
5f605ccf VZ |
400 | if (m_staticValue) |
401 | wxFindMaxSize(m_staticValue, &rect); | |
402 | ||
6819fb9b VZ |
403 | if ( width ) |
404 | *width = rect.right - rect.left; | |
405 | if ( height ) | |
406 | *height = rect.bottom - rect.top; | |
2bda0e17 KB |
407 | } |
408 | ||
da87a1ca | 409 | void wxSlider95::GetPosition(int *x, int *y) const |
2bda0e17 | 410 | { |
5f605ccf VZ |
411 | wxWindow *parent = GetParent(); |
412 | RECT rect; | |
413 | rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1; | |
414 | ||
415 | wxFindMaxSize(GetHWND(), &rect); | |
416 | ||
417 | if (m_staticMin) | |
418 | wxFindMaxSize(m_staticMin, &rect); | |
419 | if (m_staticMax) | |
420 | wxFindMaxSize(m_staticMax, &rect); | |
421 | if (m_staticValue) | |
422 | wxFindMaxSize(m_staticValue, &rect); | |
423 | ||
424 | // Since we now have the absolute screen coords, | |
425 | // if there's a parent we must subtract its top left corner | |
426 | POINT point; | |
427 | point.x = rect.left; | |
428 | point.y = rect.top; | |
429 | if (parent) | |
430 | ::ScreenToClient((HWND) parent->GetHWND(), &point); | |
431 | ||
432 | // We may be faking the client origin. | |
433 | // So a window that's really at (0, 30) may appear | |
434 | // (to wxWin apps) to be at (0, 0). | |
435 | if (GetParent()) | |
436 | { | |
437 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
438 | point.x -= pt.x; | |
439 | point.y -= pt.y; | |
440 | } | |
441 | ||
442 | *x = point.x; | |
443 | *y = point.y; | |
2bda0e17 KB |
444 | } |
445 | ||
4438caf4 VZ |
446 | // TODO one day, make sense of all this horros and replace it with a readable |
447 | // DoGetBestSize() | |
bfc6fde4 | 448 | void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
2bda0e17 | 449 | { |
5f605ccf VZ |
450 | int x1 = x; |
451 | int y1 = y; | |
452 | int w1 = width; | |
453 | int h1 = height; | |
2bda0e17 | 454 | |
5f605ccf VZ |
455 | int currentX, currentY; |
456 | GetPosition(¤tX, ¤tY); | |
822e690b | 457 | if (x == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
5f605ccf | 458 | x1 = currentX; |
822e690b | 459 | if (y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
5f605ccf | 460 | y1 = currentY; |
2bda0e17 | 461 | |
5f605ccf | 462 | AdjustForParentClientOrigin(x1, y1, sizeFlags); |
81d66cf3 | 463 | |
5f605ccf | 464 | wxChar buf[300]; |
2bda0e17 | 465 | |
5f605ccf VZ |
466 | int x_offset = x; |
467 | int y_offset = y; | |
2bda0e17 | 468 | |
5f605ccf VZ |
469 | int cx; // slider,min,max sizes |
470 | int cy; | |
471 | int cyf; | |
2bda0e17 | 472 | |
7a5e53ab | 473 | wxGetCharSize(GetHWND(), &cx, &cy, this->GetFont()); |
2bda0e17 | 474 | |
5f605ccf | 475 | if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL) |
a23fd0e1 | 476 | { |
5f605ccf VZ |
477 | if ( m_windowStyle & wxSL_LABELS ) |
478 | { | |
479 | int min_len = 0; | |
2bda0e17 | 480 | |
5f605ccf | 481 | ::GetWindowText((HWND) m_staticMin, buf, 300); |
91810703 | 482 | GetTextExtent(buf, &min_len, &cyf); |
2bda0e17 | 483 | |
5f605ccf | 484 | int max_len = 0; |
2bda0e17 | 485 | |
5f605ccf | 486 | ::GetWindowText((HWND) m_staticMax, buf, 300); |
91810703 | 487 | GetTextExtent(buf, &max_len, &cyf); |
5f605ccf VZ |
488 | if (m_staticValue) |
489 | { | |
490 | int new_width = (int)(wxMax(min_len, max_len)); | |
491 | int valueHeight = (int)cyf; | |
2bda0e17 | 492 | #ifdef __WIN32__ |
5f605ccf VZ |
493 | // For some reason, under Win95, the text edit control has |
494 | // a lot of space before the first character | |
495 | new_width += 3*cx; | |
2bda0e17 | 496 | #endif |
5f605ccf VZ |
497 | // The height needs to be a bit bigger under Win95 if |
498 | // using native 3D effects. | |
499 | valueHeight = (int) (valueHeight * 1.5) ; | |
500 | ::MoveWindow((HWND) m_staticValue, x_offset, y_offset, | |
501 | new_width, valueHeight, TRUE); | |
502 | x_offset += new_width + cx; | |
503 | } | |
504 | ||
822e690b | 505 | ::MoveWindow((HWND) m_staticMin, x_offset, y_offset, |
5f605ccf VZ |
506 | (int) min_len, cy, TRUE); |
507 | x_offset += (int)(min_len + cx); | |
508 | ||
724a907c VZ |
509 | // slider_length = (total width available) - (width used so far) |
510 | // - (width of max label) - (border) | |
511 | int slider_length = (int)(w1 - (x_offset-x) - max_len - cx); | |
5f605ccf VZ |
512 | |
513 | int slider_height = h1; | |
514 | if (slider_height < 0 ) | |
515 | slider_height = 20; | |
516 | ||
517 | // Slider must have a minimum/default length/height | |
518 | if (slider_length < 100) | |
519 | slider_length = 100; | |
520 | ||
521 | ::MoveWindow(GetHwnd(), x_offset, y_offset, | |
522 | slider_length, slider_height, TRUE); | |
523 | x_offset += slider_length + cx; | |
524 | ||
822e690b | 525 | ::MoveWindow((HWND) m_staticMax, x_offset, y_offset, |
5f605ccf VZ |
526 | (int) max_len, cy, TRUE); |
527 | } | |
528 | else | |
a23fd0e1 | 529 | { |
5f605ccf VZ |
530 | // No labels |
531 | // If we're prepared to use the existing size, then... | |
532 | if | |
533 | ( | |
822e690b WS |
534 | width == wxDefaultCoord |
535 | && height == wxDefaultCoord | |
5f605ccf VZ |
536 | && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO) |
537 | ) | |
538 | { | |
539 | GetSize(&w1, &h1); | |
540 | } | |
541 | ||
542 | if ( w1 < 0 ) | |
7bdfb981 | 543 | w1 = 100; |
5f605ccf VZ |
544 | if ( h1 < 0 ) |
545 | h1 = 20; | |
546 | ||
547 | ::MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE); | |
a23fd0e1 | 548 | } |
a23fd0e1 | 549 | } |
5f605ccf | 550 | else |
2bda0e17 | 551 | { |
5f605ccf VZ |
552 | if ( m_windowStyle & wxSL_LABELS ) |
553 | { | |
554 | int min_len; | |
555 | ::GetWindowText((HWND) m_staticMin, buf, 300); | |
91810703 | 556 | GetTextExtent(buf, &min_len, &cyf); |
5f605ccf VZ |
557 | |
558 | int max_len; | |
559 | ::GetWindowText((HWND) m_staticMax, buf, 300); | |
91810703 | 560 | GetTextExtent(buf, &max_len, &cyf); |
5f605ccf VZ |
561 | |
562 | if (m_staticValue) | |
563 | { | |
564 | int new_width = (int)(wxMax(min_len, max_len)); | |
565 | int valueHeight = (int)cyf; | |
5f605ccf | 566 | new_width += cx; |
2bda0e17 | 567 | |
5f605ccf VZ |
568 | // The height needs to be a bit bigger under Win95 if |
569 | // using native 3D effects. | |
570 | valueHeight = (int) (valueHeight * 1.5) ; | |
2bda0e17 | 571 | |
5f605ccf VZ |
572 | ::MoveWindow((HWND) m_staticValue, x_offset, y_offset, |
573 | new_width, valueHeight, TRUE); | |
574 | y_offset += valueHeight; | |
575 | } | |
2bda0e17 | 576 | |
5f605ccf VZ |
577 | ::MoveWindow((HWND) m_staticMin, x_offset, y_offset, |
578 | (int) min_len, cy, TRUE); | |
579 | y_offset += cy; | |
2bda0e17 | 580 | |
57f4f925 | 581 | // slider_length = (total height available) - (height used so far) |
724a907c VZ |
582 | // - (height of max label) - (border) |
583 | int slider_length = (int)(h1 - (y_offset-y) - cy - cy); | |
da87a1ca | 584 | |
5f605ccf VZ |
585 | int slider_width = w1; |
586 | if (slider_width < 0 ) | |
587 | slider_width = 20; | |
2bda0e17 | 588 | |
5f605ccf VZ |
589 | // Slider must have a minimum/default length |
590 | if (slider_length < 100) | |
591 | slider_length = 100; | |
2bda0e17 | 592 | |
5f605ccf VZ |
593 | ::MoveWindow(GetHwnd(), x_offset, y_offset, |
594 | slider_width, slider_length, TRUE); | |
595 | y_offset += slider_length; | |
2bda0e17 | 596 | |
5f605ccf VZ |
597 | ::MoveWindow((HWND) m_staticMax, x_offset, y_offset, |
598 | (int)max_len, cy, TRUE); | |
599 | } | |
600 | else | |
a23fd0e1 | 601 | { |
5f605ccf VZ |
602 | // No labels |
603 | // If we're prepared to use the existing size, then... | |
604 | if | |
605 | ( | |
822e690b | 606 | width == wxDefaultCoord && height == wxDefaultCoord |
5f605ccf VZ |
607 | && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO) |
608 | ) | |
609 | { | |
610 | GetSize(&w1, &h1); | |
611 | } | |
612 | ||
613 | if ( w1 < 0 ) | |
614 | w1 = 20; | |
615 | if ( h1 < 0 ) | |
7bdfb981 | 616 | h1 = 100; |
5f605ccf VZ |
617 | |
618 | ::MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE); | |
a23fd0e1 | 619 | } |
a23fd0e1 | 620 | } |
2bda0e17 KB |
621 | } |
622 | ||
7bdfb981 RD |
623 | |
624 | // A reimplementaion of the mess above changed a bit to just determine the min | |
625 | // size needed. It would certainly be nice to refactor this and DoSetSize | |
626 | // somehow. | |
627 | wxSize wxSlider95::DoGetBestSize() const | |
628 | { | |
629 | wxSize rv; | |
630 | wxChar buf[300]; | |
57f4f925 | 631 | int cx; |
7bdfb981 RD |
632 | int cy; |
633 | int cyf; | |
634 | int min_len = 0; | |
635 | int max_len = 0; | |
57f4f925 | 636 | |
7a5e53ab | 637 | wxGetCharSize(GetHWND(), &cx, &cy, this->GetFont()); |
57f4f925 | 638 | |
7bdfb981 RD |
639 | if ( !HasFlag(wxSL_VERTICAL)) |
640 | { | |
641 | rv = wxSize(100, 20); // default size for the slider itself | |
57f4f925 | 642 | |
7bdfb981 RD |
643 | if (HasFlag(wxSL_LABELS)) // do we need to add more for the labels? |
644 | { | |
645 | ::GetWindowText((HWND) m_staticMin, buf, 300); | |
91810703 | 646 | GetTextExtent(buf, &min_len, &cyf); |
7bdfb981 RD |
647 | rv.x += min_len + cx; |
648 | ||
649 | ::GetWindowText((HWND) m_staticMax, buf, 300); | |
91810703 | 650 | GetTextExtent(buf, &max_len, &cyf); |
7bdfb981 RD |
651 | rv.x += max_len + cx; |
652 | ||
653 | if (m_staticValue) | |
654 | { | |
655 | int new_width = (int)(wxMax(min_len, max_len)); | |
656 | int valueHeight = (int)cyf; | |
57f4f925 | 657 | |
7bdfb981 RD |
658 | #ifdef __WIN32__ |
659 | // For some reason, under Win95, the text edit control has | |
660 | // a lot of space before the first character | |
661 | new_width += 3*cx; | |
662 | #endif | |
663 | // The height needs to be a bit bigger under Win95 if | |
664 | // using native 3D effects. | |
665 | valueHeight = (int) (valueHeight * 1.5) ; | |
666 | ||
667 | rv.x += new_width + cx; | |
668 | rv.y = wxMax(valueHeight, rv.y); | |
669 | } | |
670 | } | |
671 | } | |
672 | else // ! wxSL_HORIZONTAL | |
673 | { | |
674 | rv = wxSize(20, 100); // default size for the slider itself | |
675 | ||
676 | if (HasFlag(wxSL_LABELS)) // do we need to add more for the labels? | |
677 | { | |
678 | ::GetWindowText((HWND) m_staticMin, buf, 300); | |
91810703 | 679 | GetTextExtent(buf, &min_len, &cyf); |
7bdfb981 RD |
680 | rv.y += cy; |
681 | ||
682 | ::GetWindowText((HWND) m_staticMax, buf, 300); | |
91810703 | 683 | GetTextExtent(buf, &max_len, &cyf); |
7bdfb981 | 684 | rv.y += cy; |
57f4f925 | 685 | |
7bdfb981 RD |
686 | if (m_staticValue) |
687 | { | |
688 | int new_width = (int)(wxMax(min_len, max_len)); | |
689 | int valueHeight = (int)cyf; | |
690 | new_width += cx; | |
691 | ||
692 | // The height needs to be a bit bigger under Win95 if | |
693 | // using native 3D effects. | |
694 | valueHeight = (int) (valueHeight * 1.5) ; | |
695 | rv.y += valueHeight; | |
696 | rv.x = wxMax(new_width, rv.x); | |
57f4f925 | 697 | } |
7bdfb981 RD |
698 | } |
699 | } | |
700 | return rv; | |
701 | } | |
702 | ||
703 | ||
debe6624 | 704 | void wxSlider95::SetRange(int minValue, int maxValue) |
2bda0e17 | 705 | { |
5f605ccf VZ |
706 | m_rangeMin = minValue; |
707 | m_rangeMax = maxValue; | |
708 | ||
709 | ::SendMessage(GetHwnd(), TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue)); | |
710 | ||
711 | wxChar buf[40]; | |
712 | if ( m_staticMin ) | |
713 | { | |
714 | wxSprintf(buf, wxT("%d"), m_rangeMin); | |
715 | ::SetWindowText((HWND) m_staticMin, buf); | |
716 | } | |
717 | ||
718 | if ( m_staticMax ) | |
719 | { | |
720 | wxSprintf(buf, wxT("%d"), m_rangeMax); | |
721 | ::SetWindowText((HWND) m_staticMax, buf); | |
722 | } | |
2bda0e17 KB |
723 | } |
724 | ||
debe6624 | 725 | WXHBRUSH wxSlider95::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, |
a23fd0e1 | 726 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 | 727 | { |
4676948b | 728 | #ifndef __WXWINCE__ |
5f605ccf VZ |
729 | if ( nCtlColor == CTLCOLOR_SCROLLBAR ) |
730 | return 0; | |
4676948b JS |
731 | #else |
732 | if ( nCtlColor != CTLCOLOR_STATIC ) | |
733 | return 0; | |
734 | #endif | |
5f605ccf VZ |
735 | // Otherwise, it's a static |
736 | return wxControl::OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam); | |
2bda0e17 KB |
737 | } |
738 | ||
739 | // For trackbars only | |
debe6624 | 740 | void wxSlider95::SetTickFreq(int n, int pos) |
2bda0e17 | 741 | { |
2bda0e17 | 742 | m_tickFreq = n; |
4438caf4 | 743 | ::SendMessage( GetHwnd(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos ); |
2bda0e17 KB |
744 | } |
745 | ||
debe6624 | 746 | void wxSlider95::SetPageSize(int pageSize) |
2bda0e17 | 747 | { |
4438caf4 | 748 | ::SendMessage( GetHwnd(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize ); |
2bda0e17 KB |
749 | m_pageSize = pageSize; |
750 | } | |
751 | ||
bfc6fde4 | 752 | int wxSlider95::GetPageSize() const |
2bda0e17 KB |
753 | { |
754 | return m_pageSize; | |
755 | } | |
756 | ||
bfc6fde4 | 757 | void wxSlider95::ClearSel() |
2bda0e17 | 758 | { |
4438caf4 | 759 | ::SendMessage( GetHwnd(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0 ); |
2bda0e17 KB |
760 | } |
761 | ||
bfc6fde4 | 762 | void wxSlider95::ClearTicks() |
2bda0e17 | 763 | { |
4438caf4 | 764 | ::SendMessage( GetHwnd(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0 ); |
2bda0e17 KB |
765 | } |
766 | ||
debe6624 | 767 | void wxSlider95::SetLineSize(int lineSize) |
2bda0e17 | 768 | { |
5f605ccf VZ |
769 | m_lineSize = lineSize; |
770 | ::SendMessage( GetHwnd(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize ); | |
2bda0e17 KB |
771 | } |
772 | ||
bfc6fde4 | 773 | int wxSlider95::GetLineSize() const |
2bda0e17 | 774 | { |
5f605ccf VZ |
775 | return (int) ::SendMessage( GetHwnd(), TBM_GETLINESIZE, |
776 | (WPARAM) 0, (LPARAM) 0 ); | |
2bda0e17 KB |
777 | } |
778 | ||
bfc6fde4 | 779 | int wxSlider95::GetSelEnd() const |
2bda0e17 | 780 | { |
5f605ccf VZ |
781 | return (int) ::SendMessage( GetHwnd(), TBM_SETSELEND, |
782 | (WPARAM) 0, (LPARAM) 0 ); | |
2bda0e17 KB |
783 | } |
784 | ||
bfc6fde4 | 785 | int wxSlider95::GetSelStart() const |
2bda0e17 | 786 | { |
5f605ccf VZ |
787 | return (int) ::SendMessage( GetHwnd(), TBM_GETSELSTART, |
788 | (WPARAM) 0, (LPARAM) 0 ); | |
2bda0e17 KB |
789 | } |
790 | ||
debe6624 | 791 | void wxSlider95::SetSelection(int minPos, int maxPos) |
2bda0e17 | 792 | { |
5f605ccf VZ |
793 | ::SendMessage(GetHwnd(), TBM_SETSEL, |
794 | (WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) ); | |
2bda0e17 KB |
795 | } |
796 | ||
debe6624 | 797 | void wxSlider95::SetThumbLength(int len) |
2bda0e17 | 798 | { |
5f605ccf | 799 | ::SendMessage( GetHwnd(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0 ); |
2bda0e17 KB |
800 | } |
801 | ||
bfc6fde4 | 802 | int wxSlider95::GetThumbLength() const |
2bda0e17 | 803 | { |
5f605ccf VZ |
804 | return (int) ::SendMessage( GetHwnd(), TBM_GETTHUMBLENGTH, |
805 | (WPARAM) 0, (LPARAM) 0 ); | |
2bda0e17 KB |
806 | } |
807 | ||
debe6624 | 808 | void wxSlider95::SetTick(int tickPos) |
2bda0e17 | 809 | { |
4438caf4 | 810 | ::SendMessage( GetHwnd(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos ); |
2bda0e17 KB |
811 | } |
812 | ||
da87a1ca | 813 | bool wxSlider95::ContainsHWND(WXHWND hWnd) const |
2bda0e17 | 814 | { |
5f605ccf VZ |
815 | return |
816 | ( | |
817 | hWnd == GetStaticMin() | |
818 | || hWnd == GetStaticMax() | |
819 | || hWnd == GetEditValue() | |
820 | ); | |
2bda0e17 KB |
821 | } |
822 | ||
da87a1ca | 823 | void wxSlider95::Command (wxCommandEvent & event) |
2bda0e17 | 824 | { |
5f605ccf VZ |
825 | SetValue (event.GetInt()); |
826 | ProcessCommand (event); | |
2bda0e17 KB |
827 | } |
828 | ||
debe6624 | 829 | bool wxSlider95::Show(bool show) |
2bda0e17 | 830 | { |
a23fd0e1 | 831 | wxWindow::Show(show); |
2bda0e17 KB |
832 | |
833 | int cshow; | |
834 | if (show) | |
835 | cshow = SW_SHOW; | |
836 | else | |
837 | cshow = SW_HIDE; | |
838 | ||
839 | if(m_staticValue) | |
a23fd0e1 | 840 | ShowWindow((HWND) m_staticValue, (BOOL)cshow); |
5f605ccf | 841 | |
2bda0e17 | 842 | if(m_staticMin) |
a23fd0e1 | 843 | ShowWindow((HWND) m_staticMin, (BOOL)cshow); |
5f605ccf | 844 | |
2bda0e17 | 845 | if(m_staticMax) |
a23fd0e1 | 846 | ShowWindow((HWND) m_staticMax, (BOOL)cshow); |
5f605ccf | 847 | |
822e690b | 848 | return true; |
2bda0e17 KB |
849 | } |
850 | ||
da87a1ca JS |
851 | #endif |
852 | // __WIN95__ | |
2bda0e17 | 853 | |
1e6feb95 | 854 | #endif // wxUSE_SLIDER |