blob: 827f7eb57fec722d526960ff40aeece12a2f4471 [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 Rossum97842951995-02-19 15:59:49 +000013#ifndef HAVE_UNIVERSAL_HEADERS
14#define NewModalFilterProc(x) (x)
15#endif
16
Guido van Rossum17448e21995-01-30 11:53:55 +000017/* XXX Shouldn't this be a stack? */
18static PyObject *Dlg_FilterProc_callback = NULL;
19
Guido van Rossum17448e21995-01-30 11:53:55 +000020static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog,
21 EventRecord *event,
22 short *itemHit)
23{
24 Boolean rv;
25 PyObject *args, *res;
26 PyObject *callback = Dlg_FilterProc_callback;
27 if (callback == NULL)
28 return 0; /* Default behavior */
29 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
Guido van Rossum0437e891995-02-21 20:56:21 +000030 args = Py_BuildValue("O&O&", WinObj_WhichWindow, dialog, PyMac_BuildEventRecord, event);
Guido van Rossum17448e21995-01-30 11:53:55 +000031 if (args == NULL)
32 res = NULL;
33 else {
34 res = PyEval_CallObject(callback, args);
35 Py_DECREF(args);
36 }
37 if (res == NULL) {
Jack Jansendeff89c1998-10-12 20:53:15 +000038 PySys_WriteStderr("Exception in Dialog Filter\n");
Guido van Rossum17448e21995-01-30 11:53:55 +000039 PyErr_Print();
40 *itemHit = -1; /* Fake return item */
41 return 1; /* We handled it */
42 }
43 else {
44 Dlg_FilterProc_callback = callback;
45 if (PyInt_Check(res)) {
46 *itemHit = PyInt_AsLong(res);
47 rv = 1;
48 }
49 else
50 rv = PyObject_IsTrue(res);
51 }
52 Py_DECREF(res);
53 return rv;
54}
55
56static ModalFilterProcPtr
57Dlg_PassFilterProc(PyObject *callback)
58{
59 PyObject *tmp = Dlg_FilterProc_callback;
60 Dlg_FilterProc_callback = NULL;
61 if (callback == Py_None) {
62 Py_XDECREF(tmp);
63 return NULL;
64 }
65 Py_INCREF(callback);
66 Dlg_FilterProc_callback = callback;
67 Py_XDECREF(tmp);
68 return &Dlg_UnivFilterProc;
69}
70
Jack Jansendf901df1998-07-10 15:47:48 +000071static PyObject *Dlg_UserItemProc_callback = NULL;
72
73static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
74 short item)
75{
76 PyObject *args, *res;
77
78 if (Dlg_UserItemProc_callback == NULL)
79 return; /* Default behavior */
80 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
81 args = Py_BuildValue("O&h", WinObj_WhichWindow, dialog, item);
82 if (args == NULL)
83 res = NULL;
84 else {
85 res = PyEval_CallObject(Dlg_UserItemProc_callback, args);
86 Py_DECREF(args);
87 }
88 if (res == NULL) {
Jack Jansendeff89c1998-10-12 20:53:15 +000089 PySys_WriteStderr("Exception in Dialog UserItem proc\n");
Jack Jansendf901df1998-07-10 15:47:48 +000090 PyErr_Print();
91 }
92 Py_XDECREF(res);
93 return;
94}
95
Guido van Rossum17448e21995-01-30 11:53:55 +000096extern PyMethodChain WinObj_chain;
97
98static PyObject *Dlg_Error;
99
100/* ----------------------- Object type Dialog ----------------------- */
101
102PyTypeObject Dialog_Type;
103
104#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
105
106typedef struct DialogObject {
107 PyObject_HEAD
108 DialogPtr ob_itself;
109} DialogObject;
110
111PyObject *DlgObj_New(itself)
Guido van Rossum97842951995-02-19 15:59:49 +0000112 DialogPtr itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000113{
114 DialogObject *it;
115 if (itself == NULL) return Py_None;
116 it = PyObject_NEW(DialogObject, &Dialog_Type);
117 if (it == NULL) return NULL;
118 it->ob_itself = itself;
Jack Jansene79dc762000-06-02 21:35:07 +0000119 SetWRefCon(GetDialogWindow(itself), (long)it);
Guido van Rossum17448e21995-01-30 11:53:55 +0000120 return (PyObject *)it;
121}
122DlgObj_Convert(v, p_itself)
123 PyObject *v;
124 DialogPtr *p_itself;
125{
126 if (v == Py_None) { *p_itself = NULL; return 1; }
127 if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
128 return 1; }
129 if (!DlgObj_Check(v))
130 {
131 PyErr_SetString(PyExc_TypeError, "Dialog required");
132 return 0;
133 }
134 *p_itself = ((DialogObject *)v)->ob_itself;
135 return 1;
136}
137
138static void DlgObj_dealloc(self)
139 DialogObject *self;
140{
141 DisposeDialog(self->ob_itself);
142 PyMem_DEL(self);
143}
144
145static PyObject *DlgObj_DrawDialog(_self, _args)
146 DialogObject *_self;
147 PyObject *_args;
148{
149 PyObject *_res = NULL;
150 if (!PyArg_ParseTuple(_args, ""))
151 return NULL;
152 DrawDialog(_self->ob_itself);
153 Py_INCREF(Py_None);
154 _res = Py_None;
155 return _res;
156}
157
Guido van Rossum17448e21995-01-30 11:53:55 +0000158static PyObject *DlgObj_UpdateDialog(_self, _args)
159 DialogObject *_self;
160 PyObject *_args;
161{
162 PyObject *_res = NULL;
Jack Jansen2b724171996-04-10 14:48:19 +0000163 RgnHandle updateRgn;
164 if (!PyArg_ParseTuple(_args, "O&",
165 ResObj_Convert, &updateRgn))
Guido van Rossum17448e21995-01-30 11:53:55 +0000166 return NULL;
167 UpdateDialog(_self->ob_itself,
Jack Jansen2b724171996-04-10 14:48:19 +0000168 updateRgn);
Guido van Rossum17448e21995-01-30 11:53:55 +0000169 Py_INCREF(Py_None);
170 _res = Py_None;
171 return _res;
172}
173
Jack Jansenae8a68f1995-06-06 12:55:40 +0000174static PyObject *DlgObj_HideDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000175 DialogObject *_self;
176 PyObject *_args;
177{
178 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000179 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000180 if (!PyArg_ParseTuple(_args, "h",
181 &itemNo))
182 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000183 HideDialogItem(_self->ob_itself,
184 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000185 Py_INCREF(Py_None);
186 _res = Py_None;
187 return _res;
188}
189
Jack Jansenae8a68f1995-06-06 12:55:40 +0000190static PyObject *DlgObj_ShowDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000191 DialogObject *_self;
192 PyObject *_args;
193{
194 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000195 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000196 if (!PyArg_ParseTuple(_args, "h",
197 &itemNo))
198 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000199 ShowDialogItem(_self->ob_itself,
200 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000201 Py_INCREF(Py_None);
202 _res = Py_None;
203 return _res;
204}
205
Jack Jansenae8a68f1995-06-06 12:55:40 +0000206static PyObject *DlgObj_FindDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000207 DialogObject *_self;
208 PyObject *_args;
209{
210 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000211 DialogItemIndexZeroBased _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000212 Point thePt;
213 if (!PyArg_ParseTuple(_args, "O&",
214 PyMac_GetPoint, &thePt))
215 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000216 _rv = FindDialogItem(_self->ob_itself,
217 thePt);
Guido van Rossum17448e21995-01-30 11:53:55 +0000218 _res = Py_BuildValue("h",
219 _rv);
220 return _res;
221}
222
Jack Jansenae8a68f1995-06-06 12:55:40 +0000223static PyObject *DlgObj_DialogCut(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000224 DialogObject *_self;
225 PyObject *_args;
226{
227 PyObject *_res = NULL;
228 if (!PyArg_ParseTuple(_args, ""))
229 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000230 DialogCut(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000231 Py_INCREF(Py_None);
232 _res = Py_None;
233 return _res;
234}
235
Jack Jansenae8a68f1995-06-06 12:55:40 +0000236static PyObject *DlgObj_DialogPaste(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000237 DialogObject *_self;
238 PyObject *_args;
239{
240 PyObject *_res = NULL;
241 if (!PyArg_ParseTuple(_args, ""))
242 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000243 DialogPaste(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000244 Py_INCREF(Py_None);
245 _res = Py_None;
246 return _res;
247}
248
Jack Jansenae8a68f1995-06-06 12:55:40 +0000249static PyObject *DlgObj_DialogCopy(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000250 DialogObject *_self;
251 PyObject *_args;
252{
253 PyObject *_res = NULL;
254 if (!PyArg_ParseTuple(_args, ""))
255 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000256 DialogCopy(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000257 Py_INCREF(Py_None);
258 _res = Py_None;
259 return _res;
260}
261
Jack Jansenae8a68f1995-06-06 12:55:40 +0000262static PyObject *DlgObj_DialogDelete(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000263 DialogObject *_self;
264 PyObject *_args;
265{
266 PyObject *_res = NULL;
267 if (!PyArg_ParseTuple(_args, ""))
268 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000269 DialogDelete(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000270 Py_INCREF(Py_None);
271 _res = Py_None;
272 return _res;
273}
274
Jack Jansen21f96871998-02-20 16:02:09 +0000275static PyObject *DlgObj_GetDialogItem(_self, _args)
276 DialogObject *_self;
277 PyObject *_args;
278{
279 PyObject *_res = NULL;
280 DialogItemIndex itemNo;
281 DialogItemType itemType;
282 Handle item;
283 Rect box;
284 if (!PyArg_ParseTuple(_args, "h",
285 &itemNo))
286 return NULL;
287 GetDialogItem(_self->ob_itself,
288 itemNo,
289 &itemType,
290 &item,
291 &box);
292 _res = Py_BuildValue("hO&O&",
293 itemType,
294 OptResObj_New, item,
295 PyMac_BuildRect, &box);
296 return _res;
297}
298
299static PyObject *DlgObj_SetDialogItem(_self, _args)
300 DialogObject *_self;
301 PyObject *_args;
302{
303 PyObject *_res = NULL;
304 DialogItemIndex itemNo;
305 DialogItemType itemType;
306 Handle item;
307 Rect box;
308 if (!PyArg_ParseTuple(_args, "hhO&O&",
309 &itemNo,
310 &itemType,
311 ResObj_Convert, &item,
312 PyMac_GetRect, &box))
313 return NULL;
314 SetDialogItem(_self->ob_itself,
315 itemNo,
316 itemType,
317 item,
318 &box);
319 Py_INCREF(Py_None);
320 _res = Py_None;
321 return _res;
322}
323
324static PyObject *DlgObj_SelectDialogItemText(_self, _args)
325 DialogObject *_self;
326 PyObject *_args;
327{
328 PyObject *_res = NULL;
329 DialogItemIndex itemNo;
330 SInt16 strtSel;
331 SInt16 endSel;
332 if (!PyArg_ParseTuple(_args, "hhh",
333 &itemNo,
334 &strtSel,
335 &endSel))
336 return NULL;
337 SelectDialogItemText(_self->ob_itself,
338 itemNo,
339 strtSel,
340 endSel);
341 Py_INCREF(Py_None);
342 _res = Py_None;
343 return _res;
344}
345
Guido van Rossum17448e21995-01-30 11:53:55 +0000346static PyObject *DlgObj_AppendDITL(_self, _args)
347 DialogObject *_self;
348 PyObject *_args;
349{
350 PyObject *_res = NULL;
351 Handle theHandle;
352 DITLMethod method;
353 if (!PyArg_ParseTuple(_args, "O&h",
354 ResObj_Convert, &theHandle,
355 &method))
356 return NULL;
357 AppendDITL(_self->ob_itself,
358 theHandle,
359 method);
360 Py_INCREF(Py_None);
361 _res = Py_None;
362 return _res;
363}
364
365static PyObject *DlgObj_CountDITL(_self, _args)
366 DialogObject *_self;
367 PyObject *_args;
368{
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
379static PyObject *DlgObj_ShortenDITL(_self, _args)
380 DialogObject *_self;
381 PyObject *_args;
382{
383 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000384 DialogItemIndex numberItems;
Guido van Rossum17448e21995-01-30 11:53:55 +0000385 if (!PyArg_ParseTuple(_args, "h",
386 &numberItems))
387 return NULL;
388 ShortenDITL(_self->ob_itself,
389 numberItems);
390 Py_INCREF(Py_None);
391 _res = Py_None;
392 return _res;
393}
394
Jack Jansenae8a68f1995-06-06 12:55:40 +0000395static PyObject *DlgObj_StdFilterProc(_self, _args)
396 DialogObject *_self;
397 PyObject *_args;
398{
399 PyObject *_res = NULL;
400 Boolean _rv;
401 EventRecord event;
Jack Jansen21f96871998-02-20 16:02:09 +0000402 DialogItemIndex itemHit;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000403 if (!PyArg_ParseTuple(_args, ""))
404 return NULL;
405 _rv = StdFilterProc(_self->ob_itself,
406 &event,
407 &itemHit);
408 _res = Py_BuildValue("bO&h",
409 _rv,
410 PyMac_BuildEventRecord, &event,
411 itemHit);
412 return _res;
413}
414
415static PyObject *DlgObj_SetDialogDefaultItem(_self, _args)
416 DialogObject *_self;
417 PyObject *_args;
418{
419 PyObject *_res = NULL;
420 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000421 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000422 if (!PyArg_ParseTuple(_args, "h",
423 &newItem))
424 return NULL;
425 _err = SetDialogDefaultItem(_self->ob_itself,
426 newItem);
427 if (_err != noErr) return PyMac_Error(_err);
428 Py_INCREF(Py_None);
429 _res = Py_None;
430 return _res;
431}
432
433static PyObject *DlgObj_SetDialogCancelItem(_self, _args)
434 DialogObject *_self;
435 PyObject *_args;
436{
437 PyObject *_res = NULL;
438 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000439 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000440 if (!PyArg_ParseTuple(_args, "h",
441 &newItem))
442 return NULL;
443 _err = SetDialogCancelItem(_self->ob_itself,
444 newItem);
445 if (_err != noErr) return PyMac_Error(_err);
446 Py_INCREF(Py_None);
447 _res = Py_None;
448 return _res;
449}
450
451static PyObject *DlgObj_SetDialogTracksCursor(_self, _args)
452 DialogObject *_self;
453 PyObject *_args;
454{
455 PyObject *_res = NULL;
456 OSErr _err;
457 Boolean tracks;
458 if (!PyArg_ParseTuple(_args, "b",
459 &tracks))
460 return NULL;
461 _err = SetDialogTracksCursor(_self->ob_itself,
462 tracks);
463 if (_err != noErr) return PyMac_Error(_err);
464 Py_INCREF(Py_None);
465 _res = Py_None;
466 return _res;
467}
468
Jack Jansen21f96871998-02-20 16:02:09 +0000469static PyObject *DlgObj_AutoSizeDialog(_self, _args)
470 DialogObject *_self;
471 PyObject *_args;
472{
473 PyObject *_res = NULL;
474 OSErr _err;
475 if (!PyArg_ParseTuple(_args, ""))
476 return NULL;
477 _err = AutoSizeDialog(_self->ob_itself);
478 if (_err != noErr) return PyMac_Error(_err);
479 Py_INCREF(Py_None);
480 _res = Py_None;
481 return _res;
482}
483
484static PyObject *DlgObj_GetDialogItemAsControl(_self, _args)
485 DialogObject *_self;
486 PyObject *_args;
487{
488 PyObject *_res = NULL;
489 OSErr _err;
490 SInt16 inItemNo;
491 ControlHandle outControl;
492 if (!PyArg_ParseTuple(_args, "h",
493 &inItemNo))
494 return NULL;
495 _err = GetDialogItemAsControl(_self->ob_itself,
496 inItemNo,
497 &outControl);
498 if (_err != noErr) return PyMac_Error(_err);
499 _res = Py_BuildValue("O&",
500 CtlObj_New, outControl);
501 return _res;
502}
503
504static PyObject *DlgObj_MoveDialogItem(_self, _args)
505 DialogObject *_self;
506 PyObject *_args;
507{
508 PyObject *_res = NULL;
509 OSErr _err;
510 SInt16 inItemNo;
511 SInt16 inHoriz;
512 SInt16 inVert;
513 if (!PyArg_ParseTuple(_args, "hhh",
514 &inItemNo,
515 &inHoriz,
516 &inVert))
517 return NULL;
518 _err = MoveDialogItem(_self->ob_itself,
519 inItemNo,
520 inHoriz,
521 inVert);
522 if (_err != noErr) return PyMac_Error(_err);
523 Py_INCREF(Py_None);
524 _res = Py_None;
525 return _res;
526}
527
528static PyObject *DlgObj_SizeDialogItem(_self, _args)
529 DialogObject *_self;
530 PyObject *_args;
531{
532 PyObject *_res = NULL;
533 OSErr _err;
534 SInt16 inItemNo;
Jack Jansen21f96871998-02-20 16:02:09 +0000535 SInt16 inWidth;
Jack Jansen1c4e6141998-04-21 15:23:55 +0000536 SInt16 inHeight;
Jack Jansen21f96871998-02-20 16:02:09 +0000537 if (!PyArg_ParseTuple(_args, "hhh",
538 &inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000539 &inWidth,
540 &inHeight))
Jack Jansen21f96871998-02-20 16:02:09 +0000541 return NULL;
542 _err = SizeDialogItem(_self->ob_itself,
543 inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000544 inWidth,
545 inHeight);
Jack Jansen21f96871998-02-20 16:02:09 +0000546 if (_err != noErr) return PyMac_Error(_err);
547 Py_INCREF(Py_None);
548 _res = Py_None;
549 return _res;
550}
551
Jack Jansena05ac601999-12-12 21:41:51 +0000552static PyObject *DlgObj_AppendDialogItemList(_self, _args)
553 DialogObject *_self;
554 PyObject *_args;
555{
556 PyObject *_res = NULL;
557 OSErr _err;
558 SInt16 ditlID;
559 DITLMethod method;
560 if (!PyArg_ParseTuple(_args, "hh",
561 &ditlID,
562 &method))
563 return NULL;
564 _err = AppendDialogItemList(_self->ob_itself,
565 ditlID,
566 method);
567 if (_err != noErr) return PyMac_Error(_err);
568 Py_INCREF(Py_None);
569 _res = Py_None;
570 return _res;
571}
572
573static PyObject *DlgObj_SetDialogTimeout(_self, _args)
574 DialogObject *_self;
575 PyObject *_args;
576{
577 PyObject *_res = NULL;
578 OSStatus _err;
579 SInt16 inButtonToPress;
580 UInt32 inSecondsToWait;
581 if (!PyArg_ParseTuple(_args, "hl",
582 &inButtonToPress,
583 &inSecondsToWait))
584 return NULL;
585 _err = SetDialogTimeout(_self->ob_itself,
586 inButtonToPress,
587 inSecondsToWait);
588 if (_err != noErr) return PyMac_Error(_err);
589 Py_INCREF(Py_None);
590 _res = Py_None;
591 return _res;
592}
593
594static PyObject *DlgObj_GetDialogTimeout(_self, _args)
595 DialogObject *_self;
596 PyObject *_args;
597{
598 PyObject *_res = NULL;
599 OSStatus _err;
600 SInt16 outButtonToPress;
601 UInt32 outSecondsToWait;
602 UInt32 outSecondsRemaining;
603 if (!PyArg_ParseTuple(_args, ""))
604 return NULL;
605 _err = GetDialogTimeout(_self->ob_itself,
606 &outButtonToPress,
607 &outSecondsToWait,
608 &outSecondsRemaining);
609 if (_err != noErr) return PyMac_Error(_err);
610 _res = Py_BuildValue("hll",
611 outButtonToPress,
612 outSecondsToWait,
613 outSecondsRemaining);
614 return _res;
615}
616
617static PyObject *DlgObj_SetModalDialogEventMask(_self, _args)
618 DialogObject *_self;
619 PyObject *_args;
620{
621 PyObject *_res = NULL;
622 OSStatus _err;
623 EventMask inMask;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000624 if (!PyArg_ParseTuple(_args, "H",
Jack Jansena05ac601999-12-12 21:41:51 +0000625 &inMask))
626 return NULL;
627 _err = SetModalDialogEventMask(_self->ob_itself,
628 inMask);
629 if (_err != noErr) return PyMac_Error(_err);
630 Py_INCREF(Py_None);
631 _res = Py_None;
632 return _res;
633}
634
635static PyObject *DlgObj_GetModalDialogEventMask(_self, _args)
636 DialogObject *_self;
637 PyObject *_args;
638{
639 PyObject *_res = NULL;
640 OSStatus _err;
641 EventMask outMask;
642 if (!PyArg_ParseTuple(_args, ""))
643 return NULL;
644 _err = GetModalDialogEventMask(_self->ob_itself,
645 &outMask);
646 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000647 _res = Py_BuildValue("H",
Jack Jansena05ac601999-12-12 21:41:51 +0000648 outMask);
649 return _res;
650}
651
Jack Jansend96cb501996-09-23 15:48:46 +0000652static PyObject *DlgObj_GetDialogWindow(_self, _args)
653 DialogObject *_self;
654 PyObject *_args;
655{
656 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000657 WindowPtr _rv;
Jack Jansend96cb501996-09-23 15:48:46 +0000658 if (!PyArg_ParseTuple(_args, ""))
659 return NULL;
660 _rv = GetDialogWindow(_self->ob_itself);
661 _res = Py_BuildValue("O&",
Jack Jansene79dc762000-06-02 21:35:07 +0000662 WinObj_New, _rv);
Jack Jansend96cb501996-09-23 15:48:46 +0000663 return _res;
664}
665
666static PyObject *DlgObj_GetDialogDefaultItem(_self, _args)
667 DialogObject *_self;
668 PyObject *_args;
669{
670 PyObject *_res = NULL;
671 SInt16 _rv;
672 if (!PyArg_ParseTuple(_args, ""))
673 return NULL;
674 _rv = GetDialogDefaultItem(_self->ob_itself);
675 _res = Py_BuildValue("h",
676 _rv);
677 return _res;
678}
679
680static PyObject *DlgObj_GetDialogCancelItem(_self, _args)
681 DialogObject *_self;
682 PyObject *_args;
683{
684 PyObject *_res = NULL;
685 SInt16 _rv;
686 if (!PyArg_ParseTuple(_args, ""))
687 return NULL;
688 _rv = GetDialogCancelItem(_self->ob_itself);
689 _res = Py_BuildValue("h",
690 _rv);
691 return _res;
692}
693
694static PyObject *DlgObj_GetDialogKeyboardFocusItem(_self, _args)
695 DialogObject *_self;
696 PyObject *_args;
697{
698 PyObject *_res = NULL;
699 SInt16 _rv;
700 if (!PyArg_ParseTuple(_args, ""))
701 return NULL;
702 _rv = GetDialogKeyboardFocusItem(_self->ob_itself);
703 _res = Py_BuildValue("h",
704 _rv);
705 return _res;
706}
707
Jack Jansen74a1e632000-07-14 22:37:27 +0000708#if !TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000709
Jack Jansend96cb501996-09-23 15:48:46 +0000710static PyObject *DlgObj_SetGrafPortOfDialog(_self, _args)
711 DialogObject *_self;
712 PyObject *_args;
713{
714 PyObject *_res = NULL;
715 if (!PyArg_ParseTuple(_args, ""))
716 return NULL;
717 SetGrafPortOfDialog(_self->ob_itself);
718 Py_INCREF(Py_None);
719 _res = Py_None;
720 return _res;
721}
Jack Jansene79dc762000-06-02 21:35:07 +0000722#endif
Jack Jansend96cb501996-09-23 15:48:46 +0000723
Guido van Rossum17448e21995-01-30 11:53:55 +0000724static PyMethodDef DlgObj_methods[] = {
725 {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
726 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000727 {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
Jack Jansen2b724171996-04-10 14:48:19 +0000728 "(RgnHandle updateRgn) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000729 {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000730 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000731 {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000732 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000733 {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000734 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000735 {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000736 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000737 {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000738 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000739 {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000740 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000741 {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000742 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000743 {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1,
744 "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"},
745 {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1,
746 "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"},
747 {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1,
748 "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000749 {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
750 "(Handle theHandle, DITLMethod method) -> None"},
751 {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000752 "() -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000753 {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000754 "(DialogItemIndex numberItems) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000755 {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000756 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000757 {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000758 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000759 {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000760 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000761 {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
762 "(Boolean tracks) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000763 {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1,
764 "() -> None"},
765 {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1,
766 "(SInt16 inItemNo) -> (ControlHandle outControl)"},
767 {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1,
768 "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"},
769 {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000770 "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +0000771 {"AppendDialogItemList", (PyCFunction)DlgObj_AppendDialogItemList, 1,
772 "(SInt16 ditlID, DITLMethod method) -> None"},
773 {"SetDialogTimeout", (PyCFunction)DlgObj_SetDialogTimeout, 1,
774 "(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None"},
775 {"GetDialogTimeout", (PyCFunction)DlgObj_GetDialogTimeout, 1,
776 "() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)"},
777 {"SetModalDialogEventMask", (PyCFunction)DlgObj_SetModalDialogEventMask, 1,
778 "(EventMask inMask) -> None"},
779 {"GetModalDialogEventMask", (PyCFunction)DlgObj_GetModalDialogEventMask, 1,
780 "() -> (EventMask outMask)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000781 {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
Jack Jansene79dc762000-06-02 21:35:07 +0000782 "() -> (WindowPtr _rv)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000783 {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1,
784 "() -> (SInt16 _rv)"},
785 {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1,
786 "() -> (SInt16 _rv)"},
787 {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1,
788 "() -> (SInt16 _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +0000789
Jack Jansen74a1e632000-07-14 22:37:27 +0000790#if !TARGET_API_MAC_CARBON
Jack Jansend96cb501996-09-23 15:48:46 +0000791 {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1,
792 "() -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +0000793#endif
Guido van Rossum17448e21995-01-30 11:53:55 +0000794 {NULL, NULL, 0}
795};
796
797PyMethodChain DlgObj_chain = { DlgObj_methods, &WinObj_chain };
798
799static PyObject *DlgObj_getattr(self, name)
800 DialogObject *self;
801 char *name;
802{
803 return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name);
804}
805
806#define DlgObj_setattr NULL
807
Jack Jansena05ac601999-12-12 21:41:51 +0000808#define DlgObj_compare NULL
809
810#define DlgObj_repr NULL
811
812#define DlgObj_hash NULL
813
Guido van Rossum17448e21995-01-30 11:53:55 +0000814PyTypeObject Dialog_Type = {
815 PyObject_HEAD_INIT(&PyType_Type)
816 0, /*ob_size*/
817 "Dialog", /*tp_name*/
818 sizeof(DialogObject), /*tp_basicsize*/
819 0, /*tp_itemsize*/
820 /* methods */
821 (destructor) DlgObj_dealloc, /*tp_dealloc*/
822 0, /*tp_print*/
823 (getattrfunc) DlgObj_getattr, /*tp_getattr*/
824 (setattrfunc) DlgObj_setattr, /*tp_setattr*/
Jack Jansena05ac601999-12-12 21:41:51 +0000825 (cmpfunc) DlgObj_compare, /*tp_compare*/
826 (reprfunc) DlgObj_repr, /*tp_repr*/
827 (PyNumberMethods *)0, /* tp_as_number */
828 (PySequenceMethods *)0, /* tp_as_sequence */
829 (PyMappingMethods *)0, /* tp_as_mapping */
830 (hashfunc) DlgObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +0000831};
832
833/* --------------------- End object type Dialog --------------------- */
834
835
836static PyObject *Dlg_NewDialog(_self, _args)
837 PyObject *_self;
838 PyObject *_args;
839{
840 PyObject *_res = NULL;
841 DialogPtr _rv;
842 Rect boundsRect;
843 Str255 title;
844 Boolean visible;
Jack Jansen21f96871998-02-20 16:02:09 +0000845 SInt16 procID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000846 WindowPtr behind;
847 Boolean goAwayFlag;
Jack Jansen21f96871998-02-20 16:02:09 +0000848 SInt32 refCon;
849 Handle items;
Guido van Rossum17448e21995-01-30 11:53:55 +0000850 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
851 PyMac_GetRect, &boundsRect,
852 PyMac_GetStr255, title,
853 &visible,
854 &procID,
855 WinObj_Convert, &behind,
856 &goAwayFlag,
857 &refCon,
Jack Jansen21f96871998-02-20 16:02:09 +0000858 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +0000859 return NULL;
860 _rv = NewDialog((void *)0,
861 &boundsRect,
862 title,
863 visible,
864 procID,
865 behind,
866 goAwayFlag,
867 refCon,
Jack Jansen21f96871998-02-20 16:02:09 +0000868 items);
Guido van Rossum17448e21995-01-30 11:53:55 +0000869 _res = Py_BuildValue("O&",
870 DlgObj_New, _rv);
871 return _res;
872}
873
874static PyObject *Dlg_GetNewDialog(_self, _args)
875 PyObject *_self;
876 PyObject *_args;
877{
878 PyObject *_res = NULL;
879 DialogPtr _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000880 SInt16 dialogID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000881 WindowPtr behind;
882 if (!PyArg_ParseTuple(_args, "hO&",
883 &dialogID,
884 WinObj_Convert, &behind))
885 return NULL;
886 _rv = GetNewDialog(dialogID,
887 (void *)0,
888 behind);
889 _res = Py_BuildValue("O&",
890 DlgObj_New, _rv);
891 return _res;
892}
893
Jack Jansen21f96871998-02-20 16:02:09 +0000894static PyObject *Dlg_NewColorDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000895 PyObject *_self;
896 PyObject *_args;
897{
898 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000899 DialogPtr _rv;
900 Rect boundsRect;
901 Str255 title;
902 Boolean visible;
903 SInt16 procID;
904 WindowPtr behind;
905 Boolean goAwayFlag;
906 SInt32 refCon;
907 Handle items;
908 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
909 PyMac_GetRect, &boundsRect,
910 PyMac_GetStr255, title,
911 &visible,
912 &procID,
913 WinObj_Convert, &behind,
914 &goAwayFlag,
915 &refCon,
916 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +0000917 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000918 _rv = NewColorDialog((void *)0,
919 &boundsRect,
920 title,
921 visible,
922 procID,
923 behind,
924 goAwayFlag,
925 refCon,
926 items);
927 _res = Py_BuildValue("O&",
928 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +0000929 return _res;
930}
931
932static PyObject *Dlg_ModalDialog(_self, _args)
933 PyObject *_self;
934 PyObject *_args;
935{
936 PyObject *_res = NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000937 PyObject* modalFilter;
Jack Jansen21f96871998-02-20 16:02:09 +0000938 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +0000939 if (!PyArg_ParseTuple(_args, "O",
Jack Jansenae8a68f1995-06-06 12:55:40 +0000940 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +0000941 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000942 ModalDialog(NewModalFilterProc(Dlg_PassFilterProc(modalFilter)),
Guido van Rossum17448e21995-01-30 11:53:55 +0000943 &itemHit);
944 _res = Py_BuildValue("h",
945 itemHit);
946 return _res;
947}
948
949static PyObject *Dlg_IsDialogEvent(_self, _args)
950 PyObject *_self;
951 PyObject *_args;
952{
953 PyObject *_res = NULL;
954 Boolean _rv;
955 EventRecord theEvent;
956 if (!PyArg_ParseTuple(_args, "O&",
957 PyMac_GetEventRecord, &theEvent))
958 return NULL;
959 _rv = IsDialogEvent(&theEvent);
960 _res = Py_BuildValue("b",
961 _rv);
962 return _res;
963}
964
965static PyObject *Dlg_DialogSelect(_self, _args)
966 PyObject *_self;
967 PyObject *_args;
968{
969 PyObject *_res = NULL;
970 Boolean _rv;
971 EventRecord theEvent;
972 DialogPtr theDialog;
Jack Jansen21f96871998-02-20 16:02:09 +0000973 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +0000974 if (!PyArg_ParseTuple(_args, "O&",
975 PyMac_GetEventRecord, &theEvent))
976 return NULL;
977 _rv = DialogSelect(&theEvent,
978 &theDialog,
979 &itemHit);
980 _res = Py_BuildValue("bO&h",
981 _rv,
982 WinObj_WhichWindow, theDialog,
983 itemHit);
984 return _res;
985}
986
987static PyObject *Dlg_Alert(_self, _args)
988 PyObject *_self;
989 PyObject *_args;
990{
991 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000992 DialogItemIndex _rv;
993 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000994 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +0000995 if (!PyArg_ParseTuple(_args, "hO",
996 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +0000997 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +0000998 return NULL;
999 _rv = Alert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001000 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001001 _res = Py_BuildValue("h",
1002 _rv);
1003 return _res;
1004}
1005
1006static PyObject *Dlg_StopAlert(_self, _args)
1007 PyObject *_self;
1008 PyObject *_args;
1009{
1010 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001011 DialogItemIndex _rv;
1012 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001013 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001014 if (!PyArg_ParseTuple(_args, "hO",
1015 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001016 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001017 return NULL;
1018 _rv = StopAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001019 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001020 _res = Py_BuildValue("h",
1021 _rv);
1022 return _res;
1023}
1024
1025static PyObject *Dlg_NoteAlert(_self, _args)
1026 PyObject *_self;
1027 PyObject *_args;
1028{
1029 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001030 DialogItemIndex _rv;
1031 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001032 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001033 if (!PyArg_ParseTuple(_args, "hO",
1034 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001035 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001036 return NULL;
1037 _rv = NoteAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001038 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001039 _res = Py_BuildValue("h",
1040 _rv);
1041 return _res;
1042}
1043
1044static PyObject *Dlg_CautionAlert(_self, _args)
1045 PyObject *_self;
1046 PyObject *_args;
1047{
1048 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001049 DialogItemIndex _rv;
1050 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001051 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001052 if (!PyArg_ParseTuple(_args, "hO",
1053 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001054 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001055 return NULL;
1056 _rv = CautionAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001057 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001058 _res = Py_BuildValue("h",
1059 _rv);
1060 return _res;
1061}
1062
Jack Jansen21f96871998-02-20 16:02:09 +00001063static PyObject *Dlg_ParamText(_self, _args)
1064 PyObject *_self;
1065 PyObject *_args;
1066{
1067 PyObject *_res = NULL;
1068 Str255 param0;
1069 Str255 param1;
1070 Str255 param2;
1071 Str255 param3;
1072 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1073 PyMac_GetStr255, param0,
1074 PyMac_GetStr255, param1,
1075 PyMac_GetStr255, param2,
1076 PyMac_GetStr255, param3))
1077 return NULL;
1078 ParamText(param0,
1079 param1,
1080 param2,
1081 param3);
1082 Py_INCREF(Py_None);
1083 _res = Py_None;
1084 return _res;
1085}
1086
Jack Jansenae8a68f1995-06-06 12:55:40 +00001087static PyObject *Dlg_GetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001088 PyObject *_self;
1089 PyObject *_args;
1090{
1091 PyObject *_res = NULL;
1092 Handle item;
1093 Str255 text;
1094 if (!PyArg_ParseTuple(_args, "O&",
1095 ResObj_Convert, &item))
1096 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001097 GetDialogItemText(item,
1098 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001099 _res = Py_BuildValue("O&",
1100 PyMac_BuildStr255, text);
1101 return _res;
1102}
1103
Jack Jansenae8a68f1995-06-06 12:55:40 +00001104static PyObject *Dlg_SetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001105 PyObject *_self;
1106 PyObject *_args;
1107{
1108 PyObject *_res = NULL;
1109 Handle item;
1110 Str255 text;
1111 if (!PyArg_ParseTuple(_args, "O&O&",
1112 ResObj_Convert, &item,
1113 PyMac_GetStr255, text))
1114 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001115 SetDialogItemText(item,
1116 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001117 Py_INCREF(Py_None);
1118 _res = Py_None;
1119 return _res;
1120}
1121
Jack Jansenae8a68f1995-06-06 12:55:40 +00001122static PyObject *Dlg_GetAlertStage(_self, _args)
1123 PyObject *_self;
1124 PyObject *_args;
1125{
1126 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001127 SInt16 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001128 if (!PyArg_ParseTuple(_args, ""))
1129 return NULL;
1130 _rv = GetAlertStage();
1131 _res = Py_BuildValue("h",
1132 _rv);
1133 return _res;
1134}
1135
Jack Jansen21f96871998-02-20 16:02:09 +00001136static PyObject *Dlg_SetDialogFont(_self, _args)
1137 PyObject *_self;
1138 PyObject *_args;
1139{
1140 PyObject *_res = NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001141 SInt16 fontNum;
Jack Jansen21f96871998-02-20 16:02:09 +00001142 if (!PyArg_ParseTuple(_args, "h",
Jack Jansena05ac601999-12-12 21:41:51 +00001143 &fontNum))
Jack Jansen21f96871998-02-20 16:02:09 +00001144 return NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001145 SetDialogFont(fontNum);
Jack Jansen21f96871998-02-20 16:02:09 +00001146 Py_INCREF(Py_None);
1147 _res = Py_None;
1148 return _res;
1149}
1150
Jack Jansenae8a68f1995-06-06 12:55:40 +00001151static PyObject *Dlg_ResetAlertStage(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001152 PyObject *_self;
1153 PyObject *_args;
1154{
1155 PyObject *_res = NULL;
1156 if (!PyArg_ParseTuple(_args, ""))
1157 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001158 ResetAlertStage();
Guido van Rossum17448e21995-01-30 11:53:55 +00001159 Py_INCREF(Py_None);
1160 _res = Py_None;
1161 return _res;
1162}
1163
Jack Jansen21f96871998-02-20 16:02:09 +00001164static PyObject *Dlg_NewFeaturesDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001165 PyObject *_self;
1166 PyObject *_args;
1167{
1168 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001169 DialogPtr _rv;
1170 Rect inBoundsRect;
1171 Str255 inTitle;
1172 Boolean inIsVisible;
1173 SInt16 inProcID;
1174 WindowPtr inBehind;
1175 Boolean inGoAwayFlag;
1176 SInt32 inRefCon;
1177 Handle inItemListHandle;
1178 UInt32 inFlags;
1179 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
1180 PyMac_GetRect, &inBoundsRect,
1181 PyMac_GetStr255, inTitle,
1182 &inIsVisible,
1183 &inProcID,
1184 WinObj_Convert, &inBehind,
1185 &inGoAwayFlag,
1186 &inRefCon,
1187 ResObj_Convert, &inItemListHandle,
1188 &inFlags))
Guido van Rossum17448e21995-01-30 11:53:55 +00001189 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001190 _rv = NewFeaturesDialog((void *)0,
1191 &inBoundsRect,
1192 inTitle,
1193 inIsVisible,
1194 inProcID,
1195 inBehind,
1196 inGoAwayFlag,
1197 inRefCon,
1198 inItemListHandle,
1199 inFlags);
1200 _res = Py_BuildValue("O&",
1201 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +00001202 return _res;
1203}
1204
Jack Jansendf901df1998-07-10 15:47:48 +00001205static PyObject *Dlg_SetUserItemHandler(_self, _args)
1206 PyObject *_self;
1207 PyObject *_args;
1208{
1209 PyObject *_res = NULL;
1210
1211 PyObject *new = NULL;
1212
1213
1214 if (!PyArg_ParseTuple(_args, "|O", &new))
1215 return NULL;
1216
1217 if (Dlg_UserItemProc_callback && new && new != Py_None) {
1218 PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
1219 return NULL;
1220 }
1221
1222 if (new == Py_None) {
1223 new = NULL;
1224 _res = Py_None;
1225 Py_INCREF(Py_None);
1226 } else {
1227 Py_INCREF(new);
1228 _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc));
1229 }
1230
1231 Dlg_UserItemProc_callback = new;
1232 return _res;
1233
1234}
1235
Guido van Rossum17448e21995-01-30 11:53:55 +00001236static PyMethodDef Dlg_methods[] = {
1237 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001238 "(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 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001240 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1241 {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
1242 "(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 +00001243 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001244 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001245 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
1246 "(EventRecord theEvent) -> (Boolean _rv)"},
1247 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001248 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001249 {"Alert", (PyCFunction)Dlg_Alert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001250 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001251 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001252 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001253 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001254 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001255 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001256 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1257 {"ParamText", (PyCFunction)Dlg_ParamText, 1,
1258 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001259 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001260 "(Handle item) -> (Str255 text)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001261 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001262 "(Handle item, Str255 text) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001263 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001264 "() -> (SInt16 _rv)"},
1265 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
Jack Jansena05ac601999-12-12 21:41:51 +00001266 "(SInt16 fontNum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001267 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001268 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001269 {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
1270 "(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 +00001271 {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
1272 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001273 {NULL, NULL, 0}
1274};
1275
1276
1277
1278
1279void initDlg()
1280{
1281 PyObject *m;
1282 PyObject *d;
1283
1284
1285
1286
1287 m = Py_InitModule("Dlg", Dlg_methods);
1288 d = PyModule_GetDict(m);
1289 Dlg_Error = PyMac_GetOSErrException();
1290 if (Dlg_Error == NULL ||
1291 PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
1292 Py_FatalError("can't initialize Dlg.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001293 Dialog_Type.ob_type = &PyType_Type;
1294 Py_INCREF(&Dialog_Type);
1295 if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0)
1296 Py_FatalError("can't initialize DialogType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001297}
1298
1299/* ========================= End module Dlg ========================= */
1300