Selecting text from right to left didn't work. I disabled the use of

ResizeSelection() because it didn't support this. Selecting text flicker 
a lot now, it will be fixed later. Selection should be changed to work a 
bit more like BTextView. This fixes bug #1638


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23058 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2007-12-04 10:58:31 +00:00
parent dc5e011806
commit ee3f1027be
2 changed files with 38 additions and 61 deletions
+35 -58
View File
@@ -41,6 +41,7 @@
#include <termios.h> #include <termios.h>
#include <new> #include <new>
#include <algorithm>
// defined VTKeyTbl.c // defined VTKeyTbl.c
extern int function_keycode_table[]; extern int function_keycode_table[];
@@ -167,7 +168,7 @@ TermView::TermView(BRect frame, int32 argc, const char **argv, int32 historySize
fScrBot(fTermRows - 1), fScrBot(fTermRows - 1),
fScrBufSize(historySize), fScrBufSize(historySize),
fScrRegionSet(0), fScrRegionSet(0),
fPreviousMousePoint(0, 0), fClickPoint(0, 0),
fSelStart(-1, -1), fSelStart(-1, -1),
fSelEnd(-1, -1), fSelEnd(-1, -1),
fMouseTracking(false), fMouseTracking(false),
@@ -215,7 +216,7 @@ TermView::TermView(int rows, int columns, int32 argc, const char **argv, int32 h
fScrBot(fTermRows - 1), fScrBot(fTermRows - 1),
fScrBufSize(historySize), fScrBufSize(historySize),
fScrRegionSet(0), fScrRegionSet(0),
fPreviousMousePoint(0, 0), fClickPoint(0, 0),
fSelStart(-1, -1), fSelStart(-1, -1),
fSelEnd(-1, -1), fSelEnd(-1, -1),
fMouseTracking(false), fMouseTracking(false),
@@ -264,7 +265,7 @@ TermView::TermView(BMessage *archive)
fScrBot(fTermRows - 1), fScrBot(fTermRows - 1),
fScrBufSize(1000), fScrBufSize(1000),
fScrRegionSet(0), fScrRegionSet(0),
fPreviousMousePoint(0, 0), fClickPoint(0, 0),
fSelStart(-1, -1), fSelStart(-1, -1),
fSelEnd(-1, -1), fSelEnd(-1, -1),
fMouseTracking(false), fMouseTracking(false),
@@ -1825,8 +1826,6 @@ TermView::_WritePTY(const uchar *text, int numBytes)
void void
TermView::MouseDown(BPoint where) TermView::MouseDown(BPoint where)
{ {
// TODO: Get rid of the extra thread for mouse tracking,
// and implement it using something like BTextView uses.
if (!IsFocus()) if (!IsFocus())
MakeFocus(); MakeFocus();
@@ -1879,7 +1878,7 @@ TermView::MouseDown(BPoint where)
} }
// If mouse has a lot of movement, disable double/triple click. // If mouse has a lot of movement, disable double/triple click.
/*BPoint inPoint = fPreviousMousePoint - where; /*BPoint inPoint = fClickPoint - where;
if (abs((int)inPoint.x) > 16 || abs((int)inPoint.y) > 16) if (abs((int)inPoint.x) > 16 || abs((int)inPoint.y) > 16)
clicks = 1; clicks = 1;
*/ */
@@ -1887,7 +1886,7 @@ TermView::MouseDown(BPoint where)
SetMouseEventMask(B_POINTER_EVENTS | B_KEYBOARD_EVENTS, SetMouseEventMask(B_POINTER_EVENTS | B_KEYBOARD_EVENTS,
B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS); B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS);
fPreviousMousePoint = where; fClickPoint = where;
if (mod & B_SHIFT_KEY) if (mod & B_SHIFT_KEY)
_AddSelectRegion(_BPointToCurPos(where)); _AddSelectRegion(_BPointToCurPos(where));
@@ -1927,58 +1926,32 @@ TermView::MouseMoved(BPoint where, uint32 transit, const BMessage *message)
if (!fMouseTracking) if (!fMouseTracking)
return; return;
bool selected = _HasSelection(); CurPos startPos = _BPointToCurPos(fClickPoint);
//int32 button;
//Window()->CurrentMessage()->FindInt32("buttons", &button);
CurPos startPos = _BPointToCurPos(fPreviousMousePoint);
CurPos endPos = _BPointToCurPos(where); CurPos endPos = _BPointToCurPos(where);
if (endPos.y < 0) if (endPos.y < 0)
return; return;
if (!selected) { _DeSelect();
_Select(startPos, endPos); _Select(startPos, endPos);
selected = true;
} else {
// Align cursor point to text.
if (startPos == endPos)
return;
if (endPos > startPos) { // Scroll check
where.x -= fFontWidth / 2; if (fScrollBar != NULL) {
endPos = _BPointToCurPos(where); // Get now scroll point
//edpos.x--; float scrollStart, scrollEnd;
if (endPos.x < 0) fScrollBar->GetRange(&scrollStart, &scrollEnd);
endPos.x = 0; float scrollPos = fScrollBar->Value();
} else if (endPos < startPos) {
where.x += fFontWidth / 2; if (where.y < Bounds().LeftTop().y ) {
endPos = _BPointToCurPos(where); // mouse point left of window
//edpos.x++; if (scrollPos != scrollStart)
if (endPos.x > fTermColumns) ScrollTo(0, where.y);
endPos.x = fTermColumns;
} }
// Scroll check if (where.y > Bounds().LeftBottom().y) {
if (fScrollBar != NULL) { // mouse point left of window
// Get now scroll point if (scrollPos != scrollEnd)
float scrollStart, scrollEnd; ScrollTo(0, where.y);
fScrollBar->GetRange(&scrollStart, &scrollEnd);
float scrollPos = fScrollBar->Value();
if (where.y < Bounds().LeftTop().y ) {
// mouse point left of window
if (scrollPos != scrollStart)
ScrollTo(0, where.y);
}
if (where.y > Bounds().LeftBottom().y) {
// mouse point left of window
if (scrollPos != scrollEnd)
ScrollTo(0, where.y);
}
} }
_ResizeSelectRegion(endPos);
} }
} }
@@ -1995,6 +1968,9 @@ TermView::MouseUp(BPoint where)
void void
TermView::_Select(CurPos start, CurPos end) TermView::_Select(CurPos start, CurPos end)
{ {
if (end < start)
std::swap(start, end);
if (start.x < 0) if (start.x < 0)
start.x = 0; start.x = 0;
if (end.x >= fTermColumns) if (end.x >= fTermColumns)
@@ -2104,6 +2080,8 @@ TermView::_AddSelectRegion(CurPos pos)
void void
TermView::_ResizeSelectRegion(CurPos pos) TermView::_ResizeSelectRegion(CurPos pos)
{ {
//TODO: Broken. Selecting from right to left doesn't work.
CurPos inPos = fSelEnd; CurPos inPos = fSelEnd;
// error check, and if mouse point to a plase full width character, // error check, and if mouse point to a plase full width character,
@@ -2127,9 +2105,10 @@ TermView::_ResizeSelectRegion(CurPos pos)
if (pos.x >= fTermColumns) if (pos.x >= fTermColumns)
pos.x = fTermColumns - 1; pos.x = fTermColumns - 1;
} }
fSelEnd = pos; fSelEnd = pos;
fTextBuffer->Select(fSelStart, pos); fTextBuffer->Select(fSelStart, fSelEnd);
_TermDrawSelectedRegion(inPos, pos); _TermDrawSelectedRegion(inPos, pos);
} }
@@ -2189,14 +2168,12 @@ TermView::_SelectWord(BPoint where, int mod)
void void
TermView::_SelectLine(BPoint where, int mod) TermView::_SelectLine(BPoint where, int mod)
{ {
CurPos start, end, pos; CurPos pos = _BPointToCurPos(where);
pos = _BPointToCurPos(where);
if (mod & B_SHIFT_KEY) { if (mod & B_SHIFT_KEY) {
start = CurPos(0, pos.y); CurPos start = CurPos(0, pos.y);
end = CurPos(fTermColumns - 1, pos.y); CurPos end = CurPos(fTermColumns - 1, pos.y);
if (start < fSelStart) if (start < fSelStart)
_AddSelectRegion(start); _AddSelectRegion(start);
@@ -2406,7 +2383,7 @@ TermView::InitiateDrag()
BString copyStr(""); BString copyStr("");
fTextBuffer->GetStringFromRegion(copyStr, fSelStart, fSelEnd); fTextBuffer->GetStringFromRegion(copyStr, fSelStart, fSelEnd);
BMessage message(B_MIME_TYPE); BMessage message(B_MIME_DATA);
message.AddData("text/plain", B_MIME_TYPE, copyStr.String(), copyStr.Length()); message.AddData("text/plain", B_MIME_TYPE, copyStr.String(), copyStr.Length());
BPoint start = _CurPosToBPoint(fSelStart); BPoint start = _CurPosToBPoint(fSelStart);
+1 -1
View File
@@ -259,7 +259,7 @@ private:
int32 fScrBufSize; int32 fScrBufSize;
bool fScrRegionSet; bool fScrRegionSet;
BPoint fPreviousMousePoint; BPoint fClickPoint;
// view selection // view selection
CurPos fSelStart; CurPos fSelStart;