riched20: Implements FR_WHOLEWORD for EM_FINDTEXT
Lei Zhang
leiz at ucla.edu
Mon Mar 6 22:21:22 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. It does not
use functions from wctype.h
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.
---
ChangeLog:
---
editor.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
tests/editor.c | 4 +--
2 files changed, 66 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 7 Mar 2006 04:17:09 -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) && isalnumW(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 (isalnumW(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) && isalnumW(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 (isalnumW(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/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 7 Mar 2006 04:17:12 -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