emit click event by pressing spacebar

This commit is contained in:
Jinhao
2016-02-07 00:49:29 +08:00
parent ca5b2e246e
commit e7cae6d17a
11 changed files with 217 additions and 64 deletions

View File

@@ -1,7 +1,7 @@
/*
* A Bedrock Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@@ -795,6 +795,7 @@ namespace detail
auto& context = *brock.get_thread_context();
auto pressed_wd = root_runtime->condition.pressed;
auto pressed_wd_space = root_runtime->condition.pressed_by_space;
auto hovered_wd = root_runtime->condition.hovered;
parameter_decoder pmdec;
@@ -913,6 +914,10 @@ namespace detail
def_window_proc = true;
break;
case WM_LBUTTONDBLCLK: case WM_MBUTTONDBLCLK: case WM_RBUTTONDBLCLK:
//Ignore mouse events when a window has been pressed by pressing spacebar
if (pressed_wd_space)
break;
pressed_wd = nullptr;
msgwnd = brock.wd_manager().find_window(native_window, pmdec.mouse.x, pmdec.mouse.y);
if(msgwnd && msgwnd->flags.enabled)
@@ -938,8 +943,13 @@ namespace detail
def_window_proc = true;
break;
case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_RBUTTONDOWN:
//Ignore mouse events when a window has been pressed by pressing spacebar
if (pressed_wd_space)
break;
msgwnd = brock.wd_manager().find_window(native_window, pmdec.mouse.x, pmdec.mouse.y);
if(nullptr == msgwnd) break;
if ((nullptr == msgwnd) || (pressed_wd && (msgwnd != pressed_wd)))
break;
//if event on the menubar, just remove the menu if it is not associating with the menubar
if ((msgwnd == msgwnd->root_widget->other.attribute.root->menubar) && brock.get_menu(msgwnd->root, true))
@@ -994,7 +1004,11 @@ namespace detail
case WM_LBUTTONUP:
case WM_MBUTTONUP:
case WM_RBUTTONUP:
msgwnd = brock.wd_manager().find_window(native_window, pmdec.mouse.x, pmdec.mouse.y);
//Ignore mouse events when a window has been pressed by pressing spacebar
if (pressed_wd_space)
break;
msgwnd = brock.wd_manager().find_window(native_window, pmdec.mouse.x, pmdec.mouse.y);
if(nullptr == msgwnd)
break;
@@ -1015,7 +1029,7 @@ namespace detail
if (msgwnd->dimension.is_hit(arg.pos))
{
msgwnd->flags.action = mouse_action::over;
if (::nana::mouse::left_button == arg.button)
if ((::nana::mouse::left_button == arg.button) && (pressed_wd == msgwnd))
{
click_arg.window_handle = reinterpret_cast<window>(msgwnd);
emit_drawer(&drawer::click, msgwnd, click_arg, &context);
@@ -1045,6 +1059,10 @@ namespace detail
pressed_wd = nullptr;
break;
case WM_MOUSEMOVE:
//Ignore mouse events when a window has been pressed by pressing spacebar
if (pressed_wd_space)
break;
msgwnd = brock.wd_manager().find_window(native_window, pmdec.mouse.x, pmdec.mouse.y);
if (brock.wd_manager().available(hovered_wd) && (msgwnd != hovered_wd))
{
@@ -1397,16 +1415,42 @@ namespace detail
if(msgwnd)
{
if((wParam == 9) && (!msgwnd->visible || (false == (msgwnd->flags.tab & tab_type::eating)))) //Tab
auto & wd_manager = brock.wd_manager();
if((VK_TAB == wParam) && (!msgwnd->visible || (false == (msgwnd->flags.tab & tab_type::eating)))) //Tab
{
bool is_forward = (::GetKeyState(VK_SHIFT) >= 0);
auto tstop_wd = brock.wd_manager().tabstop(msgwnd, is_forward);
auto tstop_wd = wd_manager.tabstop(msgwnd, is_forward);
if (tstop_wd)
{
brock.wd_manager().set_focus(tstop_wd, false);
brock.wd_manager().do_lazy_refresh(msgwnd, false);
brock.wd_manager().do_lazy_refresh(tstop_wd, true);
wd_manager.set_focus(tstop_wd, false);
wd_manager.do_lazy_refresh(msgwnd, false);
wd_manager.do_lazy_refresh(tstop_wd, true);
}
}
else if ((VK_SPACE == wParam) && msgwnd->flags.space_click_enabled)
{
//Clicked by spacebar
if (nullptr == pressed_wd && nullptr == pressed_wd_space)
{
arg_mouse arg;
arg.alt = false;
arg.button = ::nana::mouse::left_button;
arg.ctrl = false;
arg.evt_code = event_code::mouse_down;
arg.left_button = true;
arg.mid_button = false;
arg.pos.x = 0;
arg.pos.y = 0;
arg.window_handle = reinterpret_cast<window>(msgwnd);
msgwnd->flags.action = mouse_action::pressed;
pressed_wd_space = msgwnd;
auto retain = msgwnd->together.events_ptr;
emit_drawer(&drawer::mouse_down, msgwnd, arg, &context);
wd_manager.do_lazy_refresh(msgwnd, false);
}
}
else
@@ -1456,18 +1500,48 @@ namespace detail
}
return 0;
case WM_KEYUP:
if(wParam != 18) //MUST NOT BE AN ALT
if(wParam != VK_MENU) //MUST NOT BE AN ALT
{
msgwnd = brock.focus();
if(msgwnd)
{
arg_keyboard arg;
arg.evt_code = event_code::key_release;
arg.window_handle = reinterpret_cast<window>(msgwnd);
arg.key = static_cast<wchar_t>(wParam);
brock.get_key_state(arg);
arg.ignore = false;
brock.emit(event_code::key_release, msgwnd, arg, true, &context);
if (msgwnd == pressed_wd_space)
{
msgwnd->flags.action = mouse_action::normal;
arg_click click_arg;
click_arg.mouse_args = nullptr;
click_arg.window_handle = reinterpret_cast<window>(msgwnd);
auto retain = msgwnd->together.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<window>(msgwnd);
emit_drawer(&drawer::mouse_up, msgwnd, arg, &context);
brock.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<window>(msgwnd);
arg.key = static_cast<wchar_t>(wParam);
brock.get_key_state(arg);
arg.ignore = false;
brock.emit(event_code::key_release, msgwnd, arg, true, &context);
}
}
}
else
@@ -1521,6 +1595,7 @@ namespace detail
{
root_runtime->condition.pressed = pressed_wd;
root_runtime->condition.hovered = hovered_wd;
root_runtime->condition.pressed_by_space = pressed_wd_space;
}
if (!def_window_proc)