Implements double click event on items, allowing to block the category expansion change.

This commit is contained in:
Leonardo Backes Vargas
2015-12-24 20:25:50 -02:00
parent 13669f7591
commit 3f1991ba1a
2 changed files with 52 additions and 17 deletions

View File

@@ -466,13 +466,25 @@ namespace nana
} }
}//end namespace drawerbase }//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 : public event_arg
{ {
mutable drawerbase::listbox::item_proxy item; drawerbase::listbox::index_pair item;
bool selected; 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 namespace drawerbase
@@ -484,6 +496,7 @@ namespace nana
{ {
basic_event<arg_listbox> checked; basic_event<arg_listbox> checked;
basic_event<arg_listbox> selected; basic_event<arg_listbox> selected;
basic_event<arg_item> item_dbl_click;
}; };
struct scheme struct scheme

View File

@@ -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 (essence_->pointer_where.first == essence_t::parts::header)
if (cursor::size_we == essence_->lister.wd_ptr()->cursor()) if (cursor::size_we == essence_->lister.wd_ptr()->cursor())
@@ -3564,22 +3564,28 @@ namespace nana
//Get the item which the mouse is placed. //Get the item which the mouse is placed.
if (lister.forward(offset_y, essence_->pointer_where.second, item_pos)) 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 if (!item_pos.is_category()) //being the npos of item.second is a category
return; return;
bool do_expand = (lister.expand(item_pos.cat) == false); if(!ai.category_change_blocked()){
lister.expand(item_pos.cat, do_expand); bool do_expand = (lister.expand(item_pos.cat) == false);
lister.expand(item_pos.cat, do_expand);
if(false == do_expand) if(false == do_expand)
{ {
auto last = lister.last(); auto last = lister.last();
size_type n = essence_->number_of_lister_items(false); size_type n = essence_->number_of_lister_items(false);
if (lister.backward(last, n, last)) if (lister.backward(last, n, last))
offset_y = last; offset_y = last;
} }
essence_->adjust_scroll_life(); essence_->adjust_scroll_life();
refresh(graph); refresh(graph);
API::lazy_refresh(); 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 //class listbox
listbox::listbox(window wd, bool visible) listbox::listbox(window wd, bool visible)
{ {