A fix for non-English input issue.

Extended ASCII characters input issue, window title bar issue.
This commit is contained in:
cnjinhao 2014-12-23 17:09:30 +08:00
parent 7a42e8e2ed
commit 977a6c0e86
8 changed files with 52 additions and 36 deletions

View File

@ -1,6 +1,7 @@
/* /*
* Platform Specification Implementation * 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. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
@ -102,13 +103,12 @@ namespace detail
unsigned whitespace_pixels; unsigned whitespace_pixels;
}string; }string;
#if defined(NANA_UNICODE) #if defined(NANA_UNICODE)
XftDraw * xftdraw; XftDraw * xftdraw{nullptr};
XftColor xft_fgcolor; XftColor xft_fgcolor;
XftColor xft_bgcolor;
const std::string charset(const nana::string& str, const std::string& strcode); const std::string charset(const nana::string& str, const std::string& strcode);
#endif #endif
private: private:
unsigned fgcolor_; unsigned fgcolor_{0xFFFFFFFF};
#if defined(NANA_UNICODE) #if defined(NANA_UNICODE)
struct conv_tag struct conv_tag
{ {
@ -131,6 +131,7 @@ namespace detail
Atom net_wm_state_maximized_horz; Atom net_wm_state_maximized_horz;
Atom net_wm_state_maximized_vert; Atom net_wm_state_maximized_vert;
Atom net_wm_state_modal; Atom net_wm_state_modal;
Atom net_wm_name;
Atom net_wm_window_type; Atom net_wm_window_type;
Atom net_wm_window_type_normal; Atom net_wm_window_type_normal;
Atom net_wm_window_type_utility; Atom net_wm_window_type_utility;

View File

@ -1,5 +1,6 @@
/* /*
* Platform Specification Implementation * Platform Specification Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com)
* *
* Distributed under the Nana Software License, Version 1.0. * Distributed under the Nana Software License, Version 1.0.
@ -283,13 +284,11 @@ namespace detail
}; };
drawable_impl_type::drawable_impl_type() drawable_impl_type::drawable_impl_type()
: fgcolor_(0xFFFFFFFF)
{ {
string.tab_length = 4; string.tab_length = 4;
string.tab_pixels = 0; string.tab_pixels = 0;
string.whitespace_pixels = 0; string.whitespace_pixels = 0;
#if defined(NANA_UNICODE) #if defined(NANA_UNICODE)
xftdraw = 0;
conv_.handle = ::iconv_open("UTF-8", "UTF-32"); conv_.handle = ::iconv_open("UTF-8", "UTF-32");
conv_.code = "UTF-32"; conv_.code = "UTF-32";
#endif #endif
@ -304,8 +303,9 @@ namespace detail
void drawable_impl_type::fgcolor(unsigned color) void drawable_impl_type::fgcolor(unsigned color)
{ {
if(color != fgcolor_) if(color == fgcolor_)
{ return;
auto & spec = nana::detail::platform_spec::instance(); auto & spec = nana::detail::platform_spec::instance();
platform_scope_guard psg; platform_scope_guard psg;
@ -327,7 +327,6 @@ namespace detail
xft_fgcolor.color.alpha = 0xFFFF; xft_fgcolor.color.alpha = 0xFFFF;
#endif #endif
} }
}
class font_deleter class font_deleter
{ {
@ -394,7 +393,7 @@ namespace detail
} }
} }
else else
langstr_dup = "zh_CN.UTF-8"; langstr_dup = "en_US.UTF-8";
std::setlocale(LC_CTYPE, langstr_dup.c_str()); std::setlocale(LC_CTYPE, langstr_dup.c_str());
if(::XSupportsLocale()) if(::XSupportsLocale())
::XSetLocaleModifiers(langstr_dup.c_str()); ::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_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_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_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 = ::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_normal = ::XInternAtom(display_, "_NET_WM_WINDOW_TYPE_NORMAL", False);
atombase_.net_wm_window_type_utility = ::XInternAtom(display_, "_NET_WM_WINDOW_TYPE_UTILITY", False); atombase_.net_wm_window_type_utility = ::XInternAtom(display_, "_NET_WM_WINDOW_TYPE_UTILITY", False);

View File

@ -1,5 +1,6 @@
/* /*
* Platform Specification Selector * Platform Specification Selector
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com)
* *
* Distributed under the Nana Software License, Version 1.0. * Distributed under the Nana Software License, Version 1.0.

View File

@ -954,7 +954,7 @@ namespace detail
} }
keybuf[len] = 0; keybuf[len] = 0;
nana::char_t keychar; nana::char_t keychar = 0;
switch(status) switch(status)
{ {
case XLookupKeySym: case XLookupKeySym:
@ -983,8 +983,6 @@ namespace detail
keychar = keyboard::os_insert; break; keychar = keyboard::os_insert; break;
case XK_Delete: case XK_Delete:
keychar = keyboard::os_del; break; keychar = keyboard::os_del; break;
default:
keychar = keysym;
} }
context.platform.keychar = keychar; context.platform.keychar = keychar;
if(keychar == keyboard::tab && (false == (msgwnd->flags.tab & detail::tab_type::eating))) //Tab if(keychar == keyboard::tab && (false == (msgwnd->flags.tab & detail::tab_type::eating))) //Tab
@ -1001,7 +999,7 @@ namespace detail
{ {
context.is_alt_pressed = true; context.is_alt_pressed = true;
} }
else else if(keychar)
{ {
arg_keyboard arg; arg_keyboard arg;
arg.ignore = false; arg.ignore = false;
@ -1019,7 +1017,7 @@ namespace detail
} }
case XLookupChars: case XLookupChars:
{ {
const nana::char_t * charbuf; const ::nana::char_t* charbuf;
#if defined(NANA_UNICODE) #if defined(NANA_UNICODE)
nana::detail::charset_conv charset("UTF-32", "UTF-8"); nana::detail::charset_conv charset("UTF-32", "UTF-8");
const std::string& str = charset.charset(std::string(keybuf, keybuf + len)); const std::string& str = charset.charset(std::string(keybuf, keybuf + len));

View File

@ -1099,6 +1099,9 @@ namespace nana{
nana::detail::platform_scope_guard psg; nana::detail::platform_scope_guard psg;
::XStringListToTextProperty(&text, 1, &name); ::XStringListToTextProperty(&text, 1, &name);
::XSetWMName(restrict::spec.open_display(), reinterpret_cast<Window>(wd), &name); ::XSetWMName(restrict::spec.open_display(), reinterpret_cast<Window>(wd), &name);
::XChangeProperty(restrict::spec.open_display(), reinterpret_cast<Window>(wd),
restrict::spec.atombase().net_wm_name, restrict::spec.atombase().utf8_string, 8,
PropModeReplace, reinterpret_cast<unsigned char*>(text), mbstr.size());
#endif #endif
} }

View File

@ -1193,7 +1193,7 @@ namespace nana{ namespace widgets
undo(false); undo(false);
break; break;
default: default:
if (key >= 0xFF || (32 <= key && key <= 126)) if (key > 0x7F || (32 <= key && key <= 126))
put(key); put(key);
else if (sizeof(nana::char_t) == sizeof(char)) else if (sizeof(nana::char_t) == sizeof(char))
{ //Non-Unicode Version for Non-English characters { //Non-Unicode Version for Non-English characters

View File

@ -1,6 +1,7 @@
/* /*
* Platform Implementation * 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. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
@ -200,11 +201,23 @@ namespace detail
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
::TextOut(dw->context, x, y, str, static_cast<int>(len)); ::TextOut(dw->context, x, y, str, static_cast<int>(len));
#elif defined(NANA_X11) #elif defined(NANA_X11)
auto disp = ::nana::detail::platform_spec::instance().open_display();
#if defined(NANA_UNICODE) #if defined(NANA_UNICODE)
/*
std::string utf8str = nana::charset(nana::string(str, len)); std::string utf8str = nana::charset(nana::string(str, len));
XftFont * fs = reinterpret_cast<XftFont*>(dw->font->handle); XftFont * fs = reinterpret_cast<XftFont*>(dw->font->handle);
::XftDrawStringUtf8(dw->xftdraw, &(dw->xft_fgcolor), fs, x, y + fs->ascent, ::XftDrawStringUtf8(dw->xftdraw, &(dw->xft_fgcolor), fs, x, y + fs->ascent,
reinterpret_cast<XftChar8*>(const_cast<char*>(utf8str.c_str())), utf8str.size()); reinterpret_cast<XftChar8*>(const_cast<char*>(utf8str.c_str())), utf8str.size());
*/
auto fs = reinterpret_cast<XftFont*>(dw->font->handle);
std::unique_ptr<FT_UInt> 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 #else
XFontSet fs = reinterpret_cast<XFontSet>(dw->font->handle); XFontSet fs = reinterpret_cast<XFontSet>(dw->font->handle);
XFontSetExtents * ext = ::XExtentsOfFontSet(fs); XFontSetExtents * ext = ::XExtentsOfFontSet(fs);
@ -221,7 +234,7 @@ namespace detail
if(descent < (*i)->descent) if(descent < (*i)->descent)
descent = (*i)->descent; descent = (*i)->descent;
} }
XmbDrawString(display, dw->pixmap, reinterpret_cast<XFontSet>(dw->font->handle), dw->context, x, y + ascent + descent, buf, len); XmbDrawString(disp, dw->pixmap, reinterpret_cast<XFontSet>(dw->font->handle), dw->context, x, y + ascent + descent, buf, len);
#endif #endif
#endif #endif
} }

View File

@ -1,7 +1,7 @@
/* /*
* Paint Graphics Implementation * Paint Graphics Implementation
* Nana C++ Library(http://www.nanapro.org) * 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. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at