[1/7] comctl32/listview: Implement LVM_CANCELEDITLABEL with tests
Nikolay Sivov
bunglehead at gmail.com
Sun Jun 21 17:50:00 CDT 2009
Changelog:
- Implement LVM_CANCELEDITLABEL with tests
>From f9e22c32cb53cb4d89209888e24615d063e908c9 Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <bunglehead at gmail.com>
Date: Sat, 20 Jun 2009 00:39:50 +0400
Subject: 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..9e43444 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..5aa7146 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);
--
1.5.6.5
More information about the wine-patches
mailing list