mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
More List Manager interfacing:
- CreateCustomList(): write LDEF's in Python! (carbon + classic) - list.LGetCellDataLocation() (Jack: what's with this _WIN32/pywintoolbox.h stuff?)
This commit is contained in:
parent
7a33d8bb64
commit
dd4830ac1d
3 changed files with 363 additions and 23 deletions
|
@ -5,12 +5,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include "pywintoolbox.h"
|
|
||||||
#else
|
|
||||||
#include "macglue.h"
|
#include "macglue.h"
|
||||||
#include "pymactoolbox.h"
|
#include "pymactoolbox.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Macro to test whether a weak-loaded CFM function exists */
|
/* Macro to test whether a weak-loaded CFM function exists */
|
||||||
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
|
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
|
||||||
|
@ -62,6 +58,42 @@ extern int _ListObj_Convert(PyObject *, ListHandle *);
|
||||||
#define as_List(x) ((ListHandle)x)
|
#define as_List(x) ((ListHandle)x)
|
||||||
#define as_Resource(lh) ((Handle)lh)
|
#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;
|
static PyObject *List_Error;
|
||||||
|
|
||||||
/* ------------------------ Object type List ------------------------ */
|
/* ------------------------ Object type List ------------------------ */
|
||||||
|
@ -73,6 +105,8 @@ PyTypeObject List_Type;
|
||||||
typedef struct ListObject {
|
typedef struct ListObject {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
ListHandle ob_itself;
|
ListHandle ob_itself;
|
||||||
|
PyObject *ob_ldef_func;
|
||||||
|
int ob_have_ldef_stub;
|
||||||
int ob_must_be_disposed;
|
int ob_must_be_disposed;
|
||||||
} ListObject;
|
} ListObject;
|
||||||
|
|
||||||
|
@ -86,7 +120,10 @@ PyObject *ListObj_New(ListHandle itself)
|
||||||
it = PyObject_NEW(ListObject, &List_Type);
|
it = PyObject_NEW(ListObject, &List_Type);
|
||||||
if (it == NULL) return NULL;
|
if (it == NULL) return NULL;
|
||||||
it->ob_itself = itself;
|
it->ob_itself = itself;
|
||||||
|
it->ob_ldef_func = NULL;
|
||||||
|
it->ob_have_ldef_stub = 0;
|
||||||
it->ob_must_be_disposed = 1;
|
it->ob_must_be_disposed = 1;
|
||||||
|
SetListRefCon(itself, (long)it);
|
||||||
return (PyObject *)it;
|
return (PyObject *)it;
|
||||||
}
|
}
|
||||||
int ListObj_Convert(PyObject *v, ListHandle *p_itself)
|
int ListObj_Convert(PyObject *v, ListHandle *p_itself)
|
||||||
|
@ -102,6 +139,12 @@ int ListObj_Convert(PyObject *v, ListHandle *p_itself)
|
||||||
|
|
||||||
static void ListObj_dealloc(ListObject *self)
|
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);
|
if (self->ob_must_be_disposed && self->ob_itself) LDispose(self->ob_itself);
|
||||||
PyMem_DEL(self);
|
PyMem_DEL(self);
|
||||||
}
|
}
|
||||||
|
@ -476,6 +519,25 @@ static PyObject *ListObj_LDraw(ListObject *_self, PyObject *_args)
|
||||||
return _res;
|
return _res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
static PyObject *ListObj_as_Resource(ListObject *_self, PyObject *_args)
|
||||||
{
|
{
|
||||||
PyObject *_res = NULL;
|
PyObject *_res = NULL;
|
||||||
|
@ -533,6 +595,8 @@ static PyMethodDef ListObj_methods[] = {
|
||||||
"(Boolean setIt, Point theCell) -> None"},
|
"(Boolean setIt, Point theCell) -> None"},
|
||||||
{"LDraw", (PyCFunction)ListObj_LDraw, 1,
|
{"LDraw", (PyCFunction)ListObj_LDraw, 1,
|
||||||
"(Point theCell) -> None"},
|
"(Point theCell) -> None"},
|
||||||
|
{"LGetCellDataLocation", (PyCFunction)ListObj_LGetCellDataLocation, 1,
|
||||||
|
"(Point theCell) -> (short offset, short len)"},
|
||||||
{"as_Resource", (PyCFunction)ListObj_as_Resource, 1,
|
{"as_Resource", (PyCFunction)ListObj_as_Resource, 1,
|
||||||
"() -> (Handle _rv)"},
|
"() -> (Handle _rv)"},
|
||||||
{NULL, NULL, 0}
|
{NULL, NULL, 0}
|
||||||
|
@ -545,9 +609,9 @@ static PyObject *ListObj_getattr(ListObject *self, char *name)
|
||||||
{
|
{
|
||||||
/* XXXX Should we HLock() here?? */
|
/* XXXX Should we HLock() here?? */
|
||||||
if ( strcmp(name, "listFlags") == 0 )
|
if ( strcmp(name, "listFlags") == 0 )
|
||||||
return Py_BuildValue("l", (long)(*self->ob_itself)->listFlags & 0xff);
|
return Py_BuildValue("l", (long)GetListFlags(self->ob_itself) & 0xff);
|
||||||
if ( strcmp(name, "selFlags") == 0 )
|
if ( strcmp(name, "selFlags") == 0 )
|
||||||
return Py_BuildValue("l", (long)(*self->ob_itself)->selFlags & 0xff);
|
return Py_BuildValue("l", (long)GetListSelectionFlags(self->ob_itself) & 0xff);
|
||||||
}
|
}
|
||||||
return Py_FindMethodInChain(&ListObj_chain, (PyObject *)self, name);
|
return Py_FindMethodInChain(&ListObj_chain, (PyObject *)self, name);
|
||||||
}
|
}
|
||||||
|
@ -561,12 +625,11 @@ ListObj_setattr(ListObject *self, char *name, PyObject *value)
|
||||||
return -1;
|
return -1;
|
||||||
intval = PyInt_AsLong(value);
|
intval = PyInt_AsLong(value);
|
||||||
if (strcmp(name, "listFlags") == 0 ) {
|
if (strcmp(name, "listFlags") == 0 ) {
|
||||||
/* XXXX Should we HLock the handle here?? */
|
SetListFlags(self->ob_itself, intval);
|
||||||
(*self->ob_itself)->listFlags = intval;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (strcmp(name, "selFlags") == 0 ) {
|
if (strcmp(name, "selFlags") == 0 ) {
|
||||||
(*self->ob_itself)->selFlags = intval;
|
SetListSelectionFlags(self->ob_itself, intval);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -601,6 +664,79 @@ PyTypeObject List_Type = {
|
||||||
/* ---------------------- End object type List ---------------------- */
|
/* ---------------------- End object type List ---------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
static PyObject *List_LNew(PyObject *_self, PyObject *_args)
|
||||||
{
|
{
|
||||||
PyObject *_res = NULL;
|
PyObject *_res = NULL;
|
||||||
|
@ -937,6 +1073,8 @@ static PyObject *List_as_List(PyObject *_self, PyObject *_args)
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyMethodDef List_methods[] = {
|
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,
|
{"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)"},
|
"(Rect rView, Rect dataBounds, Point cSize, short theProc, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle _rv)"},
|
||||||
{"GetListPort", (PyCFunction)List_GetListPort, 1,
|
{"GetListPort", (PyCFunction)List_GetListPort, 1,
|
||||||
|
@ -984,6 +1122,42 @@ static PyMethodDef List_methods[] = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
void init_List(void)
|
||||||
{
|
{
|
||||||
|
@ -992,8 +1166,10 @@ void init_List(void)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PyMac_INIT_TOOLBOX_OBJECT_NEW(ListHandle, ListObj_New);
|
myListDefFunctionUPP = NewListDefUPP((ListDefProcPtr)myListDefFunction);
|
||||||
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ListHandle, ListObj_Convert);
|
|
||||||
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(ListHandle, ListObj_New);
|
||||||
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ListHandle, ListObj_Convert);
|
||||||
|
|
||||||
|
|
||||||
m = Py_InitModule("_List", List_methods);
|
m = Py_InitModule("_List", List_methods);
|
||||||
|
|
|
@ -39,7 +39,8 @@ class MyScanner(Scanner):
|
||||||
return [
|
return [
|
||||||
"LDispose", # Done by removing the object
|
"LDispose", # Done by removing the object
|
||||||
"LSearch", # We don't want to handle procs just yet
|
"LSearch", # We don't want to handle procs just yet
|
||||||
"LGetCellDataLocation", # What does this do??
|
"CreateCustomList", # done manually
|
||||||
|
"SetListDefinitionProc",
|
||||||
|
|
||||||
# These have funny argument/return values
|
# These have funny argument/return values
|
||||||
"GetListViewBounds",
|
"GetListViewBounds",
|
||||||
|
@ -54,10 +55,7 @@ class MyScanner(Scanner):
|
||||||
|
|
||||||
def makeblacklisttypes(self):
|
def makeblacklisttypes(self):
|
||||||
return [
|
return [
|
||||||
'ListDefSpec', # Too difficult for now
|
"ListClickLoopUPP", # Too difficult for now
|
||||||
'ListDefSpec_ptr', # ditto
|
|
||||||
"ListDefUPP",
|
|
||||||
"ListClickLoopUPP",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def makerepairinstructions(self):
|
def makerepairinstructions(self):
|
||||||
|
|
|
@ -26,6 +26,9 @@ ListRef = ListHandle # Obsolete, but used in Lists.h
|
||||||
Cell = Point
|
Cell = Point
|
||||||
ListBounds = Rect
|
ListBounds = Rect
|
||||||
ListBounds_ptr = Rect_ptr
|
ListBounds_ptr = Rect_ptr
|
||||||
|
|
||||||
|
ListDefSpec = ListDefSpec_ptr = OpaqueType("ListDefSpec", "PyMac_BuildListDefSpec", "PyMac_GetListDefSpec")
|
||||||
|
|
||||||
VarOutBufferShortsize = VarHeapOutputBufferType('char', 'short', 's') # (buf, &len)
|
VarOutBufferShortsize = VarHeapOutputBufferType('char', 'short', 's') # (buf, &len)
|
||||||
InBufferShortsize = VarInputBufferType('char', 'short', 's') # (buf, len)
|
InBufferShortsize = VarInputBufferType('char', 'short', 's') # (buf, len)
|
||||||
|
|
||||||
|
@ -76,11 +79,49 @@ extern int _ListObj_Convert(PyObject *, ListHandle *);
|
||||||
|
|
||||||
#define as_List(x) ((ListHandle)x)
|
#define as_List(x) ((ListHandle)x)
|
||||||
#define as_Resource(lh) ((Handle)lh)
|
#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 + """
|
initstuff = initstuff + """
|
||||||
PyMac_INIT_TOOLBOX_OBJECT_NEW(ListHandle, ListObj_New);
|
myListDefFunctionUPP = NewListDefUPP((ListDefProcPtr)myListDefFunction);
|
||||||
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ListHandle, ListObj_Convert);
|
|
||||||
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(ListHandle, ListObj_New);
|
||||||
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ListHandle, ListObj_Convert);
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class ListMethodGenerator(MethodGenerator):
|
class ListMethodGenerator(MethodGenerator):
|
||||||
|
@ -98,9 +139,9 @@ class ListMethodGenerator(MethodGenerator):
|
||||||
getattrHookCode = """{
|
getattrHookCode = """{
|
||||||
/* XXXX Should we HLock() here?? */
|
/* XXXX Should we HLock() here?? */
|
||||||
if ( strcmp(name, "listFlags") == 0 )
|
if ( strcmp(name, "listFlags") == 0 )
|
||||||
return Py_BuildValue("l", (long)(*self->ob_itself)->listFlags & 0xff);
|
return Py_BuildValue("l", (long)GetListFlags(self->ob_itself) & 0xff);
|
||||||
if ( strcmp(name, "selFlags") == 0 )
|
if ( strcmp(name, "selFlags") == 0 )
|
||||||
return Py_BuildValue("l", (long)(*self->ob_itself)->selFlags & 0xff);
|
return Py_BuildValue("l", (long)GetListSelectionFlags(self->ob_itself) & 0xff);
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
setattrCode = """
|
setattrCode = """
|
||||||
|
@ -113,12 +154,11 @@ ListObj_setattr(ListObject *self, char *name, PyObject *value)
|
||||||
return -1;
|
return -1;
|
||||||
intval = PyInt_AsLong(value);
|
intval = PyInt_AsLong(value);
|
||||||
if (strcmp(name, "listFlags") == 0 ) {
|
if (strcmp(name, "listFlags") == 0 ) {
|
||||||
/* XXXX Should we HLock the handle here?? */
|
SetListFlags(self->ob_itself, intval);
|
||||||
(*self->ob_itself)->listFlags = intval;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (strcmp(name, "selFlags") == 0 ) {
|
if (strcmp(name, "selFlags") == 0 ) {
|
||||||
(*self->ob_itself)->selFlags = intval;
|
SetListSelectionFlags(self->ob_itself, intval);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -130,6 +170,8 @@ class MyObjectDefinition(GlobalObjectDefinition):
|
||||||
|
|
||||||
def outputStructMembers(self):
|
def outputStructMembers(self):
|
||||||
ObjectDefinition.outputStructMembers(self)
|
ObjectDefinition.outputStructMembers(self)
|
||||||
|
Output("PyObject *ob_ldef_func;")
|
||||||
|
Output("int ob_have_ldef_stub;")
|
||||||
Output("int ob_must_be_disposed;")
|
Output("int ob_must_be_disposed;")
|
||||||
|
|
||||||
def outputCheckNewArg(self):
|
def outputCheckNewArg(self):
|
||||||
|
@ -140,9 +182,18 @@ class MyObjectDefinition(GlobalObjectDefinition):
|
||||||
|
|
||||||
def outputInitStructMembers(self):
|
def outputInitStructMembers(self):
|
||||||
ObjectDefinition.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("it->ob_must_be_disposed = 1;")
|
||||||
|
Output("SetListRefCon(itself, (long)it);")
|
||||||
|
|
||||||
def outputFreeIt(self, itselfname):
|
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)
|
Output("if (self->ob_must_be_disposed && %s) LDispose(%s);", itselfname, itselfname)
|
||||||
|
|
||||||
def outputGetattrHook(self):
|
def outputGetattrHook(self):
|
||||||
|
@ -153,6 +204,44 @@ class MyObjectDefinition(GlobalObjectDefinition):
|
||||||
|
|
||||||
# From here on it's basically all boiler plate...
|
# 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
|
# Create the generator groups and link them
|
||||||
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
|
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
|
||||||
object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
|
object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
|
||||||
|
@ -186,11 +275,88 @@ functions.append(f)
|
||||||
f = Method(Handle, 'as_Resource', (ListHandle, 'lh', InMode))
|
f = Method(Handle, 'as_Resource', (ListHandle, 'lh', InMode))
|
||||||
methods.append(f)
|
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
|
# add the populated lists to the generator groups
|
||||||
# (in a different wordl the scan program would generate this)
|
# (in a different wordl the scan program would generate this)
|
||||||
for f in functions: module.add(f)
|
for f in functions: module.add(f)
|
||||||
for f in methods: object.add(f)
|
for f in methods: object.add(f)
|
||||||
|
|
||||||
|
|
||||||
# generate output (open the output file as late as possible)
|
# generate output (open the output file as late as possible)
|
||||||
SetOutputFileName(OUTPUTFILE)
|
SetOutputFileName(OUTPUTFILE)
|
||||||
module.generate()
|
module.generate()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue