refactoring general events

This commit is contained in:
Jinhao 2019-03-09 18:12:47 +08:00
parent 2abae1dd68
commit 0d96fcc097
2 changed files with 11 additions and 27 deletions

View File

@ -47,12 +47,11 @@ namespace nana
struct docker_base struct docker_base
: public docker_interface : public docker_interface
{ {
event_interface * event_ptr; event_interface * const event_ptr;
bool flag_deleted{ false }; bool flag_deleted;
const bool unignorable; const bool unignorable;
docker_base(event_interface*, bool unignorable_flag); docker_base(event_interface*, bool unignorable_flag);
detail::event_interface * get_event() const override; detail::event_interface * get_event() const override;
}; };
@ -221,33 +220,16 @@ namespace nana
//The dockers may resize when a new event handler is created by a calling handler. //The dockers may resize when a new event handler is created by a calling handler.
//Traverses with position can avaid crash error which caused by a iterator which becomes invalid. //Traverses with position can avaid crash error which caused by a iterator which becomes invalid.
for (std::size_t i = 0; i < dockers_->size(); ++i)
auto i = dockers_->data();
auto const end = i + dockers_->size();
for (; i != end; ++i)
{ {
if (static_cast<docker*>(*i)->flag_deleted) auto d = static_cast<docker*>(dockers_->data()[i]);
if (d->flag_deleted || (arg.propagation_stopped() && !d->unignorable))
continue; continue;
static_cast<docker*>(*i)->invoke(arg); d->invoke(arg);
if (window_handle && (!detail::check_window(window_handle))) if (window_handle && (!detail::check_window(window_handle)))
break; break;
if (arg.propagation_stopped())
{
for (++i; i != end; ++i)
{
if (!static_cast<docker*>(*i)->unignorable || static_cast<docker*>(*i)->flag_deleted)
continue;
static_cast<docker*>(*i)->invoke(arg);
if (window_handle && (!detail::check_window(window_handle)))
break;
}
break;
}
} }
} }
private: private:

View File

@ -34,8 +34,10 @@ namespace nana
//class docker_base //class docker_base
docker_base::docker_base(event_interface* evt, bool unignorable_flag) docker_base::docker_base(event_interface* evt, bool unignorable_flag):
: event_ptr(evt), unignorable(unignorable_flag) event_ptr(evt),
flag_deleted(false),
unignorable(unignorable_flag)
{} {}
detail::event_interface * docker_base::get_event() const detail::event_interface * docker_base::get_event() const