improve stability of event

This commit is contained in:
Jinhao
2016-04-10 15:23:44 +08:00
parent 88b9149f54
commit 07b5b19545
23 changed files with 118 additions and 121 deletions

View File

@@ -3,8 +3,6 @@
#include <nana/gui/detail/general_events.hpp>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#if defined(STD_THREAD_NOT_SUPPORTED)
#include <nana/std_mutex.hpp>
@@ -19,15 +17,12 @@ namespace nana
class events_operation
{
public:
void make(window, const std::shared_ptr<general_events> &);
void umake(window);
void register_evt(event_handle);
void cancel(event_handle);
void erase(event_handle);
private:
std::recursive_mutex mutex_;
std::unordered_set<event_handle> handles_;
std::unordered_map<window, std::shared_ptr<general_events>> evt_table_;
};
}//end namespace detail
}//end namespace nana

View File

@@ -23,8 +23,8 @@ namespace nana
{
namespace detail
{
bool check_window(window);
void events_operation_register(event_handle);
void events_operation_cancel(event_handle);
class event_interface
{
@@ -161,7 +161,7 @@ namespace nana
return _m_emplace(new docker(this, factory<prototype, std::is_bind_expression<prototype>::value>::build(std::forward<Function>(fn)), true), in_front);
}
void emit(arg_reference& arg)
void emit(arg_reference& arg, window window_handle)
{
internal_scope_guard lock;
if (nullptr == dockers_)
@@ -181,6 +181,10 @@ namespace nana
continue;
static_cast<docker*>(*i)->invoke(arg);
if (window_handle && (!detail::check_window(window_handle)))
break;
if (arg.propagation_stopped())
{
for (++i; i != end; ++i)
@@ -189,6 +193,9 @@ namespace nana
continue;
static_cast<docker*>(*i)->invoke(arg);
if (window_handle && (!detail::check_window(window_handle)))
break;
}
break;
}

View File

@@ -66,7 +66,7 @@ namespace nana
T null_val;
arg_categorize<T> arg(widget_, vp ? *vp : null_val);
widget_.events().selected.emit(arg);
widget_.events().selected.emit(arg, widget_.handle());
}
private:
::nana::categorize<T> & widget_;

View File

@@ -314,7 +314,7 @@ namespace nana
private:
void _m_emit_value_changed()
{
widget_->events().value_changed.emit({ widget_->handle() });
widget_->events().value_changed.emit({ widget_->handle() }, widget_->handle());
}
void _m_tick()

View File

@@ -111,14 +111,14 @@ namespace nana
if(pos != npos)
{
drawer_trigger_.at_no_bound_check(pos) = T();
tabbar_.events().added.emit(arg_tabbar({ tabbar_, tabbar_[pos] }));
tabbar_.events().added.emit(arg_tabbar({ tabbar_, tabbar_[pos] }), tabbar_);
}
}
void activated(std::size_t pos) override
{
if(pos != npos)
tabbar_.events().activated.emit(arg_tabbar({ tabbar_, tabbar_[pos]}));
tabbar_.events().activated.emit(arg_tabbar({ tabbar_, tabbar_[pos]}), tabbar_);
}
bool removed(std::size_t pos, bool & close_attach) override
@@ -126,7 +126,7 @@ namespace nana
if (pos != npos)
{
::nana::arg_tabbar_removed<T> arg(tabbar_, tabbar_[pos]);
tabbar_.events().removed.emit(arg);
tabbar_.events().removed.emit(arg, tabbar_);
close_attach = arg.close_attach_window;
return arg.remove;
}