Add GetUpdatedAscendingSortIndicator() helper function
It seems like this function will need to be used in every implementation of EVT_LIST_COL_CLICK handler when using sorting, so it makes sense to provide it in the library itself.
This commit is contained in:
@@ -451,6 +451,12 @@ public:
|
|||||||
void RemoveSortIndicator() { ShowSortIndicator(-1); }
|
void RemoveSortIndicator() { ShowSortIndicator(-1); }
|
||||||
virtual int GetSortIndicator() const { return -1; }
|
virtual int GetSortIndicator() const { return -1; }
|
||||||
virtual bool IsAscendingSortIndicator() const { return true; }
|
virtual bool IsAscendingSortIndicator() const { return true; }
|
||||||
|
bool GetUpdatedAscendingSortIndicator(int col) const
|
||||||
|
{
|
||||||
|
// If clicking on the same column by which we already sort, toggle the sort
|
||||||
|
// direction, otherwise use ascending sort by default.
|
||||||
|
return col == GetSortIndicator() ? !IsAscendingSortIndicator() : true;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Return pointer to the corresponding m_imagesXXX.
|
// Return pointer to the corresponding m_imagesXXX.
|
||||||
|
|||||||
@@ -1460,6 +1460,31 @@ public:
|
|||||||
*/
|
*/
|
||||||
int GetSortIndicator() const;
|
int GetSortIndicator() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the new value to use for sort indicator after clicking a
|
||||||
|
column.
|
||||||
|
|
||||||
|
This helper function can be useful in the EVT_LIST_COL_CLICK handler
|
||||||
|
when it updates the sort indicator after the user clicked on a column.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
@code
|
||||||
|
void MyListCtrl::OnColClick(wxListEvent& event)
|
||||||
|
{
|
||||||
|
int col = event.GetColumn();
|
||||||
|
if ( col == -1 )
|
||||||
|
return; // clicked outside any column.
|
||||||
|
|
||||||
|
const bool ascending = GetUpdatedAscendingSortIndicator(col);
|
||||||
|
SortItems(MyCompareFunction, ascending);
|
||||||
|
ShowSortIndicator(col, ascending);
|
||||||
|
}
|
||||||
|
@endcode
|
||||||
|
|
||||||
|
@since 3.1.6
|
||||||
|
*/
|
||||||
|
bool GetUpdatedAscendingSortIndicator(int col) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns @true if the sort indicator direction is ascending,
|
Returns @true if the sort indicator direction is ascending,
|
||||||
@false when the direction is descending.
|
@false when the direction is descending.
|
||||||
|
|||||||
@@ -1089,15 +1089,8 @@ void MyListCtrl::OnColClick(wxListEvent& event)
|
|||||||
return; // clicked outside any column.
|
return; // clicked outside any column.
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
// sort on item data (SetItemData)
|
||||||
|
const bool ascending = GetUpdatedAscendingSortIndicator(col);
|
||||||
if ( SortItems(MyCompareFunction, ascending) )
|
if ( SortItems(MyCompareFunction, ascending) )
|
||||||
{
|
{
|
||||||
ShowSortIndicator(col, ascending);
|
ShowSortIndicator(col, ascending);
|
||||||
|
|||||||
Reference in New Issue
Block a user