From 04e57771a4b205e5934c75f31aa7f8da3894881f Mon Sep 17 00:00:00 2001 From: Jinhao Date: Fri, 10 Aug 2018 23:35:11 +0800 Subject: [PATCH] eliminate GCC warings when -Wimplicit-fallthrough is enabled --- source/detail/posix/msg_dispatcher.hpp | 4 +- source/gui/detail/bedrock_posix.cpp | 65 +++++++++++ source/gui/detail/native_window_interface.cpp | 104 ------------------ source/gui/place.cpp | 46 ++++---- source/gui/place_parts.hpp | 18 ++- source/gui/widgets/combox.cpp | 12 +- source/gui/widgets/listbox.cpp | 7 +- 7 files changed, 113 insertions(+), 143 deletions(-) diff --git a/source/detail/posix/msg_dispatcher.hpp b/source/detail/posix/msg_dispatcher.hpp index 8aed6ce5..6bef753e 100644 --- a/source/detail/posix/msg_dispatcher.hpp +++ b/source/detail/posix/msg_dispatcher.hpp @@ -1,6 +1,6 @@ /* * Message Dispatcher Implementation - * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -221,6 +221,8 @@ namespace detail case 0: msg_pack.kind = msg_pack.kind_xevent; msg_pack.u.xevent = event; + _m_msg_dispatch(msg_pack); + break; case 1: _m_msg_dispatch(msg_pack); } diff --git a/source/gui/detail/bedrock_posix.cpp b/source/gui/detail/bedrock_posix.cpp index 62dd68ee..debbbfee 100644 --- a/source/gui/detail/bedrock_posix.cpp +++ b/source/gui/detail/bedrock_posix.cpp @@ -575,6 +575,62 @@ namespace detail return true; } + void x_lookup_chars(const root_misc* rruntime, basic_window * msgwd, char* keybuf, std::size_t keybuf_len, const arg_keyboard& modifiers_status) + { + if (!msgwd->flags.enabled) + return; + + static auto& brock = detail::bedrock::instance(); + auto & wd_manager = brock.wd_manager(); + + auto& context = *brock.get_thread_context(msgwd->thread_id); + + auto const native_window = rruntime->window->root; + + + nana::detail::charset_conv charset(NANA_UNICODE, "UTF-8"); + const std::string& str = charset.charset(std::string(keybuf, keybuf + keybuf_len)); + auto const charbuf = reinterpret_cast(str.c_str()); + auto const len = str.size() / sizeof(wchar_t); + + for(std::size_t i = 0; i < len; ++i) + { + arg_keyboard arg = modifiers_status; + arg.ignore = false; + arg.key = charbuf[i]; + + // ignore Unicode BOM (it may or may not appear) + if (arg.key == 0xFEFF) continue; + + //Only accept tab when it is not ignored. + if ((keyboard::tab == arg.key) && rruntime->condition.ignore_tab) + continue; + + if(context.is_alt_pressed) + { + arg.ctrl = arg.shift = false; + arg.evt_code = event_code::shortkey; + brock.shortkey_occurred(true); + auto shr_wd = wd_manager.find_shortkey(native_window, arg.key); + if(shr_wd) + { + arg.window_handle = reinterpret_cast(shr_wd); + brock.emit(event_code::shortkey, shr_wd, arg, true, &context); + } + continue; + } + + arg.evt_code = event_code::key_char; + arg.window_handle = reinterpret_cast(msgwd); + msgwd->annex.events_ptr->key_char.emit(arg, reinterpret_cast(msgwd)); + if(arg.ignore == false && wd_manager.available(msgwd)) + draw_invoker(&drawer::key_char, msgwd, arg, &context); + } + + if(brock.shortkey_occurred(false)) + context.is_alt_pressed = false; + } + void window_proc_for_xevent(Display* /*display*/, XEvent& xevent) { typedef detail::bedrock::core_window_t core_window_t; @@ -1077,6 +1133,8 @@ namespace detail wd_manager.do_lazy_refresh(msgwnd, false); break; } +#if 0 + //Fall through case XLookupChars: if (msgwnd->flags.enabled) { @@ -1124,6 +1182,13 @@ namespace detail context.is_alt_pressed = false; } break; +#else + x_lookup_chars(root_runtime, msgwnd, keybuf, len, modifiers_status); + break; + case XLookupChars: + x_lookup_chars(root_runtime, msgwnd, keybuf, len, modifiers_status); + break; +#endif } wd_manager.do_lazy_refresh(msgwnd, false); diff --git a/source/gui/detail/native_window_interface.cpp b/source/gui/detail/native_window_interface.cpp index a8c86c1a..3fc6fcaf 100644 --- a/source/gui/detail/native_window_interface.cpp +++ b/source/gui/detail/native_window_interface.cpp @@ -182,88 +182,6 @@ namespace nana{ return nullptr; } - // Revise the position for moving window. Because the window is moved depending on - //implementation of Window Manager. A reparenting window may not be moved the origin to - //the specified location. it may be moved the left-top corner to the specified location. - -#if 0 - void x11_revise_position(native_window_type wd, int &x, int& y, bool written) - { - auto const disp = restrict::spec.open_display(); - auto const owner = reinterpret_cast(restrict::spec.get_owner(wd)); - auto const root_wd = restrict::spec.root_window(); - - if(written) - { - Window decoration_wd = 0; - if(owner) - { - Window child; - - if(owner != root_wd) - { - ::XTranslateCoordinates(disp, owner, root_wd, - x, y, &x, &y, &child); - } - - decoration_wd = reinterpret_cast(x11_parent_window(wd)); - if((decoration_wd == owner) || (decoration_wd == root_wd)) - decoration_wd = 0; - } - - if(decoration_wd) - { - auto fm_extents = native_interface::window_frame_extents(wd); - - XWindowAttributes attr; - ::XGetWindowAttributes(disp, reinterpret_cast(wd), &attr); - - x += attr.x - fm_extents.left; - y += attr.y - fm_extents.top; - } - } - } -#else - void x11_revise_position(native_window_type wd, int &x, int& y, bool written) - { - return; - auto const disp = restrict::spec.open_display(); - auto const root_wd = restrict::spec.root_window(); - - if(written) - { - auto decoration_wd = x11_decoration_frame(wd); - - - if(decoration_wd) - { - auto const owner = reinterpret_cast(restrict::spec.get_owner(wd)); - Window child; - ::XTranslateCoordinates(disp, owner, root_wd, - x, y, &x, &y, &child); - - - auto fm_extents = native_interface::window_frame_extents(wd); - - XWindowAttributes attr; - ::XGetWindowAttributes(disp, reinterpret_cast(wd), &attr); - - point client_pos{0, 0}; - ::XTranslateCoordinates(disp, reinterpret_cast(wd), root_wd, 0, 0, &client_pos.x, &client_pos.y, &child); - - point decoration_pos{0, 0}; - ::XTranslateCoordinates(disp, reinterpret_cast(decoration_wd), root_wd, 0, 0, &decoration_pos.x, &decoration_pos.y, &child); - - auto x1 = (client_pos.x - decoration_pos.x - fm_extents.left); - auto y1 = (client_pos.y - decoration_pos.y - fm_extents.top); - - return; - x -= (client_pos.x - decoration_pos.x - fm_extents.left); - y -= (client_pos.y - decoration_pos.y - fm_extents.top); - } - } - } -#endif void x11_apply_exposed_position(native_window_type wd) { @@ -1010,23 +928,7 @@ namespace nana{ point scr_pos; nana::detail::platform_scope_guard lock; -#if 0 - auto coord_wd = restrict::spec.get_owner(wd); - if(coord_wd) - { - //wd is a top level window. It returns the position of its decoration window. - auto decr = x11_parent_window(wd); - if(decr != coord_wd) - wd = decr; - } - else - coord_wd = get_window(wd, window_relationship::parent); - Window child; - ::XTranslateCoordinates(restrict::spec.open_display(), reinterpret_cast(wd), reinterpret_cast(coord_wd), 0, 0, &scr_pos.x, &scr_pos.y, &child); - - x11_revise_position(wd, scr_pos.x, scr_pos.y, false); -#else point origin{}; auto coord_wd = restrict::spec.get_owner(wd); @@ -1049,8 +951,6 @@ namespace nana{ Window child; ::XTranslateCoordinates(restrict::spec.open_display(), reinterpret_cast(wd), reinterpret_cast(coord_wd), origin.x, origin.y, &scr_pos.x, &scr_pos.y, &child); -#endif - return scr_pos; #endif } @@ -1092,14 +992,11 @@ namespace nana{ auto const owner = restrict::spec.get_owner(wd); if(owner && (owner != reinterpret_cast(restrict::spec.root_window()))) { - auto fm_extents = window_frame_extents(owner); auto origin = window_position(owner); x += origin.x; y += origin.y; } - x11_revise_position(wd, x, y, true); - ::XMoveWindow(disp, reinterpret_cast(wd), x, y); //Wait for the configuration notify to update the local attribute of position so that @@ -1179,7 +1076,6 @@ namespace nana{ y += origin.y; } - x11_revise_position(wd, x, y, true); ::XMoveResizeWindow(disp, reinterpret_cast(wd), x, y, r.width, r.height); //Wait for the configuration notify to update the local attribute of position so that diff --git a/source/gui/place.cpp b/source/gui/place.cpp index 96d7ac6d..5b22491e 100644 --- a/source/gui/place.cpp +++ b/source/gui/place.cpp @@ -798,17 +798,20 @@ namespace nana case number_t::kind::real: return static_cast(number.real()); case number_t::kind::percent: - adjustable_px = area_px * number.real(); case number_t::kind::none: - { - auto fpx = adjustable_px + precise_px; - auto px = static_cast(fpx); - precise_px = fpx - px; - return px; - } break; + default: + return 0; //Useless } - return 0; //Useless + + if(number_t::kind::percent == number.kind_of()) + adjustable_px = area_px * number.real() + precise_px; + else + adjustable_px += precise_px; + + auto const px = static_cast(adjustable_px); + precise_px = adjustable_px - px; + return px; } std::pair calc_weight_floor() @@ -2879,25 +2882,26 @@ namespace nana } field_gather * attached_field = nullptr; - if (name.size()) + + //find the field with specified name. + //the field may not be created. + auto i = fields.find(name); + if (fields.end() != i) { - //find the field with specified name. - //the field may not be created. - auto i = fields.find(name); - if (fields.end() != i) - { - attached_field = i->second; - //the field is attached to a division, it means there is another division with same name. - if (attached_field->attached) - throw std::runtime_error("place, the name '" + name + "' is redefined."); - } + attached_field = i->second; + //the field is attached to a division, it means there is another division with same name. + if (attached_field->attached) + throw std::runtime_error("place, the name '" + name + "' is redefined."); } token unmatch = token::width; switch (div_type) { - case token::eof: unmatch = token::height; // "horitontal" div - case token::vert: // "vertical" div + case token::eof: // "horitontal" div + case token::vert: // "vertical" div + if(token::eof == div_type) + unmatch = token::height; + for (auto& ch : children) if (ch->weigth_type == unmatch) throw std::invalid_argument("nana.place: unmatch vertical-heigth/horizontal-width betwen division '" diff --git a/source/gui/place_parts.hpp b/source/gui/place_parts.hpp index b17be9cd..ca2ea8d7 100644 --- a/source/gui/place_parts.hpp +++ b/source/gui/place_parts.hpp @@ -1,7 +1,7 @@ /* * Parts of Class Place * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -607,12 +607,16 @@ namespace nana it = ib = 0; il = ir = 1; break; - default: - il = 3; //left case 3: //top, right, bottom it = 0; ir = 1; ib = 2; + break; + default: //left, top, right, bottom, left + it = 0; + ir = 1; + ib = 2; + il = 3; } int pos = 0; @@ -661,12 +665,16 @@ namespace nana it = ib = 0; il = ir = 1; break; - default: - il = 3; //left case 3: //top, right, bottom it = 0; ir = 1; ib = 2; + break; + default: //left, top, right, bottom, left + it = 0; + ir = 1; + ib = 2; + il = 3; } using px_type = decltype(r.height); diff --git a/source/gui/widgets/combox.cpp b/source/gui/widgets/combox.cpp index dcaf5c43..56ce8b55 100644 --- a/source/gui/widgets/combox.cpp +++ b/source/gui/widgets/combox.cpp @@ -1,7 +1,7 @@ /* * A Combox Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -732,7 +732,6 @@ namespace nana bool call_other_keys = false; if(drawer_->editable()) { - bool is_move_up = false; switch(arg.key) { case keyboard::os_arrow_left: @@ -741,9 +740,8 @@ namespace nana drawer_->editor()->reset_caret(); break; case keyboard::os_arrow_up: - is_move_up = true; case keyboard::os_arrow_down: - drawer_->move_items(is_move_up, true); + drawer_->move_items((keyboard::os_arrow_up == arg.key), true); break; default: call_other_keys = true; @@ -751,15 +749,15 @@ namespace nana } else { - bool is_move_up = false; switch(arg.key) { case keyboard::os_arrow_left: case keyboard::os_arrow_up: - is_move_up = true; + drawer_->move_items(true, true); + break; case keyboard::os_arrow_right: case keyboard::os_arrow_down: - drawer_->move_items(is_move_up, true); + drawer_->move_items(false, true); break; default: call_other_keys = true; diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index 05b9687f..f25ac277 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -4477,14 +4477,11 @@ namespace nana if (list.first().empty()) return; - bool upward = false; - switch(arg.key) { case keyboard::os_arrow_up: - upward = true; case keyboard::os_arrow_down: - list.move_select(upward, !arg.shift, true); + list.move_select((keyboard::os_arrow_up == arg.key), !arg.shift, true); break; case L' ': { @@ -4496,9 +4493,9 @@ namespace nana } break; case keyboard::os_pageup : - upward = true; case keyboard::os_pagedown: { + auto const upward = (keyboard::os_pageup == arg.key); auto const item_px = essence_->item_height(); auto picked_items = list.pick_items(true, true); index_pair init_idx = (picked_items.empty() ? list.first() : picked_items[0]);