Dylan Smith : richedit: Use ME_Cursor instead of offsets for ME_CharFromPos .
Alexandre Julliard
julliard at winehq.org
Thu Aug 13 10:40:53 CDT 2009
Module: wine
Branch: master
Commit: 02228ee176a2e1403cb4320b13febe6d9b0b5179
URL: http://source.winehq.org/git/wine.git/?a=commit;h=02228ee176a2e1403cb4320b13febe6d9b0b5179
Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date: Thu Aug 13 08:44:09 2009 -0400
richedit: Use ME_Cursor instead of offsets for ME_CharFromPos.
---
dlls/riched20/caret.c | 16 +++++++++-------
dlls/riched20/editor.c | 32 ++++++++++++++++++--------------
dlls/riched20/editor.h | 2 +-
3 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index 0cece5e..fe594a0 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -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;
}
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 0b7ee7f..e56d8d4 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -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, ¶, &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;
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 3dc00b8..1cffe99 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -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);
More information about the wine-cvs
mailing list