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