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
This commit is contained in:
@@ -294,7 +294,7 @@ TermBuffer::EraseBelow(const CurPos &pos)
|
|||||||
memset(fBuffer[ROW(row)] + col, 0, (fColumnSize - col ) * sizeof(term_buffer));
|
memset(fBuffer[ROW(row)] + col, 0, (fColumnSize - col ) * sizeof(term_buffer));
|
||||||
|
|
||||||
for (int i = row; i < fRowSize; i++) {
|
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;
|
fBuffer[ROW(bot)] = ptr;
|
||||||
EraseLine(bot);
|
_EraseLine(bot);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// scroll up
|
// scroll up
|
||||||
@@ -324,7 +324,7 @@ TermBuffer::ScrollRegion(int top, int bot, int dir, int num)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fBuffer[ROW(top)] = ptr;
|
fBuffer[ROW(top)] = ptr;
|
||||||
EraseLine(top);
|
_EraseLine(top);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -335,7 +335,7 @@ void
|
|||||||
TermBuffer::ScrollLine()
|
TermBuffer::ScrollLine()
|
||||||
{
|
{
|
||||||
for (int i = fRowSize; i < fRowSize * 2; i++) {
|
for (int i = fRowSize; i < fRowSize * 2; i++) {
|
||||||
EraseLine(i);
|
_EraseLine(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
fRowOffset++;
|
fRowOffset++;
|
||||||
@@ -359,10 +359,10 @@ TermBuffer::ResizeTo(int newRows, int newCols, int offset)
|
|||||||
|
|
||||||
if (newRows <= fRowSize) {
|
if (newRows <= fRowSize) {
|
||||||
for (i = newRows; i <= fRowSize; i++)
|
for (i = newRows; i <= fRowSize; i++)
|
||||||
EraseLine(i);
|
_EraseLine(i);
|
||||||
} else {
|
} else {
|
||||||
for (i = fRowSize; i <= newRows * 2; i++)
|
for (i = fRowSize; i <= newRows * 2; i++)
|
||||||
EraseLine(i);
|
_EraseLine(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
fCurrentColumnSize = newCols;
|
fCurrentColumnSize = newCols;
|
||||||
@@ -380,7 +380,7 @@ TermBuffer::Size() const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TermBuffer::EraseLine(int row)
|
TermBuffer::_EraseLine(int row)
|
||||||
{
|
{
|
||||||
memset(fBuffer[ROW(row)], 0, fColumnSize * sizeof(term_buffer));
|
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
|
bool
|
||||||
TermBuffer::FindWord(const CurPos &pos, CurPos *start, CurPos *end)
|
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)
|
if (start_x > x)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
fSelStart.Set(start_x, y);
|
|
||||||
if (start != NULL)
|
if (start != NULL)
|
||||||
start->Set(start_x, y);
|
start->Set(start_x, y);
|
||||||
|
|
||||||
fSelEnd.Set(x, y);
|
|
||||||
if (end != NULL)
|
if (end != NULL)
|
||||||
end->Set(x, y);
|
end->Set(x, y);
|
||||||
|
|
||||||
@@ -520,33 +511,33 @@ start:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Get a string from selected region.
|
//! Get a string from the given region.
|
||||||
void
|
void
|
||||||
TermBuffer::GetStringFromRegion(BString &str)
|
TermBuffer::GetStringFromRegion(BString &str, const CurPos &start, const CurPos &end)
|
||||||
{
|
{
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
if (fSelStart.y == fSelEnd.y) {
|
if (start.y == end.y) {
|
||||||
y = fSelStart.y;
|
y = start.y;
|
||||||
for (int x = fSelStart.x ; x <= fSelEnd.x; x++) {
|
for (int x = start.x ; x <= end.x; x++) {
|
||||||
GetCharFromRegion(x, y, str);
|
GetCharFromRegion(x, y, str);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
y = fSelStart.y;
|
y = start.y;
|
||||||
for (int x = fSelStart.x ; x < fCurrentColumnSize; x++) {
|
for (int x = start.x ; x < fCurrentColumnSize; x++) {
|
||||||
GetCharFromRegion(x, y, str);
|
GetCharFromRegion(x, y, str);
|
||||||
}
|
}
|
||||||
AvoidWaste(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++) {
|
for (int x = 0 ; x < fCurrentColumnSize; x++) {
|
||||||
GetCharFromRegion(x, y, str);
|
GetCharFromRegion(x, y, str);
|
||||||
}
|
}
|
||||||
AvoidWaste(str);
|
AvoidWaste(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
y = fSelEnd.y;
|
y = end.y;
|
||||||
for (int x = 0 ; x <= fSelEnd.x; x++) {
|
for (int x = 0 ; x <= end.x; x++) {
|
||||||
GetCharFromRegion(x, y, str);
|
GetCharFromRegion(x, y, str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public:
|
|||||||
//
|
//
|
||||||
int GetChar(int row, int col, uchar *u, ushort *attr);
|
int GetChar(int row, int col, uchar *u, ushort *attr);
|
||||||
int GetString(int row, int col, int num, 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 WriteChar(const CurPos &pos, const uchar *u, ushort attr);
|
||||||
void WriteCR(const CurPos &pos);
|
void WriteCR(const CurPos &pos);
|
||||||
@@ -96,13 +96,11 @@ public:
|
|||||||
|
|
||||||
const CurPos &GetSelectionStart() { return fSelStart; };
|
const CurPos &GetSelectionStart() { return fSelStart; };
|
||||||
const CurPos &GetSelectionEnd() { return fSelEnd; };
|
const CurPos &GetSelectionEnd() { return fSelEnd; };
|
||||||
|
|
||||||
int CheckSelectedRegion (const CurPos &pos);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Other methods
|
// 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);
|
void GetCharFromRegion (int x, int y, BString &str);
|
||||||
static void AvoidWaste (BString &str);
|
static void AvoidWaste (BString &str);
|
||||||
@@ -112,7 +110,7 @@ static void AvoidWaste (BString &str);
|
|||||||
int32 Size() const;
|
int32 Size() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void EraseLine(int line);
|
void _EraseLine(int line);
|
||||||
|
|
||||||
term_buffer **fBuffer;
|
term_buffer **fBuffer;
|
||||||
int fBufferSize;
|
int fBufferSize;
|
||||||
|
|||||||
@@ -762,7 +762,7 @@ TermView::ViewThread(void *data)
|
|||||||
int width, height;
|
int width, height;
|
||||||
sDrawRect pos;
|
sDrawRect pos;
|
||||||
|
|
||||||
//#define INVALIDATE
|
#define INVALIDATE
|
||||||
#ifndef INVALIDATE
|
#ifndef INVALIDATE
|
||||||
int i, j, count;
|
int i, j, count;
|
||||||
int m_flag;
|
int m_flag;
|
||||||
@@ -1578,7 +1578,7 @@ TermView::DoCopy()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
BString copyStr;
|
BString copyStr;
|
||||||
fTextBuffer->GetStringFromRegion(copyStr);
|
fTextBuffer->GetStringFromRegion(copyStr, fSelStart, fSelEnd);
|
||||||
|
|
||||||
if (be_clipboard->Lock()) {
|
if (be_clipboard->Lock()) {
|
||||||
BMessage *clipMsg = NULL;
|
BMessage *clipMsg = NULL;
|
||||||
@@ -1701,7 +1701,7 @@ TermView::MouseDown(BPoint where)
|
|||||||
if (HasSelection()) {
|
if (HasSelection()) {
|
||||||
// copy text from region
|
// copy text from region
|
||||||
BString copy;
|
BString copy;
|
||||||
fTextBuffer->GetStringFromRegion(copy);
|
fTextBuffer->GetStringFromRegion(copy, fSelStart, fSelEnd);
|
||||||
WritePTY((uchar *)copy.String(), copy.Length());
|
WritePTY((uchar *)copy.String(), copy.Length());
|
||||||
} else {
|
} else {
|
||||||
// copy text from clipboard.
|
// copy text from clipboard.
|
||||||
@@ -1747,7 +1747,7 @@ TermView::MouseDown(BPoint where)
|
|||||||
&& abs((int)(where.y - p.y)) < 4);
|
&& abs((int)(where.y - p.y)) < 4);
|
||||||
|
|
||||||
BString copyStr("");
|
BString copyStr("");
|
||||||
fTextBuffer->GetStringFromRegion(copyStr);
|
fTextBuffer->GetStringFromRegion(copyStr, fSelStart, fSelEnd);
|
||||||
|
|
||||||
BMessage msg(B_MIME_TYPE);
|
BMessage msg(B_MIME_TYPE);
|
||||||
msg.AddData("text/plain", B_MIME_TYPE, copyStr.String(), copyStr.Length());
|
msg.AddData("text/plain", B_MIME_TYPE, copyStr.String(), copyStr.Length());
|
||||||
@@ -2004,7 +2004,8 @@ TermView::SelectWord(BPoint where, int mod)
|
|||||||
|
|
||||||
pos = BPointToCurPos(where);
|
pos = BPointToCurPos(where);
|
||||||
flag = fTextBuffer->FindWord(pos, &start, &end);
|
flag = fTextBuffer->FindWord(pos, &start, &end);
|
||||||
|
fTextBuffer->Select(start, end);
|
||||||
|
|
||||||
if (mod & B_SHIFT_KEY) {
|
if (mod & B_SHIFT_KEY) {
|
||||||
|
|
||||||
if (flag) {
|
if (flag) {
|
||||||
@@ -2122,8 +2123,8 @@ TermView::Find(const BString &str, bool forwardSearch, bool matchCase, bool matc
|
|||||||
BString buffer;
|
BString buffer;
|
||||||
fTextBuffer->ToString(buffer);
|
fTextBuffer->ToString(buffer);
|
||||||
|
|
||||||
CurPos selectionstart = fTextBuffer->GetSelectionStart();
|
CurPos selectionstart = fSelStart;
|
||||||
CurPos selectionend = fTextBuffer->GetSelectionEnd();
|
CurPos selectionend = fSelEnd;
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
if (selectionstart.x >= 0 || selectionstart.y >= 0) {
|
if (selectionstart.x >= 0 || selectionstart.y >= 0) {
|
||||||
@@ -2205,7 +2206,7 @@ void
|
|||||||
TermView::GetSelection(BString &str)
|
TermView::GetSelection(BString &str)
|
||||||
{
|
{
|
||||||
str.SetTo("");
|
str.SetTo("");
|
||||||
fTextBuffer->GetStringFromRegion(str);
|
fTextBuffer->GetStringFromRegion(str, fSelStart, fSelEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user