Merge branch 'hotfixes'

This commit is contained in:
cnjinhao 2015-01-02 23:21:56 +08:00
commit 2409a1d5bd
12 changed files with 111 additions and 41 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

@ -102,12 +102,15 @@ namespace nana
: public widget_object<category::widget_tag, drawerbase::menubar::trigger> : public widget_object<category::widget_tag, drawerbase::menubar::trigger>
{ {
public: public:
menubar(); ///< The default constructor delay creation. menubar() = default; ///< The default constructor delay creation.
menubar(window); ///< Create a menubar at the top of the specified window. menubar(window); ///< Create a menubar at the top of the specified window.
~menubar();
void create(window); ///< Create a menubar at the top of the specified window. void create(window); ///< Create a menubar at the top of the specified window.
menu& push_back(const nana::string&); ///< Appends a new (empty) menu. menu& push_back(const nana::string&); ///< Appends a new (empty) menu.
menu& at(size_t index) const; ///< Gets the menu specified by index. menu& at(size_t index) const; ///< Gets the menu specified by index.
std::size_t length() const; ///< Number of menus. std::size_t length() const; ///< Number of menus.
private:
::nana::event_handle evt_resized_{nullptr};
};//end class menubar };//end class menubar
}//end namespace nana }//end namespace nana
#endif #endif

View File

@ -129,7 +129,9 @@ namespace nana
void load(nana::string file); void load(nana::string file);
void store(nana::string file); void store(nana::string file);
void store(nana::string file, nana::unicode encoding); void store(nana::string file, nana::unicode encoding);
textbox& reset(nana::string = {}); ///< discard the old text and set a newtext
//A workaround for reset, explicit default constructor syntax, because VC2013 incorrectly treats {} as {0}.
textbox& reset(nana::string = nana::string()); ///< discard the old text and set a newtext
/// The file of last store operation. /// The file of last store operation.
nana::string filename() const; nana::string filename() const;

View File

