From dc23624ee66a769cd002c4266ac00999a8e5c1ee Mon Sep 17 00:00:00 2001 From: besh81 Date: Fri, 23 Feb 2018 16:14:10 +0100 Subject: [PATCH 1/8] Add listbox::clear_headers() and menubar::clear() Added listbox::clear_headers() to remove all the columns from the listbox Added menubar::clear() to remove all the items from menubar --- include/nana/gui/widgets/listbox.hpp | 2 ++ include/nana/gui/widgets/menubar.hpp | 1 + source/gui/widgets/listbox.cpp | 13 +++++++++++++ source/gui/widgets/menubar.cpp | 7 +++++++ 4 files changed, 23 insertions(+) diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index d57ee4c6..dd4d13d9 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -1411,6 +1411,8 @@ the nana::detail::basic_window member pointer scheme size_type append_header(std::string text_utf8, unsigned width = 120); size_type append_header(std::wstring text, unsigned width = 120); + void clear_headers(); ///< Removes all the columns. + cat_proxy append(std::string category); ///< Appends a new category to the end cat_proxy append(std::wstring category); ///< Appends a new category to the end void append(std::initializer_list categories); ///< Appends categories to the end diff --git a/include/nana/gui/widgets/menubar.hpp b/include/nana/gui/widgets/menubar.hpp index 24c965b5..75158284 100644 --- a/include/nana/gui/widgets/menubar.hpp +++ b/include/nana/gui/widgets/menubar.hpp @@ -95,6 +95,7 @@ namespace nana menu& push_back(const std::string&); ///< Appends a new (empty) menu. menu& at(size_t index) const; ///< Gets the menu specified by index. std::size_t length() const; ///< Number of menus. + void clear(); ///< Removes all the menus. /// Deselects the menu /** diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index c2d75048..c6e47f8c 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -307,6 +307,11 @@ namespace nana return cont_.back().index; } + void clear() + { + cont_.clear(); + } + unsigned pixels() const noexcept ///< the visible width of the whole header { unsigned pixels = 0; @@ -5319,6 +5324,14 @@ namespace nana return pos; } + void listbox::clear_headers() + { + internal_scope_guard lock; + auto & ess = _m_ess(); + ess.header.clear(); + ess.update(); + } + listbox::cat_proxy listbox::append(std::string s) { internal_scope_guard lock; diff --git a/source/gui/widgets/menubar.cpp b/source/gui/widgets/menubar.cpp index 5071c094..3c211ba6 100644 --- a/source/gui/widgets/menubar.cpp +++ b/source/gui/widgets/menubar.cpp @@ -625,6 +625,13 @@ namespace nana { return get_drawer_trigger().ess().items.size(); } + + void menubar::clear() + { + internal_scope_guard lock; + get_drawer_trigger().ess().items.clear(); + API::refresh_window(handle()); + } bool menubar::cancel() { From 4c200e68a5c405d995c01fb89384587cc7a7521c Mon Sep 17 00:00:00 2001 From: besh81 Date: Mon, 26 Feb 2018 15:45:31 +0100 Subject: [PATCH 2/8] Added listbox::clear_headers() and menubar::clear() Added listbox::clear_headers() to remove all the columns (included categories and items) from the listbox Added menubar::clear() to remove all the items from menubar --- source/gui/widgets/listbox.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index c6e47f8c..a47142b2 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -5328,6 +5328,7 @@ namespace nana { internal_scope_guard lock; auto & ess = _m_ess(); + ess.lister.erase(); ess.header.clear(); ess.update(); } From 9690c38b83fd6bfc8481dfbb72980b1373fec8f0 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Fri, 2 Mar 2018 03:39:25 +0800 Subject: [PATCH 3/8] fix crash that occurs when place::modify a field which isn't leftmost one --- source/gui/place.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/source/gui/place.cpp b/source/gui/place.cpp index f243fcf0..7b79e910 100644 --- a/source/gui/place.cpp +++ b/source/gui/place.cpp @@ -1,7 +1,7 @@ /* * An Implementation of Place for Layout * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -3184,6 +3184,22 @@ namespace nana modified_ptr->div_owner = div_owner; modified_ptr->div_next = div_next; + + if (div_owner) + { + implement::division * pv_div = nullptr; + //Updates the div_next of the div at front of modified one. + for (auto & div : div_owner->children) + { + if (div.get() == modified_ptr) + { + if (pv_div) + pv_div->div_next = modified_ptr; + break; + } + pv_div = div.get(); + } + } } catch (...) { From 592da3fe4fed108daaea9572b6e61161156a8281 Mon Sep 17 00:00:00 2001 From: besh81 Date: Sat, 17 Mar 2018 09:40:11 +0100 Subject: [PATCH 4/8] Added group.field_display() and group.erase() --- include/nana/gui/widgets/group.hpp | 4 ++++ source/gui/widgets/group.cpp | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/nana/gui/widgets/group.hpp b/include/nana/gui/widgets/group.hpp index 2e264289..8507c555 100644 --- a/include/nana/gui/widgets/group.hpp +++ b/include/nana/gui/widgets/group.hpp @@ -66,6 +66,10 @@ namespace nana{ group& collocate() throw(); group& div(const char* div_str) throw(); field_reference operator[](const char* field); + + void field_display(const char* field_name, bool display); /// Widget* create_child(const char* field, Args && ... args) diff --git a/source/gui/widgets/group.cpp b/source/gui/widgets/group.cpp index 87d2ebc6..aedb110f 100644 --- a/source/gui/widgets/group.cpp +++ b/source/gui/widgets/group.cpp @@ -194,6 +194,21 @@ namespace nana{ return impl_->place_content.field(field); } + void group::field_display(const char* field_name, bool display) + { + impl_->place_content.field_display(field_name, display); + } + + bool group::field_display(const char* field_name) const + { + return impl_->place_content.field_display(field_name); + } + + void group::erase(window handle) + { + impl_->place_content.erase(handle); + } + void group::_m_add_child(const char* field, widget* wdg) { impl_->place_content[field] << wdg->handle(); From fcb5c816312baeace680cbb3235e02abad0eb940 Mon Sep 17 00:00:00 2001 From: besh81 Date: Sun, 18 Mar 2018 10:48:17 +0100 Subject: [PATCH 5/8] Added toolbar.clear() --- include/nana/gui/widgets/toolbar.hpp | 1 + source/gui/widgets/toolbar.cpp | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/nana/gui/widgets/toolbar.hpp b/include/nana/gui/widgets/toolbar.hpp index d92c7f8a..b3b7223e 100644 --- a/include/nana/gui/widgets/toolbar.hpp +++ b/include/nana/gui/widgets/toolbar.hpp @@ -90,6 +90,7 @@ namespace nana void separate(); ///< Adds a separator. void append(const ::std::string& text, const nana::paint::image& img); ///< Adds a control button. void append(const ::std::string& text); ///< Adds a control button. + void clear(); ///< Removes all control buttons and separators. bool enable(size_type index) const; void enable(size_type index, bool enable_state); void scale(unsigned s); ///< Sets the scale of control button. diff --git a/source/gui/widgets/toolbar.cpp b/source/gui/widgets/toolbar.cpp index 953e4796..7fb927cc 100644 --- a/source/gui/widgets/toolbar.cpp +++ b/source/gui/widgets/toolbar.cpp @@ -57,8 +57,7 @@ namespace nana ~item_container() { - for(auto ptr : cont_) - delete ptr; + clear(); } void insert(size_type pos, std::string text, const nana::paint::image& img, item_type::kind type) @@ -120,6 +119,15 @@ namespace nana { return cont_.at(pos); } + + void clear() + { + for(auto ptr : cont_) + delete ptr; + + cont_.clear(); + } + private: container_type cont_; size_t right_{ npos }; @@ -461,6 +469,12 @@ namespace nana API::refresh_window(this->handle()); } + void toolbar::clear() + { + get_drawer_trigger().items().clear(); + API::refresh_window(this->handle()); + } + bool toolbar::enable(size_type pos) const { auto & items = get_drawer_trigger().items(); From dd0c75fb0d01567c777629b61a78abc41730eca3 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 1 Apr 2018 00:02:24 +0800 Subject: [PATCH 6/8] update file information --- include/nana/gui/widgets/group.hpp | 2 +- include/nana/gui/widgets/toolbar.hpp | 2 +- source/gui/widgets/group.cpp | 2 +- source/gui/widgets/toolbar.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/nana/gui/widgets/group.hpp b/include/nana/gui/widgets/group.hpp index 8507c555..46a15e20 100644 --- a/include/nana/gui/widgets/group.hpp +++ b/include/nana/gui/widgets/group.hpp @@ -1,7 +1,7 @@ /** * A group widget implementation * Nana C++ Library(http://www.nanaro.org) - * Copyright(C) 2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2015-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at diff --git a/include/nana/gui/widgets/toolbar.hpp b/include/nana/gui/widgets/toolbar.hpp index b3b7223e..a8684f8f 100644 --- a/include/nana/gui/widgets/toolbar.hpp +++ b/include/nana/gui/widgets/toolbar.hpp @@ -1,7 +1,7 @@ /** * A Toolbar Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at diff --git a/source/gui/widgets/group.cpp b/source/gui/widgets/group.cpp index aedb110f..74475099 100644 --- a/source/gui/widgets/group.cpp +++ b/source/gui/widgets/group.cpp @@ -1,7 +1,7 @@ /** * A group widget implementation * Nana C++ Library(http://www.nanaro.org) - * Copyright(C) 2015-2017 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2015-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at diff --git a/source/gui/widgets/toolbar.cpp b/source/gui/widgets/toolbar.cpp index 7fb927cc..95f064f1 100644 --- a/source/gui/widgets/toolbar.cpp +++ b/source/gui/widgets/toolbar.cpp @@ -1,7 +1,7 @@ /* * A Toolbar Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at From 335305c97c369ca3dd1b6cac87f760ecc6fcc7f0 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 1 Apr 2018 00:11:19 +0800 Subject: [PATCH 7/8] fix bug that treebox::item_proxy::size returns the depth of the node --- source/gui/widgets/treebox.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/gui/widgets/treebox.cpp b/source/gui/widgets/treebox.cpp index 88468861..ac4c2799 100644 --- a/source/gui/widgets/treebox.cpp +++ b/source/gui/widgets/treebox.cpp @@ -1,7 +1,7 @@ /* * A Treebox Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -958,10 +958,14 @@ namespace nana return *this; } + std::size_t item_proxy::size() const { std::size_t n = 0; - for(auto child = node_->child; child; child = child->child) + + //Fixed by ErrorFlynn + //this method incorrectly returned the number of levels beneath the nodes using child = child->child + for(auto child = node_->child; child; child = child->next) ++n; return n; From 9370f13a1bab1a25f0ef8b8bf47ab3d0cae658a0 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Thu, 12 Apr 2018 12:46:52 +0800 Subject: [PATCH 8/8] fix crash occurs when listbox is selecting item after pressing shift(#312) --- source/gui/widgets/listbox.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index a47142b2..ff6363d7 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -1522,9 +1522,37 @@ namespace nana return n; } - template - std::vector> select_display_range_if(const index_pair& fr_abs, index_pair to_dpl, bool deselect_others, Pred pred) + /// Finds a good item or category if an item specified by pos is invaild + index_pair find_next_good(index_pair pos, bool ignore_category) const noexcept { + //Return the pos if it is good + if (this->good(pos)) + return pos; + + while(pos.cat < this->categories_.size()) + { + if ((pos.npos == pos.item) && !ignore_category) + return pos; + + auto cat_item_size = this->get(pos.cat)->items.size(); + + if (pos.item < cat_item_size) + return pos; + + if ((pos.npos == pos.item) && (cat_item_size > 0) && ignore_category) + return index_pair{ pos.cat, 0 }; + + ++pos.cat; + pos.item = pos.npos; + } + return index_pair{}; + } + + template + std::vector> select_display_range_if(index_pair fr_abs, index_pair to_dpl, bool deselect_others, Pred pred) + { + fr_abs = find_next_good(fr_abs, true); + if (to_dpl.empty()) { if (fr_abs.empty()) @@ -1532,6 +1560,7 @@ namespace nana to_dpl = this->last(); } + auto fr_dpl = (fr_abs.is_category() ? fr_abs : this->index_cast(fr_abs, false)); //Converts an absolute position to display position if (fr_dpl > to_dpl)