fix listbox thread-safe issue(#329)
This commit is contained in:
parent
3962cc1aee
commit
df5fda9096
@ -1028,6 +1028,7 @@ namespace nana
|
||||
template<typename T>
|
||||
void append_model(const T& t)
|
||||
{
|
||||
nana::internal_scope_guard lock;
|
||||
_m_try_append_model(const_virtual_pointer{ &t });
|
||||
_m_update();
|
||||
}
|
||||
|
||||
@ -5380,6 +5380,7 @@ namespace nana
|
||||
|
||||
void listbox::auto_draw(bool enabled) noexcept
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
auto & ess = _m_ess();
|
||||
if (ess.auto_draw != enabled)
|
||||
{
|
||||
@ -5390,6 +5391,7 @@ namespace nana
|
||||
|
||||
void listbox::scroll(bool to_bottom, size_type cat_pos)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
auto & ess = _m_ess();
|
||||
auto cats = this->size_categ();
|
||||
|
||||
@ -5488,6 +5490,7 @@ namespace nana
|
||||
|
||||
rectangle listbox::content_area() const
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
auto & ess = _m_ess();
|
||||
auto carea = ess.content_area();
|
||||
carea.x += ess.header.margin();
|
||||
@ -5534,29 +5537,34 @@ namespace nana
|
||||
|
||||
listbox::cat_proxy listbox::at(size_type pos)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
check_range(pos, size_categ());
|
||||
return{ &_m_ess(), pos };
|
||||
}
|
||||
|
||||
const listbox::cat_proxy listbox::at(size_type pos) const
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
check_range(pos, size_categ());
|
||||
return{ &_m_ess(), pos };
|
||||
}
|
||||
|
||||
listbox::item_proxy listbox::at(const index_pair& abs_pos)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
return at(abs_pos.cat).at(abs_pos.item);
|
||||
}
|
||||
|
||||
const listbox::item_proxy listbox::at(const index_pair& pos_abs) const
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
return at(pos_abs.cat).at(pos_abs.item);
|
||||
}
|
||||
|
||||
// Contributed by leobackes(pr#97)
|
||||
listbox::index_pair listbox::cast( const point& pos ) const
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
auto & ess=_m_ess();
|
||||
auto _where = ess.where(pos);
|
||||
|
||||
@ -5568,27 +5576,32 @@ namespace nana
|
||||
|
||||
auto listbox::column_at(size_type pos, bool disp_order) -> column_interface&
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
return _m_ess().header.at(pos, disp_order);
|
||||
}
|
||||
|
||||
auto listbox::column_at(size_type pos, bool disp_order) const -> const column_interface&
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
return _m_ess().header.at(pos, disp_order);
|
||||
}
|
||||
|
||||
auto listbox::column_size() const ->size_type
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
return _m_ess().header.cont().size();
|
||||
}
|
||||
|
||||
//Contributed by leobackes(pr#97)
|
||||
listbox::size_type listbox::column_from_pos ( const point& pos ) const
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
return _m_ess().column_from_pos(pos.x);
|
||||
}
|
||||
|
||||
void listbox::checkable(bool chkable)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
auto & ess = _m_ess();
|
||||
if(ess.checkable != chkable)
|
||||
{
|
||||
@ -5599,11 +5612,13 @@ namespace nana
|
||||
|
||||
auto listbox::checked() const -> index_pairs
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
return _m_ess().lister.pick_items(false);
|
||||
}
|
||||
|
||||
void listbox::clear(size_type cat)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
auto & ess = _m_ess();
|
||||
|
||||
auto origin = ess.content_view->origin();
|
||||
@ -5627,6 +5642,7 @@ namespace nana
|
||||
|
||||
void listbox::clear()
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
auto & ess = _m_ess();
|
||||
|
||||
ess.lister.clear();
|
||||
@ -5641,6 +5657,7 @@ namespace nana
|
||||
|
||||
void listbox::erase(size_type cat)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
auto & ess = _m_ess();
|
||||
|
||||
auto origin = ess.content_view->origin();
|
||||
@ -5665,6 +5682,7 @@ namespace nana
|
||||
|
||||
void listbox::erase()
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
auto & ess = _m_ess();
|
||||
ess.lister.erase();
|
||||
ess.calc_content_size();
|
||||
@ -5673,6 +5691,8 @@ namespace nana
|
||||
|
||||
void listbox::erase(index_pairs indexes)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
|
||||
std::sort(indexes.begin(), indexes.end(), [](const index_pair& pos1, const index_pair& pos2)
|
||||
{
|
||||
return (pos1 > pos2);
|
||||
@ -5722,6 +5742,7 @@ namespace nana
|
||||
if(ip.empty())
|
||||
return ip;
|
||||
|
||||
internal_scope_guard lock;
|
||||
auto * ess = ip._m_ess();
|
||||
auto _where = ip.pos();
|
||||
|
||||
@ -5744,48 +5765,57 @@ namespace nana
|
||||
|
||||
bool listbox::sortable() const
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
return _m_ess().header.sortable();
|
||||
}
|
||||
|
||||
void listbox::sortable(bool enable)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
_m_ess().header.sortable(enable);
|
||||
}
|
||||
|
||||
void listbox::set_sort_compare(size_type col, std::function<bool(const std::string&, nana::any*, const std::string&, nana::any*, bool reverse)> strick_ordering)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
_m_ess().header.at(col).weak_ordering = std::move(strick_ordering);
|
||||
}
|
||||
|
||||
/// sort() and ivalidate any existing reference from display position to absolute item, that is: after sort() display offset point to different items
|
||||
void listbox::sort_col(size_type col, bool reverse)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
_m_ess().lister.sort_column(col, &reverse);
|
||||
}
|
||||
|
||||
auto listbox::sort_col() const -> size_type
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
return _m_ess().lister.sort_attrs().column;
|
||||
}
|
||||
|
||||
/// potencially ivalidate any existing reference from display position to absolute item, that is: after sort() display offset point to different items
|
||||
void listbox::unsort()
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
this->sort_col(npos, false);
|
||||
}
|
||||
|
||||
bool listbox::freeze_sort(bool freeze)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
return !_m_ess().lister.active_sort(!freeze);
|
||||
}
|
||||
|
||||
auto listbox::selected() const -> index_pairs
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
return _m_ess().lister.pick_items(true); // absolute positions, no relative to display
|
||||
}
|
||||
|
||||
void listbox::show_header(bool sh)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
_m_ess().header.visible(sh);
|
||||
_m_ess().update();
|
||||
}
|
||||
@ -5797,6 +5827,7 @@ namespace nana
|
||||
|
||||
void listbox::move_select(bool upwards) ///<Selects an item besides the current selected item in the display.
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
_m_ess().lister.move_select(upwards, true, true);
|
||||
_m_ess().update();
|
||||
}
|
||||
@ -5829,6 +5860,7 @@ namespace nana
|
||||
|
||||
listbox& listbox::category_icon(std::function<void(paint::graphics& graph, const rectangle& rt_icon, bool expanded)> icon_renderer)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
_m_ess().ctg_icon_renderer.swap(icon_renderer);
|
||||
_m_ess().update();
|
||||
return *this;
|
||||
@ -5836,6 +5868,7 @@ namespace nana
|
||||
|
||||
listbox& listbox::category_icon(const paint::image& img_expanded, const paint::image&& img_collapsed)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
_m_ess().ctg_icon_renderer = [img_expanded, img_collapsed](paint::graphics& graph, const rectangle& rt_icon, bool expanded)
|
||||
{
|
||||
if (expanded)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user