richedit: Implemented triple click selection.

oldstable
Dylan Smith 2008-07-07 11:04:02 -04:00 committed by Alexandre Julliard
parent 7c352b9638
commit 69cf4e9ac4
3 changed files with 78 additions and 7 deletions

View File

@ -787,6 +787,14 @@ ME_SelectByType(ME_TextEditor *editor, ME_SelectionType selectionType)
editor->pCursors[1].nOffset = 0;
break;
}
case stDocument:
/* Select everything with cursor anchored from the start of the text */
editor->nSelectionType = stDocument;
editor->pCursors[1].pRun = ME_FindItemFwd(editor->pBuffer->pFirst, diRun);
editor->pCursors[1].nOffset = 0;
editor->pCursors[0].pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun);
editor->pCursors[0].nOffset = 0;
break;
default: assert(0);
}
/* Store the anchor positions for extending the selection. */
@ -925,7 +933,7 @@ static void ME_ExtendAnchorSelection(ME_TextEditor *editor)
{
ME_Cursor tmp_cursor;
int curOfs, anchorStartOfs, anchorEndOfs;
if (editor->nSelectionType == stPosition)
if (editor->nSelectionType == stPosition || editor->nSelectionType == stDocument)
return;
curOfs = ME_GetCursorOfs(editor, 0);
anchorStartOfs = ME_GetCursorOfs(editor, 2);
@ -992,10 +1000,16 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum)
if (clickNum > 1)
{
editor->pCursors[1] = editor->pCursors[0];
if (x >= editor->selofs)
if (is_shift) {
if (x >= editor->selofs)
ME_SelectByType(editor, stWord);
else
ME_SelectByType(editor, stParagraph);
} else if (clickNum % 2 == 0) {
ME_SelectByType(editor, stWord);
else
} else {
ME_SelectByType(editor, stParagraph);
}
}
else if (!is_shift)
{
@ -1016,8 +1030,10 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum)
{
if (clickNum < 2) {
ME_SelectByType(editor, stLine);
} else {
} else if (clickNum % 2 == 0 || is_shift) {
ME_SelectByType(editor, stParagraph);
} else {
ME_SelectByType(editor, stDocument);
}
}
ME_InvalidateSelection(editor);
@ -1032,6 +1048,8 @@ void ME_MouseMove(ME_TextEditor *editor, int x, int y)
{
ME_Cursor tmp_cursor;
if (editor->nSelectionType == stDocument)
return;
y += ME_GetYScrollPos(editor);
tmp_cursor = editor->pCursors[0];

View File

@ -1612,6 +1612,57 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey)
return FALSE;
}
/* Process the message and calculate the new click count.
*
* returns: The click count if it is mouse down event, else returns 0. */
static int ME_CalculateClickCount(HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam)
{
static int clickNum = 0;
if (msg < WM_MOUSEFIRST || msg > WM_MOUSELAST)
return 0;
if ((msg == WM_LBUTTONDBLCLK) ||
(msg == WM_RBUTTONDBLCLK) ||
(msg == WM_MBUTTONDBLCLK) ||
(msg == WM_XBUTTONDBLCLK))
{
msg -= (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
}
if ((msg == WM_LBUTTONDOWN) ||
(msg == WM_RBUTTONDOWN) ||
(msg == WM_MBUTTONDOWN) ||
(msg == WM_XBUTTONDOWN))
{
static MSG prevClickMsg;
MSG clickMsg;
clickMsg.hwnd = hWnd;
clickMsg.message = msg;
clickMsg.wParam = wParam;
clickMsg.lParam = lParam;
clickMsg.time = GetMessageTime();
clickMsg.pt.x = LOWORD(lParam);
clickMsg.pt.x = HIWORD(lParam);
if ((clickNum != 0) &&
(clickMsg.message == prevClickMsg.message) &&
(clickMsg.hwnd == prevClickMsg.hwnd) &&
(clickMsg.wParam == prevClickMsg.wParam) &&
(clickMsg.time - prevClickMsg.time < GetDoubleClickTime()) &&
(abs(clickMsg.pt.x - prevClickMsg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
(abs(clickMsg.pt.y - prevClickMsg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
{
clickNum++;
} else {
clickNum = 1;
}
prevClickMsg = clickMsg;
} else {
return 0;
}
return clickNum;
}
static BOOL ME_SetCursor(ME_TextEditor *editor, int x)
{
if ((GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_SELECTIONBAR) &&
@ -2979,14 +3030,13 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
case WM_LBUTTONDBLCLK:
case WM_LBUTTONDOWN:
{
int clickNum = (msg == WM_LBUTTONDBLCLK) ? 2 : 1;
ME_CommitUndo(editor); /* End coalesced undos for typed characters */
if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
!ME_FilterEvent(editor, msg, &wParam, &lParam))
return 0;
SetFocus(hWnd);
ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam),
clickNum);
ME_CalculateClickCount(hWnd, msg, wParam, lParam));
SetCapture(hWnd);
ME_LinkNotify(editor,msg,wParam,lParam);
if (!ME_SetCursor(editor, LOWORD(lParam))) goto do_default;
@ -3004,6 +3054,8 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
case WM_LBUTTONUP:
if (GetCapture() == hWnd)
ReleaseCapture();
if (editor->nSelectionType == stDocument)
editor->nSelectionType = stPosition;
if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
!ME_FilterEvent(editor, msg, &wParam, &lParam))
return 0;

View File

@ -248,7 +248,8 @@ typedef enum {
stPosition = 0,
stWord,
stLine,
stParagraph
stParagraph,
stDocument
} ME_SelectionType;
typedef struct tagME_FontTableItem {