2 /* =========================== Module Dlg =========================== */
9 #include "pymactoolbox.h"
11 #ifdef WITHOUT_FRAMEWORKS
14 #include <Carbon/Carbon.h>
17 #ifdef USE_TOOLBOX_OBJECT_GLUE
18 extern PyObject
*_DlgObj_New(DialogRef
);
19 extern PyObject
*_DlgObj_WhichDialog(DialogRef
);
20 extern int _DlgObj_Convert(PyObject
*, DialogRef
*);
22 #define DlgObj_New _DlgObj_New
23 #define DlgObj_WhichDialog _DlgObj_WhichDialog
24 #define DlgObj_Convert _DlgObj_Convert
27 #if !ACCESSOR_CALLS_ARE_FUNCTIONS
28 #define GetDialogTextEditHandle(dlg) (((DialogPeek)(dlg))->textH)
29 #define SetPortDialogPort(dlg) SetPort(dlg)
30 #define GetDialogPort(dlg) ((CGrafPtr)(dlg))
31 #define GetDialogFromWindow(win) ((DialogRef)(win))
34 /* XXX Shouldn't this be a stack? */
35 static PyObject
*Dlg_FilterProc_callback
= NULL
;
37 static pascal Boolean
Dlg_UnivFilterProc(DialogPtr dialog
,
43 PyObject
*callback
= Dlg_FilterProc_callback
;
45 return 0; /* Default behavior */
46 Dlg_FilterProc_callback
= NULL
; /* We'll restore it when call successful */
47 args
= Py_BuildValue("O&O&", DlgObj_WhichDialog
, dialog
, PyMac_BuildEventRecord
, event
);
51 res
= PyEval_CallObject(callback
, args
);
55 PySys_WriteStderr("Exception in Dialog Filter\n");
57 *itemHit
= -1; /* Fake return item */
58 return 1; /* We handled it */
61 Dlg_FilterProc_callback
= callback
;
62 if (PyInt_Check(res
)) {
63 *itemHit
= PyInt_AsLong(res
);
67 rv
= PyObject_IsTrue(res
);
74 Dlg_PassFilterProc(PyObject
*callback
)
76 PyObject
*tmp
= Dlg_FilterProc_callback
;
77 static ModalFilterUPP UnivFilterUpp
= NULL
;
79 Dlg_FilterProc_callback
= NULL
;
80 if (callback
== Py_None
) {
85 Dlg_FilterProc_callback
= callback
;
87 if ( UnivFilterUpp
== NULL
)
88 UnivFilterUpp
= NewModalFilterUPP(&Dlg_UnivFilterProc
);
92 static PyObject
*Dlg_UserItemProc_callback
= NULL
;
94 static pascal void Dlg_UnivUserItemProc(DialogPtr dialog
,
99 if (Dlg_UserItemProc_callback
== NULL
)
100 return; /* Default behavior */
101 Dlg_FilterProc_callback
= NULL
; /* We'll restore it when call successful */
102 args
= Py_BuildValue("O&h", DlgObj_WhichDialog
, dialog
, item
);
106 res
= PyEval_CallObject(Dlg_UserItemProc_callback
, args
);
110 PySys_WriteStderr("Exception in Dialog UserItem proc\n");
119 ** Treating DialogObjects as WindowObjects is (I think) illegal under Carbon.
120 ** However, as they are still identical under MacOS9 Carbon this is a problem, even
121 ** if we neatly call GetDialogWindow() at the right places: there's one refcon field
122 ** and it points to the DialogObject, so WinObj_WhichWindow will smartly return the
123 ** dialog object, and therefore we still don't have a WindowObject.
124 ** I'll leave the chaining code in place for now, with this comment to warn the
125 ** unsuspecting victims (i.e. me, probably, in a few weeks:-)
127 extern PyMethodChain WinObj_chain
;
130 static PyObject
*Dlg_Error
;
132 /* ----------------------- Object type Dialog ----------------------- */
134 PyTypeObject Dialog_Type
;
136 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
138 typedef struct DialogObject
{
143 PyObject
*DlgObj_New(DialogPtr itself
)
146 if (itself
== NULL
) return Py_None
;
147 it
= PyObject_NEW(DialogObject
, &Dialog_Type
);
148 if (it
== NULL
) return NULL
;
149 it
->ob_itself
= itself
;
150 SetWRefCon(GetDialogWindow(itself
), (long)it
);
151 return (PyObject
*)it
;
153 DlgObj_Convert(PyObject
*v
, DialogPtr
*p_itself
)
155 if (v
== Py_None
) { *p_itself
= NULL
; return 1; }
156 if (PyInt_Check(v
)) { *p_itself
= (DialogPtr
)PyInt_AsLong(v
);
158 if (!DlgObj_Check(v
))
160 PyErr_SetString(PyExc_TypeError
, "Dialog required");
163 *p_itself
= ((DialogObject
*)v
)->ob_itself
;
167 static void DlgObj_dealloc(DialogObject
*self
)
169 DisposeDialog(self
->ob_itself
);
173 static PyObject
*DlgObj_DrawDialog(DialogObject
*_self
, PyObject
*_args
)
175 PyObject
*_res
= NULL
;
176 if (!PyArg_ParseTuple(_args
, ""))
178 DrawDialog(_self
->ob_itself
);
184 static PyObject
*DlgObj_UpdateDialog(DialogObject
*_self
, PyObject
*_args
)
186 PyObject
*_res
= NULL
;
188 if (!PyArg_ParseTuple(_args
, "O&",
189 ResObj_Convert
, &updateRgn
))
191 UpdateDialog(_self
->ob_itself
,
198 static PyObject
*DlgObj_HideDialogItem(DialogObject
*_self
, PyObject
*_args
)
200 PyObject
*_res
= NULL
;
201 DialogItemIndex itemNo
;
202 if (!PyArg_ParseTuple(_args
, "h",
205 HideDialogItem(_self
->ob_itself
,
212 static PyObject
*DlgObj_ShowDialogItem(DialogObject
*_self
, PyObject
*_args
)
214 PyObject
*_res
= NULL
;
215 DialogItemIndex itemNo
;
216 if (!PyArg_ParseTuple(_args
, "h",
219 ShowDialogItem(_self
->ob_itself
,
226 static PyObject
*DlgObj_FindDialogItem(DialogObject
*_self
, PyObject
*_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(DialogObject
*_self
, PyObject
*_args
)
243 PyObject
*_res
= NULL
;
244 if (!PyArg_ParseTuple(_args
, ""))
246 DialogCut(_self
->ob_itself
);
252 static PyObject
*DlgObj_DialogPaste(DialogObject
*_self
, PyObject
*_args
)
254 PyObject
*_res
= NULL
;
255 if (!PyArg_ParseTuple(_args
, ""))
257 DialogPaste(_self
->ob_itself
);
263 static PyObject
*DlgObj_DialogCopy(DialogObject
*_self
, PyObject
*_args
)
265 PyObject
*_res
= NULL
;
266 if (!PyArg_ParseTuple(_args
, ""))
268 DialogCopy(_self
->ob_itself
);
274 static PyObject
*DlgObj_DialogDelete(DialogObject
*_self
, PyObject
*_args
)
276 PyObject
*_res
= NULL
;
277 if (!PyArg_ParseTuple(_args
, ""))
279 DialogDelete(_self
->ob_itself
);
285 static PyObject
*DlgObj_GetDialogItem(DialogObject
*_self
, PyObject
*_args
)
287 PyObject
*_res
= NULL
;
288 DialogItemIndex itemNo
;
289 DialogItemType itemType
;
292 if (!PyArg_ParseTuple(_args
, "h",
295 GetDialogItem(_self
->ob_itself
,
300 _res
= Py_BuildValue("hO&O&",
303 PyMac_BuildRect
, &box
);
307 static PyObject
*DlgObj_SetDialogItem(DialogObject
*_self
, PyObject
*_args
)
309 PyObject
*_res
= NULL
;
310 DialogItemIndex itemNo
;
311 DialogItemType itemType
;
314 if (!PyArg_ParseTuple(_args
, "hhO&O&",
317 ResObj_Convert
, &item
,
318 PyMac_GetRect
, &box
))
320 SetDialogItem(_self
->ob_itself
,
330 static PyObject
*DlgObj_SelectDialogItemText(DialogObject
*_self
, PyObject
*_args
)
332 PyObject
*_res
= NULL
;
333 DialogItemIndex itemNo
;
336 if (!PyArg_ParseTuple(_args
, "hhh",
341 SelectDialogItemText(_self
->ob_itself
,
350 static PyObject
*DlgObj_AppendDITL(DialogObject
*_self
, PyObject
*_args
)
352 PyObject
*_res
= NULL
;
355 if (!PyArg_ParseTuple(_args
, "O&h",
356 ResObj_Convert
, &theHandle
,
359 AppendDITL(_self
->ob_itself
,
367 static PyObject
*DlgObj_CountDITL(DialogObject
*_self
, PyObject
*_args
)
369 PyObject
*_res
= NULL
;
371 if (!PyArg_ParseTuple(_args
, ""))
373 _rv
= CountDITL(_self
->ob_itself
);
374 _res
= Py_BuildValue("h",
379 static PyObject
*DlgObj_ShortenDITL(DialogObject
*_self
, PyObject
*_args
)
381 PyObject
*_res
= NULL
;
382 DialogItemIndex numberItems
;
383 if (!PyArg_ParseTuple(_args
, "h",
386 ShortenDITL(_self
->ob_itself
,
393 #if TARGET_API_MAC_CARBON
395 static PyObject
*DlgObj_InsertDialogItem(DialogObject
*_self
, PyObject
*_args
)
397 PyObject
*_res
= NULL
;
399 DialogItemIndex afterItem
;
400 DialogItemType itemType
;
403 if (!PyArg_ParseTuple(_args
, "hhO&O&",
406 ResObj_Convert
, &itemHandle
,
407 PyMac_GetRect
, &box
))
409 _err
= InsertDialogItem(_self
->ob_itself
,
414 if (_err
!= noErr
) return PyMac_Error(_err
);
421 #if TARGET_API_MAC_CARBON
423 static PyObject
*DlgObj_RemoveDialogItems(DialogObject
*_self
, PyObject
*_args
)
425 PyObject
*_res
= NULL
;
427 DialogItemIndex itemNo
;
428 DialogItemIndex amountToRemove
;
429 Boolean disposeItemData
;
430 if (!PyArg_ParseTuple(_args
, "hhb",
435 _err
= RemoveDialogItems(_self
->ob_itself
,
439 if (_err
!= noErr
) return PyMac_Error(_err
);
446 static PyObject
*DlgObj_StdFilterProc(DialogObject
*_self
, PyObject
*_args
)
448 PyObject
*_res
= NULL
;
451 DialogItemIndex itemHit
;
452 if (!PyArg_ParseTuple(_args
, ""))
454 _rv
= StdFilterProc(_self
->ob_itself
,
457 _res
= Py_BuildValue("bO&h",
459 PyMac_BuildEventRecord
, &event
,
464 static PyObject
*DlgObj_SetDialogDefaultItem(DialogObject
*_self
, PyObject
*_args
)
466 PyObject
*_res
= NULL
;
468 DialogItemIndex newItem
;
469 if (!PyArg_ParseTuple(_args
, "h",
472 _err
= SetDialogDefaultItem(_self
->ob_itself
,
474 if (_err
!= noErr
) return PyMac_Error(_err
);
480 static PyObject
*DlgObj_SetDialogCancelItem(DialogObject
*_self
, PyObject
*_args
)
482 PyObject
*_res
= NULL
;
484 DialogItemIndex newItem
;
485 if (!PyArg_ParseTuple(_args
, "h",
488 _err
= SetDialogCancelItem(_self
->ob_itself
,
490 if (_err
!= noErr
) return PyMac_Error(_err
);
496 static PyObject
*DlgObj_SetDialogTracksCursor(DialogObject
*_self
, PyObject
*_args
)
498 PyObject
*_res
= NULL
;
501 if (!PyArg_ParseTuple(_args
, "b",
504 _err
= SetDialogTracksCursor(_self
->ob_itself
,
506 if (_err
!= noErr
) return PyMac_Error(_err
);
512 static PyObject
*DlgObj_AutoSizeDialog(DialogObject
*_self
, PyObject
*_args
)
514 PyObject
*_res
= NULL
;
516 if (!PyArg_ParseTuple(_args
, ""))
518 _err
= AutoSizeDialog(_self
->ob_itself
);
519 if (_err
!= noErr
) return PyMac_Error(_err
);
525 static PyObject
*DlgObj_GetDialogItemAsControl(DialogObject
*_self
, PyObject
*_args
)
527 PyObject
*_res
= NULL
;
530 ControlHandle outControl
;
531 if (!PyArg_ParseTuple(_args
, "h",
534 _err
= GetDialogItemAsControl(_self
->ob_itself
,
537 if (_err
!= noErr
) return PyMac_Error(_err
);
538 _res
= Py_BuildValue("O&",
539 CtlObj_New
, outControl
);
543 static PyObject
*DlgObj_MoveDialogItem(DialogObject
*_self
, PyObject
*_args
)
545 PyObject
*_res
= NULL
;
550 if (!PyArg_ParseTuple(_args
, "hhh",
555 _err
= MoveDialogItem(_self
->ob_itself
,
559 if (_err
!= noErr
) return PyMac_Error(_err
);
565 static PyObject
*DlgObj_SizeDialogItem(DialogObject
*_self
, PyObject
*_args
)
567 PyObject
*_res
= NULL
;
572 if (!PyArg_ParseTuple(_args
, "hhh",
577 _err
= SizeDialogItem(_self
->ob_itself
,
581 if (_err
!= noErr
) return PyMac_Error(_err
);
587 static PyObject
*DlgObj_AppendDialogItemList(DialogObject
*_self
, PyObject
*_args
)
589 PyObject
*_res
= NULL
;
593 if (!PyArg_ParseTuple(_args
, "hh",
597 _err
= AppendDialogItemList(_self
->ob_itself
,
600 if (_err
!= noErr
) return PyMac_Error(_err
);
606 static PyObject
*DlgObj_SetDialogTimeout(DialogObject
*_self
, PyObject
*_args
)
608 PyObject
*_res
= NULL
;
610 SInt16 inButtonToPress
;
611 UInt32 inSecondsToWait
;
612 if (!PyArg_ParseTuple(_args
, "hl",
616 _err
= SetDialogTimeout(_self
->ob_itself
,
619 if (_err
!= noErr
) return PyMac_Error(_err
);
625 static PyObject
*DlgObj_GetDialogTimeout(DialogObject
*_self
, PyObject
*_args
)
627 PyObject
*_res
= NULL
;
629 SInt16 outButtonToPress
;
630 UInt32 outSecondsToWait
;
631 UInt32 outSecondsRemaining
;
632 if (!PyArg_ParseTuple(_args
, ""))
634 _err
= GetDialogTimeout(_self
->ob_itself
,
637 &outSecondsRemaining
);
638 if (_err
!= noErr
) return PyMac_Error(_err
);
639 _res
= Py_BuildValue("hll",
642 outSecondsRemaining
);
646 static PyObject
*DlgObj_SetModalDialogEventMask(DialogObject
*_self
, PyObject
*_args
)
648 PyObject
*_res
= NULL
;
651 if (!PyArg_ParseTuple(_args
, "H",
654 _err
= SetModalDialogEventMask(_self
->ob_itself
,
656 if (_err
!= noErr
) return PyMac_Error(_err
);
662 static PyObject
*DlgObj_GetModalDialogEventMask(DialogObject
*_self
, PyObject
*_args
)
664 PyObject
*_res
= NULL
;
667 if (!PyArg_ParseTuple(_args
, ""))
669 _err
= GetModalDialogEventMask(_self
->ob_itself
,
671 if (_err
!= noErr
) return PyMac_Error(_err
);
672 _res
= Py_BuildValue("H",
677 static PyObject
*DlgObj_GetDialogWindow(DialogObject
*_self
, PyObject
*_args
)
679 PyObject
*_res
= NULL
;
681 if (!PyArg_ParseTuple(_args
, ""))
683 _rv
= GetDialogWindow(_self
->ob_itself
);
684 _res
= Py_BuildValue("O&",
689 static PyObject
*DlgObj_GetDialogTextEditHandle(DialogObject
*_self
, PyObject
*_args
)
691 PyObject
*_res
= NULL
;
693 if (!PyArg_ParseTuple(_args
, ""))
695 _rv
= GetDialogTextEditHandle(_self
->ob_itself
);
696 _res
= Py_BuildValue("O&",
701 static PyObject
*DlgObj_GetDialogDefaultItem(DialogObject
*_self
, PyObject
*_args
)
703 PyObject
*_res
= NULL
;
705 if (!PyArg_ParseTuple(_args
, ""))
707 _rv
= GetDialogDefaultItem(_self
->ob_itself
);
708 _res
= Py_BuildValue("h",
713 static PyObject
*DlgObj_GetDialogCancelItem(DialogObject
*_self
, PyObject
*_args
)
715 PyObject
*_res
= NULL
;
717 if (!PyArg_ParseTuple(_args
, ""))
719 _rv
= GetDialogCancelItem(_self
->ob_itself
);
720 _res
= Py_BuildValue("h",
725 static PyObject
*DlgObj_GetDialogKeyboardFocusItem(DialogObject
*_self
, PyObject
*_args
)
727 PyObject
*_res
= NULL
;
729 if (!PyArg_ParseTuple(_args
, ""))
731 _rv
= GetDialogKeyboardFocusItem(_self
->ob_itself
);
732 _res
= Py_BuildValue("h",
737 static PyObject
*DlgObj_SetPortDialogPort(DialogObject
*_self
, PyObject
*_args
)
739 PyObject
*_res
= NULL
;
740 if (!PyArg_ParseTuple(_args
, ""))
742 SetPortDialogPort(_self
->ob_itself
);
748 static PyObject
*DlgObj_GetDialogPort(DialogObject
*_self
, PyObject
*_args
)
750 PyObject
*_res
= NULL
;
752 if (!PyArg_ParseTuple(_args
, ""))
754 _rv
= GetDialogPort(_self
->ob_itself
);
755 _res
= Py_BuildValue("O&",
760 #if !TARGET_API_MAC_CARBON
762 static PyObject
*DlgObj_SetGrafPortOfDialog(DialogObject
*_self
, PyObject
*_args
)
764 PyObject
*_res
= NULL
;
765 if (!PyArg_ParseTuple(_args
, ""))
767 SetGrafPortOfDialog(_self
->ob_itself
);
774 static PyMethodDef DlgObj_methods
[] = {
775 {"DrawDialog", (PyCFunction
)DlgObj_DrawDialog
, 1,
777 {"UpdateDialog", (PyCFunction
)DlgObj_UpdateDialog
, 1,
778 "(RgnHandle updateRgn) -> None"},
779 {"HideDialogItem", (PyCFunction
)DlgObj_HideDialogItem
, 1,
780 "(DialogItemIndex itemNo) -> None"},
781 {"ShowDialogItem", (PyCFunction
)DlgObj_ShowDialogItem
, 1,
782 "(DialogItemIndex itemNo) -> None"},
783 {"FindDialogItem", (PyCFunction
)DlgObj_FindDialogItem
, 1,
784 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
785 {"DialogCut", (PyCFunction
)DlgObj_DialogCut
, 1,
787 {"DialogPaste", (PyCFunction
)DlgObj_DialogPaste
, 1,
789 {"DialogCopy", (PyCFunction
)DlgObj_DialogCopy
, 1,
791 {"DialogDelete", (PyCFunction
)DlgObj_DialogDelete
, 1,
793 {"GetDialogItem", (PyCFunction
)DlgObj_GetDialogItem
, 1,
794 "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"},
795 {"SetDialogItem", (PyCFunction
)DlgObj_SetDialogItem
, 1,
796 "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"},
797 {"SelectDialogItemText", (PyCFunction
)DlgObj_SelectDialogItemText
, 1,
798 "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"},
799 {"AppendDITL", (PyCFunction
)DlgObj_AppendDITL
, 1,
800 "(Handle theHandle, DITLMethod method) -> None"},
801 {"CountDITL", (PyCFunction
)DlgObj_CountDITL
, 1,
802 "() -> (DialogItemIndex _rv)"},
803 {"ShortenDITL", (PyCFunction
)DlgObj_ShortenDITL
, 1,
804 "(DialogItemIndex numberItems) -> None"},
806 #if TARGET_API_MAC_CARBON
807 {"InsertDialogItem", (PyCFunction
)DlgObj_InsertDialogItem
, 1,
808 "(DialogItemIndex afterItem, DialogItemType itemType, Handle itemHandle, Rect box) -> None"},
811 #if TARGET_API_MAC_CARBON
812 {"RemoveDialogItems", (PyCFunction
)DlgObj_RemoveDialogItems
, 1,
813 "(DialogItemIndex itemNo, DialogItemIndex amountToRemove, Boolean disposeItemData) -> None"},
815 {"StdFilterProc", (PyCFunction
)DlgObj_StdFilterProc
, 1,
816 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
817 {"SetDialogDefaultItem", (PyCFunction
)DlgObj_SetDialogDefaultItem
, 1,
818 "(DialogItemIndex newItem) -> None"},
819 {"SetDialogCancelItem", (PyCFunction
)DlgObj_SetDialogCancelItem
, 1,
820 "(DialogItemIndex newItem) -> None"},
821 {"SetDialogTracksCursor", (PyCFunction
)DlgObj_SetDialogTracksCursor
, 1,
822 "(Boolean tracks) -> None"},
823 {"AutoSizeDialog", (PyCFunction
)DlgObj_AutoSizeDialog
, 1,
825 {"GetDialogItemAsControl", (PyCFunction
)DlgObj_GetDialogItemAsControl
, 1,
826 "(SInt16 inItemNo) -> (ControlHandle outControl)"},
827 {"MoveDialogItem", (PyCFunction
)DlgObj_MoveDialogItem
, 1,
828 "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"},
829 {"SizeDialogItem", (PyCFunction
)DlgObj_SizeDialogItem
, 1,
830 "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"},
831 {"AppendDialogItemList", (PyCFunction
)DlgObj_AppendDialogItemList
, 1,
832 "(SInt16 ditlID, DITLMethod method) -> None"},
833 {"SetDialogTimeout", (PyCFunction
)DlgObj_SetDialogTimeout
, 1,
834 "(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None"},
835 {"GetDialogTimeout", (PyCFunction
)DlgObj_GetDialogTimeout
, 1,
836 "() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)"},
837 {"SetModalDialogEventMask", (PyCFunction
)DlgObj_SetModalDialogEventMask
, 1,
838 "(EventMask inMask) -> None"},
839 {"GetModalDialogEventMask", (PyCFunction
)DlgObj_GetModalDialogEventMask
, 1,
840 "() -> (EventMask outMask)"},
841 {"GetDialogWindow", (PyCFunction
)DlgObj_GetDialogWindow
, 1,
842 "() -> (WindowPtr _rv)"},
843 {"GetDialogTextEditHandle", (PyCFunction
)DlgObj_GetDialogTextEditHandle
, 1,
844 "() -> (TEHandle _rv)"},
845 {"GetDialogDefaultItem", (PyCFunction
)DlgObj_GetDialogDefaultItem
, 1,
846 "() -> (SInt16 _rv)"},
847 {"GetDialogCancelItem", (PyCFunction
)DlgObj_GetDialogCancelItem
, 1,
848 "() -> (SInt16 _rv)"},
849 {"GetDialogKeyboardFocusItem", (PyCFunction
)DlgObj_GetDialogKeyboardFocusItem
, 1,
850 "() -> (SInt16 _rv)"},
851 {"SetPortDialogPort", (PyCFunction
)DlgObj_SetPortDialogPort
, 1,
853 {"GetDialogPort", (PyCFunction
)DlgObj_GetDialogPort
, 1,
854 "() -> (CGrafPtr _rv)"},
856 #if !TARGET_API_MAC_CARBON
857 {"SetGrafPortOfDialog", (PyCFunction
)DlgObj_SetGrafPortOfDialog
, 1,
863 PyMethodChain DlgObj_chain
= { DlgObj_methods
, NULL
};
865 static PyObject
*DlgObj_getattr(DialogObject
*self
, char *name
)
867 return Py_FindMethodInChain(&DlgObj_chain
, (PyObject
*)self
, name
);
870 #define DlgObj_setattr NULL
872 static int DlgObj_compare(DialogObject
*self
, DialogObject
*other
)
874 if ( self
->ob_itself
> other
->ob_itself
) return 1;
875 if ( self
->ob_itself
< other
->ob_itself
) return -1;
879 #define DlgObj_repr NULL
881 static int DlgObj_hash(DialogObject
*self
)
883 return (int)self
->ob_itself
;
886 PyTypeObject Dialog_Type
= {
887 PyObject_HEAD_INIT(&PyType_Type
)
889 "Dialog", /*tp_name*/
890 sizeof(DialogObject
), /*tp_basicsize*/
893 (destructor
) DlgObj_dealloc
, /*tp_dealloc*/
895 (getattrfunc
) DlgObj_getattr
, /*tp_getattr*/
896 (setattrfunc
) DlgObj_setattr
, /*tp_setattr*/
897 (cmpfunc
) DlgObj_compare
, /*tp_compare*/
898 (reprfunc
) DlgObj_repr
, /*tp_repr*/
899 (PyNumberMethods
*)0, /* tp_as_number */
900 (PySequenceMethods
*)0, /* tp_as_sequence */
901 (PyMappingMethods
*)0, /* tp_as_mapping */
902 (hashfunc
) DlgObj_hash
, /*tp_hash*/
905 /* --------------------- End object type Dialog --------------------- */
908 static PyObject
*Dlg_NewDialog(PyObject
*_self
, PyObject
*_args
)
910 PyObject
*_res
= NULL
;
920 if (!PyArg_ParseTuple(_args
, "O&O&bhO&blO&",
921 PyMac_GetRect
, &boundsRect
,
922 PyMac_GetStr255
, title
,
925 WinObj_Convert
, &behind
,
928 ResObj_Convert
, &items
))
930 _rv
= NewDialog((void *)0,
939 _res
= Py_BuildValue("O&",
944 static PyObject
*Dlg_GetNewDialog(PyObject
*_self
, PyObject
*_args
)
946 PyObject
*_res
= NULL
;
950 if (!PyArg_ParseTuple(_args
, "hO&",
952 WinObj_Convert
, &behind
))
954 _rv
= GetNewDialog(dialogID
,
957 _res
= Py_BuildValue("O&",
962 static PyObject
*Dlg_NewColorDialog(PyObject
*_self
, PyObject
*_args
)
964 PyObject
*_res
= NULL
;
974 if (!PyArg_ParseTuple(_args
, "O&O&bhO&blO&",
975 PyMac_GetRect
, &boundsRect
,
976 PyMac_GetStr255
, title
,
979 WinObj_Convert
, &behind
,
982 ResObj_Convert
, &items
))
984 _rv
= NewColorDialog((void *)0,
993 _res
= Py_BuildValue("O&",
998 static PyObject
*Dlg_ModalDialog(PyObject
*_self
, PyObject
*_args
)
1000 PyObject
*_res
= NULL
;
1001 PyObject
* modalFilter
;
1002 DialogItemIndex itemHit
;
1003 if (!PyArg_ParseTuple(_args
, "O",
1006 ModalDialog(Dlg_PassFilterProc(modalFilter
),
1008 _res
= Py_BuildValue("h",
1013 static PyObject
*Dlg_IsDialogEvent(PyObject
*_self
, PyObject
*_args
)
1015 PyObject
*_res
= NULL
;
1017 EventRecord theEvent
;
1018 if (!PyArg_ParseTuple(_args
, "O&",
1019 PyMac_GetEventRecord
, &theEvent
))
1021 _rv
= IsDialogEvent(&theEvent
);
1022 _res
= Py_BuildValue("b",
1027 static PyObject
*Dlg_DialogSelect(PyObject
*_self
, PyObject
*_args
)
1029 PyObject
*_res
= NULL
;
1031 EventRecord theEvent
;
1032 DialogPtr theDialog
;
1033 DialogItemIndex itemHit
;
1034 if (!PyArg_ParseTuple(_args
, "O&",
1035 PyMac_GetEventRecord
, &theEvent
))
1037 _rv
= DialogSelect(&theEvent
,
1040 _res
= Py_BuildValue("bO&h",
1042 DlgObj_WhichDialog
, theDialog
,
1047 static PyObject
*Dlg_Alert(PyObject
*_self
, PyObject
*_args
)
1049 PyObject
*_res
= NULL
;
1050 DialogItemIndex _rv
;
1052 PyObject
* modalFilter
;
1053 if (!PyArg_ParseTuple(_args
, "hO",
1057 _rv
= Alert(alertID
,
1058 Dlg_PassFilterProc(modalFilter
));
1059 _res
= Py_BuildValue("h",
1064 static PyObject
*Dlg_StopAlert(PyObject
*_self
, PyObject
*_args
)
1066 PyObject
*_res
= NULL
;
1067 DialogItemIndex _rv
;
1069 PyObject
* modalFilter
;
1070 if (!PyArg_ParseTuple(_args
, "hO",
1074 _rv
= StopAlert(alertID
,
1075 Dlg_PassFilterProc(modalFilter
));
1076 _res
= Py_BuildValue("h",
1081 static PyObject
*Dlg_NoteAlert(PyObject
*_self
, PyObject
*_args
)
1083 PyObject
*_res
= NULL
;
1084 DialogItemIndex _rv
;
1086 PyObject
* modalFilter
;
1087 if (!PyArg_ParseTuple(_args
, "hO",
1091 _rv
= NoteAlert(alertID
,
1092 Dlg_PassFilterProc(modalFilter
));
1093 _res
= Py_BuildValue("h",
1098 static PyObject
*Dlg_CautionAlert(PyObject
*_self
, PyObject
*_args
)
1100 PyObject
*_res
= NULL
;
1101 DialogItemIndex _rv
;
1103 PyObject
* modalFilter
;
1104 if (!PyArg_ParseTuple(_args
, "hO",
1108 _rv
= CautionAlert(alertID
,
1109 Dlg_PassFilterProc(modalFilter
));
1110 _res
= Py_BuildValue("h",
1115 static PyObject
*Dlg_ParamText(PyObject
*_self
, PyObject
*_args
)
1117 PyObject
*_res
= NULL
;
1122 if (!PyArg_ParseTuple(_args
, "O&O&O&O&",
1123 PyMac_GetStr255
, param0
,
1124 PyMac_GetStr255
, param1
,
1125 PyMac_GetStr255
, param2
,
1126 PyMac_GetStr255
, param3
))
1137 static PyObject
*Dlg_GetDialogItemText(PyObject
*_self
, PyObject
*_args
)
1139 PyObject
*_res
= NULL
;
1142 if (!PyArg_ParseTuple(_args
, "O&",
1143 ResObj_Convert
, &item
))
1145 GetDialogItemText(item
,
1147 _res
= Py_BuildValue("O&",
1148 PyMac_BuildStr255
, text
);
1152 static PyObject
*Dlg_SetDialogItemText(PyObject
*_self
, PyObject
*_args
)
1154 PyObject
*_res
= NULL
;
1157 if (!PyArg_ParseTuple(_args
, "O&O&",
1158 ResObj_Convert
, &item
,
1159 PyMac_GetStr255
, text
))
1161 SetDialogItemText(item
,
1168 static PyObject
*Dlg_GetAlertStage(PyObject
*_self
, PyObject
*_args
)
1170 PyObject
*_res
= NULL
;
1172 if (!PyArg_ParseTuple(_args
, ""))
1174 _rv
= GetAlertStage();
1175 _res
= Py_BuildValue("h",
1180 static PyObject
*Dlg_SetDialogFont(PyObject
*_self
, PyObject
*_args
)
1182 PyObject
*_res
= NULL
;
1184 if (!PyArg_ParseTuple(_args
, "h",
1187 SetDialogFont(fontNum
);
1193 static PyObject
*Dlg_ResetAlertStage(PyObject
*_self
, PyObject
*_args
)
1195 PyObject
*_res
= NULL
;
1196 if (!PyArg_ParseTuple(_args
, ""))
1204 #if TARGET_API_MAC_CARBON
1206 static PyObject
*Dlg_GetParamText(PyObject
*_self
, PyObject
*_args
)
1208 PyObject
*_res
= NULL
;
1213 if (!PyArg_ParseTuple(_args
, "O&O&O&O&",
1214 PyMac_GetStr255
, param0
,
1215 PyMac_GetStr255
, param1
,
1216 PyMac_GetStr255
, param2
,
1217 PyMac_GetStr255
, param3
))
1219 GetParamText(param0
,
1229 static PyObject
*Dlg_NewFeaturesDialog(PyObject
*_self
, PyObject
*_args
)
1231 PyObject
*_res
= NULL
;
1235 Boolean inIsVisible
;
1238 Boolean inGoAwayFlag
;
1240 Handle inItemListHandle
;
1242 if (!PyArg_ParseTuple(_args
, "O&O&bhO&blO&l",
1243 PyMac_GetRect
, &inBoundsRect
,
1244 PyMac_GetStr255
, inTitle
,
1247 WinObj_Convert
, &inBehind
,
1250 ResObj_Convert
, &inItemListHandle
,
1253 _rv
= NewFeaturesDialog((void *)0,
1263 _res
= Py_BuildValue("O&",
1268 static PyObject
*Dlg_GetDialogFromWindow(PyObject
*_self
, PyObject
*_args
)
1270 PyObject
*_res
= NULL
;
1273 if (!PyArg_ParseTuple(_args
, "O&",
1274 WinObj_Convert
, &window
))
1276 _rv
= GetDialogFromWindow(window
);
1277 _res
= Py_BuildValue("O&",
1282 static PyObject
*Dlg_SetUserItemHandler(PyObject
*_self
, PyObject
*_args
)
1284 PyObject
*_res
= NULL
;
1286 PyObject
*new = NULL
;
1289 if (!PyArg_ParseTuple(_args
, "|O", &new))
1292 if (Dlg_UserItemProc_callback
&& new && new != Py_None
) {
1293 PyErr_SetString(Dlg_Error
, "Another UserItemProc is already installed");
1297 if (new == NULL
|| new == Py_None
) {
1303 _res
= Py_BuildValue("O&", ResObj_New
, (Handle
)NewUserItemUPP(Dlg_UnivUserItemProc
));
1306 Dlg_UserItemProc_callback
= new;
1311 static PyMethodDef Dlg_methods
[] = {
1312 {"NewDialog", (PyCFunction
)Dlg_NewDialog
, 1,
1313 "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
1314 {"GetNewDialog", (PyCFunction
)Dlg_GetNewDialog
, 1,
1315 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1316 {"NewColorDialog", (PyCFunction
)Dlg_NewColorDialog
, 1,
1317 "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
1318 {"ModalDialog", (PyCFunction
)Dlg_ModalDialog
, 1,
1319 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
1320 {"IsDialogEvent", (PyCFunction
)Dlg_IsDialogEvent
, 1,
1321 "(EventRecord theEvent) -> (Boolean _rv)"},
1322 {"DialogSelect", (PyCFunction
)Dlg_DialogSelect
, 1,
1323 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
1324 {"Alert", (PyCFunction
)Dlg_Alert
, 1,
1325 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1326 {"StopAlert", (PyCFunction
)Dlg_StopAlert
, 1,
1327 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1328 {"NoteAlert", (PyCFunction
)Dlg_NoteAlert
, 1,
1329 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1330 {"CautionAlert", (PyCFunction
)Dlg_CautionAlert
, 1,
1331 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1332 {"ParamText", (PyCFunction
)Dlg_ParamText
, 1,
1333 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1334 {"GetDialogItemText", (PyCFunction
)Dlg_GetDialogItemText
, 1,
1335 "(Handle item) -> (Str255 text)"},
1336 {"SetDialogItemText", (PyCFunction
)Dlg_SetDialogItemText
, 1,
1337 "(Handle item, Str255 text) -> None"},
1338 {"GetAlertStage", (PyCFunction
)Dlg_GetAlertStage
, 1,
1339 "() -> (SInt16 _rv)"},
1340 {"SetDialogFont", (PyCFunction
)Dlg_SetDialogFont
, 1,
1341 "(SInt16 fontNum) -> None"},
1342 {"ResetAlertStage", (PyCFunction
)Dlg_ResetAlertStage
, 1,
1345 #if TARGET_API_MAC_CARBON
1346 {"GetParamText", (PyCFunction
)Dlg_GetParamText
, 1,
1347 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1349 {"NewFeaturesDialog", (PyCFunction
)Dlg_NewFeaturesDialog
, 1,
1350 "(Rect inBoundsRect, Str255 inTitle, Boolean inIsVisible, SInt16 inProcID, WindowPtr inBehind, Boolean inGoAwayFlag, SInt32 inRefCon, Handle inItemListHandle, UInt32 inFlags) -> (DialogPtr _rv)"},
1351 {"GetDialogFromWindow", (PyCFunction
)Dlg_GetDialogFromWindow
, 1,
1352 "(WindowPtr window) -> (DialogPtr _rv)"},
1353 {"SetUserItemHandler", (PyCFunction
)Dlg_SetUserItemHandler
, 1,
1360 /* Return the WindowPtr corresponding to a DialogObject */
1363 DlgObj_ConvertToWindow(PyObject
*self
)
1365 if ( DlgObj_Check(self
) )
1366 return GetDialogWindow(((DialogObject
*)self
)->ob_itself
);
1370 /* Return the object corresponding to the dialog, or None */
1373 DlgObj_WhichDialog(DialogPtr d
)
1381 WindowPtr w
= GetDialogWindow(d
);
1383 it
= (PyObject
*) GetWRefCon(w
);
1384 if (it
== NULL
|| ((DialogObject
*)it
)->ob_itself
!= d
|| !DlgObj_Check(it
)) {
1386 /* Should do this, but we don't have an ob_freeit for dialogs yet. */
1388 ((WindowObject
*)it
)->ob_freeit
= NULL
;
1408 PyMac_INIT_TOOLBOX_OBJECT_NEW(DialogPtr
, DlgObj_New
);
1409 PyMac_INIT_TOOLBOX_OBJECT_NEW(DialogPtr
, DlgObj_WhichDialog
);
1410 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DialogPtr
, DlgObj_Convert
);
1413 m
= Py_InitModule("Dlg", Dlg_methods
);
1414 d
= PyModule_GetDict(m
);
1415 Dlg_Error
= PyMac_GetOSErrException();
1416 if (Dlg_Error
== NULL
||
1417 PyDict_SetItemString(d
, "Error", Dlg_Error
) != 0)
1419 Dialog_Type
.ob_type
= &PyType_Type
;
1420 Py_INCREF(&Dialog_Type
);
1421 if (PyDict_SetItemString(d
, "DialogType", (PyObject
*)&Dialog_Type
) != 0)
1422 Py_FatalError("can't initialize DialogType");
1425 /* ========================= End module Dlg ========================= */