This commit was manufactured by cvs2svn to create tag 'r212c1'.
[python/dscho.git] / Mac / Modules / list / Listmodule.c
blob6e2861341290ff393a4fc5d3c3e6863eec77685e
2 /* ========================== Module List =========================== */
4 #include "Python.h"
8 #include "macglue.h"
9 #include "pymactoolbox.h"
11 #ifdef WITHOUT_FRAMEWORKS
12 #include <Lists.h>
13 #else
14 #include <Carbon/Carbon.h>
15 #endif
17 #ifdef USE_TOOLBOX_OBJECT_GLUE
18 extern PyObject *_ListObj_New(ListHandle);
19 extern int _ListObj_Convert(PyObject *, ListHandle *);
21 #define ListObj_New _ListObj_New
22 #define ListObj_Convert _ListObj_Convert
23 #endif
25 #if !ACCESSOR_CALLS_ARE_FUNCTIONS
26 #define GetListPort(list) ((CGrafPtr)(*(list))->port)
27 #define GetListVerticalScrollBar(list) ((*(list))->vScroll)
28 #define GetListHorizontalScrollBar(list) ((*(list))->hScroll)
29 #define GetListActive(list) ((*(list))->lActive)
30 #define GetListClickTime(list) ((*(list))->clikTime)
31 #define GetListRefCon(list) ((*(list))->refCon)
32 #define GetListDefinition(list) ((*(list))->listDefProc) /* XXX Is this indeed the same? */
33 #define GetListUserHandle(list) ((*(list))->userHandle)
34 #define GetListDataHandle(list) ((*(list))->cells)
35 #define GetListFlags(list) ((*(list))->listFlags)
36 #define GetListSelectionFlags(list) ((*(list))->selFlags)
37 #define SetListViewBounds(list, bounds) (((*(list))->rView) = *(bounds))
39 #define SetListPort(list, port) (((*(list))->port) = (GrafPtr)(port))
40 #define SetListCellIndent(list, ind) (((*(list))->indent) = *(ind))
41 #define SetListClickTime(list, time) (((*(list))->clikTime) = (time))
42 #define SetListLastClick(list, click) (((*(list)->lastClick) = *(click))
43 #define SetListRefCon(list, refcon) (((*(list))->refCon) = (refcon))
44 #define SetListUserHandle(list, handle) (((*(list))->userHandle) = (handle))
45 #define SetListFlags(list, flags) (((*(list))->listFlags) = (flags))
46 #define SetListSelectionFlags(list, flags) (((*(list))->selFlags) = (flags))
48 #endif
50 #define as_List(x) ((ListHandle)x)
51 #define as_Resource(lh) ((Handle)lh)
53 static PyObject *List_Error;
55 /* ------------------------ Object type List ------------------------ */
57 PyTypeObject List_Type;
59 #define ListObj_Check(x) ((x)->ob_type == &List_Type)
61 typedef struct ListObject {
62 PyObject_HEAD
63 ListHandle ob_itself;
64 int ob_must_be_disposed;
65 } ListObject;
67 PyObject *ListObj_New(ListHandle itself)
69 ListObject *it;
70 if (itself == NULL) {
71 PyErr_SetString(List_Error,"Cannot create null List");
72 return NULL;
74 it = PyObject_NEW(ListObject, &List_Type);
75 if (it == NULL) return NULL;
76 it->ob_itself = itself;
77 it->ob_must_be_disposed = 1;
78 return (PyObject *)it;
80 ListObj_Convert(PyObject *v, ListHandle *p_itself)
82 if (!ListObj_Check(v))
84 PyErr_SetString(PyExc_TypeError, "List required");
85 return 0;
87 *p_itself = ((ListObject *)v)->ob_itself;
88 return 1;
91 static void ListObj_dealloc(ListObject *self)
93 if (self->ob_must_be_disposed && self->ob_itself) LDispose(self->ob_itself);
94 PyMem_DEL(self);
97 static PyObject *ListObj_LAddColumn(ListObject *_self, PyObject *_args)
99 PyObject *_res = NULL;
100 short _rv;
101 short count;
102 short colNum;
103 if (!PyArg_ParseTuple(_args, "hh",
104 &count,
105 &colNum))
106 return NULL;
107 _rv = LAddColumn(count,
108 colNum,
109 _self->ob_itself);
110 _res = Py_BuildValue("h",
111 _rv);
112 return _res;
115 static PyObject *ListObj_LAddRow(ListObject *_self, PyObject *_args)
117 PyObject *_res = NULL;
118 short _rv;
119 short count;
120 short rowNum;
121 if (!PyArg_ParseTuple(_args, "hh",
122 &count,
123 &rowNum))
124 return NULL;
125 _rv = LAddRow(count,
126 rowNum,
127 _self->ob_itself);
128 _res = Py_BuildValue("h",
129 _rv);
130 return _res;
133 static PyObject *ListObj_LDelColumn(ListObject *_self, PyObject *_args)
135 PyObject *_res = NULL;
136 short count;
137 short colNum;
138 if (!PyArg_ParseTuple(_args, "hh",
139 &count,
140 &colNum))
141 return NULL;
142 LDelColumn(count,
143 colNum,
144 _self->ob_itself);
145 Py_INCREF(Py_None);
146 _res = Py_None;
147 return _res;
150 static PyObject *ListObj_LDelRow(ListObject *_self, PyObject *_args)
152 PyObject *_res = NULL;
153 short count;
154 short rowNum;
155 if (!PyArg_ParseTuple(_args, "hh",
156 &count,
157 &rowNum))
158 return NULL;
159 LDelRow(count,
160 rowNum,
161 _self->ob_itself);
162 Py_INCREF(Py_None);
163 _res = Py_None;
164 return _res;
167 static PyObject *ListObj_LGetSelect(ListObject *_self, PyObject *_args)
169 PyObject *_res = NULL;
170 Boolean _rv;
171 Boolean next;
172 Point theCell;
173 if (!PyArg_ParseTuple(_args, "bO&",
174 &next,
175 PyMac_GetPoint, &theCell))
176 return NULL;
177 _rv = LGetSelect(next,
178 &theCell,
179 _self->ob_itself);
180 _res = Py_BuildValue("bO&",
181 _rv,
182 PyMac_BuildPoint, theCell);
183 return _res;
186 static PyObject *ListObj_LLastClick(ListObject *_self, PyObject *_args)
188 PyObject *_res = NULL;
189 Point _rv;
190 if (!PyArg_ParseTuple(_args, ""))
191 return NULL;
192 _rv = LLastClick(_self->ob_itself);
193 _res = Py_BuildValue("O&",
194 PyMac_BuildPoint, _rv);
195 return _res;
198 static PyObject *ListObj_LNextCell(ListObject *_self, PyObject *_args)
200 PyObject *_res = NULL;
201 Boolean _rv;
202 Boolean hNext;
203 Boolean vNext;
204 Point theCell;
205 if (!PyArg_ParseTuple(_args, "bbO&",
206 &hNext,
207 &vNext,
208 PyMac_GetPoint, &theCell))
209 return NULL;
210 _rv = LNextCell(hNext,
211 vNext,
212 &theCell,
213 _self->ob_itself);
214 _res = Py_BuildValue("bO&",
215 _rv,
216 PyMac_BuildPoint, theCell);
217 return _res;
220 static PyObject *ListObj_LSize(ListObject *_self, PyObject *_args)
222 PyObject *_res = NULL;
223 short listWidth;
224 short listHeight;
225 if (!PyArg_ParseTuple(_args, "hh",
226 &listWidth,
227 &listHeight))
228 return NULL;
229 LSize(listWidth,
230 listHeight,
231 _self->ob_itself);
232 Py_INCREF(Py_None);
233 _res = Py_None;
234 return _res;
237 static PyObject *ListObj_LSetDrawingMode(ListObject *_self, PyObject *_args)
239 PyObject *_res = NULL;
240 Boolean drawIt;
241 if (!PyArg_ParseTuple(_args, "b",
242 &drawIt))
243 return NULL;
244 LSetDrawingMode(drawIt,
245 _self->ob_itself);
246 Py_INCREF(Py_None);
247 _res = Py_None;
248 return _res;
251 static PyObject *ListObj_LScroll(ListObject *_self, PyObject *_args)
253 PyObject *_res = NULL;
254 short dCols;
255 short dRows;
256 if (!PyArg_ParseTuple(_args, "hh",
257 &dCols,
258 &dRows))
259 return NULL;
260 LScroll(dCols,
261 dRows,
262 _self->ob_itself);
263 Py_INCREF(Py_None);
264 _res = Py_None;
265 return _res;
268 static PyObject *ListObj_LAutoScroll(ListObject *_self, PyObject *_args)
270 PyObject *_res = NULL;
271 if (!PyArg_ParseTuple(_args, ""))
272 return NULL;
273 LAutoScroll(_self->ob_itself);
274 Py_INCREF(Py_None);
275 _res = Py_None;
276 return _res;
279 static PyObject *ListObj_LUpdate(ListObject *_self, PyObject *_args)
281 PyObject *_res = NULL;
282 RgnHandle theRgn;
283 if (!PyArg_ParseTuple(_args, "O&",
284 ResObj_Convert, &theRgn))
285 return NULL;
286 LUpdate(theRgn,
287 _self->ob_itself);
288 Py_INCREF(Py_None);
289 _res = Py_None;
290 return _res;
293 static PyObject *ListObj_LActivate(ListObject *_self, PyObject *_args)
295 PyObject *_res = NULL;
296 Boolean act;
297 if (!PyArg_ParseTuple(_args, "b",
298 &act))
299 return NULL;
300 LActivate(act,
301 _self->ob_itself);
302 Py_INCREF(Py_None);
303 _res = Py_None;
304 return _res;
307 static PyObject *ListObj_LCellSize(ListObject *_self, PyObject *_args)
309 PyObject *_res = NULL;
310 Point cSize;
311 if (!PyArg_ParseTuple(_args, "O&",
312 PyMac_GetPoint, &cSize))
313 return NULL;
314 LCellSize(cSize,
315 _self->ob_itself);
316 Py_INCREF(Py_None);
317 _res = Py_None;
318 return _res;
321 static PyObject *ListObj_LClick(ListObject *_self, PyObject *_args)
323 PyObject *_res = NULL;
324 Boolean _rv;
325 Point pt;
326 short modifiers;
327 if (!PyArg_ParseTuple(_args, "O&h",
328 PyMac_GetPoint, &pt,
329 &modifiers))
330 return NULL;
331 _rv = LClick(pt,
332 modifiers,
333 _self->ob_itself);
334 _res = Py_BuildValue("b",
335 _rv);
336 return _res;
339 static PyObject *ListObj_LAddToCell(ListObject *_self, PyObject *_args)
341 PyObject *_res = NULL;
342 char *dataPtr__in__;
343 short dataPtr__len__;
344 int dataPtr__in_len__;
345 Point theCell;
346 if (!PyArg_ParseTuple(_args, "s#O&",
347 &dataPtr__in__, &dataPtr__in_len__,
348 PyMac_GetPoint, &theCell))
349 return NULL;
350 dataPtr__len__ = dataPtr__in_len__;
351 LAddToCell(dataPtr__in__, dataPtr__len__,
352 theCell,
353 _self->ob_itself);
354 Py_INCREF(Py_None);
355 _res = Py_None;
356 dataPtr__error__: ;
357 return _res;
360 static PyObject *ListObj_LClrCell(ListObject *_self, PyObject *_args)
362 PyObject *_res = NULL;
363 Point theCell;
364 if (!PyArg_ParseTuple(_args, "O&",
365 PyMac_GetPoint, &theCell))
366 return NULL;
367 LClrCell(theCell,
368 _self->ob_itself);
369 Py_INCREF(Py_None);
370 _res = Py_None;
371 return _res;
374 static PyObject *ListObj_LGetCell(ListObject *_self, PyObject *_args)
376 PyObject *_res = NULL;
377 char *dataPtr__out__;
378 short dataPtr__len__;
379 int dataPtr__in_len__;
380 Point theCell;
381 if (!PyArg_ParseTuple(_args, "iO&",
382 &dataPtr__in_len__,
383 PyMac_GetPoint, &theCell))
384 return NULL;
385 if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
387 PyErr_NoMemory();
388 goto dataPtr__error__;
390 dataPtr__len__ = dataPtr__in_len__;
391 LGetCell(dataPtr__out__, &dataPtr__len__,
392 theCell,
393 _self->ob_itself);
394 _res = Py_BuildValue("s#",
395 dataPtr__out__, (int)dataPtr__len__);
396 free(dataPtr__out__);
397 dataPtr__error__: ;
398 return _res;
401 static PyObject *ListObj_LRect(ListObject *_self, PyObject *_args)
403 PyObject *_res = NULL;
404 Rect cellRect;
405 Point theCell;
406 if (!PyArg_ParseTuple(_args, "O&",
407 PyMac_GetPoint, &theCell))
408 return NULL;
409 LRect(&cellRect,
410 theCell,
411 _self->ob_itself);
412 _res = Py_BuildValue("O&",
413 PyMac_BuildRect, &cellRect);
414 return _res;
417 static PyObject *ListObj_LSetCell(ListObject *_self, PyObject *_args)
419 PyObject *_res = NULL;
420 char *dataPtr__in__;
421 short dataPtr__len__;
422 int dataPtr__in_len__;
423 Point theCell;
424 if (!PyArg_ParseTuple(_args, "s#O&",
425 &dataPtr__in__, &dataPtr__in_len__,
426 PyMac_GetPoint, &theCell))
427 return NULL;
428 dataPtr__len__ = dataPtr__in_len__;
429 LSetCell(dataPtr__in__, dataPtr__len__,
430 theCell,
431 _self->ob_itself);
432 Py_INCREF(Py_None);
433 _res = Py_None;
434 dataPtr__error__: ;
435 return _res;
438 static PyObject *ListObj_LSetSelect(ListObject *_self, PyObject *_args)
440 PyObject *_res = NULL;
441 Boolean setIt;
442 Point theCell;
443 if (!PyArg_ParseTuple(_args, "bO&",
444 &setIt,
445 PyMac_GetPoint, &theCell))
446 return NULL;
447 LSetSelect(setIt,
448 theCell,
449 _self->ob_itself);
450 Py_INCREF(Py_None);
451 _res = Py_None;
452 return _res;
455 static PyObject *ListObj_LDraw(ListObject *_self, PyObject *_args)
457 PyObject *_res = NULL;
458 Point theCell;
459 if (!PyArg_ParseTuple(_args, "O&",
460 PyMac_GetPoint, &theCell))
461 return NULL;
462 LDraw(theCell,
463 _self->ob_itself);
464 Py_INCREF(Py_None);
465 _res = Py_None;
466 return _res;
469 static PyObject *ListObj_as_Resource(ListObject *_self, PyObject *_args)
471 PyObject *_res = NULL;
472 Handle _rv;
473 if (!PyArg_ParseTuple(_args, ""))
474 return NULL;
475 _rv = as_Resource(_self->ob_itself);
476 _res = Py_BuildValue("O&",
477 ResObj_New, _rv);
478 return _res;
481 static PyMethodDef ListObj_methods[] = {
482 {"LAddColumn", (PyCFunction)ListObj_LAddColumn, 1,
483 "(short count, short colNum) -> (short _rv)"},
484 {"LAddRow", (PyCFunction)ListObj_LAddRow, 1,
485 "(short count, short rowNum) -> (short _rv)"},
486 {"LDelColumn", (PyCFunction)ListObj_LDelColumn, 1,
487 "(short count, short colNum) -> None"},
488 {"LDelRow", (PyCFunction)ListObj_LDelRow, 1,
489 "(short count, short rowNum) -> None"},
490 {"LGetSelect", (PyCFunction)ListObj_LGetSelect, 1,
491 "(Boolean next, Point theCell) -> (Boolean _rv, Point theCell)"},
492 {"LLastClick", (PyCFunction)ListObj_LLastClick, 1,
493 "() -> (Point _rv)"},
494 {"LNextCell", (PyCFunction)ListObj_LNextCell, 1,
495 "(Boolean hNext, Boolean vNext, Point theCell) -> (Boolean _rv, Point theCell)"},
496 {"LSize", (PyCFunction)ListObj_LSize, 1,
497 "(short listWidth, short listHeight) -> None"},
498 {"LSetDrawingMode", (PyCFunction)ListObj_LSetDrawingMode, 1,
499 "(Boolean drawIt) -> None"},
500 {"LScroll", (PyCFunction)ListObj_LScroll, 1,
501 "(short dCols, short dRows) -> None"},
502 {"LAutoScroll", (PyCFunction)ListObj_LAutoScroll, 1,
503 "() -> None"},
504 {"LUpdate", (PyCFunction)ListObj_LUpdate, 1,
505 "(RgnHandle theRgn) -> None"},
506 {"LActivate", (PyCFunction)ListObj_LActivate, 1,
507 "(Boolean act) -> None"},
508 {"LCellSize", (PyCFunction)ListObj_LCellSize, 1,
509 "(Point cSize) -> None"},
510 {"LClick", (PyCFunction)ListObj_LClick, 1,
511 "(Point pt, short modifiers) -> (Boolean _rv)"},
512 {"LAddToCell", (PyCFunction)ListObj_LAddToCell, 1,
513 "(Buffer dataPtr, Point theCell) -> None"},
514 {"LClrCell", (PyCFunction)ListObj_LClrCell, 1,
515 "(Point theCell) -> None"},
516 {"LGetCell", (PyCFunction)ListObj_LGetCell, 1,
517 "(Buffer dataPtr, Point theCell) -> (Buffer dataPtr)"},
518 {"LRect", (PyCFunction)ListObj_LRect, 1,
519 "(Point theCell) -> (Rect cellRect)"},
520 {"LSetCell", (PyCFunction)ListObj_LSetCell, 1,
521 "(Buffer dataPtr, Point theCell) -> None"},
522 {"LSetSelect", (PyCFunction)ListObj_LSetSelect, 1,
523 "(Boolean setIt, Point theCell) -> None"},
524 {"LDraw", (PyCFunction)ListObj_LDraw, 1,
525 "(Point theCell) -> None"},
526 {"as_Resource", (PyCFunction)ListObj_as_Resource, 1,
527 "() -> (Handle _rv)"},
528 {NULL, NULL, 0}
531 PyMethodChain ListObj_chain = { ListObj_methods, NULL };
533 static PyObject *ListObj_getattr(ListObject *self, char *name)
536 /* XXXX Should we HLock() here?? */
537 if ( strcmp(name, "listFlags") == 0 )
538 return Py_BuildValue("l", (long)(*self->ob_itself)->listFlags & 0xff);
539 if ( strcmp(name, "selFlags") == 0 )
540 return Py_BuildValue("l", (long)(*self->ob_itself)->selFlags & 0xff);
542 return Py_FindMethodInChain(&ListObj_chain, (PyObject *)self, name);
545 static int
546 ListObj_setattr(ListObject *self, char *name, PyObject *value)
548 long intval;
550 if ( value == NULL || !PyInt_Check(value) )
551 return -1;
552 intval = PyInt_AsLong(value);
553 if (strcmp(name, "listFlags") == 0 ) {
554 /* XXXX Should we HLock the handle here?? */
555 (*self->ob_itself)->listFlags = intval;
556 return 0;
558 if (strcmp(name, "selFlags") == 0 ) {
559 (*self->ob_itself)->selFlags = intval;
560 return 0;
562 return -1;
566 #define ListObj_compare NULL
568 #define ListObj_repr NULL
570 #define ListObj_hash NULL
572 PyTypeObject List_Type = {
573 PyObject_HEAD_INIT(&PyType_Type)
574 0, /*ob_size*/
575 "List", /*tp_name*/
576 sizeof(ListObject), /*tp_basicsize*/
577 0, /*tp_itemsize*/
578 /* methods */
579 (destructor) ListObj_dealloc, /*tp_dealloc*/
580 0, /*tp_print*/
581 (getattrfunc) ListObj_getattr, /*tp_getattr*/
582 (setattrfunc) ListObj_setattr, /*tp_setattr*/
583 (cmpfunc) ListObj_compare, /*tp_compare*/
584 (reprfunc) ListObj_repr, /*tp_repr*/
585 (PyNumberMethods *)0, /* tp_as_number */
586 (PySequenceMethods *)0, /* tp_as_sequence */
587 (PyMappingMethods *)0, /* tp_as_mapping */
588 (hashfunc) ListObj_hash, /*tp_hash*/
591 /* ---------------------- End object type List ---------------------- */
594 static PyObject *List_LNew(PyObject *_self, PyObject *_args)
596 PyObject *_res = NULL;
597 ListHandle _rv;
598 Rect rView;
599 Rect dataBounds;
600 Point cSize;
601 short theProc;
602 WindowPtr theWindow;
603 Boolean drawIt;
604 Boolean hasGrow;
605 Boolean scrollHoriz;
606 Boolean scrollVert;
607 if (!PyArg_ParseTuple(_args, "O&O&O&hO&bbbb",
608 PyMac_GetRect, &rView,
609 PyMac_GetRect, &dataBounds,
610 PyMac_GetPoint, &cSize,
611 &theProc,
612 WinObj_Convert, &theWindow,
613 &drawIt,
614 &hasGrow,
615 &scrollHoriz,
616 &scrollVert))
617 return NULL;
618 _rv = LNew(&rView,
619 &dataBounds,
620 cSize,
621 theProc,
622 theWindow,
623 drawIt,
624 hasGrow,
625 scrollHoriz,
626 scrollVert);
627 _res = Py_BuildValue("O&",
628 ListObj_New, _rv);
629 return _res;
632 static PyObject *List_GetListPort(PyObject *_self, PyObject *_args)
634 PyObject *_res = NULL;
635 CGrafPtr _rv;
636 ListHandle list;
637 if (!PyArg_ParseTuple(_args, "O&",
638 ListObj_Convert, &list))
639 return NULL;
640 _rv = GetListPort(list);
641 _res = Py_BuildValue("O&",
642 GrafObj_New, _rv);
643 return _res;
646 static PyObject *List_GetListVerticalScrollBar(PyObject *_self, PyObject *_args)
648 PyObject *_res = NULL;
649 ControlHandle _rv;
650 ListHandle list;
651 if (!PyArg_ParseTuple(_args, "O&",
652 ListObj_Convert, &list))
653 return NULL;
654 _rv = GetListVerticalScrollBar(list);
655 _res = Py_BuildValue("O&",
656 CtlObj_New, _rv);
657 return _res;
660 static PyObject *List_GetListHorizontalScrollBar(PyObject *_self, PyObject *_args)
662 PyObject *_res = NULL;
663 ControlHandle _rv;
664 ListHandle list;
665 if (!PyArg_ParseTuple(_args, "O&",
666 ListObj_Convert, &list))
667 return NULL;
668 _rv = GetListHorizontalScrollBar(list);
669 _res = Py_BuildValue("O&",
670 CtlObj_New, _rv);
671 return _res;
674 static PyObject *List_GetListActive(PyObject *_self, PyObject *_args)
676 PyObject *_res = NULL;
677 Boolean _rv;
678 ListHandle list;
679 if (!PyArg_ParseTuple(_args, "O&",
680 ListObj_Convert, &list))
681 return NULL;
682 _rv = GetListActive(list);
683 _res = Py_BuildValue("b",
684 _rv);
685 return _res;
688 static PyObject *List_GetListClickTime(PyObject *_self, PyObject *_args)
690 PyObject *_res = NULL;
691 SInt32 _rv;
692 ListHandle list;
693 if (!PyArg_ParseTuple(_args, "O&",
694 ListObj_Convert, &list))
695 return NULL;
696 _rv = GetListClickTime(list);
697 _res = Py_BuildValue("l",
698 _rv);
699 return _res;
702 static PyObject *List_GetListRefCon(PyObject *_self, PyObject *_args)
704 PyObject *_res = NULL;
705 SInt32 _rv;
706 ListHandle list;
707 if (!PyArg_ParseTuple(_args, "O&",
708 ListObj_Convert, &list))
709 return NULL;
710 _rv = GetListRefCon(list);
711 _res = Py_BuildValue("l",
712 _rv);
713 return _res;
716 static PyObject *List_GetListDefinition(PyObject *_self, PyObject *_args)
718 PyObject *_res = NULL;
719 Handle _rv;
720 ListHandle list;
721 if (!PyArg_ParseTuple(_args, "O&",
722 ListObj_Convert, &list))
723 return NULL;
724 _rv = GetListDefinition(list);
725 _res = Py_BuildValue("O&",
726 ResObj_New, _rv);
727 return _res;
730 static PyObject *List_GetListUserHandle(PyObject *_self, PyObject *_args)
732 PyObject *_res = NULL;
733 Handle _rv;
734 ListHandle list;
735 if (!PyArg_ParseTuple(_args, "O&",
736 ListObj_Convert, &list))
737 return NULL;
738 _rv = GetListUserHandle(list);
739 _res = Py_BuildValue("O&",
740 ResObj_New, _rv);
741 return _res;
744 static PyObject *List_GetListDataHandle(PyObject *_self, PyObject *_args)
746 PyObject *_res = NULL;
747 DataHandle _rv;
748 ListHandle list;
749 if (!PyArg_ParseTuple(_args, "O&",
750 ListObj_Convert, &list))
751 return NULL;
752 _rv = GetListDataHandle(list);
753 _res = Py_BuildValue("O&",
754 ResObj_New, _rv);
755 return _res;
758 static PyObject *List_GetListFlags(PyObject *_self, PyObject *_args)
760 PyObject *_res = NULL;
761 OptionBits _rv;
762 ListHandle list;
763 if (!PyArg_ParseTuple(_args, "O&",
764 ListObj_Convert, &list))
765 return NULL;
766 _rv = GetListFlags(list);
767 _res = Py_BuildValue("l",
768 _rv);
769 return _res;
772 static PyObject *List_GetListSelectionFlags(PyObject *_self, PyObject *_args)
774 PyObject *_res = NULL;
775 OptionBits _rv;
776 ListHandle list;
777 if (!PyArg_ParseTuple(_args, "O&",
778 ListObj_Convert, &list))
779 return NULL;
780 _rv = GetListSelectionFlags(list);
781 _res = Py_BuildValue("l",
782 _rv);
783 return _res;
786 static PyObject *List_SetListViewBounds(PyObject *_self, PyObject *_args)
788 PyObject *_res = NULL;
789 ListHandle list;
790 Rect view;
791 if (!PyArg_ParseTuple(_args, "O&O&",
792 ListObj_Convert, &list,
793 PyMac_GetRect, &view))
794 return NULL;
795 SetListViewBounds(list,
796 &view);
797 Py_INCREF(Py_None);
798 _res = Py_None;
799 return _res;
802 static PyObject *List_SetListPort(PyObject *_self, PyObject *_args)
804 PyObject *_res = NULL;
805 ListHandle list;
806 CGrafPtr port;
807 if (!PyArg_ParseTuple(_args, "O&O&",
808 ListObj_Convert, &list,
809 GrafObj_Convert, &port))
810 return NULL;
811 SetListPort(list,
812 port);
813 Py_INCREF(Py_None);
814 _res = Py_None;
815 return _res;
818 static PyObject *List_SetListCellIndent(PyObject *_self, PyObject *_args)
820 PyObject *_res = NULL;
821 ListHandle list;
822 Point indent;
823 if (!PyArg_ParseTuple(_args, "O&O&",
824 ListObj_Convert, &list,
825 PyMac_GetPoint, &indent))
826 return NULL;
827 SetListCellIndent(list,
828 &indent);
829 Py_INCREF(Py_None);
830 _res = Py_None;
831 return _res;
834 static PyObject *List_SetListClickTime(PyObject *_self, PyObject *_args)
836 PyObject *_res = NULL;
837 ListHandle list;
838 SInt32 time;
839 if (!PyArg_ParseTuple(_args, "O&l",
840 ListObj_Convert, &list,
841 &time))
842 return NULL;
843 SetListClickTime(list,
844 time);
845 Py_INCREF(Py_None);
846 _res = Py_None;
847 return _res;
850 static PyObject *List_SetListRefCon(PyObject *_self, PyObject *_args)
852 PyObject *_res = NULL;
853 ListHandle list;
854 SInt32 refCon;
855 if (!PyArg_ParseTuple(_args, "O&l",
856 ListObj_Convert, &list,
857 &refCon))
858 return NULL;
859 SetListRefCon(list,
860 refCon);
861 Py_INCREF(Py_None);
862 _res = Py_None;
863 return _res;
866 static PyObject *List_SetListUserHandle(PyObject *_self, PyObject *_args)
868 PyObject *_res = NULL;
869 ListHandle list;
870 Handle userHandle;
871 if (!PyArg_ParseTuple(_args, "O&O&",
872 ListObj_Convert, &list,
873 ResObj_Convert, &userHandle))
874 return NULL;
875 SetListUserHandle(list,
876 userHandle);
877 Py_INCREF(Py_None);
878 _res = Py_None;
879 return _res;
882 static PyObject *List_SetListFlags(PyObject *_self, PyObject *_args)
884 PyObject *_res = NULL;
885 ListHandle list;
886 OptionBits listFlags;
887 if (!PyArg_ParseTuple(_args, "O&l",
888 ListObj_Convert, &list,
889 &listFlags))
890 return NULL;
891 SetListFlags(list,
892 listFlags);
893 Py_INCREF(Py_None);
894 _res = Py_None;
895 return _res;
898 static PyObject *List_SetListSelectionFlags(PyObject *_self, PyObject *_args)
900 PyObject *_res = NULL;
901 ListHandle list;
902 OptionBits selectionFlags;
903 if (!PyArg_ParseTuple(_args, "O&l",
904 ListObj_Convert, &list,
905 &selectionFlags))
906 return NULL;
907 SetListSelectionFlags(list,
908 selectionFlags);
909 Py_INCREF(Py_None);
910 _res = Py_None;
911 return _res;
914 static PyObject *List_as_List(PyObject *_self, PyObject *_args)
916 PyObject *_res = NULL;
918 Handle h;
919 ListObject *l;
920 if (!PyArg_ParseTuple(_args, "O&", ResObj_Convert, &h))
921 return NULL;
922 l = (ListObject *)ListObj_New(as_List(h));
923 l->ob_must_be_disposed = 0;
924 return Py_BuildValue("O", l);
928 static PyMethodDef List_methods[] = {
929 {"LNew", (PyCFunction)List_LNew, 1,
930 "(Rect rView, Rect dataBounds, Point cSize, short theProc, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle _rv)"},
931 {"GetListPort", (PyCFunction)List_GetListPort, 1,
932 "(ListHandle list) -> (CGrafPtr _rv)"},
933 {"GetListVerticalScrollBar", (PyCFunction)List_GetListVerticalScrollBar, 1,
934 "(ListHandle list) -> (ControlHandle _rv)"},
935 {"GetListHorizontalScrollBar", (PyCFunction)List_GetListHorizontalScrollBar, 1,
936 "(ListHandle list) -> (ControlHandle _rv)"},
937 {"GetListActive", (PyCFunction)List_GetListActive, 1,
938 "(ListHandle list) -> (Boolean _rv)"},
939 {"GetListClickTime", (PyCFunction)List_GetListClickTime, 1,
940 "(ListHandle list) -> (SInt32 _rv)"},
941 {"GetListRefCon", (PyCFunction)List_GetListRefCon, 1,
942 "(ListHandle list) -> (SInt32 _rv)"},
943 {"GetListDefinition", (PyCFunction)List_GetListDefinition, 1,
944 "(ListHandle list) -> (Handle _rv)"},
945 {"GetListUserHandle", (PyCFunction)List_GetListUserHandle, 1,
946 "(ListHandle list) -> (Handle _rv)"},
947 {"GetListDataHandle", (PyCFunction)List_GetListDataHandle, 1,
948 "(ListHandle list) -> (DataHandle _rv)"},
949 {"GetListFlags", (PyCFunction)List_GetListFlags, 1,
950 "(ListHandle list) -> (OptionBits _rv)"},
951 {"GetListSelectionFlags", (PyCFunction)List_GetListSelectionFlags, 1,
952 "(ListHandle list) -> (OptionBits _rv)"},
953 {"SetListViewBounds", (PyCFunction)List_SetListViewBounds, 1,
954 "(ListHandle list, Rect view) -> None"},
955 {"SetListPort", (PyCFunction)List_SetListPort, 1,
956 "(ListHandle list, CGrafPtr port) -> None"},
957 {"SetListCellIndent", (PyCFunction)List_SetListCellIndent, 1,
958 "(ListHandle list, Point indent) -> None"},
959 {"SetListClickTime", (PyCFunction)List_SetListClickTime, 1,
960 "(ListHandle list, SInt32 time) -> None"},
961 {"SetListRefCon", (PyCFunction)List_SetListRefCon, 1,
962 "(ListHandle list, SInt32 refCon) -> None"},
963 {"SetListUserHandle", (PyCFunction)List_SetListUserHandle, 1,
964 "(ListHandle list, Handle userHandle) -> None"},
965 {"SetListFlags", (PyCFunction)List_SetListFlags, 1,
966 "(ListHandle list, OptionBits listFlags) -> None"},
967 {"SetListSelectionFlags", (PyCFunction)List_SetListSelectionFlags, 1,
968 "(ListHandle list, OptionBits selectionFlags) -> None"},
969 {"as_List", (PyCFunction)List_as_List, 1,
970 "(Resource)->List.\nReturns List object (which is not auto-freed!)"},
971 {NULL, NULL, 0}
977 void initList(void)
979 PyObject *m;
980 PyObject *d;
984 PyMac_INIT_TOOLBOX_OBJECT_NEW(ListHandle, ListObj_New);
985 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ListHandle, ListObj_Convert);
988 m = Py_InitModule("List", List_methods);
989 d = PyModule_GetDict(m);
990 List_Error = PyMac_GetOSErrException();
991 if (List_Error == NULL ||
992 PyDict_SetItemString(d, "Error", List_Error) != 0)
993 return;
994 List_Type.ob_type = &PyType_Type;
995 Py_INCREF(&List_Type);
996 if (PyDict_SetItemString(d, "ListType", (PyObject *)&List_Type) != 0)
997 Py_FatalError("can't initialize ListType");
1000 /* ======================== End module List ========================= */