From 1158eeac58dd189fafad3289e463f6a43b21b550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 6 Apr 2008 16:47:43 +0000 Subject: [PATCH] According to my tests on R5, a BScrollBar with a proportion of 0.0, the value that it has when you never set it, uses the large step to figure out the proportion it should display. This fixes Pe's scroll bars to display the "correct" proportion. Of course the proportion is only correct if the large step indeed equals the page size. Fixes #1758. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24838 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/ScrollBar.cpp | 45 +++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/kits/interface/ScrollBar.cpp b/src/kits/interface/ScrollBar.cpp index 2ae7c4ec10..7e0d7631ad 100644 --- a/src/kits/interface/ScrollBar.cpp +++ b/src/kits/interface/ScrollBar.cpp @@ -21,7 +21,7 @@ #include #include -//#define TRACE_SCROLLBAR +#define TRACE_SCROLLBAR #ifdef TRACE_SCROLLBAR # define TRACE(x...) printf(x) #else @@ -445,15 +445,33 @@ BScrollBar::GetRange(float *min, float *max) const void BScrollBar::SetSteps(float smallStep, float largeStep) { - // Under R5, steps can be set only after being attached to a window, probably because - // the data is kept server-side. We'll just remove that limitation... :P + TRACE("BScrollBar(%s)::SetSteps(small=%.1f, large=%.1f)\n", Name(), + smallStep, largeStep); - // 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 - fSmallStep = roundf(smallStep); - fLargeStep = roundf(largeStep); + // Under R5, steps can be set only after being attached to a window, + // probably because the data is kept server-side. We'll just remove + // that limitation... :P - // TODO: test use of fractional values and make them work properly if they don't + // 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 + smallStep = roundf(smallStep); + largeStep = roundf(largeStep); + if (fSmallStep == smallStep && fLargeStep == largeStep) + return; + + fSmallStep = smallStep; + fLargeStep = largeStep; + + if (fProportion == 0.0) { + // special case, proportion is based on fLargeStep if it was never + // set, so it means we need to invalidate here + _UpdateThumbFrame(); + Invalidate(); + } + + // TODO: test use of fractional values and make them work properly if + // they don't } // GetSteps @@ -1123,8 +1141,17 @@ BScrollBar::_UpdateThumbFrame() float thumbSize = minSize; float proportion = fProportion; - if (fMin == fMax || proportion > 1.0 || proportion < 0.0) + if (fMin >= fMax || proportion > 1.0 || proportion < 0.0) proportion = 1.0; + if (proportion == 0.0) { + // Special case a proportion of 0.0, use the large step value + // in that case (NOTE: fMin == fMax already handled above) + // This calculation is based on the assumption that "large step" + // scrolls by one "page size". + proportion = fLargeStep / (2 * (fMax - fMin)); + if (proportion > 1.0) + proportion = 1.0; + } if (fPrivateData->fScrollBarInfo.proportional) thumbSize += (maxSize - minSize) * proportion; thumbSize = floorf(thumbSize + 0.5);