blob: 3c3c855a0872acbf3233342f4c4fbe0368a503c1 [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001
2/* =========================== Module Dlg =========================== */
3
4#include "Python.h"
5
6
7
Guido van Rossum17448e21995-01-30 11:53:55 +00008#include "macglue.h"
Jack Jansen9d8b96c2000-07-14 22:16:45 +00009#include "pymactoolbox.h"
Guido van Rossum17448e21995-01-30 11:53:55 +000010
Jack Jansenfa77e1a2001-05-22 21:56:42 +000011#ifdef WITHOUT_FRAMEWORKS
Guido van Rossum17448e21995-01-30 11:53:55 +000012#include <Dialogs.h>
Jack Jansenfa77e1a2001-05-22 21:56:42 +000013#else
14#include <Carbon/Carbon.h>
15#endif
16
Jack Jansen0e04eec2001-05-17 21:58:34 +000017#ifdef USE_TOOLBOX_OBJECT_GLUE
18extern PyObject *_DlgObj_New(DialogRef);
19extern PyObject *_DlgObj_WhichDialog(DialogRef);
20extern int _DlgObj_Convert(PyObject *, DialogRef *);
21
22#define DlgObj_New _DlgObj_New
23#define DlgObj_WhichDialog _DlgObj_WhichDialog
24#define DlgObj_Convert _DlgObj_Convert
25#endif
Guido van Rossum17448e21995-01-30 11:53:55 +000026
Jack Jansenf7d5aa62000-12-10 23:43:49 +000027#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))
32#endif
33
Guido van Rossum17448e21995-01-30 11:53:55 +000034/* XXX Shouldn't this be a stack? */
35static PyObject *Dlg_FilterProc_callback = NULL;
36
Guido van Rossum17448e21995-01-30 11:53:55 +000037static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog,
38 EventRecord *event,
39 short *itemHit)
40{
41 Boolean rv;
42 PyObject *args, *res;
43 PyObject *callback = Dlg_FilterProc_callback;
44 if (callback == NULL)
45 return 0; /* Default behavior */
46 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
Jack Jansen69e7f112001-02-06 16:14:54 +000047 args = Py_BuildValue("O&O&", DlgObj_WhichDialog, dialog, PyMac_BuildEventRecord, event);
Guido van Rossum17448e21995-01-30 11:53:55 +000048 if (args == NULL)
49 res = NULL;
50 else {
51 res = PyEval_CallObject(callback, args);
52 Py_DECREF(args);
53 }
54 if (res == NULL) {
Jack Jansendeff89c1998-10-12 20:53:15 +000055 PySys_WriteStderr("Exception in Dialog Filter\n");
Guido van Rossum17448e21995-01-30 11:53:55 +000056 PyErr_Print();
57 *itemHit = -1; /* Fake return item */
58 return 1; /* We handled it */
59 }
60 else {
61 Dlg_FilterProc_callback = callback;
62 if (PyInt_Check(res)) {
63 *itemHit = PyInt_AsLong(res);
64 rv = 1;
65 }
66 else
67 rv = PyObject_IsTrue(res);
68 }
69 Py_DECREF(res);
70 return rv;
71}
72
Jack Jansen599ce9c2001-02-20 22:27:43 +000073static ModalFilterUPP
Guido van Rossum17448e21995-01-30 11:53:55 +000074Dlg_PassFilterProc(PyObject *callback)
75{
76 PyObject *tmp = Dlg_FilterProc_callback;
Jack Jansen599ce9c2001-02-20 22:27:43 +000077 static ModalFilterUPP UnivFilterUpp = NULL;
78
Guido van Rossum17448e21995-01-30 11:53:55 +000079 Dlg_FilterProc_callback = NULL;
80 if (callback == Py_None) {
81 Py_XDECREF(tmp);
82 return NULL;
83 }
84 Py_INCREF(callback);
85 Dlg_FilterProc_callback = callback;
86 Py_XDECREF(tmp);
Jack Jansen599ce9c2001-02-20 22:27:43 +000087 if ( UnivFilterUpp == NULL )
88 UnivFilterUpp = NewModalFilterUPP(&Dlg_UnivFilterProc);
89 return UnivFilterUpp;
Guido van Rossum17448e21995-01-30 11:53:55 +000090}
91
Jack Jansendf901df1998-07-10 15:47:48 +000092static PyObject *Dlg_UserItemProc_callback = NULL;
93
94static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
95 short item)
96{
97 PyObject *args, *res;
98
99 if (Dlg_UserItemProc_callback == NULL)
100 return; /* Default behavior */
101 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
Jack Jansen69e7f112001-02-06 16:14:54 +0000102 args = Py_BuildValue("O&h", DlgObj_WhichDialog, dialog, item);
Jack Jansendf901df1998-07-10 15:47:48 +0000103 if (args == NULL)
104 res = NULL;
105 else {
106 res = PyEval_CallObject(Dlg_UserItemProc_callback, args);
107 Py_DECREF(args);
108 }
109 if (res == NULL) {
Jack Jansendeff89c1998-10-12 20:53:15 +0000110 PySys_WriteStderr("Exception in Dialog UserItem proc\n");
Jack Jansendf901df1998-07-10 15:47:48 +0000111 PyErr_Print();
112 }
113 Py_XDECREF(res);
114 return;
115}
116
Jack Jansen69e7f112001-02-06 16:14:54 +0000117#if 0
Jack Jansenb8c4c7b2000-08-25 22:25:54 +0000118/*
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:-)
126*/
Guido van Rossum17448e21995-01-30 11:53:55 +0000127extern PyMethodChain WinObj_chain;
Jack Jansenb8c4c7b2000-08-25 22:25:54 +0000128#endif
Guido van Rossum17448e21995-01-30 11:53:55 +0000129
130static PyObject *Dlg_Error;
131
132/* ----------------------- Object type Dialog ----------------------- */
133
134PyTypeObject Dialog_Type;
135
136#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
137
138typedef struct DialogObject {
139 PyObject_HEAD
140 DialogPtr ob_itself;
141} DialogObject;
142
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000143PyObject *DlgObj_New(DialogPtr itself)
Guido van Rossum17448e21995-01-30 11:53:55 +0000144{
145 DialogObject *it;
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;
Jack Jansene79dc762000-06-02 21:35:07 +0000150 SetWRefCon(GetDialogWindow(itself), (long)it);
Guido van Rossum17448e21995-01-30 11:53:55 +0000151 return (PyObject *)it;
152}
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000153DlgObj_Convert(PyObject *v, DialogPtr *p_itself)
Guido van Rossum17448e21995-01-30 11:53:55 +0000154{
155 if (v == Py_None) { *p_itself = NULL; return 1; }
156 if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
157 return 1; }
158 if (!DlgObj_Check(v))
159 {
160 PyErr_SetString(PyExc_TypeError, "Dialog required");
161 return 0;
162 }
163 *p_itself = ((DialogObject *)v)->ob_itself;
164 return 1;
165}
166
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000167static void DlgObj_dealloc(DialogObject *self)
Guido van Rossum17448e21995-01-30 11:53:55 +0000168{
169 DisposeDialog(self->ob_itself);
170 PyMem_DEL(self);
171}
172
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000173static PyObject *DlgObj_DrawDialog(DialogObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000174{
175 PyObject *_res = NULL;
176 if (!PyArg_ParseTuple(_args, ""))
177 return NULL;
178 DrawDialog(_self->ob_itself);
179 Py_INCREF(Py_None);
180 _res = Py_None;
181 return _res;
182}
183
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000184static PyObject *DlgObj_UpdateDialog(DialogObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000185{
186 PyObject *_res = NULL;
Jack Jansen2b724171996-04-10 14:48:19 +0000187 RgnHandle updateRgn;
188 if (!PyArg_ParseTuple(_args, "O&",
189 ResObj_Convert, &updateRgn))
Guido van Rossum17448e21995-01-30 11:53:55 +0000190 return NULL;
191 UpdateDialog(_self->ob_itself,
Jack Jansen2b724171996-04-10 14:48:19 +0000192 updateRgn);
Guido van Rossum17448e21995-01-30 11:53:55 +0000193 Py_INCREF(Py_None);
194 _res = Py_None;
195 return _res;
196}
197
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000198static PyObject *DlgObj_HideDialogItem(DialogObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000199{
200 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000201 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000202 if (!PyArg_ParseTuple(_args, "h",
203 &itemNo))
204 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000205 HideDialogItem(_self->ob_itself,
206 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000207 Py_INCREF(Py_None);
208 _res = Py_None;
209 return _res;
210}
211
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000212static PyObject *DlgObj_ShowDialogItem(DialogObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000213{
214 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000215 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000216 if (!PyArg_ParseTuple(_args, "h",
217 &itemNo))
218 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000219 ShowDialogItem(_self->ob_itself,
220 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000221 Py_INCREF(Py_None);
222 _res = Py_None;
223 return _res;
224}
225
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000226static PyObject *DlgObj_FindDialogItem(DialogObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000227{
228 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000229 DialogItemIndexZeroBased _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000230 Point thePt;
231 if (!PyArg_ParseTuple(_args, "O&",
232 PyMac_GetPoint, &thePt))
233 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000234 _rv = FindDialogItem(_self->ob_itself,
235 thePt);
Guido van Rossum17448e21995-01-30 11:53:55 +0000236 _res = Py_BuildValue("h",
237 _rv);
238 return _res;
239}
240
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000241static PyObject *DlgObj_DialogCut(DialogObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000242{
243 PyObject *_res = NULL;
244 if (!PyArg_ParseTuple(_args, ""))
245 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000246 DialogCut(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000247 Py_INCREF(Py_None);
248 _res = Py_None;
249 return _res;
250}
251
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000252static PyObject *DlgObj_DialogPaste(DialogObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000253{
254 PyObject *_res = NULL;
255 if (!PyArg_ParseTuple(_args, ""))
256 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000257 DialogPaste(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000258 Py_INCREF(Py_None);
259 _res = Py_None;
260 return _res;
261}
262
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000263static PyObject *DlgObj_DialogCopy(DialogObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000264{
265 PyObject *_res = NULL;
266 if (!PyArg_ParseTuple(_args, ""))
267 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000268 DialogCopy(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000269 Py_INCREF(Py_None);
270 _res = Py_None;
271 return _res;
272}
273
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000274static PyObject *DlgObj_DialogDelete(DialogObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000275{
276 PyObject *_res = NULL;
277 if (!PyArg_ParseTuple(_args, ""))
278 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000279 DialogDelete(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000280 Py_INCREF(Py_None);
281 _res = Py_None;
282 return _res;
283}
284
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000285static PyObject *DlgObj_GetDialogItem(DialogObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000286{
287 PyObject *_res = NULL;
288 DialogItemIndex itemNo;
289 DialogItemType itemType;
290 Handle item;
291 Rect box;
292 if (!PyArg_ParseTuple(_args, "h",
293 &itemNo))
294 return NULL;
295 GetDialogItem(_self->ob_itself,
296 itemNo,
297 &itemType,
298 &item,
299 &box);
300 _res = Py_BuildValue("hO&O&",
301 itemType,
302 OptResObj_New, item,
303 PyMac_BuildRect, &box);
304 return _res;
305}
306
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000307static PyObject *DlgObj_SetDialogItem(DialogObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000308{
309 PyObject *_res = NULL;
310 DialogItemIndex itemNo;
311 DialogItemType itemType;
312 Handle item;
313 Rect box;
314 if (!PyArg_ParseTuple(_args, "hhO&O&",
315 &itemNo,
316 &itemType,
317 ResObj_Convert, &item,
318 PyMac_GetRect, &box))
319 return NULL;
320 SetDialogItem(_self->ob_itself,
321 itemNo,
322 itemType,
323 item,
324 &box);
325 Py_INCREF(Py_None);
326 _res = Py_None;
327 return _res;
328}
329
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000330static PyObject *DlgObj_SelectDialogItemText(DialogObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000331{
332 PyObject *_res = NULL;
333 DialogItemIndex itemNo;
334 SInt16 strtSel;
335 SInt16 endSel;
336 if (!PyArg_ParseTuple(_args, "hhh",
337 &itemNo,
338 &strtSel,
339 &endSel))
340 return NULL;
341 SelectDialogItemText(_self->ob_itself,
342 itemNo,
343 strtSel,
344 endSel);
345 Py_INCREF(Py_None);
346 _res = Py_None;
347 return _res;
348}
349
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000350static PyObject *DlgObj_AppendDITL(DialogObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000351{
352 PyObject *_res = NULL;
353 Handle theHandle;
354 DITLMethod method;
355 if (!PyArg_ParseTuple(_args, "O&h",
356 ResObj_Convert, &theHandle,
357 &method))
358 return NULL;
359 AppendDITL(_self->ob_itself,
360 theHandle,
361 method);
362 Py_INCREF(Py_None);
363 _res = Py_None;
364 return _res;
365}
366
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000367static PyObject *DlgObj_CountDITL(DialogObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000368{
369 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000370 DialogItemIndex _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000371 if (!PyArg_ParseTuple(_args, ""))
372 return NULL;
373 _rv = CountDITL(_self->ob_itself);
374 _res = Py_BuildValue("h",
375 _rv);
376 return _res;
377}
378
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000379static PyObject *DlgObj_ShortenDITL(DialogObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000380{
381 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000382 DialogItemIndex numberItems;
Guido van Rossum17448e21995-01-30 11:53:55 +0000383 if (!PyArg_ParseTuple(_args, "h",
384 &numberItems))
385 return NULL;
386 ShortenDITL(_self->ob_itself,
387 numberItems);
388 Py_INCREF(Py_None);
389 _res = Py_None;
390 return _res;
391}
392
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000393#if TARGET_API_MAC_CARBON
394
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000395static PyObject *DlgObj_InsertDialogItem(DialogObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000396{
397 PyObject *_res = NULL;
398 OSStatus _err;
399 DialogItemIndex afterItem;
400 DialogItemType itemType;
401 Handle itemHandle;
402 Rect box;
403 if (!PyArg_ParseTuple(_args, "hhO&O&",
404 &afterItem,
405 &itemType,
406 ResObj_Convert, &itemHandle,
407 PyMac_GetRect, &box))
408 return NULL;
409 _err = InsertDialogItem(_self->ob_itself,
410 afterItem,
411 itemType,
412 itemHandle,
413 &box);
414 if (_err != noErr) return PyMac_Error(_err);
415 Py_INCREF(Py_None);
416 _res = Py_None;
417 return _res;
418}
419#endif
420
421#if TARGET_API_MAC_CARBON
422
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000423static PyObject *DlgObj_RemoveDialogItems(DialogObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000424{
425 PyObject *_res = NULL;
426 OSStatus _err;
427 DialogItemIndex itemNo;
428 DialogItemIndex amountToRemove;
429 Boolean disposeItemData;
430 if (!PyArg_ParseTuple(_args, "hhb",
431 &itemNo,
432 &amountToRemove,
433 &disposeItemData))
434 return NULL;
435 _err = RemoveDialogItems(_self->ob_itself,
436 itemNo,
437 amountToRemove,
438 disposeItemData);
439 if (_err != noErr) return PyMac_Error(_err);
440 Py_INCREF(Py_None);
441 _res = Py_None;
442 return _res;
443}
444#endif
445
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000446static PyObject *DlgObj_StdFilterProc(DialogObject *_self, PyObject *_args)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000447{
448 PyObject *_res = NULL;
449 Boolean _rv;
450 EventRecord event;
Jack Jansen21f96871998-02-20 16:02:09 +0000451 DialogItemIndex itemHit;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000452 if (!PyArg_ParseTuple(_args, ""))
453 return NULL;
454 _rv = StdFilterProc(_self->ob_itself,
455 &event,
456 &itemHit);
457 _res = Py_BuildValue("bO&h",
458 _rv,
459 PyMac_BuildEventRecord, &event,
460 itemHit);
461 return _res;
462}
463
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000464static PyObject *DlgObj_SetDialogDefaultItem(DialogObject *_self, PyObject *_args)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000465{
466 PyObject *_res = NULL;
467 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000468 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000469 if (!PyArg_ParseTuple(_args, "h",
470 &newItem))
471 return NULL;
472 _err = SetDialogDefaultItem(_self->ob_itself,
473 newItem);
474 if (_err != noErr) return PyMac_Error(_err);
475 Py_INCREF(Py_None);
476 _res = Py_None;
477 return _res;
478}
479
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000480static PyObject *DlgObj_SetDialogCancelItem(DialogObject *_self, PyObject *_args)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000481{
482 PyObject *_res = NULL;
483 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000484 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000485 if (!PyArg_ParseTuple(_args, "h",
486 &newItem))
487 return NULL;
488 _err = SetDialogCancelItem(_self->ob_itself,
489 newItem);
490 if (_err != noErr) return PyMac_Error(_err);
491 Py_INCREF(Py_None);
492 _res = Py_None;
493 return _res;
494}
495
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000496static PyObject *DlgObj_SetDialogTracksCursor(DialogObject *_self, PyObject *_args)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000497{
498 PyObject *_res = NULL;
499 OSErr _err;
500 Boolean tracks;
501 if (!PyArg_ParseTuple(_args, "b",
502 &tracks))
503 return NULL;
504 _err = SetDialogTracksCursor(_self->ob_itself,
505 tracks);
506 if (_err != noErr) return PyMac_Error(_err);
507 Py_INCREF(Py_None);
508 _res = Py_None;
509 return _res;
510}
511
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000512static PyObject *DlgObj_AutoSizeDialog(DialogObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000513{
514 PyObject *_res = NULL;
515 OSErr _err;
516 if (!PyArg_ParseTuple(_args, ""))
517 return NULL;
518 _err = AutoSizeDialog(_self->ob_itself);
519 if (_err != noErr) return PyMac_Error(_err);
520 Py_INCREF(Py_None);
521 _res = Py_None;
522 return _res;
523}
524
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000525static PyObject *DlgObj_GetDialogItemAsControl(DialogObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000526{
527 PyObject *_res = NULL;
528 OSErr _err;
529 SInt16 inItemNo;
530 ControlHandle outControl;
531 if (!PyArg_ParseTuple(_args, "h",
532 &inItemNo))
533 return NULL;
534 _err = GetDialogItemAsControl(_self->ob_itself,
535 inItemNo,
536 &outControl);
537 if (_err != noErr) return PyMac_Error(_err);
538 _res = Py_BuildValue("O&",
539 CtlObj_New, outControl);
540 return _res;
541}
542
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000543static PyObject *DlgObj_MoveDialogItem(DialogObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000544{
545 PyObject *_res = NULL;
546 OSErr _err;
547 SInt16 inItemNo;
548 SInt16 inHoriz;
549 SInt16 inVert;
550 if (!PyArg_ParseTuple(_args, "hhh",
551 &inItemNo,
552 &inHoriz,
553 &inVert))
554 return NULL;
555 _err = MoveDialogItem(_self->ob_itself,
556 inItemNo,
557 inHoriz,
558 inVert);
559 if (_err != noErr) return PyMac_Error(_err);
560 Py_INCREF(Py_None);
561 _res = Py_None;
562 return _res;
563}
564
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000565static PyObject *DlgObj_SizeDialogItem(DialogObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000566{
567 PyObject *_res = NULL;
568 OSErr _err;
569 SInt16 inItemNo;
Jack Jansen21f96871998-02-20 16:02:09 +0000570 SInt16 inWidth;
Jack Jansen1c4e6141998-04-21 15:23:55 +0000571 SInt16 inHeight;
Jack Jansen21f96871998-02-20 16:02:09 +0000572 if (!PyArg_ParseTuple(_args, "hhh",
573 &inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000574 &inWidth,
575 &inHeight))
Jack Jansen21f96871998-02-20 16:02:09 +0000576 return NULL;
577 _err = SizeDialogItem(_self->ob_itself,
578 inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000579 inWidth,
580 inHeight);
Jack Jansen21f96871998-02-20 16:02:09 +0000581 if (_err != noErr) return PyMac_Error(_err);
582 Py_INCREF(Py_None);
583 _res = Py_None;
584 return _res;
585}
586
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000587static PyObject *DlgObj_AppendDialogItemList(DialogObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000588{
589 PyObject *_res = NULL;
590 OSErr _err;
591 SInt16 ditlID;
592 DITLMethod method;
593 if (!PyArg_ParseTuple(_args, "hh",
594 &ditlID,
595 &method))
596 return NULL;
597 _err = AppendDialogItemList(_self->ob_itself,
598 ditlID,
599 method);
600 if (_err != noErr) return PyMac_Error(_err);
601 Py_INCREF(Py_None);
602 _res = Py_None;
603 return _res;
604}
605
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000606static PyObject *DlgObj_SetDialogTimeout(DialogObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000607{
608 PyObject *_res = NULL;
609 OSStatus _err;
610 SInt16 inButtonToPress;
611 UInt32 inSecondsToWait;
612 if (!PyArg_ParseTuple(_args, "hl",
613 &inButtonToPress,
614 &inSecondsToWait))
615 return NULL;
616 _err = SetDialogTimeout(_self->ob_itself,
617 inButtonToPress,
618 inSecondsToWait);
619 if (_err != noErr) return PyMac_Error(_err);
620 Py_INCREF(Py_None);
621 _res = Py_None;
622 return _res;
623}
624
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000625static PyObject *DlgObj_GetDialogTimeout(DialogObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000626{
627 PyObject *_res = NULL;
628 OSStatus _err;
629 SInt16 outButtonToPress;
630 UInt32 outSecondsToWait;
631 UInt32 outSecondsRemaining;
632 if (!PyArg_ParseTuple(_args, ""))
633 return NULL;
634 _err = GetDialogTimeout(_self->ob_itself,
635 &outButtonToPress,
636 &outSecondsToWait,
637 &outSecondsRemaining);
638 if (_err != noErr) return PyMac_Error(_err);
639 _res = Py_BuildValue("hll",
640 outButtonToPress,
641 outSecondsToWait,
642 outSecondsRemaining);
643 return _res;
644}
645
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000646static PyObject *DlgObj_SetModalDialogEventMask(DialogObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000647{
648 PyObject *_res = NULL;
649 OSStatus _err;
650 EventMask inMask;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000651 if (!PyArg_ParseTuple(_args, "H",
Jack Jansena05ac601999-12-12 21:41:51 +0000652 &inMask))
653 return NULL;
654 _err = SetModalDialogEventMask(_self->ob_itself,
655 inMask);
656 if (_err != noErr) return PyMac_Error(_err);
657 Py_INCREF(Py_None);
658 _res = Py_None;
659 return _res;
660}
661
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000662static PyObject *DlgObj_GetModalDialogEventMask(DialogObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000663{
664 PyObject *_res = NULL;
665 OSStatus _err;
666 EventMask outMask;
667 if (!PyArg_ParseTuple(_args, ""))
668 return NULL;
669 _err = GetModalDialogEventMask(_self->ob_itself,
670 &outMask);
671 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000672 _res = Py_BuildValue("H",
Jack Jansena05ac601999-12-12 21:41:51 +0000673 outMask);
674 return _res;
675}
676
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000677static PyObject *DlgObj_GetDialogWindow(DialogObject *_self, PyObject *_args)
Jack Jansend96cb501996-09-23 15:48:46 +0000678{
679 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000680 WindowPtr _rv;
Jack Jansend96cb501996-09-23 15:48:46 +0000681 if (!PyArg_ParseTuple(_args, ""))
682 return NULL;
683 _rv = GetDialogWindow(_self->ob_itself);
684 _res = Py_BuildValue("O&",
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000685 WinObj_New, _rv);
686 return _res;
687}
688
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000689static PyObject *DlgObj_GetDialogTextEditHandle(DialogObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000690{
691 PyObject *_res = NULL;
692 TEHandle _rv;
693 if (!PyArg_ParseTuple(_args, ""))
694 return NULL;
695 _rv = GetDialogTextEditHandle(_self->ob_itself);
696 _res = Py_BuildValue("O&",
697 ResObj_New, _rv);
Jack Jansend96cb501996-09-23 15:48:46 +0000698 return _res;
699}
700
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000701static PyObject *DlgObj_GetDialogDefaultItem(DialogObject *_self, PyObject *_args)
Jack Jansend96cb501996-09-23 15:48:46 +0000702{
703 PyObject *_res = NULL;
704 SInt16 _rv;
705 if (!PyArg_ParseTuple(_args, ""))
706 return NULL;
707 _rv = GetDialogDefaultItem(_self->ob_itself);
708 _res = Py_BuildValue("h",
709 _rv);
710 return _res;
711}
712
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000713static PyObject *DlgObj_GetDialogCancelItem(DialogObject *_self, PyObject *_args)
Jack Jansend96cb501996-09-23 15:48:46 +0000714{
715 PyObject *_res = NULL;
716 SInt16 _rv;
717 if (!PyArg_ParseTuple(_args, ""))
718 return NULL;
719 _rv = GetDialogCancelItem(_self->ob_itself);
720 _res = Py_BuildValue("h",
721 _rv);
722 return _res;
723}
724
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000725static PyObject *DlgObj_GetDialogKeyboardFocusItem(DialogObject *_self, PyObject *_args)
Jack Jansend96cb501996-09-23 15:48:46 +0000726{
727 PyObject *_res = NULL;
728 SInt16 _rv;
729 if (!PyArg_ParseTuple(_args, ""))
730 return NULL;
731 _rv = GetDialogKeyboardFocusItem(_self->ob_itself);
732 _res = Py_BuildValue("h",
733 _rv);
734 return _res;
735}
736
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000737static PyObject *DlgObj_SetPortDialogPort(DialogObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000738{
739 PyObject *_res = NULL;
740 if (!PyArg_ParseTuple(_args, ""))
741 return NULL;
742 SetPortDialogPort(_self->ob_itself);
743 Py_INCREF(Py_None);
744 _res = Py_None;
745 return _res;
746}
747
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000748static PyObject *DlgObj_GetDialogPort(DialogObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000749{
750 PyObject *_res = NULL;
751 CGrafPtr _rv;
752 if (!PyArg_ParseTuple(_args, ""))
753 return NULL;
754 _rv = GetDialogPort(_self->ob_itself);
755 _res = Py_BuildValue("O&",
756 GrafObj_New, _rv);
757 return _res;
758}
759
Jack Jansen74a1e632000-07-14 22:37:27 +0000760#if !TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000761
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000762static PyObject *DlgObj_SetGrafPortOfDialog(DialogObject *_self, PyObject *_args)
Jack Jansend96cb501996-09-23 15:48:46 +0000763{
764 PyObject *_res = NULL;
765 if (!PyArg_ParseTuple(_args, ""))
766 return NULL;
767 SetGrafPortOfDialog(_self->ob_itself);
768 Py_INCREF(Py_None);
769 _res = Py_None;
770 return _res;
771}
Jack Jansene79dc762000-06-02 21:35:07 +0000772#endif
Jack Jansend96cb501996-09-23 15:48:46 +0000773
Guido van Rossum17448e21995-01-30 11:53:55 +0000774static PyMethodDef DlgObj_methods[] = {
775 {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
776 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000777 {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
Jack Jansen2b724171996-04-10 14:48:19 +0000778 "(RgnHandle updateRgn) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000779 {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000780 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000781 {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000782 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000783 {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000784 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000785 {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000786 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000787 {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000788 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000789 {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000790 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000791 {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000792 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000793 {"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"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000799 {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
800 "(Handle theHandle, DITLMethod method) -> None"},
801 {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000802 "() -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000803 {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000804 "(DialogItemIndex numberItems) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000805
806#if TARGET_API_MAC_CARBON
807 {"InsertDialogItem", (PyCFunction)DlgObj_InsertDialogItem, 1,
808 "(DialogItemIndex afterItem, DialogItemType itemType, Handle itemHandle, Rect box) -> None"},
809#endif
810
811#if TARGET_API_MAC_CARBON
812 {"RemoveDialogItems", (PyCFunction)DlgObj_RemoveDialogItems, 1,
813 "(DialogItemIndex itemNo, DialogItemIndex amountToRemove, Boolean disposeItemData) -> None"},
814#endif
Jack Jansenae8a68f1995-06-06 12:55:40 +0000815 {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000816 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000817 {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000818 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000819 {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000820 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000821 {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
822 "(Boolean tracks) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000823 {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1,
824 "() -> None"},
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,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000830 "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +0000831 {"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)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000841 {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
Jack Jansene79dc762000-06-02 21:35:07 +0000842 "() -> (WindowPtr _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000843 {"GetDialogTextEditHandle", (PyCFunction)DlgObj_GetDialogTextEditHandle, 1,
844 "() -> (TEHandle _rv)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000845 {"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)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000851 {"SetPortDialogPort", (PyCFunction)DlgObj_SetPortDialogPort, 1,
852 "() -> None"},
853 {"GetDialogPort", (PyCFunction)DlgObj_GetDialogPort, 1,
854 "() -> (CGrafPtr _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +0000855
Jack Jansen74a1e632000-07-14 22:37:27 +0000856#if !TARGET_API_MAC_CARBON
Jack Jansend96cb501996-09-23 15:48:46 +0000857 {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1,
858 "() -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +0000859#endif
Guido van Rossum17448e21995-01-30 11:53:55 +0000860 {NULL, NULL, 0}
861};
862
Jack Jansen69e7f112001-02-06 16:14:54 +0000863PyMethodChain DlgObj_chain = { DlgObj_methods, NULL };
Guido van Rossum17448e21995-01-30 11:53:55 +0000864
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000865static PyObject *DlgObj_getattr(DialogObject *self, char *name)
Guido van Rossum17448e21995-01-30 11:53:55 +0000866{
867 return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name);
868}
869
870#define DlgObj_setattr NULL
871
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000872static int DlgObj_compare(DialogObject *self, DialogObject *other)
Jack Jansen69e7f112001-02-06 16:14:54 +0000873{
874 if ( self->ob_itself > other->ob_itself ) return 1;
875 if ( self->ob_itself < other->ob_itself ) return -1;
876 return 0;
877}
Jack Jansena05ac601999-12-12 21:41:51 +0000878
879#define DlgObj_repr NULL
880
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000881static int DlgObj_hash(DialogObject *self)
Jack Jansen69e7f112001-02-06 16:14:54 +0000882{
883 return (int)self->ob_itself;
884}
Jack Jansena05ac601999-12-12 21:41:51 +0000885
Guido van Rossum17448e21995-01-30 11:53:55 +0000886PyTypeObject Dialog_Type = {
887 PyObject_HEAD_INIT(&PyType_Type)
888 0, /*ob_size*/
889 "Dialog", /*tp_name*/
890 sizeof(DialogObject), /*tp_basicsize*/
891 0, /*tp_itemsize*/
892 /* methods */
893 (destructor) DlgObj_dealloc, /*tp_dealloc*/
894 0, /*tp_print*/
895 (getattrfunc) DlgObj_getattr, /*tp_getattr*/
896 (setattrfunc) DlgObj_setattr, /*tp_setattr*/
Jack Jansena05ac601999-12-12 21:41:51 +0000897 (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*/
Guido van Rossum17448e21995-01-30 11:53:55 +0000903};
904
905/* --------------------- End object type Dialog --------------------- */
906
907
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000908static PyObject *Dlg_NewDialog(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000909{
910 PyObject *_res = NULL;
911 DialogPtr _rv;
912 Rect boundsRect;
913 Str255 title;
914 Boolean visible;
Jack Jansen21f96871998-02-20 16:02:09 +0000915 SInt16 procID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000916 WindowPtr behind;
917 Boolean goAwayFlag;
Jack Jansen21f96871998-02-20 16:02:09 +0000918 SInt32 refCon;
919 Handle items;
Guido van Rossum17448e21995-01-30 11:53:55 +0000920 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
921 PyMac_GetRect, &boundsRect,
922 PyMac_GetStr255, title,
923 &visible,
924 &procID,
925 WinObj_Convert, &behind,
926 &goAwayFlag,
927 &refCon,
Jack Jansen21f96871998-02-20 16:02:09 +0000928 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +0000929 return NULL;
930 _rv = NewDialog((void *)0,
931 &boundsRect,
932 title,
933 visible,
934 procID,
935 behind,
936 goAwayFlag,
937 refCon,
Jack Jansen21f96871998-02-20 16:02:09 +0000938 items);
Guido van Rossum17448e21995-01-30 11:53:55 +0000939 _res = Py_BuildValue("O&",
940 DlgObj_New, _rv);
941 return _res;
942}
943
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000944static PyObject *Dlg_GetNewDialog(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000945{
946 PyObject *_res = NULL;
947 DialogPtr _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000948 SInt16 dialogID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000949 WindowPtr behind;
950 if (!PyArg_ParseTuple(_args, "hO&",
951 &dialogID,
952 WinObj_Convert, &behind))
953 return NULL;
954 _rv = GetNewDialog(dialogID,
955 (void *)0,
956 behind);
957 _res = Py_BuildValue("O&",
958 DlgObj_New, _rv);
959 return _res;
960}
961
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000962static PyObject *Dlg_NewColorDialog(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000963{
964 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000965 DialogPtr _rv;
966 Rect boundsRect;
967 Str255 title;
968 Boolean visible;
969 SInt16 procID;
970 WindowPtr behind;
971 Boolean goAwayFlag;
972 SInt32 refCon;
973 Handle items;
974 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
975 PyMac_GetRect, &boundsRect,
976 PyMac_GetStr255, title,
977 &visible,
978 &procID,
979 WinObj_Convert, &behind,
980 &goAwayFlag,
981 &refCon,
982 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +0000983 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000984 _rv = NewColorDialog((void *)0,
985 &boundsRect,
986 title,
987 visible,
988 procID,
989 behind,
990 goAwayFlag,
991 refCon,
992 items);
993 _res = Py_BuildValue("O&",
994 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +0000995 return _res;
996}
997
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000998static PyObject *Dlg_ModalDialog(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000999{
1000 PyObject *_res = NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001001 PyObject* modalFilter;
Jack Jansen21f96871998-02-20 16:02:09 +00001002 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +00001003 if (!PyArg_ParseTuple(_args, "O",
Jack Jansenae8a68f1995-06-06 12:55:40 +00001004 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001005 return NULL;
Jack Jansen599ce9c2001-02-20 22:27:43 +00001006 ModalDialog(Dlg_PassFilterProc(modalFilter),
Guido van Rossum17448e21995-01-30 11:53:55 +00001007 &itemHit);
1008 _res = Py_BuildValue("h",
1009 itemHit);
1010 return _res;
1011}
1012
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001013static PyObject *Dlg_IsDialogEvent(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001014{
1015 PyObject *_res = NULL;
1016 Boolean _rv;
1017 EventRecord theEvent;
1018 if (!PyArg_ParseTuple(_args, "O&",
1019 PyMac_GetEventRecord, &theEvent))
1020 return NULL;
1021 _rv = IsDialogEvent(&theEvent);
1022 _res = Py_BuildValue("b",
1023 _rv);
1024 return _res;
1025}
1026
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001027static PyObject *Dlg_DialogSelect(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001028{
1029 PyObject *_res = NULL;
1030 Boolean _rv;
1031 EventRecord theEvent;
1032 DialogPtr theDialog;
Jack Jansen21f96871998-02-20 16:02:09 +00001033 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +00001034 if (!PyArg_ParseTuple(_args, "O&",
1035 PyMac_GetEventRecord, &theEvent))
1036 return NULL;
1037 _rv = DialogSelect(&theEvent,
1038 &theDialog,
1039 &itemHit);
1040 _res = Py_BuildValue("bO&h",
1041 _rv,
Jack Jansen69e7f112001-02-06 16:14:54 +00001042 DlgObj_WhichDialog, theDialog,
Guido van Rossum17448e21995-01-30 11:53:55 +00001043 itemHit);
1044 return _res;
1045}
1046
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001047static PyObject *Dlg_Alert(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001048{
1049 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001050 DialogItemIndex _rv;
1051 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001052 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001053 if (!PyArg_ParseTuple(_args, "hO",
1054 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001055 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001056 return NULL;
1057 _rv = Alert(alertID,
Jack Jansen599ce9c2001-02-20 22:27:43 +00001058 Dlg_PassFilterProc(modalFilter));
Guido van Rossum17448e21995-01-30 11:53:55 +00001059 _res = Py_BuildValue("h",
1060 _rv);
1061 return _res;
1062}
1063
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001064static PyObject *Dlg_StopAlert(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001065{
1066 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001067 DialogItemIndex _rv;
1068 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001069 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001070 if (!PyArg_ParseTuple(_args, "hO",
1071 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001072 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001073 return NULL;
1074 _rv = StopAlert(alertID,
Jack Jansen599ce9c2001-02-20 22:27:43 +00001075 Dlg_PassFilterProc(modalFilter));
Guido van Rossum17448e21995-01-30 11:53:55 +00001076 _res = Py_BuildValue("h",
1077 _rv);
1078 return _res;
1079}
1080
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001081static PyObject *Dlg_NoteAlert(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001082{
1083 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001084 DialogItemIndex _rv;
1085 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001086 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001087 if (!PyArg_ParseTuple(_args, "hO",
1088 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001089 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001090 return NULL;
1091 _rv = NoteAlert(alertID,
Jack Jansen599ce9c2001-02-20 22:27:43 +00001092 Dlg_PassFilterProc(modalFilter));
Guido van Rossum17448e21995-01-30 11:53:55 +00001093 _res = Py_BuildValue("h",
1094 _rv);
1095 return _res;
1096}
1097
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001098static PyObject *Dlg_CautionAlert(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001099{
1100 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001101 DialogItemIndex _rv;
1102 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001103 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001104 if (!PyArg_ParseTuple(_args, "hO",
1105 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001106 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001107 return NULL;
1108 _rv = CautionAlert(alertID,
Jack Jansen599ce9c2001-02-20 22:27:43 +00001109 Dlg_PassFilterProc(modalFilter));
Guido van Rossum17448e21995-01-30 11:53:55 +00001110 _res = Py_BuildValue("h",
1111 _rv);
1112 return _res;
1113}
1114
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001115static PyObject *Dlg_ParamText(PyObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +00001116{
1117 PyObject *_res = NULL;
1118 Str255 param0;
1119 Str255 param1;
1120 Str255 param2;
1121 Str255 param3;
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))
1127 return NULL;
1128 ParamText(param0,
1129 param1,
1130 param2,
1131 param3);
1132 Py_INCREF(Py_None);
1133 _res = Py_None;
1134 return _res;
1135}
1136
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001137static PyObject *Dlg_GetDialogItemText(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001138{
1139 PyObject *_res = NULL;
1140 Handle item;
1141 Str255 text;
1142 if (!PyArg_ParseTuple(_args, "O&",
1143 ResObj_Convert, &item))
1144 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001145 GetDialogItemText(item,
1146 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001147 _res = Py_BuildValue("O&",
1148 PyMac_BuildStr255, text);
1149 return _res;
1150}
1151
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001152static PyObject *Dlg_SetDialogItemText(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001153{
1154 PyObject *_res = NULL;
1155 Handle item;
1156 Str255 text;
1157 if (!PyArg_ParseTuple(_args, "O&O&",
1158 ResObj_Convert, &item,
1159 PyMac_GetStr255, text))
1160 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001161 SetDialogItemText(item,
1162 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001163 Py_INCREF(Py_None);
1164 _res = Py_None;
1165 return _res;
1166}
1167
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001168static PyObject *Dlg_GetAlertStage(PyObject *_self, PyObject *_args)
Jack Jansenae8a68f1995-06-06 12:55:40 +00001169{
1170 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001171 SInt16 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001172 if (!PyArg_ParseTuple(_args, ""))
1173 return NULL;
1174 _rv = GetAlertStage();
1175 _res = Py_BuildValue("h",
1176 _rv);
1177 return _res;
1178}
1179
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001180static PyObject *Dlg_SetDialogFont(PyObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +00001181{
1182 PyObject *_res = NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001183 SInt16 fontNum;
Jack Jansen21f96871998-02-20 16:02:09 +00001184 if (!PyArg_ParseTuple(_args, "h",
Jack Jansena05ac601999-12-12 21:41:51 +00001185 &fontNum))
Jack Jansen21f96871998-02-20 16:02:09 +00001186 return NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001187 SetDialogFont(fontNum);
Jack Jansen21f96871998-02-20 16:02:09 +00001188 Py_INCREF(Py_None);
1189 _res = Py_None;
1190 return _res;
1191}
1192
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001193static PyObject *Dlg_ResetAlertStage(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001194{
1195 PyObject *_res = NULL;
1196 if (!PyArg_ParseTuple(_args, ""))
1197 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001198 ResetAlertStage();
Guido van Rossum17448e21995-01-30 11:53:55 +00001199 Py_INCREF(Py_None);
1200 _res = Py_None;
1201 return _res;
1202}
1203
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001204#if TARGET_API_MAC_CARBON
1205
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001206static PyObject *Dlg_GetParamText(PyObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001207{
1208 PyObject *_res = NULL;
1209 Str255 param0;
1210 Str255 param1;
1211 Str255 param2;
1212 Str255 param3;
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))
1218 return NULL;
1219 GetParamText(param0,
1220 param1,
1221 param2,
1222 param3);
1223 Py_INCREF(Py_None);
1224 _res = Py_None;
1225 return _res;
1226}
1227#endif
1228
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001229static PyObject *Dlg_NewFeaturesDialog(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001230{
1231 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001232 DialogPtr _rv;
1233 Rect inBoundsRect;
1234 Str255 inTitle;
1235 Boolean inIsVisible;
1236 SInt16 inProcID;
1237 WindowPtr inBehind;
1238 Boolean inGoAwayFlag;
1239 SInt32 inRefCon;
1240 Handle inItemListHandle;
1241 UInt32 inFlags;
1242 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
1243 PyMac_GetRect, &inBoundsRect,
1244 PyMac_GetStr255, inTitle,
1245 &inIsVisible,
1246 &inProcID,
1247 WinObj_Convert, &inBehind,
1248 &inGoAwayFlag,
1249 &inRefCon,
1250 ResObj_Convert, &inItemListHandle,
1251 &inFlags))
Guido van Rossum17448e21995-01-30 11:53:55 +00001252 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001253 _rv = NewFeaturesDialog((void *)0,
1254 &inBoundsRect,
1255 inTitle,
1256 inIsVisible,
1257 inProcID,
1258 inBehind,
1259 inGoAwayFlag,
1260 inRefCon,
1261 inItemListHandle,
1262 inFlags);
1263 _res = Py_BuildValue("O&",
1264 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +00001265 return _res;
1266}
1267
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001268static PyObject *Dlg_GetDialogFromWindow(PyObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001269{
1270 PyObject *_res = NULL;
1271 DialogPtr _rv;
1272 WindowPtr window;
1273 if (!PyArg_ParseTuple(_args, "O&",
1274 WinObj_Convert, &window))
1275 return NULL;
1276 _rv = GetDialogFromWindow(window);
1277 _res = Py_BuildValue("O&",
1278 DlgObj_New, _rv);
1279 return _res;
1280}
1281
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001282static PyObject *Dlg_SetUserItemHandler(PyObject *_self, PyObject *_args)
Jack Jansendf901df1998-07-10 15:47:48 +00001283{
1284 PyObject *_res = NULL;
1285
1286 PyObject *new = NULL;
1287
1288
1289 if (!PyArg_ParseTuple(_args, "|O", &new))
1290 return NULL;
1291
1292 if (Dlg_UserItemProc_callback && new && new != Py_None) {
1293 PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
1294 return NULL;
1295 }
1296
Jack Jansen599ce9c2001-02-20 22:27:43 +00001297 if (new == NULL || new == Py_None) {
Jack Jansendf901df1998-07-10 15:47:48 +00001298 new = NULL;
1299 _res = Py_None;
1300 Py_INCREF(Py_None);
1301 } else {
1302 Py_INCREF(new);
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001303 _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemUPP(Dlg_UnivUserItemProc));
Jack Jansendf901df1998-07-10 15:47:48 +00001304 }
1305
1306 Dlg_UserItemProc_callback = new;
1307 return _res;
1308
1309}
1310
Guido van Rossum17448e21995-01-30 11:53:55 +00001311static PyMethodDef Dlg_methods[] = {
1312 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001313 "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001314 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001315 "(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)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001318 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001319 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001320 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
1321 "(EventRecord theEvent) -> (Boolean _rv)"},
1322 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001323 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001324 {"Alert", (PyCFunction)Dlg_Alert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001325 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001326 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001327 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001328 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001329 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001330 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001331 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1332 {"ParamText", (PyCFunction)Dlg_ParamText, 1,
1333 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001334 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001335 "(Handle item) -> (Str255 text)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001336 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001337 "(Handle item, Str255 text) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001338 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001339 "() -> (SInt16 _rv)"},
1340 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
Jack Jansena05ac601999-12-12 21:41:51 +00001341 "(SInt16 fontNum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001342 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001343 "() -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001344
1345#if TARGET_API_MAC_CARBON
1346 {"GetParamText", (PyCFunction)Dlg_GetParamText, 1,
1347 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1348#endif
Jack Jansen21f96871998-02-20 16:02:09 +00001349 {"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)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001351 {"GetDialogFromWindow", (PyCFunction)Dlg_GetDialogFromWindow, 1,
1352 "(WindowPtr window) -> (DialogPtr _rv)"},
Jack Jansendf901df1998-07-10 15:47:48 +00001353 {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
1354 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001355 {NULL, NULL, 0}
1356};
1357
1358
1359
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001360/* Return the WindowPtr corresponding to a DialogObject */
Jack Jansen0e04eec2001-05-17 21:58:34 +00001361#if 0
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001362WindowPtr
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001363DlgObj_ConvertToWindow(PyObject *self)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001364{
1365 if ( DlgObj_Check(self) )
1366 return GetDialogWindow(((DialogObject *)self)->ob_itself);
1367 return NULL;
1368}
Jack Jansen0e04eec2001-05-17 21:58:34 +00001369#endif
Jack Jansen69e7f112001-02-06 16:14:54 +00001370/* Return the object corresponding to the dialog, or None */
1371
1372PyObject *
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001373DlgObj_WhichDialog(DialogPtr d)
Jack Jansen69e7f112001-02-06 16:14:54 +00001374{
1375 PyObject *it;
1376
1377 if (d == NULL) {
1378 it = Py_None;
1379 Py_INCREF(it);
1380 } else {
1381 WindowPtr w = GetDialogWindow(d);
1382
1383 it = (PyObject *) GetWRefCon(w);
1384 if (it == NULL || ((DialogObject *)it)->ob_itself != d || !DlgObj_Check(it)) {
1385#if 0
1386 /* Should do this, but we don't have an ob_freeit for dialogs yet. */
1387 it = WinObj_New(w);
1388 ((WindowObject *)it)->ob_freeit = NULL;
1389#else
1390 it = Py_None;
1391 Py_INCREF(it);
1392#endif
1393 } else {
1394 Py_INCREF(it);
1395 }
1396 }
1397 return it;
1398}
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001399
Guido van Rossum17448e21995-01-30 11:53:55 +00001400
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001401void initDlg(void)
Guido van Rossum17448e21995-01-30 11:53:55 +00001402{
1403 PyObject *m;
1404 PyObject *d;
1405
1406
1407
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001408 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);
Jack Jansen0e04eec2001-05-17 21:58:34 +00001411
Guido van Rossum17448e21995-01-30 11:53:55 +00001412
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)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001418 return;
Jack Jansena755e681997-09-20 17:40:22 +00001419 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");
Guido van Rossum17448e21995-01-30 11:53:55 +00001423}
1424
1425/* ========================= End module Dlg ========================= */
1426