Remove wxListCtrl::EnableSortIndicator()

The old API seems unnecessarily complex, it is simpler to just let the
application call ShowSortIndicator() itself from its
wxEVT_LIST_COL_CLICK handler, which needs to be defined anyhow in order
to actually sort the items, rather than require it to enable sort
indicator, explicitly set it initially and then remember to not set it
any longer in response to the column clicks.

Also make RemoveSortIndicator() non-virtual and implement it simply as
ShowSortIndicator(-1) because this actually simplifies the code too.
This commit is contained in:
Vadim Zeitlin
2021-12-14 01:06:21 +00:00
parent 30ce892ed5
commit 52649cc566
8 changed files with 33 additions and 142 deletions

View File

@@ -461,8 +461,6 @@ void MyFrame::RecreateList(long flags, bool withText)
flags |
wxBORDER_THEME | wxLC_EDIT_LABELS);
m_listCtrl->EnableSortIndicator();
if ( old )
{
wxSizer* const sizer = m_panel->GetSizer();
@@ -1091,10 +1089,18 @@ void MyListCtrl::OnColClick(wxListEvent& event)
return; // clicked outside any column.
}
if ( IsSortIndicatorEnabled() )
// If clicking on the same column by which we already sort, toggle the sort
// direction, otherwise use ascending sort by default.
bool ascending;
if ( col == GetSortIndicator() )
ascending = !IsAscendingSortIndicator();
else
ascending = true;
// sort on item data (SetItemData)
if ( SortItems(MyCompareFunction, ascending) )
{
// sort on item data (SetItemData), disable when sorting fails
EnableSortIndicator( SortItems(MyCompareFunction, IsAscendingSortIndicator()) );
ShowSortIndicator(col, ascending);
}
// set or unset image