| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: slider.cpp |
| 3 | // Purpose: wxSlider |
| 4 | // Author: David Webster |
| 5 | // Modified by: |
| 6 | // Created: 10/15/99 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) David Webster |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | // For compilers that support precompilation, includes "wx.h". |
| 13 | #include "wx/wxprec.h" |
| 14 | |
| 15 | #ifdef __BORLANDC__ |
| 16 | #pragma hdrstop |
| 17 | #endif |
| 18 | |
| 19 | #ifndef WX_PRECOMP |
| 20 | #include <stdio.h> |
| 21 | #include <wx/utils.h> |
| 22 | #include <wx/brush.h> |
| 23 | #endif |
| 24 | |
| 25 | #include "wx/slider.h" |
| 26 | #include "wx/os2/private.h" |
| 27 | |
| 28 | #if !USE_SHARED_LIBRARY |
| 29 | IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) |
| 30 | #endif |
| 31 | |
| 32 | // Slider |
| 33 | wxSlider::wxSlider() |
| 34 | { |
| 35 | m_staticValue = 0; |
| 36 | m_staticMin = 0; |
| 37 | m_staticMax = 0; |
| 38 | m_pageSize = 1; |
| 39 | m_lineSize = 1; |
| 40 | m_rangeMax = 0; |
| 41 | m_rangeMin = 0; |
| 42 | m_tickFreq = 0; |
| 43 | } |
| 44 | |
| 45 | bool wxSlider::Create(wxWindow *parent, wxWindowID id, |
| 46 | int value, int minValue, int maxValue, |
| 47 | const wxPoint& pos, |
| 48 | const wxSize& size, long style, |
| 49 | #if wxUSE_VALIDATORS |
| 50 | const wxValidator& validator, |
| 51 | #endif |
| 52 | const wxString& name) |
| 53 | { |
| 54 | SetName(name); |
| 55 | #if wxUSE_VALIDATORS |
| 56 | SetValidator(validator); |
| 57 | #endif |
| 58 | |
| 59 | if (parent) parent->AddChild(this); |
| 60 | |
| 61 | m_lineSize = 1; |
| 62 | m_windowStyle = style; |
| 63 | m_tickFreq = 0; |
| 64 | |
| 65 | if ( id == -1 ) |
| 66 | m_windowId = (int)NewControlId(); |
| 67 | else |
| 68 | m_windowId = id; |
| 69 | |
| 70 | m_rangeMax = maxValue; |
| 71 | m_rangeMin = minValue; |
| 72 | |
| 73 | m_pageSize = (int)((maxValue-minValue)/10); |
| 74 | |
| 75 | // TODO create slider |
| 76 | |
| 77 | return FALSE; |
| 78 | } |
| 79 | |
| 80 | bool wxSlider::OS2OnScroll(int WXUNUSED(orientation), WXWORD wParam, |
| 81 | WXWORD pos, WXHWND control) |
| 82 | { |
| 83 | int position = 0; // Dummy - not used in this mode |
| 84 | |
| 85 | int nScrollInc; |
| 86 | wxEventType scrollEvent = wxEVT_NULL; |
| 87 | // TODO: |
| 88 | /* |
| 89 | switch ( wParam ) |
| 90 | { |
| 91 | case SB_TOP: |
| 92 | nScrollInc = m_rangeMax - position; |
| 93 | scrollEvent = wxEVT_SCROLL_TOP; |
| 94 | break; |
| 95 | |
| 96 | case SB_BOTTOM: |
| 97 | nScrollInc = - position; |
| 98 | scrollEvent = wxEVT_SCROLL_BOTTOM; |
| 99 | break; |
| 100 | |
| 101 | case SB_LINEUP: |
| 102 | nScrollInc = - GetLineSize(); |
| 103 | scrollEvent = wxEVT_SCROLL_LINEUP; |
| 104 | break; |
| 105 | |
| 106 | case SB_LINEDOWN: |
| 107 | nScrollInc = GetLineSize(); |
| 108 | scrollEvent = wxEVT_SCROLL_LINEDOWN; |
| 109 | break; |
| 110 | |
| 111 | case SB_PAGEUP: |
| 112 | nScrollInc = -GetPageSize(); |
| 113 | scrollEvent = wxEVT_SCROLL_PAGEUP; |
| 114 | break; |
| 115 | |
| 116 | case SB_PAGEDOWN: |
| 117 | nScrollInc = GetPageSize(); |
| 118 | scrollEvent = wxEVT_SCROLL_PAGEDOWN; |
| 119 | break; |
| 120 | |
| 121 | case SB_THUMBTRACK: |
| 122 | case SB_THUMBPOSITION: |
| 123 | #ifdef __WIN32__ |
| 124 | nScrollInc = (signed short)pos - position; |
| 125 | #else // Win16 |
| 126 | nScrollInc = pos - position; |
| 127 | #endif // Win32/16 |
| 128 | scrollEvent = wxEVT_SCROLL_THUMBTRACK; |
| 129 | break; |
| 130 | |
| 131 | default: |
| 132 | nScrollInc = 0; |
| 133 | } |
| 134 | |
| 135 | if ( nScrollInc == 0 ) |
| 136 | { |
| 137 | // no event... |
| 138 | return FALSE; |
| 139 | } |
| 140 | |
| 141 | int newPos = (int)::SendMessage((HWND) control, TBM_GETPOS, 0, 0); |
| 142 | if ( (newPos < GetMin()) || (newPos > GetMax()) ) |
| 143 | { |
| 144 | // out of range - but we did process it |
| 145 | return TRUE; |
| 146 | } |
| 147 | */ |
| 148 | int newPos = 0; //temporary |
| 149 | SetValue(newPos); |
| 150 | |
| 151 | wxScrollEvent event(scrollEvent, m_windowId); |
| 152 | event.SetPosition(newPos); |
| 153 | event.SetEventObject( this ); |
| 154 | GetEventHandler()->ProcessEvent(event); |
| 155 | |
| 156 | wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() ); |
| 157 | cevent.SetEventObject( this ); |
| 158 | |
| 159 | return GetEventHandler()->ProcessEvent( cevent ); |
| 160 | } |
| 161 | |
| 162 | wxSlider::~wxSlider() |
| 163 | { |
| 164 | // TODO: |
| 165 | } |
| 166 | |
| 167 | int wxSlider::GetValue() const |
| 168 | { |
| 169 | // TODO |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | void wxSlider::SetValue(int value) |
| 174 | { |
| 175 | // TODO |
| 176 | } |
| 177 | |
| 178 | void wxSlider::GetSize(int *width, int *height) const |
| 179 | { |
| 180 | // TODO |
| 181 | } |
| 182 | |
| 183 | void wxSlider::GetPosition(int *x, int *y) const |
| 184 | { |
| 185 | // TODO |
| 186 | } |
| 187 | |
| 188 | // TODO one day, make sense of all this horros and replace it with a readable |
| 189 | // DoGetBestSize() |
| 190 | void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
| 191 | { |
| 192 | int x1 = x; |
| 193 | int y1 = y; |
| 194 | int w1 = width; |
| 195 | int h1 = height; |
| 196 | |
| 197 | int currentX, currentY; |
| 198 | GetPosition(¤tX, ¤tY); |
| 199 | if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
| 200 | x1 = currentX; |
| 201 | if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
| 202 | y1 = currentY; |
| 203 | |
| 204 | // TODO: |
| 205 | /* |
| 206 | |
| 207 | AdjustForParentClientOrigin(x1, y1, sizeFlags); |
| 208 | |
| 209 | wxChar buf[300]; |
| 210 | |
| 211 | int x_offset = x; |
| 212 | int y_offset = y; |
| 213 | |
| 214 | int cx; // slider,min,max sizes |
| 215 | int cy; |
| 216 | int cyf; |
| 217 | |
| 218 | wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont()); |
| 219 | |
| 220 | if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL) |
| 221 | { |
| 222 | if ( m_windowStyle & wxSL_LABELS ) |
| 223 | { |
| 224 | int min_len = 0; |
| 225 | |
| 226 | GetWindowText((HWND) m_staticMin, buf, 300); |
| 227 | GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont()); |
| 228 | |
| 229 | int max_len = 0; |
| 230 | |
| 231 | GetWindowText((HWND) m_staticMax, buf, 300); |
| 232 | GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont()); |
| 233 | if (m_staticValue) |
| 234 | { |
| 235 | int new_width = (int)(wxMax(min_len, max_len)); |
| 236 | int valueHeight = (int)cyf; |
| 237 | #ifdef __WIN32__ |
| 238 | // For some reason, under Win95, the text edit control has |
| 239 | // a lot of space before the first character |
| 240 | new_width += 3*cx; |
| 241 | #endif |
| 242 | // The height needs to be a bit bigger under Win95 if using native |
| 243 | // 3D effects. |
| 244 | valueHeight = (int) (valueHeight * 1.5) ; |
| 245 | MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE); |
| 246 | x_offset += new_width + cx; |
| 247 | } |
| 248 | |
| 249 | MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE); |
| 250 | x_offset += (int)(min_len + cx); |
| 251 | |
| 252 | int slider_length = (int)(w1 - x_offset - max_len - cx); |
| 253 | |
| 254 | int slider_height = h1; |
| 255 | if (slider_height < 0 ) |
| 256 | slider_height = 20; |
| 257 | |
| 258 | // Slider must have a minimum/default length/height |
| 259 | if (slider_length < 100) |
| 260 | slider_length = 100; |
| 261 | |
| 262 | MoveWindow(GetHwnd(), x_offset, y_offset, slider_length, slider_height, TRUE); |
| 263 | x_offset += slider_length + cx; |
| 264 | |
| 265 | MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); |
| 266 | } |
| 267 | else |
| 268 | { |
| 269 | // No labels |
| 270 | // If we're prepared to use the existing size, then... |
| 271 | if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) |
| 272 | { |
| 273 | GetSize(&w1, &h1); |
| 274 | } |
| 275 | if ( w1 < 0 ) |
| 276 | w1 = 200; |
| 277 | if ( h1 < 0 ) |
| 278 | h1 = 20; |
| 279 | MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE); |
| 280 | } |
| 281 | } |
| 282 | else |
| 283 | { |
| 284 | if ( m_windowStyle & wxSL_LABELS ) |
| 285 | { |
| 286 | int min_len; |
| 287 | GetWindowText((HWND) m_staticMin, buf, 300); |
| 288 | GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont()); |
| 289 | |
| 290 | int max_len; |
| 291 | GetWindowText((HWND) m_staticMax, buf, 300); |
| 292 | GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont()); |
| 293 | |
| 294 | if (m_staticValue) |
| 295 | { |
| 296 | int new_width = (int)(wxMax(min_len, max_len)); |
| 297 | int valueHeight = (int)cyf; |
| 298 | //// Suggested change by George Tasker - remove this block... |
| 299 | #ifdef __WIN32__ |
| 300 | // For some reason, under Win95, the text edit control has |
| 301 | // a lot of space before the first character |
| 302 | new_width += 3*cx; |
| 303 | #endif |
| 304 | ... and replace with following line: |
| 305 | new_width += cx; |
| 306 | |
| 307 | // The height needs to be a bit bigger under Win95 if using native |
| 308 | // 3D effects. |
| 309 | valueHeight = (int) (valueHeight * 1.5) ; |
| 310 | |
| 311 | MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE); |
| 312 | y_offset += valueHeight; |
| 313 | } |
| 314 | |
| 315 | MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE); |
| 316 | y_offset += cy; |
| 317 | |
| 318 | int slider_length = (int)(h1 - y_offset - cy - cy); |
| 319 | |
| 320 | int slider_width = w1; |
| 321 | if (slider_width < 0 ) |
| 322 | slider_width = 20; |
| 323 | |
| 324 | // Slider must have a minimum/default length |
| 325 | if (slider_length < 100) |
| 326 | slider_length = 100; |
| 327 | |
| 328 | MoveWindow(GetHwnd(), x_offset, y_offset, slider_width, slider_length, TRUE); |
| 329 | y_offset += slider_length; |
| 330 | |
| 331 | MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); |
| 332 | } |
| 333 | else |
| 334 | { |
| 335 | // No labels |
| 336 | // If we're prepared to use the existing size, then... |
| 337 | if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) |
| 338 | { |
| 339 | GetSize(&w1, &h1); |
| 340 | } |
| 341 | if ( w1 < 0 ) |
| 342 | w1 = 20; |
| 343 | if ( h1 < 0 ) |
| 344 | h1 = 200; |
| 345 | MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE); |
| 346 | } |
| 347 | } |
| 348 | */ |
| 349 | } |
| 350 | |
| 351 | void wxSlider::SetRange(int minValue, int maxValue) |
| 352 | { |
| 353 | m_rangeMin = minValue; |
| 354 | m_rangeMax = maxValue; |
| 355 | |
| 356 | // TODO |
| 357 | } |
| 358 | |
| 359 | WXHBRUSH wxSlider::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, |
| 360 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
| 361 | { |
| 362 | // TODO: |
| 363 | /* |
| 364 | if ( nCtlColor == CTLCOLOR_SCROLLBAR ) |
| 365 | return 0; |
| 366 | |
| 367 | // Otherwise, it's a static |
| 368 | if (GetParent()->GetTransparentBackground()) |
| 369 | SetBkMode((HDC) pDC, TRANSPARENT); |
| 370 | else |
| 371 | SetBkMode((HDC) pDC, OPAQUE); |
| 372 | |
| 373 | ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); |
| 374 | ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); |
| 375 | |
| 376 | wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); |
| 377 | return (WXHBRUSH) backgroundBrush->GetResourceHandle(); |
| 378 | */ |
| 379 | return (WXHBRUSH)0; |
| 380 | } |
| 381 | |
| 382 | // For trackbars only |
| 383 | void wxSlider::SetTickFreq(int n, int pos) |
| 384 | { |
| 385 | // TODO |
| 386 | m_tickFreq = n; |
| 387 | } |
| 388 | |
| 389 | void wxSlider::SetPageSize(int pageSize) |
| 390 | { |
| 391 | // TODO |
| 392 | m_pageSize = pageSize; |
| 393 | } |
| 394 | |
| 395 | int wxSlider::GetPageSize() const |
| 396 | { |
| 397 | return m_pageSize; |
| 398 | } |
| 399 | |
| 400 | void wxSlider::ClearSel() |
| 401 | { |
| 402 | // TODO |
| 403 | } |
| 404 | |
| 405 | void wxSlider::ClearTicks() |
| 406 | { |
| 407 | // TODO |
| 408 | } |
| 409 | |
| 410 | void wxSlider::SetLineSize(int lineSize) |
| 411 | { |
| 412 | m_lineSize = lineSize; |
| 413 | // TODO |
| 414 | } |
| 415 | |
| 416 | int wxSlider::GetLineSize() const |
| 417 | { |
| 418 | // TODO |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | int wxSlider::GetSelEnd() const |
| 423 | { |
| 424 | // TODO |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | int wxSlider::GetSelStart() const |
| 429 | { |
| 430 | // TODO |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | void wxSlider::SetSelection(int minPos, int maxPos) |
| 435 | { |
| 436 | // TODO |
| 437 | } |
| 438 | |
| 439 | void wxSlider::SetThumbLength(int len) |
| 440 | { |
| 441 | // TODO |
| 442 | } |
| 443 | |
| 444 | int wxSlider::GetThumbLength() const |
| 445 | { |
| 446 | // TODO |
| 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | void wxSlider::SetTick(int tickPos) |
| 451 | { |
| 452 | // TODO |
| 453 | } |
| 454 | |
| 455 | bool wxSlider::ContainsHWND(WXHWND hWnd) const |
| 456 | { |
| 457 | return ( hWnd == GetStaticMin() || hWnd == GetStaticMax() || hWnd == GetEditValue() ); |
| 458 | } |
| 459 | |
| 460 | void wxSlider::Command (wxCommandEvent & event) |
| 461 | { |
| 462 | SetValue (event.GetInt()); |
| 463 | ProcessCommand (event); |
| 464 | } |
| 465 | |
| 466 | bool wxSlider::Show(bool show) |
| 467 | { |
| 468 | // TODO |
| 469 | return TRUE; |
| 470 | } |
| 471 | |