Commit 02228ee1 authored by Dylan Smith's avatar Dylan Smith Committed by Alexandre Julliard

richedit: Use ME_Cursor instead of offsets for ME_CharFromPos.

parent a69ef265
......@@ -1004,30 +1004,32 @@ static BOOL ME_FindPixelPos(ME_TextEditor *editor, int x, int y,
}
/* Returns the character offset closest to the pixel position
/* Sets the cursor to the position closest to the pixel position
*
* x & y are pixel positions in client coordinates.
*
* isExact will be set to TRUE if the run is directly under the pixel
* position, FALSE if it not, unless isExact is set to NULL.
*
* return FALSE if outside client area and the cursor is not set,
* otherwise TRUE is returned.
*/
int ME_CharFromPos(ME_TextEditor *editor, int x, int y, BOOL *isExact)
BOOL ME_CharFromPos(ME_TextEditor *editor, int x, int y,
ME_Cursor *cursor, BOOL *isExact)
{
ME_Cursor cursor;
RECT rc;
BOOL bResult;
ITextHost_TxGetClientRect(editor->texthost, &rc);
if (x < 0 || y < 0 || x >= rc.right || y >= rc.bottom) {
if (isExact) *isExact = FALSE;
return -1;
return FALSE;
}
x += editor->horz_si.nPos;
y += editor->vert_si.nPos;
bResult = ME_FindPixelPos(editor, x, y, &cursor, NULL);
bResult = ME_FindPixelPos(editor, x, y, cursor, NULL);
if (isExact) *isExact = bResult;
return cursor.pPara->member.para.nCharOfs
+ cursor.pRun->member.run.nCharOfs + cursor.nOffset;
return TRUE;
}
......
......@@ -2476,9 +2476,9 @@ static int ME_CalculateClickCount(ME_TextEditor *editor, UINT msg, WPARAM wParam
static BOOL ME_SetCursor(ME_TextEditor *editor)
{
ME_Cursor cursor;
POINT pt;
BOOL isExact;
int offset;
SCROLLBARINFO sbi;
DWORD messagePos = GetMessagePos();
pt.x = (short)LOWORD(messagePos);
......@@ -2533,13 +2533,11 @@ static BOOL ME_SetCursor(ME_TextEditor *editor)
ITextHost_TxSetCursor(editor->texthost, hLeft, FALSE);
return TRUE;
}
offset = ME_CharFromPos(editor, pt.x, pt.y, &isExact);
ME_CharFromPos(editor, pt.x, pt.y, &cursor, &isExact);
if (isExact)
{
ME_Cursor cursor;
ME_Run *run;
ME_CursorFromCharOfs(editor, offset, &cursor);
run = &cursor.pRun->member.run;
if (run->style->fmt.dwMask & CFM_LINK &&
run->style->fmt.dwEffects & CFE_LINK)
......@@ -2553,6 +2551,7 @@ static BOOL ME_SetCursor(ME_TextEditor *editor)
if (ME_IsSelection(editor))
{
int selStart, selEnd;
int offset = ME_GetCursorOfs(&cursor);
ME_GetSelectionOfs(editor, &selStart, &selEnd);
if (selStart <= offset && selEnd >= offset) {
......@@ -2926,20 +2925,17 @@ get_msg_name(UINT msg)
static void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam)
{
int x,y;
ME_DisplayItem *para, *run;
BOOL isExact;
int nCharOfs; /* The start of the clicked text. Absolute character offset */
ME_Cursor cursor; /* The start of the clicked text. */
ENLINK info;
x = (short)LOWORD(lParam);
y = (short)HIWORD(lParam);
nCharOfs = ME_CharFromPos(editor, x, y, &isExact);
ME_CharFromPos(editor, x, y, &cursor, &isExact);
if (!isExact) return;
ME_RunOfsFromCharOfs(editor, nCharOfs, &para, &run, NULL);
if ((run->member.run.style->fmt.dwMask & CFM_LINK)
&& (run->member.run.style->fmt.dwEffects & CFE_LINK))
if (cursor.pRun->member.run.style->fmt.dwMask & CFM_LINK &&
cursor.pRun->member.run.style->fmt.dwEffects & CFE_LINK)
{ /* The clicked run has CFE_LINK set */
info.nmhdr.hwndFrom = editor->hWnd;
info.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID);
......@@ -2947,8 +2943,9 @@ static void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM
info.msg = msg;
info.wParam = wParam;
info.lParam = lParam;
info.chrg.cpMin = ME_CharOfsFromRunOfs(editor, para, run, 0);
info.chrg.cpMax = info.chrg.cpMin + run->member.run.strText->nLen;
cursor.nOffset = 0;
info.chrg.cpMin = ME_GetCursorOfs(&cursor);
info.chrg.cpMax = info.chrg.cpMin + cursor.pRun->member.run.strText->nLen;
SendMessageW(GetParent(editor->hWnd), WM_NOTIFY,info.nmhdr.idFrom, (LPARAM)&info);
}
}
......@@ -3824,7 +3821,14 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
case EM_SETZOOM:
return ME_SetZoom(editor, wParam, lParam);
case EM_CHARFROMPOS:
return ME_CharFromPos(editor, ((POINTL *)lParam)->x, ((POINTL *)lParam)->y, NULL);
{
ME_Cursor cursor;
if (ME_CharFromPos(editor, ((POINTL *)lParam)->x, ((POINTL *)lParam)->y,
&cursor, NULL))
return ME_GetCursorOfs(&cursor);
else
return -1;
}
case EM_POSFROMCHAR:
{
ME_DisplayItem *pPara, *pRun;
......
......@@ -162,7 +162,7 @@ int ME_SetSelection(ME_TextEditor *editor, int from, int to);
void ME_HideCaret(ME_TextEditor *ed);
void ME_ShowCaret(ME_TextEditor *ed);
void ME_MoveCaret(ME_TextEditor *ed);
int ME_CharFromPos(ME_TextEditor *editor, int x, int y, BOOL *isExact);
BOOL ME_CharFromPos(ME_TextEditor *editor, int x, int y, ME_Cursor *cursor, BOOL *isExact);
void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum);
void ME_MouseMove(ME_TextEditor *editor, int x, int y);
BOOL ME_DeleteTextAtCursor(ME_TextEditor *editor, int nCursor, int nChars);
......
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