Thread: [pywin32-checkins] pywin32/win32/src win32clipboardmodule.cpp, 1.22, 1.23
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2008-01-07 03:10:53
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24981 Modified Files: win32clipboardmodule.cpp Log Message: Allow to build with UNICODE defined Index: win32clipboardmodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32clipboardmodule.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** win32clipboardmodule.cpp 25 Aug 2007 05:14:55 -0000 1.22 --- win32clipboardmodule.cpp 7 Jan 2008 03:10:53 -0000 1.23 *************** *** 18,21 **** --- 18,23 ---- #define PY_SSIZE_T_CLEAN // this should be Py_ssize_t clean! + // #define UNICODE + // #define _UNICODE // CRT function (_tcs*) switch based on this #include "windows.h" #include "Python.h" *************** *** 311,316 **** // @pyparm int|format|CF_TEXT|Specifies a clipboard format. For a description of // the standard clipboard formats, see Standard Clipboard Formats. ! int format = CF_TEXT; if (!PyArg_ParseTuple(args, "|i:GetClipboardData:", &format)) { --- 313,321 ---- // @pyparm int|format|CF_TEXT|Specifies a clipboard format. For a description of // the standard clipboard formats, see Standard Clipboard Formats. ! #ifdef UNICODE ! int format = CF_UNICODETEXT; ! #else int format = CF_TEXT; + #endif if (!PyArg_ParseTuple(args, "|i:GetClipboardData:", &format)) { *************** *** 507,511 **** } ! char buf[256]; int rc; Py_BEGIN_ALLOW_THREADS; --- 512,516 ---- } ! TCHAR buf[256]; int rc; Py_BEGIN_ALLOW_THREADS; *************** *** 516,521 **** return ReturnAPIError("GetClipboardFormatName"); } ! ! return Py_BuildValue("s", buf); // @pyseeapi GetClipboardFormatName --- 521,525 ---- return ReturnAPIError("GetClipboardFormatName"); } ! return PyWinObject_FromTCHAR(buf); // @pyseeapi GetClipboardFormatName *************** *** 580,584 **** // @comm This method is not available on some early Windows (eg 95) machines. ! HMODULE hmod = LoadLibrary("user32.dll"); PFNGetClipboardSequenceNumber pfnGetClipboardSequenceNumber = NULL; if (hmod) pfnGetClipboardSequenceNumber=(PFNGetClipboardSequenceNumber)GetProcAddress(hmod, "GetClipboardSequenceNumber"); --- 584,588 ---- // @comm This method is not available on some early Windows (eg 95) machines. ! HMODULE hmod = LoadLibrary(TEXT("user32.dll")); PFNGetClipboardSequenceNumber pfnGetClipboardSequenceNumber = NULL; if (hmod) pfnGetClipboardSequenceNumber=(PFNGetClipboardSequenceNumber)GetProcAddress(hmod, "GetClipboardSequenceNumber"); *************** *** 815,837 **** py_register_clipboard_format(PyObject* self, PyObject* args) { ! ! // @pyparm string|name||String that names the new format. ! ! char *name; ! if (!PyArg_ParseTuple(args, "s:RegisterClipboardFormat", ! &name)) { ! return NULL; ! } ! ! UINT rc; ! Py_BEGIN_ALLOW_THREADS; ! rc = RegisterClipboardFormat(name); ! Py_END_ALLOW_THREADS; ! ! if (!rc) { ! return ReturnAPIError("RegisterClipboardFormat"); ! } ! ! return (Py_BuildValue("i", (int)rc)); // @comm If a registered format with the specified name already exists, a --- 819,837 ---- py_register_clipboard_format(PyObject* self, PyObject* args) { ! TCHAR *name; ! PyObject *obname; ! if (!PyArg_ParseTuple(args, "O:RegisterClipboardFormat", ! &obname)) // @pyparm string|name||String that names the new format. ! return NULL; ! if (!PyWinObject_AsTCHAR(obname, &name, FALSE)) ! return NULL; ! UINT rc; ! Py_BEGIN_ALLOW_THREADS; ! rc = RegisterClipboardFormat(name); ! Py_END_ALLOW_THREADS; ! PyWinObject_FreeTCHAR(name); ! if (!rc) ! return ReturnAPIError("RegisterClipboardFormat"); ! return PyInt_FromLong(rc); // @comm If a registered format with the specified name already exists, a *************** *** 949,990 **** py_set_clipboard_text(PyObject* self, PyObject* args) { ! // @pyparm string|text||The text to place on the clipboard. ! ! int format = CF_TEXT; ! char *text; ! Py_ssize_t size; ! if (!PyArg_ParseTuple(args, "s#:SetClipboardText", ! &text, &size)) { ! return NULL; ! } ! ! HGLOBAL hMem; ! LPTSTR pszDst; ! ! hMem = GlobalAlloc(GHND, size+1); ! if (hMem == NULL) { ! return ReturnAPIError("GlobalAlloc"); ! } ! pszDst = (char*)GlobalLock(hMem); ! lstrcpy(pszDst, text); ! pszDst[size] = 0; ! GlobalUnlock(hMem); ! ! HANDLE data; ! Py_BEGIN_ALLOW_THREADS; ! data = SetClipboardData((UINT)format, hMem); ! Py_END_ALLOW_THREADS; ! ! if (!data) ! return ReturnAPIError("SetClipboardText"); ! return PyWinLong_FromHANDLE(data); ! // @pyseeapi SetClipboardData ! // @rdesc If the function succeeds, the return value is integer handle ! // of the data.<nl> ! // If the function fails, win32api.error is raised with the GetLastError ! // info. } --- 949,994 ---- 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; ! Py_BEGIN_ALLOW_THREADS; ! data = SetClipboardData((UINT)format, hMem); ! Py_END_ALLOW_THREADS; ! if (!data) ! PyWin_SetAPIError("SetClipboardText"); ! else ! ret = PyWinLong_FromHANDLE(data); ! } ! PyWinObject_FreeTCHAR(text); ! return ret; ! // @pyseeapi SetClipboardData ! // @rdesc If the function succeeds, the return value is integer handle ! // of the data.<nl> ! // If the function fails, win32api.error is raised with the GetLastError ! // info. } |