From 08a6ab444bfb2c09e42517f899158f57a64b3200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 15 Oct 2008 14:06:25 +0000 Subject: [PATCH] * Added a _MouseDistanceSinceLastClick() that returns the square of the pixel distance of the last click and the point passed in. * Use this one to delay starting of character wide selections. * Also, treat double/triple clicks as single clicks if the mouse moved too far. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28132 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/TermView.cpp | 30 ++++++++++++++++++++---------- src/apps/terminal/TermView.h | 3 +++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index 5a5111dd92..59ec366151 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -1802,6 +1802,15 @@ TermView::_WritePTY(const char* text, int32 numBytes) } +//! Returns the square of the actual pixel distance between both points +float +TermView::_MouseDistanceSinceLastClick(BPoint where) +{ + return (fLastClickPoint.x - where.x) * (fLastClickPoint.x - where.x) + + (fLastClickPoint.y - where.y) * (fLastClickPoint.y - where.y); +} + + void TermView::MouseDown(BPoint where) { @@ -1816,6 +1825,7 @@ TermView::MouseDown(BPoint where) // paste button if ((buttons & (B_SECONDARY_MOUSE_BUTTON | B_TERTIARY_MOUSE_BUTTON)) != 0) { Paste(gMouseClipboard); + fLastClickPoint = where; return; } @@ -1850,14 +1860,12 @@ TermView::MouseDown(BPoint where) } } - // If mouse has a lot of movement, disable double/triple click. - /*BPoint inPoint = fClickPoint - where; - if (abs((int)inPoint.x) > 16 || abs((int)inPoint.y) > 16) + // If mouse has moved too much, disable double/triple click. + if (_MouseDistanceSinceLastClick(where) > 8) clicks = 1; - */ SetMouseEventMask(B_POINTER_EVENTS | B_KEYBOARD_EVENTS, - B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS); + B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS); TermPos clickPos = _ConvertToTerminal(where); @@ -1876,7 +1884,7 @@ TermView::MouseDown(BPoint where) switch (clicks) { case 1: - fMouseTracking = true; + fCheckMouseTracking = true; fSelectGranularity = SELECT_CHARS; break; @@ -1892,17 +1900,19 @@ TermView::MouseDown(BPoint where) fSelectGranularity = SELECT_LINES; break; } - return; } - BView::MouseDown(where); + fLastClickPoint = where; } void TermView::MouseMoved(BPoint where, uint32 transit, const BMessage *message) { - BView::MouseMoved(where, transit, message); + if (fCheckMouseTracking) { + if (_MouseDistanceSinceLastClick(where) > 9) + fMouseTracking = true; + } if (!fMouseTracking) return; @@ -1962,7 +1972,7 @@ TermView::MouseMoved(BPoint where, uint32 transit, const BMessage *message) void TermView::MouseUp(BPoint where) { - BView::MouseUp(where); + fCheckMouseTracking = false; fMouseTracking = false; if (fAutoScrollRunner != NULL) { diff --git a/src/apps/terminal/TermView.h b/src/apps/terminal/TermView.h index 6de9bad54d..8a12bb4720 100644 --- a/src/apps/terminal/TermView.h +++ b/src/apps/terminal/TermView.h @@ -150,6 +150,7 @@ private: // void _ConfirmString(const char *, int32); // selection + float _MouseDistanceSinceLastClick(BPoint where); void _Select(TermPos start, TermPos end, bool inclusive, bool setInitialSelection); void _ExtendSelection(TermPos, bool inclusive, @@ -242,7 +243,9 @@ private: TermPos fInitialSelectionStart; TermPos fInitialSelectionEnd; bool fMouseTracking; + bool fCheckMouseTracking; int fSelectGranularity; + BPoint fLastClickPoint; // Input Method parameter. int fIMViewPtr;