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 # if defined(__VISAGECPP__)
51 const wxValidator
* validator
,
53 const wxValidator
& validator
,
60 SetValidator(validator
);
63 if (parent
) parent
->AddChild(this);
66 m_windowStyle
= style
;
70 m_windowId
= (int)NewControlId();
74 m_rangeMax
= maxValue
;
75 m_rangeMin
= minValue
;
77 m_pageSize
= (int)((maxValue
-minValue
)/10);
84 bool wxSlider::OS2OnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
85 WXWORD pos
, WXHWND control
)
87 int position
= 0; // Dummy - not used in this mode
90 wxEventType scrollEvent
= wxEVT_NULL
;
96 nScrollInc = m_rangeMax - position;
97 scrollEvent = wxEVT_SCROLL_TOP;
101 nScrollInc = - position;
102 scrollEvent = wxEVT_SCROLL_BOTTOM;
106 nScrollInc = - GetLineSize();
107 scrollEvent = wxEVT_SCROLL_LINEUP;
111 nScrollInc = GetLineSize();
112 scrollEvent = wxEVT_SCROLL_LINEDOWN;
116 nScrollInc = -GetPageSize();
117 scrollEvent = wxEVT_SCROLL_PAGEUP;
121 nScrollInc = GetPageSize();
122 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
126 case SB_THUMBPOSITION:
128 nScrollInc = (signed short)pos - position;
130 nScrollInc = pos - position;
132 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
139 if ( nScrollInc == 0 )
145 int newPos = (int)::SendMessage((HWND) control, TBM_GETPOS, 0, 0);
146 if ( (newPos < GetMin()) || (newPos > GetMax()) )
148 // out of range - but we did process it
152 int newPos
= 0; //temporary
155 wxScrollEvent
event(scrollEvent
, m_windowId
);
156 event
.SetPosition(newPos
);
157 event
.SetEventObject( this );
158 GetEventHandler()->ProcessEvent(event
);
160 wxCommandEvent
cevent( wxEVT_COMMAND_SLIDER_UPDATED
, GetId() );
161 cevent
.SetEventObject( this );
163 return GetEventHandler()->ProcessEvent( cevent
);
166 wxSlider::~wxSlider()
171 int wxSlider::GetValue() const
177 void wxSlider::SetValue(int value
)
182 void wxSlider::GetSize(int *width
, int *height
) const
187 void wxSlider::GetPosition(int *x
, int *y
) const
192 // TODO one day, make sense of all this horros and replace it with a readable
194 void wxSlider::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
201 int currentX
, currentY
;
202 GetPosition(¤tX
, ¤tY
);
203 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
205 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
211 AdjustForParentClientOrigin(x1, y1, sizeFlags);
218 int cx; // slider,min,max sizes
222 wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
224 if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL)
226 if ( m_windowStyle & wxSL_LABELS )
230 GetWindowText((HWND) m_staticMin, buf, 300);
231 GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont());
235 GetWindowText((HWND) m_staticMax, buf, 300);
236 GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont());
239 int new_width = (int)(wxMax(min_len, max_len));
240 int valueHeight = (int)cyf;
242 // For some reason, under Win95, the text edit control has
243 // a lot of space before the first character
246 // The height needs to be a bit bigger under Win95 if using native
248 valueHeight = (int) (valueHeight * 1.5) ;
249 MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE);
250 x_offset += new_width + cx;
253 MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE);
254 x_offset += (int)(min_len + cx);
256 int slider_length = (int)(w1 - x_offset - max_len - cx);
258 int slider_height = h1;
259 if (slider_height < 0 )
262 // Slider must have a minimum/default length/height
263 if (slider_length < 100)
266 MoveWindow(GetHwnd(), x_offset, y_offset, slider_length, slider_height, TRUE);
267 x_offset += slider_length + cx;
269 MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE);
274 // If we're prepared to use the existing size, then...
275 if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
283 MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
288 if ( m_windowStyle & wxSL_LABELS )
291 GetWindowText((HWND) m_staticMin, buf, 300);
292 GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont());
295 GetWindowText((HWND) m_staticMax, buf, 300);
296 GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont());
300 int new_width = (int)(wxMax(min_len, max_len));
301 int valueHeight = (int)cyf;
302 //// Suggested change by George Tasker - remove this block...
304 // For some reason, under Win95, the text edit control has
305 // a lot of space before the first character
308 ... and replace with following line:
311 // The height needs to be a bit bigger under Win95 if using native
313 valueHeight = (int) (valueHeight * 1.5) ;
315 MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE);
316 y_offset += valueHeight;
319 MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE);
322 int slider_length = (int)(h1 - y_offset - cy - cy);
324 int slider_width = w1;
325 if (slider_width < 0 )
328 // Slider must have a minimum/default length
329 if (slider_length < 100)
332 MoveWindow(GetHwnd(), x_offset, y_offset, slider_width, slider_length, TRUE);
333 y_offset += slider_length;
335 MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE);
340 // If we're prepared to use the existing size, then...
341 if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
349 MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
355 void wxSlider::SetRange(int minValue
, int maxValue
)
357 m_rangeMin
= minValue
;
358 m_rangeMax
= maxValue
;
363 WXHBRUSH
wxSlider::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
364 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
368 if ( nCtlColor == CTLCOLOR_SCROLLBAR )
371 // Otherwise, it's a static
372 if (GetParent()->GetTransparentBackground())
373 SetBkMode((HDC) pDC, TRANSPARENT);
375 SetBkMode((HDC) pDC, OPAQUE);
377 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
378 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
380 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
381 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
386 // For trackbars only
387 void wxSlider::SetTickFreq(int n
, int pos
)
393 void wxSlider::SetPageSize(int pageSize
)
396 m_pageSize
= pageSize
;
399 int wxSlider::GetPageSize() const
404 void wxSlider::ClearSel()
409 void wxSlider::ClearTicks()
414 void wxSlider::SetLineSize(int lineSize
)
416 m_lineSize
= lineSize
;
420 int wxSlider::GetLineSize() const
426 int wxSlider::GetSelEnd() const
432 int wxSlider::GetSelStart() const
438 void wxSlider::SetSelection(int minPos
, int maxPos
)
443 void wxSlider::SetThumbLength(int len
)
448 int wxSlider::GetThumbLength() const
454 void wxSlider::SetTick(int tickPos
)
459 bool wxSlider::ContainsHWND(WXHWND hWnd
) const
461 return ( hWnd
== GetStaticMin() || hWnd
== GetStaticMax() || hWnd
== GetEditValue() );
464 void wxSlider::Command (wxCommandEvent
& event
)
466 SetValue (event
.GetInt());
467 ProcessCommand (event
);
470 bool wxSlider::Show(bool show
)