From 3f1991ba1a61876582a87a7e5dc1b0429d9a24d3 Mon Sep 17 00:00:00 2001 From: Leonardo Backes Vargas Date: Thu, 24 Dec 2015 20:25:50 -0200 Subject: [PATCH] Implements double click event on items, allowing to block the category expansion change. --- include/nana/gui/widgets/listbox.hpp | 21 +++++++++--- source/gui/widgets/listbox.cpp | 48 ++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index 4aa7cfb7..b266a021 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -466,13 +466,25 @@ namespace nana } }//end namespace drawerbase - struct arg_listbox + struct arg_listbox + : public event_arg + { + mutable drawerbase::listbox::item_proxy item; + bool selected; + + arg_listbox(const drawerbase::listbox::item_proxy&, bool selected); + }; + struct arg_item : public event_arg { - mutable drawerbase::listbox::item_proxy item; - bool selected; + drawerbase::listbox::index_pair item; + drawerbase::listbox::size_type column; + void block_category_change() const; + bool category_change_blocked() const; - arg_listbox(const drawerbase::listbox::item_proxy&, bool selected); + arg_item(const drawerbase::listbox::index_pair&, drawerbase::listbox::size_type column); + private: + mutable bool _m_block_change; }; namespace drawerbase @@ -484,6 +496,7 @@ namespace nana { basic_event checked; basic_event selected; + basic_event item_dbl_click; }; struct scheme diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index db0af9d3..98bc5fc1 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -3545,7 +3545,7 @@ namespace nana } } - void trigger::dbl_click(graph_reference graph, const arg_mouse&) + void trigger::dbl_click(graph_reference graph, const arg_mouse& arg) { if (essence_->pointer_where.first == essence_t::parts::header) if (cursor::size_we == essence_->lister.wd_ptr()->cursor()) @@ -3564,22 +3564,28 @@ namespace nana //Get the item which the mouse is placed. if (lister.forward(offset_y, essence_->pointer_where.second, item_pos)) { + drawerbase::listbox::size_type col=essence_->header.item_by_x(arg.pos.x - 2 - essence_->scroll.offset_x); + arg_item ai(item_pos, col==npos?-1:col); + lister.wd_ptr()->events().item_dbl_click.emit(ai); + if (!item_pos.is_category()) //being the npos of item.second is a category return; - bool do_expand = (lister.expand(item_pos.cat) == false); - lister.expand(item_pos.cat, do_expand); + if(!ai.category_change_blocked()){ + bool do_expand = (lister.expand(item_pos.cat) == false); + lister.expand(item_pos.cat, do_expand); - if(false == do_expand) - { - auto last = lister.last(); - size_type n = essence_->number_of_lister_items(false); - if (lister.backward(last, n, last)) - offset_y = last; - } - essence_->adjust_scroll_life(); - refresh(graph); - API::lazy_refresh(); + if(false == do_expand) + { + auto last = lister.last(); + size_type n = essence_->number_of_lister_items(false); + if (lister.backward(last, n, last)) + offset_y = last; + } + essence_->adjust_scroll_life(); + refresh(graph); + API::lazy_refresh(); + } } } @@ -4285,6 +4291,22 @@ namespace nana { } + arg_item::arg_item ( const nana::drawerbase::listbox::index_pair& itm, nana::drawerbase::listbox::size_type column ) + : item(itm), column(column), _m_block_change(false) + { + } + + void arg_item::block_category_change() const { + _m_block_change=true; + } + + bool arg_item::category_change_blocked() const { + return _m_block_change; + } + + + + //class listbox listbox::listbox(window wd, bool visible) {