From 3f1991ba1a61876582a87a7e5dc1b0429d9a24d3 Mon Sep 17 00:00:00 2001 From: Leonardo Backes Vargas Date: Thu, 24 Dec 2015 20:25:50 -0200 Subject: [PATCH 1/2] 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) { From 4609bfc458cf976bcd16443c37e0495e6e2daacc Mon Sep 17 00:00:00 2001 From: Leonardo Backes Vargas Date: Mon, 11 Jan 2016 23:28:20 -0200 Subject: [PATCH 2/2] Merge cnjinhao/develop --- include/nana/gui/widgets/listbox.hpp | 12 +++++--- source/gui/widgets/listbox.cpp | 46 +++++++++++++++++++++------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index b266a021..ed70e8ff 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -474,15 +474,14 @@ namespace nana arg_listbox(const drawerbase::listbox::item_proxy&, bool selected); }; - struct arg_item + struct arg_category : public event_arg { - drawerbase::listbox::index_pair item; - drawerbase::listbox::size_type column; + drawerbase::listbox::cat_proxy category; void block_category_change() const; bool category_change_blocked() const; - arg_item(const drawerbase::listbox::index_pair&, drawerbase::listbox::size_type column); + arg_category(const drawerbase::listbox::cat_proxy&); private: mutable bool _m_block_change; }; @@ -496,7 +495,7 @@ namespace nana { basic_event checked; basic_event selected; - basic_event item_dbl_click; + basic_event category_dbl_click; }; struct scheme @@ -628,6 +627,9 @@ By \a clicking on one header the list get \a reordered, first up, and then down } item_proxy at(const index_pair &abs_pos) const; + index_pair at(const point & pos) const; + columns_indexs column_from_pos(const point & pos); + void insert(const index_pair&, ::std::string); /// where(int x, int y){ + std::pair new_where; if(2 < x && x < static_cast(graph->width()) - 2 && 1 < y && y < static_cast(graph->height()) - 1) { @@ -2201,7 +2200,12 @@ namespace nana new_where.first = parts::unknown; new_where.second = npos; } + return new_where; + } + bool calc_where(int x, int y) + { + std::pair< parts, size_t > new_where=where(x,y); if (new_where == pointer_where) return false; @@ -3564,13 +3568,12 @@ 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; + arg_category ai(cat_proxy(essence_, item_pos.cat)); + lister.wd_ptr()->events().category_dbl_click.emit(ai); + if(!ai.category_change_blocked()){ bool do_expand = (lister.expand(item_pos.cat) == false); lister.expand(item_pos.cat, do_expand); @@ -4291,16 +4294,16 @@ 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) + arg_category::arg_category ( const nana::drawerbase::listbox::cat_proxy& cat ) + : category(cat), _m_block_change(false) { } - void arg_item::block_category_change() const { + void arg_category::block_category_change() const { _m_block_change=true; } - bool arg_item::category_change_blocked() const { + bool arg_category::category_change_blocked() const { return _m_block_change; } @@ -4478,6 +4481,27 @@ namespace nana return at(pos_abs.cat).at(pos_abs.item); } + listbox::index_pair listbox::at ( const point& pos ) const + { + auto & ess=_m_ess(); + auto _where=ess.where(pos.x, pos.y); + index_pair item_pos{npos,npos}; + if(_where.first==drawerbase::listbox::essence_t::parts::lister){ + auto & offset_y = ess.scroll.offset_y_dpl; + ess.lister.forward(offset_y, _where.second, item_pos); + } + return item_pos; + } + + listbox::columns_indexs listbox::column_from_pos ( const point& pos ) + { + auto & ess=_m_ess(); + columns_indexs col=ess.header.item_by_x(pos.x - 2 - ess.scroll.offset_x); + return col; + } + + + void listbox::insert(const index_pair& pos, std::string text) { internal_scope_guard lock;