Update of /cvsroot/pywin32/pywin32/Pythonwin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32754
Modified Files:
Tag: py3k
win32ctrlList.cpp win32ctrlTree.cpp win32ui.h win32util.cpp
win32view.cpp
Log Message:
Free text in LV_COLUMN
Autoduck fixes for TV_ITEM, LV_ITEM, LV_COLUMN
Index: win32ui.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/win32ui.h,v
retrieving revision 1.7.2.2
retrieving revision 1.7.2.3
diff -C2 -d -r1.7.2.2 -r1.7.2.3
*** win32ui.h 2 Sep 2008 02:14:43 -0000 1.7.2.2
--- win32ui.h 4 Sep 2008 02:27:19 -0000 1.7.2.3
***************
*** 357,362 ****
PYW_EXPORT void PyWinObject_FreeLV_ITEM(LV_ITEM *pItem);
! PYW_EXPORT PyObject *MakeLV_COLUMNTuple(LV_COLUMN *item);
! PYW_EXPORT BOOL ParseLV_COLUMNTuple( PyObject *args, LV_COLUMN *pItem);
PYW_EXPORT BOOL PyWinObject_AsTV_ITEM( PyObject *args, TV_ITEM *pItem);
--- 357,363 ----
PYW_EXPORT void PyWinObject_FreeLV_ITEM(LV_ITEM *pItem);
! PYW_EXPORT PyObject *PyWinObject_FromLV_COLUMN(LV_COLUMN *pCol);
! PYW_EXPORT BOOL PyWinObject_AsLV_COLUMN( PyObject *args, LV_COLUMN *pCol);
! PYW_EXPORT void PyWinObject_FreeLV_COLUMN(LV_COLUMN *pCol);
PYW_EXPORT BOOL PyWinObject_AsTV_ITEM( PyObject *args, TV_ITEM *pItem);
Index: win32util.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/win32util.cpp,v
retrieving revision 1.13.2.2
retrieving revision 1.13.2.3
diff -C2 -d -r1.13.2.2 -r1.13.2.3
*** win32util.cpp 2 Sep 2008 02:14:43 -0000 1.13.2.2
--- win32util.cpp 4 Sep 2008 02:27:19 -0000 1.13.2.3
***************
*** 448,475 ****
//
// LV_COLUMN
! PyObject *MakeLV_COLUMNTuple(LV_COLUMN *item)
{
PyObject *ret = PyTuple_New(4);
if (ret==NULL) return NULL;
! if (item->mask & LVCF_FMT) {
! PyTuple_SET_ITEM(ret, 0, PyInt_FromLong(item->fmt));
} else {
Py_INCREF(Py_None);
PyTuple_SET_ITEM(ret, 0, Py_None);
}
! if (item->mask & LVCF_WIDTH) {
! PyTuple_SET_ITEM(ret, 1, PyInt_FromLong(item->cx));
} else {
Py_INCREF(Py_None);
PyTuple_SET_ITEM(ret, 1, Py_None);
}
! if ((item->mask & LVCF_TEXT) && (item->pszText != NULL)) {
! PyTuple_SET_ITEM(ret, 2, PyWinObject_FromTCHAR(item->pszText));
} else {
Py_INCREF(Py_None);
PyTuple_SET_ITEM(ret, 2, Py_None);
}
! if (item->mask & LVCF_SUBITEM) {
! PyTuple_SET_ITEM(ret, 3, PyInt_FromLong(item->iSubItem));
} else {
Py_INCREF(Py_None);
--- 448,475 ----
//
// LV_COLUMN
! PyObject *PyWinObject_FromLV_COLUMN(LV_COLUMN *pCol)
{
PyObject *ret = PyTuple_New(4);
if (ret==NULL) return NULL;
! if (pCol->mask & LVCF_FMT) {
! PyTuple_SET_ITEM(ret, 0, PyInt_FromLong(pCol->fmt));
} else {
Py_INCREF(Py_None);
PyTuple_SET_ITEM(ret, 0, Py_None);
}
! if (pCol->mask & LVCF_WIDTH) {
! PyTuple_SET_ITEM(ret, 1, PyInt_FromLong(pCol->cx));
} else {
Py_INCREF(Py_None);
PyTuple_SET_ITEM(ret, 1, Py_None);
}
! if ((pCol->mask & LVCF_TEXT) && (pCol->pszText != NULL)) {
! PyTuple_SET_ITEM(ret, 2, PyWinObject_FromTCHAR(pCol->pszText));
} else {
Py_INCREF(Py_None);
PyTuple_SET_ITEM(ret, 2, Py_None);
}
! if (pCol->mask & LVCF_SUBITEM) {
! PyTuple_SET_ITEM(ret, 3, PyInt_FromLong(pCol->iSubItem));
} else {
Py_INCREF(Py_None);
***************
*** 478,481 ****
--- 478,487 ----
return ret;
}
+
+ void PyWinObject_FreeLV_COLUMN(LV_COLUMN *pCol){
+ if (pCol->mask & LVCF_TEXT)
+ PyWinObject_FreeTCHAR(pCol->pszText);
+ }
+
// @object LV_COLUMN|A tuple that describes a Win32 LV_COLUMN tuple. Used by the <o PyCListCtrl> object.
// A tuple of 4 items, being fmt, cx, pszText, iSubItem
***************
*** 486,537 ****
// <nl>When passed to Python, will always be a tuple of size 4, and items may be None if not available.
// <nl>When passed from Python, the tuple may be any length up to 4, and any item may be None.
! BOOL ParseLV_COLUMNTuple( PyObject *args, LV_COLUMN *pItem)
{
PyObject *ob;
! pItem->mask = 0;
! Py_ssize_t len = PyTuple_Size(args);
if (len > 4) {
! PyErr_SetString(PyExc_TypeError, "LV_COLUMN tuple has invalid size");
return FALSE;
! }
! assert (!PyErr_Occurred()); // PyErr_Clear(); // clear any errors, so I can detect my own.
// 0 - fmt
if (len<1) return TRUE;
! if ((ob=PyTuple_GetItem(args, 0))==NULL)
! return FALSE;
if (ob != Py_None) {
! pItem->fmt = (int)PyInt_AsLong(ob);
! if (pItem->fmt==-1 && PyErr_Occurred()) return FALSE;
! pItem->mask |= LVCF_FMT;
}
// 1 - cx
if (len<2) return TRUE;
! if ((ob=PyTuple_GetItem(args, 1))==NULL)
! return FALSE;
if (ob != Py_None) {
! pItem->cx = (int)PyInt_AsLong(ob);
! if (pItem->cx==-1 && PyErr_Occurred()) return FALSE;
! pItem->mask |= LVCF_WIDTH;
}
// 2 - text
if (len<3) return TRUE;
-
ob=PyTuple_GET_ITEM(args, 2);
! if (!PyWinObject_AsTCHAR(ob, &pItem->pszText, TRUE, (DWORD *)&pItem->cchTextMax))
return FALSE;
! // ??? Need to free this somewhere ???
! if (pItem->pszText)
! pItem->mask |= LVCF_TEXT;
// 3 - subitem
if (len<4) return TRUE;
! if ((ob=PyTuple_GetItem(args, 3))==NULL)
! return FALSE;
if (ob != Py_None) {
! pItem->mask |= LVCF_SUBITEM;
! pItem->iSubItem = PyInt_AsLong(ob);
! if (pItem->iSubItem==-1 && PyErr_Occurred())
return FALSE;
! }
return TRUE;
}
--- 492,546 ----
// <nl>When passed to Python, will always be a tuple of size 4, and items may be None if not available.
// <nl>When passed from Python, the tuple may be any length up to 4, and any item may be None.
! BOOL PyWinObject_AsLV_COLUMN( PyObject *args, LV_COLUMN *pCol)
{
+ ZeroMemory(pCol, sizeof(*pCol));
+ if (!PyTuple_Check(args)){
+ PyErr_SetString(PyExc_TypeError, "LV_COLUMN must be a tuple");
+ return FALSE;
+ }
PyObject *ob;
! Py_ssize_t len = PyTuple_GET_SIZE(args);
if (len > 4) {
! PyErr_SetString(PyExc_TypeError, "LV_COLUMN can contain at most 4 items");
return FALSE;
! }
!
// 0 - fmt
if (len<1) return TRUE;
! ob=PyTuple_GET_ITEM(args, 0);
if (ob != Py_None) {
! pCol->fmt = PyInt_AsLong(ob);
! if (pCol->fmt==-1 && PyErr_Occurred()) return FALSE;
! pCol->mask |= LVCF_FMT;
}
+
// 1 - cx
if (len<2) return TRUE;
! ob=PyTuple_GET_ITEM(args, 1);
if (ob != Py_None) {
! pCol->cx = PyInt_AsLong(ob);
! if (pCol->cx==-1 && PyErr_Occurred()) return FALSE;
! pCol->mask |= LVCF_WIDTH;
}
+
// 2 - text
if (len<3) return TRUE;
ob=PyTuple_GET_ITEM(args, 2);
! if (!PyWinObject_AsTCHAR(ob, &pCol->pszText, TRUE, (DWORD *)&pCol->cchTextMax))
return FALSE;
! if (pCol->pszText)
! pCol->mask |= LVCF_TEXT;
// 3 - subitem
if (len<4) return TRUE;
! ob=PyTuple_GET_ITEM(args, 3);
if (ob != Py_None) {
! pCol->iSubItem = PyInt_AsLong(ob);
! if (pCol->iSubItem==-1 && PyErr_Occurred()){
! PyWinObject_FreeLV_COLUMN(pCol);
return FALSE;
! }
! pCol->mask |= LVCF_SUBITEM;
! }
return TRUE;
}
Index: win32view.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/win32view.cpp,v
retrieving revision 1.4.2.1
retrieving revision 1.4.2.2
diff -C2 -d -r1.4.2.1 -r1.4.2.2
*** win32view.cpp 29 Aug 2008 05:53:30 -0000 1.4.2.1
--- win32view.cpp 4 Sep 2008 02:27:19 -0000 1.4.2.2
***************
*** 1020,1024 ****
PyCCtrlView_Type PyCListView::type("PyCListView",
&PyCCtrlView::type, // @base PyCListView|PyCCtrlView
! &PyCListCtrl::type, // ??? need to add this to tp_bases so PyCListView inherits PyCListCtrl methods ???
RUNTIME_CLASS(CListView),
sizeof(PyCListView),
--- 1020,1024 ----
PyCCtrlView_Type PyCListView::type("PyCListView",
&PyCCtrlView::type, // @base PyCListView|PyCCtrlView
! &PyCListCtrl::type,
RUNTIME_CLASS(CListView),
sizeof(PyCListView),
Index: win32ctrlList.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/win32ctrlList.cpp,v
retrieving revision 1.3.2.2
retrieving revision 1.3.2.3
diff -C2 -d -r1.3.2.2 -r1.3.2.3
*** win32ctrlList.cpp 2 Sep 2008 02:14:43 -0000 1.3.2.2
--- win32ctrlList.cpp 4 Sep 2008 02:27:19 -0000 1.3.2.3
***************
*** 228,239 ****
if (!PyArg_ParseTuple(args, "iO:InsertColumn",
&iColNo, // @pyparm int|colNo||The new column number
! &obLVCol)) // @pyparm <om PyCListCtrl.LV_COLUMN tuple>|item||A tuple describing the new column.
return NULL;
LV_COLUMN lvCol;
! if (!ParseLV_COLUMNTuple(obLVCol, &lvCol))
return NULL;
GUI_BGN_SAVE;
int ret = pList->InsertColumn(iColNo, &lvCol);
GUI_END_SAVE;
if (ret==-1)
RETURN_ERR("InsertColumn failed");
--- 228,240 ----
if (!PyArg_ParseTuple(args, "iO:InsertColumn",
&iColNo, // @pyparm int|colNo||The new column number
! &obLVCol)) // @pyparm <o LV_COLUMN>|item||A tuple describing the new column.
return NULL;
LV_COLUMN lvCol;
! if (!PyWinObject_AsLV_COLUMN(obLVCol, &lvCol))
return NULL;
GUI_BGN_SAVE;
int ret = pList->InsertColumn(iColNo, &lvCol);
GUI_END_SAVE;
+ PyWinObject_FreeLV_COLUMN(&lvCol);
if (ret==-1)
RETURN_ERR("InsertColumn failed");
***************
*** 253,267 ****
if (!PyArg_ParseTuple(args, "iO:InsertColumn",
&iColNo, // @pyparm int|colNo||The to be modified column number
! &obLVCol)) // @pyparm <om PyCListCtrl.LV_COLUMN tuple>|item||A tuple describing the modified column.
return NULL;
LV_COLUMN lvCol;
! if (!ParseLV_COLUMNTuple(obLVCol, &lvCol))
return NULL;
GUI_BGN_SAVE;
int ret = pList->SetColumn(iColNo, &lvCol);
GUI_END_SAVE;
if (ret==-1)
RETURN_ERR("SetColumn failed");
! return Py_BuildValue("i",ret);
}
--- 254,269 ----
if (!PyArg_ParseTuple(args, "iO:InsertColumn",
&iColNo, // @pyparm int|colNo||The to be modified column number
! &obLVCol)) // @pyparm <o LV_COLUMN>|item||A tuple describing the modified column.
return NULL;
LV_COLUMN lvCol;
! if (!PyWinObject_AsLV_COLUMN(obLVCol, &lvCol))
return NULL;
GUI_BGN_SAVE;
int ret = pList->SetColumn(iColNo, &lvCol);
GUI_END_SAVE;
+ PyWinObject_FreeLV_COLUMN(&lvCol);
if (ret==-1)
RETURN_ERR("SetColumn failed");
! return PyInt_FromLong(ret);
}
***************
*** 299,303 ****
PyErr_Clear();
if (PyArg_ParseTuple(args, "O:InsertItem",
! &obLVItem)) { // @pyparm <om PyCListCtrl.LV_ITEM tuple>|item||A tuple describing the new item.
LV_ITEM lvItem;
if (!PyWinObject_AsLV_ITEM(obLVItem, &lvItem))
--- 301,305 ----
PyErr_Clear();
if (PyArg_ParseTuple(args, "O:InsertItem",
! &obLVItem)) { // @pyparm <o LV_ITEM>|item||A tuple describing the new item.
LV_ITEM lvItem;
if (!PyWinObject_AsLV_ITEM(obLVItem, &lvItem))
***************
*** 316,320 ****
if (ret==-1)
RETURN_ERR("InsertItem failed");
! return Py_BuildValue("i",ret);
}
--- 318,322 ----
if (ret==-1)
RETURN_ERR("InsertItem failed");
! return PyInt_FromLong(ret);
}
***************
*** 327,331 ****
return NULL;
if (!PyArg_ParseTuple(args, "O:SetItem",
! &obLVItem)) // @pyparm <om PyCListCtrl.LV_ITEM tuple>|item||A tuple describing the new item.
return NULL;
LV_ITEM lvItem;
--- 329,333 ----
return NULL;
if (!PyArg_ParseTuple(args, "O:SetItem",
! &obLVItem)) // @pyparm <o LV_ITEM>|item||A tuple describing the new item.
return NULL;
LV_ITEM lvItem;
***************
*** 363,367 ****
}
! // @pymethod <om PyCListCtrl.LV_COLUMN tuple>|PyCListCtrl|GetColumn|Retrieves the details of a column in the control.
PyObject *PyCListCtrl_GetColumn( PyObject *self, PyObject *args )
{
--- 365,369 ----
}
! // @pymethod <o LV_COLUMN>|PyCListCtrl|GetColumn|Retrieves the details of a column in the control.
PyObject *PyCListCtrl_GetColumn( PyObject *self, PyObject *args )
{
***************
*** 382,386 ****
if (!ok)
RETURN_ERR("GetColumn failed");
! return MakeLV_COLUMNTuple(&lvItem);
}
--- 384,388 ----
if (!ok)
RETURN_ERR("GetColumn failed");
! return PyWinObject_FromLV_COLUMN(&lvItem);
}
***************
*** 455,459 ****
}
! // @pymethod <om PyCListCtrl.LV_ITEM tuple>|PyCListCtrl|GetItem|Retrieves the details of an items attributes.
PyObject *PyCListCtrl_GetItem( PyObject *self, PyObject *args )
{
--- 457,461 ----
}
! // @pymethod <o LV_ITEM>|PyCListCtrl|GetItem|Retrieves the details of an items attributes.
PyObject *PyCListCtrl_GetItem( PyObject *self, PyObject *args )
{
Index: win32ctrlTree.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/win32ctrlTree.cpp,v
retrieving revision 1.6.2.2
retrieving revision 1.6.2.3
diff -C2 -d -r1.6.2.2 -r1.6.2.3
*** win32ctrlTree.cpp 2 Sep 2008 02:14:43 -0000 1.6.2.2
--- win32ctrlTree.cpp 4 Sep 2008 02:27:19 -0000 1.6.2.3
***************
*** 482,486 ****
PyWinObject_AsHANDLE, &tvItem.hParent, // @pyparm HTREEITEM|hParent||The parent item. If commctrl.TVI_ROOT or 0, it is added to the root.
PyWinObject_AsHANDLE, &tvItem.hInsertAfter, // @pyparm HTREEITEM|hInsertAfter||The item to insert after. Can be an item or TVI_FIRST, TVI_LAST or TVI_SORT
! &obTVItem)) { // @pyparm <om PyCTreeCtrl.TV_ITEM tuple>|item||A tuple describing the new item.
if (!PyWinObject_AsTV_ITEM(obTVItem, &tvItem.item))
return NULL;
--- 482,486 ----
PyWinObject_AsHANDLE, &tvItem.hParent, // @pyparm HTREEITEM|hParent||The parent item. If commctrl.TVI_ROOT or 0, it is added to the root.
PyWinObject_AsHANDLE, &tvItem.hInsertAfter, // @pyparm HTREEITEM|hInsertAfter||The item to insert after. Can be an item or TVI_FIRST, TVI_LAST or TVI_SORT
! &obTVItem)) { // @pyparm <o TV_ITEM>|item||A tuple describing the new item.
if (!PyWinObject_AsTV_ITEM(obTVItem, &tvItem.item))
return NULL;
***************
*** 511,515 ****
return NULL;
if (!PyArg_ParseTuple(args, "O:SetItem",
! &obTVItem)) // @pyparm <om PyCTreeCtrl.TV_ITEM tuple>|item||A tuple describing the new item.
return NULL;
TV_ITEM tvItem;
--- 511,515 ----
return NULL;
if (!PyArg_ParseTuple(args, "O:SetItem",
! &obTVItem)) // @pyparm <o TV_ITEM>|item||A tuple describing the new item.
return NULL;
TV_ITEM tvItem;
***************
*** 547,551 ****
}
! // @pymethod <om PyCTreeCtrl.TV_ITEM tuple>|PyCTreeCtrl|GetItem|Retrieves the details of an items attributes.
PyObject *PyCTreeCtrl_GetItem( PyObject *self, PyObject *args )
{
--- 547,551 ----
}
! // @pymethod <o TV_ITEM>|PyCTreeCtrl|GetItem|Retrieves the details of an items attributes.
PyObject *PyCTreeCtrl_GetItem( PyObject *self, PyObject *args )
{
|