Nikolay Sivov : comctl32/listview: Implement LVM_CANCELEDITLABEL with tests .

Alexandre Julliard julliard at winehq.org
Mon Jun 22 09:04:14 CDT 2009


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

Author: Nikolay Sivov <bunglehead at gmail.com>
Date:   Sat Jun 20 00:39:50 2009 +0400

comctl32/listview: Implement LVM_CANCELEDITLABEL with tests.

---

 dlls/comctl32/listview.c       |   31 +++++++++++++++++++-----
 dlls/comctl32/tests/listview.c |   50 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 7 deletions(-)

diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c
index ebf49c6..f9608c6 100644
--- a/dlls/comctl32/listview.c
+++ b/dlls/comctl32/listview.c
@@ -106,7 +106,6 @@
  *   -- LVN_BEGINRDRAG
  *
  * Messages:
- *   -- LVM_CANCELEDITLABEL
  *   -- LVM_ENABLEGROUPVIEW
  *   -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
  *   -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
@@ -419,6 +418,7 @@ static BOOL LISTVIEW_EnsureVisible(LISTVIEW_INFO *, INT, BOOL);
 static HWND CreateEditLabelT(LISTVIEW_INFO *, LPCWSTR, DWORD, BOOL);
 static HIMAGELIST LISTVIEW_SetImageList(LISTVIEW_INFO *, INT, HIMAGELIST);
 static INT LISTVIEW_HitTest(const LISTVIEW_INFO *, LPLVHITTESTINFO, BOOL, BOOL);
+static BOOL LISTVIEW_EndEditLabelT(LISTVIEW_INFO *, BOOL, BOOL);
 
 /******** Text handling functions *************************************/
 
@@ -4591,6 +4591,26 @@ static DWORD LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO *infoPtr, INT nIte
   return dwViewRect;
 }
 
+/***
+ * DESCRIPTION:
+ * Cancel edit label with saving item text.
+ *
+ * PARAMETER(S):
+ * [I] infoPtr : valid pointer to the listview structure
+ *
+ * RETURN:
+ * Always returns TRUE.
+ */
+static LRESULT LISTVIEW_CancelEditLabel(LISTVIEW_INFO *infoPtr)
+{
+    /* handle value will be lost after LISTVIEW_EndEditLabelT */
+    HWND edit = infoPtr->hwndEdit;
+
+    LISTVIEW_EndEditLabelT(infoPtr, TRUE, IsWindowUnicode(infoPtr->hwndEdit));
+    SendMessageW(edit, WM_CLOSE, 0, 0);
+
+    return TRUE;
+}
 
 /***
  * DESCRIPTION:
@@ -10113,7 +10133,8 @@ LISTVIEW_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
   case LVM_ARRANGE:
     return LISTVIEW_Arrange(infoPtr, (INT)wParam);
 
-/* case LVM_CANCELEDITLABEL: */
+  case LVM_CANCELEDITLABEL:
+    return LISTVIEW_CancelEditLabel(infoPtr);
 
   case LVM_CREATEDRAGIMAGE:
     return (LRESULT)LISTVIEW_CreateDragImage(infoPtr, (INT)wParam, (LPPOINT)lParam);
@@ -10734,11 +10755,7 @@ static LRESULT LISTVIEW_Command(LISTVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lP
 	}
 	case EN_KILLFOCUS:
 	{
-	    /* handle value will be lost after LISTVIEW_EndEditLabelT */
-	    HWND edit = infoPtr->hwndEdit;
-
-	    LISTVIEW_EndEditLabelT(infoPtr, TRUE, IsWindowUnicode(infoPtr->hwndEdit));
-	    SendMessageW(edit, WM_CLOSE, 0, 0);
+	    LISTVIEW_CancelEditLabel(infoPtr);
 	}
 
 	default:
diff --git a/dlls/comctl32/tests/listview.c b/dlls/comctl32/tests/listview.c
index 2c3ab64..7d14294 100644
--- a/dlls/comctl32/tests/listview.c
+++ b/dlls/comctl32/tests/listview.c
@@ -3534,6 +3534,55 @@ static void test_get_set_view(void)
     DestroyWindow(hwnd);
 }
 
+static void test_canceleditlabel(void)
+{
+    HWND hwnd, hwndedit;
+    DWORD ret;
+    CHAR buff[10];
+    LVITEMA itema;
+    static CHAR test[] = "test";
+    static const CHAR test1[] = "test1";
+
+    hwnd = create_listview_control(LVS_EDITLABELS);
+    ok(hwnd != NULL, "failed to create a listview window\n");
+
+    insert_item(hwnd, 0);
+
+    /* try without edit created */
+    ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
+    expect(TRUE, ret);
+
+    /* cancel without data change */
+    SetFocus(hwnd);
+    hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
+    ok(IsWindow(hwndedit), "Expected edit control to be created\n");
+    ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
+    expect(TRUE, ret);
+    ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
+
+    /* cancel after data change */
+    memset(&itema, 0, sizeof(itema));
+    itema.pszText = test;
+    ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
+    expect(TRUE, ret);
+    SetFocus(hwnd);
+    hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
+    ok(IsWindow(hwndedit), "Expected edit control to be created\n");
+    ret = SetWindowText(hwndedit, test1);
+    ok(ret != 0, "Expected edit text to change\n");
+    ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
+    expect(TRUE, ret);
+    ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
+    memset(&itema, 0, sizeof(itema));
+    itema.pszText = buff;
+    itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
+    ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
+    expect(5, ret);
+    ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
+
+    DestroyWindow(hwnd);
+}
+
 START_TEST(listview)
 {
     HMODULE hComctl32;
@@ -3598,6 +3647,7 @@ START_TEST(listview)
 
     /* comctl32 version 6 tests start here */
     test_get_set_view();
+    test_canceleditlabel();
 
     unload_v6_module(ctx_cookie);
 




More information about the wine-cvs mailing list