From abc4576ffe65e8621e901e83dc92626a6ce75173 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 15 Dec 2018 23:37:36 +0100 Subject: [PATCH] Invalidate selection after deleting wxListBox item with GTK+ 3 For consistency with the other ports, invalidate the selection when deleting the selected item or any item before it. Closes #18267. --- docs/changes.txt | 4 ++++ src/gtk/listbox.cpp | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index fc7fcb1e00..33b8cece02 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -113,6 +113,10 @@ All (GUI): - Fix wxInfoBar close button size in high DPI (Stefan Ziegler). - Make disabling the window before creating it actually work. +wxGTK: + +- Invalidate selection after deleting wxListBox item with GTK+ 3 too. + 3.1.2: (released 2018-12-10) ---------------------------- diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 0a0f6a8c0f..954fb060a0 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -497,6 +497,25 @@ void wxListBox::DoDeleteOneItem(unsigned int n) // this returns false if iter is invalid (e.g. deleting item at end) but // since we don't use iter, we ignore the return value gtk_list_store_remove(m_liststore, &iter); + +#ifdef __WXGTK3__ + // Invalidate selection in a single-selection control for consistency with + // MSW and GTK+ 2 where this happens automatically when deleting the + // selected item or any item before it. + if ( !HasMultipleSelection() ) + { + const int sel = GetSelection(); + if ( sel != wxNOT_FOUND && static_cast(sel) >= n ) + { + // Don't call SetSelection() from here, it's not totally clear if + // it is safe to do, so just do this at GTK+ level. + gtk_tree_selection_unselect_all + ( + gtk_tree_view_get_selection(m_treeview) + ); + } + } +#endif // __WXGTK3__ } // ----------------------------------------------------------------------------