From c9dcf7979ba66a535bfcb15065e9d8f3ccde1631 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Thu, 22 Nov 2007 10:53:53 +0000 Subject: [PATCH] BTextView::_ScrollToOffset() just didn't work correctly most of the times, since xdiff and ydiff didn't take the point returned by PointAt() into account. Thanks to Andrea Anzani for noticing this. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22977 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/TextView.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/kits/interface/TextView.cpp b/src/kits/interface/TextView.cpp index 52de606aab..4c8a477fc7 100644 --- a/src/kits/interface/TextView.cpp +++ b/src/kits/interface/TextView.cpp @@ -1909,6 +1909,7 @@ BTextView::ScrollToOffset(int32 inOffset) _ScrollToOffset(inOffset, ScrollBar(B_HORIZONTAL) != NULL, ScrollBar(B_VERTICAL) != NULL); } + void BTextView::_ScrollToOffset(int32 inOffset, bool useHorz, bool useVert) { @@ -1917,25 +1918,19 @@ BTextView::_ScrollToOffset(int32 inOffset, bool useHorz, bool useVert) float xdiff = 0.0; float ydiff = 0.0; BPoint point = PointAt(inOffset, &lineHeight); - + if (useHorz) { - if (point.x < bounds.left) { - xdiff = -1 * (bounds.IntegerWidth() / 2); - // normalize scroll value to prevent scrolling past left boundary of view - if (bounds.left < fabs(xdiff)) - xdiff = -1 * bounds.left; - } else if (point.x >= bounds.right) - xdiff = bounds.IntegerWidth() / 2; + if (point.x < bounds.left) + xdiff = point.x - bounds.left - bounds.IntegerWidth() / 2; + else if (point.x >= bounds.right) + xdiff = point.x - bounds.right + bounds.IntegerWidth() / 2; } if (useVert) { - if (point.y < bounds.top) { - ydiff = -1 * (bounds.IntegerHeight() / 2); - // normalize scroll value to prevent scrolling past top of view - if (bounds.top < fabs(ydiff)) - ydiff = -1 * bounds.top; - } else if (point.y >= bounds.bottom) - ydiff = bounds.IntegerHeight() / 2; + if (point.y < bounds.top) + ydiff = point.y - bounds.top - bounds.IntegerHeight() / 2; + else if (point.y >= bounds.bottom) + ydiff = point.y - bounds.bottom + bounds.IntegerHeight() / 2; } ScrollBy(xdiff, ydiff);