[PATCH 6/7] Fix find using partial string logic

Nikolay Sivov bunglehead at gmail.com
Sat Nov 21 13:19:54 CST 2009


---
 dlls/comctl32/listview.c       |    7 ++++---
 dlls/comctl32/tests/listview.c |   39 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c
index feedce7..ad2165f 100644
--- a/dlls/comctl32/listview.c
+++ b/dlls/comctl32/listview.c
@@ -5949,12 +5949,13 @@ again:
             else
                 continue;
         }
-	
+
         if (lvItem.mask & LVIF_TEXT)
 	{
             if (lpFindInfo->flags & LVFI_PARTIAL)
             {
-            	if (strstrW(lvItem.pszText, lpFindInfo->psz) == NULL) continue;
+            	WCHAR *p = strstrW(lvItem.pszText, lpFindInfo->psz);
+            	if (!p || p != lvItem.pszText) continue;
             }
             else
             {
@@ -5963,7 +5964,7 @@ again:
 	}
 
         if (!bNearest) return nItem;
-	
+
 	/* This is very inefficient. To do a good job here,
 	 * we need a sorted array of (x,y) item positions */
 	LISTVIEW_GetItemOrigin(infoPtr, nItem, &Position);
diff --git a/dlls/comctl32/tests/listview.c b/dlls/comctl32/tests/listview.c
index 7bf2b03..55e7d96 100644
--- a/dlls/comctl32/tests/listview.c
+++ b/dlls/comctl32/tests/listview.c
@@ -4023,7 +4023,7 @@ static void test_LVS_EX_TRANSPARENTBKGND(void)
     DestroyWindow(hwnd);
 }
 
-static void test_ApproximateViewRect(void)
+static void test_approximate_viewrect(void)
 {
     HWND hwnd;
     DWORD ret;
@@ -4097,6 +4097,40 @@ static void test_ApproximateViewRect(void)
     DestroyWindow(hwnd);
 }
 
+static void test_finditem(void)
+{
+    LVFINDINFOA fi;
+    static char f[5];
+    HWND hwnd;
+    DWORD r;
+
+    hwnd = create_listview_control(0);
+    insert_item(hwnd, 0);
+
+    memset(&fi, 0, sizeof(fi));
+
+    /* full string search, inserted text was "foo" */
+    strcpy(f, "foo");
+    fi.flags = LVFI_STRING;
+    fi.psz = f;
+    r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
+    expect(0, r);
+    /* partial string search, inserted text was "foo" */
+    strcpy(f, "fo");
+    fi.flags = LVFI_STRING | LVFI_PARTIAL;
+    fi.psz = f;
+    r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
+    expect(0, r);
+    /* partial string search, part after start char */
+    strcpy(f, "oo");
+    fi.flags = LVFI_STRING | LVFI_PARTIAL;
+    fi.psz = f;
+    r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
+    expect(-1, r);
+
+    DestroyWindow(hwnd);
+}
+
 START_TEST(listview)
 {
     HMODULE hComctl32;
@@ -4154,7 +4188,8 @@ START_TEST(listview)
     test_indentation();
     test_getitemspacing();
     test_getcolumnwidth();
-    test_ApproximateViewRect();
+    test_approximate_viewrect();
+    test_finditem();
 
     if (!load_v6_module(&ctx_cookie, &hCtx))
     {
-- 
1.5.6.5


--=-zF5Gj1YkjCxQ8ot+QCK4--




More information about the wine-patches mailing list