Commit 69cf4e9a authored by Dylan Smith's avatar Dylan Smith Committed by Alexandre Julliard

richedit: Implemented triple click selection.

parent 7c352b96
...@@ -787,6 +787,14 @@ ME_SelectByType(ME_TextEditor *editor, ME_SelectionType selectionType) ...@@ -787,6 +787,14 @@ ME_SelectByType(ME_TextEditor *editor, ME_SelectionType selectionType)
editor->pCursors[1].nOffset = 0; editor->pCursors[1].nOffset = 0;
break; 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); default: assert(0);
} }
/* Store the anchor positions for extending the selection. */ /* Store the anchor positions for extending the selection. */
...@@ -925,7 +933,7 @@ static void ME_ExtendAnchorSelection(ME_TextEditor *editor) ...@@ -925,7 +933,7 @@ static void ME_ExtendAnchorSelection(ME_TextEditor *editor)
{ {
ME_Cursor tmp_cursor; ME_Cursor tmp_cursor;
int curOfs, anchorStartOfs, anchorEndOfs; int curOfs, anchorStartOfs, anchorEndOfs;
if (editor->nSelectionType == stPosition) if (editor->nSelectionType == stPosition || editor->nSelectionType == stDocument)
return; return;
curOfs = ME_GetCursorOfs(editor, 0); curOfs = ME_GetCursorOfs(editor, 0);
anchorStartOfs = ME_GetCursorOfs(editor, 2); anchorStartOfs = ME_GetCursorOfs(editor, 2);
...@@ -992,10 +1000,16 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum) ...@@ -992,10 +1000,16 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum)
if (clickNum > 1) if (clickNum > 1)
{ {
editor->pCursors[1] = editor->pCursors[0]; 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); ME_SelectByType(editor, stWord);
else } else {
ME_SelectByType(editor, stParagraph); ME_SelectByType(editor, stParagraph);
}
} }
else if (!is_shift) else if (!is_shift)
{ {
...@@ -1016,8 +1030,10 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum) ...@@ -1016,8 +1030,10 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum)
{ {
if (clickNum < 2) { if (clickNum < 2) {
ME_SelectByType(editor, stLine); ME_SelectByType(editor, stLine);
} else { } else if (clickNum % 2 == 0 || is_shift) {
ME_SelectByType(editor, stParagraph); ME_SelectByType(editor, stParagraph);
} else {
ME_SelectByType(editor, stDocument);
} }
} }
ME_InvalidateSelection(editor); ME_InvalidateSelection(editor);
...@@ -1032,6 +1048,8 @@ void ME_MouseMove(ME_TextEditor *editor, int x, int y) ...@@ -1032,6 +1048,8 @@ void ME_MouseMove(ME_TextEditor *editor, int x, int y)
{ {
ME_Cursor tmp_cursor; ME_Cursor tmp_cursor;
if (editor->nSelectionType == stDocument)
return;
y += ME_GetYScrollPos(editor); y += ME_GetYScrollPos(editor);
tmp_cursor = editor->pCursors[0]; tmp_cursor = editor->pCursors[0];
......
...@@ -1612,6 +1612,57 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey) ...@@ -1612,6 +1612,57 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey)
return FALSE; 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) static BOOL ME_SetCursor(ME_TextEditor *editor, int x)
{ {
if ((GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_SELECTIONBAR) && if ((GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_SELECTIONBAR) &&
...@@ -2979,14 +3030,13 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, ...@@ -2979,14 +3030,13 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
case WM_LBUTTONDBLCLK: case WM_LBUTTONDBLCLK:
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
{ {
int clickNum = (msg == WM_LBUTTONDBLCLK) ? 2 : 1;
ME_CommitUndo(editor); /* End coalesced undos for typed characters */ ME_CommitUndo(editor); /* End coalesced undos for typed characters */
if ((editor->nEventMask & ENM_MOUSEEVENTS) && if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
!ME_FilterEvent(editor, msg, &wParam, &lParam)) !ME_FilterEvent(editor, msg, &wParam, &lParam))
return 0; return 0;
SetFocus(hWnd); SetFocus(hWnd);
ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam), ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam),
clickNum); ME_CalculateClickCount(hWnd, msg, wParam, lParam));
SetCapture(hWnd); SetCapture(hWnd);
ME_LinkNotify(editor,msg,wParam,lParam); ME_LinkNotify(editor,msg,wParam,lParam);
if (!ME_SetCursor(editor, LOWORD(lParam))) goto do_default; if (!ME_SetCursor(editor, LOWORD(lParam))) goto do_default;
...@@ -3004,6 +3054,8 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, ...@@ -3004,6 +3054,8 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
case WM_LBUTTONUP: case WM_LBUTTONUP:
if (GetCapture() == hWnd) if (GetCapture() == hWnd)
ReleaseCapture(); ReleaseCapture();
if (editor->nSelectionType == stDocument)
editor->nSelectionType = stPosition;
if ((editor->nEventMask & ENM_MOUSEEVENTS) && if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
!ME_FilterEvent(editor, msg, &wParam, &lParam)) !ME_FilterEvent(editor, msg, &wParam, &lParam))
return 0; return 0;
......
...@@ -248,7 +248,8 @@ typedef enum { ...@@ -248,7 +248,8 @@ typedef enum {
stPosition = 0, stPosition = 0,
stWord, stWord,
stLine, stLine,
stParagraph stParagraph,
stDocument
} ME_SelectionType; } ME_SelectionType;
typedef struct tagME_FontTableItem { typedef struct tagME_FontTableItem {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment