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.
This commit is contained in:
Vadim Zeitlin 2018-12-15 23:37:36 +01:00
parent cdd0430b37
commit abc4576ffe
2 changed files with 23 additions and 0 deletions

View File

@ -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)
----------------------------

View File

@ -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<unsigned>(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__
}
// ----------------------------------------------------------------------------