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

@@ -233,7 +233,7 @@ namespace detail
{
if(wd)
{
internal_scope_guard isg;
internal_scope_guard lock;
if(wd_manager().available(wd))
return wd->other.category;
}
@@ -656,12 +656,17 @@ namespace detail
auto pre_event_window = context.event_window;
auto pressed_wd = root_runtime->condition.pressed;
auto pressed_wd_space = root_runtime->condition.pressed_by_space;
auto hovered_wd = root_runtime->condition.hovered;
const int message = xevent.type;
switch(xevent.type)
{
case EnterNotify:
//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, xevent.xcrossing.x, xevent.xcrossing.y);
if(msgwnd)
{
@@ -733,6 +738,10 @@ namespace detail
}
break;
case ButtonPress:
//Ignore mouse events when a window has been pressed by pressing spacebar
if(pressed_wd_space)
break;
if(xevent.xbutton.button == Button4 || xevent.xbutton.button == Button5)
break;
@@ -788,6 +797,10 @@ namespace detail
}
break;
case ButtonRelease:
//Ignore mouse events when a window has been pressed by pressing spacebar
if(pressed_wd_space)
break;
if(xevent.xbutton.button == Button4 || xevent.xbutton.button == Button5)
{
//The hovered window receives the message, unlike in Windows, no redirection is required.
@@ -898,6 +911,10 @@ namespace detail
else
break;
//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, xevent.xmotion.x, xevent.xmotion.y);
if (brock.wd_manager().available(hovered_wd) && (msgwnd != hovered_wd))
{
@@ -1018,6 +1035,7 @@ namespace detail
keybuf[len] = 0;
wchar_t os_code = 0;
auto & wd_manager = brock.wd_manager();
switch(status)
{
case XLookupKeySym:
@@ -1027,11 +1045,37 @@ namespace detail
{
arg_keyboard argkey;
brock.get_key_state(argkey);
auto tstop_wd = brock.wd_manager().tabstop(msgwnd, !argkey.shift);
auto tstop_wd = wd_manager.tabstop(msgwnd, !argkey.shift);
if (tstop_wd)
{
brock.wd_manager().set_focus(tstop_wd, 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((keyboard::space == os_code) && 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 if(keyboard::alt == os_code)
@@ -1081,7 +1125,7 @@ namespace detail
if(XLookupKeySym == status)
{
brock.wd_manager().do_lazy_refresh(msgwnd, false);
wd_manager.do_lazy_refresh(msgwnd, false);
break;
}
case XLookupChars:
@@ -1109,7 +1153,7 @@ namespace detail
arg.ctrl = arg.shift = false;
arg.evt_code = event_code::shortkey;
brock.set_keyboard_shortkey(true);
auto shr_wd = brock.wd_manager().find_shortkey(native_window, arg.key);
auto shr_wd = wd_manager.find_shortkey(native_window, arg.key);
if(shr_wd)
{
arg.window_handle = reinterpret_cast<window>(shr_wd);
@@ -1121,7 +1165,7 @@ namespace detail
arg.window_handle = reinterpret_cast<window>(msgwnd);
brock.get_key_state(arg);
msgwnd->together.events_ptr->key_char.emit(arg);
if(arg.ignore == false && brock.wd_manager().available(msgwnd))
if(arg.ignore == false && wd_manager.available(msgwnd))
brock.emit_drawer(event_code::key_char, msgwnd, arg, &context);
}
@@ -1131,7 +1175,7 @@ namespace detail
break;
}
brock.wd_manager().do_lazy_refresh(msgwnd, false);
wd_manager.do_lazy_refresh(msgwnd, false);
if(keybuf != fixbuf)
delete [] keybuf;
}
@@ -1149,13 +1193,43 @@ namespace detail
msgwnd = brock.focus();
if(msgwnd)
{
arg_keyboard arg;
arg.evt_code = event_code::key_release;
arg.window_handle = reinterpret_cast<window>(msgwnd);
arg.ignore = false;
arg.key = os_code;
brock.get_key_state(arg);
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.ignore = false;
arg.key = os_code;
brock.get_key_state(arg);
brock.emit(event_code::key_release, msgwnd, arg, true, &context);
}
}
if(os_code < keyboard::os_arrow_left || keyboard::os_arrow_down < os_code)
@@ -1216,6 +1290,7 @@ namespace detail
context.event_window = pre_event_window;
root_runtime->condition.pressed = pressed_wd;
root_runtime->condition.hovered = hovered_wd;
root_runtime->condition.pressed_by_space = pressed_wd_space;
}
else
{