Added _Show/_HideCaret() and used them in place of more bug-prone code.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21558 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2007-07-04 20:20:09 +00:00
parent 4ec75bbee6
commit 99584ef9a2
2 changed files with 41 additions and 45 deletions
+2
View File
@@ -337,6 +337,8 @@ virtual void _ReservedTextView12();
int32 startOffset = -1, int32 startOffset = -1,
bool erase = false); bool erase = false);
void DrawCaret(int32 offset); void DrawCaret(int32 offset);
void _ShowCaret();
void _HideCaret();
void InvertCaret(); void InvertCaret();
void DragCaret(int32 offset); void DragCaret(int32 offset);
+39 -45
View File
@@ -467,9 +467,7 @@ BTextView::MouseDown(BPoint where)
if (!IsFocus()) if (!IsFocus())
MakeFocus(); MakeFocus();
// hide the caret if it's visible _HideCaret();
if (fCaretVisible)
InvertCaret();
StopMouseTracking(); StopMouseTracking();
@@ -669,8 +667,7 @@ BTextView::KeyDown(const char *bytes, int32 numBytes)
// hide the cursor and caret // hide the cursor and caret
be_app->ObscureCursor(); be_app->ObscureCursor();
if (fCaretVisible) _HideCaret();
InvertCaret();
switch (keyPressed) { switch (keyPressed) {
case B_BACKSPACE: case B_BACKSPACE:
@@ -715,10 +712,8 @@ BTextView::KeyDown(const char *bytes, int32 numBytes)
} }
// draw the caret // draw the caret
if (fSelStart == fSelEnd) { if (fSelStart == fSelEnd)
if (!fCaretVisible) _ShowCaret();
InvertCaret();
}
} }
@@ -994,8 +989,7 @@ BTextView::SetText(const char *inText, int32 inLength, const text_run_array *inR
if (fSelStart != fSelEnd) if (fSelStart != fSelEnd)
Highlight(fSelStart, fSelEnd); Highlight(fSelStart, fSelEnd);
else { else {
if (fCaretVisible) _HideCaret();
InvertCaret();
} }
} }
@@ -1012,10 +1006,8 @@ BTextView::SetText(const char *inText, int32 inLength, const text_run_array *inR
ScrollToOffset(fSelStart); ScrollToOffset(fSelStart);
// draw the caret // draw the caret
if (fActive) { if (fActive)
if (!fCaretVisible) _ShowCaret();
InvertCaret();
}
} }
@@ -1056,10 +1048,8 @@ BTextView::SetText(BFile *inFile, int32 inOffset, int32 inLength,
ScrollToOffset(fSelStart); ScrollToOffset(fSelStart);
// draw the caret // draw the caret
if (fActive) { if (fActive)
if (!fCaretVisible) _ShowCaret();
InvertCaret();
}
} }
@@ -1120,10 +1110,8 @@ BTextView::Delete(int32 startOffset, int32 endOffset)
if (fActive) { if (fActive) {
if (fSelStart != fSelEnd) if (fSelStart != fSelEnd)
Highlight(fSelStart, fSelEnd); Highlight(fSelStart, fSelEnd);
else { else
if (fCaretVisible) _HideCaret();
InvertCaret();
}
} }
// remove data from buffer // remove data from buffer
DeleteText(startOffset, endOffset); DeleteText(startOffset, endOffset);
@@ -1140,10 +1128,8 @@ BTextView::Delete(int32 startOffset, int32 endOffset)
Refresh(startOffset, endOffset, true, true); Refresh(startOffset, endOffset, true, true);
// draw the caret // draw the caret
if (fActive) { if (fActive)
if (!fCaretVisible) _ShowCaret();
InvertCaret();
}
} }
@@ -1383,9 +1369,7 @@ BTextView::Select(int32 startOffset, int32 endOffset)
fStyles->InvalidateNullStyle(); fStyles->InvalidateNullStyle();
// hide the caret _HideCaret();
if (fCaretVisible)
InvertCaret();
if (startOffset == endOffset) { if (startOffset == endOffset) {
if (fSelStart != fSelEnd) { if (fSelStart != fSelEnd) {
@@ -2137,8 +2121,7 @@ BTextView::MakeEditable(bool editable)
fStyles->InvalidateNullStyle(); fStyles->InvalidateNullStyle();
if (Window() != NULL && fActive) { if (Window() != NULL && fActive) {
if (!fEditable) { if (!fEditable) {
if (fCaretVisible) _HideCaret();
InvertCaret();
CancelInputMethod(); CancelInputMethod();
} }
} }
@@ -2171,8 +2154,7 @@ BTextView::SetWordWrap(bool wrap)
if (fSelStart != fSelEnd) if (fSelStart != fSelEnd)
Highlight(fSelStart, fSelEnd); Highlight(fSelStart, fSelEnd);
else { else {
if (fCaretVisible) _HideCaret();
InvertCaret();
} }
} }
@@ -2183,10 +2165,8 @@ BTextView::SetWordWrap(bool wrap)
// show the caret, hilite the selection // show the caret, hilite the selection
if (fSelStart != fSelEnd && fSelectable) if (fSelStart != fSelEnd && fSelectable)
Highlight(fSelStart, fSelEnd); Highlight(fSelStart, fSelEnd);
else { else
if (!fCaretVisible) _ShowCaret();
InvertCaret();
}
} }
} }
} }
@@ -2352,8 +2332,8 @@ BTextView::MakeResizable(bool resize, BView *resizeView)
if (fSelStart != fSelEnd && fSelectable) if (fSelStart != fSelEnd && fSelectable)
Highlight(fSelStart, fSelEnd); Highlight(fSelStart, fSelEnd);
else if (fCaretVisible) else
InvertCaret(); _HideCaret();
} }
} }
} else { } else {
@@ -3751,6 +3731,22 @@ BTextView::DrawCaret(int32 offset)
} }
inline void
BTextView::_ShowCaret()
{
if (!fCaretVisible)
InvertCaret();
}
inline void
BTextView::_HideCaret()
{
if (fCaretVisible)
InvertCaret();
}
/*! \brief Inverts the blinking caret status. /*! \brief Inverts the blinking caret status.
Hides the caret if it is being shown, and if it's hidden, shows it. Hides the caret if it is being shown, and if it's hidden, shows it.
*/ */
@@ -4170,7 +4166,7 @@ BTextView::Activate()
Highlight(fSelStart, fSelEnd); Highlight(fSelStart, fSelEnd);
} else { } else {
if (fEditable) if (fEditable)
InvertCaret(); _ShowCaret();
} }
BPoint where; BPoint where;
@@ -4194,10 +4190,8 @@ BTextView::Deactivate()
if (fSelStart != fSelEnd) { if (fSelStart != fSelEnd) {
if (fSelectable) if (fSelectable)
Highlight(fSelStart, fSelEnd); Highlight(fSelStart, fSelEnd);
} else { } else
if (fCaretVisible) _HideCaret();
InvertCaret();
}
BPoint where; BPoint where;
ulong buttons; ulong buttons;