2 /* =========================== Module Cm ============================ */
8 #define SystemSevenOrLater 1
16 extern PyObject
*ResObj_New(Handle
);
17 extern int ResObj_Convert(PyObject
*, Handle
*);
18 extern PyObject
*OptResObj_New(Handle
);
19 extern int OptResObj_Convert(PyObject
*, Handle
*);
21 extern PyObject
*WinObj_New(WindowPtr
);
22 extern int WinObj_Convert(PyObject
*, WindowPtr
*);
23 extern PyTypeObject Window_Type
;
24 #define WinObj_Check(x) ((x)->ob_type == &Window_Type)
26 extern PyObject
*DlgObj_New(DialogPtr
);
27 extern int DlgObj_Convert(PyObject
*, DialogPtr
*);
28 extern PyTypeObject Dialog_Type
;
29 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
31 extern PyObject
*MenuObj_New(MenuHandle
);
32 extern int MenuObj_Convert(PyObject
*, MenuHandle
*);
34 extern PyObject
*CtlObj_New(ControlHandle
);
35 extern int CtlObj_Convert(PyObject
*, ControlHandle
*);
37 extern PyObject
*GrafObj_New(GrafPtr
);
38 extern int GrafObj_Convert(PyObject
*, GrafPtr
*);
40 extern PyObject
*BMObj_New(BitMapPtr
);
41 extern int BMObj_Convert(PyObject
*, BitMapPtr
*);
43 extern PyObject
*WinObj_WhichWindow(WindowPtr
);
45 #include <Components.h>
48 ** Parse/generate ComponentDescriptor records
50 PyObject
*CmpDesc_New(itself
)
51 ComponentDescription
*itself
;
54 return Py_BuildValue("O&O&O&ll",
55 PyMac_BuildOSType
, itself
->componentType
,
56 PyMac_BuildOSType
, itself
->componentSubType
,
57 PyMac_BuildOSType
, itself
->componentManufacturer
,
58 itself
->componentFlags
, itself
->componentFlagsMask
);
61 CmpDesc_Convert(v
, p_itself
)
63 ComponentDescription
*p_itself
;
65 return PyArg_ParseTuple(v
, "O&O&O&ll",
66 PyMac_GetOSType
, &p_itself
->componentType
,
67 PyMac_GetOSType
, &p_itself
->componentSubType
,
68 PyMac_GetOSType
, &p_itself
->componentManufacturer
,
69 &p_itself
->componentFlags
, &p_itself
->componentFlagsMask
);
73 static PyObject
*Cm_Error
;
75 /* ----------------- Object type ComponentInstance ------------------ */
77 PyTypeObject ComponentInstance_Type
;
79 #define CmpInstObj_Check(x) ((x)->ob_type == &ComponentInstance_Type)
81 typedef struct ComponentInstanceObject
{
83 ComponentInstance ob_itself
;
84 } ComponentInstanceObject
;
86 PyObject
*CmpInstObj_New(itself
)
87 ComponentInstance itself
;
89 ComponentInstanceObject
*it
;
91 PyErr_SetString(Cm_Error
,"NULL ComponentInstance");
94 it
= PyObject_NEW(ComponentInstanceObject
, &ComponentInstance_Type
);
95 if (it
== NULL
) return NULL
;
96 it
->ob_itself
= itself
;
97 return (PyObject
*)it
;
99 CmpInstObj_Convert(v
, p_itself
)
101 ComponentInstance
*p_itself
;
103 if (!CmpInstObj_Check(v
))
105 PyErr_SetString(PyExc_TypeError
, "ComponentInstance required");
108 *p_itself
= ((ComponentInstanceObject
*)v
)->ob_itself
;
112 static void CmpInstObj_dealloc(self
)
113 ComponentInstanceObject
*self
;
115 /* Cleanup of self->ob_itself goes here */
119 static PyObject
*CmpInstObj_CloseComponent(_self
, _args
)
120 ComponentInstanceObject
*_self
;
123 PyObject
*_res
= NULL
;
125 if (!PyArg_ParseTuple(_args
, ""))
127 _err
= CloseComponent(_self
->ob_itself
);
128 if (_err
!= noErr
) return PyMac_Error(_err
);
134 static PyObject
*CmpInstObj_GetComponentInstanceError(_self
, _args
)
135 ComponentInstanceObject
*_self
;
138 PyObject
*_res
= NULL
;
140 if (!PyArg_ParseTuple(_args
, ""))
142 _err
= GetComponentInstanceError(_self
->ob_itself
);
143 if (_err
!= noErr
) return PyMac_Error(_err
);
149 static PyObject
*CmpInstObj_SetComponentInstanceError(_self
, _args
)
150 ComponentInstanceObject
*_self
;
153 PyObject
*_res
= NULL
;
155 if (!PyArg_ParseTuple(_args
, "h",
158 SetComponentInstanceError(_self
->ob_itself
,
165 static PyObject
*CmpInstObj_GetComponentInstanceStorage(_self
, _args
)
166 ComponentInstanceObject
*_self
;
169 PyObject
*_res
= NULL
;
171 if (!PyArg_ParseTuple(_args
, ""))
173 _rv
= GetComponentInstanceStorage(_self
->ob_itself
);
174 _res
= Py_BuildValue("O&",
179 static PyObject
*CmpInstObj_SetComponentInstanceStorage(_self
, _args
)
180 ComponentInstanceObject
*_self
;
183 PyObject
*_res
= NULL
;
185 if (!PyArg_ParseTuple(_args
, "O&",
186 ResObj_Convert
, &theStorage
))
188 SetComponentInstanceStorage(_self
->ob_itself
,
195 static PyObject
*CmpInstObj_GetComponentInstanceA5(_self
, _args
)
196 ComponentInstanceObject
*_self
;
199 PyObject
*_res
= NULL
;
201 if (!PyArg_ParseTuple(_args
, ""))
203 _rv
= GetComponentInstanceA5(_self
->ob_itself
);
204 _res
= Py_BuildValue("l",
209 static PyObject
*CmpInstObj_SetComponentInstanceA5(_self
, _args
)
210 ComponentInstanceObject
*_self
;
213 PyObject
*_res
= NULL
;
215 if (!PyArg_ParseTuple(_args
, "l",
218 SetComponentInstanceA5(_self
->ob_itself
,
225 static PyObject
*CmpInstObj_ComponentFunctionImplemented(_self
, _args
)
226 ComponentInstanceObject
*_self
;
229 PyObject
*_res
= NULL
;
232 if (!PyArg_ParseTuple(_args
, "h",
235 _rv
= ComponentFunctionImplemented(_self
->ob_itself
,
237 _res
= Py_BuildValue("l",
242 static PyObject
*CmpInstObj_GetComponentVersion(_self
, _args
)
243 ComponentInstanceObject
*_self
;
246 PyObject
*_res
= NULL
;
248 if (!PyArg_ParseTuple(_args
, ""))
250 _rv
= GetComponentVersion(_self
->ob_itself
);
251 _res
= Py_BuildValue("l",
256 static PyObject
*CmpInstObj_ComponentSetTarget(_self
, _args
)
257 ComponentInstanceObject
*_self
;
260 PyObject
*_res
= NULL
;
262 ComponentInstance target
;
263 if (!PyArg_ParseTuple(_args
, "O&",
264 CmpInstObj_Convert
, &target
))
266 _rv
= ComponentSetTarget(_self
->ob_itself
,
268 _res
= Py_BuildValue("l",
273 static PyMethodDef CmpInstObj_methods
[] = {
274 {"CloseComponent", (PyCFunction
)CmpInstObj_CloseComponent
, 1,
276 {"GetComponentInstanceError", (PyCFunction
)CmpInstObj_GetComponentInstanceError
, 1,
278 {"SetComponentInstanceError", (PyCFunction
)CmpInstObj_SetComponentInstanceError
, 1,
279 "(OSErr theError) -> None"},
280 {"GetComponentInstanceStorage", (PyCFunction
)CmpInstObj_GetComponentInstanceStorage
, 1,
281 "() -> (Handle _rv)"},
282 {"SetComponentInstanceStorage", (PyCFunction
)CmpInstObj_SetComponentInstanceStorage
, 1,
283 "(Handle theStorage) -> None"},
284 {"GetComponentInstanceA5", (PyCFunction
)CmpInstObj_GetComponentInstanceA5
, 1,
286 {"SetComponentInstanceA5", (PyCFunction
)CmpInstObj_SetComponentInstanceA5
, 1,
287 "(long theA5) -> None"},
288 {"ComponentFunctionImplemented", (PyCFunction
)CmpInstObj_ComponentFunctionImplemented
, 1,
289 "(short ftnNumber) -> (long _rv)"},
290 {"GetComponentVersion", (PyCFunction
)CmpInstObj_GetComponentVersion
, 1,
292 {"ComponentSetTarget", (PyCFunction
)CmpInstObj_ComponentSetTarget
, 1,
293 "(ComponentInstance target) -> (long _rv)"},
297 PyMethodChain CmpInstObj_chain
= { CmpInstObj_methods
, NULL
};
299 static PyObject
*CmpInstObj_getattr(self
, name
)
300 ComponentInstanceObject
*self
;
303 return Py_FindMethodInChain(&CmpInstObj_chain
, (PyObject
*)self
, name
);
306 #define CmpInstObj_setattr NULL
308 PyTypeObject ComponentInstance_Type
= {
309 PyObject_HEAD_INIT(&PyType_Type
)
311 "ComponentInstance", /*tp_name*/
312 sizeof(ComponentInstanceObject
), /*tp_basicsize*/
315 (destructor
) CmpInstObj_dealloc
, /*tp_dealloc*/
317 (getattrfunc
) CmpInstObj_getattr
, /*tp_getattr*/
318 (setattrfunc
) CmpInstObj_setattr
, /*tp_setattr*/
321 /* --------------- End object type ComponentInstance ---------------- */
324 /* --------------------- Object type Component ---------------------- */
326 PyTypeObject Component_Type
;
328 #define CmpObj_Check(x) ((x)->ob_type == &Component_Type)
330 typedef struct ComponentObject
{
335 PyObject
*CmpObj_New(itself
)
339 if (itself
== NULL
) {
340 /* XXXX Or should we return None? */
341 PyErr_SetString(Cm_Error
,"No such component");
344 it
= PyObject_NEW(ComponentObject
, &Component_Type
);
345 if (it
== NULL
) return NULL
;
346 it
->ob_itself
= itself
;
347 return (PyObject
*)it
;
349 CmpObj_Convert(v
, p_itself
)
353 if ( v
== Py_None
) {
357 if (!CmpObj_Check(v
))
359 PyErr_SetString(PyExc_TypeError
, "Component required");
362 *p_itself
= ((ComponentObject
*)v
)->ob_itself
;
366 static void CmpObj_dealloc(self
)
367 ComponentObject
*self
;
369 /* Cleanup of self->ob_itself goes here */
373 static PyObject
*CmpObj_UnregisterComponent(_self
, _args
)
374 ComponentObject
*_self
;
377 PyObject
*_res
= NULL
;
379 if (!PyArg_ParseTuple(_args
, ""))
381 _err
= UnregisterComponent(_self
->ob_itself
);
382 if (_err
!= noErr
) return PyMac_Error(_err
);
388 static PyObject
*CmpObj_GetComponentInfo(_self
, _args
)
389 ComponentObject
*_self
;
392 PyObject
*_res
= NULL
;
394 ComponentDescription cd
;
395 Handle componentName
;
396 Handle componentInfo
;
397 Handle componentIcon
;
398 if (!PyArg_ParseTuple(_args
, "O&O&O&",
399 ResObj_Convert
, &componentName
,
400 ResObj_Convert
, &componentInfo
,
401 ResObj_Convert
, &componentIcon
))
403 _err
= GetComponentInfo(_self
->ob_itself
,
408 if (_err
!= noErr
) return PyMac_Error(_err
);
409 _res
= Py_BuildValue("O&",
414 static PyObject
*CmpObj_OpenComponent(_self
, _args
)
415 ComponentObject
*_self
;
418 PyObject
*_res
= NULL
;
419 ComponentInstance _rv
;
420 if (!PyArg_ParseTuple(_args
, ""))
422 _rv
= OpenComponent(_self
->ob_itself
);
423 _res
= Py_BuildValue("O&",
424 CmpInstObj_New
, _rv
);
428 static PyObject
*CmpObj_GetComponentRefcon(_self
, _args
)
429 ComponentObject
*_self
;
432 PyObject
*_res
= NULL
;
434 if (!PyArg_ParseTuple(_args
, ""))
436 _rv
= GetComponentRefcon(_self
->ob_itself
);
437 _res
= Py_BuildValue("l",
442 static PyObject
*CmpObj_SetComponentRefcon(_self
, _args
)
443 ComponentObject
*_self
;
446 PyObject
*_res
= NULL
;
448 if (!PyArg_ParseTuple(_args
, "l",
451 SetComponentRefcon(_self
->ob_itself
,
458 static PyObject
*CmpObj_OpenComponentResFile(_self
, _args
)
459 ComponentObject
*_self
;
462 PyObject
*_res
= NULL
;
464 if (!PyArg_ParseTuple(_args
, ""))
466 _rv
= OpenComponentResFile(_self
->ob_itself
);
467 _res
= Py_BuildValue("h",
472 static PyObject
*CmpObj_GetComponentResource(_self
, _args
)
473 ComponentObject
*_self
;
476 PyObject
*_res
= NULL
;
481 if (!PyArg_ParseTuple(_args
, "O&h",
482 PyMac_GetOSType
, &resType
,
485 _err
= GetComponentResource(_self
->ob_itself
,
489 if (_err
!= noErr
) return PyMac_Error(_err
);
490 _res
= Py_BuildValue("O&",
491 ResObj_New
, theResource
);
495 static PyObject
*CmpObj_GetComponentIndString(_self
, _args
)
496 ComponentObject
*_self
;
499 PyObject
*_res
= NULL
;
504 if (!PyArg_ParseTuple(_args
, "O&hh",
505 PyMac_GetStr255
, theString
,
509 _err
= GetComponentIndString(_self
->ob_itself
,
513 if (_err
!= noErr
) return PyMac_Error(_err
);
519 static PyObject
*CmpObj_ResolveComponentAlias(_self
, _args
)
520 ComponentObject
*_self
;
523 PyObject
*_res
= NULL
;
525 if (!PyArg_ParseTuple(_args
, ""))
527 _rv
= ResolveComponentAlias(_self
->ob_itself
);
528 _res
= Py_BuildValue("O&",
533 static PyObject
*CmpObj_CountComponentInstances(_self
, _args
)
534 ComponentObject
*_self
;
537 PyObject
*_res
= NULL
;
539 if (!PyArg_ParseTuple(_args
, ""))
541 _rv
= CountComponentInstances(_self
->ob_itself
);
542 _res
= Py_BuildValue("l",
547 static PyObject
*CmpObj_SetDefaultComponent(_self
, _args
)
548 ComponentObject
*_self
;
551 PyObject
*_res
= NULL
;
554 if (!PyArg_ParseTuple(_args
, "h",
557 _err
= SetDefaultComponent(_self
->ob_itself
,
559 if (_err
!= noErr
) return PyMac_Error(_err
);
565 static PyObject
*CmpObj_CaptureComponent(_self
, _args
)
566 ComponentObject
*_self
;
569 PyObject
*_res
= NULL
;
571 Component capturingComponent
;
572 if (!PyArg_ParseTuple(_args
, "O&",
573 CmpObj_Convert
, &capturingComponent
))
575 _rv
= CaptureComponent(_self
->ob_itself
,
577 _res
= Py_BuildValue("O&",
582 static PyObject
*CmpObj_UncaptureComponent(_self
, _args
)
583 ComponentObject
*_self
;
586 PyObject
*_res
= NULL
;
588 if (!PyArg_ParseTuple(_args
, ""))
590 _err
= UncaptureComponent(_self
->ob_itself
);
591 if (_err
!= noErr
) return PyMac_Error(_err
);
597 static PyObject
*CmpObj_GetComponentIconSuite(_self
, _args
)
598 ComponentObject
*_self
;
601 PyObject
*_res
= NULL
;
604 if (!PyArg_ParseTuple(_args
, ""))
606 _err
= GetComponentIconSuite(_self
->ob_itself
,
608 if (_err
!= noErr
) return PyMac_Error(_err
);
609 _res
= Py_BuildValue("O&",
610 ResObj_New
, iconSuite
);
614 static PyMethodDef CmpObj_methods
[] = {
615 {"UnregisterComponent", (PyCFunction
)CmpObj_UnregisterComponent
, 1,
617 {"GetComponentInfo", (PyCFunction
)CmpObj_GetComponentInfo
, 1,
618 "(Handle componentName, Handle componentInfo, Handle componentIcon) -> (ComponentDescription cd)"},
619 {"OpenComponent", (PyCFunction
)CmpObj_OpenComponent
, 1,
620 "() -> (ComponentInstance _rv)"},
621 {"GetComponentRefcon", (PyCFunction
)CmpObj_GetComponentRefcon
, 1,
623 {"SetComponentRefcon", (PyCFunction
)CmpObj_SetComponentRefcon
, 1,
624 "(long theRefcon) -> None"},
625 {"OpenComponentResFile", (PyCFunction
)CmpObj_OpenComponentResFile
, 1,
626 "() -> (short _rv)"},
627 {"GetComponentResource", (PyCFunction
)CmpObj_GetComponentResource
, 1,
628 "(OSType resType, short resID) -> (Handle theResource)"},
629 {"GetComponentIndString", (PyCFunction
)CmpObj_GetComponentIndString
, 1,
630 "(Str255 theString, short strListID, short index) -> None"},
631 {"ResolveComponentAlias", (PyCFunction
)CmpObj_ResolveComponentAlias
, 1,
632 "() -> (Component _rv)"},
633 {"CountComponentInstances", (PyCFunction
)CmpObj_CountComponentInstances
, 1,
635 {"SetDefaultComponent", (PyCFunction
)CmpObj_SetDefaultComponent
, 1,
636 "(short flags) -> None"},
637 {"CaptureComponent", (PyCFunction
)CmpObj_CaptureComponent
, 1,
638 "(Component capturingComponent) -> (Component _rv)"},
639 {"UncaptureComponent", (PyCFunction
)CmpObj_UncaptureComponent
, 1,
641 {"GetComponentIconSuite", (PyCFunction
)CmpObj_GetComponentIconSuite
, 1,
642 "() -> (Handle iconSuite)"},
646 PyMethodChain CmpObj_chain
= { CmpObj_methods
, NULL
};
648 static PyObject
*CmpObj_getattr(self
, name
)
649 ComponentObject
*self
;
652 return Py_FindMethodInChain(&CmpObj_chain
, (PyObject
*)self
, name
);
655 #define CmpObj_setattr NULL
657 PyTypeObject Component_Type
= {
658 PyObject_HEAD_INIT(&PyType_Type
)
660 "Component", /*tp_name*/
661 sizeof(ComponentObject
), /*tp_basicsize*/
664 (destructor
) CmpObj_dealloc
, /*tp_dealloc*/
666 (getattrfunc
) CmpObj_getattr
, /*tp_getattr*/
667 (setattrfunc
) CmpObj_setattr
, /*tp_setattr*/
670 /* ------------------- End object type Component -------------------- */
673 static PyObject
*Cm_RegisterComponentResource(_self
, _args
)
677 PyObject
*_res
= NULL
;
679 ComponentResourceHandle cr
;
681 if (!PyArg_ParseTuple(_args
, "O&h",
685 _rv
= RegisterComponentResource(cr
,
687 _res
= Py_BuildValue("O&",
692 static PyObject
*Cm_FindNextComponent(_self
, _args
)
696 PyObject
*_res
= NULL
;
698 Component aComponent
;
699 ComponentDescription looking
;
700 if (!PyArg_ParseTuple(_args
, "O&O&",
701 CmpObj_Convert
, &aComponent
,
702 CmpDesc_Convert
, &looking
))
704 _rv
= FindNextComponent(aComponent
,
706 _res
= Py_BuildValue("O&",
711 static PyObject
*Cm_CountComponents(_self
, _args
)
715 PyObject
*_res
= NULL
;
717 ComponentDescription looking
;
718 if (!PyArg_ParseTuple(_args
, "O&",
719 CmpDesc_Convert
, &looking
))
721 _rv
= CountComponents(&looking
);
722 _res
= Py_BuildValue("l",
727 static PyObject
*Cm_GetComponentListModSeed(_self
, _args
)
731 PyObject
*_res
= NULL
;
733 if (!PyArg_ParseTuple(_args
, ""))
735 _rv
= GetComponentListModSeed();
736 _res
= Py_BuildValue("l",
741 static PyObject
*Cm_CloseComponentResFile(_self
, _args
)
745 PyObject
*_res
= NULL
;
748 if (!PyArg_ParseTuple(_args
, "h",
751 _err
= CloseComponentResFile(refnum
);
752 if (_err
!= noErr
) return PyMac_Error(_err
);
758 static PyObject
*Cm_OpenDefaultComponent(_self
, _args
)
762 PyObject
*_res
= NULL
;
763 ComponentInstance _rv
;
764 OSType componentType
;
765 OSType componentSubType
;
766 if (!PyArg_ParseTuple(_args
, "O&O&",
767 PyMac_GetOSType
, &componentType
,
768 PyMac_GetOSType
, &componentSubType
))
770 _rv
= OpenDefaultComponent(componentType
,
772 _res
= Py_BuildValue("O&",
773 CmpInstObj_New
, _rv
);
777 static PyObject
*Cm_RegisterComponentResourceFile(_self
, _args
)
781 PyObject
*_res
= NULL
;
785 if (!PyArg_ParseTuple(_args
, "hh",
789 _rv
= RegisterComponentResourceFile(resRefNum
,
791 _res
= Py_BuildValue("l",
796 static PyMethodDef Cm_methods
[] = {
797 {"RegisterComponentResource", (PyCFunction
)Cm_RegisterComponentResource
, 1,
798 "(ComponentResourceHandle cr, short global) -> (Component _rv)"},
799 {"FindNextComponent", (PyCFunction
)Cm_FindNextComponent
, 1,
800 "(Component aComponent, ComponentDescription looking) -> (Component _rv)"},
801 {"CountComponents", (PyCFunction
)Cm_CountComponents
, 1,
802 "(ComponentDescription looking) -> (long _rv)"},
803 {"GetComponentListModSeed", (PyCFunction
)Cm_GetComponentListModSeed
, 1,
805 {"CloseComponentResFile", (PyCFunction
)Cm_CloseComponentResFile
, 1,
806 "(short refnum) -> None"},
807 {"OpenDefaultComponent", (PyCFunction
)Cm_OpenDefaultComponent
, 1,
808 "(OSType componentType, OSType componentSubType) -> (ComponentInstance _rv)"},
809 {"RegisterComponentResourceFile", (PyCFunction
)Cm_RegisterComponentResourceFile
, 1,
810 "(short resRefNum, short global) -> (long _rv)"},
825 m
= Py_InitModule("Cm", Cm_methods
);
826 d
= PyModule_GetDict(m
);
827 Cm_Error
= PyMac_GetOSErrException();
828 if (Cm_Error
== NULL
||
829 PyDict_SetItemString(d
, "Error", Cm_Error
) != 0)
830 Py_FatalError("can't initialize Cm.Error");
831 ComponentInstance_Type
.ob_type
= &PyType_Type
;
832 Py_INCREF(&ComponentInstance_Type
);
833 if (PyDict_SetItemString(d
, "ComponentInstanceType", (PyObject
*)&ComponentInstance_Type
) != 0)
834 Py_FatalError("can't initialize ComponentInstanceType");
835 Component_Type
.ob_type
= &PyType_Type
;
836 Py_INCREF(&Component_Type
);
837 if (PyDict_SetItemString(d
, "ComponentType", (PyObject
*)&Component_Type
) != 0)
838 Py_FatalError("can't initialize ComponentType");
841 /* ========================= End module Cm ========================== */