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