This commit was manufactured by cvs2svn to create tag 'r221c2'.
[python/dscho.git] / Mac / Modules / cm / _Cmmodule.c
blobd148f771f3b8d7d4a89974ebf27454c1deb90bec
2 /* =========================== Module _Cm =========================== */
4 #include "Python.h"
8 #ifdef _WIN32
9 #include "pywintoolbox.h"
10 #else
11 #include "macglue.h"
12 #include "pymactoolbox.h"
13 #endif
15 /* Macro to test whether a weak-loaded CFM function exists */
16 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
17 PyErr_SetString(PyExc_NotImplementedError, \
18 "Not available in this shared library/OS version"); \
19 return NULL; \
20 }} while(0)
23 #ifdef WITHOUT_FRAMEWORKS
24 #include <Components.h>
25 #else
26 #include <Carbon/Carbon.h>
27 #endif
29 #ifdef USE_TOOLBOX_OBJECT_GLUE
30 extern PyObject *_CmpObj_New(Component);
31 extern int _CmpObj_Convert(PyObject *, Component *);
32 extern PyObject *_CmpInstObj_New(ComponentInstance);
33 extern int _CmpInstObj_Convert(PyObject *, ComponentInstance *);
35 #define CmpObj_New _CmpObj_New
36 #define CmpObj_Convert _CmpObj_Convert
37 #define CmpInstObj_New _CmpInstObj_New
38 #define CmpInstObj_Convert _CmpInstObj_Convert
39 #endif
42 ** Parse/generate ComponentDescriptor records
44 static PyObject *
45 CmpDesc_New(ComponentDescription *itself)
48 return Py_BuildValue("O&O&O&ll",
49 PyMac_BuildOSType, itself->componentType,
50 PyMac_BuildOSType, itself->componentSubType,
51 PyMac_BuildOSType, itself->componentManufacturer,
52 itself->componentFlags, itself->componentFlagsMask);
55 static int
56 CmpDesc_Convert(PyObject *v, ComponentDescription *p_itself)
58 return PyArg_ParseTuple(v, "O&O&O&ll",
59 PyMac_GetOSType, &p_itself->componentType,
60 PyMac_GetOSType, &p_itself->componentSubType,
61 PyMac_GetOSType, &p_itself->componentManufacturer,
62 &p_itself->componentFlags, &p_itself->componentFlagsMask);
66 static PyObject *Cm_Error;
68 /* ----------------- Object type ComponentInstance ------------------ */
70 PyTypeObject ComponentInstance_Type;
72 #define CmpInstObj_Check(x) ((x)->ob_type == &ComponentInstance_Type)
74 typedef struct ComponentInstanceObject {
75 PyObject_HEAD
76 ComponentInstance ob_itself;
77 } ComponentInstanceObject;
79 PyObject *CmpInstObj_New(ComponentInstance itself)
81 ComponentInstanceObject *it;
82 if (itself == NULL) {
83 PyErr_SetString(Cm_Error,"NULL ComponentInstance");
84 return NULL;
86 it = PyObject_NEW(ComponentInstanceObject, &ComponentInstance_Type);
87 if (it == NULL) return NULL;
88 it->ob_itself = itself;
89 return (PyObject *)it;
91 int CmpInstObj_Convert(PyObject *v, ComponentInstance *p_itself)
93 if (!CmpInstObj_Check(v))
95 PyErr_SetString(PyExc_TypeError, "ComponentInstance required");
96 return 0;
98 *p_itself = ((ComponentInstanceObject *)v)->ob_itself;
99 return 1;
102 static void CmpInstObj_dealloc(ComponentInstanceObject *self)
104 /* Cleanup of self->ob_itself goes here */
105 PyMem_DEL(self);
108 static PyObject *CmpInstObj_CloseComponent(ComponentInstanceObject *_self, PyObject *_args)
110 PyObject *_res = NULL;
111 OSErr _err;
112 #ifndef CloseComponent
113 PyMac_PRECHECK(CloseComponent);
114 #endif
115 if (!PyArg_ParseTuple(_args, ""))
116 return NULL;
117 _err = CloseComponent(_self->ob_itself);
118 if (_err != noErr) return PyMac_Error(_err);
119 Py_INCREF(Py_None);
120 _res = Py_None;
121 return _res;
124 static PyObject *CmpInstObj_GetComponentInstanceError(ComponentInstanceObject *_self, PyObject *_args)
126 PyObject *_res = NULL;
127 OSErr _err;
128 #ifndef GetComponentInstanceError
129 PyMac_PRECHECK(GetComponentInstanceError);
130 #endif
131 if (!PyArg_ParseTuple(_args, ""))
132 return NULL;
133 _err = GetComponentInstanceError(_self->ob_itself);
134 if (_err != noErr) return PyMac_Error(_err);
135 Py_INCREF(Py_None);
136 _res = Py_None;
137 return _res;
140 static PyObject *CmpInstObj_SetComponentInstanceError(ComponentInstanceObject *_self, PyObject *_args)
142 PyObject *_res = NULL;
143 OSErr theError;
144 #ifndef SetComponentInstanceError
145 PyMac_PRECHECK(SetComponentInstanceError);
146 #endif
147 if (!PyArg_ParseTuple(_args, "h",
148 &theError))
149 return NULL;
150 SetComponentInstanceError(_self->ob_itself,
151 theError);
152 Py_INCREF(Py_None);
153 _res = Py_None;
154 return _res;
157 static PyObject *CmpInstObj_GetComponentInstanceStorage(ComponentInstanceObject *_self, PyObject *_args)
159 PyObject *_res = NULL;
160 Handle _rv;
161 #ifndef GetComponentInstanceStorage
162 PyMac_PRECHECK(GetComponentInstanceStorage);
163 #endif
164 if (!PyArg_ParseTuple(_args, ""))
165 return NULL;
166 _rv = GetComponentInstanceStorage(_self->ob_itself);
167 _res = Py_BuildValue("O&",
168 ResObj_New, _rv);
169 return _res;
172 static PyObject *CmpInstObj_SetComponentInstanceStorage(ComponentInstanceObject *_self, PyObject *_args)
174 PyObject *_res = NULL;
175 Handle theStorage;
176 #ifndef SetComponentInstanceStorage
177 PyMac_PRECHECK(SetComponentInstanceStorage);
178 #endif
179 if (!PyArg_ParseTuple(_args, "O&",
180 ResObj_Convert, &theStorage))
181 return NULL;
182 SetComponentInstanceStorage(_self->ob_itself,
183 theStorage);
184 Py_INCREF(Py_None);
185 _res = Py_None;
186 return _res;
189 #if !TARGET_API_MAC_CARBON
191 static PyObject *CmpInstObj_GetComponentInstanceA5(ComponentInstanceObject *_self, PyObject *_args)
193 PyObject *_res = NULL;
194 long _rv;
195 #ifndef GetComponentInstanceA5
196 PyMac_PRECHECK(GetComponentInstanceA5);
197 #endif
198 if (!PyArg_ParseTuple(_args, ""))
199 return NULL;
200 _rv = GetComponentInstanceA5(_self->ob_itself);
201 _res = Py_BuildValue("l",
202 _rv);
203 return _res;
205 #endif
207 #if !TARGET_API_MAC_CARBON
209 static PyObject *CmpInstObj_SetComponentInstanceA5(ComponentInstanceObject *_self, PyObject *_args)
211 PyObject *_res = NULL;
212 long theA5;
213 #ifndef SetComponentInstanceA5
214 PyMac_PRECHECK(SetComponentInstanceA5);
215 #endif
216 if (!PyArg_ParseTuple(_args, "l",
217 &theA5))
218 return NULL;
219 SetComponentInstanceA5(_self->ob_itself,
220 theA5);
221 Py_INCREF(Py_None);
222 _res = Py_None;
223 return _res;
225 #endif
227 static PyObject *CmpInstObj_ComponentFunctionImplemented(ComponentInstanceObject *_self, PyObject *_args)
229 PyObject *_res = NULL;
230 long _rv;
231 short ftnNumber;
232 #ifndef ComponentFunctionImplemented
233 PyMac_PRECHECK(ComponentFunctionImplemented);
234 #endif
235 if (!PyArg_ParseTuple(_args, "h",
236 &ftnNumber))
237 return NULL;
238 _rv = ComponentFunctionImplemented(_self->ob_itself,
239 ftnNumber);
240 _res = Py_BuildValue("l",
241 _rv);
242 return _res;
245 static PyObject *CmpInstObj_GetComponentVersion(ComponentInstanceObject *_self, PyObject *_args)
247 PyObject *_res = NULL;
248 long _rv;
249 #ifndef GetComponentVersion
250 PyMac_PRECHECK(GetComponentVersion);
251 #endif
252 if (!PyArg_ParseTuple(_args, ""))
253 return NULL;
254 _rv = GetComponentVersion(_self->ob_itself);
255 _res = Py_BuildValue("l",
256 _rv);
257 return _res;
260 static PyObject *CmpInstObj_ComponentSetTarget(ComponentInstanceObject *_self, PyObject *_args)
262 PyObject *_res = NULL;
263 long _rv;
264 ComponentInstance target;
265 #ifndef ComponentSetTarget
266 PyMac_PRECHECK(ComponentSetTarget);
267 #endif
268 if (!PyArg_ParseTuple(_args, "O&",
269 CmpInstObj_Convert, &target))
270 return NULL;
271 _rv = ComponentSetTarget(_self->ob_itself,
272 target);
273 _res = Py_BuildValue("l",
274 _rv);
275 return _res;
278 static PyMethodDef CmpInstObj_methods[] = {
279 {"CloseComponent", (PyCFunction)CmpInstObj_CloseComponent, 1,
280 "() -> None"},
281 {"GetComponentInstanceError", (PyCFunction)CmpInstObj_GetComponentInstanceError, 1,
282 "() -> None"},
283 {"SetComponentInstanceError", (PyCFunction)CmpInstObj_SetComponentInstanceError, 1,
284 "(OSErr theError) -> None"},
285 {"GetComponentInstanceStorage", (PyCFunction)CmpInstObj_GetComponentInstanceStorage, 1,
286 "() -> (Handle _rv)"},
287 {"SetComponentInstanceStorage", (PyCFunction)CmpInstObj_SetComponentInstanceStorage, 1,
288 "(Handle theStorage) -> None"},
290 #if !TARGET_API_MAC_CARBON
291 {"GetComponentInstanceA5", (PyCFunction)CmpInstObj_GetComponentInstanceA5, 1,
292 "() -> (long _rv)"},
293 #endif
295 #if !TARGET_API_MAC_CARBON
296 {"SetComponentInstanceA5", (PyCFunction)CmpInstObj_SetComponentInstanceA5, 1,
297 "(long theA5) -> None"},
298 #endif
299 {"ComponentFunctionImplemented", (PyCFunction)CmpInstObj_ComponentFunctionImplemented, 1,
300 "(short ftnNumber) -> (long _rv)"},
301 {"GetComponentVersion", (PyCFunction)CmpInstObj_GetComponentVersion, 1,
302 "() -> (long _rv)"},
303 {"ComponentSetTarget", (PyCFunction)CmpInstObj_ComponentSetTarget, 1,
304 "(ComponentInstance target) -> (long _rv)"},
305 {NULL, NULL, 0}
308 PyMethodChain CmpInstObj_chain = { CmpInstObj_methods, NULL };
310 static PyObject *CmpInstObj_getattr(ComponentInstanceObject *self, char *name)
312 return Py_FindMethodInChain(&CmpInstObj_chain, (PyObject *)self, name);
315 #define CmpInstObj_setattr NULL
317 #define CmpInstObj_compare NULL
319 #define CmpInstObj_repr NULL
321 #define CmpInstObj_hash NULL
323 PyTypeObject ComponentInstance_Type = {
324 PyObject_HEAD_INIT(NULL)
325 0, /*ob_size*/
326 "_Cm.ComponentInstance", /*tp_name*/
327 sizeof(ComponentInstanceObject), /*tp_basicsize*/
328 0, /*tp_itemsize*/
329 /* methods */
330 (destructor) CmpInstObj_dealloc, /*tp_dealloc*/
331 0, /*tp_print*/
332 (getattrfunc) CmpInstObj_getattr, /*tp_getattr*/
333 (setattrfunc) CmpInstObj_setattr, /*tp_setattr*/
334 (cmpfunc) CmpInstObj_compare, /*tp_compare*/
335 (reprfunc) CmpInstObj_repr, /*tp_repr*/
336 (PyNumberMethods *)0, /* tp_as_number */
337 (PySequenceMethods *)0, /* tp_as_sequence */
338 (PyMappingMethods *)0, /* tp_as_mapping */
339 (hashfunc) CmpInstObj_hash, /*tp_hash*/
342 /* --------------- End object type ComponentInstance ---------------- */
345 /* --------------------- Object type Component ---------------------- */
347 PyTypeObject Component_Type;
349 #define CmpObj_Check(x) ((x)->ob_type == &Component_Type)
351 typedef struct ComponentObject {
352 PyObject_HEAD
353 Component ob_itself;
354 } ComponentObject;
356 PyObject *CmpObj_New(Component itself)
358 ComponentObject *it;
359 if (itself == NULL) {
360 /* XXXX Or should we return None? */
361 PyErr_SetString(Cm_Error,"No such component");
362 return NULL;
364 it = PyObject_NEW(ComponentObject, &Component_Type);
365 if (it == NULL) return NULL;
366 it->ob_itself = itself;
367 return (PyObject *)it;
369 int CmpObj_Convert(PyObject *v, Component *p_itself)
371 if ( v == Py_None ) {
372 *p_itself = 0;
373 return 1;
375 if (!CmpObj_Check(v))
377 PyErr_SetString(PyExc_TypeError, "Component required");
378 return 0;
380 *p_itself = ((ComponentObject *)v)->ob_itself;
381 return 1;
384 static void CmpObj_dealloc(ComponentObject *self)
386 /* Cleanup of self->ob_itself goes here */
387 PyMem_DEL(self);
390 static PyObject *CmpObj_UnregisterComponent(ComponentObject *_self, PyObject *_args)
392 PyObject *_res = NULL;
393 OSErr _err;
394 #ifndef UnregisterComponent
395 PyMac_PRECHECK(UnregisterComponent);
396 #endif
397 if (!PyArg_ParseTuple(_args, ""))
398 return NULL;
399 _err = UnregisterComponent(_self->ob_itself);
400 if (_err != noErr) return PyMac_Error(_err);
401 Py_INCREF(Py_None);
402 _res = Py_None;
403 return _res;
406 static PyObject *CmpObj_GetComponentInfo(ComponentObject *_self, PyObject *_args)
408 PyObject *_res = NULL;
409 OSErr _err;
410 ComponentDescription cd;
411 Handle componentName;
412 Handle componentInfo;
413 Handle componentIcon;
414 #ifndef GetComponentInfo
415 PyMac_PRECHECK(GetComponentInfo);
416 #endif
417 if (!PyArg_ParseTuple(_args, "O&O&O&",
418 ResObj_Convert, &componentName,
419 ResObj_Convert, &componentInfo,
420 ResObj_Convert, &componentIcon))
421 return NULL;
422 _err = GetComponentInfo(_self->ob_itself,
423 &cd,
424 componentName,
425 componentInfo,
426 componentIcon);
427 if (_err != noErr) return PyMac_Error(_err);
428 _res = Py_BuildValue("O&",
429 CmpDesc_New, &cd);
430 return _res;
433 static PyObject *CmpObj_OpenComponent(ComponentObject *_self, PyObject *_args)
435 PyObject *_res = NULL;
436 ComponentInstance _rv;
437 #ifndef OpenComponent
438 PyMac_PRECHECK(OpenComponent);
439 #endif
440 if (!PyArg_ParseTuple(_args, ""))
441 return NULL;
442 _rv = OpenComponent(_self->ob_itself);
443 _res = Py_BuildValue("O&",
444 CmpInstObj_New, _rv);
445 return _res;
448 static PyObject *CmpObj_ResolveComponentAlias(ComponentObject *_self, PyObject *_args)
450 PyObject *_res = NULL;
451 Component _rv;
452 #ifndef ResolveComponentAlias
453 PyMac_PRECHECK(ResolveComponentAlias);
454 #endif
455 if (!PyArg_ParseTuple(_args, ""))
456 return NULL;
457 _rv = ResolveComponentAlias(_self->ob_itself);
458 _res = Py_BuildValue("O&",
459 CmpObj_New, _rv);
460 return _res;
463 static PyObject *CmpObj_GetComponentPublicIndString(ComponentObject *_self, PyObject *_args)
465 PyObject *_res = NULL;
466 OSErr _err;
467 Str255 theString;
468 short strListID;
469 short index;
470 #ifndef GetComponentPublicIndString
471 PyMac_PRECHECK(GetComponentPublicIndString);
472 #endif
473 if (!PyArg_ParseTuple(_args, "O&hh",
474 PyMac_GetStr255, theString,
475 &strListID,
476 &index))
477 return NULL;
478 _err = GetComponentPublicIndString(_self->ob_itself,
479 theString,
480 strListID,
481 index);
482 if (_err != noErr) return PyMac_Error(_err);
483 Py_INCREF(Py_None);
484 _res = Py_None;
485 return _res;
488 static PyObject *CmpObj_GetComponentRefcon(ComponentObject *_self, PyObject *_args)
490 PyObject *_res = NULL;
491 long _rv;
492 #ifndef GetComponentRefcon
493 PyMac_PRECHECK(GetComponentRefcon);
494 #endif
495 if (!PyArg_ParseTuple(_args, ""))
496 return NULL;
497 _rv = GetComponentRefcon(_self->ob_itself);
498 _res = Py_BuildValue("l",
499 _rv);
500 return _res;
503 static PyObject *CmpObj_SetComponentRefcon(ComponentObject *_self, PyObject *_args)
505 PyObject *_res = NULL;
506 long theRefcon;
507 #ifndef SetComponentRefcon
508 PyMac_PRECHECK(SetComponentRefcon);
509 #endif
510 if (!PyArg_ParseTuple(_args, "l",
511 &theRefcon))
512 return NULL;
513 SetComponentRefcon(_self->ob_itself,
514 theRefcon);
515 Py_INCREF(Py_None);
516 _res = Py_None;
517 return _res;
520 static PyObject *CmpObj_OpenComponentResFile(ComponentObject *_self, PyObject *_args)
522 PyObject *_res = NULL;
523 short _rv;
524 #ifndef OpenComponentResFile
525 PyMac_PRECHECK(OpenComponentResFile);
526 #endif
527 if (!PyArg_ParseTuple(_args, ""))
528 return NULL;
529 _rv = OpenComponentResFile(_self->ob_itself);
530 _res = Py_BuildValue("h",
531 _rv);
532 return _res;
535 static PyObject *CmpObj_GetComponentResource(ComponentObject *_self, PyObject *_args)
537 PyObject *_res = NULL;
538 OSErr _err;
539 OSType resType;
540 short resID;
541 Handle theResource;
542 #ifndef GetComponentResource
543 PyMac_PRECHECK(GetComponentResource);
544 #endif
545 if (!PyArg_ParseTuple(_args, "O&h",
546 PyMac_GetOSType, &resType,
547 &resID))
548 return NULL;
549 _err = GetComponentResource(_self->ob_itself,
550 resType,
551 resID,
552 &theResource);
553 if (_err != noErr) return PyMac_Error(_err);
554 _res = Py_BuildValue("O&",
555 ResObj_New, theResource);
556 return _res;
559 static PyObject *CmpObj_GetComponentIndString(ComponentObject *_self, PyObject *_args)
561 PyObject *_res = NULL;
562 OSErr _err;
563 Str255 theString;
564 short strListID;
565 short index;
566 #ifndef GetComponentIndString
567 PyMac_PRECHECK(GetComponentIndString);
568 #endif
569 if (!PyArg_ParseTuple(_args, "O&hh",
570 PyMac_GetStr255, theString,
571 &strListID,
572 &index))
573 return NULL;
574 _err = GetComponentIndString(_self->ob_itself,
575 theString,
576 strListID,
577 index);
578 if (_err != noErr) return PyMac_Error(_err);
579 Py_INCREF(Py_None);
580 _res = Py_None;
581 return _res;
584 static PyObject *CmpObj_CountComponentInstances(ComponentObject *_self, PyObject *_args)
586 PyObject *_res = NULL;
587 long _rv;
588 #ifndef CountComponentInstances
589 PyMac_PRECHECK(CountComponentInstances);
590 #endif
591 if (!PyArg_ParseTuple(_args, ""))
592 return NULL;
593 _rv = CountComponentInstances(_self->ob_itself);
594 _res = Py_BuildValue("l",
595 _rv);
596 return _res;
599 static PyObject *CmpObj_SetDefaultComponent(ComponentObject *_self, PyObject *_args)
601 PyObject *_res = NULL;
602 OSErr _err;
603 short flags;
604 #ifndef SetDefaultComponent
605 PyMac_PRECHECK(SetDefaultComponent);
606 #endif
607 if (!PyArg_ParseTuple(_args, "h",
608 &flags))
609 return NULL;
610 _err = SetDefaultComponent(_self->ob_itself,
611 flags);
612 if (_err != noErr) return PyMac_Error(_err);
613 Py_INCREF(Py_None);
614 _res = Py_None;
615 return _res;
618 static PyObject *CmpObj_CaptureComponent(ComponentObject *_self, PyObject *_args)
620 PyObject *_res = NULL;
621 Component _rv;
622 Component capturingComponent;
623 #ifndef CaptureComponent
624 PyMac_PRECHECK(CaptureComponent);
625 #endif
626 if (!PyArg_ParseTuple(_args, "O&",
627 CmpObj_Convert, &capturingComponent))
628 return NULL;
629 _rv = CaptureComponent(_self->ob_itself,
630 capturingComponent);
631 _res = Py_BuildValue("O&",
632 CmpObj_New, _rv);
633 return _res;
636 static PyObject *CmpObj_UncaptureComponent(ComponentObject *_self, PyObject *_args)
638 PyObject *_res = NULL;
639 OSErr _err;
640 #ifndef UncaptureComponent
641 PyMac_PRECHECK(UncaptureComponent);
642 #endif
643 if (!PyArg_ParseTuple(_args, ""))
644 return NULL;
645 _err = UncaptureComponent(_self->ob_itself);
646 if (_err != noErr) return PyMac_Error(_err);
647 Py_INCREF(Py_None);
648 _res = Py_None;
649 return _res;
652 static PyObject *CmpObj_GetComponentIconSuite(ComponentObject *_self, PyObject *_args)
654 PyObject *_res = NULL;
655 OSErr _err;
656 Handle iconSuite;
657 #ifndef GetComponentIconSuite
658 PyMac_PRECHECK(GetComponentIconSuite);
659 #endif
660 if (!PyArg_ParseTuple(_args, ""))
661 return NULL;
662 _err = GetComponentIconSuite(_self->ob_itself,
663 &iconSuite);
664 if (_err != noErr) return PyMac_Error(_err);
665 _res = Py_BuildValue("O&",
666 ResObj_New, iconSuite);
667 return _res;
670 static PyMethodDef CmpObj_methods[] = {
671 {"UnregisterComponent", (PyCFunction)CmpObj_UnregisterComponent, 1,
672 "() -> None"},
673 {"GetComponentInfo", (PyCFunction)CmpObj_GetComponentInfo, 1,
674 "(Handle componentName, Handle componentInfo, Handle componentIcon) -> (ComponentDescription cd)"},
675 {"OpenComponent", (PyCFunction)CmpObj_OpenComponent, 1,
676 "() -> (ComponentInstance _rv)"},
677 {"ResolveComponentAlias", (PyCFunction)CmpObj_ResolveComponentAlias, 1,
678 "() -> (Component _rv)"},
679 {"GetComponentPublicIndString", (PyCFunction)CmpObj_GetComponentPublicIndString, 1,
680 "(Str255 theString, short strListID, short index) -> None"},
681 {"GetComponentRefcon", (PyCFunction)CmpObj_GetComponentRefcon, 1,
682 "() -> (long _rv)"},
683 {"SetComponentRefcon", (PyCFunction)CmpObj_SetComponentRefcon, 1,
684 "(long theRefcon) -> None"},
685 {"OpenComponentResFile", (PyCFunction)CmpObj_OpenComponentResFile, 1,
686 "() -> (short _rv)"},
687 {"GetComponentResource", (PyCFunction)CmpObj_GetComponentResource, 1,
688 "(OSType resType, short resID) -> (Handle theResource)"},
689 {"GetComponentIndString", (PyCFunction)CmpObj_GetComponentIndString, 1,
690 "(Str255 theString, short strListID, short index) -> None"},
691 {"CountComponentInstances", (PyCFunction)CmpObj_CountComponentInstances, 1,
692 "() -> (long _rv)"},
693 {"SetDefaultComponent", (PyCFunction)CmpObj_SetDefaultComponent, 1,
694 "(short flags) -> None"},
695 {"CaptureComponent", (PyCFunction)CmpObj_CaptureComponent, 1,
696 "(Component capturingComponent) -> (Component _rv)"},
697 {"UncaptureComponent", (PyCFunction)CmpObj_UncaptureComponent, 1,
698 "() -> None"},
699 {"GetComponentIconSuite", (PyCFunction)CmpObj_GetComponentIconSuite, 1,
700 "() -> (Handle iconSuite)"},
701 {NULL, NULL, 0}
704 PyMethodChain CmpObj_chain = { CmpObj_methods, NULL };
706 static PyObject *CmpObj_getattr(ComponentObject *self, char *name)
708 return Py_FindMethodInChain(&CmpObj_chain, (PyObject *)self, name);
711 #define CmpObj_setattr NULL
713 #define CmpObj_compare NULL
715 #define CmpObj_repr NULL
717 #define CmpObj_hash NULL
719 PyTypeObject Component_Type = {
720 PyObject_HEAD_INIT(NULL)
721 0, /*ob_size*/
722 "_Cm.Component", /*tp_name*/
723 sizeof(ComponentObject), /*tp_basicsize*/
724 0, /*tp_itemsize*/
725 /* methods */
726 (destructor) CmpObj_dealloc, /*tp_dealloc*/
727 0, /*tp_print*/
728 (getattrfunc) CmpObj_getattr, /*tp_getattr*/
729 (setattrfunc) CmpObj_setattr, /*tp_setattr*/
730 (cmpfunc) CmpObj_compare, /*tp_compare*/
731 (reprfunc) CmpObj_repr, /*tp_repr*/
732 (PyNumberMethods *)0, /* tp_as_number */
733 (PySequenceMethods *)0, /* tp_as_sequence */
734 (PyMappingMethods *)0, /* tp_as_mapping */
735 (hashfunc) CmpObj_hash, /*tp_hash*/
738 /* ------------------- End object type Component -------------------- */
741 static PyObject *Cm_RegisterComponentResource(PyObject *_self, PyObject *_args)
743 PyObject *_res = NULL;
744 Component _rv;
745 ComponentResourceHandle cr;
746 short global;
747 #ifndef RegisterComponentResource
748 PyMac_PRECHECK(RegisterComponentResource);
749 #endif
750 if (!PyArg_ParseTuple(_args, "O&h",
751 ResObj_Convert, &cr,
752 &global))
753 return NULL;
754 _rv = RegisterComponentResource(cr,
755 global);
756 _res = Py_BuildValue("O&",
757 CmpObj_New, _rv);
758 return _res;
761 static PyObject *Cm_FindNextComponent(PyObject *_self, PyObject *_args)
763 PyObject *_res = NULL;
764 Component _rv;
765 Component aComponent;
766 ComponentDescription looking;
767 #ifndef FindNextComponent
768 PyMac_PRECHECK(FindNextComponent);
769 #endif
770 if (!PyArg_ParseTuple(_args, "O&O&",
771 CmpObj_Convert, &aComponent,
772 CmpDesc_Convert, &looking))
773 return NULL;
774 _rv = FindNextComponent(aComponent,
775 &looking);
776 _res = Py_BuildValue("O&",
777 CmpObj_New, _rv);
778 return _res;
781 static PyObject *Cm_CountComponents(PyObject *_self, PyObject *_args)
783 PyObject *_res = NULL;
784 long _rv;
785 ComponentDescription looking;
786 #ifndef CountComponents
787 PyMac_PRECHECK(CountComponents);
788 #endif
789 if (!PyArg_ParseTuple(_args, "O&",
790 CmpDesc_Convert, &looking))
791 return NULL;
792 _rv = CountComponents(&looking);
793 _res = Py_BuildValue("l",
794 _rv);
795 return _res;
798 static PyObject *Cm_GetComponentListModSeed(PyObject *_self, PyObject *_args)
800 PyObject *_res = NULL;
801 long _rv;
802 #ifndef GetComponentListModSeed
803 PyMac_PRECHECK(GetComponentListModSeed);
804 #endif
805 if (!PyArg_ParseTuple(_args, ""))
806 return NULL;
807 _rv = GetComponentListModSeed();
808 _res = Py_BuildValue("l",
809 _rv);
810 return _res;
813 static PyObject *Cm_CloseComponentResFile(PyObject *_self, PyObject *_args)
815 PyObject *_res = NULL;
816 OSErr _err;
817 short refnum;
818 #ifndef CloseComponentResFile
819 PyMac_PRECHECK(CloseComponentResFile);
820 #endif
821 if (!PyArg_ParseTuple(_args, "h",
822 &refnum))
823 return NULL;
824 _err = CloseComponentResFile(refnum);
825 if (_err != noErr) return PyMac_Error(_err);
826 Py_INCREF(Py_None);
827 _res = Py_None;
828 return _res;
831 static PyObject *Cm_OpenDefaultComponent(PyObject *_self, PyObject *_args)
833 PyObject *_res = NULL;
834 ComponentInstance _rv;
835 OSType componentType;
836 OSType componentSubType;
837 #ifndef OpenDefaultComponent
838 PyMac_PRECHECK(OpenDefaultComponent);
839 #endif
840 if (!PyArg_ParseTuple(_args, "O&O&",
841 PyMac_GetOSType, &componentType,
842 PyMac_GetOSType, &componentSubType))
843 return NULL;
844 _rv = OpenDefaultComponent(componentType,
845 componentSubType);
846 _res = Py_BuildValue("O&",
847 CmpInstObj_New, _rv);
848 return _res;
851 static PyObject *Cm_RegisterComponentResourceFile(PyObject *_self, PyObject *_args)
853 PyObject *_res = NULL;
854 long _rv;
855 short resRefNum;
856 short global;
857 #ifndef RegisterComponentResourceFile
858 PyMac_PRECHECK(RegisterComponentResourceFile);
859 #endif
860 if (!PyArg_ParseTuple(_args, "hh",
861 &resRefNum,
862 &global))
863 return NULL;
864 _rv = RegisterComponentResourceFile(resRefNum,
865 global);
866 _res = Py_BuildValue("l",
867 _rv);
868 return _res;
871 static PyMethodDef Cm_methods[] = {
872 {"RegisterComponentResource", (PyCFunction)Cm_RegisterComponentResource, 1,
873 "(ComponentResourceHandle cr, short global) -> (Component _rv)"},
874 {"FindNextComponent", (PyCFunction)Cm_FindNextComponent, 1,
875 "(Component aComponent, ComponentDescription looking) -> (Component _rv)"},
876 {"CountComponents", (PyCFunction)Cm_CountComponents, 1,
877 "(ComponentDescription looking) -> (long _rv)"},
878 {"GetComponentListModSeed", (PyCFunction)Cm_GetComponentListModSeed, 1,
879 "() -> (long _rv)"},
880 {"CloseComponentResFile", (PyCFunction)Cm_CloseComponentResFile, 1,
881 "(short refnum) -> None"},
882 {"OpenDefaultComponent", (PyCFunction)Cm_OpenDefaultComponent, 1,
883 "(OSType componentType, OSType componentSubType) -> (ComponentInstance _rv)"},
884 {"RegisterComponentResourceFile", (PyCFunction)Cm_RegisterComponentResourceFile, 1,
885 "(short resRefNum, short global) -> (long _rv)"},
886 {NULL, NULL, 0}
892 void init_Cm(void)
894 PyObject *m;
895 PyObject *d;
899 PyMac_INIT_TOOLBOX_OBJECT_NEW(Component, CmpObj_New);
900 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Component, CmpObj_Convert);
901 PyMac_INIT_TOOLBOX_OBJECT_NEW(ComponentInstance, CmpInstObj_New);
902 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ComponentInstance, CmpInstObj_Convert);
905 m = Py_InitModule("_Cm", Cm_methods);
906 d = PyModule_GetDict(m);
907 Cm_Error = PyMac_GetOSErrException();
908 if (Cm_Error == NULL ||
909 PyDict_SetItemString(d, "Error", Cm_Error) != 0)
910 return;
911 ComponentInstance_Type.ob_type = &PyType_Type;
912 Py_INCREF(&ComponentInstance_Type);
913 if (PyDict_SetItemString(d, "ComponentInstanceType", (PyObject *)&ComponentInstance_Type) != 0)
914 Py_FatalError("can't initialize ComponentInstanceType");
915 Component_Type.ob_type = &PyType_Type;
916 Py_INCREF(&Component_Type);
917 if (PyDict_SetItemString(d, "ComponentType", (PyObject *)&Component_Type) != 0)
918 Py_FatalError("can't initialize ComponentType");
921 /* ========================= End module _Cm ========================= */