From 6d8d6cad9da47bc0390985127aadc269e027880e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 16 May 2005 12:02:23 +0000 Subject: [PATCH] Work in progress to improve BTextView and BTextControl. I don't know what _BTextInput_::AlignTextRect() was thought to do. Some of the fixes are Haiku specific and we need to make sure that we don't need them later on (flushing drawing commands). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12685 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/BTextView/TextView.cpp | 6 ++++++ src/kits/interface/TextControl.cpp | 26 +++++++++++------------ src/kits/interface/TextInput.cpp | 18 +++++++++++++--- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/kits/interface/BTextView/TextView.cpp b/src/kits/interface/BTextView/TextView.cpp index 74848bb3d9..e6ea63520d 100644 --- a/src/kits/interface/BTextView/TextView.cpp +++ b/src/kits/interface/BTextView/TextView.cpp @@ -2166,6 +2166,9 @@ BTextView::Highlight(int32 startOffset, int32 endOffset) SetDrawingMode(B_OP_INVERT); FillRegion(&selRegion, B_SOLID_HIGH); SetDrawingMode(B_OP_COPY); +// TODO: unnecessary in R5 - maybe we should +// carry out drawing commands outside Draw() immediately? +Flush(); } @@ -3807,6 +3810,9 @@ BTextView::DrawCaret(int32 offset) caretRect.bottom = caretPoint.y + lineHeight; InvertRect(caretRect); +// TODO: This call seems not necessary on R5. So we need to fix something +// in our app_server. We should "auto-flush" eventually. +Flush(); } diff --git a/src/kits/interface/TextControl.cpp b/src/kits/interface/TextControl.cpp index cb1cdfef53..02c83c530c 100644 --- a/src/kits/interface/TextControl.cpp +++ b/src/kits/interface/TextControl.cpp @@ -348,10 +348,12 @@ BTextControl::AttachedToWindow() void BTextControl::MakeFocus(bool state) { - fText->MakeFocus(state); + if (state != fText->IsFocus()) { + fText->MakeFocus(state); - if (state) - fText->SelectAll(); + if (state) + fText->SelectAll(); + } } @@ -399,17 +401,12 @@ BTextControl::SetEnabled(bool state) void BTextControl::GetPreferredSize(float *width, float *height) { - BFont font; - GetFont(&font); - font_height fh; - font.GetHeight(&fh); - if (height) - *height = (float)ceil(fh.ascent + fh.descent + fh.leading) + 7.0f; + *height = fText->LineHeight(0) + 8.0f; // TODO: this one I need to find out if (width) - *width = 4.0f + (float)ceil(font.StringWidth(Label()))*2.0f; + *width = 4.0f + ceilf(StringWidth(Label())) * 2.0f; } @@ -538,8 +535,11 @@ BTextControl::FrameResized(float newWidth, float newHeight) void BTextControl::WindowActivated(bool active) { - if (fText->IsFocus()) - Invalidate(); + if (fText->IsFocus()) { + BRect rect(fText->Frame()); + rect.InsetBy(-1.0, -1.0); + Invalidate(rect); + } } @@ -576,13 +576,11 @@ BTextControl::InitData(const char *label, const char *initial_text, BRect bounds(Bounds()); fText = NULL; - //fLabel = NULL; fModificationMessage = NULL; fLabelAlign = B_ALIGN_LEFT; fDivider = 0.0f; fPrevWidth = 0; fPrevHeight = 0; - //fClean = true; fSkipSetFlags = false; int32 flags = 0; diff --git a/src/kits/interface/TextInput.cpp b/src/kits/interface/TextInput.cpp index a86f186913..106825f28f 100644 --- a/src/kits/interface/TextInput.cpp +++ b/src/kits/interface/TextInput.cpp @@ -83,8 +83,14 @@ _BTextInput_::Archive(BMessage *data, bool deep) const void _BTextInput_::FrameResized(float width, float height) { +printf("_BTextInput_::FrameResized()\n"); BTextView::FrameResized(width, height); AlignTextRect(); +// TODO: just to get something working, it wouldn't be correct for +// scrolled views +BRect textRect(Bounds()); +textRect.InsetBy(2.0, 2.0); +SetTextRect(textRect); } @@ -154,8 +160,14 @@ _BTextInput_::MakeFocus(bool state) } if (Window()) { - Draw(Bounds()); - Flush(); +// TODO: why do we have to invalidate here? +// I'm leaving this in, but it looks suspicious... :-) + Invalidate(Bounds()); + if (BView* parent = Parent()) { + BRect frame = Frame(); + frame.InsetBy(-1.0, -1.0); + parent->Invalidate(frame); + } } } @@ -163,7 +175,7 @@ _BTextInput_::MakeFocus(bool state) void _BTextInput_::AlignTextRect() { - // TODO + }