X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7e126a0784c24166888759bbc96d65a59c062fa8..cc9a39576ab6edb139c9bb77d01f4118853e04d2:/src/stc/PlatWX.cpp diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 4b983f1cd6..b3232e6aa5 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -40,7 +40,9 @@ PRectangle PRectangleFromwxRect(wxRect rc) { wxColour wxColourFromCA(const ColourAllocated& ca) { ColourDesired cd(ca.AsLong()); - return wxColour(cd.GetRed(), cd.GetGreen(), cd.GetBlue()); + return wxColour((unsigned char)cd.GetRed(), + (unsigned char)cd.GetGreen(), + (unsigned char)cd.GetBlue()); } //---------------------------------------------------------------------- @@ -1015,7 +1017,8 @@ void ListBoxImpl::GetValue(int n, char *value, int len) { void ListBoxImpl::RegisterImage(int type, const char *xpm_data) { wxMemoryInputStream stream(xpm_data, strlen(xpm_data)+1); - wxBitmap bmp(wxImage(stream, wxBITMAP_TYPE_XPM)); + wxImage img(stream, wxBITMAP_TYPE_XPM); + wxBitmap bmp(img); if (! imgList) { // assumes all images are the same size @@ -1249,25 +1252,46 @@ double ElapsedTime::Duration(bool reset) { //---------------------------------------------------------------------- #if wxUSE_UNICODE + +#include "UniConversion.h" + +// Convert using Scintilla's functions instead of wx's, Scintilla's are more +// forgiving and won't assert... + wxString stc2wx(const char* str, size_t len) { - // note: we assume that str is of length len not including the terminating null. - if (!len) return wxEmptyString; - else if (str[len-1] == 0) - // It's already terminated correctly. - return wxString(str, wxConvUTF8, len); - char *buffer=new char[len+1]; - strncpy(buffer, str, len); - buffer[len]=0; + size_t wclen = UCS2Length(str, len); + wxWCharBuffer buffer(wclen+1); + + size_t actualLen = UCS2FromUTF8(str, len, buffer.data(), wclen+1); + return wxString(buffer.data(), actualLen); +} + + - wxString cstr(buffer, wxConvUTF8, len); +wxString stc2wx(const char* str) +{ + return stc2wx(str, strlen(str)); +} + + +const wxWX2MBbuf wx2stc(const wxString& str) +{ + const wchar_t* wcstr = str.c_str(); + size_t wclen = str.length(); + size_t len = UTF8Length(wcstr, wclen); + + wxCharBuffer buffer(len+1); + UTF8FromUCS2(wcstr, wclen, buffer.data(), len); - delete[] buffer; - return cstr; + // TODO check NULL termination!! + + return buffer; } + #endif