2 /* =========================== Module Dlg =========================== */
9 #include "pymactoolbox.h"
13 #if !ACCESSOR_CALLS_ARE_FUNCTIONS
14 #define GetDialogTextEditHandle(dlg) (((DialogPeek)(dlg))->textH)
15 #define SetPortDialogPort(dlg) SetPort(dlg)
16 #define GetDialogPort(dlg) ((CGrafPtr)(dlg))
17 #define GetDialogFromWindow(win) ((DialogRef)(win))
20 /* XXX Shouldn't this be a stack? */
21 static PyObject
*Dlg_FilterProc_callback
= NULL
;
23 static pascal Boolean
Dlg_UnivFilterProc(DialogPtr dialog
,
29 PyObject
*callback
= Dlg_FilterProc_callback
;
31 return 0; /* Default behavior */
32 Dlg_FilterProc_callback
= NULL
; /* We'll restore it when call successful */
33 args
= Py_BuildValue("O&O&", DlgObj_WhichDialog
, dialog
, PyMac_BuildEventRecord
, event
);
37 res
= PyEval_CallObject(callback
, args
);
41 PySys_WriteStderr("Exception in Dialog Filter\n");
43 *itemHit
= -1; /* Fake return item */
44 return 1; /* We handled it */
47 Dlg_FilterProc_callback
= callback
;
48 if (PyInt_Check(res
)) {
49 *itemHit
= PyInt_AsLong(res
);
53 rv
= PyObject_IsTrue(res
);
60 Dlg_PassFilterProc(PyObject
*callback
)
62 PyObject
*tmp
= Dlg_FilterProc_callback
;
63 static ModalFilterUPP UnivFilterUpp
= NULL
;
65 Dlg_FilterProc_callback
= NULL
;
66 if (callback
== Py_None
) {
71 Dlg_FilterProc_callback
= callback
;
73 if ( UnivFilterUpp
== NULL
)
74 UnivFilterUpp
= NewModalFilterUPP(&Dlg_UnivFilterProc
);
78 static PyObject
*Dlg_UserItemProc_callback
= NULL
;
80 static pascal void Dlg_UnivUserItemProc(DialogPtr dialog
,
85 if (Dlg_UserItemProc_callback
== NULL
)
86 return; /* Default behavior */
87 Dlg_FilterProc_callback
= NULL
; /* We'll restore it when call successful */
88 args
= Py_BuildValue("O&h", DlgObj_WhichDialog
, dialog
, item
);
92 res
= PyEval_CallObject(Dlg_UserItemProc_callback
, args
);
96 PySys_WriteStderr("Exception in Dialog UserItem proc\n");
105 ** Treating DialogObjects as WindowObjects is (I think) illegal under Carbon.
106 ** However, as they are still identical under MacOS9 Carbon this is a problem, even
107 ** if we neatly call GetDialogWindow() at the right places: there's one refcon field
108 ** and it points to the DialogObject, so WinObj_WhichWindow will smartly return the
109 ** dialog object, and therefore we still don't have a WindowObject.
110 ** I'll leave the chaining code in place for now, with this comment to warn the
111 ** unsuspecting victims (i.e. me, probably, in a few weeks:-)
113 extern PyMethodChain WinObj_chain
;
116 static PyObject
*Dlg_Error
;
118 /* ----------------------- Object type Dialog ----------------------- */
120 PyTypeObject Dialog_Type
;
122 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
124 typedef struct DialogObject
{
129 PyObject
*DlgObj_New(itself
)
133 if (itself
== NULL
) return Py_None
;
134 it
= PyObject_NEW(DialogObject
, &Dialog_Type
);
135 if (it
== NULL
) return NULL
;
136 it
->ob_itself
= itself
;
137 SetWRefCon(GetDialogWindow(itself
), (long)it
);
138 return (PyObject
*)it
;
140 DlgObj_Convert(v
, p_itself
)
144 if (v
== Py_None
) { *p_itself
= NULL
; return 1; }
145 if (PyInt_Check(v
)) { *p_itself
= (DialogPtr
)PyInt_AsLong(v
);
147 if (!DlgObj_Check(v
))
149 PyErr_SetString(PyExc_TypeError
, "Dialog required");
152 *p_itself
= ((DialogObject
*)v
)->ob_itself
;
156 static void DlgObj_dealloc(self
)
159 DisposeDialog(self
->ob_itself
);
163 static PyObject
*DlgObj_DrawDialog(_self
, _args
)
167 PyObject
*_res
= NULL
;
168 if (!PyArg_ParseTuple(_args
, ""))
170 DrawDialog(_self
->ob_itself
);
176 static PyObject
*DlgObj_UpdateDialog(_self
, _args
)
180 PyObject
*_res
= NULL
;
182 if (!PyArg_ParseTuple(_args
, "O&",
183 ResObj_Convert
, &updateRgn
))
185 UpdateDialog(_self
->ob_itself
,
192 static PyObject
*DlgObj_HideDialogItem(_self
, _args
)
196 PyObject
*_res
= NULL
;
197 DialogItemIndex itemNo
;
198 if (!PyArg_ParseTuple(_args
, "h",
201 HideDialogItem(_self
->ob_itself
,
208 static PyObject
*DlgObj_ShowDialogItem(_self
, _args
)
212 PyObject
*_res
= NULL
;
213 DialogItemIndex itemNo
;
214 if (!PyArg_ParseTuple(_args
, "h",
217 ShowDialogItem(_self
->ob_itself
,
224 static PyObject
*DlgObj_FindDialogItem(_self
, _args
)
228 PyObject
*_res
= NULL
;
229 DialogItemIndexZeroBased _rv
;
231 if (!PyArg_ParseTuple(_args
, "O&",
232 PyMac_GetPoint
, &thePt
))
234 _rv
= FindDialogItem(_self
->ob_itself
,
236 _res
= Py_BuildValue("h",
241 static PyObject
*DlgObj_DialogCut(_self
, _args
)
245 PyObject
*_res
= NULL
;
246 if (!PyArg_ParseTuple(_args
, ""))
248 DialogCut(_self
->ob_itself
);
254 static PyObject
*DlgObj_DialogPaste(_self
, _args
)
258 PyObject
*_res
= NULL
;
259 if (!PyArg_ParseTuple(_args
, ""))
261 DialogPaste(_self
->ob_itself
);
267 static PyObject
*DlgObj_DialogCopy(_self
, _args
)
271 PyObject
*_res
= NULL
;
272 if (!PyArg_ParseTuple(_args
, ""))
274 DialogCopy(_self
->ob_itself
);
280 static PyObject
*DlgObj_DialogDelete(_self
, _args
)
284 PyObject
*_res
= NULL
;
285 if (!PyArg_ParseTuple(_args
, ""))
287 DialogDelete(_self
->ob_itself
);
293 static PyObject
*DlgObj_GetDialogItem(_self
, _args
)
297 PyObject
*_res
= NULL
;
298 DialogItemIndex itemNo
;
299 DialogItemType itemType
;
302 if (!PyArg_ParseTuple(_args
, "h",
305 GetDialogItem(_self
->ob_itself
,
310 _res
= Py_BuildValue("hO&O&",
313 PyMac_BuildRect
, &box
);
317 static PyObject
*DlgObj_SetDialogItem(_self
, _args
)
321 PyObject
*_res
= NULL
;
322 DialogItemIndex itemNo
;
323 DialogItemType itemType
;
326 if (!PyArg_ParseTuple(_args
, "hhO&O&",
329 ResObj_Convert
, &item
,
330 PyMac_GetRect
, &box
))
332 SetDialogItem(_self
->ob_itself
,
342 static PyObject
*DlgObj_SelectDialogItemText(_self
, _args
)
346 PyObject
*_res
= NULL
;
347 DialogItemIndex itemNo
;
350 if (!PyArg_ParseTuple(_args
, "hhh",
355 SelectDialogItemText(_self
->ob_itself
,
364 static PyObject
*DlgObj_AppendDITL(_self
, _args
)
368 PyObject
*_res
= NULL
;
371 if (!PyArg_ParseTuple(_args
, "O&h",
372 ResObj_Convert
, &theHandle
,
375 AppendDITL(_self
->ob_itself
,
383 static PyObject
*DlgObj_CountDITL(_self
, _args
)
387 PyObject
*_res
= NULL
;
389 if (!PyArg_ParseTuple(_args
, ""))
391 _rv
= CountDITL(_self
->ob_itself
);
392 _res
= Py_BuildValue("h",
397 static PyObject
*DlgObj_ShortenDITL(_self
, _args
)
401 PyObject
*_res
= NULL
;
402 DialogItemIndex numberItems
;
403 if (!PyArg_ParseTuple(_args
, "h",
406 ShortenDITL(_self
->ob_itself
,
413 #if TARGET_API_MAC_CARBON
415 static PyObject
*DlgObj_InsertDialogItem(_self
, _args
)
419 PyObject
*_res
= NULL
;
421 DialogItemIndex afterItem
;
422 DialogItemType itemType
;
425 if (!PyArg_ParseTuple(_args
, "hhO&O&",
428 ResObj_Convert
, &itemHandle
,
429 PyMac_GetRect
, &box
))
431 _err
= InsertDialogItem(_self
->ob_itself
,
436 if (_err
!= noErr
) return PyMac_Error(_err
);
443 #if TARGET_API_MAC_CARBON
445 static PyObject
*DlgObj_RemoveDialogItems(_self
, _args
)
449 PyObject
*_res
= NULL
;
451 DialogItemIndex itemNo
;
452 DialogItemIndex amountToRemove
;
453 Boolean disposeItemData
;
454 if (!PyArg_ParseTuple(_args
, "hhb",
459 _err
= RemoveDialogItems(_self
->ob_itself
,
463 if (_err
!= noErr
) return PyMac_Error(_err
);
470 static PyObject
*DlgObj_StdFilterProc(_self
, _args
)
474 PyObject
*_res
= NULL
;
477 DialogItemIndex itemHit
;
478 if (!PyArg_ParseTuple(_args
, ""))
480 _rv
= StdFilterProc(_self
->ob_itself
,
483 _res
= Py_BuildValue("bO&h",
485 PyMac_BuildEventRecord
, &event
,
490 static PyObject
*DlgObj_SetDialogDefaultItem(_self
, _args
)
494 PyObject
*_res
= NULL
;
496 DialogItemIndex newItem
;
497 if (!PyArg_ParseTuple(_args
, "h",
500 _err
= SetDialogDefaultItem(_self
->ob_itself
,
502 if (_err
!= noErr
) return PyMac_Error(_err
);
508 static PyObject
*DlgObj_SetDialogCancelItem(_self
, _args
)
512 PyObject
*_res
= NULL
;
514 DialogItemIndex newItem
;
515 if (!PyArg_ParseTuple(_args
, "h",
518 _err
= SetDialogCancelItem(_self
->ob_itself
,
520 if (_err
!= noErr
) return PyMac_Error(_err
);
526 static PyObject
*DlgObj_SetDialogTracksCursor(_self
, _args
)
530 PyObject
*_res
= NULL
;
533 if (!PyArg_ParseTuple(_args
, "b",
536 _err
= SetDialogTracksCursor(_self
->ob_itself
,
538 if (_err
!= noErr
) return PyMac_Error(_err
);
544 static PyObject
*DlgObj_AutoSizeDialog(_self
, _args
)
548 PyObject
*_res
= NULL
;
550 if (!PyArg_ParseTuple(_args
, ""))
552 _err
= AutoSizeDialog(_self
->ob_itself
);
553 if (_err
!= noErr
) return PyMac_Error(_err
);
559 static PyObject
*DlgObj_GetDialogItemAsControl(_self
, _args
)
563 PyObject
*_res
= NULL
;
566 ControlHandle outControl
;
567 if (!PyArg_ParseTuple(_args
, "h",
570 _err
= GetDialogItemAsControl(_self
->ob_itself
,
573 if (_err
!= noErr
) return PyMac_Error(_err
);
574 _res
= Py_BuildValue("O&",
575 CtlObj_New
, outControl
);
579 static PyObject
*DlgObj_MoveDialogItem(_self
, _args
)
583 PyObject
*_res
= NULL
;
588 if (!PyArg_ParseTuple(_args
, "hhh",
593 _err
= MoveDialogItem(_self
->ob_itself
,
597 if (_err
!= noErr
) return PyMac_Error(_err
);
603 static PyObject
*DlgObj_SizeDialogItem(_self
, _args
)
607 PyObject
*_res
= NULL
;
612 if (!PyArg_ParseTuple(_args
, "hhh",
617 _err
= SizeDialogItem(_self
->ob_itself
,
621 if (_err
!= noErr
) return PyMac_Error(_err
);
627 static PyObject
*DlgObj_AppendDialogItemList(_self
, _args
)
631 PyObject
*_res
= NULL
;
635 if (!PyArg_ParseTuple(_args
, "hh",
639 _err
= AppendDialogItemList(_self
->ob_itself
,
642 if (_err
!= noErr
) return PyMac_Error(_err
);
648 static PyObject
*DlgObj_SetDialogTimeout(_self
, _args
)
652 PyObject
*_res
= NULL
;
654 SInt16 inButtonToPress
;
655 UInt32 inSecondsToWait
;
656 if (!PyArg_ParseTuple(_args
, "hl",
660 _err
= SetDialogTimeout(_self
->ob_itself
,
663 if (_err
!= noErr
) return PyMac_Error(_err
);
669 static PyObject
*DlgObj_GetDialogTimeout(_self
, _args
)
673 PyObject
*_res
= NULL
;
675 SInt16 outButtonToPress
;
676 UInt32 outSecondsToWait
;
677 UInt32 outSecondsRemaining
;
678 if (!PyArg_ParseTuple(_args
, ""))
680 _err
= GetDialogTimeout(_self
->ob_itself
,
683 &outSecondsRemaining
);
684 if (_err
!= noErr
) return PyMac_Error(_err
);
685 _res
= Py_BuildValue("hll",
688 outSecondsRemaining
);
692 static PyObject
*DlgObj_SetModalDialogEventMask(_self
, _args
)
696 PyObject
*_res
= NULL
;
699 if (!PyArg_ParseTuple(_args
, "H",
702 _err
= SetModalDialogEventMask(_self
->ob_itself
,
704 if (_err
!= noErr
) return PyMac_Error(_err
);
710 static PyObject
*DlgObj_GetModalDialogEventMask(_self
, _args
)
714 PyObject
*_res
= NULL
;
717 if (!PyArg_ParseTuple(_args
, ""))
719 _err
= GetModalDialogEventMask(_self
->ob_itself
,
721 if (_err
!= noErr
) return PyMac_Error(_err
);
722 _res
= Py_BuildValue("H",
727 static PyObject
*DlgObj_GetDialogWindow(_self
, _args
)
731 PyObject
*_res
= NULL
;
733 if (!PyArg_ParseTuple(_args
, ""))
735 _rv
= GetDialogWindow(_self
->ob_itself
);
736 _res
= Py_BuildValue("O&",
741 static PyObject
*DlgObj_GetDialogTextEditHandle(_self
, _args
)
745 PyObject
*_res
= NULL
;
747 if (!PyArg_ParseTuple(_args
, ""))
749 _rv
= GetDialogTextEditHandle(_self
->ob_itself
);
750 _res
= Py_BuildValue("O&",
755 static PyObject
*DlgObj_GetDialogDefaultItem(_self
, _args
)
759 PyObject
*_res
= NULL
;
761 if (!PyArg_ParseTuple(_args
, ""))
763 _rv
= GetDialogDefaultItem(_self
->ob_itself
);
764 _res
= Py_BuildValue("h",
769 static PyObject
*DlgObj_GetDialogCancelItem(_self
, _args
)
773 PyObject
*_res
= NULL
;
775 if (!PyArg_ParseTuple(_args
, ""))
777 _rv
= GetDialogCancelItem(_self
->ob_itself
);
778 _res
= Py_BuildValue("h",
783 static PyObject
*DlgObj_GetDialogKeyboardFocusItem(_self
, _args
)
787 PyObject
*_res
= NULL
;
789 if (!PyArg_ParseTuple(_args
, ""))
791 _rv
= GetDialogKeyboardFocusItem(_self
->ob_itself
);
792 _res
= Py_BuildValue("h",
797 static PyObject
*DlgObj_SetPortDialogPort(_self
, _args
)
801 PyObject
*_res
= NULL
;
802 if (!PyArg_ParseTuple(_args
, ""))
804 SetPortDialogPort(_self
->ob_itself
);
810 static PyObject
*DlgObj_GetDialogPort(_self
, _args
)
814 PyObject
*_res
= NULL
;
816 if (!PyArg_ParseTuple(_args
, ""))
818 _rv
= GetDialogPort(_self
->ob_itself
);
819 _res
= Py_BuildValue("O&",
824 #if !TARGET_API_MAC_CARBON
826 static PyObject
*DlgObj_SetGrafPortOfDialog(_self
, _args
)
830 PyObject
*_res
= NULL
;
831 if (!PyArg_ParseTuple(_args
, ""))
833 SetGrafPortOfDialog(_self
->ob_itself
);
840 static PyMethodDef DlgObj_methods
[] = {
841 {"DrawDialog", (PyCFunction
)DlgObj_DrawDialog
, 1,
843 {"UpdateDialog", (PyCFunction
)DlgObj_UpdateDialog
, 1,
844 "(RgnHandle updateRgn) -> None"},
845 {"HideDialogItem", (PyCFunction
)DlgObj_HideDialogItem
, 1,
846 "(DialogItemIndex itemNo) -> None"},
847 {"ShowDialogItem", (PyCFunction
)DlgObj_ShowDialogItem
, 1,
848 "(DialogItemIndex itemNo) -> None"},
849 {"FindDialogItem", (PyCFunction
)DlgObj_FindDialogItem
, 1,
850 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
851 {"DialogCut", (PyCFunction
)DlgObj_DialogCut
, 1,
853 {"DialogPaste", (PyCFunction
)DlgObj_DialogPaste
, 1,
855 {"DialogCopy", (PyCFunction
)DlgObj_DialogCopy
, 1,
857 {"DialogDelete", (PyCFunction
)DlgObj_DialogDelete
, 1,
859 {"GetDialogItem", (PyCFunction
)DlgObj_GetDialogItem
, 1,
860 "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"},
861 {"SetDialogItem", (PyCFunction
)DlgObj_SetDialogItem
, 1,
862 "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"},
863 {"SelectDialogItemText", (PyCFunction
)DlgObj_SelectDialogItemText
, 1,
864 "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"},
865 {"AppendDITL", (PyCFunction
)DlgObj_AppendDITL
, 1,
866 "(Handle theHandle, DITLMethod method) -> None"},
867 {"CountDITL", (PyCFunction
)DlgObj_CountDITL
, 1,
868 "() -> (DialogItemIndex _rv)"},
869 {"ShortenDITL", (PyCFunction
)DlgObj_ShortenDITL
, 1,
870 "(DialogItemIndex numberItems) -> None"},
872 #if TARGET_API_MAC_CARBON
873 {"InsertDialogItem", (PyCFunction
)DlgObj_InsertDialogItem
, 1,
874 "(DialogItemIndex afterItem, DialogItemType itemType, Handle itemHandle, Rect box) -> None"},
877 #if TARGET_API_MAC_CARBON
878 {"RemoveDialogItems", (PyCFunction
)DlgObj_RemoveDialogItems
, 1,
879 "(DialogItemIndex itemNo, DialogItemIndex amountToRemove, Boolean disposeItemData) -> None"},
881 {"StdFilterProc", (PyCFunction
)DlgObj_StdFilterProc
, 1,
882 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
883 {"SetDialogDefaultItem", (PyCFunction
)DlgObj_SetDialogDefaultItem
, 1,
884 "(DialogItemIndex newItem) -> None"},
885 {"SetDialogCancelItem", (PyCFunction
)DlgObj_SetDialogCancelItem
, 1,
886 "(DialogItemIndex newItem) -> None"},
887 {"SetDialogTracksCursor", (PyCFunction
)DlgObj_SetDialogTracksCursor
, 1,
888 "(Boolean tracks) -> None"},
889 {"AutoSizeDialog", (PyCFunction
)DlgObj_AutoSizeDialog
, 1,
891 {"GetDialogItemAsControl", (PyCFunction
)DlgObj_GetDialogItemAsControl
, 1,
892 "(SInt16 inItemNo) -> (ControlHandle outControl)"},
893 {"MoveDialogItem", (PyCFunction
)DlgObj_MoveDialogItem
, 1,
894 "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"},
895 {"SizeDialogItem", (PyCFunction
)DlgObj_SizeDialogItem
, 1,
896 "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"},
897 {"AppendDialogItemList", (PyCFunction
)DlgObj_AppendDialogItemList
, 1,
898 "(SInt16 ditlID, DITLMethod method) -> None"},
899 {"SetDialogTimeout", (PyCFunction
)DlgObj_SetDialogTimeout
, 1,
900 "(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None"},
901 {"GetDialogTimeout", (PyCFunction
)DlgObj_GetDialogTimeout
, 1,
902 "() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)"},
903 {"SetModalDialogEventMask", (PyCFunction
)DlgObj_SetModalDialogEventMask
, 1,
904 "(EventMask inMask) -> None"},
905 {"GetModalDialogEventMask", (PyCFunction
)DlgObj_GetModalDialogEventMask
, 1,
906 "() -> (EventMask outMask)"},
907 {"GetDialogWindow", (PyCFunction
)DlgObj_GetDialogWindow
, 1,
908 "() -> (WindowPtr _rv)"},
909 {"GetDialogTextEditHandle", (PyCFunction
)DlgObj_GetDialogTextEditHandle
, 1,
910 "() -> (TEHandle _rv)"},
911 {"GetDialogDefaultItem", (PyCFunction
)DlgObj_GetDialogDefaultItem
, 1,
912 "() -> (SInt16 _rv)"},
913 {"GetDialogCancelItem", (PyCFunction
)DlgObj_GetDialogCancelItem
, 1,
914 "() -> (SInt16 _rv)"},
915 {"GetDialogKeyboardFocusItem", (PyCFunction
)DlgObj_GetDialogKeyboardFocusItem
, 1,
916 "() -> (SInt16 _rv)"},
917 {"SetPortDialogPort", (PyCFunction
)DlgObj_SetPortDialogPort
, 1,
919 {"GetDialogPort", (PyCFunction
)DlgObj_GetDialogPort
, 1,
920 "() -> (CGrafPtr _rv)"},
922 #if !TARGET_API_MAC_CARBON
923 {"SetGrafPortOfDialog", (PyCFunction
)DlgObj_SetGrafPortOfDialog
, 1,
929 PyMethodChain DlgObj_chain
= { DlgObj_methods
, NULL
};
931 static PyObject
*DlgObj_getattr(self
, name
)
935 return Py_FindMethodInChain(&DlgObj_chain
, (PyObject
*)self
, name
);
938 #define DlgObj_setattr NULL
940 static int DlgObj_compare(self
, other
)
941 DialogObject
*self
, *other
;
943 if ( self
->ob_itself
> other
->ob_itself
) return 1;
944 if ( self
->ob_itself
< other
->ob_itself
) return -1;
948 #define DlgObj_repr NULL
950 static int DlgObj_hash(self
)
953 return (int)self
->ob_itself
;
956 PyTypeObject Dialog_Type
= {
957 PyObject_HEAD_INIT(&PyType_Type
)
959 "Dialog", /*tp_name*/
960 sizeof(DialogObject
), /*tp_basicsize*/
963 (destructor
) DlgObj_dealloc
, /*tp_dealloc*/
965 (getattrfunc
) DlgObj_getattr
, /*tp_getattr*/
966 (setattrfunc
) DlgObj_setattr
, /*tp_setattr*/
967 (cmpfunc
) DlgObj_compare
, /*tp_compare*/
968 (reprfunc
) DlgObj_repr
, /*tp_repr*/
969 (PyNumberMethods
*)0, /* tp_as_number */
970 (PySequenceMethods
*)0, /* tp_as_sequence */
971 (PyMappingMethods
*)0, /* tp_as_mapping */
972 (hashfunc
) DlgObj_hash
, /*tp_hash*/
975 /* --------------------- End object type Dialog --------------------- */
978 static PyObject
*Dlg_NewDialog(_self
, _args
)
982 PyObject
*_res
= NULL
;
992 if (!PyArg_ParseTuple(_args
, "O&O&bhO&blO&",
993 PyMac_GetRect
, &boundsRect
,
994 PyMac_GetStr255
, title
,
997 WinObj_Convert
, &behind
,
1000 ResObj_Convert
, &items
))
1002 _rv
= NewDialog((void *)0,
1011 _res
= Py_BuildValue("O&",
1016 static PyObject
*Dlg_GetNewDialog(_self
, _args
)
1020 PyObject
*_res
= NULL
;
1024 if (!PyArg_ParseTuple(_args
, "hO&",
1026 WinObj_Convert
, &behind
))
1028 _rv
= GetNewDialog(dialogID
,
1031 _res
= Py_BuildValue("O&",
1036 static PyObject
*Dlg_NewColorDialog(_self
, _args
)
1040 PyObject
*_res
= NULL
;
1050 if (!PyArg_ParseTuple(_args
, "O&O&bhO&blO&",
1051 PyMac_GetRect
, &boundsRect
,
1052 PyMac_GetStr255
, title
,
1055 WinObj_Convert
, &behind
,
1058 ResObj_Convert
, &items
))
1060 _rv
= NewColorDialog((void *)0,
1069 _res
= Py_BuildValue("O&",
1074 static PyObject
*Dlg_ModalDialog(_self
, _args
)
1078 PyObject
*_res
= NULL
;
1079 PyObject
* modalFilter
;
1080 DialogItemIndex itemHit
;
1081 if (!PyArg_ParseTuple(_args
, "O",
1084 ModalDialog(Dlg_PassFilterProc(modalFilter
),
1086 _res
= Py_BuildValue("h",
1091 static PyObject
*Dlg_IsDialogEvent(_self
, _args
)
1095 PyObject
*_res
= NULL
;
1097 EventRecord theEvent
;
1098 if (!PyArg_ParseTuple(_args
, "O&",
1099 PyMac_GetEventRecord
, &theEvent
))
1101 _rv
= IsDialogEvent(&theEvent
);
1102 _res
= Py_BuildValue("b",
1107 static PyObject
*Dlg_DialogSelect(_self
, _args
)
1111 PyObject
*_res
= NULL
;
1113 EventRecord theEvent
;
1114 DialogPtr theDialog
;
1115 DialogItemIndex itemHit
;
1116 if (!PyArg_ParseTuple(_args
, "O&",
1117 PyMac_GetEventRecord
, &theEvent
))
1119 _rv
= DialogSelect(&theEvent
,
1122 _res
= Py_BuildValue("bO&h",
1124 DlgObj_WhichDialog
, theDialog
,
1129 static PyObject
*Dlg_Alert(_self
, _args
)
1133 PyObject
*_res
= NULL
;
1134 DialogItemIndex _rv
;
1136 PyObject
* modalFilter
;
1137 if (!PyArg_ParseTuple(_args
, "hO",
1141 _rv
= Alert(alertID
,
1142 Dlg_PassFilterProc(modalFilter
));
1143 _res
= Py_BuildValue("h",
1148 static PyObject
*Dlg_StopAlert(_self
, _args
)
1152 PyObject
*_res
= NULL
;
1153 DialogItemIndex _rv
;
1155 PyObject
* modalFilter
;
1156 if (!PyArg_ParseTuple(_args
, "hO",
1160 _rv
= StopAlert(alertID
,
1161 Dlg_PassFilterProc(modalFilter
));
1162 _res
= Py_BuildValue("h",
1167 static PyObject
*Dlg_NoteAlert(_self
, _args
)
1171 PyObject
*_res
= NULL
;
1172 DialogItemIndex _rv
;
1174 PyObject
* modalFilter
;
1175 if (!PyArg_ParseTuple(_args
, "hO",
1179 _rv
= NoteAlert(alertID
,
1180 Dlg_PassFilterProc(modalFilter
));
1181 _res
= Py_BuildValue("h",
1186 static PyObject
*Dlg_CautionAlert(_self
, _args
)
1190 PyObject
*_res
= NULL
;
1191 DialogItemIndex _rv
;
1193 PyObject
* modalFilter
;
1194 if (!PyArg_ParseTuple(_args
, "hO",
1198 _rv
= CautionAlert(alertID
,
1199 Dlg_PassFilterProc(modalFilter
));
1200 _res
= Py_BuildValue("h",
1205 static PyObject
*Dlg_ParamText(_self
, _args
)
1209 PyObject
*_res
= NULL
;
1214 if (!PyArg_ParseTuple(_args
, "O&O&O&O&",
1215 PyMac_GetStr255
, param0
,
1216 PyMac_GetStr255
, param1
,
1217 PyMac_GetStr255
, param2
,
1218 PyMac_GetStr255
, param3
))
1229 static PyObject
*Dlg_GetDialogItemText(_self
, _args
)
1233 PyObject
*_res
= NULL
;
1236 if (!PyArg_ParseTuple(_args
, "O&",
1237 ResObj_Convert
, &item
))
1239 GetDialogItemText(item
,
1241 _res
= Py_BuildValue("O&",
1242 PyMac_BuildStr255
, text
);
1246 static PyObject
*Dlg_SetDialogItemText(_self
, _args
)
1250 PyObject
*_res
= NULL
;
1253 if (!PyArg_ParseTuple(_args
, "O&O&",
1254 ResObj_Convert
, &item
,
1255 PyMac_GetStr255
, text
))
1257 SetDialogItemText(item
,
1264 static PyObject
*Dlg_GetAlertStage(_self
, _args
)
1268 PyObject
*_res
= NULL
;
1270 if (!PyArg_ParseTuple(_args
, ""))
1272 _rv
= GetAlertStage();
1273 _res
= Py_BuildValue("h",
1278 static PyObject
*Dlg_SetDialogFont(_self
, _args
)
1282 PyObject
*_res
= NULL
;
1284 if (!PyArg_ParseTuple(_args
, "h",
1287 SetDialogFont(fontNum
);
1293 static PyObject
*Dlg_ResetAlertStage(_self
, _args
)
1297 PyObject
*_res
= NULL
;
1298 if (!PyArg_ParseTuple(_args
, ""))
1306 #if TARGET_API_MAC_CARBON
1308 static PyObject
*Dlg_GetParamText(_self
, _args
)
1312 PyObject
*_res
= NULL
;
1317 if (!PyArg_ParseTuple(_args
, "O&O&O&O&",
1318 PyMac_GetStr255
, param0
,
1319 PyMac_GetStr255
, param1
,
1320 PyMac_GetStr255
, param2
,
1321 PyMac_GetStr255
, param3
))
1323 GetParamText(param0
,
1333 static PyObject
*Dlg_NewFeaturesDialog(_self
, _args
)
1337 PyObject
*_res
= NULL
;
1341 Boolean inIsVisible
;
1344 Boolean inGoAwayFlag
;
1346 Handle inItemListHandle
;
1348 if (!PyArg_ParseTuple(_args
, "O&O&bhO&blO&l",
1349 PyMac_GetRect
, &inBoundsRect
,
1350 PyMac_GetStr255
, inTitle
,
1353 WinObj_Convert
, &inBehind
,
1356 ResObj_Convert
, &inItemListHandle
,
1359 _rv
= NewFeaturesDialog((void *)0,
1369 _res
= Py_BuildValue("O&",
1374 static PyObject
*Dlg_GetDialogFromWindow(_self
, _args
)
1378 PyObject
*_res
= NULL
;
1381 if (!PyArg_ParseTuple(_args
, "O&",
1382 WinObj_Convert
, &window
))
1384 _rv
= GetDialogFromWindow(window
);
1385 _res
= Py_BuildValue("O&",
1390 static PyObject
*Dlg_SetUserItemHandler(_self
, _args
)
1394 PyObject
*_res
= NULL
;
1396 PyObject
*new = NULL
;
1399 if (!PyArg_ParseTuple(_args
, "|O", &new))
1402 if (Dlg_UserItemProc_callback
&& new && new != Py_None
) {
1403 PyErr_SetString(Dlg_Error
, "Another UserItemProc is already installed");
1407 if (new == NULL
|| new == Py_None
) {
1413 _res
= Py_BuildValue("O&", ResObj_New
, (Handle
)NewUserItemProc(Dlg_UnivUserItemProc
));
1416 Dlg_UserItemProc_callback
= new;
1421 static PyMethodDef Dlg_methods
[] = {
1422 {"NewDialog", (PyCFunction
)Dlg_NewDialog
, 1,
1423 "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
1424 {"GetNewDialog", (PyCFunction
)Dlg_GetNewDialog
, 1,
1425 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1426 {"NewColorDialog", (PyCFunction
)Dlg_NewColorDialog
, 1,
1427 "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
1428 {"ModalDialog", (PyCFunction
)Dlg_ModalDialog
, 1,
1429 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
1430 {"IsDialogEvent", (PyCFunction
)Dlg_IsDialogEvent
, 1,
1431 "(EventRecord theEvent) -> (Boolean _rv)"},
1432 {"DialogSelect", (PyCFunction
)Dlg_DialogSelect
, 1,
1433 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
1434 {"Alert", (PyCFunction
)Dlg_Alert
, 1,
1435 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1436 {"StopAlert", (PyCFunction
)Dlg_StopAlert
, 1,
1437 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1438 {"NoteAlert", (PyCFunction
)Dlg_NoteAlert
, 1,
1439 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1440 {"CautionAlert", (PyCFunction
)Dlg_CautionAlert
, 1,
1441 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1442 {"ParamText", (PyCFunction
)Dlg_ParamText
, 1,
1443 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1444 {"GetDialogItemText", (PyCFunction
)Dlg_GetDialogItemText
, 1,
1445 "(Handle item) -> (Str255 text)"},
1446 {"SetDialogItemText", (PyCFunction
)Dlg_SetDialogItemText
, 1,
1447 "(Handle item, Str255 text) -> None"},
1448 {"GetAlertStage", (PyCFunction
)Dlg_GetAlertStage
, 1,
1449 "() -> (SInt16 _rv)"},
1450 {"SetDialogFont", (PyCFunction
)Dlg_SetDialogFont
, 1,
1451 "(SInt16 fontNum) -> None"},
1452 {"ResetAlertStage", (PyCFunction
)Dlg_ResetAlertStage
, 1,
1455 #if TARGET_API_MAC_CARBON
1456 {"GetParamText", (PyCFunction
)Dlg_GetParamText
, 1,
1457 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1459 {"NewFeaturesDialog", (PyCFunction
)Dlg_NewFeaturesDialog
, 1,
1460 "(Rect inBoundsRect, Str255 inTitle, Boolean inIsVisible, SInt16 inProcID, WindowPtr inBehind, Boolean inGoAwayFlag, SInt32 inRefCon, Handle inItemListHandle, UInt32 inFlags) -> (DialogPtr _rv)"},
1461 {"GetDialogFromWindow", (PyCFunction
)Dlg_GetDialogFromWindow
, 1,
1462 "(WindowPtr window) -> (DialogPtr _rv)"},
1463 {"SetUserItemHandler", (PyCFunction
)Dlg_SetUserItemHandler
, 1,
1470 /* Return the WindowPtr corresponding to a DialogObject */
1473 DlgObj_ConvertToWindow(self
)
1476 if ( DlgObj_Check(self
) )
1477 return GetDialogWindow(((DialogObject
*)self
)->ob_itself
);
1480 /* Return the object corresponding to the dialog, or None */
1483 DlgObj_WhichDialog(d
)
1492 WindowPtr w
= GetDialogWindow(d
);
1494 it
= (PyObject
*) GetWRefCon(w
);
1495 if (it
== NULL
|| ((DialogObject
*)it
)->ob_itself
!= d
|| !DlgObj_Check(it
)) {
1497 /* Should do this, but we don't have an ob_freeit for dialogs yet. */
1499 ((WindowObject
*)it
)->ob_freeit
= NULL
;
1520 m
= Py_InitModule("Dlg", Dlg_methods
);
1521 d
= PyModule_GetDict(m
);
1522 Dlg_Error
= PyMac_GetOSErrException();
1523 if (Dlg_Error
== NULL
||
1524 PyDict_SetItemString(d
, "Error", Dlg_Error
) != 0)
1526 Dialog_Type
.ob_type
= &PyType_Type
;
1527 Py_INCREF(&Dialog_Type
);
1528 if (PyDict_SetItemString(d
, "DialogType", (PyObject
*)&Dialog_Type
) != 0)
1529 Py_FatalError("can't initialize DialogType");
1532 /* ========================= End module Dlg ========================= */