[pywin32-checkins] pywin32/win32/src win32gui.i,1.92,1.93
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2006-12-24 06:44:58
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24853/win32/src Modified Files: win32gui.i Log Message: Add more drawing and DC functions Load function pointers for some functions formerly only in winxpgui so they can be used on Win2k Remove some instances of handles converted using PyArg_ParseTuple "l" format Index: win32gui.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32gui.i,v retrieving revision 1.92 retrieving revision 1.93 diff -C2 -d -r1.92 -r1.93 *** win32gui.i 20 Dec 2006 16:57:08 -0000 1.92 --- win32gui.i 24 Dec 2006 06:44:56 -0000 1.93 *************** *** 42,45 **** --- 42,47 ---- typedef BOOL (WINAPI *GetLayeredWindowAttributesfunc)(HWND, COLORREF *, BYTE *, DWORD *); static GetLayeredWindowAttributesfunc pfnGetLayeredWindowAttributes=NULL; + typedef BOOL (WINAPI *UpdateLayeredWindowfunc)(HWND,HDC,POINT *,SIZE *,HDC,POINT *,COLORREF,BLENDFUNCTION *,DWORD); + static UpdateLayeredWindowfunc pfnUpdateLayeredWindow=NULL; typedef BOOL (WINAPI *AngleArcfunc)(HDC, int, int, DWORD, FLOAT, FLOAT); static AngleArcfunc pfnAngleArc=NULL; *************** *** 54,57 **** --- 56,73 ---- typedef BOOL (WINAPI *CombineTransformfunc)(LPXFORM,CONST XFORM *,CONST XFORM *); static CombineTransformfunc pfnCombineTransform=NULL; + typedef BOOL (WINAPI *GradientFillfunc)(HDC,PTRIVERTEX,ULONG,PVOID,ULONG,ULONG); + static GradientFillfunc pfnGradientFill=NULL; + typedef BOOL (WINAPI *TransparentBltfunc)(HDC,int,int,int,int,HDC,int,int,int,int,UINT); + static TransparentBltfunc pfnTransparentBlt=NULL; + typedef BOOL (WINAPI *MaskBltfunc)(HDC,int,int,int,int,HDC,int,int,HBITMAP,int,int,DWORD); + static MaskBltfunc pfnMaskBlt=NULL; + typedef BOOL (WINAPI *AlphaBlendfunc)(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION); + static AlphaBlendfunc pfnAlphaBlend=NULL; + typedef BOOL (WINAPI *AnimateWindowfunc)(HWND,DWORD,DWORD); + static AnimateWindowfunc pfnAnimateWindow=NULL; + typedef DWORD (WINAPI *GetLayoutfunc)(HDC); + static GetLayoutfunc pfnGetLayout=NULL; + typedef DWORD (WINAPI *SetLayoutfunc)(HDC, DWORD); + static SetLayoutfunc pfnSetLayout=NULL; static PyObject *g_AtomMap = NULL; // Mapping class atoms to Python WNDPROC *************** *** 98,101 **** --- 114,144 ---- } } + + // @object PyBLENDFUNCTION|Tuple of four small ints used to fill a BLENDFUNCTION struct + // All 4 ints must fit in a byte (0-255). + // @pyseeapi BLENDFUNCTION + BOOL PyWinObject_AsBLENDFUNCTION(PyObject *obbl, BLENDFUNCTION *pbl) + { + if (!PyTuple_Check(obbl)){ + PyErr_SetString(PyExc_TypeError, "BLENDFUNCTION must be a tuple of four small ints (0-255)"); + return FALSE; + } + return PyArg_ParseTuple(obbl, "BBBB:BLENDFUNCTION", + &pbl->BlendOp, // @tupleitem 0|int|BlendOp|Only defined value is AC_SRC_OVER (0) + &pbl->BlendFlags, // @tupleitem 1|int|BlendFlags|None currently defined, must be 0 + &pbl->SourceConstantAlpha, // @tupleitem 2|int|SourceConstantAlpha|Transparency to be applied to entire source. (255 is opaque) + &pbl->AlphaFormat); // @tupleitem 3|int|AlphaFormat|Only defined flag is AC_SRC_ALPHA, used when src bitmap contains per-pixel alpha + } + + // @object PySIZE|Tuple of two ints (cx,cy) representing a SIZE struct + BOOL PyWinObject_AsSIZE(PyObject *obsize, SIZE *psize) + { + if (!PyTuple_Check(obsize)){ + PyErr_SetString(PyExc_TypeError, "SIZE must be a tuple of 2 ints (x,y)"); + return FALSE; + } + return PyArg_ParseTuple(obsize, "ll;SIZE must be a tuple of 2 ints (x,y)", + &psize->cx, &psize->cy); + } %} *************** *** 114,117 **** --- 157,162 ---- if (strcmp(pmd->ml_name, "SetLayeredWindowAttributes")==0 || strcmp(pmd->ml_name, "GetLayeredWindowAttributes")==0 || + strcmp(pmd->ml_name, "UpdateLayeredWindow")==0 || + strcmp(pmd->ml_name, "AnimateWindow")==0 || strcmp(pmd->ml_name, "GetOpenFileNameW")==0 || strcmp(pmd->ml_name, "GetSaveFileNameW")==0 || *************** *** 125,128 **** --- 170,175 ---- pfnSetLayeredWindowAttributes=(SetLayeredWindowAttributesfunc)GetProcAddress(hmodule,"SetLayeredWindowAttributes"); pfnGetLayeredWindowAttributes=(GetLayeredWindowAttributesfunc)GetProcAddress(hmodule,"GetLayeredWindowAttributes"); + pfnUpdateLayeredWindow=(UpdateLayeredWindowfunc)GetProcAddress(hmodule,"UpdateLayeredWindow"); + pfnAnimateWindow=(AnimateWindowfunc)GetProcAddress(hmodule,"AnimateWindow"); } *************** *** 137,142 **** --- 184,201 ---- pfnModifyWorldTransform=(ModifyWorldTransformfunc)GetProcAddress(hmodule,"ModifyWorldTransform"); pfnCombineTransform=(CombineTransformfunc)GetProcAddress(hmodule,"CombineTransform"); + pfnMaskBlt=(MaskBltfunc)GetProcAddress(hmodule,"MaskBlt"); + pfnGetLayout=(GetLayoutfunc)GetProcAddress(hmodule,"GetLayout"); + pfnSetLayout=(SetLayoutfunc)GetProcAddress(hmodule,"SetLayout"); + } + hmodule=GetModuleHandle("msimg32.dll"); + if (hmodule==NULL) + hmodule=LoadLibrary("msimg32.dll"); + if (hmodule){ + pfnGradientFill=(GradientFillfunc)GetProcAddress(hmodule,"GradientFill"); + pfnTransparentBlt=(TransparentBltfunc)GetProcAddress(hmodule,"TransparentBlt"); + pfnAlphaBlend=(AlphaBlendfunc)GetProcAddress(hmodule,"AlphaBlend"); + } %} *************** *** 366,378 **** %typemap(python,in) POINT *INPUT { ! POINT r; ! if (PyTuple_Check($source)) { ! if (PyArg_ParseTuple($source, "ll", &r.x, &r.y) == 0) { ! return PyErr_Format(PyExc_TypeError, "%s: a POINT must be a tuple of integers", "$name"); ! } ! $target = &r; ! } else { ! return PyErr_Format(PyExc_TypeError, "%s: a POINT must be a tuple of integers", "$name"); ! } } --- 425,432 ---- %typemap(python,in) POINT *INPUT { ! POINT pt; ! if (!PyWinObject_AsPOINT($source, &pt)) ! return NULL; ! $target = &pt; } *************** *** 381,394 **** %typemap(python,argout) POINT *BOTH = POINT *OUTPUT; ! %typemap(python,in) SIZE *INPUT { SIZE s; ! if (PyTuple_Check($source)) { ! if (PyArg_ParseTuple($source, "ll", &s.cx, &s.cy) == 0) { ! return PyErr_Format(PyExc_TypeError, "%s: a SIZE must be a tuple of integers", "$name"); ! } ! $target = &s; ! } else { ! return PyErr_Format(PyExc_TypeError, "%s: a SIZE must be a tuple of integers", "$name"); ! } } --- 435,443 ---- %typemap(python,argout) POINT *BOTH = POINT *OUTPUT; ! %typemap(python,in) SIZE *INPUT{ SIZE s; ! if (!PyWinObject_AsSIZE($source, &s)) ! return NULL; ! $target = &s; } *************** *** 434,447 **** %typemap(python,in) BLENDFUNCTION *INPUT { BLENDFUNCTION bf; ! if (PyTuple_Check($source)) { ! if (PyArg_ParseTuple($source, "bbbb:" "$name" " tuple", ! &bf.BlendOp, &bf.BlendFlags, ! &bf.SourceConstantAlpha, &bf.AlphaFormat) == 0) { ! return NULL; ! } ! $target = &bf; ! } else { ! return PyErr_Format(PyExc_TypeError, "%s: This param must be a tuple of four integers", "$name"); ! } } --- 483,489 ---- %typemap(python,in) BLENDFUNCTION *INPUT { BLENDFUNCTION bf; ! if (!PyWinObject_AsBLENDFUNCTION($source, &bf)) ! return NULL; ! $target = &bf; } *************** *** 1172,1179 **** { PyObject *obFamily; ! PyObject *obProc; PyObject *obExtra = Py_None; ! long hdc; ! // @pyparm int|hdc||Handle to a device context for which to enumerate available fonts // @pyparm string/<o PyUnicode>|Family||Family of fonts to enumerate. If none, first member of each font family will be returned. // @pyparm function|EnumFontFamProc||The Python function called with each font family. This function is called with 4 arguments. --- 1214,1221 ---- { PyObject *obFamily; ! PyObject *obProc, *obdc; PyObject *obExtra = Py_None; ! HDC hdc; ! // @pyparm <o PyHANDLE>|hdc||Handle to a device context for which to enumerate available fonts // @pyparm string/<o PyUnicode>|Family||Family of fonts to enumerate. If none, first member of each font family will be returned. // @pyparm function|EnumFontFamProc||The Python function called with each font family. This function is called with 4 arguments. *************** *** 1185,1189 **** // object - The Param originally passed in to EnumFontFamilies ! if (!PyArg_ParseTuple(args, "lOO|O", &hdc, &obFamily, &obProc, &obExtra)) return NULL; if (!PyCallable_Check(obProc)) { --- 1227,1233 ---- // object - The Param originally passed in to EnumFontFamilies ! if (!PyArg_ParseTuple(args, "OOO|O", &obdc, &obFamily, &obProc, &obExtra)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obdc, (HANDLE *)&hdc, FALSE)) return NULL; if (!PyCallable_Check(obProc)) { *************** *** 1195,1199 **** return NULL; PyObject *lparam = Py_BuildValue("OO", obProc, obExtra); ! int rc = EnumFontFamilies((HDC)hdc, szFamily, EnumFontFamProc, (LPARAM)lparam); Py_XDECREF(lparam); PyWinObject_FreeTCHAR(szFamily); --- 1239,1243 ---- return NULL; PyObject *lparam = Py_BuildValue("OO", obProc, obExtra); ! int rc = EnumFontFamilies(hdc, szFamily, EnumFontFamProc, (LPARAM)lparam); Py_XDECREF(lparam); PyWinObject_FreeTCHAR(szFamily); *************** *** 1243,1254 **** %{ ! // @pyswig object|GetObject| static PyObject *PyGetObject(PyObject *self, PyObject *args) { ! long hob; ! // @pyparm int|handle||Handle to the object. ! if (!PyArg_ParseTuple(args, "l", &hob)) return NULL; ! DWORD typ = GetObjectType((HGDIOBJ)hob); // @comm The result depends on the type of the handle. // For example, if the handle identifies a Font, a <o LOGFONT> object --- 1287,1301 ---- %{ ! // @pyswig object|GetObject|Returns a struct containing the parameters used to create a GDI object static PyObject *PyGetObject(PyObject *self, PyObject *args) { ! HGDIOBJ hob; ! PyObject *ob; ! // @pyparm <o PyHANDLE>|handle||Handle to the object. ! if (!PyArg_ParseTuple(args, "O", &ob)) return NULL; ! if (!PyWinObject_AsHANDLE(ob, &hob, FALSE)) ! return NULL; ! DWORD typ = GetObjectType(hob); // @comm The result depends on the type of the handle. // For example, if the handle identifies a Font, a <o LOGFONT> object *************** *** 1257,1261 **** case OBJ_FONT: { LOGFONT lf; ! if (GetObject((HGDIOBJ)hob, sizeof(LOGFONT), &lf)==0) return PyWin_SetAPIError("GetObject"); return new PyLOGFONT(&lf); --- 1304,1308 ---- case OBJ_FONT: { LOGFONT lf; ! if (GetObject(hob, sizeof(LOGFONT), &lf)==0) return PyWin_SetAPIError("GetObject"); return new PyLOGFONT(&lf); *************** *** 1263,1267 **** case OBJ_BITMAP: { BITMAP bm; ! if (GetObject((HGDIOBJ)hob, sizeof(BITMAP), &bm)==0) return PyWin_SetAPIError("GetObject"); return new PyBITMAP(&bm); --- 1310,1314 ---- case OBJ_BITMAP: { BITMAP bm; ! if (GetObject(hob, sizeof(BITMAP), &bm)==0) return PyWin_SetAPIError("GetObject"); return new PyBITMAP(&bm); *************** *** 1281,1286 **** HANDLE h; DWORD t; ! // @pyparm int|h||A handle to a GDI object ! if (!PyArg_ParseTuple(args, "l:GetObjectType", &h)) return NULL; t=GetObjectType(h); --- 1328,1336 ---- HANDLE h; DWORD t; ! PyObject *ob; ! // @pyparm <o PyHANDLE>|h||A handle to a GDI object ! if (!PyArg_ParseTuple(args, "O:GetObjectType", &ob)) ! return NULL; ! if (!PyWinObject_AsHANDLE(ob, &h, FALSE)) return NULL; t=GetObjectType(h); *************** *** 1531,1551 **** #ifndef MS_WINCE // @pyswig int|FlashWindow|The FlashWindow function flashes the specified window one time. It does not change the active state of the window. ! // @pyparm int|hwnd|| ! // @pyparm int|bInvert|| BOOL FlashWindow(HWND hwnd, BOOL bInvert); - // @pyswig int|FlashWindowEx|The FlashWindowEx function flashes the specified window a specified number of times. %{ PyObject *PyFlashWindowEx(PyObject *self, PyObject *args) { ! PyObject *ret; BOOL rc; FLASHWINFO f; f.cbSize = sizeof f; ! // @pyparm int|hwnd|| ! // @pyparm int|dwFlags|| ! // @pyparm int|uCount|| ! // @pyparm int|dwTimeout|| ! if (!PyArg_ParseTuple(args, "iiii", &f.hwnd, &f.dwFlags, &f.uCount, &f.dwTimeout)) return NULL; // not on NT --- 1581,1603 ---- #ifndef MS_WINCE // @pyswig int|FlashWindow|The FlashWindow function flashes the specified window one time. It does not change the active state of the window. ! // @pyparm <o PyHANDLE>|hwnd||Handle to a window ! // @pyparm int|bInvert||Indicates if window should toggle between active and inactive BOOL FlashWindow(HWND hwnd, BOOL bInvert); + // @pyswig int|FlashWindowEx|The FlashWindowEx function flashes the specified window a specified number of times. %{ PyObject *PyFlashWindowEx(PyObject *self, PyObject *args) { ! PyObject *ret, *obhwnd; BOOL rc; FLASHWINFO f; f.cbSize = sizeof f; ! // @pyparm <o PyHANDLE>|hwnd||Handle to a window ! // @pyparm int|dwFlags||Combination of win32con.FLASHW_* flags ! // @pyparm int|uCount||Nbr of times to flash ! // @pyparm int|dwTimeout||Elapsed time between flashes, in milliseconds ! if (!PyArg_ParseTuple(args, "Oiii", &obhwnd, &f.dwFlags, &f.uCount, &f.dwTimeout)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&f.hwnd, FALSE)) return NULL; // not on NT *************** *** 1568,1599 **** #endif // MS_WINCE - // To avoid LoadLibrary etc (ie, keep my life simple) for functions - // that don't exist on NT, only put them in winxpgui. - %ifdef WINXPGUI - - // @pyswig |AnimateWindow|Enables you to produce special effects when showing or hiding windows. There are three types of animation: roll, slide, and alpha-blended fade. - // @comm To avoid complications with Windows NT, this function only exists in winxpgui (not win32gui) - BOOLAPI AnimateWindow( - HWND hwnd, // @pyparm int|hwnd||handle to window - DWORD dwTime, // @pyparm int|dwTime||duration of animation - DWORD dwFlags // @pyparm int|dwFlags||animation type - ); - - // @pyswig |UpdateLayeredWindow|Updates the position, size, shape, content, and translucency of a layered window. - // @comm To avoid complications with Windows NT, this function only exists in winxpgui (not win32gui) - BOOLAPI UpdateLayeredWindow( - HWND hwnd, // @pyparm int|hwnd||handle to layered window - HDC hdcDst, // @pyparm int|hdcDst||handle to screen DC - POINT *INPUT, // @pyparm (x,y)|pointDest||new screen position - SIZE *INPUT, // @pyparm (cx, cy)|size||new size of the layered window - HDC hdcSrc, // @pyparm int|hdcSrc||handle to surface DC - POINT *INPUT, // @pyparm (x,y)|pointSrc||layer position - COLORREF crKey, // @pyparm int|colorKey||color key - BLENDFUNCTION *INPUT, // @pyparm (int, int, int, int)|blend||blend function - DWORD dwFlags // @pyparm int|flags||options - ); - - %endif // End of winxpgui only functions - // @pyswig int|GetWindowLong| --- 1620,1623 ---- *************** *** 1613,1622 **** HWND hwnd; int index; ! PyObject *ob; long l; // @pyparm int|hwnd||The handle to the window // @pyparm int|index||The index of the item to set. // @pyparm object|value||The value to set. ! if (!PyArg_ParseTuple(args, "liO", &hwnd, &index, &ob)) return NULL; switch (index) { --- 1637,1648 ---- HWND hwnd; int index; ! PyObject *ob, *obhwnd; long l; // @pyparm int|hwnd||The handle to the window // @pyparm int|index||The index of the item to set. // @pyparm object|value||The value to set. ! if (!PyArg_ParseTuple(args, "OiO", &obhwnd, &index, &ob)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd, FALSE)) return NULL; switch (index) { *************** *** 2460,2483 **** #endif /* not MS_WINCE */ ! %ifdef WINXPGUI // @pyswig |MaskBlt|Combines the color data for the source and destination // bitmaps using the specified mask and raster operation. ! // @comm This function is available only in winxpgui, as it is not supported ! // on Win9x. ! BOOLAPI MaskBlt( ! HDC hdcDest, // handle to destination DC ! int nXDest, // x-coord of destination upper-left corner ! int nYDest, // y-coord of destination upper-left corner ! int nWidth, // width of source and destination ! int nHeight, // height of source and destination ! HDC hdcSrc, // handle to source DC ! int nXSrc, // x-coord of upper-left corner of source ! int nYSrc, // y-coord of upper-left corner of source ! HBITMAP hbmMask, // handle to monochrome bit mask ! int xMask, // horizontal offset into mask bitmap ! int yMask, // vertical offset into mask bitmap ! DWORD dwRop // raster operation code ! ); ! %endif // @pyswig int|ImageList_Add|Adds an image or images to an image list. --- 2486,2612 ---- #endif /* not MS_WINCE */ ! %{ ! // @pyswig |TransparentBlt|Transfers color from one DC to another, with one color treated as transparent ! static PyObject *PyTransparentBlt(PyObject *self, PyObject *args) ! { ! CHECK_PFN(TransparentBlt); ! PyObject *obsrc, *obdst; ! HDC src, dst; ! int src_x, src_y, src_width, src_height; ! int dst_x, dst_y, dst_width, dst_height; ! UINT transparent; ! BOOL ret; ! if (!PyArg_ParseTuple(args,"OiiiiOiiiiI:TransparentBlt", ! &obdst, // @pyparm <o PyHANDLE>|Dest||Destination device context handle ! &dst_x, // @pyparm int|XOriginDest||X pos of dest rect ! &dst_y, // @pyparm int|YOriginDest||Y pos of dest rect ! &dst_width, // @pyparm int|WidthDest||Width of dest rect ! &dst_height, // @pyparm int|HeightDest||Height of dest rect ! &obsrc, // @pyparm <o PyHANDLE>|Src||Source DC handle ! &src_x, // @pyparm int|XOriginSrc||X pos of src rect ! &src_y, // @pyparm int|YOriginSrc||Y pos of src rect ! &src_width, // @pyparm int|WidthSrc||Width of src rect ! &src_height, // @pyparm int|HeightSrc||Height of src rect ! &transparent)) // @pyparm int|Transparent||RGB color value that will be transparent ! return NULL; ! if (!PyWinObject_AsHANDLE(obdst, (HANDLE *)&dst, FALSE)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obsrc, (HANDLE *)&src, FALSE)) ! return NULL; ! Py_BEGIN_ALLOW_THREADS ! ret=(*pfnTransparentBlt)( ! dst, dst_x, dst_y, dst_width, dst_height, ! src, src_x, src_y, src_width, src_height, ! transparent); ! Py_END_ALLOW_THREADS ! if (!ret) ! return PyWin_SetAPIError("TransparentBlt"); ! Py_INCREF(Py_None); ! return Py_None; ! } ! // @pyswig |MaskBlt|Combines the color data for the source and destination // bitmaps using the specified mask and raster operation. ! // @comm This function is not supported on Win9x. ! // @pyseeapi MaskBlt ! static PyObject *PyMaskBlt(PyObject *self, PyObject *args) ! { ! CHECK_PFN(MaskBlt); ! PyObject *obsrc, *obdst, *obmask; ! HDC src, dst; ! HBITMAP mask; ! int dst_x, dst_y, dst_width, dst_height; ! int src_x, src_y; ! int mask_x, mask_y; ! DWORD rop; ! if (!PyArg_ParseTuple(args,"OiiiiOiiOiik:MaskBlt", ! &obdst, // @pyparm <o PyHANDLE>|Dest||Destination device context handle ! &dst_x, // @pyparm int|XDest||X pos of dest rect ! &dst_y, // @pyparm int|YDest||Y pos of dest rect ! &dst_width, // @pyparm int|Width||Width of rect to be copied ! &dst_height, // @pyparm int|Height||Height of rect to be copied ! &obsrc, // @pyparm <o PyHANDLE>|Src||Source DC handle ! &src_x, // @pyparm int|XSrc||X pos of src rect ! &src_y, // @pyparm int|YSrc||Y pos of src rect ! &obmask, // @pyparm <o PyHANDLE>|Mask||Handle to monochrome bitmap used to mask color ! &mask_x, // @pyparm int|xMask||X pos in mask ! &mask_y, // @pyparm int|yMask||Y pos in mask ! &rop)) // @pyparm int|Rop||Foreground and background raster operations. See MSDN docs for how to construct this value. ! return NULL; ! if (!PyWinObject_AsHANDLE(obdst, (HANDLE *)&dst, FALSE)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obsrc, (HANDLE *)&src, FALSE)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obmask, (HANDLE *)&mask, FALSE)) ! return NULL; ! if (!(*pfnMaskBlt)( ! dst, dst_x, dst_y, dst_width, dst_height, ! src, src_x, src_y, ! mask, mask_x, mask_y, rop)) ! return PyWin_SetAPIError("MaskBlt"); ! Py_INCREF(Py_None); ! return Py_None; ! } ! ! // @pyswig |AlphaBlend|Transfers color information using alpha blending ! static PyObject *PyAlphaBlend(PyObject *self, PyObject *args) ! { ! CHECK_PFN(AlphaBlend); ! PyObject *obsrc, *obdst, *obbl; ! HDC src, dst; ! int src_x, src_y, src_width, src_height; ! int dst_x, dst_y, dst_width, dst_height; ! BLENDFUNCTION bl; ! if (!PyArg_ParseTuple(args,"OiiiiOiiiiO:AlphaBlend", ! &obdst, // @pyparm <o PyHANDLE>|Dest||Destination device context handle ! &dst_x, // @pyparm int|XOriginDest||X pos of dest rect ! &dst_y, // @pyparm int|YOriginDest||Y pos of dest rect ! &dst_width, // @pyparm int|WidthDest||Width of dest rect ! &dst_height, // @pyparm int|HeightDest||Height of dest rect ! &obsrc, // @pyparm <o PyHANDLE>|Src||Source DC handle ! &src_x, // @pyparm int|XOriginSrc||X pos of src rect ! &src_y, // @pyparm int|YOriginSrc||Y pos of src rect ! &src_width, // @pyparm int|WidthSrc||Width of src rect ! &src_height, // @pyparm int|HeightSrc||Height of src rect ! &obbl)) // @pyparm <o PyBLENDFUNCTION>|blendFunction||Alpha blending parameters ! return NULL; ! if (!PyWinObject_AsHANDLE(obdst, (HANDLE *)&dst, FALSE)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obsrc, (HANDLE *)&src, FALSE)) ! return NULL; ! if (!PyWinObject_AsBLENDFUNCTION(obbl, &bl)) ! return NULL; ! if (!(*pfnAlphaBlend)( ! dst, dst_x, dst_y, dst_width, dst_height, ! src, src_x, src_y, src_width, src_height, ! bl)) ! return PyWin_SetAPIError("AlphaBlend"); ! Py_INCREF(Py_None); ! return Py_None; ! } ! %} ! %native (TransparentBlt) PyTransparentBlt; ! %native (MaskBlt) PyMaskBlt; ! %native (AlphaBlend) PyAlphaBlend; // @pyswig int|ImageList_Add|Adds an image or images to an image list. *************** *** 2734,2737 **** --- 2863,2871 ---- ); + // @pyswig <o PyHANDLE>|GetCurrentObject|Retrieves currently selected object from a DC + HGDIOBJ GetCurrentObject( + HDC hdc, // @pyparm <o PyHANDLE>|hdc||Handle to a device context + UINT ObjectType); // @pyparm int|ObjectType||Type of object to retrieve, one of win32con.OBJ_*; + HINSTANCE GetModuleHandle(TCHAR *INPUT_NULLOK); *************** *** 2767,2772 **** PyGetWindowPlacement(PyObject *self, PyObject *args) { ! int hwnd; ! if (!PyArg_ParseTuple(args, "i:GetWindowPlacement", &hwnd)) return NULL; --- 2901,2909 ---- PyGetWindowPlacement(PyObject *self, PyObject *args) { ! HWND hwnd; ! PyObject *obhwnd; ! if (!PyArg_ParseTuple(args, "O:GetWindowPlacement", &obhwnd)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd)) return NULL; *************** *** 2775,2779 **** BOOL ok; Py_BEGIN_ALLOW_THREADS ! ok = GetWindowPlacement( (HWND)hwnd, &pment ); Py_END_ALLOW_THREADS if (!ok) --- 2912,2916 ---- BOOL ok; Py_BEGIN_ALLOW_THREADS ! ok = GetWindowPlacement(hwnd, &pment ); Py_END_ALLOW_THREADS if (!ok) *************** *** 3384,3387 **** --- 3521,3531 ---- HDC hdc); // @pyparm <o PyHANDLE>|hdc||Handle to a device context + // @pyswig RedrawWindow|Causes a portion of a window to be redrawn + BOOLAPI RedrawWindow( + HWND hWnd, // @pyparm <o PyHANDLE>|hWnd||Handle to window to be redrawn + RECT *INPUT_NULLOK, // @pyparm (int,int,int,int)|rcUpdate||Rectangle (left, top, right, bottom) identifying part of window to be redrawn, can be None + HRGN hrgnUpdate, // @pyparm <o PyHANDLE>|hrgnUpdate||Handle to region to be updated + UINT flags); // @pyparm int|flags||Combination of win32con.RDW_* flags + %{ // @pyswig cx, cy|GetTextExtentPoint32|Computes the width and height of the specified string of text. *************** *** 3613,3616 **** --- 3757,3799 ---- return PyInt_FromLong(prevmode); } + + // @pyswig int|GetLayout|Retrieves the layout mode of a device context + // @rdesc Returns one of win32con.LAYOUT_* + static PyObject *PyGetLayout(PyObject *self, PyObject *args) + { + CHECK_PFN(GetLayout); + HDC hdc; + PyObject *obdc; + DWORD prevlayout; + if (!PyArg_ParseTuple(args, "O:GetLayout", + &obdc)) // @pyparm <o PyHANDLE>|hdc||Handle to a device context + return NULL; + if (!PyWinObject_AsHANDLE(obdc, (HANDLE *)&hdc, FALSE)) + return NULL; + prevlayout=(*pfnGetLayout)(hdc); + if (prevlayout==GDI_ERROR) + return PyWin_SetAPIError("GetLayout"); + return PyLong_FromUnsignedLong(prevlayout); + } + + // @pyswig int|SetLayout|Sets the layout for a device context + // @rdesc Returns the previous layout mode + static PyObject *PySetLayout(PyObject *self, PyObject *args) + { + CHECK_PFN(SetLayout); + HDC hdc; + PyObject *obdc; + DWORD newlayout, prevlayout; + if (!PyArg_ParseTuple(args, "Ok:SetLayout", + &obdc, // @pyparm <o PyHANDLE>|hdc||Handle to a device context + &newlayout)) // @pyparm int|Layout||One of win32con.LAYOUT_* constants + return NULL; + if (!PyWinObject_AsHANDLE(obdc, (HANDLE *)&hdc, FALSE)) + return NULL; + prevlayout=(*pfnSetLayout)(hdc, newlayout); + if (prevlayout==GDI_ERROR) + return PyWin_SetAPIError("SetLayout"); + return PyLong_FromUnsignedLong(prevlayout); + } %} *************** *** 3626,3629 **** --- 3809,3814 ---- %native (GetGraphicsMode) PyGetGraphicsMode; %native (SetGraphicsMode) PySetGraphicsMode; + %native (GetLayout) PyGetLayout; + %native (SetLayout) PySetLayout; %{ *************** *** 3867,3870 **** --- 4052,4221 ---- %native (SetViewportExtEx) PySetViewportExtEx; + %{ + // @object PyTRIVERTEX|Dict representing a TRIVERTEX struct containing color information at a point + // @pyseeapi TRIVERTEX + BOOL PyWinObject_AsTRIVERTEX(PyObject *obtv, TRIVERTEX *ptv) + { + static char *keywords[]={"x","y","Red","Green","Blue","Alpha", NULL}; + if (!PyDict_Check(obtv)){ + PyErr_SetString(PyExc_TypeError,"TRIVERTEX must be a dict"); + return FALSE; + } + PyObject *dummy_tuple=PyTuple_New(0); + if (dummy_tuple==NULL) + return FALSE; + BOOL ret=PyArg_ParseTupleAndKeywords(dummy_tuple, obtv, "llHHHH", keywords, + &ptv->x, // @prop int|x|X coord in logical units + &ptv->y, // @prop int|y|Y coord in logical units + &ptv->Red, // @prop int|Red|Red component + &ptv->Green, // @prop int|Green|Green component + &ptv->Blue, // @prop int|Blue|Blue component + &ptv->Alpha); // @prop int|Alpha|Transparency value + Py_DECREF(dummy_tuple); + return ret; + } + + BOOL PyWinObject_AsTRIVERTEXArray(PyObject *obtvs, TRIVERTEX **ptvs, DWORD *item_cnt) + { + BOOL ret=TRUE; + DWORD bufsize, tuple_index; + PyObject *trivertex_tuple=NULL, *tuple_item; + *ptvs=NULL; + *item_cnt=0; + + if ((trivertex_tuple=PySequence_Tuple(obtvs))==NULL) + return FALSE; + *item_cnt=PyTuple_GET_SIZE(trivertex_tuple); + bufsize=*item_cnt * sizeof(TRIVERTEX); + *ptvs=(TRIVERTEX *)malloc(bufsize); + if (*ptvs==NULL){ + PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", bufsize); + ret=FALSE; + } + else + for (tuple_index=0; tuple_index<*item_cnt; tuple_index++){ + tuple_item=PyTuple_GET_ITEM(trivertex_tuple,tuple_index); + if (!PyWinObject_AsTRIVERTEX(tuple_item, &(*ptvs)[tuple_index])){ + ret=FALSE; + break; + } + } + if (!ret) + if (*ptvs!=NULL){ + free(*ptvs); + *ptvs=NULL; + *item_cnt=0; + } + Py_XDECREF(trivertex_tuple); + return ret; + } + + BOOL PyWinObject_AsMeshArray(PyObject *obmesh, ULONG mode, void **pmesh, DWORD *item_cnt) + { + BOOL ret=TRUE, triangle; + DWORD bufsize, tuple_index; + PyObject *mesh_tuple=NULL, *tuple_item; + *pmesh=NULL; + *item_cnt=0; + + if ((mesh_tuple=PySequence_Tuple(obmesh))==NULL) + return FALSE; + *item_cnt=PyTuple_GET_SIZE(mesh_tuple); + switch (mode){ + case GRADIENT_FILL_TRIANGLE: + bufsize=*item_cnt * sizeof(GRADIENT_TRIANGLE); + triangle=TRUE; + break; + case GRADIENT_FILL_RECT_H: + case GRADIENT_FILL_RECT_V: + bufsize=*item_cnt * sizeof(GRADIENT_RECT); + triangle=FALSE; + break; + default: + PyErr_Format(PyExc_ValueError,"Unrecognized value for gradient fill mode: %d", mode); + return FALSE; + } + + *pmesh=malloc(bufsize); + if (*pmesh==NULL){ + PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", bufsize); + ret=FALSE; + } + else + for (tuple_index=0; tuple_index<*item_cnt; tuple_index++){ + tuple_item=PyTuple_GET_ITEM(mesh_tuple,tuple_index); + if (!PyTuple_Check(tuple_item)){ + PyErr_SetString(PyExc_TypeError,"Mesh elements must be tuples of 2 or 3 ints"); + ret=FALSE; + break; + } + if (triangle){ + if (!PyArg_ParseTuple(tuple_item, "kkk:GRADIENT_TRIANGLE", + &((GRADIENT_TRIANGLE *)(*pmesh))[tuple_index].Vertex1, + &((GRADIENT_TRIANGLE *)(*pmesh))[tuple_index].Vertex2, + &((GRADIENT_TRIANGLE *)(*pmesh))[tuple_index].Vertex3)){ + ret=FALSE; + break; + } + } + else + if (!PyArg_ParseTuple(tuple_item, "kk:GRADIENT_RECT", + &((GRADIENT_RECT *)(*pmesh))[tuple_index].UpperLeft, + &((GRADIENT_RECT *)(*pmesh))[tuple_index].LowerRight)){ + ret=FALSE; + break; + } + } + if (!ret) + if (*pmesh!=NULL){ + free(*pmesh); + *pmesh=NULL; + *item_cnt=0; + } + Py_XDECREF(mesh_tuple); + return ret; + } + + // @pyswig |GradientFill|Shades triangles or rectangles by interpolating between vertex colors + static PyObject *PyGradientFill(PyObject *self, PyObject *args) + { + CHECK_PFN(GradientFill); + HDC hdc; + PTRIVERTEX ptv=NULL; + ULONG tv_cnt, mesh_cnt, mode; + PVOID pmesh=NULL; + BOOL bres; + PyObject *obdc, *obtvs, *obmesh, *ret=NULL; + if (!PyArg_ParseTuple(args, "OOOk:GradientFill", + &obdc, // @pyparm int|hdc||Handle to device context + &obtvs, // @pyparm (<o PyTRIVERTEX>,...)|Vertex||Sequence of TRIVERTEX dicts defining color info + &obmesh, // @pyparm tuple|Mesh||Sequence of tuples containing either 2 or 3 ints that index into the trivertex array to define either triangles or rectangles + &mode)) // @pyparm int|Mode||win32con.GRADIENT_FILL_* value defining whether to fill by triangle or by rectangle + return NULL; + if (!PyWinObject_AsHANDLE(obdc, (HANDLE *)&hdc, FALSE)) + return NULL; + if (!PyWinObject_AsTRIVERTEXArray(obtvs, &ptv, &tv_cnt)) + goto cleanup; + if (!PyWinObject_AsMeshArray(obmesh, mode, &pmesh, &mesh_cnt)) + goto cleanup; + Py_BEGIN_ALLOW_THREADS + bres=(*pfnGradientFill)(hdc, ptv, tv_cnt, pmesh, mesh_cnt, mode); + Py_END_ALLOW_THREADS + if (!bres) + PyWin_SetAPIError("GradientFill"); + else{ + Py_INCREF(Py_None); + ret=Py_None; + } + cleanup: + if (ptv) + free(ptv); + if (pmesh) + free(pmesh); + return ret; + } + %} + %native (GradientFill) PyGradientFill; + // @pyswig int|GetOpenFileName|Creates an Open dialog box that lets the user specify the drive, directory, and the name of a file or set of files to open. *************** *** 6248,6249 **** --- 6599,6700 ---- PyCFunction pfnPyGetLayeredWindowAttributes=(PyCFunction)PyGetLayeredWindowAttributes; %} + + // @pyswig |UpdateLayeredWindow|Updates the position, size, shape, content, and translucency of a layered window. + // @comm This function is only available on Windows 2000 and later + // @comm Accepts keyword arguments. + %{ + PyObject *PyUpdateLayeredWindow(PyObject *self, PyObject *args, PyObject *kwargs) + { + CHECK_PFN(UpdateLayeredWindow); + static char *keywords[]={"hwnd","hdcDst","ptDst","size","hdcSrc", + "ptSrc","Key","blend","Flags", NULL}; + HWND hwnd; + HDC hdcDst, hdcSrc; + PyObject *obhwnd, *obsrc=Py_None, *obdst=Py_None; + PyObject *obptSrc=Py_None, *obptDst=Py_None, *obsize=Py_None, *obblend=Py_None; + COLORREF crKey=0; + POINT ptSrc, ptDst; + POINT *pptSrc=NULL, *pptDst=NULL; + SIZE size; + SIZE *psize=NULL; + BLENDFUNCTION blend={0,0,255,0}; + DWORD Flags=0; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OOOOOkOk:UpdateLayeredWindow", keywords, + &obhwnd, // @pyparm <o PyHANDLE>|hwnd||handle to layered window + &obdst, // @pyparm <o PyHANDLE>|hdcDst|None|handle to screen DC, can be None. *Must* be None if hdcSrc is None + &obptDst, // @pyparm (x,y)|ptDst|None|New screen position, can be None. + &obsize, // @pyparm (cx, cy)|size|None|New size of the layered window, can be None. *Must* be None if hdcSrc is None. + &obsrc, // @pyparm int|hdcSrc|None|handle to surface DC for the window, can be None + &obptSrc, // @pyparm (x,y)|ptSrc|None|layer position, can be None. *Must* be None if hdcSrc is None. + &crKey, // @pyparm int|Key|0|Color key, generate using <om win32api.RGB> + &obblend, // @pyparm (int, int, int, int)|blend|(0,0,255,0)|<o PyBLENDFUNCTION> specifying alpha blending parameters + &Flags)) // @pyparm int|Flags|0|One of the win32con.ULW_* values. Use 0 if hdcSrc is None. + return NULL; + if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd, FALSE)) + return NULL; + if (!PyWinObject_AsHANDLE(obdst, (HANDLE *)&hdcDst, TRUE)) + return NULL; + if (!PyWinObject_AsHANDLE(obsrc, (HANDLE *)&hdcSrc, TRUE)) + return NULL; + if (obblend!=Py_None) + if (!PyWinObject_AsBLENDFUNCTION(obblend, &blend)) + return NULL; + if (obptDst!=Py_None){ + if (!PyWinObject_AsPOINT(obptDst, &ptDst)) + return NULL; + pptDst=&ptDst; + } + if (obsize!=Py_None){ + if (!PyWinObject_AsSIZE(obsize, &size)) + return NULL; + psize=&size; + } + if (obptSrc!=Py_None){ + if (!PyWinObject_AsPOINT(obptSrc, &ptSrc)) + return NULL; + pptSrc=&ptSrc; + } + + BOOL ret; + Py_BEGIN_ALLOW_THREADS + ret=(*pfnUpdateLayeredWindow)(hwnd, hdcDst, pptDst, psize, hdcSrc, pptSrc, crKey, &blend, Flags); + Py_END_ALLOW_THREADS + if (!ret) + return PyWin_SetAPIError("UpdateLayeredWindow"); + Py_INCREF(Py_None); + return Py_None; + } + PyCFunction pfnPyUpdateLayeredWindow=(PyCFunction)PyUpdateLayeredWindow; + %} + %native (UpdateLayeredWindow) pfnPyUpdateLayeredWindow; + + %{ + // @pyswig |AnimateWindow|Enables you to produce special effects when showing or hiding windows. There are three types of animation: roll, slide, and alpha-blended fade. + // @comm This function is available on Win2k and later + // @comm Accepts keyword args + PyObject *PyAnimateWindow(PyObject *self, PyObject *args, PyObject *kwargs) + { + CHECK_PFN(AnimateWindow); + static char *keywords[]={"hwnd","Time","Flags", NULL}; + PyObject *obhwnd; + HWND hwnd; + DWORD duration, flags; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Okk", keywords, + &obhwnd, // @pyparm <o PyHANDLE>|hwnd||handle to window + &duration, // @pyparm int|Time||Duration of animation in ms + &flags)) // @pyparm int|Flags||Animation type, combination of win32con.AW_* flags + return NULL; + if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd, FALSE)) + return NULL; + BOOL ret; + Py_BEGIN_ALLOW_THREADS + ret=(*pfnAnimateWindow)(hwnd, duration, flags); + Py_END_ALLOW_THREADS + if (!ret) + return PyWin_SetAPIError("AnimateWindow"); + Py_INCREF(Py_None); + return Py_None; + } + PyCFunction pfnPyAnimateWindow=(PyCFunction)PyAnimateWindow; + %} + %native (AnimateWindow) pfnPyAnimateWindow; |