Eric Pouech : richedit: Rewrote FindPixelPos so that it always return something.

Alexandre Julliard julliard at winehq.org
Wed Jan 2 07:34:55 CST 2008


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

Author: Eric Pouech <eric.pouech at orange.fr>
Date:   Tue Jan  1 22:05:05 2008 +0100

richedit: Rewrote FindPixelPos so that it always return something.

Made the function static as well.

---

 dlls/riched20/caret.c  |  131 ++++++++++++++++++++---------------------------
 dlls/riched20/editor.h |    1 -
 dlls/riched20/wrap.c   |    4 +-
 3 files changed, 58 insertions(+), 78 deletions(-)

diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index 46ab7c9..2ca076d 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -704,102 +704,83 @@ int ME_GetCursorOfs(ME_TextEditor *editor, int nCursor)
     + pCursor->pRun->member.run.nCharOfs + pCursor->nOffset;
 }
 
-int ME_FindPixelPos(ME_TextEditor *editor, int x, int y, ME_Cursor *result, BOOL *is_eol)
+static void ME_FindPixelPos(ME_TextEditor *editor, int x, int y, ME_Cursor *result, BOOL *is_eol)
 {
   ME_DisplayItem *p = editor->pBuffer->pFirst->member.para.next_para;
+  ME_DisplayItem *last = NULL;
   int rx = 0;
-  
+
   if (is_eol)
     *is_eol = 0;
 
-  while(p != editor->pBuffer->pLast)
+  /* find paragraph */
+  for (; p != editor->pBuffer->pLast; p = p->member.para.next_para)
   {
-    if (p->type == diParagraph)
+    assert(p->type == diParagraph);
+    if (y < p->member.para.nYPos + p->member.para.nHeight)
     {
-      int ry = y - p->member.para.nYPos;
-      if (ry < 0)
-      {
-        result->pRun = ME_FindItemFwd(p, diRun);
-        result->nOffset = 0;
-        return 0;
-      }
-      if (ry >= p->member.para.nHeight)
-      {
-        p = p->member.para.next_para;
-        continue;
-      }
+      y -= p->member.para.nYPos;
       p = ME_FindItemFwd(p, diStartRow);
-      y = ry;
-      continue;
+      break;
     }
-    if (p->type == diStartRow)
+  }
+  /* find row */
+  for (; p != editor->pBuffer->pLast; )
+  {
+    ME_DisplayItem *pp;
+    assert(p->type == diStartRow);
+    if (y < p->member.row.nYPos + p->member.row.nHeight)
     {
-      int ry = y - p->member.row.nYPos;
-      if (ry < 0)
-        return 0;
-      if (ry >= p->member.row.nHeight)
-      {
-        p = ME_FindItemFwd(p, diStartRowOrParagraphOrEnd);
-        if (p->type != diStartRow)
-          return 0;
-        continue;
-      }
-      p = ME_FindItemFwd(p, diRun);
-      continue;
+        p = ME_FindItemFwd(p, diRun);
+        break;
+    }
+    pp = ME_FindItemFwd(p, diStartRowOrParagraphOrEnd);
+    if (pp->type != diStartRow)
+    {
+        p = ME_FindItemFwd(p, diRun);
+        break;
     }
-    if (p->type == diRun)
+    p = pp;
+  }
+  for (; p != editor->pBuffer->pLast; p = p->next)
+  {
+    switch (p->type)
     {
-      ME_DisplayItem *pp;
+    case diRun:
       rx = x - p->member.run.pt.x;
-      if (rx < 0)
-        rx = 0;
-      if (rx >= p->member.run.nWidth) /* not this run yet... find next item */
-      {
-        pp = p;
-        do {
-          p = p->next;
-          if (p->type == diRun)
-          {
-            rx = x - p->member.run.pt.x;
-            goto continue_search;
-          }
-          if (p->type == diStartRow)
-          {
-            p = ME_FindItemFwd(p, diRun);
-            if (is_eol)
-              *is_eol = 1;
-            rx = 0; /* FIXME not sure */
-            goto found_here;
-          }
-          if (p->type == diParagraph || p->type == diTextEnd)
-          {
-            rx = 0; /* FIXME not sure */
-            p = pp;
-            goto found_here;
-          }
-        } while(1);
-        continue;
-      }
-    found_here:
-      if (p->member.run.nFlags & MERF_ENDPARA)
-        rx = 0;
-      result->pRun = p;
-      result->nOffset = ME_CharFromPointCursor(editor, rx, &p->member.run);
-      if (editor->pCursors[0].nOffset == p->member.run.strText->nLen && rx)
+      if (rx < p->member.run.nWidth)
       {
-        result->pRun = ME_FindItemFwd(editor->pCursors[0].pRun, diRun);
-        result->nOffset = 0;
+      found_here:
+        assert(p->type == diRun);
+        if ((p->member.run.nFlags & MERF_ENDPARA) || rx < 0)
+          rx = 0;
+        result->pRun = p;
+        result->nOffset = ME_CharFromPointCursor(editor, rx, &p->member.run);
+        if (editor->pCursors[0].nOffset == p->member.run.strText->nLen && rx)
+        {
+          result->pRun = ME_FindItemFwd(editor->pCursors[0].pRun, diRun);
+          result->nOffset = 0;
+        }
+        return;
       }
-      return 1;
+      break;
+    case diStartRow:
+      p = ME_FindItemFwd(p, diRun);
+      if (is_eol) *is_eol = 1;
+      rx = 0; /* FIXME not sure */
+      goto found_here;
+    case diParagraph:
+    case diTextEnd:
+      rx = 0; /* FIXME not sure */
+      p = last;
+      goto found_here;
+    default: assert(0);
     }
-    assert(0);
-  continue_search:
-    ;
+    last = p;
   }
   result->pRun = ME_FindItemBack(p, diRun);
   result->nOffset = 0;
   assert(result->pRun->member.run.nFlags & MERF_ENDPARA);
-  return 0;
 }
 
 
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 0223b30..c9baf98 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -181,7 +181,6 @@ void ME_SelectWord(ME_TextEditor *editor);
 void ME_HideCaret(ME_TextEditor *ed);
 void ME_ShowCaret(ME_TextEditor *ed);
 void ME_MoveCaret(ME_TextEditor *ed);
