1 /////////////////////////////////////////////////////////////////////////////
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
25 #include "wx/slider.h"
26 #include "wx/os2/private.h"
28 #if !USE_SHARED_LIBRARY
29 IMPLEMENT_DYNAMIC_CLASS(wxSlider
, wxControl
)
45 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
46 int value
, int minValue
, int maxValue
,
48 const wxSize
& size
, long style
,
50 const wxValidator
& validator
,
56 SetValidator(validator
);
59 if (parent
) parent
->AddChild(this);
62 m_windowStyle
= style
;
66 m_windowId
= (int)NewControlId();
70 m_rangeMax
= maxValue
;
71 m_rangeMin
= minValue
;
73 m_pageSize
= (int)((maxValue
-minValue
)/10);
80 bool wxSlider::OS2OnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
81 WXWORD pos
, WXHWND control
)
83 int position
= 0; // Dummy - not used in this mode
86 wxEventType scrollEvent
= wxEVT_NULL
;
92 nScrollInc = m_rangeMax - position;
93 scrollEvent = wxEVT_SCROLL_TOP;
97 nScrollInc = - position;
98 scrollEvent = wxEVT_SCROLL_BOTTOM;
102 nScrollInc = - GetLineSize();
103 scrollEvent = wxEVT_SCROLL_LINEUP;
107 nScrollInc = GetLineSize();
108 scrollEvent = wxEVT_SCROLL_LINEDOWN;
112 nScrollInc = -GetPageSize();
113 scrollEvent = wxEVT_SCROLL_PAGEUP;
117 nScrollInc = GetPageSize();
118 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
122 case SB_THUMBPOSITION:
124 nScrollInc = (signed short)pos - position;
126 nScrollInc = pos - position;
128 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
135 if ( nScrollInc == 0 )
141 int newPos = (int)::SendMessage((HWND) control, TBM_GETPOS, 0, 0);
142 if ( (newPos < GetMin()) || (newPos > GetMax()) )
144 // out of range - but we did process it
148 int newPos
= 0; //temporary
151 wxScrollEvent
event(scrollEvent
, m_windowId
);
152 event
.SetPosition(newPos
);
153 event
.SetEventObject( this );
154 GetEventHandler()->ProcessEvent(event
);
156 wxCommandEvent
cevent( wxEVT_COMMAND_SLIDER_UPDATED
, GetId() );
157 cevent
.SetEventObject( this );
159 return GetEventHandler()->ProcessEvent( cevent
);
162 wxSlider::~wxSlider()
167 int wxSlider::GetValue() const
173 void wxSlider::SetValue(int value
)
178 void wxSlider::GetSize(int *width
, int *height
) const
183 void wxSlider::GetPosition(int *x
, int *y
) const
188 // TODO one day, make sense of all this horros and replace it with a readable
190 void wxSlider::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
197 int currentX
, currentY
;
198 GetPosition(¤tX
, ¤tY
);
199 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
201 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
207 AdjustForParentClientOrigin(x1, y1, sizeFlags);
214 int cx; // slider,min,max sizes
218 wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
220 if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL)
222 if ( m_windowStyle & wxSL_LABELS )
226 GetWindowText((HWND) m_staticMin, buf, 300);
227 GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont());
231 GetWindowText((HWND) m_staticMax, buf, 300);
232 GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont());
235 int new_width = (int)(wxMax(min_len, max_len));
236 int valueHeight = (int)cyf;
238 // For some reason, under Win95, the text edit control has
239 // a lot of space before the first character
242 // The height needs to be a bit bigger under Win95 if using native
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;
249 MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE);
250 x_offset += (int)(min_len + cx);
252 int slider_length = (int)(w1 - x_offset - max_len - cx);
254 int slider_height = h1;
255 if (slider_height < 0 )
258 // Slider must have a minimum/default length/height
259 if (slider_length < 100)
262 MoveWindow(GetHwnd(), x_offset, y_offset, slider_length, slider_height, TRUE);
263 x_offset += slider_length + cx;
265 MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE);
270 // If we're prepared to use the existing size, then...
271 if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
279 MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
284 if ( m_windowStyle & wxSL_LABELS )
287 GetWindowText((HWND) m_staticMin, buf, 300);
288 GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont());
291 GetWindowText((HWND) m_staticMax, buf, 300);
292 GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont());
296 int new_width = (int)(wxMax(min_len, max_len));
297 int valueHeight = (int)cyf;
298 //// Suggested change by George Tasker - remove this block...
300 // For some reason, under Win95, the text edit control has
301 // a lot of space before the first character
304 ... and replace with following line:
307 // The height needs to be a bit bigger under Win95 if using native
309 valueHeight = (int) (valueHeight * 1.5) ;
311 MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE);
312 y_offset += valueHeight;
315 MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE);
318 int slider_length = (int)(h1 - y_offset - cy - cy);
320 int slider_width = w1;
321 if (slider_width < 0 )
324 // Slider must have a minimum/default length
325 if (slider_length < 100)
328 MoveWindow(GetHwnd(), x_offset, y_offset, slider_width, slider_length, TRUE);
329 y_offset += slider_length;
331 MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE);
336 // If we're prepared to use the existing size, then...
337 if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
345 MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
351 void wxSlider::SetRange(int minValue
, int maxValue
)
353 m_rangeMin
= minValue
;
354 m_rangeMax
= maxValue
;
359 WXHBRUSH
wxSlider::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
360 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
364 if ( nCtlColor == CTLCOLOR_SCROLLBAR )
367 // Otherwise, it's a static
368 if (GetParent()->GetTransparentBackground())
369 SetBkMode((HDC) pDC, TRANSPARENT);
371 SetBkMode((HDC) pDC, OPAQUE);
373 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
374 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
376 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
377 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
382 // For trackbars only
383 void wxSlider::SetTickFreq(int n
, int pos
)
389 void wxSlider::SetPageSize(int pageSize
)
392 m_pageSize
= pageSize
;
395 int wxSlider::GetPageSize() const
400 void wxSlider::ClearSel()
405 void wxSlider::ClearTicks()
410 void wxSlider::SetLineSize(int lineSize
)
412 m_lineSize
= lineSize
;
416 int wxSlider::GetLineSize() const
422 int wxSlider::GetSelEnd() const
428 int wxSlider::GetSelStart() const
434 void wxSlider::SetSelection(int minPos
, int maxPos
)
439 void wxSlider::SetThumbLength(int len
)
444 int wxSlider::GetThumbLength() const
450 void wxSlider::SetTick(int tickPos
)
455 bool wxSlider::ContainsHWND(WXHWND hWnd
) const
457 return ( hWnd
== GetStaticMin() || hWnd
== GetStaticMax() || hWnd
== GetEditValue() );
460 void wxSlider::Command (wxCommandEvent
& event
)
462 SetValue (event
.GetInt());
463 ProcessCommand (event
);
466 bool wxSlider::Show(bool show
)