@ -799,16 +799,31 @@ namespace nana
switch(utf_x_) switch(utf_x_)
{ {
case unicode::utf8: case unicode::utf8:
#if defined(NANA_MINGW)
strbuf = detail::utf8_to_utf16(data_, true);
detail::put_utf16char(strbuf, 0, true);
#else
strbuf = detail::utf8_to_utf32(data_, true); strbuf = detail::utf8_to_utf32(data_, true);
detail::put_utf32char(strbuf, 0, true); detail::put_utf32char(strbuf, 0, true);
#endif
break; break;
case unicode::utf16: case unicode::utf16:
#if defined(NANA_MINGW)
strbuf = data_;
detail::put_utf16char(strbuf, 0, true);
#else
strbuf = detail::utf16_to_utf32(data_); strbuf = detail::utf16_to_utf32(data_);
detail::put_utf32char(strbuf, 0, true); detail::put_utf32char(strbuf, 0, true);
#endif
break; break;
case unicode::utf32: case unicode::utf32:
#if defined(NANA_MINGW)
strbuf = detail::utf32_to_utf16(data_);
detail::put_utf16char(strbuf, 0, true);
#else
strbuf = data_; strbuf = data_;
detail::put_utf32char(strbuf, 0, true); detail::put_utf32char(strbuf, 0, true);
#endif
break; break;
} }
@ -892,13 +907,25 @@ namespace nana
switch(utf_x_) switch(utf_x_)
{ {
case unicode::utf8: case unicode::utf8:
#if defined(NANA_MINGW)
bytes = detail::utf8_to_utf16(data_, true);
#else
bytes = detail::utf8_to_utf32(data_, true); bytes = detail::utf8_to_utf32(data_, true);
#endif
break; break;
case unicode::utf16: case unicode::utf16:
#if defined(NANA_MINGW)
bytes = data_;
#else
bytes = detail::utf16_to_utf32(data_); bytes = detail::utf16_to_utf32(data_);
#endif
break; break;
case unicode::utf32: case unicode::utf32:
#if defined(NANA_MINGW)
bytes = detail::utf32_to_utf16(data_);
#else
bytes = data_; bytes = data_;
#endif
break; break;
} }
return std::wstring(reinterpret_cast<const wchar_t*>(bytes.c_str()), bytes.size() / sizeof(wchar_t)); return std::wstring(reinterpret_cast<const wchar_t*>(bytes.c_str()), bytes.size() / sizeof(wchar_t));
@ -957,11 +984,23 @@ namespace nana
switch(encoding) switch(encoding)
{ {
case unicode::utf8: case unicode::utf8:
#if defined(NANA_MINGW)
return detail::utf16_to_utf8(std::string(reinterpret_cast<const char*>(data_.c_str()), data_.size() * sizeof(wchar_t)));
#else
return detail::utf32_to_utf8(std::string(reinterpret_cast<const char*>(data_.c_str()), data_.size() * sizeof(wchar_t))); return detail::utf32_to_utf8(std::string(reinterpret_cast<const char*>(data_.c_str()), data_.size() * sizeof(wchar_t)));
#endif
case unicode::utf16: case unicode::utf16:
return detail::utf32_to_utf16(std::string(reinterpret_cast<const char*>(data_.c_str()), data_.size() * sizeof(wchar_t))); #if defined(NANA_MINGW)
case unicode::utf32:
return std::string(reinterpret_cast<const char*>(data_.c_str()), data_.size() * sizeof(wchar_t)); return std::string(reinterpret_cast<const char*>(data_.c_str()), data_.size() * sizeof(wchar_t));
#else
return detail::utf32_to_utf16(std::string(reinterpret_cast<const char*>(data_.c_str()), data_.size() * sizeof(wchar_t)));
#endif
case unicode::utf32:
#if defined(NANA_MINGW)
return detail::utf16_to_utf32(std::string(reinterpret_cast<const char*>(data_.c_str()), data_.size() * sizeof(wchar_t)));
#else
return std::string(reinterpret_cast<const char*>(data_.c_str()), data_.size() * sizeof(wchar_t));
#endif
} }
return {}; return {};
} }

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,29 +303,29 @@ 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();
platform_scope_guard psg;
fgcolor_ = color; auto & spec = nana::detail::platform_spec::instance();
switch(spec.screen_depth()) platform_scope_guard psg;
{
case 16: fgcolor_ = color;
color = ((((color >> 16) & 0xFF) * 31 / 255) << 11) | switch(spec.screen_depth())
{
case 16:
color = ((((color >> 16) & 0xFF) * 31 / 255) << 11) |
((((color >> 8) & 0xFF) * 63 / 255) << 5) | ((((color >> 8) & 0xFF) * 63 / 255) << 5) |
(color & 0xFF) * 31 / 255; (color & 0xFF) * 31 / 255;
break; 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
} }
::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 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.
@ -9,7 +10,7 @@
* @file: nana/detail/platform_spec_selector.cpp * @file: nana/detail/platform_spec_selector.cpp
* *
* This file is used to support the Nana project of some cross-platform IDE, * This file is used to support the Nana project of some cross-platform IDE,
* *
*/ */
#include <nana/config.hpp> #include <nana/config.hpp>

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

@ -574,17 +574,27 @@ namespace nana
//class menubar //class menubar
menubar::menubar(){}
menubar::menubar(window wd) menubar::menubar(window wd)
{ {
create(wd); create(wd);
} }
menubar::~menubar()
{
API::umake_event(evt_resized_);
}
void menubar::create(window wd) void menubar::create(window wd)
{ {
widget_object<category::widget_tag, drawerbase::menubar::trigger> widget_object<category::widget_tag, drawerbase::menubar::trigger>
::create(wd, rectangle(nana::size(API::window_size(wd).width, 28))); ::create(wd, rectangle(nana::size(API::window_size(wd).width, 28)));
API::attach_menubar(handle()); API::attach_menubar(handle());
evt_resized_ = API::events(wd).resized([this](const ::nana::arg_resized& arg)
{
auto sz = this->size();
sz.width = arg.width;
this->size(sz);
});
} }
menu& menubar::push_back(const nana::string& text) menu& menubar::push_back(const nana::string& text)

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