X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a290fa5a7deebe9d96c0c0089d18e27d4bd9b624..daebb84bff054d3833baca58a5dc506de56c64a1:/src/univ/slider.cpp diff --git a/src/univ/slider.cpp b/src/univ/slider.cpp index bd6eac32a2..e554c51ae2 100644 --- a/src/univ/slider.cpp +++ b/src/univ/slider.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: univ/slider.cpp +// Name: src/univ/slider.cpp // Purpose: implementation of the universal version of wxSlider // Author: Vadim Zeitlin // Modified by: @@ -22,9 +22,9 @@ or right. What we really need is probably a more fine grain control on labels, i.e. we - should be able to select if we show nothign at all, the current value only + should be able to select if we show nothing at all, the current value only or the value and the limits - the current approach is just that of the - greatest common denominator. + lowest common denominator. TODO: @@ -42,10 +42,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "univslider.h" -#endif - #include "wx/wxprec.h" #ifdef __BORLANDC__ @@ -184,7 +180,8 @@ bool wxSlider::ChangeValueBy(int inc) bool wxSlider::ChangeValueTo(int value) { // check if the value is going to change at all - if (value == m_value) return false; + if (value == m_value) + return false; // this method is protected and we should only call it with normalized // value! @@ -194,11 +191,15 @@ bool wxSlider::ChangeValueTo(int value) Refresh(); - // generate the event + // generate the events: both a specific scroll event and a command event + wxScrollEvent eventScroll(wxEVT_SCROLL_CHANGED, GetId()); + eventScroll.SetPosition(m_value); + eventScroll.SetEventObject( this ); + (void)GetEventHandler()->ProcessEvent(eventScroll); + wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId()); event.SetInt(m_value); event.SetEventObject(this); - (void)GetEventHandler()->ProcessEvent(event); return true; @@ -313,7 +314,7 @@ int wxSlider::GetThumbLength() const { wxSize sz = GetDefaultThumbSize(); int len = (IsVert() ? sz.x : sz.y); - if (m_thumbSize > len) + if (m_thumbSize > len) { return m_thumbSize; } @@ -389,7 +390,7 @@ wxSize wxSlider::DoGetBestClientSize() const if ( HasTicks() ) { wxCoord lenTick = GetRenderer()->GetSliderTickLen(); - if (style & wxSL_BOTH) + if (style & wxSL_BOTH) { lenTick = 2 * lenTick; } @@ -482,25 +483,25 @@ void wxSlider::CalcGeometry() m_rectLabel = wxRect(rectTotal.GetPosition(), sizeLabels); - if (style & wxSL_TOP) + if (style & wxSL_TOP) { // shrink and offset the slider to the bottom m_rectSlider.y += sizeLabels.y + SLIDER_LABEL_MARGIN; m_rectSlider.height -= sizeLabels.y + SLIDER_LABEL_MARGIN; } - else if (style & wxSL_BOTTOM) + else if (style & wxSL_BOTTOM) { // shrink the slider and move the label to the bottom m_rectSlider.height -= sizeLabels.y + SLIDER_LABEL_MARGIN; m_rectLabel.y += m_rectSlider.height + SLIDER_LABEL_MARGIN; } - else if (style & wxSL_LEFT) + else if (style & wxSL_LEFT) { // shrink and offset the slider to the right m_rectSlider.x += sizeLabels.x + SLIDER_LABEL_MARGIN; m_rectSlider.width -= sizeLabels.x + SLIDER_LABEL_MARGIN; } - else if (style & wxSL_RIGHT) + else if (style & wxSL_RIGHT) { // shrink the slider and move the label to the right m_rectSlider.width -= sizeLabels.x + SLIDER_LABEL_MARGIN; @@ -518,7 +519,7 @@ void wxSlider::CalcGeometry() if ( IsVert() ) { - if (style & (wxSL_LEFT|wxSL_BOTH)) + if (style & (wxSL_LEFT|wxSL_BOTH)) { m_rectTicks.x = m_rectSlider.x; } @@ -530,7 +531,7 @@ void wxSlider::CalcGeometry() } else // horizontal { - if (style & (wxSL_TOP|wxSL_BOTH)) + if (style & (wxSL_TOP|wxSL_BOTH)) { m_rectTicks.y = m_rectSlider.y; } @@ -599,8 +600,9 @@ void wxSlider::CalcThumbRect(const wxRect *rectShaftIn, } wxCoord lenShaft, - lenThumb, - *p; + lenThumb; + wxCoord *p; + wxRect rectThumb(rectShaft.GetPosition(), GetThumbSize()); if ( isVertical ) { @@ -708,19 +710,19 @@ void wxSlider::DoDraw(wxControlRenderer *renderer) { // align it to be close to the shaft int align = 0; - if (style & wxSL_TOP) + if (style & wxSL_TOP) { align = wxALIGN_CENTRE_HORIZONTAL|wxALIGN_TOP; } - else if (style & wxSL_BOTTOM) + else if (style & wxSL_BOTTOM) { align = wxALIGN_CENTRE_HORIZONTAL|wxALIGN_BOTTOM; } - else if (style & wxSL_LEFT) + else if (style & wxSL_LEFT) { align = wxALIGN_CENTRE_VERTICAL|wxALIGN_LEFT; } - else if (style & wxSL_RIGHT) + else if (style & wxSL_RIGHT) { align = wxALIGN_CENTRE_VERTICAL|wxALIGN_RIGHT; } @@ -742,49 +744,80 @@ bool wxSlider::PerformAction(const wxControlAction& action, long numArg, const wxString& strArg) { - if ( action == wxACTION_SLIDER_START ) + wxEventType scrollEvent = wxEVT_NULL; + int value; + bool valueChanged = true; + + if ( action == wxACTION_SLIDER_START ) { - ChangeValueTo(m_min); + scrollEvent = wxEVT_SCROLL_TOP; + value = m_min; } else if ( action == wxACTION_SLIDER_END ) { - ChangeValueTo(m_max); + scrollEvent = wxEVT_SCROLL_BOTTOM; + value = m_max; } else if ( action == wxACTION_SLIDER_PAGE_CHANGE ) { - ChangeValueBy(numArg * GetPageSize()); + value = NormalizeValue(m_value + numArg * GetPageSize()); } else if ( action == wxACTION_SLIDER_LINE_UP ) { - ChangeValueBy(+GetLineSize()); + scrollEvent = wxEVT_SCROLL_LINEUP; + value = NormalizeValue(m_value + +GetLineSize()); } else if ( action == wxACTION_SLIDER_LINE_DOWN ) { - ChangeValueBy(-GetLineSize()); + scrollEvent = wxEVT_SCROLL_LINEDOWN; + value = NormalizeValue(m_value + -GetLineSize()); } else if ( action == wxACTION_SLIDER_PAGE_UP ) { - ChangeValueBy(+GetPageSize()); + scrollEvent = wxEVT_SCROLL_PAGEUP; + value = NormalizeValue(m_value + +GetPageSize()); } else if ( action == wxACTION_SLIDER_PAGE_DOWN ) { - ChangeValueBy(-GetPageSize()); + scrollEvent = wxEVT_SCROLL_PAGEDOWN; + value = NormalizeValue(m_value + -GetPageSize()); } - else if ( action == wxACTION_SLIDER_THUMB_DRAG ) + else if ( action == wxACTION_SLIDER_THUMB_DRAG || + action == wxACTION_SLIDER_THUMB_MOVE ) { - // no special processing for it - return true; + scrollEvent = wxEVT_SCROLL_THUMBTRACK; + + // we shouldn't generate a command event about this change but we still + // should update our value and the slider appearance + valueChanged = false; + m_value = + value = (int)numArg; + Refresh(); } - else if ( action == wxACTION_SLIDER_THUMB_MOVE || - action == wxACTION_SLIDER_THUMB_RELEASE ) + else if ( action == wxACTION_SLIDER_THUMB_RELEASE ) { - ChangeValueTo((int)numArg); + scrollEvent = wxEVT_SCROLL_THUMBRELEASE; + value = (int)numArg; } else { return wxControl::PerformAction(action, numArg, strArg); } + // update wxSlider current value and generate wxCommandEvent, except while + // dragging the thumb + if ( valueChanged ) + ChangeValueTo(value); + + // also generate more precise wxScrollEvent if applicable + if ( scrollEvent != wxEVT_NULL ) + { + wxScrollEvent event(scrollEvent, GetId()); + event.SetPosition(value); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent(event); + } + return true; } @@ -799,14 +832,14 @@ wxScrollThumb::Shaft wxSlider::HitTest(const wxPoint& pt) const CalcThumbRect(&rectShaft, &rectThumb, NULL); // check for possible shaft or thumb hit - if (!rectShaft.Inside(pt) && !rectThumb.Inside(pt)) + if (!rectShaft.Inside(pt) && !rectThumb.Inside(pt)) { return wxScrollThumb::Shaft_None; } // the position to test and the start and end of the thumb wxCoord x, x1, x2, x3, x4; - if (IsVert()) + if (IsVert()) { x = pt.y; x1 = rectThumb.GetBottom(); @@ -822,13 +855,13 @@ wxScrollThumb::Shaft wxSlider::HitTest(const wxPoint& pt) const x3 = rectThumb.GetRight(); x4 = rectShaft.GetRight(); } - if ((x1 <= x) & (x < x2)) + if ((x1 <= x) && (x < x2)) { // or to the left return wxScrollThumb::Shaft_Above; } - if ((x3 < x) & (x <= x4)) { + if ((x3 < x) && (x <= x4)) { // or to the right return wxScrollThumb::Shaft_Below; } @@ -896,7 +929,7 @@ void wxSlider::SetShaftPartState(wxScrollThumb::Shaft shaftPart, void wxSlider::OnThumbDragStart(int pos) { - if (IsVert()) + if (IsVert()) { PerformAction(wxACTION_SLIDER_THUMB_DRAG, m_max - pos); } @@ -908,7 +941,7 @@ void wxSlider::OnThumbDragStart(int pos) void wxSlider::OnThumbDrag(int pos) { - if (IsVert()) + if (IsVert()) { PerformAction(wxACTION_SLIDER_THUMB_MOVE, m_max - pos); } @@ -920,7 +953,7 @@ void wxSlider::OnThumbDrag(int pos) void wxSlider::OnThumbDragEnd(int pos) { - if (IsVert()) + if (IsVert()) { PerformAction(wxACTION_SLIDER_THUMB_RELEASE, m_max - pos); } @@ -951,7 +984,7 @@ bool wxStdSliderButtonInputHandler::HandleKey(wxInputConsumer *consumer, const wxKeyEvent& event, bool pressed) { - if ( pressed ) + if ( pressed ) { int keycode = event.GetKeyCode(); @@ -976,12 +1009,10 @@ bool wxStdSliderButtonInputHandler::HandleKey(wxInputConsumer *consumer, action = wxACTION_SLIDER_LINE_DOWN; break; - case WXK_PRIOR: case WXK_PAGEUP: action = wxACTION_SLIDER_PAGE_UP; break; - case WXK_NEXT: case WXK_PAGEDOWN: action = wxACTION_SLIDER_PAGE_DOWN; break;