Moved scroll implementation from ScrollBy into ScrollTo and made ScrollBy simply wrap a call to the former. This

guarantees that the virtual hook is called in all cases, and fixes bugs 1252 and 1838.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25559 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Rene Gollent 2008-05-19 00:16:49 +00:00
parent a69e04b96e
commit 087592136a

View File

@ -1491,13 +1491,20 @@ BView::ScrollBar(orientation posture) const
void void
BView::ScrollBy(float deltaX, float deltaY) BView::ScrollBy(float deltaX, float deltaY)
{
ScrollTo(BPoint(fBounds.left + deltaX, fBounds.top + deltaY));
}
void
BView::ScrollTo(BPoint where)
{ {
// scrolling by fractional values is not supported // scrolling by fractional values is not supported
deltaX = roundf(deltaX); where.x = roundf(where.x);
deltaY = roundf(deltaY); where.y = roundf(where.y);
// no reason to process this further if no scroll is intended. // no reason to process this further if no scroll is intended.
if (deltaX == 0 && deltaY == 0) if (where.x == fBounds.left && where.y == fBounds.top)
return; return;
// make sure scrolling is within valid bounds // make sure scrolling is within valid bounds
@ -1505,19 +1512,19 @@ BView::ScrollBy(float deltaX, float deltaY)
float min, max; float min, max;
fHorScroller->GetRange(&min, &max); fHorScroller->GetRange(&min, &max);
if (deltaX + fBounds.left < min) if (where.x < min)
deltaX = min - fBounds.left; where.x = min;
else if (deltaX + fBounds.left > max) else if (where.x > max)
deltaX = max - fBounds.left; where.x = max;
} }
if (fVerScroller) { if (fVerScroller) {
float min, max; float min, max;
fVerScroller->GetRange(&min, &max); fVerScroller->GetRange(&min, &max);
if (deltaY + fBounds.top < min) if (where.y < min)
deltaY = min - fBounds.top; where.y = min;
else if (deltaY + fBounds.top > max) else if (where.y > max)
deltaY = max - fBounds.top; where.y = max;
} }
_CheckLockAndSwitchCurrent(); _CheckLockAndSwitchCurrent();
@ -1525,8 +1532,8 @@ BView::ScrollBy(float deltaX, float deltaY)
// if we're attached to a window tell app_server about this change // if we're attached to a window tell app_server about this change
if (fOwner) { if (fOwner) {
fOwner->fLink->StartMessage(AS_VIEW_SCROLL); fOwner->fLink->StartMessage(AS_VIEW_SCROLL);
fOwner->fLink->Attach<float>(deltaX); fOwner->fLink->Attach<float>(where.x - fBounds.left);
fOwner->fLink->Attach<float>(deltaY); fOwner->fLink->Attach<float>(where.y - fBounds.top);
fOwner->fLink->Flush(); fOwner->fLink->Flush();
@ -1534,20 +1541,14 @@ BView::ScrollBy(float deltaX, float deltaY)
} }
// we modify our bounds rectangle by deltaX/deltaY coord units hor/ver. // we modify our bounds rectangle by deltaX/deltaY coord units hor/ver.
fBounds.OffsetBy(deltaX, deltaY); fBounds.OffsetTo(where.x, where.y);
// then set the new values of the scrollbars // then set the new values of the scrollbars
if (fHorScroller && deltaX != 0.0) if (fHorScroller)
fHorScroller->SetValue(fBounds.left); fHorScroller->SetValue(fBounds.left);
if (fVerScroller && deltaY != 0.0) if (fVerScroller)
fVerScroller->SetValue(fBounds.top); fVerScroller->SetValue(fBounds.top);
}
void
BView::ScrollTo(BPoint where)
{
ScrollBy(where.x - fBounds.left, where.y - fBounds.top);
} }