From 5f703bff4c212afbbf5442bed410830f677d5eb3 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sat, 23 Jun 2018 06:16:19 +0800 Subject: [PATCH] ensure click event consistency the order of click events generated by mouse and keyboard are different --- include/nana/gui/widgets/checkbox.hpp | 4 ++- source/gui/detail/bedrock_posix.cpp | 41 ++++++++++++------------ source/gui/detail/bedrock_windows.cpp | 46 ++++++++++++++------------- source/gui/widgets/checkbox.cpp | 6 ++-- 4 files changed, 51 insertions(+), 46 deletions(-) diff --git a/include/nana/gui/widgets/checkbox.hpp b/include/nana/gui/widgets/checkbox.hpp index e3b31d69..c6f3a064 100644 --- a/include/nana/gui/widgets/checkbox.hpp +++ b/include/nana/gui/widgets/checkbox.hpp @@ -79,7 +79,9 @@ namespace drawerbase void element_set(const char* name); void react(bool want); ///< Enables the reverse check while clicking on the checkbox. 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, /// related options. Users can choose one and only one option. diff --git a/source/gui/detail/bedrock_posix.cpp b/source/gui/detail/bedrock_posix.cpp index 571b91bc..abb38f11 100644 --- a/source/gui/detail/bedrock_posix.cpp +++ b/source/gui/detail/bedrock_posix.cpp @@ -1149,28 +1149,29 @@ namespace detail { msgwnd->set_action(mouse_action::normal); - arg_click click_arg; - click_arg.mouse_args = nullptr; - click_arg.window_handle = reinterpret_cast(msgwnd); + auto retain = msgwnd->annex.events_ptr; - auto retain = msgwnd->annex.events_ptr; - if (brock.emit(event_code::click, msgwnd, click_arg, true, &context)) - { - 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(msgwnd); + arg_click click_arg; + click_arg.mouse_args = nullptr; + click_arg.window_handle = reinterpret_cast(msgwnd); - draw_invoker(&drawer::mouse_up, msgwnd, arg, &context); - wd_manager.do_lazy_refresh(msgwnd, false); - } - pressed_wd_space = nullptr; + 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(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 { diff --git a/source/gui/detail/bedrock_windows.cpp b/source/gui/detail/bedrock_windows.cpp index d8769fd9..674fe475 100644 --- a/source/gui/detail/bedrock_windows.cpp +++ b/source/gui/detail/bedrock_windows.cpp @@ -1495,38 +1495,40 @@ namespace detail { msgwnd->set_action(mouse_action::normal); + auto retain = msgwnd->annex.events_ptr; + arg_click click_arg; click_arg.mouse_args = nullptr; click_arg.window_handle = reinterpret_cast(msgwnd); - auto retain = msgwnd->annex.events_ptr; - if (brock.emit(event_code::click, msgwnd, click_arg, true, &context)) - { - 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(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(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); - } + pressed_wd_space = nullptr; } else { - arg_keyboard arg; - arg.evt_code = event_code::key_release; - arg.window_handle = reinterpret_cast(msgwnd); - arg.key = translate_virtual_key(wParam); - brock.get_key_state(arg); - arg.ignore = false; - brock.emit(event_code::key_release, msgwnd, arg, true, &context); + arg_keyboard keyboard_arg; + keyboard_arg.evt_code = event_code::key_release; + keyboard_arg.window_handle = reinterpret_cast(msgwnd); + keyboard_arg.key = translate_virtual_key(wParam); + brock.get_key_state(keyboard_arg); + keyboard_arg.ignore = false; + + brock.emit(event_code::key_release, msgwnd, keyboard_arg, true, &context); } } } diff --git a/source/gui/widgets/checkbox.cpp b/source/gui/widgets/checkbox.cpp index 66fb22de..06a5f0ee 100644 --- a/source/gui/widgets/checkbox.cpp +++ b/source/gui/widgets/checkbox.cpp @@ -167,12 +167,12 @@ namespace nana{ namespace drawerbase 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; - 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()); arg_checkbox arg(this);