From 6bcdc69ec05e6929c9ac5d63fb4a5976301dd4d0 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Fri, 7 Aug 2009 00:13:25 +0400 Subject: [PATCH] comctl32/treeview: Check passed handle value in WM_COMMAND handler. --- dlls/comctl32/tests/treeview.c | 16 ++++++++++++++++ dlls/comctl32/treeview.c | 7 +++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/dlls/comctl32/tests/treeview.c b/dlls/comctl32/tests/treeview.c index 7c86450a902..5cfaf2007a4 100644 --- a/dlls/comctl32/tests/treeview.c +++ b/dlls/comctl32/tests/treeview.c @@ -879,9 +879,25 @@ static void test_itemedit(void) /* item shouldn't be selected automatically after TVM_EDITLABEL */ r = SendMessage(hTree, TVM_GETITEMSTATE, (WPARAM)hRoot, TVIS_SELECTED); expect(0, r); + /* try to cancel with wrong edit handle */ + r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)NULL); + expect(0, r); + ok(IsWindow(edit), "Expected edit control to be valid\n"); r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit); expect(0, r); ok(!IsWindow(edit), "Expected edit control to be destroyed\n"); + /* try to cancel without creating edit */ + r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)NULL); + expect(0, r); + + /* try to cancel with wrong (not null) handle */ + edit = (HWND)SendMessage(hTree, TVM_EDITLABEL, 0, (LPARAM)hRoot); + ok(IsWindow(edit), "Expected valid handle\n"); + r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hTree); + expect(0, r); + ok(IsWindow(edit), "Expected edit control to be valid\n"); + r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit); + expect(0, r); /* remove selection after starting edit */ r = TreeView_SelectItem(hTree, hRoot); diff --git a/dlls/comctl32/treeview.c b/dlls/comctl32/treeview.c index 44bb84192ef..a38434d7895 100644 --- a/dlls/comctl32/treeview.c +++ b/dlls/comctl32/treeview.c @@ -3651,8 +3651,11 @@ TREEVIEW_Command(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam) break; } case EN_KILLFOCUS: - TREEVIEW_EndEditLabelNow(infoPtr, FALSE); - break; + /* apparently we should respect passed handle value */ + if (infoPtr->hwndEdit != (HWND)lParam) return FALSE; + + TREEVIEW_EndEditLabelNow(infoPtr, FALSE); + break; default: return SendMessageW(infoPtr->hwndNotify, WM_COMMAND, wParam, lParam);