[pywin32-checkins] pywin32/win32/src win32clipboardmodule.cpp, 1.23.2.1, 1.23.2.2
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-11-26 07:17:52
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv14888/win32/src Modified Files: Tag: py3k win32clipboardmodule.cpp Log Message: Merge various changes from trunk and py3k-integration bzr branch Index: win32clipboardmodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32clipboardmodule.cpp,v retrieving revision 1.23.2.1 retrieving revision 1.23.2.2 diff -C2 -d -r1.23.2.1 -r1.23.2.2 *** win32clipboardmodule.cpp 29 Aug 2008 04:59:26 -0000 1.23.2.1 --- win32clipboardmodule.cpp 26 Nov 2008 07:17:39 -0000 1.23.2.2 *************** *** 313,316 **** --- 313,317 ---- // @pyparm int|format|CF_TEXT|Specifies a clipboard format. For a description of // the standard clipboard formats, see Standard Clipboard Formats. + // In Unicode builds (ie, python 3k), the default is CF_UNICODETEXT. #ifdef UNICODE int format = CF_UNICODETEXT; *************** *** 894,903 **** // In py3k, unicode no longer supports buffer interface if (PyUnicode_Check(obhandle)){ ! wchar_t *wchar_buf=PyUnicode_AS_UNICODE(obhandle); ! // ??? WTF None of the of Python Api functions return the correct size ??? ! bufSize = (wcslen(wchar_buf)+1) * sizeof(wchar_buf[0]); ! buf=(void *)wchar_buf; ! } ! else{ if (PyObject_AsReadBuffer(obhandle,&buf,&bufSize)==-1) return NULL; --- 895,901 ---- // In py3k, unicode no longer supports buffer interface if (PyUnicode_Check(obhandle)){ ! bufSize = PyUnicode_GET_DATA_SIZE(obhandle) + sizeof(Py_UNICODE); ! buf=(void *)PyUnicode_AS_UNICODE(obhandle); ! } else { if (PyObject_AsReadBuffer(obhandle,&buf,&bufSize)==-1) return NULL; *************** *** 946,977 **** // @pymethod int|win32clipboard|SetClipboardText|Convienience function to // call SetClipboardData with text. ! static PyObject * py_set_clipboard_text(PyObject* self, PyObject* args) { - #ifdef UNICODE - int format = CF_UNICODETEXT; - #else int format = CF_TEXT; - #endif - TCHAR *text; PyObject *obtext, *ret=NULL; ! DWORD size; ! if (!PyArg_ParseTuple(args, "O:SetClipboardText", ! &obtext)) // @pyparm str/unicode|text||The text to place on the clipboard. return NULL; ! if (!PyWinObject_AsTCHAR(obtext, &text, FALSE, &size)) ! return NULL; HGLOBAL hMem; ! LPTSTR pszDst=NULL; ! hMem = GlobalAlloc(GHND, (size+1) * sizeof(TCHAR)); if (hMem == NULL) PyWin_SetAPIError("GlobalAlloc"); else{ ! pszDst = (TCHAR *)GlobalLock(hMem); ! _tcscpy(pszDst, text); ! pszDst[size] = 0; GlobalUnlock(hMem); HANDLE data; --- 944,991 ---- // @pymethod int|win32clipboard|SetClipboardText|Convienience function to // call SetClipboardData with text. ! // @comm You may pass a Unicode or string/bytes object to this function, ! // but depending on the value of the 'format' param, it may be converted ! // to the appropriate type for that param. ! // @comm Many applications will want to call this function twice, with the ! // same string specified but CF_UNICODETEXT specified the second. static PyObject * py_set_clipboard_text(PyObject* self, PyObject* args) { int format = CF_TEXT; PyObject *obtext, *ret=NULL; ! if (!PyArg_ParseTuple(args, "O|i:SetClipboardText", ! &obtext, // @pyparm str/unicode|text||The text to place on the clipboard. ! &format)) // @pyparm int|format|CF_TEXT|The clipboard format to use - must be CF_TEXT or CF_UNICODETEXT return NULL; ! const void *src = 0; ! DWORD cb = 0; // number of bytes *excluding* NULL ! size_t size_null = 0; ! if (format == CF_TEXT) { ! if (!PyWinObject_AsString(obtext, (char **)&src, FALSE, &cb)) ! return NULL; ! size_null = sizeof(char); ! } else if (format == CF_UNICODETEXT) { ! DWORD cchars; ! if (!PyWinObject_AsWCHAR(obtext, (WCHAR **)&src, FALSE, &cchars)) ! return NULL; ! cb = cchars * sizeof(WCHAR); ! size_null = sizeof(WCHAR); ! } else { ! return PyErr_Format(PyExc_ValueError, "Format arg must be one of CF_TEXT (%d) or CF_UNICODETEXT (%d) - got %d", ! CF_TEXT, CF_UNICODETEXT, format); ! } ! HGLOBAL hMem; ! BYTE *dest=NULL; ! hMem = GlobalAlloc(GHND, cb + size_null); if (hMem == NULL) PyWin_SetAPIError("GlobalAlloc"); else{ ! dest = (BYTE *)GlobalLock(hMem); ! memcpy(dest, src, cb); ! // whack the terminator on. ! memset(dest+cb, 0, size_null); GlobalUnlock(hMem); HANDLE data; *************** *** 984,988 **** ret = PyWinLong_FromHANDLE(data); } ! PyWinObject_FreeTCHAR(text); return ret; // @pyseeapi SetClipboardData --- 998,1005 ---- ret = PyWinLong_FromHANDLE(data); } ! if (format == CF_TEXT) ! PyWinObject_FreeString((char *)src); ! else ! PyWinObject_FreeWCHAR((WCHAR *)src); return ret; // @pyseeapi SetClipboardData *************** *** 1179,1182 **** --- 1196,1206 ---- AddConstants(module); PyDict_SetItemString(dict, "error", PyWinExc_ApiError); + PyDict_SetItemString(dict,"UNICODE", + #ifdef UNICODE + Py_True + #else + Py_False + #endif + ); } *************** *** 1203,1206 **** --- 1227,1237 ---- if (PyDict_SetItemString(dict, "error", PyWinExc_ApiError)==-1) return NULL; + PyDict_SetItemString(dict,"UNICODE", + #ifdef UNICODE + Py_True + #else + Py_False + #endif + ); return module; } |