Updated for hfsplus module, new gusi libs.
[python/dscho.git] / Mac / Modules / dlg / _Dlgmodule.c
blob8a0dd4fb0c32326cd7a2cfb26ec20f69a907e673
2 /* ========================== Module _Dlg =========================== */
4 #include "Python.h"
8 #include "macglue.h"
9 #include "pymactoolbox.h"
11 /* Macro to test whether a weak-loaded CFM function exists */
12 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
13 PyErr_SetString(PyExc_NotImplementedError, \
14 "Not available in this shared library/OS version"); \
15 return NULL; \
16 }} while(0)
19 #ifdef WITHOUT_FRAMEWORKS
20 #include <Dialogs.h>
21 #else
22 #include <Carbon/Carbon.h>
23 #endif
25 #ifdef USE_TOOLBOX_OBJECT_GLUE
26 extern PyObject *_DlgObj_New(DialogRef);
27 extern PyObject *_DlgObj_WhichDialog(DialogRef);
28 extern int _DlgObj_Convert(PyObject *, DialogRef *);
30 #define DlgObj_New _DlgObj_New
31 #define DlgObj_WhichDialog _DlgObj_WhichDialog
32 #define DlgObj_Convert _DlgObj_Convert
33 #endif
35 #if !ACCESSOR_CALLS_ARE_FUNCTIONS && UNIVERSAL_INTERFACES_VERSION < 0x340
36 #define GetDialogTextEditHandle(dlg) (((DialogPeek)(dlg))->textH)
37 #define SetPortDialogPort(dlg) SetPort(dlg)
38 #define GetDialogPort(dlg) ((CGrafPtr)(dlg))
39 #define GetDialogFromWindow(win) ((DialogRef)(win))
40 #endif
42 /* XXX Shouldn't this be a stack? */
43 static PyObject *Dlg_FilterProc_callback = NULL;
45 static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog,
46 EventRecord *event,
47 short *itemHit)
49 Boolean rv;
50 PyObject *args, *res;
51 PyObject *callback = Dlg_FilterProc_callback;
52 if (callback == NULL)
53 return 0; /* Default behavior */
54 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
55 args = Py_BuildValue("O&O&", DlgObj_WhichDialog, dialog, PyMac_BuildEventRecord, event);
56 if (args == NULL)
57 res = NULL;
58 else {
59 res = PyEval_CallObject(callback, args);
60 Py_DECREF(args);
62 if (res == NULL) {
63 PySys_WriteStderr("Exception in Dialog Filter\n");
64 PyErr_Print();
65 *itemHit = -1; /* Fake return item */
66 return 1; /* We handled it */
68 else {
69 Dlg_FilterProc_callback = callback;
70 if (PyInt_Check(res)) {
71 *itemHit = PyInt_AsLong(res);
72 rv = 1;
74 else
75 rv = PyObject_IsTrue(res);
77 Py_DECREF(res);
78 return rv;
81 static ModalFilterUPP
82 Dlg_PassFilterProc(PyObject *callback)
84 PyObject *tmp = Dlg_FilterProc_callback;
85 static ModalFilterUPP UnivFilterUpp = NULL;
87 Dlg_FilterProc_callback = NULL;
88 if (callback == Py_None) {
89 Py_XDECREF(tmp);
90 return NULL;
92 Py_INCREF(callback);
93 Dlg_FilterProc_callback = callback;
94 Py_XDECREF(tmp);
95 if ( UnivFilterUpp == NULL )
96 UnivFilterUpp = NewModalFilterUPP(&Dlg_UnivFilterProc);
97 return UnivFilterUpp;
100 static PyObject *Dlg_UserItemProc_callback = NULL;
102 static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
103 short item)
105 PyObject *args, *res;
107 if (Dlg_UserItemProc_callback == NULL)
108 return; /* Default behavior */
109 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
110 args = Py_BuildValue("O&h", DlgObj_WhichDialog, dialog, item);
111 if (args == NULL)
112 res = NULL;
113 else {
114 res = PyEval_CallObject(Dlg_UserItemProc_callback, args);
115 Py_DECREF(args);
117 if (res == NULL) {
118 PySys_WriteStderr("Exception in Dialog UserItem proc\n");
119 PyErr_Print();
121 Py_XDECREF(res);
122 return;
125 #if 0
127 ** Treating DialogObjects as WindowObjects is (I think) illegal under Carbon.
128 ** However, as they are still identical under MacOS9 Carbon this is a problem, even
129 ** if we neatly call GetDialogWindow() at the right places: there's one refcon field
130 ** and it points to the DialogObject, so WinObj_WhichWindow will smartly return the
131 ** dialog object, and therefore we still don't have a WindowObject.
132 ** I'll leave the chaining code in place for now, with this comment to warn the
133 ** unsuspecting victims (i.e. me, probably, in a few weeks:-)
135 extern PyMethodChain WinObj_chain;
136 #endif
138 static PyObject *Dlg_Error;
140 /* ----------------------- Object type Dialog ----------------------- */
142 PyTypeObject Dialog_Type;
144 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
146 typedef struct DialogObject {
147 PyObject_HEAD
148 DialogPtr ob_itself;
149 } DialogObject;
151 PyObject *DlgObj_New(DialogPtr itself)
153 DialogObject *it;
154 if (itself == NULL) return Py_None;
155 it = PyObject_NEW(DialogObject, &Dialog_Type);
156 if (it == NULL) return NULL;
157 it->ob_itself = itself;
158 SetWRefCon(GetDialogWindow(itself), (long)it);
159 return (PyObject *)it;
161 int DlgObj_Convert(PyObject *v, DialogPtr *p_itself)
163 if (v == Py_None) { *p_itself = NULL; return 1; }
164 if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
165 return 1; }
166 if (!DlgObj_Check(v))
168 PyErr_SetString(PyExc_TypeError, "Dialog required");
169 return 0;
171 *p_itself = ((DialogObject *)v)->ob_itself;
172 return 1;
175 static void DlgObj_dealloc(DialogObject *self)
177 DisposeDialog(self->ob_itself);
178 PyMem_DEL(self);
181 static PyObject *DlgObj_DrawDialog(DialogObject *_self, PyObject *_args)
183 PyObject *_res = NULL;
184 #ifndef DrawDialog
185 PyMac_PRECHECK(DrawDialog);
186 #endif
187 if (!PyArg_ParseTuple(_args, ""))
188 return NULL;
189 DrawDialog(_self->ob_itself);
190 Py_INCREF(Py_None);
191 _res = Py_None;
192 return _res;
195 static PyObject *DlgObj_UpdateDialog(DialogObject *_self, PyObject *_args)
197 PyObject *_res = NULL;
198 RgnHandle updateRgn;
199 #ifndef UpdateDialog
200 PyMac_PRECHECK(UpdateDialog);
201 #endif
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(DialogObject *_self, PyObject *_args)
214 PyObject *_res = NULL;
215 DialogItemIndex itemNo;
216 #ifndef HideDialogItem
217 PyMac_PRECHECK(HideDialogItem);
218 #endif
219 if (!PyArg_ParseTuple(_args, "h",
220 &itemNo))
221 return NULL;
222 HideDialogItem(_self->ob_itself,
223 itemNo);
224 Py_INCREF(Py_None);
225 _res = Py_None;
226 return _res;
229 static PyObject *DlgObj_ShowDialogItem(DialogObject *_self, PyObject *_args)
231 PyObject *_res = NULL;
232 DialogItemIndex itemNo;
233 #ifndef ShowDialogItem
234 PyMac_PRECHECK(ShowDialogItem);
235 #endif
236 if (!PyArg_ParseTuple(_args, "h",
237 &itemNo))
238 return NULL;
239 ShowDialogItem(_self->ob_itself,
240 itemNo);
241 Py_INCREF(Py_None);
242 _res = Py_None;
243 return _res;
246 static PyObject *DlgObj_FindDialogItem(DialogObject *_self, PyObject *_args)
248 PyObject *_res = NULL;
249 DialogItemIndexZeroBased _rv;
250 Point thePt;
251 #ifndef FindDialogItem
252 PyMac_PRECHECK(FindDialogItem);
253 #endif
254 if (!PyArg_ParseTuple(_args, "O&",
255 PyMac_GetPoint, &thePt))
256 return NULL;
257 _rv = FindDialogItem(_self->ob_itself,
258 thePt);
259 _res = Py_BuildValue("h",
260 _rv);
261 return _res;
264 static PyObject *DlgObj_DialogCut(DialogObject *_self, PyObject *_args)
266 PyObject *_res = NULL;
267 #ifndef DialogCut
268 PyMac_PRECHECK(DialogCut);
269 #endif
270 if (!PyArg_ParseTuple(_args, ""))
271 return NULL;
272 DialogCut(_self->ob_itself);
273 Py_INCREF(Py_None);
274 _res = Py_None;
275 return _res;
278 static PyObject *DlgObj_DialogPaste(DialogObject *_self, PyObject *_args)
280 PyObject *_res = NULL;
281 #ifndef DialogPaste
282 PyMac_PRECHECK(DialogPaste);
283 #endif
284 if (!PyArg_ParseTuple(_args, ""))
285 return NULL;
286 DialogPaste(_self->ob_itself);
287 Py_INCREF(Py_None);
288 _res = Py_None;
289 return _res;
292 static PyObject *DlgObj_DialogCopy(DialogObject *_self, PyObject *_args)
294 PyObject *_res = NULL;
295 #ifndef DialogCopy
296 PyMac_PRECHECK(DialogCopy);
297 #endif
298 if (!PyArg_ParseTuple(_args, ""))
299 return NULL;
300 DialogCopy(_self->ob_itself);
301 Py_INCREF(Py_None);
302 _res = Py_None;
303 return _res;
306 static PyObject *DlgObj_DialogDelete(DialogObject *_self, PyObject *_args)
308 PyObject *_res = NULL;
309 #ifndef DialogDelete
310 PyMac_PRECHECK(DialogDelete);
311 #endif
312 if (!PyArg_ParseTuple(_args, ""))
313 return NULL;
314 DialogDelete(_self->ob_itself);
315 Py_INCREF(Py_None);
316 _res = Py_None;
317 return _res;
320 static PyObject *DlgObj_GetDialogItem(DialogObject *_self, PyObject *_args)
322 PyObject *_res = NULL;
323 DialogItemIndex itemNo;
324 DialogItemType itemType;
325 Handle item;
326 Rect box;
327 #ifndef GetDialogItem
328 PyMac_PRECHECK(GetDialogItem);
329 #endif
330 if (!PyArg_ParseTuple(_args, "h",
331 &itemNo))
332 return NULL;
333 GetDialogItem(_self->ob_itself,
334 itemNo,
335 &itemType,
336 &item,
337 &box);
338 _res = Py_BuildValue("hO&O&",
339 itemType,
340 OptResObj_New, item,
341 PyMac_BuildRect, &box);
342 return _res;
345 static PyObject *DlgObj_SetDialogItem(DialogObject *_self, PyObject *_args)
347 PyObject *_res = NULL;
348 DialogItemIndex itemNo;
349 DialogItemType itemType;
350 Handle item;
351 Rect box;
352 #ifndef SetDialogItem
353 PyMac_PRECHECK(SetDialogItem);
354 #endif
355 if (!PyArg_ParseTuple(_args, "hhO&O&",
356 &itemNo,
357 &itemType,
358 ResObj_Convert, &item,
359 PyMac_GetRect, &box))
360 return NULL;
361 SetDialogItem(_self->ob_itself,
362 itemNo,
363 itemType,
364 item,
365 &box);
366 Py_INCREF(Py_None);
367 _res = Py_None;
368 return _res;
371 static PyObject *DlgObj_SelectDialogItemText(DialogObject *_self, PyObject *_args)
373 PyObject *_res = NULL;
374 DialogItemIndex itemNo;
375 SInt16 strtSel;
376 SInt16 endSel;
377 #ifndef SelectDialogItemText
378 PyMac_PRECHECK(SelectDialogItemText);
379 #endif
380 if (!PyArg_ParseTuple(_args, "hhh",
381 &itemNo,
382 &strtSel,
383 &endSel))
384 return NULL;
385 SelectDialogItemText(_self->ob_itself,
386 itemNo,
387 strtSel,
388 endSel);
389 Py_INCREF(Py_None);
390 _res = Py_None;
391 return _res;
394 static PyObject *DlgObj_AppendDITL(DialogObject *_self, PyObject *_args)
396 PyObject *_res = NULL;
397 Handle theHandle;
398 DITLMethod method;
399 #ifndef AppendDITL
400 PyMac_PRECHECK(AppendDITL);
401 #endif
402 if (!PyArg_ParseTuple(_args, "O&h",
403 ResObj_Convert, &theHandle,
404 &method))
405 return NULL;
406 AppendDITL(_self->ob_itself,
407 theHandle,
408 method);
409 Py_INCREF(Py_None);
410 _res = Py_None;
411 return _res;
414 static PyObject *DlgObj_CountDITL(DialogObject *_self, PyObject *_args)
416 PyObject *_res = NULL;
417 DialogItemIndex _rv;
418 #ifndef CountDITL
419 PyMac_PRECHECK(CountDITL);
420 #endif
421 if (!PyArg_ParseTuple(_args, ""))
422 return NULL;
423 _rv = CountDITL(_self->ob_itself);
424 _res = Py_BuildValue("h",
425 _rv);
426 return _res;
429 static PyObject *DlgObj_ShortenDITL(DialogObject *_self, PyObject *_args)
431 PyObject *_res = NULL;
432 DialogItemIndex numberItems;
433 #ifndef ShortenDITL
434 PyMac_PRECHECK(ShortenDITL);
435 #endif
436 if (!PyArg_ParseTuple(_args, "h",
437 &numberItems))
438 return NULL;
439 ShortenDITL(_self->ob_itself,
440 numberItems);
441 Py_INCREF(Py_None);
442 _res = Py_None;
443 return _res;
446 #if TARGET_API_MAC_CARBON
448 static PyObject *DlgObj_InsertDialogItem(DialogObject *_self, PyObject *_args)
450 PyObject *_res = NULL;
451 OSStatus _err;
452 DialogItemIndex afterItem;
453 DialogItemType itemType;
454 Handle itemHandle;
455 Rect box;
456 #ifndef InsertDialogItem
457 PyMac_PRECHECK(InsertDialogItem);
458 #endif
459 if (!PyArg_ParseTuple(_args, "hhO&O&",
460 &afterItem,
461 &itemType,
462 ResObj_Convert, &itemHandle,
463 PyMac_GetRect, &box))
464 return NULL;
465 _err = InsertDialogItem(_self->ob_itself,
466 afterItem,
467 itemType,
468 itemHandle,
469 &box);
470 if (_err != noErr) return PyMac_Error(_err);
471 Py_INCREF(Py_None);
472 _res = Py_None;
473 return _res;
475 #endif
477 #if TARGET_API_MAC_CARBON
479 static PyObject *DlgObj_RemoveDialogItems(DialogObject *_self, PyObject *_args)
481 PyObject *_res = NULL;
482 OSStatus _err;
483 DialogItemIndex itemNo;
484 DialogItemIndex amountToRemove;
485 Boolean disposeItemData;
486 #ifndef RemoveDialogItems
487 PyMac_PRECHECK(RemoveDialogItems);
488 #endif
489 if (!PyArg_ParseTuple(_args, "hhb",
490 &itemNo,
491 &amountToRemove,
492 &disposeItemData))
493 return NULL;
494 _err = RemoveDialogItems(_self->ob_itself,
495 itemNo,
496 amountToRemove,
497 disposeItemData);
498 if (_err != noErr) return PyMac_Error(_err);
499 Py_INCREF(Py_None);
500 _res = Py_None;
501 return _res;
503 #endif
505 static PyObject *DlgObj_StdFilterProc(DialogObject *_self, PyObject *_args)
507 PyObject *_res = NULL;
508 Boolean _rv;
509 EventRecord event;
510 DialogItemIndex itemHit;
511 #ifndef StdFilterProc
512 PyMac_PRECHECK(StdFilterProc);
513 #endif
514 if (!PyArg_ParseTuple(_args, ""))
515 return NULL;
516 _rv = StdFilterProc(_self->ob_itself,
517 &event,
518 &itemHit);
519 _res = Py_BuildValue("bO&h",
520 _rv,
521 PyMac_BuildEventRecord, &event,
522 itemHit);
523 return _res;
526 static PyObject *DlgObj_SetDialogDefaultItem(DialogObject *_self, PyObject *_args)
528 PyObject *_res = NULL;
529 OSErr _err;
530 DialogItemIndex newItem;
531 #ifndef SetDialogDefaultItem
532 PyMac_PRECHECK(SetDialogDefaultItem);
533 #endif
534 if (!PyArg_ParseTuple(_args, "h",
535 &newItem))
536 return NULL;
537 _err = SetDialogDefaultItem(_self->ob_itself,
538 newItem);
539 if (_err != noErr) return PyMac_Error(_err);
540 Py_INCREF(Py_None);
541 _res = Py_None;
542 return _res;
545 static PyObject *DlgObj_SetDialogCancelItem(DialogObject *_self, PyObject *_args)
547 PyObject *_res = NULL;
548 OSErr _err;
549 DialogItemIndex newItem;
550 #ifndef SetDialogCancelItem
551 PyMac_PRECHECK(SetDialogCancelItem);
552 #endif
553 if (!PyArg_ParseTuple(_args, "h",
554 &newItem))
555 return NULL;
556 _err = SetDialogCancelItem(_self->ob_itself,
557 newItem);
558 if (_err != noErr) return PyMac_Error(_err);
559 Py_INCREF(Py_None);
560 _res = Py_None;
561 return _res;
564 static PyObject *DlgObj_SetDialogTracksCursor(DialogObject *_self, PyObject *_args)
566 PyObject *_res = NULL;
567 OSErr _err;
568 Boolean tracks;
569 #ifndef SetDialogTracksCursor
570 PyMac_PRECHECK(SetDialogTracksCursor);
571 #endif
572 if (!PyArg_ParseTuple(_args, "b",
573 &tracks))
574 return NULL;
575 _err = SetDialogTracksCursor(_self->ob_itself,
576 tracks);
577 if (_err != noErr) return PyMac_Error(_err);
578 Py_INCREF(Py_None);
579 _res = Py_None;
580 return _res;
583 static PyObject *DlgObj_AutoSizeDialog(DialogObject *_self, PyObject *_args)
585 PyObject *_res = NULL;
586 OSErr _err;
587 #ifndef AutoSizeDialog
588 PyMac_PRECHECK(AutoSizeDialog);
589 #endif
590 if (!PyArg_ParseTuple(_args, ""))
591 return NULL;
592 _err = AutoSizeDialog(_self->ob_itself);
593 if (_err != noErr) return PyMac_Error(_err);
594 Py_INCREF(Py_None);
595 _res = Py_None;
596 return _res;
599 static PyObject *DlgObj_GetDialogItemAsControl(DialogObject *_self, PyObject *_args)
601 PyObject *_res = NULL;
602 OSErr _err;
603 SInt16 inItemNo;
604 ControlHandle outControl;
605 #ifndef GetDialogItemAsControl
606 PyMac_PRECHECK(GetDialogItemAsControl);
607 #endif
608 if (!PyArg_ParseTuple(_args, "h",
609 &inItemNo))
610 return NULL;
611 _err = GetDialogItemAsControl(_self->ob_itself,
612 inItemNo,
613 &outControl);
614 if (_err != noErr) return PyMac_Error(_err);
615 _res = Py_BuildValue("O&",
616 CtlObj_New, outControl);
617 return _res;
620 static PyObject *DlgObj_MoveDialogItem(DialogObject *_self, PyObject *_args)
622 PyObject *_res = NULL;
623 OSErr _err;
624 SInt16 inItemNo;
625 SInt16 inHoriz;
626 SInt16 inVert;
627 #ifndef MoveDialogItem
628 PyMac_PRECHECK(MoveDialogItem);
629 #endif
630 if (!PyArg_ParseTuple(_args, "hhh",
631 &inItemNo,
632 &inHoriz,
633 &inVert))
634 return NULL;
635 _err = MoveDialogItem(_self->ob_itself,
636 inItemNo,
637 inHoriz,
638 inVert);
639 if (_err != noErr) return PyMac_Error(_err);
640 Py_INCREF(Py_None);
641 _res = Py_None;
642 return _res;
645 static PyObject *DlgObj_SizeDialogItem(DialogObject *_self, PyObject *_args)
647 PyObject *_res = NULL;
648 OSErr _err;
649 SInt16 inItemNo;
650 SInt16 inWidth;
651 SInt16 inHeight;
652 #ifndef SizeDialogItem
653 PyMac_PRECHECK(SizeDialogItem);
654 #endif
655 if (!PyArg_ParseTuple(_args, "hhh",
656 &inItemNo,
657 &inWidth,
658 &inHeight))
659 return NULL;
660 _err = SizeDialogItem(_self->ob_itself,
661 inItemNo,
662 inWidth,
663 inHeight);
664 if (_err != noErr) return PyMac_Error(_err);
665 Py_INCREF(Py_None);
666 _res = Py_None;
667 return _res;
670 static PyObject *DlgObj_AppendDialogItemList(DialogObject *_self, PyObject *_args)
672 PyObject *_res = NULL;
673 OSErr _err;
674 SInt16 ditlID;
675 DITLMethod method;
676 #ifndef AppendDialogItemList
677 PyMac_PRECHECK(AppendDialogItemList);
678 #endif
679 if (!PyArg_ParseTuple(_args, "hh",
680 &ditlID,
681 &method))
682 return NULL;
683 _err = AppendDialogItemList(_self->ob_itself,
684 ditlID,
685 method);
686 if (_err != noErr) return PyMac_Error(_err);
687 Py_INCREF(Py_None);
688 _res = Py_None;
689 return _res;
692 static PyObject *DlgObj_SetDialogTimeout(DialogObject *_self, PyObject *_args)
694 PyObject *_res = NULL;
695 OSStatus _err;
696 SInt16 inButtonToPress;
697 UInt32 inSecondsToWait;
698 #ifndef SetDialogTimeout
699 PyMac_PRECHECK(SetDialogTimeout);
700 #endif
701 if (!PyArg_ParseTuple(_args, "hl",
702 &inButtonToPress,
703 &inSecondsToWait))
704 return NULL;
705 _err = SetDialogTimeout(_self->ob_itself,
706 inButtonToPress,
707 inSecondsToWait);
708 if (_err != noErr) return PyMac_Error(_err);
709 Py_INCREF(Py_None);
710 _res = Py_None;
711 return _res;
714 static PyObject *DlgObj_GetDialogTimeout(DialogObject *_self, PyObject *_args)
716 PyObject *_res = NULL;
717 OSStatus _err;
718 SInt16 outButtonToPress;
719 UInt32 outSecondsToWait;
720 UInt32 outSecondsRemaining;
721 #ifndef GetDialogTimeout
722 PyMac_PRECHECK(GetDialogTimeout);
723 #endif
724 if (!PyArg_ParseTuple(_args, ""))
725 return NULL;
726 _err = GetDialogTimeout(_self->ob_itself,
727 &outButtonToPress,
728 &outSecondsToWait,
729 &outSecondsRemaining);
730 if (_err != noErr) return PyMac_Error(_err);
731 _res = Py_BuildValue("hll",
732 outButtonToPress,
733 outSecondsToWait,
734 outSecondsRemaining);
735 return _res;
738 static PyObject *DlgObj_SetModalDialogEventMask(DialogObject *_self, PyObject *_args)
740 PyObject *_res = NULL;
741 OSStatus _err;
742 EventMask inMask;
743 #ifndef SetModalDialogEventMask
744 PyMac_PRECHECK(SetModalDialogEventMask);
745 #endif
746 if (!PyArg_ParseTuple(_args, "H",
747 &inMask))
748 return NULL;
749 _err = SetModalDialogEventMask(_self->ob_itself,
750 inMask);
751 if (_err != noErr) return PyMac_Error(_err);
752 Py_INCREF(Py_None);
753 _res = Py_None;
754 return _res;
757 static PyObject *DlgObj_GetModalDialogEventMask(DialogObject *_self, PyObject *_args)
759 PyObject *_res = NULL;
760 OSStatus _err;
761 EventMask outMask;
762 #ifndef GetModalDialogEventMask
763 PyMac_PRECHECK(GetModalDialogEventMask);
764 #endif
765 if (!PyArg_ParseTuple(_args, ""))
766 return NULL;
767 _err = GetModalDialogEventMask(_self->ob_itself,
768 &outMask);
769 if (_err != noErr) return PyMac_Error(_err);
770 _res = Py_BuildValue("H",
771 outMask);
772 return _res;
775 static PyObject *DlgObj_GetDialogWindow(DialogObject *_self, PyObject *_args)
777 PyObject *_res = NULL;
778 WindowPtr _rv;
779 #ifndef GetDialogWindow
780 PyMac_PRECHECK(GetDialogWindow);
781 #endif
782 if (!PyArg_ParseTuple(_args, ""))
783 return NULL;
784 _rv = GetDialogWindow(_self->ob_itself);
785 _res = Py_BuildValue("O&",
786 WinObj_New, _rv);
787 return _res;
790 static PyObject *DlgObj_GetDialogTextEditHandle(DialogObject *_self, PyObject *_args)
792 PyObject *_res = NULL;
793 TEHandle _rv;
794 #ifndef GetDialogTextEditHandle
795 PyMac_PRECHECK(GetDialogTextEditHandle);
796 #endif
797 if (!PyArg_ParseTuple(_args, ""))
798 return NULL;
799 _rv = GetDialogTextEditHandle(_self->ob_itself);
800 _res = Py_BuildValue("O&",
801 ResObj_New, _rv);
802 return _res;
805 static PyObject *DlgObj_GetDialogDefaultItem(DialogObject *_self, PyObject *_args)
807 PyObject *_res = NULL;
808 SInt16 _rv;
809 #ifndef GetDialogDefaultItem
810 PyMac_PRECHECK(GetDialogDefaultItem);
811 #endif
812 if (!PyArg_ParseTuple(_args, ""))
813 return NULL;
814 _rv = GetDialogDefaultItem(_self->ob_itself);
815 _res = Py_BuildValue("h",
816 _rv);
817 return _res;
820 static PyObject *DlgObj_GetDialogCancelItem(DialogObject *_self, PyObject *_args)
822 PyObject *_res = NULL;
823 SInt16 _rv;
824 #ifndef GetDialogCancelItem
825 PyMac_PRECHECK(GetDialogCancelItem);
826 #endif
827 if (!PyArg_ParseTuple(_args, ""))
828 return NULL;
829 _rv = GetDialogCancelItem(_self->ob_itself);
830 _res = Py_BuildValue("h",
831 _rv);
832 return _res;
835 static PyObject *DlgObj_GetDialogKeyboardFocusItem(DialogObject *_self, PyObject *_args)
837 PyObject *_res = NULL;
838 SInt16 _rv;
839 #ifndef GetDialogKeyboardFocusItem
840 PyMac_PRECHECK(GetDialogKeyboardFocusItem);
841 #endif
842 if (!PyArg_ParseTuple(_args, ""))
843 return NULL;
844 _rv = GetDialogKeyboardFocusItem(_self->ob_itself);
845 _res = Py_BuildValue("h",
846 _rv);
847 return _res;
850 static PyObject *DlgObj_SetPortDialogPort(DialogObject *_self, PyObject *_args)
852 PyObject *_res = NULL;
853 #ifndef SetPortDialogPort
854 PyMac_PRECHECK(SetPortDialogPort);
855 #endif
856 if (!PyArg_ParseTuple(_args, ""))
857 return NULL;
858 SetPortDialogPort(_self->ob_itself);
859 Py_INCREF(Py_None);
860 _res = Py_None;
861 return _res;
864 static PyObject *DlgObj_GetDialogPort(DialogObject *_self, PyObject *_args)
866 PyObject *_res = NULL;
867 CGrafPtr _rv;
868 #ifndef GetDialogPort
869 PyMac_PRECHECK(GetDialogPort);
870 #endif
871 if (!PyArg_ParseTuple(_args, ""))
872 return NULL;
873 _rv = GetDialogPort(_self->ob_itself);
874 _res = Py_BuildValue("O&",
875 GrafObj_New, _rv);
876 return _res;
879 #if !TARGET_API_MAC_CARBON
881 static PyObject *DlgObj_SetGrafPortOfDialog(DialogObject *_self, PyObject *_args)
883 PyObject *_res = NULL;
884 #ifndef SetGrafPortOfDialog
885 PyMac_PRECHECK(SetGrafPortOfDialog);
886 #endif
887 if (!PyArg_ParseTuple(_args, ""))
888 return NULL;
889 SetGrafPortOfDialog(_self->ob_itself);
890 Py_INCREF(Py_None);
891 _res = Py_None;
892 return _res;
894 #endif
896 static PyMethodDef DlgObj_methods[] = {
897 {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
898 "() -> None"},
899 {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
900 "(RgnHandle updateRgn) -> None"},
901 {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
902 "(DialogItemIndex itemNo) -> None"},
903 {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
904 "(DialogItemIndex itemNo) -> None"},
905 {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
906 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
907 {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
908 "() -> None"},
909 {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
910 "() -> None"},
911 {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
912 "() -> None"},
913 {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
914 "() -> None"},
915 {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1,
916 "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"},
917 {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1,
918 "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"},
919 {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1,
920 "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"},
921 {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
922 "(Handle theHandle, DITLMethod method) -> None"},
923 {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
924 "() -> (DialogItemIndex _rv)"},
925 {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
926 "(DialogItemIndex numberItems) -> None"},
928 #if TARGET_API_MAC_CARBON
929 {"InsertDialogItem", (PyCFunction)DlgObj_InsertDialogItem, 1,
930 "(DialogItemIndex afterItem, DialogItemType itemType, Handle itemHandle, Rect box) -> None"},
931 #endif
933 #if TARGET_API_MAC_CARBON
934 {"RemoveDialogItems", (PyCFunction)DlgObj_RemoveDialogItems, 1,
935 "(DialogItemIndex itemNo, DialogItemIndex amountToRemove, Boolean disposeItemData) -> None"},
936 #endif
937 {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
938 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
939 {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
940 "(DialogItemIndex newItem) -> None"},
941 {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
942 "(DialogItemIndex newItem) -> None"},
943 {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
944 "(Boolean tracks) -> None"},
945 {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1,
946 "() -> None"},
947 {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1,
948 "(SInt16 inItemNo) -> (ControlHandle outControl)"},
949 {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1,
950 "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"},
951 {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1,
952 "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"},
953 {"AppendDialogItemList", (PyCFunction)DlgObj_AppendDialogItemList, 1,
954 "(SInt16 ditlID, DITLMethod method) -> None"},
955 {"SetDialogTimeout", (PyCFunction)DlgObj_SetDialogTimeout, 1,
956 "(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None"},
957 {"GetDialogTimeout", (PyCFunction)DlgObj_GetDialogTimeout, 1,
958 "() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)"},
959 {"SetModalDialogEventMask", (PyCFunction)DlgObj_SetModalDialogEventMask, 1,
960 "(EventMask inMask) -> None"},
961 {"GetModalDialogEventMask", (PyCFunction)DlgObj_GetModalDialogEventMask, 1,
962 "() -> (EventMask outMask)"},
963 {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
964 "() -> (WindowPtr _rv)"},
965 {"GetDialogTextEditHandle", (PyCFunction)DlgObj_GetDialogTextEditHandle, 1,
966 "() -> (TEHandle _rv)"},
967 {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1,
968 "() -> (SInt16 _rv)"},
969 {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1,
970 "() -> (SInt16 _rv)"},
971 {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1,
972 "() -> (SInt16 _rv)"},
973 {"SetPortDialogPort", (PyCFunction)DlgObj_SetPortDialogPort, 1,
974 "() -> None"},
975 {"GetDialogPort", (PyCFunction)DlgObj_GetDialogPort, 1,
976 "() -> (CGrafPtr _rv)"},
978 #if !TARGET_API_MAC_CARBON
979 {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1,
980 "() -> None"},
981 #endif
982 {NULL, NULL, 0}
985 PyMethodChain DlgObj_chain = { DlgObj_methods, NULL };
987 static PyObject *DlgObj_getattr(DialogObject *self, char *name)
989 return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name);
992 #define DlgObj_setattr NULL
994 static int DlgObj_compare(DialogObject *self, DialogObject *other)
996 if ( self->ob_itself > other->ob_itself ) return 1;
997 if ( self->ob_itself < other->ob_itself ) return -1;
998 return 0;
1001 #define DlgObj_repr NULL
1003 static int DlgObj_hash(DialogObject *self)
1005 return (int)self->ob_itself;
1008 PyTypeObject Dialog_Type = {
1009 PyObject_HEAD_INIT(NULL)
1010 0, /*ob_size*/
1011 "_Dlg.Dialog", /*tp_name*/
1012 sizeof(DialogObject), /*tp_basicsize*/
1013 0, /*tp_itemsize*/
1014 /* methods */
1015 (destructor) DlgObj_dealloc, /*tp_dealloc*/
1016 0, /*tp_print*/
1017 (getattrfunc) DlgObj_getattr, /*tp_getattr*/
1018 (setattrfunc) DlgObj_setattr, /*tp_setattr*/
1019 (cmpfunc) DlgObj_compare, /*tp_compare*/
1020 (reprfunc) DlgObj_repr, /*tp_repr*/
1021 (PyNumberMethods *)0, /* tp_as_number */
1022 (PySequenceMethods *)0, /* tp_as_sequence */
1023 (PyMappingMethods *)0, /* tp_as_mapping */
1024 (hashfunc) DlgObj_hash, /*tp_hash*/
1027 /* --------------------- End object type Dialog --------------------- */
1030 static PyObject *Dlg_NewDialog(PyObject *_self, PyObject *_args)
1032 PyObject *_res = NULL;
1033 DialogPtr _rv;
1034 Rect boundsRect;
1035 Str255 title;
1036 Boolean visible;
1037 SInt16 procID;
1038 WindowPtr behind;
1039 Boolean goAwayFlag;
1040 SInt32 refCon;
1041 Handle items;
1042 #ifndef NewDialog
1043 PyMac_PRECHECK(NewDialog);
1044 #endif
1045 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
1046 PyMac_GetRect, &boundsRect,
1047 PyMac_GetStr255, title,
1048 &visible,
1049 &procID,
1050 WinObj_Convert, &behind,
1051 &goAwayFlag,
1052 &refCon,
1053 ResObj_Convert, &items))
1054 return NULL;
1055 _rv = NewDialog((void *)0,
1056 &boundsRect,
1057 title,
1058 visible,
1059 procID,
1060 behind,
1061 goAwayFlag,
1062 refCon,
1063 items);
1064 _res = Py_BuildValue("O&",
1065 DlgObj_New, _rv);
1066 return _res;
1069 static PyObject *Dlg_GetNewDialog(PyObject *_self, PyObject *_args)
1071 PyObject *_res = NULL;
1072 DialogPtr _rv;
1073 SInt16 dialogID;
1074 WindowPtr behind;
1075 #ifndef GetNewDialog
1076 PyMac_PRECHECK(GetNewDialog);
1077 #endif
1078 if (!PyArg_ParseTuple(_args, "hO&",
1079 &dialogID,
1080 WinObj_Convert, &behind))
1081 return NULL;
1082 _rv = GetNewDialog(dialogID,
1083 (void *)0,
1084 behind);
1085 _res = Py_BuildValue("O&",
1086 DlgObj_New, _rv);
1087 return _res;
1090 static PyObject *Dlg_NewColorDialog(PyObject *_self, PyObject *_args)
1092 PyObject *_res = NULL;
1093 DialogPtr _rv;
1094 Rect boundsRect;
1095 Str255 title;
1096 Boolean visible;
1097 SInt16 procID;
1098 WindowPtr behind;
1099 Boolean goAwayFlag;
1100 SInt32 refCon;
1101 Handle items;
1102 #ifndef NewColorDialog
1103 PyMac_PRECHECK(NewColorDialog);
1104 #endif
1105 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
1106 PyMac_GetRect, &boundsRect,
1107 PyMac_GetStr255, title,
1108 &visible,
1109 &procID,
1110 WinObj_Convert, &behind,
1111 &goAwayFlag,
1112 &refCon,
1113 ResObj_Convert, &items))
1114 return NULL;
1115 _rv = NewColorDialog((void *)0,
1116 &boundsRect,
1117 title,
1118 visible,
1119 procID,
1120 behind,
1121 goAwayFlag,
1122 refCon,
1123 items);
1124 _res = Py_BuildValue("O&",
1125 DlgObj_New, _rv);
1126 return _res;
1129 static PyObject *Dlg_ModalDialog(PyObject *_self, PyObject *_args)
1131 PyObject *_res = NULL;
1132 PyObject* modalFilter;
1133 DialogItemIndex itemHit;
1134 #ifndef ModalDialog
1135 PyMac_PRECHECK(ModalDialog);
1136 #endif
1137 if (!PyArg_ParseTuple(_args, "O",
1138 &modalFilter))
1139 return NULL;
1140 ModalDialog(Dlg_PassFilterProc(modalFilter),
1141 &itemHit);
1142 _res = Py_BuildValue("h",
1143 itemHit);
1144 return _res;
1147 static PyObject *Dlg_IsDialogEvent(PyObject *_self, PyObject *_args)
1149 PyObject *_res = NULL;
1150 Boolean _rv;
1151 EventRecord theEvent;
1152 #ifndef IsDialogEvent
1153 PyMac_PRECHECK(IsDialogEvent);
1154 #endif
1155 if (!PyArg_ParseTuple(_args, "O&",
1156 PyMac_GetEventRecord, &theEvent))
1157 return NULL;
1158 _rv = IsDialogEvent(&theEvent);
1159 _res = Py_BuildValue("b",
1160 _rv);
1161 return _res;
1164 static PyObject *Dlg_DialogSelect(PyObject *_self, PyObject *_args)
1166 PyObject *_res = NULL;
1167 Boolean _rv;
1168 EventRecord theEvent;
1169 DialogPtr theDialog;
1170 DialogItemIndex itemHit;
1171 #ifndef DialogSelect
1172 PyMac_PRECHECK(DialogSelect);
1173 #endif
1174 if (!PyArg_ParseTuple(_args, "O&",
1175 PyMac_GetEventRecord, &theEvent))
1176 return NULL;
1177 _rv = DialogSelect(&theEvent,
1178 &theDialog,
1179 &itemHit);
1180 _res = Py_BuildValue("bO&h",
1181 _rv,
1182 DlgObj_WhichDialog, theDialog,
1183 itemHit);
1184 return _res;
1187 static PyObject *Dlg_Alert(PyObject *_self, PyObject *_args)
1189 PyObject *_res = NULL;
1190 DialogItemIndex _rv;
1191 SInt16 alertID;
1192 PyObject* modalFilter;
1193 #ifndef Alert
1194 PyMac_PRECHECK(Alert);
1195 #endif
1196 if (!PyArg_ParseTuple(_args, "hO",
1197 &alertID,
1198 &modalFilter))
1199 return NULL;
1200 _rv = Alert(alertID,
1201 Dlg_PassFilterProc(modalFilter));
1202 _res = Py_BuildValue("h",
1203 _rv);
1204 return _res;
1207 static PyObject *Dlg_StopAlert(PyObject *_self, PyObject *_args)
1209 PyObject *_res = NULL;
1210 DialogItemIndex _rv;
1211 SInt16 alertID;
1212 PyObject* modalFilter;
1213 #ifndef StopAlert
1214 PyMac_PRECHECK(StopAlert);
1215 #endif
1216 if (!PyArg_ParseTuple(_args, "hO",
1217 &alertID,
1218 &modalFilter))
1219 return NULL;
1220 _rv = StopAlert(alertID,
1221 Dlg_PassFilterProc(modalFilter));
1222 _res = Py_BuildValue("h",
1223 _rv);
1224 return _res;
1227 static PyObject *Dlg_NoteAlert(PyObject *_self, PyObject *_args)
1229 PyObject *_res = NULL;
1230 DialogItemIndex _rv;
1231 SInt16 alertID;
1232 PyObject* modalFilter;
1233 #ifndef NoteAlert
1234 PyMac_PRECHECK(NoteAlert);
1235 #endif
1236 if (!PyArg_ParseTuple(_args, "hO",
1237 &alertID,
1238 &modalFilter))
1239 return NULL;
1240 _rv = NoteAlert(alertID,
1241 Dlg_PassFilterProc(modalFilter));
1242 _res = Py_BuildValue("h",
1243 _rv);
1244 return _res;
1247 static PyObject *Dlg_CautionAlert(PyObject *_self, PyObject *_args)
1249 PyObject *_res = NULL;
1250 DialogItemIndex _rv;
1251 SInt16 alertID;
1252 PyObject* modalFilter;
1253 #ifndef CautionAlert
1254 PyMac_PRECHECK(CautionAlert);
1255 #endif
1256 if (!PyArg_ParseTuple(_args, "hO",
1257 &alertID,
1258 &modalFilter))
1259 return NULL;
1260 _rv = CautionAlert(alertID,
1261 Dlg_PassFilterProc(modalFilter));
1262 _res = Py_BuildValue("h",
1263 _rv);
1264 return _res;
1267 static PyObject *Dlg_ParamText(PyObject *_self, PyObject *_args)
1269 PyObject *_res = NULL;
1270 Str255 param0;
1271 Str255 param1;
1272 Str255 param2;
1273 Str255 param3;
1274 #ifndef ParamText
1275 PyMac_PRECHECK(ParamText);
1276 #endif
1277 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1278 PyMac_GetStr255, param0,
1279 PyMac_GetStr255, param1,
1280 PyMac_GetStr255, param2,
1281 PyMac_GetStr255, param3))
1282 return NULL;
1283 ParamText(param0,
1284 param1,
1285 param2,
1286 param3);
1287 Py_INCREF(Py_None);
1288 _res = Py_None;
1289 return _res;
1292 static PyObject *Dlg_GetDialogItemText(PyObject *_self, PyObject *_args)
1294 PyObject *_res = NULL;
1295 Handle item;
1296 Str255 text;
1297 #ifndef GetDialogItemText
1298 PyMac_PRECHECK(GetDialogItemText);
1299 #endif
1300 if (!PyArg_ParseTuple(_args, "O&",
1301 ResObj_Convert, &item))
1302 return NULL;
1303 GetDialogItemText(item,
1304 text);
1305 _res = Py_BuildValue("O&",
1306 PyMac_BuildStr255, text);
1307 return _res;
1310 static PyObject *Dlg_SetDialogItemText(PyObject *_self, PyObject *_args)
1312 PyObject *_res = NULL;
1313 Handle item;
1314 Str255 text;
1315 #ifndef SetDialogItemText
1316 PyMac_PRECHECK(SetDialogItemText);
1317 #endif
1318 if (!PyArg_ParseTuple(_args, "O&O&",
1319 ResObj_Convert, &item,
1320 PyMac_GetStr255, text))
1321 return NULL;
1322 SetDialogItemText(item,
1323 text);
1324 Py_INCREF(Py_None);
1325 _res = Py_None;
1326 return _res;
1329 static PyObject *Dlg_GetAlertStage(PyObject *_self, PyObject *_args)
1331 PyObject *_res = NULL;
1332 SInt16 _rv;
1333 #ifndef GetAlertStage
1334 PyMac_PRECHECK(GetAlertStage);
1335 #endif
1336 if (!PyArg_ParseTuple(_args, ""))
1337 return NULL;
1338 _rv = GetAlertStage();
1339 _res = Py_BuildValue("h",
1340 _rv);
1341 return _res;
1344 static PyObject *Dlg_SetDialogFont(PyObject *_self, PyObject *_args)
1346 PyObject *_res = NULL;
1347 SInt16 fontNum;
1348 #ifndef SetDialogFont
1349 PyMac_PRECHECK(SetDialogFont);
1350 #endif
1351 if (!PyArg_ParseTuple(_args, "h",
1352 &fontNum))
1353 return NULL;
1354 SetDialogFont(fontNum);
1355 Py_INCREF(Py_None);
1356 _res = Py_None;
1357 return _res;
1360 static PyObject *Dlg_ResetAlertStage(PyObject *_self, PyObject *_args)
1362 PyObject *_res = NULL;
1363 #ifndef ResetAlertStage
1364 PyMac_PRECHECK(ResetAlertStage);
1365 #endif
1366 if (!PyArg_ParseTuple(_args, ""))
1367 return NULL;
1368 ResetAlertStage();
1369 Py_INCREF(Py_None);
1370 _res = Py_None;
1371 return _res;
1374 #if TARGET_API_MAC_CARBON
1376 static PyObject *Dlg_GetParamText(PyObject *_self, PyObject *_args)
1378 PyObject *_res = NULL;
1379 Str255 param0;
1380 Str255 param1;
1381 Str255 param2;
1382 Str255 param3;
1383 #ifndef GetParamText
1384 PyMac_PRECHECK(GetParamText);
1385 #endif
1386 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1387 PyMac_GetStr255, param0,
1388 PyMac_GetStr255, param1,
1389 PyMac_GetStr255, param2,
1390 PyMac_GetStr255, param3))
1391 return NULL;
1392 GetParamText(param0,
1393 param1,
1394 param2,
1395 param3);
1396 Py_INCREF(Py_None);
1397 _res = Py_None;
1398 return _res;
1400 #endif
1402 static PyObject *Dlg_NewFeaturesDialog(PyObject *_self, PyObject *_args)
1404 PyObject *_res = NULL;
1405 DialogPtr _rv;
1406 Rect inBoundsRect;
1407 Str255 inTitle;
1408 Boolean inIsVisible;
1409 SInt16 inProcID;
1410 WindowPtr inBehind;
1411 Boolean inGoAwayFlag;
1412 SInt32 inRefCon;
1413 Handle inItemListHandle;
1414 UInt32 inFlags;
1415 #ifndef NewFeaturesDialog
1416 PyMac_PRECHECK(NewFeaturesDialog);
1417 #endif
1418 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
1419 PyMac_GetRect, &inBoundsRect,
1420 PyMac_GetStr255, inTitle,
1421 &inIsVisible,
1422 &inProcID,
1423 WinObj_Convert, &inBehind,
1424 &inGoAwayFlag,
1425 &inRefCon,
1426 ResObj_Convert, &inItemListHandle,
1427 &inFlags))
1428 return NULL;
1429 _rv = NewFeaturesDialog((void *)0,
1430 &inBoundsRect,
1431 inTitle,
1432 inIsVisible,
1433 inProcID,
1434 inBehind,
1435 inGoAwayFlag,
1436 inRefCon,
1437 inItemListHandle,
1438 inFlags);
1439 _res = Py_BuildValue("O&",
1440 DlgObj_New, _rv);
1441 return _res;
1444 static PyObject *Dlg_GetDialogFromWindow(PyObject *_self, PyObject *_args)
1446 PyObject *_res = NULL;
1447 DialogPtr _rv;
1448 WindowPtr window;
1449 #ifndef GetDialogFromWindow
1450 PyMac_PRECHECK(GetDialogFromWindow);
1451 #endif
1452 if (!PyArg_ParseTuple(_args, "O&",
1453 WinObj_Convert, &window))
1454 return NULL;
1455 _rv = GetDialogFromWindow(window);
1456 _res = Py_BuildValue("O&",
1457 DlgObj_New, _rv);
1458 return _res;
1461 static PyObject *Dlg_SetUserItemHandler(PyObject *_self, PyObject *_args)
1463 PyObject *_res = NULL;
1465 PyObject *new = NULL;
1468 if (!PyArg_ParseTuple(_args, "|O", &new))
1469 return NULL;
1471 if (Dlg_UserItemProc_callback && new && new != Py_None) {
1472 PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
1473 return NULL;
1476 if (new == NULL || new == Py_None) {
1477 new = NULL;
1478 _res = Py_None;
1479 Py_INCREF(Py_None);
1480 } else {
1481 Py_INCREF(new);
1482 _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemUPP(Dlg_UnivUserItemProc));
1485 Dlg_UserItemProc_callback = new;
1486 return _res;
1490 static PyMethodDef Dlg_methods[] = {
1491 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
1492 "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
1493 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
1494 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1495 {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
1496 "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
1497 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
1498 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
1499 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
1500 "(EventRecord theEvent) -> (Boolean _rv)"},
1501 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
1502 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
1503 {"Alert", (PyCFunction)Dlg_Alert, 1,
1504 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1505 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
1506 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1507 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
1508 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1509 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
1510 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1511 {"ParamText", (PyCFunction)Dlg_ParamText, 1,
1512 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1513 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
1514 "(Handle item) -> (Str255 text)"},
1515 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
1516 "(Handle item, Str255 text) -> None"},
1517 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
1518 "() -> (SInt16 _rv)"},
1519 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
1520 "(SInt16 fontNum) -> None"},
1521 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
1522 "() -> None"},
1524 #if TARGET_API_MAC_CARBON
1525 {"GetParamText", (PyCFunction)Dlg_GetParamText, 1,
1526 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1527 #endif
1528 {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
1529 "(Rect inBoundsRect, Str255 inTitle, Boolean inIsVisible, SInt16 inProcID, WindowPtr inBehind, Boolean inGoAwayFlag, SInt32 inRefCon, Handle inItemListHandle, UInt32 inFlags) -> (DialogPtr _rv)"},
1530 {"GetDialogFromWindow", (PyCFunction)Dlg_GetDialogFromWindow, 1,
1531 "(WindowPtr window) -> (DialogPtr _rv)"},
1532 {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
1533 NULL},
1534 {NULL, NULL, 0}
1539 /* Return the WindowPtr corresponding to a DialogObject */
1540 #if 0
1541 WindowPtr
1542 DlgObj_ConvertToWindow(PyObject *self)
1544 if ( DlgObj_Check(self) )
1545 return GetDialogWindow(((DialogObject *)self)->ob_itself);
1546 return NULL;
1548 #endif
1549 /* Return the object corresponding to the dialog, or None */
1551 PyObject *
1552 DlgObj_WhichDialog(DialogPtr d)
1554 PyObject *it;
1556 if (d == NULL) {
1557 it = Py_None;
1558 Py_INCREF(it);
1559 } else {
1560 WindowPtr w = GetDialogWindow(d);
1562 it = (PyObject *) GetWRefCon(w);
1563 if (it == NULL || ((DialogObject *)it)->ob_itself != d || !DlgObj_Check(it)) {
1564 #if 0
1565 /* Should do this, but we don't have an ob_freeit for dialogs yet. */
1566 it = WinObj_New(w);
1567 ((WindowObject *)it)->ob_freeit = NULL;
1568 #else
1569 it = Py_None;
1570 Py_INCREF(it);
1571 #endif
1572 } else {
1573 Py_INCREF(it);
1576 return it;
1580 void init_Dlg(void)
1582 PyObject *m;
1583 PyObject *d;
1587 PyMac_INIT_TOOLBOX_OBJECT_NEW(DialogPtr, DlgObj_New);
1588 PyMac_INIT_TOOLBOX_OBJECT_NEW(DialogPtr, DlgObj_WhichDialog);
1589 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DialogPtr, DlgObj_Convert);
1592 m = Py_InitModule("_Dlg", Dlg_methods);
1593 d = PyModule_GetDict(m);
1594 Dlg_Error = PyMac_GetOSErrException();
1595 if (Dlg_Error == NULL ||
1596 PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
1597 return;
1598 Dialog_Type.ob_type = &PyType_Type;
1599 Py_INCREF(&Dialog_Type);
1600 if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0)
1601 Py_FatalError("can't initialize DialogType");
1604 /* ======================== End module _Dlg ========================= */