-int ME_FindPixelPos(ME_TextEditor *editor, int x, int y, ME_Cursor *result, BOOL *is_eol);
 int ME_CharFromPos(ME_TextEditor *editor, int x, int y);
 void ME_LButtonDown(ME_TextEditor *editor, int x, int y);
 void ME_MouseMove(ME_TextEditor *editor, int x, int y);
diff --git a/dlls/riched20/wrap.c b/dlls/riched20/wrap.c
index f0b2c49..e72983e 100644
--- a/dlls/riched20/wrap.c
+++ b/dlls/riched20/wrap.c
@@ -354,8 +354,8 @@ static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp, DWORD begino
   wc.context = c;
 /*   wc.para_style = tp->member.para.style; */
   wc.style = NULL;
-  wc.nFirstMargin = ME_twips2points(c, tp->member.para.pFmt->dxStartIndent, dpi) + beginofs
-  wc.nLeftMargin = wc.nFirstMargin + ME_twips2points(c, tp->member.para.pFmt->dxOffset, dpi) + beginofs
+  wc.nFirstMargin = ME_twips2points(c, tp->member.para.pFmt->dxStartIndent, dpi) + beginofs;
+  wc.nLeftMargin = wc.nFirstMargin + ME_twips2points(c, tp->member.para.pFmt->dxOffset, dpi) + beginofs;
   wc.nRightMargin = ME_twips2points(c, tp->member.para.pFmt->dxRightIndent, dpi);
   wc.nRow = 0;
   wc.pt.x = 0;




More information about the wine-cvs mailing list