BTextControl:
* Placed _BTextInput_ into BPrivate namespace. * Made _BTextInput_::AlignTextRect() smarter, it centers the line vertically, for the case that the BTextControl has a larger label font. Improved insets for asthetics. * Used _BTextInput_::AlignTextRect() consistently in BTextControl, no more custom calls to SetTextRect(). Account for minimum vertical inset of 2 pixels in GetPreferredSize(). * Consistendly select all text when gaining focus in _BTextInput_. * Override MouseDown() in case the control did not have focus before, or else BTextView::MouseDown() will deselct the text again and place the cursor. (in line with BeOS behavior) * Removed unused fBool member from _BTextInput_ and other cleanup. BTextView: * Reimplemented BTextView::_AutoResize() so that it works well with BTextControl and autoscrolling when the alignment is not B_ALIGN_LEFT. I needed two new members for this, fLeftInset and fRightInset which are the original insets from the fTextRects. It might currently be broken for renaming things in Tracker, I will have to check. _AutoResize() no longer messes up the fTextRect insets. * Fixed stray carrets sometimes being left over, mostly when auto scrolling, but I observed them in other cases as well. * Prevent negative scrolling offsets when autoscrolling. Fixes weird scrolling offsets when navigating to the left. * Reset scrolling to B_ORIGIN when SetText() is called. Fixes for example starting to type in the middle of the control in Vision when entering new text and autoscrolling was triggered before. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24101 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -333,24 +333,26 @@ BTextControl::Draw(BRect updateRect)
|
||||
// label
|
||||
|
||||
if (Label()) {
|
||||
font_height fontHeight;
|
||||
GetFontHeight(&fontHeight);
|
||||
font_height fh;
|
||||
GetFontHeight(&fh);
|
||||
|
||||
float y = fontHeight.ascent + fText->Frame().top + 1;
|
||||
float y = Bounds().top
|
||||
+ (Bounds().Height() + 1 - fh.ascent - fh.descent) / 2
|
||||
+ fh.ascent;
|
||||
float x;
|
||||
|
||||
float labelWidth = StringWidth(Label());
|
||||
switch (fLabelAlign) {
|
||||
case B_ALIGN_RIGHT:
|
||||
x = fDivider - labelWidth - 3.0f;
|
||||
x = fDivider - labelWidth - 3.0;
|
||||
break;
|
||||
|
||||
case B_ALIGN_CENTER:
|
||||
x = fDivider - labelWidth / 2.0f;
|
||||
x = fDivider - labelWidth / 2.0;
|
||||
break;
|
||||
|
||||
default:
|
||||
x = 3.0f;
|
||||
x = 0.0;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -373,7 +375,6 @@ BTextControl::MouseDown(BPoint where)
|
||||
{
|
||||
if (!fText->IsFocus()) {
|
||||
fText->MakeFocus(true);
|
||||
fText->SelectAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,7 +429,7 @@ BTextControl::GetPreferredSize(float *_width, float *_height)
|
||||
GetFontHeight(&fontHeight);
|
||||
float labelHeight = ceil(fontHeight.ascent + fontHeight.descent
|
||||
+ fontHeight.leading);
|
||||
float textHeight = ceilf(fText->LineHeight(0)) + 4.0;
|
||||
float textHeight = ceilf(fText->LineHeight(0) + 1.0) + 4.0;
|
||||
|
||||
*_height = max_c(labelHeight, textHeight);
|
||||
}
|
||||
@@ -730,7 +731,7 @@ BTextControl::_InitData(const char* label, const char* initialText,
|
||||
}
|
||||
|
||||
if (archive)
|
||||
fText = static_cast<_BTextInput_ *>(FindView("_input_"));
|
||||
fText = static_cast<BPrivate::_BTextInput_*>(FindView("_input_"));
|
||||
else {
|
||||
BRect frame(fDivider, bounds.top,
|
||||
bounds.right, bounds.bottom);
|
||||
@@ -739,7 +740,7 @@ BTextControl::_InitData(const char* label, const char* initialText,
|
||||
frame.InsetBy(2.0, 3.0);
|
||||
BRect textRect(frame.OffsetToCopy(B_ORIGIN));
|
||||
|
||||
fText = new _BTextInput_(frame, textRect,
|
||||
fText = new BPrivate::_BTextInput_(frame, textRect,
|
||||
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | navigableFlags);
|
||||
AddChild(fText);
|
||||
@@ -775,16 +776,7 @@ BTextControl::_LayoutTextView()
|
||||
frame.InsetBy(2.0, 2.0);
|
||||
fText->MoveTo(frame.left, frame.top);
|
||||
fText->ResizeTo(frame.Width(), frame.Height());
|
||||
|
||||
BRect textRect(frame.OffsetToCopy(B_ORIGIN));
|
||||
|
||||
// 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
|
||||
float lineHeight = ceilf(fText->LineHeight(0));
|
||||
textRect.InsetBy(1, floorf((frame.Height() - lineHeight) / 2));
|
||||
fText->SetTextRect(textRect);
|
||||
fText->AlignTextRect();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user