From 1cbca49a83413070679edb9c7b01dacdc63f6c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Wed, 15 Oct 2008 21:07:37 +0000 Subject: [PATCH] zooey + stippi: * Fix the calculation of the fTextRect member. The BeOS behavior (and also the previous Haiku behavior) was to recalculate the "bottom" always. This was not taken care of in SetTextRect() (needs to override the passed bottom). * The insets are already tracked in fLayoutData, use this in _UpdateScrollBars() to calculate the correct data width/height (an improvement over the BeOS behavior it seems). * Try to minimize the need to call _Refresh(), which reduces flickering a whole lot. * Fix several instances where fTextRect was recalculated based on Bounds() and the saved insets, where it was broken when the BTextView was scrolled. Fixes #2784. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28151 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/TextView.cpp | 55 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/src/kits/interface/TextView.cpp b/src/kits/interface/TextView.cpp index c2897d23f6..1f90c125db 100644 --- a/src/kits/interface/TextView.cpp +++ b/src/kits/interface/TextView.cpp @@ -2135,16 +2135,25 @@ BTextView::SetTextRect(BRect rect) { if (rect == fTextRect) return; - + + bool needsRefresh = fTextRect.left != rect.left + || fTextRect.right != rect.right || fTextRect.top != rect.top; + + fLayoutData->UpdateInsets(Bounds().OffsetToCopy(B_ORIGIN), rect); + + if (!needsRefresh) + rect.bottom = fTextRect.bottom; + fTextRect = rect; fMinTextRectWidth = fTextRect.Width(); // used in auto-resizing mode to keep the text rect from // shrinking below a certain value. - fLayoutData->UpdateInsets(Bounds(), fTextRect); - - if (Window() != NULL) - Invalidate(); + if (needsRefresh) { + // In BeOS, the text rect height is always adjusted to the text data + // height. Setting a narrower text rect will therefore enlarge the height. + _Refresh(0, TextLength(), true, false); + } } @@ -2186,7 +2195,7 @@ void BTextView::GetInsets(float* _left, float* _top, float* _right, float* _bottom) const { - BRect bounds = Bounds(); + BRect bounds = Bounds().OffsetToCopy(B_ORIGIN); if (_left) *_left = fTextRect.left - bounds.left; @@ -2707,24 +2716,12 @@ BTextView::DoLayout() size.height = fLayoutData->min.height; // layout text rect - BPoint previousLocation = fTextRect.LeftTop(); - float previousTextWidth = fTextRect.Width(); - - fTextRect = Bounds(); - fTextRect.left += fLayoutData->leftInset; - fTextRect.top += fLayoutData->topInset; - fTextRect.right -= fLayoutData->rightInset; - fTextRect.bottom -= fLayoutData->bottomInset; - - // recalculate linebreaks and invalidate if necessary - if (previousTextWidth != fTextRect.Width() - || previousLocation != fTextRect.LeftTop()) { - int32 startLine = 0; - int32 endLine = fLines->NumLines() - 1; - _RecalculateLineBreaks(&startLine, &endLine); - } - - Invalidate(); + BRect textRect = Bounds().OffsetToCopy(B_ORIGIN); + textRect.left += fLayoutData->leftInset; + textRect.top += fLayoutData->topInset; + textRect.right -= fLayoutData->rightInset; + textRect.bottom -= fLayoutData->bottomInset; + SetTextRect(textRect); } @@ -3130,7 +3127,7 @@ BTextView::_InitObject(BRect textRect, const BFont *initialFont, fTrackingMouse = NULL; fLayoutData = new LayoutData; - fLayoutData->UpdateInsets(Bounds(), fTextRect); + fLayoutData->UpdateInsets(Bounds().OffsetToCopy(B_ORIGIN), fTextRect); } @@ -4485,8 +4482,8 @@ BTextView::_UpdateScrollbars() // do we have a horizontal scroll bar? if (horizontalScrollBar != NULL) { long viewWidth = bounds.IntegerWidth(); - long dataWidth = fTextRect.IntegerWidth(); - dataWidth += (long)ceilf(fTextRect.left) + 1; + long dataWidth = (long)ceilf(fTextRect.IntegerWidth() + + fLayoutData->leftInset + fLayoutData->rightInset); long maxRange = dataWidth - viewWidth; maxRange = max_c(maxRange, 0); @@ -4499,8 +4496,8 @@ BTextView::_UpdateScrollbars() // how about a vertical scroll bar? if (verticalScrollBar != NULL) { long viewHeight = bounds.IntegerHeight(); - long dataHeight = fTextRect.IntegerHeight(); - dataHeight += (long)ceilf(fTextRect.top) + 1; + long dataHeight = (long)ceilf(fTextRect.IntegerHeight() + + fLayoutData->topInset + fLayoutData->bottomInset); long maxRange = dataHeight - viewHeight; maxRange = max_c(maxRange, 0);