blob: b6868398c48446931c47278f7839329fbccf2226 [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
Jack Jansenb8c4c7b2000-08-25 22:25:54 +000092#if 1
93/*
94** Treating DialogObjects as WindowObjects is (I think) illegal under Carbon.
95** However, as they are still identical under MacOS9 Carbon this is a problem, even
96** if we neatly call GetDialogWindow() at the right places: there's one refcon field
97** and it points to the DialogObject, so WinObj_WhichWindow will smartly return the
98** dialog object, and therefore we still don't have a WindowObject.
99** I'll leave the chaining code in place for now, with this comment to warn the
100** unsuspecting victims (i.e. me, probably, in a few weeks:-)
101*/
Guido van Rossum17448e21995-01-30 11:53:55 +0000102extern PyMethodChain WinObj_chain;
Jack Jansenb8c4c7b2000-08-25 22:25:54 +0000103#endif
Guido van Rossum17448e21995-01-30 11:53:55 +0000104
105static PyObject *Dlg_Error;
106
107/* ----------------------- Object type Dialog ----------------------- */
108
109PyTypeObject Dialog_Type;
110
111#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
112
113typedef struct DialogObject {
114 PyObject_HEAD
115 DialogPtr ob_itself;
116} DialogObject;
117
118PyObject *DlgObj_New(itself)
Guido van Rossum97842951995-02-19 15:59:49 +0000119 DialogPtr itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000120{
121 DialogObject *it;
122 if (itself == NULL) return Py_None;
123 it = PyObject_NEW(DialogObject, &Dialog_Type);
124 if (it == NULL) return NULL;
125 it->ob_itself = itself;
Jack Jansene79dc762000-06-02 21:35:07 +0000126 SetWRefCon(GetDialogWindow(itself), (long)it);
Guido van Rossum17448e21995-01-30 11:53:55 +0000127 return (PyObject *)it;
128}
129DlgObj_Convert(v, p_itself)
130 PyObject *v;
131 DialogPtr *p_itself;
132{
133 if (v == Py_None) { *p_itself = NULL; return 1; }
134 if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
135 return 1; }
136 if (!DlgObj_Check(v))
137 {
138 PyErr_SetString(PyExc_TypeError, "Dialog required");
139 return 0;
140 }
141 *p_itself = ((DialogObject *)v)->ob_itself;
142 return 1;
143}
144
145static void DlgObj_dealloc(self)
146 DialogObject *self;
147{
148 DisposeDialog(self->ob_itself);
149 PyMem_DEL(self);
150}
151
152static PyObject *DlgObj_DrawDialog(_self, _args)
153 DialogObject *_self;
154 PyObject *_args;
155{
156 PyObject *_res = NULL;
157 if (!PyArg_ParseTuple(_args, ""))
158 return NULL;
159 DrawDialog(_self->ob_itself);
160 Py_INCREF(Py_None);
161 _res = Py_None;
162 return _res;
163}
164
Guido van Rossum17448e21995-01-30 11:53:55 +0000165static PyObject *DlgObj_UpdateDialog(_self, _args)
166 DialogObject *_self;
167 PyObject *_args;
168{
169 PyObject *_res = NULL;
Jack Jansen2b724171996-04-10 14:48:19 +0000170 RgnHandle updateRgn;
171 if (!PyArg_ParseTuple(_args, "O&",
172 ResObj_Convert, &updateRgn))
Guido van Rossum17448e21995-01-30 11:53:55 +0000173 return NULL;
174 UpdateDialog(_self->ob_itself,
Jack Jansen2b724171996-04-10 14:48:19 +0000175 updateRgn);
Guido van Rossum17448e21995-01-30 11:53:55 +0000176 Py_INCREF(Py_None);
177 _res = Py_None;
178 return _res;
179}
180
Jack Jansenae8a68f1995-06-06 12:55:40 +0000181static PyObject *DlgObj_HideDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000182 DialogObject *_self;
183 PyObject *_args;
184{
185 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000186 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000187 if (!PyArg_ParseTuple(_args, "h",
188 &itemNo))
189 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000190 HideDialogItem(_self->ob_itself,
191 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000192 Py_INCREF(Py_None);
193 _res = Py_None;
194 return _res;
195}
196
Jack Jansenae8a68f1995-06-06 12:55:40 +0000197static PyObject *DlgObj_ShowDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000198 DialogObject *_self;
199 PyObject *_args;
200{
201 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000202 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000203 if (!PyArg_ParseTuple(_args, "h",
204 &itemNo))
205 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000206 ShowDialogItem(_self->ob_itself,
207 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000208 Py_INCREF(Py_None);
209 _res = Py_None;
210 return _res;
211}
212
Jack Jansenae8a68f1995-06-06 12:55:40 +0000213static PyObject *DlgObj_FindDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000214 DialogObject *_self;
215 PyObject *_args;
216{
217 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000218 DialogItemIndexZeroBased _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000219 Point thePt;
220 if (!PyArg_ParseTuple(_args, "O&",
221 PyMac_GetPoint, &thePt))
222 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000223 _rv = FindDialogItem(_self->ob_itself,
224 thePt);
Guido van Rossum17448e21995-01-30 11:53:55 +0000225 _res = Py_BuildValue("h",
226 _rv);
227 return _res;
228}
229
Jack Jansenae8a68f1995-06-06 12:55:40 +0000230static PyObject *DlgObj_DialogCut(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000231 DialogObject *_self;
232 PyObject *_args;
233{
234 PyObject *_res = NULL;
235 if (!PyArg_ParseTuple(_args, ""))
236 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000237 DialogCut(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000238 Py_INCREF(Py_None);
239 _res = Py_None;
240 return _res;
241}
242
Jack Jansenae8a68f1995-06-06 12:55:40 +0000243static PyObject *DlgObj_DialogPaste(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000244 DialogObject *_self;
245 PyObject *_args;
246{
247 PyObject *_res = NULL;
248 if (!PyArg_ParseTuple(_args, ""))
249 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000250 DialogPaste(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000251 Py_INCREF(Py_None);
252 _res = Py_None;
253 return _res;
254}
255
Jack Jansenae8a68f1995-06-06 12:55:40 +0000256static PyObject *DlgObj_DialogCopy(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000257 DialogObject *_self;
258 PyObject *_args;
259{
260 PyObject *_res = NULL;
261 if (!PyArg_ParseTuple(_args, ""))
262 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000263 DialogCopy(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000264 Py_INCREF(Py_None);
265 _res = Py_None;
266 return _res;
267}
268
Jack Jansenae8a68f1995-06-06 12:55:40 +0000269static PyObject *DlgObj_DialogDelete(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000270 DialogObject *_self;
271 PyObject *_args;
272{
273 PyObject *_res = NULL;
274 if (!PyArg_ParseTuple(_args, ""))
275 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000276 DialogDelete(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000277 Py_INCREF(Py_None);
278 _res = Py_None;
279 return _res;
280}
281
Jack Jansen21f96871998-02-20 16:02:09 +0000282static PyObject *DlgObj_GetDialogItem(_self, _args)
283 DialogObject *_self;
284 PyObject *_args;
285{
286 PyObject *_res = NULL;
287 DialogItemIndex itemNo;
288 DialogItemType itemType;
289 Handle item;
290 Rect box;
291 if (!PyArg_ParseTuple(_args, "h",
292 &itemNo))
293 return NULL;
294 GetDialogItem(_self->ob_itself,
295 itemNo,
296 &itemType,
297 &item,
298 &box);
299 _res = Py_BuildValue("hO&O&",
300 itemType,
301 OptResObj_New, item,
302 PyMac_BuildRect, &box);
303 return _res;
304}
305
306static PyObject *DlgObj_SetDialogItem(_self, _args)
307 DialogObject *_self;
308 PyObject *_args;
309{
310 PyObject *_res = NULL;
311 DialogItemIndex itemNo;
312 DialogItemType itemType;
313 Handle item;
314 Rect box;
315 if (!PyArg_ParseTuple(_args, "hhO&O&",
316 &itemNo,
317 &itemType,
318 ResObj_Convert, &item,
319 PyMac_GetRect, &box))
320 return NULL;
321 SetDialogItem(_self->ob_itself,
322 itemNo,
323 itemType,
324 item,
325 &box);
326 Py_INCREF(Py_None);
327 _res = Py_None;
328 return _res;
329}
330
331static PyObject *DlgObj_SelectDialogItemText(_self, _args)
332 DialogObject *_self;
333 PyObject *_args;
334{
335 PyObject *_res = NULL;
336 DialogItemIndex itemNo;
337 SInt16 strtSel;
338 SInt16 endSel;
339 if (!PyArg_ParseTuple(_args, "hhh",
340 &itemNo,
341 &strtSel,
342 &endSel))
343 return NULL;
344 SelectDialogItemText(_self->ob_itself,
345 itemNo,
346 strtSel,
347 endSel);
348 Py_INCREF(Py_None);
349 _res = Py_None;
350 return _res;
351}
352
Guido van Rossum17448e21995-01-30 11:53:55 +0000353static PyObject *DlgObj_AppendDITL(_self, _args)
354 DialogObject *_self;
355 PyObject *_args;
356{
357 PyObject *_res = NULL;
358 Handle theHandle;
359 DITLMethod method;
360 if (!PyArg_ParseTuple(_args, "O&h",
361 ResObj_Convert, &theHandle,
362 &method))
363 return NULL;
364 AppendDITL(_self->ob_itself,
365 theHandle,
366 method);
367 Py_INCREF(Py_None);
368 _res = Py_None;
369 return _res;
370}
371
372static PyObject *DlgObj_CountDITL(_self, _args)
373 DialogObject *_self;
374 PyObject *_args;
375{
376 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000377 DialogItemIndex _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000378 if (!PyArg_ParseTuple(_args, ""))
379 return NULL;
380 _rv = CountDITL(_self->ob_itself);
381 _res = Py_BuildValue("h",
382 _rv);
383 return _res;
384}
385
386static PyObject *DlgObj_ShortenDITL(_self, _args)
387 DialogObject *_self;
388 PyObject *_args;
389{
390 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000391 DialogItemIndex numberItems;
Guido van Rossum17448e21995-01-30 11:53:55 +0000392 if (!PyArg_ParseTuple(_args, "h",
393 &numberItems))
394 return NULL;
395 ShortenDITL(_self->ob_itself,
396 numberItems);
397 Py_INCREF(Py_None);
398 _res = Py_None;
399 return _res;
400}
401
Jack Jansenae8a68f1995-06-06 12:55:40 +0000402static PyObject *DlgObj_StdFilterProc(_self, _args)
403 DialogObject *_self;
404 PyObject *_args;
405{
406 PyObject *_res = NULL;
407 Boolean _rv;
408 EventRecord event;
Jack Jansen21f96871998-02-20 16:02:09 +0000409 DialogItemIndex itemHit;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000410 if (!PyArg_ParseTuple(_args, ""))
411 return NULL;
412 _rv = StdFilterProc(_self->ob_itself,
413 &event,
414 &itemHit);
415 _res = Py_BuildValue("bO&h",
416 _rv,
417 PyMac_BuildEventRecord, &event,
418 itemHit);
419 return _res;
420}
421
422static PyObject *DlgObj_SetDialogDefaultItem(_self, _args)
423 DialogObject *_self;
424 PyObject *_args;
425{
426 PyObject *_res = NULL;
427 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000428 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000429 if (!PyArg_ParseTuple(_args, "h",
430 &newItem))
431 return NULL;
432 _err = SetDialogDefaultItem(_self->ob_itself,
433 newItem);
434 if (_err != noErr) return PyMac_Error(_err);
435 Py_INCREF(Py_None);
436 _res = Py_None;
437 return _res;
438}
439
440static PyObject *DlgObj_SetDialogCancelItem(_self, _args)
441 DialogObject *_self;
442 PyObject *_args;
443{
444 PyObject *_res = NULL;
445 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000446 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000447 if (!PyArg_ParseTuple(_args, "h",
448 &newItem))
449 return NULL;
450 _err = SetDialogCancelItem(_self->ob_itself,
451 newItem);
452 if (_err != noErr) return PyMac_Error(_err);
453 Py_INCREF(Py_None);
454 _res = Py_None;
455 return _res;
456}
457
458static PyObject *DlgObj_SetDialogTracksCursor(_self, _args)
459 DialogObject *_self;
460 PyObject *_args;
461{
462 PyObject *_res = NULL;
463 OSErr _err;
464 Boolean tracks;
465 if (!PyArg_ParseTuple(_args, "b",
466 &tracks))
467 return NULL;
468 _err = SetDialogTracksCursor(_self->ob_itself,
469 tracks);
470 if (_err != noErr) return PyMac_Error(_err);
471 Py_INCREF(Py_None);
472 _res = Py_None;
473 return _res;
474}
475
Jack Jansen21f96871998-02-20 16:02:09 +0000476static PyObject *DlgObj_AutoSizeDialog(_self, _args)
477 DialogObject *_self;
478 PyObject *_args;
479{
480 PyObject *_res = NULL;
481 OSErr _err;
482 if (!PyArg_ParseTuple(_args, ""))
483 return NULL;
484 _err = AutoSizeDialog(_self->ob_itself);
485 if (_err != noErr) return PyMac_Error(_err);
486 Py_INCREF(Py_None);
487 _res = Py_None;
488 return _res;
489}
490
491static PyObject *DlgObj_GetDialogItemAsControl(_self, _args)
492 DialogObject *_self;
493 PyObject *_args;
494{
495 PyObject *_res = NULL;
496 OSErr _err;
497 SInt16 inItemNo;
498 ControlHandle outControl;
499 if (!PyArg_ParseTuple(_args, "h",
500 &inItemNo))
501 return NULL;
502 _err = GetDialogItemAsControl(_self->ob_itself,
503 inItemNo,
504 &outControl);
505 if (_err != noErr) return PyMac_Error(_err);
506 _res = Py_BuildValue("O&",
507 CtlObj_New, outControl);
508 return _res;
509}
510
511static PyObject *DlgObj_MoveDialogItem(_self, _args)
512 DialogObject *_self;
513 PyObject *_args;
514{
515 PyObject *_res = NULL;
516 OSErr _err;
517 SInt16 inItemNo;
518 SInt16 inHoriz;
519 SInt16 inVert;
520 if (!PyArg_ParseTuple(_args, "hhh",
521 &inItemNo,
522 &inHoriz,
523 &inVert))
524 return NULL;
525 _err = MoveDialogItem(_self->ob_itself,
526 inItemNo,
527 inHoriz,
528 inVert);
529 if (_err != noErr) return PyMac_Error(_err);
530 Py_INCREF(Py_None);
531 _res = Py_None;
532 return _res;
533}
534
535static PyObject *DlgObj_SizeDialogItem(_self, _args)
536 DialogObject *_self;
537 PyObject *_args;
538{
539 PyObject *_res = NULL;
540 OSErr _err;
541 SInt16 inItemNo;
Jack Jansen21f96871998-02-20 16:02:09 +0000542 SInt16 inWidth;
Jack Jansen1c4e6141998-04-21 15:23:55 +0000543 SInt16 inHeight;
Jack Jansen21f96871998-02-20 16:02:09 +0000544 if (!PyArg_ParseTuple(_args, "hhh",
545 &inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000546 &inWidth,
547 &inHeight))
Jack Jansen21f96871998-02-20 16:02:09 +0000548 return NULL;
549 _err = SizeDialogItem(_self->ob_itself,
550 inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000551 inWidth,
552 inHeight);
Jack Jansen21f96871998-02-20 16:02:09 +0000553 if (_err != noErr) return PyMac_Error(_err);
554 Py_INCREF(Py_None);
555 _res = Py_None;
556 return _res;
557}
558
Jack Jansena05ac601999-12-12 21:41:51 +0000559static PyObject *DlgObj_AppendDialogItemList(_self, _args)
560 DialogObject *_self;
561 PyObject *_args;
562{
563 PyObject *_res = NULL;
564 OSErr _err;
565 SInt16 ditlID;
566 DITLMethod method;
567 if (!PyArg_ParseTuple(_args, "hh",
568 &ditlID,
569 &method))
570 return NULL;
571 _err = AppendDialogItemList(_self->ob_itself,
572 ditlID,
573 method);
574 if (_err != noErr) return PyMac_Error(_err);
575 Py_INCREF(Py_None);
576 _res = Py_None;
577 return _res;
578}
579
580static PyObject *DlgObj_SetDialogTimeout(_self, _args)
581 DialogObject *_self;
582 PyObject *_args;
583{
584 PyObject *_res = NULL;
585 OSStatus _err;
586 SInt16 inButtonToPress;
587 UInt32 inSecondsToWait;
588 if (!PyArg_ParseTuple(_args, "hl",
589 &inButtonToPress,
590 &inSecondsToWait))
591 return NULL;
592 _err = SetDialogTimeout(_self->ob_itself,
593 inButtonToPress,
594 inSecondsToWait);
595 if (_err != noErr) return PyMac_Error(_err);
596 Py_INCREF(Py_None);
597 _res = Py_None;
598 return _res;
599}
600
601static PyObject *DlgObj_GetDialogTimeout(_self, _args)
602 DialogObject *_self;
603 PyObject *_args;
604{
605 PyObject *_res = NULL;
606 OSStatus _err;
607 SInt16 outButtonToPress;
608 UInt32 outSecondsToWait;
609 UInt32 outSecondsRemaining;
610 if (!PyArg_ParseTuple(_args, ""))
611 return NULL;
612 _err = GetDialogTimeout(_self->ob_itself,
613 &outButtonToPress,
614 &outSecondsToWait,
615 &outSecondsRemaining);
616 if (_err != noErr) return PyMac_Error(_err);
617 _res = Py_BuildValue("hll",
618 outButtonToPress,
619 outSecondsToWait,
620 outSecondsRemaining);
621 return _res;
622}
623
624static PyObject *DlgObj_SetModalDialogEventMask(_self, _args)
625 DialogObject *_self;
626 PyObject *_args;
627{
628 PyObject *_res = NULL;
629 OSStatus _err;
630 EventMask inMask;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000631 if (!PyArg_ParseTuple(_args, "H",
Jack Jansena05ac601999-12-12 21:41:51 +0000632 &inMask))
633 return NULL;
634 _err = SetModalDialogEventMask(_self->ob_itself,
635 inMask);
636 if (_err != noErr) return PyMac_Error(_err);
637 Py_INCREF(Py_None);
638 _res = Py_None;
639 return _res;
640}
641
642static PyObject *DlgObj_GetModalDialogEventMask(_self, _args)
643 DialogObject *_self;
644 PyObject *_args;
645{
646 PyObject *_res = NULL;
647 OSStatus _err;
648 EventMask outMask;
649 if (!PyArg_ParseTuple(_args, ""))
650 return NULL;
651 _err = GetModalDialogEventMask(_self->ob_itself,
652 &outMask);
653 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000654 _res = Py_BuildValue("H",
Jack Jansena05ac601999-12-12 21:41:51 +0000655 outMask);
656 return _res;
657}
658
Jack Jansend96cb501996-09-23 15:48:46 +0000659static PyObject *DlgObj_GetDialogWindow(_self, _args)
660 DialogObject *_self;
661 PyObject *_args;
662{
663 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000664 WindowPtr _rv;
Jack Jansend96cb501996-09-23 15:48:46 +0000665 if (!PyArg_ParseTuple(_args, ""))
666 return NULL;
667 _rv = GetDialogWindow(_self->ob_itself);
668 _res = Py_BuildValue("O&",
Jack Jansenb8c4c7b2000-08-25 22:25:54 +0000669 WinObj_WhichWindow, _rv);
Jack Jansend96cb501996-09-23 15:48:46 +0000670 return _res;
671}
672
673static PyObject *DlgObj_GetDialogDefaultItem(_self, _args)
674 DialogObject *_self;
675 PyObject *_args;
676{
677 PyObject *_res = NULL;
678 SInt16 _rv;
679 if (!PyArg_ParseTuple(_args, ""))
680 return NULL;
681 _rv = GetDialogDefaultItem(_self->ob_itself);
682 _res = Py_BuildValue("h",
683 _rv);
684 return _res;
685}
686
687static PyObject *DlgObj_GetDialogCancelItem(_self, _args)
688 DialogObject *_self;
689 PyObject *_args;
690{
691 PyObject *_res = NULL;
692 SInt16 _rv;
693 if (!PyArg_ParseTuple(_args, ""))
694 return NULL;
695 _rv = GetDialogCancelItem(_self->ob_itself);
696 _res = Py_BuildValue("h",
697 _rv);
698 return _res;
699}
700
701static PyObject *DlgObj_GetDialogKeyboardFocusItem(_self, _args)
702 DialogObject *_self;
703 PyObject *_args;
704{
705 PyObject *_res = NULL;
706 SInt16 _rv;
707 if (!PyArg_ParseTuple(_args, ""))
708 return NULL;
709 _rv = GetDialogKeyboardFocusItem(_self->ob_itself);
710 _res = Py_BuildValue("h",
711 _rv);
712 return _res;
713}
714
Jack Jansen74a1e632000-07-14 22:37:27 +0000715#if !TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000716
Jack Jansend96cb501996-09-23 15:48:46 +0000717static PyObject *DlgObj_SetGrafPortOfDialog(_self, _args)
718 DialogObject *_self;
719 PyObject *_args;
720{
721 PyObject *_res = NULL;
722 if (!PyArg_ParseTuple(_args, ""))
723 return NULL;
724 SetGrafPortOfDialog(_self->ob_itself);
725 Py_INCREF(Py_None);
726 _res = Py_None;
727 return _res;
728}
Jack Jansene79dc762000-06-02 21:35:07 +0000729#endif
Jack Jansend96cb501996-09-23 15:48:46 +0000730
Guido van Rossum17448e21995-01-30 11:53:55 +0000731static PyMethodDef DlgObj_methods[] = {
732 {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
733 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000734 {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
Jack Jansen2b724171996-04-10 14:48:19 +0000735 "(RgnHandle updateRgn) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000736 {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000737 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000738 {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000739 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000740 {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000741 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000742 {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000743 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000744 {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000745 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000746 {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000747 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000748 {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000749 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000750 {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1,
751 "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"},
752 {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1,
753 "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"},
754 {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1,
755 "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000756 {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
757 "(Handle theHandle, DITLMethod method) -> None"},
758 {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000759 "() -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000760 {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000761 "(DialogItemIndex numberItems) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000762 {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000763 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000764 {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000765 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000766 {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000767 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000768 {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
769 "(Boolean tracks) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000770 {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1,
771 "() -> None"},
772 {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1,
773 "(SInt16 inItemNo) -> (ControlHandle outControl)"},
774 {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1,
775 "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"},
776 {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000777 "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +0000778 {"AppendDialogItemList", (PyCFunction)DlgObj_AppendDialogItemList, 1,
779 "(SInt16 ditlID, DITLMethod method) -> None"},
780 {"SetDialogTimeout", (PyCFunction)DlgObj_SetDialogTimeout, 1,
781 "(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None"},
782 {"GetDialogTimeout", (PyCFunction)DlgObj_GetDialogTimeout, 1,
783 "() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)"},
784 {"SetModalDialogEventMask", (PyCFunction)DlgObj_SetModalDialogEventMask, 1,
785 "(EventMask inMask) -> None"},
786 {"GetModalDialogEventMask", (PyCFunction)DlgObj_GetModalDialogEventMask, 1,
787 "() -> (EventMask outMask)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000788 {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
Jack Jansene79dc762000-06-02 21:35:07 +0000789 "() -> (WindowPtr _rv)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000790 {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1,
791 "() -> (SInt16 _rv)"},
792 {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1,
793 "() -> (SInt16 _rv)"},
794 {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1,
795 "() -> (SInt16 _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +0000796
Jack Jansen74a1e632000-07-14 22:37:27 +0000797#if !TARGET_API_MAC_CARBON
Jack Jansend96cb501996-09-23 15:48:46 +0000798 {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1,
799 "() -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +0000800#endif
Guido van Rossum17448e21995-01-30 11:53:55 +0000801 {NULL, NULL, 0}
802};
803
804PyMethodChain DlgObj_chain = { DlgObj_methods, &WinObj_chain };
805
806static PyObject *DlgObj_getattr(self, name)
807 DialogObject *self;
808 char *name;
809{
810 return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name);
811}
812
813#define DlgObj_setattr NULL
814
Jack Jansena05ac601999-12-12 21:41:51 +0000815#define DlgObj_compare NULL
816
817#define DlgObj_repr NULL
818
819#define DlgObj_hash NULL
820
Guido van Rossum17448e21995-01-30 11:53:55 +0000821PyTypeObject Dialog_Type = {
822 PyObject_HEAD_INIT(&PyType_Type)
823 0, /*ob_size*/
824 "Dialog", /*tp_name*/
825 sizeof(DialogObject), /*tp_basicsize*/
826 0, /*tp_itemsize*/
827 /* methods */
828 (destructor) DlgObj_dealloc, /*tp_dealloc*/
829 0, /*tp_print*/
830 (getattrfunc) DlgObj_getattr, /*tp_getattr*/
831 (setattrfunc) DlgObj_setattr, /*tp_setattr*/
Jack Jansena05ac601999-12-12 21:41:51 +0000832 (cmpfunc) DlgObj_compare, /*tp_compare*/
833 (reprfunc) DlgObj_repr, /*tp_repr*/
834 (PyNumberMethods *)0, /* tp_as_number */
835 (PySequenceMethods *)0, /* tp_as_sequence */
836 (PyMappingMethods *)0, /* tp_as_mapping */
837 (hashfunc) DlgObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +0000838};
839
840/* --------------------- End object type Dialog --------------------- */
841
842
843static PyObject *Dlg_NewDialog(_self, _args)
844 PyObject *_self;
845 PyObject *_args;
846{
847 PyObject *_res = NULL;
848 DialogPtr _rv;
849 Rect boundsRect;
850 Str255 title;
851 Boolean visible;
Jack Jansen21f96871998-02-20 16:02:09 +0000852 SInt16 procID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000853 WindowPtr behind;
854 Boolean goAwayFlag;
Jack Jansen21f96871998-02-20 16:02:09 +0000855 SInt32 refCon;
856 Handle items;
Guido van Rossum17448e21995-01-30 11:53:55 +0000857 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
858 PyMac_GetRect, &boundsRect,
859 PyMac_GetStr255, title,
860 &visible,
861 &procID,
862 WinObj_Convert, &behind,
863 &goAwayFlag,
864 &refCon,
Jack Jansen21f96871998-02-20 16:02:09 +0000865 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +0000866 return NULL;
867 _rv = NewDialog((void *)0,
868 &boundsRect,
869 title,
870 visible,
871 procID,
872 behind,
873 goAwayFlag,
874 refCon,
Jack Jansen21f96871998-02-20 16:02:09 +0000875 items);
Guido van Rossum17448e21995-01-30 11:53:55 +0000876 _res = Py_BuildValue("O&",
877 DlgObj_New, _rv);
878 return _res;
879}
880
881static PyObject *Dlg_GetNewDialog(_self, _args)
882 PyObject *_self;
883 PyObject *_args;
884{
885 PyObject *_res = NULL;
886 DialogPtr _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000887 SInt16 dialogID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000888 WindowPtr behind;
889 if (!PyArg_ParseTuple(_args, "hO&",
890 &dialogID,
891 WinObj_Convert, &behind))
892 return NULL;
893 _rv = GetNewDialog(dialogID,
894 (void *)0,
895 behind);
896 _res = Py_BuildValue("O&",
897 DlgObj_New, _rv);
898 return _res;
899}
900
Jack Jansen21f96871998-02-20 16:02:09 +0000901static PyObject *Dlg_NewColorDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000902 PyObject *_self;
903 PyObject *_args;
904{
905 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000906 DialogPtr _rv;
907 Rect boundsRect;
908 Str255 title;
909 Boolean visible;
910 SInt16 procID;
911 WindowPtr behind;
912 Boolean goAwayFlag;
913 SInt32 refCon;
914 Handle items;
915 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
916 PyMac_GetRect, &boundsRect,
917 PyMac_GetStr255, title,
918 &visible,
919 &procID,
920 WinObj_Convert, &behind,
921 &goAwayFlag,
922 &refCon,
923 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +0000924 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000925 _rv = NewColorDialog((void *)0,
926 &boundsRect,
927 title,
928 visible,
929 procID,
930 behind,
931 goAwayFlag,
932 refCon,
933 items);
934 _res = Py_BuildValue("O&",
935 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +0000936 return _res;
937}
938
939static PyObject *Dlg_ModalDialog(_self, _args)
940 PyObject *_self;
941 PyObject *_args;
942{
943 PyObject *_res = NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000944 PyObject* modalFilter;
Jack Jansen21f96871998-02-20 16:02:09 +0000945 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +0000946 if (!PyArg_ParseTuple(_args, "O",
Jack Jansenae8a68f1995-06-06 12:55:40 +0000947 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +0000948 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000949 ModalDialog(NewModalFilterProc(Dlg_PassFilterProc(modalFilter)),
Guido van Rossum17448e21995-01-30 11:53:55 +0000950 &itemHit);
951 _res = Py_BuildValue("h",
952 itemHit);
953 return _res;
954}
955
956static PyObject *Dlg_IsDialogEvent(_self, _args)
957 PyObject *_self;
958 PyObject *_args;
959{
960 PyObject *_res = NULL;
961 Boolean _rv;
962 EventRecord theEvent;
963 if (!PyArg_ParseTuple(_args, "O&",
964 PyMac_GetEventRecord, &theEvent))
965 return NULL;
966 _rv = IsDialogEvent(&theEvent);
967 _res = Py_BuildValue("b",
968 _rv);
969 return _res;
970}
971
972static PyObject *Dlg_DialogSelect(_self, _args)
973 PyObject *_self;
974 PyObject *_args;
975{
976 PyObject *_res = NULL;
977 Boolean _rv;
978 EventRecord theEvent;
979 DialogPtr theDialog;
Jack Jansen21f96871998-02-20 16:02:09 +0000980 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +0000981 if (!PyArg_ParseTuple(_args, "O&",
982 PyMac_GetEventRecord, &theEvent))
983 return NULL;
984 _rv = DialogSelect(&theEvent,
985 &theDialog,
986 &itemHit);
987 _res = Py_BuildValue("bO&h",
988 _rv,
989 WinObj_WhichWindow, theDialog,
990 itemHit);
991 return _res;
992}
993
994static PyObject *Dlg_Alert(_self, _args)
995 PyObject *_self;
996 PyObject *_args;
997{
998 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000999 DialogItemIndex _rv;
1000 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001001 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001002 if (!PyArg_ParseTuple(_args, "hO",
1003 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001004 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001005 return NULL;
1006 _rv = Alert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001007 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001008 _res = Py_BuildValue("h",
1009 _rv);
1010 return _res;
1011}
1012
1013static PyObject *Dlg_StopAlert(_self, _args)
1014 PyObject *_self;
1015 PyObject *_args;
1016{
1017 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001018 DialogItemIndex _rv;
1019 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001020 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001021 if (!PyArg_ParseTuple(_args, "hO",
1022 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001023 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001024 return NULL;
1025 _rv = StopAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001026 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001027 _res = Py_BuildValue("h",
1028 _rv);
1029 return _res;
1030}
1031
1032static PyObject *Dlg_NoteAlert(_self, _args)
1033 PyObject *_self;
1034 PyObject *_args;
1035{
1036 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001037 DialogItemIndex _rv;
1038 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001039 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001040 if (!PyArg_ParseTuple(_args, "hO",
1041 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001042 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001043 return NULL;
1044 _rv = NoteAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001045 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001046 _res = Py_BuildValue("h",
1047 _rv);
1048 return _res;
1049}
1050
1051static PyObject *Dlg_CautionAlert(_self, _args)
1052 PyObject *_self;
1053 PyObject *_args;
1054{
1055 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001056 DialogItemIndex _rv;
1057 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001058 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001059 if (!PyArg_ParseTuple(_args, "hO",
1060 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001061 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001062 return NULL;
1063 _rv = CautionAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001064 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001065 _res = Py_BuildValue("h",
1066 _rv);
1067 return _res;
1068}
1069
Jack Jansen21f96871998-02-20 16:02:09 +00001070static PyObject *Dlg_ParamText(_self, _args)
1071 PyObject *_self;
1072 PyObject *_args;
1073{
1074 PyObject *_res = NULL;
1075 Str255 param0;
1076 Str255 param1;
1077 Str255 param2;
1078 Str255 param3;
1079 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1080 PyMac_GetStr255, param0,
1081 PyMac_GetStr255, param1,
1082 PyMac_GetStr255, param2,
1083 PyMac_GetStr255, param3))
1084 return NULL;
1085 ParamText(param0,
1086 param1,
1087 param2,
1088 param3);
1089 Py_INCREF(Py_None);
1090 _res = Py_None;
1091 return _res;
1092}
1093
Jack Jansenae8a68f1995-06-06 12:55:40 +00001094static PyObject *Dlg_GetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001095 PyObject *_self;
1096 PyObject *_args;
1097{
1098 PyObject *_res = NULL;
1099 Handle item;
1100 Str255 text;
1101 if (!PyArg_ParseTuple(_args, "O&",
1102 ResObj_Convert, &item))
1103 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001104 GetDialogItemText(item,
1105 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001106 _res = Py_BuildValue("O&",
1107 PyMac_BuildStr255, text);
1108 return _res;
1109}
1110
Jack Jansenae8a68f1995-06-06 12:55:40 +00001111static PyObject *Dlg_SetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001112 PyObject *_self;
1113 PyObject *_args;
1114{
1115 PyObject *_res = NULL;
1116 Handle item;
1117 Str255 text;
1118 if (!PyArg_ParseTuple(_args, "O&O&",
1119 ResObj_Convert, &item,
1120 PyMac_GetStr255, text))
1121 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001122 SetDialogItemText(item,
1123 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001124 Py_INCREF(Py_None);
1125 _res = Py_None;
1126 return _res;
1127}
1128
Jack Jansenae8a68f1995-06-06 12:55:40 +00001129static PyObject *Dlg_GetAlertStage(_self, _args)
1130 PyObject *_self;
1131 PyObject *_args;
1132{
1133 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001134 SInt16 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001135 if (!PyArg_ParseTuple(_args, ""))
1136 return NULL;
1137 _rv = GetAlertStage();
1138 _res = Py_BuildValue("h",
1139 _rv);
1140 return _res;
1141}
1142
Jack Jansen21f96871998-02-20 16:02:09 +00001143static PyObject *Dlg_SetDialogFont(_self, _args)
1144 PyObject *_self;
1145 PyObject *_args;
1146{
1147 PyObject *_res = NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001148 SInt16 fontNum;
Jack Jansen21f96871998-02-20 16:02:09 +00001149 if (!PyArg_ParseTuple(_args, "h",
Jack Jansena05ac601999-12-12 21:41:51 +00001150 &fontNum))
Jack Jansen21f96871998-02-20 16:02:09 +00001151 return NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001152 SetDialogFont(fontNum);
Jack Jansen21f96871998-02-20 16:02:09 +00001153 Py_INCREF(Py_None);
1154 _res = Py_None;
1155 return _res;
1156}
1157
Jack Jansenae8a68f1995-06-06 12:55:40 +00001158static PyObject *Dlg_ResetAlertStage(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001159 PyObject *_self;
1160 PyObject *_args;
1161{
1162 PyObject *_res = NULL;
1163 if (!PyArg_ParseTuple(_args, ""))
1164 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001165 ResetAlertStage();
Guido van Rossum17448e21995-01-30 11:53:55 +00001166 Py_INCREF(Py_None);
1167 _res = Py_None;
1168 return _res;
1169}
1170
Jack Jansen21f96871998-02-20 16:02:09 +00001171static PyObject *Dlg_NewFeaturesDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001172 PyObject *_self;
1173 PyObject *_args;
1174{
1175 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001176 DialogPtr _rv;
1177 Rect inBoundsRect;
1178 Str255 inTitle;
1179 Boolean inIsVisible;
1180 SInt16 inProcID;
1181 WindowPtr inBehind;
1182 Boolean inGoAwayFlag;
1183 SInt32 inRefCon;
1184 Handle inItemListHandle;
1185 UInt32 inFlags;
1186 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
1187 PyMac_GetRect, &inBoundsRect,
1188 PyMac_GetStr255, inTitle,
1189 &inIsVisible,
1190 &inProcID,
1191 WinObj_Convert, &inBehind,
1192 &inGoAwayFlag,
1193 &inRefCon,
1194 ResObj_Convert, &inItemListHandle,
1195 &inFlags))
Guido van Rossum17448e21995-01-30 11:53:55 +00001196 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001197 _rv = NewFeaturesDialog((void *)0,
1198 &inBoundsRect,
1199 inTitle,
1200 inIsVisible,
1201 inProcID,
1202 inBehind,
1203 inGoAwayFlag,
1204 inRefCon,
1205 inItemListHandle,
1206 inFlags);
1207 _res = Py_BuildValue("O&",
1208 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +00001209 return _res;
1210}
1211
Jack Jansendf901df1998-07-10 15:47:48 +00001212static PyObject *Dlg_SetUserItemHandler(_self, _args)
1213 PyObject *_self;
1214 PyObject *_args;
1215{
1216 PyObject *_res = NULL;
1217
1218 PyObject *new = NULL;
1219
1220
1221 if (!PyArg_ParseTuple(_args, "|O", &new))
1222 return NULL;
1223
1224 if (Dlg_UserItemProc_callback && new && new != Py_None) {
1225 PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
1226 return NULL;
1227 }
1228
1229 if (new == Py_None) {
1230 new = NULL;
1231 _res = Py_None;
1232 Py_INCREF(Py_None);
1233 } else {
1234 Py_INCREF(new);
1235 _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc));
1236 }
1237
1238 Dlg_UserItemProc_callback = new;
1239 return _res;
1240
1241}
1242
Guido van Rossum17448e21995-01-30 11:53:55 +00001243static PyMethodDef Dlg_methods[] = {
1244 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001245 "(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 +00001246 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001247 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1248 {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
1249 "(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 +00001250 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001251 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001252 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
1253 "(EventRecord theEvent) -> (Boolean _rv)"},
1254 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001255 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001256 {"Alert", (PyCFunction)Dlg_Alert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001257 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001258 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001259 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001260 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001261 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001262 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001263 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1264 {"ParamText", (PyCFunction)Dlg_ParamText, 1,
1265 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001266 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001267 "(Handle item) -> (Str255 text)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001268 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001269 "(Handle item, Str255 text) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001270 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001271 "() -> (SInt16 _rv)"},
1272 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
Jack Jansena05ac601999-12-12 21:41:51 +00001273 "(SInt16 fontNum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001274 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001275 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001276 {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
1277 "(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 +00001278 {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
1279 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001280 {NULL, NULL, 0}
1281};
1282
1283
1284
1285
1286void initDlg()
1287{
1288 PyObject *m;
1289 PyObject *d;
1290
1291
1292
1293
1294 m = Py_InitModule("Dlg", Dlg_methods);
1295 d = PyModule_GetDict(m);
1296 Dlg_Error = PyMac_GetOSErrException();
1297 if (Dlg_Error == NULL ||
1298 PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
1299 Py_FatalError("can't initialize Dlg.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001300 Dialog_Type.ob_type = &PyType_Type;
1301 Py_INCREF(&Dialog_Type);
1302 if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0)
1303 Py_FatalError("can't initialize DialogType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001304}
1305
1306/* ========================= End module Dlg ========================= */
1307