From 977a6c0e86d1092ead500a1d3a2be382a2846bd1 Mon Sep 17 00:00:00 2001 From: cnjinhao Date: Tue, 23 Dec 2014 17:09:30 +0800 Subject: [PATCH] A fix for non-English input issue. Extended ASCII characters input issue, window title bar issue. --- .../nana/detail/linux_X11/platform_spec.hpp | 9 ++-- source/detail/linux_X11/platform_spec.cpp | 44 +++++++++---------- source/detail/platform_spec_selector.cpp | 3 +- source/gui/detail/linux_X11/bedrock.cpp | 8 ++-- source/gui/detail/native_window_interface.cpp | 3 ++ source/gui/widgets/skeletons/text_editor.cpp | 2 +- .../paint/detail/native_paint_interface.cpp | 17 ++++++- source/paint/graphics.cpp | 2 +- 8 files changed, 52 insertions(+), 36 deletions(-) diff --git a/include/nana/detail/linux_X11/platform_spec.hpp b/include/nana/detail/linux_X11/platform_spec.hpp index f9914ecd..be306f5c 100644 --- a/include/nana/detail/linux_X11/platform_spec.hpp +++ b/include/nana/detail/linux_X11/platform_spec.hpp @@ -1,6 +1,7 @@ /* * Platform Specification Implementation - * Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com) + * Nana C++ Library(http://www.nanapro.org) + * Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -102,13 +103,12 @@ namespace detail unsigned whitespace_pixels; }string; #if defined(NANA_UNICODE) - XftDraw * xftdraw; + XftDraw * xftdraw{nullptr}; XftColor xft_fgcolor; - XftColor xft_bgcolor; const std::string charset(const nana::string& str, const std::string& strcode); #endif private: - unsigned fgcolor_; + unsigned fgcolor_{0xFFFFFFFF}; #if defined(NANA_UNICODE) struct conv_tag { @@ -131,6 +131,7 @@ namespace detail Atom net_wm_state_maximized_horz; Atom net_wm_state_maximized_vert; Atom net_wm_state_modal; + Atom net_wm_name; Atom net_wm_window_type; Atom net_wm_window_type_normal; Atom net_wm_window_type_utility; diff --git a/source/detail/linux_X11/platform_spec.cpp b/source/detail/linux_X11/platform_spec.cpp index 38301911..a0751b4b 100644 --- a/source/detail/linux_X11/platform_spec.cpp +++ b/source/detail/linux_X11/platform_spec.cpp @@ -1,5 +1,6 @@ /* * Platform Specification Implementation + * Nana C++ Library(http://www.nanapro.org) * Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Nana Software License, Version 1.0. @@ -283,13 +284,11 @@ namespace detail }; drawable_impl_type::drawable_impl_type() - : fgcolor_(0xFFFFFFFF) { string.tab_length = 4; string.tab_pixels = 0; string.whitespace_pixels = 0; #if defined(NANA_UNICODE) - xftdraw = 0; conv_.handle = ::iconv_open("UTF-8", "UTF-32"); conv_.code = "UTF-32"; #endif @@ -304,29 +303,29 @@ namespace detail void drawable_impl_type::fgcolor(unsigned color) { - if(color != fgcolor_) - { - auto & spec = nana::detail::platform_spec::instance(); - platform_scope_guard psg; + if(color == fgcolor_) + return; - fgcolor_ = color; - switch(spec.screen_depth()) - { - case 16: - color = ((((color >> 16) & 0xFF) * 31 / 255) << 11) | + auto & spec = nana::detail::platform_spec::instance(); + platform_scope_guard psg; + + fgcolor_ = color; + switch(spec.screen_depth()) + { + case 16: + color = ((((color >> 16) & 0xFF) * 31 / 255) << 11) | ((((color >> 8) & 0xFF) * 63 / 255) << 5) | (color & 0xFF) * 31 / 255; - break; - } - ::XSetForeground(spec.open_display(), context, color); - ::XSetBackground(spec.open_display(), context, color); -#if defined(NANA_UNICODE) - xft_fgcolor.color.red = ((0xFF0000 & color) >> 16) * 0x101; - xft_fgcolor.color.green = ((0xFF00 & color) >> 8) * 0x101; - xft_fgcolor.color.blue = (0xFF & color) * 0x101; - xft_fgcolor.color.alpha = 0xFFFF; -#endif + break; } + ::XSetForeground(spec.open_display(), context, color); + ::XSetBackground(spec.open_display(), context, color); +#if defined(NANA_UNICODE) + xft_fgcolor.color.red = ((0xFF0000 & color) >> 16) * 0x101; + xft_fgcolor.color.green = ((0xFF00 & color) >> 8) * 0x101; + xft_fgcolor.color.blue = (0xFF & color) * 0x101; + xft_fgcolor.color.alpha = 0xFFFF; +#endif } class font_deleter @@ -394,7 +393,7 @@ namespace detail } } else - langstr_dup = "zh_CN.UTF-8"; + langstr_dup = "en_US.UTF-8"; std::setlocale(LC_CTYPE, langstr_dup.c_str()); if(::XSupportsLocale()) ::XSetLocaleModifiers(langstr_dup.c_str()); @@ -416,6 +415,7 @@ namespace detail atombase_.net_wm_state_maximized_horz = ::XInternAtom(display_, "_NET_WM_STATE_MAXIMIZED_HORZ", False); atombase_.net_wm_state_maximized_vert = ::XInternAtom(display_, "_NET_WM_STATE_MAXIMIZED_VERT", False); atombase_.net_wm_state_modal = ::XInternAtom(display_, "_NET_WM_STATE_MODAL", False); + atombase_.net_wm_name = ::XInternAtom(display_, "_NET_WM_NAME", False); atombase_.net_wm_window_type = ::XInternAtom(display_, "_NET_WM_WINDOW_TYPE", False); atombase_.net_wm_window_type_normal = ::XInternAtom(display_, "_NET_WM_WINDOW_TYPE_NORMAL", False); atombase_.net_wm_window_type_utility = ::XInternAtom(display_, "_NET_WM_WINDOW_TYPE_UTILITY", False); diff --git a/source/detail/platform_spec_selector.cpp b/source/detail/platform_spec_selector.cpp index f3eeab01..1bf8a3c5 100644 --- a/source/detail/platform_spec_selector.cpp +++ b/source/detail/platform_spec_selector.cpp @@ -1,5 +1,6 @@ /* * Platform Specification Selector + * Nana C++ Library(http://www.nanapro.org) * Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Nana Software License, Version 1.0. @@ -9,7 +10,7 @@ * @file: nana/detail/platform_spec_selector.cpp * * This file is used to support the Nana project of some cross-platform IDE, - * + * */ #include diff --git a/source/gui/detail/linux_X11/bedrock.cpp b/source/gui/detail/linux_X11/bedrock.cpp index 2a82d049..10aa860a 100644 --- a/source/gui/detail/linux_X11/bedrock.cpp +++ b/source/gui/detail/linux_X11/bedrock.cpp @@ -954,7 +954,7 @@ namespace detail } keybuf[len] = 0; - nana::char_t keychar; + nana::char_t keychar = 0; switch(status) { case XLookupKeySym: @@ -983,8 +983,6 @@ namespace detail keychar = keyboard::os_insert; break; case XK_Delete: keychar = keyboard::os_del; break; - default: - keychar = keysym; } context.platform.keychar = keychar; if(keychar == keyboard::tab && (false == (msgwnd->flags.tab & detail::tab_type::eating))) //Tab @@ -1001,7 +999,7 @@ namespace detail { context.is_alt_pressed = true; } - else + else if(keychar) { arg_keyboard arg; arg.ignore = false; @@ -1019,7 +1017,7 @@ namespace detail } case XLookupChars: { - const nana::char_t * charbuf; + const ::nana::char_t* charbuf; #if defined(NANA_UNICODE) nana::detail::charset_conv charset("UTF-32", "UTF-8"); const std::string& str = charset.charset(std::string(keybuf, keybuf + len)); diff --git a/source/gui/detail/native_window_interface.cpp b/source/gui/detail/native_window_interface.cpp index 541bba9b..9199ce79 100644 --- a/source/gui/detail/native_window_interface.cpp +++ b/source/gui/detail/native_window_interface.cpp @@ -1099,6 +1099,9 @@ namespace nana{ nana::detail::platform_scope_guard psg; ::XStringListToTextProperty(&text, 1, &name); ::XSetWMName(restrict::spec.open_display(), reinterpret_cast(wd), &name); + ::XChangeProperty(restrict::spec.open_display(), reinterpret_cast(wd), + restrict::spec.atombase().net_wm_name, restrict::spec.atombase().utf8_string, 8, + PropModeReplace, reinterpret_cast(text), mbstr.size()); #endif } diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index de5c0946..be087de0 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -1193,7 +1193,7 @@ namespace nana{ namespace widgets undo(false); break; default: - if (key >= 0xFF || (32 <= key && key <= 126)) + if (key > 0x7F || (32 <= key && key <= 126)) put(key); else if (sizeof(nana::char_t) == sizeof(char)) { //Non-Unicode Version for Non-English characters diff --git a/source/paint/detail/native_paint_interface.cpp b/source/paint/detail/native_paint_interface.cpp index aff60b44..0a7e7f99 100644 --- a/source/paint/detail/native_paint_interface.cpp +++ b/source/paint/detail/native_paint_interface.cpp @@ -1,6 +1,7 @@ /* * Platform Implementation - * Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com) + * Nana C++ Library(http://www.nanapro.org) + * Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -200,11 +201,23 @@ namespace detail #if defined(NANA_WINDOWS) ::TextOut(dw->context, x, y, str, static_cast(len)); #elif defined(NANA_X11) + auto disp = ::nana::detail::platform_spec::instance().open_display(); #if defined(NANA_UNICODE) + /* std::string utf8str = nana::charset(nana::string(str, len)); XftFont * fs = reinterpret_cast(dw->font->handle); ::XftDrawStringUtf8(dw->xftdraw, &(dw->xft_fgcolor), fs, x, y + fs->ascent, reinterpret_cast(const_cast(utf8str.c_str())), utf8str.size()); + */ + auto fs = reinterpret_cast(dw->font->handle); + std::unique_ptr glyphs_ptr(new FT_UInt[len]); + auto glyphs = glyphs_ptr.get(); + const auto endstr = str + len; + for(auto chr = str; chr != endstr; ++chr) + { + (*glyphs++) = XftCharIndex(disp, fs, *chr); + } + XftDrawGlyphs(dw->xftdraw, &(dw->xft_fgcolor), fs, x, y + fs->ascent, glyphs_ptr.get(), len); #else XFontSet fs = reinterpret_cast(dw->font->handle); XFontSetExtents * ext = ::XExtentsOfFontSet(fs); @@ -221,7 +234,7 @@ namespace detail if(descent < (*i)->descent) descent = (*i)->descent; } - XmbDrawString(display, dw->pixmap, reinterpret_cast(dw->font->handle), dw->context, x, y + ascent + descent, buf, len); + XmbDrawString(disp, dw->pixmap, reinterpret_cast(dw->font->handle), dw->context, x, y + ascent + descent, buf, len); #endif #endif } diff --git a/source/paint/graphics.cpp b/source/paint/graphics.cpp index 2d5ba66d..23ee377b 100644 --- a/source/paint/graphics.cpp +++ b/source/paint/graphics.cpp @@ -1,7 +1,7 @@ /* * Paint Graphics Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at