changes by Barry, e.g. font lock & email addresses
[python/dscho.git] / Mac / Modules / list / Listmodule.c
blob747b477352aec9e858e9cecb889afc7e3274cff8
2 /* ========================== Module List =========================== */
4 #include "Python.h"
8 #define SystemSevenOrLater 1
10 #include "macglue.h"
11 #include <Memory.h>
12 #include <Dialogs.h>
13 #include <Menus.h>
14 #include <Controls.h>
16 extern PyObject *ResObj_New(Handle);
17 extern PyObject *ResObj_OptNew(Handle);
18 extern int ResObj_Convert(PyObject *, Handle *);
20 extern PyObject *WinObj_New(WindowPtr);
21 extern int WinObj_Convert(PyObject *, WindowPtr *);
23 extern PyObject *DlgObj_New(DialogPtr);
24 extern int DlgObj_Convert(PyObject *, DialogPtr *);
25 extern PyTypeObject Dialog_Type;
26 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
28 extern PyObject *MenuObj_New(MenuHandle);
29 extern int MenuObj_Convert(PyObject *, MenuHandle *);
31 extern PyObject *CtlObj_New(ControlHandle);
32 extern int CtlObj_Convert(PyObject *, ControlHandle *);
34 extern PyObject *WinObj_WhichWindow(WindowPtr);
36 #include <Lists.h>
38 static PyObject *List_Error;
40 /* ------------------------ Object type List ------------------------ */
42 PyTypeObject List_Type;
44 #define ListObj_Check(x) ((x)->ob_type == &List_Type)
46 typedef struct ListObject {
47 PyObject_HEAD
48 ListRef ob_itself;
49 } ListObject;
51 PyObject *ListObj_New(itself)
52 ListRef itself;
54 ListObject *it;
55 if (itself == NULL) {
56 PyErr_SetString(List_Error,"Cannot create null List");
57 return NULL;
59 it = PyObject_NEW(ListObject, &List_Type);
60 if (it == NULL) return NULL;
61 it->ob_itself = itself;
62 return (PyObject *)it;
64 ListObj_Convert(v, p_itself)
65 PyObject *v;
66 ListRef *p_itself;
68 if (!ListObj_Check(v))
70 PyErr_SetString(PyExc_TypeError, "List required");
71 return 0;
73 *p_itself = ((ListObject *)v)->ob_itself;
74 return 1;
77 static void ListObj_dealloc(self)
78 ListObject *self;
80 LDispose(self->ob_itself);
81 PyMem_DEL(self);
84 static PyObject *ListObj_LAddColumn(_self, _args)
85 ListObject *_self;
86 PyObject *_args;
88 PyObject *_res = NULL;
89 short _rv;
90 short count;
91 short colNum;
92 if (!PyArg_ParseTuple(_args, "hh",
93 &count,
94 &colNum))
95 return NULL;
96 _rv = LAddColumn(count,
97 colNum,
98 _self->ob_itself);
99 _res = Py_BuildValue("h",
100 _rv);
101 return _res;
104 static PyObject *ListObj_LAddRow(_self, _args)
105 ListObject *_self;
106 PyObject *_args;
108 PyObject *_res = NULL;
109 short _rv;
110 short count;
111 short rowNum;
112 if (!PyArg_ParseTuple(_args, "hh",
113 &count,
114 &rowNum))
115 return NULL;
116 _rv = LAddRow(count,
117 rowNum,
118 _self->ob_itself);
119 _res = Py_BuildValue("h",
120 _rv);
121 return _res;
124 static PyObject *ListObj_LDelColumn(_self, _args)
125 ListObject *_self;
126 PyObject *_args;
128 PyObject *_res = NULL;
129 short count;
130 short colNum;
131 if (!PyArg_ParseTuple(_args, "hh",
132 &count,
133 &colNum))
134 return NULL;
135 LDelColumn(count,
136 colNum,
137 _self->ob_itself);
138 Py_INCREF(Py_None);
139 _res = Py_None;
140 return _res;
143 static PyObject *ListObj_LDelRow(_self, _args)
144 ListObject *_self;
145 PyObject *_args;
147 PyObject *_res = NULL;
148 short count;
149 short rowNum;
150 if (!PyArg_ParseTuple(_args, "hh",
151 &count,
152 &rowNum))
153 return NULL;
154 LDelRow(count,
155 rowNum,
156 _self->ob_itself);
157 Py_INCREF(Py_None);
158 _res = Py_None;
159 return _res;
162 static PyObject *ListObj_LGetSelect(_self, _args)
163 ListObject *_self;
164 PyObject *_args;
166 PyObject *_res = NULL;
167 Boolean _rv;
168 Boolean next;
169 Point theCell;
170 if (!PyArg_ParseTuple(_args, "bO&",
171 &next,
172 PyMac_GetPoint, &theCell))
173 return NULL;
174 _rv = LGetSelect(next,
175 &theCell,
176 _self->ob_itself);
177 _res = Py_BuildValue("bO&",
178 _rv,
179 PyMac_BuildPoint, theCell);
180 return _res;
183 static PyObject *ListObj_LLastClick(_self, _args)
184 ListObject *_self;
185 PyObject *_args;
187 PyObject *_res = NULL;
188 Point _rv;
189 if (!PyArg_ParseTuple(_args, ""))
190 return NULL;
191 _rv = LLastClick(_self->ob_itself);
192 _res = Py_BuildValue("O&",
193 PyMac_BuildPoint, _rv);
194 return _res;
197 static PyObject *ListObj_LNextCell(_self, _args)
198 ListObject *_self;
199 PyObject *_args;
201 PyObject *_res = NULL;
202 Boolean _rv;
203 Boolean hNext;
204 Boolean vNext;
205 Point theCell;
206 if (!PyArg_ParseTuple(_args, "bbO&",
207 &hNext,
208 &vNext,
209 PyMac_GetPoint, &theCell))
210 return NULL;
211 _rv = LNextCell(hNext,
212 vNext,
213 &theCell,
214 _self->ob_itself);
215 _res = Py_BuildValue("bO&",
216 _rv,
217 PyMac_BuildPoint, theCell);
218 return _res;
221 static PyObject *ListObj_LSize(_self, _args)
222 ListObject *_self;
223 PyObject *_args;
225 PyObject *_res = NULL;
226 short listWidth;
227 short listHeight;
228 if (!PyArg_ParseTuple(_args, "hh",
229 &listWidth,
230 &listHeight))
231 return NULL;
232 LSize(listWidth,
233 listHeight,
234 _self->ob_itself);
235 Py_INCREF(Py_None);
236 _res = Py_None;
237 return _res;
240 static PyObject *ListObj_LSetDrawingMode(_self, _args)
241 ListObject *_self;
242 PyObject *_args;
244 PyObject *_res = NULL;
245 Boolean drawIt;
246 if (!PyArg_ParseTuple(_args, "b",
247 &drawIt))
248 return NULL;
249 LSetDrawingMode(drawIt,
250 _self->ob_itself);
251 Py_INCREF(Py_None);
252 _res = Py_None;
253 return _res;
256 static PyObject *ListObj_LScroll(_self, _args)
257 ListObject *_self;
258 PyObject *_args;
260 PyObject *_res = NULL;
261 short dCols;
262 short dRows;
263 if (!PyArg_ParseTuple(_args, "hh",
264 &dCols,
265 &dRows))
266 return NULL;
267 LScroll(dCols,
268 dRows,
269 _self->ob_itself);
270 Py_INCREF(Py_None);
271 _res = Py_None;
272 return _res;
275 static PyObject *ListObj_LAutoScroll(_self, _args)
276 ListObject *_self;
277 PyObject *_args;
279 PyObject *_res = NULL;
280 if (!PyArg_ParseTuple(_args, ""))
281 return NULL;
282 LAutoScroll(_self->ob_itself);
283 Py_INCREF(Py_None);
284 _res = Py_None;
285 return _res;
288 static PyObject *ListObj_LUpdate(_self, _args)
289 ListObject *_self;
290 PyObject *_args;
292 PyObject *_res = NULL;
293 if (!PyArg_ParseTuple(_args, ""))
294 return NULL;
295 LUpdate((*_self->ob_itself)->port->visRgn,
296 _self->ob_itself);
297 Py_INCREF(Py_None);
298 _res = Py_None;
299 return _res;
302 static PyObject *ListObj_LActivate(_self, _args)
303 ListObject *_self;
304 PyObject *_args;
306 PyObject *_res = NULL;
307 Boolean act;
308 if (!PyArg_ParseTuple(_args, "b",
309 &act))
310 return NULL;
311 LActivate(act,
312 _self->ob_itself);
313 Py_INCREF(Py_None);
314 _res = Py_None;
315 return _res;
318 static PyObject *ListObj_LCellSize(_self, _args)
319 ListObject *_self;
320 PyObject *_args;
322 PyObject *_res = NULL;
323 Point cSize;
324 if (!PyArg_ParseTuple(_args, "O&",
325 PyMac_GetPoint, &cSize))
326 return NULL;
327 LCellSize(cSize,
328 _self->ob_itself);
329 Py_INCREF(Py_None);
330 _res = Py_None;
331 return _res;
334 static PyObject *ListObj_LClick(_self, _args)
335 ListObject *_self;
336 PyObject *_args;
338 PyObject *_res = NULL;
339 Boolean _rv;
340 Point pt;
341 short modifiers;
342 if (!PyArg_ParseTuple(_args, "O&h",
343 PyMac_GetPoint, &pt,
344 &modifiers))
345 return NULL;
346 _rv = LClick(pt,
347 modifiers,
348 _self->ob_itself);
349 _res = Py_BuildValue("b",
350 _rv);
351 return _res;
354 static PyObject *ListObj_LAddToCell(_self, _args)
355 ListObject *_self;
356 PyObject *_args;
358 PyObject *_res = NULL;
359 char *dataPtr__in__;
360 short dataPtr__len__;
361 int dataPtr__in_len__;
362 Point theCell;
363 if (!PyArg_ParseTuple(_args, "s#O&",
364 &dataPtr__in__, &dataPtr__in_len__,
365 PyMac_GetPoint, &theCell))
366 return NULL;
367 dataPtr__len__ = dataPtr__in_len__;
368 LAddToCell(dataPtr__in__, dataPtr__len__,
369 theCell,
370 _self->ob_itself);
371 Py_INCREF(Py_None);
372 _res = Py_None;
373 dataPtr__error__: ;
374 return _res;
377 static PyObject *ListObj_LClrCell(_self, _args)
378 ListObject *_self;
379 PyObject *_args;
381 PyObject *_res = NULL;
382 Point theCell;
383 if (!PyArg_ParseTuple(_args, "O&",
384 PyMac_GetPoint, &theCell))
385 return NULL;
386 LClrCell(theCell,
387 _self->ob_itself);
388 Py_INCREF(Py_None);
389 _res = Py_None;
390 return _res;
393 static PyObject *ListObj_LGetCell(_self, _args)
394 ListObject *_self;
395 PyObject *_args;
397 PyObject *_res = NULL;
398 char *dataPtr__out__;
399 short dataPtr__len__;
400 int dataPtr__in_len__;
401 Point theCell;
402 if (!PyArg_ParseTuple(_args, "iO&",
403 &dataPtr__in_len__,
404 PyMac_GetPoint, &theCell))
405 return NULL;
406 if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
408 PyErr_NoMemory();
409 goto dataPtr__error__;
411 dataPtr__len__ = dataPtr__in_len__;
412 LGetCell(dataPtr__out__, &dataPtr__len__,
413 theCell,
414 _self->ob_itself);
415 _res = Py_BuildValue("s#",
416 dataPtr__out__, (int)dataPtr__len__);
417 free(dataPtr__out__);
418 dataPtr__error__: ;
419 return _res;
422 static PyObject *ListObj_LRect(_self, _args)
423 ListObject *_self;
424 PyObject *_args;
426 PyObject *_res = NULL;
427 Rect cellRect;
428 Point theCell;
429 if (!PyArg_ParseTuple(_args, "O&",
430 PyMac_GetPoint, &theCell))
431 return NULL;
432 LRect(&cellRect,
433 theCell,
434 _self->ob_itself);
435 _res = Py_BuildValue("O&",
436 PyMac_BuildRect, &cellRect);
437 return _res;
440 static PyObject *ListObj_LSetCell(_self, _args)
441 ListObject *_self;
442 PyObject *_args;
444 PyObject *_res = NULL;
445 char *dataPtr__in__;
446 short dataPtr__len__;
447 int dataPtr__in_len__;
448 Point theCell;
449 if (!PyArg_ParseTuple(_args, "s#O&",
450 &dataPtr__in__, &dataPtr__in_len__,
451 PyMac_GetPoint, &theCell))
452 return NULL;
453 dataPtr__len__ = dataPtr__in_len__;
454 LSetCell(dataPtr__in__, dataPtr__len__,
455 theCell,
456 _self->ob_itself);
457 Py_INCREF(Py_None);
458 _res = Py_None;
459 dataPtr__error__: ;
460 return _res;
463 static PyObject *ListObj_LSetSelect(_self, _args)
464 ListObject *_self;
465 PyObject *_args;
467 PyObject *_res = NULL;
468 Boolean setIt;
469 Point theCell;
470 if (!PyArg_ParseTuple(_args, "bO&",
471 &setIt,
472 PyMac_GetPoint, &theCell))
473 return NULL;
474 LSetSelect(setIt,
475 theCell,
476 _self->ob_itself);
477 Py_INCREF(Py_None);
478 _res = Py_None;
479 return _res;
482 static PyObject *ListObj_LDraw(_self, _args)
483 ListObject *_self;
484 PyObject *_args;
486 PyObject *_res = NULL;
487 Point theCell;
488 if (!PyArg_ParseTuple(_args, "O&",
489 PyMac_GetPoint, &theCell))
490 return NULL;
491 LDraw(theCell,
492 _self->ob_itself);
493 Py_INCREF(Py_None);
494 _res = Py_None;
495 return _res;
498 static PyMethodDef ListObj_methods[] = {
499 {"LAddColumn", (PyCFunction)ListObj_LAddColumn, 1,
500 "(short count, short colNum) -> (short _rv)"},
501 {"LAddRow", (PyCFunction)ListObj_LAddRow, 1,
502 "(short count, short rowNum) -> (short _rv)"},
503 {"LDelColumn", (PyCFunction)ListObj_LDelColumn, 1,
504 "(short count, short colNum) -> None"},
505 {"LDelRow", (PyCFunction)ListObj_LDelRow, 1,
506 "(short count, short rowNum) -> None"},
507 {"LGetSelect", (PyCFunction)ListObj_LGetSelect, 1,
508 "(Boolean next, Point theCell) -> (Boolean _rv, Point theCell)"},
509 {"LLastClick", (PyCFunction)ListObj_LLastClick, 1,
510 "() -> (Point _rv)"},
511 {"LNextCell", (PyCFunction)ListObj_LNextCell, 1,
512 "(Boolean hNext, Boolean vNext, Point theCell) -> (Boolean _rv, Point theCell)"},
513 {"LSize", (PyCFunction)ListObj_LSize, 1,
514 "(short listWidth, short listHeight) -> None"},
515 {"LSetDrawingMode", (PyCFunction)ListObj_LSetDrawingMode, 1,
516 "(Boolean drawIt) -> None"},
517 {"LScroll", (PyCFunction)ListObj_LScroll, 1,
518 "(short dCols, short dRows) -> None"},
519 {"LAutoScroll", (PyCFunction)ListObj_LAutoScroll, 1,
520 "() -> None"},
521 {"LUpdate", (PyCFunction)ListObj_LUpdate, 1,
522 "() -> None"},
523 {"LActivate", (PyCFunction)ListObj_LActivate, 1,
524 "(Boolean act) -> None"},
525 {"LCellSize", (PyCFunction)ListObj_LCellSize, 1,
526 "(Point cSize) -> None"},
527 {"LClick", (PyCFunction)ListObj_LClick, 1,
528 "(Point pt, short modifiers) -> (Boolean _rv)"},
529 {"LAddToCell", (PyCFunction)ListObj_LAddToCell, 1,
530 "(Buffer dataPtr, Point theCell) -> None"},
531 {"LClrCell", (PyCFunction)ListObj_LClrCell, 1,
532 "(Point theCell) -> None"},
533 {"LGetCell", (PyCFunction)ListObj_LGetCell, 1,
534 "(Buffer dataPtr, Point theCell) -> (Buffer dataPtr)"},
535 {"LRect", (PyCFunction)ListObj_LRect, 1,
536 "(Point theCell) -> (Rect cellRect)"},
537 {"LSetCell", (PyCFunction)ListObj_LSetCell, 1,
538 "(Buffer dataPtr, Point theCell) -> None"},
539 {"LSetSelect", (PyCFunction)ListObj_LSetSelect, 1,
540 "(Boolean setIt, Point theCell) -> None"},
541 {"LDraw", (PyCFunction)ListObj_LDraw, 1,
542 "(Point theCell) -> None"},
543 {NULL, NULL, 0}
546 PyMethodChain ListObj_chain = { ListObj_methods, NULL };
548 static PyObject *ListObj_getattr(self, name)
549 ListObject *self;
550 char *name;
552 return Py_FindMethodInChain(&ListObj_chain, (PyObject *)self, name);
555 #define ListObj_setattr NULL
557 PyTypeObject List_Type = {
558 PyObject_HEAD_INIT(&PyType_Type)
559 0, /*ob_size*/
560 "List", /*tp_name*/
561 sizeof(ListObject), /*tp_basicsize*/
562 0, /*tp_itemsize*/
563 /* methods */
564 (destructor) ListObj_dealloc, /*tp_dealloc*/
565 0, /*tp_print*/
566 (getattrfunc) ListObj_getattr, /*tp_getattr*/
567 (setattrfunc) ListObj_setattr, /*tp_setattr*/
570 /* ---------------------- End object type List ---------------------- */
573 static PyObject *List_LNew(_self, _args)
574 PyObject *_self;
575 PyObject *_args;
577 PyObject *_res = NULL;
578 ListRef _rv;
579 Rect rView;
580 Rect dataBounds;
581 Point cSize;
582 short theProc;
583 WindowPtr theWindow;
584 Boolean drawIt;
585 Boolean hasGrow;
586 Boolean scrollHoriz;
587 Boolean scrollVert;
588 if (!PyArg_ParseTuple(_args, "O&O&O&hO&bbbb",
589 PyMac_GetRect, &rView,
590 PyMac_GetRect, &dataBounds,
591 PyMac_GetPoint, &cSize,
592 &theProc,
593 WinObj_Convert, &theWindow,
594 &drawIt,
595 &hasGrow,
596 &scrollHoriz,
597 &scrollVert))
598 return NULL;
599 _rv = LNew(&rView,
600 &dataBounds,
601 cSize,
602 theProc,
603 theWindow,
604 drawIt,
605 hasGrow,
606 scrollHoriz,
607 scrollVert);
608 _res = Py_BuildValue("O&",
609 ListObj_New, _rv);
610 return _res;
613 static PyMethodDef List_methods[] = {
614 {"LNew", (PyCFunction)List_LNew, 1,
615 "(Rect rView, Rect dataBounds, Point cSize, short theProc, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListRef _rv)"},
616 {NULL, NULL, 0}
622 void initList()
624 PyObject *m;
625 PyObject *d;
630 m = Py_InitModule("List", List_methods);
631 d = PyModule_GetDict(m);
632 List_Error = PyMac_GetOSErrException();
633 if (List_Error == NULL ||
634 PyDict_SetItemString(d, "Error", List_Error) != 0)
635 Py_FatalError("can't initialize List.Error");
638 /* ======================== End module List ========================= */