2 /* =========================== Module Dlg =========================== */
8 #define SystemSevenOrLater 1
16 extern PyObject
*ResObj_New(Handle
);
17 extern int ResObj_Convert(PyObject
*, Handle
*);
18 extern PyObject
*OptResObj_New(Handle
);
19 extern int OptResObj_Convert(PyObject
*, Handle
*);
21 extern PyObject
*WinObj_New(WindowPtr
);
22 extern int WinObj_Convert(PyObject
*, WindowPtr
*);
23 extern PyTypeObject Window_Type
;
24 #define WinObj_Check(x) ((x)->ob_type == &Window_Type)
26 extern PyObject
*DlgObj_New(DialogPtr
);
27 extern int DlgObj_Convert(PyObject
*, DialogPtr
*);
28 extern PyTypeObject Dialog_Type
;
29 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
31 extern PyObject
*MenuObj_New(MenuHandle
);
32 extern int MenuObj_Convert(PyObject
*, MenuHandle
*);
34 extern PyObject
*CtlObj_New(ControlHandle
);
35 extern int CtlObj_Convert(PyObject
*, ControlHandle
*);
37 extern PyObject
*GrafObj_New(GrafPtr
);
38 extern int GrafObj_Convert(PyObject
*, GrafPtr
*);
40 extern PyObject
*BMObj_New(BitMapPtr
);
41 extern int BMObj_Convert(PyObject
*, BitMapPtr
*);
43 extern PyObject
*WinObj_WhichWindow(WindowPtr
);
47 #ifndef HAVE_UNIVERSAL_HEADERS
48 #define NewModalFilterProc(x) (x)
51 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
53 /* XXX Shouldn't this be a stack? */
54 static PyObject
*Dlg_FilterProc_callback
= NULL
;
56 static PyObject
*DlgObj_New(DialogPtr
); /* Forward */
58 static pascal Boolean
Dlg_UnivFilterProc(DialogPtr dialog
,
64 PyObject
*callback
= Dlg_FilterProc_callback
;
66 return 0; /* Default behavior */
67 Dlg_FilterProc_callback
= NULL
; /* We'll restore it when call successful */
68 args
= Py_BuildValue("O&O&", WinObj_WhichWindow
, dialog
, PyMac_BuildEventRecord
, event
);
72 res
= PyEval_CallObject(callback
, args
);
76 fprintf(stderr
, "Exception in Dialog Filter\n");
78 *itemHit
= -1; /* Fake return item */
79 return 1; /* We handled it */
82 Dlg_FilterProc_callback
= callback
;
83 if (PyInt_Check(res
)) {
84 *itemHit
= PyInt_AsLong(res
);
88 rv
= PyObject_IsTrue(res
);
94 static ModalFilterProcPtr
95 Dlg_PassFilterProc(PyObject
*callback
)
97 PyObject
*tmp
= Dlg_FilterProc_callback
;
98 Dlg_FilterProc_callback
= NULL
;
99 if (callback
== Py_None
) {
104 Dlg_FilterProc_callback
= callback
;
106 return &Dlg_UnivFilterProc
;
109 extern PyMethodChain WinObj_chain
;
111 static PyObject
*Dlg_Error
;
113 /* ----------------------- Object type Dialog ----------------------- */
115 PyTypeObject Dialog_Type
;
117 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
119 typedef struct DialogObject
{
124 PyObject
*DlgObj_New(itself
)
128 if (itself
== NULL
) return Py_None
;
129 it
= PyObject_NEW(DialogObject
, &Dialog_Type
);
130 if (it
== NULL
) return NULL
;
131 it
->ob_itself
= itself
;
132 SetWRefCon(itself
, (long)it
);
133 return (PyObject
*)it
;
135 DlgObj_Convert(v
, p_itself
)
139 if (v
== Py_None
) { *p_itself
= NULL
; return 1; }
140 if (PyInt_Check(v
)) { *p_itself
= (DialogPtr
)PyInt_AsLong(v
);
142 if (!DlgObj_Check(v
))
144 PyErr_SetString(PyExc_TypeError
, "Dialog required");
147 *p_itself
= ((DialogObject
*)v
)->ob_itself
;
151 static void DlgObj_dealloc(self
)
154 DisposeDialog(self
->ob_itself
);
158 static PyObject
*DlgObj_DrawDialog(_self
, _args
)
162 PyObject
*_res
= NULL
;
163 if (!PyArg_ParseTuple(_args
, ""))
165 DrawDialog(_self
->ob_itself
);
171 static PyObject
*DlgObj_UpdateDialog(_self
, _args
)
175 PyObject
*_res
= NULL
;
177 if (!PyArg_ParseTuple(_args
, "O&",
178 ResObj_Convert
, &updateRgn
))
180 UpdateDialog(_self
->ob_itself
,
187 static PyObject
*DlgObj_GetDialogItem(_self
, _args
)
191 PyObject
*_res
= NULL
;
196 if (!PyArg_ParseTuple(_args
, "h",
199 GetDialogItem(_self
->ob_itself
,
204 _res
= Py_BuildValue("hO&O&",
207 PyMac_BuildRect
, &box
);
211 static PyObject
*DlgObj_SetDialogItem(_self
, _args
)
215 PyObject
*_res
= NULL
;
220 if (!PyArg_ParseTuple(_args
, "hhO&O&",
223 ResObj_Convert
, &item
,
224 PyMac_GetRect
, &box
))
226 SetDialogItem(_self
->ob_itself
,
236 static PyObject
*DlgObj_HideDialogItem(_self
, _args
)
240 PyObject
*_res
= NULL
;
242 if (!PyArg_ParseTuple(_args
, "h",
245 HideDialogItem(_self
->ob_itself
,
252 static PyObject
*DlgObj_ShowDialogItem(_self
, _args
)
256 PyObject
*_res
= NULL
;
258 if (!PyArg_ParseTuple(_args
, "h",
261 ShowDialogItem(_self
->ob_itself
,
268 static PyObject
*DlgObj_SelectDialogItemText(_self
, _args
)
272 PyObject
*_res
= NULL
;
276 if (!PyArg_ParseTuple(_args
, "hhh",
281 SelectDialogItemText(_self
->ob_itself
,
290 static PyObject
*DlgObj_FindDialogItem(_self
, _args
)
294 PyObject
*_res
= NULL
;
297 if (!PyArg_ParseTuple(_args
, "O&",
298 PyMac_GetPoint
, &thePt
))
300 _rv
= FindDialogItem(_self
->ob_itself
,
302 _res
= Py_BuildValue("h",
307 static PyObject
*DlgObj_DialogCut(_self
, _args
)
311 PyObject
*_res
= NULL
;
312 if (!PyArg_ParseTuple(_args
, ""))
314 DialogCut(_self
->ob_itself
);
320 static PyObject
*DlgObj_DialogPaste(_self
, _args
)
324 PyObject
*_res
= NULL
;
325 if (!PyArg_ParseTuple(_args
, ""))
327 DialogPaste(_self
->ob_itself
);
333 static PyObject
*DlgObj_DialogCopy(_self
, _args
)
337 PyObject
*_res
= NULL
;
338 if (!PyArg_ParseTuple(_args
, ""))
340 DialogCopy(_self
->ob_itself
);
346 static PyObject
*DlgObj_DialogDelete(_self
, _args
)
350 PyObject
*_res
= NULL
;
351 if (!PyArg_ParseTuple(_args
, ""))
353 DialogDelete(_self
->ob_itself
);
359 static PyObject
*DlgObj_AppendDITL(_self
, _args
)
363 PyObject
*_res
= NULL
;
366 if (!PyArg_ParseTuple(_args
, "O&h",
367 ResObj_Convert
, &theHandle
,
370 AppendDITL(_self
->ob_itself
,
378 static PyObject
*DlgObj_CountDITL(_self
, _args
)
382 PyObject
*_res
= NULL
;
384 if (!PyArg_ParseTuple(_args
, ""))
386 _rv
= CountDITL(_self
->ob_itself
);
387 _res
= Py_BuildValue("h",
392 static PyObject
*DlgObj_ShortenDITL(_self
, _args
)
396 PyObject
*_res
= NULL
;
398 if (!PyArg_ParseTuple(_args
, "h",
401 ShortenDITL(_self
->ob_itself
,
408 static PyObject
*DlgObj_StdFilterProc(_self
, _args
)
412 PyObject
*_res
= NULL
;
416 if (!PyArg_ParseTuple(_args
, ""))
418 _rv
= StdFilterProc(_self
->ob_itself
,
421 _res
= Py_BuildValue("bO&h",
423 PyMac_BuildEventRecord
, &event
,
428 static PyObject
*DlgObj_SetDialogDefaultItem(_self
, _args
)
432 PyObject
*_res
= NULL
;
435 if (!PyArg_ParseTuple(_args
, "h",
438 _err
= SetDialogDefaultItem(_self
->ob_itself
,
440 if (_err
!= noErr
) return PyMac_Error(_err
);
446 static PyObject
*DlgObj_SetDialogCancelItem(_self
, _args
)
450 PyObject
*_res
= NULL
;
453 if (!PyArg_ParseTuple(_args
, "h",
456 _err
= SetDialogCancelItem(_self
->ob_itself
,
458 if (_err
!= noErr
) return PyMac_Error(_err
);
464 static PyObject
*DlgObj_SetDialogTracksCursor(_self
, _args
)
468 PyObject
*_res
= NULL
;
471 if (!PyArg_ParseTuple(_args
, "b",
474 _err
= SetDialogTracksCursor(_self
->ob_itself
,
476 if (_err
!= noErr
) return PyMac_Error(_err
);
482 static PyObject
*DlgObj_GetDialogWindow(_self
, _args
)
486 PyObject
*_res
= NULL
;
488 if (!PyArg_ParseTuple(_args
, ""))
490 _rv
= GetDialogWindow(_self
->ob_itself
);
491 _res
= Py_BuildValue("O&",
492 WinObj_WhichWindow
, _rv
);
496 static PyObject
*DlgObj_GetDialogDefaultItem(_self
, _args
)
500 PyObject
*_res
= NULL
;
502 if (!PyArg_ParseTuple(_args
, ""))
504 _rv
= GetDialogDefaultItem(_self
->ob_itself
);
505 _res
= Py_BuildValue("h",
510 static PyObject
*DlgObj_GetDialogCancelItem(_self
, _args
)
514 PyObject
*_res
= NULL
;
516 if (!PyArg_ParseTuple(_args
, ""))
518 _rv
= GetDialogCancelItem(_self
->ob_itself
);
519 _res
= Py_BuildValue("h",
524 static PyObject
*DlgObj_GetDialogKeyboardFocusItem(_self
, _args
)
528 PyObject
*_res
= NULL
;
530 if (!PyArg_ParseTuple(_args
, ""))
532 _rv
= GetDialogKeyboardFocusItem(_self
->ob_itself
);
533 _res
= Py_BuildValue("h",
538 static PyObject
*DlgObj_SetGrafPortOfDialog(_self
, _args
)
542 PyObject
*_res
= NULL
;
543 if (!PyArg_ParseTuple(_args
, ""))
545 SetGrafPortOfDialog(_self
->ob_itself
);
551 static PyMethodDef DlgObj_methods
[] = {
552 {"DrawDialog", (PyCFunction
)DlgObj_DrawDialog
, 1,
554 {"UpdateDialog", (PyCFunction
)DlgObj_UpdateDialog
, 1,
555 "(RgnHandle updateRgn) -> None"},
556 {"GetDialogItem", (PyCFunction
)DlgObj_GetDialogItem
, 1,
557 "(short itemNo) -> (short itemType, Handle item, Rect box)"},
558 {"SetDialogItem", (PyCFunction
)DlgObj_SetDialogItem
, 1,
559 "(short itemNo, short itemType, Handle item, Rect box) -> None"},
560 {"HideDialogItem", (PyCFunction
)DlgObj_HideDialogItem
, 1,
561 "(short itemNo) -> None"},
562 {"ShowDialogItem", (PyCFunction
)DlgObj_ShowDialogItem
, 1,
563 "(short itemNo) -> None"},
564 {"SelectDialogItemText", (PyCFunction
)DlgObj_SelectDialogItemText
, 1,
565 "(short itemNo, short strtSel, short endSel) -> None"},
566 {"FindDialogItem", (PyCFunction
)DlgObj_FindDialogItem
, 1,
567 "(Point thePt) -> (short _rv)"},
568 {"DialogCut", (PyCFunction
)DlgObj_DialogCut
, 1,
570 {"DialogPaste", (PyCFunction
)DlgObj_DialogPaste
, 1,
572 {"DialogCopy", (PyCFunction
)DlgObj_DialogCopy
, 1,
574 {"DialogDelete", (PyCFunction
)DlgObj_DialogDelete
, 1,
576 {"AppendDITL", (PyCFunction
)DlgObj_AppendDITL
, 1,
577 "(Handle theHandle, DITLMethod method) -> None"},
578 {"CountDITL", (PyCFunction
)DlgObj_CountDITL
, 1,
579 "() -> (short _rv)"},
580 {"ShortenDITL", (PyCFunction
)DlgObj_ShortenDITL
, 1,
581 "(short numberItems) -> None"},
582 {"StdFilterProc", (PyCFunction
)DlgObj_StdFilterProc
, 1,
583 "() -> (Boolean _rv, EventRecord event, short itemHit)"},
584 {"SetDialogDefaultItem", (PyCFunction
)DlgObj_SetDialogDefaultItem
, 1,
585 "(short newItem) -> None"},
586 {"SetDialogCancelItem", (PyCFunction
)DlgObj_SetDialogCancelItem
, 1,
587 "(short newItem) -> None"},
588 {"SetDialogTracksCursor", (PyCFunction
)DlgObj_SetDialogTracksCursor
, 1,
589 "(Boolean tracks) -> None"},
590 {"GetDialogWindow", (PyCFunction
)DlgObj_GetDialogWindow
, 1,
591 "() -> (DialogPtr _rv)"},
592 {"GetDialogDefaultItem", (PyCFunction
)DlgObj_GetDialogDefaultItem
, 1,
593 "() -> (SInt16 _rv)"},
594 {"GetDialogCancelItem", (PyCFunction
)DlgObj_GetDialogCancelItem
, 1,
595 "() -> (SInt16 _rv)"},
596 {"GetDialogKeyboardFocusItem", (PyCFunction
)DlgObj_GetDialogKeyboardFocusItem
, 1,
597 "() -> (SInt16 _rv)"},
598 {"SetGrafPortOfDialog", (PyCFunction
)DlgObj_SetGrafPortOfDialog
, 1,
603 PyMethodChain DlgObj_chain
= { DlgObj_methods
, &WinObj_chain
};
605 static PyObject
*DlgObj_getattr(self
, name
)
609 return Py_FindMethodInChain(&DlgObj_chain
, (PyObject
*)self
, name
);
612 #define DlgObj_setattr NULL
614 PyTypeObject Dialog_Type
= {
615 PyObject_HEAD_INIT(&PyType_Type
)
617 "Dialog", /*tp_name*/
618 sizeof(DialogObject
), /*tp_basicsize*/
621 (destructor
) DlgObj_dealloc
, /*tp_dealloc*/
623 (getattrfunc
) DlgObj_getattr
, /*tp_getattr*/
624 (setattrfunc
) DlgObj_setattr
, /*tp_setattr*/
627 /* --------------------- End object type Dialog --------------------- */
630 static PyObject
*Dlg_NewDialog(_self
, _args
)
634 PyObject
*_res
= NULL
;
644 if (!PyArg_ParseTuple(_args
, "O&O&bhO&blO&",
645 PyMac_GetRect
, &boundsRect
,
646 PyMac_GetStr255
, title
,
649 WinObj_Convert
, &behind
,
652 ResObj_Convert
, &itmLstHndl
))
654 _rv
= NewDialog((void *)0,
663 _res
= Py_BuildValue("O&",
668 static PyObject
*Dlg_GetNewDialog(_self
, _args
)
672 PyObject
*_res
= NULL
;
676 if (!PyArg_ParseTuple(_args
, "hO&",
678 WinObj_Convert
, &behind
))
680 _rv
= GetNewDialog(dialogID
,
683 _res
= Py_BuildValue("O&",
688 static PyObject
*Dlg_ParamText(_self
, _args
)
692 PyObject
*_res
= NULL
;
697 if (!PyArg_ParseTuple(_args
, "O&O&O&O&",
698 PyMac_GetStr255
, param0
,
699 PyMac_GetStr255
, param1
,
700 PyMac_GetStr255
, param2
,
701 PyMac_GetStr255
, param3
))
712 static PyObject
*Dlg_ModalDialog(_self
, _args
)
716 PyObject
*_res
= NULL
;
717 PyObject
* modalFilter
;
719 if (!PyArg_ParseTuple(_args
, "O",
722 ModalDialog(NewModalFilterProc(Dlg_PassFilterProc(modalFilter
)),
724 _res
= Py_BuildValue("h",
729 static PyObject
*Dlg_IsDialogEvent(_self
, _args
)
733 PyObject
*_res
= NULL
;
735 EventRecord theEvent
;
736 if (!PyArg_ParseTuple(_args
, "O&",
737 PyMac_GetEventRecord
, &theEvent
))
739 _rv
= IsDialogEvent(&theEvent
);
740 _res
= Py_BuildValue("b",
745 static PyObject
*Dlg_DialogSelect(_self
, _args
)
749 PyObject
*_res
= NULL
;
751 EventRecord theEvent
;
754 if (!PyArg_ParseTuple(_args
, "O&",
755 PyMac_GetEventRecord
, &theEvent
))
757 _rv
= DialogSelect(&theEvent
,
760 _res
= Py_BuildValue("bO&h",
762 WinObj_WhichWindow
, theDialog
,
767 static PyObject
*Dlg_Alert(_self
, _args
)
771 PyObject
*_res
= NULL
;
774 PyObject
* modalFilter
;
775 if (!PyArg_ParseTuple(_args
, "hO",
780 NewModalFilterProc(Dlg_PassFilterProc(modalFilter
)));
781 _res
= Py_BuildValue("h",
786 static PyObject
*Dlg_StopAlert(_self
, _args
)
790 PyObject
*_res
= NULL
;
793 PyObject
* modalFilter
;
794 if (!PyArg_ParseTuple(_args
, "hO",
798 _rv
= StopAlert(alertID
,
799 NewModalFilterProc(Dlg_PassFilterProc(modalFilter
)));
800 _res
= Py_BuildValue("h",
805 static PyObject
*Dlg_NoteAlert(_self
, _args
)
809 PyObject
*_res
= NULL
;
812 PyObject
* modalFilter
;
813 if (!PyArg_ParseTuple(_args
, "hO",
817 _rv
= NoteAlert(alertID
,
818 NewModalFilterProc(Dlg_PassFilterProc(modalFilter
)));
819 _res
= Py_BuildValue("h",
824 static PyObject
*Dlg_CautionAlert(_self
, _args
)
828 PyObject
*_res
= NULL
;
831 PyObject
* modalFilter
;
832 if (!PyArg_ParseTuple(_args
, "hO",
836 _rv
= CautionAlert(alertID
,
837 NewModalFilterProc(Dlg_PassFilterProc(modalFilter
)));
838 _res
= Py_BuildValue("h",
843 static PyObject
*Dlg_GetDialogItemText(_self
, _args
)
847 PyObject
*_res
= NULL
;
850 if (!PyArg_ParseTuple(_args
, "O&",
851 ResObj_Convert
, &item
))
853 GetDialogItemText(item
,
855 _res
= Py_BuildValue("O&",
856 PyMac_BuildStr255
, text
);
860 static PyObject
*Dlg_SetDialogItemText(_self
, _args
)
864 PyObject
*_res
= NULL
;
867 if (!PyArg_ParseTuple(_args
, "O&O&",
868 ResObj_Convert
, &item
,
869 PyMac_GetStr255
, text
))
871 SetDialogItemText(item
,
878 static PyObject
*Dlg_NewColorDialog(_self
, _args
)
882 PyObject
*_res
= NULL
;
892 if (!PyArg_ParseTuple(_args
, "O&O&bhO&blO&",
893 PyMac_GetRect
, &boundsRect
,
894 PyMac_GetStr255
, title
,
897 WinObj_Convert
, &behind
,
900 ResObj_Convert
, &items
))
902 _rv
= NewColorDialog((void *)0,
911 _res
= Py_BuildValue("O&",
916 static PyObject
*Dlg_GetAlertStage(_self
, _args
)
920 PyObject
*_res
= NULL
;
922 if (!PyArg_ParseTuple(_args
, ""))
924 _rv
= GetAlertStage();
925 _res
= Py_BuildValue("h",
930 static PyObject
*Dlg_ResetAlertStage(_self
, _args
)
934 PyObject
*_res
= NULL
;
935 if (!PyArg_ParseTuple(_args
, ""))
943 static PyObject
*Dlg_SetDialogFont(_self
, _args
)
947 PyObject
*_res
= NULL
;
949 if (!PyArg_ParseTuple(_args
, "h",
952 SetDialogFont(value
);
958 static PyMethodDef Dlg_methods
[] = {
959 {"NewDialog", (PyCFunction
)Dlg_NewDialog
, 1,
960 "(Rect boundsRect, Str255 title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon, Handle itmLstHndl) -> (DialogPtr _rv)"},
961 {"GetNewDialog", (PyCFunction
)Dlg_GetNewDialog
, 1,
962 "(short dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
963 {"ParamText", (PyCFunction
)Dlg_ParamText
, 1,
964 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
965 {"ModalDialog", (PyCFunction
)Dlg_ModalDialog
, 1,
966 "(PyObject* modalFilter) -> (short itemHit)"},
967 {"IsDialogEvent", (PyCFunction
)Dlg_IsDialogEvent
, 1,
968 "(EventRecord theEvent) -> (Boolean _rv)"},
969 {"DialogSelect", (PyCFunction
)Dlg_DialogSelect
, 1,
970 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, short itemHit)"},
971 {"Alert", (PyCFunction
)Dlg_Alert
, 1,
972 "(short alertID, PyObject* modalFilter) -> (short _rv)"},
973 {"StopAlert", (PyCFunction
)Dlg_StopAlert
, 1,
974 "(short alertID, PyObject* modalFilter) -> (short _rv)"},
975 {"NoteAlert", (PyCFunction
)Dlg_NoteAlert
, 1,
976 "(short alertID, PyObject* modalFilter) -> (short _rv)"},
977 {"CautionAlert", (PyCFunction
)Dlg_CautionAlert
, 1,
978 "(short alertID, PyObject* modalFilter) -> (short _rv)"},
979 {"GetDialogItemText", (PyCFunction
)Dlg_GetDialogItemText
, 1,
980 "(Handle item) -> (Str255 text)"},
981 {"SetDialogItemText", (PyCFunction
)Dlg_SetDialogItemText
, 1,
982 "(Handle item, Str255 text) -> None"},
983 {"NewColorDialog", (PyCFunction
)Dlg_NewColorDialog
, 1,
984 "(Rect boundsRect, Str255 title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon, Handle items) -> (DialogPtr _rv)"},
985 {"GetAlertStage", (PyCFunction
)Dlg_GetAlertStage
, 1,
986 "() -> (short _rv)"},
987 {"ResetAlertStage", (PyCFunction
)Dlg_ResetAlertStage
, 1,
989 {"SetDialogFont", (PyCFunction
)Dlg_SetDialogFont
, 1,
990 "(short value) -> None"},
1005 m
= Py_InitModule("Dlg", Dlg_methods
);
1006 d
= PyModule_GetDict(m
);
1007 Dlg_Error
= PyMac_GetOSErrException();
1008 if (Dlg_Error
== NULL
||
1009 PyDict_SetItemString(d
, "Error", Dlg_Error
) != 0)
1010 Py_FatalError("can't initialize Dlg.Error");
1011 Dialog_Type
.ob_type
= &PyType_Type
;
1012 Py_INCREF(&Dialog_Type
);
1013 if (PyDict_SetItemString(d
, "DialogType", (PyObject
*)&Dialog_Type
) != 0)
1014 Py_FatalError("can't initialize DialogType");
1017 /* ========================= End module Dlg ========================= */