2 /* ========================== Module List =========================== */
8 #define SystemSevenOrLater 1
16 extern PyObject
*ResObj_New(Handle
);
17 extern int ResObj_Convert(PyObject
*, Handle
*);
18 extern PyObject
*OptResObj_New(Handle
);
19 extern int OptResObj_Convert(PyObject
*, Handle
*);
21 extern PyObject
*WinObj_New(WindowPtr
);
22 extern int WinObj_Convert(PyObject
*, WindowPtr
*);
23 extern PyTypeObject Window_Type
;
24 #define WinObj_Check(x) ((x)->ob_type == &Window_Type)
26 extern PyObject
*DlgObj_New(DialogPtr
);
27 extern int DlgObj_Convert(PyObject
*, DialogPtr
*);
28 extern PyTypeObject Dialog_Type
;
29 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
31 extern PyObject
*MenuObj_New(MenuHandle
);
32 extern int MenuObj_Convert(PyObject
*, MenuHandle
*);
34 extern PyObject
*CtlObj_New(ControlHandle
);
35 extern int CtlObj_Convert(PyObject
*, ControlHandle
*);
37 extern PyObject
*GrafObj_New(GrafPtr
);
38 extern int GrafObj_Convert(PyObject
*, GrafPtr
*);
40 extern PyObject
*BMObj_New(BitMapPtr
);
41 extern int BMObj_Convert(PyObject
*, BitMapPtr
*);
43 extern PyObject
*WinObj_WhichWindow(WindowPtr
);
47 static PyObject
*List_Error
;
49 /* ------------------------ Object type List ------------------------ */
51 PyTypeObject List_Type
;
53 #define ListObj_Check(x) ((x)->ob_type == &List_Type)
55 typedef struct ListObject
{
60 PyObject
*ListObj_New(itself
)
65 PyErr_SetString(List_Error
,"Cannot create null List");
68 it
= PyObject_NEW(ListObject
, &List_Type
);
69 if (it
== NULL
) return NULL
;
70 it
->ob_itself
= itself
;
71 return (PyObject
*)it
;
73 ListObj_Convert(v
, p_itself
)
77 if (!ListObj_Check(v
))
79 PyErr_SetString(PyExc_TypeError
, "List required");
82 *p_itself
= ((ListObject
*)v
)->ob_itself
;
86 static void ListObj_dealloc(self
)
89 LDispose(self
->ob_itself
);
93 static PyObject
*ListObj_LAddColumn(_self
, _args
)
97 PyObject
*_res
= NULL
;
101 if (!PyArg_ParseTuple(_args
, "hh",
105 _rv
= LAddColumn(count
,
108 _res
= Py_BuildValue("h",
113 static PyObject
*ListObj_LAddRow(_self
, _args
)
117 PyObject
*_res
= NULL
;
121 if (!PyArg_ParseTuple(_args
, "hh",
128 _res
= Py_BuildValue("h",
133 static PyObject
*ListObj_LDelColumn(_self
, _args
)
137 PyObject
*_res
= NULL
;
140 if (!PyArg_ParseTuple(_args
, "hh",
152 static PyObject
*ListObj_LDelRow(_self
, _args
)
156 PyObject
*_res
= NULL
;
159 if (!PyArg_ParseTuple(_args
, "hh",
171 static PyObject
*ListObj_LGetSelect(_self
, _args
)
175 PyObject
*_res
= NULL
;
179 if (!PyArg_ParseTuple(_args
, "bO&",
181 PyMac_GetPoint
, &theCell
))
183 _rv
= LGetSelect(next
,
186 _res
= Py_BuildValue("bO&",
188 PyMac_BuildPoint
, theCell
);
192 static PyObject
*ListObj_LLastClick(_self
, _args
)
196 PyObject
*_res
= NULL
;
198 if (!PyArg_ParseTuple(_args
, ""))
200 _rv
= LLastClick(_self
->ob_itself
);
201 _res
= Py_BuildValue("O&",
202 PyMac_BuildPoint
, _rv
);
206 static PyObject
*ListObj_LNextCell(_self
, _args
)
210 PyObject
*_res
= NULL
;
215 if (!PyArg_ParseTuple(_args
, "bbO&",
218 PyMac_GetPoint
, &theCell
))
220 _rv
= LNextCell(hNext
,
224 _res
= Py_BuildValue("bO&",
226 PyMac_BuildPoint
, theCell
);
230 static PyObject
*ListObj_LSize(_self
, _args
)
234 PyObject
*_res
= NULL
;
237 if (!PyArg_ParseTuple(_args
, "hh",
249 static PyObject
*ListObj_LSetDrawingMode(_self
, _args
)
253 PyObject
*_res
= NULL
;
255 if (!PyArg_ParseTuple(_args
, "b",
258 LSetDrawingMode(drawIt
,
265 static PyObject
*ListObj_LScroll(_self
, _args
)
269 PyObject
*_res
= NULL
;
272 if (!PyArg_ParseTuple(_args
, "hh",
284 static PyObject
*ListObj_LAutoScroll(_self
, _args
)
288 PyObject
*_res
= NULL
;
289 if (!PyArg_ParseTuple(_args
, ""))
291 LAutoScroll(_self
->ob_itself
);
297 static PyObject
*ListObj_LUpdate(_self
, _args
)
301 PyObject
*_res
= NULL
;
303 if (!PyArg_ParseTuple(_args
, "O&",
304 ResObj_Convert
, &theRgn
))
313 static PyObject
*ListObj_LActivate(_self
, _args
)
317 PyObject
*_res
= NULL
;
319 if (!PyArg_ParseTuple(_args
, "b",
329 static PyObject
*ListObj_LCellSize(_self
, _args
)
333 PyObject
*_res
= NULL
;
335 if (!PyArg_ParseTuple(_args
, "O&",
336 PyMac_GetPoint
, &cSize
))
345 static PyObject
*ListObj_LClick(_self
, _args
)
349 PyObject
*_res
= NULL
;
353 if (!PyArg_ParseTuple(_args
, "O&h",
360 _res
= Py_BuildValue("b",
365 static PyObject
*ListObj_LAddToCell(_self
, _args
)
369 PyObject
*_res
= NULL
;
371 short dataPtr__len__
;
372 int dataPtr__in_len__
;
374 if (!PyArg_ParseTuple(_args
, "s#O&",
375 &dataPtr__in__
, &dataPtr__in_len__
,
376 PyMac_GetPoint
, &theCell
))
378 dataPtr__len__
= dataPtr__in_len__
;
379 LAddToCell(dataPtr__in__
, dataPtr__len__
,
388 static PyObject
*ListObj_LClrCell(_self
, _args
)
392 PyObject
*_res
= NULL
;
394 if (!PyArg_ParseTuple(_args
, "O&",
395 PyMac_GetPoint
, &theCell
))
404 static PyObject
*ListObj_LGetCell(_self
, _args
)
408 PyObject
*_res
= NULL
;
409 char *dataPtr__out__
;
410 short dataPtr__len__
;
411 int dataPtr__in_len__
;
413 if (!PyArg_ParseTuple(_args
, "iO&",
415 PyMac_GetPoint
, &theCell
))
417 if ((dataPtr__out__
= malloc(dataPtr__in_len__
)) == NULL
)
420 goto dataPtr__error__
;
422 dataPtr__len__
= dataPtr__in_len__
;
423 LGetCell(dataPtr__out__
, &dataPtr__len__
,
426 _res
= Py_BuildValue("s#",
427 dataPtr__out__
, (int)dataPtr__len__
);
428 free(dataPtr__out__
);
433 static PyObject
*ListObj_LRect(_self
, _args
)
437 PyObject
*_res
= NULL
;
440 if (!PyArg_ParseTuple(_args
, "O&",
441 PyMac_GetPoint
, &theCell
))
446 _res
= Py_BuildValue("O&",
447 PyMac_BuildRect
, &cellRect
);
451 static PyObject
*ListObj_LSetCell(_self
, _args
)
455 PyObject
*_res
= NULL
;
457 short dataPtr__len__
;
458 int dataPtr__in_len__
;
460 if (!PyArg_ParseTuple(_args
, "s#O&",
461 &dataPtr__in__
, &dataPtr__in_len__
,
462 PyMac_GetPoint
, &theCell
))
464 dataPtr__len__
= dataPtr__in_len__
;
465 LSetCell(dataPtr__in__
, dataPtr__len__
,
474 static PyObject
*ListObj_LSetSelect(_self
, _args
)
478 PyObject
*_res
= NULL
;
481 if (!PyArg_ParseTuple(_args
, "bO&",
483 PyMac_GetPoint
, &theCell
))
493 static PyObject
*ListObj_LDraw(_self
, _args
)
497 PyObject
*_res
= NULL
;
499 if (!PyArg_ParseTuple(_args
, "O&",
500 PyMac_GetPoint
, &theCell
))
509 static PyMethodDef ListObj_methods
[] = {
510 {"LAddColumn", (PyCFunction
)ListObj_LAddColumn
, 1,
511 "(short count, short colNum) -> (short _rv)"},
512 {"LAddRow", (PyCFunction
)ListObj_LAddRow
, 1,
513 "(short count, short rowNum) -> (short _rv)"},
514 {"LDelColumn", (PyCFunction
)ListObj_LDelColumn
, 1,
515 "(short count, short colNum) -> None"},
516 {"LDelRow", (PyCFunction
)ListObj_LDelRow
, 1,
517 "(short count, short rowNum) -> None"},
518 {"LGetSelect", (PyCFunction
)ListObj_LGetSelect
, 1,
519 "(Boolean next, Point theCell) -> (Boolean _rv, Point theCell)"},
520 {"LLastClick", (PyCFunction
)ListObj_LLastClick
, 1,
521 "() -> (Point _rv)"},
522 {"LNextCell", (PyCFunction
)ListObj_LNextCell
, 1,
523 "(Boolean hNext, Boolean vNext, Point theCell) -> (Boolean _rv, Point theCell)"},
524 {"LSize", (PyCFunction
)ListObj_LSize
, 1,
525 "(short listWidth, short listHeight) -> None"},
526 {"LSetDrawingMode", (PyCFunction
)ListObj_LSetDrawingMode
, 1,
527 "(Boolean drawIt) -> None"},
528 {"LScroll", (PyCFunction
)ListObj_LScroll
, 1,
529 "(short dCols, short dRows) -> None"},
530 {"LAutoScroll", (PyCFunction
)ListObj_LAutoScroll
, 1,
532 {"LUpdate", (PyCFunction
)ListObj_LUpdate
, 1,
533 "(RgnHandle theRgn) -> None"},
534 {"LActivate", (PyCFunction
)ListObj_LActivate
, 1,
535 "(Boolean act) -> None"},
536 {"LCellSize", (PyCFunction
)ListObj_LCellSize
, 1,
537 "(Point cSize) -> None"},
538 {"LClick", (PyCFunction
)ListObj_LClick
, 1,
539 "(Point pt, short modifiers) -> (Boolean _rv)"},
540 {"LAddToCell", (PyCFunction
)ListObj_LAddToCell
, 1,
541 "(Buffer dataPtr, Point theCell) -> None"},
542 {"LClrCell", (PyCFunction
)ListObj_LClrCell
, 1,
543 "(Point theCell) -> None"},
544 {"LGetCell", (PyCFunction
)ListObj_LGetCell
, 1,
545 "(Buffer dataPtr, Point theCell) -> (Buffer dataPtr)"},
546 {"LRect", (PyCFunction
)ListObj_LRect
, 1,
547 "(Point theCell) -> (Rect cellRect)"},
548 {"LSetCell", (PyCFunction
)ListObj_LSetCell
, 1,
549 "(Buffer dataPtr, Point theCell) -> None"},
550 {"LSetSelect", (PyCFunction
)ListObj_LSetSelect
, 1,
551 "(Boolean setIt, Point theCell) -> None"},
552 {"LDraw", (PyCFunction
)ListObj_LDraw
, 1,
553 "(Point theCell) -> None"},
557 PyMethodChain ListObj_chain
= { ListObj_methods
, NULL
};
559 static PyObject
*ListObj_getattr(self
, name
)
564 /* XXXX Should we HLock() here?? */
565 if ( strcmp(name
, "listFlags") == 0 )
566 return Py_BuildValue("l", (long)(*self
->ob_itself
)->listFlags
& 0xff);
567 if ( strcmp(name
, "selFlags") == 0 )
568 return Py_BuildValue("l", (long)(*self
->ob_itself
)->selFlags
& 0xff);
570 return Py_FindMethodInChain(&ListObj_chain
, (PyObject
*)self
, name
);
574 ListObj_setattr(self
, name
, value
)
581 if ( value
== NULL
|| !PyInt_Check(value
) )
583 intval
= PyInt_AsLong(value
);
584 if (strcmp(name
, "listFlags") == 0 ) {
585 /* XXXX Should we HLock the handle here?? */
586 (*self
->ob_itself
)->listFlags
= intval
;
589 if (strcmp(name
, "selFlags") == 0 ) {
590 (*self
->ob_itself
)->selFlags
= intval
;
597 PyTypeObject List_Type
= {
598 PyObject_HEAD_INIT(&PyType_Type
)
601 sizeof(ListObject
), /*tp_basicsize*/
604 (destructor
) ListObj_dealloc
, /*tp_dealloc*/
606 (getattrfunc
) ListObj_getattr
, /*tp_getattr*/
607 (setattrfunc
) ListObj_setattr
, /*tp_setattr*/
610 /* ---------------------- End object type List ---------------------- */
613 static PyObject
*List_LNew(_self
, _args
)
617 PyObject
*_res
= NULL
;
628 if (!PyArg_ParseTuple(_args
, "O&O&O&hO&bbbb",
629 PyMac_GetRect
, &rView
,
630 PyMac_GetRect
, &dataBounds
,
631 PyMac_GetPoint
, &cSize
,
633 WinObj_Convert
, &theWindow
,
648 _res
= Py_BuildValue("O&",
653 static PyMethodDef List_methods
[] = {
654 {"LNew", (PyCFunction
)List_LNew
, 1,
655 "(Rect rView, Rect dataBounds, Point cSize, short theProc, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle _rv)"},
670 m
= Py_InitModule("List", List_methods
);
671 d
= PyModule_GetDict(m
);
672 List_Error
= PyMac_GetOSErrException();
673 if (List_Error
== NULL
||
674 PyDict_SetItemString(d
, "Error", List_Error
) != 0)
675 Py_FatalError("can't initialize List.Error");
676 List_Type
.ob_type
= &PyType_Type
;
677 Py_INCREF(&List_Type
);
678 if (PyDict_SetItemString(d
, "ListType", (PyObject
*)&List_Type
) != 0)
679 Py_FatalError("can't initialize ListType");
682 /* ======================== End module List ========================= */