From f186bd4d4035909759af0e5e9fcfd958a879ed6f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 5 Jun 2010 22:58:09 +0000 Subject: [PATCH] Don't send listbox selection events when mouse wasn't clicked on an item. Windows sends events even if the mouse is clicked in the area below the items, filter them out by checking the item under the mouse ourselves. Also use synchronous GetMessagePos() function to get the mouse position instead of the asynchronous GetCursorPos() which was wrongly used by the old code. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64499 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/listbox.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index b8255628c8..3e19b2a9f2 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -663,15 +663,11 @@ bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) // item ourselves below in this case. n = SendMessage(GetHwnd(), LB_GETCARETINDEX, 0, 0); } - else - { - n = HitTest(ScreenToClient(wxGetMousePosition())); - } + //else: n will be determined below from the mouse position } else if ( param == LBN_DBLCLK ) { evtType = wxEVT_COMMAND_LISTBOX_DOUBLECLICKED; - n = HitTest(ScreenToClient(wxGetMousePosition())); } else { @@ -679,7 +675,17 @@ bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) return false; } - // only send an event if we have a valid item + // Find the item position if it was a mouse-generated selection event or a + // double click event (which is always generated using the mouse) + if ( n == wxNOT_FOUND ) + { + const DWORD pos = ::GetMessagePos(); + const wxPoint pt(GET_X_LPARAM(pos), GET_Y_LPARAM(pos)); + n = HitTest(ScreenToClient(wxPoint(pt))); + } + + // We get events even when mouse is clicked outside of any valid item from + // Windows, just ignore them. return n != wxNOT_FOUND && SendEvent(evtType, n, true /* selection */); } -- 2.49.0