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

@@ -982,7 +982,6 @@ wxListHeaderWindow::wxListHeaderWindow()
m_owner = NULL;
m_resizeCursor = NULL;
m_enableSortCol = false;
m_sortAsc = true;
m_sortCol = -1;
}
@@ -1104,7 +1103,7 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
#endif
wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE;
if ( m_enableSortCol && i == m_sortCol )
if ( i == m_sortCol )
{
if ( m_sortAsc )
sortArrow = wxHDR_SORT_ICON_UP;
@@ -1334,12 +1333,6 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
colItem.SetState(state & ~wxLIST_STATE_SELECTED);
m_owner->SetColumn(i, colItem);
}
if ( m_sortCol != m_column )
m_sortAsc = true;
else
m_sortAsc = !m_sortAsc;
m_sortCol = m_column;
}
SendListEvent( event.LeftDown()
@@ -5084,47 +5077,18 @@ bool wxGenericListCtrl::IsItemChecked(long item) const
return m_mainWin->IsItemChecked(item);
}
void wxGenericListCtrl::EnableSortIndicator(bool enable)
{
if ( m_headerWin && enable != m_headerWin->m_enableSortCol )
{
m_headerWin->m_enableSortCol = enable;
m_headerWin->Refresh();
}
}
bool wxGenericListCtrl::IsSortIndicatorEnabled() const
{
return m_headerWin && m_headerWin->m_enableSortCol;
}
void wxGenericListCtrl::ShowSortIndicator(int idx, bool ascending)
{
if ( idx == -1 )
{
RemoveSortIndicator();
}
else if ( m_headerWin &&
if ( m_headerWin &&
(idx != m_headerWin->m_sortCol ||
ascending != m_headerWin->m_sortAsc) )
(idx != -1 && ascending != m_headerWin->m_sortAsc)) )
{
m_headerWin->m_enableSortCol = true;
m_headerWin->m_sortCol = idx;
m_headerWin->m_sortAsc = ascending;
m_headerWin->Refresh();
}
}
void wxGenericListCtrl::RemoveSortIndicator()
{
if ( m_headerWin && m_headerWin->m_sortCol != -1 )
{
m_headerWin->m_sortCol = -1;
m_headerWin->m_sortAsc = true;
m_headerWin->Refresh();
}
}
int wxGenericListCtrl::GetSortIndicator() const
{
if ( m_headerWin )