From 67752172a087d2b30440aefb3fbc7453ca846548 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Mon, 2 Nov 2015 23:39:32 +0800 Subject: [PATCH] fix tabbar flying-close issue --- include/nana/gui/widgets/tabbar.hpp | 41 ++++++++++++++++++++++++----- source/gui/widgets/tabbar.cpp | 23 +++++++++------- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/include/nana/gui/widgets/tabbar.hpp b/include/nana/gui/widgets/tabbar.hpp index 206f3e4e..2ed73ab4 100644 --- a/include/nana/gui/widgets/tabbar.hpp +++ b/include/nana/gui/widgets/tabbar.hpp @@ -140,7 +140,16 @@ namespace nana : public drawer_trigger { public: - enum toolbox_button_t{ButtonAdd, ButtonScroll, ButtonList, ButtonClose}; + //enum toolbox_button_t{ButtonAdd, ButtonScroll, ButtonList, ButtonClose}; //deprecated + + enum class kits + { + add, + scroll, + list, + close + }; + trigger(); ~trigger(); void activate(std::size_t); @@ -158,7 +167,7 @@ namespace nana void tab_image(size_t, const nana::paint::image&); void text(std::size_t, const nana::string&); nana::string text(std::size_t) const; - bool toolbox_button(toolbox_button_t, bool); + bool toolbox(kits, bool); private: void attached(widget_reference, graph_reference) override; void detached() override; @@ -182,18 +191,28 @@ namespace nana typedef Type value_type; ///< The type of element data which is stored in the tabbar. typedef drawerbase::tabbar::item_renderer item_renderer; ///< A user-defined item renderer should be derived from this interface. + //These member types is deprecated, they will be removed in Nana 1.3 struct button_add{}; ///< The type identifies the add button of the tabbar's toolbox. struct button_scroll{}; ///< The type identifies the scroll button of the tabbar's toolbox. struct button_list{}; ///< The type identifies the list button of the tabbar's toolbox. struct button_close{}; ///< The type identifies the close button of the tabbar's toolbox. - /// A template class identifies the buttons of the tabbar’s toolbox. Refer to notes for more details. + //This template class is deprecated, it will be removed in 1.3 + /// A template class identifies the buttons of the tabbar's toolbox. Refer to notes for more details. template struct button_container { typedef meta::fixed_type_set type_set; }; + enum class kits + { + add, ///< The type identifies the add button of the tabbar's toolbox. + scroll, ///< The type identifies the scroll button of the tabbar's toolbox + list, ///< The type identifies the list button of the tabbar's toolbox + close ///< The type identifies the close button of the tabbar's toolbox + }; + tabbar() { evt_agent_.reset(new drawerbase::tabbar::event_agent(*this, this->get_drawer_trigger())); @@ -304,22 +323,30 @@ namespace nana auto & tg = this->get_drawer_trigger(); bool redraw = false; + using inner_kits = drawerbase::tabbar::trigger::kits; + if(type_set::template count::value) - redraw |= tg.toolbox_button(tg.ButtonAdd, enable); + redraw |= tg.toolbox(inner_kits::add, enable); if(type_set::template count::value) - redraw |= tg.toolbox_button(tg.ButtonScroll, enable); + redraw |= tg.toolbox(inner_kits::scroll, enable); if(type_set::template count::value) - redraw |= tg.toolbox_button(tg.ButtonList, enable); + redraw |= tg.toolbox(inner_kits::add, enable); if(type_set::template count::value) - redraw |= tg.toolbox_button(tg.ButtonClose, enable); + redraw |= tg.toolbox(inner_kits::close, enable); if(redraw) API::refresh_window(this->handle()); } + void toolbox(kits kit, bool enable) + { + if (this->get_drawer_trigger().toolbox(kit, enable)) + API::refresh_window(this->handle()); + } + void text(std::size_t pos, const nana::string& str) /// Sets the title of the specified item, If pos is invalid, the method throws an std::out_of_range object. { this->get_drawer_trigger().text(pos, str); diff --git a/source/gui/widgets/tabbar.cpp b/source/gui/widgets/tabbar.cpp index 3fde24cc..c0acd9f3 100644 --- a/source/gui/widgets/tabbar.cpp +++ b/source/gui/widgets/tabbar.cpp @@ -435,6 +435,7 @@ namespace nana { if ((nullptr == evt_agent_) || evt_agent_->removed(pos)) { + API::show_window(iterator_at(pos)->relative, false); list_.erase(iterator_at(pos)); _m_adjust(); @@ -459,6 +460,8 @@ namespace nana basis_.scroll_pixels = 0; } + if (basis_.active != ::nana::npos) + API::show_window(iterator_at(basis_.active)->relative, true); if(evt_agent_) evt_agent_->activated(basis_.active); return true; @@ -1192,23 +1195,23 @@ namespace nana return layouter_->text(i); } - bool trigger::toolbox_button(toolbox_button_t btn, bool enable) + bool trigger::toolbox(kits btn, bool enable) { - toolbox::button_t tb = toolbox::ButtonSize; - toolbox & tbobj = layouter_->toolbox_object(); + auto tb = toolbox::ButtonSize; + auto& tbox = layouter_->toolbox_object(); switch(btn) { - case trigger::ButtonAdd: + case kits::add: tb = toolbox::ButtonAdd; break; - case trigger::ButtonList: + case kits::list: tb = toolbox::ButtonList; break; - case trigger::ButtonClose: + case kits::close: tb = toolbox::ButtonClose; break; - case trigger::ButtonScroll: - tbobj.enable(toolbox::ButtonScrollBack, enable); - return tbobj.enable(tbobj.ButtonScrollNext, enable); + case kits::scroll: + tbox.enable(toolbox::ButtonScrollBack, enable); + return tbox.enable(tbox.ButtonScrollNext, enable); } - return (tb != toolbox::ButtonSize ? tbobj.enable(tb, enable) : false); + return (tb != toolbox::ButtonSize ? tbox.enable(tb, enable) : false); } void trigger::attached(widget_reference widget, graph_reference graph)