Let wxListCtrl::ShowSortIndicator() implicitly enable indicators
It doesn't seem right for ShowSortIndicator() to silently do nothing if EnableSortIndicator() hadn't been called before, so make it enable the sort indicators if they hadn't been enabled yet. The alternative would be to assert in this function, but this seems less useful. Also add some comments to wxMSW version.
This commit is contained in:
@@ -426,6 +426,11 @@ protected:
|
||||
int m_colCount; // Windows doesn't have GetColumnCount so must
|
||||
// keep track of inserted/deleted columns
|
||||
|
||||
// m_sortCol and m_sortAsc are used only if m_enableSortCol is true.
|
||||
//
|
||||
// Note that m_sortCol may be set to -1, but this is not the same as
|
||||
// setting m_enableSortCol to false, as the control updates the sort
|
||||
// indicator on column click in the former case, but not in the latter.
|
||||
bool m_enableSortCol;
|
||||
bool m_sortAsc;
|
||||
int m_sortCol;
|
||||
@@ -457,7 +462,8 @@ private:
|
||||
// in-place editor control.
|
||||
void OnCharHook(wxKeyEvent& event);
|
||||
|
||||
// Draw the sort arrow arror in the header.
|
||||
// Draw the sort arrow in the header. Should only be called when sort
|
||||
// indicators are enabled.
|
||||
void DrawSortArrow();
|
||||
|
||||
// Object using for header custom drawing if necessary, may be NULL.
|
||||
|
||||
@@ -1428,6 +1428,9 @@ public:
|
||||
indicator in ascending order, or toggle it in the opposite order. To
|
||||
sort the list, call SortItems() in EVT_LIST_COL_CLICK.
|
||||
|
||||
Note that calling ShowSortIndicator() implicitly enables sort
|
||||
indicators.
|
||||
|
||||
@note In wxMSW, this will disable the header icon of the column.
|
||||
|
||||
@param enable
|
||||
@@ -1448,7 +1451,9 @@ public:
|
||||
|
||||
/**
|
||||
Show the sort indicator of a specific column in a specific direction.
|
||||
Sort indicators have to be enabled using EnableSortIndicator().
|
||||
|
||||
This function also enables showing sort indicators if
|
||||
EnableSortIndicator() hadn't been called.
|
||||
|
||||
@note This does not actually sort the list, use SortItems() for this.
|
||||
|
||||
|
||||
@@ -5108,6 +5108,7 @@ void wxGenericListCtrl::ShowSortIndicator(int idx, bool ascending)
|
||||
(idx != m_headerWin->m_sortCol ||
|
||||
ascending != m_headerWin->m_sortAsc) )
|
||||
{
|
||||
m_headerWin->m_enableSortCol = true;
|
||||
m_headerWin->m_sortCol = idx;
|
||||
m_headerWin->m_sortAsc = ascending;
|
||||
m_headerWin->Refresh();
|
||||
|
||||
@@ -1459,6 +1459,13 @@ bool wxListCtrl::IsItemChecked(long item) const
|
||||
void wxListCtrl::EnableSortIndicator(bool enable)
|
||||
{
|
||||
m_enableSortCol = enable;
|
||||
|
||||
// This is the only place where we call this function even with disabled
|
||||
// sort indicators because we may need to reset the currently shown
|
||||
// indicator after disabling it.
|
||||
//
|
||||
// Also note that we should *not* skip calling it m_enableSortCol didn't
|
||||
// change, as ShowSortIndicator() relies on it being called here.
|
||||
DrawSortArrow();
|
||||
}
|
||||
|
||||
@@ -1477,7 +1484,11 @@ void wxListCtrl::ShowSortIndicator(int idx, bool ascending)
|
||||
{
|
||||
m_sortCol = idx;
|
||||
m_sortAsc = ascending;
|
||||
DrawSortArrow();
|
||||
|
||||
// We need to enable the sort indicators if they're not enabled yet and
|
||||
// if they're already enabled, this will update the actually shown sort
|
||||
// indicator.
|
||||
EnableSortIndicator();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1485,6 +1496,8 @@ void wxListCtrl::RemoveSortIndicator()
|
||||
{
|
||||
m_sortCol = -1;
|
||||
m_sortAsc = true;
|
||||
|
||||
if ( IsSortIndicatorEnabled() )
|
||||
DrawSortArrow();
|
||||
}
|
||||
|
||||
@@ -2091,6 +2104,7 @@ long wxListCtrl::DoInsertColumn(long col, const wxListItem& item)
|
||||
SetColumnWidth(n, wxLIST_AUTOSIZE_USEHEADER);
|
||||
}
|
||||
|
||||
if ( IsSortIndicatorEnabled() )
|
||||
DrawSortArrow();
|
||||
|
||||
return n;
|
||||
@@ -2472,6 +2486,7 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
|
||||
else
|
||||
m_sortAsc = !m_sortAsc;
|
||||
m_sortCol = nmLV->iSubItem;
|
||||
if ( IsSortIndicatorEnabled() )
|
||||
DrawSortArrow();
|
||||
|
||||
eventType = wxEVT_LIST_COL_CLICK;
|
||||
@@ -3432,7 +3447,7 @@ void wxListCtrl::DrawSortArrow()
|
||||
{
|
||||
if ( ListView_GetColumn(GetHwnd(), col, &lvCol) )
|
||||
{
|
||||
if ( m_enableSortCol && col == m_sortCol )
|
||||
if ( col == m_sortCol )
|
||||
{
|
||||
if ( m_sortAsc )
|
||||
lvCol.fmt = (lvCol.fmt & ~HDF_SORTDOWN) | HDF_SORTUP;
|
||||
|
||||
Reference in New Issue
Block a user