From ef33382e43d6b40e716dde67715a423d5c06eb8b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 26 Jun 2006 00:46:32 +0000 Subject: [PATCH] deselect all items when SetSelection(-1) is called (patch 1506943) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39836 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/listbox.h | 1 + src/gtk/listbox.cpp | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/wx/gtk/listbox.h b/include/wx/gtk/listbox.h index 00adce243d..c5c28a4e78 100644 --- a/include/wx/gtk/listbox.h +++ b/include/wx/gtk/listbox.h @@ -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: diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index d27e0502ad..beb8d7d336 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -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) -- 2.45.2