code reviews

This commit is contained in:
Jinhao
2015-10-13 01:38:53 +08:00
parent 500aa030ae
commit 1b5aed2e5f
41 changed files with 830 additions and 1001 deletions

View File

@@ -233,7 +233,7 @@ namespace detail
if(wd)
{
internal_scope_guard isg;
if(wd_manager.available(wd))
if(wd_manager().available(wd))
return wd->other.category;
}
return category::flags::super;
@@ -241,21 +241,10 @@ namespace detail
bedrock::core_window_t* bedrock::focus()
{
core_window_t* wd = wd_manager.root(native_interface::get_focus_window());
core_window_t* wd = wd_manager().root(native_interface::get_focus_window());
return (wd ? wd->other.attribute.root->focus : 0);
}
native_window_type bedrock::root(core_window_t* wd)
{
if(wd)
{
internal_scope_guard isg;
if(wd_manager.available(wd))
return wd->root;
}
return nullptr;
}
void bedrock::set_menubar_taken(core_window_t* wd)
{
auto pre = impl_->menu.taken_window;
@@ -265,8 +254,8 @@ namespace detail
if ((!wd) && pre)
{
internal_scope_guard lock;
wd_manager.set_focus(pre, false);
wd_manager.update(pre, true, false);
wd_manager().set_focus(pre, false);
wd_manager().update(pre, true, false);
}
}
@@ -381,17 +370,9 @@ namespace detail
//No implementation for Linux
}
bool bedrock::emit(event_code evt_code, core_window_t* wd, const arg_mouse& arg, bool ask_update, thread_context* thrd)
{
if(evt_code != arg.evt_code)
throw std::runtime_error("Nana.bedrock: Invalid event arg.");
return emit(evt_code, wd, static_cast<const ::nana::event_arg&>(arg), ask_update, thrd);
}
bool bedrock::emit(event_code evt_code, core_window_t* wd, const ::nana::event_arg& arg, bool ask_update, thread_context* thrd)
{
if(wd_manager.available(wd) == false)
if(wd_manager().available(wd) == false)
return false;
core_window_t * prev_wd;
@@ -408,7 +389,7 @@ namespace detail
_m_emit_core(evt_code, wd, false, arg);
if(ask_update)
wd_manager.do_lazy_refresh(wd, false);
wd_manager().do_lazy_refresh(wd, false);
else
wd->other.upd_state = core_window_t::update_state::none;
@@ -418,7 +399,7 @@ namespace detail
bool bedrock::emit_drawer(event_code evt_code, core_window_t* wd, const ::nana::event_arg& arg, thread_context* thrd)
{
if(wd_manager.available(wd) == false)
if(wd_manager().available(wd) == false)
return false;
core_window_t * prev_wd;
@@ -541,7 +522,7 @@ namespace detail
static auto& brock = detail::bedrock::instance();
auto native_window = reinterpret_cast<native_window_type>(msg.u.packet_window);
auto root_runtime = brock.wd_manager.root_runtime(native_window);
auto root_runtime = brock.wd_manager().root_runtime(native_window);
if(root_runtime)
{
@@ -550,7 +531,7 @@ namespace detail
switch(msg.kind)
{
case nana::detail::msg_packet_tag::kind_mouse_drop:
msgwd = brock.wd_manager.find_window(native_window, msg.u.mouse_drop.x, msg.u.mouse_drop.y);
msgwd = brock.wd_manager().find_window(native_window, msg.u.mouse_drop.x, msg.u.mouse_drop.y);
if(msgwd)
{
arg_dropfiles arg;
@@ -560,7 +541,7 @@ namespace detail
arg.pos.x = msg.u.mouse_drop.x - msgwd->pos_root.x;
arg.pos.y = msg.u.mouse_drop.y - msgwd->pos_root.y;
msgwd->together.events_ptr->mouse_dropfiles.emit(arg);
brock.wd_manager.do_lazy_refresh(msgwd, false);
brock.wd_manager().do_lazy_refresh(msgwd, false);
}
break;
default:
@@ -572,7 +553,7 @@ namespace detail
template<typename Arg>
void emit_drawer(void(::nana::detail::drawer::*event_ptr)(const Arg&), basic_window* wd, const Arg& arg, bedrock::thread_context* thrd)
{
if(bedrock::instance().wd_manager.available(wd) == false)
if(bedrock::instance().wd_manager().available(wd) == false)
return;
basic_window * pre_wd;
if(thrd)
@@ -597,7 +578,7 @@ namespace detail
static core_window_t* last_mouse_down_window;
auto native_window = reinterpret_cast<native_window_type>(event_window(xevent));
auto root_runtime = brock.wd_manager.root_runtime(native_window);
auto root_runtime = brock.wd_manager().root_runtime(native_window);
if(root_runtime)
{
@@ -612,7 +593,7 @@ namespace detail
switch(xevent.type)
{
case EnterNotify:
msgwnd = brock.wd_manager.find_window(native_window, xevent.xcrossing.x, xevent.xcrossing.y);
msgwnd = brock.wd_manager().find_window(native_window, xevent.xcrossing.x, xevent.xcrossing.y);
if(msgwnd)
{
if (mouse_action::pressed != msgwnd->flags.action)
@@ -626,7 +607,7 @@ namespace detail
arg.evt_code = event_code::mouse_move;
brock.emit(event_code::mouse_move, msgwnd, arg, true, &context);
if (!brock.wd_manager.available(hovered_wd))
if (!brock.wd_manager().available(hovered_wd))
hovered_wd = nullptr;
}
break;
@@ -646,7 +627,7 @@ namespace detail
arg.receiver = native_window;
arg.getting = true;
if(!brock.emit(event_code::focus, focus, arg, true, &context))
brock.wd_manager.set_focus(msgwnd, true);
brock.wd_manager().set_focus(msgwnd, true);
}
break;
case FocusOut:
@@ -672,7 +653,7 @@ namespace detail
if(msgwnd->dimension.width != static_cast<unsigned>(xevent.xconfigure.width) || msgwnd->dimension.height != static_cast<unsigned>(xevent.xconfigure.height))
{
auto & cf = xevent.xconfigure;
brock.wd_manager.size(msgwnd, nana::size{static_cast<unsigned>(cf.width), static_cast<unsigned>(cf.height)}, true, true);
brock.wd_manager().size(msgwnd, nana::size{static_cast<unsigned>(cf.width), static_cast<unsigned>(cf.height)}, true, true);
}
if(msgwnd->pos_native.x != xevent.xconfigure.x || msgwnd->pos_native.y != xevent.xconfigure.y)
@@ -686,7 +667,7 @@ namespace detail
if(xevent.xbutton.button == Button4 || xevent.xbutton.button == Button5)
break;
msgwnd = brock.wd_manager.find_window(native_window, xevent.xbutton.x, xevent.xbutton.y);
msgwnd = brock.wd_manager().find_window(native_window, xevent.xbutton.x, xevent.xbutton.y);
if(nullptr == msgwnd) break;
if ((msgwnd == msgwnd->root_widget->other.attribute.root->menubar) && brock.get_menu(msgwnd->root, true))
@@ -706,9 +687,9 @@ namespace detail
if (new_focus && !new_focus->flags.ignore_mouse_focus)
{
context.event_window = new_focus;
auto kill_focus = brock.wd_manager.set_focus(new_focus, false);
auto kill_focus = brock.wd_manager().set_focus(new_focus, false);
if (kill_focus != new_focus)
brock.wd_manager.do_lazy_refresh(kill_focus, false);
brock.wd_manager().do_lazy_refresh(kill_focus, false);
}
}
@@ -722,7 +703,7 @@ namespace detail
arg.evt_code = dbl_click ? event_code::dbl_click : event_code::mouse_down;
if(brock.emit(arg.evt_code, msgwnd, arg, true, &context))
{
if (brock.wd_manager.available(msgwnd))
if (brock.wd_manager().available(msgwnd))
{
pressed_wd = msgwnd;
//If a root window is created during the mouse_down event, Nana.GUI will ignore the mouse_up event.
@@ -731,7 +712,7 @@ namespace detail
//call the drawer mouse up event for restoring the surface graphics
msgwnd->flags.action = mouse_action::normal;
emit_drawer(&drawer::mouse_up, msgwnd, arg, &context);
brock.wd_manager.do_lazy_refresh(msgwnd, false);
brock.wd_manager().do_lazy_refresh(msgwnd, false);
}
}
}
@@ -758,7 +739,7 @@ namespace detail
}
else
{
msgwnd = brock.wd_manager.find_window(native_window, xevent.xbutton.x, xevent.xbutton.y);
msgwnd = brock.wd_manager().find_window(native_window, xevent.xbutton.x, xevent.xbutton.y);
if(nullptr == msgwnd)
break;
@@ -786,7 +767,7 @@ namespace detail
}
//Do mouse_up, this handle may be closed by click handler.
if(brock.wd_manager.available(msgwnd) && msgwnd->flags.enabled)
if(brock.wd_manager().available(msgwnd) && msgwnd->flags.enabled)
{
if(hit)
msgwnd->flags.action = mouse_action::over;
@@ -805,7 +786,7 @@ namespace detail
evt_ptr->click.emit(arg);
}
if (brock.wd_manager.available(msgwnd))
if (brock.wd_manager().available(msgwnd))
{
arg.evt_code = event_code::mouse_up;
evt_ptr->mouse_up.emit(arg);
@@ -818,7 +799,7 @@ namespace detail
arg.by_mouse = true;
msgwnd->together.events_ptr->click.emit(arg);
}
brock.wd_manager.do_lazy_refresh(msgwnd, false);
brock.wd_manager().do_lazy_refresh(msgwnd, false);
}
pressed_wd = nullptr;
}
@@ -826,7 +807,7 @@ namespace detail
case DestroyNotify:
{
auto & spec = nana::detail::platform_spec::instance();
if(brock.wd_manager.available(msgwnd))
if(brock.wd_manager().available(msgwnd))
{
//The msgwnd may be destroyed if the window is destroyed by calling native interface of close_window().
if (msgwnd->root == brock.get_menu())
@@ -836,10 +817,10 @@ namespace detail
}
spec.remove(native_window);
brock.wd_manager.destroy(msgwnd);
brock.wd_manager().destroy(msgwnd);
brock.rt_manager.remove_if_exists(msgwnd);
brock.wd_manager.destroy_handle(msgwnd);
brock.manage_form_loader(msgwnd, false);
brock.wd_manager().destroy_handle(msgwnd);
}
}
break;
@@ -854,8 +835,8 @@ namespace detail
else
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))
msgwnd = brock.wd_manager().find_window(native_window, xevent.xmotion.x, xevent.xmotion.y);
if (brock.wd_manager().available(hovered_wd) && (msgwnd != hovered_wd))
{
brock.event_msleave(hovered_wd);
hovered_wd->flags.action = mouse_action::normal;
@@ -863,14 +844,14 @@ namespace detail
//if msgwnd is neither a captured window nor a child of captured window,
//redirect the msgwnd to the captured window.
auto cap_wd = brock.wd_manager.capture_redirect(msgwnd);
auto cap_wd = brock.wd_manager().capture_redirect(msgwnd);
if(cap_wd)
msgwnd = cap_wd;
}
else if(msgwnd)
{
bool prev_captured_inside;
if(brock.wd_manager.capture_window_entered(xevent.xmotion.x, xevent.xmotion.y, prev_captured_inside))
if(brock.wd_manager().capture_window_entered(xevent.xmotion.x, xevent.xmotion.y, prev_captured_inside))
{
event_code evt_code;
if(prev_captured_inside)
@@ -909,7 +890,7 @@ namespace detail
arg.evt_code = event_code::mouse_move;
brock.emit(event_code::mouse_move, msgwnd, arg, true, &context);
}
if (!brock.wd_manager.available(hovered_wd))
if (!brock.wd_manager().available(hovered_wd))
hovered_wd = nullptr;
break;
case MapNotify:
@@ -1010,11 +991,11 @@ namespace detail
{
arg_keyboard argkey;
brock.get_key_state(argkey);
auto tstop_wd = brock.wd_manager.tabstop(msgwnd, !argkey.shift);
auto tstop_wd = brock.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);
brock.wd_manager().set_focus(tstop_wd, false);
brock.wd_manager().do_lazy_refresh(tstop_wd, true);
}
}
else if(keyboard::alt == keychar)
@@ -1050,7 +1031,7 @@ namespace detail
arg.window_handle = reinterpret_cast<window>(msgwnd);
brock.emit(event_code::key_press, msgwnd, arg, true, &context);
if((XLookupKeySym == status) && (brock.wd_manager.available(msgwnd)))
if((XLookupKeySym == status) && (brock.wd_manager().available(msgwnd)))
{
//call key_char event if status is XLookupKeySym to avaid calling key_char
//twice, because the status would be equal to XLookupChars if the input method is
@@ -1069,7 +1050,7 @@ namespace detail
if(XLookupKeySym == status)
{
brock.wd_manager.do_lazy_refresh(msgwnd, false);
brock.wd_manager().do_lazy_refresh(msgwnd, false);
break;
}
case XLookupChars:
@@ -1099,7 +1080,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 = brock.wd_manager().find_shortkey(native_window, arg.key);
if(shr_wd)
{
arg.window_handle = reinterpret_cast<window>(shr_wd);
@@ -1112,7 +1093,7 @@ namespace detail
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 && brock.wd_manager().available(msgwnd))
brock.emit_drawer(event_code::key_char, msgwnd, arg, &context);
}
@@ -1121,7 +1102,7 @@ namespace detail
}
break;
}
brock.wd_manager.do_lazy_refresh(msgwnd, false);
brock.wd_manager().do_lazy_refresh(msgwnd, false);
if(keybuf != fixbuf)
delete [] keybuf;
}
@@ -1156,7 +1137,7 @@ namespace detail
{
bool set_focus = (brock.focus() != msgwnd) && (!msgwnd->root_widget->flags.ignore_menubar_focus);
if (set_focus)
brock.wd_manager.set_focus(msgwnd, false);
brock.wd_manager().set_focus(msgwnd, false);
arg_keyboard arg;
arg.evt_code = event_code::key_release;
@@ -1194,7 +1175,7 @@ namespace detail
}
}
root_runtime = brock.wd_manager.root_runtime(native_window);
root_runtime = brock.wd_manager().root_runtime(native_window);
if(root_runtime)
{
context.event_window = pre_event_window;
@@ -1207,11 +1188,11 @@ namespace detail
if(context) context->event_window = pre_event_window;
}
auto thread_id = ::nana::system::this_thread_id()
brock.wd_manager.call_safe_place(thread_id);
auto thread_id = ::nana::system::this_thread_id();
brock.wd_manager().call_safe_place(thread_id);
if(msgwnd)
brock.wd_manager.remove_trash_handle(thread_id);
brock.wd_manager().remove_trash_handle(thread_id);
}
}
@@ -1226,18 +1207,18 @@ namespace detail
}
++(context->event_pump_ref_count);
wd_manager.internal_lock().revert();
wd_manager().internal_lock().revert();
native_window_type owner_native = 0;
core_window_t * owner = 0;
if(modal_window)
{
native_window_type modal = root(reinterpret_cast<core_window_t*>(modal_window));
native_window_type modal = reinterpret_cast<core_window_t*>(modal_window)->root;
owner_native = native_interface::get_owner_window(modal);
if(owner_native)
{
native_interface::enable_window(owner_native, false);
owner = wd_manager.root(owner_native);
owner = wd_manager().root(owner_native);
if(owner)
owner->flags.enabled = false;
}
@@ -1252,7 +1233,7 @@ namespace detail
native_interface::enable_window(owner_native, true);
}
wd_manager.internal_lock().forward();
wd_manager().internal_lock().forward();
if(0 == --(context->event_pump_ref_count))
{
if(0 == modal_window || 0 == context->window_count)
@@ -1338,7 +1319,7 @@ namespace detail
void bedrock::undefine_state_cursor(core_window_t * wd, thread_context* thrd)
{
if (!wd_manager.available(wd))
if (!wd_manager().available(wd))
return;
wd->root_widget->other.attribute.root->state_cursor = nana::cursor::arrow;
@@ -1350,7 +1331,7 @@ namespace detail
return;
native_interface::calc_window_point(native_handle, pos);
auto rev_wd = wd_manager.find_window(native_handle, pos.x, pos.y);
auto rev_wd = wd_manager().find_window(native_handle, pos.x, pos.y);
if (rev_wd)
set_cursor(rev_wd, rev_wd->predef_cursor, thrd);
}