Home | History | Annotate | Download | only in cm
      1 
      2 /* =========================== Module _Cm =========================== */
      3 
      4 #include "Python.h"
      5 
      6 
      7 
      8 #include "pymactoolbox.h"
      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 *_CmpObj_New(Component);
     22 extern int _CmpObj_Convert(PyObject *, Component *);
     23 extern PyObject *_CmpInstObj_New(ComponentInstance);
     24 extern int _CmpInstObj_Convert(PyObject *, ComponentInstance *);
     25 
     26 #define CmpObj_New _CmpObj_New
     27 #define CmpObj_Convert _CmpObj_Convert
     28 #define CmpInstObj_New _CmpInstObj_New
     29 #define CmpInstObj_Convert _CmpInstObj_Convert
     30 #endif
     31 
     32 /*
     33 ** Parse/generate ComponentDescriptor records
     34 */
     35 static PyObject *
     36 CmpDesc_New(ComponentDescription *itself)
     37 {
     38 
     39     return Py_BuildValue("O&O&O&ll",
     40         PyMac_BuildOSType, itself->componentType,
     41         PyMac_BuildOSType, itself->componentSubType,
     42         PyMac_BuildOSType, itself->componentManufacturer,
     43         itself->componentFlags, itself->componentFlagsMask);
     44 }
     45 
     46 static int
     47 CmpDesc_Convert(PyObject *v, ComponentDescription *p_itself)
     48 {
     49     return PyArg_ParseTuple(v, "O&O&O&ll",
     50         PyMac_GetOSType, &p_itself->componentType,
     51         PyMac_GetOSType, &p_itself->componentSubType,
     52         PyMac_GetOSType, &p_itself->componentManufacturer,
     53         &p_itself->componentFlags, &p_itself->componentFlagsMask);
     54 }
     55 
     56 
     57 static PyObject *Cm_Error;
     58 
     59 /* ----------------- Object type ComponentInstance ------------------ */
     60 
     61 PyTypeObject ComponentInstance_Type;
     62 
     63 #define CmpInstObj_Check(x) ((x)->ob_type == &ComponentInstance_Type || PyObject_TypeCheck((x), &ComponentInstance_Type))
     64 
     65 typedef struct ComponentInstanceObject {
     66     PyObject_HEAD
     67     ComponentInstance ob_itself;
     68 } ComponentInstanceObject;
     69 
     70 PyObject *CmpInstObj_New(ComponentInstance itself)
     71 {
     72     ComponentInstanceObject *it;
     73     if (itself == NULL) {
     74                                     PyErr_SetString(Cm_Error,"NULL ComponentInstance");
     75                                     return NULL;
     76                             }
     77     it = PyObject_NEW(ComponentInstanceObject, &ComponentInstance_Type);
     78     if (it == NULL) return NULL;
     79     it->ob_itself = itself;
     80     return (PyObject *)it;
     81 }
     82 
     83 int CmpInstObj_Convert(PyObject *v, ComponentInstance *p_itself)
     84 {
     85     if (!CmpInstObj_Check(v))
     86     {
     87         PyErr_SetString(PyExc_TypeError, "ComponentInstance required");
     88         return 0;
     89     }
     90     *p_itself = ((ComponentInstanceObject *)v)->ob_itself;
     91     return 1;
     92 }
     93 
     94 static void CmpInstObj_dealloc(ComponentInstanceObject *self)
     95 {
     96     /* Cleanup of self->ob_itself goes here */
     97     self->ob_type->tp_free((PyObject *)self);
     98 }
     99 
    100 static PyObject *CmpInstObj_CloseComponent(ComponentInstanceObject *_self, PyObject *_args)
    101 {
    102     PyObject *_res = NULL;
    103     OSErr _err;
    104 #ifndef CloseComponent
    105     PyMac_PRECHECK(CloseComponent);
    106 #endif
    107     if (!PyArg_ParseTuple(_args, ""))
    108         return NULL;
    109     _err = CloseComponent(_self->ob_itself);
    110     if (_err != noErr) return PyMac_Error(_err);
    111     Py_INCREF(Py_None);
    112     _res = Py_None;
    113     return _res;
    114 }
    115 
    116 static PyObject *CmpInstObj_GetComponentInstanceError(ComponentInstanceObject *_self, PyObject *_args)
    117 {
    118     PyObject *_res = NULL;
    119     OSErr _err;
    120 #ifndef GetComponentInstanceError
    121     PyMac_PRECHECK(GetComponentInstanceError);
    122 #endif
    123     if (!PyArg_ParseTuple(_args, ""))
    124         return NULL;
    125     _err = GetComponentInstanceError(_self->ob_itself);
    126     if (_err != noErr) return PyMac_Error(_err);
    127     Py_INCREF(Py_None);
    128     _res = Py_None;
    129     return _res;
    130 }
    131 
    132 static PyObject *CmpInstObj_SetComponentInstanceError(ComponentInstanceObject *_self, PyObject *_args)
    133 {
    134     PyObject *_res = NULL;
    135     OSErr theError;
    136 #ifndef SetComponentInstanceError
    137     PyMac_PRECHECK(SetComponentInstanceError);
    138 #endif
    139     if (!PyArg_ParseTuple(_args, "h",
    140                           &theError))
    141         return NULL;
    142     SetComponentInstanceError(_self->ob_itself,
    143                               theError);
    144     Py_INCREF(Py_None);
    145     _res = Py_None;
    146     return _res;
    147 }
    148 
    149 static PyObject *CmpInstObj_GetComponentInstanceStorage(ComponentInstanceObject *_self, PyObject *_args)
    150 {
    151     PyObject *_res = NULL;
    152     Handle _rv;
    153 #ifndef GetComponentInstanceStorage
    154     PyMac_PRECHECK(GetComponentInstanceStorage);
    155 #endif
    156     if (!PyArg_ParseTuple(_args, ""))
    157         return NULL;
    158     _rv = GetComponentInstanceStorage(_self->ob_itself);
    159     _res = Py_BuildValue("O&",
    160                          ResObj_New, _rv);
    161     return _res;
    162 }
    163 
    164 static PyObject *CmpInstObj_SetComponentInstanceStorage(ComponentInstanceObject *_self, PyObject *_args)
    165 {
    166     PyObject *_res = NULL;
    167     Handle theStorage;
    168 #ifndef SetComponentInstanceStorage
    169     PyMac_PRECHECK(SetComponentInstanceStorage);
    170 #endif
    171     if (!PyArg_ParseTuple(_args, "O&",
    172                           ResObj_Convert, &theStorage))
    173         return NULL;
    174     SetComponentInstanceStorage(_self->ob_itself,
    175                                 theStorage);
    176     Py_INCREF(Py_None);
    177     _res = Py_None;
    178     return _res;
    179 }
    180 
    181 #ifndef __LP64__
    182 static PyObject *CmpInstObj_ComponentFunctionImplemented(ComponentInstanceObject *_self, PyObject *_args)
    183 {
    184     PyObject *_res = NULL;
    185     long _rv;
    186     short ftnNumber;
    187 #ifndef ComponentFunctionImplemented
    188     PyMac_PRECHECK(ComponentFunctionImplemented);
    189 #endif
    190     if (!PyArg_ParseTuple(_args, "h",
    191                           &ftnNumber))
    192         return NULL;
    193     _rv = ComponentFunctionImplemented(_self->ob_itself,
    194                                        ftnNumber);
    195     _res = Py_BuildValue("l",
    196                          _rv);
    197     return _res;
    198 }
    199 
    200 static PyObject *CmpInstObj_GetComponentVersion(ComponentInstanceObject *_self, PyObject *_args)
    201 {
    202     PyObject *_res = NULL;
    203     long _rv;
    204 #ifndef GetComponentVersion
    205     PyMac_PRECHECK(GetComponentVersion);
    206 #endif
    207     if (!PyArg_ParseTuple(_args, ""))
    208         return NULL;
    209     _rv = GetComponentVersion(_self->ob_itself);
    210     _res = Py_BuildValue("l",
    211                          _rv);
    212     return _res;
    213 }
    214 
    215 static PyObject *CmpInstObj_ComponentSetTarget(ComponentInstanceObject *_self, PyObject *_args)
    216 {
    217     PyObject *_res = NULL;
    218     long _rv;
    219     ComponentInstance target;
    220 #ifndef ComponentSetTarget
    221     PyMac_PRECHECK(ComponentSetTarget);
    222 #endif
    223     if (!PyArg_ParseTuple(_args, "O&",
    224                           CmpInstObj_Convert, &target))
    225         return NULL;
    226     _rv = ComponentSetTarget(_self->ob_itself,
    227                              target);
    228     _res = Py_BuildValue("l",
    229                          _rv);
    230     return _res;
    231 }
    232 #endif /* !__LP64__*/
    233 
    234 static PyMethodDef CmpInstObj_methods[] = {
    235     {"CloseComponent", (PyCFunction)CmpInstObj_CloseComponent, 1,
    236      PyDoc_STR("() -> None")},
    237     {"GetComponentInstanceError", (PyCFunction)CmpInstObj_GetComponentInstanceError, 1,
    238      PyDoc_STR("() -> None")},
    239     {"SetComponentInstanceError", (PyCFunction)CmpInstObj_SetComponentInstanceError, 1,
    240      PyDoc_STR("(OSErr theError) -> None")},
    241     {"GetComponentInstanceStorage", (PyCFunction)CmpInstObj_GetComponentInstanceStorage, 1,
    242      PyDoc_STR("() -> (Handle _rv)")},
    243     {"SetComponentInstanceStorage", (PyCFunction)CmpInstObj_SetComponentInstanceStorage, 1,
    244      PyDoc_STR("(Handle theStorage) -> None")},
    245 #ifndef __LP64__
    246     {"ComponentFunctionImplemented", (PyCFunction)CmpInstObj_ComponentFunctionImplemented, 1,
    247      PyDoc_STR("(short ftnNumber) -> (long _rv)")},
    248     {"GetComponentVersion", (PyCFunction)CmpInstObj_GetComponentVersion, 1,
    249      PyDoc_STR("() -> (long _rv)")},
    250     {"ComponentSetTarget", (PyCFunction)CmpInstObj_ComponentSetTarget, 1,
    251      PyDoc_STR("(ComponentInstance target) -> (long _rv)")},
    252 #endif /* !__LP64__ */
    253     {NULL, NULL, 0}
    254 };
    255 
    256 #define CmpInstObj_getsetlist NULL
    257 
    258 
    259 #define CmpInstObj_compare NULL
    260 
    261 #define CmpInstObj_repr NULL
    262 
    263 #define CmpInstObj_hash NULL
    264 #define CmpInstObj_tp_init 0
    265 
    266 #define CmpInstObj_tp_alloc PyType_GenericAlloc
    267 
    268 static PyObject *CmpInstObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
    269 {
    270     PyObject *_self;
    271     ComponentInstance itself;
    272     char *kw[] = {"itself", 0};
    273 
    274     if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CmpInstObj_Convert, &itself)) return NULL;
    275     if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL;
    276     ((ComponentInstanceObject *)_self)->ob_itself = itself;
    277     return _self;
    278 }
    279 
    280 #define CmpInstObj_tp_free PyObject_Del
    281 
    282 
    283 PyTypeObject ComponentInstance_Type = {
    284     PyObject_HEAD_INIT(NULL)
    285     0, /*ob_size*/
    286     "_Cm.ComponentInstance", /*tp_name*/
    287     sizeof(ComponentInstanceObject), /*tp_basicsize*/
    288     0, /*tp_itemsize*/
    289     /* methods */
    290     (destructor) CmpInstObj_dealloc, /*tp_dealloc*/
    291     0, /*tp_print*/
    292     (getattrfunc)0, /*tp_getattr*/
    293     (setattrfunc)0, /*tp_setattr*/
    294     (cmpfunc) CmpInstObj_compare, /*tp_compare*/
    295     (reprfunc) CmpInstObj_repr, /*tp_repr*/
    296     (PyNumberMethods *)0, /* tp_as_number */
    297     (PySequenceMethods *)0, /* tp_as_sequence */
    298     (PyMappingMethods *)0, /* tp_as_mapping */
    299     (hashfunc) CmpInstObj_hash, /*tp_hash*/
    300     0, /*tp_call*/
    301     0, /*tp_str*/
    302     PyObject_GenericGetAttr, /*tp_getattro*/
    303     PyObject_GenericSetAttr, /*tp_setattro */
    304     0, /*tp_as_buffer*/
    305     Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
    306     0, /*tp_doc*/
    307     0, /*tp_traverse*/
    308     0, /*tp_clear*/
    309     0, /*tp_richcompare*/
    310     0, /*tp_weaklistoffset*/
    311     0, /*tp_iter*/
    312     0, /*tp_iternext*/
    313     CmpInstObj_methods, /* tp_methods */
    314     0, /*tp_members*/
    315     CmpInstObj_getsetlist, /*tp_getset*/
    316     0, /*tp_base*/
    317     0, /*tp_dict*/
    318     0, /*tp_descr_get*/
    319     0, /*tp_descr_set*/
    320     0, /*tp_dictoffset*/
    321     CmpInstObj_tp_init, /* tp_init */
    322     CmpInstObj_tp_alloc, /* tp_alloc */
    323     CmpInstObj_tp_new, /* tp_new */
    324     CmpInstObj_tp_free, /* tp_free */
    325 };
    326 
    327 /* --------------- End object type ComponentInstance ---------------- */
    328 
    329 
    330 /* --------------------- Object type Component ---------------------- */
    331 
    332 PyTypeObject Component_Type;
    333 
    334 #define CmpObj_Check(x) ((x)->ob_type == &Component_Type || PyObject_TypeCheck((x), &Component_Type))
    335 
    336 typedef struct ComponentObject {
    337     PyObject_HEAD
    338     Component ob_itself;
    339 } ComponentObject;
    340 
    341 PyObject *CmpObj_New(Component itself)
    342 {
    343     ComponentObject *it;
    344     if (itself == NULL) {
    345                                     /* XXXX Or should we return None? */
    346                     PyErr_SetString(Cm_Error,"No such component");
    347                     return NULL;
    348                 }
    349     it = PyObject_NEW(ComponentObject, &Component_Type);
    350     if (it == NULL) return NULL;
    351     it->ob_itself = itself;
    352     return (PyObject *)it;
    353 }
    354 
    355 int CmpObj_Convert(PyObject *v, Component *p_itself)
    356 {
    357     if ( v == Py_None ) {
    358                                     *p_itself = 0;
    359                                     return 1;
    360         }
    361     if (!CmpObj_Check(v))
    362     {
    363         PyErr_SetString(PyExc_TypeError, "Component required");
    364         return 0;
    365     }
    366     *p_itself = ((ComponentObject *)v)->ob_itself;
    367     return 1;
    368 }
    369 
    370 static void CmpObj_dealloc(ComponentObject *self)
    371 {
    372     /* Cleanup of self->ob_itself goes here */
    373     self->ob_type->tp_free((PyObject *)self);
    374 }
    375 
    376 static PyObject *CmpObj_UnregisterComponent(ComponentObject *_self, PyObject *_args)
    377 {
    378     PyObject *_res = NULL;
    379     OSErr _err;
    380 #ifndef UnregisterComponent
    381     PyMac_PRECHECK(UnregisterComponent);
    382 #endif
    383     if (!PyArg_ParseTuple(_args, ""))
    384         return NULL;
    385     _err = UnregisterComponent(_self->ob_itself);
    386     if (_err != noErr) return PyMac_Error(_err);
    387     Py_INCREF(Py_None);
    388     _res = Py_None;
    389     return _res;
    390 }
    391 
    392 static PyObject *CmpObj_GetComponentInfo(ComponentObject *_self, PyObject *_args)
    393 {
    394     PyObject *_res = NULL;
    395     OSErr _err;
    396     ComponentDescription cd;
    397     Handle componentName;
    398     Handle componentInfo;
    399     Handle componentIcon;
    400 #ifndef GetComponentInfo
    401     PyMac_PRECHECK(GetComponentInfo);
    402 #endif
    403     if (!PyArg_ParseTuple(_args, "O&O&O&",
    404                           ResObj_Convert, &componentName,
    405                           ResObj_Convert, &componentInfo,
    406                           ResObj_Convert, &componentIcon))
    407         return NULL;
    408     _err = GetComponentInfo(_self->ob_itself,
    409                             &cd,
    410                             componentName,
    411                             componentInfo,
    412                             componentIcon);
    413     if (_err != noErr) return PyMac_Error(_err);
    414     _res = Py_BuildValue("O&",
    415                          CmpDesc_New, &cd);
    416     return _res;
    417 }
    418 
    419 static PyObject *CmpObj_OpenComponent(ComponentObject *_self, PyObject *_args)
    420 {
    421     PyObject *_res = NULL;
    422     ComponentInstance _rv;
    423 #ifndef OpenComponent
    424     PyMac_PRECHECK(OpenComponent);
    425 #endif
    426     if (!PyArg_ParseTuple(_args, ""))
    427         return NULL;
    428     _rv = OpenComponent(_self->ob_itself);
    429     _res = Py_BuildValue("O&",
    430                          CmpInstObj_New, _rv);
    431     return _res;
    432 }
    433 
    434 static PyObject *CmpObj_ResolveComponentAlias(ComponentObject *_self, PyObject *_args)
    435 {
    436     PyObject *_res = NULL;
    437     Component _rv;
    438 #ifndef ResolveComponentAlias
    439     PyMac_PRECHECK(ResolveComponentAlias);
    440 #endif
    441     if (!PyArg_ParseTuple(_args, ""))
    442         return NULL;
    443     _rv = ResolveComponentAlias(_self->ob_itself);
    444     _res = Py_BuildValue("O&",
    445                          CmpObj_New, _rv);
    446     return _res;
    447 }
    448 
    449 static PyObject *CmpObj_GetComponentPublicIndString(ComponentObject *_self, PyObject *_args)
    450 {
    451     PyObject *_res = NULL;
    452     OSErr _err;
    453     Str255 theString;
    454     short strListID;
    455     short index;
    456 #ifndef GetComponentPublicIndString
    457     PyMac_PRECHECK(GetComponentPublicIndString);
    458 #endif
    459     if (!PyArg_ParseTuple(_args, "O&hh",
    460                           PyMac_GetStr255, theString,
    461                           &strListID,
    462                           &index))
    463         return NULL;
    464     _err = GetComponentPublicIndString(_self->ob_itself,
    465                                        theString,
    466                                        strListID,
    467                                        index);
    468     if (_err != noErr) return PyMac_Error(_err);
    469     Py_INCREF(Py_None);
    470     _res = Py_None;
    471     return _res;
    472 }
    473 
    474 static PyObject *CmpObj_GetComponentRefcon(ComponentObject *_self, PyObject *_args)
    475 {
    476     PyObject *_res = NULL;
    477     long _rv;
    478 #ifndef GetComponentRefcon
    479     PyMac_PRECHECK(GetComponentRefcon);
    480 #endif
    481     if (!PyArg_ParseTuple(_args, ""))
    482         return NULL;
    483     _rv = GetComponentRefcon(_self->ob_itself);
    484     _res = Py_BuildValue("l",
    485                          _rv);
    486     return _res;
    487 }
    488 
    489 static PyObject *CmpObj_SetComponentRefcon(ComponentObject *_self, PyObject *_args)
    490 {
    491     PyObject *_res = NULL;
    492     long theRefcon;
    493 #ifndef SetComponentRefcon
    494     PyMac_PRECHECK(SetComponentRefcon);
    495 #endif
    496     if (!PyArg_ParseTuple(_args, "l",
    497                           &theRefcon))
    498         return NULL;
    499     SetComponentRefcon(_self->ob_itself,
    500                        theRefcon);
    501     Py_INCREF(Py_None);
    502     _res = Py_None;
    503     return _res;
    504 }
    505 
    506 static PyObject *CmpObj_OpenComponentResFile(ComponentObject *_self, PyObject *_args)
    507 {
    508     PyObject *_res = NULL;
    509     short _rv;
    510 #ifndef OpenComponentResFile
    511     PyMac_PRECHECK(OpenComponentResFile);
    512 #endif
    513     if (!PyArg_ParseTuple(_args, ""))
    514         return NULL;
    515     _rv = OpenComponentResFile(_self->ob_itself);
    516     _res = Py_BuildValue("h",
    517                          _rv);
    518     return _res;
    519 }
    520 
    521 static PyObject *CmpObj_GetComponentResource(ComponentObject *_self, PyObject *_args)
    522 {
    523     PyObject *_res = NULL;
    524     OSErr _err;
    525     OSType resType;
    526     short resID;
    527     Handle theResource;
    528 #ifndef GetComponentResource
    529     PyMac_PRECHECK(GetComponentResource);
    530 #endif
    531     if (!PyArg_ParseTuple(_args, "O&h",
    532                           PyMac_GetOSType, &resType,
    533                           &resID))
    534         return NULL;
    535     _err = GetComponentResource(_self->ob_itself,
    536                                 resType,
    537                                 resID,
    538                                 &theResource);
    539     if (_err != noErr) return PyMac_Error(_err);
    540     _res = Py_BuildValue("O&",
    541                          ResObj_New, theResource);
    542     return _res;
    543 }
    544 
    545 static PyObject *CmpObj_GetComponentIndString(ComponentObject *_self, PyObject *_args)
    546 {
    547     PyObject *_res = NULL;
    548     OSErr _err;
    549     Str255 theString;
    550     short strListID;
    551     short index;
    552 #ifndef GetComponentIndString
    553     PyMac_PRECHECK(GetComponentIndString);
    554 #endif
    555     if (!PyArg_ParseTuple(_args, "O&hh",
    556                           PyMac_GetStr255, theString,
    557                           &strListID,
    558                           &index))
    559         return NULL;
    560     _err = GetComponentIndString(_self->ob_itself,
    561                                  theString,
    562                                  strListID,
    563                                  index);
    564     if (_err != noErr) return PyMac_Error(_err);
    565     Py_INCREF(Py_None);
    566     _res = Py_None;
    567     return _res;
    568 }
    569 
    570 static PyObject *CmpObj_CountComponentInstances(ComponentObject *_self, PyObject *_args)
    571 {
    572     PyObject *_res = NULL;
    573     long _rv;
    574 #ifndef CountComponentInstances
    575     PyMac_PRECHECK(CountComponentInstances);
    576 #endif
    577     if (!PyArg_ParseTuple(_args, ""))
    578         return NULL;
    579     _rv = CountComponentInstances(_self->ob_itself);
    580     _res = Py_BuildValue("l",
    581                          _rv);
    582     return _res;
    583 }
    584 
    585 static PyObject *CmpObj_SetDefaultComponent(ComponentObject *_self, PyObject *_args)
    586 {
    587     PyObject *_res = NULL;
    588     OSErr _err;
    589     short flags;
    590 #ifndef SetDefaultComponent
    591     PyMac_PRECHECK(SetDefaultComponent);
    592 #endif
    593     if (!PyArg_ParseTuple(_args, "h",
    594                           &flags))
    595         return NULL;
    596     _err = SetDefaultComponent(_self->ob_itself,
    597                                flags);
    598     if (_err != noErr) return PyMac_Error(_err);
    599     Py_INCREF(Py_None);
    600     _res = Py_None;
    601     return _res;
    602 }
    603 
    604 static PyObject *CmpObj_CaptureComponent(ComponentObject *_self, PyObject *_args)
    605 {
    606     PyObject *_res = NULL;
    607     Component _rv;
    608     Component capturingComponent;
    609 #ifndef CaptureComponent
    610     PyMac_PRECHECK(CaptureComponent);
    611 #endif
    612     if (!PyArg_ParseTuple(_args, "O&",
    613                           CmpObj_Convert, &capturingComponent))
    614         return NULL;
    615     _rv = CaptureComponent(_self->ob_itself,
    616                            capturingComponent);
    617     _res = Py_BuildValue("O&",
    618                          CmpObj_New, _rv);
    619     return _res;
    620 }
    621 
    622 static PyObject *CmpObj_UncaptureComponent(ComponentObject *_self, PyObject *_args)
    623 {
    624     PyObject *_res = NULL;
    625     OSErr _err;
    626 #ifndef UncaptureComponent
    627     PyMac_PRECHECK(UncaptureComponent);
    628 #endif
    629     if (!PyArg_ParseTuple(_args, ""))
    630         return NULL;
    631     _err = UncaptureComponent(_self->ob_itself);
    632     if (_err != noErr) return PyMac_Error(_err);
    633     Py_INCREF(Py_None);
    634     _res = Py_None;
    635     return _res;
    636 }
    637 
    638 #ifndef __LP64__
    639 static PyObject *CmpObj_GetComponentIconSuite(ComponentObject *_self, PyObject *_args)
    640 {
    641     PyObject *_res = NULL;
    642     OSErr _err;
    643     Handle iconSuite;
    644 #ifndef GetComponentIconSuite
    645     PyMac_PRECHECK(GetComponentIconSuite);
    646 #endif
    647     if (!PyArg_ParseTuple(_args, ""))
    648         return NULL;
    649     _err = GetComponentIconSuite(_self->ob_itself,
    650                                  &iconSuite);
    651     if (_err != noErr) return PyMac_Error(_err);
    652     _res = Py_BuildValue("O&",
    653                          ResObj_New, iconSuite);
    654     return _res;
    655 }
    656 #endif /* !__LP64__ */
    657 
    658 static PyMethodDef CmpObj_methods[] = {
    659     {"UnregisterComponent", (PyCFunction)CmpObj_UnregisterComponent, 1,
    660      PyDoc_STR("() -> None")},
    661     {"GetComponentInfo", (PyCFunction)CmpObj_GetComponentInfo, 1,
    662      PyDoc_STR("(Handle componentName, Handle componentInfo, Handle componentIcon) -> (ComponentDescription cd)")},
    663     {"OpenComponent", (PyCFunction)CmpObj_OpenComponent, 1,
    664      PyDoc_STR("() -> (ComponentInstance _rv)")},
    665     {"ResolveComponentAlias", (PyCFunction)CmpObj_ResolveComponentAlias, 1,
    666      PyDoc_STR("() -> (Component _rv)")},
    667     {"GetComponentPublicIndString", (PyCFunction)CmpObj_GetComponentPublicIndString, 1,
    668      PyDoc_STR("(Str255 theString, short strListID, short index) -> None")},
    669     {"GetComponentRefcon", (PyCFunction)CmpObj_GetComponentRefcon, 1,
    670      PyDoc_STR("() -> (long _rv)")},
    671     {"SetComponentRefcon", (PyCFunction)CmpObj_SetComponentRefcon, 1,
    672      PyDoc_STR("(long theRefcon) -> None")},
    673     {"OpenComponentResFile", (PyCFunction)CmpObj_OpenComponentResFile, 1,
    674      PyDoc_STR("() -> (short _rv)")},
    675     {"GetComponentResource", (PyCFunction)CmpObj_GetComponentResource, 1,
    676      PyDoc_STR("(OSType resType, short resID) -> (Handle theResource)")},
    677     {"GetComponentIndString", (PyCFunction)CmpObj_GetComponentIndString, 1,
    678      PyDoc_STR("(Str255 theString, short strListID, short index) -> None")},
    679     {"CountComponentInstances", (PyCFunction)CmpObj_CountComponentInstances, 1,
    680      PyDoc_STR("() -> (long _rv)")},
    681     {"SetDefaultComponent", (PyCFunction)CmpObj_SetDefaultComponent, 1,
    682      PyDoc_STR("(short flags) -> None")},
    683     {"CaptureComponent", (PyCFunction)CmpObj_CaptureComponent, 1,
    684      PyDoc_STR("(Component capturingComponent) -> (Component _rv)")},
    685     {"UncaptureComponent", (PyCFunction)CmpObj_UncaptureComponent, 1,
    686      PyDoc_STR("() -> None")},
    687 #ifndef __LP64__
    688     {"GetComponentIconSuite", (PyCFunction)CmpObj_GetComponentIconSuite, 1,
    689      PyDoc_STR("() -> (Handle iconSuite)")},
    690 #endif /* !__LP64__ */
    691     {NULL, NULL, 0}
    692 };
    693 
    694 #define CmpObj_getsetlist NULL
    695 
    696 
    697 #define CmpObj_compare NULL
    698 
    699 #define CmpObj_repr NULL
    700 
    701 #define CmpObj_hash NULL
    702 #define CmpObj_tp_init 0
    703 
    704 #define CmpObj_tp_alloc PyType_GenericAlloc
    705 
    706 static PyObject *CmpObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
    707 {
    708     PyObject *_self;
    709     Component itself;
    710     char *kw[] = {"itself", 0};
    711 
    712     if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CmpObj_Convert, &itself)) return NULL;
    713     if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL;
    714     ((ComponentObject *)_self)->ob_itself = itself;
    715     return _self;
    716 }
    717 
    718 #define CmpObj_tp_free PyObject_Del
    719 
    720 
    721 PyTypeObject Component_Type = {
    722     PyObject_HEAD_INIT(NULL)
    723     0, /*ob_size*/
    724     "_Cm.Component", /*tp_name*/
    725     sizeof(ComponentObject), /*tp_basicsize*/
    726     0, /*tp_itemsize*/
    727     /* methods */
    728     (destructor) CmpObj_dealloc, /*tp_dealloc*/
    729     0, /*tp_print*/
    730     (getattrfunc)0, /*tp_getattr*/
    731     (setattrfunc)0, /*tp_setattr*/
    732     (cmpfunc) CmpObj_compare, /*tp_compare*/
    733     (reprfunc) CmpObj_repr, /*tp_repr*/
    734     (PyNumberMethods *)0, /* tp_as_number */
    735     (PySequenceMethods *)0, /* tp_as_sequence */
    736     (PyMappingMethods *)0, /* tp_as_mapping */
    737     (hashfunc) CmpObj_hash, /*tp_hash*/
    738     0, /*tp_call*/
    739     0, /*tp_str*/
    740     PyObject_GenericGetAttr, /*tp_getattro*/
    741     PyObject_GenericSetAttr, /*tp_setattro */
    742     0, /*tp_as_buffer*/
    743     Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
    744     0, /*tp_doc*/
    745     0, /*tp_traverse*/
    746     0, /*tp_clear*/
    747     0, /*tp_richcompare*/
    748     0, /*tp_weaklistoffset*/
    749     0, /*tp_iter*/
    750     0, /*tp_iternext*/
    751     CmpObj_methods, /* tp_methods */
    752     0, /*tp_members*/
    753     CmpObj_getsetlist, /*tp_getset*/
    754     0, /*tp_base*/
    755     0, /*tp_dict*/
    756     0, /*tp_descr_get*/
    757     0, /*tp_descr_set*/
    758     0, /*tp_dictoffset*/
    759     CmpObj_tp_init, /* tp_init */
    760     CmpObj_tp_alloc, /* tp_alloc */
    761     CmpObj_tp_new, /* tp_new */
    762     CmpObj_tp_free, /* tp_free */
    763 };
    764 
    765 /* ------------------- End object type Component -------------------- */
    766 
    767 
    768 static PyObject *Cm_RegisterComponentResource(PyObject *_self, PyObject *_args)
    769 {
    770     PyObject *_res = NULL;
    771     Component _rv;
    772     ComponentResourceHandle cr;
    773     short global;
    774 #ifndef RegisterComponentResource
    775     PyMac_PRECHECK(RegisterComponentResource);
    776 #endif
    777     if (!PyArg_ParseTuple(_args, "O&h",
    778                           ResObj_Convert, &cr,
    779                           &global))
    780         return NULL;
    781     _rv = RegisterComponentResource(cr,
    782                                     global);
    783     _res = Py_BuildValue("O&",
    784                          CmpObj_New, _rv);
    785     return _res;
    786 }
    787 
    788 static PyObject *Cm_FindNextComponent(PyObject *_self, PyObject *_args)
    789 {
    790     PyObject *_res = NULL;
    791     Component _rv;
    792     Component aComponent;
    793     ComponentDescription looking;
    794 #ifndef FindNextComponent
    795     PyMac_PRECHECK(FindNextComponent);
    796 #endif
    797     if (!PyArg_ParseTuple(_args, "O&O&",
    798                           CmpObj_Convert, &aComponent,
    799                           CmpDesc_Convert, &looking))
    800         return NULL;
    801     _rv = FindNextComponent(aComponent,
    802                             &looking);
    803     _res = Py_BuildValue("O&",
    804                          CmpObj_New, _rv);
    805     return _res;
    806 }
    807 
    808 static PyObject *Cm_CountComponents(PyObject *_self, PyObject *_args)
    809 {
    810     PyObject *_res = NULL;
    811     long _rv;
    812     ComponentDescription looking;
    813 #ifndef CountComponents
    814     PyMac_PRECHECK(CountComponents);
    815 #endif
    816     if (!PyArg_ParseTuple(_args, "O&",
    817                           CmpDesc_Convert, &looking))
    818         return NULL;
    819     _rv = CountComponents(&looking);
    820     _res = Py_BuildValue("l",
    821                          _rv);
    822     return _res;
    823 }
    824 
    825 static PyObject *Cm_GetComponentListModSeed(PyObject *_self, PyObject *_args)
    826 {
    827     PyObject *_res = NULL;
    828     long _rv;
    829 #ifndef GetComponentListModSeed
    830     PyMac_PRECHECK(GetComponentListModSeed);
    831 #endif
    832     if (!PyArg_ParseTuple(_args, ""))
    833         return NULL;
    834     _rv = GetComponentListModSeed();
    835     _res = Py_BuildValue("l",
    836                          _rv);
    837     return _res;
    838 }
    839 
    840 static PyObject *Cm_CloseComponentResFile(PyObject *_self, PyObject *_args)
    841 {
    842     PyObject *_res = NULL;
    843     OSErr _err;
    844     short refnum;
    845 #ifndef CloseComponentResFile
    846     PyMac_PRECHECK(CloseComponentResFile);
    847 #endif
    848     if (!PyArg_ParseTuple(_args, "h",
    849                           &refnum))
    850         return NULL;
    851     _err = CloseComponentResFile(refnum);
    852     if (_err != noErr) return PyMac_Error(_err);
    853     Py_INCREF(Py_None);
    854     _res = Py_None;
    855     return _res;
    856 }
    857 
    858 static PyObject *Cm_OpenDefaultComponent(PyObject *_self, PyObject *_args)
    859 {
    860     PyObject *_res = NULL;
    861     ComponentInstance _rv;
    862     OSType componentType;
    863     OSType componentSubType;
    864 #ifndef OpenDefaultComponent
    865     PyMac_PRECHECK(OpenDefaultComponent);
    866 #endif
    867     if (!PyArg_ParseTuple(_args, "O&O&",
    868                           PyMac_GetOSType, &componentType,
    869                           PyMac_GetOSType, &componentSubType))
    870         return NULL;
    871     _rv = OpenDefaultComponent(componentType,
    872                                componentSubType);
    873     _res = Py_BuildValue("O&",
    874                          CmpInstObj_New, _rv);
    875     return _res;
    876 }
    877 
    878 static PyObject *Cm_RegisterComponentResourceFile(PyObject *_self, PyObject *_args)
    879 {
    880     PyObject *_res = NULL;
    881     long _rv;
    882     short resRefNum;
    883     short global;
    884 #ifndef RegisterComponentResourceFile
    885     PyMac_PRECHECK(RegisterComponentResourceFile);
    886 #endif
    887     if (!PyArg_ParseTuple(_args, "hh",
    888                           &resRefNum,
    889                           &global))
    890         return NULL;
    891     _rv = RegisterComponentResourceFile(resRefNum,
    892                                         global);
    893     _res = Py_BuildValue("l",
    894                          _rv);
    895     return _res;
    896 }
    897 
    898 static PyMethodDef Cm_methods[] = {
    899     {"RegisterComponentResource", (PyCFunction)Cm_RegisterComponentResource, 1,
    900      PyDoc_STR("(ComponentResourceHandle cr, short global) -> (Component _rv)")},
    901     {"FindNextComponent", (PyCFunction)Cm_FindNextComponent, 1,
    902      PyDoc_STR("(Component aComponent, ComponentDescription looking) -> (Component _rv)")},
    903     {"CountComponents", (PyCFunction)Cm_CountComponents, 1,
    904      PyDoc_STR("(ComponentDescription looking) -> (long _rv)")},
    905     {"GetComponentListModSeed", (PyCFunction)Cm_GetComponentListModSeed, 1,
    906      PyDoc_STR("() -> (long _rv)")},
    907     {"CloseComponentResFile", (PyCFunction)Cm_CloseComponentResFile, 1,
    908      PyDoc_STR("(short refnum) -> None")},
    909     {"OpenDefaultComponent", (PyCFunction)Cm_OpenDefaultComponent, 1,
    910      PyDoc_STR("(OSType componentType, OSType componentSubType) -> (ComponentInstance _rv)")},
    911     {"RegisterComponentResourceFile", (PyCFunction)Cm_RegisterComponentResourceFile, 1,
    912      PyDoc_STR("(short resRefNum, short global) -> (long _rv)")},
    913     {NULL, NULL, 0}
    914 };
    915 
    916 
    917 
    918 
    919 void init_Cm(void)
    920 {
    921     PyObject *m;
    922     PyObject *d;
    923 
    924 
    925 
    926         PyMac_INIT_TOOLBOX_OBJECT_NEW(Component, CmpObj_New);
    927         PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Component, CmpObj_Convert);
    928         PyMac_INIT_TOOLBOX_OBJECT_NEW(ComponentInstance, CmpInstObj_New);
    929         PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ComponentInstance, CmpInstObj_Convert);
    930 
    931 
    932     m = Py_InitModule("_Cm", Cm_methods);
    933     d = PyModule_GetDict(m);
    934     Cm_Error = PyMac_GetOSErrException();
    935     if (Cm_Error == NULL ||
    936         PyDict_SetItemString(d, "Error", Cm_Error) != 0)
    937         return;
    938     ComponentInstance_Type.ob_type = &PyType_Type;
    939     if (PyType_Ready(&ComponentInstance_Type) < 0) return;
    940     Py_INCREF(&ComponentInstance_Type);
    941     PyModule_AddObject(m, "ComponentInstance", (PyObject *)&ComponentInstance_Type);
    942     /* Backward-compatible name */
    943     Py_INCREF(&ComponentInstance_Type);
    944     PyModule_AddObject(m, "ComponentInstanceType", (PyObject *)&ComponentInstance_Type);
    945     Component_Type.ob_type = &PyType_Type;
    946     if (PyType_Ready(&Component_Type) < 0) return;
    947     Py_INCREF(&Component_Type);
    948     PyModule_AddObject(m, "Component", (PyObject *)&Component_Type);
    949     /* Backward-compatible name */
    950     Py_INCREF(&Component_Type);
    951     PyModule_AddObject(m, "ComponentType", (PyObject *)&Component_Type);
    952 }
    953 
    954 /* ========================= End module _Cm ========================= */
    955 
    956