fix a bug that msgbox uses local codepage

This commit is contained in:
Jinhao 2016-07-09 10:27:18 +08:00
parent e73fc679f4
commit 6ee314a9ea
2 changed files with 26 additions and 6 deletions

View File

@ -61,6 +61,12 @@ namespace nana
/// Writes a string to the buffer. /// Writes a string to the buffer.
msgbox & operator<<(const wchar_t*); 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. /// Writes a string to the buffer.
msgbox & operator<<(const nana::charset&); msgbox & operator<<(const nana::charset&);

View File

@ -355,14 +355,12 @@ namespace nana
msgbox::msgbox(const std::string& title) msgbox::msgbox(const std::string& title)
: wd_(nullptr), title_(title), button_(ok), icon_(icon_none) : wd_(nullptr), title_(title), button_(ok), icon_(icon_none)
{ {
// throw_not_utf8(title_);
review_utf8(title_); review_utf8(title_);
} }
msgbox::msgbox(window wd, const std::string& title, button_t b) msgbox::msgbox(window wd, const std::string& title, button_t b)
: wd_(wd), title_(title), button_(b), icon_(icon_none) : wd_(wd), title_(title), button_(b), icon_(icon_none)
{ {
// throw_not_utf8(title_);
review_utf8(title_); review_utf8(title_);
} }
@ -380,19 +378,35 @@ namespace nana
msgbox & msgbox::operator<<(const std::wstring& str) msgbox & msgbox::operator<<(const std::wstring& str)
{ {
sstream_ << to_osmbstr(to_utf8(str)); sstream_ << to_utf8(str);
return *this; return *this;
} }
msgbox & msgbox::operator<<(const wchar_t* str) msgbox & msgbox::operator<<(const wchar_t* str)
{ {
sstream_ << to_osmbstr(to_utf8(str)); sstream_ << to_utf8(str);
return *this; 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) msgbox & msgbox::operator<<(const nana::charset& cs)
{ {
std::string str = cs; std::string str = cs.to_bytes(nana::unicode::utf8);
sstream_ << str; sstream_ << str;
return *this; return *this;
} }
@ -454,7 +468,7 @@ namespace nana
return pick_yes; return pick_yes;
#elif defined(NANA_X11) #elif defined(NANA_X11)
msgbox_window box(wd_, title_, button_, icon_); msgbox_window box(wd_, title_, button_, icon_);
box.prompt(nana::charset(sstream_.str())); box.prompt(sstream_.str());
return box.pick(); return box.pick();
#endif #endif
return pick_yes; return pick_yes;