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 #define as_List(x) ((ListHandle)x)
48 #define as_Resource(lh) ((Handle)lh)
50 static PyObject
*List_Error
;
52 /* ------------------------ Object type List ------------------------ */
54 PyTypeObject List_Type
;
56 #define ListObj_Check(x) ((x)->ob_type == &List_Type)
58 typedef struct ListObject
{
61 int ob_must_be_disposed
;
64 PyObject
*ListObj_New(itself
)
69 PyErr_SetString(List_Error
,"Cannot create null List");
72 it
= PyObject_NEW(ListObject
, &List_Type
);
73 if (it
== NULL
) return NULL
;
74 it
->ob_itself
= itself
;
75 it
->ob_must_be_disposed
= 1;
76 return (PyObject
*)it
;
78 ListObj_Convert(v
, p_itself
)
82 if (!ListObj_Check(v
))
84 PyErr_SetString(PyExc_TypeError
, "List required");
87 *p_itself
= ((ListObject
*)v
)->ob_itself
;
91 static void ListObj_dealloc(self
)
94 if (self
->ob_must_be_disposed
&& self
->ob_itself
) LDispose(self
->ob_itself
);
98 static PyObject
*ListObj_LAddColumn(_self
, _args
)
102 PyObject
*_res
= NULL
;
106 if (!PyArg_ParseTuple(_args
, "hh",
110 _rv
= LAddColumn(count
,
113 _res
= Py_BuildValue("h",
118 static PyObject
*ListObj_LAddRow(_self
, _args
)
122 PyObject
*_res
= NULL
;
126 if (!PyArg_ParseTuple(_args
, "hh",
133 _res
= Py_BuildValue("h",
138 static PyObject
*ListObj_LDelColumn(_self
, _args
)
142 PyObject
*_res
= NULL
;
145 if (!PyArg_ParseTuple(_args
, "hh",
157 static PyObject
*ListObj_LDelRow(_self
, _args
)
161 PyObject
*_res
= NULL
;
164 if (!PyArg_ParseTuple(_args
, "hh",
176 static PyObject
*ListObj_LGetSelect(_self
, _args
)
180 PyObject
*_res
= NULL
;
184 if (!PyArg_ParseTuple(_args
, "bO&",
186 PyMac_GetPoint
, &theCell
))
188 _rv
= LGetSelect(next
,
191 _res
= Py_BuildValue("bO&",
193 PyMac_BuildPoint
, theCell
);
197 static PyObject
*ListObj_LLastClick(_self
, _args
)
201 PyObject
*_res
= NULL
;
203 if (!PyArg_ParseTuple(_args
, ""))
205 _rv
= LLastClick(_self
->ob_itself
);
206 _res
= Py_BuildValue("O&",
207 PyMac_BuildPoint
, _rv
);
211 static PyObject
*ListObj_LNextCell(_self
, _args
)
215 PyObject
*_res
= NULL
;
220 if (!PyArg_ParseTuple(_args
, "bbO&",
223 PyMac_GetPoint
, &theCell
))
225 _rv
= LNextCell(hNext
,
229 _res
= Py_BuildValue("bO&",
231 PyMac_BuildPoint
, theCell
);
235 static PyObject
*ListObj_LSize(_self
, _args
)
239 PyObject
*_res
= NULL
;
242 if (!PyArg_ParseTuple(_args
, "hh",
254 static PyObject
*ListObj_LSetDrawingMode(_self
, _args
)
258 PyObject
*_res
= NULL
;
260 if (!PyArg_ParseTuple(_args
, "b",
263 LSetDrawingMode(drawIt
,
270 static PyObject
*ListObj_LScroll(_self
, _args
)
274 PyObject
*_res
= NULL
;
277 if (!PyArg_ParseTuple(_args
, "hh",
289 static PyObject
*ListObj_LAutoScroll(_self
, _args
)
293 PyObject
*_res
= NULL
;
294 if (!PyArg_ParseTuple(_args
, ""))
296 LAutoScroll(_self
->ob_itself
);
302 static PyObject
*ListObj_LUpdate(_self
, _args
)
306 PyObject
*_res
= NULL
;
308 if (!PyArg_ParseTuple(_args
, "O&",
309 ResObj_Convert
, &theRgn
))
318 static PyObject
*ListObj_LActivate(_self
, _args
)
322 PyObject
*_res
= NULL
;
324 if (!PyArg_ParseTuple(_args
, "b",
334 static PyObject
*ListObj_LCellSize(_self
, _args
)
338 PyObject
*_res
= NULL
;
340 if (!PyArg_ParseTuple(_args
, "O&",
341 PyMac_GetPoint
, &cSize
))
350 static PyObject
*ListObj_LClick(_self
, _args
)
354 PyObject
*_res
= NULL
;
358 if (!PyArg_ParseTuple(_args
, "O&h",
365 _res
= Py_BuildValue("b",
370 static PyObject
*ListObj_LAddToCell(_self
, _args
)
374 PyObject
*_res
= NULL
;
376 short dataPtr__len__
;
377 int dataPtr__in_len__
;
379 if (!PyArg_ParseTuple(_args
, "s#O&",
380 &dataPtr__in__
, &dataPtr__in_len__
,
381 PyMac_GetPoint
, &theCell
))
383 dataPtr__len__
= dataPtr__in_len__
;
384 LAddToCell(dataPtr__in__
, dataPtr__len__
,
393 static PyObject
*ListObj_LClrCell(_self
, _args
)
397 PyObject
*_res
= NULL
;
399 if (!PyArg_ParseTuple(_args
, "O&",
400 PyMac_GetPoint
, &theCell
))
409 static PyObject
*ListObj_LGetCell(_self
, _args
)
413 PyObject
*_res
= NULL
;
414 char *dataPtr__out__
;
415 short dataPtr__len__
;
416 int dataPtr__in_len__
;
418 if (!PyArg_ParseTuple(_args
, "iO&",
420 PyMac_GetPoint
, &theCell
))
422 if ((dataPtr__out__
= malloc(dataPtr__in_len__
)) == NULL
)
425 goto dataPtr__error__
;
427 dataPtr__len__
= dataPtr__in_len__
;
428 LGetCell(dataPtr__out__
, &dataPtr__len__
,
431 _res
= Py_BuildValue("s#",
432 dataPtr__out__
, (int)dataPtr__len__
);
433 free(dataPtr__out__
);
438 static PyObject
*ListObj_LRect(_self
, _args
)
442 PyObject
*_res
= NULL
;
445 if (!PyArg_ParseTuple(_args
, "O&",
446 PyMac_GetPoint
, &theCell
))
451 _res
= Py_BuildValue("O&",
452 PyMac_BuildRect
, &cellRect
);
456 static PyObject
*ListObj_LSetCell(_self
, _args
)
460 PyObject
*_res
= NULL
;
462 short dataPtr__len__
;
463 int dataPtr__in_len__
;
465 if (!PyArg_ParseTuple(_args
, "s#O&",
466 &dataPtr__in__
, &dataPtr__in_len__
,
467 PyMac_GetPoint
, &theCell
))
469 dataPtr__len__
= dataPtr__in_len__
;
470 LSetCell(dataPtr__in__
, dataPtr__len__
,
479 static PyObject
*ListObj_LSetSelect(_self
, _args
)
483 PyObject
*_res
= NULL
;
486 if (!PyArg_ParseTuple(_args
, "bO&",
488 PyMac_GetPoint
, &theCell
))
498 static PyObject
*ListObj_LDraw(_self
, _args
)
502 PyObject
*_res
= NULL
;
504 if (!PyArg_ParseTuple(_args
, "O&",
505 PyMac_GetPoint
, &theCell
))
514 static PyObject
*ListObj_as_Resource(_self
, _args
)
518 PyObject
*_res
= NULL
;
520 if (!PyArg_ParseTuple(_args
, ""))
522 _rv
= as_Resource(_self
->ob_itself
);
523 _res
= Py_BuildValue("O&",
528 static PyMethodDef ListObj_methods
[] = {
529 {"LAddColumn", (PyCFunction
)ListObj_LAddColumn
, 1,
530 "(short count, short colNum) -> (short _rv)"},
531 {"LAddRow", (PyCFunction
)ListObj_LAddRow
, 1,
532 "(short count, short rowNum) -> (short _rv)"},
533 {"LDelColumn", (PyCFunction
)ListObj_LDelColumn
, 1,
534 "(short count, short colNum) -> None"},
535 {"LDelRow", (PyCFunction
)ListObj_LDelRow
, 1,
536 "(short count, short rowNum) -> None"},
537 {"LGetSelect", (PyCFunction
)ListObj_LGetSelect
, 1,
538 "(Boolean next, Point theCell) -> (Boolean _rv, Point theCell)"},
539 {"LLastClick", (PyCFunction
)ListObj_LLastClick
, 1,
540 "() -> (Point _rv)"},
541 {"LNextCell", (PyCFunction
)ListObj_LNextCell
, 1,
542 "(Boolean hNext, Boolean vNext, Point theCell) -> (Boolean _rv, Point theCell)"},
543 {"LSize", (PyCFunction
)ListObj_LSize
, 1,
544 "(short listWidth, short listHeight) -> None"},
545 {"LSetDrawingMode", (PyCFunction
)ListObj_LSetDrawingMode
, 1,
546 "(Boolean drawIt) -> None"},
547 {"LScroll", (PyCFunction
)ListObj_LScroll
, 1,
548 "(short dCols, short dRows) -> None"},
549 {"LAutoScroll", (PyCFunction
)ListObj_LAutoScroll
, 1,
551 {"LUpdate", (PyCFunction
)ListObj_LUpdate
, 1,
552 "(RgnHandle theRgn) -> None"},
553 {"LActivate", (PyCFunction
)ListObj_LActivate
, 1,
554 "(Boolean act) -> None"},
555 {"LCellSize", (PyCFunction
)ListObj_LCellSize
, 1,
556 "(Point cSize) -> None"},
557 {"LClick", (PyCFunction
)ListObj_LClick
, 1,
558 "(Point pt, short modifiers) -> (Boolean _rv)"},
559 {"LAddToCell", (PyCFunction
)ListObj_LAddToCell
, 1,
560 "(Buffer dataPtr, Point theCell) -> None"},
561 {"LClrCell", (PyCFunction
)ListObj_LClrCell
, 1,
562 "(Point theCell) -> None"},
563 {"LGetCell", (PyCFunction
)ListObj_LGetCell
, 1,
564 "(Buffer dataPtr, Point theCell) -> (Buffer dataPtr)"},
565 {"LRect", (PyCFunction
)ListObj_LRect
, 1,
566 "(Point theCell) -> (Rect cellRect)"},
567 {"LSetCell", (PyCFunction
)ListObj_LSetCell
, 1,
568 "(Buffer dataPtr, Point theCell) -> None"},
569 {"LSetSelect", (PyCFunction
)ListObj_LSetSelect
, 1,
570 "(Boolean setIt, Point theCell) -> None"},
571 {"LDraw", (PyCFunction
)ListObj_LDraw
, 1,
572 "(Point theCell) -> None"},
573 {"as_Resource", (PyCFunction
)ListObj_as_Resource
, 1,
574 "() -> (Handle _rv)"},
578 PyMethodChain ListObj_chain
= { ListObj_methods
, NULL
};
580 static PyObject
*ListObj_getattr(self
, name
)
585 /* XXXX Should we HLock() here?? */
586 if ( strcmp(name
, "listFlags") == 0 )
587 return Py_BuildValue("l", (long)(*self
->ob_itself
)->listFlags
& 0xff);
588 if ( strcmp(name
, "selFlags") == 0 )
589 return Py_BuildValue("l", (long)(*self
->ob_itself
)->selFlags
& 0xff);
591 return Py_FindMethodInChain(&ListObj_chain
, (PyObject
*)self
, name
);
595 ListObj_setattr(self
, name
, value
)
602 if ( value
== NULL
|| !PyInt_Check(value
) )
604 intval
= PyInt_AsLong(value
);
605 if (strcmp(name
, "listFlags") == 0 ) {
606 /* XXXX Should we HLock the handle here?? */
607 (*self
->ob_itself
)->listFlags
= intval
;
610 if (strcmp(name
, "selFlags") == 0 ) {
611 (*self
->ob_itself
)->selFlags
= intval
;
618 #define ListObj_compare NULL
620 #define ListObj_repr NULL
622 #define ListObj_hash NULL
624 PyTypeObject List_Type
= {
625 PyObject_HEAD_INIT(&PyType_Type
)
628 sizeof(ListObject
), /*tp_basicsize*/
631 (destructor
) ListObj_dealloc
, /*tp_dealloc*/
633 (getattrfunc
) ListObj_getattr
, /*tp_getattr*/
634 (setattrfunc
) ListObj_setattr
, /*tp_setattr*/
635 (cmpfunc
) ListObj_compare
, /*tp_compare*/
636 (reprfunc
) ListObj_repr
, /*tp_repr*/
637 (PyNumberMethods
*)0, /* tp_as_number */
638 (PySequenceMethods
*)0, /* tp_as_sequence */
639 (PyMappingMethods
*)0, /* tp_as_mapping */
640 (hashfunc
) ListObj_hash
, /*tp_hash*/
643 /* ---------------------- End object type List ---------------------- */
646 static PyObject
*List_LNew(_self
, _args
)
650 PyObject
*_res
= NULL
;
661 if (!PyArg_ParseTuple(_args
, "O&O&O&hO&bbbb",
662 PyMac_GetRect
, &rView
,
663 PyMac_GetRect
, &dataBounds
,
664 PyMac_GetPoint
, &cSize
,
666 WinObj_Convert
, &theWindow
,
681 _res
= Py_BuildValue("O&",
686 static PyObject
*List_as_List(_self
, _args
)
690 PyObject
*_res
= NULL
;
694 if (!PyArg_ParseTuple(_args
, "O&", ResObj_Convert
, &h
))
696 l
= (ListObject
*)ListObj_New(as_List(h
));
697 l
->ob_must_be_disposed
= 0;
698 return Py_BuildValue("O", l
);
702 static PyMethodDef List_methods
[] = {
703 {"LNew", (PyCFunction
)List_LNew
, 1,
704 "(Rect rView, Rect dataBounds, Point cSize, short theProc, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle _rv)"},
705 {"as_List", (PyCFunction
)List_as_List
, 1,
706 "(Resource)->List.\nReturns List object (which is not auto-freed!)"},
721 m
= Py_InitModule("List", List_methods
);
722 d
= PyModule_GetDict(m
);
723 List_Error
= PyMac_GetOSErrException();
724 if (List_Error
== NULL
||
725 PyDict_SetItemString(d
, "Error", List_Error
) != 0)
726 Py_FatalError("can't initialize List.Error");
727 List_Type
.ob_type
= &PyType_Type
;
728 Py_INCREF(&List_Type
);
729 if (PyDict_SetItemString(d
, "ListType", (PyObject
*)&List_Type
) != 0)
730 Py_FatalError("can't initialize ListType");
733 /* ======================== End module List ========================= */