2 /* ========================== Module _List ========================== */
9 #include "pywintoolbox.h"
12 #include "pymactoolbox.h"
15 /* Macro to test whether a weak-loaded CFM function exists */
16 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
17 PyErr_SetString(PyExc_NotImplementedError, \
18 "Not available in this shared library/OS version"); \
23 #ifdef WITHOUT_FRAMEWORKS
26 #include <Carbon/Carbon.h>
29 #ifdef USE_TOOLBOX_OBJECT_GLUE
30 extern PyObject
*_ListObj_New(ListHandle
);
31 extern int _ListObj_Convert(PyObject
*, ListHandle
*);
33 #define ListObj_New _ListObj_New
34 #define ListObj_Convert _ListObj_Convert
37 #if !ACCESSOR_CALLS_ARE_FUNCTIONS
38 #define GetListPort(list) ((CGrafPtr)(*(list))->port)
39 #define GetListVerticalScrollBar(list) ((*(list))->vScroll)
40 #define GetListHorizontalScrollBar(list) ((*(list))->hScroll)
41 #define GetListActive(list) ((*(list))->lActive)
42 #define GetListClickTime(list) ((*(list))->clikTime)
43 #define GetListRefCon(list) ((*(list))->refCon)
44 #define GetListDefinition(list) ((*(list))->listDefProc) /* XXX Is this indeed the same? */
45 #define GetListUserHandle(list) ((*(list))->userHandle)
46 #define GetListDataHandle(list) ((*(list))->cells)
47 #define GetListFlags(list) ((*(list))->listFlags)
48 #define GetListSelectionFlags(list) ((*(list))->selFlags)
49 #define SetListViewBounds(list, bounds) (((*(list))->rView) = *(bounds))
51 #define SetListPort(list, port) (((*(list))->port) = (GrafPtr)(port))
52 #define SetListCellIndent(list, ind) (((*(list))->indent) = *(ind))
53 #define SetListClickTime(list, time) (((*(list))->clikTime) = (time))
54 #define SetListLastClick(list, click) (((*(list)->lastClick) = *(click))
55 #define SetListRefCon(list, refcon) (((*(list))->refCon) = (refcon))
56 #define SetListUserHandle(list, handle) (((*(list))->userHandle) = (handle))
57 #define SetListFlags(list, flags) (((*(list))->listFlags) = (flags))
58 #define SetListSelectionFlags(list, flags) (((*(list))->selFlags) = (flags))
62 #define as_List(x) ((ListHandle)x)
63 #define as_Resource(lh) ((Handle)lh)
65 static ListDefUPP myListDefFunctionUPP
;
67 #if !TARGET_API_MAC_CARBON
69 #define kJumpAbs 0x4EF9
71 #pragma options align=mac68k
73 short jmpabs
; /* 4EF9 */
74 ListDefUPP theUPP
; /* 00000000 */
75 } LDEFStub
, **LDEFStubHandle
;
76 #pragma options align=reset
78 static OSErr
installLDEFStub(ListHandle list
) {
81 stubH
= (LDEFStubHandle
)NewHandleClear(sizeof(LDEFStub
));
85 (*stubH
)->jmpabs
= kJumpAbs
;
86 (*stubH
)->theUPP
= myListDefFunctionUPP
;
87 HLock((Handle
) stubH
);
89 (*list
)->listDefProc
= (Handle
)stubH
;
93 static void removeLDEFStub(ListHandle list
) {
94 if ((*list
)->listDefProc
)
95 DisposeHandle((Handle
)(*list
)->listDefProc
);
96 (*list
)->listDefProc
= NULL
;
101 static PyObject
*List_Error
;
103 /* ------------------------ Object type List ------------------------ */
105 PyTypeObject List_Type
;
107 #define ListObj_Check(x) ((x)->ob_type == &List_Type)
109 typedef struct ListObject
{
111 ListHandle ob_itself
;
112 PyObject
*ob_ldef_func
;
113 int ob_have_ldef_stub
;
114 int ob_must_be_disposed
;
117 PyObject
*ListObj_New(ListHandle itself
)
120 if (itself
== NULL
) {
121 PyErr_SetString(List_Error
,"Cannot create null List");
124 it
= PyObject_NEW(ListObject
, &List_Type
);
125 if (it
== NULL
) return NULL
;
126 it
->ob_itself
= itself
;
127 it
->ob_ldef_func
= NULL
;
128 it
->ob_have_ldef_stub
= 0;
129 it
->ob_must_be_disposed
= 1;
130 SetListRefCon(itself
, (long)it
);
131 return (PyObject
*)it
;
133 int ListObj_Convert(PyObject
*v
, ListHandle
*p_itself
)
135 if (!ListObj_Check(v
))
137 PyErr_SetString(PyExc_TypeError
, "List required");
140 *p_itself
= ((ListObject
*)v
)->ob_itself
;
144 static void ListObj_dealloc(ListObject
*self
)
146 Py_XDECREF(self
->ob_ldef_func
);
147 self
->ob_ldef_func
= NULL
;
148 #if !TARGET_API_MAC_CARBON
149 if (self
->ob_have_ldef_stub
) removeLDEFStub(self
->ob_itself
);
151 SetListRefCon(self
->ob_itself
, (long)0);
152 if (self
->ob_must_be_disposed
&& self
->ob_itself
) LDispose(self
->ob_itself
);
156 static PyObject
*ListObj_LAddColumn(ListObject
*_self
, PyObject
*_args
)
158 PyObject
*_res
= NULL
;
162 if (!PyArg_ParseTuple(_args
, "hh",
166 _rv
= LAddColumn(count
,
169 _res
= Py_BuildValue("h",
174 static PyObject
*ListObj_LAddRow(ListObject
*_self
, PyObject
*_args
)
176 PyObject
*_res
= NULL
;
180 if (!PyArg_ParseTuple(_args
, "hh",
187 _res
= Py_BuildValue("h",
192 static PyObject
*ListObj_LDelColumn(ListObject
*_self
, PyObject
*_args
)
194 PyObject
*_res
= NULL
;
197 if (!PyArg_ParseTuple(_args
, "hh",
209 static PyObject
*ListObj_LDelRow(ListObject
*_self
, PyObject
*_args
)
211 PyObject
*_res
= NULL
;
214 if (!PyArg_ParseTuple(_args
, "hh",
226 static PyObject
*ListObj_LGetSelect(ListObject
*_self
, PyObject
*_args
)
228 PyObject
*_res
= NULL
;
232 if (!PyArg_ParseTuple(_args
, "bO&",
234 PyMac_GetPoint
, &theCell
))
236 _rv
= LGetSelect(next
,
239 _res
= Py_BuildValue("bO&",
241 PyMac_BuildPoint
, theCell
);
245 static PyObject
*ListObj_LLastClick(ListObject
*_self
, PyObject
*_args
)
247 PyObject
*_res
= NULL
;
249 if (!PyArg_ParseTuple(_args
, ""))
251 _rv
= LLastClick(_self
->ob_itself
);
252 _res
= Py_BuildValue("O&",
253 PyMac_BuildPoint
, _rv
);
257 static PyObject
*ListObj_LNextCell(ListObject
*_self
, PyObject
*_args
)
259 PyObject
*_res
= NULL
;
264 if (!PyArg_ParseTuple(_args
, "bbO&",
267 PyMac_GetPoint
, &theCell
))
269 _rv
= LNextCell(hNext
,
273 _res
= Py_BuildValue("bO&",
275 PyMac_BuildPoint
, theCell
);
279 static PyObject
*ListObj_LSize(ListObject
*_self
, PyObject
*_args
)
281 PyObject
*_res
= NULL
;
284 if (!PyArg_ParseTuple(_args
, "hh",
296 static PyObject
*ListObj_LSetDrawingMode(ListObject
*_self
, PyObject
*_args
)
298 PyObject
*_res
= NULL
;
300 if (!PyArg_ParseTuple(_args
, "b",
303 LSetDrawingMode(drawIt
,
310 static PyObject
*ListObj_LScroll(ListObject
*_self
, PyObject
*_args
)
312 PyObject
*_res
= NULL
;
315 if (!PyArg_ParseTuple(_args
, "hh",
327 static PyObject
*ListObj_LAutoScroll(ListObject
*_self
, PyObject
*_args
)
329 PyObject
*_res
= NULL
;
330 if (!PyArg_ParseTuple(_args
, ""))
332 LAutoScroll(_self
->ob_itself
);
338 static PyObject
*ListObj_LUpdate(ListObject
*_self
, PyObject
*_args
)
340 PyObject
*_res
= NULL
;
342 if (!PyArg_ParseTuple(_args
, "O&",
343 ResObj_Convert
, &theRgn
))
352 static PyObject
*ListObj_LActivate(ListObject
*_self
, PyObject
*_args
)
354 PyObject
*_res
= NULL
;
356 if (!PyArg_ParseTuple(_args
, "b",
366 static PyObject
*ListObj_LCellSize(ListObject
*_self
, PyObject
*_args
)
368 PyObject
*_res
= NULL
;
370 if (!PyArg_ParseTuple(_args
, "O&",
371 PyMac_GetPoint
, &cSize
))
380 static PyObject
*ListObj_LClick(ListObject
*_self
, PyObject
*_args
)
382 PyObject
*_res
= NULL
;
385 EventModifiers modifiers
;
386 if (!PyArg_ParseTuple(_args
, "O&H",
393 _res
= Py_BuildValue("b",
398 static PyObject
*ListObj_LAddToCell(ListObject
*_self
, PyObject
*_args
)
400 PyObject
*_res
= NULL
;
402 short dataPtr__len__
;
403 int dataPtr__in_len__
;
405 if (!PyArg_ParseTuple(_args
, "s#O&",
406 &dataPtr__in__
, &dataPtr__in_len__
,
407 PyMac_GetPoint
, &theCell
))
409 dataPtr__len__
= dataPtr__in_len__
;
410 LAddToCell(dataPtr__in__
, dataPtr__len__
,
418 static PyObject
*ListObj_LClrCell(ListObject
*_self
, PyObject
*_args
)
420 PyObject
*_res
= NULL
;
422 if (!PyArg_ParseTuple(_args
, "O&",
423 PyMac_GetPoint
, &theCell
))
432 static PyObject
*ListObj_LGetCell(ListObject
*_self
, PyObject
*_args
)
434 PyObject
*_res
= NULL
;
435 char *dataPtr__out__
;
436 short dataPtr__len__
;
437 int dataPtr__in_len__
;
439 if (!PyArg_ParseTuple(_args
, "iO&",
441 PyMac_GetPoint
, &theCell
))
443 if ((dataPtr__out__
= malloc(dataPtr__in_len__
)) == NULL
)
446 goto dataPtr__error__
;
448 dataPtr__len__
= dataPtr__in_len__
;
449 LGetCell(dataPtr__out__
, &dataPtr__len__
,
452 _res
= Py_BuildValue("s#",
453 dataPtr__out__
, (int)dataPtr__len__
);
454 free(dataPtr__out__
);
459 static PyObject
*ListObj_LRect(ListObject
*_self
, PyObject
*_args
)
461 PyObject
*_res
= NULL
;
464 if (!PyArg_ParseTuple(_args
, "O&",
465 PyMac_GetPoint
, &theCell
))
470 _res
= Py_BuildValue("O&",
471 PyMac_BuildRect
, &cellRect
);
475 static PyObject
*ListObj_LSetCell(ListObject
*_self
, PyObject
*_args
)
477 PyObject
*_res
= NULL
;
479 short dataPtr__len__
;
480 int dataPtr__in_len__
;
482 if (!PyArg_ParseTuple(_args
, "s#O&",
483 &dataPtr__in__
, &dataPtr__in_len__
,
484 PyMac_GetPoint
, &theCell
))
486 dataPtr__len__
= dataPtr__in_len__
;
487 LSetCell(dataPtr__in__
, dataPtr__len__
,
495 static PyObject
*ListObj_LSetSelect(ListObject
*_self
, PyObject
*_args
)
497 PyObject
*_res
= NULL
;
500 if (!PyArg_ParseTuple(_args
, "bO&",
502 PyMac_GetPoint
, &theCell
))
512 static PyObject
*ListObj_LDraw(ListObject
*_self
, PyObject
*_args
)
514 PyObject
*_res
= NULL
;
516 if (!PyArg_ParseTuple(_args
, "O&",
517 PyMac_GetPoint
, &theCell
))
526 static PyObject
*ListObj_LGetCellDataLocation(ListObject
*_self
, PyObject
*_args
)
528 PyObject
*_res
= NULL
;
532 if (!PyArg_ParseTuple(_args
, "O&",
533 PyMac_GetPoint
, &theCell
))
535 LGetCellDataLocation(&offset
,
539 _res
= Py_BuildValue("hh",
545 static PyObject
*ListObj_as_Resource(ListObject
*_self
, PyObject
*_args
)
547 PyObject
*_res
= NULL
;
549 if (!PyArg_ParseTuple(_args
, ""))
551 _rv
= as_Resource(_self
->ob_itself
);
552 _res
= Py_BuildValue("O&",
557 static PyMethodDef ListObj_methods
[] = {
558 {"LAddColumn", (PyCFunction
)ListObj_LAddColumn
, 1,
559 PyDoc_STR("(short count, short colNum) -> (short _rv)")},
560 {"LAddRow", (PyCFunction
)ListObj_LAddRow
, 1,
561 PyDoc_STR("(short count, short rowNum) -> (short _rv)")},
562 {"LDelColumn", (PyCFunction
)ListObj_LDelColumn
, 1,
563 PyDoc_STR("(short count, short colNum) -> None")},
564 {"LDelRow", (PyCFunction
)ListObj_LDelRow
, 1,
565 PyDoc_STR("(short count, short rowNum) -> None")},
566 {"LGetSelect", (PyCFunction
)ListObj_LGetSelect
, 1,
567 PyDoc_STR("(Boolean next, Point theCell) -> (Boolean _rv, Point theCell)")},
568 {"LLastClick", (PyCFunction
)ListObj_LLastClick
, 1,
569 PyDoc_STR("() -> (Point _rv)")},
570 {"LNextCell", (PyCFunction
)ListObj_LNextCell
, 1,
571 PyDoc_STR("(Boolean hNext, Boolean vNext, Point theCell) -> (Boolean _rv, Point theCell)")},
572 {"LSize", (PyCFunction
)ListObj_LSize
, 1,
573 PyDoc_STR("(short listWidth, short listHeight) -> None")},
574 {"LSetDrawingMode", (PyCFunction
)ListObj_LSetDrawingMode
, 1,
575 PyDoc_STR("(Boolean drawIt) -> None")},
576 {"LScroll", (PyCFunction
)ListObj_LScroll
, 1,
577 PyDoc_STR("(short dCols, short dRows) -> None")},
578 {"LAutoScroll", (PyCFunction
)ListObj_LAutoScroll
, 1,
579 PyDoc_STR("() -> None")},
580 {"LUpdate", (PyCFunction
)ListObj_LUpdate
, 1,
581 PyDoc_STR("(RgnHandle theRgn) -> None")},
582 {"LActivate", (PyCFunction
)ListObj_LActivate
, 1,
583 PyDoc_STR("(Boolean act) -> None")},
584 {"LCellSize", (PyCFunction
)ListObj_LCellSize
, 1,
585 PyDoc_STR("(Point cSize) -> None")},
586 {"LClick", (PyCFunction
)ListObj_LClick
, 1,
587 PyDoc_STR("(Point pt, EventModifiers modifiers) -> (Boolean _rv)")},
588 {"LAddToCell", (PyCFunction
)ListObj_LAddToCell
, 1,
589 PyDoc_STR("(Buffer dataPtr, Point theCell) -> None")},
590 {"LClrCell", (PyCFunction
)ListObj_LClrCell
, 1,
591 PyDoc_STR("(Point theCell) -> None")},
592 {"LGetCell", (PyCFunction
)ListObj_LGetCell
, 1,
593 PyDoc_STR("(Buffer dataPtr, Point theCell) -> (Buffer dataPtr)")},
594 {"LRect", (PyCFunction
)ListObj_LRect
, 1,
595 PyDoc_STR("(Point theCell) -> (Rect cellRect)")},
596 {"LSetCell", (PyCFunction
)ListObj_LSetCell
, 1,
597 PyDoc_STR("(Buffer dataPtr, Point theCell) -> None")},
598 {"LSetSelect", (PyCFunction
)ListObj_LSetSelect
, 1,
599 PyDoc_STR("(Boolean setIt, Point theCell) -> None")},
600 {"LDraw", (PyCFunction
)ListObj_LDraw
, 1,
601 PyDoc_STR("(Point theCell) -> None")},
602 {"LGetCellDataLocation", (PyCFunction
)ListObj_LGetCellDataLocation
, 1,
603 PyDoc_STR("(Point theCell) -> (short offset, short len)")},
604 {"as_Resource", (PyCFunction
)ListObj_as_Resource
, 1,
605 PyDoc_STR("() -> (Handle _rv)")},
609 PyMethodChain ListObj_chain
= { ListObj_methods
, NULL
};
611 static PyObject
*ListObj_getattr(ListObject
*self
, char *name
)
614 if ( strcmp(name
, "listFlags") == 0 )
615 return Py_BuildValue("l", (long)GetListFlags(self
->ob_itself
) & 0xff);
616 if ( strcmp(name
, "selFlags") == 0 )
617 return Py_BuildValue("l", (long)GetListSelectionFlags(self
->ob_itself
) & 0xff);
618 if ( strcmp(name
, "cellSize") == 0 )
619 return Py_BuildValue("O&", PyMac_BuildPoint
, (*self
->ob_itself
)->cellSize
);
621 return Py_FindMethodInChain(&ListObj_chain
, (PyObject
*)self
, name
);
625 ListObj_setattr(ListObject
*self
, char *name
, PyObject
*value
)
630 if ( value
== NULL
) {
631 PyErr_SetString(PyExc_AttributeError
, "Cannot delete attribute");
634 if (strcmp(name
, "listFlags") == 0 )
635 err
= PyArg_Parse(value
, "B", &(*self
->ob_itself
)->listFlags
);
636 else if (strcmp(name
, "selFlags") == 0 )
637 err
= PyArg_Parse(value
, "B", &(*self
->ob_itself
)->selFlags
);
638 else if (strcmp(name
, "cellSize") == 0 )
639 err
= PyArg_Parse(value
, "O&", PyMac_GetPoint
, &(*self
->ob_itself
)->cellSize
);
641 PyErr_SetString(PyExc_AttributeError
, "No such attribute");
647 #define ListObj_compare NULL
649 #define ListObj_repr NULL
651 #define ListObj_hash NULL
653 PyTypeObject List_Type
= {
654 PyObject_HEAD_INIT(NULL
)
656 "_List.List", /*tp_name*/
657 sizeof(ListObject
), /*tp_basicsize*/
660 (destructor
) ListObj_dealloc
, /*tp_dealloc*/
662 (getattrfunc
) ListObj_getattr
, /*tp_getattr*/
663 (setattrfunc
) ListObj_setattr
, /*tp_setattr*/
664 (cmpfunc
) ListObj_compare
, /*tp_compare*/
665 (reprfunc
) ListObj_repr
, /*tp_repr*/
666 (PyNumberMethods
*)0, /* tp_as_number */
667 (PySequenceMethods
*)0, /* tp_as_sequence */
668 (PyMappingMethods
*)0, /* tp_as_mapping */
669 (hashfunc
) ListObj_hash
, /*tp_hash*/
672 /* ---------------------- End object type List ---------------------- */
675 static PyObject
*List_CreateCustomList(PyObject
*_self
, PyObject
*_args
)
677 PyObject
*_res
= NULL
;
682 PyObject
*listDefFunc
;
691 if (!PyArg_ParseTuple(_args
, "O&O&O&(iO)O&bbbb",
692 PyMac_GetRect
, &rView
,
693 PyMac_GetRect
, &dataBounds
,
694 PyMac_GetPoint
, &cellSize
,
695 &theSpec
.defType
, &listDefFunc
,
696 WinObj_Convert
, &theWindow
,
704 #if TARGET_API_MAC_CARBON
705 /* Carbon applications use the CreateCustomList API */
706 theSpec
.u
.userProc
= myListDefFunctionUPP
;
707 CreateCustomList(&rView
,
719 /* pre-Carbon applications set the address in the LDEF
720 to a routine descriptor referring to their list
721 definition routine. */
722 outList
= LNew(&rView
,
727 drawIt
, /* XXX must be false */
731 if (installLDEFStub(outList
) != noErr
) {
732 PyErr_SetString(PyExc_MemoryError
, "can't create LDEF stub");
737 _res
= ListObj_New(outList
);
740 Py_INCREF(listDefFunc
);
741 ((ListObject
*)_res
)->ob_ldef_func
= listDefFunc
;
742 #if !TARGET_API_MAC_CARBON
743 ((ListObject
*)_res
)->ob_have_ldef_stub
= 1;
748 static PyObject
*List_LNew(PyObject
*_self
, PyObject
*_args
)
750 PyObject
*_res
= NULL
;
761 if (!PyArg_ParseTuple(_args
, "O&O&O&hO&bbbb",
762 PyMac_GetRect
, &rView
,
763 PyMac_GetRect
, &dataBounds
,
764 PyMac_GetPoint
, &cSize
,
766 WinObj_Convert
, &theWindow
,
781 _res
= Py_BuildValue("O&",
786 static PyObject
*List_GetListPort(PyObject
*_self
, PyObject
*_args
)
788 PyObject
*_res
= NULL
;
791 if (!PyArg_ParseTuple(_args
, "O&",
792 ListObj_Convert
, &list
))
794 _rv
= GetListPort(list
);
795 _res
= Py_BuildValue("O&",
800 static PyObject
*List_GetListVerticalScrollBar(PyObject
*_self
, PyObject
*_args
)
802 PyObject
*_res
= NULL
;
805 if (!PyArg_ParseTuple(_args
, "O&",
806 ListObj_Convert
, &list
))
808 _rv
= GetListVerticalScrollBar(list
);
809 _res
= Py_BuildValue("O&",
814 static PyObject
*List_GetListHorizontalScrollBar(PyObject
*_self
, PyObject
*_args
)
816 PyObject
*_res
= NULL
;
819 if (!PyArg_ParseTuple(_args
, "O&",
820 ListObj_Convert
, &list
))
822 _rv
= GetListHorizontalScrollBar(list
);
823 _res
= Py_BuildValue("O&",
828 static PyObject
*List_GetListActive(PyObject
*_self
, PyObject
*_args
)
830 PyObject
*_res
= NULL
;
833 if (!PyArg_ParseTuple(_args
, "O&",
834 ListObj_Convert
, &list
))
836 _rv
= GetListActive(list
);
837 _res
= Py_BuildValue("b",
842 static PyObject
*List_GetListClickTime(PyObject
*_self
, PyObject
*_args
)
844 PyObject
*_res
= NULL
;
847 if (!PyArg_ParseTuple(_args
, "O&",
848 ListObj_Convert
, &list
))
850 _rv
= GetListClickTime(list
);
851 _res
= Py_BuildValue("l",
856 static PyObject
*List_GetListRefCon(PyObject
*_self
, PyObject
*_args
)
858 PyObject
*_res
= NULL
;
861 if (!PyArg_ParseTuple(_args
, "O&",
862 ListObj_Convert
, &list
))
864 _rv
= GetListRefCon(list
);
865 _res
= Py_BuildValue("l",
870 static PyObject
*List_GetListDefinition(PyObject
*_self
, PyObject
*_args
)
872 PyObject
*_res
= NULL
;
875 if (!PyArg_ParseTuple(_args
, "O&",
876 ListObj_Convert
, &list
))
878 _rv
= GetListDefinition(list
);
879 _res
= Py_BuildValue("O&",
884 static PyObject
*List_GetListUserHandle(PyObject
*_self
, PyObject
*_args
)
886 PyObject
*_res
= NULL
;
889 if (!PyArg_ParseTuple(_args
, "O&",
890 ListObj_Convert
, &list
))
892 _rv
= GetListUserHandle(list
);
893 _res
= Py_BuildValue("O&",
898 static PyObject
*List_GetListDataHandle(PyObject
*_self
, PyObject
*_args
)
900 PyObject
*_res
= NULL
;
903 if (!PyArg_ParseTuple(_args
, "O&",
904 ListObj_Convert
, &list
))
906 _rv
= GetListDataHandle(list
);
907 _res
= Py_BuildValue("O&",
912 static PyObject
*List_GetListFlags(PyObject
*_self
, PyObject
*_args
)
914 PyObject
*_res
= NULL
;
917 if (!PyArg_ParseTuple(_args
, "O&",
918 ListObj_Convert
, &list
))
920 _rv
= GetListFlags(list
);
921 _res
= Py_BuildValue("l",
926 static PyObject
*List_GetListSelectionFlags(PyObject
*_self
, PyObject
*_args
)
928 PyObject
*_res
= NULL
;
931 if (!PyArg_ParseTuple(_args
, "O&",
932 ListObj_Convert
, &list
))
934 _rv
= GetListSelectionFlags(list
);
935 _res
= Py_BuildValue("l",
940 static PyObject
*List_SetListViewBounds(PyObject
*_self
, PyObject
*_args
)
942 PyObject
*_res
= NULL
;
945 if (!PyArg_ParseTuple(_args
, "O&O&",
946 ListObj_Convert
, &list
,
947 PyMac_GetRect
, &view
))
949 SetListViewBounds(list
,
956 static PyObject
*List_SetListPort(PyObject
*_self
, PyObject
*_args
)
958 PyObject
*_res
= NULL
;
961 if (!PyArg_ParseTuple(_args
, "O&O&",
962 ListObj_Convert
, &list
,
963 GrafObj_Convert
, &port
))
972 static PyObject
*List_SetListCellIndent(PyObject
*_self
, PyObject
*_args
)
974 PyObject
*_res
= NULL
;
977 if (!PyArg_ParseTuple(_args
, "O&O&",
978 ListObj_Convert
, &list
,
979 PyMac_GetPoint
, &indent
))
981 SetListCellIndent(list
,
988 static PyObject
*List_SetListClickTime(PyObject
*_self
, PyObject
*_args
)
990 PyObject
*_res
= NULL
;
993 if (!PyArg_ParseTuple(_args
, "O&l",
994 ListObj_Convert
, &list
,
997 SetListClickTime(list
,
1004 static PyObject
*List_SetListRefCon(PyObject
*_self
, PyObject
*_args
)
1006 PyObject
*_res
= NULL
;
1009 if (!PyArg_ParseTuple(_args
, "O&l",
1010 ListObj_Convert
, &list
,
1020 static PyObject
*List_SetListUserHandle(PyObject
*_self
, PyObject
*_args
)
1022 PyObject
*_res
= NULL
;
1025 if (!PyArg_ParseTuple(_args
, "O&O&",
1026 ListObj_Convert
, &list
,
1027 ResObj_Convert
, &userHandle
))
1029 SetListUserHandle(list
,
1036 static PyObject
*List_SetListFlags(PyObject
*_self
, PyObject
*_args
)
1038 PyObject
*_res
= NULL
;
1040 OptionBits listFlags
;
1041 if (!PyArg_ParseTuple(_args
, "O&l",
1042 ListObj_Convert
, &list
,
1052 static PyObject
*List_SetListSelectionFlags(PyObject
*_self
, PyObject
*_args
)
1054 PyObject
*_res
= NULL
;
1056 OptionBits selectionFlags
;
1057 if (!PyArg_ParseTuple(_args
, "O&l",
1058 ListObj_Convert
, &list
,
1061 SetListSelectionFlags(list
,
1068 static PyObject
*List_as_List(PyObject
*_self
, PyObject
*_args
)
1070 PyObject
*_res
= NULL
;
1074 if (!PyArg_ParseTuple(_args
, "O&", ResObj_Convert
, &h
))
1076 l
= (ListObject
*)ListObj_New(as_List(h
));
1077 l
->ob_must_be_disposed
= 0;
1078 _res
= Py_BuildValue("O", l
);
1083 static PyMethodDef List_methods
[] = {
1084 {"CreateCustomList", (PyCFunction
)List_CreateCustomList
, 1,
1085 PyDoc_STR("(Rect rView, Rect dataBounds, Point cellSize, ListDefSpec theSpec, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle outList)")},
1086 {"LNew", (PyCFunction
)List_LNew
, 1,
1087 PyDoc_STR("(Rect rView, Rect dataBounds, Point cSize, short theProc, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle _rv)")},
1088 {"GetListPort", (PyCFunction
)List_GetListPort
, 1,
1089 PyDoc_STR("(ListHandle list) -> (CGrafPtr _rv)")},
1090 {"GetListVerticalScrollBar", (PyCFunction
)List_GetListVerticalScrollBar
, 1,
1091 PyDoc_STR("(ListHandle list) -> (ControlHandle _rv)")},
1092 {"GetListHorizontalScrollBar", (PyCFunction
)List_GetListHorizontalScrollBar
, 1,
1093 PyDoc_STR("(ListHandle list) -> (ControlHandle _rv)")},
1094 {"GetListActive", (PyCFunction
)List_GetListActive
, 1,
1095 PyDoc_STR("(ListHandle list) -> (Boolean _rv)")},
1096 {"GetListClickTime", (PyCFunction
)List_GetListClickTime
, 1,
1097 PyDoc_STR("(ListHandle list) -> (SInt32 _rv)")},
1098 {"GetListRefCon", (PyCFunction
)List_GetListRefCon
, 1,
1099 PyDoc_STR("(ListHandle list) -> (SInt32 _rv)")},
1100 {"GetListDefinition", (PyCFunction
)List_GetListDefinition
, 1,
1101 PyDoc_STR("(ListHandle list) -> (Handle _rv)")},
1102 {"GetListUserHandle", (PyCFunction
)List_GetListUserHandle
, 1,
1103 PyDoc_STR("(ListHandle list) -> (Handle _rv)")},
1104 {"GetListDataHandle", (PyCFunction
)List_GetListDataHandle
, 1,
1105 PyDoc_STR("(ListHandle list) -> (DataHandle _rv)")},
1106 {"GetListFlags", (PyCFunction
)List_GetListFlags
, 1,
1107 PyDoc_STR("(ListHandle list) -> (OptionBits _rv)")},
1108 {"GetListSelectionFlags", (PyCFunction
)List_GetListSelectionFlags
, 1,
1109 PyDoc_STR("(ListHandle list) -> (OptionBits _rv)")},
1110 {"SetListViewBounds", (PyCFunction
)List_SetListViewBounds
, 1,
1111 PyDoc_STR("(ListHandle list, Rect view) -> None")},
1112 {"SetListPort", (PyCFunction
)List_SetListPort
, 1,
1113 PyDoc_STR("(ListHandle list, CGrafPtr port) -> None")},
1114 {"SetListCellIndent", (PyCFunction
)List_SetListCellIndent
, 1,
1115 PyDoc_STR("(ListHandle list, Point indent) -> None")},
1116 {"SetListClickTime", (PyCFunction
)List_SetListClickTime
, 1,
1117 PyDoc_STR("(ListHandle list, SInt32 time) -> None")},
1118 {"SetListRefCon", (PyCFunction
)List_SetListRefCon
, 1,
1119 PyDoc_STR("(ListHandle list, SInt32 refCon) -> None")},
1120 {"SetListUserHandle", (PyCFunction
)List_SetListUserHandle
, 1,
1121 PyDoc_STR("(ListHandle list, Handle userHandle) -> None")},
1122 {"SetListFlags", (PyCFunction
)List_SetListFlags
, 1,
1123 PyDoc_STR("(ListHandle list, OptionBits listFlags) -> None")},
1124 {"SetListSelectionFlags", (PyCFunction
)List_SetListSelectionFlags
, 1,
1125 PyDoc_STR("(ListHandle list, OptionBits selectionFlags) -> None")},
1126 {"as_List", (PyCFunction
)List_as_List
, 1,
1127 PyDoc_STR("(Resource)->List.\nReturns List object (which is not auto-freed!)")},
1133 static void myListDefFunction(SInt16 message
,
1141 PyObject
*listDefFunc
, *args
, *rv
=NULL
;
1144 self
= (ListObject
*)GetListRefCon(theList
);
1145 if (self
== NULL
|| self
->ob_itself
!= theList
)
1146 return; /* nothing we can do */
1147 listDefFunc
= self
->ob_ldef_func
;
1148 if (listDefFunc
== NULL
)
1149 return; /* nothing we can do */
1150 args
= Py_BuildValue("hbO&O&hhO", message
,
1152 PyMac_BuildRect
, cellRect
,
1153 PyMac_BuildPoint
, theCell
,
1158 rv
= PyEval_CallObject(listDefFunc
, args
);
1162 PySys_WriteStderr("error in list definition callback:\n");
1170 void init_List(void)
1177 myListDefFunctionUPP
= NewListDefUPP((ListDefProcPtr
)myListDefFunction
);
1179 PyMac_INIT_TOOLBOX_OBJECT_NEW(ListHandle
, ListObj_New
);
1180 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ListHandle
, ListObj_Convert
);
1183 m
= Py_InitModule("_List", List_methods
);
1184 d
= PyModule_GetDict(m
);
1185 List_Error
= PyMac_GetOSErrException();
1186 if (List_Error
== NULL
||
1187 PyDict_SetItemString(d
, "Error", List_Error
) != 0)
1189 List_Type
.ob_type
= &PyType_Type
;
1190 Py_INCREF(&List_Type
);
1191 if (PyDict_SetItemString(d
, "ListType", (PyObject
*)&List_Type
) != 0)
1192 Py_FatalError("can't initialize ListType");
1195 /* ======================== End module _List ======================== */