From 91675cb32d76a1e25879b942aac7f9292eed49b7 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Thu, 1 Nov 2018 06:37:26 +0800 Subject: [PATCH] improve listbox methods listbox::hovered() and listbox::insert_item() --- include/nana/gui/widgets/listbox.hpp | 13 ++++-- source/gui/widgets/listbox.cpp | 70 +++++++++++++++++++++++----- 2 files changed, 68 insertions(+), 15 deletions(-) diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index dde46edc..ae02ef38 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -1481,9 +1481,19 @@ the nana::detail::basic_window member pointer scheme */ void insert_item(const index_pair& abs_pos, const ::std::wstring& text); + + void insert_item(index_pair abs_pos, const listbox& rhs, const index_pairs& indexes); + /// Returns an index of item which contains the specified point. index_pair cast(const point & screen_pos) const; + /// Returns the item which is hovered + /** + * @param return_end Indicates whether to return an end position instead of empty position if an item is not hovered. + * @return The position of the hovered item. If return_end is true, it returns the position next to the last item of last category if an item is not hovered. + */ + index_pair hovered(bool return_end) const; + /// Returns the absolute position of column which contains the specified point. size_type column_from_pos(const point & pos) const; @@ -1497,9 +1507,6 @@ the nana::detail::basic_window member pointer scheme void erase(index_pairs indexes); ///column_size(), rhs.column_size()); + + if (0 == columns) + return; + + item_proxy it_new = this->at(abs_pos.cat).end(); + for (auto & idx : indexes) + { + auto it_src = rhs.at(idx.cat).at(idx.item); + + if (abs_pos.item < this->at(abs_pos.cat).size()) + { + this->insert_item(abs_pos, it_src.text(0)); + it_new = this->at(abs_pos); + } + else + { + it_new = this->at(abs_pos.cat).append(it_src.text(0)); + } + + for (std::size_t col = 1; col < columns; ++col) + it_new.text(col, it_src.text(col)); + + ++abs_pos.item; + } + } + listbox::cat_proxy listbox::at(size_type pos) { internal_scope_guard lock; @@ -5663,6 +5692,35 @@ namespace nana return index_pair{ npos, npos }; } + listbox::index_pair listbox::hovered(bool return_end) const + { + using parts = drawerbase::listbox::essence::parts; + + internal_scope_guard lock; + + auto cur_pos = API::cursor_position(); + API::calc_window_point(handle(), cur_pos); + + auto pt_where = _m_ess().where(cur_pos); + + if ((pt_where.first == parts::list || pt_where.first == parts::checker) && pt_where.second != npos) + { + auto pos = _m_ess().lister.advance(_m_ess().first_display(), static_cast(pt_where.second)); + if (return_end && pos.is_category()) + { + if (0 < pos.cat) + --pos.cat; + pos.item = this->size_item(pos.cat); + } + return pos; + + } + else if (return_end) + return index_pair{ this->size_categ() - 1, this->size_item(this->size_categ() - 1) }; + + return index_pair{ npos, npos }; + } + auto listbox::column_at(size_type pos, bool disp_order) -> column_interface& { internal_scope_guard lock; @@ -5852,18 +5910,6 @@ namespace nana return item_proxy(ess); } - listbox::index_pair listbox::hovered() const - { - internal_scope_guard lock; - using parts = drawerbase::listbox::essence::parts; - - auto & ptr_where = _m_ess().pointer_where; - if ((ptr_where.first == parts::list || ptr_where.first == parts::checker) && ptr_where.second != npos) - return _m_ess().lister.advance(_m_ess().first_display(), static_cast(ptr_where.second)); - - return index_pair{ npos, npos }; - } - bool listbox::sortable() const { internal_scope_guard lock;