From 6ee314a9ea31361ee582154e796770fd6eebd264 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sat, 9 Jul 2016 10:27:18 +0800 Subject: [PATCH] fix a bug that msgbox uses local codepage --- include/nana/gui/msgbox.hpp | 6 ++++++ source/gui/msgbox.cpp | 26 ++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/include/nana/gui/msgbox.hpp b/include/nana/gui/msgbox.hpp index e21392e0..bb17c448 100644 --- a/include/nana/gui/msgbox.hpp +++ b/include/nana/gui/msgbox.hpp @@ -61,6 +61,12 @@ namespace nana /// Writes a string to the buffer. msgbox & operator<<(const wchar_t*); + /// Writes a UTF-8 string to the buffer. + msgbox & operator<<(const std::string&); + + /// Writes a UTF-8 string to the buffer. + msgbox & operator<<(const char*); + /// Writes a string to the buffer. msgbox & operator<<(const nana::charset&); diff --git a/source/gui/msgbox.cpp b/source/gui/msgbox.cpp index e3accf06..dadb5422 100644 --- a/source/gui/msgbox.cpp +++ b/source/gui/msgbox.cpp @@ -355,14 +355,12 @@ namespace nana msgbox::msgbox(const std::string& title) : wd_(nullptr), title_(title), button_(ok), icon_(icon_none) { - // throw_not_utf8(title_); review_utf8(title_); } msgbox::msgbox(window wd, const std::string& title, button_t b) : wd_(wd), title_(title), button_(b), icon_(icon_none) { - // throw_not_utf8(title_); review_utf8(title_); } @@ -380,19 +378,35 @@ namespace nana msgbox & msgbox::operator<<(const std::wstring& str) { - sstream_ << to_osmbstr(to_utf8(str)); + sstream_ << to_utf8(str); return *this; } msgbox & msgbox::operator<<(const wchar_t* str) { - sstream_ << to_osmbstr(to_utf8(str)); + sstream_ << to_utf8(str); return *this; } + + /// Writes a UTF-8 string to the buffer. + msgbox & msgbox::operator<<(const std::string& u8str) + { + review_utf8(u8str); + sstream_ << u8str; + + return *this; + } + + /// Writes a UTF-8 string to the buffer. + msgbox & msgbox::operator<<(const char* u8str) + { + return operator<<(std::string{ u8str }); + } + msgbox & msgbox::operator<<(const nana::charset& cs) { - std::string str = cs; + std::string str = cs.to_bytes(nana::unicode::utf8); sstream_ << str; return *this; } @@ -454,7 +468,7 @@ namespace nana return pick_yes; #elif defined(NANA_X11) msgbox_window box(wd_, title_, button_, icon_); - box.prompt(nana::charset(sstream_.str())); + box.prompt(sstream_.str()); return box.pick(); #endif return pick_yes;