Fix more regressions in _AutoResize() visible when renaming a file in Tracker

(reported by Axel):
* _AutoResize() can no longer check the difference between the textrect and
  the maximum line width, as the textrect is no being adjusted earlier during
  the line-calculation code - instead, it needs to measure the difference
  between the bounds and the textrect width plus the insets.
* MakeResizable(true) needs to reset the right inset, as otherwise the auto-
  resizing would get confused about how large the textview needs to be
  (seems to be an artefact of how Tracker creates the textview).
* GetInsets() doesn't need to compute the insets, as they're maintained in
  fLayoutData.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33813 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe
2009-10-28 17:39:02 +00:00
parent 1aa885efee
commit 4b0f176d9c
+26 -17
View File
@@ -140,10 +140,20 @@ struct BTextView::LayoutData {
void UpdateInsets(const BRect& bounds, const BRect& textRect) void UpdateInsets(const BRect& bounds, const BRect& textRect)
{ {
leftInset = textRect.left - bounds.left; // we disallow negative insets, as they would cause parts of the
topInset = textRect.top - bounds.top; // text to be hidden
rightInset = bounds.right - textRect.right; leftInset = textRect.left >= bounds.left
bottomInset = bounds.bottom - textRect.bottom; ? textRect.left - bounds.left
: 0;
topInset = textRect.top >= bounds.top
? textRect.top - bounds.top
: 0;
rightInset = bounds.right >= textRect.right
? bounds.right - textRect.right
: leftInset;
bottomInset = bounds.bottom >= textRect.bottom
? bounds.bottom - textRect.bottom
: topInset;
} }
float leftInset; float leftInset;
@@ -2235,16 +2245,14 @@ void
BTextView::GetInsets(float* _left, float* _top, float* _right, BTextView::GetInsets(float* _left, float* _top, float* _right,
float* _bottom) const float* _bottom) const
{ {
BRect bounds = Bounds().OffsetToCopy(B_ORIGIN);
if (_left) if (_left)
*_left = fTextRect.left - bounds.left; *_left = fLayoutData->leftInset;
if (_top) if (_top)
*_top = fTextRect.top - bounds.top; *_top = fLayoutData->topInset;
if (_right) if (_right)
*_right = bounds.right - fTextRect.right; *_right = fLayoutData->rightInset;
if (_bottom) if (_bottom)
*_bottom = bounds.bottom - fTextRect.bottom; *_bottom = fLayoutData->bottomInset;
} }
@@ -2570,6 +2578,11 @@ BTextView::MakeResizable(bool resize, BView *resizeView)
_HideCaret(); _HideCaret();
} }
} }
// We need to reset the right inset, as otherwise the auto-resize would
// get confused about just how wide the textview needs to be.
// This seems to be an artefact of how Tracker creates the textview
// during a rename action.
fLayoutData->rightInset = fLayoutData->leftInset;
} else { } else {
fResizable = false; fResizable = false;
fContainerView = NULL; fContainerView = NULL;
@@ -4881,12 +4894,9 @@ BTextView::_AutoResize(bool redraw)
return; return;
BRect bounds = Bounds(); BRect bounds = Bounds();
float oldWidth = fTextRect.Width(); float oldWidth = bounds.Width();
float minWidth = fContainerView != NULL ? 3.0 : fMinTextRectWidth; float newWidth = ceilf(fLayoutData->leftInset + fTextRect.Width()
float newWidth = max_c(minWidth, ceilf(fLines->MaxWidth())); + fLayoutData->rightInset);
if (newWidth == oldWidth)
return;
if (fContainerView != NULL) { if (fContainerView != NULL) {
// NOTE: This container view thing is only used by Tracker. // NOTE: This container view thing is only used by Tracker.
@@ -4902,7 +4912,6 @@ BTextView::_AutoResize(bool redraw)
fContainerView->ResizeBy(ceilf(newWidth - oldWidth), 0); fContainerView->ResizeBy(ceilf(newWidth - oldWidth), 0);
} }
fTextRect.right = fTextRect.left + newWidth;
if (redraw) if (redraw)
_RequestDrawLines(0, 0); _RequestDrawLines(0, 0);