blob: 1738f3e3445f82ba479f01069d06ad0c4097d6aa [file] [log] [blame]
Jack Jansenb9968561995-11-30 15:03:09 +00001
2/* =========================== Module Cm ============================ */
3
4#include "Python.h"
5
6
7
Jack Jansenb9968561995-11-30 15:03:09 +00008#include "macglue.h"
Jack Jansen9d8b96c2000-07-14 22:16:45 +00009#include "pymactoolbox.h"
Jack Jansenb9968561995-11-30 15:03:09 +000010
Jack Jansenfa77e1a2001-05-22 21:56:42 +000011#ifdef WITHOUT_FRAMEWORKS
Jack Jansenb9968561995-11-30 15:03:09 +000012#include <Components.h>
Jack Jansenfa77e1a2001-05-22 21:56:42 +000013#else
14#include <Carbon/Carbon.h>
15#endif
16
Jack Jansen0e04eec2001-05-17 21:58:34 +000017#ifdef USE_TOOLBOX_OBJECT_GLUE
18extern PyObject *_CmpObj_New(Component);
19extern int _CmpObj_Convert(PyObject *, Component *);
20extern PyObject *_CmpInstObj_New(ComponentInstance);
21extern int _CmpInstObj_Convert(PyObject *, ComponentInstance *);
22
23#define CmpObj_New _CmpObj_New
24#define CmpObj_Convert _CmpObj_Convert
25#define CmpInstObj_New _CmpInstObj_New
26#define CmpInstObj_Convert _CmpInstObj_Convert
27#endif
Jack Jansenb9968561995-11-30 15:03:09 +000028
29/*
30** Parse/generate ComponentDescriptor records
31*/
Jack Jansen9d8b96c2000-07-14 22:16:45 +000032static PyObject *
Jack Jansenfa77e1a2001-05-22 21:56:42 +000033CmpDesc_New(ComponentDescription *itself)
Jack Jansenb9968561995-11-30 15:03:09 +000034{
35
36 return Py_BuildValue("O&O&O&ll",
37 PyMac_BuildOSType, itself->componentType,
38 PyMac_BuildOSType, itself->componentSubType,
39 PyMac_BuildOSType, itself->componentManufacturer,
40 itself->componentFlags, itself->componentFlagsMask);
41}
42
Jack Jansen9d8b96c2000-07-14 22:16:45 +000043static int
Jack Jansenfa77e1a2001-05-22 21:56:42 +000044CmpDesc_Convert(PyObject *v, ComponentDescription *p_itself)
Jack Jansenb9968561995-11-30 15:03:09 +000045{
46 return PyArg_ParseTuple(v, "O&O&O&ll",
47 PyMac_GetOSType, &p_itself->componentType,
48 PyMac_GetOSType, &p_itself->componentSubType,
49 PyMac_GetOSType, &p_itself->componentManufacturer,
50 &p_itself->componentFlags, &p_itself->componentFlagsMask);
51}
52
53
54static PyObject *Cm_Error;
55
56/* ----------------- Object type ComponentInstance ------------------ */
57
58PyTypeObject ComponentInstance_Type;
59
60#define CmpInstObj_Check(x) ((x)->ob_type == &ComponentInstance_Type)
61
62typedef struct ComponentInstanceObject {
63 PyObject_HEAD
64 ComponentInstance ob_itself;
65} ComponentInstanceObject;
66
Jack Jansenfa77e1a2001-05-22 21:56:42 +000067PyObject *CmpInstObj_New(ComponentInstance itself)
Jack Jansenb9968561995-11-30 15:03:09 +000068{
69 ComponentInstanceObject *it;
70 if (itself == NULL) {
71 PyErr_SetString(Cm_Error,"NULL ComponentInstance");
72 return NULL;
73 }
74 it = PyObject_NEW(ComponentInstanceObject, &ComponentInstance_Type);
75 if (it == NULL) return NULL;
76 it->ob_itself = itself;
77 return (PyObject *)it;
78}
Jack Jansenfa77e1a2001-05-22 21:56:42 +000079CmpInstObj_Convert(PyObject *v, ComponentInstance *p_itself)
Jack Jansenb9968561995-11-30 15:03:09 +000080{
81 if (!CmpInstObj_Check(v))
82 {
83 PyErr_SetString(PyExc_TypeError, "ComponentInstance required");
84 return 0;
85 }
86 *p_itself = ((ComponentInstanceObject *)v)->ob_itself;
87 return 1;
88}
89
Jack Jansenfa77e1a2001-05-22 21:56:42 +000090static void CmpInstObj_dealloc(ComponentInstanceObject *self)
Jack Jansenb9968561995-11-30 15:03:09 +000091{
92 /* Cleanup of self->ob_itself goes here */
93 PyMem_DEL(self);
94}
95
Jack Jansenfa77e1a2001-05-22 21:56:42 +000096static PyObject *CmpInstObj_CloseComponent(ComponentInstanceObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +000097{
98 PyObject *_res = NULL;
99 OSErr _err;
100 if (!PyArg_ParseTuple(_args, ""))
101 return NULL;
102 _err = CloseComponent(_self->ob_itself);
103 if (_err != noErr) return PyMac_Error(_err);
104 Py_INCREF(Py_None);
105 _res = Py_None;
106 return _res;
107}
108
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000109static PyObject *CmpInstObj_GetComponentInstanceError(ComponentInstanceObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000110{
111 PyObject *_res = NULL;
112 OSErr _err;
113 if (!PyArg_ParseTuple(_args, ""))
114 return NULL;
115 _err = GetComponentInstanceError(_self->ob_itself);
116 if (_err != noErr) return PyMac_Error(_err);
117 Py_INCREF(Py_None);
118 _res = Py_None;
119 return _res;
120}
121
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000122static PyObject *CmpInstObj_SetComponentInstanceError(ComponentInstanceObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000123{
124 PyObject *_res = NULL;
125 OSErr theError;
126 if (!PyArg_ParseTuple(_args, "h",
127 &theError))
128 return NULL;
129 SetComponentInstanceError(_self->ob_itself,
130 theError);
131 Py_INCREF(Py_None);
132 _res = Py_None;
133 return _res;
134}
135
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000136static PyObject *CmpInstObj_GetComponentInstanceStorage(ComponentInstanceObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000137{
138 PyObject *_res = NULL;
139 Handle _rv;
140 if (!PyArg_ParseTuple(_args, ""))
141 return NULL;
142 _rv = GetComponentInstanceStorage(_self->ob_itself);
143 _res = Py_BuildValue("O&",
144 ResObj_New, _rv);
145 return _res;
146}
147
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000148static PyObject *CmpInstObj_SetComponentInstanceStorage(ComponentInstanceObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000149{
150 PyObject *_res = NULL;
151 Handle theStorage;
152 if (!PyArg_ParseTuple(_args, "O&",
153 ResObj_Convert, &theStorage))
154 return NULL;
155 SetComponentInstanceStorage(_self->ob_itself,
156 theStorage);
157 Py_INCREF(Py_None);
158 _res = Py_None;
159 return _res;
160}
161
Jack Jansen74a1e632000-07-14 22:37:27 +0000162#if !TARGET_API_MAC_CARBON
Jack Jansen8d929ae2000-06-21 22:07:06 +0000163
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000164static PyObject *CmpInstObj_GetComponentInstanceA5(ComponentInstanceObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000165{
166 PyObject *_res = NULL;
167 long _rv;
168 if (!PyArg_ParseTuple(_args, ""))
169 return NULL;
170 _rv = GetComponentInstanceA5(_self->ob_itself);
171 _res = Py_BuildValue("l",
172 _rv);
173 return _res;
174}
Jack Jansen8d929ae2000-06-21 22:07:06 +0000175#endif
176
Jack Jansen74a1e632000-07-14 22:37:27 +0000177#if !TARGET_API_MAC_CARBON
Jack Jansenb9968561995-11-30 15:03:09 +0000178
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000179static PyObject *CmpInstObj_SetComponentInstanceA5(ComponentInstanceObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000180{
181 PyObject *_res = NULL;
182 long theA5;
183 if (!PyArg_ParseTuple(_args, "l",
184 &theA5))
185 return NULL;
186 SetComponentInstanceA5(_self->ob_itself,
187 theA5);
188 Py_INCREF(Py_None);
189 _res = Py_None;
190 return _res;
191}
Jack Jansen8d929ae2000-06-21 22:07:06 +0000192#endif
Jack Jansenb9968561995-11-30 15:03:09 +0000193
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000194static PyObject *CmpInstObj_ComponentFunctionImplemented(ComponentInstanceObject *_self, PyObject *_args)
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000195{
196 PyObject *_res = NULL;
197 long _rv;
198 short ftnNumber;
199 if (!PyArg_ParseTuple(_args, "h",
200 &ftnNumber))
201 return NULL;
202 _rv = ComponentFunctionImplemented(_self->ob_itself,
203 ftnNumber);
204 _res = Py_BuildValue("l",
205 _rv);
206 return _res;
207}
208
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000209static PyObject *CmpInstObj_GetComponentVersion(ComponentInstanceObject *_self, PyObject *_args)
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000210{
211 PyObject *_res = NULL;
212 long _rv;
213 if (!PyArg_ParseTuple(_args, ""))
214 return NULL;
215 _rv = GetComponentVersion(_self->ob_itself);
216 _res = Py_BuildValue("l",
217 _rv);
218 return _res;
219}
220
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000221static PyObject *CmpInstObj_ComponentSetTarget(ComponentInstanceObject *_self, PyObject *_args)
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000222{
223 PyObject *_res = NULL;
224 long _rv;
225 ComponentInstance target;
226 if (!PyArg_ParseTuple(_args, "O&",
227 CmpInstObj_Convert, &target))
228 return NULL;
229 _rv = ComponentSetTarget(_self->ob_itself,
230 target);
231 _res = Py_BuildValue("l",
232 _rv);
233 return _res;
234}
235
Jack Jansenb9968561995-11-30 15:03:09 +0000236static PyMethodDef CmpInstObj_methods[] = {
237 {"CloseComponent", (PyCFunction)CmpInstObj_CloseComponent, 1,
238 "() -> None"},
239 {"GetComponentInstanceError", (PyCFunction)CmpInstObj_GetComponentInstanceError, 1,
240 "() -> None"},
Jack Jansenb9968561995-11-30 15:03:09 +0000241 {"SetComponentInstanceError", (PyCFunction)CmpInstObj_SetComponentInstanceError, 1,
242 "(OSErr theError) -> None"},
243 {"GetComponentInstanceStorage", (PyCFunction)CmpInstObj_GetComponentInstanceStorage, 1,
244 "() -> (Handle _rv)"},
245 {"SetComponentInstanceStorage", (PyCFunction)CmpInstObj_SetComponentInstanceStorage, 1,
246 "(Handle theStorage) -> None"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000247
Jack Jansen74a1e632000-07-14 22:37:27 +0000248#if !TARGET_API_MAC_CARBON
Jack Jansenb9968561995-11-30 15:03:09 +0000249 {"GetComponentInstanceA5", (PyCFunction)CmpInstObj_GetComponentInstanceA5, 1,
250 "() -> (long _rv)"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000251#endif
252
Jack Jansen74a1e632000-07-14 22:37:27 +0000253#if !TARGET_API_MAC_CARBON
Jack Jansenb9968561995-11-30 15:03:09 +0000254 {"SetComponentInstanceA5", (PyCFunction)CmpInstObj_SetComponentInstanceA5, 1,
255 "(long theA5) -> None"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000256#endif
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000257 {"ComponentFunctionImplemented", (PyCFunction)CmpInstObj_ComponentFunctionImplemented, 1,
258 "(short ftnNumber) -> (long _rv)"},
259 {"GetComponentVersion", (PyCFunction)CmpInstObj_GetComponentVersion, 1,
260 "() -> (long _rv)"},
261 {"ComponentSetTarget", (PyCFunction)CmpInstObj_ComponentSetTarget, 1,
262 "(ComponentInstance target) -> (long _rv)"},
Jack Jansenb9968561995-11-30 15:03:09 +0000263 {NULL, NULL, 0}
264};
265
266PyMethodChain CmpInstObj_chain = { CmpInstObj_methods, NULL };
267
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000268static PyObject *CmpInstObj_getattr(ComponentInstanceObject *self, char *name)
Jack Jansenb9968561995-11-30 15:03:09 +0000269{
270 return Py_FindMethodInChain(&CmpInstObj_chain, (PyObject *)self, name);
271}
272
273#define CmpInstObj_setattr NULL
274
Jack Jansena05ac601999-12-12 21:41:51 +0000275#define CmpInstObj_compare NULL
276
277#define CmpInstObj_repr NULL
278
279#define CmpInstObj_hash NULL
280
Jack Jansenb9968561995-11-30 15:03:09 +0000281PyTypeObject ComponentInstance_Type = {
282 PyObject_HEAD_INIT(&PyType_Type)
283 0, /*ob_size*/
284 "ComponentInstance", /*tp_name*/
285 sizeof(ComponentInstanceObject), /*tp_basicsize*/
286 0, /*tp_itemsize*/
287 /* methods */
288 (destructor) CmpInstObj_dealloc, /*tp_dealloc*/
289 0, /*tp_print*/
290 (getattrfunc) CmpInstObj_getattr, /*tp_getattr*/
291 (setattrfunc) CmpInstObj_setattr, /*tp_setattr*/
Jack Jansena05ac601999-12-12 21:41:51 +0000292 (cmpfunc) CmpInstObj_compare, /*tp_compare*/
293 (reprfunc) CmpInstObj_repr, /*tp_repr*/
294 (PyNumberMethods *)0, /* tp_as_number */
295 (PySequenceMethods *)0, /* tp_as_sequence */
296 (PyMappingMethods *)0, /* tp_as_mapping */
297 (hashfunc) CmpInstObj_hash, /*tp_hash*/
Jack Jansenb9968561995-11-30 15:03:09 +0000298};
299
300/* --------------- End object type ComponentInstance ---------------- */
301
302
303/* --------------------- Object type Component ---------------------- */
304
305PyTypeObject Component_Type;
306
307#define CmpObj_Check(x) ((x)->ob_type == &Component_Type)
308
309typedef struct ComponentObject {
310 PyObject_HEAD
311 Component ob_itself;
312} ComponentObject;
313
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000314PyObject *CmpObj_New(Component itself)
Jack Jansenb9968561995-11-30 15:03:09 +0000315{
316 ComponentObject *it;
317 if (itself == NULL) {
318 /* XXXX Or should we return None? */
319 PyErr_SetString(Cm_Error,"No such component");
320 return NULL;
321 }
322 it = PyObject_NEW(ComponentObject, &Component_Type);
323 if (it == NULL) return NULL;
324 it->ob_itself = itself;
325 return (PyObject *)it;
326}
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000327CmpObj_Convert(PyObject *v, Component *p_itself)
Jack Jansenb9968561995-11-30 15:03:09 +0000328{
329 if ( v == Py_None ) {
330 *p_itself = 0;
331 return 1;
332 }
333 if (!CmpObj_Check(v))
334 {
335 PyErr_SetString(PyExc_TypeError, "Component required");
336 return 0;
337 }
338 *p_itself = ((ComponentObject *)v)->ob_itself;
339 return 1;
340}
341
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000342static void CmpObj_dealloc(ComponentObject *self)
Jack Jansenb9968561995-11-30 15:03:09 +0000343{
344 /* Cleanup of self->ob_itself goes here */
345 PyMem_DEL(self);
346}
347
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000348static PyObject *CmpObj_UnregisterComponent(ComponentObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000349{
350 PyObject *_res = NULL;
351 OSErr _err;
352 if (!PyArg_ParseTuple(_args, ""))
353 return NULL;
354 _err = UnregisterComponent(_self->ob_itself);
355 if (_err != noErr) return PyMac_Error(_err);
356 Py_INCREF(Py_None);
357 _res = Py_None;
358 return _res;
359}
360
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000361static PyObject *CmpObj_GetComponentInfo(ComponentObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000362{
363 PyObject *_res = NULL;
364 OSErr _err;
365 ComponentDescription cd;
366 Handle componentName;
367 Handle componentInfo;
368 Handle componentIcon;
369 if (!PyArg_ParseTuple(_args, "O&O&O&",
370 ResObj_Convert, &componentName,
371 ResObj_Convert, &componentInfo,
372 ResObj_Convert, &componentIcon))
373 return NULL;
374 _err = GetComponentInfo(_self->ob_itself,
375 &cd,
376 componentName,
377 componentInfo,
378 componentIcon);
379 if (_err != noErr) return PyMac_Error(_err);
380 _res = Py_BuildValue("O&",
381 CmpDesc_New, &cd);
382 return _res;
383}
384
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000385static PyObject *CmpObj_OpenComponent(ComponentObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000386{
387 PyObject *_res = NULL;
388 ComponentInstance _rv;
389 if (!PyArg_ParseTuple(_args, ""))
390 return NULL;
391 _rv = OpenComponent(_self->ob_itself);
392 _res = Py_BuildValue("O&",
393 CmpInstObj_New, _rv);
394 return _res;
395}
396
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000397static PyObject *CmpObj_GetComponentRefcon(ComponentObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000398{
399 PyObject *_res = NULL;
400 long _rv;
401 if (!PyArg_ParseTuple(_args, ""))
402 return NULL;
403 _rv = GetComponentRefcon(_self->ob_itself);
404 _res = Py_BuildValue("l",
405 _rv);
406 return _res;
407}
408
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000409static PyObject *CmpObj_SetComponentRefcon(ComponentObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000410{
411 PyObject *_res = NULL;
412 long theRefcon;
413 if (!PyArg_ParseTuple(_args, "l",
414 &theRefcon))
415 return NULL;
416 SetComponentRefcon(_self->ob_itself,
417 theRefcon);
418 Py_INCREF(Py_None);
419 _res = Py_None;
420 return _res;
421}
422
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000423static PyObject *CmpObj_OpenComponentResFile(ComponentObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000424{
425 PyObject *_res = NULL;
426 short _rv;
427 if (!PyArg_ParseTuple(_args, ""))
428 return NULL;
429 _rv = OpenComponentResFile(_self->ob_itself);
430 _res = Py_BuildValue("h",
431 _rv);
432 return _res;
433}
434
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000435static PyObject *CmpObj_GetComponentResource(ComponentObject *_self, PyObject *_args)
Jack Jansen1c4e6141998-04-21 15:23:55 +0000436{
437 PyObject *_res = NULL;
438 OSErr _err;
439 OSType resType;
440 short resID;
441 Handle theResource;
442 if (!PyArg_ParseTuple(_args, "O&h",
443 PyMac_GetOSType, &resType,
444 &resID))
445 return NULL;
446 _err = GetComponentResource(_self->ob_itself,
447 resType,
448 resID,
449 &theResource);
450 if (_err != noErr) return PyMac_Error(_err);
451 _res = Py_BuildValue("O&",
452 ResObj_New, theResource);
453 return _res;
454}
455
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000456static PyObject *CmpObj_GetComponentIndString(ComponentObject *_self, PyObject *_args)
Jack Jansen1c4e6141998-04-21 15:23:55 +0000457{
458 PyObject *_res = NULL;
459 OSErr _err;
460 Str255 theString;
461 short strListID;
462 short index;
463 if (!PyArg_ParseTuple(_args, "O&hh",
464 PyMac_GetStr255, theString,
465 &strListID,
466 &index))
467 return NULL;
468 _err = GetComponentIndString(_self->ob_itself,
469 theString,
470 strListID,
471 index);
472 if (_err != noErr) return PyMac_Error(_err);
473 Py_INCREF(Py_None);
474 _res = Py_None;
475 return _res;
476}
477
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000478static PyObject *CmpObj_ResolveComponentAlias(ComponentObject *_self, PyObject *_args)
Jack Jansen1c4e6141998-04-21 15:23:55 +0000479{
480 PyObject *_res = NULL;
481 Component _rv;
482 if (!PyArg_ParseTuple(_args, ""))
483 return NULL;
484 _rv = ResolveComponentAlias(_self->ob_itself);
485 _res = Py_BuildValue("O&",
486 CmpObj_New, _rv);
487 return _res;
488}
489
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000490static PyObject *CmpObj_CountComponentInstances(ComponentObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000491{
492 PyObject *_res = NULL;
493 long _rv;
494 if (!PyArg_ParseTuple(_args, ""))
495 return NULL;
496 _rv = CountComponentInstances(_self->ob_itself);
497 _res = Py_BuildValue("l",
498 _rv);
499 return _res;
500}
501
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000502static PyObject *CmpObj_SetDefaultComponent(ComponentObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000503{
504 PyObject *_res = NULL;
505 OSErr _err;
506 short flags;
507 if (!PyArg_ParseTuple(_args, "h",
508 &flags))
509 return NULL;
510 _err = SetDefaultComponent(_self->ob_itself,
511 flags);
512 if (_err != noErr) return PyMac_Error(_err);
513 Py_INCREF(Py_None);
514 _res = Py_None;
515 return _res;
516}
517
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000518static PyObject *CmpObj_CaptureComponent(ComponentObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000519{
520 PyObject *_res = NULL;
521 Component _rv;
522 Component capturingComponent;
523 if (!PyArg_ParseTuple(_args, "O&",
524 CmpObj_Convert, &capturingComponent))
525 return NULL;
526 _rv = CaptureComponent(_self->ob_itself,
527 capturingComponent);
528 _res = Py_BuildValue("O&",
529 CmpObj_New, _rv);
530 return _res;
531}
532
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000533static PyObject *CmpObj_UncaptureComponent(ComponentObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000534{
535 PyObject *_res = NULL;
536 OSErr _err;
537 if (!PyArg_ParseTuple(_args, ""))
538 return NULL;
539 _err = UncaptureComponent(_self->ob_itself);
540 if (_err != noErr) return PyMac_Error(_err);
541 Py_INCREF(Py_None);
542 _res = Py_None;
543 return _res;
544}
545
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000546static PyObject *CmpObj_GetComponentIconSuite(ComponentObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000547{
548 PyObject *_res = NULL;
549 OSErr _err;
550 Handle iconSuite;
551 if (!PyArg_ParseTuple(_args, ""))
552 return NULL;
553 _err = GetComponentIconSuite(_self->ob_itself,
554 &iconSuite);
555 if (_err != noErr) return PyMac_Error(_err);
556 _res = Py_BuildValue("O&",
557 ResObj_New, iconSuite);
558 return _res;
559}
560
561static PyMethodDef CmpObj_methods[] = {
562 {"UnregisterComponent", (PyCFunction)CmpObj_UnregisterComponent, 1,
563 "() -> None"},
564 {"GetComponentInfo", (PyCFunction)CmpObj_GetComponentInfo, 1,
565 "(Handle componentName, Handle componentInfo, Handle componentIcon) -> (ComponentDescription cd)"},
566 {"OpenComponent", (PyCFunction)CmpObj_OpenComponent, 1,
567 "() -> (ComponentInstance _rv)"},
568 {"GetComponentRefcon", (PyCFunction)CmpObj_GetComponentRefcon, 1,
569 "() -> (long _rv)"},
570 {"SetComponentRefcon", (PyCFunction)CmpObj_SetComponentRefcon, 1,
571 "(long theRefcon) -> None"},
572 {"OpenComponentResFile", (PyCFunction)CmpObj_OpenComponentResFile, 1,
573 "() -> (short _rv)"},
Jack Jansen1c4e6141998-04-21 15:23:55 +0000574 {"GetComponentResource", (PyCFunction)CmpObj_GetComponentResource, 1,
575 "(OSType resType, short resID) -> (Handle theResource)"},
576 {"GetComponentIndString", (PyCFunction)CmpObj_GetComponentIndString, 1,
577 "(Str255 theString, short strListID, short index) -> None"},
578 {"ResolveComponentAlias", (PyCFunction)CmpObj_ResolveComponentAlias, 1,
579 "() -> (Component _rv)"},
Jack Jansenb9968561995-11-30 15:03:09 +0000580 {"CountComponentInstances", (PyCFunction)CmpObj_CountComponentInstances, 1,
581 "() -> (long _rv)"},
582 {"SetDefaultComponent", (PyCFunction)CmpObj_SetDefaultComponent, 1,
583 "(short flags) -> None"},
584 {"CaptureComponent", (PyCFunction)CmpObj_CaptureComponent, 1,
585 "(Component capturingComponent) -> (Component _rv)"},
586 {"UncaptureComponent", (PyCFunction)CmpObj_UncaptureComponent, 1,
587 "() -> None"},
588 {"GetComponentIconSuite", (PyCFunction)CmpObj_GetComponentIconSuite, 1,
589 "() -> (Handle iconSuite)"},
590 {NULL, NULL, 0}
591};
592
593PyMethodChain CmpObj_chain = { CmpObj_methods, NULL };
594
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000595static PyObject *CmpObj_getattr(ComponentObject *self, char *name)
Jack Jansenb9968561995-11-30 15:03:09 +0000596{
597 return Py_FindMethodInChain(&CmpObj_chain, (PyObject *)self, name);
598}
599
600#define CmpObj_setattr NULL
601
Jack Jansena05ac601999-12-12 21:41:51 +0000602#define CmpObj_compare NULL
603
604#define CmpObj_repr NULL
605
606#define CmpObj_hash NULL
607
Jack Jansenb9968561995-11-30 15:03:09 +0000608PyTypeObject Component_Type = {
609 PyObject_HEAD_INIT(&PyType_Type)
610 0, /*ob_size*/
611 "Component", /*tp_name*/
612 sizeof(ComponentObject), /*tp_basicsize*/
613 0, /*tp_itemsize*/
614 /* methods */
615 (destructor) CmpObj_dealloc, /*tp_dealloc*/
616 0, /*tp_print*/
617 (getattrfunc) CmpObj_getattr, /*tp_getattr*/
618 (setattrfunc) CmpObj_setattr, /*tp_setattr*/
Jack Jansena05ac601999-12-12 21:41:51 +0000619 (cmpfunc) CmpObj_compare, /*tp_compare*/
620 (reprfunc) CmpObj_repr, /*tp_repr*/
621 (PyNumberMethods *)0, /* tp_as_number */
622 (PySequenceMethods *)0, /* tp_as_sequence */
623 (PyMappingMethods *)0, /* tp_as_mapping */
624 (hashfunc) CmpObj_hash, /*tp_hash*/
Jack Jansenb9968561995-11-30 15:03:09 +0000625};
626
627/* ------------------- End object type Component -------------------- */
628
629
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000630static PyObject *Cm_RegisterComponentResource(PyObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000631{
632 PyObject *_res = NULL;
633 Component _rv;
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000634 ComponentResourceHandle cr;
Jack Jansenb9968561995-11-30 15:03:09 +0000635 short global;
636 if (!PyArg_ParseTuple(_args, "O&h",
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000637 ResObj_Convert, &cr,
Jack Jansenb9968561995-11-30 15:03:09 +0000638 &global))
639 return NULL;
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000640 _rv = RegisterComponentResource(cr,
Jack Jansenb9968561995-11-30 15:03:09 +0000641 global);
642 _res = Py_BuildValue("O&",
643 CmpObj_New, _rv);
644 return _res;
645}
646
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000647static PyObject *Cm_FindNextComponent(PyObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000648{
649 PyObject *_res = NULL;
650 Component _rv;
651 Component aComponent;
652 ComponentDescription looking;
653 if (!PyArg_ParseTuple(_args, "O&O&",
654 CmpObj_Convert, &aComponent,
655 CmpDesc_Convert, &looking))
656 return NULL;
657 _rv = FindNextComponent(aComponent,
658 &looking);
659 _res = Py_BuildValue("O&",
660 CmpObj_New, _rv);
661 return _res;
662}
663
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000664static PyObject *Cm_CountComponents(PyObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000665{
666 PyObject *_res = NULL;
667 long _rv;
668 ComponentDescription looking;
669 if (!PyArg_ParseTuple(_args, "O&",
670 CmpDesc_Convert, &looking))
671 return NULL;
672 _rv = CountComponents(&looking);
673 _res = Py_BuildValue("l",
674 _rv);
675 return _res;
676}
677
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000678static PyObject *Cm_GetComponentListModSeed(PyObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000679{
680 PyObject *_res = NULL;
681 long _rv;
682 if (!PyArg_ParseTuple(_args, ""))
683 return NULL;
684 _rv = GetComponentListModSeed();
685 _res = Py_BuildValue("l",
686 _rv);
687 return _res;
688}
689
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000690static PyObject *Cm_CloseComponentResFile(PyObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000691{
692 PyObject *_res = NULL;
693 OSErr _err;
694 short refnum;
695 if (!PyArg_ParseTuple(_args, "h",
696 &refnum))
697 return NULL;
698 _err = CloseComponentResFile(refnum);
699 if (_err != noErr) return PyMac_Error(_err);
700 Py_INCREF(Py_None);
701 _res = Py_None;
702 return _res;
703}
704
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000705static PyObject *Cm_OpenDefaultComponent(PyObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000706{
707 PyObject *_res = NULL;
708 ComponentInstance _rv;
709 OSType componentType;
710 OSType componentSubType;
711 if (!PyArg_ParseTuple(_args, "O&O&",
712 PyMac_GetOSType, &componentType,
713 PyMac_GetOSType, &componentSubType))
714 return NULL;
715 _rv = OpenDefaultComponent(componentType,
716 componentSubType);
717 _res = Py_BuildValue("O&",
718 CmpInstObj_New, _rv);
719 return _res;
720}
721
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000722static PyObject *Cm_RegisterComponentResourceFile(PyObject *_self, PyObject *_args)
Jack Jansenb9968561995-11-30 15:03:09 +0000723{
724 PyObject *_res = NULL;
725 long _rv;
726 short resRefNum;
727 short global;
728 if (!PyArg_ParseTuple(_args, "hh",
729 &resRefNum,
730 &global))
731 return NULL;
732 _rv = RegisterComponentResourceFile(resRefNum,
733 global);
734 _res = Py_BuildValue("l",
735 _rv);
736 return _res;
737}
738
739static PyMethodDef Cm_methods[] = {
740 {"RegisterComponentResource", (PyCFunction)Cm_RegisterComponentResource, 1,
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000741 "(ComponentResourceHandle cr, short global) -> (Component _rv)"},
Jack Jansenb9968561995-11-30 15:03:09 +0000742 {"FindNextComponent", (PyCFunction)Cm_FindNextComponent, 1,
743 "(Component aComponent, ComponentDescription looking) -> (Component _rv)"},
744 {"CountComponents", (PyCFunction)Cm_CountComponents, 1,
745 "(ComponentDescription looking) -> (long _rv)"},
746 {"GetComponentListModSeed", (PyCFunction)Cm_GetComponentListModSeed, 1,
747 "() -> (long _rv)"},
748 {"CloseComponentResFile", (PyCFunction)Cm_CloseComponentResFile, 1,
749 "(short refnum) -> None"},
750 {"OpenDefaultComponent", (PyCFunction)Cm_OpenDefaultComponent, 1,
751 "(OSType componentType, OSType componentSubType) -> (ComponentInstance _rv)"},
752 {"RegisterComponentResourceFile", (PyCFunction)Cm_RegisterComponentResourceFile, 1,
753 "(short resRefNum, short global) -> (long _rv)"},
754 {NULL, NULL, 0}
755};
756
757
758
759
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000760void initCm(void)
Jack Jansenb9968561995-11-30 15:03:09 +0000761{
762 PyObject *m;
763 PyObject *d;
764
765
766
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000767 PyMac_INIT_TOOLBOX_OBJECT_NEW(Component, CmpObj_New);
768 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Component, CmpObj_Convert);
769 PyMac_INIT_TOOLBOX_OBJECT_NEW(ComponentInstance, CmpInstObj_New);
770 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ComponentInstance, CmpInstObj_Convert);
Jack Jansen0e04eec2001-05-17 21:58:34 +0000771
Jack Jansenb9968561995-11-30 15:03:09 +0000772
773 m = Py_InitModule("Cm", Cm_methods);
774 d = PyModule_GetDict(m);
775 Cm_Error = PyMac_GetOSErrException();
776 if (Cm_Error == NULL ||
777 PyDict_SetItemString(d, "Error", Cm_Error) != 0)
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000778 return;
Jack Jansena755e681997-09-20 17:40:22 +0000779 ComponentInstance_Type.ob_type = &PyType_Type;
780 Py_INCREF(&ComponentInstance_Type);
781 if (PyDict_SetItemString(d, "ComponentInstanceType", (PyObject *)&ComponentInstance_Type) != 0)
782 Py_FatalError("can't initialize ComponentInstanceType");
783 Component_Type.ob_type = &PyType_Type;
784 Py_INCREF(&Component_Type);
785 if (PyDict_SetItemString(d, "ComponentType", (PyObject *)&Component_Type) != 0)
786 Py_FatalError("can't initialize ComponentType");
Jack Jansenb9968561995-11-30 15:03:09 +0000787}
788
789/* ========================= End module Cm ========================== */
790