* avoid endless loop in some cases concerning scrolling with fractional coords

* detect invalid params to SetRange()


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17675 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2006-05-31 19:21:16 +00:00
parent 95f766fa3e
commit 25f03a7bd8

View File

@ -299,12 +299,12 @@ BScrollBar::SetValue(float value)
if (value < fMin) if (value < fMin)
value = fMin; value = fMin;
fValue = value; fValue = roundf(value);
_UpdateThumbFrame(); _UpdateThumbFrame();
_UpdateArrowButtons(); _UpdateArrowButtons();
ValueChanged(value); ValueChanged(fValue);
} }
// Value // Value
@ -323,11 +323,11 @@ BScrollBar::ValueChanged(float newValue)
BRect targetBounds = fTarget->Bounds(); BRect targetBounds = fTarget->Bounds();
// if vertical, check bounds top and scroll if different from newValue // if vertical, check bounds top and scroll if different from newValue
if (fOrientation == B_VERTICAL && targetBounds.top != newValue) { if (fOrientation == B_VERTICAL && targetBounds.top != newValue) {
fTarget->ScrollTo(targetBounds.left, newValue); fTarget->ScrollBy(0.0, newValue - targetBounds.top);
} }
// if horizontal, check bounds left and scroll if different from newValue // if horizontal, check bounds left and scroll if different from newValue
if (fOrientation == B_HORIZONTAL && targetBounds.left != newValue) { if (fOrientation == B_HORIZONTAL && targetBounds.left != newValue) {
fTarget->ScrollTo(newValue, targetBounds.top); fTarget->ScrollBy(newValue - targetBounds.left, 0.0);
} }
} }
@ -371,6 +371,14 @@ BScrollBar::Proportion() const
void void
BScrollBar::SetRange(float min, float max) BScrollBar::SetRange(float min, float max)
{ {
if (min > max || isnanf(min) || isnanf(max) || isinff(min) || isinff(max)) {
min = 0;
max = 0;
}
min = roundf(min);
max = roundf(max);
if (fMin == min && fMax == max) if (fMin == min && fMax == max)
return; return;
@ -378,7 +386,7 @@ BScrollBar::SetRange(float min, float max)
fMax = max; fMax = max;
if (fValue < fMin || fValue > fMax) if (fValue < fMin || fValue > fMax)
ValueChanged(fValue); SetValue(fValue);
else { else {
_UpdateThumbFrame(); _UpdateThumbFrame();
Invalidate(); Invalidate();
@ -404,15 +412,15 @@ BScrollBar::SetSteps(float smallStep, float largeStep)
// The BeBook also says that we need to specify an integer value even though the step // The BeBook also says that we need to specify an integer value even though the step
// values are floats. For the moment, we'll just make sure that they are integers // values are floats. For the moment, we'll just make sure that they are integers
fSmallStep = (int32)smallStep; fSmallStep = roundf(smallStep);
fLargeStep = (int32)largeStep; fLargeStep = roundf(largeStep);
// TODO: test use of fractional values and make them work properly if they don't // TODO: test use of fractional values and make them work properly if they don't
} }
// GetSteps // GetSteps
void void
BScrollBar::GetSteps(float *smallStep, float *largeStep) const BScrollBar::GetSteps(float* smallStep, float* largeStep) const
{ {
if (smallStep) if (smallStep)
*smallStep = fSmallStep; *smallStep = fSmallStep;
@ -543,8 +551,9 @@ BScrollBar::MouseDown(BPoint where)
fPrivateData->fExitRepeater = false; fPrivateData->fExitRepeater = false;
fPrivateData->fThumbInc = scrollValue; fPrivateData->fThumbInc = scrollValue;
fPrivateData->fDoRepeat = true; fPrivateData->fDoRepeat = true;
fPrivateData->fRepeaterThread = spawn_thread(fPrivateData->button_repeater_thread, fPrivateData->fRepeaterThread
"scroll repeater", B_NORMAL_PRIORITY, fPrivateData); = spawn_thread(fPrivateData->button_repeater_thread,
"scroll repeater", B_NORMAL_PRIORITY, fPrivateData);
resume_thread(fPrivateData->fRepeaterThread); resume_thread(fPrivateData->fRepeaterThread);
} }
} }