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