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