From dc23624ee66a769cd002c4266ac00999a8e5c1ee Mon Sep 17 00:00:00 2001 From: besh81 Date: Fri, 23 Feb 2018 16:14:10 +0100 Subject: [PATCH 1/2] 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/2] 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(); }