Dylan Smith : richedit: Clicking below end of text now selects closest character.

Alexandre Julliard julliard at winehq.org
Mon Jun 30 08:26:23 CDT 2008


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

Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date:   Fri Jun 27 09:18:39 2008 -0400

richedit: Clicking below end of text now selects closest character.

Before the end of the text was selected when clicking below the end of
the text, rather than using the x position to find the appropriate
character on the last row that is closest to the pixel position.

---

 dlls/riched20/caret.c        |   14 ++++++++++++++
 dlls/riched20/tests/editor.c |   23 ++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index 462b98a..ebf6c56 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -799,6 +799,20 @@ static void ME_FindPixelPos(ME_TextEditor *editor, int x, int y, ME_Cursor *resu
     }
     p = pp;
   }
+  if (p == editor->pBuffer->pLast)
+  {
+    /* The position is below the last paragraph, so the last row will be used
+     * rather than the end of the text, so the x position will be used to
+     * determine the offset closest to the pixel position. */
+    p = ME_FindItemBack(p, diStartRow);
+    if (p != NULL){
+      p = ME_FindItemFwd(p, diRun);
+    }
+    else
+    {
+      p = editor->pBuffer->pLast;
+    }
+  }
   for (; p != editor->pBuffer->pLast; p = p->next)
   {
     switch (p->type)
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index 064e780..241c65b 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -4496,7 +4496,8 @@ static void test_undo_coalescing(void)
 #define SEND_CTRL_LEFT(hwnd) SEND_CTRL_EXT_KEY(hwnd, VK_LEFT, 0x4b)
 #define SEND_CTRL_RIGHT(hwnd) SEND_CTRL_EXT_KEY(hwnd, VK_RIGHT, 0x4d)
 
-static void test_word_movement(){
+static void test_word_movement(void)
+{
     HWND hwnd;
     int result;
     int sel_start, sel_end;
@@ -4554,6 +4555,25 @@ static void test_word_movement(){
     DestroyWindow(hwnd);
 }
 
+static void test_EM_CHARFROMPOS(void)
+{
+    HWND hwnd;
+    int result;
+    POINTL point;
+    point.x = 0;
+    point.y = 50;
+
+    /* multi-line control inserts CR normally */
+    hwnd = new_richedit(NULL);
+    result = SendMessageA(hwnd, WM_SETTEXT, 0,
+                          (LPARAM)"one two three four five six seven");
+
+    result = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&point);
+    ok(result == 0, "expected character index of 0 but got %d\n", result);
+
+    DestroyWindow(hwnd);
+}
+
 START_TEST( editor )
 {
   MSG msg;
@@ -4601,6 +4621,7 @@ START_TEST( editor )
   test_eventMask();
   test_undo_coalescing();
   test_word_movement();
+  test_EM_CHARFROMPOS();
 
   /* Set the environment variable WINETEST_RICHED20 to keep windows
    * responsive and open for 30 seconds. This is useful for debugging.




More information about the wine-cvs mailing list