From 77c039be428f402d1a2c982fa2be68f04e08e8e3 Mon Sep 17 00:00:00 2001 From: beru Date: Mon, 27 Apr 2015 06:18:28 +0900 Subject: [PATCH] add methods to get/set sortability of listbox --- include/nana/gui/widgets/listbox.hpp | 5 ++++- source/gui/widgets/listbox.cpp | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index 1827a585..4ad8d9da 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -552,7 +552,10 @@ By \a clicking on a header the list get \a reordered, first up, and then down al _m_ease_key(&key); } - ///Sets a strict weak ordering comparer for a column + bool sortable() const; + void sortable(bool enable); + + ///Sets a strict weak ordering comparer for a column void set_sort_compare(size_type col, std::function strick_ordering); diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index e47706d2..3f7c6a46 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -348,6 +348,16 @@ namespace nana return false; } + bool sortable() const + { + return sortable_; + } + + void sortable(bool enable) + { + sortable_ = enable; + } + std::function fetch_comp(std::size_t index) const { if(index < cont_.size()) @@ -507,6 +517,7 @@ namespace nana } private: bool visible_{true}; + bool sortable_{true}; container cont_; }; @@ -3183,7 +3194,7 @@ namespace nana auto prev_state = essence_->ptr_state; essence_->ptr_state = item_state::highlighted; //Do sort - if (essence_->pointer_where.first == parts::header && prev_state == item_state::pressed) + if (essence_->header.sortable() && essence_->pointer_where.first == parts::header && prev_state == item_state::pressed) { if(essence_->pointer_where.second < essence_->header.cont().size()) { @@ -4018,6 +4029,16 @@ namespace nana return item_proxy(ess); } + bool listbox::sortable() const + { + return _m_ess().header.sortable(); + } + + void listbox::sortable(bool enable) + { + _m_ess().header.sortable(enable); + } + void listbox::set_sort_compare(size_type col, std::function strick_ordering) { _m_ess().header.column(col).weak_ordering = std::move(strick_ordering);