Now the scrollbar works much more like the R5 scrollbar:

* prevents the target view from being scrolled out of range
 * handles Trackers completely confused usage of scrollbars

There is just one problem with Tracker's horizontal scrollbar
scrolling the title view much further than it should, which I
will look into tomorrow...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15457 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2005-12-09 23:27:35 +00:00
parent 4f9b08dffa
commit a04f5a1a5b
+75 -65
View File
@@ -237,57 +237,8 @@ BScrollBar::AttachedToWindow()
// R5's SB contacts the server if fValue!=0. I *think* we don't need to do anything here... // R5's SB contacts the server if fValue!=0. I *think* we don't need to do anything here...
} }
// SetValue
void
BScrollBar::SetValue(float value)
{
if (value > fMax)
value = fMax;
if (value < fMin)
value = fMin;
if (fValue != value) {
fValue = value;
ValueChanged(fValue);
}
}
// Value
float
BScrollBar::Value() const
{
return fValue;
}
// SetProportion
void
BScrollBar::SetProportion(float value)
{
if (value < 0.0)
value = 0.0;
if (value > 1.0)
value = 1.0;
if (value != fProportion) {
fProportion = value;
_UpdateThumbFrame();
}
}
// Proportion
float
BScrollBar::Proportion() const
{
return fProportion;
}
// ValueChanged
void
BScrollBar::ValueChanged(float newValue)
{
/* /*
From the BeBook: From the BeBook (on ValueChanged()):
Responds to a notification that the value of the scroll bar has changed to Responds to a notification that the value of the scroll bar has changed to
newValue. For a horizontal scroll bar, this function interprets newValue newValue. For a horizontal scroll bar, this function interprets newValue
@@ -316,6 +267,33 @@ if the target has been set by name, but the name doesn't correspond to
an actual BView within the scroll bar's window. an actual BView within the scroll bar's window.
*/ */
// SetValue
void
BScrollBar::SetValue(float value)
{
ValueChanged(value);
}
// Value
float
BScrollBar::Value() const
{
return fValue;
}
// ValueChanged
void
BScrollBar::ValueChanged(float newValue)
{
if (newValue > fMax)
newValue = fMax;
if (newValue < fMin)
newValue = fMin;
if (newValue == fValue)
return;
if (fTarget) { if (fTarget) {
// cache target bounds // cache target bounds
BRect targetBounds = fTarget->Bounds(); BRect targetBounds = fTarget->Bounds();
@@ -328,27 +306,59 @@ an actual BView within the scroll bar's window.
fTarget->ScrollTo(newValue, targetBounds.top); fTarget->ScrollTo(newValue, targetBounds.top);
} }
} }
fValue = newValue;
_UpdateThumbFrame(); _UpdateThumbFrame();
_UpdateArrowButtons(); _UpdateArrowButtons();
} }
// SetProportion
void
BScrollBar::SetProportion(float value)
{
/* if (value < 0.0)
value = 0.0;
if (value > 1.0)
value = 1.0;*/
if (value != fProportion) {
bool oldEnabled = fPrivateData->fEnabled && fMin < fMax && fProportion < 1.0 && fProportion >= 0.0;
fProportion = value;
bool newEnabled = fPrivateData->fEnabled && fMin < fMax && fProportion < 1.0 && fProportion >= 0.0;
_UpdateThumbFrame();
if (oldEnabled != newEnabled)
Invalidate();
}
}
// Proportion
float
BScrollBar::Proportion() const
{
return fProportion;
}
// SetRange // SetRange
void void
BScrollBar::SetRange(float min, float max) BScrollBar::SetRange(float min, float max)
{ {
if (fMin == min && fMax == max)
return;
fMin = min; fMin = min;
fMax = max; fMax = max;
if (fValue > fMax) if (fValue < fMin || fValue > fMax)
fValue = fMax; ValueChanged(fValue);
else if (fValue < fMin) else {
fValue = fMin; _UpdateThumbFrame();
Invalidate();
Invalidate(); }
// Just a sort-of hack for now. ValueChanged is called, but with
// what value??
ValueChanged(fValue);
} }
// GetRange // GetRange
@@ -534,7 +544,7 @@ BScrollBar::MouseUp(BPoint pt)
void void
BScrollBar::MouseMoved(BPoint where, uint32 transit, const BMessage* message) BScrollBar::MouseMoved(BPoint where, uint32 transit, const BMessage* message)
{ {
if (!fPrivateData->fEnabled || fMin >= fMax || fProportion >= 1.0) if (!fPrivateData->fEnabled || fMin >= fMax || fProportion >= 1.0 || fProportion < 0.0)
return; return;
if (fPrivateData->fButtonDown != NOARROW) { if (fPrivateData->fButtonDown != NOARROW) {
@@ -589,7 +599,7 @@ BScrollBar::Draw(BRect updateRect)
StrokeRect(bounds); StrokeRect(bounds);
bounds.InsetBy(1.0, 1.0); bounds.InsetBy(1.0, 1.0);
bool enabled = fPrivateData->fEnabled && fMin < fMax && fProportion < 1.0; bool enabled = fPrivateData->fEnabled && fMin < fMax && fProportion < 1.0 && fProportion >= 0.0;
rgb_color light, light1, dark, dark1, dark2, dark4; rgb_color light, light1, dark, dark1, dark2, dark4;
if (enabled) { if (enabled) {
@@ -822,7 +832,7 @@ BScrollBar::Draw(BRect updateRect)
// TODO: Add the other thumb styles - dots and lines // TODO: Add the other thumb styles - dots and lines
} else { } else {
if (fMin >= fMax || fProportion >= 1.0) { if (fMin >= fMax || fProportion >= 1.0 || fProportion < 0.0) {
// we cannot scroll at all // we cannot scroll at all
_DrawDisabledBackground(thumbBG, light, dark, dark1); _DrawDisabledBackground(thumbBG, light, dark, dark1);
} else { } else {
@@ -1016,7 +1026,7 @@ BScrollBar::_UpdateThumbFrame()
float thumbSize = minSize; float thumbSize = minSize;
float proportion = fProportion; float proportion = fProportion;
if (fMin == fMax) if (fMin == fMax || proportion > 1.0 || proportion < 0.0)
proportion = 1.0; proportion = 1.0;
if (fPrivateData->fScrollBarInfo.proportional) if (fPrivateData->fScrollBarInfo.proportional)
thumbSize += (maxSize - minSize) * proportion; thumbSize += (maxSize - minSize) * proportion;