2 /* ========================== Module _Dlg =========================== */
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"); \
19 #ifdef WITHOUT_FRAMEWORKS
22 #include <Carbon/Carbon.h>
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
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))
42 /* XXX Shouldn't this be a stack? */
43 static PyObject
*Dlg_FilterProc_callback
= NULL
;
45 static pascal Boolean
Dlg_UnivFilterProc(DialogPtr dialog
,
51 PyObject
*callback
= Dlg_FilterProc_callback
;
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
);
59 res
= PyEval_CallObject(callback
, args
);
63 PySys_WriteStderr("Exception in Dialog Filter\n");
65 *itemHit
= -1; /* Fake return item */
66 return 1; /* We handled it */
69 Dlg_FilterProc_callback
= callback
;
70 if (PyInt_Check(res
)) {
71 *itemHit
= PyInt_AsLong(res
);
75 rv
= PyObject_IsTrue(res
);
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
) {
93 Dlg_FilterProc_callback
= callback
;
95 if ( UnivFilterUpp
== NULL
)
96 UnivFilterUpp
= NewModalFilterUPP(&Dlg_UnivFilterProc
);
100 static PyObject
*Dlg_UserItemProc_callback
= NULL
;
102 static pascal void Dlg_UnivUserItemProc(DialogPtr dialog
,
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
);
114 res
= PyEval_CallObject(Dlg_UserItemProc_callback
, args
);
118 PySys_WriteStderr("Exception in Dialog UserItem proc\n");
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
;
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
{
151 PyObject
*DlgObj_New(DialogPtr itself
)
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
);
166 if (!DlgObj_Check(v
))
168 PyErr_SetString(PyExc_TypeError
, "Dialog required");
171 *p_itself
= ((DialogObject
*)v
)->ob_itself
;
175 static void DlgObj_dealloc(DialogObject
*self
)
177 DisposeDialog(self
->ob_itself
);
181 static PyObject
*DlgObj_DrawDialog(DialogObject
*_self
, PyObject
*_args
)
183 PyObject
*_res
= NULL
;
185 PyMac_PRECHECK(DrawDialog
);
187 if (!PyArg_ParseTuple(_args
, ""))
189 DrawDialog(_self
->ob_itself
);
195 static PyObject
*DlgObj_UpdateDialog(DialogObject
*_self
, PyObject
*_args
)
197 PyObject
*_res
= NULL
;
200 PyMac_PRECHECK(UpdateDialog
);
202 if (!PyArg_ParseTuple(_args
, "O&",
203 ResObj_Convert
, &updateRgn
))
205 UpdateDialog(_self
->ob_itself
,
212 static PyObject
*DlgObj_HideDialogItem(DialogObject
*_self
, PyObject
*_args
)
214 PyObject
*_res
= NULL
;
215 DialogItemIndex itemNo
;
216 #ifndef HideDialogItem
217 PyMac_PRECHECK(HideDialogItem
);
219 if (!PyArg_ParseTuple(_args
, "h",
222 HideDialogItem(_self
->ob_itself
,
229 static PyObject
*DlgObj_ShowDialogItem(DialogObject
*_self
, PyObject
*_args
)
231 PyObject
*_res
= NULL
;
232 DialogItemIndex itemNo
;
233 #ifndef ShowDialogItem
234 PyMac_PRECHECK(ShowDialogItem
);
236 if (!PyArg_ParseTuple(_args
, "h",
239 ShowDialogItem(_self
->ob_itself
,
246 static PyObject
*DlgObj_FindDialogItem(DialogObject
*_self
, PyObject
*_args
)
248 PyObject
*_res
= NULL
;
249 DialogItemIndexZeroBased _rv
;
251 #ifndef FindDialogItem
252 PyMac_PRECHECK(FindDialogItem
);
254 if (!PyArg_ParseTuple(_args
, "O&",
255 PyMac_GetPoint
, &thePt
))
257 _rv
= FindDialogItem(_self
->ob_itself
,
259 _res
= Py_BuildValue("h",
264 static PyObject
*DlgObj_DialogCut(DialogObject
*_self
, PyObject
*_args
)
266 PyObject
*_res
= NULL
;
268 PyMac_PRECHECK(DialogCut
);
270 if (!PyArg_ParseTuple(_args
, ""))
272 DialogCut(_self
->ob_itself
);
278 static PyObject
*DlgObj_DialogPaste(DialogObject
*_self
, PyObject
*_args
)
280 PyObject
*_res
= NULL
;
282 PyMac_PRECHECK(DialogPaste
);
284 if (!PyArg_ParseTuple(_args
, ""))
286 DialogPaste(_self
->ob_itself
);
292 static PyObject
*DlgObj_DialogCopy(DialogObject
*_self
, PyObject
*_args
)
294 PyObject
*_res
= NULL
;
296 PyMac_PRECHECK(DialogCopy
);
298 if (!PyArg_ParseTuple(_args
, ""))
300 DialogCopy(_self
->ob_itself
);
306 static PyObject
*DlgObj_DialogDelete(DialogObject
*_self
, PyObject
*_args
)
308 PyObject
*_res
= NULL
;
310 PyMac_PRECHECK(DialogDelete
);
312 if (!PyArg_ParseTuple(_args
, ""))
314 DialogDelete(_self
->ob_itself
);
320 static PyObject
*DlgObj_GetDialogItem(DialogObject
*_self
, PyObject
*_args
)
322 PyObject
*_res
= NULL
;
323 DialogItemIndex itemNo
;
324 DialogItemType itemType
;
327 #ifndef GetDialogItem
328 PyMac_PRECHECK(GetDialogItem
);
330 if (!PyArg_ParseTuple(_args
, "h",
333 GetDialogItem(_self
->ob_itself
,
338 _res
= Py_BuildValue("hO&O&",
341 PyMac_BuildRect
, &box
);
345 static PyObject
*DlgObj_SetDialogItem(DialogObject
*_self
, PyObject
*_args
)
347 PyObject
*_res
= NULL
;
348 DialogItemIndex itemNo
;
349 DialogItemType itemType
;
352 #ifndef SetDialogItem
353 PyMac_PRECHECK(SetDialogItem
);
355 if (!PyArg_ParseTuple(_args
, "hhO&O&",
358 ResObj_Convert
, &item
,
359 PyMac_GetRect
, &box
))
361 SetDialogItem(_self
->ob_itself
,
371 static PyObject
*DlgObj_SelectDialogItemText(DialogObject
*_self
, PyObject
*_args
)
373 PyObject
*_res
= NULL
;
374 DialogItemIndex itemNo
;
377 #ifndef SelectDialogItemText
378 PyMac_PRECHECK(SelectDialogItemText
);
380 if (!PyArg_ParseTuple(_args
, "hhh",
385 SelectDialogItemText(_self
->ob_itself
,
394 static PyObject
*DlgObj_AppendDITL(DialogObject
*_self
, PyObject
*_args
)
396 PyObject
*_res
= NULL
;
400 PyMac_PRECHECK(AppendDITL
);
402 if (!PyArg_ParseTuple(_args
, "O&h",
403 ResObj_Convert
, &theHandle
,
406 AppendDITL(_self
->ob_itself
,
414 static PyObject
*DlgObj_CountDITL(DialogObject
*_self
, PyObject
*_args
)
416 PyObject
*_res
= NULL
;
419 PyMac_PRECHECK(CountDITL
);
421 if (!PyArg_ParseTuple(_args
, ""))
423 _rv
= CountDITL(_self
->ob_itself
);
424 _res
= Py_BuildValue("h",
429 static PyObject
*DlgObj_ShortenDITL(DialogObject
*_self
, PyObject
*_args
)
431 PyObject
*_res
= NULL
;
432 DialogItemIndex numberItems
;
434 PyMac_PRECHECK(ShortenDITL
);
436 if (!PyArg_ParseTuple(_args
, "h",
439 ShortenDITL(_self
->ob_itself
,
446 #if TARGET_API_MAC_CARBON
448 static PyObject
*DlgObj_InsertDialogItem(DialogObject
*_self
, PyObject
*_args
)
450 PyObject
*_res
= NULL
;
452 DialogItemIndex afterItem
;
453 DialogItemType itemType
;
456 #ifndef InsertDialogItem
457 PyMac_PRECHECK(InsertDialogItem
);
459 if (!PyArg_ParseTuple(_args
, "hhO&O&",
462 ResObj_Convert
, &itemHandle
,
463 PyMac_GetRect
, &box
))
465 _err
= InsertDialogItem(_self
->ob_itself
,
470 if (_err
!= noErr
) return PyMac_Error(_err
);
477 #if TARGET_API_MAC_CARBON
479 static PyObject
*DlgObj_RemoveDialogItems(DialogObject
*_self
, PyObject
*_args
)
481 PyObject
*_res
= NULL
;
483 DialogItemIndex itemNo
;
484 DialogItemIndex amountToRemove
;
485 Boolean disposeItemData
;
486 #ifndef RemoveDialogItems
487 PyMac_PRECHECK(RemoveDialogItems
);
489 if (!PyArg_ParseTuple(_args
, "hhb",
494 _err
= RemoveDialogItems(_self
->ob_itself
,
498 if (_err
!= noErr
) return PyMac_Error(_err
);
505 static PyObject
*DlgObj_StdFilterProc(DialogObject
*_self
, PyObject
*_args
)
507 PyObject
*_res
= NULL
;
510 DialogItemIndex itemHit
;
511 #ifndef StdFilterProc
512 PyMac_PRECHECK(StdFilterProc
);
514 if (!PyArg_ParseTuple(_args
, ""))
516 _rv
= StdFilterProc(_self
->ob_itself
,
519 _res
= Py_BuildValue("bO&h",
521 PyMac_BuildEventRecord
, &event
,
526 static PyObject
*DlgObj_SetDialogDefaultItem(DialogObject
*_self
, PyObject
*_args
)
528 PyObject
*_res
= NULL
;
530 DialogItemIndex newItem
;
531 #ifndef SetDialogDefaultItem
532 PyMac_PRECHECK(SetDialogDefaultItem
);
534 if (!PyArg_ParseTuple(_args
, "h",
537 _err
= SetDialogDefaultItem(_self
->ob_itself
,
539 if (_err
!= noErr
) return PyMac_Error(_err
);
545 static PyObject
*DlgObj_SetDialogCancelItem(DialogObject
*_self
, PyObject
*_args
)
547 PyObject
*_res
= NULL
;
549 DialogItemIndex newItem
;
550 #ifndef SetDialogCancelItem
551 PyMac_PRECHECK(SetDialogCancelItem
);
553 if (!PyArg_ParseTuple(_args
, "h",
556 _err
= SetDialogCancelItem(_self
->ob_itself
,
558 if (_err
!= noErr
) return PyMac_Error(_err
);
564 static PyObject
*DlgObj_SetDialogTracksCursor(DialogObject
*_self
, PyObject
*_args
)
566 PyObject
*_res
= NULL
;
569 #ifndef SetDialogTracksCursor
570 PyMac_PRECHECK(SetDialogTracksCursor
);
572 if (!PyArg_ParseTuple(_args
, "b",
575 _err
= SetDialogTracksCursor(_self
->ob_itself
,
577 if (_err
!= noErr
) return PyMac_Error(_err
);
583 static PyObject
*DlgObj_AutoSizeDialog(DialogObject
*_self
, PyObject
*_args
)
585 PyObject
*_res
= NULL
;
587 #ifndef AutoSizeDialog
588 PyMac_PRECHECK(AutoSizeDialog
);
590 if (!PyArg_ParseTuple(_args
, ""))
592 _err
= AutoSizeDialog(_self
->ob_itself
);
593 if (_err
!= noErr
) return PyMac_Error(_err
);
599 static PyObject
*DlgObj_GetDialogItemAsControl(DialogObject
*_self
, PyObject
*_args
)
601 PyObject
*_res
= NULL
;
604 ControlHandle outControl
;
605 #ifndef GetDialogItemAsControl
606 PyMac_PRECHECK(GetDialogItemAsControl
);
608 if (!PyArg_ParseTuple(_args
, "h",
611 _err
= GetDialogItemAsControl(_self
->ob_itself
,
614 if (_err
!= noErr
) return PyMac_Error(_err
);
615 _res
= Py_BuildValue("O&",
616 CtlObj_New
, outControl
);
620 static PyObject
*DlgObj_MoveDialogItem(DialogObject
*_self
, PyObject
*_args
)
622 PyObject
*_res
= NULL
;
627 #ifndef MoveDialogItem
628 PyMac_PRECHECK(MoveDialogItem
);
630 if (!PyArg_ParseTuple(_args
, "hhh",
635 _err
= MoveDialogItem(_self
->ob_itself
,
639 if (_err
!= noErr
) return PyMac_Error(_err
);
645 static PyObject
*DlgObj_SizeDialogItem(DialogObject
*_self
, PyObject
*_args
)
647 PyObject
*_res
= NULL
;
652 #ifndef SizeDialogItem
653 PyMac_PRECHECK(SizeDialogItem
);
655 if (!PyArg_ParseTuple(_args
, "hhh",
660 _err
= SizeDialogItem(_self
->ob_itself
,
664 if (_err
!= noErr
) return PyMac_Error(_err
);
670 static PyObject
*DlgObj_AppendDialogItemList(DialogObject
*_self
, PyObject
*_args
)
672 PyObject
*_res
= NULL
;
676 #ifndef AppendDialogItemList
677 PyMac_PRECHECK(AppendDialogItemList
);
679 if (!PyArg_ParseTuple(_args
, "hh",
683 _err
= AppendDialogItemList(_self
->ob_itself
,
686 if (_err
!= noErr
) return PyMac_Error(_err
);
692 static PyObject
*DlgObj_SetDialogTimeout(DialogObject
*_self
, PyObject
*_args
)
694 PyObject
*_res
= NULL
;
696 SInt16 inButtonToPress
;
697 UInt32 inSecondsToWait
;
698 #ifndef SetDialogTimeout
699 PyMac_PRECHECK(SetDialogTimeout
);
701 if (!PyArg_ParseTuple(_args
, "hl",
705 _err
= SetDialogTimeout(_self
->ob_itself
,
708 if (_err
!= noErr
) return PyMac_Error(_err
);
714 static PyObject
*DlgObj_GetDialogTimeout(DialogObject
*_self
, PyObject
*_args
)
716 PyObject
*_res
= NULL
;
718 SInt16 outButtonToPress
;
719 UInt32 outSecondsToWait
;
720 UInt32 outSecondsRemaining
;
721 #ifndef GetDialogTimeout
722 PyMac_PRECHECK(GetDialogTimeout
);
724 if (!PyArg_ParseTuple(_args
, ""))
726 _err
= GetDialogTimeout(_self
->ob_itself
,
729 &outSecondsRemaining
);
730 if (_err
!= noErr
) return PyMac_Error(_err
);
731 _res
= Py_BuildValue("hll",
734 outSecondsRemaining
);
738 static PyObject
*DlgObj_SetModalDialogEventMask(DialogObject
*_self
, PyObject
*_args
)
740 PyObject
*_res
= NULL
;
743 #ifndef SetModalDialogEventMask
744 PyMac_PRECHECK(SetModalDialogEventMask
);
746 if (!PyArg_ParseTuple(_args
, "H",
749 _err
= SetModalDialogEventMask(_self
->ob_itself
,
751 if (_err
!= noErr
) return PyMac_Error(_err
);
757 static PyObject
*DlgObj_GetModalDialogEventMask(DialogObject
*_self
, PyObject
*_args
)
759 PyObject
*_res
= NULL
;
762 #ifndef GetModalDialogEventMask
763 PyMac_PRECHECK(GetModalDialogEventMask
);
765 if (!PyArg_ParseTuple(_args
, ""))
767 _err
= GetModalDialogEventMask(_self
->ob_itself
,
769 if (_err
!= noErr
) return PyMac_Error(_err
);
770 _res
= Py_BuildValue("H",
775 static PyObject
*DlgObj_GetDialogWindow(DialogObject
*_self
, PyObject
*_args
)
777 PyObject
*_res
= NULL
;
779 #ifndef GetDialogWindow
780 PyMac_PRECHECK(GetDialogWindow
);
782 if (!PyArg_ParseTuple(_args
, ""))
784 _rv
= GetDialogWindow(_self
->ob_itself
);
785 _res
= Py_BuildValue("O&",
790 static PyObject
*DlgObj_GetDialogTextEditHandle(DialogObject
*_self
, PyObject
*_args
)
792 PyObject
*_res
= NULL
;
794 #ifndef GetDialogTextEditHandle
795 PyMac_PRECHECK(GetDialogTextEditHandle
);
797 if (!PyArg_ParseTuple(_args
, ""))
799 _rv
= GetDialogTextEditHandle(_self
->ob_itself
);
800 _res
= Py_BuildValue("O&",
805 static PyObject
*DlgObj_GetDialogDefaultItem(DialogObject
*_self
, PyObject
*_args
)
807 PyObject
*_res
= NULL
;
809 #ifndef GetDialogDefaultItem
810 PyMac_PRECHECK(GetDialogDefaultItem
);
812 if (!PyArg_ParseTuple(_args
, ""))
814 _rv
= GetDialogDefaultItem(_self
->ob_itself
);
815 _res
= Py_BuildValue("h",
820 static PyObject
*DlgObj_GetDialogCancelItem(DialogObject
*_self
, PyObject
*_args
)
822 PyObject
*_res
= NULL
;
824 #ifndef GetDialogCancelItem
825 PyMac_PRECHECK(GetDialogCancelItem
);
827 if (!PyArg_ParseTuple(_args
, ""))
829 _rv
= GetDialogCancelItem(_self
->ob_itself
);
830 _res
= Py_BuildValue("h",
835 static PyObject
*DlgObj_GetDialogKeyboardFocusItem(DialogObject
*_self
, PyObject
*_args
)
837 PyObject
*_res
= NULL
;
839 #ifndef GetDialogKeyboardFocusItem
840 PyMac_PRECHECK(GetDialogKeyboardFocusItem
);
842 if (!PyArg_ParseTuple(_args
, ""))
844 _rv
= GetDialogKeyboardFocusItem(_self
->ob_itself
);
845 _res
= Py_BuildValue("h",
850 static PyObject
*DlgObj_SetPortDialogPort(DialogObject
*_self
, PyObject
*_args
)
852 PyObject
*_res
= NULL
;
853 #ifndef SetPortDialogPort
854 PyMac_PRECHECK(SetPortDialogPort
);
856 if (!PyArg_ParseTuple(_args
, ""))
858 SetPortDialogPort(_self
->ob_itself
);
864 static PyObject
*DlgObj_GetDialogPort(DialogObject
*_self
, PyObject
*_args
)
866 PyObject
*_res
= NULL
;
868 #ifndef GetDialogPort
869 PyMac_PRECHECK(GetDialogPort
);
871 if (!PyArg_ParseTuple(_args
, ""))
873 _rv
= GetDialogPort(_self
->ob_itself
);
874 _res
= Py_BuildValue("O&",
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
);
887 if (!PyArg_ParseTuple(_args
, ""))
889 SetGrafPortOfDialog(_self
->ob_itself
);
896 static PyMethodDef DlgObj_methods
[] = {
897 {"DrawDialog", (PyCFunction
)DlgObj_DrawDialog
, 1,
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,
909 {"DialogPaste", (PyCFunction
)DlgObj_DialogPaste
, 1,
911 {"DialogCopy", (PyCFunction
)DlgObj_DialogCopy
, 1,
913 {"DialogDelete", (PyCFunction
)DlgObj_DialogDelete
, 1,
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"},
933 #if TARGET_API_MAC_CARBON
934 {"RemoveDialogItems", (PyCFunction
)DlgObj_RemoveDialogItems
, 1,
935 "(DialogItemIndex itemNo, DialogItemIndex amountToRemove, Boolean disposeItemData) -> None"},
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,
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,
975 {"GetDialogPort", (PyCFunction
)DlgObj_GetDialogPort
, 1,
976 "() -> (CGrafPtr _rv)"},
978 #if !TARGET_API_MAC_CARBON
979 {"SetGrafPortOfDialog", (PyCFunction
)DlgObj_SetGrafPortOfDialog
, 1,
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;
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
)
1011 "_Dlg.Dialog", /*tp_name*/
1012 sizeof(DialogObject
), /*tp_basicsize*/
1015 (destructor
) DlgObj_dealloc
, /*tp_dealloc*/
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
;
1043 PyMac_PRECHECK(NewDialog
);
1045 if (!PyArg_ParseTuple(_args
, "O&O&bhO&blO&",
1046 PyMac_GetRect
, &boundsRect
,
1047 PyMac_GetStr255
, title
,
1050 WinObj_Convert
, &behind
,
1053 ResObj_Convert
, &items
))
1055 _rv
= NewDialog((void *)0,
1064 _res
= Py_BuildValue("O&",
1069 static PyObject
*Dlg_GetNewDialog(PyObject
*_self
, PyObject
*_args
)
1071 PyObject
*_res
= NULL
;
1075 #ifndef GetNewDialog
1076 PyMac_PRECHECK(GetNewDialog
);
1078 if (!PyArg_ParseTuple(_args
, "hO&",
1080 WinObj_Convert
, &behind
))
1082 _rv
= GetNewDialog(dialogID
,
1085 _res
= Py_BuildValue("O&",
1090 static PyObject
*Dlg_NewColorDialog(PyObject
*_self
, PyObject
*_args
)
1092 PyObject
*_res
= NULL
;
1102 #ifndef NewColorDialog
1103 PyMac_PRECHECK(NewColorDialog
);
1105 if (!PyArg_ParseTuple(_args
, "O&O&bhO&blO&",
1106 PyMac_GetRect
, &boundsRect
,
1107 PyMac_GetStr255
, title
,
1110 WinObj_Convert
, &behind
,
1113 ResObj_Convert
, &items
))
1115 _rv
= NewColorDialog((void *)0,
1124 _res
= Py_BuildValue("O&",
1129 static PyObject
*Dlg_ModalDialog(PyObject
*_self
, PyObject
*_args
)
1131 PyObject
*_res
= NULL
;
1132 PyObject
* modalFilter
;
1133 DialogItemIndex itemHit
;
1135 PyMac_PRECHECK(ModalDialog
);
1137 if (!PyArg_ParseTuple(_args
, "O",
1140 ModalDialog(Dlg_PassFilterProc(modalFilter
),
1142 _res
= Py_BuildValue("h",
1147 static PyObject
*Dlg_IsDialogEvent(PyObject
*_self
, PyObject
*_args
)
1149 PyObject
*_res
= NULL
;
1151 EventRecord theEvent
;
1152 #ifndef IsDialogEvent
1153 PyMac_PRECHECK(IsDialogEvent
);
1155 if (!PyArg_ParseTuple(_args
, "O&",
1156 PyMac_GetEventRecord
, &theEvent
))
1158 _rv
= IsDialogEvent(&theEvent
);
1159 _res
= Py_BuildValue("b",
1164 static PyObject
*Dlg_DialogSelect(PyObject
*_self
, PyObject
*_args
)
1166 PyObject
*_res
= NULL
;
1168 EventRecord theEvent
;
1169 DialogPtr theDialog
;
1170 DialogItemIndex itemHit
;
1171 #ifndef DialogSelect
1172 PyMac_PRECHECK(DialogSelect
);
1174 if (!PyArg_ParseTuple(_args
, "O&",
1175 PyMac_GetEventRecord
, &theEvent
))
1177 _rv
= DialogSelect(&theEvent
,
1180 _res
= Py_BuildValue("bO&h",
1182 DlgObj_WhichDialog
, theDialog
,
1187 static PyObject
*Dlg_Alert(PyObject
*_self
, PyObject
*_args
)
1189 PyObject
*_res
= NULL
;
1190 DialogItemIndex _rv
;
1192 PyObject
* modalFilter
;
1194 PyMac_PRECHECK(Alert
);
1196 if (!PyArg_ParseTuple(_args
, "hO",
1200 _rv
= Alert(alertID
,
1201 Dlg_PassFilterProc(modalFilter
));
1202 _res
= Py_BuildValue("h",
1207 static PyObject
*Dlg_StopAlert(PyObject
*_self
, PyObject
*_args
)
1209 PyObject
*_res
= NULL
;
1210 DialogItemIndex _rv
;
1212 PyObject
* modalFilter
;
1214 PyMac_PRECHECK(StopAlert
);
1216 if (!PyArg_ParseTuple(_args
, "hO",
1220 _rv
= StopAlert(alertID
,
1221 Dlg_PassFilterProc(modalFilter
));
1222 _res
= Py_BuildValue("h",
1227 static PyObject
*Dlg_NoteAlert(PyObject
*_self
, PyObject
*_args
)
1229 PyObject
*_res
= NULL
;
1230 DialogItemIndex _rv
;
1232 PyObject
* modalFilter
;
1234 PyMac_PRECHECK(NoteAlert
);
1236 if (!PyArg_ParseTuple(_args
, "hO",
1240 _rv
= NoteAlert(alertID
,
1241 Dlg_PassFilterProc(modalFilter
));
1242 _res
= Py_BuildValue("h",
1247 static PyObject
*Dlg_CautionAlert(PyObject
*_self
, PyObject
*_args
)
1249 PyObject
*_res
= NULL
;
1250 DialogItemIndex _rv
;
1252 PyObject
* modalFilter
;
1253 #ifndef CautionAlert
1254 PyMac_PRECHECK(CautionAlert
);
1256 if (!PyArg_ParseTuple(_args
, "hO",
1260 _rv
= CautionAlert(alertID
,
1261 Dlg_PassFilterProc(modalFilter
));
1262 _res
= Py_BuildValue("h",
1267 static PyObject
*Dlg_ParamText(PyObject
*_self
, PyObject
*_args
)
1269 PyObject
*_res
= NULL
;
1275 PyMac_PRECHECK(ParamText
);
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
))
1292 static PyObject
*Dlg_GetDialogItemText(PyObject
*_self
, PyObject
*_args
)
1294 PyObject
*_res
= NULL
;
1297 #ifndef GetDialogItemText
1298 PyMac_PRECHECK(GetDialogItemText
);
1300 if (!PyArg_ParseTuple(_args
, "O&",
1301 ResObj_Convert
, &item
))
1303 GetDialogItemText(item
,
1305 _res
= Py_BuildValue("O&",
1306 PyMac_BuildStr255
, text
);
1310 static PyObject
*Dlg_SetDialogItemText(PyObject
*_self
, PyObject
*_args
)
1312 PyObject
*_res
= NULL
;
1315 #ifndef SetDialogItemText
1316 PyMac_PRECHECK(SetDialogItemText
);
1318 if (!PyArg_ParseTuple(_args
, "O&O&",
1319 ResObj_Convert
, &item
,
1320 PyMac_GetStr255
, text
))
1322 SetDialogItemText(item
,
1329 static PyObject
*Dlg_GetAlertStage(PyObject
*_self
, PyObject
*_args
)
1331 PyObject
*_res
= NULL
;
1333 #ifndef GetAlertStage
1334 PyMac_PRECHECK(GetAlertStage
);
1336 if (!PyArg_ParseTuple(_args
, ""))
1338 _rv
= GetAlertStage();
1339 _res
= Py_BuildValue("h",
1344 static PyObject
*Dlg_SetDialogFont(PyObject
*_self
, PyObject
*_args
)
1346 PyObject
*_res
= NULL
;
1348 #ifndef SetDialogFont
1349 PyMac_PRECHECK(SetDialogFont
);
1351 if (!PyArg_ParseTuple(_args
, "h",
1354 SetDialogFont(fontNum
);
1360 static PyObject
*Dlg_ResetAlertStage(PyObject
*_self
, PyObject
*_args
)
1362 PyObject
*_res
= NULL
;
1363 #ifndef ResetAlertStage
1364 PyMac_PRECHECK(ResetAlertStage
);
1366 if (!PyArg_ParseTuple(_args
, ""))
1374 #if TARGET_API_MAC_CARBON
1376 static PyObject
*Dlg_GetParamText(PyObject
*_self
, PyObject
*_args
)
1378 PyObject
*_res
= NULL
;
1383 #ifndef GetParamText
1384 PyMac_PRECHECK(GetParamText
);
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
))
1392 GetParamText(param0
,
1402 static PyObject
*Dlg_NewFeaturesDialog(PyObject
*_self
, PyObject
*_args
)
1404 PyObject
*_res
= NULL
;
1408 Boolean inIsVisible
;
1411 Boolean inGoAwayFlag
;
1413 Handle inItemListHandle
;
1415 #ifndef NewFeaturesDialog
1416 PyMac_PRECHECK(NewFeaturesDialog
);
1418 if (!PyArg_ParseTuple(_args
, "O&O&bhO&blO&l",
1419 PyMac_GetRect
, &inBoundsRect
,
1420 PyMac_GetStr255
, inTitle
,
1423 WinObj_Convert
, &inBehind
,
1426 ResObj_Convert
, &inItemListHandle
,
1429 _rv
= NewFeaturesDialog((void *)0,
1439 _res
= Py_BuildValue("O&",
1444 static PyObject
*Dlg_GetDialogFromWindow(PyObject
*_self
, PyObject
*_args
)
1446 PyObject
*_res
= NULL
;
1449 #ifndef GetDialogFromWindow
1450 PyMac_PRECHECK(GetDialogFromWindow
);
1452 if (!PyArg_ParseTuple(_args
, "O&",
1453 WinObj_Convert
, &window
))
1455 _rv
= GetDialogFromWindow(window
);
1456 _res
= Py_BuildValue("O&",
1461 static PyObject
*Dlg_SetUserItemHandler(PyObject
*_self
, PyObject
*_args
)
1463 PyObject
*_res
= NULL
;
1465 PyObject
*new = NULL
;
1468 if (!PyArg_ParseTuple(_args
, "|O", &new))
1471 if (Dlg_UserItemProc_callback
&& new && new != Py_None
) {
1472 PyErr_SetString(Dlg_Error
, "Another UserItemProc is already installed");
1476 if (new == NULL
|| new == Py_None
) {
1482 _res
= Py_BuildValue("O&", ResObj_New
, (Handle
)NewUserItemUPP(Dlg_UnivUserItemProc
));
1485 Dlg_UserItemProc_callback
= new;
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,
1524 #if TARGET_API_MAC_CARBON
1525 {"GetParamText", (PyCFunction
)Dlg_GetParamText
, 1,
1526 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
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,
1539 /* Return the WindowPtr corresponding to a DialogObject */
1542 DlgObj_ConvertToWindow(PyObject
*self
)
1544 if ( DlgObj_Check(self
) )
1545 return GetDialogWindow(((DialogObject
*)self
)->ob_itself
);
1549 /* Return the object corresponding to the dialog, or None */
1552 DlgObj_WhichDialog(DialogPtr d
)
1560 WindowPtr w
= GetDialogWindow(d
);
1562 it
= (PyObject
*) GetWRefCon(w
);
1563 if (it
== NULL
|| ((DialogObject
*)it
)->ob_itself
!= d
|| !DlgObj_Check(it
)) {
1565 /* Should do this, but we don't have an ob_freeit for dialogs yet. */
1567 ((WindowObject
*)it
)->ob_freeit
= NULL
;
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)
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 ========================= */