From 0267367f3fa8ff15eeb5381c2e9eb1d34f23ba02 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sat, 2 May 2015 02:25:04 +0800 Subject: [PATCH] fix menu ESC issues --- source/gui/detail/win32/bedrock.cpp | 36 +++++++++++++++++------------ source/gui/widgets/menubar.cpp | 3 +++ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/source/gui/detail/win32/bedrock.cpp b/source/gui/detail/win32/bedrock.cpp index 58c4eb6e..71ae2f02 100644 --- a/source/gui/detail/win32/bedrock.cpp +++ b/source/gui/detail/win32/bedrock.cpp @@ -663,7 +663,6 @@ namespace detail case WM_SETFOCUS: case WM_KILLFOCUS: case WM_PAINT: - case WM_SYSCOMMAND: case WM_CLOSE: case WM_MOUSEACTIVATE: case WM_GETMINMAXINFO: @@ -1314,6 +1313,7 @@ namespace detail } break; case WM_SYSCHAR: + def_window_proc = true; brock.set_keyboard_shortkey(true); msgwnd = brock.wd_manager.find_shortkey(native_window, static_cast(wParam)); if(msgwnd) @@ -1325,10 +1325,11 @@ namespace detail arg.window_handle = reinterpret_cast(msgwnd); arg.ignore = false; brock.emit(event_code::shortkey, msgwnd, arg, true, &context); + def_window_proc = false; } - def_window_proc = true; break; case WM_SYSKEYDOWN: + def_window_proc = true; if (brock.whether_keyboard_shortkey() == false) { msgwnd = msgwnd->root_widget->other.attribute.root->menubar; @@ -1348,14 +1349,16 @@ namespace detail else brock.erase_menu(true); } - def_window_proc = true; break; case WM_SYSKEYUP: + def_window_proc = true; if(brock.set_keyboard_shortkey(false) == false) { msgwnd = msgwnd->root_widget->other.attribute.root->menubar; if(msgwnd) { + //Don't call default window proc to avoid popuping system menu. + def_window_proc = false; bool set_focus = (brock.focus() != msgwnd) && (!msgwnd->root_widget->flags.ignore_menubar_focus); if (set_focus) brock.wd_manager.set_focus(msgwnd, false); @@ -1375,15 +1378,15 @@ namespace detail } } } - def_window_proc = true; break; case WM_KEYDOWN: if(msgwnd->flags.enabled) { - if (brock.get_menu()) + auto menu_wd = brock.get_menu(); + if (menu_wd) brock.delay_restore(0); //Enable delay restore - if(msgwnd->root != brock.get_menu()) + if (msgwnd->root != menu_wd) msgwnd = brock.focus(); if(msgwnd) @@ -1408,6 +1411,17 @@ namespace detail arg.key = static_cast(wParam); brock.get_key_state(arg); brock.emit(event_code::key_press, msgwnd, arg, true, &context); + + if (msgwnd->root_widget->other.attribute.root->menubar == msgwnd) + { + //In order to keep the focus on the menubar, cancel the delay_restore + //when pressing ESC to close the menu which is popuped by the menubar. + //If no menu popuped by the menubar, it should enable delay restore to + //restore the focus for taken window. + + int cmd = (menu_wd && (keyboard::escape == static_cast(wParam)) ? 1 : 0); + brock.delay_restore(cmd); + } } } } @@ -1455,14 +1469,6 @@ namespace detail brock.delay_restore(2); //Restores while key release break; - case WM_SYSCOMMAND: - if (SC_TASKLIST == wParam) - { - int debug = 0; - //brock.close_menu_if_focus_other_window() - } - def_window_proc = true; - break; case WM_CLOSE: { arg_unload arg; @@ -1571,7 +1577,7 @@ namespace detail break; case 2: //Restore if key released //restores the focus when menu is closed by pressing keyboard - if (!impl_->menu.window) + if ((!impl_->menu.window) && impl_->menu.delay_restore) set_menubar_taken(nullptr); break; case 3: //Restores if destroying diff --git a/source/gui/widgets/menubar.cpp b/source/gui/widgets/menubar.cpp index 0be611c5..2c1de33d 100644 --- a/source/gui/widgets/menubar.cpp +++ b/source/gui/widgets/menubar.cpp @@ -460,6 +460,9 @@ namespace nana API::update_window(widget_->handle()); } }); + + if (API::focus_window() != this->widget_->handle()) + API::focus_window(widget_->handle()); menu_accessor::popup(*state_.menu, *widget_, m->pos.x, m->pos.y + static_cast(m->size.height)); return true; }