Apparently the code to forestall Tk eating events was too aggressive (Tk user input...
[python/dscho.git] / Mac / Modules / dlg / Dlgmodule.c
blob2262b544e678b70fbf63434e8ba89bfbc752f545
2 /* =========================== Module Dlg =========================== */
4 #include "Python.h"
8 #include "macglue.h"
9 #include "pymactoolbox.h"
11 #include <Dialogs.h>
13 #if !ACCESSOR_CALLS_ARE_FUNCTIONS
14 #define GetDialogTextEditHandle(dlg) (((DialogPeek)(dlg))->textH)
15 #define SetPortDialogPort(dlg) SetPort(dlg)
16 #define GetDialogPort(dlg) ((CGrafPtr)(dlg))
17 #define GetDialogFromWindow(win) ((DialogRef)(win))
18 #endif
20 /* XXX Shouldn't this be a stack? */
21 static PyObject *Dlg_FilterProc_callback = NULL;
23 static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog,
24 EventRecord *event,
25 short *itemHit)
27 Boolean rv;
28 PyObject *args, *res;
29 PyObject *callback = Dlg_FilterProc_callback;
30 if (callback == NULL)
31 return 0; /* Default behavior */
32 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
33 args = Py_BuildValue("O&O&", DlgObj_WhichDialog, dialog, PyMac_BuildEventRecord, event);
34 if (args == NULL)
35 res = NULL;
36 else {
37 res = PyEval_CallObject(callback, args);
38 Py_DECREF(args);
40 if (res == NULL) {
41 PySys_WriteStderr("Exception in Dialog Filter\n");
42 PyErr_Print();
43 *itemHit = -1; /* Fake return item */
44 return 1; /* We handled it */
46 else {
47 Dlg_FilterProc_callback = callback;
48 if (PyInt_Check(res)) {
49 *itemHit = PyInt_AsLong(res);
50 rv = 1;
52 else
53 rv = PyObject_IsTrue(res);
55 Py_DECREF(res);
56 return rv;
59 static ModalFilterUPP
60 Dlg_PassFilterProc(PyObject *callback)
62 PyObject *tmp = Dlg_FilterProc_callback;
63 static ModalFilterUPP UnivFilterUpp = NULL;
65 Dlg_FilterProc_callback = NULL;
66 if (callback == Py_None) {
67 Py_XDECREF(tmp);
68 return NULL;
70 Py_INCREF(callback);
71 Dlg_FilterProc_callback = callback;
72 Py_XDECREF(tmp);
73 if ( UnivFilterUpp == NULL )
74 UnivFilterUpp = NewModalFilterUPP(&Dlg_UnivFilterProc);
75 return UnivFilterUpp;
78 static PyObject *Dlg_UserItemProc_callback = NULL;
80 static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
81 short item)
83 PyObject *args, *res;
85 if (Dlg_UserItemProc_callback == NULL)
86 return; /* Default behavior */
87 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
88 args = Py_BuildValue("O&h", DlgObj_WhichDialog, dialog, item);
89 if (args == NULL)
90 res = NULL;
91 else {
92 res = PyEval_CallObject(Dlg_UserItemProc_callback, args);
93 Py_DECREF(args);
95 if (res == NULL) {
96 PySys_WriteStderr("Exception in Dialog UserItem proc\n");
97 PyErr_Print();
99 Py_XDECREF(res);
100 return;
103 #if 0
105 ** Treating DialogObjects as WindowObjects is (I think) illegal under Carbon.
106 ** However, as they are still identical under MacOS9 Carbon this is a problem, even
107 ** if we neatly call GetDialogWindow() at the right places: there's one refcon field
108 ** and it points to the DialogObject, so WinObj_WhichWindow will smartly return the
109 ** dialog object, and therefore we still don't have a WindowObject.
110 ** I'll leave the chaining code in place for now, with this comment to warn the
111 ** unsuspecting victims (i.e. me, probably, in a few weeks:-)
113 extern PyMethodChain WinObj_chain;
114 #endif
116 static PyObject *Dlg_Error;
118 /* ----------------------- Object type Dialog ----------------------- */
120 PyTypeObject Dialog_Type;
122 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
124 typedef struct DialogObject {
125 PyObject_HEAD
126 DialogPtr ob_itself;
127 } DialogObject;
129 PyObject *DlgObj_New(itself)
130 DialogPtr itself;
132 DialogObject *it;
133 if (itself == NULL) return Py_None;
134 it = PyObject_NEW(DialogObject, &Dialog_Type);
135 if (it == NULL) return NULL;
136 it->ob_itself = itself;
137 SetWRefCon(GetDialogWindow(itself), (long)it);
138 return (PyObject *)it;
140 DlgObj_Convert(v, p_itself)
141 PyObject *v;
142 DialogPtr *p_itself;
144 if (v == Py_None) { *p_itself = NULL; return 1; }
145 if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
146 return 1; }
147 if (!DlgObj_Check(v))
149 PyErr_SetString(PyExc_TypeError, "Dialog required");
150 return 0;
152 *p_itself = ((DialogObject *)v)->ob_itself;
153 return 1;
156 static void DlgObj_dealloc(self)
157 DialogObject *self;
159 DisposeDialog(self->ob_itself);
160 PyMem_DEL(self);
163 static PyObject *DlgObj_DrawDialog(_self, _args)
164 DialogObject *_self;
165 PyObject *_args;
167 PyObject *_res = NULL;
168 if (!PyArg_ParseTuple(_args, ""))
169 return NULL;
170 DrawDialog(_self->ob_itself);
171 Py_INCREF(Py_None);
172 _res = Py_None;
173 return _res;
176 static PyObject *DlgObj_UpdateDialog(_self, _args)
177 DialogObject *_self;
178 PyObject *_args;
180 PyObject *_res = NULL;
181 RgnHandle updateRgn;
182 if (!PyArg_ParseTuple(_args, "O&",
183 ResObj_Convert, &updateRgn))
184 return NULL;
185 UpdateDialog(_self->ob_itself,
186 updateRgn);
187 Py_INCREF(Py_None);
188 _res = Py_None;
189 return _res;
192 static PyObject *DlgObj_HideDialogItem(_self, _args)
193 DialogObject *_self;
194 PyObject *_args;
196 PyObject *_res = NULL;
197 DialogItemIndex itemNo;
198 if (!PyArg_ParseTuple(_args, "h",
199 &itemNo))
200 return NULL;
201 HideDialogItem(_self->ob_itself,
202 itemNo);
203 Py_INCREF(Py_None);
204 _res = Py_None;
205 return _res;
208 static PyObject *DlgObj_ShowDialogItem(_self, _args)
209 DialogObject *_self;
210 PyObject *_args;
212 PyObject *_res = NULL;
213 DialogItemIndex itemNo;
214 if (!PyArg_ParseTuple(_args, "h",
215 &itemNo))
216 return NULL;
217 ShowDialogItem(_self->ob_itself,
218 itemNo);
219 Py_INCREF(Py_None);
220 _res = Py_None;
221 return _res;
224 static PyObject *DlgObj_FindDialogItem(_self, _args)
225 DialogObject *_self;
226 PyObject *_args;
228 PyObject *_res = NULL;
229 DialogItemIndexZeroBased _rv;
230 Point thePt;
231 if (!PyArg_ParseTuple(_args, "O&",
232 PyMac_GetPoint, &thePt))
233 return NULL;
234 _rv = FindDialogItem(_self->ob_itself,
235 thePt);
236 _res = Py_BuildValue("h",
237 _rv);
238 return _res;
241 static PyObject *DlgObj_DialogCut(_self, _args)
242 DialogObject *_self;
243 PyObject *_args;
245 PyObject *_res = NULL;
246 if (!PyArg_ParseTuple(_args, ""))
247 return NULL;
248 DialogCut(_self->ob_itself);
249 Py_INCREF(Py_None);
250 _res = Py_None;
251 return _res;
254 static PyObject *DlgObj_DialogPaste(_self, _args)
255 DialogObject *_self;
256 PyObject *_args;
258 PyObject *_res = NULL;
259 if (!PyArg_ParseTuple(_args, ""))
260 return NULL;
261 DialogPaste(_self->ob_itself);
262 Py_INCREF(Py_None);
263 _res = Py_None;
264 return _res;
267 static PyObject *DlgObj_DialogCopy(_self, _args)
268 DialogObject *_self;
269 PyObject *_args;
271 PyObject *_res = NULL;
272 if (!PyArg_ParseTuple(_args, ""))
273 return NULL;
274 DialogCopy(_self->ob_itself);
275 Py_INCREF(Py_None);
276 _res = Py_None;
277 return _res;
280 static PyObject *DlgObj_DialogDelete(_self, _args)
281 DialogObject *_self;
282 PyObject *_args;
284 PyObject *_res = NULL;
285 if (!PyArg_ParseTuple(_args, ""))
286 return NULL;
287 DialogDelete(_self->ob_itself);
288 Py_INCREF(Py_None);
289 _res = Py_None;
290 return _res;
293 static PyObject *DlgObj_GetDialogItem(_self, _args)
294 DialogObject *_self;
295 PyObject *_args;
297 PyObject *_res = NULL;
298 DialogItemIndex itemNo;
299 DialogItemType itemType;
300 Handle item;
301 Rect box;
302 if (!PyArg_ParseTuple(_args, "h",
303 &itemNo))
304 return NULL;
305 GetDialogItem(_self->ob_itself,
306 itemNo,
307 &itemType,
308 &item,
309 &box);
310 _res = Py_BuildValue("hO&O&",
311 itemType,
312 OptResObj_New, item,
313 PyMac_BuildRect, &box);
314 return _res;
317 static PyObject *DlgObj_SetDialogItem(_self, _args)
318 DialogObject *_self;
319 PyObject *_args;
321 PyObject *_res = NULL;
322 DialogItemIndex itemNo;
323 DialogItemType itemType;
324 Handle item;
325 Rect box;
326 if (!PyArg_ParseTuple(_args, "hhO&O&",
327 &itemNo,
328 &itemType,
329 ResObj_Convert, &item,
330 PyMac_GetRect, &box))
331 return NULL;
332 SetDialogItem(_self->ob_itself,
333 itemNo,
334 itemType,
335 item,
336 &box);
337 Py_INCREF(Py_None);
338 _res = Py_None;
339 return _res;
342 static PyObject *DlgObj_SelectDialogItemText(_self, _args)
343 DialogObject *_self;
344 PyObject *_args;
346 PyObject *_res = NULL;
347 DialogItemIndex itemNo;
348 SInt16 strtSel;
349 SInt16 endSel;
350 if (!PyArg_ParseTuple(_args, "hhh",
351 &itemNo,
352 &strtSel,
353 &endSel))
354 return NULL;
355 SelectDialogItemText(_self->ob_itself,
356 itemNo,
357 strtSel,
358 endSel);
359 Py_INCREF(Py_None);
360 _res = Py_None;
361 return _res;
364 static PyObject *DlgObj_AppendDITL(_self, _args)
365 DialogObject *_self;
366 PyObject *_args;
368 PyObject *_res = NULL;
369 Handle theHandle;
370 DITLMethod method;
371 if (!PyArg_ParseTuple(_args, "O&h",
372 ResObj_Convert, &theHandle,
373 &method))
374 return NULL;
375 AppendDITL(_self->ob_itself,
376 theHandle,
377 method);
378 Py_INCREF(Py_None);
379 _res = Py_None;
380 return _res;
383 static PyObject *DlgObj_CountDITL(_self, _args)
384 DialogObject *_self;
385 PyObject *_args;
387 PyObject *_res = NULL;
388 DialogItemIndex _rv;
389 if (!PyArg_ParseTuple(_args, ""))
390 return NULL;
391 _rv = CountDITL(_self->ob_itself);
392 _res = Py_BuildValue("h",
393 _rv);
394 return _res;
397 static PyObject *DlgObj_ShortenDITL(_self, _args)
398 DialogObject *_self;
399 PyObject *_args;
401 PyObject *_res = NULL;
402 DialogItemIndex numberItems;
403 if (!PyArg_ParseTuple(_args, "h",
404 &numberItems))
405 return NULL;
406 ShortenDITL(_self->ob_itself,
407 numberItems);
408 Py_INCREF(Py_None);
409 _res = Py_None;
410 return _res;
413 #if TARGET_API_MAC_CARBON
415 static PyObject *DlgObj_InsertDialogItem(_self, _args)
416 DialogObject *_self;
417 PyObject *_args;
419 PyObject *_res = NULL;
420 OSStatus _err;
421 DialogItemIndex afterItem;
422 DialogItemType itemType;
423 Handle itemHandle;
424 Rect box;
425 if (!PyArg_ParseTuple(_args, "hhO&O&",
426 &afterItem,
427 &itemType,
428 ResObj_Convert, &itemHandle,
429 PyMac_GetRect, &box))
430 return NULL;
431 _err = InsertDialogItem(_self->ob_itself,
432 afterItem,
433 itemType,
434 itemHandle,
435 &box);
436 if (_err != noErr) return PyMac_Error(_err);
437 Py_INCREF(Py_None);
438 _res = Py_None;
439 return _res;
441 #endif
443 #if TARGET_API_MAC_CARBON
445 static PyObject *DlgObj_RemoveDialogItems(_self, _args)
446 DialogObject *_self;
447 PyObject *_args;
449 PyObject *_res = NULL;
450 OSStatus _err;
451 DialogItemIndex itemNo;
452 DialogItemIndex amountToRemove;
453 Boolean disposeItemData;
454 if (!PyArg_ParseTuple(_args, "hhb",
455 &itemNo,
456 &amountToRemove,
457 &disposeItemData))
458 return NULL;
459 _err = RemoveDialogItems(_self->ob_itself,
460 itemNo,
461 amountToRemove,
462 disposeItemData);
463 if (_err != noErr) return PyMac_Error(_err);
464 Py_INCREF(Py_None);
465 _res = Py_None;
466 return _res;
468 #endif
470 static PyObject *DlgObj_StdFilterProc(_self, _args)
471 DialogObject *_self;
472 PyObject *_args;
474 PyObject *_res = NULL;
475 Boolean _rv;
476 EventRecord event;
477 DialogItemIndex itemHit;
478 if (!PyArg_ParseTuple(_args, ""))
479 return NULL;
480 _rv = StdFilterProc(_self->ob_itself,
481 &event,
482 &itemHit);
483 _res = Py_BuildValue("bO&h",
484 _rv,
485 PyMac_BuildEventRecord, &event,
486 itemHit);
487 return _res;
490 static PyObject *DlgObj_SetDialogDefaultItem(_self, _args)
491 DialogObject *_self;
492 PyObject *_args;
494 PyObject *_res = NULL;
495 OSErr _err;
496 DialogItemIndex newItem;
497 if (!PyArg_ParseTuple(_args, "h",
498 &newItem))
499 return NULL;
500 _err = SetDialogDefaultItem(_self->ob_itself,
501 newItem);
502 if (_err != noErr) return PyMac_Error(_err);
503 Py_INCREF(Py_None);
504 _res = Py_None;
505 return _res;
508 static PyObject *DlgObj_SetDialogCancelItem(_self, _args)
509 DialogObject *_self;
510 PyObject *_args;
512 PyObject *_res = NULL;
513 OSErr _err;
514 DialogItemIndex newItem;
515 if (!PyArg_ParseTuple(_args, "h",
516 &newItem))
517 return NULL;
518 _err = SetDialogCancelItem(_self->ob_itself,
519 newItem);
520 if (_err != noErr) return PyMac_Error(_err);
521 Py_INCREF(Py_None);
522 _res = Py_None;
523 return _res;
526 static PyObject *DlgObj_SetDialogTracksCursor(_self, _args)
527 DialogObject *_self;
528 PyObject *_args;
530 PyObject *_res = NULL;
531 OSErr _err;
532 Boolean tracks;
533 if (!PyArg_ParseTuple(_args, "b",
534 &tracks))
535 return NULL;
536 _err = SetDialogTracksCursor(_self->ob_itself,
537 tracks);
538 if (_err != noErr) return PyMac_Error(_err);
539 Py_INCREF(Py_None);
540 _res = Py_None;
541 return _res;
544 static PyObject *DlgObj_AutoSizeDialog(_self, _args)
545 DialogObject *_self;
546 PyObject *_args;
548 PyObject *_res = NULL;
549 OSErr _err;
550 if (!PyArg_ParseTuple(_args, ""))
551 return NULL;
552 _err = AutoSizeDialog(_self->ob_itself);
553 if (_err != noErr) return PyMac_Error(_err);
554 Py_INCREF(Py_None);
555 _res = Py_None;
556 return _res;
559 static PyObject *DlgObj_GetDialogItemAsControl(_self, _args)
560 DialogObject *_self;
561 PyObject *_args;
563 PyObject *_res = NULL;
564 OSErr _err;
565 SInt16 inItemNo;
566 ControlHandle outControl;
567 if (!PyArg_ParseTuple(_args, "h",
568 &inItemNo))
569 return NULL;
570 _err = GetDialogItemAsControl(_self->ob_itself,
571 inItemNo,
572 &outControl);
573 if (_err != noErr) return PyMac_Error(_err);
574 _res = Py_BuildValue("O&",
575 CtlObj_New, outControl);
576 return _res;
579 static PyObject *DlgObj_MoveDialogItem(_self, _args)
580 DialogObject *_self;
581 PyObject *_args;
583 PyObject *_res = NULL;
584 OSErr _err;
585 SInt16 inItemNo;
586 SInt16 inHoriz;
587 SInt16 inVert;
588 if (!PyArg_ParseTuple(_args, "hhh",
589 &inItemNo,
590 &inHoriz,
591 &inVert))
592 return NULL;
593 _err = MoveDialogItem(_self->ob_itself,
594 inItemNo,
595 inHoriz,
596 inVert);
597 if (_err != noErr) return PyMac_Error(_err);
598 Py_INCREF(Py_None);
599 _res = Py_None;
600 return _res;
603 static PyObject *DlgObj_SizeDialogItem(_self, _args)
604 DialogObject *_self;
605 PyObject *_args;
607 PyObject *_res = NULL;
608 OSErr _err;
609 SInt16 inItemNo;
610 SInt16 inWidth;
611 SInt16 inHeight;
612 if (!PyArg_ParseTuple(_args, "hhh",
613 &inItemNo,
614 &inWidth,
615 &inHeight))
616 return NULL;
617 _err = SizeDialogItem(_self->ob_itself,
618 inItemNo,
619 inWidth,
620 inHeight);
621 if (_err != noErr) return PyMac_Error(_err);
622 Py_INCREF(Py_None);
623 _res = Py_None;
624 return _res;
627 static PyObject *DlgObj_AppendDialogItemList(_self, _args)
628 DialogObject *_self;
629 PyObject *_args;
631 PyObject *_res = NULL;
632 OSErr _err;
633 SInt16 ditlID;
634 DITLMethod method;
635 if (!PyArg_ParseTuple(_args, "hh",
636 &ditlID,
637 &method))
638 return NULL;
639 _err = AppendDialogItemList(_self->ob_itself,
640 ditlID,
641 method);
642 if (_err != noErr) return PyMac_Error(_err);
643 Py_INCREF(Py_None);
644 _res = Py_None;
645 return _res;
648 static PyObject *DlgObj_SetDialogTimeout(_self, _args)
649 DialogObject *_self;
650 PyObject *_args;
652 PyObject *_res = NULL;
653 OSStatus _err;
654 SInt16 inButtonToPress;
655 UInt32 inSecondsToWait;
656 if (!PyArg_ParseTuple(_args, "hl",
657 &inButtonToPress,
658 &inSecondsToWait))
659 return NULL;
660 _err = SetDialogTimeout(_self->ob_itself,
661 inButtonToPress,
662 inSecondsToWait);
663 if (_err != noErr) return PyMac_Error(_err);
664 Py_INCREF(Py_None);
665 _res = Py_None;
666 return _res;
669 static PyObject *DlgObj_GetDialogTimeout(_self, _args)
670 DialogObject *_self;
671 PyObject *_args;
673 PyObject *_res = NULL;
674 OSStatus _err;
675 SInt16 outButtonToPress;
676 UInt32 outSecondsToWait;
677 UInt32 outSecondsRemaining;
678 if (!PyArg_ParseTuple(_args, ""))
679 return NULL;
680 _err = GetDialogTimeout(_self->ob_itself,
681 &outButtonToPress,
682 &outSecondsToWait,
683 &outSecondsRemaining);
684 if (_err != noErr) return PyMac_Error(_err);
685 _res = Py_BuildValue("hll",
686 outButtonToPress,
687 outSecondsToWait,
688 outSecondsRemaining);
689 return _res;
692 static PyObject *DlgObj_SetModalDialogEventMask(_self, _args)
693 DialogObject *_self;
694 PyObject *_args;
696 PyObject *_res = NULL;
697 OSStatus _err;
698 EventMask inMask;
699 if (!PyArg_ParseTuple(_args, "H",
700 &inMask))
701 return NULL;
702 _err = SetModalDialogEventMask(_self->ob_itself,
703 inMask);
704 if (_err != noErr) return PyMac_Error(_err);
705 Py_INCREF(Py_None);
706 _res = Py_None;
707 return _res;
710 static PyObject *DlgObj_GetModalDialogEventMask(_self, _args)
711 DialogObject *_self;
712 PyObject *_args;
714 PyObject *_res = NULL;
715 OSStatus _err;
716 EventMask outMask;
717 if (!PyArg_ParseTuple(_args, ""))
718 return NULL;
719 _err = GetModalDialogEventMask(_self->ob_itself,
720 &outMask);
721 if (_err != noErr) return PyMac_Error(_err);
722 _res = Py_BuildValue("H",
723 outMask);
724 return _res;
727 static PyObject *DlgObj_GetDialogWindow(_self, _args)
728 DialogObject *_self;
729 PyObject *_args;
731 PyObject *_res = NULL;
732 WindowPtr _rv;
733 if (!PyArg_ParseTuple(_args, ""))
734 return NULL;
735 _rv = GetDialogWindow(_self->ob_itself);
736 _res = Py_BuildValue("O&",
737 WinObj_New, _rv);
738 return _res;
741 static PyObject *DlgObj_GetDialogTextEditHandle(_self, _args)
742 DialogObject *_self;
743 PyObject *_args;
745 PyObject *_res = NULL;
746 TEHandle _rv;
747 if (!PyArg_ParseTuple(_args, ""))
748 return NULL;
749 _rv = GetDialogTextEditHandle(_self->ob_itself);
750 _res = Py_BuildValue("O&",
751 ResObj_New, _rv);
752 return _res;
755 static PyObject *DlgObj_GetDialogDefaultItem(_self, _args)
756 DialogObject *_self;
757 PyObject *_args;
759 PyObject *_res = NULL;
760 SInt16 _rv;
761 if (!PyArg_ParseTuple(_args, ""))
762 return NULL;
763 _rv = GetDialogDefaultItem(_self->ob_itself);
764 _res = Py_BuildValue("h",
765 _rv);
766 return _res;
769 static PyObject *DlgObj_GetDialogCancelItem(_self, _args)
770 DialogObject *_self;
771 PyObject *_args;
773 PyObject *_res = NULL;
774 SInt16 _rv;
775 if (!PyArg_ParseTuple(_args, ""))
776 return NULL;
777 _rv = GetDialogCancelItem(_self->ob_itself);
778 _res = Py_BuildValue("h",
779 _rv);
780 return _res;
783 static PyObject *DlgObj_GetDialogKeyboardFocusItem(_self, _args)
784 DialogObject *_self;
785 PyObject *_args;
787 PyObject *_res = NULL;
788 SInt16 _rv;
789 if (!PyArg_ParseTuple(_args, ""))
790 return NULL;
791 _rv = GetDialogKeyboardFocusItem(_self->ob_itself);
792 _res = Py_BuildValue("h",
793 _rv);
794 return _res;
797 static PyObject *DlgObj_SetPortDialogPort(_self, _args)
798 DialogObject *_self;
799 PyObject *_args;
801 PyObject *_res = NULL;
802 if (!PyArg_ParseTuple(_args, ""))
803 return NULL;
804 SetPortDialogPort(_self->ob_itself);
805 Py_INCREF(Py_None);
806 _res = Py_None;
807 return _res;
810 static PyObject *DlgObj_GetDialogPort(_self, _args)
811 DialogObject *_self;
812 PyObject *_args;
814 PyObject *_res = NULL;
815 CGrafPtr _rv;
816 if (!PyArg_ParseTuple(_args, ""))
817 return NULL;
818 _rv = GetDialogPort(_self->ob_itself);
819 _res = Py_BuildValue("O&",
820 GrafObj_New, _rv);
821 return _res;
824 #if !TARGET_API_MAC_CARBON
826 static PyObject *DlgObj_SetGrafPortOfDialog(_self, _args)
827 DialogObject *_self;
828 PyObject *_args;
830 PyObject *_res = NULL;
831 if (!PyArg_ParseTuple(_args, ""))
832 return NULL;
833 SetGrafPortOfDialog(_self->ob_itself);
834 Py_INCREF(Py_None);
835 _res = Py_None;
836 return _res;
838 #endif
840 static PyMethodDef DlgObj_methods[] = {
841 {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
842 "() -> None"},
843 {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
844 "(RgnHandle updateRgn) -> None"},
845 {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
846 "(DialogItemIndex itemNo) -> None"},
847 {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
848 "(DialogItemIndex itemNo) -> None"},
849 {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
850 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
851 {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
852 "() -> None"},
853 {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
854 "() -> None"},
855 {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
856 "() -> None"},
857 {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
858 "() -> None"},
859 {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1,
860 "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"},
861 {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1,
862 "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"},
863 {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1,
864 "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"},
865 {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
866 "(Handle theHandle, DITLMethod method) -> None"},
867 {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
868 "() -> (DialogItemIndex _rv)"},
869 {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
870 "(DialogItemIndex numberItems) -> None"},
872 #if TARGET_API_MAC_CARBON
873 {"InsertDialogItem", (PyCFunction)DlgObj_InsertDialogItem, 1,
874 "(DialogItemIndex afterItem, DialogItemType itemType, Handle itemHandle, Rect box) -> None"},
875 #endif
877 #if TARGET_API_MAC_CARBON
878 {"RemoveDialogItems", (PyCFunction)DlgObj_RemoveDialogItems, 1,
879 "(DialogItemIndex itemNo, DialogItemIndex amountToRemove, Boolean disposeItemData) -> None"},
880 #endif
881 {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
882 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
883 {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
884 "(DialogItemIndex newItem) -> None"},
885 {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
886 "(DialogItemIndex newItem) -> None"},
887 {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
888 "(Boolean tracks) -> None"},
889 {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1,
890 "() -> None"},
891 {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1,
892 "(SInt16 inItemNo) -> (ControlHandle outControl)"},
893 {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1,
894 "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"},
895 {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1,
896 "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"},
897 {"AppendDialogItemList", (PyCFunction)DlgObj_AppendDialogItemList, 1,
898 "(SInt16 ditlID, DITLMethod method) -> None"},
899 {"SetDialogTimeout", (PyCFunction)DlgObj_SetDialogTimeout, 1,
900 "(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None"},
901 {"GetDialogTimeout", (PyCFunction)DlgObj_GetDialogTimeout, 1,
902 "() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)"},
903 {"SetModalDialogEventMask", (PyCFunction)DlgObj_SetModalDialogEventMask, 1,
904 "(EventMask inMask) -> None"},
905 {"GetModalDialogEventMask", (PyCFunction)DlgObj_GetModalDialogEventMask, 1,
906 "() -> (EventMask outMask)"},
907 {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
908 "() -> (WindowPtr _rv)"},
909 {"GetDialogTextEditHandle", (PyCFunction)DlgObj_GetDialogTextEditHandle, 1,
910 "() -> (TEHandle _rv)"},
911 {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1,
912 "() -> (SInt16 _rv)"},
913 {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1,
914 "() -> (SInt16 _rv)"},
915 {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1,
916 "() -> (SInt16 _rv)"},
917 {"SetPortDialogPort", (PyCFunction)DlgObj_SetPortDialogPort, 1,
918 "() -> None"},
919 {"GetDialogPort", (PyCFunction)DlgObj_GetDialogPort, 1,
920 "() -> (CGrafPtr _rv)"},
922 #if !TARGET_API_MAC_CARBON
923 {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1,
924 "() -> None"},
925 #endif
926 {NULL, NULL, 0}
929 PyMethodChain DlgObj_chain = { DlgObj_methods, NULL };
931 static PyObject *DlgObj_getattr(self, name)
932 DialogObject *self;
933 char *name;
935 return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name);
938 #define DlgObj_setattr NULL
940 static int DlgObj_compare(self, other)
941 DialogObject *self, *other;
943 if ( self->ob_itself > other->ob_itself ) return 1;
944 if ( self->ob_itself < other->ob_itself ) return -1;
945 return 0;
948 #define DlgObj_repr NULL
950 static int DlgObj_hash(self)
951 DialogObject *self;
953 return (int)self->ob_itself;
956 PyTypeObject Dialog_Type = {
957 PyObject_HEAD_INIT(&PyType_Type)
958 0, /*ob_size*/
959 "Dialog", /*tp_name*/
960 sizeof(DialogObject), /*tp_basicsize*/
961 0, /*tp_itemsize*/
962 /* methods */
963 (destructor) DlgObj_dealloc, /*tp_dealloc*/
964 0, /*tp_print*/
965 (getattrfunc) DlgObj_getattr, /*tp_getattr*/
966 (setattrfunc) DlgObj_setattr, /*tp_setattr*/
967 (cmpfunc) DlgObj_compare, /*tp_compare*/
968 (reprfunc) DlgObj_repr, /*tp_repr*/
969 (PyNumberMethods *)0, /* tp_as_number */
970 (PySequenceMethods *)0, /* tp_as_sequence */
971 (PyMappingMethods *)0, /* tp_as_mapping */
972 (hashfunc) DlgObj_hash, /*tp_hash*/
975 /* --------------------- End object type Dialog --------------------- */
978 static PyObject *Dlg_NewDialog(_self, _args)
979 PyObject *_self;
980 PyObject *_args;
982 PyObject *_res = NULL;
983 DialogPtr _rv;
984 Rect boundsRect;
985 Str255 title;
986 Boolean visible;
987 SInt16 procID;
988 WindowPtr behind;
989 Boolean goAwayFlag;
990 SInt32 refCon;
991 Handle items;
992 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
993 PyMac_GetRect, &boundsRect,
994 PyMac_GetStr255, title,
995 &visible,
996 &procID,
997 WinObj_Convert, &behind,
998 &goAwayFlag,
999 &refCon,
1000 ResObj_Convert, &items))
1001 return NULL;
1002 _rv = NewDialog((void *)0,
1003 &boundsRect,
1004 title,
1005 visible,
1006 procID,
1007 behind,
1008 goAwayFlag,
1009 refCon,
1010 items);
1011 _res = Py_BuildValue("O&",
1012 DlgObj_New, _rv);
1013 return _res;
1016 static PyObject *Dlg_GetNewDialog(_self, _args)
1017 PyObject *_self;
1018 PyObject *_args;
1020 PyObject *_res = NULL;
1021 DialogPtr _rv;
1022 SInt16 dialogID;
1023 WindowPtr behind;
1024 if (!PyArg_ParseTuple(_args, "hO&",
1025 &dialogID,
1026 WinObj_Convert, &behind))
1027 return NULL;
1028 _rv = GetNewDialog(dialogID,
1029 (void *)0,
1030 behind);
1031 _res = Py_BuildValue("O&",
1032 DlgObj_New, _rv);
1033 return _res;
1036 static PyObject *Dlg_NewColorDialog(_self, _args)
1037 PyObject *_self;
1038 PyObject *_args;
1040 PyObject *_res = NULL;
1041 DialogPtr _rv;
1042 Rect boundsRect;
1043 Str255 title;
1044 Boolean visible;
1045 SInt16 procID;
1046 WindowPtr behind;
1047 Boolean goAwayFlag;
1048 SInt32 refCon;
1049 Handle items;
1050 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
1051 PyMac_GetRect, &boundsRect,
1052 PyMac_GetStr255, title,
1053 &visible,
1054 &procID,
1055 WinObj_Convert, &behind,
1056 &goAwayFlag,
1057 &refCon,
1058 ResObj_Convert, &items))
1059 return NULL;
1060 _rv = NewColorDialog((void *)0,
1061 &boundsRect,
1062 title,
1063 visible,
1064 procID,
1065 behind,
1066 goAwayFlag,
1067 refCon,
1068 items);
1069 _res = Py_BuildValue("O&",
1070 DlgObj_New, _rv);
1071 return _res;
1074 static PyObject *Dlg_ModalDialog(_self, _args)
1075 PyObject *_self;
1076 PyObject *_args;
1078 PyObject *_res = NULL;
1079 PyObject* modalFilter;
1080 DialogItemIndex itemHit;
1081 if (!PyArg_ParseTuple(_args, "O",
1082 &modalFilter))
1083 return NULL;
1084 ModalDialog(Dlg_PassFilterProc(modalFilter),
1085 &itemHit);
1086 _res = Py_BuildValue("h",
1087 itemHit);
1088 return _res;
1091 static PyObject *Dlg_IsDialogEvent(_self, _args)
1092 PyObject *_self;
1093 PyObject *_args;
1095 PyObject *_res = NULL;
1096 Boolean _rv;
1097 EventRecord theEvent;
1098 if (!PyArg_ParseTuple(_args, "O&",
1099 PyMac_GetEventRecord, &theEvent))
1100 return NULL;
1101 _rv = IsDialogEvent(&theEvent);
1102 _res = Py_BuildValue("b",
1103 _rv);
1104 return _res;
1107 static PyObject *Dlg_DialogSelect(_self, _args)
1108 PyObject *_self;
1109 PyObject *_args;
1111 PyObject *_res = NULL;
1112 Boolean _rv;
1113 EventRecord theEvent;
1114 DialogPtr theDialog;
1115 DialogItemIndex itemHit;
1116 if (!PyArg_ParseTuple(_args, "O&",
1117 PyMac_GetEventRecord, &theEvent))
1118 return NULL;
1119 _rv = DialogSelect(&theEvent,
1120 &theDialog,
1121 &itemHit);
1122 _res = Py_BuildValue("bO&h",
1123 _rv,
1124 DlgObj_WhichDialog, theDialog,
1125 itemHit);
1126 return _res;
1129 static PyObject *Dlg_Alert(_self, _args)
1130 PyObject *_self;
1131 PyObject *_args;
1133 PyObject *_res = NULL;
1134 DialogItemIndex _rv;
1135 SInt16 alertID;
1136 PyObject* modalFilter;
1137 if (!PyArg_ParseTuple(_args, "hO",
1138 &alertID,
1139 &modalFilter))
1140 return NULL;
1141 _rv = Alert(alertID,
1142 Dlg_PassFilterProc(modalFilter));
1143 _res = Py_BuildValue("h",
1144 _rv);
1145 return _res;
1148 static PyObject *Dlg_StopAlert(_self, _args)
1149 PyObject *_self;
1150 PyObject *_args;
1152 PyObject *_res = NULL;
1153 DialogItemIndex _rv;
1154 SInt16 alertID;
1155 PyObject* modalFilter;
1156 if (!PyArg_ParseTuple(_args, "hO",
1157 &alertID,
1158 &modalFilter))
1159 return NULL;
1160 _rv = StopAlert(alertID,
1161 Dlg_PassFilterProc(modalFilter));
1162 _res = Py_BuildValue("h",
1163 _rv);
1164 return _res;
1167 static PyObject *Dlg_NoteAlert(_self, _args)
1168 PyObject *_self;
1169 PyObject *_args;
1171 PyObject *_res = NULL;
1172 DialogItemIndex _rv;
1173 SInt16 alertID;
1174 PyObject* modalFilter;
1175 if (!PyArg_ParseTuple(_args, "hO",
1176 &alertID,
1177 &modalFilter))
1178 return NULL;
1179 _rv = NoteAlert(alertID,
1180 Dlg_PassFilterProc(modalFilter));
1181 _res = Py_BuildValue("h",
1182 _rv);
1183 return _res;
1186 static PyObject *Dlg_CautionAlert(_self, _args)
1187 PyObject *_self;
1188 PyObject *_args;
1190 PyObject *_res = NULL;
1191 DialogItemIndex _rv;
1192 SInt16 alertID;
1193 PyObject* modalFilter;
1194 if (!PyArg_ParseTuple(_args, "hO",
1195 &alertID,
1196 &modalFilter))
1197 return NULL;
1198 _rv = CautionAlert(alertID,
1199 Dlg_PassFilterProc(modalFilter));
1200 _res = Py_BuildValue("h",
1201 _rv);
1202 return _res;
1205 static PyObject *Dlg_ParamText(_self, _args)
1206 PyObject *_self;
1207 PyObject *_args;
1209 PyObject *_res = NULL;
1210 Str255 param0;
1211 Str255 param1;
1212 Str255 param2;
1213 Str255 param3;
1214 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1215 PyMac_GetStr255, param0,
1216 PyMac_GetStr255, param1,
1217 PyMac_GetStr255, param2,
1218 PyMac_GetStr255, param3))
1219 return NULL;
1220 ParamText(param0,
1221 param1,
1222 param2,
1223 param3);
1224 Py_INCREF(Py_None);
1225 _res = Py_None;
1226 return _res;
1229 static PyObject *Dlg_GetDialogItemText(_self, _args)
1230 PyObject *_self;
1231 PyObject *_args;
1233 PyObject *_res = NULL;
1234 Handle item;
1235 Str255 text;
1236 if (!PyArg_ParseTuple(_args, "O&",
1237 ResObj_Convert, &item))
1238 return NULL;
1239 GetDialogItemText(item,
1240 text);
1241 _res = Py_BuildValue("O&",
1242 PyMac_BuildStr255, text);
1243 return _res;
1246 static PyObject *Dlg_SetDialogItemText(_self, _args)
1247 PyObject *_self;
1248 PyObject *_args;
1250 PyObject *_res = NULL;
1251 Handle item;
1252 Str255 text;
1253 if (!PyArg_ParseTuple(_args, "O&O&",
1254 ResObj_Convert, &item,
1255 PyMac_GetStr255, text))
1256 return NULL;
1257 SetDialogItemText(item,
1258 text);
1259 Py_INCREF(Py_None);
1260 _res = Py_None;
1261 return _res;
1264 static PyObject *Dlg_GetAlertStage(_self, _args)
1265 PyObject *_self;
1266 PyObject *_args;
1268 PyObject *_res = NULL;
1269 SInt16 _rv;
1270 if (!PyArg_ParseTuple(_args, ""))
1271 return NULL;
1272 _rv = GetAlertStage();
1273 _res = Py_BuildValue("h",
1274 _rv);
1275 return _res;
1278 static PyObject *Dlg_SetDialogFont(_self, _args)
1279 PyObject *_self;
1280 PyObject *_args;
1282 PyObject *_res = NULL;
1283 SInt16 fontNum;
1284 if (!PyArg_ParseTuple(_args, "h",
1285 &fontNum))
1286 return NULL;
1287 SetDialogFont(fontNum);
1288 Py_INCREF(Py_None);
1289 _res = Py_None;
1290 return _res;
1293 static PyObject *Dlg_ResetAlertStage(_self, _args)
1294 PyObject *_self;
1295 PyObject *_args;
1297 PyObject *_res = NULL;
1298 if (!PyArg_ParseTuple(_args, ""))
1299 return NULL;
1300 ResetAlertStage();
1301 Py_INCREF(Py_None);
1302 _res = Py_None;
1303 return _res;
1306 #if TARGET_API_MAC_CARBON
1308 static PyObject *Dlg_GetParamText(_self, _args)
1309 PyObject *_self;
1310 PyObject *_args;
1312 PyObject *_res = NULL;
1313 Str255 param0;
1314 Str255 param1;
1315 Str255 param2;
1316 Str255 param3;
1317 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1318 PyMac_GetStr255, param0,
1319 PyMac_GetStr255, param1,
1320 PyMac_GetStr255, param2,
1321 PyMac_GetStr255, param3))
1322 return NULL;
1323 GetParamText(param0,
1324 param1,
1325 param2,
1326 param3);
1327 Py_INCREF(Py_None);
1328 _res = Py_None;
1329 return _res;
1331 #endif
1333 static PyObject *Dlg_NewFeaturesDialog(_self, _args)
1334 PyObject *_self;
1335 PyObject *_args;
1337 PyObject *_res = NULL;
1338 DialogPtr _rv;
1339 Rect inBoundsRect;
1340 Str255 inTitle;
1341 Boolean inIsVisible;
1342 SInt16 inProcID;
1343 WindowPtr inBehind;
1344 Boolean inGoAwayFlag;
1345 SInt32 inRefCon;
1346 Handle inItemListHandle;
1347 UInt32 inFlags;
1348 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
1349 PyMac_GetRect, &inBoundsRect,
1350 PyMac_GetStr255, inTitle,
1351 &inIsVisible,
1352 &inProcID,
1353 WinObj_Convert, &inBehind,
1354 &inGoAwayFlag,
1355 &inRefCon,
1356 ResObj_Convert, &inItemListHandle,
1357 &inFlags))
1358 return NULL;
1359 _rv = NewFeaturesDialog((void *)0,
1360 &inBoundsRect,
1361 inTitle,
1362 inIsVisible,
1363 inProcID,
1364 inBehind,
1365 inGoAwayFlag,
1366 inRefCon,
1367 inItemListHandle,
1368 inFlags);
1369 _res = Py_BuildValue("O&",
1370 DlgObj_New, _rv);
1371 return _res;
1374 static PyObject *Dlg_GetDialogFromWindow(_self, _args)
1375 PyObject *_self;
1376 PyObject *_args;
1378 PyObject *_res = NULL;
1379 DialogPtr _rv;
1380 WindowPtr window;
1381 if (!PyArg_ParseTuple(_args, "O&",
1382 WinObj_Convert, &window))
1383 return NULL;
1384 _rv = GetDialogFromWindow(window);
1385 _res = Py_BuildValue("O&",
1386 DlgObj_New, _rv);
1387 return _res;
1390 static PyObject *Dlg_SetUserItemHandler(_self, _args)
1391 PyObject *_self;
1392 PyObject *_args;
1394 PyObject *_res = NULL;
1396 PyObject *new = NULL;
1399 if (!PyArg_ParseTuple(_args, "|O", &new))
1400 return NULL;
1402 if (Dlg_UserItemProc_callback && new && new != Py_None) {
1403 PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
1404 return NULL;
1407 if (new == NULL || new == Py_None) {
1408 new = NULL;
1409 _res = Py_None;
1410 Py_INCREF(Py_None);
1411 } else {
1412 Py_INCREF(new);
1413 _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc));
1416 Dlg_UserItemProc_callback = new;
1417 return _res;
1421 static PyMethodDef Dlg_methods[] = {
1422 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
1423 "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
1424 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
1425 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1426 {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
1427 "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
1428 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
1429 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
1430 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
1431 "(EventRecord theEvent) -> (Boolean _rv)"},
1432 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
1433 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
1434 {"Alert", (PyCFunction)Dlg_Alert, 1,
1435 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1436 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
1437 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1438 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
1439 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1440 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
1441 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1442 {"ParamText", (PyCFunction)Dlg_ParamText, 1,
1443 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1444 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
1445 "(Handle item) -> (Str255 text)"},
1446 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
1447 "(Handle item, Str255 text) -> None"},
1448 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
1449 "() -> (SInt16 _rv)"},
1450 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
1451 "(SInt16 fontNum) -> None"},
1452 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
1453 "() -> None"},
1455 #if TARGET_API_MAC_CARBON
1456 {"GetParamText", (PyCFunction)Dlg_GetParamText, 1,
1457 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1458 #endif
1459 {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
1460 "(Rect inBoundsRect, Str255 inTitle, Boolean inIsVisible, SInt16 inProcID, WindowPtr inBehind, Boolean inGoAwayFlag, SInt32 inRefCon, Handle inItemListHandle, UInt32 inFlags) -> (DialogPtr _rv)"},
1461 {"GetDialogFromWindow", (PyCFunction)Dlg_GetDialogFromWindow, 1,
1462 "(WindowPtr window) -> (DialogPtr _rv)"},
1463 {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
1464 NULL},
1465 {NULL, NULL, 0}
1470 /* Return the WindowPtr corresponding to a DialogObject */
1472 WindowPtr
1473 DlgObj_ConvertToWindow(self)
1474 PyObject *self;
1476 if ( DlgObj_Check(self) )
1477 return GetDialogWindow(((DialogObject *)self)->ob_itself);
1478 return NULL;
1480 /* Return the object corresponding to the dialog, or None */
1482 PyObject *
1483 DlgObj_WhichDialog(d)
1484 DialogPtr d;
1486 PyObject *it;
1488 if (d == NULL) {
1489 it = Py_None;
1490 Py_INCREF(it);
1491 } else {
1492 WindowPtr w = GetDialogWindow(d);
1494 it = (PyObject *) GetWRefCon(w);
1495 if (it == NULL || ((DialogObject *)it)->ob_itself != d || !DlgObj_Check(it)) {
1496 #if 0
1497 /* Should do this, but we don't have an ob_freeit for dialogs yet. */
1498 it = WinObj_New(w);
1499 ((WindowObject *)it)->ob_freeit = NULL;
1500 #else
1501 it = Py_None;
1502 Py_INCREF(it);
1503 #endif
1504 } else {
1505 Py_INCREF(it);
1508 return it;
1512 void initDlg()
1514 PyObject *m;
1515 PyObject *d;
1520 m = Py_InitModule("Dlg", Dlg_methods);
1521 d = PyModule_GetDict(m);
1522 Dlg_Error = PyMac_GetOSErrException();
1523 if (Dlg_Error == NULL ||
1524 PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
1525 return;
1526 Dialog_Type.ob_type = &PyType_Type;
1527 Py_INCREF(&Dialog_Type);
1528 if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0)
1529 Py_FatalError("can't initialize DialogType");
1532 /* ========================= End module Dlg ========================= */