blob: 4eb0be313e1e7399225dca7049bbda10b9844228 [file] [log] [blame]
Jack Jansenb9968561995-11-30 15:03:09 +00001
2/* =========================== Module Cm ============================ */
3
4#include "Python.h"
5
6
7
8#define SystemSevenOrLater 1
9
10#include "macglue.h"
11#include <Memory.h>
12#include <Dialogs.h>
13#include <Menus.h>
14#include <Controls.h>
15
16extern PyObject *ResObj_New(Handle);
Jack Jansenb9968561995-11-30 15:03:09 +000017extern int ResObj_Convert(PyObject *, Handle *);
Jack Jansen425e9eb1995-12-12 15:02:03 +000018extern PyObject *OptResObj_New(Handle);
19extern int OptResObj_Convert(PyObject *, Handle *);
Jack Jansenb9968561995-11-30 15:03:09 +000020
21extern PyObject *WinObj_New(WindowPtr);
22extern int WinObj_Convert(PyObject *, WindowPtr *);
23extern PyTypeObject Window_Type;
24#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
25
26extern PyObject *DlgObj_New(DialogPtr);
27extern int DlgObj_Convert(PyObject *, DialogPtr *);
28extern PyTypeObject Dialog_Type;
29#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
30
31extern PyObject *MenuObj_New(MenuHandle);
32extern int MenuObj_Convert(PyObject *, MenuHandle *);
33
34extern PyObject *CtlObj_New(ControlHandle);
35extern int CtlObj_Convert(PyObject *, ControlHandle *);
36
37extern PyObject *GrafObj_New(GrafPtr);
38extern int GrafObj_Convert(PyObject *, GrafPtr *);
39
40extern PyObject *BMObj_New(BitMapPtr);
41extern int BMObj_Convert(PyObject *, BitMapPtr *);
42
Jack Jansenb9968561995-11-30 15:03:09 +000043extern PyObject *WinObj_WhichWindow(WindowPtr);
44
45#include <Components.h>
46
47/*
48** Parse/generate ComponentDescriptor records
49*/
50PyObject *CmpDesc_New(itself)
51 ComponentDescription *itself;
52{
53
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);
59}
60
61CmpDesc_Convert(v, p_itself)
62 PyObject *v;
63 ComponentDescription *p_itself;
64{
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);
70}
71
72
73static PyObject *Cm_Error;
74
75/* ----------------- Object type ComponentInstance ------------------ */
76
77PyTypeObject ComponentInstance_Type;
78
79#define CmpInstObj_Check(x) ((x)->ob_type == &ComponentInstance_Type)
80
81typedef struct ComponentInstanceObject {
82 PyObject_HEAD
83 ComponentInstance ob_itself;
84} ComponentInstanceObject;
85
86PyObject *CmpInstObj_New(itself)
87 ComponentInstance itself;
88{
89 ComponentInstanceObject *it;
90 if (itself == NULL) {
91 PyErr_SetString(Cm_Error,"NULL ComponentInstance");
92 return NULL;
93 }
94 it = PyObject_NEW(ComponentInstanceObject, &ComponentInstance_Type);
95 if (it == NULL) return NULL;
96 it->ob_itself = itself;
97 return (PyObject *)it;
98}
99CmpInstObj_Convert(v, p_itself)
100 PyObject *v;
101 ComponentInstance *p_itself;
102{
103 if (!CmpInstObj_Check(v))
104 {
105 PyErr_SetString(PyExc_TypeError, "ComponentInstance required");
106 return 0;
107 }
108 *p_itself = ((ComponentInstanceObject *)v)->ob_itself;
109 return 1;
110}
111
112static void CmpInstObj_dealloc(self)
113 ComponentInstanceObject *self;
114{
115 /* Cleanup of self->ob_itself goes here */
116 PyMem_DEL(self);
117}
118
119static PyObject *CmpInstObj_CloseComponent(_self, _args)
120 ComponentInstanceObject *_self;
121 PyObject *_args;
122{
123 PyObject *_res = NULL;
124 OSErr _err;
125 if (!PyArg_ParseTuple(_args, ""))
126 return NULL;
127 _err = CloseComponent(_self->ob_itself);
128 if (_err != noErr) return PyMac_Error(_err);
129 Py_INCREF(Py_None);
130 _res = Py_None;
131 return _res;
132}
133
134static PyObject *CmpInstObj_GetComponentInstanceError(_self, _args)
135 ComponentInstanceObject *_self;
136 PyObject *_args;
137{
138 PyObject *_res = NULL;
139 OSErr _err;
140 if (!PyArg_ParseTuple(_args, ""))
141 return NULL;
142 _err = GetComponentInstanceError(_self->ob_itself);
143 if (_err != noErr) return PyMac_Error(_err);
144 Py_INCREF(Py_None);
145 _res = Py_None;
146 return _res;
147}
148
Jack Jansenb9968561995-11-30 15:03:09 +0000149static PyObject *CmpInstObj_SetComponentInstanceError(_self, _args)
150 ComponentInstanceObject *_self;
151 PyObject *_args;
152{
153 PyObject *_res = NULL;
154 OSErr theError;
155 if (!PyArg_ParseTuple(_args, "h",
156 &theError))
157 return NULL;
158 SetComponentInstanceError(_self->ob_itself,
159 theError);
160 Py_INCREF(Py_None);
161 _res = Py_None;
162 return _res;
163}
164
165static PyObject *CmpInstObj_GetComponentInstanceStorage(_self, _args)
166 ComponentInstanceObject *_self;
167 PyObject *_args;
168{
169 PyObject *_res = NULL;
170 Handle _rv;
171 if (!PyArg_ParseTuple(_args, ""))
172 return NULL;
173 _rv = GetComponentInstanceStorage(_self->ob_itself);
174 _res = Py_BuildValue("O&",
175 ResObj_New, _rv);
176 return _res;
177}
178
179static PyObject *CmpInstObj_SetComponentInstanceStorage(_self, _args)
180 ComponentInstanceObject *_self;
181 PyObject *_args;
182{
183 PyObject *_res = NULL;
184 Handle theStorage;
185 if (!PyArg_ParseTuple(_args, "O&",
186 ResObj_Convert, &theStorage))
187 return NULL;
188 SetComponentInstanceStorage(_self->ob_itself,
189 theStorage);
190 Py_INCREF(Py_None);
191 _res = Py_None;
192 return _res;
193}
194
195static PyObject *CmpInstObj_GetComponentInstanceA5(_self, _args)
196 ComponentInstanceObject *_self;
197 PyObject *_args;
198{
199 PyObject *_res = NULL;
200 long _rv;
201 if (!PyArg_ParseTuple(_args, ""))
202 return NULL;
203 _rv = GetComponentInstanceA5(_self->ob_itself);
204 _res = Py_BuildValue("l",
205 _rv);
206 return _res;
207}
208
209static PyObject *CmpInstObj_SetComponentInstanceA5(_self, _args)
210 ComponentInstanceObject *_self;
211 PyObject *_args;
212{
213 PyObject *_res = NULL;
214 long theA5;
215 if (!PyArg_ParseTuple(_args, "l",
216 &theA5))
217 return NULL;
218 SetComponentInstanceA5(_self->ob_itself,
219 theA5);
220 Py_INCREF(Py_None);
221 _res = Py_None;
222 return _res;
223}
224
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000225static PyObject *CmpInstObj_ComponentFunctionImplemented(_self, _args)
226 ComponentInstanceObject *_self;
227 PyObject *_args;
228{
229 PyObject *_res = NULL;
230 long _rv;
231 short ftnNumber;
232 if (!PyArg_ParseTuple(_args, "h",
233 &ftnNumber))
234 return NULL;
235 _rv = ComponentFunctionImplemented(_self->ob_itself,
236 ftnNumber);
237 _res = Py_BuildValue("l",
238 _rv);
239 return _res;
240}
241
242static PyObject *CmpInstObj_GetComponentVersion(_self, _args)
243 ComponentInstanceObject *_self;
244 PyObject *_args;
245{
246 PyObject *_res = NULL;
247 long _rv;
248 if (!PyArg_ParseTuple(_args, ""))
249 return NULL;
250 _rv = GetComponentVersion(_self->ob_itself);
251 _res = Py_BuildValue("l",
252 _rv);
253 return _res;
254}
255
256static PyObject *CmpInstObj_ComponentSetTarget(_self, _args)
257 ComponentInstanceObject *_self;
258 PyObject *_args;
259{
260 PyObject *_res = NULL;
261 long _rv;
262 ComponentInstance target;
263 if (!PyArg_ParseTuple(_args, "O&",
264 CmpInstObj_Convert, &target))
265 return NULL;
266 _rv = ComponentSetTarget(_self->ob_itself,
267 target);
268 _res = Py_BuildValue("l",
269 _rv);
270 return _res;
271}
272
Jack Jansenb9968561995-11-30 15:03:09 +0000273static PyMethodDef CmpInstObj_methods[] = {
274 {"CloseComponent", (PyCFunction)CmpInstObj_CloseComponent, 1,
275 "() -> None"},
276 {"GetComponentInstanceError", (PyCFunction)CmpInstObj_GetComponentInstanceError, 1,
277 "() -> None"},
Jack Jansenb9968561995-11-30 15:03:09 +0000278 {"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,
285 "() -> (long _rv)"},
286 {"SetComponentInstanceA5", (PyCFunction)CmpInstObj_SetComponentInstanceA5, 1,
287 "(long theA5) -> None"},
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000288 {"ComponentFunctionImplemented", (PyCFunction)CmpInstObj_ComponentFunctionImplemented, 1,
289 "(short ftnNumber) -> (long _rv)"},
290 {"GetComponentVersion", (PyCFunction)CmpInstObj_GetComponentVersion, 1,
291 "() -> (long _rv)"},
292 {"ComponentSetTarget", (PyCFunction)CmpInstObj_ComponentSetTarget, 1,
293 "(ComponentInstance target) -> (long _rv)"},
Jack Jansenb9968561995-11-30 15:03:09 +0000294 {NULL, NULL, 0}
295};
296
297PyMethodChain CmpInstObj_chain = { CmpInstObj_methods, NULL };
298
299static PyObject *CmpInstObj_getattr(self, name)
300 ComponentInstanceObject *self;
301 char *name;
302{
303 return Py_FindMethodInChain(&CmpInstObj_chain, (PyObject *)self, name);
304}
305
306#define CmpInstObj_setattr NULL
307
308PyTypeObject ComponentInstance_Type = {
309 PyObject_HEAD_INIT(&PyType_Type)
310 0, /*ob_size*/
311 "ComponentInstance", /*tp_name*/
312 sizeof(ComponentInstanceObject), /*tp_basicsize*/
313 0, /*tp_itemsize*/
314 /* methods */
315 (destructor) CmpInstObj_dealloc, /*tp_dealloc*/
316 0, /*tp_print*/
317 (getattrfunc) CmpInstObj_getattr, /*tp_getattr*/
318 (setattrfunc) CmpInstObj_setattr, /*tp_setattr*/
319};
320
321/* --------------- End object type ComponentInstance ---------------- */
322
323
324/* --------------------- Object type Component ---------------------- */
325
326PyTypeObject Component_Type;
327
328#define CmpObj_Check(x) ((x)->ob_type == &Component_Type)
329
330typedef struct ComponentObject {
331 PyObject_HEAD
332 Component ob_itself;
333} ComponentObject;
334
335PyObject *CmpObj_New(itself)
336 Component itself;
337{
338 ComponentObject *it;
339 if (itself == NULL) {
340 /* XXXX Or should we return None? */
341 PyErr_SetString(Cm_Error,"No such component");
342 return NULL;
343 }
344 it = PyObject_NEW(ComponentObject, &Component_Type);
345 if (it == NULL) return NULL;
346 it->ob_itself = itself;
347 return (PyObject *)it;
348}
349CmpObj_Convert(v, p_itself)
350 PyObject *v;
351 Component *p_itself;
352{
353 if ( v == Py_None ) {
354 *p_itself = 0;
355 return 1;
356 }
357 if (!CmpObj_Check(v))
358 {
359 PyErr_SetString(PyExc_TypeError, "Component required");
360 return 0;
361 }
362 *p_itself = ((ComponentObject *)v)->ob_itself;
363 return 1;
364}
365
366static void CmpObj_dealloc(self)
367 ComponentObject *self;
368{
369 /* Cleanup of self->ob_itself goes here */
370 PyMem_DEL(self);
371}
372
373static PyObject *CmpObj_UnregisterComponent(_self, _args)
374 ComponentObject *_self;
375 PyObject *_args;
376{
377 PyObject *_res = NULL;
378 OSErr _err;
379 if (!PyArg_ParseTuple(_args, ""))
380 return NULL;
381 _err = UnregisterComponent(_self->ob_itself);
382 if (_err != noErr) return PyMac_Error(_err);
383 Py_INCREF(Py_None);
384 _res = Py_None;
385 return _res;
386}
387
388static PyObject *CmpObj_GetComponentInfo(_self, _args)
389 ComponentObject *_self;
390 PyObject *_args;
391{
392 PyObject *_res = NULL;
393 OSErr _err;
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))
402 return NULL;
403 _err = GetComponentInfo(_self->ob_itself,
404 &cd,
405 componentName,
406 componentInfo,
407 componentIcon);
408 if (_err != noErr) return PyMac_Error(_err);
409 _res = Py_BuildValue("O&",
410 CmpDesc_New, &cd);
411 return _res;
412}
413
414static PyObject *CmpObj_OpenComponent(_self, _args)
415 ComponentObject *_self;
416 PyObject *_args;
417{
418 PyObject *_res = NULL;
419 ComponentInstance _rv;
420 if (!PyArg_ParseTuple(_args, ""))
421 return NULL;
422 _rv = OpenComponent(_self->ob_itself);
423 _res = Py_BuildValue("O&",
424 CmpInstObj_New, _rv);
425 return _res;
426}
427
428static PyObject *CmpObj_GetComponentRefcon(_self, _args)
429 ComponentObject *_self;
430 PyObject *_args;
431{
432 PyObject *_res = NULL;
433 long _rv;
434 if (!PyArg_ParseTuple(_args, ""))
435 return NULL;
436 _rv = GetComponentRefcon(_self->ob_itself);
437 _res = Py_BuildValue("l",
438 _rv);
439 return _res;
440}
441
442static PyObject *CmpObj_SetComponentRefcon(_self, _args)
443 ComponentObject *_self;
444 PyObject *_args;
445{
446 PyObject *_res = NULL;
447 long theRefcon;
448 if (!PyArg_ParseTuple(_args, "l",
449 &theRefcon))
450 return NULL;
451 SetComponentRefcon(_self->ob_itself,
452 theRefcon);
453 Py_INCREF(Py_None);
454 _res = Py_None;
455 return _res;
456}
457
458static PyObject *CmpObj_OpenComponentResFile(_self, _args)
459 ComponentObject *_self;
460 PyObject *_args;
461{
462 PyObject *_res = NULL;
463 short _rv;
464 if (!PyArg_ParseTuple(_args, ""))
465 return NULL;
466 _rv = OpenComponentResFile(_self->ob_itself);
467 _res = Py_BuildValue("h",
468 _rv);
469 return _res;
470}
471
Jack Jansen1c4e6141998-04-21 15:23:55 +0000472static PyObject *CmpObj_GetComponentResource(_self, _args)
473 ComponentObject *_self;
474 PyObject *_args;
475{
476 PyObject *_res = NULL;
477 OSErr _err;
478 OSType resType;
479 short resID;
480 Handle theResource;
481 if (!PyArg_ParseTuple(_args, "O&h",
482 PyMac_GetOSType, &resType,
483 &resID))
484 return NULL;
485 _err = GetComponentResource(_self->ob_itself,
486 resType,
487 resID,
488 &theResource);
489 if (_err != noErr) return PyMac_Error(_err);
490 _res = Py_BuildValue("O&",
491 ResObj_New, theResource);
492 return _res;
493}
494
495static PyObject *CmpObj_GetComponentIndString(_self, _args)
496 ComponentObject *_self;
497 PyObject *_args;
498{
499 PyObject *_res = NULL;
500 OSErr _err;
501 Str255 theString;
502 short strListID;
503 short index;
504 if (!PyArg_ParseTuple(_args, "O&hh",
505 PyMac_GetStr255, theString,
506 &strListID,
507 &index))
508 return NULL;
509 _err = GetComponentIndString(_self->ob_itself,
510 theString,
511 strListID,
512 index);
513 if (_err != noErr) return PyMac_Error(_err);
514 Py_INCREF(Py_None);
515 _res = Py_None;
516 return _res;
517}
518
519static PyObject *CmpObj_ResolveComponentAlias(_self, _args)
520 ComponentObject *_self;
521 PyObject *_args;
522{
523 PyObject *_res = NULL;
524 Component _rv;
525 if (!PyArg_ParseTuple(_args, ""))
526 return NULL;
527 _rv = ResolveComponentAlias(_self->ob_itself);
528 _res = Py_BuildValue("O&",
529 CmpObj_New, _rv);
530 return _res;
531}
532
Jack Jansenb9968561995-11-30 15:03:09 +0000533static PyObject *CmpObj_CountComponentInstances(_self, _args)
534 ComponentObject *_self;
535 PyObject *_args;
536{
537 PyObject *_res = NULL;
538 long _rv;
539 if (!PyArg_ParseTuple(_args, ""))
540 return NULL;
541 _rv = CountComponentInstances(_self->ob_itself);
542 _res = Py_BuildValue("l",
543 _rv);
544 return _res;
545}
546
547static PyObject *CmpObj_SetDefaultComponent(_self, _args)
548 ComponentObject *_self;
549 PyObject *_args;
550{
551 PyObject *_res = NULL;
552 OSErr _err;
553 short flags;
554 if (!PyArg_ParseTuple(_args, "h",
555 &flags))
556 return NULL;
557 _err = SetDefaultComponent(_self->ob_itself,
558 flags);
559 if (_err != noErr) return PyMac_Error(_err);
560 Py_INCREF(Py_None);
561 _res = Py_None;
562 return _res;
563}
564
565static PyObject *CmpObj_CaptureComponent(_self, _args)
566 ComponentObject *_self;
567 PyObject *_args;
568{
569 PyObject *_res = NULL;
570 Component _rv;
571 Component capturingComponent;
572 if (!PyArg_ParseTuple(_args, "O&",
573 CmpObj_Convert, &capturingComponent))
574 return NULL;
575 _rv = CaptureComponent(_self->ob_itself,
576 capturingComponent);
577 _res = Py_BuildValue("O&",
578 CmpObj_New, _rv);
579 return _res;
580}
581
582static PyObject *CmpObj_UncaptureComponent(_self, _args)
583 ComponentObject *_self;
584 PyObject *_args;
585{
586 PyObject *_res = NULL;
587 OSErr _err;
588 if (!PyArg_ParseTuple(_args, ""))
589 return NULL;
590 _err = UncaptureComponent(_self->ob_itself);
591 if (_err != noErr) return PyMac_Error(_err);
592 Py_INCREF(Py_None);
593 _res = Py_None;
594 return _res;
595}
596
597static PyObject *CmpObj_GetComponentIconSuite(_self, _args)
598 ComponentObject *_self;
599 PyObject *_args;
600{
601 PyObject *_res = NULL;
602 OSErr _err;
603 Handle iconSuite;
604 if (!PyArg_ParseTuple(_args, ""))
605 return NULL;
606 _err = GetComponentIconSuite(_self->ob_itself,
607 &iconSuite);
608 if (_err != noErr) return PyMac_Error(_err);
609 _res = Py_BuildValue("O&",
610 ResObj_New, iconSuite);
611 return _res;
612}
613
614static PyMethodDef CmpObj_methods[] = {
615 {"UnregisterComponent", (PyCFunction)CmpObj_UnregisterComponent, 1,
616 "() -> None"},
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,
622 "() -> (long _rv)"},
623 {"SetComponentRefcon", (PyCFunction)CmpObj_SetComponentRefcon, 1,
624 "(long theRefcon) -> None"},
625 {"OpenComponentResFile", (PyCFunction)CmpObj_OpenComponentResFile, 1,
626 "() -> (short _rv)"},
Jack Jansen1c4e6141998-04-21 15:23:55 +0000627 {"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)"},
Jack Jansenb9968561995-11-30 15:03:09 +0000633 {"CountComponentInstances", (PyCFunction)CmpObj_CountComponentInstances, 1,
634 "() -> (long _rv)"},
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,
640 "() -> None"},
641 {"GetComponentIconSuite", (PyCFunction)CmpObj_GetComponentIconSuite, 1,
642 "() -> (Handle iconSuite)"},
643 {NULL, NULL, 0}
644};
645
646PyMethodChain CmpObj_chain = { CmpObj_methods, NULL };
647
648static PyObject *CmpObj_getattr(self, name)
649 ComponentObject *self;
650 char *name;
651{
652 return Py_FindMethodInChain(&CmpObj_chain, (PyObject *)self, name);
653}
654
655#define CmpObj_setattr NULL
656
657PyTypeObject Component_Type = {
658 PyObject_HEAD_INIT(&PyType_Type)
659 0, /*ob_size*/
660 "Component", /*tp_name*/
661 sizeof(ComponentObject), /*tp_basicsize*/
662 0, /*tp_itemsize*/
663 /* methods */
664 (destructor) CmpObj_dealloc, /*tp_dealloc*/
665 0, /*tp_print*/
666 (getattrfunc) CmpObj_getattr, /*tp_getattr*/
667 (setattrfunc) CmpObj_setattr, /*tp_setattr*/
668};
669
670/* ------------------- End object type Component -------------------- */
671
672
673static PyObject *Cm_RegisterComponentResource(_self, _args)
674 PyObject *_self;
675 PyObject *_args;
676{
677 PyObject *_res = NULL;
678 Component _rv;
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000679 ComponentResourceHandle cr;
Jack Jansenb9968561995-11-30 15:03:09 +0000680 short global;
681 if (!PyArg_ParseTuple(_args, "O&h",
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000682 ResObj_Convert, &cr,
Jack Jansenb9968561995-11-30 15:03:09 +0000683 &global))
684 return NULL;
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000685 _rv = RegisterComponentResource(cr,
Jack Jansenb9968561995-11-30 15:03:09 +0000686 global);
687 _res = Py_BuildValue("O&",
688 CmpObj_New, _rv);
689 return _res;
690}
691
692static PyObject *Cm_FindNextComponent(_self, _args)
693 PyObject *_self;
694 PyObject *_args;
695{
696 PyObject *_res = NULL;
697 Component _rv;
698 Component aComponent;
699 ComponentDescription looking;
700 if (!PyArg_ParseTuple(_args, "O&O&",
701 CmpObj_Convert, &aComponent,
702 CmpDesc_Convert, &looking))
703 return NULL;
704 _rv = FindNextComponent(aComponent,
705 &looking);
706 _res = Py_BuildValue("O&",
707 CmpObj_New, _rv);
708 return _res;
709}
710
711static PyObject *Cm_CountComponents(_self, _args)
712 PyObject *_self;
713 PyObject *_args;
714{
715 PyObject *_res = NULL;
716 long _rv;
717 ComponentDescription looking;
718 if (!PyArg_ParseTuple(_args, "O&",
719 CmpDesc_Convert, &looking))
720 return NULL;
721 _rv = CountComponents(&looking);
722 _res = Py_BuildValue("l",
723 _rv);
724 return _res;
725}
726
727static PyObject *Cm_GetComponentListModSeed(_self, _args)
728 PyObject *_self;
729 PyObject *_args;
730{
731 PyObject *_res = NULL;
732 long _rv;
733 if (!PyArg_ParseTuple(_args, ""))
734 return NULL;
735 _rv = GetComponentListModSeed();
736 _res = Py_BuildValue("l",
737 _rv);
738 return _res;
739}
740
741static PyObject *Cm_CloseComponentResFile(_self, _args)
742 PyObject *_self;
743 PyObject *_args;
744{
745 PyObject *_res = NULL;
746 OSErr _err;
747 short refnum;
748 if (!PyArg_ParseTuple(_args, "h",
749 &refnum))
750 return NULL;
751 _err = CloseComponentResFile(refnum);
752 if (_err != noErr) return PyMac_Error(_err);
753 Py_INCREF(Py_None);
754 _res = Py_None;
755 return _res;
756}
757
758static PyObject *Cm_OpenDefaultComponent(_self, _args)
759 PyObject *_self;
760 PyObject *_args;
761{
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))
769 return NULL;
770 _rv = OpenDefaultComponent(componentType,
771 componentSubType);
772 _res = Py_BuildValue("O&",
773 CmpInstObj_New, _rv);
774 return _res;
775}
776
777static PyObject *Cm_RegisterComponentResourceFile(_self, _args)
778 PyObject *_self;
779 PyObject *_args;
780{
781 PyObject *_res = NULL;
782 long _rv;
783 short resRefNum;
784 short global;
785 if (!PyArg_ParseTuple(_args, "hh",
786 &resRefNum,
787 &global))
788 return NULL;
789 _rv = RegisterComponentResourceFile(resRefNum,
790 global);
791 _res = Py_BuildValue("l",
792 _rv);
793 return _res;
794}
795
796static PyMethodDef Cm_methods[] = {
797 {"RegisterComponentResource", (PyCFunction)Cm_RegisterComponentResource, 1,
Jack Jansen4a8c54e1997-02-24 13:56:59 +0000798 "(ComponentResourceHandle cr, short global) -> (Component _rv)"},
Jack Jansenb9968561995-11-30 15:03:09 +0000799 {"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,
804 "() -> (long _rv)"},
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)"},
811 {NULL, NULL, 0}
812};
813
814
815
816
817void initCm()
818{
819 PyObject *m;
820 PyObject *d;
821
822
823
824
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");
Jack Jansena755e681997-09-20 17:40:22 +0000831 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");
Jack Jansenb9968561995-11-30 15:03:09 +0000839}
840
841/* ========================= End module Cm ========================== */
842