From fb29f5b0fb77e2079d4b272a932c15bf355ffb65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 4 Jan 2007 14:25:13 +0000 Subject: [PATCH] Changes to let updates happen less frequently: * _ContrainPoint() was broken as it could never change the point it was supposed to contrain. * MouseDown() no longer sends a notification message automatically (only if it changed something) * MouseMoved() and synchronous MouseDown() will now only send modification messages if something actually changed (not for every mouse update). * After key presses, the invokation message is only sent when the value changed. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19697 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/interface/Slider.h | 2 +- src/kits/interface/Slider.cpp | 34 ++++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/headers/os/interface/Slider.h b/headers/os/interface/Slider.h index eb1e6f0327..e0666d9b33 100644 --- a/headers/os/interface/Slider.h +++ b/headers/os/interface/Slider.h @@ -148,7 +148,7 @@ class BSlider : public BControl { float _MinPosition() const; float _MaxPosition() const; - bool _ConstrainPoint(BPoint point, BPoint compare) const; + bool _ConstrainPoint(BPoint& point, BPoint compare) const; virtual void _ReservedSlider5(); virtual void _ReservedSlider6(); diff --git a/src/kits/interface/Slider.cpp b/src/kits/interface/Slider.cpp index 99baf89148..5a3c7d5866 100644 --- a/src/kits/interface/Slider.cpp +++ b/src/kits/interface/Slider.cpp @@ -407,14 +407,20 @@ BSlider::KeyDown(const char *bytes, int32 numBytes) switch (bytes[0]) { case B_LEFT_ARROW: case B_DOWN_ARROW: { + int32 oldValue = Value(); + SetValue(Value() - KeyIncrementValue()); - Invoke(); + if (oldValue != Value()) + Invoke(); break; } case B_RIGHT_ARROW: case B_UP_ARROW: { + int32 oldValue = Value(); + SetValue(Value() + KeyIncrementValue()); - Invoke(); + if (oldValue != Value()) + Invoke(); break; } default: @@ -423,8 +429,13 @@ BSlider::KeyDown(const char *bytes, int32 numBytes) } +/*! + Makes sure the \a point is within valid bounds. + Returns \c true if the relevant coordinate (depending on the orientation + of the slider) differs from \a comparePoint. +*/ bool -BSlider::_ConstrainPoint(BPoint point, BPoint comparePoint) const +BSlider::_ConstrainPoint(BPoint& point, BPoint comparePoint) const { if (fOrientation == B_HORIZONTAL) { if (point.x != comparePoint.x) { @@ -465,7 +476,8 @@ BSlider::MouseDown(BPoint point) _ConstrainPoint(point, fInitialLocation); SetValue(ValueForPoint(point)); - InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); + if (_Location() != fInitialLocation) + InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) { SetTracking(true); @@ -481,8 +493,11 @@ BSlider::MouseDown(BPoint point) GetMouse(&point, &buttons, true); if (_ConstrainPoint(point, prevPoint)) { - SetValue(ValueForPoint(point)); - InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); + int32 value = ValueForPoint(point); + if (value != Value()) { + SetValue(value); + InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); + } } } if (_Location() != fInitialLocation) @@ -509,8 +524,11 @@ BSlider::MouseMoved(BPoint point, uint32 transit, const BMessage *message) { if (IsTracking()) { if (_ConstrainPoint(point, _Location())) { - SetValue(ValueForPoint(point)); - InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); + int32 value = ValueForPoint(point); + if (value != Value()) { + SetValue(value); + InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); + } } } else BControl::MouseMoved(point, transit, message);