X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f2eb4ad2267c8dfd04288c0eb7be10ce1da240e6..9741fd45f734ea30e094f5b15f092b8394621204:/src/msw/listbox.cpp diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index b8255628c8..53d60ce89b 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,8 +675,38 @@ bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) return false; } - // only send an event if we have a valid item - return n != wxNOT_FOUND && SendEvent(evtType, n, true /* selection */); + // 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. + if ( n == wxNOT_FOUND ) + return false; + + // As we don't use m_oldSelections in single selection mode, we store the + // last item that we notified the user about in it in this case because we + // need to remember it to be able to filter out the dummy LBN_SELCHANGE + // messages that we get when the user clicks on an already selected item. + if ( param == LBN_SELCHANGE ) + { + if ( !m_oldSelections.empty() && *m_oldSelections.begin() == n ) + { + // Same item as the last time. + return false; + } + + m_oldSelections.clear(); + m_oldSelections.push_back(n); + } + + // Do generate an event otherwise. + return SendEvent(evtType, n, true /* selection */); } WXLRESULT