Fixes to allow compilation in Unicode mode on wxGTK2. Python's

internal Unicode representation may or may not match wchar_t.
Previously I was using the optimized APIs that assumed they were the
same, but they aren't on Linux so this checkin switches to the more
general Python APIs.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@18518 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2003-01-02 22:24:44 +00:00
parent 952a4831ee
commit b5ae0a9a3b
7 changed files with 27 additions and 30 deletions

View File

@@ -407,7 +407,7 @@ public:
for (int i=0; i<count; i++) { for (int i=0; i<count; i++) {
#if wxUSE_UNICODE #if wxUSE_UNICODE
PyList_SetItem(list, i, PyUnicode_FromUnicode(files[i], files[i].Len())); PyList_SetItem(list, i, PyUnicode_FromWideChar(files[i], files[i].Len()));
#else #else
PyList_SetItem(list, i, PyString_FromString((const char*)files[i])); PyList_SetItem(list, i, PyString_FromString((const char*)files[i]));
#endif #endif

View File

@@ -361,6 +361,9 @@ public:
wxString GetStyleString() const; wxString GetStyleString() const;
wxString GetWeightString() const; wxString GetWeightString() const;
void SetNoAntiAliasing( bool no = TRUE );
bool GetNoAntiAliasing();
static wxFontEncoding GetDefaultEncoding(); static wxFontEncoding GetDefaultEncoding();
static void SetDefaultEncoding(wxFontEncoding encoding); static void SetDefaultEncoding(wxFontEncoding encoding);

View File

@@ -302,12 +302,7 @@ void __wxPreStart(PyObject* moduleDict)
int x; int x;
for(x=0; x<argc; x++) { for(x=0; x<argc; x++) {
PyObject *item = PyList_GetItem(sysargv, x); PyObject *item = PyList_GetItem(sysargv, x);
#if wxUSE_UNICODE argv[x] = wxPyCopyCString(Py2wxString(item));
if (PyUnicode_Check(item))
argv[x] = wxPyCopyCString(PyUnicode_AS_UNICODE(item));
else
#endif
argv[x] = wxPyCopyCString(PyString_AsString(item));
} }
argv[argc] = NULL; argv[argc] = NULL;
} }
@@ -338,12 +333,7 @@ PyObject* __wxStart(PyObject* /* self */, PyObject* args)
int x; int x;
for(x=0; x<argc; x++) { for(x=0; x<argc; x++) {
PyObject *pyArg = PyList_GetItem(sysargv, x); PyObject *pyArg = PyList_GetItem(sysargv, x);
#if wxUSE_UNICODE argv[x] = wxPyCopyWString(Py2wxString(pyArg));
if (PyUnicode_Check(pyArg))
argv[x] = wxPyCopyWString(PyUnicode_AS_UNICODE(pyArg));
else
#endif
argv[x] = wxPyCopyWString(PyString_AsString(pyArg));
} }
argv[argc] = NULL; argv[argc] = NULL;
} }
@@ -522,7 +512,7 @@ PyObject* wxPyClassExists(const wxString& className) {
char buff[64]; // should always be big enough... char buff[64]; // should always be big enough...
sprintf(buff, "%sPtr", className.mbc_str()); sprintf(buff, "%sPtr", (const char*)className.mbc_str());
PyObject* classobj = PyDict_GetItemString(wxPython_dict, buff); PyObject* classobj = PyDict_GetItemString(wxPython_dict, buff);
return classobj; // returns NULL if not found return classobj; // returns NULL if not found
@@ -1474,7 +1464,10 @@ wxString* wxString_in_helper(PyObject* source) {
} }
#if wxUSE_UNICODE #if wxUSE_UNICODE
if (PyUnicode_Check(source)) { if (PyUnicode_Check(source)) {
target = new wxString(PyUnicode_AS_UNICODE(source)); target = new wxString();
size_t len = PyUnicode_GET_SIZE(source);
PyUnicode_AsWideChar((PyUnicodeObject*)source, target->GetWriteBuf(len), len);
target->UngetWriteBuf();
} else { } else {
// It is a string, get pointers to it and transform to unicode // It is a string, get pointers to it and transform to unicode
char* tmpPtr; int tmpSize; char* tmpPtr; int tmpSize;
@@ -1516,7 +1509,9 @@ wxString Py2wxString(PyObject* source)
#if wxUSE_UNICODE #if wxUSE_UNICODE
if (PyUnicode_Check(source)) { if (PyUnicode_Check(source)) {
target = PyUnicode_AS_UNICODE(source); size_t len = PyUnicode_GET_SIZE(source);
PyUnicode_AsWideChar((PyUnicodeObject*)source, target.GetWriteBuf(len), len);
target.UngetWriteBuf();
} else { } else {
// It is a string, get pointers to it and transform to unicode // It is a string, get pointers to it and transform to unicode
char* tmpPtr; int tmpSize; char* tmpPtr; int tmpSize;
@@ -1549,7 +1544,7 @@ PyObject* wx2PyString(const wxString& src)
{ {
PyObject* str; PyObject* str;
#if wxUSE_UNICODE #if wxUSE_UNICODE
str = PyUnicode_FromUnicode(src.c_str(), src.Len()); str = PyUnicode_FromWideChar(src.c_str(), src.Len());
#else #else
str = PyString_FromStringAndSize(src.c_str(), src.Len()); str = PyString_FromStringAndSize(src.c_str(), src.Len());
#endif #endif
@@ -2170,7 +2165,7 @@ PyObject* wxArrayString2PyList_helper(const wxArrayString& arr) {
PyObject* list = PyList_New(0); PyObject* list = PyList_New(0);
for (size_t i=0; i < arr.GetCount(); i++) { for (size_t i=0; i < arr.GetCount(); i++) {
#if wxUSE_UNICODE #if wxUSE_UNICODE
PyObject* str = PyUnicode_FromUnicode(arr[i].c_str(), arr[i].Len()); PyObject* str = PyUnicode_FromWideChar(arr[i].c_str(), arr[i].Len());
#else #else
PyObject* str = PyString_FromStringAndSize(arr[i].c_str(), arr[i].Len()); PyObject* str = PyString_FromStringAndSize(arr[i].c_str(), arr[i].Len());
#endif #endif

View File

@@ -1212,7 +1212,7 @@ public:
wxString str; wxString str;
if (self->GetMimeType(&str)) { if (self->GetMimeType(&str)) {
#if wxUSE_UNICODE #if wxUSE_UNICODE
return PyUnicode_FromUnicode(str.c_str(), str.Len()); return PyUnicode_FromWideChar(str.c_str(), str.Len());
#else #else
return PyString_FromStringAndSize(str.c_str(), str.Len()); return PyString_FromStringAndSize(str.c_str(), str.Len());
#endif #endif
@@ -1264,7 +1264,7 @@ public:
PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon), PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
wxT("wxIcon"), TRUE)); wxT("wxIcon"), TRUE));
#if wxUSE_UNICODE #if wxUSE_UNICODE
PyTuple_SetItem(tuple, 1, PyUnicode_FromUnicode(iconFile.c_str(), iconFile.Len())); PyTuple_SetItem(tuple, 1, PyUnicode_FromWideChar(iconFile.c_str(), iconFile.Len()));
#else #else
PyTuple_SetItem(tuple, 1, PyString_FromStringAndSize(iconFile.c_str(), iconFile.Len())); PyTuple_SetItem(tuple, 1, PyString_FromStringAndSize(iconFile.c_str(), iconFile.Len()));
#endif #endif
@@ -1283,7 +1283,7 @@ public:
wxString str; wxString str;
if (self->GetDescription(&str)) { if (self->GetDescription(&str)) {
#if wxUSE_UNICODE #if wxUSE_UNICODE
return PyUnicode_FromUnicode(str.c_str(), str.Len()); return PyUnicode_FromWideChar(str.c_str(), str.Len());
#else #else
return PyString_FromStringAndSize(str.c_str(), str.Len()); return PyString_FromStringAndSize(str.c_str(), str.Len());
#endif #endif
@@ -1300,7 +1300,7 @@ public:
wxString str; wxString str;
if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype))) { if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
#if wxUSE_UNICODE #if wxUSE_UNICODE
return PyUnicode_FromUnicode(str.c_str(), str.Len()); return PyUnicode_FromWideChar(str.c_str(), str.Len());
#else #else
return PyString_FromStringAndSize(str.c_str(), str.Len()); return PyString_FromStringAndSize(str.c_str(), str.Len());
#endif #endif
@@ -1317,7 +1317,7 @@ public:
wxString str; wxString str;
if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype))) { if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
#if wxUSE_UNICODE #if wxUSE_UNICODE
return PyUnicode_FromUnicode(str.c_str(), str.Len()); return PyUnicode_FromWideChar(str.c_str(), str.Len());
#else #else
return PyString_FromStringAndSize(str.c_str(), str.Len()); return PyString_FromStringAndSize(str.c_str(), str.Len());
#endif #endif
@@ -1696,7 +1696,7 @@ public:
// #define ADD_STRING(dict, str) \ // #define ADD_STRING(dict, str) \
// wxString tmp##str(str); \ // wxString tmp##str(str); \
// PyDict_SetItemString(dict, #str, \ // PyDict_SetItemString(dict, #str, \
// PyUnicode_FromUnicode(tmp##str.c_str(), tmp##str.Len())) // PyUnicode_FromWideChar(tmp##str.c_str(), tmp##str.Len()))
// #else // #else
// #define ADD_STRING(dict, str) \ // #define ADD_STRING(dict, str) \
// PyDict_SetItemString(d, #str, PyString_FromString(str)) // PyDict_SetItemString(d, #str, PyString_FromString(str))

View File

@@ -168,7 +168,7 @@ $function
%typemap(python, out) wxString { %typemap(python, out) wxString {
#if wxUSE_UNICODE #if wxUSE_UNICODE
$target = PyUnicode_FromUnicode($source->c_str(), $source->Len()); $target = PyUnicode_FromWideChar($source->c_str(), $source->Len());
#else #else
$target = PyString_FromStringAndSize($source->c_str(), $source->Len()); $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
#endif #endif
@@ -180,7 +180,7 @@ $function
%typemap(python, out) wxString* { %typemap(python, out) wxString* {
#if wxUSE_UNICODE #if wxUSE_UNICODE
$target = PyUnicode_FromUnicode($source->c_str(), $source->Len()); $target = PyUnicode_FromWideChar($source->c_str(), $source->Len());
#else #else
$target = PyString_FromStringAndSize($source->c_str(), $source->Len()); $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
#endif #endif
@@ -274,11 +274,10 @@ $function
PyObject* item = PySequence_GetItem($source, i); PyObject* item = PySequence_GetItem($source, i);
#if wxUSE_UNICODE #if wxUSE_UNICODE
PyObject* str = PyObject_Unicode(item); PyObject* str = PyObject_Unicode(item);
$target->Add(PyUnicode_AsUnicode(str));
#else #else
PyObject* str = PyObject_Str(item); PyObject* str = PyObject_Str(item);
$target->Add(PyString_AsString(str));
#endif #endif
$target->Add(Py2wxString(str));
Py_DECREF(item); Py_DECREF(item);
Py_DECREF(str); Py_DECREF(str);
} }

View File

@@ -46,7 +46,7 @@
if (ret) { if (ret) {
PyTuple_SET_ITEM(ret, 0, PyInt_FromLong(flag)); PyTuple_SET_ITEM(ret, 0, PyInt_FromLong(flag));
#if wxUSE_UNICODE #if wxUSE_UNICODE
PyTuple_SET_ITEM(ret, 1, PyUnicode_FromUnicode(str.c_str(), str.Len())); PyTuple_SET_ITEM(ret, 1, PyUnicode_FromWideChar(str.c_str(), str.Len()));
#else #else
PyTuple_SET_ITEM(ret, 1, PyString_FromStringAndSize(str.c_str(), str.Len())); PyTuple_SET_ITEM(ret, 1, PyString_FromStringAndSize(str.c_str(), str.Len()));
#endif #endif

View File

@@ -277,7 +277,7 @@ static wxPyCoreAPI API = {
PyDict_SetItemString(d,"wxVERSION_NUMBER", PyInt_FromLong((long)wxVERSION_NUMBER )); PyDict_SetItemString(d,"wxVERSION_NUMBER", PyInt_FromLong((long)wxVERSION_NUMBER ));
#if wxUSE_UNICODE #if wxUSE_UNICODE
wxString tempStr(wxVERSION_STRING); wxString tempStr(wxVERSION_STRING);
PyDict_SetItemString(d,"wxVERSION_STRING", PyUnicode_FromUnicode(tempStr.c_str(), tempStr.Len())); PyDict_SetItemString(d,"wxVERSION_STRING", PyUnicode_FromWideChar(tempStr.c_str(), tempStr.Len()));
#else #else
PyDict_SetItemString(d,"wxVERSION_STRING", PyString_FromString(wxVERSION_STRING)); PyDict_SetItemString(d,"wxVERSION_STRING", PyString_FromString(wxVERSION_STRING));
#endif #endif