Bump version to 0.9.1.
[python/dscho.git] / Mac / Modules / dlg / Dlgmodule.c
blob33ce3909999c78442ec88cea81535af5447a1d68
2 /* =========================== Module Dlg =========================== */
4 #include "Python.h"
8 #include "macglue.h"
9 #include "pymactoolbox.h"
11 #include <Dialogs.h>
13 /* XXX Shouldn't this be a stack? */
14 static PyObject *Dlg_FilterProc_callback = NULL;
16 static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog,
17 EventRecord *event,
18 short *itemHit)
20 Boolean rv;
21 PyObject *args, *res;
22 PyObject *callback = Dlg_FilterProc_callback;
23 if (callback == NULL)
24 return 0; /* Default behavior */
25 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
26 args = Py_BuildValue("O&O&", WinObj_WhichWindow, dialog, PyMac_BuildEventRecord, event);
27 if (args == NULL)
28 res = NULL;
29 else {
30 res = PyEval_CallObject(callback, args);
31 Py_DECREF(args);
33 if (res == NULL) {
34 PySys_WriteStderr("Exception in Dialog Filter\n");
35 PyErr_Print();
36 *itemHit = -1; /* Fake return item */
37 return 1; /* We handled it */
39 else {
40 Dlg_FilterProc_callback = callback;
41 if (PyInt_Check(res)) {
42 *itemHit = PyInt_AsLong(res);
43 rv = 1;
45 else
46 rv = PyObject_IsTrue(res);
48 Py_DECREF(res);
49 return rv;
52 static ModalFilterProcPtr
53 Dlg_PassFilterProc(PyObject *callback)
55 PyObject *tmp = Dlg_FilterProc_callback;
56 Dlg_FilterProc_callback = NULL;
57 if (callback == Py_None) {
58 Py_XDECREF(tmp);
59 return NULL;
61 Py_INCREF(callback);
62 Dlg_FilterProc_callback = callback;
63 Py_XDECREF(tmp);
64 return &Dlg_UnivFilterProc;
67 static PyObject *Dlg_UserItemProc_callback = NULL;
69 static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
70 short item)
72 PyObject *args, *res;
74 if (Dlg_UserItemProc_callback == NULL)
75 return; /* Default behavior */
76 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
77 args = Py_BuildValue("O&h", WinObj_WhichWindow, dialog, item);
78 if (args == NULL)
79 res = NULL;
80 else {
81 res = PyEval_CallObject(Dlg_UserItemProc_callback, args);
82 Py_DECREF(args);
84 if (res == NULL) {
85 PySys_WriteStderr("Exception in Dialog UserItem proc\n");
86 PyErr_Print();
88 Py_XDECREF(res);
89 return;
92 extern PyMethodChain WinObj_chain;
94 static PyObject *Dlg_Error;
96 /* ----------------------- Object type Dialog ----------------------- */
98 PyTypeObject Dialog_Type;
100 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
102 typedef struct DialogObject {
103 PyObject_HEAD
104 DialogPtr ob_itself;
105 } DialogObject;
107 PyObject *DlgObj_New(itself)
108 DialogPtr itself;
110 DialogObject *it;
111 if (itself == NULL) return Py_None;
112 it = PyObject_NEW(DialogObject, &Dialog_Type);
113 if (it == NULL) return NULL;
114 it->ob_itself = itself;
115 SetWRefCon(GetDialogWindow(itself), (long)it);
116 return (PyObject *)it;
118 DlgObj_Convert(v, p_itself)
119 PyObject *v;
120 DialogPtr *p_itself;
122 if (v == Py_None) { *p_itself = NULL; return 1; }
123 if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
124 return 1; }
125 if (!DlgObj_Check(v))
127 PyErr_SetString(PyExc_TypeError, "Dialog required");
128 return 0;
130 *p_itself = ((DialogObject *)v)->ob_itself;
131 return 1;
134 static void DlgObj_dealloc(self)
135 DialogObject *self;
137 DisposeDialog(self->ob_itself);
138 PyMem_DEL(self);
141 static PyObject *DlgObj_DrawDialog(_self, _args)
142 DialogObject *_self;
143 PyObject *_args;
145 PyObject *_res = NULL;
146 if (!PyArg_ParseTuple(_args, ""))
147 return NULL;
148 DrawDialog(_self->ob_itself);
149 Py_INCREF(Py_None);
150 _res = Py_None;
151 return _res;
154 static PyObject *DlgObj_UpdateDialog(_self, _args)
155 DialogObject *_self;
156 PyObject *_args;
158 PyObject *_res = NULL;
159 RgnHandle updateRgn;
160 if (!PyArg_ParseTuple(_args, "O&",
161 ResObj_Convert, &updateRgn))
162 return NULL;
163 UpdateDialog(_self->ob_itself,
164 updateRgn);
165 Py_INCREF(Py_None);
166 _res = Py_None;
167 return _res;
170 static PyObject *DlgObj_HideDialogItem(_self, _args)
171 DialogObject *_self;
172 PyObject *_args;
174 PyObject *_res = NULL;
175 DialogItemIndex itemNo;
176 if (!PyArg_ParseTuple(_args, "h",
177 &itemNo))
178 return NULL;
179 HideDialogItem(_self->ob_itself,
180 itemNo);
181 Py_INCREF(Py_None);
182 _res = Py_None;
183 return _res;
186 static PyObject *DlgObj_ShowDialogItem(_self, _args)
187 DialogObject *_self;
188 PyObject *_args;
190 PyObject *_res = NULL;
191 DialogItemIndex itemNo;
192 if (!PyArg_ParseTuple(_args, "h",
193 &itemNo))
194 return NULL;
195 ShowDialogItem(_self->ob_itself,
196 itemNo);
197 Py_INCREF(Py_None);
198 _res = Py_None;
199 return _res;
202 static PyObject *DlgObj_FindDialogItem(_self, _args)
203 DialogObject *_self;
204 PyObject *_args;
206 PyObject *_res = NULL;
207 DialogItemIndexZeroBased _rv;
208 Point thePt;
209 if (!PyArg_ParseTuple(_args, "O&",
210 PyMac_GetPoint, &thePt))
211 return NULL;
212 _rv = FindDialogItem(_self->ob_itself,
213 thePt);
214 _res = Py_BuildValue("h",
215 _rv);
216 return _res;
219 static PyObject *DlgObj_DialogCut(_self, _args)
220 DialogObject *_self;
221 PyObject *_args;
223 PyObject *_res = NULL;
224 if (!PyArg_ParseTuple(_args, ""))
225 return NULL;
226 DialogCut(_self->ob_itself);
227 Py_INCREF(Py_None);
228 _res = Py_None;
229 return _res;
232 static PyObject *DlgObj_DialogPaste(_self, _args)
233 DialogObject *_self;
234 PyObject *_args;
236 PyObject *_res = NULL;
237 if (!PyArg_ParseTuple(_args, ""))
238 return NULL;
239 DialogPaste(_self->ob_itself);
240 Py_INCREF(Py_None);
241 _res = Py_None;
242 return _res;
245 static PyObject *DlgObj_DialogCopy(_self, _args)
246 DialogObject *_self;
247 PyObject *_args;
249 PyObject *_res = NULL;
250 if (!PyArg_ParseTuple(_args, ""))
251 return NULL;
252 DialogCopy(_self->ob_itself);
253 Py_INCREF(Py_None);
254 _res = Py_None;
255 return _res;
258 static PyObject *DlgObj_DialogDelete(_self, _args)
259 DialogObject *_self;
260 PyObject *_args;
262 PyObject *_res = NULL;
263 if (!PyArg_ParseTuple(_args, ""))
264 return NULL;
265 DialogDelete(_self->ob_itself);
266 Py_INCREF(Py_None);
267 _res = Py_None;
268 return _res;
271 static PyObject *DlgObj_GetDialogItem(_self, _args)
272 DialogObject *_self;
273 PyObject *_args;
275 PyObject *_res = NULL;
276 DialogItemIndex itemNo;
277 DialogItemType itemType;
278 Handle item;
279 Rect box;
280 if (!PyArg_ParseTuple(_args, "h",
281 &itemNo))
282 return NULL;
283 GetDialogItem(_self->ob_itself,
284 itemNo,
285 &itemType,
286 &item,
287 &box);
288 _res = Py_BuildValue("hO&O&",
289 itemType,
290 OptResObj_New, item,
291 PyMac_BuildRect, &box);
292 return _res;
295 static PyObject *DlgObj_SetDialogItem(_self, _args)
296 DialogObject *_self;
297 PyObject *_args;
299 PyObject *_res = NULL;
300 DialogItemIndex itemNo;
301 DialogItemType itemType;
302 Handle item;
303 Rect box;
304 if (!PyArg_ParseTuple(_args, "hhO&O&",
305 &itemNo,
306 &itemType,
307 ResObj_Convert, &item,
308 PyMac_GetRect, &box))
309 return NULL;
310 SetDialogItem(_self->ob_itself,
311 itemNo,
312 itemType,
313 item,
314 &box);
315 Py_INCREF(Py_None);
316 _res = Py_None;
317 return _res;
320 static PyObject *DlgObj_SelectDialogItemText(_self, _args)
321 DialogObject *_self;
322 PyObject *_args;
324 PyObject *_res = NULL;
325 DialogItemIndex itemNo;
326 SInt16 strtSel;
327 SInt16 endSel;
328 if (!PyArg_ParseTuple(_args, "hhh",
329 &itemNo,
330 &strtSel,
331 &endSel))
332 return NULL;
333 SelectDialogItemText(_self->ob_itself,
334 itemNo,
335 strtSel,
336 endSel);
337 Py_INCREF(Py_None);
338 _res = Py_None;
339 return _res;
342 static PyObject *DlgObj_AppendDITL(_self, _args)
343 DialogObject *_self;
344 PyObject *_args;
346 PyObject *_res = NULL;
347 Handle theHandle;
348 DITLMethod method;
349 if (!PyArg_ParseTuple(_args, "O&h",
350 ResObj_Convert, &theHandle,
351 &method))
352 return NULL;
353 AppendDITL(_self->ob_itself,
354 theHandle,
355 method);
356 Py_INCREF(Py_None);
357 _res = Py_None;
358 return _res;
361 static PyObject *DlgObj_CountDITL(_self, _args)
362 DialogObject *_self;
363 PyObject *_args;
365 PyObject *_res = NULL;
366 DialogItemIndex _rv;
367 if (!PyArg_ParseTuple(_args, ""))
368 return NULL;
369 _rv = CountDITL(_self->ob_itself);
370 _res = Py_BuildValue("h",
371 _rv);
372 return _res;
375 static PyObject *DlgObj_ShortenDITL(_self, _args)
376 DialogObject *_self;
377 PyObject *_args;
379 PyObject *_res = NULL;
380 DialogItemIndex numberItems;
381 if (!PyArg_ParseTuple(_args, "h",
382 &numberItems))
383 return NULL;
384 ShortenDITL(_self->ob_itself,
385 numberItems);
386 Py_INCREF(Py_None);
387 _res = Py_None;
388 return _res;
391 static PyObject *DlgObj_StdFilterProc(_self, _args)
392 DialogObject *_self;
393 PyObject *_args;
395 PyObject *_res = NULL;
396 Boolean _rv;
397 EventRecord event;
398 DialogItemIndex itemHit;
399 if (!PyArg_ParseTuple(_args, ""))
400 return NULL;
401 _rv = StdFilterProc(_self->ob_itself,
402 &event,
403 &itemHit);
404 _res = Py_BuildValue("bO&h",
405 _rv,
406 PyMac_BuildEventRecord, &event,
407 itemHit);
408 return _res;
411 static PyObject *DlgObj_SetDialogDefaultItem(_self, _args)
412 DialogObject *_self;
413 PyObject *_args;
415 PyObject *_res = NULL;
416 OSErr _err;
417 DialogItemIndex newItem;
418 if (!PyArg_ParseTuple(_args, "h",
419 &newItem))
420 return NULL;
421 _err = SetDialogDefaultItem(_self->ob_itself,
422 newItem);
423 if (_err != noErr) return PyMac_Error(_err);
424 Py_INCREF(Py_None);
425 _res = Py_None;
426 return _res;
429 static PyObject *DlgObj_SetDialogCancelItem(_self, _args)
430 DialogObject *_self;
431 PyObject *_args;
433 PyObject *_res = NULL;
434 OSErr _err;
435 DialogItemIndex newItem;
436 if (!PyArg_ParseTuple(_args, "h",
437 &newItem))
438 return NULL;
439 _err = SetDialogCancelItem(_self->ob_itself,
440 newItem);
441 if (_err != noErr) return PyMac_Error(_err);
442 Py_INCREF(Py_None);
443 _res = Py_None;
444 return _res;
447 static PyObject *DlgObj_SetDialogTracksCursor(_self, _args)
448 DialogObject *_self;
449 PyObject *_args;
451 PyObject *_res = NULL;
452 OSErr _err;
453 Boolean tracks;
454 if (!PyArg_ParseTuple(_args, "b",
455 &tracks))
456 return NULL;
457 _err = SetDialogTracksCursor(_self->ob_itself,
458 tracks);
459 if (_err != noErr) return PyMac_Error(_err);
460 Py_INCREF(Py_None);
461 _res = Py_None;
462 return _res;
465 static PyObject *DlgObj_AutoSizeDialog(_self, _args)
466 DialogObject *_self;
467 PyObject *_args;
469 PyObject *_res = NULL;
470 OSErr _err;
471 if (!PyArg_ParseTuple(_args, ""))
472 return NULL;
473 _err = AutoSizeDialog(_self->ob_itself);
474 if (_err != noErr) return PyMac_Error(_err);
475 Py_INCREF(Py_None);
476 _res = Py_None;
477 return _res;
480 static PyObject *DlgObj_GetDialogItemAsControl(_self, _args)
481 DialogObject *_self;
482 PyObject *_args;
484 PyObject *_res = NULL;
485 OSErr _err;
486 SInt16 inItemNo;
487 ControlHandle outControl;
488 if (!PyArg_ParseTuple(_args, "h",
489 &inItemNo))
490 return NULL;
491 _err = GetDialogItemAsControl(_self->ob_itself,
492 inItemNo,
493 &outControl);
494 if (_err != noErr) return PyMac_Error(_err);
495 _res = Py_BuildValue("O&",
496 CtlObj_New, outControl);
497 return _res;
500 static PyObject *DlgObj_MoveDialogItem(_self, _args)
501 DialogObject *_self;
502 PyObject *_args;
504 PyObject *_res = NULL;
505 OSErr _err;
506 SInt16 inItemNo;
507 SInt16 inHoriz;
508 SInt16 inVert;
509 if (!PyArg_ParseTuple(_args, "hhh",
510 &inItemNo,
511 &inHoriz,
512 &inVert))
513 return NULL;
514 _err = MoveDialogItem(_self->ob_itself,
515 inItemNo,
516 inHoriz,
517 inVert);
518 if (_err != noErr) return PyMac_Error(_err);
519 Py_INCREF(Py_None);
520 _res = Py_None;
521 return _res;
524 static PyObject *DlgObj_SizeDialogItem(_self, _args)
525 DialogObject *_self;
526 PyObject *_args;
528 PyObject *_res = NULL;
529 OSErr _err;
530 SInt16 inItemNo;
531 SInt16 inWidth;
532 SInt16 inHeight;
533 if (!PyArg_ParseTuple(_args, "hhh",
534 &inItemNo,
535 &inWidth,
536 &inHeight))
537 return NULL;
538 _err = SizeDialogItem(_self->ob_itself,
539 inItemNo,
540 inWidth,
541 inHeight);
542 if (_err != noErr) return PyMac_Error(_err);
543 Py_INCREF(Py_None);
544 _res = Py_None;
545 return _res;
548 static PyObject *DlgObj_AppendDialogItemList(_self, _args)
549 DialogObject *_self;
550 PyObject *_args;
552 PyObject *_res = NULL;
553 OSErr _err;
554 SInt16 ditlID;
555 DITLMethod method;
556 if (!PyArg_ParseTuple(_args, "hh",
557 &ditlID,
558 &method))
559 return NULL;
560 _err = AppendDialogItemList(_self->ob_itself,
561 ditlID,
562 method);
563 if (_err != noErr) return PyMac_Error(_err);
564 Py_INCREF(Py_None);
565 _res = Py_None;
566 return _res;
569 static PyObject *DlgObj_SetDialogTimeout(_self, _args)
570 DialogObject *_self;
571 PyObject *_args;
573 PyObject *_res = NULL;
574 OSStatus _err;
575 SInt16 inButtonToPress;
576 UInt32 inSecondsToWait;
577 if (!PyArg_ParseTuple(_args, "hl",
578 &inButtonToPress,
579 &inSecondsToWait))
580 return NULL;
581 _err = SetDialogTimeout(_self->ob_itself,
582 inButtonToPress,
583 inSecondsToWait);
584 if (_err != noErr) return PyMac_Error(_err);
585 Py_INCREF(Py_None);
586 _res = Py_None;
587 return _res;
590 static PyObject *DlgObj_GetDialogTimeout(_self, _args)
591 DialogObject *_self;
592 PyObject *_args;
594 PyObject *_res = NULL;
595 OSStatus _err;
596 SInt16 outButtonToPress;
597 UInt32 outSecondsToWait;
598 UInt32 outSecondsRemaining;
599 if (!PyArg_ParseTuple(_args, ""))
600 return NULL;
601 _err = GetDialogTimeout(_self->ob_itself,
602 &outButtonToPress,
603 &outSecondsToWait,
604 &outSecondsRemaining);
605 if (_err != noErr) return PyMac_Error(_err);
606 _res = Py_BuildValue("hll",
607 outButtonToPress,
608 outSecondsToWait,
609 outSecondsRemaining);
610 return _res;
613 static PyObject *DlgObj_SetModalDialogEventMask(_self, _args)
614 DialogObject *_self;
615 PyObject *_args;
617 PyObject *_res = NULL;
618 OSStatus _err;
619 EventMask inMask;
620 if (!PyArg_ParseTuple(_args, "H",
621 &inMask))
622 return NULL;
623 _err = SetModalDialogEventMask(_self->ob_itself,
624 inMask);
625 if (_err != noErr) return PyMac_Error(_err);
626 Py_INCREF(Py_None);
627 _res = Py_None;
628 return _res;
631 static PyObject *DlgObj_GetModalDialogEventMask(_self, _args)
632 DialogObject *_self;
633 PyObject *_args;
635 PyObject *_res = NULL;
636 OSStatus _err;
637 EventMask outMask;
638 if (!PyArg_ParseTuple(_args, ""))
639 return NULL;
640 _err = GetModalDialogEventMask(_self->ob_itself,
641 &outMask);
642 if (_err != noErr) return PyMac_Error(_err);
643 _res = Py_BuildValue("H",
644 outMask);
645 return _res;
648 static PyObject *DlgObj_GetDialogWindow(_self, _args)
649 DialogObject *_self;
650 PyObject *_args;
652 PyObject *_res = NULL;
653 WindowPtr _rv;
654 if (!PyArg_ParseTuple(_args, ""))
655 return NULL;
656 _rv = GetDialogWindow(_self->ob_itself);
657 _res = Py_BuildValue("O&",
658 WinObj_New, _rv);
659 return _res;
662 static PyObject *DlgObj_GetDialogDefaultItem(_self, _args)
663 DialogObject *_self;
664 PyObject *_args;
666 PyObject *_res = NULL;
667 SInt16 _rv;
668 if (!PyArg_ParseTuple(_args, ""))
669 return NULL;
670 _rv = GetDialogDefaultItem(_self->ob_itself);
671 _res = Py_BuildValue("h",
672 _rv);
673 return _res;
676 static PyObject *DlgObj_GetDialogCancelItem(_self, _args)
677 DialogObject *_self;
678 PyObject *_args;
680 PyObject *_res = NULL;
681 SInt16 _rv;
682 if (!PyArg_ParseTuple(_args, ""))
683 return NULL;
684 _rv = GetDialogCancelItem(_self->ob_itself);
685 _res = Py_BuildValue("h",
686 _rv);
687 return _res;
690 static PyObject *DlgObj_GetDialogKeyboardFocusItem(_self, _args)
691 DialogObject *_self;
692 PyObject *_args;
694 PyObject *_res = NULL;
695 SInt16 _rv;
696 if (!PyArg_ParseTuple(_args, ""))
697 return NULL;
698 _rv = GetDialogKeyboardFocusItem(_self->ob_itself);
699 _res = Py_BuildValue("h",
700 _rv);
701 return _res;
704 #if !TARGET_API_MAC_CARBON
706 static PyObject *DlgObj_SetGrafPortOfDialog(_self, _args)
707 DialogObject *_self;
708 PyObject *_args;
710 PyObject *_res = NULL;
711 if (!PyArg_ParseTuple(_args, ""))
712 return NULL;
713 SetGrafPortOfDialog(_self->ob_itself);
714 Py_INCREF(Py_None);
715 _res = Py_None;
716 return _res;
718 #endif
720 static PyMethodDef DlgObj_methods[] = {
721 {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
722 "() -> None"},
723 {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
724 "(RgnHandle updateRgn) -> None"},
725 {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
726 "(DialogItemIndex itemNo) -> None"},
727 {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
728 "(DialogItemIndex itemNo) -> None"},
729 {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
730 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
731 {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
732 "() -> None"},
733 {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
734 "() -> None"},
735 {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
736 "() -> None"},
737 {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
738 "() -> None"},
739 {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1,
740 "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"},
741 {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1,
742 "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"},
743 {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1,
744 "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"},
745 {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
746 "(Handle theHandle, DITLMethod method) -> None"},
747 {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
748 "() -> (DialogItemIndex _rv)"},
749 {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
750 "(DialogItemIndex numberItems) -> None"},
751 {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
752 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
753 {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
754 "(DialogItemIndex newItem) -> None"},
755 {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
756 "(DialogItemIndex newItem) -> None"},
757 {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
758 "(Boolean tracks) -> None"},
759 {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1,
760 "() -> None"},
761 {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1,
762 "(SInt16 inItemNo) -> (ControlHandle outControl)"},
763 {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1,
764 "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"},
765 {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1,
766 "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"},
767 {"AppendDialogItemList", (PyCFunction)DlgObj_AppendDialogItemList, 1,
768 "(SInt16 ditlID, DITLMethod method) -> None"},
769 {"SetDialogTimeout", (PyCFunction)DlgObj_SetDialogTimeout, 1,
770 "(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None"},
771 {"GetDialogTimeout", (PyCFunction)DlgObj_GetDialogTimeout, 1,
772 "() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)"},
773 {"SetModalDialogEventMask", (PyCFunction)DlgObj_SetModalDialogEventMask, 1,
774 "(EventMask inMask) -> None"},
775 {"GetModalDialogEventMask", (PyCFunction)DlgObj_GetModalDialogEventMask, 1,
776 "() -> (EventMask outMask)"},
777 {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
778 "() -> (WindowPtr _rv)"},
779 {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1,
780 "() -> (SInt16 _rv)"},
781 {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1,
782 "() -> (SInt16 _rv)"},
783 {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1,
784 "() -> (SInt16 _rv)"},
786 #if !TARGET_API_MAC_CARBON
787 {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1,
788 "() -> None"},
789 #endif
790 {NULL, NULL, 0}
793 PyMethodChain DlgObj_chain = { DlgObj_methods, &WinObj_chain };
795 static PyObject *DlgObj_getattr(self, name)
796 DialogObject *self;
797 char *name;
799 return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name);
802 #define DlgObj_setattr NULL
804 #define DlgObj_compare NULL
806 #define DlgObj_repr NULL
808 #define DlgObj_hash NULL
810 PyTypeObject Dialog_Type = {
811 PyObject_HEAD_INIT(&PyType_Type)
812 0, /*ob_size*/
813 "Dialog", /*tp_name*/
814 sizeof(DialogObject), /*tp_basicsize*/
815 0, /*tp_itemsize*/
816 /* methods */
817 (destructor) DlgObj_dealloc, /*tp_dealloc*/
818 0, /*tp_print*/
819 (getattrfunc) DlgObj_getattr, /*tp_getattr*/
820 (setattrfunc) DlgObj_setattr, /*tp_setattr*/
821 (cmpfunc) DlgObj_compare, /*tp_compare*/
822 (reprfunc) DlgObj_repr, /*tp_repr*/
823 (PyNumberMethods *)0, /* tp_as_number */
824 (PySequenceMethods *)0, /* tp_as_sequence */
825 (PyMappingMethods *)0, /* tp_as_mapping */
826 (hashfunc) DlgObj_hash, /*tp_hash*/
829 /* --------------------- End object type Dialog --------------------- */
832 static PyObject *Dlg_NewDialog(_self, _args)
833 PyObject *_self;
834 PyObject *_args;
836 PyObject *_res = NULL;
837 DialogPtr _rv;
838 Rect boundsRect;
839 Str255 title;
840 Boolean visible;
841 SInt16 procID;
842 WindowPtr behind;
843 Boolean goAwayFlag;
844 SInt32 refCon;
845 Handle items;
846 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
847 PyMac_GetRect, &boundsRect,
848 PyMac_GetStr255, title,
849 &visible,
850 &procID,
851 WinObj_Convert, &behind,
852 &goAwayFlag,
853 &refCon,
854 ResObj_Convert, &items))
855 return NULL;
856 _rv = NewDialog((void *)0,
857 &boundsRect,
858 title,
859 visible,
860 procID,
861 behind,
862 goAwayFlag,
863 refCon,
864 items);
865 _res = Py_BuildValue("O&",
866 DlgObj_New, _rv);
867 return _res;
870 static PyObject *Dlg_GetNewDialog(_self, _args)
871 PyObject *_self;
872 PyObject *_args;
874 PyObject *_res = NULL;
875 DialogPtr _rv;
876 SInt16 dialogID;
877 WindowPtr behind;
878 if (!PyArg_ParseTuple(_args, "hO&",
879 &dialogID,
880 WinObj_Convert, &behind))
881 return NULL;
882 _rv = GetNewDialog(dialogID,
883 (void *)0,
884 behind);
885 _res = Py_BuildValue("O&",
886 DlgObj_New, _rv);
887 return _res;
890 static PyObject *Dlg_NewColorDialog(_self, _args)
891 PyObject *_self;
892 PyObject *_args;
894 PyObject *_res = NULL;
895 DialogPtr _rv;
896 Rect boundsRect;
897 Str255 title;
898 Boolean visible;
899 SInt16 procID;
900 WindowPtr behind;
901 Boolean goAwayFlag;
902 SInt32 refCon;
903 Handle items;
904 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
905 PyMac_GetRect, &boundsRect,
906 PyMac_GetStr255, title,
907 &visible,
908 &procID,
909 WinObj_Convert, &behind,
910 &goAwayFlag,
911 &refCon,
912 ResObj_Convert, &items))
913 return NULL;
914 _rv = NewColorDialog((void *)0,
915 &boundsRect,
916 title,
917 visible,
918 procID,
919 behind,
920 goAwayFlag,
921 refCon,
922 items);
923 _res = Py_BuildValue("O&",
924 DlgObj_New, _rv);
925 return _res;
928 static PyObject *Dlg_ModalDialog(_self, _args)
929 PyObject *_self;
930 PyObject *_args;
932 PyObject *_res = NULL;
933 PyObject* modalFilter;
934 DialogItemIndex itemHit;
935 if (!PyArg_ParseTuple(_args, "O",
936 &modalFilter))
937 return NULL;
938 ModalDialog(NewModalFilterProc(Dlg_PassFilterProc(modalFilter)),
939 &itemHit);
940 _res = Py_BuildValue("h",
941 itemHit);
942 return _res;
945 static PyObject *Dlg_IsDialogEvent(_self, _args)
946 PyObject *_self;
947 PyObject *_args;
949 PyObject *_res = NULL;
950 Boolean _rv;
951 EventRecord theEvent;
952 if (!PyArg_ParseTuple(_args, "O&",
953 PyMac_GetEventRecord, &theEvent))
954 return NULL;
955 _rv = IsDialogEvent(&theEvent);
956 _res = Py_BuildValue("b",
957 _rv);
958 return _res;
961 static PyObject *Dlg_DialogSelect(_self, _args)
962 PyObject *_self;
963 PyObject *_args;
965 PyObject *_res = NULL;
966 Boolean _rv;
967 EventRecord theEvent;
968 DialogPtr theDialog;
969 DialogItemIndex itemHit;
970 if (!PyArg_ParseTuple(_args, "O&",
971 PyMac_GetEventRecord, &theEvent))
972 return NULL;
973 _rv = DialogSelect(&theEvent,
974 &theDialog,
975 &itemHit);
976 _res = Py_BuildValue("bO&h",
977 _rv,
978 WinObj_WhichWindow, theDialog,
979 itemHit);
980 return _res;
983 static PyObject *Dlg_Alert(_self, _args)
984 PyObject *_self;
985 PyObject *_args;
987 PyObject *_res = NULL;
988 DialogItemIndex _rv;
989 SInt16 alertID;
990 PyObject* modalFilter;
991 if (!PyArg_ParseTuple(_args, "hO",
992 &alertID,
993 &modalFilter))
994 return NULL;
995 _rv = Alert(alertID,
996 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
997 _res = Py_BuildValue("h",
998 _rv);
999 return _res;
1002 static PyObject *Dlg_StopAlert(_self, _args)
1003 PyObject *_self;
1004 PyObject *_args;
1006 PyObject *_res = NULL;
1007 DialogItemIndex _rv;
1008 SInt16 alertID;
1009 PyObject* modalFilter;
1010 if (!PyArg_ParseTuple(_args, "hO",
1011 &alertID,
1012 &modalFilter))
1013 return NULL;
1014 _rv = StopAlert(alertID,
1015 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
1016 _res = Py_BuildValue("h",
1017 _rv);
1018 return _res;
1021 static PyObject *Dlg_NoteAlert(_self, _args)
1022 PyObject *_self;
1023 PyObject *_args;
1025 PyObject *_res = NULL;
1026 DialogItemIndex _rv;
1027 SInt16 alertID;
1028 PyObject* modalFilter;
1029 if (!PyArg_ParseTuple(_args, "hO",
1030 &alertID,
1031 &modalFilter))
1032 return NULL;
1033 _rv = NoteAlert(alertID,
1034 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
1035 _res = Py_BuildValue("h",
1036 _rv);
1037 return _res;
1040 static PyObject *Dlg_CautionAlert(_self, _args)
1041 PyObject *_self;
1042 PyObject *_args;
1044 PyObject *_res = NULL;
1045 DialogItemIndex _rv;
1046 SInt16 alertID;
1047 PyObject* modalFilter;
1048 if (!PyArg_ParseTuple(_args, "hO",
1049 &alertID,
1050 &modalFilter))
1051 return NULL;
1052 _rv = CautionAlert(alertID,
1053 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
1054 _res = Py_BuildValue("h",
1055 _rv);
1056 return _res;
1059 static PyObject *Dlg_ParamText(_self, _args)
1060 PyObject *_self;
1061 PyObject *_args;
1063 PyObject *_res = NULL;
1064 Str255 param0;
1065 Str255 param1;
1066 Str255 param2;
1067 Str255 param3;
1068 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1069 PyMac_GetStr255, param0,
1070 PyMac_GetStr255, param1,
1071 PyMac_GetStr255, param2,
1072 PyMac_GetStr255, param3))
1073 return NULL;
1074 ParamText(param0,
1075 param1,
1076 param2,
1077 param3);
1078 Py_INCREF(Py_None);
1079 _res = Py_None;
1080 return _res;
1083 static PyObject *Dlg_GetDialogItemText(_self, _args)
1084 PyObject *_self;
1085 PyObject *_args;
1087 PyObject *_res = NULL;
1088 Handle item;
1089 Str255 text;
1090 if (!PyArg_ParseTuple(_args, "O&",
1091 ResObj_Convert, &item))
1092 return NULL;
1093 GetDialogItemText(item,
1094 text);
1095 _res = Py_BuildValue("O&",
1096 PyMac_BuildStr255, text);
1097 return _res;
1100 static PyObject *Dlg_SetDialogItemText(_self, _args)
1101 PyObject *_self;
1102 PyObject *_args;
1104 PyObject *_res = NULL;
1105 Handle item;
1106 Str255 text;
1107 if (!PyArg_ParseTuple(_args, "O&O&",
1108 ResObj_Convert, &item,
1109 PyMac_GetStr255, text))
1110 return NULL;
1111 SetDialogItemText(item,
1112 text);
1113 Py_INCREF(Py_None);
1114 _res = Py_None;
1115 return _res;
1118 static PyObject *Dlg_GetAlertStage(_self, _args)
1119 PyObject *_self;
1120 PyObject *_args;
1122 PyObject *_res = NULL;
1123 SInt16 _rv;
1124 if (!PyArg_ParseTuple(_args, ""))
1125 return NULL;
1126 _rv = GetAlertStage();
1127 _res = Py_BuildValue("h",
1128 _rv);
1129 return _res;
1132 static PyObject *Dlg_SetDialogFont(_self, _args)
1133 PyObject *_self;
1134 PyObject *_args;
1136 PyObject *_res = NULL;
1137 SInt16 fontNum;
1138 if (!PyArg_ParseTuple(_args, "h",
1139 &fontNum))
1140 return NULL;
1141 SetDialogFont(fontNum);
1142 Py_INCREF(Py_None);
1143 _res = Py_None;
1144 return _res;
1147 static PyObject *Dlg_ResetAlertStage(_self, _args)
1148 PyObject *_self;
1149 PyObject *_args;
1151 PyObject *_res = NULL;
1152 if (!PyArg_ParseTuple(_args, ""))
1153 return NULL;
1154 ResetAlertStage();
1155 Py_INCREF(Py_None);
1156 _res = Py_None;
1157 return _res;
1160 static PyObject *Dlg_NewFeaturesDialog(_self, _args)
1161 PyObject *_self;
1162 PyObject *_args;
1164 PyObject *_res = NULL;
1165 DialogPtr _rv;
1166 Rect inBoundsRect;
1167 Str255 inTitle;
1168 Boolean inIsVisible;
1169 SInt16 inProcID;
1170 WindowPtr inBehind;
1171 Boolean inGoAwayFlag;
1172 SInt32 inRefCon;
1173 Handle inItemListHandle;
1174 UInt32 inFlags;
1175 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
1176 PyMac_GetRect, &inBoundsRect,
1177 PyMac_GetStr255, inTitle,
1178 &inIsVisible,
1179 &inProcID,
1180 WinObj_Convert, &inBehind,
1181 &inGoAwayFlag,
1182 &inRefCon,
1183 ResObj_Convert, &inItemListHandle,
1184 &inFlags))
1185 return NULL;
1186 _rv = NewFeaturesDialog((void *)0,
1187 &inBoundsRect,
1188 inTitle,
1189 inIsVisible,
1190 inProcID,
1191 inBehind,
1192 inGoAwayFlag,
1193 inRefCon,
1194 inItemListHandle,
1195 inFlags);
1196 _res = Py_BuildValue("O&",
1197 DlgObj_New, _rv);
1198 return _res;
1201 static PyObject *Dlg_SetUserItemHandler(_self, _args)
1202 PyObject *_self;
1203 PyObject *_args;
1205 PyObject *_res = NULL;
1207 PyObject *new = NULL;
1210 if (!PyArg_ParseTuple(_args, "|O", &new))
1211 return NULL;
1213 if (Dlg_UserItemProc_callback && new && new != Py_None) {
1214 PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
1215 return NULL;
1218 if (new == Py_None) {
1219 new = NULL;
1220 _res = Py_None;
1221 Py_INCREF(Py_None);
1222 } else {
1223 Py_INCREF(new);
1224 _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc));
1227 Dlg_UserItemProc_callback = new;
1228 return _res;
1232 static PyMethodDef Dlg_methods[] = {
1233 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
1234 "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
1235 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
1236 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1237 {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
1238 "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
1239 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
1240 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
1241 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
1242 "(EventRecord theEvent) -> (Boolean _rv)"},
1243 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
1244 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
1245 {"Alert", (PyCFunction)Dlg_Alert, 1,
1246 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1247 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
1248 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1249 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
1250 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1251 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
1252 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1253 {"ParamText", (PyCFunction)Dlg_ParamText, 1,
1254 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1255 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
1256 "(Handle item) -> (Str255 text)"},
1257 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
1258 "(Handle item, Str255 text) -> None"},
1259 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
1260 "() -> (SInt16 _rv)"},
1261 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
1262 "(SInt16 fontNum) -> None"},
1263 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
1264 "() -> None"},
1265 {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
1266 "(Rect inBoundsRect, Str255 inTitle, Boolean inIsVisible, SInt16 inProcID, WindowPtr inBehind, Boolean inGoAwayFlag, SInt32 inRefCon, Handle inItemListHandle, UInt32 inFlags) -> (DialogPtr _rv)"},
1267 {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
1268 NULL},
1269 {NULL, NULL, 0}
1275 void initDlg()
1277 PyObject *m;
1278 PyObject *d;
1283 m = Py_InitModule("Dlg", Dlg_methods);
1284 d = PyModule_GetDict(m);
1285 Dlg_Error = PyMac_GetOSErrException();
1286 if (Dlg_Error == NULL ||
1287 PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
1288 Py_FatalError("can't initialize Dlg.Error");
1289 Dialog_Type.ob_type = &PyType_Type;
1290 Py_INCREF(&Dialog_Type);
1291 if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0)
1292 Py_FatalError("can't initialize DialogType");
1295 /* ========================= End module Dlg ========================= */