From d342dd3f50b8e8c3210af0560b3993b7a2986ab3 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Fri, 29 Jun 2007 11:18:41 +0000 Subject: [PATCH] a small step towards removing (duplicate) selection logic from TermBuffer. Enabled invalidating in TextView instead of weird redrawing. Seems much faster. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21524 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/TermBuffer.cpp | 43 +++++++++++++------------------- src/apps/terminal/TermBuffer.h | 8 +++--- src/apps/terminal/TermView.cpp | 17 +++++++------ 3 files changed, 29 insertions(+), 39 deletions(-) diff --git a/src/apps/terminal/TermBuffer.cpp b/src/apps/terminal/TermBuffer.cpp index dfa4f47321..dad43ea95c 100644 --- a/src/apps/terminal/TermBuffer.cpp +++ b/src/apps/terminal/TermBuffer.cpp @@ -294,7 +294,7 @@ TermBuffer::EraseBelow(const CurPos &pos) memset(fBuffer[ROW(row)] + col, 0, (fColumnSize - col ) * sizeof(term_buffer)); for (int i = row; i < fRowSize; i++) { - EraseLine(i); + _EraseLine(i); } } @@ -312,7 +312,7 @@ TermBuffer::ScrollRegion(int top, int bot, int dir, int num) } fBuffer[ROW(bot)] = ptr; - EraseLine(bot); + _EraseLine(bot); } } else { // scroll up @@ -324,7 +324,7 @@ TermBuffer::ScrollRegion(int top, int bot, int dir, int num) } fBuffer[ROW(top)] = ptr; - EraseLine(top); + _EraseLine(top); } } } @@ -335,7 +335,7 @@ void TermBuffer::ScrollLine() { for (int i = fRowSize; i < fRowSize * 2; i++) { - EraseLine(i); + _EraseLine(i); } fRowOffset++; @@ -359,10 +359,10 @@ TermBuffer::ResizeTo(int newRows, int newCols, int offset) if (newRows <= fRowSize) { for (i = newRows; i <= fRowSize; i++) - EraseLine(i); + _EraseLine(i); } else { for (i = fRowSize; i <= newRows * 2; i++) - EraseLine(i); + _EraseLine(i); } fCurrentColumnSize = newCols; @@ -380,7 +380,7 @@ TermBuffer::Size() const void -TermBuffer::EraseLine(int row) +TermBuffer::_EraseLine(int row) { memset(fBuffer[ROW(row)], 0, fColumnSize * sizeof(term_buffer)); } @@ -422,13 +422,6 @@ TermBuffer::DeSelect() } -//! Check cursor position which be including selected area. -int -TermBuffer::CheckSelectedRegion (const CurPos &pos) -{ - return fSelStart.y == pos.y || fSelEnd.y == pos.y; -} - bool TermBuffer::FindWord(const CurPos &pos, CurPos *start, CurPos *end) @@ -459,11 +452,9 @@ TermBuffer::FindWord(const CurPos &pos, CurPos *start, CurPos *end) if (start_x > x) return false; - fSelStart.Set(start_x, y); if (start != NULL) start->Set(start_x, y); - fSelEnd.Set(x, y); if (end != NULL) end->Set(x, y); @@ -520,33 +511,33 @@ start: } -//! Get a string from selected region. +//! Get a string from the given region. void -TermBuffer::GetStringFromRegion(BString &str) +TermBuffer::GetStringFromRegion(BString &str, const CurPos &start, const CurPos &end) { int y; - if (fSelStart.y == fSelEnd.y) { - y = fSelStart.y; - for (int x = fSelStart.x ; x <= fSelEnd.x; x++) { + if (start.y == end.y) { + y = start.y; + for (int x = start.x ; x <= end.x; x++) { GetCharFromRegion(x, y, str); } } else { - y = fSelStart.y; - for (int x = fSelStart.x ; x < fCurrentColumnSize; x++) { + y = start.y; + for (int x = start.x ; x < fCurrentColumnSize; x++) { GetCharFromRegion(x, y, str); } AvoidWaste(str); - for (y = fSelStart.y + 1 ; y < fSelEnd.y; y++) { + for (y = start.y + 1 ; y < end.y; y++) { for (int x = 0 ; x < fCurrentColumnSize; x++) { GetCharFromRegion(x, y, str); } AvoidWaste(str); } - y = fSelEnd.y; - for (int x = 0 ; x <= fSelEnd.x; x++) { + y = end.y; + for (int x = 0 ; x <= end.x; x++) { GetCharFromRegion(x, y, str); } } diff --git a/src/apps/terminal/TermBuffer.h b/src/apps/terminal/TermBuffer.h index aa631d2282..a63e020d4b 100644 --- a/src/apps/terminal/TermBuffer.h +++ b/src/apps/terminal/TermBuffer.h @@ -60,7 +60,7 @@ public: // int GetChar(int row, int col, uchar *u, ushort *attr); int GetString(int row, int col, int num, uchar *u, ushort *attr); - void GetStringFromRegion (BString ©Str); + void GetStringFromRegion(BString ©Str, const CurPos &start, const CurPos &end); void WriteChar(const CurPos &pos, const uchar *u, ushort attr); void WriteCR(const CurPos &pos); @@ -96,13 +96,11 @@ public: const CurPos &GetSelectionStart() { return fSelStart; }; const CurPos &GetSelectionEnd() { return fSelEnd; }; - - int CheckSelectedRegion (const CurPos &pos); // // Other methods // - bool FindWord (const CurPos &pos, CurPos *start, CurPos *end); + bool FindWord(const CurPos &pos, CurPos *start, CurPos *end); void GetCharFromRegion (int x, int y, BString &str); static void AvoidWaste (BString &str); @@ -112,7 +110,7 @@ static void AvoidWaste (BString &str); int32 Size() const; private: - void EraseLine(int line); + void _EraseLine(int line); term_buffer **fBuffer; int fBufferSize; diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index b9f35abc79..b2c0f0cb2d 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -762,7 +762,7 @@ TermView::ViewThread(void *data) int width, height; sDrawRect pos; -//#define INVALIDATE +#define INVALIDATE #ifndef INVALIDATE int i, j, count; int m_flag; @@ -1578,7 +1578,7 @@ TermView::DoCopy() return; BString copyStr; - fTextBuffer->GetStringFromRegion(copyStr); + fTextBuffer->GetStringFromRegion(copyStr, fSelStart, fSelEnd); if (be_clipboard->Lock()) { BMessage *clipMsg = NULL; @@ -1701,7 +1701,7 @@ TermView::MouseDown(BPoint where) if (HasSelection()) { // copy text from region BString copy; - fTextBuffer->GetStringFromRegion(copy); + fTextBuffer->GetStringFromRegion(copy, fSelStart, fSelEnd); WritePTY((uchar *)copy.String(), copy.Length()); } else { // copy text from clipboard. @@ -1747,7 +1747,7 @@ TermView::MouseDown(BPoint where) && abs((int)(where.y - p.y)) < 4); BString copyStr(""); - fTextBuffer->GetStringFromRegion(copyStr); + fTextBuffer->GetStringFromRegion(copyStr, fSelStart, fSelEnd); BMessage msg(B_MIME_TYPE); msg.AddData("text/plain", B_MIME_TYPE, copyStr.String(), copyStr.Length()); @@ -2004,7 +2004,8 @@ TermView::SelectWord(BPoint where, int mod) pos = BPointToCurPos(where); flag = fTextBuffer->FindWord(pos, &start, &end); - + fTextBuffer->Select(start, end); + if (mod & B_SHIFT_KEY) { if (flag) { @@ -2122,8 +2123,8 @@ TermView::Find(const BString &str, bool forwardSearch, bool matchCase, bool matc BString buffer; fTextBuffer->ToString(buffer); - CurPos selectionstart = fTextBuffer->GetSelectionStart(); - CurPos selectionend = fTextBuffer->GetSelectionEnd(); + CurPos selectionstart = fSelStart; + CurPos selectionend = fSelEnd; int offset = 0; if (selectionstart.x >= 0 || selectionstart.y >= 0) { @@ -2205,7 +2206,7 @@ void TermView::GetSelection(BString &str) { str.SetTo(""); - fTextBuffer->GetStringFromRegion(str); + fTextBuffer->GetStringFromRegion(str, fSelStart, fSelEnd); }