- Fixed wrong redrawing of the caret in some particular circumstancies

(most notably when you clicked the first time on the textview, the caret 
would be left "drawn" on the old position.
- Implemented vertical auto scrolling (horizontal auto scrolling is 
still missing). Note that the view jumps when there is nothing to 
scroll, might be a bug in BView::ScrollBy() ?
 


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19692 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2007-01-04 09:40:54 +00:00
parent 8eb93fe5e3
commit 23fb6e0efe
+29 -15
View File
@@ -913,21 +913,32 @@ BTextView::MessageReceived(BMessage *message)
} }
} else { } else {
// Scroll the view a bit if mouse is outside the view bounds // Scroll the view a bit if mouse is outside the view bounds
BPoint scrollBy;
BRect bounds = Bounds(); // TODO: Use the textrect instead ? BRect bounds = Bounds();
if (fWhere.x > bounds.right)
// TODO: Horizontal scrolling
/*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; scrollBy.x = fWhere.x - bounds.left;
*/
float lineHeight = 0;
float diff = 0;
if (fWhere.y > bounds.bottom) {
lineHeight = LineHeight(LineAt(bounds.LeftBottom()));
diff = fWhere.y - bounds.bottom;
} else if (fWhere.y < bounds.top) {
lineHeight = LineHeight(LineAt(bounds.LeftTop()));
diff = fWhere.y - bounds.top; // negative value
}
if (fWhere.y > bounds.bottom) // Always scroll vertically by multiples of line height,
scrollBy.y = fWhere.y - bounds.bottom; // based on the distance of the cursor from the border of the view
else if (fWhere.y < bounds.top) // TODO: Refine this, I can't even remember how beos works here
scrollBy.y = fWhere.y - bounds.top; BPoint scrollBy;
scrollBy.y = lineHeight > 0 ? lineHeight * (int32)(floorf(diff) / lineHeight) : 0;
// TODO: Review this, it's not working correctly if (scrollBy != B_ORIGIN)
//if (scrollBy != B_ORIGIN) ScrollBy(scrollBy.x, scrollBy.y);
// ScrollBy(scrollBy.x, scrollBy.y);
} }
break; break;
} }
@@ -1830,8 +1841,7 @@ BTextView::OffsetAt(int32 line) const
\param outToOffset A pointer to an integer which will contain the ending offset of the word. \param outToOffset A pointer to an integer which will contain the ending offset of the word.
*/ */
void void
BTextView::FindWord(int32 inOffset, int32 *outFromOffset, BTextView::FindWord(int32 inOffset, int32 *outFromOffset, int32 *outToOffset)
int32 *outToOffset)
{ {
int32 offset; int32 offset;
uint32 charType = CharClassification(inOffset); uint32 charType = CharClassification(inOffset);
@@ -2228,7 +2238,7 @@ BTextView::DoesWordWrap() const
void void
BTextView::SetMaxBytes(int32 max) BTextView::SetMaxBytes(int32 max)
{ {
int32 textLength = fText->Length(); const int32 textLength = fText->Length();
fMaxBytes = max; fMaxBytes = max;
if (fMaxBytes < textLength) if (fMaxBytes < textLength)
@@ -3569,6 +3579,10 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, bool era
if (fAlignment != B_ALIGN_LEFT) if (fAlignment != B_ALIGN_LEFT)
erase = true; erase = true;
// Actually hide the caret
if (fCaretVisible)
DrawCaret(fSelStart);
BRect eraseRect = clipRect; BRect eraseRect = clipRect;
long startEraseLine = startLine; long startEraseLine = startLine;
STELine* line = (*fLines)[startLine]; STELine* line = (*fLines)[startLine];
@@ -3922,7 +3936,7 @@ BTextView::InitiateDrag()
BMessenger messenger(this); BMessenger messenger(this);
BMessage message(_DISPOSE_DRAG_); BMessage message(_DISPOSE_DRAG_);
fDragRunner = new (nothrow) BMessageRunner(this, &message, 100000); fDragRunner = new (nothrow) BMessageRunner(messenger, &message, 100000);
} }