blob: 33ce3909999c78442ec88cea81535af5447a1d68 [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
11#include <Dialogs.h>
12
Guido van Rossum17448e21995-01-30 11:53:55 +000013/* XXX Shouldn't this be a stack? */
14static PyObject *Dlg_FilterProc_callback = NULL;
15
Guido van Rossum17448e21995-01-30 11:53:55 +000016static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog,
17 EventRecord *event,
18 short *itemHit)
19{
20 Boolean rv;
21 PyObject *args, *res;
22 PyObject *callback = Dlg_FilterProc_callback;
23 if (callback == NULL)
24 return 0; /* Default behavior */
25 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
Guido van Rossum0437e891995-02-21 20:56:21 +000026 args = Py_BuildValue("O&O&", WinObj_WhichWindow, dialog, PyMac_BuildEventRecord, event);
Guido van Rossum17448e21995-01-30 11:53:55 +000027 if (args == NULL)
28 res = NULL;
29 else {
30 res = PyEval_CallObject(callback, args);
31 Py_DECREF(args);
32 }
33 if (res == NULL) {
Jack Jansendeff89c1998-10-12 20:53:15 +000034 PySys_WriteStderr("Exception in Dialog Filter\n");
Guido van Rossum17448e21995-01-30 11:53:55 +000035 PyErr_Print();
36 *itemHit = -1; /* Fake return item */
37 return 1; /* We handled it */
38 }
39 else {
40 Dlg_FilterProc_callback = callback;
41 if (PyInt_Check(res)) {
42 *itemHit = PyInt_AsLong(res);
43 rv = 1;
44 }
45 else
46 rv = PyObject_IsTrue(res);
47 }
48 Py_DECREF(res);
49 return rv;
50}
51
52static ModalFilterProcPtr
53Dlg_PassFilterProc(PyObject *callback)
54{
55 PyObject *tmp = Dlg_FilterProc_callback;
56 Dlg_FilterProc_callback = NULL;
57 if (callback == Py_None) {
58 Py_XDECREF(tmp);
59 return NULL;
60 }
61 Py_INCREF(callback);
62 Dlg_FilterProc_callback = callback;
63 Py_XDECREF(tmp);
64 return &Dlg_UnivFilterProc;
65}
66
Jack Jansendf901df1998-07-10 15:47:48 +000067static PyObject *Dlg_UserItemProc_callback = NULL;
68
69static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
70 short item)
71{
72 PyObject *args, *res;
73
74 if (Dlg_UserItemProc_callback == NULL)
75 return; /* Default behavior */
76 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
77 args = Py_BuildValue("O&h", WinObj_WhichWindow, dialog, item);
78 if (args == NULL)
79 res = NULL;
80 else {
81 res = PyEval_CallObject(Dlg_UserItemProc_callback, args);
82 Py_DECREF(args);
83 }
84 if (res == NULL) {
Jack Jansendeff89c1998-10-12 20:53:15 +000085 PySys_WriteStderr("Exception in Dialog UserItem proc\n");
Jack Jansendf901df1998-07-10 15:47:48 +000086 PyErr_Print();
87 }
88 Py_XDECREF(res);
89 return;
90}
91
Guido van Rossum17448e21995-01-30 11:53:55 +000092extern PyMethodChain WinObj_chain;
93
94static PyObject *Dlg_Error;
95
96/* ----------------------- Object type Dialog ----------------------- */
97
98PyTypeObject Dialog_Type;
99
100#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
101
102typedef struct DialogObject {
103 PyObject_HEAD
104 DialogPtr ob_itself;
105} DialogObject;
106
107PyObject *DlgObj_New(itself)
Guido van Rossum97842951995-02-19 15:59:49 +0000108 DialogPtr itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000109{
110 DialogObject *it;
111 if (itself == NULL) return Py_None;
112 it = PyObject_NEW(DialogObject, &Dialog_Type);
113 if (it == NULL) return NULL;
114 it->ob_itself = itself;
Jack Jansene79dc762000-06-02 21:35:07 +0000115 SetWRefCon(GetDialogWindow(itself), (long)it);
Guido van Rossum17448e21995-01-30 11:53:55 +0000116 return (PyObject *)it;
117}
118DlgObj_Convert(v, p_itself)
119 PyObject *v;
120 DialogPtr *p_itself;
121{
122 if (v == Py_None) { *p_itself = NULL; return 1; }
123 if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
124 return 1; }
125 if (!DlgObj_Check(v))
126 {
127 PyErr_SetString(PyExc_TypeError, "Dialog required");
128 return 0;
129 }
130 *p_itself = ((DialogObject *)v)->ob_itself;
131 return 1;
132}
133
134static void DlgObj_dealloc(self)
135 DialogObject *self;
136{
137 DisposeDialog(self->ob_itself);
138 PyMem_DEL(self);
139}
140
141static PyObject *DlgObj_DrawDialog(_self, _args)
142 DialogObject *_self;
143 PyObject *_args;
144{
145 PyObject *_res = NULL;
146 if (!PyArg_ParseTuple(_args, ""))
147 return NULL;
148 DrawDialog(_self->ob_itself);
149 Py_INCREF(Py_None);
150 _res = Py_None;
151 return _res;
152}
153
Guido van Rossum17448e21995-01-30 11:53:55 +0000154static PyObject *DlgObj_UpdateDialog(_self, _args)
155 DialogObject *_self;
156 PyObject *_args;
157{
158 PyObject *_res = NULL;
Jack Jansen2b724171996-04-10 14:48:19 +0000159 RgnHandle updateRgn;
160 if (!PyArg_ParseTuple(_args, "O&",
161 ResObj_Convert, &updateRgn))
Guido van Rossum17448e21995-01-30 11:53:55 +0000162 return NULL;
163 UpdateDialog(_self->ob_itself,
Jack Jansen2b724171996-04-10 14:48:19 +0000164 updateRgn);
Guido van Rossum17448e21995-01-30 11:53:55 +0000165 Py_INCREF(Py_None);
166 _res = Py_None;
167 return _res;
168}
169
Jack Jansenae8a68f1995-06-06 12:55:40 +0000170static PyObject *DlgObj_HideDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000171 DialogObject *_self;
172 PyObject *_args;
173{
174 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000175 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000176 if (!PyArg_ParseTuple(_args, "h",
177 &itemNo))
178 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000179 HideDialogItem(_self->ob_itself,
180 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000181 Py_INCREF(Py_None);
182 _res = Py_None;
183 return _res;
184}
185
Jack Jansenae8a68f1995-06-06 12:55:40 +0000186static PyObject *DlgObj_ShowDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000187 DialogObject *_self;
188 PyObject *_args;
189{
190 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000191 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000192 if (!PyArg_ParseTuple(_args, "h",
193 &itemNo))
194 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000195 ShowDialogItem(_self->ob_itself,
196 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000197 Py_INCREF(Py_None);
198 _res = Py_None;
199 return _res;
200}
201
Jack Jansenae8a68f1995-06-06 12:55:40 +0000202static PyObject *DlgObj_FindDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000203 DialogObject *_self;
204 PyObject *_args;
205{
206 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000207 DialogItemIndexZeroBased _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000208 Point thePt;
209 if (!PyArg_ParseTuple(_args, "O&",
210 PyMac_GetPoint, &thePt))
211 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000212 _rv = FindDialogItem(_self->ob_itself,
213 thePt);
Guido van Rossum17448e21995-01-30 11:53:55 +0000214 _res = Py_BuildValue("h",
215 _rv);
216 return _res;
217}
218
Jack Jansenae8a68f1995-06-06 12:55:40 +0000219static PyObject *DlgObj_DialogCut(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000220 DialogObject *_self;
221 PyObject *_args;
222{
223 PyObject *_res = NULL;
224 if (!PyArg_ParseTuple(_args, ""))
225 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000226 DialogCut(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000227 Py_INCREF(Py_None);
228 _res = Py_None;
229 return _res;
230}
231
Jack Jansenae8a68f1995-06-06 12:55:40 +0000232static PyObject *DlgObj_DialogPaste(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000233 DialogObject *_self;
234 PyObject *_args;
235{
236 PyObject *_res = NULL;
237 if (!PyArg_ParseTuple(_args, ""))
238 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000239 DialogPaste(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000240 Py_INCREF(Py_None);
241 _res = Py_None;
242 return _res;
243}
244
Jack Jansenae8a68f1995-06-06 12:55:40 +0000245static PyObject *DlgObj_DialogCopy(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000246 DialogObject *_self;
247 PyObject *_args;
248{
249 PyObject *_res = NULL;
250 if (!PyArg_ParseTuple(_args, ""))
251 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000252 DialogCopy(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000253 Py_INCREF(Py_None);
254 _res = Py_None;
255 return _res;
256}
257
Jack Jansenae8a68f1995-06-06 12:55:40 +0000258static PyObject *DlgObj_DialogDelete(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000259 DialogObject *_self;
260 PyObject *_args;
261{
262 PyObject *_res = NULL;
263 if (!PyArg_ParseTuple(_args, ""))
264 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000265 DialogDelete(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000266 Py_INCREF(Py_None);
267 _res = Py_None;
268 return _res;
269}
270
Jack Jansen21f96871998-02-20 16:02:09 +0000271static PyObject *DlgObj_GetDialogItem(_self, _args)
272 DialogObject *_self;
273 PyObject *_args;
274{
275 PyObject *_res = NULL;
276 DialogItemIndex itemNo;
277 DialogItemType itemType;
278 Handle item;
279 Rect box;
280 if (!PyArg_ParseTuple(_args, "h",
281 &itemNo))
282 return NULL;
283 GetDialogItem(_self->ob_itself,
284 itemNo,
285 &itemType,
286 &item,
287 &box);
288 _res = Py_BuildValue("hO&O&",
289 itemType,
290 OptResObj_New, item,
291 PyMac_BuildRect, &box);
292 return _res;
293}
294
295static PyObject *DlgObj_SetDialogItem(_self, _args)
296 DialogObject *_self;
297 PyObject *_args;
298{
299 PyObject *_res = NULL;
300 DialogItemIndex itemNo;
301 DialogItemType itemType;
302 Handle item;
303 Rect box;
304 if (!PyArg_ParseTuple(_args, "hhO&O&",
305 &itemNo,
306 &itemType,
307 ResObj_Convert, &item,
308 PyMac_GetRect, &box))
309 return NULL;
310 SetDialogItem(_self->ob_itself,
311 itemNo,
312 itemType,
313 item,
314 &box);
315 Py_INCREF(Py_None);
316 _res = Py_None;
317 return _res;
318}
319
320static PyObject *DlgObj_SelectDialogItemText(_self, _args)
321 DialogObject *_self;
322 PyObject *_args;
323{
324 PyObject *_res = NULL;
325 DialogItemIndex itemNo;
326 SInt16 strtSel;
327 SInt16 endSel;
328 if (!PyArg_ParseTuple(_args, "hhh",
329 &itemNo,
330 &strtSel,
331 &endSel))
332 return NULL;
333 SelectDialogItemText(_self->ob_itself,
334 itemNo,
335 strtSel,
336 endSel);
337 Py_INCREF(Py_None);
338 _res = Py_None;
339 return _res;
340}
341
Guido van Rossum17448e21995-01-30 11:53:55 +0000342static PyObject *DlgObj_AppendDITL(_self, _args)
343 DialogObject *_self;
344 PyObject *_args;
345{
346 PyObject *_res = NULL;
347 Handle theHandle;
348 DITLMethod method;
349 if (!PyArg_ParseTuple(_args, "O&h",
350 ResObj_Convert, &theHandle,
351 &method))
352 return NULL;
353 AppendDITL(_self->ob_itself,
354 theHandle,
355 method);
356 Py_INCREF(Py_None);
357 _res = Py_None;
358 return _res;
359}
360
361static PyObject *DlgObj_CountDITL(_self, _args)
362 DialogObject *_self;
363 PyObject *_args;
364{
365 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000366 DialogItemIndex _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000367 if (!PyArg_ParseTuple(_args, ""))
368 return NULL;
369 _rv = CountDITL(_self->ob_itself);
370 _res = Py_BuildValue("h",
371 _rv);
372 return _res;
373}
374
375static PyObject *DlgObj_ShortenDITL(_self, _args)
376 DialogObject *_self;
377 PyObject *_args;
378{
379 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000380 DialogItemIndex numberItems;
Guido van Rossum17448e21995-01-30 11:53:55 +0000381 if (!PyArg_ParseTuple(_args, "h",
382 &numberItems))
383 return NULL;
384 ShortenDITL(_self->ob_itself,
385 numberItems);
386 Py_INCREF(Py_None);
387 _res = Py_None;
388 return _res;
389}
390
Jack Jansenae8a68f1995-06-06 12:55:40 +0000391static PyObject *DlgObj_StdFilterProc(_self, _args)
392 DialogObject *_self;
393 PyObject *_args;
394{
395 PyObject *_res = NULL;
396 Boolean _rv;
397 EventRecord event;
Jack Jansen21f96871998-02-20 16:02:09 +0000398 DialogItemIndex itemHit;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000399 if (!PyArg_ParseTuple(_args, ""))
400 return NULL;
401 _rv = StdFilterProc(_self->ob_itself,
402 &event,
403 &itemHit);
404 _res = Py_BuildValue("bO&h",
405 _rv,
406 PyMac_BuildEventRecord, &event,
407 itemHit);
408 return _res;
409}
410
411static PyObject *DlgObj_SetDialogDefaultItem(_self, _args)
412 DialogObject *_self;
413 PyObject *_args;
414{
415 PyObject *_res = NULL;
416 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000417 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000418 if (!PyArg_ParseTuple(_args, "h",
419 &newItem))
420 return NULL;
421 _err = SetDialogDefaultItem(_self->ob_itself,
422 newItem);
423 if (_err != noErr) return PyMac_Error(_err);
424 Py_INCREF(Py_None);
425 _res = Py_None;
426 return _res;
427}
428
429static PyObject *DlgObj_SetDialogCancelItem(_self, _args)
430 DialogObject *_self;
431 PyObject *_args;
432{
433 PyObject *_res = NULL;
434 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000435 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000436 if (!PyArg_ParseTuple(_args, "h",
437 &newItem))
438 return NULL;
439 _err = SetDialogCancelItem(_self->ob_itself,
440 newItem);
441 if (_err != noErr) return PyMac_Error(_err);
442 Py_INCREF(Py_None);
443 _res = Py_None;
444 return _res;
445}
446
447static PyObject *DlgObj_SetDialogTracksCursor(_self, _args)
448 DialogObject *_self;
449 PyObject *_args;
450{
451 PyObject *_res = NULL;
452 OSErr _err;
453 Boolean tracks;
454 if (!PyArg_ParseTuple(_args, "b",
455 &tracks))
456 return NULL;
457 _err = SetDialogTracksCursor(_self->ob_itself,
458 tracks);
459 if (_err != noErr) return PyMac_Error(_err);
460 Py_INCREF(Py_None);
461 _res = Py_None;
462 return _res;
463}
464
Jack Jansen21f96871998-02-20 16:02:09 +0000465static PyObject *DlgObj_AutoSizeDialog(_self, _args)
466 DialogObject *_self;
467 PyObject *_args;
468{
469 PyObject *_res = NULL;
470 OSErr _err;
471 if (!PyArg_ParseTuple(_args, ""))
472 return NULL;
473 _err = AutoSizeDialog(_self->ob_itself);
474 if (_err != noErr) return PyMac_Error(_err);
475 Py_INCREF(Py_None);
476 _res = Py_None;
477 return _res;
478}
479
480static PyObject *DlgObj_GetDialogItemAsControl(_self, _args)
481 DialogObject *_self;
482 PyObject *_args;
483{
484 PyObject *_res = NULL;
485 OSErr _err;
486 SInt16 inItemNo;
487 ControlHandle outControl;
488 if (!PyArg_ParseTuple(_args, "h",
489 &inItemNo))
490 return NULL;
491 _err = GetDialogItemAsControl(_self->ob_itself,
492 inItemNo,
493 &outControl);
494 if (_err != noErr) return PyMac_Error(_err);
495 _res = Py_BuildValue("O&",
496 CtlObj_New, outControl);
497 return _res;
498}
499
500static PyObject *DlgObj_MoveDialogItem(_self, _args)
501 DialogObject *_self;
502 PyObject *_args;
503{
504 PyObject *_res = NULL;
505 OSErr _err;
506 SInt16 inItemNo;
507 SInt16 inHoriz;
508 SInt16 inVert;
509 if (!PyArg_ParseTuple(_args, "hhh",
510 &inItemNo,
511 &inHoriz,
512 &inVert))
513 return NULL;
514 _err = MoveDialogItem(_self->ob_itself,
515 inItemNo,
516 inHoriz,
517 inVert);
518 if (_err != noErr) return PyMac_Error(_err);
519 Py_INCREF(Py_None);
520 _res = Py_None;
521 return _res;
522}
523
524static PyObject *DlgObj_SizeDialogItem(_self, _args)
525 DialogObject *_self;
526 PyObject *_args;
527{
528 PyObject *_res = NULL;
529 OSErr _err;
530 SInt16 inItemNo;
Jack Jansen21f96871998-02-20 16:02:09 +0000531 SInt16 inWidth;
Jack Jansen1c4e6141998-04-21 15:23:55 +0000532 SInt16 inHeight;
Jack Jansen21f96871998-02-20 16:02:09 +0000533 if (!PyArg_ParseTuple(_args, "hhh",
534 &inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000535 &inWidth,
536 &inHeight))
Jack Jansen21f96871998-02-20 16:02:09 +0000537 return NULL;
538 _err = SizeDialogItem(_self->ob_itself,
539 inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000540 inWidth,
541 inHeight);
Jack Jansen21f96871998-02-20 16:02:09 +0000542 if (_err != noErr) return PyMac_Error(_err);
543 Py_INCREF(Py_None);
544 _res = Py_None;
545 return _res;
546}
547
Jack Jansena05ac601999-12-12 21:41:51 +0000548static PyObject *DlgObj_AppendDialogItemList(_self, _args)
549 DialogObject *_self;
550 PyObject *_args;
551{
552 PyObject *_res = NULL;
553 OSErr _err;
554 SInt16 ditlID;
555 DITLMethod method;
556 if (!PyArg_ParseTuple(_args, "hh",
557 &ditlID,
558 &method))
559 return NULL;
560 _err = AppendDialogItemList(_self->ob_itself,
561 ditlID,
562 method);
563 if (_err != noErr) return PyMac_Error(_err);
564 Py_INCREF(Py_None);
565 _res = Py_None;
566 return _res;
567}
568
569static PyObject *DlgObj_SetDialogTimeout(_self, _args)
570 DialogObject *_self;
571 PyObject *_args;
572{
573 PyObject *_res = NULL;
574 OSStatus _err;
575 SInt16 inButtonToPress;
576 UInt32 inSecondsToWait;
577 if (!PyArg_ParseTuple(_args, "hl",
578 &inButtonToPress,
579 &inSecondsToWait))
580 return NULL;
581 _err = SetDialogTimeout(_self->ob_itself,
582 inButtonToPress,
583 inSecondsToWait);
584 if (_err != noErr) return PyMac_Error(_err);
585 Py_INCREF(Py_None);
586 _res = Py_None;
587 return _res;
588}
589
590static PyObject *DlgObj_GetDialogTimeout(_self, _args)
591 DialogObject *_self;
592 PyObject *_args;
593{
594 PyObject *_res = NULL;
595 OSStatus _err;
596 SInt16 outButtonToPress;
597 UInt32 outSecondsToWait;
598 UInt32 outSecondsRemaining;
599 if (!PyArg_ParseTuple(_args, ""))
600 return NULL;
601 _err = GetDialogTimeout(_self->ob_itself,
602 &outButtonToPress,
603 &outSecondsToWait,
604 &outSecondsRemaining);
605 if (_err != noErr) return PyMac_Error(_err);
606 _res = Py_BuildValue("hll",
607 outButtonToPress,
608 outSecondsToWait,
609 outSecondsRemaining);
610 return _res;
611}
612
613static PyObject *DlgObj_SetModalDialogEventMask(_self, _args)
614 DialogObject *_self;
615 PyObject *_args;
616{
617 PyObject *_res = NULL;
618 OSStatus _err;
619 EventMask inMask;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000620 if (!PyArg_ParseTuple(_args, "H",
Jack Jansena05ac601999-12-12 21:41:51 +0000621 &inMask))
622 return NULL;
623 _err = SetModalDialogEventMask(_self->ob_itself,
624 inMask);
625 if (_err != noErr) return PyMac_Error(_err);
626 Py_INCREF(Py_None);
627 _res = Py_None;
628 return _res;
629}
630
631static PyObject *DlgObj_GetModalDialogEventMask(_self, _args)
632 DialogObject *_self;
633 PyObject *_args;
634{
635 PyObject *_res = NULL;
636 OSStatus _err;
637 EventMask outMask;
638 if (!PyArg_ParseTuple(_args, ""))
639 return NULL;
640 _err = GetModalDialogEventMask(_self->ob_itself,
641 &outMask);
642 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000643 _res = Py_BuildValue("H",
Jack Jansena05ac601999-12-12 21:41:51 +0000644 outMask);
645 return _res;
646}
647
Jack Jansend96cb501996-09-23 15:48:46 +0000648static PyObject *DlgObj_GetDialogWindow(_self, _args)
649 DialogObject *_self;
650 PyObject *_args;
651{
652 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000653 WindowPtr _rv;
Jack Jansend96cb501996-09-23 15:48:46 +0000654 if (!PyArg_ParseTuple(_args, ""))
655 return NULL;
656 _rv = GetDialogWindow(_self->ob_itself);
657 _res = Py_BuildValue("O&",
Jack Jansene79dc762000-06-02 21:35:07 +0000658 WinObj_New, _rv);
Jack Jansend96cb501996-09-23 15:48:46 +0000659 return _res;
660}
661
662static PyObject *DlgObj_GetDialogDefaultItem(_self, _args)
663 DialogObject *_self;
664 PyObject *_args;
665{
666 PyObject *_res = NULL;
667 SInt16 _rv;
668 if (!PyArg_ParseTuple(_args, ""))
669 return NULL;
670 _rv = GetDialogDefaultItem(_self->ob_itself);
671 _res = Py_BuildValue("h",
672 _rv);
673 return _res;
674}
675
676static PyObject *DlgObj_GetDialogCancelItem(_self, _args)
677 DialogObject *_self;
678 PyObject *_args;
679{
680 PyObject *_res = NULL;
681 SInt16 _rv;
682 if (!PyArg_ParseTuple(_args, ""))
683 return NULL;
684 _rv = GetDialogCancelItem(_self->ob_itself);
685 _res = Py_BuildValue("h",
686 _rv);
687 return _res;
688}
689
690static PyObject *DlgObj_GetDialogKeyboardFocusItem(_self, _args)
691 DialogObject *_self;
692 PyObject *_args;
693{
694 PyObject *_res = NULL;
695 SInt16 _rv;
696 if (!PyArg_ParseTuple(_args, ""))
697 return NULL;
698 _rv = GetDialogKeyboardFocusItem(_self->ob_itself);
699 _res = Py_BuildValue("h",
700 _rv);
701 return _res;
702}
703
Jack Jansen74a1e632000-07-14 22:37:27 +0000704#if !TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000705
Jack Jansend96cb501996-09-23 15:48:46 +0000706static PyObject *DlgObj_SetGrafPortOfDialog(_self, _args)
707 DialogObject *_self;
708 PyObject *_args;
709{
710 PyObject *_res = NULL;
711 if (!PyArg_ParseTuple(_args, ""))
712 return NULL;
713 SetGrafPortOfDialog(_self->ob_itself);
714 Py_INCREF(Py_None);
715 _res = Py_None;
716 return _res;
717}
Jack Jansene79dc762000-06-02 21:35:07 +0000718#endif
Jack Jansend96cb501996-09-23 15:48:46 +0000719
Guido van Rossum17448e21995-01-30 11:53:55 +0000720static PyMethodDef DlgObj_methods[] = {
721 {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
722 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000723 {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
Jack Jansen2b724171996-04-10 14:48:19 +0000724 "(RgnHandle updateRgn) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000725 {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000726 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000727 {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000728 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000729 {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000730 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000731 {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000732 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000733 {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000734 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000735 {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000736 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000737 {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000738 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000739 {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1,
740 "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"},
741 {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1,
742 "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"},
743 {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1,
744 "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000745 {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
746 "(Handle theHandle, DITLMethod method) -> None"},
747 {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000748 "() -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000749 {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000750 "(DialogItemIndex numberItems) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000751 {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000752 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000753 {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000754 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000755 {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000756 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000757 {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
758 "(Boolean tracks) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000759 {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1,
760 "() -> None"},
761 {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1,
762 "(SInt16 inItemNo) -> (ControlHandle outControl)"},
763 {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1,
764 "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"},
765 {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000766 "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +0000767 {"AppendDialogItemList", (PyCFunction)DlgObj_AppendDialogItemList, 1,
768 "(SInt16 ditlID, DITLMethod method) -> None"},
769 {"SetDialogTimeout", (PyCFunction)DlgObj_SetDialogTimeout, 1,
770 "(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None"},
771 {"GetDialogTimeout", (PyCFunction)DlgObj_GetDialogTimeout, 1,
772 "() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)"},
773 {"SetModalDialogEventMask", (PyCFunction)DlgObj_SetModalDialogEventMask, 1,
774 "(EventMask inMask) -> None"},
775 {"GetModalDialogEventMask", (PyCFunction)DlgObj_GetModalDialogEventMask, 1,
776 "() -> (EventMask outMask)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000777 {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
Jack Jansene79dc762000-06-02 21:35:07 +0000778 "() -> (WindowPtr _rv)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000779 {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1,
780 "() -> (SInt16 _rv)"},
781 {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1,
782 "() -> (SInt16 _rv)"},
783 {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1,
784 "() -> (SInt16 _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +0000785
Jack Jansen74a1e632000-07-14 22:37:27 +0000786#if !TARGET_API_MAC_CARBON
Jack Jansend96cb501996-09-23 15:48:46 +0000787 {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1,
788 "() -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +0000789#endif
Guido van Rossum17448e21995-01-30 11:53:55 +0000790 {NULL, NULL, 0}
791};
792
793PyMethodChain DlgObj_chain = { DlgObj_methods, &WinObj_chain };
794
795static PyObject *DlgObj_getattr(self, name)
796 DialogObject *self;
797 char *name;
798{
799 return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name);
800}
801
802#define DlgObj_setattr NULL
803
Jack Jansena05ac601999-12-12 21:41:51 +0000804#define DlgObj_compare NULL
805
806#define DlgObj_repr NULL
807
808#define DlgObj_hash NULL
809
Guido van Rossum17448e21995-01-30 11:53:55 +0000810PyTypeObject Dialog_Type = {
811 PyObject_HEAD_INIT(&PyType_Type)
812 0, /*ob_size*/
813 "Dialog", /*tp_name*/
814 sizeof(DialogObject), /*tp_basicsize*/
815 0, /*tp_itemsize*/
816 /* methods */
817 (destructor) DlgObj_dealloc, /*tp_dealloc*/
818 0, /*tp_print*/
819 (getattrfunc) DlgObj_getattr, /*tp_getattr*/
820 (setattrfunc) DlgObj_setattr, /*tp_setattr*/
Jack Jansena05ac601999-12-12 21:41:51 +0000821 (cmpfunc) DlgObj_compare, /*tp_compare*/
822 (reprfunc) DlgObj_repr, /*tp_repr*/
823 (PyNumberMethods *)0, /* tp_as_number */
824 (PySequenceMethods *)0, /* tp_as_sequence */
825 (PyMappingMethods *)0, /* tp_as_mapping */
826 (hashfunc) DlgObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +0000827};
828
829/* --------------------- End object type Dialog --------------------- */
830
831
832static PyObject *Dlg_NewDialog(_self, _args)
833 PyObject *_self;
834 PyObject *_args;
835{
836 PyObject *_res = NULL;
837 DialogPtr _rv;
838 Rect boundsRect;
839 Str255 title;
840 Boolean visible;
Jack Jansen21f96871998-02-20 16:02:09 +0000841 SInt16 procID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000842 WindowPtr behind;
843 Boolean goAwayFlag;
Jack Jansen21f96871998-02-20 16:02:09 +0000844 SInt32 refCon;
845 Handle items;
Guido van Rossum17448e21995-01-30 11:53:55 +0000846 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
847 PyMac_GetRect, &boundsRect,
848 PyMac_GetStr255, title,
849 &visible,
850 &procID,
851 WinObj_Convert, &behind,
852 &goAwayFlag,
853 &refCon,
Jack Jansen21f96871998-02-20 16:02:09 +0000854 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +0000855 return NULL;
856 _rv = NewDialog((void *)0,
857 &boundsRect,
858 title,
859 visible,
860 procID,
861 behind,
862 goAwayFlag,
863 refCon,
Jack Jansen21f96871998-02-20 16:02:09 +0000864 items);
Guido van Rossum17448e21995-01-30 11:53:55 +0000865 _res = Py_BuildValue("O&",
866 DlgObj_New, _rv);
867 return _res;
868}
869
870static PyObject *Dlg_GetNewDialog(_self, _args)
871 PyObject *_self;
872 PyObject *_args;
873{
874 PyObject *_res = NULL;
875 DialogPtr _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000876 SInt16 dialogID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000877 WindowPtr behind;
878 if (!PyArg_ParseTuple(_args, "hO&",
879 &dialogID,
880 WinObj_Convert, &behind))
881 return NULL;
882 _rv = GetNewDialog(dialogID,
883 (void *)0,
884 behind);
885 _res = Py_BuildValue("O&",
886 DlgObj_New, _rv);
887 return _res;
888}
889
Jack Jansen21f96871998-02-20 16:02:09 +0000890static PyObject *Dlg_NewColorDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000891 PyObject *_self;
892 PyObject *_args;
893{
894 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000895 DialogPtr _rv;
896 Rect boundsRect;
897 Str255 title;
898 Boolean visible;
899 SInt16 procID;
900 WindowPtr behind;
901 Boolean goAwayFlag;
902 SInt32 refCon;
903 Handle items;
904 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
905 PyMac_GetRect, &boundsRect,
906 PyMac_GetStr255, title,
907 &visible,
908 &procID,
909 WinObj_Convert, &behind,
910 &goAwayFlag,
911 &refCon,
912 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +0000913 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000914 _rv = NewColorDialog((void *)0,
915 &boundsRect,
916 title,
917 visible,
918 procID,
919 behind,
920 goAwayFlag,
921 refCon,
922 items);
923 _res = Py_BuildValue("O&",
924 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +0000925 return _res;
926}
927
928static PyObject *Dlg_ModalDialog(_self, _args)
929 PyObject *_self;
930 PyObject *_args;
931{
932 PyObject *_res = NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000933 PyObject* modalFilter;
Jack Jansen21f96871998-02-20 16:02:09 +0000934 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +0000935 if (!PyArg_ParseTuple(_args, "O",
Jack Jansenae8a68f1995-06-06 12:55:40 +0000936 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +0000937 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000938 ModalDialog(NewModalFilterProc(Dlg_PassFilterProc(modalFilter)),
Guido van Rossum17448e21995-01-30 11:53:55 +0000939 &itemHit);
940 _res = Py_BuildValue("h",
941 itemHit);
942 return _res;
943}
944
945static PyObject *Dlg_IsDialogEvent(_self, _args)
946 PyObject *_self;
947 PyObject *_args;
948{
949 PyObject *_res = NULL;
950 Boolean _rv;
951 EventRecord theEvent;
952 if (!PyArg_ParseTuple(_args, "O&",
953 PyMac_GetEventRecord, &theEvent))
954 return NULL;
955 _rv = IsDialogEvent(&theEvent);
956 _res = Py_BuildValue("b",
957 _rv);
958 return _res;
959}
960
961static PyObject *Dlg_DialogSelect(_self, _args)
962 PyObject *_self;
963 PyObject *_args;
964{
965 PyObject *_res = NULL;
966 Boolean _rv;
967 EventRecord theEvent;
968 DialogPtr theDialog;
Jack Jansen21f96871998-02-20 16:02:09 +0000969 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +0000970 if (!PyArg_ParseTuple(_args, "O&",
971 PyMac_GetEventRecord, &theEvent))
972 return NULL;
973 _rv = DialogSelect(&theEvent,
974 &theDialog,
975 &itemHit);
976 _res = Py_BuildValue("bO&h",
977 _rv,
978 WinObj_WhichWindow, theDialog,
979 itemHit);
980 return _res;
981}
982
983static PyObject *Dlg_Alert(_self, _args)
984 PyObject *_self;
985 PyObject *_args;
986{
987 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000988 DialogItemIndex _rv;
989 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000990 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +0000991 if (!PyArg_ParseTuple(_args, "hO",
992 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +0000993 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +0000994 return NULL;
995 _rv = Alert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +0000996 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +0000997 _res = Py_BuildValue("h",
998 _rv);
999 return _res;
1000}
1001
1002static PyObject *Dlg_StopAlert(_self, _args)
1003 PyObject *_self;
1004 PyObject *_args;
1005{
1006 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001007 DialogItemIndex _rv;
1008 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001009 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001010 if (!PyArg_ParseTuple(_args, "hO",
1011 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001012 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001013 return NULL;
1014 _rv = StopAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001015 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001016 _res = Py_BuildValue("h",
1017 _rv);
1018 return _res;
1019}
1020
1021static PyObject *Dlg_NoteAlert(_self, _args)
1022 PyObject *_self;
1023 PyObject *_args;
1024{
1025 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001026 DialogItemIndex _rv;
1027 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001028 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001029 if (!PyArg_ParseTuple(_args, "hO",
1030 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001031 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001032 return NULL;
1033 _rv = NoteAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001034 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001035 _res = Py_BuildValue("h",
1036 _rv);
1037 return _res;
1038}
1039
1040static PyObject *Dlg_CautionAlert(_self, _args)
1041 PyObject *_self;
1042 PyObject *_args;
1043{
1044 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001045 DialogItemIndex _rv;
1046 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001047 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001048 if (!PyArg_ParseTuple(_args, "hO",
1049 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001050 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001051 return NULL;
1052 _rv = CautionAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001053 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001054 _res = Py_BuildValue("h",
1055 _rv);
1056 return _res;
1057}
1058
Jack Jansen21f96871998-02-20 16:02:09 +00001059static PyObject *Dlg_ParamText(_self, _args)
1060 PyObject *_self;
1061 PyObject *_args;
1062{
1063 PyObject *_res = NULL;
1064 Str255 param0;
1065 Str255 param1;
1066 Str255 param2;
1067 Str255 param3;
1068 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1069 PyMac_GetStr255, param0,
1070 PyMac_GetStr255, param1,
1071 PyMac_GetStr255, param2,
1072 PyMac_GetStr255, param3))
1073 return NULL;
1074 ParamText(param0,
1075 param1,
1076 param2,
1077 param3);
1078 Py_INCREF(Py_None);
1079 _res = Py_None;
1080 return _res;
1081}
1082
Jack Jansenae8a68f1995-06-06 12:55:40 +00001083static PyObject *Dlg_GetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001084 PyObject *_self;
1085 PyObject *_args;
1086{
1087 PyObject *_res = NULL;
1088 Handle item;
1089 Str255 text;
1090 if (!PyArg_ParseTuple(_args, "O&",
1091 ResObj_Convert, &item))
1092 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001093 GetDialogItemText(item,
1094 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001095 _res = Py_BuildValue("O&",
1096 PyMac_BuildStr255, text);
1097 return _res;
1098}
1099
Jack Jansenae8a68f1995-06-06 12:55:40 +00001100static PyObject *Dlg_SetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001101 PyObject *_self;
1102 PyObject *_args;
1103{
1104 PyObject *_res = NULL;
1105 Handle item;
1106 Str255 text;
1107 if (!PyArg_ParseTuple(_args, "O&O&",
1108 ResObj_Convert, &item,
1109 PyMac_GetStr255, text))
1110 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001111 SetDialogItemText(item,
1112 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001113 Py_INCREF(Py_None);
1114 _res = Py_None;
1115 return _res;
1116}
1117
Jack Jansenae8a68f1995-06-06 12:55:40 +00001118static PyObject *Dlg_GetAlertStage(_self, _args)
1119 PyObject *_self;
1120 PyObject *_args;
1121{
1122 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001123 SInt16 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001124 if (!PyArg_ParseTuple(_args, ""))
1125 return NULL;
1126 _rv = GetAlertStage();
1127 _res = Py_BuildValue("h",
1128 _rv);
1129 return _res;
1130}
1131
Jack Jansen21f96871998-02-20 16:02:09 +00001132static PyObject *Dlg_SetDialogFont(_self, _args)
1133 PyObject *_self;
1134 PyObject *_args;
1135{
1136 PyObject *_res = NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001137 SInt16 fontNum;
Jack Jansen21f96871998-02-20 16:02:09 +00001138 if (!PyArg_ParseTuple(_args, "h",
Jack Jansena05ac601999-12-12 21:41:51 +00001139 &fontNum))
Jack Jansen21f96871998-02-20 16:02:09 +00001140 return NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001141 SetDialogFont(fontNum);
Jack Jansen21f96871998-02-20 16:02:09 +00001142 Py_INCREF(Py_None);
1143 _res = Py_None;
1144 return _res;
1145}
1146
Jack Jansenae8a68f1995-06-06 12:55:40 +00001147static PyObject *Dlg_ResetAlertStage(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001148 PyObject *_self;
1149 PyObject *_args;
1150{
1151 PyObject *_res = NULL;
1152 if (!PyArg_ParseTuple(_args, ""))
1153 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001154 ResetAlertStage();
Guido van Rossum17448e21995-01-30 11:53:55 +00001155 Py_INCREF(Py_None);
1156 _res = Py_None;
1157 return _res;
1158}
1159
Jack Jansen21f96871998-02-20 16:02:09 +00001160static PyObject *Dlg_NewFeaturesDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001161 PyObject *_self;
1162 PyObject *_args;
1163{
1164 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001165 DialogPtr _rv;
1166 Rect inBoundsRect;
1167 Str255 inTitle;
1168 Boolean inIsVisible;
1169 SInt16 inProcID;
1170 WindowPtr inBehind;
1171 Boolean inGoAwayFlag;
1172 SInt32 inRefCon;
1173 Handle inItemListHandle;
1174 UInt32 inFlags;
1175 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
1176 PyMac_GetRect, &inBoundsRect,
1177 PyMac_GetStr255, inTitle,
1178 &inIsVisible,
1179 &inProcID,
1180 WinObj_Convert, &inBehind,
1181 &inGoAwayFlag,
1182 &inRefCon,
1183 ResObj_Convert, &inItemListHandle,
1184 &inFlags))
Guido van Rossum17448e21995-01-30 11:53:55 +00001185 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001186 _rv = NewFeaturesDialog((void *)0,
1187 &inBoundsRect,
1188 inTitle,
1189 inIsVisible,
1190 inProcID,
1191 inBehind,
1192 inGoAwayFlag,
1193 inRefCon,
1194 inItemListHandle,
1195 inFlags);
1196 _res = Py_BuildValue("O&",
1197 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +00001198 return _res;
1199}
1200
Jack Jansendf901df1998-07-10 15:47:48 +00001201static PyObject *Dlg_SetUserItemHandler(_self, _args)
1202 PyObject *_self;
1203 PyObject *_args;
1204{
1205 PyObject *_res = NULL;
1206
1207 PyObject *new = NULL;
1208
1209
1210 if (!PyArg_ParseTuple(_args, "|O", &new))
1211 return NULL;
1212
1213 if (Dlg_UserItemProc_callback && new && new != Py_None) {
1214 PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
1215 return NULL;
1216 }
1217
1218 if (new == Py_None) {
1219 new = NULL;
1220 _res = Py_None;
1221 Py_INCREF(Py_None);
1222 } else {
1223 Py_INCREF(new);
1224 _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc));
1225 }
1226
1227 Dlg_UserItemProc_callback = new;
1228 return _res;
1229
1230}
1231
Guido van Rossum17448e21995-01-30 11:53:55 +00001232static PyMethodDef Dlg_methods[] = {
1233 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001234 "(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 +00001235 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001236 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1237 {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
1238 "(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 +00001239 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001240 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001241 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
1242 "(EventRecord theEvent) -> (Boolean _rv)"},
1243 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001244 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001245 {"Alert", (PyCFunction)Dlg_Alert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001246 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001247 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001248 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001249 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001250 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001251 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001252 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1253 {"ParamText", (PyCFunction)Dlg_ParamText, 1,
1254 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001255 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001256 "(Handle item) -> (Str255 text)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001257 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001258 "(Handle item, Str255 text) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001259 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001260 "() -> (SInt16 _rv)"},
1261 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
Jack Jansena05ac601999-12-12 21:41:51 +00001262 "(SInt16 fontNum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001263 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001264 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001265 {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
1266 "(Rect inBoundsRect, Str255 inTitle, Boolean inIsVisible, SInt16 inProcID, WindowPtr inBehind, Boolean inGoAwayFlag, SInt32 inRefCon, Handle inItemListHandle, UInt32 inFlags) -> (DialogPtr _rv)"},
Jack Jansendf901df1998-07-10 15:47:48 +00001267 {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
1268 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001269 {NULL, NULL, 0}
1270};
1271
1272
1273
1274
1275void initDlg()
1276{
1277 PyObject *m;
1278 PyObject *d;
1279
1280
1281
1282
1283 m = Py_InitModule("Dlg", Dlg_methods);
1284 d = PyModule_GetDict(m);
1285 Dlg_Error = PyMac_GetOSErrException();
1286 if (Dlg_Error == NULL ||
1287 PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
1288 Py_FatalError("can't initialize Dlg.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001289 Dialog_Type.ob_type = &PyType_Type;
1290 Py_INCREF(&Dialog_Type);
1291 if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0)
1292 Py_FatalError("can't initialize DialogType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001293}
1294
1295/* ========================= End module Dlg ========================= */
1296