Oops -- Lib/Test should be Lib/test, of course!
[python/dscho.git] / Mac / Modules / dlg / Dlgmodule.c
blob75f8b285957a7caef5c391f4787804143b6ed909
2 /* =========================== Module Dlg =========================== */
4 #include "Python.h"
8 #define SystemSevenOrLater 1
10 #include "macglue.h"
11 #include <Memory.h>
12 #include <Dialogs.h>
13 #include <Menus.h>
14 #include <Controls.h>
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 <Dialogs.h>
47 #ifndef HAVE_UNIVERSAL_HEADERS
48 #define NewModalFilterProc(x) (x)
49 #endif
51 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
53 /* XXX Shouldn't this be a stack? */
54 static PyObject *Dlg_FilterProc_callback = NULL;
56 static PyObject *DlgObj_New(DialogPtr); /* Forward */
58 static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog,
59 EventRecord *event,
60 short *itemHit)
62 Boolean rv;
63 PyObject *args, *res;
64 PyObject *callback = Dlg_FilterProc_callback;
65 if (callback == NULL)
66 return 0; /* Default behavior */
67 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
68 args = Py_BuildValue("O&O&", WinObj_WhichWindow, dialog, PyMac_BuildEventRecord, event);
69 if (args == NULL)
70 res = NULL;
71 else {
72 res = PyEval_CallObject(callback, args);
73 Py_DECREF(args);
75 if (res == NULL) {
76 fprintf(stderr, "Exception in Dialog Filter\n");
77 PyErr_Print();
78 *itemHit = -1; /* Fake return item */
79 return 1; /* We handled it */
81 else {
82 Dlg_FilterProc_callback = callback;
83 if (PyInt_Check(res)) {
84 *itemHit = PyInt_AsLong(res);
85 rv = 1;
87 else
88 rv = PyObject_IsTrue(res);
90 Py_DECREF(res);
91 return rv;
94 static ModalFilterProcPtr
95 Dlg_PassFilterProc(PyObject *callback)
97 PyObject *tmp = Dlg_FilterProc_callback;
98 Dlg_FilterProc_callback = NULL;
99 if (callback == Py_None) {
100 Py_XDECREF(tmp);
101 return NULL;
103 Py_INCREF(callback);
104 Dlg_FilterProc_callback = callback;
105 Py_XDECREF(tmp);
106 return &Dlg_UnivFilterProc;
109 extern PyMethodChain WinObj_chain;
111 static PyObject *Dlg_Error;
113 /* ----------------------- Object type Dialog ----------------------- */
115 PyTypeObject Dialog_Type;
117 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
119 typedef struct DialogObject {
120 PyObject_HEAD
121 DialogPtr ob_itself;
122 } DialogObject;
124 PyObject *DlgObj_New(itself)
125 DialogPtr itself;
127 DialogObject *it;
128 if (itself == NULL) return Py_None;
129 it = PyObject_NEW(DialogObject, &Dialog_Type);
130 if (it == NULL) return NULL;
131 it->ob_itself = itself;
132 SetWRefCon(itself, (long)it);
133 return (PyObject *)it;
135 DlgObj_Convert(v, p_itself)
136 PyObject *v;
137 DialogPtr *p_itself;
139 if (v == Py_None) { *p_itself = NULL; return 1; }
140 if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
141 return 1; }
142 if (!DlgObj_Check(v))
144 PyErr_SetString(PyExc_TypeError, "Dialog required");
145 return 0;
147 *p_itself = ((DialogObject *)v)->ob_itself;
148 return 1;
151 static void DlgObj_dealloc(self)
152 DialogObject *self;
154 DisposeDialog(self->ob_itself);
155 PyMem_DEL(self);
158 static PyObject *DlgObj_DrawDialog(_self, _args)
159 DialogObject *_self;
160 PyObject *_args;
162 PyObject *_res = NULL;
163 if (!PyArg_ParseTuple(_args, ""))
164 return NULL;
165 DrawDialog(_self->ob_itself);
166 Py_INCREF(Py_None);
167 _res = Py_None;
168 return _res;
171 static PyObject *DlgObj_UpdateDialog(_self, _args)
172 DialogObject *_self;
173 PyObject *_args;
175 PyObject *_res = NULL;
176 RgnHandle updateRgn;
177 if (!PyArg_ParseTuple(_args, "O&",
178 ResObj_Convert, &updateRgn))
179 return NULL;
180 UpdateDialog(_self->ob_itself,
181 updateRgn);
182 Py_INCREF(Py_None);
183 _res = Py_None;
184 return _res;
187 static PyObject *DlgObj_HideDialogItem(_self, _args)
188 DialogObject *_self;
189 PyObject *_args;
191 PyObject *_res = NULL;
192 DialogItemIndex itemNo;
193 if (!PyArg_ParseTuple(_args, "h",
194 &itemNo))
195 return NULL;
196 HideDialogItem(_self->ob_itself,
197 itemNo);
198 Py_INCREF(Py_None);
199 _res = Py_None;
200 return _res;
203 static PyObject *DlgObj_ShowDialogItem(_self, _args)
204 DialogObject *_self;
205 PyObject *_args;
207 PyObject *_res = NULL;
208 DialogItemIndex itemNo;
209 if (!PyArg_ParseTuple(_args, "h",
210 &itemNo))
211 return NULL;
212 ShowDialogItem(_self->ob_itself,
213 itemNo);
214 Py_INCREF(Py_None);
215 _res = Py_None;
216 return _res;
219 static PyObject *DlgObj_FindDialogItem(_self, _args)
220 DialogObject *_self;
221 PyObject *_args;
223 PyObject *_res = NULL;
224 DialogItemIndexZeroBased _rv;
225 Point thePt;
226 if (!PyArg_ParseTuple(_args, "O&",
227 PyMac_GetPoint, &thePt))
228 return NULL;
229 _rv = FindDialogItem(_self->ob_itself,
230 thePt);
231 _res = Py_BuildValue("h",
232 _rv);
233 return _res;
236 static PyObject *DlgObj_DialogCut(_self, _args)
237 DialogObject *_self;
238 PyObject *_args;
240 PyObject *_res = NULL;
241 if (!PyArg_ParseTuple(_args, ""))
242 return NULL;
243 DialogCut(_self->ob_itself);
244 Py_INCREF(Py_None);
245 _res = Py_None;
246 return _res;
249 static PyObject *DlgObj_DialogPaste(_self, _args)
250 DialogObject *_self;
251 PyObject *_args;
253 PyObject *_res = NULL;
254 if (!PyArg_ParseTuple(_args, ""))
255 return NULL;
256 DialogPaste(_self->ob_itself);
257 Py_INCREF(Py_None);
258 _res = Py_None;
259 return _res;
262 static PyObject *DlgObj_DialogCopy(_self, _args)
263 DialogObject *_self;
264 PyObject *_args;
266 PyObject *_res = NULL;
267 if (!PyArg_ParseTuple(_args, ""))
268 return NULL;
269 DialogCopy(_self->ob_itself);
270 Py_INCREF(Py_None);
271 _res = Py_None;
272 return _res;
275 static PyObject *DlgObj_DialogDelete(_self, _args)
276 DialogObject *_self;
277 PyObject *_args;
279 PyObject *_res = NULL;
280 if (!PyArg_ParseTuple(_args, ""))
281 return NULL;
282 DialogDelete(_self->ob_itself);
283 Py_INCREF(Py_None);
284 _res = Py_None;
285 return _res;
288 static PyObject *DlgObj_GetDialogItem(_self, _args)
289 DialogObject *_self;
290 PyObject *_args;
292 PyObject *_res = NULL;
293 DialogItemIndex itemNo;
294 DialogItemType itemType;
295 Handle item;
296 Rect box;
297 if (!PyArg_ParseTuple(_args, "h",
298 &itemNo))
299 return NULL;
300 GetDialogItem(_self->ob_itself,
301 itemNo,
302 &itemType,
303 &item,
304 &box);
305 _res = Py_BuildValue("hO&O&",
306 itemType,
307 OptResObj_New, item,
308 PyMac_BuildRect, &box);
309 return _res;
312 static PyObject *DlgObj_SetDialogItem(_self, _args)
313 DialogObject *_self;
314 PyObject *_args;
316 PyObject *_res = NULL;
317 DialogItemIndex itemNo;
318 DialogItemType itemType;
319 Handle item;
320 Rect box;
321 if (!PyArg_ParseTuple(_args, "hhO&O&",
322 &itemNo,
323 &itemType,
324 ResObj_Convert, &item,
325 PyMac_GetRect, &box))
326 return NULL;
327 SetDialogItem(_self->ob_itself,
328 itemNo,
329 itemType,
330 item,
331 &box);
332 Py_INCREF(Py_None);
333 _res = Py_None;
334 return _res;
337 static PyObject *DlgObj_SelectDialogItemText(_self, _args)
338 DialogObject *_self;
339 PyObject *_args;
341 PyObject *_res = NULL;
342 DialogItemIndex itemNo;
343 SInt16 strtSel;
344 SInt16 endSel;
345 if (!PyArg_ParseTuple(_args, "hhh",
346 &itemNo,
347 &strtSel,
348 &endSel))
349 return NULL;
350 SelectDialogItemText(_self->ob_itself,
351 itemNo,
352 strtSel,
353 endSel);
354 Py_INCREF(Py_None);
355 _res = Py_None;
356 return _res;
359 static PyObject *DlgObj_AppendDITL(_self, _args)
360 DialogObject *_self;
361 PyObject *_args;
363 PyObject *_res = NULL;
364 Handle theHandle;
365 DITLMethod method;
366 if (!PyArg_ParseTuple(_args, "O&h",
367 ResObj_Convert, &theHandle,
368 &method))
369 return NULL;
370 AppendDITL(_self->ob_itself,
371 theHandle,
372 method);
373 Py_INCREF(Py_None);
374 _res = Py_None;
375 return _res;
378 static PyObject *DlgObj_CountDITL(_self, _args)
379 DialogObject *_self;
380 PyObject *_args;
382 PyObject *_res = NULL;
383 DialogItemIndex _rv;
384 if (!PyArg_ParseTuple(_args, ""))
385 return NULL;
386 _rv = CountDITL(_self->ob_itself);
387 _res = Py_BuildValue("h",
388 _rv);
389 return _res;
392 static PyObject *DlgObj_ShortenDITL(_self, _args)
393 DialogObject *_self;
394 PyObject *_args;
396 PyObject *_res = NULL;
397 DialogItemIndex numberItems;
398 if (!PyArg_ParseTuple(_args, "h",
399 &numberItems))
400 return NULL;
401 ShortenDITL(_self->ob_itself,
402 numberItems);
403 Py_INCREF(Py_None);
404 _res = Py_None;
405 return _res;
408 static PyObject *DlgObj_StdFilterProc(_self, _args)
409 DialogObject *_self;
410 PyObject *_args;
412 PyObject *_res = NULL;
413 Boolean _rv;
414 EventRecord event;
415 DialogItemIndex itemHit;
416 if (!PyArg_ParseTuple(_args, ""))
417 return NULL;
418 _rv = StdFilterProc(_self->ob_itself,
419 &event,
420 &itemHit);
421 _res = Py_BuildValue("bO&h",
422 _rv,
423 PyMac_BuildEventRecord, &event,
424 itemHit);
425 return _res;
428 static PyObject *DlgObj_SetDialogDefaultItem(_self, _args)
429 DialogObject *_self;
430 PyObject *_args;
432 PyObject *_res = NULL;
433 OSErr _err;
434 DialogItemIndex newItem;
435 if (!PyArg_ParseTuple(_args, "h",
436 &newItem))
437 return NULL;
438 _err = SetDialogDefaultItem(_self->ob_itself,
439 newItem);
440 if (_err != noErr) return PyMac_Error(_err);
441 Py_INCREF(Py_None);
442 _res = Py_None;
443 return _res;
446 static PyObject *DlgObj_SetDialogCancelItem(_self, _args)
447 DialogObject *_self;
448 PyObject *_args;
450 PyObject *_res = NULL;
451 OSErr _err;
452 DialogItemIndex newItem;
453 if (!PyArg_ParseTuple(_args, "h",
454 &newItem))
455 return NULL;
456 _err = SetDialogCancelItem(_self->ob_itself,
457 newItem);
458 if (_err != noErr) return PyMac_Error(_err);
459 Py_INCREF(Py_None);
460 _res = Py_None;
461 return _res;
464 static PyObject *DlgObj_SetDialogTracksCursor(_self, _args)
465 DialogObject *_self;
466 PyObject *_args;
468 PyObject *_res = NULL;
469 OSErr _err;
470 Boolean tracks;
471 if (!PyArg_ParseTuple(_args, "b",
472 &tracks))
473 return NULL;
474 _err = SetDialogTracksCursor(_self->ob_itself,
475 tracks);
476 if (_err != noErr) return PyMac_Error(_err);
477 Py_INCREF(Py_None);
478 _res = Py_None;
479 return _res;
482 static PyObject *DlgObj_AutoSizeDialog(_self, _args)
483 DialogObject *_self;
484 PyObject *_args;
486 PyObject *_res = NULL;
487 OSErr _err;
488 if (!PyArg_ParseTuple(_args, ""))
489 return NULL;
490 _err = AutoSizeDialog(_self->ob_itself);
491 if (_err != noErr) return PyMac_Error(_err);
492 Py_INCREF(Py_None);
493 _res = Py_None;
494 return _res;
497 static PyObject *DlgObj_GetDialogItemAsControl(_self, _args)
498 DialogObject *_self;
499 PyObject *_args;
501 PyObject *_res = NULL;
502 OSErr _err;
503 SInt16 inItemNo;
504 ControlHandle outControl;
505 if (!PyArg_ParseTuple(_args, "h",
506 &inItemNo))
507 return NULL;
508 _err = GetDialogItemAsControl(_self->ob_itself,
509 inItemNo,
510 &outControl);
511 if (_err != noErr) return PyMac_Error(_err);
512 _res = Py_BuildValue("O&",
513 CtlObj_New, outControl);
514 return _res;
517 static PyObject *DlgObj_MoveDialogItem(_self, _args)
518 DialogObject *_self;
519 PyObject *_args;
521 PyObject *_res = NULL;
522 OSErr _err;
523 SInt16 inItemNo;
524 SInt16 inHoriz;
525 SInt16 inVert;
526 if (!PyArg_ParseTuple(_args, "hhh",
527 &inItemNo,
528 &inHoriz,
529 &inVert))
530 return NULL;
531 _err = MoveDialogItem(_self->ob_itself,
532 inItemNo,
533 inHoriz,
534 inVert);
535 if (_err != noErr) return PyMac_Error(_err);
536 Py_INCREF(Py_None);
537 _res = Py_None;
538 return _res;
541 static PyObject *DlgObj_SizeDialogItem(_self, _args)
542 DialogObject *_self;
543 PyObject *_args;
545 PyObject *_res = NULL;
546 OSErr _err;
547 SInt16 inItemNo;
548 SInt16 inHeight;
549 SInt16 inWidth;
550 if (!PyArg_ParseTuple(_args, "hhh",
551 &inItemNo,
552 &inHeight,
553 &inWidth))
554 return NULL;
555 _err = SizeDialogItem(_self->ob_itself,
556 inItemNo,
557 inHeight,
558 inWidth);
559 if (_err != noErr) return PyMac_Error(_err);
560 Py_INCREF(Py_None);
561 _res = Py_None;
562 return _res;
565 static PyObject *DlgObj_GetDialogWindow(_self, _args)
566 DialogObject *_self;
567 PyObject *_args;
569 PyObject *_res = NULL;
570 DialogPtr _rv;
571 if (!PyArg_ParseTuple(_args, ""))
572 return NULL;
573 _rv = GetDialogWindow(_self->ob_itself);
574 _res = Py_BuildValue("O&",
575 WinObj_WhichWindow, _rv);
576 return _res;
579 static PyObject *DlgObj_GetDialogDefaultItem(_self, _args)
580 DialogObject *_self;
581 PyObject *_args;
583 PyObject *_res = NULL;
584 SInt16 _rv;
585 if (!PyArg_ParseTuple(_args, ""))
586 return NULL;
587 _rv = GetDialogDefaultItem(_self->ob_itself);
588 _res = Py_BuildValue("h",
589 _rv);
590 return _res;
593 static PyObject *DlgObj_GetDialogCancelItem(_self, _args)
594 DialogObject *_self;
595 PyObject *_args;
597 PyObject *_res = NULL;
598 SInt16 _rv;
599 if (!PyArg_ParseTuple(_args, ""))
600 return NULL;
601 _rv = GetDialogCancelItem(_self->ob_itself);
602 _res = Py_BuildValue("h",
603 _rv);
604 return _res;
607 static PyObject *DlgObj_GetDialogKeyboardFocusItem(_self, _args)
608 DialogObject *_self;
609 PyObject *_args;
611 PyObject *_res = NULL;
612 SInt16 _rv;
613 if (!PyArg_ParseTuple(_args, ""))
614 return NULL;
615 _rv = GetDialogKeyboardFocusItem(_self->ob_itself);
616 _res = Py_BuildValue("h",
617 _rv);
618 return _res;
621 static PyObject *DlgObj_SetGrafPortOfDialog(_self, _args)
622 DialogObject *_self;
623 PyObject *_args;
625 PyObject *_res = NULL;
626 if (!PyArg_ParseTuple(_args, ""))
627 return NULL;
628 SetGrafPortOfDialog(_self->ob_itself);
629 Py_INCREF(Py_None);
630 _res = Py_None;
631 return _res;
634 static PyMethodDef DlgObj_methods[] = {
635 {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
636 "() -> None"},
637 {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
638 "(RgnHandle updateRgn) -> None"},
639 {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
640 "(DialogItemIndex itemNo) -> None"},
641 {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
642 "(DialogItemIndex itemNo) -> None"},
643 {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
644 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
645 {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
646 "() -> None"},
647 {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
648 "() -> None"},
649 {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
650 "() -> None"},
651 {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
652 "() -> None"},
653 {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1,
654 "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"},
655 {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1,
656 "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"},
657 {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1,
658 "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"},
659 {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
660 "(Handle theHandle, DITLMethod method) -> None"},
661 {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
662 "() -> (DialogItemIndex _rv)"},
663 {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
664 "(DialogItemIndex numberItems) -> None"},
665 {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
666 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
667 {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
668 "(DialogItemIndex newItem) -> None"},
669 {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
670 "(DialogItemIndex newItem) -> None"},
671 {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
672 "(Boolean tracks) -> None"},
673 {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1,
674 "() -> None"},
675 {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1,
676 "(SInt16 inItemNo) -> (ControlHandle outControl)"},
677 {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1,
678 "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"},
679 {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1,
680 "(SInt16 inItemNo, SInt16 inHeight, SInt16 inWidth) -> None"},
681 {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
682 "() -> (DialogPtr _rv)"},
683 {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1,
684 "() -> (SInt16 _rv)"},
685 {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1,
686 "() -> (SInt16 _rv)"},
687 {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1,
688 "() -> (SInt16 _rv)"},
689 {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1,
690 "() -> None"},
691 {NULL, NULL, 0}
694 PyMethodChain DlgObj_chain = { DlgObj_methods, &WinObj_chain };
696 static PyObject *DlgObj_getattr(self, name)
697 DialogObject *self;
698 char *name;
700 return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name);
703 #define DlgObj_setattr NULL
705 PyTypeObject Dialog_Type = {
706 PyObject_HEAD_INIT(&PyType_Type)
707 0, /*ob_size*/
708 "Dialog", /*tp_name*/
709 sizeof(DialogObject), /*tp_basicsize*/
710 0, /*tp_itemsize*/
711 /* methods */
712 (destructor) DlgObj_dealloc, /*tp_dealloc*/
713 0, /*tp_print*/
714 (getattrfunc) DlgObj_getattr, /*tp_getattr*/
715 (setattrfunc) DlgObj_setattr, /*tp_setattr*/
718 /* --------------------- End object type Dialog --------------------- */
721 static PyObject *Dlg_NewDialog(_self, _args)
722 PyObject *_self;
723 PyObject *_args;
725 PyObject *_res = NULL;
726 DialogPtr _rv;
727 Rect boundsRect;
728 Str255 title;
729 Boolean visible;
730 SInt16 procID;
731 WindowPtr behind;
732 Boolean goAwayFlag;
733 SInt32 refCon;
734 Handle items;
735 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
736 PyMac_GetRect, &boundsRect,
737 PyMac_GetStr255, title,
738 &visible,
739 &procID,
740 WinObj_Convert, &behind,
741 &goAwayFlag,
742 &refCon,
743 ResObj_Convert, &items))
744 return NULL;
745 _rv = NewDialog((void *)0,
746 &boundsRect,
747 title,
748 visible,
749 procID,
750 behind,
751 goAwayFlag,
752 refCon,
753 items);
754 _res = Py_BuildValue("O&",
755 DlgObj_New, _rv);
756 return _res;
759 static PyObject *Dlg_GetNewDialog(_self, _args)
760 PyObject *_self;
761 PyObject *_args;
763 PyObject *_res = NULL;
764 DialogPtr _rv;
765 SInt16 dialogID;
766 WindowPtr behind;
767 if (!PyArg_ParseTuple(_args, "hO&",
768 &dialogID,
769 WinObj_Convert, &behind))
770 return NULL;
771 _rv = GetNewDialog(dialogID,
772 (void *)0,
773 behind);
774 _res = Py_BuildValue("O&",
775 DlgObj_New, _rv);
776 return _res;
779 static PyObject *Dlg_NewColorDialog(_self, _args)
780 PyObject *_self;
781 PyObject *_args;
783 PyObject *_res = NULL;
784 DialogPtr _rv;
785 Rect boundsRect;
786 Str255 title;
787 Boolean visible;
788 SInt16 procID;
789 WindowPtr behind;
790 Boolean goAwayFlag;
791 SInt32 refCon;
792 Handle items;
793 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
794 PyMac_GetRect, &boundsRect,
795 PyMac_GetStr255, title,
796 &visible,
797 &procID,
798 WinObj_Convert, &behind,
799 &goAwayFlag,
800 &refCon,
801 ResObj_Convert, &items))
802 return NULL;
803 _rv = NewColorDialog((void *)0,
804 &boundsRect,
805 title,
806 visible,
807 procID,
808 behind,
809 goAwayFlag,
810 refCon,
811 items);
812 _res = Py_BuildValue("O&",
813 DlgObj_New, _rv);
814 return _res;
817 static PyObject *Dlg_ModalDialog(_self, _args)
818 PyObject *_self;
819 PyObject *_args;
821 PyObject *_res = NULL;
822 PyObject* modalFilter;
823 DialogItemIndex itemHit;
824 if (!PyArg_ParseTuple(_args, "O",
825 &modalFilter))
826 return NULL;
827 ModalDialog(NewModalFilterProc(Dlg_PassFilterProc(modalFilter)),
828 &itemHit);
829 _res = Py_BuildValue("h",
830 itemHit);
831 return _res;
834 static PyObject *Dlg_IsDialogEvent(_self, _args)
835 PyObject *_self;
836 PyObject *_args;
838 PyObject *_res = NULL;
839 Boolean _rv;
840 EventRecord theEvent;
841 if (!PyArg_ParseTuple(_args, "O&",
842 PyMac_GetEventRecord, &theEvent))
843 return NULL;
844 _rv = IsDialogEvent(&theEvent);
845 _res = Py_BuildValue("b",
846 _rv);
847 return _res;
850 static PyObject *Dlg_DialogSelect(_self, _args)
851 PyObject *_self;
852 PyObject *_args;
854 PyObject *_res = NULL;
855 Boolean _rv;
856 EventRecord theEvent;
857 DialogPtr theDialog;
858 DialogItemIndex itemHit;
859 if (!PyArg_ParseTuple(_args, "O&",
860 PyMac_GetEventRecord, &theEvent))
861 return NULL;
862 _rv = DialogSelect(&theEvent,
863 &theDialog,
864 &itemHit);
865 _res = Py_BuildValue("bO&h",
866 _rv,
867 WinObj_WhichWindow, theDialog,
868 itemHit);
869 return _res;
872 static PyObject *Dlg_Alert(_self, _args)
873 PyObject *_self;
874 PyObject *_args;
876 PyObject *_res = NULL;
877 DialogItemIndex _rv;
878 SInt16 alertID;
879 PyObject* modalFilter;
880 if (!PyArg_ParseTuple(_args, "hO",
881 &alertID,
882 &modalFilter))
883 return NULL;
884 _rv = Alert(alertID,
885 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
886 _res = Py_BuildValue("h",
887 _rv);
888 return _res;
891 static PyObject *Dlg_StopAlert(_self, _args)
892 PyObject *_self;
893 PyObject *_args;
895 PyObject *_res = NULL;
896 DialogItemIndex _rv;
897 SInt16 alertID;
898 PyObject* modalFilter;
899 if (!PyArg_ParseTuple(_args, "hO",
900 &alertID,
901 &modalFilter))
902 return NULL;
903 _rv = StopAlert(alertID,
904 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
905 _res = Py_BuildValue("h",
906 _rv);
907 return _res;
910 static PyObject *Dlg_NoteAlert(_self, _args)
911 PyObject *_self;
912 PyObject *_args;
914 PyObject *_res = NULL;
915 DialogItemIndex _rv;
916 SInt16 alertID;
917 PyObject* modalFilter;
918 if (!PyArg_ParseTuple(_args, "hO",
919 &alertID,
920 &modalFilter))
921 return NULL;
922 _rv = NoteAlert(alertID,
923 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
924 _res = Py_BuildValue("h",
925 _rv);
926 return _res;
929 static PyObject *Dlg_CautionAlert(_self, _args)
930 PyObject *_self;
931 PyObject *_args;
933 PyObject *_res = NULL;
934 DialogItemIndex _rv;
935 SInt16 alertID;
936 PyObject* modalFilter;
937 if (!PyArg_ParseTuple(_args, "hO",
938 &alertID,
939 &modalFilter))
940 return NULL;
941 _rv = CautionAlert(alertID,
942 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
943 _res = Py_BuildValue("h",
944 _rv);
945 return _res;
948 static PyObject *Dlg_ParamText(_self, _args)
949 PyObject *_self;
950 PyObject *_args;
952 PyObject *_res = NULL;
953 Str255 param0;
954 Str255 param1;
955 Str255 param2;
956 Str255 param3;
957 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
958 PyMac_GetStr255, param0,
959 PyMac_GetStr255, param1,
960 PyMac_GetStr255, param2,
961 PyMac_GetStr255, param3))
962 return NULL;
963 ParamText(param0,
964 param1,
965 param2,
966 param3);
967 Py_INCREF(Py_None);
968 _res = Py_None;
969 return _res;
972 static PyObject *Dlg_GetDialogItemText(_self, _args)
973 PyObject *_self;
974 PyObject *_args;
976 PyObject *_res = NULL;
977 Handle item;
978 Str255 text;
979 if (!PyArg_ParseTuple(_args, "O&",
980 ResObj_Convert, &item))
981 return NULL;
982 GetDialogItemText(item,
983 text);
984 _res = Py_BuildValue("O&",
985 PyMac_BuildStr255, text);
986 return _res;
989 static PyObject *Dlg_SetDialogItemText(_self, _args)
990 PyObject *_self;
991 PyObject *_args;
993 PyObject *_res = NULL;
994 Handle item;
995 Str255 text;
996 if (!PyArg_ParseTuple(_args, "O&O&",
997 ResObj_Convert, &item,
998 PyMac_GetStr255, text))
999 return NULL;
1000 SetDialogItemText(item,
1001 text);
1002 Py_INCREF(Py_None);
1003 _res = Py_None;
1004 return _res;
1007 static PyObject *Dlg_GetAlertStage(_self, _args)
1008 PyObject *_self;
1009 PyObject *_args;
1011 PyObject *_res = NULL;
1012 SInt16 _rv;
1013 if (!PyArg_ParseTuple(_args, ""))
1014 return NULL;
1015 _rv = GetAlertStage();
1016 _res = Py_BuildValue("h",
1017 _rv);
1018 return _res;
1021 static PyObject *Dlg_SetDialogFont(_self, _args)
1022 PyObject *_self;
1023 PyObject *_args;
1025 PyObject *_res = NULL;
1026 SInt16 value;
1027 if (!PyArg_ParseTuple(_args, "h",
1028 &value))
1029 return NULL;
1030 SetDialogFont(value);
1031 Py_INCREF(Py_None);
1032 _res = Py_None;
1033 return _res;
1036 static PyObject *Dlg_ResetAlertStage(_self, _args)
1037 PyObject *_self;
1038 PyObject *_args;
1040 PyObject *_res = NULL;
1041 if (!PyArg_ParseTuple(_args, ""))
1042 return NULL;
1043 ResetAlertStage();
1044 Py_INCREF(Py_None);
1045 _res = Py_None;
1046 return _res;
1049 static PyObject *Dlg_NewFeaturesDialog(_self, _args)
1050 PyObject *_self;
1051 PyObject *_args;
1053 PyObject *_res = NULL;
1054 DialogPtr _rv;
1055 Rect inBoundsRect;
1056 Str255 inTitle;
1057 Boolean inIsVisible;
1058 SInt16 inProcID;
1059 WindowPtr inBehind;
1060 Boolean inGoAwayFlag;
1061 SInt32 inRefCon;
1062 Handle inItemListHandle;
1063 UInt32 inFlags;
1064 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
1065 PyMac_GetRect, &inBoundsRect,
1066 PyMac_GetStr255, inTitle,
1067 &inIsVisible,
1068 &inProcID,
1069 WinObj_Convert, &inBehind,
1070 &inGoAwayFlag,
1071 &inRefCon,
1072 ResObj_Convert, &inItemListHandle,
1073 &inFlags))
1074 return NULL;
1075 _rv = NewFeaturesDialog((void *)0,
1076 &inBoundsRect,
1077 inTitle,
1078 inIsVisible,
1079 inProcID,
1080 inBehind,
1081 inGoAwayFlag,
1082 inRefCon,
1083 inItemListHandle,
1084 inFlags);
1085 _res = Py_BuildValue("O&",
1086 DlgObj_New, _rv);
1087 return _res;
1090 static PyMethodDef Dlg_methods[] = {
1091 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
1092 "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
1093 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
1094 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1095 {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
1096 "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
1097 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
1098 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
1099 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
1100 "(EventRecord theEvent) -> (Boolean _rv)"},
1101 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
1102 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
1103 {"Alert", (PyCFunction)Dlg_Alert, 1,
1104 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1105 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
1106 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1107 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
1108 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1109 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
1110 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1111 {"ParamText", (PyCFunction)Dlg_ParamText, 1,
1112 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1113 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
1114 "(Handle item) -> (Str255 text)"},
1115 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
1116 "(Handle item, Str255 text) -> None"},
1117 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
1118 "() -> (SInt16 _rv)"},
1119 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
1120 "(SInt16 value) -> None"},
1121 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
1122 "() -> None"},
1123 {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
1124 "(Rect inBoundsRect, Str255 inTitle, Boolean inIsVisible, SInt16 inProcID, WindowPtr inBehind, Boolean inGoAwayFlag, SInt32 inRefCon, Handle inItemListHandle, UInt32 inFlags) -> (DialogPtr _rv)"},
1125 {NULL, NULL, 0}
1131 void initDlg()
1133 PyObject *m;
1134 PyObject *d;
1139 m = Py_InitModule("Dlg", Dlg_methods);
1140 d = PyModule_GetDict(m);
1141 Dlg_Error = PyMac_GetOSErrException();
1142 if (Dlg_Error == NULL ||
1143 PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
1144 Py_FatalError("can't initialize Dlg.Error");
1145 Dialog_Type.ob_type = &PyType_Type;
1146 Py_INCREF(&Dialog_Type);
1147 if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0)
1148 Py_FatalError("can't initialize DialogType");
1151 /* ========================= End module Dlg ========================= */