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

@@ -51,16 +51,16 @@ namespace nana
namespace detail
{
bool check_window(window wd)
{
return bedrock::instance().wd_manager().available(reinterpret_cast<window_manager::core_window_t*>(wd));
}
void events_operation_register(event_handle evt)
{
bedrock::instance().evt_operation().register_evt(evt);
}
void events_operation_cancel(event_handle evt)
{
bedrock::instance().evt_operation().cancel(evt);
}
class bedrock::flag_guard
{
public:
@@ -213,21 +213,21 @@ namespace nana
auto retain = wd->together.events_ptr;
auto evts_ptr = retain.get();
switch (evt_code)
{
case event_code::click:
{
auto arg = dynamic_cast<const arg_click*>(&event_arg);
if (nullptr == arg)
return;
if (arg)
{
//enable refreshing flag, this is a RAII class for exception-safe
flag_guard fguard(this, wd);
wd->drawer.click(*arg);
{
//enable refreshing flag, this is a RAII class for exception-safe
flag_guard fguard(this, wd);
wd->drawer.click(*arg);
}
if (!draw_only)
evts_ptr->click.emit(*arg, reinterpret_cast<window>(wd));
}
if (!draw_only)
evts_ptr->click.emit(*arg);
}
break;
case event_code::dbl_click:
@@ -281,7 +281,7 @@ namespace nana
}
if (!draw_only)
evt_addr->emit(*arg);
evt_addr->emit(*arg, reinterpret_cast<window>(wd));
break;
}
case event_code::mouse_wheel:
@@ -296,7 +296,7 @@ namespace nana
}
if (!draw_only)
evts_ptr->mouse_wheel.emit(*arg);
evts_ptr->mouse_wheel.emit(*arg, reinterpret_cast<window>(wd));
}
break;
}
@@ -340,7 +340,7 @@ namespace nana
}
if (!draw_only)
evt_addr->emit(*arg);
evt_addr->emit(*arg, reinterpret_cast<window>(wd));
break;
}
case event_code::expose:
@@ -348,7 +348,7 @@ namespace nana
{
auto arg = dynamic_cast<const arg_expose*>(&event_arg);
if (arg)
evts_ptr->expose.emit(*arg);
evts_ptr->expose.emit(*arg, reinterpret_cast<window>(wd));
}
break;
case event_code::focus:
@@ -362,7 +362,7 @@ namespace nana
wd->drawer.focus(*arg);
}
if (!draw_only)
evts_ptr->focus.emit(*arg);
evts_ptr->focus.emit(*arg, reinterpret_cast<window>(wd));
}
break;
}
@@ -377,7 +377,7 @@ namespace nana
wd->drawer.move(*arg);
}
if (!draw_only)
evts_ptr->move.emit(*arg);
evts_ptr->move.emit(*arg, reinterpret_cast<window>(wd));
}
break;
}
@@ -392,7 +392,7 @@ namespace nana
wd->drawer.resizing(*arg);
}
if (!draw_only)
evts_ptr->resizing.emit(*arg);
evts_ptr->resizing.emit(*arg, reinterpret_cast<window>(wd));
}
break;
}
@@ -407,7 +407,7 @@ namespace nana
wd->drawer.resized(*arg);
}
if (!draw_only)
evts_ptr->resized.emit(*arg);
evts_ptr->resized.emit(*arg, reinterpret_cast<window>(wd));
}
break;
}
@@ -419,7 +419,7 @@ namespace nana
{
auto evt_root = dynamic_cast<events_root_extension*>(evts_ptr);
if (evt_root)
evt_root->unload.emit(*arg);
evt_root->unload.emit(*arg, reinterpret_cast<window>(wd));
}
}
break;
@@ -428,7 +428,7 @@ namespace nana
{
auto arg = dynamic_cast<const arg_destroy*>(&event_arg);
if (arg)
evts_ptr->destroy.emit(*arg);
evts_ptr->destroy.emit(*arg, reinterpret_cast<window>(wd));
}
break;
default:

