add new method listbox;:set_deselect

set a predicate that decides to deselect selected items in mouse_up event.
This commit is contained in:
Jinhao
2019-05-23 00:49:56 +08:00
parent a21d58a5fe
commit 396319ea28
2 changed files with 21 additions and 1 deletions

View File

@@ -2011,6 +2011,8 @@ namespace nana
std::function<void(paint::graphics&, const rectangle&, bool)> ctg_icon_renderer; ///< Renderer for the category icon
std::function<bool(nana::mouse)> pred_msup_deselect;
struct operation_rep
{
operation_states state{operation_states::none};
@@ -4470,7 +4472,10 @@ namespace nana
if (operation_states::msup_deselect == essence_->operation.state)
{
essence_->operation.state = operation_states::none;
need_refresh |= essence_->lister.select_for_all(false, essence_->operation.item);
//Don't deselect if the predicate returns false
if(!(essence_->pred_msup_deselect && !essence_->pred_msup_deselect(arg.button)))
need_refresh |= essence_->lister.select_for_all(false, essence_->operation.item);
}
if (need_refresh)
@@ -6102,6 +6107,11 @@ namespace nana
return indexes;
}
void listbox::set_deselect(std::function<bool(nana::mouse)> predicate)
{
_m_ess().pred_msup_deselect = std::move(predicate);
}
drawerbase::listbox::essence & listbox::_m_ess() const
{
return get_drawer_trigger().ess();