[pywin32-checkins] pywin32/win32/src win32gui.i,1.33,1.34
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2004-04-09 11:21:20
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25204 Modified Files: win32gui.i Log Message: * Add CheckMenuRadioItem and ExtractIconEx, TranslateMessage and DispatchMessage * PyGetString and PySetString check the pointer values before reading/ writing. Index: win32gui.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32gui.i,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** win32gui.i 30 Mar 2004 04:10:14 -0000 1.33 --- win32gui.i 9 Apr 2004 11:08:01 -0000 1.34 *************** *** 82,85 **** --- 82,97 ---- } + %typemap(python,in) MSG *INPUT { + if (PyArg_ParseTuple($source, "(iiiii(ii))", + &$target->hwnd, + &$target->message, + &$target->wParam, + &$target->lParam, + &$target->time, + &$target->pt.x, + &$target->pt.y)) + return PyErr_Format(PyExc_TypeError, "%s: This param must be a tuple of format 'iiiii(ii)'", "$name"); + } + %typemap(python,ignore) RECT *OUTPUT(RECT temp) { *************** *** 799,804 **** if (len == 0) return PyUnicodeObject_FromString(""); ! return PyWinObject_FromTCHAR(addr, len); ! } %} --- 811,820 ---- if (len == 0) return PyUnicodeObject_FromString(""); ! if (IsBadReadPtr(addr, len)) { ! PyErr_SetString(PyExc_ValueError, ! "The value is not a valid address for reading"); ! return NULL; ! } ! return PyWinObject_FromTCHAR(addr, len); } %} *************** *** 825,833 **** } ! if(maxLen) ! _tcsncpy( addr, source, maxLen); ! else ! _tcscpy(addr,source); Py_INCREF(Py_None); return Py_None; --- 841,853 ---- } ! if (!maxLen) ! maxLen = _tcslen(source)+1; + if (IsBadWritePtr(addr, maxLen)) { + PyErr_SetString(PyExc_ValueError, + "The value is not a valid address for writing"); + return NULL; + } + _tcsncpy( addr, source, maxLen); Py_INCREF(Py_None); return Py_None; *************** *** 1792,1795 **** --- 1812,1821 ---- %native (PumpWaitingMessages) PyPumpWaitingMessages; + // @pyswig int|TranslateMessage| + BOOL TranslateMessage(MSG *INPUT); + + // @pyswig int|DispatchMessage| + LRESULT DispatchMessage(MSG *INPUT); + // DELETE ME! %{ *************** *** 2055,2058 **** --- 2081,2146 ---- HICON ExtractIcon(HINSTANCE hinst, TCHAR *modName, UINT index); + // @pyswig int|ExtractIconEx| + // @pyparm string|moduleName|| + // @pyparm int|index|| + // @pyparm int|numIcons|1| + // @comm You must destroy each icon handle returned by calling the <om win32gui.DestroyIcon> function. + // @rdesc If index==-1, the result is an integer with the number of icons in + // the file, otherwise it is 2 arrays of icon handles. + %{ + static PyObject *PyExtractIconEx(PyObject *self, PyObject *args) + { + int i; + char *fname; + int index, nicons=1, nicons_got; + if (!PyArg_ParseTuple(args, "si|i", &fname, &index, &nicons)) + return NULL; + if (index==-1) { + nicons = ExtractIconEx(fname, index, NULL, NULL, 0); + return PyInt_FromLong(nicons); + } + if (nicons<=0) + return PyErr_Format(PyExc_ValueError, "Must supply a valid number of icons to fetch."); + HICON *rgLarge = NULL; + HICON *rgSmall = NULL; + PyObject *ret = NULL; + PyObject *objects_large = NULL; + PyObject *objects_small = NULL; + rgLarge = (HICON *)calloc(nicons, sizeof(HICON)); + if (rgLarge==NULL) { + PyErr_NoMemory(); + goto done; + } + rgSmall = (HICON *)calloc(nicons, sizeof(HICON)); + if (rgSmall==NULL) { + PyErr_NoMemory(); + goto done; + } + nicons_got = ExtractIconEx(fname, index, rgLarge, rgSmall, nicons); + if (nicons_got==-1) { + PyWin_SetAPIError("ExtractIconEx"); + goto done; + } + // Asking for 1 always says it got 2!? + nicons = min(nicons, nicons_got); + objects_large = PyList_New(nicons); + if (!objects_large) goto done; + objects_small = PyList_New(nicons); + if (!objects_small) goto done; + for (i=0;i<nicons;i++) { + PyList_SET_ITEM(objects_large, i, PyInt_FromLong((long)rgLarge[i])); + PyList_SET_ITEM(objects_small, i, PyInt_FromLong((long)rgSmall[i])); + } + ret = Py_BuildValue("OO", objects_large, objects_small); + done: + Py_XDECREF(objects_large); + Py_XDECREF(objects_small); + if (rgLarge) free(rgLarge); + if (rgSmall) free(rgSmall); + return ret; + } + %} + %native (ExtractIconEx) PyExtractIconEx; + // @pyswig |DestroyIcon| // @pyparm int|hicon||The icon to destroy. *************** *** 2155,2158 **** --- 2243,2257 ---- ); + // @pyswig |CheckMenuRadioItem|Checks a specified menu item and makes it a + // radio item. At the same time, the function clears all other menu items in + // the associated group and clears the radio-item type flag for those items. + BOOLAPI CheckMenuRadioItem( + HMENU hMenu, // @pyparm int|hMenu||handle to menu + UINT idFirst, // @pyparm int|idFirst||identifier or position of first item + UINT idLast, // @pyparm int|idLast||identifier or position of last item + UINT idCheck, // @pyparm int|idCheck||identifier or position of item to check + UINT uFlags // @pyparm int|uFlags||options + ); + BOOLAPI DrawFocusRect(HDC hDC, RECT *INPUT); |