Revert "IK: align BTextView text rect/fix alignment"

This reverts commit a9b301871d.

hrev54496

Change-Id: Ife3c834ad98d330f04976d9adf3b1553e7aca034
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3153
Reviewed-by: Axel Dörfler <[email protected]>
This commit is contained in:
John Scipione
2020-08-19 03:38:41 +00:00
parent 90f9b5590f
commit 22758f1690
9 changed files with 175 additions and 251 deletions
+1 -1
View File
@@ -136,7 +136,7 @@ class Haiku(callbacks.Plugin):
to = None to = None
if len(args) > 0: if len(args) > 0:
to = args[0] to = args[0]
t = "Current release: http://www.haiku-os.org/get-haiku - Nightly builds: http://download.haiku-os.org" t = "Current release: http://www.haiku-os.org/get-haiku - Nightly builds: http://haiku-files.org/haiku/development/"
irc.reply(t, to = to) irc.reply(t, to = to)
def dl(self, irc, msg, args): def dl(self, irc, msg, args):
+2 -3
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2007-2020 Haiku, Inc. All rights reserved. * Copyright 2007-2009, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _TEXTVIEW_H #ifndef _TEXTVIEW_H
@@ -416,7 +416,6 @@ private:
LineBuffer* fLines; LineBuffer* fLines;
StyleBuffer* fStyles; StyleBuffer* fStyles;
BRect fTextRect; BRect fTextRect;
BRect fAlignedTextRect;
int32 fSelStart; int32 fSelStart;
int32 fSelEnd; int32 fSelEnd;
bool fCaretVisible; bool fCaretVisible;
@@ -464,7 +463,7 @@ private:
bool fInstalledRemoveCommandWordwiseShortcuts : 1; bool fInstalledRemoveCommandWordwiseShortcuts : 1;
bool fInstalledRemoveOptionWordwiseShortcuts : 1; bool fInstalledRemoveOptionWordwiseShortcuts : 1;
uint32 _reserved[2]; uint32 _reserved[6];
}; };
#endif // _TEXTVIEW_H #endif // _TEXTVIEW_H
+4 -3
View File
@@ -1,12 +1,11 @@
/* /*
* Copyright 2001-2020 Haiku Inc. All rights reserved. * Copyright 2001-2015, Haiku Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Frans van Nispen (xlr8@tref.nl) * Frans van Nispen (xlr8@tref.nl)
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Ingo Weinhold <bonefish@cs.tu-berlin.de> * Ingo Weinhold <bonefish@cs.tu-berlin.de>
* John Scipione <jscipione@gmail.com>
*/ */
@@ -638,6 +637,7 @@ void
BTextControl::SetAlignment(alignment labelAlignment, alignment textAlignment) BTextControl::SetAlignment(alignment labelAlignment, alignment textAlignment)
{ {
fText->SetAlignment(textAlignment); fText->SetAlignment(textAlignment);
fText->AlignTextRect();
if (fLabelAlign != labelAlignment) { if (fLabelAlign != labelAlignment) {
fLabelAlign = labelAlignment; fLabelAlign = labelAlignment;
@@ -911,7 +911,6 @@ BTextControl::DoLayout()
// place the text view and set the divider // place the text view and set the divider
textFrame.InsetBy(kFrameMargin, kFrameMargin); textFrame.InsetBy(kFrameMargin, kFrameMargin);
BLayoutUtils::AlignInFrame(fText, textFrame); BLayoutUtils::AlignInFrame(fText, textFrame);
fText->SetTextRect(textFrame.OffsetToCopy(B_ORIGIN));
fDivider = divider; fDivider = divider;
@@ -1116,6 +1115,7 @@ BTextControl::_InitText(const char* initialText, const BMessage* archive)
SetText(initialText); SetText(initialText);
fText->SetAlignment(B_ALIGN_LEFT); fText->SetAlignment(B_ALIGN_LEFT);
fText->AlignTextRect();
} }
// Although this is not strictly initializing the text view, // Although this is not strictly initializing the text view,
@@ -1171,6 +1171,7 @@ BTextControl::_LayoutTextView()
frame.InsetBy(kFrameMargin, kFrameMargin); frame.InsetBy(kFrameMargin, kFrameMargin);
fText->MoveTo(frame.left, frame.top); fText->MoveTo(frame.left, frame.top);
fText->ResizeTo(frame.Width(), frame.Height()); fText->ResizeTo(frame.Width(), frame.Height());
fText->AlignTextRect();
TRACE("width: %.2f, height: %.2f\n", Frame().Width(), Frame().Height()); TRACE("width: %.2f, height: %.2f\n", Frame().Width(), Frame().Height());
TRACE("fDivider: %.2f\n", fDivider); TRACE("fDivider: %.2f\n", fDivider);
+40 -2
View File
@@ -1,11 +1,10 @@
/* /*
* Copyright 2001-2020 Haiku Inc. All rights reserved. * Copyright 2001-2015, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Frans van Nispen (xlr8@tref.nl) * Frans van Nispen (xlr8@tref.nl)
* Marc Flerackers (mflerackers@androme.be) * Marc Flerackers (mflerackers@androme.be)
* John Scipione (jscipione@gmail.com)
*/ */
@@ -15,6 +14,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ControlLook.h>
#include <InterfaceDefs.h> #include <InterfaceDefs.h>
#include <LayoutUtils.h> #include <LayoutUtils.h>
#include <Message.h> #include <Message.h>
@@ -84,6 +84,8 @@ void
_BTextInput_::FrameResized(float width, float height) _BTextInput_::FrameResized(float width, float height)
{ {
BTextView::FrameResized(width, height); BTextView::FrameResized(width, height);
AlignTextRect();
} }
@@ -160,6 +162,42 @@ _BTextInput_::MinSize()
} }
void
_BTextInput_::AlignTextRect()
{
// the label font could require the control to be higher than
// necessary for the text view, we compensate this by layouting
// the text rect to be in the middle, normally this means there
// is one pixel spacing on each side
BRect textRect(Bounds());
float vInset = max_c(1,
floorf((textRect.Height() - LineHeight(0)) / 2.0));
float hInset = 2;
float textFontWidth = TextRect().right;
switch (Alignment()) {
case B_ALIGN_LEFT:
hInset = be_control_look->DefaultLabelSpacing();
break;
case B_ALIGN_RIGHT:
hInset = textRect.right - textFontWidth;
hInset -= be_control_look->DefaultLabelSpacing();
break;
case B_ALIGN_CENTER:
hInset = (textRect.right - textFontWidth) / 2.0;
break;
default:
break;
}
textRect.InsetBy(hInset, vInset);
SetTextRect(textRect);
}
void void
_BTextInput_::SetInitialText() _BTextInput_::SetInitialText()
{ {
+2 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2020 Haiku Inc. All rights reserved. * Copyright 2001-2008, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -11,7 +11,6 @@
#ifndef _TEXT_CONTROLI_H #ifndef _TEXT_CONTROLI_H
#define _TEXT_CONTROLI_H #define _TEXT_CONTROLI_H
#include <TextView.h> #include <TextView.h>
@@ -37,6 +36,7 @@ virtual void MakeFocus(bool focusState = true);
virtual BSize MinSize(); virtual BSize MinSize();
void AlignTextRect();
void SetInitialText(); void SetInitialText();
virtual void Paste(BClipboard *clipboard); virtual void Paste(BClipboard *clipboard);
+124 -238
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2020 Haiku, Inc. All rights reserved. * Copyright 2001-2015 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -25,7 +25,6 @@
#include <TextView.h> #include <TextView.h>
#include <algorithm>
#include <new> #include <new>
#include <stdio.h> #include <stdio.h>
@@ -35,7 +34,6 @@
#include <Beep.h> #include <Beep.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Clipboard.h> #include <Clipboard.h>
#include <ControlLook.h>
#include <Debug.h> #include <Debug.h>
#include <Entry.h> #include <Entry.h>
#include <Input.h> #include <Input.h>
@@ -157,17 +155,12 @@ struct BTextView::LayoutData {
topInset(0), topInset(0),
rightInset(0), rightInset(0),
bottomInset(0), bottomInset(0),
valid(false), valid(false)
overridden(false)
{ {
} }
void UpdateInsets(const BRect& bounds, const BRect& textRect) void UpdateInsets(const BRect& bounds, const BRect& textRect)
{ {
// do not update insets if SetInsets() was called
if (overridden)
return;
// we disallow negative insets, as they would cause parts of the // we disallow negative insets, as they would cause parts of the
// text to be hidden // text to be hidden
leftInset = textRect.left >= bounds.left leftInset = textRect.left >= bounds.left
@@ -191,8 +184,7 @@ struct BTextView::LayoutData {
BSize min; BSize min;
BSize preferred; BSize preferred;
bool valid : 1; bool valid;
bool overridden : 1;
}; };
@@ -268,15 +260,7 @@ BTextView::BTextView(BRect frame, const char* name, BRect textRect,
uint32 resizeMask, uint32 flags) uint32 resizeMask, uint32 flags)
: :
BView(frame, name, resizeMask, BView(frame, name, resizeMask,
flags | B_FRAME_EVENTS | B_PULSE_NEEDED | B_INPUT_METHOD_AWARE), flags | B_FRAME_EVENTS | B_PULSE_NEEDED | B_INPUT_METHOD_AWARE)
fText(NULL),
fLines(NULL),
fStyles(NULL),
fDisallowedChars(NULL),
fUndo(NULL),
fDragRunner(NULL),
fClickRunner(NULL),
fLayoutData(NULL)
{ {
_InitObject(textRect, NULL, NULL); _InitObject(textRect, NULL, NULL);
SetViewUIColor(B_DOCUMENT_BACKGROUND_COLOR); SetViewUIColor(B_DOCUMENT_BACKGROUND_COLOR);
@@ -288,15 +272,7 @@ BTextView::BTextView(BRect frame, const char* name, BRect textRect,
uint32 resizeMask, uint32 flags) uint32 resizeMask, uint32 flags)
: :
BView(frame, name, resizeMask, BView(frame, name, resizeMask,
flags | B_FRAME_EVENTS | B_PULSE_NEEDED | B_INPUT_METHOD_AWARE), flags | B_FRAME_EVENTS | B_PULSE_NEEDED | B_INPUT_METHOD_AWARE)
fText(NULL),
fLines(NULL),
fStyles(NULL),
fDisallowedChars(NULL),
fUndo(NULL),
fDragRunner(NULL),
fClickRunner(NULL),
fLayoutData(NULL)
{ {
_InitObject(textRect, initialFont, initialColor); _InitObject(textRect, initialFont, initialColor);
SetViewUIColor(B_DOCUMENT_BACKGROUND_COLOR); SetViewUIColor(B_DOCUMENT_BACKGROUND_COLOR);
@@ -306,15 +282,7 @@ BTextView::BTextView(BRect frame, const char* name, BRect textRect,
BTextView::BTextView(const char* name, uint32 flags) BTextView::BTextView(const char* name, uint32 flags)
: :
BView(name, BView(name,
flags | B_FRAME_EVENTS | B_PULSE_NEEDED | B_INPUT_METHOD_AWARE), flags | B_FRAME_EVENTS | B_PULSE_NEEDED | B_INPUT_METHOD_AWARE)
fText(NULL),
fLines(NULL),
fStyles(NULL),
fDisallowedChars(NULL),
fUndo(NULL),
fDragRunner(NULL),
fClickRunner(NULL),
fLayoutData(NULL)
{ {
_InitObject(Bounds(), NULL, NULL); _InitObject(Bounds(), NULL, NULL);
SetViewUIColor(B_DOCUMENT_BACKGROUND_COLOR); SetViewUIColor(B_DOCUMENT_BACKGROUND_COLOR);
@@ -325,15 +293,7 @@ BTextView::BTextView(const char* name, const BFont* initialFont,
const rgb_color* initialColor, uint32 flags) const rgb_color* initialColor, uint32 flags)
: :
BView(name, BView(name,
flags | B_FRAME_EVENTS | B_PULSE_NEEDED | B_INPUT_METHOD_AWARE), flags | B_FRAME_EVENTS | B_PULSE_NEEDED | B_INPUT_METHOD_AWARE)
fText(NULL),
fLines(NULL),
fStyles(NULL),
fDisallowedChars(NULL),
fUndo(NULL),
fDragRunner(NULL),
fClickRunner(NULL),
fLayoutData(NULL)
{ {
_InitObject(Bounds(), initialFont, initialColor); _InitObject(Bounds(), initialFont, initialColor);
SetViewUIColor(B_DOCUMENT_BACKGROUND_COLOR); SetViewUIColor(B_DOCUMENT_BACKGROUND_COLOR);
@@ -342,15 +302,7 @@ BTextView::BTextView(const char* name, const BFont* initialFont,
BTextView::BTextView(BMessage* archive) BTextView::BTextView(BMessage* archive)
: :
BView(archive), BView(archive)
fText(NULL),
fLines(NULL),
fStyles(NULL),
fDisallowedChars(NULL),
fUndo(NULL),
fDragRunner(NULL),
fClickRunner(NULL),
fLayoutData(NULL)
{ {
CALLED(); CALLED();
BRect rect; BRect rect;
@@ -442,8 +394,8 @@ BTextView::~BTextView()
delete fStyles; delete fStyles;
delete fDisallowedChars; delete fDisallowedChars;
delete fUndo; delete fUndo;
delete fDragRunner;
delete fClickRunner; delete fClickRunner;
delete fDragRunner;
delete fLayoutData; delete fLayoutData;
} }
@@ -1154,6 +1106,7 @@ BTextView::SetText(const char* text, int32 length, const text_run_array* runs)
// recalculate line breaks and draw the text // recalculate line breaks and draw the text
_Refresh(0, length, false); _Refresh(0, length, false);
fCaretOffset = fSelStart = fSelEnd = 0; fCaretOffset = fSelStart = fSelEnd = 0;
ScrollTo(B_ORIGIN);
// draw the caret // draw the caret
_ShowCaret(); _ShowCaret();
@@ -1728,7 +1681,6 @@ BTextView::LineAt(int32 offset) const
int32 lineNum = _LineAt(offset); int32 lineNum = _LineAt(offset);
if (_IsOnEmptyLastLine(offset)) if (_IsOnEmptyLastLine(offset))
lineNum++; lineNum++;
return lineNum; return lineNum;
} }
@@ -1737,7 +1689,7 @@ int32
BTextView::LineAt(BPoint point) const BTextView::LineAt(BPoint point) const
{ {
int32 lineNum = _LineAt(point); int32 lineNum = _LineAt(point);
if ((*fLines)[lineNum + 1]->origin <= point.y - fAlignedTextRect.top) if ((*fLines)[lineNum + 1]->origin <= point.y - fTextRect.top)
lineNum++; lineNum++;
return lineNum; return lineNum;
@@ -1760,7 +1712,7 @@ BTextView::PointAt(int32 offset, float* _height) const
BPoint result; BPoint result;
result.x = 0.0; result.x = 0.0;
result.y = line->origin + fAlignedTextRect.top; result.y = line->origin + fTextRect.top;
bool onEmptyLastLine = _IsOnEmptyLastLine(offset); bool onEmptyLastLine = _IsOnEmptyLastLine(offset);
@@ -1786,14 +1738,14 @@ BTextView::PointAt(int32 offset, float* _height) const
if (fAlignment != B_ALIGN_LEFT) { if (fAlignment != B_ALIGN_LEFT) {
float lineWidth = onEmptyLastLine ? 0.0 : LineWidth(lineNum); float lineWidth = onEmptyLastLine ? 0.0 : LineWidth(lineNum);
float alignmentOffset = fAlignedTextRect.Width() - lineWidth; float alignmentOffset = fTextRect.Width() - lineWidth;
if (fAlignment == B_ALIGN_CENTER) if (fAlignment == B_ALIGN_CENTER)
alignmentOffset = floorf(alignmentOffset / 2); alignmentOffset /= 2;
result.x += alignmentOffset; result.x += alignmentOffset;
} }
// convert from text rect coordinates // convert from text rect coordinates
result.x += fAlignedTextRect.left; result.x += fTextRect.left;
// round up // round up
result.x = lroundf(result.x); result.x = lroundf(result.x);
@@ -1811,9 +1763,9 @@ BTextView::OffsetAt(BPoint point) const
const int32 textLength = fText->Length(); const int32 textLength = fText->Length();
// should we even bother? // should we even bother?
if (point.y >= fAlignedTextRect.bottom) if (point.y >= fTextRect.bottom)
return textLength; return textLength;
else if (point.y < fAlignedTextRect.top) else if (point.y < fTextRect.top)
return 0; return 0;
int32 lineNum = _LineAt(point); int32 lineNum = _LineAt(point);
@@ -1827,22 +1779,21 @@ BTextView::OffsetAt(BPoint point) const
// lower than the bottom of the last line, return the last offset // lower than the bottom of the last line, return the last offset
// (can happen for newlines) // (can happen for newlines)
if (lineNum == (fLines->NumLines() - 1)) { if (lineNum == (fLines->NumLines() - 1)) {
if (point.y >= ((line + 1)->origin + fAlignedTextRect.top)) if (point.y >= ((line + 1)->origin + fTextRect.top))
return textLength; return textLength;
} }
#endif #endif
// convert to text rect coordinates // convert to text rect coordinates
if (fAlignment != B_ALIGN_LEFT) { if (fAlignment != B_ALIGN_LEFT) {
float alignmentOffset = fAlignedTextRect.Width() float alignmentOffset = fTextRect.Width() - LineWidth(lineNum);
- LineWidth(lineNum);
if (fAlignment == B_ALIGN_CENTER) if (fAlignment == B_ALIGN_CENTER)
alignmentOffset = floorf(alignmentOffset / 2); alignmentOffset /= 2;
point.x -= alignmentOffset; point.x -= alignmentOffset;
} }
point.x -= fAlignedTextRect.left; point.x -= fTextRect.left;
point.x = std::max(point.x, 0.0f); point.x = max_c(point.x, 0.0);
// ToDo: The following code isn't very efficient, because it always starts // ToDo: The following code isn't very efficient, because it always starts
// from the left end, so when the point is near the right end it's very // from the left end, so when the point is near the right end it's very
@@ -2069,7 +2020,6 @@ BTextView::GetTextRegion(int32 startOffset, int32 endOffset,
startOffset = 0; startOffset = 0;
else if (startOffset > fText->Length()) else if (startOffset > fText->Length())
startOffset = fText->Length(); startOffset = fText->Length();
if (endOffset < 0) if (endOffset < 0)
endOffset = 0; endOffset = 0;
else if (endOffset > fText->Length()) else if (endOffset > fText->Length())
@@ -2091,29 +2041,29 @@ BTextView::GetTextRegion(int32 startOffset, int32 endOffset,
if (startPt.y == endPt.y) { if (startPt.y == endPt.y) {
// this is a one-line region // this is a one-line region
selRect.left = std::max(startPt.x, fAlignedTextRect.left); selRect.left = max_c(startPt.x, fTextRect.left);
selRect.top = startPt.y; selRect.top = startPt.y;
selRect.right = endPt.x - 1.0; selRect.right = endPt.x - 1.0;
selRect.bottom = endPt.y + endLineHeight - 1.0; selRect.bottom = endPt.y + endLineHeight - 1.0;
outRegion->Include(selRect); outRegion->Include(selRect);
} else { } else {
// more than one line in the specified offset range // more than one line in the specified offset range
selRect.left = std::max(startPt.x, fAlignedTextRect.left); selRect.left = max_c(startPt.x, fTextRect.left);
selRect.top = startPt.y; selRect.top = startPt.y;
selRect.right = fAlignedTextRect.right; selRect.right = fTextRect.right;
selRect.bottom = startPt.y + startLineHeight - 1.0; selRect.bottom = startPt.y + startLineHeight - 1.0;
outRegion->Include(selRect); outRegion->Include(selRect);
if (startPt.y + startLineHeight < endPt.y) { if (startPt.y + startLineHeight < endPt.y) {
// more than two lines in the range // more than two lines in the range
selRect.left = fAlignedTextRect.left; selRect.left = fTextRect.left;
selRect.top = startPt.y + startLineHeight; selRect.top = startPt.y + startLineHeight;
selRect.right = fAlignedTextRect.right; selRect.right = fTextRect.right;
selRect.bottom = endPt.y - 1.0; selRect.bottom = endPt.y - 1.0;
outRegion->Include(selRect); outRegion->Include(selRect);
} }
selRect.left = fAlignedTextRect.left; selRect.left = fTextRect.left;
selRect.top = endPt.y; selRect.top = endPt.y;
selRect.right = endPt.x - 1.0; selRect.right = endPt.x - 1.0;
selRect.bottom = endPt.y + endLineHeight - 1.0; selRect.bottom = endPt.y + endLineHeight - 1.0;
@@ -2132,10 +2082,13 @@ BTextView::ScrollToOffset(int32 offset)
BPoint point = PointAt(offset, &lineHeight); BPoint point = PointAt(offset, &lineHeight);
// horizontal // horizontal
float extraSpace = fAlignment == B_ALIGN_LEFT ?
ceilf(bounds.IntegerWidth() / 2) : 0.0;
if (point.x < bounds.left) if (point.x < bounds.left)
xDiff = point.x - bounds.right; xDiff = point.x - bounds.left - extraSpace;
else if (point.x > bounds.right) else if (point.x > bounds.right)
xDiff = point.x - bounds.left; xDiff = point.x - bounds.right + extraSpace;
// vertical // vertical
if (point.y < bounds.top) if (point.y < bounds.top)
@@ -2203,9 +2156,6 @@ BTextView::SetTextRect(BRect rect)
fLayoutData->UpdateInsets(Bounds().OffsetToCopy(B_ORIGIN), rect); fLayoutData->UpdateInsets(Bounds().OffsetToCopy(B_ORIGIN), rect);
fTextRect = rect;
fAlignedTextRect = fTextRect;
_ResetTextRect(); _ResetTextRect();
} }
@@ -2220,21 +2170,21 @@ BTextView::TextRect() const
void void
BTextView::_ResetTextRect() BTextView::_ResetTextRect()
{ {
BRect oldTextRect(fAlignedTextRect); BRect oldTextRect(fTextRect);
// reset text rect to old text bounds minus insets // reset text rect to bounds minus insets ...
fAlignedTextRect = fTextRect; fTextRect = Bounds().OffsetToCopy(B_ORIGIN);
fAlignedTextRect.left += fLayoutData->leftInset; fTextRect.left += fLayoutData->leftInset;
fAlignedTextRect.top += fLayoutData->topInset; fTextRect.top += fLayoutData->topInset;
fAlignedTextRect.right -= fLayoutData->rightInset; fTextRect.right -= fLayoutData->rightInset;
fAlignedTextRect.bottom -= fLayoutData->bottomInset; fTextRect.bottom -= fLayoutData->bottomInset;
// and rewrap (potentially adjusting the right and the bottom of the text // and rewrap (potentially adjusting the right and the bottom of the text
// rect) // rect)
_Refresh(0, TextLength(), false); _Refresh(0, TextLength(), false);
// Make sure that the dirty area outside the text is redrawn too. // Make sure that the dirty area outside the text is redrawn too.
BRegion invalid(oldTextRect | fAlignedTextRect); BRegion invalid(oldTextRect | fTextRect);
invalid.Exclude(fAlignedTextRect); invalid.Exclude(fTextRect);
Invalidate(&invalid); Invalidate(&invalid);
} }
@@ -2253,8 +2203,6 @@ BTextView::SetInsets(float left, float top, float right, float bottom)
fLayoutData->rightInset = right; fLayoutData->rightInset = right;
fLayoutData->bottomInset = bottom; fLayoutData->bottomInset = bottom;
fLayoutData->overridden = true;
InvalidateLayout(); InvalidateLayout();
Invalidate(); Invalidate();
} }
@@ -2376,9 +2324,8 @@ BTextView::SetWordWrap(bool wrap)
fWrap = wrap; fWrap = wrap;
if (wrap) if (wrap)
_ResetTextRect(); // calls _Refresh _ResetTextRect();
else _Refresh(0, fText->Length(), false);
_Refresh(0, fText->Length(), false);
if (updateOnScreen) { if (updateOnScreen) {
// show the caret, hilite the selection // show the caret, hilite the selection
@@ -2666,15 +2613,15 @@ BTextView::GetHeightForWidth(float width, float* min, float* max,
} }
// TODO: don't change the actual text rect! // TODO: don't change the actual text rect!
fAlignedTextRect.right = fAlignedTextRect.left + width; fTextRect.right = fTextRect.left + width;
_Refresh(0, TextLength(), false); _Refresh(0, TextLength(), false);
if (min != NULL) if (min != NULL)
*min = fAlignedTextRect.Height(); *min = fTextRect.Height();
if (max != NULL) if (max != NULL)
*max = B_SIZE_UNLIMITED; *max = B_SIZE_UNLIMITED;
if (preferred != NULL) if (preferred != NULL)
*preferred = fAlignedTextRect.Height(); *preferred = fTextRect.Height();
} }
@@ -2715,12 +2662,6 @@ BTextView::DoLayout()
if (size.height < fLayoutData->min.height) if (size.height < fLayoutData->min.height)
size.height = fLayoutData->min.height; size.height = fLayoutData->min.height;
// reset insets to 0 unless SetInsets() was called
BRect bounds(Bounds());
fLayoutData->UpdateInsets(Bounds().OffsetToCopy(B_ORIGIN), bounds);
// reset text rect to Bounds()
fTextRect = bounds;
fAlignedTextRect = fTextRect;
_ResetTextRect(); _ResetTextRect();
} }
@@ -2744,7 +2685,7 @@ BTextView::_ValidateLayoutData()
fLayoutData->min = min; fLayoutData->min = min;
// compute our preferred size // compute our preferred size
fLayoutData->preferred.height = fAlignedTextRect.Height() fLayoutData->preferred.height = fTextRect.Height()
+ fLayoutData->topInset + fLayoutData->bottomInset; + fLayoutData->topInset + fLayoutData->bottomInset;
if (fWrap) if (fWrap)
@@ -3153,7 +3094,6 @@ BTextView::_InitObject(BRect textRect, const BFont* initialFont,
// to have less code duplication, and a single place where to do changes // to have less code duplication, and a single place where to do changes
// if needed. // if needed.
fTextRect = textRect; fTextRect = textRect;
fAlignedTextRect = textRect;
// NOTE: The only places where text rect is changed: // NOTE: The only places where text rect is changed:
// * width is possibly adjusted in _AutoResize(), // * width is possibly adjusted in _AutoResize(),
// * height is adjusted in _RecalculateLineBreaks(). // * height is adjusted in _RecalculateLineBreaks().
@@ -3190,7 +3130,7 @@ BTextView::_InitObject(BRect textRect, const BFont* initialFont,
fTrackingMouse = NULL; fTrackingMouse = NULL;
fLayoutData = new LayoutData; fLayoutData = new LayoutData;
fLayoutData->UpdateInsets(Bounds().OffsetToCopy(B_ORIGIN), textRect); fLayoutData->UpdateInsets(Bounds().OffsetToCopy(B_ORIGIN), fTextRect);
fLastClickOffset = -1; fLastClickOffset = -1;
@@ -3379,8 +3319,7 @@ BTextView::_HandleArrowKey(uint32 arrowKey, int32 modifiers)
if (optionKeyDown && !commandKeyDown && !controlKeyDown) if (optionKeyDown && !commandKeyDown && !controlKeyDown)
fCaretOffset = _NextLineEnd(fCaretOffset); fCaretOffset = _NextLineEnd(fCaretOffset);
else if (commandKeyDown && !optionKeyDown && !controlKeyDown) { else if (commandKeyDown && !optionKeyDown && !controlKeyDown) {
_ScrollTo(0, fAlignedTextRect.bottom _ScrollTo(0, fTextRect.bottom + fLayoutData->bottomInset);
+ fLayoutData->bottomInset);
fCaretOffset = fText->Length(); fCaretOffset = fText->Length();
} else { } else {
float height; float height;
@@ -3443,7 +3382,8 @@ BTextView::_HandleDelete(int32 modifiers)
} }
if (fUndo) { if (fUndo) {
TypingUndoBuffer* undoBuffer = dynamic_cast<TypingUndoBuffer*>(fUndo); TypingUndoBuffer* undoBuffer = dynamic_cast<TypingUndoBuffer*>(
fUndo);
if (!undoBuffer) { if (!undoBuffer) {
delete fUndo; delete fUndo;
fUndo = undoBuffer = new TypingUndoBuffer(this); fUndo = undoBuffer = new TypingUndoBuffer(this);
@@ -3525,13 +3465,11 @@ BTextView::_HandlePageKey(uint32 pageKey, int32 modifiers)
case B_END: case B_END:
if (!fEditable) { if (!fEditable) {
fCaretOffset = fText->Length(); fCaretOffset = fText->Length();
_ScrollTo(0, fAlignedTextRect.bottom _ScrollTo(0, fTextRect.bottom + fLayoutData->bottomInset);
+ fLayoutData->bottomInset);
break; break;
} else { } else {
if (commandKeyDown && !optionKeyDown && !controlKeyDown) { if (commandKeyDown && !optionKeyDown && !controlKeyDown) {
_ScrollTo(0, fAlignedTextRect.bottom _ScrollTo(0, fTextRect.bottom + fLayoutData->bottomInset);
+ fLayoutData->bottomInset);
fCaretOffset = fText->Length(); fCaretOffset = fText->Length();
} else { } else {
// If we are on the last line, just go to the last // If we are on the last line, just go to the last
@@ -3684,6 +3622,7 @@ BTextView::_HandleAlphaKey(const char* bytes, int32 numBytes)
_DoInsertText(bytes, numBytes, fSelStart, NULL); _DoInsertText(bytes, numBytes, fSelStart, NULL);
fCaretOffset = fSelEnd; fCaretOffset = fSelEnd;
ScrollToOffset(fCaretOffset); ScrollToOffset(fCaretOffset);
} }
@@ -3699,8 +3638,8 @@ void
BTextView::_Refresh(int32 fromOffset, int32 toOffset, bool scroll) BTextView::_Refresh(int32 fromOffset, int32 toOffset, bool scroll)
{ {
// TODO: Cleanup // TODO: Cleanup
float saveHeight = fAlignedTextRect.Height(); float saveHeight = fTextRect.Height();
float saveWidth = fAlignedTextRect.Width(); float saveWidth = fTextRect.Width();
int32 fromLine = _LineAt(fromOffset); int32 fromLine = _LineAt(fromOffset);
int32 toLine = _LineAt(toOffset); int32 toLine = _LineAt(toOffset);
int32 saveFromLine = fromLine; int32 saveFromLine = fromLine;
@@ -3713,7 +3652,7 @@ BTextView::_Refresh(int32 fromOffset, int32 toOffset, bool scroll)
return; return;
BRect bounds = Bounds(); BRect bounds = Bounds();
float newHeight = fAlignedTextRect.Height(); float newHeight = fTextRect.Height();
// if the line breaks have changed, force an erase // if the line breaks have changed, force an erase
if (fromLine != saveFromLine || toLine != saveToLine if (fromLine != saveFromLine || toLine != saveToLine
@@ -3723,20 +3662,17 @@ BTextView::_Refresh(int32 fromOffset, int32 toOffset, bool scroll)
if (newHeight != saveHeight) { if (newHeight != saveHeight) {
// the text area has changed // the text area has changed
if (newHeight < saveHeight) { if (newHeight < saveHeight)
toLine = _LineAt(BPoint(0.0f, toLine = _LineAt(BPoint(0.0f, saveHeight + fTextRect.top));
saveHeight + fAlignedTextRect.top)); else
} else { toLine = _LineAt(BPoint(0.0f, newHeight + fTextRect.top));
toLine = _LineAt(BPoint(0.0f,
newHeight + fAlignedTextRect.top));
}
} }
// draw only those lines that are visible // draw only those lines that are visible
int32 fromVisible = _LineAt(BPoint(0.0f, bounds.top)); int32 fromVisible = _LineAt(BPoint(0.0f, bounds.top));
int32 toVisible = _LineAt(BPoint(0.0f, bounds.bottom)); int32 toVisible = _LineAt(BPoint(0.0f, bounds.bottom));
fromLine = std::max(fromVisible, fromLine); fromLine = max_c(fromVisible, fromLine);
toLine = std::min(toLine, toVisible); toLine = min_c(toLine, toVisible);
_AutoResize(false); _AutoResize(false);
@@ -3744,9 +3680,8 @@ BTextView::_Refresh(int32 fromOffset, int32 toOffset, bool scroll)
// erase the area below the text // erase the area below the text
BRect eraseRect = bounds; BRect eraseRect = bounds;
eraseRect.top = fAlignedTextRect.top eraseRect.top = fTextRect.top + (*fLines)[fLines->NumLines()]->origin;
+ (*fLines)[fLines->NumLines()]->origin; eraseRect.bottom = fTextRect.top + saveHeight;
eraseRect.bottom = fAlignedTextRect.top + saveHeight;
if (eraseRect.bottom > eraseRect.top && eraseRect.Intersects(bounds)) { if (eraseRect.bottom > eraseRect.top && eraseRect.Intersects(bounds)) {
SetLowColor(ViewColor()); SetLowColor(ViewColor());
FillRect(eraseRect, B_SOLID_LOW); FillRect(eraseRect, B_SOLID_LOW);
@@ -3773,7 +3708,7 @@ BTextView::_RecalculateLineBreaks(int32* startLine, int32* endLine)
{ {
CALLED(); CALLED();
float width = fAlignedTextRect.Width(); float width = fTextRect.Width();
// Don't try to compute anything if the text rect is not set // Don't try to compute anything if the text rect is not set
if (width <= 0) if (width <= 0)
@@ -3845,61 +3780,16 @@ BTextView::_RecalculateLineBreaks(int32* startLine, int32* endLine)
// has always a width of 0 // has always a width of 0
(*fLines)[fLines->NumLines()]->width = 0; (*fLines)[fLines->NumLines()]->width = 0;
// update fAlignedTextRect, leave fTextRect alone // update the text rect
fAlignedTextRect = fTextRect;
// adjust insets
fAlignedTextRect.left += fLayoutData->leftInset;
fAlignedTextRect.top += fLayoutData->topInset;
fAlignedTextRect.right -= fLayoutData->rightInset;
fAlignedTextRect.bottom -= fLayoutData->bottomInset;
// Set new bottom based on text height unless bottom is below
// the bottom of text height already.
float newHeight = TextHeight(0, fLines->NumLines() - 1); float newHeight = TextHeight(0, fLines->NumLines() - 1);
fAlignedTextRect.bottom = std::max(fAlignedTextRect.bottom, fTextRect.bottom = fTextRect.top + newHeight;
fAlignedTextRect.top + newHeight);
bool doPadding = !fLayoutData->overridden && (fEditable || fSelectable);
float hPadding = doPadding ? be_control_look->DefaultLabelSpacing() : 0;
// new min width
if (!fWrap) { if (!fWrap) {
fMinTextRectWidth = fLines->MaxWidth(); fMinTextRectWidth = fLines->MaxWidth();
fTextRect.right = ceilf(fTextRect.left + fMinTextRectWidth);
// expand width if needed (including padding)
switch (fAlignment) {
default:
case B_ALIGN_LEFT:
// grow right
fAlignedTextRect.right = std::max(fAlignedTextRect.right,
fAlignedTextRect.left + hPadding + fMinTextRectWidth);
break;
case B_ALIGN_RIGHT:
// grow left
fAlignedTextRect.left = std::min(fAlignedTextRect.left,
fAlignedTextRect.right - hPadding - fMinTextRectWidth);
break;
case B_ALIGN_CENTER:
// grow out
if (fMinTextRectWidth + hPadding > fAlignedTextRect.Width()) {
fAlignedTextRect.InsetBy(ceilf((fAlignedTextRect.Width()
- hPadding - fMinTextRectWidth) / 2.0f), 0);
}
break;
}
}
if (doPadding) {
float hInset = floorf(hPadding / 2.0f);
float vInset = 1;
fAlignedTextRect.InsetBy(hInset, vInset);
} }
*endLine = lineIndex - 1; *endLine = lineIndex - 1;
*startLine = std::min(*startLine, *endLine); *startLine = min_c(*startLine, *endLine);
} }
@@ -3990,7 +3880,7 @@ BTextView::_FindLineBreak(int32 fromOffset, float* _ascent, float* _descent,
} }
} }
delta = std::max(delta, (int32)1); delta = max_c(delta, 1);
// do not include B_ENTER-terminator into width & height calculations // do not include B_ENTER-terminator into width & height calculations
deltaWidth = _TabExpandedStyledWidth(offset, deltaWidth = _TabExpandedStyledWidth(offset,
@@ -4021,8 +3911,8 @@ BTextView::_FindLineBreak(int32 fromOffset, float* _ascent, float* _descent,
} }
} }
*_ascent = std::max(ascent, *_ascent); *_ascent = max_c(ascent, *_ascent);
*_descent = std::max(descent, *_descent); *_descent = max_c(descent, *_descent);
offset += delta; offset += delta;
delta = 0; delta = 0;
@@ -4045,12 +3935,12 @@ BTextView::_FindLineBreak(int32 fromOffset, float* _ascent, float* _descent,
break; break;
} }
*_ascent = std::max(ascent, *_ascent); *_ascent = max_c(ascent, *_ascent);
*_descent = std::max(descent, *_descent); *_descent = max_c(descent, *_descent);
} }
} }
return std::min(offset, limit); return min_c(offset, limit);
} }
@@ -4247,8 +4137,8 @@ BTextView::_StyledWidth(int32 fromOffset, int32 length, float* _ascent,
int32 numBytes; int32 numBytes;
while ((numBytes = fStyles->Iterate(fromOffset, length, fInline, &font, while ((numBytes = fStyles->Iterate(fromOffset, length, fInline, &font,
NULL, &ascent, &descent)) != 0) { NULL, &ascent, &descent)) != 0) {
maxAscent = std::max(ascent, maxAscent); maxAscent = max_c(ascent, maxAscent);
maxDescent = std::max(descent, maxDescent); maxDescent = max_c(descent, maxDescent);
#if USE_WIDTHBUFFER #if USE_WIDTHBUFFER
// Use _BWidthBuffer_ if possible // Use _BWidthBuffer_ if possible
@@ -4326,20 +4216,19 @@ BTextView::_DrawLine(BView* view, const int32 &lineNum,
BRegion &inputRegion) BRegion &inputRegion)
{ {
STELine* line = (*fLines)[lineNum]; STELine* line = (*fLines)[lineNum];
float startLeft = fAlignedTextRect.left; float startLeft = fTextRect.left;
if (startOffset != -1) { if (startOffset != -1) {
if (ByteAt(startOffset) == B_ENTER) { if (ByteAt(startOffset) == B_ENTER) {
// StartOffset is a newline // StartOffset is a newline
startLeft = PointAt(line->offset).x; startLeft = PointAt(line->offset).x;
} else } else
startLeft = PointAt(startOffset).x; startLeft = PointAt(startOffset).x;
} else if (fAlignment != B_ALIGN_LEFT) { }
float alignmentOffset = fAlignedTextRect.Width() else if (fAlignment != B_ALIGN_LEFT) {
- LineWidth(lineNum); float alignmentOffset = fTextRect.Width() - LineWidth(lineNum);
if (fAlignment == B_ALIGN_CENTER) if (fAlignment == B_ALIGN_CENTER)
alignmentOffset = floorf(alignmentOffset / 2); alignmentOffset /= 2;
startLeft = fAlignedTextRect.left + alignmentOffset; startLeft = fTextRect.left + alignmentOffset;
} }
int32 length = (line + 1)->offset; int32 length = (line + 1)->offset;
@@ -4352,12 +4241,11 @@ BTextView::_DrawLine(BView* view, const int32 &lineNum,
if (ByteAt((line + 1)->offset - 1) == B_ENTER) if (ByteAt((line + 1)->offset - 1) == B_ENTER)
length--; length--;
view->MovePenTo(startLeft, view->MovePenTo(startLeft, line->origin + line->ascent + fTextRect.top + 1);
line->origin + line->ascent + fAlignedTextRect.top + 1);
if (erase) { if (erase) {
eraseRect.top = line->origin + fAlignedTextRect.top; eraseRect.top = line->origin + fTextRect.top;
eraseRect.bottom = (line + 1)->origin + fAlignedTextRect.top; eraseRect.bottom = (line + 1)->origin + fTextRect.top;
view->FillRect(eraseRect, B_SOLID_LOW); view->FillRect(eraseRect, B_SOLID_LOW);
} }
@@ -4379,7 +4267,7 @@ BTextView::_DrawLine(BView* view, const int32 &lineNum,
view->SetFont(font); view->SetFont(font);
view->SetHighColor(*color); view->SetHighColor(*color);
tabChars = std::min(numBytes, length); tabChars = min_c(numBytes, length);
do { do {
foundTab = fText->FindChar(B_TAB, offset, &tabChars); foundTab = fText->FindChar(B_TAB, offset, &tabChars);
if (foundTab) { if (foundTab) {
@@ -4428,12 +4316,11 @@ BTextView::_DrawLine(BView* view, const int32 &lineNum,
} }
int32 returnedBytes = tabChars; int32 returnedBytes = tabChars;
const char* stringToDraw const char* stringToDraw = fText->GetString(offset, &returnedBytes);
= fText->GetString(offset, &returnedBytes);
view->SetDrawingMode(textRenderingMode); view->SetDrawingMode(textRenderingMode);
view->DrawString(stringToDraw, returnedBytes); view->DrawString(stringToDraw, returnedBytes);
if (foundTab) { if (foundTab) {
float penPos = PenLocation().x - fAlignedTextRect.left; float penPos = PenLocation().x - fTextRect.left;
float tabWidth = _ActualTabWidth(penPos); float tabWidth = _ActualTabWidth(penPos);
if (numTabs > 1) if (numTabs > 1)
tabWidth += ((numTabs - 1) * fTabWidth); tabWidth += ((numTabs - 1) * fTabWidth);
@@ -4445,7 +4332,7 @@ BTextView::_DrawLine(BView* view, const int32 &lineNum,
offset += tabChars; offset += tabChars;
length -= tabChars; length -= tabChars;
numBytes -= tabChars; numBytes -= tabChars;
tabChars = std::min(numBytes, length); tabChars = min_c(numBytes, length);
numTabs = 0; numTabs = 0;
} while (foundTab && tabChars > 0); } while (foundTab && tabChars > 0);
} }
@@ -4460,9 +4347,9 @@ BTextView::_DrawLines(int32 startLine, int32 endLine, int32 startOffset,
return; return;
// clip the text // clip the text
BRect textRect(fAlignedTextRect); BRect textRect(fTextRect);
float minWidth = Bounds().Width() - fLayoutData->leftInset float minWidth
- fLayoutData->rightInset; = Bounds().Width() - fLayoutData->leftInset - fLayoutData->rightInset;
if (textRect.Width() < minWidth) if (textRect.Width() < minWidth)
textRect.right = textRect.left + minWidth; textRect.right = textRect.left + minWidth;
BRect clipRect = Bounds() & textRect; BRect clipRect = Bounds() & textRect;
@@ -4508,7 +4395,7 @@ BTextView::_DrawLines(int32 startLine, int32 endLine, int32 startOffset,
BPoint erasePoint = PointAt(startErase); BPoint erasePoint = PointAt(startErase);
eraseRect.left = erasePoint.x; eraseRect.left = erasePoint.x;
eraseRect.top = erasePoint.y; eraseRect.top = erasePoint.y;
eraseRect.bottom = (line + 1)->origin + fAlignedTextRect.top; eraseRect.bottom = (line + 1)->origin + fTextRect.top;
view->FillRect(eraseRect, B_SOLID_LOW); view->FillRect(eraseRect, B_SOLID_LOW);
@@ -4563,10 +4450,9 @@ BTextView::_RequestDrawLines(int32 startLine, int32 endLine)
STELine* from = (*fLines)[startLine]; STELine* from = (*fLines)[startLine];
STELine* to = endLine == maxLine ? NULL : (*fLines)[endLine + 1]; STELine* to = endLine == maxLine ? NULL : (*fLines)[endLine + 1];
BRect invalidRect(Bounds().left, from->origin + fAlignedTextRect.top, BRect invalidRect(Bounds().left, from->origin + fTextRect.top,
Bounds().right, Bounds().right,
to != NULL ? to->origin + fAlignedTextRect.top to != NULL ? to->origin + fTextRect.top : fTextRect.bottom);
: fAlignedTextRect.bottom);
Invalidate(invalidRect); Invalidate(invalidRect);
Window()->UpdateIfNeeded(); Window()->UpdateIfNeeded();
} }
@@ -4577,7 +4463,7 @@ BTextView::_DrawCaret(int32 offset, bool visible)
{ {
float lineHeight; float lineHeight;
BPoint caretPoint = PointAt(offset, &lineHeight); BPoint caretPoint = PointAt(offset, &lineHeight);
caretPoint.x = std::min(caretPoint.x, fAlignedTextRect.right); caretPoint.x = min_c(caretPoint.x, fTextRect.right);
BRect caretRect; BRect caretRect;
caretRect.left = caretRect.right = caretPoint.x; caretRect.left = caretRect.right = caretPoint.x;
@@ -4908,15 +4794,15 @@ BTextView::_PerformAutoScrolling()
// R5 does a pretty soft auto-scroll, we try to do the same by // R5 does a pretty soft auto-scroll, we try to do the same by
// simply scrolling the distance between cursor and border // simply scrolling the distance between cursor and border
if (fWhere.x > bounds.right) if (fWhere.x > bounds.right) {
scrollBy.x = fWhere.x - bounds.right; scrollBy.x = fWhere.x - bounds.right;
else if (fWhere.x < bounds.left) } else if (fWhere.x < bounds.left) {
scrollBy.x = fWhere.x - bounds.left; // negative value scrollBy.x = fWhere.x - bounds.left; // negative value
}
// prevent from scrolling out of view // prevent from scrolling out of view
if (scrollBy.x != 0.0) { if (scrollBy.x != 0.0) {
float rightMax = floorf(fAlignedTextRect.right float rightMax = floorf(fTextRect.right + fLayoutData->rightInset);
+ fLayoutData->rightInset);
if (bounds.right + scrollBy.x > rightMax) if (bounds.right + scrollBy.x > rightMax)
scrollBy.x = rightMax - bounds.right; scrollBy.x = rightMax - bounds.right;
if (bounds.left + scrollBy.x < 0) if (bounds.left + scrollBy.x < 0)
@@ -4925,14 +4811,15 @@ BTextView::_PerformAutoScrolling()
if (CountLines() > 1) { if (CountLines() > 1) {
// scroll in Y only if multiple lines! // scroll in Y only if multiple lines!
if (fWhere.y > bounds.bottom) if (fWhere.y > bounds.bottom) {
scrollBy.y = fWhere.y - bounds.bottom; scrollBy.y = fWhere.y - bounds.bottom;
else if (fWhere.y < bounds.top) } else if (fWhere.y < bounds.top) {
scrollBy.y = fWhere.y - bounds.top; // negative value scrollBy.y = fWhere.y - bounds.top; // negative value
}
// prevent from scrolling out of view // prevent from scrolling out of view
if (scrollBy.y != 0.0) { if (scrollBy.y != 0.0) {
float bottomMax = floorf(fAlignedTextRect.bottom float bottomMax = floorf(fTextRect.bottom
+ fLayoutData->bottomInset); + fLayoutData->bottomInset);
if (bounds.bottom + scrollBy.y > bottomMax) if (bounds.bottom + scrollBy.y > bottomMax)
scrollBy.y = bottomMax - bounds.bottom; scrollBy.y = bottomMax - bounds.bottom;
@@ -4957,11 +4844,11 @@ BTextView::_UpdateScrollbars()
// do we have a horizontal scroll bar? // do we have a horizontal scroll bar?
if (horizontalScrollBar != NULL) { if (horizontalScrollBar != NULL) {
long viewWidth = bounds.IntegerWidth(); long viewWidth = bounds.IntegerWidth();
long dataWidth = (long)ceilf(fAlignedTextRect.IntegerWidth() long dataWidth = (long)ceilf(fTextRect.IntegerWidth()
+ fLayoutData->leftInset + fLayoutData->rightInset); + fLayoutData->leftInset + fLayoutData->rightInset);
long maxRange = dataWidth - viewWidth; long maxRange = dataWidth - viewWidth;
maxRange = std::max(maxRange, 0l); maxRange = max_c(maxRange, 0);
horizontalScrollBar->SetRange(0, (float)maxRange); horizontalScrollBar->SetRange(0, (float)maxRange);
horizontalScrollBar->SetProportion((float)viewWidth / (float)dataWidth); horizontalScrollBar->SetProportion((float)viewWidth / (float)dataWidth);
@@ -4971,11 +4858,11 @@ BTextView::_UpdateScrollbars()
// how about a vertical scroll bar? // how about a vertical scroll bar?
if (verticalScrollBar != NULL) { if (verticalScrollBar != NULL) {
long viewHeight = bounds.IntegerHeight(); long viewHeight = bounds.IntegerHeight();
long dataHeight = (long)ceilf(fLayoutData->topInset long dataHeight = (long)ceilf(fTextRect.IntegerHeight()
+ fAlignedTextRect.IntegerHeight() + fLayoutData->bottomInset); + fLayoutData->topInset + fLayoutData->bottomInset);
long maxRange = dataHeight - viewHeight; long maxRange = dataHeight - viewHeight;
maxRange = std::max(maxRange, 0L); maxRange = max_c(maxRange, 0);
verticalScrollBar->SetRange(0, maxRange); verticalScrollBar->SetRange(0, maxRange);
verticalScrollBar->SetProportion((float)viewHeight / (float)dataHeight); verticalScrollBar->SetProportion((float)viewHeight / (float)dataHeight);
@@ -5001,13 +4888,13 @@ BTextView::_ScrollTo(float x, float y)
long viewWidth = bounds.IntegerWidth(); long viewWidth = bounds.IntegerWidth();
long viewHeight = bounds.IntegerHeight(); long viewHeight = bounds.IntegerHeight();
if (x > fAlignedTextRect.right - viewWidth) if (x > fTextRect.right - viewWidth)
x = fAlignedTextRect.right - viewWidth; x = fTextRect.right - viewWidth;
if (x < 0.0) if (x < 0.0)
x = 0.0; x = 0.0;
if (y > fAlignedTextRect.bottom + fLayoutData->bottomInset - viewHeight) if (y > fTextRect.bottom + fLayoutData->bottomInset - viewHeight)
y = fAlignedTextRect.bottom + fLayoutData->bottomInset - viewHeight; y = fTextRect.bottom + fLayoutData->bottomInset - viewHeight;
if (y < 0.0) if (y < 0.0)
y = 0.0; y = 0.0;
@@ -5023,13 +4910,13 @@ BTextView::_AutoResize(bool redraw)
return; return;
BRect bounds = Bounds(); BRect bounds = Bounds();
float oldWidth = bounds.Width();
float newWidth = ceilf(fLayoutData->leftInset + fTextRect.Width()
+ fLayoutData->rightInset);
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.
// move container view if not left aligned // move container view if not left aligned
float oldWidth = bounds.Width();
float newWidth = ceilf(fLayoutData->leftInset
+ fAlignedTextRect.Width() + fLayoutData->rightInset);
if (fAlignment == B_ALIGN_CENTER) { if (fAlignment == B_ALIGN_CENTER) {
if (fmod(ceilf(newWidth - oldWidth), 2.0) != 0.0) if (fmod(ceilf(newWidth - oldWidth), 2.0) != 0.0)
newWidth += 1; newWidth += 1;
@@ -5047,8 +4934,8 @@ BTextView::_AutoResize(bool redraw)
// erase any potential left over outside the text rect // erase any potential left over outside the text rect
// (can only be on right hand side) // (can only be on right hand side)
BRect dirty(fAlignedTextRect.right + 1, fAlignedTextRect.top, BRect dirty(fTextRect.right + 1, fTextRect.top, bounds.right,
bounds.right, fAlignedTextRect.bottom); fTextRect.bottom);
if (dirty.IsValid()) { if (dirty.IsValid()) {
SetLowColor(ViewColor()); SetLowColor(ViewColor());
FillRect(dirty, B_SOLID_LOW); FillRect(dirty, B_SOLID_LOW);
@@ -5064,9 +4951,8 @@ BTextView::_NewOffscreen(float padding)
_DeleteOffscreen(); _DeleteOffscreen();
#if USE_DOUBLEBUFFERING #if USE_DOUBLEBUFFERING
BRect bitmapRect(0, 0, fAlignedTextRect.Width() + padding, BRect bitmapRect(0, 0, fTextRect.Width() + padding, fTextRect.Height());
fAlignedTextRect.Height()); fOffscreen = new BBitmap(bitmapRect, fColorSpace, true, false);
fOffscreen = new BBitmap(bitm->Rect, fColorSpace, true, false);
if (fOffscreen != NULL && fOffscreen->Lock()) { if (fOffscreen != NULL && fOffscreen->Lock()) {
BView* bufferView = new BView(bitmapRect, "drawing view", 0, 0); BView* bufferView = new BView(bitmapRect, "drawing view", 0, 0);
fOffscreen->AddChild(bufferView); fOffscreen->AddChild(bufferView);
@@ -5780,7 +5666,7 @@ BTextView::_LineAt(int32 offset) const
int32 int32
BTextView::_LineAt(const BPoint& point) const BTextView::_LineAt(const BPoint& point) const
{ {
return fLines->PixelToLine(point.y - fAlignedTextRect.top); return fLines->PixelToLine(point.y - fTextRect.top);
} }
-1
View File
@@ -379,7 +379,6 @@ BTextWidget::StartEdit(BRect bounds, BPoseView* view, BPose* pose)
textView->SetWordWrap(false); textView->SetWordWrap(false);
DisallowMetaKeys(textView); DisallowMetaKeys(textView);
textView->SetInsets(0, 0, 0, 0);
fText->SetUpEditing(textView); fText->SetUpEditing(textView);
textView->AddFilter(new BMessageFilter(B_KEY_DOWN, TextViewFilter)); textView->AddFilter(new BMessageFilter(B_KEY_DOWN, TextViewFilter));
@@ -302,6 +302,7 @@ HeaderView::Draw(BRect)
// Font information // Font information
font_height fontMetrics; font_height fontMetrics;
BFont currentFont; BFont currentFont;
float lineHeight = 0;
float lineBase = 0; float lineBase = 0;
// Draw the main title if the user is not currently editing it // Draw the main title if the user is not currently editing it
@@ -310,6 +311,7 @@ HeaderView::Draw(BRect)
SetFontSize(be_bold_font->Size()); SetFontSize(be_bold_font->Size());
GetFont(&currentFont); GetFont(&currentFont);
currentFont.GetHeight(&fontMetrics); currentFont.GetHeight(&fontMetrics);
lineHeight = CurrentFontHeight() + 5;
lineBase = fTitleRect.bottom - fontMetrics.descent; lineBase = fTitleRect.bottom - fontMetrics.descent;
SetHighColor(labelColor); SetHighColor(labelColor);
MovePenTo(BPoint(fIconRect.right + 6, lineBase)); MovePenTo(BPoint(fIconRect.right + 6, lineBase));
@@ -146,7 +146,6 @@ PreviewView::AddPreview()
fNoPreview->SetExplicitSize(BSize(previewWidth, previewHeight)); fNoPreview->SetExplicitSize(BSize(previewWidth, previewHeight));
fNoPreview->ResizeTo(previewWidth, previewHeight); fNoPreview->ResizeTo(previewWidth, previewHeight);
fNoPreview->SetTextRect(BRect(0, 0, previewWidth, previewHeight));
fNoPreview->SetInsets(0, previewHeight / 3, 0 , 0); fNoPreview->SetInsets(0, previewHeight / 3, 0 , 0);
return fSaverView; return fSaverView;