add new method listbox;:set_deselect
set a predicate that decides to deselect selected items in mouse_up event.
This commit is contained in:
parent
a21d58a5fe
commit
396319ea28
@ -1593,6 +1593,16 @@ the nana::detail::basic_window member pointer scheme
|
||||
* @return index_pairs containing all visible items.
|
||||
*/
|
||||
index_pairs visibles() const;
|
||||
|
||||
/// Sets a predicate that indicates whether to deselect items when mouse_up is triggered.
|
||||
/**
|
||||
* The predicate is called before the listbox attempts to deselect the selected items in the mouse_up event. Other situations,
|
||||
* the predicates isn't called, for example, releasing mouse button after user performed a box selection, because listbox doesn't deselect the items during this operation.
|
||||
* @param predicate Decides to deselect the items.
|
||||
* The paramater of predicate indicates the mouse button which is releasing.
|
||||
* It returns true to deselect the selected items. It returns false to cancel to deselect the selected items.
|
||||
*/
|
||||
void set_deselect(std::function<bool(nana::mouse)> predicate);
|
||||
private:
|
||||
drawerbase::listbox::essence & _m_ess() const;
|
||||
nana::any* _m_anyobj(size_type cat, size_type index, bool allocate_if_empty) const override;
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user