ensure click event consistency

the order of click events generated by mouse and keyboard are different
This commit is contained in:
Jinhao 2018-06-23 06:16:19 +08:00
parent feaa0d1ec1
commit 5f703bff4c
4 changed files with 51 additions and 46 deletions

View File

@ -79,7 +79,9 @@ namespace drawerbase
void element_set(const char* name); void element_set(const char* name);
void react(bool want); ///< Enables the reverse check while clicking on the checkbox. void react(bool want); ///< Enables the reverse check while clicking on the checkbox.
bool checked() const; bool checked() const;
void check(bool chk);
/// Checks/unchecks the checkbox
void check(bool state);
/// \brief With the radio mode, users make a choice among a set of mutually exclusive, /// \brief With the radio mode, users make a choice among a set of mutually exclusive,
/// related options. Users can choose one and only one option. /// related options. Users can choose one and only one option.

View File

@ -1149,28 +1149,29 @@ namespace detail
{ {
msgwnd->set_action(mouse_action::normal); msgwnd->set_action(mouse_action::normal);
arg_click click_arg; auto retain = msgwnd->annex.events_ptr;
click_arg.mouse_args = nullptr;
click_arg.window_handle = reinterpret_cast<window>(msgwnd);
auto retain = msgwnd->annex.events_ptr; arg_click click_arg;
if (brock.emit(event_code::click, msgwnd, click_arg, true, &context)) click_arg.mouse_args = nullptr;
{ click_arg.window_handle = reinterpret_cast<window>(msgwnd);
arg_mouse arg;
arg.alt = false;
arg.button = ::nana::mouse::left_button;
arg.ctrl = false;
arg.evt_code = event_code::mouse_up;
arg.left_button = true;
arg.mid_button = false;
arg.pos.x = 0;
arg.pos.y = 0;
arg.window_handle = reinterpret_cast<window>(msgwnd);
draw_invoker(&drawer::mouse_up, msgwnd, arg, &context); arg_mouse arg;
wd_manager.do_lazy_refresh(msgwnd, false); arg.alt = false;
} arg.button = ::nana::mouse::left_button;
pressed_wd_space = nullptr; arg.ctrl = false;
arg.evt_code = event_code::mouse_up;
arg.left_button = true;
arg.mid_button = false;
arg.pos.x = 0;
arg.pos.y = 0;
arg.window_handle = reinterpret_cast<window>(msgwnd);
draw_invoker(&drawer::mouse_up, msgwnd, arg, &context);
if (brock.emit(event_code::click, msgwnd, click_arg, true, &context))
wd_manager.do_lazy_refresh(msgwnd, false);
pressed_wd_space = nullptr;
} }
else else
{ {

View File

@ -1495,38 +1495,40 @@ namespace detail
{ {
msgwnd->set_action(mouse_action::normal); msgwnd->set_action(mouse_action::normal);
auto retain = msgwnd->annex.events_ptr;
arg_click click_arg; arg_click click_arg;
click_arg.mouse_args = nullptr; click_arg.mouse_args = nullptr;
click_arg.window_handle = reinterpret_cast<window>(msgwnd); click_arg.window_handle = reinterpret_cast<window>(msgwnd);
auto retain = msgwnd->annex.events_ptr; arg_mouse arg;
if (brock.emit(event_code::click, msgwnd, click_arg, true, &context)) arg.alt = false;
{ arg.button = ::nana::mouse::left_button;
arg_mouse arg; arg.ctrl = false;
arg.alt = false; arg.evt_code = event_code::mouse_up;
arg.button = ::nana::mouse::left_button; arg.left_button = true;
arg.ctrl = false; arg.mid_button = false;
arg.evt_code = event_code::mouse_up; arg.pos.x = 0;
arg.left_button = true; arg.pos.y = 0;
arg.mid_button = false; arg.window_handle = reinterpret_cast<window>(msgwnd);
arg.pos.x = 0;
arg.pos.y = 0;
arg.window_handle = reinterpret_cast<window>(msgwnd);
draw_invoker(&drawer::mouse_up, msgwnd, arg, &context); draw_invoker(&drawer::mouse_up, msgwnd, arg, &context);
if (brock.emit(event_code::click, msgwnd, click_arg, true, &context))
wd_manager.do_lazy_refresh(msgwnd, false); wd_manager.do_lazy_refresh(msgwnd, false);
}
pressed_wd_space = nullptr; pressed_wd_space = nullptr;
} }
else else
{ {
arg_keyboard arg; arg_keyboard keyboard_arg;
arg.evt_code = event_code::key_release; keyboard_arg.evt_code = event_code::key_release;
arg.window_handle = reinterpret_cast<window>(msgwnd); keyboard_arg.window_handle = reinterpret_cast<window>(msgwnd);
arg.key = translate_virtual_key(wParam); keyboard_arg.key = translate_virtual_key(wParam);
brock.get_key_state(arg); brock.get_key_state(keyboard_arg);
arg.ignore = false; keyboard_arg.ignore = false;
brock.emit(event_code::key_release, msgwnd, arg, true, &context);
brock.emit(event_code::key_release, msgwnd, keyboard_arg, true, &context);
} }
} }
} }

View File

@ -167,12 +167,12 @@ namespace nana{ namespace drawerbase
return (get_drawer_trigger().impl()->crook.checked() != drawerbase::checkbox::crook_state::unchecked); return (get_drawer_trigger().impl()->crook.checked() != drawerbase::checkbox::crook_state::unchecked);
} }
void checkbox::check(bool chk) void checkbox::check(bool state)
{ {
using crook_state = drawerbase::checkbox::crook_state; using crook_state = drawerbase::checkbox::crook_state;
if (checked() != chk) if (checked() != state)
{ {
get_drawer_trigger().impl()->crook.check(chk ? crook_state::checked : crook_state::unchecked); get_drawer_trigger().impl()->crook.check(state ? crook_state::checked : crook_state::unchecked);
API::refresh_window(handle()); API::refresh_window(handle());
arg_checkbox arg(this); arg_checkbox arg(this);