From 812224488f853d318d3c18a974e053373a729ad8 Mon Sep 17 00:00:00 2001 From: Fabian Cenedese Date: Mon, 25 Sep 2017 14:45:51 +0200 Subject: [PATCH] Fix wxTreeListCtrl items comparison when using checkboxes Override DoCompareValues() to handle values of "wxDataViewCheckIconText" type which is not handled by wxDataViewModel::Compare() itself. This ensures that the items with checkboxes are sorted by their (text) contents instead of by the order of their addresses in memory as was done for them, as for any unknown values type, previously. --- src/generic/treelist.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/generic/treelist.cpp b/src/generic/treelist.cpp index 665a979190..c05cb346b4 100644 --- a/src/generic/treelist.cpp +++ b/src/generic/treelist.cpp @@ -387,6 +387,10 @@ public: unsigned col, bool ascending) const wxOVERRIDE; +protected: + virtual int DoCompareValues(const wxVariant& value1, + const wxVariant& value2) const wxOVERRIDE; + private: // The control we're associated with. wxTreeListCtrl* const m_treelist; @@ -1007,6 +1011,22 @@ wxTreeListModel::Compare(const wxDataViewItem& item1, return result; } +int wxTreeListModel::DoCompareValues(const wxVariant& value1, + const wxVariant& value2) const +{ + if ( value1.GetType() == wxS("wxDataViewCheckIconText") ) + { + wxDataViewCheckIconText iconText1, iconText2; + + iconText1 << value1; + iconText2 << value2; + + return iconText1.GetText().Cmp(iconText2.GetText()); + } + + return wxDataViewModel::DoCompareValues(value1, value2); +} + // ============================================================================ // wxTreeListCtrl implementation // ============================================================================