Home | History | Annotate | Download | only in list
      1 
      2 /* ========================== Module _List ========================== */
      3 
      4 #include "Python.h"
      5 #include "pymactoolbox.h"
      6 
      7 #if APPLE_SUPPORTS_QUICKTIME
      8 
      9 
     10 /* Macro to test whether a weak-loaded CFM function exists */
     11 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL )  {\
     12         PyErr_SetString(PyExc_NotImplementedError, \
     13             "Not available in this shared library/OS version"); \
     14         return NULL; \
     15     }} while(0)
     16 
     17 
     18 #include <Carbon/Carbon.h>
     19 
     20 #ifdef USE_TOOLBOX_OBJECT_GLUE
     21 extern PyObject *_ListObj_New(ListHandle);
     22 extern int _ListObj_Convert(PyObject *, ListHandle *);
     23 
     24 #define ListObj_New _ListObj_New
     25 #define ListObj_Convert _ListObj_Convert
     26 #endif
     27 
     28 #define as_List(x) ((ListHandle)x)
     29 #define as_Resource(lh) ((Handle)lh)
     30 
     31 static ListDefUPP myListDefFunctionUPP;
     32 
     33 
     34 static PyObject *List_Error;
     35 
     36 /* ------------------------ Object type List ------------------------ */
     37 
     38 PyTypeObject List_Type;
     39 
     40 #define ListObj_Check(x) ((x)->ob_type == &List_Type || PyObject_TypeCheck((x), &List_Type))
     41 
     42 typedef struct ListObject {
     43     PyObject_HEAD
     44     ListHandle ob_itself;
     45     PyObject *ob_ldef_func;
     46     int ob_must_be_disposed;
     47 } ListObject;
     48 
     49 PyObject *ListObj_New(ListHandle itself)
     50 {
     51     ListObject *it;
     52     if (itself == NULL) {
     53                                     PyErr_SetString(List_Error,"Cannot create null List");
     54                                     return NULL;
     55                             }
     56     it = PyObject_NEW(ListObject, &List_Type);
     57     if (it == NULL) return NULL;
     58     it->ob_itself = itself;
     59     it->ob_ldef_func = NULL;
     60     it->ob_must_be_disposed = 1;
     61     SetListRefCon(itself, (long)it);
     62     return (PyObject *)it;
     63 }
     64 
     65 int ListObj_Convert(PyObject *v, ListHandle *p_itself)
     66 {
     67     if (!ListObj_Check(v))
     68     {
     69         PyErr_SetString(PyExc_TypeError, "List required");
     70         return 0;
     71     }
     72     *p_itself = ((ListObject *)v)->ob_itself;
     73     return 1;
     74 }
     75 
     76 static void ListObj_dealloc(ListObject *self)
     77 {
     78     Py_CLEAR(self->ob_ldef_func);
     79     SetListRefCon(self->ob_itself, (long)0);
     80     if (self->ob_must_be_disposed && self->ob_itself) LDispose(self->ob_itself);
     81     self->ob_type->tp_free((PyObject *)self);
     82 }
     83 
     84 static PyObject *ListObj_LAddColumn(ListObject *_self, PyObject *_args)
     85 {
     86     PyObject *_res = NULL;
     87     short _rv;
     88     short count;
     89     short colNum;
     90     if (!PyArg_ParseTuple(_args, "hh",
     91                           &count,
     92                           &colNum))
     93         return NULL;
     94     _rv = LAddColumn(count,
     95                      colNum,
     96                      _self->ob_itself);
     97     _res = Py_BuildValue("h",
     98                          _rv);
     99     return _res;
    100 }
    101 
    102 static PyObject *ListObj_LAddRow(ListObject *_self, PyObject *_args)
    103 {
    104     PyObject *_res = NULL;
    105     short _rv;
    106     short count;
    107     short rowNum;
    108     if (!PyArg_ParseTuple(_args, "hh",
    109                           &count,
    110                           &rowNum))
    111         return NULL;
    112     _rv = LAddRow(count,
    113                   rowNum,
    114                   _self->ob_itself);
    115     _res = Py_BuildValue("h",
    116                          _rv);
    117     return _res;
    118 }
    119 
    120 static PyObject *ListObj_LDelColumn(ListObject *_self, PyObject *_args)
    121 {
    122     PyObject *_res = NULL;
    123     short count;
    124     short colNum;
    125     if (!PyArg_ParseTuple(_args, "hh",
    126                           &count,
    127                           &colNum))
    128         return NULL;
    129     LDelColumn(count,
    130                colNum,
    131                _self->ob_itself);
    132     Py_INCREF(Py_None);
    133     _res = Py_None;
    134     return _res;
    135 }
    136 
    137 static PyObject *ListObj_LDelRow(ListObject *_self, PyObject *_args)
    138 {
    139     PyObject *_res = NULL;
    140     short count;
    141     short rowNum;
    142     if (!PyArg_ParseTuple(_args, "hh",
    143                           &count,
    144                           &rowNum))
    145         return NULL;
    146     LDelRow(count,
    147         rowNum,
    148         _self->ob_itself);
    149     Py_INCREF(Py_None);
    150     _res = Py_None;
    151     return _res;
    152 }
    153 
    154 static PyObject *ListObj_LGetSelect(ListObject *_self, PyObject *_args)
    155 {
    156     PyObject *_res = NULL;
    157     Boolean _rv;
    158     Boolean next;
    159     Point theCell;
    160     if (!PyArg_ParseTuple(_args, "bO&",
    161                           &next,
    162                           PyMac_GetPoint, &theCell))
    163         return NULL;
    164     _rv = LGetSelect(next,
    165                      &theCell,
    166                      _self->ob_itself);
    167     _res = Py_BuildValue("bO&",
    168                          _rv,
    169                          PyMac_BuildPoint, theCell);
    170     return _res;
    171 }
    172 
    173 static PyObject *ListObj_LLastClick(ListObject *_self, PyObject *_args)
    174 {
    175     PyObject *_res = NULL;
    176     Point _rv;
    177     if (!PyArg_ParseTuple(_args, ""))
    178         return NULL;
    179     _rv = LLastClick(_self->ob_itself);
    180     _res = Py_BuildValue("O&",
    181                          PyMac_BuildPoint, _rv);
    182     return _res;
    183 }
    184 
    185 static PyObject *ListObj_LNextCell(ListObject *_self, PyObject *_args)
    186 {
    187     PyObject *_res = NULL;
    188     Boolean _rv;
    189     Boolean hNext;
    190     Boolean vNext;
    191     Point theCell;
    192     if (!PyArg_ParseTuple(_args, "bbO&",
    193                           &hNext,
    194                           &vNext,
    195                           PyMac_GetPoint, &theCell))
    196         return NULL;
    197     _rv = LNextCell(hNext,
    198                     vNext,
    199                     &theCell,
    200                     _self->ob_itself);
    201     _res = Py_BuildValue("bO&",
    202                          _rv,
    203                          PyMac_BuildPoint, theCell);
    204     return _res;
    205 }
    206 
    207 static PyObject *ListObj_LSize(ListObject *_self, PyObject *_args)
    208 {
    209     PyObject *_res = NULL;
    210     short listWidth;
    211     short listHeight;
    212     if (!PyArg_ParseTuple(_args, "hh",
    213                           &listWidth,
    214                           &listHeight))
    215         return NULL;
    216     LSize(listWidth,
    217           listHeight,
    218           _self->ob_itself);
    219     Py_INCREF(Py_None);
    220     _res = Py_None;
    221     return _res;
    222 }
    223 
    224 static PyObject *ListObj_LSetDrawingMode(ListObject *_self, PyObject *_args)
    225 {
    226     PyObject *_res = NULL;
    227     Boolean drawIt;
    228     if (!PyArg_ParseTuple(_args, "b",
    229                           &drawIt))
    230         return NULL;
    231     LSetDrawingMode(drawIt,
    232                     _self->ob_itself);
    233     Py_INCREF(Py_None);
    234     _res = Py_None;
    235     return _res;
    236 }
    237 
    238 static PyObject *ListObj_LScroll(ListObject *_self, PyObject *_args)
    239 {
    240     PyObject *_res = NULL;
    241     short dCols;
    242     short dRows;
    243     if (!PyArg_ParseTuple(_args, "hh",
    244                           &dCols,
    245                           &dRows))
    246         return NULL;
    247     LScroll(dCols,
    248         dRows,
    249         _self->ob_itself);
    250     Py_INCREF(Py_None);
    251     _res = Py_None;
    252     return _res;
    253 }
    254 
    255 static PyObject *ListObj_LAutoScroll(ListObject *_self, PyObject *_args)
    256 {
    257     PyObject *_res = NULL;
    258     if (!PyArg_ParseTuple(_args, ""))
    259         return NULL;
    260     LAutoScroll(_self->ob_itself);
    261     Py_INCREF(Py_None);
    262     _res = Py_None;
    263     return _res;
    264 }
    265 
    266 static PyObject *ListObj_LUpdate(ListObject *_self, PyObject *_args)
    267 {
    268     PyObject *_res = NULL;
    269     RgnHandle theRgn;
    270     if (!PyArg_ParseTuple(_args, "O&",
    271                           ResObj_Convert, &theRgn))
    272         return NULL;
    273     LUpdate(theRgn,
    274         _self->ob_itself);
    275     Py_INCREF(Py_None);
    276     _res = Py_None;
    277     return _res;
    278 }
    279 
    280 static PyObject *ListObj_LActivate(ListObject *_self, PyObject *_args)
    281 {
    282     PyObject *_res = NULL;
    283     Boolean act;
    284     if (!PyArg_ParseTuple(_args, "b",
    285                           &act))
    286         return NULL;
    287     LActivate(act,
    288               _self->ob_itself);
    289     Py_INCREF(Py_None);
    290     _res = Py_None;
    291     return _res;
    292 }
    293 
    294 static PyObject *ListObj_LCellSize(ListObject *_self, PyObject *_args)
    295 {
    296     PyObject *_res = NULL;
    297     Point cSize;
    298     if (!PyArg_ParseTuple(_args, "O&",
    299                           PyMac_GetPoint, &cSize))
    300         return NULL;
    301     LCellSize(cSize,
    302               _self->ob_itself);
    303     Py_INCREF(Py_None);
    304     _res = Py_None;
    305     return _res;
    306 }
    307 
    308 static PyObject *ListObj_LClick(ListObject *_self, PyObject *_args)
    309 {
    310     PyObject *_res = NULL;
    311     Boolean _rv;
    312     Point pt;
    313     EventModifiers modifiers;
    314     if (!PyArg_ParseTuple(_args, "O&H",
    315                           PyMac_GetPoint, &pt,
    316                           &modifiers))
    317         return NULL;
    318     _rv = LClick(pt,
    319                  modifiers,
    320                  _self->ob_itself);
    321     _res = Py_BuildValue("b",
    322                          _rv);
    323     return _res;
    324 }
    325 
    326 static PyObject *ListObj_LAddToCell(ListObject *_self, PyObject *_args)
    327 {
    328     PyObject *_res = NULL;
    329     char *dataPtr__in__;
    330     short dataPtr__len__;
    331     int dataPtr__in_len__;
    332     Point theCell;
    333     if (!PyArg_ParseTuple(_args, "s#O&",
    334                           &dataPtr__in__, &dataPtr__in_len__,
    335                           PyMac_GetPoint, &theCell))
    336         return NULL;
    337     dataPtr__len__ = dataPtr__in_len__;
    338     LAddToCell(dataPtr__in__, dataPtr__len__,
    339                theCell,
    340                _self->ob_itself);
    341     Py_INCREF(Py_None);
    342     _res = Py_None;
    343     return _res;
    344 }
    345 
    346 static PyObject *ListObj_LClrCell(ListObject *_self, PyObject *_args)
    347 {
    348     PyObject *_res = NULL;
    349     Point theCell;
    350     if (!PyArg_ParseTuple(_args, "O&",
    351                           PyMac_GetPoint, &theCell))
    352         return NULL;
    353     LClrCell(theCell,
    354              _self->ob_itself);
    355     Py_INCREF(Py_None);
    356     _res = Py_None;
    357     return _res;
    358 }
    359 
    360 static PyObject *ListObj_LGetCell(ListObject *_self, PyObject *_args)
    361 {
    362     PyObject *_res = NULL;
    363     char *dataPtr__out__;
    364     short dataPtr__len__;
    365     int dataPtr__in_len__;
    366     Point theCell;
    367     if (!PyArg_ParseTuple(_args, "iO&",
    368                           &dataPtr__in_len__,
    369                           PyMac_GetPoint, &theCell))
    370         return NULL;
    371     if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
    372     {
    373         PyErr_NoMemory();
    374         goto dataPtr__error__;
    375     }
    376     dataPtr__len__ = dataPtr__in_len__;
    377     LGetCell(dataPtr__out__, &dataPtr__len__,
    378              theCell,
    379              _self->ob_itself);
    380     _res = Py_BuildValue("s#",
    381                          dataPtr__out__, (int)dataPtr__len__);
    382     free(dataPtr__out__);
    383  dataPtr__error__: ;
    384     return _res;
    385 }
    386 
    387 static PyObject *ListObj_LRect(ListObject *_self, PyObject *_args)
    388 {
    389     PyObject *_res = NULL;
    390     Rect cellRect;
    391     Point theCell;
    392     if (!PyArg_ParseTuple(_args, "O&",
    393                           PyMac_GetPoint, &theCell))
    394         return NULL;
    395     LRect(&cellRect,
    396           theCell,
    397           _self->ob_itself);
    398     _res = Py_BuildValue("O&",
    399                          PyMac_BuildRect, &cellRect);
    400     return _res;
    401 }
    402 
    403 static PyObject *ListObj_LSetCell(ListObject *_self, PyObject *_args)
    404 {
    405     PyObject *_res = NULL;
    406     char *dataPtr__in__;
    407     short dataPtr__len__;
    408     int dataPtr__in_len__;
    409     Point theCell;
    410     if (!PyArg_ParseTuple(_args, "s#O&",
    411                           &dataPtr__in__, &dataPtr__in_len__,
    412                           PyMac_GetPoint, &theCell))
    413         return NULL;
    414     dataPtr__len__ = dataPtr__in_len__;
    415     LSetCell(dataPtr__in__, dataPtr__len__,
    416              theCell,
    417              _self->ob_itself);
    418     Py_INCREF(Py_None);
    419     _res = Py_None;
    420     return _res;
    421 }
    422 
    423 static PyObject *ListObj_LSetSelect(ListObject *_self, PyObject *_args)
    424 {
    425     PyObject *_res = NULL;
    426     Boolean setIt;
    427     Point theCell;
    428     if (!PyArg_ParseTuple(_args, "bO&",
    429                           &setIt,
    430                           PyMac_GetPoint, &theCell))
    431         return NULL;
    432     LSetSelect(setIt,
    433                theCell,
    434                _self->ob_itself);
    435     Py_INCREF(Py_None);
    436     _res = Py_None;
    437     return _res;
    438 }
    439 
    440 static PyObject *ListObj_LDraw(ListObject *_self, PyObject *_args)
    441 {
    442     PyObject *_res = NULL;
    443     Point theCell;
    444     if (!PyArg_ParseTuple(_args, "O&",
    445                           PyMac_GetPoint, &theCell))
    446         return NULL;
    447     LDraw(theCell,
    448           _self->ob_itself);
    449     Py_INCREF(Py_None);
    450     _res = Py_None;
    451     return _res;
    452 }
    453 
    454 static PyObject *ListObj_LGetCellDataLocation(ListObject *_self, PyObject *_args)
    455 {
    456     PyObject *_res = NULL;
    457     short offset;
    458     short len;
    459     Point theCell;
    460     if (!PyArg_ParseTuple(_args, "O&",
    461                           PyMac_GetPoint, &theCell))
    462         return NULL;
    463     LGetCellDataLocation(&offset,
    464                          &len,
    465                          theCell,
    466                          _self->ob_itself);
    467     _res = Py_BuildValue("hh",
    468                          offset,
    469                          len);
    470     return _res;
    471 }
    472 
    473 static PyObject *ListObj_GetListPort(ListObject *_self, PyObject *_args)
    474 {
    475     PyObject *_res = NULL;
    476     CGrafPtr _rv;
    477     if (!PyArg_ParseTuple(_args, ""))
    478         return NULL;
    479     _rv = GetListPort(_self->ob_itself);
    480     _res = Py_BuildValue("O&",
    481                          GrafObj_New, _rv);
    482     return _res;
    483 }
    484 
    485 static PyObject *ListObj_GetListVerticalScrollBar(ListObject *_self, PyObject *_args)
    486 {
    487     PyObject *_res = NULL;
    488     ControlHandle _rv;
    489     if (!PyArg_ParseTuple(_args, ""))
    490         return NULL;
    491     _rv = GetListVerticalScrollBar(_self->ob_itself);
    492     _res = Py_BuildValue("O&",
    493                          CtlObj_New, _rv);
    494     return _res;
    495 }
    496 
    497 static PyObject *ListObj_GetListHorizontalScrollBar(ListObject *_self, PyObject *_args)
    498 {
    499     PyObject *_res = NULL;
    500     ControlHandle _rv;
    501     if (!PyArg_ParseTuple(_args, ""))
    502         return NULL;
    503     _rv = GetListHorizontalScrollBar(_self->ob_itself);
    504     _res = Py_BuildValue("O&",
    505                          CtlObj_New, _rv);
    506     return _res;
    507 }
    508 
    509 static PyObject *ListObj_GetListActive(ListObject *_self, PyObject *_args)
    510 {
    511     PyObject *_res = NULL;
    512     Boolean _rv;
    513     if (!PyArg_ParseTuple(_args, ""))
    514         return NULL;
    515     _rv = GetListActive(_self->ob_itself);
    516     _res = Py_BuildValue("b",
    517                          _rv);
    518     return _res;
    519 }
    520 
    521 static PyObject *ListObj_GetListClickTime(ListObject *_self, PyObject *_args)
    522 {
    523     PyObject *_res = NULL;
    524     SInt32 _rv;
    525     if (!PyArg_ParseTuple(_args, ""))
    526         return NULL;
    527     _rv = GetListClickTime(_self->ob_itself);
    528     _res = Py_BuildValue("l",
    529                          _rv);
    530     return _res;
    531 }
    532 
    533 static PyObject *ListObj_GetListRefCon(ListObject *_self, PyObject *_args)
    534 {
    535     PyObject *_res = NULL;
    536     SInt32 _rv;
    537     if (!PyArg_ParseTuple(_args, ""))
    538         return NULL;
    539     _rv = GetListRefCon(_self->ob_itself);
    540     _res = Py_BuildValue("l",
    541                          _rv);
    542     return _res;
    543 }
    544 
    545 static PyObject *ListObj_GetListDefinition(ListObject *_self, PyObject *_args)
    546 {
    547     PyObject *_res = NULL;
    548     Handle _rv;
    549     if (!PyArg_ParseTuple(_args, ""))
    550         return NULL;
    551     _rv = GetListDefinition(_self->ob_itself);
    552     _res = Py_BuildValue("O&",
    553                          ResObj_New, _rv);
    554     return _res;
    555 }
    556 
    557 static PyObject *ListObj_GetListUserHandle(ListObject *_self, PyObject *_args)
    558 {
    559     PyObject *_res = NULL;
    560     Handle _rv;
    561     if (!PyArg_ParseTuple(_args, ""))
    562         return NULL;
    563     _rv = GetListUserHandle(_self->ob_itself);
    564     _res = Py_BuildValue("O&",
    565                          ResObj_New, _rv);
    566     return _res;
    567 }
    568 
    569 static PyObject *ListObj_GetListDataHandle(ListObject *_self, PyObject *_args)
    570 {
    571     PyObject *_res = NULL;
    572     DataHandle _rv;
    573     if (!PyArg_ParseTuple(_args, ""))
    574         return NULL;
    575     _rv = GetListDataHandle(_self->ob_itself);
    576     _res = Py_BuildValue("O&",
    577                          ResObj_New, _rv);
    578     return _res;
    579 }
    580 
    581 static PyObject *ListObj_GetListFlags(ListObject *_self, PyObject *_args)
    582 {
    583     PyObject *_res = NULL;
    584     OptionBits _rv;
    585     if (!PyArg_ParseTuple(_args, ""))
    586         return NULL;
    587     _rv = GetListFlags(_self->ob_itself);
    588     _res = Py_BuildValue("l",
    589                          _rv);
    590     return _res;
    591 }
    592 
    593 static PyObject *ListObj_GetListSelectionFlags(ListObject *_self, PyObject *_args)
    594 {
    595     PyObject *_res = NULL;
    596     OptionBits _rv;
    597     if (!PyArg_ParseTuple(_args, ""))
    598         return NULL;
    599     _rv = GetListSelectionFlags(_self->ob_itself);
    600     _res = Py_BuildValue("l",
    601                          _rv);
    602     return _res;
    603 }
    604 
    605 static PyObject *ListObj_as_Resource(ListObject *_self, PyObject *_args)
    606 {
    607     PyObject *_res = NULL;
    608     Handle _rv;
    609     if (!PyArg_ParseTuple(_args, ""))
    610         return NULL;
    611     _rv = as_Resource(_self->ob_itself);
    612     _res = Py_BuildValue("O&",
    613                          ResObj_New, _rv);
    614     return _res;
    615 }
    616 
    617 static PyMethodDef ListObj_methods[] = {
    618     {"LAddColumn", (PyCFunction)ListObj_LAddColumn, 1,
    619      PyDoc_STR("(short count, short colNum) -> (short _rv)")},
    620     {"LAddRow", (PyCFunction)ListObj_LAddRow, 1,
    621      PyDoc_STR("(short count, short rowNum) -> (short _rv)")},
    622     {"LDelColumn", (PyCFunction)ListObj_LDelColumn, 1,
    623      PyDoc_STR("(short count, short colNum) -> None")},
    624     {"LDelRow", (PyCFunction)ListObj_LDelRow, 1,
    625      PyDoc_STR("(short count, short rowNum) -> None")},
    626     {"LGetSelect", (PyCFunction)ListObj_LGetSelect, 1,
    627      PyDoc_STR("(Boolean next, Point theCell) -> (Boolean _rv, Point theCell)")},
    628     {"LLastClick", (PyCFunction)ListObj_LLastClick, 1,
    629      PyDoc_STR("() -> (Point _rv)")},
    630     {"LNextCell", (PyCFunction)ListObj_LNextCell, 1,
    631      PyDoc_STR("(Boolean hNext, Boolean vNext, Point theCell) -> (Boolean _rv, Point theCell)")},
    632     {"LSize", (PyCFunction)ListObj_LSize, 1,
    633      PyDoc_STR("(short listWidth, short listHeight) -> None")},
    634     {"LSetDrawingMode", (PyCFunction)ListObj_LSetDrawingMode, 1,
    635      PyDoc_STR("(Boolean drawIt) -> None")},
    636     {"LScroll", (PyCFunction)ListObj_LScroll, 1,
    637      PyDoc_STR("(short dCols, short dRows) -> None")},
    638     {"LAutoScroll", (PyCFunction)ListObj_LAutoScroll, 1,
    639      PyDoc_STR("() -> None")},
    640     {"LUpdate", (PyCFunction)ListObj_LUpdate, 1,
    641      PyDoc_STR("(RgnHandle theRgn) -> None")},
    642     {"LActivate", (PyCFunction)ListObj_LActivate, 1,
    643      PyDoc_STR("(Boolean act) -> None")},
    644     {"LCellSize", (PyCFunction)ListObj_LCellSize, 1,
    645      PyDoc_STR("(Point cSize) -> None")},
    646     {"LClick", (PyCFunction)ListObj_LClick, 1,
    647      PyDoc_STR("(Point pt, EventModifiers modifiers) -> (Boolean _rv)")},
    648     {"LAddToCell", (PyCFunction)ListObj_LAddToCell, 1,
    649      PyDoc_STR("(Buffer dataPtr, Point theCell) -> None")},
    650     {"LClrCell", (PyCFunction)ListObj_LClrCell, 1,
    651      PyDoc_STR("(Point theCell) -> None")},
    652     {"LGetCell", (PyCFunction)ListObj_LGetCell, 1,
    653      PyDoc_STR("(Buffer dataPtr, Point theCell) -> (Buffer dataPtr)")},
    654     {"LRect", (PyCFunction)ListObj_LRect, 1,
    655      PyDoc_STR("(Point theCell) -> (Rect cellRect)")},
    656     {"LSetCell", (PyCFunction)ListObj_LSetCell, 1,
    657      PyDoc_STR("(Buffer dataPtr, Point theCell) -> None")},
    658     {"LSetSelect", (PyCFunction)ListObj_LSetSelect, 1,
    659      PyDoc_STR("(Boolean setIt, Point theCell) -> None")},
    660     {"LDraw", (PyCFunction)ListObj_LDraw, 1,
    661      PyDoc_STR("(Point theCell) -> None")},
    662     {"LGetCellDataLocation", (PyCFunction)ListObj_LGetCellDataLocation, 1,
    663      PyDoc_STR("(Point theCell) -> (short offset, short len)")},
    664     {"GetListPort", (PyCFunction)ListObj_GetListPort, 1,
    665      PyDoc_STR("() -> (CGrafPtr _rv)")},
    666     {"GetListVerticalScrollBar", (PyCFunction)ListObj_GetListVerticalScrollBar, 1,
    667      PyDoc_STR("() -> (ControlHandle _rv)")},
    668     {"GetListHorizontalScrollBar", (PyCFunction)ListObj_GetListHorizontalScrollBar, 1,
    669      PyDoc_STR("() -> (ControlHandle _rv)")},
    670     {"GetListActive", (PyCFunction)ListObj_GetListActive, 1,
    671      PyDoc_STR("() -> (Boolean _rv)")},
    672     {"GetListClickTime", (PyCFunction)ListObj_GetListClickTime, 1,
    673      PyDoc_STR("() -> (SInt32 _rv)")},
    674     {"GetListRefCon", (PyCFunction)ListObj_GetListRefCon, 1,
    675      PyDoc_STR("() -> (SInt32 _rv)")},
    676     {"GetListDefinition", (PyCFunction)ListObj_GetListDefinition, 1,
    677      PyDoc_STR("() -> (Handle _rv)")},
    678     {"GetListUserHandle", (PyCFunction)ListObj_GetListUserHandle, 1,
    679      PyDoc_STR("() -> (Handle _rv)")},
    680     {"GetListDataHandle", (PyCFunction)ListObj_GetListDataHandle, 1,
    681      PyDoc_STR("() -> (DataHandle _rv)")},
    682     {"GetListFlags", (PyCFunction)ListObj_GetListFlags, 1,
    683      PyDoc_STR("() -> (OptionBits _rv)")},
    684     {"GetListSelectionFlags", (PyCFunction)ListObj_GetListSelectionFlags, 1,
    685      PyDoc_STR("() -> (OptionBits _rv)")},
    686     {"as_Resource", (PyCFunction)ListObj_as_Resource, 1,
    687      PyDoc_STR("() -> (Handle _rv)")},
    688     {NULL, NULL, 0}
    689 };
    690 
    691 static PyObject *ListObj_get_listFlags(ListObject *self, void *closure)
    692 {
    693     return Py_BuildValue("l", (long)GetListFlags(self->ob_itself) & 0xff);
    694 }
    695 
    696 static int ListObj_set_listFlags(ListObject *self, PyObject *v, void *closure)
    697 {
    698     if (!PyArg_Parse(v, "B", &(*self->ob_itself)->listFlags)) return -1;
    699     return 0;
    700 }
    701 
    702 static PyObject *ListObj_get_selFlags(ListObject *self, void *closure)
    703 {
    704     return Py_BuildValue("l", (long)GetListSelectionFlags(self->ob_itself) & 0xff);
    705 }
    706 
    707 static int ListObj_set_selFlags(ListObject *self, PyObject *v, void *closure)
    708 {
    709     if (!PyArg_Parse(v, "B", &(*self->ob_itself)->selFlags)) return -1;
    710     return 0;
    711 }
    712 
    713 static PyObject *ListObj_get_cellSize(ListObject *self, void *closure)
    714 {
    715     return Py_BuildValue("O&", PyMac_BuildPoint, (*self->ob_itself)->cellSize);
    716 }
    717 
    718 static int ListObj_set_cellSize(ListObject *self, PyObject *v, void *closure)
    719 {
    720     if (!PyArg_Parse(v, "O&", PyMac_GetPoint, &(*self->ob_itself)->cellSize)) return -1;
    721     return 0;
    722 }
    723 
    724 static PyGetSetDef ListObj_getsetlist[] = {
    725     {"listFlags", (getter)ListObj_get_listFlags, (setter)ListObj_set_listFlags, NULL},
    726     {"selFlags", (getter)ListObj_get_selFlags, (setter)ListObj_set_selFlags, NULL},
    727     {"cellSize", (getter)ListObj_get_cellSize, (setter)ListObj_set_cellSize, NULL},
    728     {NULL, NULL, NULL, NULL},
    729 };
    730 
    731 
    732 #define ListObj_compare NULL
    733 
    734 #define ListObj_repr NULL
    735 
    736 #define ListObj_hash NULL
    737 #define ListObj_tp_init 0
    738 
    739 #define ListObj_tp_alloc PyType_GenericAlloc
    740 
    741 static PyObject *ListObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
    742 {
    743     PyObject *_self;
    744     ListHandle itself;
    745     char *kw[] = {"itself", 0};
    746 
    747     if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, ListObj_Convert, &itself)) return NULL;
    748     if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL;
    749     ((ListObject *)_self)->ob_itself = itself;
    750     return _self;
    751 }
    752 
    753 #define ListObj_tp_free PyObject_Del
    754 
    755 
    756 PyTypeObject List_Type = {
    757     PyObject_HEAD_INIT(NULL)
    758     0, /*ob_size*/
    759     "_List.List", /*tp_name*/
    760     sizeof(ListObject), /*tp_basicsize*/
    761     0, /*tp_itemsize*/
    762     /* methods */
    763     (destructor) ListObj_dealloc, /*tp_dealloc*/
    764     0, /*tp_print*/
    765     (getattrfunc)0, /*tp_getattr*/
    766     (setattrfunc)0, /*tp_setattr*/
    767     (cmpfunc) ListObj_compare, /*tp_compare*/
    768     (reprfunc) ListObj_repr, /*tp_repr*/
    769     (PyNumberMethods *)0, /* tp_as_number */
    770     (PySequenceMethods *)0, /* tp_as_sequence */
    771     (PyMappingMethods *)0, /* tp_as_mapping */
    772     (hashfunc) ListObj_hash, /*tp_hash*/
    773     0, /*tp_call*/
    774     0, /*tp_str*/
    775     PyObject_GenericGetAttr, /*tp_getattro*/
    776     PyObject_GenericSetAttr, /*tp_setattro */
    777     0, /*tp_as_buffer*/
    778     Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
    779     0, /*tp_doc*/
    780     0, /*tp_traverse*/
    781     0, /*tp_clear*/
    782     0, /*tp_richcompare*/
    783     0, /*tp_weaklistoffset*/
    784     0, /*tp_iter*/
    785     0, /*tp_iternext*/
    786     ListObj_methods, /* tp_methods */
    787     0, /*tp_members*/
    788     ListObj_getsetlist, /*tp_getset*/
    789     0, /*tp_base*/
    790     0, /*tp_dict*/
    791     0, /*tp_descr_get*/
    792     0, /*tp_descr_set*/
    793     0, /*tp_dictoffset*/
    794     ListObj_tp_init, /* tp_init */
    795     ListObj_tp_alloc, /* tp_alloc */
    796     ListObj_tp_new, /* tp_new */
    797     ListObj_tp_free, /* tp_free */
    798 };
    799 
    800 /* ---------------------- End object type List ---------------------- */
    801 
    802 
    803 static PyObject *List_CreateCustomList(PyObject *_self, PyObject *_args)
    804 {
    805     PyObject *_res = NULL;
    806     Rect rView;
    807     Rect dataBounds;
    808     Point cellSize;
    809 
    810     PyObject *listDefFunc;
    811     ListDefSpec theSpec;
    812     WindowPtr theWindow;
    813     Boolean drawIt;
    814     Boolean hasGrow;
    815     Boolean scrollHoriz;
    816     Boolean scrollVert;
    817     ListHandle outList;
    818 
    819     if (!PyArg_ParseTuple(_args, "O&O&O&(iO)O&bbbb",
    820                           PyMac_GetRect, &rView,
    821                           PyMac_GetRect, &dataBounds,
    822                           PyMac_GetPoint, &cellSize,
    823                           &theSpec.defType, &listDefFunc,
    824                           WinObj_Convert, &theWindow,
    825                           &drawIt,
    826                           &hasGrow,
    827                           &scrollHoriz,
    828                           &scrollVert))
    829         return NULL;
    830 
    831 
    832     /* Carbon applications use the CreateCustomList API */
    833     theSpec.u.userProc = myListDefFunctionUPP;
    834     CreateCustomList(&rView,
    835                      &dataBounds,
    836                      cellSize,
    837                      &theSpec,
    838                      theWindow,
    839                      drawIt,
    840                      hasGrow,
    841                      scrollHoriz,
    842                      scrollVert,
    843                      &outList);
    844 
    845 
    846     _res = ListObj_New(outList);
    847     if (_res == NULL)
    848         return NULL;
    849     Py_INCREF(listDefFunc);
    850     ((ListObject*)_res)->ob_ldef_func = listDefFunc;
    851     return _res;
    852 }
    853 
    854 static PyObject *List_LNew(PyObject *_self, PyObject *_args)
    855 {
    856     PyObject *_res = NULL;
    857     ListHandle _rv;
    858     Rect rView;
    859     Rect dataBounds;
    860     Point cSize;
    861     short theProc;
    862     WindowPtr theWindow;
    863     Boolean drawIt;
    864     Boolean hasGrow;
    865     Boolean scrollHoriz;
    866     Boolean scrollVert;
    867     if (!PyArg_ParseTuple(_args, "O&O&O&hO&bbbb",
    868                           PyMac_GetRect, &rView,
    869                           PyMac_GetRect, &dataBounds,
    870                           PyMac_GetPoint, &cSize,
    871                           &theProc,
    872                           WinObj_Convert, &theWindow,
    873                           &drawIt,
    874                           &hasGrow,
    875                           &scrollHoriz,
    876                           &scrollVert))
    877         return NULL;
    878     _rv = LNew(&rView,
    879                &dataBounds,
    880                cSize,
    881                theProc,
    882                theWindow,
    883                drawIt,
    884                hasGrow,
    885                scrollHoriz,
    886                scrollVert);
    887     _res = Py_BuildValue("O&",
    888                          ListObj_New, _rv);
    889     return _res;
    890 }
    891 
    892 static PyObject *List_SetListViewBounds(PyObject *_self, PyObject *_args)
    893 {
    894     PyObject *_res = NULL;
    895     ListHandle list;
    896     Rect view;
    897     if (!PyArg_ParseTuple(_args, "O&O&",
    898                           ListObj_Convert, &list,
    899                           PyMac_GetRect, &view))
    900         return NULL;
    901     SetListViewBounds(list,
    902                       &view);
    903     Py_INCREF(Py_None);
    904     _res = Py_None;
    905     return _res;
    906 }
    907 
    908 static PyObject *List_SetListPort(PyObject *_self, PyObject *_args)
    909 {
    910     PyObject *_res = NULL;
    911     ListHandle list;
    912     CGrafPtr port;
    913     if (!PyArg_ParseTuple(_args, "O&O&",
    914                           ListObj_Convert, &list,
    915                           GrafObj_Convert, &port))
    916         return NULL;
    917     SetListPort(list,
    918                 port);
    919     Py_INCREF(Py_None);
    920     _res = Py_None;
    921     return _res;
    922 }
    923 
    924 static PyObject *List_SetListCellIndent(PyObject *_self, PyObject *_args)
    925 {
    926     PyObject *_res = NULL;
    927     ListHandle list;
    928     Point indent;
    929     if (!PyArg_ParseTuple(_args, "O&O&",
    930                           ListObj_Convert, &list,
    931                           PyMac_GetPoint, &indent))
    932         return NULL;
    933     SetListCellIndent(list,
    934                       &indent);
    935     Py_INCREF(Py_None);
    936     _res = Py_None;
    937     return _res;
    938 }
    939 
    940 static PyObject *List_SetListClickTime(PyObject *_self, PyObject *_args)
    941 {
    942     PyObject *_res = NULL;
    943     ListHandle list;
    944     SInt32 time;
    945     if (!PyArg_ParseTuple(_args, "O&l",
    946                           ListObj_Convert, &list,
    947                           &time))
    948         return NULL;
    949     SetListClickTime(list,
    950                      time);
    951     Py_INCREF(Py_None);
    952     _res = Py_None;
    953     return _res;
    954 }
    955 
    956 static PyObject *List_SetListRefCon(PyObject *_self, PyObject *_args)
    957 {
    958     PyObject *_res = NULL;
    959     ListHandle list;
    960     SInt32 refCon;
    961     if (!PyArg_ParseTuple(_args, "O&l",
    962                           ListObj_Convert, &list,
    963                           &refCon))
    964         return NULL;
    965     SetListRefCon(list,
    966                   refCon);
    967     Py_INCREF(Py_None);
    968     _res = Py_None;
    969     return _res;
    970 }
    971 
    972 static PyObject *List_SetListUserHandle(PyObject *_self, PyObject *_args)
    973 {
    974     PyObject *_res = NULL;
    975     ListHandle list;
    976     Handle userHandle;
    977     if (!PyArg_ParseTuple(_args, "O&O&",
    978                           ListObj_Convert, &list,
    979                           ResObj_Convert, &userHandle))
    980         return NULL;
    981     SetListUserHandle(list,
    982                       userHandle);
    983     Py_INCREF(Py_None);
    984     _res = Py_None;
    985     return _res;
    986 }
    987 
    988 static PyObject *List_SetListFlags(PyObject *_self, PyObject *_args)
    989 {
    990     PyObject *_res = NULL;
    991     ListHandle list;
    992     OptionBits listFlags;
    993     if (!PyArg_ParseTuple(_args, "O&l",
    994                           ListObj_Convert, &list,
    995                           &listFlags))
    996         return NULL;
    997     SetListFlags(list,
    998                  listFlags);
    999     Py_INCREF(Py_None);
   1000     _res = Py_None;
   1001     return _res;
   1002 }
   1003 
   1004 static PyObject *List_SetListSelectionFlags(PyObject *_self, PyObject *_args)
   1005 {
   1006     PyObject *_res = NULL;
   1007     ListHandle list;
   1008     OptionBits selectionFlags;
   1009     if (!PyArg_ParseTuple(_args, "O&l",
   1010                           ListObj_Convert, &list,
   1011                           &selectionFlags))
   1012         return NULL;
   1013     SetListSelectionFlags(list,
   1014                           selectionFlags);
   1015     Py_INCREF(Py_None);
   1016     _res = Py_None;
   1017     return _res;
   1018 }
   1019 
   1020 static PyObject *List_as_List(PyObject *_self, PyObject *_args)
   1021 {
   1022     PyObject *_res = NULL;
   1023 
   1024     Handle h;
   1025     ListObject *l;
   1026     if (!PyArg_ParseTuple(_args, "O&", ResObj_Convert, &h))
   1027         return NULL;
   1028     l = (ListObject *)ListObj_New(as_List(h));
   1029     l->ob_must_be_disposed = 0;
   1030     _res = Py_BuildValue("O", l);
   1031     return _res;
   1032 
   1033 }
   1034 #endif /* APPLE_SUPPORTS_QUICKTIME */
   1035 
   1036 static PyMethodDef List_methods[] = {
   1037 #if APPLE_SUPPORTS_QUICKTIME
   1038     {"CreateCustomList", (PyCFunction)List_CreateCustomList, 1,
   1039      PyDoc_STR("(Rect rView, Rect dataBounds, Point cellSize, ListDefSpec theSpec, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle outList)")},
   1040     {"LNew", (PyCFunction)List_LNew, 1,
   1041      PyDoc_STR("(Rect rView, Rect dataBounds, Point cSize, short theProc, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle _rv)")},
   1042     {"SetListViewBounds", (PyCFunction)List_SetListViewBounds, 1,
   1043      PyDoc_STR("(ListHandle list, Rect view) -> None")},
   1044     {"SetListPort", (PyCFunction)List_SetListPort, 1,
   1045      PyDoc_STR("(ListHandle list, CGrafPtr port) -> None")},
   1046     {"SetListCellIndent", (PyCFunction)List_SetListCellIndent, 1,
   1047      PyDoc_STR("(ListHandle list, Point indent) -> None")},
   1048     {"SetListClickTime", (PyCFunction)List_SetListClickTime, 1,
   1049      PyDoc_STR("(ListHandle list, SInt32 time) -> None")},
   1050     {"SetListRefCon", (PyCFunction)List_SetListRefCon, 1,
   1051      PyDoc_STR("(ListHandle list, SInt32 refCon) -> None")},
   1052     {"SetListUserHandle", (PyCFunction)List_SetListUserHandle, 1,
   1053      PyDoc_STR("(ListHandle list, Handle userHandle) -> None")},
   1054     {"SetListFlags", (PyCFunction)List_SetListFlags, 1,
   1055      PyDoc_STR("(ListHandle list, OptionBits listFlags) -> None")},
   1056     {"SetListSelectionFlags", (PyCFunction)List_SetListSelectionFlags, 1,
   1057      PyDoc_STR("(ListHandle list, OptionBits selectionFlags) -> None")},
   1058     {"as_List", (PyCFunction)List_as_List, 1,
   1059      PyDoc_STR("(Resource)->List.\nReturns List object (which is not auto-freed!)")},
   1060 #endif /* APPLE_SUPPORTS_QUICKTIME */
   1061     {NULL, NULL, 0}
   1062 };
   1063 
   1064 #if APPLE_SUPPORTS_QUICKTIME
   1065 
   1066 
   1067 static void myListDefFunction(SInt16 message,
   1068                        Boolean selected,
   1069                        Rect *cellRect,
   1070                        Cell theCell,
   1071                        SInt16 dataOffset,
   1072                        SInt16 dataLen,
   1073                        ListHandle theList)
   1074 {
   1075     PyObject *listDefFunc, *args, *rv=NULL;
   1076     ListObject *self;
   1077 
   1078     self = (ListObject*)GetListRefCon(theList);
   1079     if (self == NULL || self->ob_itself != theList)
   1080         return;  /* nothing we can do */
   1081     listDefFunc = self->ob_ldef_func;
   1082     if (listDefFunc == NULL)
   1083         return;  /* nothing we can do */
   1084     args = Py_BuildValue("hbO&O&hhO", message,
   1085                                       selected,
   1086                                       PyMac_BuildRect, cellRect,
   1087                                       PyMac_BuildPoint, theCell,
   1088                                       dataOffset,
   1089                                       dataLen,
   1090                                       self);
   1091     if (args != NULL) {
   1092         rv = PyEval_CallObject(listDefFunc, args);
   1093         Py_DECREF(args);
   1094     }
   1095     if (rv == NULL) {
   1096         PySys_WriteStderr("error in list definition callback:\n");
   1097         PyErr_Print();
   1098     } else {
   1099         Py_DECREF(rv);
   1100     }
   1101 }
   1102 #endif /* APPLE_SUPPORTS_QUICKTIME */
   1103 
   1104 
   1105 void init_List(void)
   1106 {
   1107     PyObject *m;
   1108 #if APPLE_SUPPORTS_QUICKTIME
   1109     PyObject *d;
   1110 
   1111 
   1112 
   1113     myListDefFunctionUPP = NewListDefUPP((ListDefProcPtr)myListDefFunction);
   1114 
   1115     PyMac_INIT_TOOLBOX_OBJECT_NEW(ListHandle, ListObj_New);
   1116     PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ListHandle, ListObj_Convert);
   1117 #endif /* APPLE_SUPPORTS_QUICKTIME */
   1118 
   1119 
   1120     m = Py_InitModule("_List", List_methods);
   1121 #if APPLE_SUPPORTS_QUICKTIME
   1122     d = PyModule_GetDict(m);
   1123     List_Error = PyMac_GetOSErrException();
   1124     if (List_Error == NULL ||
   1125         PyDict_SetItemString(d, "Error", List_Error) != 0)
   1126         return;
   1127     List_Type.ob_type = &PyType_Type;
   1128     if (PyType_Ready(&List_Type) < 0) return;
   1129     Py_INCREF(&List_Type);
   1130     PyModule_AddObject(m, "List", (PyObject *)&List_Type);
   1131     /* Backward-compatible name */
   1132     Py_INCREF(&List_Type);
   1133     PyModule_AddObject(m, "ListType", (PyObject *)&List_Type);
   1134 #endif /* APPLE_SUPPORTS_QUICKTIME */
   1135 }
   1136 
   1137 /* ======================== End module _List ======================== */
   1138 
   1139