diff --git a/include/nana/gui/widgets/group.hpp b/include/nana/gui/widgets/group.hpp index 1985c961..6ec70c0a 100644 --- a/include/nana/gui/widgets/group.hpp +++ b/include/nana/gui/widgets/group.hpp @@ -67,6 +67,10 @@ namespace nana{ group& collocate() noexcept; group& div(const char* div_str) noexcept; 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/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index aecf1ade..0202d028 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -1429,6 +1429,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/include/nana/gui/widgets/toolbar.hpp b/include/nana/gui/widgets/toolbar.hpp index cc0f4e24..02e88c6c 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 @@ -98,6 +98,8 @@ namespace nana void separate(); ///< Adds a separator. drawerbase::toolbar::item_proxy append(const ::std::string& text, const nana::paint::image& img); ///< Adds a control button. drawerbase::toolbar::item_proxy 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/place.cpp b/source/gui/place.cpp index 7c66b0aa..d4ecf449 100644 --- a/source/gui/place.cpp +++ b/source/gui/place.cpp @@ -3271,6 +3271,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 (...) { diff --git a/source/gui/widgets/group.cpp b/source/gui/widgets/group.cpp index f84058ea..b3c2658d 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(); diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index 3253a882..d26143ea 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -316,6 +316,11 @@ namespace nana return cont_.back().index; } + void clear() + { + cont_.clear(); + } + unsigned width_px() const noexcept ///< the visible width of the whole header { unsigned pixels = 0; @@ -1538,9 +1543,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()) @@ -1548,6 +1581,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) @@ -5467,6 +5501,15 @@ namespace nana return pos; } + void listbox::clear_headers() + { + internal_scope_guard lock; + auto & ess = _m_ess(); + ess.lister.erase(); + 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() { diff --git a/source/gui/widgets/toolbar.cpp b/source/gui/widgets/toolbar.cpp index d34fc524..963b99cf 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 @@ -55,8 +55,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) @@ -118,6 +117,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 }; @@ -467,6 +475,12 @@ namespace nana return {*this, get_drawer_trigger().items().size() - 1u}; } + 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(); 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;