[Python-checkins] CVS: python/dist/src/Mac/Modules/list listscan.py,1.7,1.8 listsupport.py,1.11,1.12 _Listmodule.c,1.3,1.4
Just van Rossum
jvr@users.sourceforge.net
Mon, 05 Nov 2001 00:27:59 -0800
Update of /cvsroot/python/python/dist/src/Mac/Modules/list
In directory usw-pr-cvs1:/tmp/cvs-serv30675
Modified Files:
listscan.py listsupport.py _Listmodule.c
Log Message:
More List Manager interfacing:
- CreateCustomList(): write LDEF's in Python! (carbon + classic)
- list.LGetCellDataLocation()
(Jack: what's with this _WIN32/pywintoolbox.h stuff?)
Index: listscan.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/list/listscan.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** listscan.py 2001/02/27 13:00:36 1.7
--- listscan.py 2001/11/05 08:27:57 1.8
***************
*** 40,44 ****
"LDispose", # Done by removing the object
"LSearch", # We don't want to handle procs just yet
! "LGetCellDataLocation", # What does this do??
# These have funny argument/return values
--- 40,45 ----
"LDispose", # Done by removing the object
"LSearch", # We don't want to handle procs just yet
! "CreateCustomList", # done manually
! "SetListDefinitionProc",
# These have funny argument/return values
***************
*** 55,62 ****
def makeblacklisttypes(self):
return [
! 'ListDefSpec', # Too difficult for now
! 'ListDefSpec_ptr', # ditto
! "ListDefUPP",
! "ListClickLoopUPP",
]
--- 56,60 ----
def makeblacklisttypes(self):
return [
! "ListClickLoopUPP", # Too difficult for now
]
Index: listsupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/list/listsupport.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** listsupport.py 2001/09/05 10:31:28 1.11
--- listsupport.py 2001/11/05 08:27:57 1.12
***************
*** 27,30 ****
--- 27,33 ----
ListBounds = Rect
ListBounds_ptr = Rect_ptr
+
+ ListDefSpec = ListDefSpec_ptr = OpaqueType("ListDefSpec", "PyMac_BuildListDefSpec", "PyMac_GetListDefSpec")
+
VarOutBufferShortsize = VarHeapOutputBufferType('char', 'short', 's') # (buf, &len)
InBufferShortsize = VarInputBufferType('char', 'short', 's') # (buf, len)
***************
*** 77,85 ****
#define as_List(x) ((ListHandle)x)
#define as_Resource(lh) ((Handle)lh)
"""
initstuff = initstuff + """
! PyMac_INIT_TOOLBOX_OBJECT_NEW(ListHandle, ListObj_New);
! PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ListHandle, ListObj_Convert);
"""
--- 80,126 ----
#define as_List(x) ((ListHandle)x)
#define as_Resource(lh) ((Handle)lh)
+
+ static ListDefUPP myListDefFunctionUPP;
+
+ #if !TARGET_API_MAC_CARBON
+
+ #define kJumpAbs 0x4EF9
+
+ #pragma options align=mac68k
+ typedef struct {
+ short jmpabs; /* 4EF9 */
+ ListDefUPP theUPP; /* 00000000 */
+ } LDEFStub, **LDEFStubHandle;
+ #pragma options align=reset
+
+ static OSErr installLDEFStub(ListHandle list) {
+ LDEFStubHandle stubH;
+
+ stubH = (LDEFStubHandle)NewHandleClear(sizeof(LDEFStub));
+ if (stubH == NULL)
+ return MemError();
+
+ (*stubH)->jmpabs = kJumpAbs;
+ (*stubH)->theUPP = myListDefFunctionUPP;
+ HLock((Handle) stubH);
+
+ (*list)->listDefProc = (Handle)stubH;
+ return noErr;
+ }
+
+ static void removeLDEFStub(ListHandle list) {
+ if ((*list)->listDefProc)
+ DisposeHandle((Handle)(*list)->listDefProc);
+ (*list)->listDefProc = NULL;
+ }
+
+ #endif
"""
initstuff = initstuff + """
! myListDefFunctionUPP = NewListDefUPP((ListDefProcPtr)myListDefFunction);
!
! PyMac_INIT_TOOLBOX_OBJECT_NEW(ListHandle, ListObj_New);
! PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ListHandle, ListObj_Convert);
"""
***************
*** 99,105 ****
/* XXXX Should we HLock() here?? */
if ( strcmp(name, "listFlags") == 0 )
! return Py_BuildValue("l", (long)(*self->ob_itself)->listFlags & 0xff);
if ( strcmp(name, "selFlags") == 0 )
! return Py_BuildValue("l", (long)(*self->ob_itself)->selFlags & 0xff);
}"""
--- 140,146 ----
/* XXXX Should we HLock() here?? */
if ( strcmp(name, "listFlags") == 0 )
! return Py_BuildValue("l", (long)GetListFlags(self->ob_itself) & 0xff);
if ( strcmp(name, "selFlags") == 0 )
! return Py_BuildValue("l", (long)GetListSelectionFlags(self->ob_itself) & 0xff);
}"""
***************
*** 114,123 ****
intval = PyInt_AsLong(value);
if (strcmp(name, "listFlags") == 0 ) {
! /* XXXX Should we HLock the handle here?? */
! (*self->ob_itself)->listFlags = intval;
return 0;
}
if (strcmp(name, "selFlags") == 0 ) {
! (*self->ob_itself)->selFlags = intval;
return 0;
}
--- 155,163 ----
intval = PyInt_AsLong(value);
if (strcmp(name, "listFlags") == 0 ) {
! SetListFlags(self->ob_itself, intval);
return 0;
}
if (strcmp(name, "selFlags") == 0 ) {
! SetListSelectionFlags(self->ob_itself, intval);
return 0;
}
***************
*** 131,134 ****
--- 171,176 ----
def outputStructMembers(self):
ObjectDefinition.outputStructMembers(self)
+ Output("PyObject *ob_ldef_func;")
+ Output("int ob_have_ldef_stub;")
Output("int ob_must_be_disposed;")
***************
*** 141,147 ****
--- 183,198 ----
def outputInitStructMembers(self):
ObjectDefinition.outputInitStructMembers(self)
+ Output("it->ob_ldef_func = NULL;")
+ Output("it->ob_have_ldef_stub = 0;")
Output("it->ob_must_be_disposed = 1;")
+ Output("SetListRefCon(itself, (long)it);")
def outputFreeIt(self, itselfname):
+ Output("Py_XDECREF(self->ob_ldef_func);")
+ Output("self->ob_ldef_func = NULL;")
+ Output("#if !TARGET_API_MAC_CARBON")
+ Output("if (self->ob_have_ldef_stub) removeLDEFStub(self->ob_itself);");
+ Output("#endif");
+ Output("SetListRefCon(self->ob_itself, (long)0);")
Output("if (self->ob_must_be_disposed && %s) LDispose(%s);", itselfname, itselfname)
***************
*** 154,157 ****
--- 205,246 ----
# From here on it's basically all boiler plate...
+ finalstuff = finalstuff + """
+ static void myListDefFunction(SInt16 message,
+ Boolean selected,
+ Rect *cellRect,
+ Cell theCell,
+ SInt16 dataOffset,
+ SInt16 dataLen,
+ ListHandle theList)
+ {
+ PyObject *listDefFunc, *args, *rv=NULL;
+ ListObject *self;
+
+ self = (ListObject*)GetListRefCon(theList);
+ if (self == NULL || self->ob_itself != theList)
+ return; /* nothing we can do */
+ listDefFunc = self->ob_ldef_func;
+ if (listDefFunc == NULL)
+ return; /* nothing we can do */
+ args = Py_BuildValue("hbO&O&hhO", message,
+ selected,
+ PyMac_BuildRect, cellRect,
+ PyMac_BuildPoint, theCell,
+ dataOffset,
+ dataLen,
+ self);
+ if (args != NULL) {
+ rv = PyEval_CallObject(listDefFunc, args);
+ Py_DECREF(args);
+ }
+ if (rv == NULL) {
+ PySys_WriteStderr("error in list definition callback:\\n");
+ PyErr_Print();
+ } else {
+ Py_DECREF(rv);
+ }
+ }
+ """
+
# Create the generator groups and link them
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
***************
*** 187,194 ****
--- 276,360 ----
methods.append(f)
+ # Manual generator for CreateCustomList, due to callback ideosyncracies
+ CreateCustomList_body = """\
+ Rect rView;
+ Rect dataBounds;
+ Point cellSize;
+
+ PyObject *listDefFunc;
+ ListDefSpec theSpec;
+ WindowPtr theWindow;
+ Boolean drawIt;
+ Boolean hasGrow;
+ Boolean scrollHoriz;
+ Boolean scrollVert;
+ ListHandle outList;
+
+ if (!PyArg_ParseTuple(_args, "O&O&O&(iO)O&bbbb",
+ PyMac_GetRect, &rView,
+ PyMac_GetRect, &dataBounds,
+ PyMac_GetPoint, &cellSize,
+ &theSpec.defType, &listDefFunc,
+ WinObj_Convert, &theWindow,
+ &drawIt,
+ &hasGrow,
+ &scrollHoriz,
+ &scrollVert))
+ return NULL;
+
+
+ #if TARGET_API_MAC_CARBON
+ /* Carbon applications use the CreateCustomList API */
+ theSpec.u.userProc = myListDefFunctionUPP;
+ CreateCustomList(&rView,
+ &dataBounds,
+ cellSize,
+ &theSpec,
+ theWindow,
+ drawIt,
+ hasGrow,
+ scrollHoriz,
+ scrollVert,
+ &outList);
+
+ #else
+ /* pre-Carbon applications set the address in the LDEF
+ to a routine descriptor referring to their list
+ definition routine. */
+ outList = LNew(&rView,
+ &dataBounds,
+ cellSize,
+ 0,
+ theWindow,
+ drawIt, /* XXX must be false */
+ hasGrow,
+ scrollHoriz,
+ scrollVert);
+ if (installLDEFStub(outList) != noErr) {
+ PyErr_SetString(PyExc_MemoryError, "can't create LDEF stub");
+ return NULL;
+ }
+ #endif
+
+ _res = ListObj_New(outList);
+ if (_res == NULL)
+ return NULL;
+ Py_INCREF(listDefFunc);
+ ((ListObject*)_res)->ob_ldef_func = listDefFunc;
+ #if !TARGET_API_MAC_CARBON
+ ((ListObject*)_res)->ob_have_ldef_stub = 1;
+ #endif
+ return _res;\
+ """
+
+ f = ManualGenerator("CreateCustomList", CreateCustomList_body);
+ f.docstring = lambda: "(Rect rView, Rect dataBounds, Point cellSize, ListDefSpec theSpec, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle outList)"
+ module.add(f)
+
# add the populated lists to the generator groups
# (in a different wordl the scan program would generate this)
for f in functions: module.add(f)
for f in methods: object.add(f)
+
# generate output (open the output file as late as possible)
Index: _Listmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/list/_Listmodule.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** _Listmodule.c 2001/09/05 10:30:02 1.3
--- _Listmodule.c 2001/11/05 08:27:57 1.4
***************
*** 6,15 ****
- #ifdef _WIN32
- #include "pywintoolbox.h"
- #else
#include "macglue.h"
#include "pymactoolbox.h"
- #endif
/* Macro to test whether a weak-loaded CFM function exists */
--- 6,11 ----
***************
*** 63,66 ****
--- 59,98 ----
#define as_Resource(lh) ((Handle)lh)
+ static ListDefUPP myListDefFunctionUPP;
+
+ #if !TARGET_API_MAC_CARBON
+
+ #define kJumpAbs 0x4EF9
+
+ #pragma options align=mac68k
+ typedef struct {
+ short jmpabs; /* 4EF9 */
+ ListDefUPP theUPP; /* 00000000 */
+ } LDEFStub, **LDEFStubHandle;
+ #pragma options align=reset
+
+ static OSErr installLDEFStub(ListHandle list) {
+ LDEFStubHandle stubH;
+
+ stubH = (LDEFStubHandle)NewHandleClear(sizeof(LDEFStub));
+ if (stubH == NULL)
+ return MemError();
+
+ (*stubH)->jmpabs = kJumpAbs;
+ (*stubH)->theUPP = myListDefFunctionUPP;
+ HLock((Handle) stubH);
+
+ (*list)->listDefProc = (Handle)stubH;
+ return noErr;
+ }
+
+ static void removeLDEFStub(ListHandle list) {
+ if ((*list)->listDefProc)
+ DisposeHandle((Handle)(*list)->listDefProc);
+ (*list)->listDefProc = NULL;
+ }
+
+ #endif
+
static PyObject *List_Error;
***************
*** 74,77 ****
--- 106,111 ----
PyObject_HEAD
ListHandle ob_itself;
+ PyObject *ob_ldef_func;
+ int ob_have_ldef_stub;
int ob_must_be_disposed;
} ListObject;
***************
*** 87,91 ****
--- 121,128 ----
if (it == NULL) return NULL;
it->ob_itself = itself;
+ it->ob_ldef_func = NULL;
+ it->ob_have_ldef_stub = 0;
it->ob_must_be_disposed = 1;
+ SetListRefCon(itself, (long)it);
return (PyObject *)it;
}
***************
*** 103,106 ****
--- 140,149 ----
static void ListObj_dealloc(ListObject *self)
{
+ Py_XDECREF(self->ob_ldef_func);
+ self->ob_ldef_func = NULL;
+ #if !TARGET_API_MAC_CARBON
+ if (self->ob_have_ldef_stub) removeLDEFStub(self->ob_itself);
+ #endif
+ SetListRefCon(self->ob_itself, (long)0);
if (self->ob_must_be_disposed && self->ob_itself) LDispose(self->ob_itself);
PyMem_DEL(self);
***************
*** 477,480 ****
--- 520,542 ----
}
+ static PyObject *ListObj_LGetCellDataLocation(ListObject *_self, PyObject *_args)
+ {
+ PyObject *_res = NULL;
+ short offset;
+ short len;
+ Point theCell;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetPoint, &theCell))
+ return NULL;
+ LGetCellDataLocation(&offset,
+ &len,
+ theCell,
+ _self->ob_itself);
+ _res = Py_BuildValue("hh",
+ offset,
+ len);
+ return _res;
+ }
+
static PyObject *ListObj_as_Resource(ListObject *_self, PyObject *_args)
{
***************
*** 534,537 ****
--- 596,601 ----
{"LDraw", (PyCFunction)ListObj_LDraw, 1,
"(Point theCell) -> None"},
+ {"LGetCellDataLocation", (PyCFunction)ListObj_LGetCellDataLocation, 1,
+ "(Point theCell) -> (short offset, short len)"},
{"as_Resource", (PyCFunction)ListObj_as_Resource, 1,
"() -> (Handle _rv)"},
***************
*** 546,552 ****
/* XXXX Should we HLock() here?? */
if ( strcmp(name, "listFlags") == 0 )
! return Py_BuildValue("l", (long)(*self->ob_itself)->listFlags & 0xff);
if ( strcmp(name, "selFlags") == 0 )
! return Py_BuildValue("l", (long)(*self->ob_itself)->selFlags & 0xff);
}
return Py_FindMethodInChain(&ListObj_chain, (PyObject *)self, name);
--- 610,616 ----
/* XXXX Should we HLock() here?? */
if ( strcmp(name, "listFlags") == 0 )
! return Py_BuildValue("l", (long)GetListFlags(self->ob_itself) & 0xff);
if ( strcmp(name, "selFlags") == 0 )
! return Py_BuildValue("l", (long)GetListSelectionFlags(self->ob_itself) & 0xff);
}
return Py_FindMethodInChain(&ListObj_chain, (PyObject *)self, name);
***************
*** 562,571 ****
intval = PyInt_AsLong(value);
if (strcmp(name, "listFlags") == 0 ) {
! /* XXXX Should we HLock the handle here?? */
! (*self->ob_itself)->listFlags = intval;
return 0;
}
if (strcmp(name, "selFlags") == 0 ) {
! (*self->ob_itself)->selFlags = intval;
return 0;
}
--- 626,634 ----
intval = PyInt_AsLong(value);
if (strcmp(name, "listFlags") == 0 ) {
! SetListFlags(self->ob_itself, intval);
return 0;
}
if (strcmp(name, "selFlags") == 0 ) {
! SetListSelectionFlags(self->ob_itself, intval);
return 0;
}
***************
*** 602,605 ****
--- 665,741 ----
+ static PyObject *List_CreateCustomList(PyObject *_self, PyObject *_args)
+ {
+ PyObject *_res = NULL;
+ Rect rView;
+ Rect dataBounds;
+ Point cellSize;
+
+ PyObject *listDefFunc;
+ ListDefSpec theSpec;
+ WindowPtr theWindow;
+ Boolean drawIt;
+ Boolean hasGrow;
+ Boolean scrollHoriz;
+ Boolean scrollVert;
+ ListHandle outList;
+
+ if (!PyArg_ParseTuple(_args, "O&O&O&(iO)O&bbbb",
+ PyMac_GetRect, &rView,
+ PyMac_GetRect, &dataBounds,
+ PyMac_GetPoint, &cellSize,
+ &theSpec.defType, &listDefFunc,
+ WinObj_Convert, &theWindow,
+ &drawIt,
+ &hasGrow,
+ &scrollHoriz,
+ &scrollVert))
+ return NULL;
+
+
+ #if TARGET_API_MAC_CARBON
+ /* Carbon applications use the CreateCustomList API */
+ theSpec.u.userProc = myListDefFunctionUPP;
+ CreateCustomList(&rView,
+ &dataBounds,
+ cellSize,
+ &theSpec,
+ theWindow,
+ drawIt,
+ hasGrow,
+ scrollHoriz,
+ scrollVert,
+ &outList);
+
+ #else
+ /* pre-Carbon applications set the address in the LDEF
+ to a routine descriptor referring to their list
+ definition routine. */
+ outList = LNew(&rView,
+ &dataBounds,
+ cellSize,
+ 0,
+ theWindow,
+ drawIt, /* XXX must be false */
+ hasGrow,
+ scrollHoriz,
+ scrollVert);
+ if (installLDEFStub(outList) != noErr) {
+ PyErr_SetString(PyExc_MemoryError, "can't create LDEF stub");
+ return NULL;
+ }
+ #endif
+
+ _res = ListObj_New(outList);
+ if (_res == NULL)
+ return NULL;
+ Py_INCREF(listDefFunc);
+ ((ListObject*)_res)->ob_ldef_func = listDefFunc;
+ #if !TARGET_API_MAC_CARBON
+ ((ListObject*)_res)->ob_have_ldef_stub = 1;
+ #endif
+ return _res;
+ }
+
static PyObject *List_LNew(PyObject *_self, PyObject *_args)
{
***************
*** 938,941 ****
--- 1074,1079 ----
static PyMethodDef List_methods[] = {
+ {"CreateCustomList", (PyCFunction)List_CreateCustomList, 1,
+ "(Rect rView, Rect dataBounds, Point cellSize, ListDefSpec theSpec, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle outList)"},
{"LNew", (PyCFunction)List_LNew, 1,
"(Rect rView, Rect dataBounds, Point cSize, short theProc, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle _rv)"},
***************
*** 985,988 ****
--- 1123,1162 ----
+ static void myListDefFunction(SInt16 message,
+ Boolean selected,
+ Rect *cellRect,
+ Cell theCell,
+ SInt16 dataOffset,
+ SInt16 dataLen,
+ ListHandle theList)
+ {
+ PyObject *listDefFunc, *args, *rv=NULL;
+ ListObject *self;
+
+ self = (ListObject*)GetListRefCon(theList);
+ if (self == NULL || self->ob_itself != theList)
+ return; /* nothing we can do */
+ listDefFunc = self->ob_ldef_func;
+ if (listDefFunc == NULL)
+ return; /* nothing we can do */
+ args = Py_BuildValue("hbO&O&hhO", message,
+ selected,
+ PyMac_BuildRect, cellRect,
+ PyMac_BuildPoint, theCell,
+ dataOffset,
+ dataLen,
+ self);
+ if (args != NULL) {
+ rv = PyEval_CallObject(listDefFunc, args);
+ Py_DECREF(args);
+ }
+ if (rv == NULL) {
+ PySys_WriteStderr("error in list definition callback:\n");
+ PyErr_Print();
+ } else {
+ Py_DECREF(rv);
+ }
+ }
+
void init_List(void)
***************
*** 993,998 ****
! PyMac_INIT_TOOLBOX_OBJECT_NEW(ListHandle, ListObj_New);
! PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ListHandle, ListObj_Convert);
--- 1167,1174 ----
! myListDefFunctionUPP = NewListDefUPP((ListDefProcPtr)myListDefFunction);
!
! PyMac_INIT_TOOLBOX_OBJECT_NEW(ListHandle, ListObj_New);
! PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ListHandle, ListObj_Convert);