diff --git a/headers/os/interface/Slider.h b/headers/os/interface/Slider.h index 2ce286bc03..d96029dd0c 100644 --- a/headers/os/interface/Slider.h +++ b/headers/os/interface/Slider.h @@ -70,6 +70,7 @@ public: virtual void FrameMoved(BPoint newPosition); virtual void FrameResized(float width, float height); virtual void KeyDown(const char* bytes, int32 numBytes); + virtual void KeyUp(const char* bytes, int32 numBytes); virtual void MouseDown(BPoint point); virtual void MouseUp(BPoint point); virtual void MouseMoved(BPoint point, uint32 transit, @@ -80,7 +81,7 @@ public: virtual void SetLimitLabels(const char* minLabel, const char* maxLabel); const char* MinLimitLabel() const; - const char* MaxLimitLabel() const; + const char* MaxLimitLabel() const; virtual void SetValue(int32); virtual int32 ValueForPoint(BPoint) const; virtual void SetPosition(float); diff --git a/src/kits/interface/Slider.cpp b/src/kits/interface/Slider.cpp index 536397154a..7c685c7602 100644 --- a/src/kits/interface/Slider.cpp +++ b/src/kits/interface/Slider.cpp @@ -481,32 +481,52 @@ BSlider::KeyDown(const char *bytes, int32 numBytes) switch (bytes[0]) { case B_LEFT_ARROW: - case B_DOWN_ARROW: { + case B_DOWN_ARROW: newValue -= KeyIncrementValue(); break; - } + case B_RIGHT_ARROW: - case B_UP_ARROW: { + case B_UP_ARROW: newValue += KeyIncrementValue(); break; - } + case B_HOME: newValue = fMinValue; break; case B_END: newValue = fMaxValue; break; + default: BControl::KeyDown(bytes, numBytes); return; } + if (newValue < fMinValue) + newValue = fMinValue; + if (newValue > fMaxValue) + newValue = fMaxValue; + if (newValue != Value()) { + fInitialLocation = _Location(); SetValue(newValue); InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); } } +void +BSlider::KeyUp(const char *bytes, int32 numBytes) +{ + if (fInitialLocation != _Location()) { + // The last KeyDown event triggered the modification message or no + // notification at all, we may also have sent the modification message + // continually while the user kept pressing the key. In either case, + // finish with the final message to make the behavior consistent with + // changing the value by mouse. + Invoke(); + } +} + /*! Makes sure the \a point is within valid bounds. @@ -673,7 +693,7 @@ BSlider::SetValue(int32 value) if (value == Value()) return; - + _SetLocationForValue(value); BRect oldThumbFrame = ThumbFrame();