]> git.saurik.com Git - wxWidgets.git/commitdiff
deselect all items when SetSelection(-1) is called (patch 1506943)
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 26 Jun 2006 00:46:32 +0000 (00:46 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 26 Jun 2006 00:46:32 +0000 (00:46 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39836 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/listbox.h
src/gtk/listbox.cpp

index 00adce243d8f0a4ee89711a59656b51df184c8e6..c5c28a4e78f5d2e323188722153abf7fe9f1e3e4 100644 (file)
@@ -100,6 +100,7 @@ public:
     struct _GtkTreeEntry* GtkGetEntry(int pos) const;
     void GtkInsertItems(const wxArrayString& items,
                         void** clientData, unsigned int pos);
+    void GtkDeselectAll();
     void GtkSetSelection(int n, const bool select, const bool blockEvent);
 
 protected:
index d27e0502adca825679efe3952104224302890fdf..beb8d7d33644dc4be83b01942ebd88943f31dbab 100644 (file)
@@ -944,7 +944,30 @@ bool wxListBox::IsSelected( int n ) const
 
 void wxListBox::DoSetSelection( int n, bool select )
 {
-    return GtkSetSelection(n, select, true); //docs say no events here
+    // passing -1 to SetSelection() is documented to deselect all items
+    if ( n == wxNOT_FOUND )
+    {
+        // ... and not generate any events in the process
+        GtkDeselectAll();
+    }
+
+    wxCHECK_RET( IsValid(n), wxT("invalid index in wxListBox::SetSelection") );
+
+    // don't generate the selection event
+    GtkSetSelection(n, select, true);
+}
+
+void wxListBox::GtkDeselectAll()
+{
+    wxCHECK_RET( m_treeview != NULL, wxT("invalid listbox") );
+
+    GtkTreeSelection* selection = gtk_tree_view_get_selection(m_treeview);
+
+    m_blockEvent = true;
+
+    gtk_tree_selection_unselect_all(selection);
+
+    m_blockEvent = false;
 }
 
 void wxListBox::GtkSetSelection(int n, const bool select, const bool blockEvent)