From e4b60148e76cc91cbf1c0b66bd715e9329f79490 Mon Sep 17 00:00:00 2001 From: qPCR4vir Date: Tue, 13 Nov 2018 19:01:20 +0100 Subject: [PATCH 1/4] listbox::move_column implemented by new es_header::move_to_view_pos () --- include/nana/gui/widgets/listbox.hpp | 6 ++- source/gui/widgets/listbox.cpp | 58 ++++++++++++++++++++-------- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index ecdb9be8..7622f331 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -1461,6 +1461,9 @@ the nana::detail::basic_window member pointer scheme /// Returns the number of columns size_type column_size() const; + /// Move column to view_position + void move_column(size_type abs_pos, size_type view_pos); + void column_resizable(bool resizable); bool column_resizable() const; void column_movable(bool); @@ -1517,7 +1520,8 @@ the nana::detail::basic_window member pointer scheme ///Sets a strict weak ordering comparer for a column void set_sort_compare( size_type col, - std::function strick_ordering); + std::function strick_ordering); /// sort() and ivalidate any existing reference from display position to absolute item, that is: after sort() display offset point to different items void sort_col(size_type col, bool reverse = false); diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index deb6d881..fe0f96d0 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -17,6 +17,12 @@ * dankan1890(pr#158) * */ +#include +#include +#include +#include +#include +#include #include #include //for inline widget @@ -28,12 +34,6 @@ #include #include "skeletons/content_view.hpp" -#include -#include -#include -#include -#include - namespace nana { static void check_range(std::size_t pos, std::size_t size) @@ -130,17 +130,18 @@ namespace nana struct column : public column_interface { - native_string_type caption; - unsigned width_px; - std::pair range_width_px; + native_string_type caption; //< header title + unsigned width_px; //< column width in pixels + std::pair range_width_px; //< allowed witdh bool visible_state{ true }; - /// Absolute position of column when it was creating - size_type index; + + size_type index; //< Absolute position of column when it was created nana::align alignment{ nana::align::left }; - std::function weak_ordering; + std::function weak_ordering; std::shared_ptr font; ///< The exclusive column font @@ -186,18 +187,18 @@ namespace nana { } private: - //The definition is provided after essence + /// The definition is provided after essence void _m_refresh() noexcept; private: essence* const ess_; public: - //Implementation of column_interface + /// Implementation of column_interface unsigned width() const noexcept override { return width_px; } - // Sets the width and overrides the ranged width + /// Sets the width and overrides the ranged width void width(unsigned pixels) noexcept override { width_px = pixels; @@ -223,7 +224,7 @@ namespace nana } } - size_type position(bool disp_order) const noexcept override; //The definition is provided after essence + size_type position(bool disp_order) const noexcept override; //< The definition is provided after essence std::string text() const noexcept override { @@ -542,6 +543,24 @@ namespace nana return pos; } + + /// move col to view pos + void move_to_view_pos (size_type col, size_type view, bool front) noexcept + { + if (!front) view++; + if (view >= cont_.size() ) return; + + auto i = std::find_if( cont_.begin(), + cont_.end(), + [&](const column& c){return col==c.index;}); + + if (i==cont_.end()) return; + + auto col_from = *i; + cont_.erase(i); + cont_.insert(cont_.begin()+ view, col_from); + + } /// move the col originaly at "from" to the position currently in front (or after) the col originaly at index "to" invalidating some current index void move(size_type from, size_type to, bool front) noexcept { @@ -6049,5 +6068,12 @@ namespace nana internal_scope_guard lock; return _m_ess().content_view->scroll_operation(); } + + /// Move column to view_position + void listbox::move_column(size_type abs_pos, size_type view_pos) + { + internal_scope_guard lock; + return _m_ess().header.move_to_view_pos(abs_pos, view_pos, true); + } //end class listbox }//end namespace nana From c0de9ee4602e86757985b19375cc301de9fff01d Mon Sep 17 00:00:00 2001 From: qPCR4vir Date: Tue, 13 Nov 2018 19:05:19 +0100 Subject: [PATCH 2/4] listbox::reorder_columns implemented by move_column --- include/nana/gui/widgets/listbox.hpp | 11 ++++++- source/gui/widgets/listbox.cpp | 44 ++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index 7622f331..cae6ec92 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -1464,7 +1464,16 @@ the nana::detail::basic_window member pointer scheme /// Move column to view_position void move_column(size_type abs_pos, size_type view_pos); - void column_resizable(bool resizable); + /// Sort columns in range first_col to last_col inclusive using the values from a row + void reorder_columns(size_type first_col, + size_type last_col, + index_pair row, bool reverse, + std::function comp); + + void column_resizable(bool resizable); bool column_resizable() const; void column_movable(bool); bool column_movable() const; diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index fe0f96d0..e6c7e97a 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -6069,11 +6069,43 @@ namespace nana return _m_ess().content_view->scroll_operation(); } - /// Move column to view_position - void listbox::move_column(size_type abs_pos, size_type view_pos) - { - internal_scope_guard lock; - return _m_ess().header.move_to_view_pos(abs_pos, view_pos, true); - } + /// Move column to view_position + void listbox::move_column(size_type abs_pos, size_type view_pos) + { + internal_scope_guard lock; + return _m_ess().header.move_to_view_pos(abs_pos, view_pos, true); + } + + /// Sort columns in range first_col to last_col inclusive using a row + void listbox::reorder_columns(size_type first_col, + size_type last_col, + index_pair row, bool reverse, + std::function comp) + { + if (first_col<0 || last_col<=first_col) + return; + if (last_col >= column_size()) + return; + std::vector new_idx; + for(size_type i=first_col; i<=last_col; ++i) new_idx.push_back(i); + const item_proxy & ip_row=this->at(row); + internal_scope_guard lock; + const nana::any *pnany=_m_ess().lister.anyobj(row,false); + std::sort(new_idx.begin(), new_idx.end(), [&](size_type col1, + size_type col2) + { + return comp(ip_row.text(col1), col1, + ip_row.text(col2), col2, + pnany, reverse); + }); + for(size_t i=0; i Date: Tue, 13 Nov 2018 19:42:07 +0100 Subject: [PATCH 3/4] update --- source/gui/widgets/listbox.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index e6c7e97a..dd970a65 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -6074,6 +6074,7 @@ namespace nana { internal_scope_guard lock; return _m_ess().header.move_to_view_pos(abs_pos, view_pos, true); + _m_ess().update(); } /// Sort columns in range first_col to last_col inclusive using a row @@ -6105,6 +6106,7 @@ namespace nana { move_column(new_idx[i],i+first_col); } + _m_ess().update(); } //end class listbox From 9a523366459d1dfc022ccf341c3e7858d79c48af Mon Sep 17 00:00:00 2001 From: Ariel Vina-Rodriguez Date: Fri, 18 Jan 2019 11:09:16 +0100 Subject: [PATCH 4/4] typos --- source/gui/widgets/listbox.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index dd970a65..dcdd0eca 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -132,7 +132,7 @@ namespace nana { native_string_type caption; //< header title unsigned width_px; //< column width in pixels - std::pair range_width_px; //< allowed witdh + std::pair range_width_px; //< allowed width bool visible_state{ true }; @@ -441,7 +441,7 @@ namespace nana throw std::invalid_argument("listbox: invalid header index"); } - /// find and return a ref to the column that originaly was at position "pos" previous to any list reorganization. + /// find and return a ref to the column that originally was at position "pos" previous to any list reorganization. column& at(size_type pos, bool disp_order = false) { check_range(pos, cont_.size()); @@ -508,7 +508,7 @@ namespace nana return{ left, 0 }; } - /// return the original index of the visible col currently before(in front of) or after the col originaly at index "index" + /// return the original index of the visible col currently before(in front of) or after the col originally at index "index" size_type next(size_type index) const noexcept { bool found_me = false; @@ -561,7 +561,7 @@ namespace nana cont_.insert(cont_.begin()+ view, col_from); } - /// move the col originaly at "from" to the position currently in front (or after) the col originaly at index "to" invalidating some current index + /// move the col originally at "from" to the position currently in front (or after) the col originally at index "to" invalidating some current index void move(size_type from, size_type to, bool front) noexcept { if ((from == to) || (from >= cont_.size()) || (to >= cont_.size()))