2 /* =========================== Module Cm ============================ */
9 #include "pymactoolbox.h"
11 #include <Components.h>
14 ** Parse/generate ComponentDescriptor records
18 ComponentDescription
*itself
;
21 return Py_BuildValue("O&O&O&ll",
22 PyMac_BuildOSType
, itself
->componentType
,
23 PyMac_BuildOSType
, itself
->componentSubType
,
24 PyMac_BuildOSType
, itself
->componentManufacturer
,
25 itself
->componentFlags
, itself
->componentFlagsMask
);
29 CmpDesc_Convert(v
, p_itself
)
31 ComponentDescription
*p_itself
;
33 return PyArg_ParseTuple(v
, "O&O&O&ll",
34 PyMac_GetOSType
, &p_itself
->componentType
,
35 PyMac_GetOSType
, &p_itself
->componentSubType
,
36 PyMac_GetOSType
, &p_itself
->componentManufacturer
,
37 &p_itself
->componentFlags
, &p_itself
->componentFlagsMask
);
41 static PyObject
*Cm_Error
;
43 /* ----------------- Object type ComponentInstance ------------------ */
45 PyTypeObject ComponentInstance_Type
;
47 #define CmpInstObj_Check(x) ((x)->ob_type == &ComponentInstance_Type)
49 typedef struct ComponentInstanceObject
{
51 ComponentInstance ob_itself
;
52 } ComponentInstanceObject
;
54 PyObject
*CmpInstObj_New(itself
)
55 ComponentInstance itself
;
57 ComponentInstanceObject
*it
;
59 PyErr_SetString(Cm_Error
,"NULL ComponentInstance");
62 it
= PyObject_NEW(ComponentInstanceObject
, &ComponentInstance_Type
);
63 if (it
== NULL
) return NULL
;
64 it
->ob_itself
= itself
;
65 return (PyObject
*)it
;
67 CmpInstObj_Convert(v
, p_itself
)
69 ComponentInstance
*p_itself
;
71 if (!CmpInstObj_Check(v
))
73 PyErr_SetString(PyExc_TypeError
, "ComponentInstance required");
76 *p_itself
= ((ComponentInstanceObject
*)v
)->ob_itself
;
80 static void CmpInstObj_dealloc(self
)
81 ComponentInstanceObject
*self
;
83 /* Cleanup of self->ob_itself goes here */
87 static PyObject
*CmpInstObj_CloseComponent(_self
, _args
)
88 ComponentInstanceObject
*_self
;
91 PyObject
*_res
= NULL
;
93 if (!PyArg_ParseTuple(_args
, ""))
95 _err
= CloseComponent(_self
->ob_itself
);
96 if (_err
!= noErr
) return PyMac_Error(_err
);
102 static PyObject
*CmpInstObj_GetComponentInstanceError(_self
, _args
)
103 ComponentInstanceObject
*_self
;
106 PyObject
*_res
= NULL
;
108 if (!PyArg_ParseTuple(_args
, ""))
110 _err
= GetComponentInstanceError(_self
->ob_itself
);
111 if (_err
!= noErr
) return PyMac_Error(_err
);
117 static PyObject
*CmpInstObj_SetComponentInstanceError(_self
, _args
)
118 ComponentInstanceObject
*_self
;
121 PyObject
*_res
= NULL
;
123 if (!PyArg_ParseTuple(_args
, "h",
126 SetComponentInstanceError(_self
->ob_itself
,
133 static PyObject
*CmpInstObj_GetComponentInstanceStorage(_self
, _args
)
134 ComponentInstanceObject
*_self
;
137 PyObject
*_res
= NULL
;
139 if (!PyArg_ParseTuple(_args
, ""))
141 _rv
= GetComponentInstanceStorage(_self
->ob_itself
);
142 _res
= Py_BuildValue("O&",
147 static PyObject
*CmpInstObj_SetComponentInstanceStorage(_self
, _args
)
148 ComponentInstanceObject
*_self
;
151 PyObject
*_res
= NULL
;
153 if (!PyArg_ParseTuple(_args
, "O&",
154 ResObj_Convert
, &theStorage
))
156 SetComponentInstanceStorage(_self
->ob_itself
,
163 #if !TARGET_API_MAC_CARBON
165 static PyObject
*CmpInstObj_GetComponentInstanceA5(_self
, _args
)
166 ComponentInstanceObject
*_self
;
169 PyObject
*_res
= NULL
;
171 if (!PyArg_ParseTuple(_args
, ""))
173 _rv
= GetComponentInstanceA5(_self
->ob_itself
);
174 _res
= Py_BuildValue("l",
180 #if !TARGET_API_MAC_CARBON
182 static PyObject
*CmpInstObj_SetComponentInstanceA5(_self
, _args
)
183 ComponentInstanceObject
*_self
;
186 PyObject
*_res
= NULL
;
188 if (!PyArg_ParseTuple(_args
, "l",
191 SetComponentInstanceA5(_self
->ob_itself
,
199 static PyObject
*CmpInstObj_ComponentFunctionImplemented(_self
, _args
)
200 ComponentInstanceObject
*_self
;
203 PyObject
*_res
= NULL
;
206 if (!PyArg_ParseTuple(_args
, "h",
209 _rv
= ComponentFunctionImplemented(_self
->ob_itself
,
211 _res
= Py_BuildValue("l",
216 static PyObject
*CmpInstObj_GetComponentVersion(_self
, _args
)
217 ComponentInstanceObject
*_self
;
220 PyObject
*_res
= NULL
;
222 if (!PyArg_ParseTuple(_args
, ""))
224 _rv
= GetComponentVersion(_self
->ob_itself
);
225 _res
= Py_BuildValue("l",
230 static PyObject
*CmpInstObj_ComponentSetTarget(_self
, _args
)
231 ComponentInstanceObject
*_self
;
234 PyObject
*_res
= NULL
;
236 ComponentInstance target
;
237 if (!PyArg_ParseTuple(_args
, "O&",
238 CmpInstObj_Convert
, &target
))
240 _rv
= ComponentSetTarget(_self
->ob_itself
,
242 _res
= Py_BuildValue("l",
247 static PyMethodDef CmpInstObj_methods
[] = {
248 {"CloseComponent", (PyCFunction
)CmpInstObj_CloseComponent
, 1,
250 {"GetComponentInstanceError", (PyCFunction
)CmpInstObj_GetComponentInstanceError
, 1,
252 {"SetComponentInstanceError", (PyCFunction
)CmpInstObj_SetComponentInstanceError
, 1,
253 "(OSErr theError) -> None"},
254 {"GetComponentInstanceStorage", (PyCFunction
)CmpInstObj_GetComponentInstanceStorage
, 1,
255 "() -> (Handle _rv)"},
256 {"SetComponentInstanceStorage", (PyCFunction
)CmpInstObj_SetComponentInstanceStorage
, 1,
257 "(Handle theStorage) -> None"},
259 #if !TARGET_API_MAC_CARBON
260 {"GetComponentInstanceA5", (PyCFunction
)CmpInstObj_GetComponentInstanceA5
, 1,
264 #if !TARGET_API_MAC_CARBON
265 {"SetComponentInstanceA5", (PyCFunction
)CmpInstObj_SetComponentInstanceA5
, 1,
266 "(long theA5) -> None"},
268 {"ComponentFunctionImplemented", (PyCFunction
)CmpInstObj_ComponentFunctionImplemented
, 1,
269 "(short ftnNumber) -> (long _rv)"},
270 {"GetComponentVersion", (PyCFunction
)CmpInstObj_GetComponentVersion
, 1,
272 {"ComponentSetTarget", (PyCFunction
)CmpInstObj_ComponentSetTarget
, 1,
273 "(ComponentInstance target) -> (long _rv)"},
277 PyMethodChain CmpInstObj_chain
= { CmpInstObj_methods
, NULL
};
279 static PyObject
*CmpInstObj_getattr(self
, name
)
280 ComponentInstanceObject
*self
;
283 return Py_FindMethodInChain(&CmpInstObj_chain
, (PyObject
*)self
, name
);
286 #define CmpInstObj_setattr NULL
288 #define CmpInstObj_compare NULL
290 #define CmpInstObj_repr NULL
292 #define CmpInstObj_hash NULL
294 PyTypeObject ComponentInstance_Type
= {
295 PyObject_HEAD_INIT(&PyType_Type
)
297 "ComponentInstance", /*tp_name*/
298 sizeof(ComponentInstanceObject
), /*tp_basicsize*/
301 (destructor
) CmpInstObj_dealloc
, /*tp_dealloc*/
303 (getattrfunc
) CmpInstObj_getattr
, /*tp_getattr*/
304 (setattrfunc
) CmpInstObj_setattr
, /*tp_setattr*/
305 (cmpfunc
) CmpInstObj_compare
, /*tp_compare*/
306 (reprfunc
) CmpInstObj_repr
, /*tp_repr*/
307 (PyNumberMethods
*)0, /* tp_as_number */
308 (PySequenceMethods
*)0, /* tp_as_sequence */
309 (PyMappingMethods
*)0, /* tp_as_mapping */
310 (hashfunc
) CmpInstObj_hash
, /*tp_hash*/
313 /* --------------- End object type ComponentInstance ---------------- */
316 /* --------------------- Object type Component ---------------------- */
318 PyTypeObject Component_Type
;
320 #define CmpObj_Check(x) ((x)->ob_type == &Component_Type)
322 typedef struct ComponentObject
{
327 PyObject
*CmpObj_New(itself
)
331 if (itself
== NULL
) {
332 /* XXXX Or should we return None? */
333 PyErr_SetString(Cm_Error
,"No such component");
336 it
= PyObject_NEW(ComponentObject
, &Component_Type
);
337 if (it
== NULL
) return NULL
;
338 it
->ob_itself
= itself
;
339 return (PyObject
*)it
;
341 CmpObj_Convert(v
, p_itself
)
345 if ( v
== Py_None
) {
349 if (!CmpObj_Check(v
))
351 PyErr_SetString(PyExc_TypeError
, "Component required");
354 *p_itself
= ((ComponentObject
*)v
)->ob_itself
;
358 static void CmpObj_dealloc(self
)
359 ComponentObject
*self
;
361 /* Cleanup of self->ob_itself goes here */
365 static PyObject
*CmpObj_UnregisterComponent(_self
, _args
)
366 ComponentObject
*_self
;
369 PyObject
*_res
= NULL
;
371 if (!PyArg_ParseTuple(_args
, ""))
373 _err
= UnregisterComponent(_self
->ob_itself
);
374 if (_err
!= noErr
) return PyMac_Error(_err
);
380 static PyObject
*CmpObj_GetComponentInfo(_self
, _args
)
381 ComponentObject
*_self
;
384 PyObject
*_res
= NULL
;
386 ComponentDescription cd
;
387 Handle componentName
;
388 Handle componentInfo
;
389 Handle componentIcon
;
390 if (!PyArg_ParseTuple(_args
, "O&O&O&",
391 ResObj_Convert
, &componentName
,
392 ResObj_Convert
, &componentInfo
,
393 ResObj_Convert
, &componentIcon
))
395 _err
= GetComponentInfo(_self
->ob_itself
,
400 if (_err
!= noErr
) return PyMac_Error(_err
);
401 _res
= Py_BuildValue("O&",
406 static PyObject
*CmpObj_OpenComponent(_self
, _args
)
407 ComponentObject
*_self
;
410 PyObject
*_res
= NULL
;
411 ComponentInstance _rv
;
412 if (!PyArg_ParseTuple(_args
, ""))
414 _rv
= OpenComponent(_self
->ob_itself
);
415 _res
= Py_BuildValue("O&",
416 CmpInstObj_New
, _rv
);
420 static PyObject
*CmpObj_GetComponentRefcon(_self
, _args
)
421 ComponentObject
*_self
;
424 PyObject
*_res
= NULL
;
426 if (!PyArg_ParseTuple(_args
, ""))
428 _rv
= GetComponentRefcon(_self
->ob_itself
);
429 _res
= Py_BuildValue("l",
434 static PyObject
*CmpObj_SetComponentRefcon(_self
, _args
)
435 ComponentObject
*_self
;
438 PyObject
*_res
= NULL
;
440 if (!PyArg_ParseTuple(_args
, "l",
443 SetComponentRefcon(_self
->ob_itself
,
450 static PyObject
*CmpObj_OpenComponentResFile(_self
, _args
)
451 ComponentObject
*_self
;
454 PyObject
*_res
= NULL
;
456 if (!PyArg_ParseTuple(_args
, ""))
458 _rv
= OpenComponentResFile(_self
->ob_itself
);
459 _res
= Py_BuildValue("h",
464 static PyObject
*CmpObj_GetComponentResource(_self
, _args
)
465 ComponentObject
*_self
;
468 PyObject
*_res
= NULL
;
473 if (!PyArg_ParseTuple(_args
, "O&h",
474 PyMac_GetOSType
, &resType
,
477 _err
= GetComponentResource(_self
->ob_itself
,
481 if (_err
!= noErr
) return PyMac_Error(_err
);
482 _res
= Py_BuildValue("O&",
483 ResObj_New
, theResource
);
487 static PyObject
*CmpObj_GetComponentIndString(_self
, _args
)
488 ComponentObject
*_self
;
491 PyObject
*_res
= NULL
;
496 if (!PyArg_ParseTuple(_args
, "O&hh",
497 PyMac_GetStr255
, theString
,
501 _err
= GetComponentIndString(_self
->ob_itself
,
505 if (_err
!= noErr
) return PyMac_Error(_err
);
511 static PyObject
*CmpObj_ResolveComponentAlias(_self
, _args
)
512 ComponentObject
*_self
;
515 PyObject
*_res
= NULL
;
517 if (!PyArg_ParseTuple(_args
, ""))
519 _rv
= ResolveComponentAlias(_self
->ob_itself
);
520 _res
= Py_BuildValue("O&",
525 static PyObject
*CmpObj_CountComponentInstances(_self
, _args
)
526 ComponentObject
*_self
;
529 PyObject
*_res
= NULL
;
531 if (!PyArg_ParseTuple(_args
, ""))
533 _rv
= CountComponentInstances(_self
->ob_itself
);
534 _res
= Py_BuildValue("l",
539 static PyObject
*CmpObj_SetDefaultComponent(_self
, _args
)
540 ComponentObject
*_self
;
543 PyObject
*_res
= NULL
;
546 if (!PyArg_ParseTuple(_args
, "h",
549 _err
= SetDefaultComponent(_self
->ob_itself
,
551 if (_err
!= noErr
) return PyMac_Error(_err
);
557 static PyObject
*CmpObj_CaptureComponent(_self
, _args
)
558 ComponentObject
*_self
;
561 PyObject
*_res
= NULL
;
563 Component capturingComponent
;
564 if (!PyArg_ParseTuple(_args
, "O&",
565 CmpObj_Convert
, &capturingComponent
))
567 _rv
= CaptureComponent(_self
->ob_itself
,
569 _res
= Py_BuildValue("O&",
574 static PyObject
*CmpObj_UncaptureComponent(_self
, _args
)
575 ComponentObject
*_self
;
578 PyObject
*_res
= NULL
;
580 if (!PyArg_ParseTuple(_args
, ""))
582 _err
= UncaptureComponent(_self
->ob_itself
);
583 if (_err
!= noErr
) return PyMac_Error(_err
);
589 static PyObject
*CmpObj_GetComponentIconSuite(_self
, _args
)
590 ComponentObject
*_self
;
593 PyObject
*_res
= NULL
;
596 if (!PyArg_ParseTuple(_args
, ""))
598 _err
= GetComponentIconSuite(_self
->ob_itself
,
600 if (_err
!= noErr
) return PyMac_Error(_err
);
601 _res
= Py_BuildValue("O&",
602 ResObj_New
, iconSuite
);
606 static PyMethodDef CmpObj_methods
[] = {
607 {"UnregisterComponent", (PyCFunction
)CmpObj_UnregisterComponent
, 1,
609 {"GetComponentInfo", (PyCFunction
)CmpObj_GetComponentInfo
, 1,
610 "(Handle componentName, Handle componentInfo, Handle componentIcon) -> (ComponentDescription cd)"},
611 {"OpenComponent", (PyCFunction
)CmpObj_OpenComponent
, 1,
612 "() -> (ComponentInstance _rv)"},
613 {"GetComponentRefcon", (PyCFunction
)CmpObj_GetComponentRefcon
, 1,
615 {"SetComponentRefcon", (PyCFunction
)CmpObj_SetComponentRefcon
, 1,
616 "(long theRefcon) -> None"},
617 {"OpenComponentResFile", (PyCFunction
)CmpObj_OpenComponentResFile
, 1,
618 "() -> (short _rv)"},
619 {"GetComponentResource", (PyCFunction
)CmpObj_GetComponentResource
, 1,
620 "(OSType resType, short resID) -> (Handle theResource)"},
621 {"GetComponentIndString", (PyCFunction
)CmpObj_GetComponentIndString
, 1,
622 "(Str255 theString, short strListID, short index) -> None"},
623 {"ResolveComponentAlias", (PyCFunction
)CmpObj_ResolveComponentAlias
, 1,
624 "() -> (Component _rv)"},
625 {"CountComponentInstances", (PyCFunction
)CmpObj_CountComponentInstances
, 1,
627 {"SetDefaultComponent", (PyCFunction
)CmpObj_SetDefaultComponent
, 1,
628 "(short flags) -> None"},
629 {"CaptureComponent", (PyCFunction
)CmpObj_CaptureComponent
, 1,
630 "(Component capturingComponent) -> (Component _rv)"},
631 {"UncaptureComponent", (PyCFunction
)CmpObj_UncaptureComponent
, 1,
633 {"GetComponentIconSuite", (PyCFunction
)CmpObj_GetComponentIconSuite
, 1,
634 "() -> (Handle iconSuite)"},
638 PyMethodChain CmpObj_chain
= { CmpObj_methods
, NULL
};
640 static PyObject
*CmpObj_getattr(self
, name
)
641 ComponentObject
*self
;
644 return Py_FindMethodInChain(&CmpObj_chain
, (PyObject
*)self
, name
);
647 #define CmpObj_setattr NULL
649 #define CmpObj_compare NULL
651 #define CmpObj_repr NULL
653 #define CmpObj_hash NULL
655 PyTypeObject Component_Type
= {
656 PyObject_HEAD_INIT(&PyType_Type
)
658 "Component", /*tp_name*/
659 sizeof(ComponentObject
), /*tp_basicsize*/
662 (destructor
) CmpObj_dealloc
, /*tp_dealloc*/
664 (getattrfunc
) CmpObj_getattr
, /*tp_getattr*/
665 (setattrfunc
) CmpObj_setattr
, /*tp_setattr*/
666 (cmpfunc
) CmpObj_compare
, /*tp_compare*/
667 (reprfunc
) CmpObj_repr
, /*tp_repr*/
668 (PyNumberMethods
*)0, /* tp_as_number */
669 (PySequenceMethods
*)0, /* tp_as_sequence */
670 (PyMappingMethods
*)0, /* tp_as_mapping */
671 (hashfunc
) CmpObj_hash
, /*tp_hash*/
674 /* ------------------- End object type Component -------------------- */
677 static PyObject
*Cm_RegisterComponentResource(_self
, _args
)
681 PyObject
*_res
= NULL
;
683 ComponentResourceHandle cr
;
685 if (!PyArg_ParseTuple(_args
, "O&h",
689 _rv
= RegisterComponentResource(cr
,
691 _res
= Py_BuildValue("O&",
696 static PyObject
*Cm_FindNextComponent(_self
, _args
)
700 PyObject
*_res
= NULL
;
702 Component aComponent
;
703 ComponentDescription looking
;
704 if (!PyArg_ParseTuple(_args
, "O&O&",
705 CmpObj_Convert
, &aComponent
,
706 CmpDesc_Convert
, &looking
))
708 _rv
= FindNextComponent(aComponent
,
710 _res
= Py_BuildValue("O&",
715 static PyObject
*Cm_CountComponents(_self
, _args
)
719 PyObject
*_res
= NULL
;
721 ComponentDescription looking
;
722 if (!PyArg_ParseTuple(_args
, "O&",
723 CmpDesc_Convert
, &looking
))
725 _rv
= CountComponents(&looking
);
726 _res
= Py_BuildValue("l",
731 static PyObject
*Cm_GetComponentListModSeed(_self
, _args
)
735 PyObject
*_res
= NULL
;
737 if (!PyArg_ParseTuple(_args
, ""))
739 _rv
= GetComponentListModSeed();
740 _res
= Py_BuildValue("l",
745 static PyObject
*Cm_CloseComponentResFile(_self
, _args
)
749 PyObject
*_res
= NULL
;
752 if (!PyArg_ParseTuple(_args
, "h",
755 _err
= CloseComponentResFile(refnum
);
756 if (_err
!= noErr
) return PyMac_Error(_err
);
762 static PyObject
*Cm_OpenDefaultComponent(_self
, _args
)
766 PyObject
*_res
= NULL
;
767 ComponentInstance _rv
;
768 OSType componentType
;
769 OSType componentSubType
;
770 if (!PyArg_ParseTuple(_args
, "O&O&",
771 PyMac_GetOSType
, &componentType
,
772 PyMac_GetOSType
, &componentSubType
))
774 _rv
= OpenDefaultComponent(componentType
,
776 _res
= Py_BuildValue("O&",
777 CmpInstObj_New
, _rv
);
781 static PyObject
*Cm_RegisterComponentResourceFile(_self
, _args
)
785 PyObject
*_res
= NULL
;
789 if (!PyArg_ParseTuple(_args
, "hh",
793 _rv
= RegisterComponentResourceFile(resRefNum
,
795 _res
= Py_BuildValue("l",
800 static PyMethodDef Cm_methods
[] = {
801 {"RegisterComponentResource", (PyCFunction
)Cm_RegisterComponentResource
, 1,
802 "(ComponentResourceHandle cr, short global) -> (Component _rv)"},
803 {"FindNextComponent", (PyCFunction
)Cm_FindNextComponent
, 1,
804 "(Component aComponent, ComponentDescription looking) -> (Component _rv)"},
805 {"CountComponents", (PyCFunction
)Cm_CountComponents
, 1,
806 "(ComponentDescription looking) -> (long _rv)"},
807 {"GetComponentListModSeed", (PyCFunction
)Cm_GetComponentListModSeed
, 1,
809 {"CloseComponentResFile", (PyCFunction
)Cm_CloseComponentResFile
, 1,
810 "(short refnum) -> None"},
811 {"OpenDefaultComponent", (PyCFunction
)Cm_OpenDefaultComponent
, 1,
812 "(OSType componentType, OSType componentSubType) -> (ComponentInstance _rv)"},
813 {"RegisterComponentResourceFile", (PyCFunction
)Cm_RegisterComponentResourceFile
, 1,
814 "(short resRefNum, short global) -> (long _rv)"},
829 m
= Py_InitModule("Cm", Cm_methods
);
830 d
= PyModule_GetDict(m
);
831 Cm_Error
= PyMac_GetOSErrException();
832 if (Cm_Error
== NULL
||
833 PyDict_SetItemString(d
, "Error", Cm_Error
) != 0)
835 ComponentInstance_Type
.ob_type
= &PyType_Type
;
836 Py_INCREF(&ComponentInstance_Type
);
837 if (PyDict_SetItemString(d
, "ComponentInstanceType", (PyObject
*)&ComponentInstance_Type
) != 0)
838 Py_FatalError("can't initialize ComponentInstanceType");
839 Component_Type
.ob_type
= &PyType_Type
;
840 Py_INCREF(&Component_Type
);
841 if (PyDict_SetItemString(d
, "ComponentType", (PyObject
*)&Component_Type
) != 0)
842 Py_FatalError("can't initialize ComponentType");
845 /* ========================= End module Cm ========================== */