From bbb03ec995a4e955a3f7a255dfeb05989924776a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 23 Nov 2010 13:10:54 +0000 Subject: [PATCH] Deselect all items in wxMSW wxListBox when selection is set to -1. Even though this behaviour is somewhat counterintuitive, the documentation mentions that this is what should happen and wxGTK and wxOSX already behave like this so bring wxMSW in line. wxListBox::DeselectAll() should probably just call SetSelection(wxNOT_FOUND) when the item to leave selected is not specified too now. Closes #12705. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66243 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/listbox.cpp | 6 +++++- tests/controls/listboxtest.cpp | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index 52fe4d0c4d..97bbe92840 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -351,7 +351,11 @@ void wxListBox::DoSetSelection(int N, bool select) if ( HasMultipleSelection() ) { - SendMessage(GetHwnd(), LB_SETSEL, select, N); + // Setting selection to -1 should deselect everything. + const bool deselectAll = N == wxNOT_FOUND; + SendMessage(GetHwnd(), LB_SETSEL, + deselectAll ? FALSE : select, + deselectAll ? -1 : N); } else { diff --git a/tests/controls/listboxtest.cpp b/tests/controls/listboxtest.cpp index 2a3121f0b4..98f33b9d3b 100644 --- a/tests/controls/listboxtest.cpp +++ b/tests/controls/listboxtest.cpp @@ -170,6 +170,12 @@ void ListBoxTestCase::MultipleSelect() CPPUNIT_ASSERT(!m_list->IsSelected(1)); CPPUNIT_ASSERT(m_list->IsSelected(2)); CPPUNIT_ASSERT(!m_list->IsSelected(3)); + + m_list->SetSelection(0); + m_list->SetSelection(wxNOT_FOUND); + + m_list->GetSelections(selected); + CPPUNIT_ASSERT_EQUAL(0, selected.Count()); } void ListBoxTestCase::ClickEvents() -- 2.45.2