]> git.saurik.com Git - wxWidgets.git/commitdiff
Deselect all items in wxMSW wxListBox when selection is set to -1.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 23 Nov 2010 13:10:54 +0000 (13:10 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 23 Nov 2010 13:10:54 +0000 (13:10 +0000)
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
tests/controls/listboxtest.cpp

index 52fe4d0c4d5b1d3475418eac61f5693bf8e8fa79..97bbe9284072a0717466fe8c4cb7386b681b1b0d 100644 (file)
@@ -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
     {
index 2a3121f0b44e10d65951fa9096bafcc51e04fd22..98f33b9d3b8793e746031da7bcec08a6b2f78e3b 100644 (file)
@@ -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()