Huw Davies : riched20: Simplify FindPixelPos().

Alexandre Julliard julliard at winehq.org
Wed Oct 7 16:04:11 CDT 2020


Module: wine
Branch: master
Commit: 5dc422d4e5701cba3425ad6b4c3c8c370089e787
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=5dc422d4e5701cba3425ad6b4c3c8c370089e787

Author: Huw Davies <huw at codeweavers.com>
Date:   Wed Oct  7 13:20:38 2020 +0100

riched20: Simplify FindPixelPos().

Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/riched20/caret.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index 212c9e9f99..0ed34372e3 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -1011,6 +1011,7 @@ static BOOL ME_FindPixelPos(ME_TextEditor *editor, int x, int y,
                             ME_Cursor *result, BOOL *is_eol, BOOL final_eop)
 {
   ME_DisplayItem *p = editor->pBuffer->pFirst->member.para.next_para;
+  ME_DisplayItem *row = NULL;
   BOOL isExact = TRUE;
 
   x -= editor->rcFormat.left;
@@ -1022,42 +1023,40 @@ static BOOL ME_FindPixelPos(ME_TextEditor *editor, int x, int y,
   /* find paragraph */
   for (; p != editor->pBuffer->pLast; p = p->member.para.next_para)
   {
-    assert(p->type == diParagraph);
     if (y < p->member.para.pt.y + p->member.para.nHeight)
     {
       if (p->member.para.nFlags & MEPF_ROWSTART)
         p = ME_FindPixelPosInTableRow(x, y, p);
       y -= p->member.para.pt.y;
-      p = ME_FindItemFwd(p, diStartRow);
+      row = ME_FindItemFwd(p, diStartRow);
       break;
-    } else if (p->member.para.nFlags & MEPF_ROWSTART) {
+    }
+    else if (p->member.para.nFlags & MEPF_ROWSTART)
+    {
       p = ME_GetTableRowEnd(p);
     }
   }
   /* find row */
-  for (; p != editor->pBuffer->pLast; )
+  while (row)
   {
-    ME_DisplayItem *pp;
-    assert(p->type == diStartRow);
-    if (y < p->member.row.pt.y + p->member.row.nHeight) break;
-    pp = ME_FindItemFwd(p, diStartRow);
-    if (!pp) break;
-    p = pp;
+    ME_DisplayItem *next_row;
+
+    if (y < row->member.row.pt.y + row->member.row.nHeight) break;
+    next_row = ME_FindItemFwd(row, diStartRow);
+    if (!next_row) break;
+    row = next_row;
   }
-  if (p == editor->pBuffer->pLast && !final_eop)
+
+  if (!row && !final_eop)
   {
     /* 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. */
     isExact = FALSE;
-    p = ME_FindItemBack(p, diStartRow);
-    if (!p) p = editor->pBuffer->pLast;
+    row = ME_FindItemBack(p, diStartRow);
   }
 
-  assert( p->type == diStartRow || p == editor->pBuffer->pLast );
-
-  if( p->type == diStartRow )
-      return ME_FindRunInRow( editor, p, x, result, is_eol ) && isExact;
+  if (row) return ME_FindRunInRow( editor, row, x, result, is_eol ) && isExact;
 
   ME_SetCursorToEnd(editor, result, TRUE);
   return FALSE;




More information about the wine-cvs mailing list