View File

@@ -520,7 +520,7 @@ namespace detail
delete msg.u.mouse_drop.files;
arg.pos.x = msg.u.mouse_drop.x - msgwd->pos_root.x;
arg.pos.y = msg.u.mouse_drop.y - msgwd->pos_root.y;
msgwd->together.events_ptr->mouse_dropfiles.emit(arg);
msgwd->together.events_ptr->mouse_dropfiles.emit(arg, reinterpret_cast<window>(msgwd));
brock.wd_manager().do_lazy_refresh(msgwd, false);
}
break;
@@ -842,16 +842,16 @@ namespace detail
draw_invoker(&drawer::mouse_up, msgwnd, arg, &context);
if(click_arg.window_handle)
evt_ptr->click.emit(click_arg);
evt_ptr->click.emit(click_arg, reinterpret_cast<window>(msgwnd));
if (brock.wd_manager().available(msgwnd))
{
arg.evt_code = event_code::mouse_up;
evt_ptr->mouse_up.emit(arg);
evt_ptr->mouse_up.emit(arg, reinterpret_cast<window>(msgwnd));
}
}
else if(click_arg.window_handle)
msgwnd->together.events_ptr->click.emit(click_arg);
msgwnd->together.events_ptr->click.emit(click_arg, reinterpret_cast<window>(msgwnd));
brock.wd_manager().do_lazy_refresh(msgwnd, false);
}
@@ -1143,7 +1143,7 @@ namespace detail
arg.evt_code = event_code::key_char;
arg.window_handle = reinterpret_cast<window>(msgwnd);
brock.get_key_state(arg);
msgwnd->together.events_ptr->key_char.emit(arg);
msgwnd->together.events_ptr->key_char.emit(arg, reinterpret_cast<window>(msgwnd));
if(arg.ignore == false && wd_manager.available(msgwnd))
draw_invoker(&drawer::key_char, msgwnd, arg, &context);
}

View File

@@ -931,10 +931,7 @@ namespace detail
arg_mouse arg;
assign_arg(arg, msgwnd, message, pmdec);
if (brock.emit(arg.evt_code, msgwnd, arg, true, &context))
{
if (brock.wd_manager().available(msgwnd))
pressed_wd = msgwnd;
}
pressed_wd = msgwnd;
}
break;
case WM_NCLBUTTONDOWN: case WM_NCMBUTTONDOWN: case WM_NCRBUTTONDOWN:
@@ -1042,16 +1039,16 @@ namespace detail
draw_invoker(&drawer::mouse_up, msgwnd, arg, &context);
if (click_arg.window_handle)
retain->click.emit(click_arg);
retain->click.emit(click_arg, reinterpret_cast<window>(msgwnd));
if (brock.wd_manager().available(msgwnd))
{
arg.evt_code = event_code::mouse_up;
retain->mouse_up.emit(arg);
retain->mouse_up.emit(arg, reinterpret_cast<window>(msgwnd));
}
}
else if (click_arg.window_handle)
retain->click.emit(click_arg);
retain->click.emit(click_arg, reinterpret_cast<window>(msgwnd));
brock.wd_manager().do_lazy_refresh(msgwnd, false);
}
@@ -1119,8 +1116,11 @@ namespace detail
brock.emit(event_code::mouse_enter, msgwnd, arg, true, &context);
}
arg.evt_code = event_code::mouse_move;
brock.emit(event_code::mouse_move, msgwnd, arg, true, &context);
if (hovered_wd)
{
arg.evt_code = event_code::mouse_move;
brock.emit(event_code::mouse_move, msgwnd, arg, true, &context);
}
track.hwndTrack = native_window;
restrict::track_mouse_event(&track);
}
@@ -1223,7 +1223,7 @@ namespace detail
brock.wd_manager().calc_window_point(msgwnd, dropfiles.pos);
dropfiles.window_handle = reinterpret_cast<window>(msgwnd);
msgwnd->together.events_ptr->mouse_dropfiles.emit(dropfiles);
msgwnd->together.events_ptr->mouse_dropfiles.emit(dropfiles, reinterpret_cast<window>(msgwnd));
brock.wd_manager().do_lazy_refresh(msgwnd, false);
}
}
@@ -1495,7 +1495,7 @@ namespace detail
brock.get_key_state(arg);
arg.ignore = false;
msgwnd->together.events_ptr->key_char.emit(arg);
msgwnd->together.events_ptr->key_char.emit(arg, reinterpret_cast<window>(msgwnd));
if ((false == arg.ignore) && wd_manager.available(msgwnd))
draw_invoker(&drawer::key_char, msgwnd, arg, &context);
@@ -1785,13 +1785,19 @@ namespace detail
_m_emit_core(evt_code, wd, false, arg);
if (ask_update)
wd_manager().do_lazy_refresh(wd, false);
else if (wd_manager().available(wd))
wd->other.upd_state = basic_window::update_state::none;
bool good_wd = false;
if (wd_manager().available(wd))
{
if (ask_update)
wd_manager().do_lazy_refresh(wd, false);
else
wd->other.upd_state = basic_window::update_state::none;
good_wd = true;
}
if (thrd) thrd->event_window = prev_event_wd;
return true;
return good_wd;
}
const wchar_t* translate(cursor id)

