blob: 5e8a17c443a00263e9cab2f12df07cd8ce81136e [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
11#include <Components.h>
Jack Jansen0e04eec2001-05-17 21:58:34 +000012#ifdef USE_TOOLBOX_OBJECT_GLUE
13extern PyObject *_CmpObj_New(Component);
14extern int _CmpObj_Convert(PyObject *, Component *);
15extern PyObject *_CmpInstObj_New(ComponentInstance);
16extern 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 Jansenb9968561995-11-30 15:03:09 +000023
24/*
25** Parse/generate ComponentDescriptor records
26*/
Jack Jansen9d8b96c2000-07-14 22:16:45 +000027static PyObject *
28CmpDesc_New(itself)
Jack Jansenb9968561995-11-30 15:03:09 +000029 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 Jansen9d8b96c2000-07-14 22:16:45 +000039static int
Jack Jansenb9968561995-11-30 15:03:09 +000040CmpDesc_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
52static PyObject *Cm_Error;
53
54/* ----------------- Object type ComponentInstance ------------------ */
55
56PyTypeObject ComponentInstance_Type;
57
58#define CmpInstObj_Check(x) ((x)->ob_type == &ComponentInstance_Type)
59
60typedef struct ComponentInstanceObject {
61 PyObject_HEAD
62 ComponentInstance ob_itself;
63} ComponentInstanceObject;
64
65PyObject *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}
78CmpInstObj_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
91static void CmpInstObj_dealloc(self)
92 ComponentInstanceObject *self;
93{
94 /* Cleanup of self->ob_itself goes here */
95 PyMem_DEL(self);
96}
97
98static 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
113static 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 Jansenb9968561995-11-30 15:03:09 +0000128static 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
144static 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
158static 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 Jansen74a1e632000-07-14 22:37:27 +0000174#if !TARGET_API_MAC_CARBON
Jack Jansen8d929ae2000-06-21 22:07:06 +0000175
Jack Jansenb9968561995-11-30 15:03:09 +0000176static 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 Jansen8d929ae2000-06-21 22:07:06 +0000189#endif
190
Jack Jansen74a1e632000-07-14 22:37:27 +0000191#if !TARGET_API_MAC_CARBON
Jack Jansenb9968561995-11-30 15:03:09 +0000192
193static 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 Jansen8d929ae2000-06-21 22:07:06 +0000208#endif
Jack Jansenb9968561995-11-30 15:03:09 +0000209
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000210static 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
227static 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
241static 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 Jansenb9968561995-11-30 15:03:09 +0000258static PyMethodDef CmpInstObj_methods[] = {
259 {"CloseComponent", (PyCFunction)CmpInstObj_CloseComponent, 1,
260 "() -> None"},
261 {"GetComponentInstanceError", (PyCFunction)CmpInstObj_GetComponentInstanceError, 1,
262 "() -> None"},
Jack Jansenb9968561995-11-30 15:03:09 +0000263 {"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 Jansen8d929ae2000-06-21 22:07:06 +0000269
Jack Jansen74a1e632000-07-14 22:37:27 +0000270#if !TARGET_API_MAC_CARBON
Jack Jansenb9968561995-11-30 15:03:09 +0000271 {"GetComponentInstanceA5", (PyCFunction)CmpInstObj_GetComponentInstanceA5, 1,
272 "() -> (long _rv)"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000273#endif
274
Jack Jansen74a1e632000-07-14 22:37:27 +0000275#if !TARGET_API_MAC_CARBON
Jack Jansenb9968561995-11-30 15:03:09 +0000276 {"SetComponentInstanceA5", (PyCFunction)CmpInstObj_SetComponentInstanceA5, 1,
277 "(long theA5) -> None"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000278#endif
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000279 {"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 Jansenb9968561995-11-30 15:03:09 +0000285 {NULL, NULL, 0}
286};
287
288PyMethodChain CmpInstObj_chain = { CmpInstObj_methods, NULL };
289
290static 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 Jansena05ac601999-12-12 21:41:51 +0000299#define CmpInstObj_compare NULL
300
301#define CmpInstObj_repr NULL
302
303#define CmpInstObj_hash NULL
304
Jack Jansenb9968561995-11-30 15:03:09 +0000305PyTypeObject 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 Jansena05ac601999-12-12 21:41:51 +0000316 (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 Jansenb9968561995-11-30 15:03:09 +0000322};
323
324/* --------------- End object type ComponentInstance ---------------- */
325
326
327/* --------------------- Object type Component ---------------------- */
328
329PyTypeObject Component_Type;
330
331#define CmpObj_Check(x) ((x)->ob_type == &Component_Type)
332
333typedef struct ComponentObject {
334 PyObject_HEAD
335 Component ob_itself;
336} ComponentObject;
337
338PyObject *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}
352CmpObj_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
369static void CmpObj_dealloc(self)
370 ComponentObject *self;
371{
372 /* Cleanup of self->ob_itself goes here */
373 PyMem_DEL(self);
374}
375
376static 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
391static 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
417static 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
431static 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
445static 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
461static 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 Jansen1c4e6141998-04-21 15:23:55 +0000475static 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
498static 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
522static 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 Jansenb9968561995-11-30 15:03:09 +0000536static 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
550static 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
568static 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
585static 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
600static 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
617static 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 Jansen1c4e6141998-04-21 15:23:55 +0000630 {"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 Jansenb9968561995-11-30 15:03:09 +0000636 {"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
649PyMethodChain CmpObj_chain = { CmpObj_methods, NULL };
650
651static 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 Jansena05ac601999-12-12 21:41:51 +0000660#define CmpObj_compare NULL
661
662#define CmpObj_repr NULL
663
664#define CmpObj_hash NULL
665
Jack Jansenb9968561995-11-30 15:03:09 +0000666PyTypeObject 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 Jansena05ac601999-12-12 21:41:51 +0000677 (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 Jansenb9968561995-11-30 15:03:09 +0000683};
684
685/* ------------------- End object type Component -------------------- */
686
687
688static PyObject *Cm_RegisterComponentResource(_self, _args)
689 PyObject *_self;
690 PyObject *_args;
691{
692 PyObject *_res = NULL;
693 Component _rv;
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000694 ComponentResourceHandle cr;
Jack Jansenb9968561995-11-30 15:03:09 +0000695 short global;
696 if (!PyArg_ParseTuple(_args, "O&h",
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000697 ResObj_Convert, &cr,
Jack Jansenb9968561995-11-30 15:03:09 +0000698 &global))
699 return NULL;
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000700 _rv = RegisterComponentResource(cr,
Jack Jansenb9968561995-11-30 15:03:09 +0000701 global);
702 _res = Py_BuildValue("O&",
703 CmpObj_New, _rv);
704 return _res;
705}
706
707static 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
726static 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
742static 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
756static 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
773static 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
792static 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
811static PyMethodDef Cm_methods[] = {
812 {"RegisterComponentResource", (PyCFunction)Cm_RegisterComponentResource, 1,
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000813 "(ComponentResourceHandle cr, short global) -> (Component _rv)"},
Jack Jansenb9968561995-11-30 15:03:09 +0000814 {"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
832void initCm()
833{
834 PyObject *m;
835 PyObject *d;
836
837
838
Jack Jansen0e04eec2001-05-17 21:58:34 +0000839 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 Jansenb9968561995-11-30 15:03:09 +0000844
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 Jansenf7d5aa62000-12-10 23:43:49 +0000850 return;
Jack Jansena755e681997-09-20 17:40:22 +0000851 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 Jansenb9968561995-11-30 15:03:09 +0000859}
860
861/* ========================= End module Cm ========================== */
862