X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3bc06221f04615811781ab91b46b2e44c5e9c4a4..8ac8dba00c38e34f3b69d4199366c89bf19e2cd8:/wxPython/src/helpers.cpp diff --git a/wxPython/src/helpers.cpp b/wxPython/src/helpers.cpp index a17498e304..694c5f4780 100644 --- a/wxPython/src/helpers.cpp +++ b/wxPython/src/helpers.cpp @@ -28,7 +28,9 @@ #include #include #include -#define GetXWindow(wxwin) GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) +#define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \ + GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \ + GDK_WINDOW_XWINDOW((wxwin)->m_widget->window) #include #endif @@ -47,7 +49,7 @@ //---------------------------------------------------------------------- -#if PYTHON_API_VERSION <= 1007 && wxUSE_UNICODE +#if PYTHON_API_VERSION < 1009 && wxUSE_UNICODE #error Python must support Unicode to use wxWindows Unicode #endif @@ -419,10 +421,10 @@ void wxPyApp::_BootstrapApp() goto error; } - // On wxGTK the locale will be changed to match the system settings, but - // Python needs to have LC_NUMERIC set to "C" in order for the floating - // point conversions and such to work right. -#ifdef __WXGTK__ + // On wxGTK the locale will be changed to match the system settings, + // but Python before 2.4 needs to have LC_NUMERIC set to "C" in order + // for the floating point conversions and such to work right. +#if defined(__WXGTK__) && PY_VERSION_HEX < 0x02040000 setlocale(LC_NUMERIC, "C"); #endif @@ -633,7 +635,7 @@ PyObject* __wxPySetDictionary(PyObject* /* self */, PyObject* args) PyDict_SetItemString(wxPython_dict, "USE_UNICODE", PyInt_FromLong(wxUSE_UNICODE)); PyDict_SetItemString(wxPython_dict, "__WXDEBUG__", PyInt_FromLong(wxdebug)); - + // Make a tuple of strings that gives more info about the platform. PyObject* PlatInfo = PyList_New(0); PyObject* obj; @@ -647,7 +649,7 @@ PyObject* __wxPySetDictionary(PyObject* /* self */, PyObject* args) #if wxUSE_UNICODE _AddInfoString("unicode"); #else - _AddInfoString("ascii"); + _AddInfoString("ansi"); #endif #ifdef __WXGTK__ #ifdef __WXGTK20__ @@ -1086,11 +1088,12 @@ void wxPySaveThreadState(PyThreadState* tstate) { if (info.tstate != tstate) wxLogMessage("*** tstate mismatch!???"); #endif - // info.tstate = tstate; *** DO NOT update existing ones??? + info.tstate = tstate; // allow for transient tstates // Normally it will never change, but apparently COM callbacks // (i.e. ActiveX controls) will (incorrectly IMHO) use a transient // tstate which will then be garbage the next time we try to use // it... + wxPyTMutex->Unlock(); return; } @@ -1181,7 +1184,8 @@ bool wxPyInputStream::eof() { } wxPyInputStream::~wxPyInputStream() { - /* do nothing */ + if (m_wxis) + delete m_wxis; } @@ -1382,7 +1386,7 @@ PyObject* wxPyCBInputStream::getMethod(PyObject* py, char* name) { } -size_t wxPyCBInputStream::GetSize() const { +wxFileOffset wxPyCBInputStream::GetLength() const { wxPyCBInputStream* self = (wxPyCBInputStream*)this; // cast off const if (m_seek && m_tell) { wxFileOffset temp = self->OnSysTell(); @@ -1391,7 +1395,7 @@ size_t wxPyCBInputStream::GetSize() const { return ret; } else - return 0; + return wxInvalidOffset; } @@ -1426,14 +1430,20 @@ size_t wxPyCBInputStream::OnSysWrite(const void *buffer, size_t bufsize) { return 0; } + wxFileOffset wxPyCBInputStream::OnSysSeek(wxFileOffset off, wxSeekMode mode) { bool blocked = wxPyBeginBlockThreads(); -#if defined( __WINCE__) || defined(_LARGE_FILES) || defined(__HUGEFILES_SUPPORTED) - // wxFileOffset is a 64-bit value... - PyObject* arglist = Py_BuildValue("(Li)", off, mode); -#else - PyObject* arglist = Py_BuildValue("(ii)", off, mode); -#endif + PyObject* arglist = PyTuple_New(2); + + if (sizeof(wxFileOffset) > sizeof(long)) + // wxFileOffset is a 64-bit value... + PyTuple_SET_ITEM(arglist, 0, PyLong_FromLongLong(off)); + else + PyTuple_SET_ITEM(arglist, 0, PyInt_FromLong(off)); + + PyTuple_SET_ITEM(arglist, 1, PyInt_FromLong(mode)); + + PyObject* result = PyEval_CallObject(m_seek, arglist); Py_DECREF(arglist); Py_XDECREF(result); @@ -1449,11 +1459,9 @@ wxFileOffset wxPyCBInputStream::OnSysTell() const { Py_DECREF(arglist); wxFileOffset o = 0; if (result != NULL) { -#if defined( __WINCE__) || defined(_LARGE_FILES) || defined(__HUGEFILES_SUPPORTED) if (PyLong_Check(result)) o = PyLong_AsLongLong(result); else -#endif o = PyInt_AsLong(result); Py_DECREF(result); }; @@ -1908,12 +1916,18 @@ wxString* wxString_in_helper(PyObject* source) { if (PyString_Check(source)) Py_DECREF(uni); #else - char* tmpPtr; int tmpSize; - if (PyString_AsStringAndSize(source, &tmpPtr, &tmpSize) == -1) { - PyErr_SetString(PyExc_TypeError, "Unable to convert string"); - return NULL; + // Convert to a string object if it isn't already, then to wxString + PyObject* str = source; + if (!PyString_Check(source)) { + str = PyObject_Str(source); + if (PyErr_Occurred()) return NULL; } + char* tmpPtr; int tmpSize; + PyString_AsStringAndSize(str, &tmpPtr, &tmpSize); target = new wxString(tmpPtr, tmpSize); + + if (!PyString_Check(source)) + Py_DECREF(str); #endif // wxUSE_UNICODE return target;