View File

@@ -1,4 +1,5 @@
#include <nana/gui/detail/events_operation.hpp>
#include <nana/gui/detail/bedrock.hpp>
namespace nana
{
@@ -7,18 +8,6 @@ namespace nana
//class events_operation
using lock_guard = std::lock_guard<std::recursive_mutex>;
void events_operation::make(window wd, const std::shared_ptr<general_events>& sp)
{
lock_guard lock(mutex_);
evt_table_[wd] = sp;
}
void events_operation::umake(window wd)
{
lock_guard lock(mutex_);
evt_table_.erase(wd);
}
void events_operation::register_evt(event_handle evt)
{
lock_guard lock(mutex_);
@@ -72,9 +61,11 @@ namespace nana
internal_scope_guard lock;
if (dockers_)
{
auto & evt_operation = bedrock::instance().evt_operation();
for (auto p : *dockers_)
{
detail::events_operation_cancel(reinterpret_cast<event_handle>(p));
evt_operation.cancel(reinterpret_cast<event_handle>(p));
delete p;
}
dockers_->clear();

View File

@@ -86,13 +86,12 @@ namespace detail
private:
std::vector<key_value_rep> table_;
};
//class window_manager
//class window_manager
struct window_handle_deleter
{
void operator()(basic_window* wd) const
{
bedrock::instance().evt_operation().umake(reinterpret_cast<window>(wd));
delete wd;
}
};
@@ -399,7 +398,7 @@ namespace detail
if (wd->flags.destroying)
return;
if(wd->other.category == category::root_tag::value)
if(category::flags::root == wd->other.category)
{
auto &brock = bedrock::instance();
arg_unload arg;
@@ -844,10 +843,10 @@ namespace detail
//Thread-Safe Required!
std::lock_guard<decltype(mutex_)> lock(mutex_);
//It's not worthy to redraw if visible is false
if (false == impl_->wd_register.available(wd))
return false;
//It's not worthy to redraw if visible is false
if(wd->visible && (!wd->is_draw_through()))
{
if (wd->visible_parents())
@@ -1573,7 +1572,7 @@ namespace detail
wd->drawer.detached();
wd->widget_notifier->destroy();
if(wd->other.category == category::frame_tag::value)
if(category::flags::frame == wd->other.category)
{
//The frame widget does not have an owner, and close their element windows without activating owner.
//close the frame container window, it's a native window.