Author: stippi Date: 2010-11-06 13:43:24 +0100 (Sat, 06 Nov 2010) New Revision: 39323 Changeset: http://dev.haiku-os.org/changeset/39323 Ticket: http://dev.haiku-os.org/ticket/6792 Modified: haiku/trunk/headers/os/interface/Slider.h haiku/trunk/src/kits/interface/Slider.cpp Log: * Reuse the check for changed location which decides whether to Invoke() in MouseUp() in the code path for keyboard control. Should fix ticket #6792, but I have not actually tested it. * Don't post notification values in KeyDown() when the value did not change because it was constrained between min and max values. Modified: haiku/trunk/headers/os/interface/Slider.h =================================================================== --- haiku/trunk/headers/os/interface/Slider.h 2010-11-06 12:17:49 UTC (rev 39322) +++ haiku/trunk/headers/os/interface/Slider.h 2010-11-06 12:43:24 UTC (rev 39323) @@ -70,6 +70,7 @@ 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 @@ 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); Modified: haiku/trunk/src/kits/interface/Slider.cpp =================================================================== --- haiku/trunk/src/kits/interface/Slider.cpp 2010-11-06 12:17:49 UTC (rev 39322) +++ haiku/trunk/src/kits/interface/Slider.cpp 2010-11-06 12:43:24 UTC (rev 39323) @@ -481,33 +481,53 @@ 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. Returns \c true if the relevant coordinate (depending on the orientation @@ -673,7 +693,7 @@ if (value == Value()) return; - + _SetLocationForValue(value); BRect oldThumbFrame = ThumbFrame();