Dylan Smith : richedit: Fixed EM_POSFROMCHAR for pos of text length.

Alexandre Julliard julliard at winehq.org
Wed Oct 22 08:00:31 CDT 2008


Module: wine
Branch: master
Commit: 46d79b0363494426d1c41cb1eccd88f0926d83b3
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=46d79b0363494426d1c41cb1eccd88f0926d83b3

Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date:   Wed Oct 22 02:22:41 2008 -0400

richedit: Fixed EM_POSFROMCHAR for pos of text length.

For some reason EM_POSFROMCHAR was returning 0 when the position was
equal to the end of the text, or beyond the end of the text. Instead
it should use the position at the end of the text for both these
cases.  The x value was also seen to be offset by 1 according to the
tests.

---

 dlls/riched20/editor.c       |   19 ++++++++-----------
 dlls/riched20/tests/editor.c |    6 +-----
 dlls/riched32/tests/editor.c |    4 ----
 3 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index a4a26cc..d92397e 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -3543,18 +3543,15 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
     if (wParam >= 0x40000)
         nCharOfs = lParam;
     nLength = ME_GetTextLength(editor);
-    
-    if (nCharOfs < nLength) { 
-        ME_RunOfsFromCharOfs(editor, nCharOfs, &pRun, &nOffset);
-        assert(pRun->type == diRun);
-        pt.y = pRun->member.run.pt.y;
-        pt.x = pRun->member.run.pt.x + ME_PointFromChar(editor, &pRun->member.run, nOffset);
-        pt.y += ME_GetParagraph(pRun)->member.para.pt.y;
-    } else {
-        pt.x = 0;
-        pt.y = editor->pBuffer->pLast->member.para.pt.y;
-    }
+    nCharOfs = min(nCharOfs, nLength);
+
+    ME_RunOfsFromCharOfs(editor, nCharOfs, &pRun, &nOffset);
+    assert(pRun->type == diRun);
+    pt.y = pRun->member.run.pt.y;
+    pt.x = pRun->member.run.pt.x + ME_PointFromChar(editor, &pRun->member.run, nOffset);
+    pt.y += ME_GetParagraph(pRun)->member.para.pt.y;
     pt.x += editor->selofs;
+    pt.x++; /* for some reason native offsets x by one */
 
     si.cbSize = sizeof(si);
     si.fMask = SIF_POS;
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index d57aab0..a6c4a82 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -567,9 +567,7 @@ static void test_EM_POSFROMCHAR(void)
     if (i == 0)
     {
       ok(HIWORD(result) == 0, "EM_POSFROMCHAR reports y=%d, expected 0\n", HIWORD(result));
-      todo_wine {
       ok(LOWORD(result) == 1, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result));
-      }
       xpos = LOWORD(result);
     }
     else if (i == 1)
@@ -623,9 +621,7 @@ static void test_EM_POSFROMCHAR(void)
 
   result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, 0, 0);
   ok(HIWORD(result) == 0, "EM_POSFROMCHAR reports y=%d, expected 0\n", HIWORD(result));
-  todo_wine {
   ok(LOWORD(result) == 1, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result));
-  }
   xpos = LOWORD(result);
 
   SendMessage(hwndRichEdit, WM_HSCROLL, SB_LINERIGHT, 0);
@@ -647,7 +643,7 @@ static void test_EM_POSFROMCHAR(void)
   xpos = pt.x;
   SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM)&pt,
               SendMessage(hwndRichEdit, WM_GETTEXTLENGTH, 0, 0));
-  todo_wine ok(pt.x > xpos, "pt.x = %d\n", pt.x);
+  ok(pt.x > xpos, "pt.x = %d\n", pt.x);
   xpos = pt.x;
   SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM)&pt,
               SendMessage(hwndRichEdit, WM_GETTEXTLENGTH, 0, 0)+1);
diff --git a/dlls/riched32/tests/editor.c b/dlls/riched32/tests/editor.c
index 1d07b8d..2bf44f9 100644
--- a/dlls/riched32/tests/editor.c
+++ b/dlls/riched32/tests/editor.c
@@ -742,9 +742,7 @@ static void test_EM_POSFROMCHAR(void)
     if (i == 0)
     {
       ok(pl.y == 0, "EM_POSFROMCHAR reports y=%d, expected 0\n", pl.y);
-      todo_wine {
       ok(pl.x == 1, "EM_POSFROMCHAR reports x=%d, expected 1\n", pl.x);
-      }
       xpos = pl.x;
     }
     else if (i == 1)
@@ -805,9 +803,7 @@ static void test_EM_POSFROMCHAR(void)
   result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM)&pl, 0);
   ok(result == 0, "EM_POSFROMCHAR returned %ld, expected 0\n", result);
   ok(pl.y == 0, "EM_POSFROMCHAR reports y=%d, expected 0\n", pl.y);
-  todo_wine {
   ok(pl.x == 1, "EM_POSFROMCHAR reports x=%d, expected 1\n", pl.x);
-  }
   xpos = pl.x;
 
   SendMessage(hwndRichEdit, WM_HSCROLL, SB_LINERIGHT, 0);




More information about the wine-cvs mailing list