亂碼的原因在於 streambuf 讀取字符是一個字節(byte)、一個字節的讀取的。
streambuf中的字符采用的是變長(multibyte)編碼。
而wxTextCtrlBase中的實現
int wxTextCtrlBase::overflow(int c)
{
AppendText((wxChar)c);
// return something different from EOF
return 0;
}
是把streambuf的每個單字節,當作一個unicode字符,插入到TextCtrl之中。
於是,以GB2312/GBK方式編碼的"你好"這樣兩個漢字,就會被分割成4個unicode字符。
class WXDLLEXPORT wxTextCtrlBase : public wxControl
#if wxHAS_TEXT_WINDOW_STREAM
- , public wxSTD streambuf
+ , public wxSTD basic_streambuf<wxChar, wxSTD
// the old streambuf (before we changed it)
- wxSTD streambuf *m_sbufOld;
+ wxSTD wstreambuf *m_sbufOld;
};
#endif // wxHAS_TEXT_WINDOW_STREAM
textcmn.cpp:
int wxTextCtrlBase::overflow(int c)
{
AppendText((wxChar)c);
// return something different from EOF
return 0;
}
修改為
wxTextCtrlBase::int_type wxTextCtrlBase::overflow(wxTextCtrlBase::int_type c)
{
AppendText((wxChar)c);
// return something different from EOF
return 0;
}
期待著這個patch被check in到cvs中去
歡迎光臨 中央論壇 - CENTER BBS (https://www.centerbbs.com/)