riched20: Implements FR_WHOLEWORD for EM_FINDTEXT

Lei Zhang leiz at ucla.edu
Sun Mar 5 16:20:47 CST 2006


This patch adds FR_WHOLEWORD to riched20's EM_FINDTEXT and fix a couple
small bugs introduced in earlier patches for EM_FINDTEXT.

License: LGPL
---

ChangeLog:
	- Implements FR_WHOLEWORD for EM_FINDTEXT.
	- Removed associated tests from todo list.
	- Make sure pCurItem is not NULL, in the search up code, both as a
	  sanity check and to be consistent with the code in the search
	  down block.
	- Added a missing header to editstr.h to suppress a warning msg.
---

ChangeLog:

---

 editor.c       |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 editstr.h      |    1
 tests/editor.c |    4 +--
 3 files changed, 67 insertions(+), 5 deletions(-)

Index: dlls/riched20/editor.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/editor.c,v
retrieving revision 1.103
diff -u -r1.103 editor.c
--- dlls/riched20/editor.c	2 Mar 2006 17:12:37 -0000	1.103
+++ dlls/riched20/editor.c	5 Mar 2006 06:36:49 -0000
@@ -769,12 +769,13 @@
   int nMin, nMax;
   ME_DisplayItem *item;
   ME_DisplayItem *para;
+  WCHAR wLastChar;
 
   TRACE("flags==0x%08lx, chrg->cpMin==%ld, chrg->cpMax==%ld text==%s\n",
         flags, chrg->cpMin, chrg->cpMax, debugstr_w(text));
   
-  if (flags & ~(FR_DOWN | FR_MATCHCASE))
-    FIXME("Flags 0x%08lx not implemented\n", flags & ~(FR_DOWN | FR_MATCHCASE));
+  if (flags & ~(FR_DOWN | FR_MATCHCASE | FR_WHOLEWORD))
+    FIXME("Flags 0x%08lx not implemented\n", flags & ~(FR_DOWN | FR_MATCHCASE | FR_WHOLEWORD));
 
   nMin = chrg->cpMin;
   if (chrg->cpMax == -1)
@@ -816,6 +817,7 @@
     }
 
     para = ME_GetParagraph(item);
+    wLastChar = ' '; /* Assume there is a whitespace before the first word*/
     while (item
            && para->member.para.nCharOfs + item->member.run.nCharOfs + nStart + nLen <= nMax)
     {
@@ -825,9 +827,33 @@
     
       while (pCurItem && ME_CharCompare(pCurItem->member.run.strText->szData[nCurStart + nMatched], text[nMatched], (flags & FR_MATCHCASE)))
       {
+        if ((flags & FR_WHOLEWORD) && iswalnum(wLastChar))
+          break;
+
         nMatched++;
         if (nMatched == nLen)
         {
+          ME_DisplayItem *pNextItem = pCurItem;
+          int nNextStart = nCurStart;
+          WCHAR wNextChar;
+
+          if (flags & FR_WHOLEWORD)
+          {
+            if (nCurStart + nMatched == ME_StrLen(pCurItem->member.run.strText))
+            {
+              pNextItem = ME_FindItemFwd(pCurItem, diRun);
+              nNextStart = -nMatched;
+            }
+
+            if (pNextItem)
+              wNextChar = pNextItem->member.run.strText->szData[nNextStart + nMatched];
+            else
+              wNextChar = ' ';
+
+            if (iswalnum(wNextChar))
+              break;
+          }
+
           nStart += para->member.para.nCharOfs + item->member.run.nCharOfs;
           if (chrgText)
           {
@@ -844,6 +870,11 @@
           nCurStart = -nMatched;
         }
       }
+      if (pCurItem)
+        wLastChar = pCurItem->member.run.strText->szData[nCurStart + nMatched];
+      else
+        wLastChar = ' ';
+
       nStart++;
       if (nStart == ME_StrLen(item->member.run.strText))
       {
@@ -864,6 +895,7 @@
     }
     
     para = ME_GetParagraph(item);
+    wLastChar = ' '; /* Assume there is a whitespace after the last word*/
     
     while (item
            && para->member.para.nCharOfs + item->member.run.nCharOfs + nEnd - nLen >= nMin)
@@ -872,11 +904,35 @@
       int nCurEnd = nEnd;
       int nMatched = 0;
       
-      while (ME_CharCompare(pCurItem->member.run.strText->szData[nCurEnd - nMatched - 1], text[nLen - nMatched - 1], (flags & FR_MATCHCASE)))
+      while (pCurItem && ME_CharCompare(pCurItem->member.run.strText->szData[nCurEnd - nMatched - 1], text[nLen - nMatched - 1], (flags & FR_MATCHCASE)))
       {
+        if ((flags & FR_WHOLEWORD) && iswalnum(wLastChar))
+          break;
+
         nMatched++;
         if (nMatched == nLen)
         {
+          ME_DisplayItem *pNextItem = pCurItem;
+          int nNextEnd = nCurEnd;
+          WCHAR wNextChar;
+
+          if (flags & FR_WHOLEWORD)
+          {
+            if (nNextEnd - nMatched == 0)
+            {
+              pNextItem = ME_FindItemBack(pCurItem, diRun);
+              nNextEnd = ME_StrLen(pNextItem->member.run.strText) + nMatched;
+            }
+
+            if (pNextItem)
+              wNextChar = pNextItem->member.run.strText->szData[nNextEnd - nMatched - 1];
+            else
+              wNextChar = ' ';
+
+            if (iswalnum(wNextChar))
+              break;
+          }
+
           nStart = para->member.para.nCharOfs + item->member.run.nCharOfs + nCurEnd - nMatched;
           if (chrgText)
           {
@@ -895,6 +951,11 @@
           nCurEnd = ME_StrLen(pCurItem->member.run.strText) + nMatched;
         }
       }
+      if (pCurItem)
+        wLastChar = pCurItem->member.run.strText->szData[nCurEnd - nMatched - 1];
+      else
+        wLastChar = ' ';
+
       nEnd--;
       if (nEnd < 0)
       {
Index: dlls/riched20/editstr.h
===================================================================
RCS file: /home/wine/wine/dlls/riched20/editstr.h,v
retrieving revision 1.27
diff -u -r1.27 editstr.h
--- dlls/riched20/editstr.h	2 Mar 2006 11:18:19 -0000	1.27
+++ dlls/riched20/editstr.h	5 Mar 2006 06:36:50 -0000
@@ -29,6 +29,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <wctype.h>
 
 #define COBJMACROS
 #define NONAMELESSUNION
Index: dlls/riched20/tests/editor.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/tests/editor.c,v
retrieving revision 1.11
diff -u -r1.11 editor.c
--- dlls/riched20/tests/editor.c	2 Mar 2006 17:12:37 -0000	1.11
+++ dlls/riched20/tests/editor.c	5 Mar 2006 06:36:51 -0000
@@ -92,8 +92,8 @@
   {10, 5, "", 0, -1, 0},
 
   /* Whole-word search */
-  {0, -1, "wine", FR_DOWN | FR_WHOLEWORD, 18, 1},
-  {0, -1, "win", FR_DOWN | FR_WHOLEWORD, -1, 1},
+  {0, -1, "wine", FR_DOWN | FR_WHOLEWORD, 18, 0},
+  {0, -1, "win", FR_DOWN | FR_WHOLEWORD, -1, 0},
   
   /* Bad ranges */
   {-20, 20, "Wine", FR_DOWN, -1, 0},



More information about the wine-patches mailing list