From eb7ae0d635b206ae15da8ed59e34246613f73ee7 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Mon, 13 Feb 2017 07:18:39 +0800 Subject: [PATCH] fix bug that treebox.clear only rm the 1st node --- include/nana/gui/widgets/categorize.hpp | 2 +- include/nana/gui/widgets/detail/tree_cont.hpp | 13 +++++++++---- include/nana/gui/widgets/treebox.hpp | 3 +++ source/gui/widgets/categorize.cpp | 4 ++-- source/gui/widgets/treebox.cpp | 4 ++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/include/nana/gui/widgets/categorize.hpp b/include/nana/gui/widgets/categorize.hpp index 1e64fa14..dcbdde12 100644 --- a/include/nana/gui/widgets/categorize.hpp +++ b/include/nana/gui/widgets/categorize.hpp @@ -1,7 +1,7 @@ /** * A Categorize Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2017 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/detail/tree_cont.hpp b/include/nana/gui/widgets/detail/tree_cont.hpp index c9684ba6..628007d5 100644 --- a/include/nana/gui/widgets/detail/tree_cont.hpp +++ b/include/nana/gui/widgets/detail/tree_cont.hpp @@ -1,6 +1,6 @@ /* * A Tree Container class implementation - * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -76,12 +76,17 @@ namespace detail ~tree_cont() { - clear(); + clear(&root_); } - void clear() + void clear(node_type* node) { - remove(root_.child); + while (node->child) + { + //If there is a sibling of child, the root_.child + //will be assigned with the sibling. + remove(node->child); + } } bool verify(const node_type* node) const diff --git a/include/nana/gui/widgets/treebox.hpp b/include/nana/gui/widgets/treebox.hpp index 2f4fe7d7..60b17116 100644 --- a/include/nana/gui/widgets/treebox.hpp +++ b/include/nana/gui/widgets/treebox.hpp @@ -201,6 +201,9 @@ namespace nana /// Set the check state, and it returns itself. item_proxy& check(bool); + /// Clears the child nodes + item_proxy& clear(); + /// Return true when the node is expanded \todo change to expanded ?? bool expanded() const; diff --git a/source/gui/widgets/categorize.cpp b/source/gui/widgets/categorize.cpp index cf29e267..0ce7646c 100644 --- a/source/gui/widgets/categorize.cpp +++ b/source/gui/widgets/categorize.cpp @@ -1,7 +1,7 @@ /* * A Categorize Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -343,7 +343,7 @@ namespace nana { if(tree_.get_root()->child) { - tree_.clear(); + tree_.clear(tree_.get_root()); return true; } return false; diff --git a/source/gui/widgets/treebox.cpp b/source/gui/widgets/treebox.cpp index e3bc094d..fc03ddc1 100644 --- a/source/gui/widgets/treebox.cpp +++ b/source/gui/widgets/treebox.cpp @@ -2175,8 +2175,8 @@ namespace nana void treebox::clear() { - auto impl = get_drawer_trigger().impl(); - impl->attr.tree_cont.clear(); + auto& tree_cont = get_drawer_trigger().impl()->attr.tree_cont; + tree_cont.clear(tree_cont.get_root()); get_drawer_trigger().draw(); }