The 0.5 release happened on 2/15, not on 2/14. :-)
[python/dscho.git] / Mac / Modules / dlg / Dlgmodule.c
blobfbbadd84759da55e2a3ad27b385d323a9e56a4fb
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 PySys_WriteStderr("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 static PyObject *Dlg_UserItemProc_callback = NULL;
111 static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
112 short item)
114 PyObject *args, *res;
116 if (Dlg_UserItemProc_callback == NULL)
117 return; /* Default behavior */
118 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
119 args = Py_BuildValue("O&h", WinObj_WhichWindow, dialog, item);
120 if (args == NULL)
121 res = NULL;
122 else {
123 res = PyEval_CallObject(Dlg_UserItemProc_callback, args);
124 Py_DECREF(args);
126 if (res == NULL) {
127 PySys_WriteStderr("Exception in Dialog UserItem proc\n");
128 PyErr_Print();
130 Py_XDECREF(res);
131 return;
134 extern PyMethodChain WinObj_chain;
136 static PyObject *Dlg_Error;
138 /* ----------------------- Object type Dialog ----------------------- */
140 PyTypeObject Dialog_Type;
142 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
144 typedef struct DialogObject {
145 PyObject_HEAD
146 DialogPtr ob_itself;
147 } DialogObject;
149 PyObject *DlgObj_New(itself)
150 DialogPtr itself;
152 DialogObject *it;
153 if (itself == NULL) return Py_None;
154 it = PyObject_NEW(DialogObject, &Dialog_Type);
155 if (it == NULL) return NULL;
156 it->ob_itself = itself;
157 SetWRefCon(itself, (long)it);
158 return (PyObject *)it;
160 DlgObj_Convert(v, p_itself)
161 PyObject *v;
162 DialogPtr *p_itself;
164 if (v == Py_None) { *p_itself = NULL; return 1; }
165 if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
166 return 1; }
167 if (!DlgObj_Check(v))
169 PyErr_SetString(PyExc_TypeError, "Dialog required");
170 return 0;
172 *p_itself = ((DialogObject *)v)->ob_itself;
173 return 1;
176 static void DlgObj_dealloc(self)
177 DialogObject *self;
179 DisposeDialog(self->ob_itself);
180 PyMem_DEL(self);
183 static PyObject *DlgObj_DrawDialog(_self, _args)
184 DialogObject *_self;
185 PyObject *_args;
187 PyObject *_res = NULL;
188 if (!PyArg_ParseTuple(_args, ""))
189 return NULL;
190 DrawDialog(_self->ob_itself);
191 Py_INCREF(Py_None);
192 _res = Py_None;
193 return _res;
196 static PyObject *DlgObj_UpdateDialog(_self, _args)
197 DialogObject *_self;
198 PyObject *_args;
200 PyObject *_res = NULL;
201 RgnHandle updateRgn;
202 if (!PyArg_ParseTuple(_args, "O&",
203 ResObj_Convert, &updateRgn))
204 return NULL;
205 UpdateDialog(_self->ob_itself,
206 updateRgn);
207 Py_INCREF(Py_None);
208 _res = Py_None;
209 return _res;
212 static PyObject *DlgObj_HideDialogItem(_self, _args)
213 DialogObject *_self;
214 PyObject *_args;
216 PyObject *_res = NULL;
217 DialogItemIndex itemNo;
218 if (!PyArg_ParseTuple(_args, "h",
219 &itemNo))
220 return NULL;
221 HideDialogItem(_self->ob_itself,
222 itemNo);
223 Py_INCREF(Py_None);
224 _res = Py_None;
225 return _res;
228 static PyObject *DlgObj_ShowDialogItem(_self, _args)
229 DialogObject *_self;
230 PyObject *_args;
232 PyObject *_res = NULL;
233 DialogItemIndex itemNo;
234 if (!PyArg_ParseTuple(_args, "h",
235 &itemNo))
236 return NULL;
237 ShowDialogItem(_self->ob_itself,
238 itemNo);
239 Py_INCREF(Py_None);
240 _res = Py_None;
241 return _res;
244 static PyObject *DlgObj_FindDialogItem(_self, _args)
245 DialogObject *_self;
246 PyObject *_args;
248 PyObject *_res = NULL;
249 DialogItemIndexZeroBased _rv;
250 Point thePt;
251 if (!PyArg_ParseTuple(_args, "O&",
252 PyMac_GetPoint, &thePt))
253 return NULL;
254 _rv = FindDialogItem(_self->ob_itself,
255 thePt);
256 _res = Py_BuildValue("h",
257 _rv);
258 return _res;
261 static PyObject *DlgObj_DialogCut(_self, _args)
262 DialogObject *_self;
263 PyObject *_args;
265 PyObject *_res = NULL;
266 if (!PyArg_ParseTuple(_args, ""))
267 return NULL;
268 DialogCut(_self->ob_itself);
269 Py_INCREF(Py_None);
270 _res = Py_None;
271 return _res;
274 static PyObject *DlgObj_DialogPaste(_self, _args)
275 DialogObject *_self;
276 PyObject *_args;
278 PyObject *_res = NULL;
279 if (!PyArg_ParseTuple(_args, ""))
280 return NULL;
281 DialogPaste(_self->ob_itself);
282 Py_INCREF(Py_None);
283 _res = Py_None;
284 return _res;
287 static PyObject *DlgObj_DialogCopy(_self, _args)
288 DialogObject *_self;
289 PyObject *_args;
291 PyObject *_res = NULL;
292 if (!PyArg_ParseTuple(_args, ""))
293 return NULL;
294 DialogCopy(_self->ob_itself);
295 Py_INCREF(Py_None);
296 _res = Py_None;
297 return _res;
300 static PyObject *DlgObj_DialogDelete(_self, _args)
301 DialogObject *_self;
302 PyObject *_args;
304 PyObject *_res = NULL;
305 if (!PyArg_ParseTuple(_args, ""))
306 return NULL;
307 DialogDelete(_self->ob_itself);
308 Py_INCREF(Py_None);
309 _res = Py_None;
310 return _res;
313 static PyObject *DlgObj_GetDialogItem(_self, _args)
314 DialogObject *_self;
315 PyObject *_args;
317 PyObject *_res = NULL;
318 DialogItemIndex itemNo;
319 DialogItemType itemType;
320 Handle item;
321 Rect box;
322 if (!PyArg_ParseTuple(_args, "h",
323 &itemNo))
324 return NULL;
325 GetDialogItem(_self->ob_itself,
326 itemNo,
327 &itemType,
328 &item,
329 &box);
330 _res = Py_BuildValue("hO&O&",
331 itemType,
332 OptResObj_New, item,
333 PyMac_BuildRect, &box);
334 return _res;
337 static PyObject *DlgObj_SetDialogItem(_self, _args)
338 DialogObject *_self;
339 PyObject *_args;
341 PyObject *_res = NULL;
342 DialogItemIndex itemNo;
343 DialogItemType itemType;
344 Handle item;
345 Rect box;
346 if (!PyArg_ParseTuple(_args, "hhO&O&",
347 &itemNo,
348 &itemType,
349 ResObj_Convert, &item,
350 PyMac_GetRect, &box))
351 return NULL;
352 SetDialogItem(_self->ob_itself,
353 itemNo,
354 itemType,
355 item,
356 &box);
357 Py_INCREF(Py_None);
358 _res = Py_None;
359 return _res;
362 static PyObject *DlgObj_SelectDialogItemText(_self, _args)
363 DialogObject *_self;
364 PyObject *_args;
366 PyObject *_res = NULL;
367 DialogItemIndex itemNo;
368 SInt16 strtSel;
369 SInt16 endSel;
370 if (!PyArg_ParseTuple(_args, "hhh",
371 &itemNo,
372 &strtSel,
373 &endSel))
374 return NULL;
375 SelectDialogItemText(_self->ob_itself,
376 itemNo,
377 strtSel,
378 endSel);
379 Py_INCREF(Py_None);
380 _res = Py_None;
381 return _res;
384 static PyObject *DlgObj_AppendDITL(_self, _args)
385 DialogObject *_self;
386 PyObject *_args;
388 PyObject *_res = NULL;
389 Handle theHandle;
390 DITLMethod method;
391 if (!PyArg_ParseTuple(_args, "O&h",
392 ResObj_Convert, &theHandle,
393 &method))
394 return NULL;
395 AppendDITL(_self->ob_itself,
396 theHandle,
397 method);
398 Py_INCREF(Py_None);
399 _res = Py_None;
400 return _res;
403 static PyObject *DlgObj_CountDITL(_self, _args)
404 DialogObject *_self;
405 PyObject *_args;
407 PyObject *_res = NULL;
408 DialogItemIndex _rv;
409 if (!PyArg_ParseTuple(_args, ""))
410 return NULL;
411 _rv = CountDITL(_self->ob_itself);
412 _res = Py_BuildValue("h",
413 _rv);
414 return _res;
417 static PyObject *DlgObj_ShortenDITL(_self, _args)
418 DialogObject *_self;
419 PyObject *_args;
421 PyObject *_res = NULL;
422 DialogItemIndex numberItems;
423 if (!PyArg_ParseTuple(_args, "h",
424 &numberItems))
425 return NULL;
426 ShortenDITL(_self->ob_itself,
427 numberItems);
428 Py_INCREF(Py_None);
429 _res = Py_None;
430 return _res;
433 static PyObject *DlgObj_StdFilterProc(_self, _args)
434 DialogObject *_self;
435 PyObject *_args;
437 PyObject *_res = NULL;
438 Boolean _rv;
439 EventRecord event;
440 DialogItemIndex itemHit;
441 if (!PyArg_ParseTuple(_args, ""))
442 return NULL;
443 _rv = StdFilterProc(_self->ob_itself,
444 &event,
445 &itemHit);
446 _res = Py_BuildValue("bO&h",
447 _rv,
448 PyMac_BuildEventRecord, &event,
449 itemHit);
450 return _res;
453 static PyObject *DlgObj_SetDialogDefaultItem(_self, _args)
454 DialogObject *_self;
455 PyObject *_args;
457 PyObject *_res = NULL;
458 OSErr _err;
459 DialogItemIndex newItem;
460 if (!PyArg_ParseTuple(_args, "h",
461 &newItem))
462 return NULL;
463 _err = SetDialogDefaultItem(_self->ob_itself,
464 newItem);
465 if (_err != noErr) return PyMac_Error(_err);
466 Py_INCREF(Py_None);
467 _res = Py_None;
468 return _res;
471 static PyObject *DlgObj_SetDialogCancelItem(_self, _args)
472 DialogObject *_self;
473 PyObject *_args;
475 PyObject *_res = NULL;
476 OSErr _err;
477 DialogItemIndex newItem;
478 if (!PyArg_ParseTuple(_args, "h",
479 &newItem))
480 return NULL;
481 _err = SetDialogCancelItem(_self->ob_itself,
482 newItem);
483 if (_err != noErr) return PyMac_Error(_err);
484 Py_INCREF(Py_None);
485 _res = Py_None;
486 return _res;
489 static PyObject *DlgObj_SetDialogTracksCursor(_self, _args)
490 DialogObject *_self;
491 PyObject *_args;
493 PyObject *_res = NULL;
494 OSErr _err;
495 Boolean tracks;
496 if (!PyArg_ParseTuple(_args, "b",
497 &tracks))
498 return NULL;
499 _err = SetDialogTracksCursor(_self->ob_itself,
500 tracks);
501 if (_err != noErr) return PyMac_Error(_err);
502 Py_INCREF(Py_None);
503 _res = Py_None;
504 return _res;
507 static PyObject *DlgObj_AutoSizeDialog(_self, _args)
508 DialogObject *_self;
509 PyObject *_args;
511 PyObject *_res = NULL;
512 OSErr _err;
513 if (!PyArg_ParseTuple(_args, ""))
514 return NULL;
515 _err = AutoSizeDialog(_self->ob_itself);
516 if (_err != noErr) return PyMac_Error(_err);
517 Py_INCREF(Py_None);
518 _res = Py_None;
519 return _res;
522 static PyObject *DlgObj_GetDialogItemAsControl(_self, _args)
523 DialogObject *_self;
524 PyObject *_args;
526 PyObject *_res = NULL;
527 OSErr _err;
528 SInt16 inItemNo;
529 ControlHandle outControl;
530 if (!PyArg_ParseTuple(_args, "h",
531 &inItemNo))
532 return NULL;
533 _err = GetDialogItemAsControl(_self->ob_itself,
534 inItemNo,
535 &outControl);
536 if (_err != noErr) return PyMac_Error(_err);
537 _res = Py_BuildValue("O&",
538 CtlObj_New, outControl);
539 return _res;
542 static PyObject *DlgObj_MoveDialogItem(_self, _args)
543 DialogObject *_self;
544 PyObject *_args;
546 PyObject *_res = NULL;
547 OSErr _err;
548 SInt16 inItemNo;
549 SInt16 inHoriz;
550 SInt16 inVert;
551 if (!PyArg_ParseTuple(_args, "hhh",
552 &inItemNo,
553 &inHoriz,
554 &inVert))
555 return NULL;
556 _err = MoveDialogItem(_self->ob_itself,
557 inItemNo,
558 inHoriz,
559 inVert);
560 if (_err != noErr) return PyMac_Error(_err);
561 Py_INCREF(Py_None);
562 _res = Py_None;
563 return _res;
566 static PyObject *DlgObj_SizeDialogItem(_self, _args)
567 DialogObject *_self;
568 PyObject *_args;
570 PyObject *_res = NULL;
571 OSErr _err;
572 SInt16 inItemNo;
573 SInt16 inWidth;
574 SInt16 inHeight;
575 if (!PyArg_ParseTuple(_args, "hhh",
576 &inItemNo,
577 &inWidth,
578 &inHeight))
579 return NULL;
580 _err = SizeDialogItem(_self->ob_itself,
581 inItemNo,
582 inWidth,
583 inHeight);
584 if (_err != noErr) return PyMac_Error(_err);
585 Py_INCREF(Py_None);
586 _res = Py_None;
587 return _res;
590 static PyObject *DlgObj_AppendDialogItemList(_self, _args)
591 DialogObject *_self;
592 PyObject *_args;
594 PyObject *_res = NULL;
595 OSErr _err;
596 SInt16 ditlID;
597 DITLMethod method;
598 if (!PyArg_ParseTuple(_args, "hh",
599 &ditlID,
600 &method))
601 return NULL;
602 _err = AppendDialogItemList(_self->ob_itself,
603 ditlID,
604 method);
605 if (_err != noErr) return PyMac_Error(_err);
606 Py_INCREF(Py_None);
607 _res = Py_None;
608 return _res;
611 static PyObject *DlgObj_SetDialogTimeout(_self, _args)
612 DialogObject *_self;
613 PyObject *_args;
615 PyObject *_res = NULL;
616 OSStatus _err;
617 SInt16 inButtonToPress;
618 UInt32 inSecondsToWait;
619 if (!PyArg_ParseTuple(_args, "hl",
620 &inButtonToPress,
621 &inSecondsToWait))
622 return NULL;
623 _err = SetDialogTimeout(_self->ob_itself,
624 inButtonToPress,
625 inSecondsToWait);
626 if (_err != noErr) return PyMac_Error(_err);
627 Py_INCREF(Py_None);
628 _res = Py_None;
629 return _res;
632 static PyObject *DlgObj_GetDialogTimeout(_self, _args)
633 DialogObject *_self;
634 PyObject *_args;
636 PyObject *_res = NULL;
637 OSStatus _err;
638 SInt16 outButtonToPress;
639 UInt32 outSecondsToWait;
640 UInt32 outSecondsRemaining;
641 if (!PyArg_ParseTuple(_args, ""))
642 return NULL;
643 _err = GetDialogTimeout(_self->ob_itself,
644 &outButtonToPress,
645 &outSecondsToWait,
646 &outSecondsRemaining);
647 if (_err != noErr) return PyMac_Error(_err);
648 _res = Py_BuildValue("hll",
649 outButtonToPress,
650 outSecondsToWait,
651 outSecondsRemaining);
652 return _res;
655 static PyObject *DlgObj_SetModalDialogEventMask(_self, _args)
656 DialogObject *_self;
657 PyObject *_args;
659 PyObject *_res = NULL;
660 OSStatus _err;
661 EventMask inMask;
662 if (!PyArg_ParseTuple(_args, "h",
663 &inMask))
664 return NULL;
665 _err = SetModalDialogEventMask(_self->ob_itself,
666 inMask);
667 if (_err != noErr) return PyMac_Error(_err);
668 Py_INCREF(Py_None);
669 _res = Py_None;
670 return _res;
673 static PyObject *DlgObj_GetModalDialogEventMask(_self, _args)
674 DialogObject *_self;
675 PyObject *_args;
677 PyObject *_res = NULL;
678 OSStatus _err;
679 EventMask outMask;
680 if (!PyArg_ParseTuple(_args, ""))
681 return NULL;
682 _err = GetModalDialogEventMask(_self->ob_itself,
683 &outMask);
684 if (_err != noErr) return PyMac_Error(_err);
685 _res = Py_BuildValue("h",
686 outMask);
687 return _res;
690 static PyObject *DlgObj_GetDialogWindow(_self, _args)
691 DialogObject *_self;
692 PyObject *_args;
694 PyObject *_res = NULL;
695 DialogPtr _rv;
696 if (!PyArg_ParseTuple(_args, ""))
697 return NULL;
698 _rv = GetDialogWindow(_self->ob_itself);
699 _res = Py_BuildValue("O&",
700 WinObj_WhichWindow, _rv);
701 return _res;
704 static PyObject *DlgObj_GetDialogDefaultItem(_self, _args)
705 DialogObject *_self;
706 PyObject *_args;
708 PyObject *_res = NULL;
709 SInt16 _rv;
710 if (!PyArg_ParseTuple(_args, ""))
711 return NULL;
712 _rv = GetDialogDefaultItem(_self->ob_itself);
713 _res = Py_BuildValue("h",
714 _rv);
715 return _res;
718 static PyObject *DlgObj_GetDialogCancelItem(_self, _args)
719 DialogObject *_self;
720 PyObject *_args;
722 PyObject *_res = NULL;
723 SInt16 _rv;
724 if (!PyArg_ParseTuple(_args, ""))
725 return NULL;
726 _rv = GetDialogCancelItem(_self->ob_itself);
727 _res = Py_BuildValue("h",
728 _rv);
729 return _res;
732 static PyObject *DlgObj_GetDialogKeyboardFocusItem(_self, _args)
733 DialogObject *_self;
734 PyObject *_args;
736 PyObject *_res = NULL;
737 SInt16 _rv;
738 if (!PyArg_ParseTuple(_args, ""))
739 return NULL;
740 _rv = GetDialogKeyboardFocusItem(_self->ob_itself);
741 _res = Py_BuildValue("h",
742 _rv);
743 return _res;
746 static PyObject *DlgObj_SetGrafPortOfDialog(_self, _args)
747 DialogObject *_self;
748 PyObject *_args;
750 PyObject *_res = NULL;
751 if (!PyArg_ParseTuple(_args, ""))
752 return NULL;
753 SetGrafPortOfDialog(_self->ob_itself);
754 Py_INCREF(Py_None);
755 _res = Py_None;
756 return _res;
759 static PyMethodDef DlgObj_methods[] = {
760 {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
761 "() -> None"},
762 {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
763 "(RgnHandle updateRgn) -> None"},
764 {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
765 "(DialogItemIndex itemNo) -> None"},
766 {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
767 "(DialogItemIndex itemNo) -> None"},
768 {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
769 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
770 {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
771 "() -> None"},
772 {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
773 "() -> None"},
774 {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
775 "() -> None"},
776 {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
777 "() -> None"},
778 {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1,
779 "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"},
780 {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1,
781 "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"},
782 {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1,
783 "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"},
784 {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
785 "(Handle theHandle, DITLMethod method) -> None"},
786 {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
787 "() -> (DialogItemIndex _rv)"},
788 {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
789 "(DialogItemIndex numberItems) -> None"},
790 {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
791 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
792 {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
793 "(DialogItemIndex newItem) -> None"},
794 {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
795 "(DialogItemIndex newItem) -> None"},
796 {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
797 "(Boolean tracks) -> None"},
798 {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1,
799 "() -> None"},
800 {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1,
801 "(SInt16 inItemNo) -> (ControlHandle outControl)"},
802 {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1,
803 "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"},
804 {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1,
805 "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"},
806 {"AppendDialogItemList", (PyCFunction)DlgObj_AppendDialogItemList, 1,
807 "(SInt16 ditlID, DITLMethod method) -> None"},
808 {"SetDialogTimeout", (PyCFunction)DlgObj_SetDialogTimeout, 1,
809 "(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None"},
810 {"GetDialogTimeout", (PyCFunction)DlgObj_GetDialogTimeout, 1,
811 "() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)"},
812 {"SetModalDialogEventMask", (PyCFunction)DlgObj_SetModalDialogEventMask, 1,
813 "(EventMask inMask) -> None"},
814 {"GetModalDialogEventMask", (PyCFunction)DlgObj_GetModalDialogEventMask, 1,
815 "() -> (EventMask outMask)"},
816 {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
817 "() -> (DialogPtr _rv)"},
818 {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1,
819 "() -> (SInt16 _rv)"},
820 {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1,
821 "() -> (SInt16 _rv)"},
822 {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1,
823 "() -> (SInt16 _rv)"},
824 {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1,
825 "() -> None"},
826 {NULL, NULL, 0}
829 PyMethodChain DlgObj_chain = { DlgObj_methods, &WinObj_chain };
831 static PyObject *DlgObj_getattr(self, name)
832 DialogObject *self;
833 char *name;
835 return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name);
838 #define DlgObj_setattr NULL
840 #define DlgObj_compare NULL
842 #define DlgObj_repr NULL
844 #define DlgObj_hash NULL
846 PyTypeObject Dialog_Type = {
847 PyObject_HEAD_INIT(&PyType_Type)
848 0, /*ob_size*/
849 "Dialog", /*tp_name*/
850 sizeof(DialogObject), /*tp_basicsize*/
851 0, /*tp_itemsize*/
852 /* methods */
853 (destructor) DlgObj_dealloc, /*tp_dealloc*/
854 0, /*tp_print*/
855 (getattrfunc) DlgObj_getattr, /*tp_getattr*/
856 (setattrfunc) DlgObj_setattr, /*tp_setattr*/
857 (cmpfunc) DlgObj_compare, /*tp_compare*/
858 (reprfunc) DlgObj_repr, /*tp_repr*/
859 (PyNumberMethods *)0, /* tp_as_number */
860 (PySequenceMethods *)0, /* tp_as_sequence */
861 (PyMappingMethods *)0, /* tp_as_mapping */
862 (hashfunc) DlgObj_hash, /*tp_hash*/
865 /* --------------------- End object type Dialog --------------------- */
868 static PyObject *Dlg_NewDialog(_self, _args)
869 PyObject *_self;
870 PyObject *_args;
872 PyObject *_res = NULL;
873 DialogPtr _rv;
874 Rect boundsRect;
875 Str255 title;
876 Boolean visible;
877 SInt16 procID;
878 WindowPtr behind;
879 Boolean goAwayFlag;
880 SInt32 refCon;
881 Handle items;
882 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
883 PyMac_GetRect, &boundsRect,
884 PyMac_GetStr255, title,
885 &visible,
886 &procID,
887 WinObj_Convert, &behind,
888 &goAwayFlag,
889 &refCon,
890 ResObj_Convert, &items))
891 return NULL;
892 _rv = NewDialog((void *)0,
893 &boundsRect,
894 title,
895 visible,
896 procID,
897 behind,
898 goAwayFlag,
899 refCon,
900 items);
901 _res = Py_BuildValue("O&",
902 DlgObj_New, _rv);
903 return _res;
906 static PyObject *Dlg_GetNewDialog(_self, _args)
907 PyObject *_self;
908 PyObject *_args;
910 PyObject *_res = NULL;
911 DialogPtr _rv;
912 SInt16 dialogID;
913 WindowPtr behind;
914 if (!PyArg_ParseTuple(_args, "hO&",
915 &dialogID,
916 WinObj_Convert, &behind))
917 return NULL;
918 _rv = GetNewDialog(dialogID,
919 (void *)0,
920 behind);
921 _res = Py_BuildValue("O&",
922 DlgObj_New, _rv);
923 return _res;
926 static PyObject *Dlg_NewColorDialog(_self, _args)
927 PyObject *_self;
928 PyObject *_args;
930 PyObject *_res = NULL;
931 DialogPtr _rv;
932 Rect boundsRect;
933 Str255 title;
934 Boolean visible;
935 SInt16 procID;
936 WindowPtr behind;
937 Boolean goAwayFlag;
938 SInt32 refCon;
939 Handle items;
940 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
941 PyMac_GetRect, &boundsRect,
942 PyMac_GetStr255, title,
943 &visible,
944 &procID,
945 WinObj_Convert, &behind,
946 &goAwayFlag,
947 &refCon,
948 ResObj_Convert, &items))
949 return NULL;
950 _rv = NewColorDialog((void *)0,
951 &boundsRect,
952 title,
953 visible,
954 procID,
955 behind,
956 goAwayFlag,
957 refCon,
958 items);
959 _res = Py_BuildValue("O&",
960 DlgObj_New, _rv);
961 return _res;
964 static PyObject *Dlg_ModalDialog(_self, _args)
965 PyObject *_self;
966 PyObject *_args;
968 PyObject *_res = NULL;
969 PyObject* modalFilter;
970 DialogItemIndex itemHit;
971 if (!PyArg_ParseTuple(_args, "O",
972 &modalFilter))
973 return NULL;
974 ModalDialog(NewModalFilterProc(Dlg_PassFilterProc(modalFilter)),
975 &itemHit);
976 _res = Py_BuildValue("h",
977 itemHit);
978 return _res;
981 static PyObject *Dlg_IsDialogEvent(_self, _args)
982 PyObject *_self;
983 PyObject *_args;
985 PyObject *_res = NULL;
986 Boolean _rv;
987 EventRecord theEvent;
988 if (!PyArg_ParseTuple(_args, "O&",
989 PyMac_GetEventRecord, &theEvent))
990 return NULL;
991 _rv = IsDialogEvent(&theEvent);
992 _res = Py_BuildValue("b",
993 _rv);
994 return _res;
997 static PyObject *Dlg_DialogSelect(_self, _args)
998 PyObject *_self;
999 PyObject *_args;
1001 PyObject *_res = NULL;
1002 Boolean _rv;
1003 EventRecord theEvent;
1004 DialogPtr theDialog;
1005 DialogItemIndex itemHit;
1006 if (!PyArg_ParseTuple(_args, "O&",
1007 PyMac_GetEventRecord, &theEvent))
1008 return NULL;
1009 _rv = DialogSelect(&theEvent,
1010 &theDialog,
1011 &itemHit);
1012 _res = Py_BuildValue("bO&h",
1013 _rv,
1014 WinObj_WhichWindow, theDialog,
1015 itemHit);
1016 return _res;
1019 static PyObject *Dlg_Alert(_self, _args)
1020 PyObject *_self;
1021 PyObject *_args;
1023 PyObject *_res = NULL;
1024 DialogItemIndex _rv;
1025 SInt16 alertID;
1026 PyObject* modalFilter;
1027 if (!PyArg_ParseTuple(_args, "hO",
1028 &alertID,
1029 &modalFilter))
1030 return NULL;
1031 _rv = Alert(alertID,
1032 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
1033 _res = Py_BuildValue("h",
1034 _rv);
1035 return _res;
1038 static PyObject *Dlg_StopAlert(_self, _args)
1039 PyObject *_self;
1040 PyObject *_args;
1042 PyObject *_res = NULL;
1043 DialogItemIndex _rv;
1044 SInt16 alertID;
1045 PyObject* modalFilter;
1046 if (!PyArg_ParseTuple(_args, "hO",
1047 &alertID,
1048 &modalFilter))
1049 return NULL;
1050 _rv = StopAlert(alertID,
1051 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
1052 _res = Py_BuildValue("h",
1053 _rv);
1054 return _res;
1057 static PyObject *Dlg_NoteAlert(_self, _args)
1058 PyObject *_self;
1059 PyObject *_args;
1061 PyObject *_res = NULL;
1062 DialogItemIndex _rv;
1063 SInt16 alertID;
1064 PyObject* modalFilter;
1065 if (!PyArg_ParseTuple(_args, "hO",
1066 &alertID,
1067 &modalFilter))
1068 return NULL;
1069 _rv = NoteAlert(alertID,
1070 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
1071 _res = Py_BuildValue("h",
1072 _rv);
1073 return _res;
1076 static PyObject *Dlg_CautionAlert(_self, _args)
1077 PyObject *_self;
1078 PyObject *_args;
1080 PyObject *_res = NULL;
1081 DialogItemIndex _rv;
1082 SInt16 alertID;
1083 PyObject* modalFilter;
1084 if (!PyArg_ParseTuple(_args, "hO",
1085 &alertID,
1086 &modalFilter))
1087 return NULL;
1088 _rv = CautionAlert(alertID,
1089 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
1090 _res = Py_BuildValue("h",
1091 _rv);
1092 return _res;
1095 static PyObject *Dlg_ParamText(_self, _args)
1096 PyObject *_self;
1097 PyObject *_args;
1099 PyObject *_res = NULL;
1100 Str255 param0;
1101 Str255 param1;
1102 Str255 param2;
1103 Str255 param3;
1104 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1105 PyMac_GetStr255, param0,
1106 PyMac_GetStr255, param1,
1107 PyMac_GetStr255, param2,
1108 PyMac_GetStr255, param3))
1109 return NULL;
1110 ParamText(param0,
1111 param1,
1112 param2,
1113 param3);
1114 Py_INCREF(Py_None);
1115 _res = Py_None;
1116 return _res;
1119 static PyObject *Dlg_GetDialogItemText(_self, _args)
1120 PyObject *_self;
1121 PyObject *_args;
1123 PyObject *_res = NULL;
1124 Handle item;
1125 Str255 text;
1126 if (!PyArg_ParseTuple(_args, "O&",
1127 ResObj_Convert, &item))
1128 return NULL;
1129 GetDialogItemText(item,
1130 text);
1131 _res = Py_BuildValue("O&",
1132 PyMac_BuildStr255, text);
1133 return _res;
1136 static PyObject *Dlg_SetDialogItemText(_self, _args)
1137 PyObject *_self;
1138 PyObject *_args;
1140 PyObject *_res = NULL;
1141 Handle item;
1142 Str255 text;
1143 if (!PyArg_ParseTuple(_args, "O&O&",
1144 ResObj_Convert, &item,
1145 PyMac_GetStr255, text))
1146 return NULL;
1147 SetDialogItemText(item,
1148 text);
1149 Py_INCREF(Py_None);
1150 _res = Py_None;
1151 return _res;
1154 static PyObject *Dlg_GetAlertStage(_self, _args)
1155 PyObject *_self;
1156 PyObject *_args;
1158 PyObject *_res = NULL;
1159 SInt16 _rv;
1160 if (!PyArg_ParseTuple(_args, ""))
1161 return NULL;
1162 _rv = GetAlertStage();
1163 _res = Py_BuildValue("h",
1164 _rv);
1165 return _res;
1168 static PyObject *Dlg_SetDialogFont(_self, _args)
1169 PyObject *_self;
1170 PyObject *_args;
1172 PyObject *_res = NULL;
1173 SInt16 fontNum;
1174 if (!PyArg_ParseTuple(_args, "h",
1175 &fontNum))
1176 return NULL;
1177 SetDialogFont(fontNum);
1178 Py_INCREF(Py_None);
1179 _res = Py_None;
1180 return _res;
1183 static PyObject *Dlg_ResetAlertStage(_self, _args)
1184 PyObject *_self;
1185 PyObject *_args;
1187 PyObject *_res = NULL;
1188 if (!PyArg_ParseTuple(_args, ""))
1189 return NULL;
1190 ResetAlertStage();
1191 Py_INCREF(Py_None);
1192 _res = Py_None;
1193 return _res;
1196 static PyObject *Dlg_NewFeaturesDialog(_self, _args)
1197 PyObject *_self;
1198 PyObject *_args;
1200 PyObject *_res = NULL;
1201 DialogPtr _rv;
1202 Rect inBoundsRect;
1203 Str255 inTitle;
1204 Boolean inIsVisible;
1205 SInt16 inProcID;
1206 WindowPtr inBehind;
1207 Boolean inGoAwayFlag;
1208 SInt32 inRefCon;
1209 Handle inItemListHandle;
1210 UInt32 inFlags;
1211 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
1212 PyMac_GetRect, &inBoundsRect,
1213 PyMac_GetStr255, inTitle,
1214 &inIsVisible,
1215 &inProcID,
1216 WinObj_Convert, &inBehind,
1217 &inGoAwayFlag,
1218 &inRefCon,
1219 ResObj_Convert, &inItemListHandle,
1220 &inFlags))
1221 return NULL;
1222 _rv = NewFeaturesDialog((void *)0,
1223 &inBoundsRect,
1224 inTitle,
1225 inIsVisible,
1226 inProcID,
1227 inBehind,
1228 inGoAwayFlag,
1229 inRefCon,
1230 inItemListHandle,
1231 inFlags);
1232 _res = Py_BuildValue("O&",
1233 DlgObj_New, _rv);
1234 return _res;
1237 static PyObject *Dlg_SetUserItemHandler(_self, _args)
1238 PyObject *_self;
1239 PyObject *_args;
1241 PyObject *_res = NULL;
1243 PyObject *new = NULL;
1246 if (!PyArg_ParseTuple(_args, "|O", &new))
1247 return NULL;
1249 if (Dlg_UserItemProc_callback && new && new != Py_None) {
1250 PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
1251 return NULL;
1254 if (new == Py_None) {
1255 new = NULL;
1256 _res = Py_None;
1257 Py_INCREF(Py_None);
1258 } else {
1259 Py_INCREF(new);
1260 _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc));
1263 Dlg_UserItemProc_callback = new;
1264 return _res;
1268 static PyMethodDef Dlg_methods[] = {
1269 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
1270 "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
1271 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
1272 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1273 {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
1274 "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
1275 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
1276 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
1277 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
1278 "(EventRecord theEvent) -> (Boolean _rv)"},
1279 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
1280 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
1281 {"Alert", (PyCFunction)Dlg_Alert, 1,
1282 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1283 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
1284 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1285 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
1286 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1287 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
1288 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1289 {"ParamText", (PyCFunction)Dlg_ParamText, 1,
1290 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1291 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
1292 "(Handle item) -> (Str255 text)"},
1293 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
1294 "(Handle item, Str255 text) -> None"},
1295 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
1296 "() -> (SInt16 _rv)"},
1297 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
1298 "(SInt16 fontNum) -> None"},
1299 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
1300 "() -> None"},
1301 {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
1302 "(Rect inBoundsRect, Str255 inTitle, Boolean inIsVisible, SInt16 inProcID, WindowPtr inBehind, Boolean inGoAwayFlag, SInt32 inRefCon, Handle inItemListHandle, UInt32 inFlags) -> (DialogPtr _rv)"},
1303 {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
1304 NULL},
1305 {NULL, NULL, 0}
1311 void initDlg()
1313 PyObject *m;
1314 PyObject *d;
1319 m = Py_InitModule("Dlg", Dlg_methods);
1320 d = PyModule_GetDict(m);
1321 Dlg_Error = PyMac_GetOSErrException();
1322 if (Dlg_Error == NULL ||
1323 PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
1324 Py_FatalError("can't initialize Dlg.Error");
1325 Dialog_Type.ob_type = &PyType_Type;
1326 Py_INCREF(&Dialog_Type);
1327 if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0)
1328 Py_FatalError("can't initialize DialogType");
1331 /* ========================= End module Dlg ========================= */