blob: 15f61f56b4ffbff41fa8bd69e052a532deea3720 [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001
2/* =========================== Module Dlg =========================== */
3
4#include "Python.h"
5
6
7
8#define SystemSevenOrLater 1
9
10#include "macglue.h"
11#include <Memory.h>
12#include <Dialogs.h>
13#include <Menus.h>
14#include <Controls.h>
15
16extern PyObject *ResObj_New(Handle);
17extern int ResObj_Convert(PyObject *, Handle *);
Jack Jansen425e9eb1995-12-12 15:02:03 +000018extern PyObject *OptResObj_New(Handle);
19extern int OptResObj_Convert(PyObject *, Handle *);
Guido van Rossum17448e21995-01-30 11:53:55 +000020
21extern PyObject *WinObj_New(WindowPtr);
22extern int WinObj_Convert(PyObject *, WindowPtr *);
Jack Jansen425e9eb1995-12-12 15:02:03 +000023extern PyTypeObject Window_Type;
24#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
Guido van Rossum17448e21995-01-30 11:53:55 +000025
26extern PyObject *DlgObj_New(DialogPtr);
27extern int DlgObj_Convert(PyObject *, DialogPtr *);
28extern PyTypeObject Dialog_Type;
29#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
30
31extern PyObject *MenuObj_New(MenuHandle);
32extern int MenuObj_Convert(PyObject *, MenuHandle *);
33
34extern PyObject *CtlObj_New(ControlHandle);
35extern int CtlObj_Convert(PyObject *, ControlHandle *);
36
Jack Jansen425e9eb1995-12-12 15:02:03 +000037extern PyObject *GrafObj_New(GrafPtr);
38extern int GrafObj_Convert(PyObject *, GrafPtr *);
39
40extern PyObject *BMObj_New(BitMapPtr);
41extern int BMObj_Convert(PyObject *, BitMapPtr *);
42
Guido van Rossum17448e21995-01-30 11:53:55 +000043extern PyObject *WinObj_WhichWindow(WindowPtr);
44
45#include <Dialogs.h>
46
Guido van Rossum97842951995-02-19 15:59:49 +000047#ifndef HAVE_UNIVERSAL_HEADERS
48#define NewModalFilterProc(x) (x)
49#endif
50
Guido van Rossum17448e21995-01-30 11:53:55 +000051#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
52
53/* XXX Shouldn't this be a stack? */
54static PyObject *Dlg_FilterProc_callback = NULL;
55
56static PyObject *DlgObj_New(DialogPtr); /* Forward */
57
58static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog,
59 EventRecord *event,
60 short *itemHit)
61{
62 Boolean rv;
63 PyObject *args, *res;
64 PyObject *callback = Dlg_FilterProc_callback;
65 if (callback == NULL)
66 return 0; /* Default behavior */
67 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
Guido van Rossum0437e891995-02-21 20:56:21 +000068 args = Py_BuildValue("O&O&", WinObj_WhichWindow, dialog, PyMac_BuildEventRecord, event);
Guido van Rossum17448e21995-01-30 11:53:55 +000069 if (args == NULL)
70 res = NULL;
71 else {
72 res = PyEval_CallObject(callback, args);
73 Py_DECREF(args);
74 }
75 if (res == NULL) {
Jack Jansendeff89c1998-10-12 20:53:15 +000076 PySys_WriteStderr("Exception in Dialog Filter\n");
Guido van Rossum17448e21995-01-30 11:53:55 +000077 PyErr_Print();
78 *itemHit = -1; /* Fake return item */
79 return 1; /* We handled it */
80 }
81 else {
82 Dlg_FilterProc_callback = callback;
83 if (PyInt_Check(res)) {
84 *itemHit = PyInt_AsLong(res);
85 rv = 1;
86 }
87 else
88 rv = PyObject_IsTrue(res);
89 }
90 Py_DECREF(res);
91 return rv;
92}
93
94static ModalFilterProcPtr
95Dlg_PassFilterProc(PyObject *callback)
96{
97 PyObject *tmp = Dlg_FilterProc_callback;
98 Dlg_FilterProc_callback = NULL;
99 if (callback == Py_None) {
100 Py_XDECREF(tmp);
101 return NULL;
102 }
103 Py_INCREF(callback);
104 Dlg_FilterProc_callback = callback;
105 Py_XDECREF(tmp);
106 return &Dlg_UnivFilterProc;
107}
108
Jack Jansendf901df1998-07-10 15:47:48 +0000109static PyObject *Dlg_UserItemProc_callback = NULL;
110
111static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
112 short item)
113{
114 PyObject *args, *res;
115
116 if (Dlg_UserItemProc_callback == NULL)
117 return; /* Default behavior */
118 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
119 args = Py_BuildValue("O&h", WinObj_WhichWindow, dialog, item);
120 if (args == NULL)
121 res = NULL;
122 else {
123 res = PyEval_CallObject(Dlg_UserItemProc_callback, args);
124 Py_DECREF(args);
125 }
126 if (res == NULL) {
Jack Jansendeff89c1998-10-12 20:53:15 +0000127 PySys_WriteStderr("Exception in Dialog UserItem proc\n");
Jack Jansendf901df1998-07-10 15:47:48 +0000128 PyErr_Print();
129 }
130 Py_XDECREF(res);
131 return;
132}
133
Guido van Rossum17448e21995-01-30 11:53:55 +0000134extern PyMethodChain WinObj_chain;
135
136static PyObject *Dlg_Error;
137
138/* ----------------------- Object type Dialog ----------------------- */
139
140PyTypeObject Dialog_Type;
141
142#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
143
144typedef struct DialogObject {
145 PyObject_HEAD
146 DialogPtr ob_itself;
147} DialogObject;
148
149PyObject *DlgObj_New(itself)
Guido van Rossum97842951995-02-19 15:59:49 +0000150 DialogPtr itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000151{
152 DialogObject *it;
153 if (itself == NULL) return Py_None;
154 it = PyObject_NEW(DialogObject, &Dialog_Type);
155 if (it == NULL) return NULL;
156 it->ob_itself = itself;
Jack Jansene79dc762000-06-02 21:35:07 +0000157 SetWRefCon(GetDialogWindow(itself), (long)it);
Guido van Rossum17448e21995-01-30 11:53:55 +0000158 return (PyObject *)it;
159}
160DlgObj_Convert(v, p_itself)
161 PyObject *v;
162 DialogPtr *p_itself;
163{
164 if (v == Py_None) { *p_itself = NULL; return 1; }
165 if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
166 return 1; }
167 if (!DlgObj_Check(v))
168 {
169 PyErr_SetString(PyExc_TypeError, "Dialog required");
170 return 0;
171 }
172 *p_itself = ((DialogObject *)v)->ob_itself;
173 return 1;
174}
175
176static void DlgObj_dealloc(self)
177 DialogObject *self;
178{
179 DisposeDialog(self->ob_itself);
180 PyMem_DEL(self);
181}
182
183static PyObject *DlgObj_DrawDialog(_self, _args)
184 DialogObject *_self;
185 PyObject *_args;
186{
187 PyObject *_res = NULL;
188 if (!PyArg_ParseTuple(_args, ""))
189 return NULL;
190 DrawDialog(_self->ob_itself);
191 Py_INCREF(Py_None);
192 _res = Py_None;
193 return _res;
194}
195
Guido van Rossum17448e21995-01-30 11:53:55 +0000196static PyObject *DlgObj_UpdateDialog(_self, _args)
197 DialogObject *_self;
198 PyObject *_args;
199{
200 PyObject *_res = NULL;
Jack Jansen2b724171996-04-10 14:48:19 +0000201 RgnHandle updateRgn;
202 if (!PyArg_ParseTuple(_args, "O&",
203 ResObj_Convert, &updateRgn))
Guido van Rossum17448e21995-01-30 11:53:55 +0000204 return NULL;
205 UpdateDialog(_self->ob_itself,
Jack Jansen2b724171996-04-10 14:48:19 +0000206 updateRgn);
Guido van Rossum17448e21995-01-30 11:53:55 +0000207 Py_INCREF(Py_None);
208 _res = Py_None;
209 return _res;
210}
211
Jack Jansenae8a68f1995-06-06 12:55:40 +0000212static PyObject *DlgObj_HideDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000213 DialogObject *_self;
214 PyObject *_args;
215{
216 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000217 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000218 if (!PyArg_ParseTuple(_args, "h",
219 &itemNo))
220 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000221 HideDialogItem(_self->ob_itself,
222 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000223 Py_INCREF(Py_None);
224 _res = Py_None;
225 return _res;
226}
227
Jack Jansenae8a68f1995-06-06 12:55:40 +0000228static PyObject *DlgObj_ShowDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000229 DialogObject *_self;
230 PyObject *_args;
231{
232 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000233 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000234 if (!PyArg_ParseTuple(_args, "h",
235 &itemNo))
236 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000237 ShowDialogItem(_self->ob_itself,
238 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000239 Py_INCREF(Py_None);
240 _res = Py_None;
241 return _res;
242}
243
Jack Jansenae8a68f1995-06-06 12:55:40 +0000244static PyObject *DlgObj_FindDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000245 DialogObject *_self;
246 PyObject *_args;
247{
248 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000249 DialogItemIndexZeroBased _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000250 Point thePt;
251 if (!PyArg_ParseTuple(_args, "O&",
252 PyMac_GetPoint, &thePt))
253 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000254 _rv = FindDialogItem(_self->ob_itself,
255 thePt);
Guido van Rossum17448e21995-01-30 11:53:55 +0000256 _res = Py_BuildValue("h",
257 _rv);
258 return _res;
259}
260
Jack Jansenae8a68f1995-06-06 12:55:40 +0000261static PyObject *DlgObj_DialogCut(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000262 DialogObject *_self;
263 PyObject *_args;
264{
265 PyObject *_res = NULL;
266 if (!PyArg_ParseTuple(_args, ""))
267 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000268 DialogCut(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000269 Py_INCREF(Py_None);
270 _res = Py_None;
271 return _res;
272}
273
Jack Jansenae8a68f1995-06-06 12:55:40 +0000274static PyObject *DlgObj_DialogPaste(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000275 DialogObject *_self;
276 PyObject *_args;
277{
278 PyObject *_res = NULL;
279 if (!PyArg_ParseTuple(_args, ""))
280 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000281 DialogPaste(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000282 Py_INCREF(Py_None);
283 _res = Py_None;
284 return _res;
285}
286
Jack Jansenae8a68f1995-06-06 12:55:40 +0000287static PyObject *DlgObj_DialogCopy(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000288 DialogObject *_self;
289 PyObject *_args;
290{
291 PyObject *_res = NULL;
292 if (!PyArg_ParseTuple(_args, ""))
293 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000294 DialogCopy(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000295 Py_INCREF(Py_None);
296 _res = Py_None;
297 return _res;
298}
299
Jack Jansenae8a68f1995-06-06 12:55:40 +0000300static PyObject *DlgObj_DialogDelete(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000301 DialogObject *_self;
302 PyObject *_args;
303{
304 PyObject *_res = NULL;
305 if (!PyArg_ParseTuple(_args, ""))
306 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000307 DialogDelete(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000308 Py_INCREF(Py_None);
309 _res = Py_None;
310 return _res;
311}
312
Jack Jansen21f96871998-02-20 16:02:09 +0000313static PyObject *DlgObj_GetDialogItem(_self, _args)
314 DialogObject *_self;
315 PyObject *_args;
316{
317 PyObject *_res = NULL;
318 DialogItemIndex itemNo;
319 DialogItemType itemType;
320 Handle item;
321 Rect box;
322 if (!PyArg_ParseTuple(_args, "h",
323 &itemNo))
324 return NULL;
325 GetDialogItem(_self->ob_itself,
326 itemNo,
327 &itemType,
328 &item,
329 &box);
330 _res = Py_BuildValue("hO&O&",
331 itemType,
332 OptResObj_New, item,
333 PyMac_BuildRect, &box);
334 return _res;
335}
336
337static PyObject *DlgObj_SetDialogItem(_self, _args)
338 DialogObject *_self;
339 PyObject *_args;
340{
341 PyObject *_res = NULL;
342 DialogItemIndex itemNo;
343 DialogItemType itemType;
344 Handle item;
345 Rect box;
346 if (!PyArg_ParseTuple(_args, "hhO&O&",
347 &itemNo,
348 &itemType,
349 ResObj_Convert, &item,
350 PyMac_GetRect, &box))
351 return NULL;
352 SetDialogItem(_self->ob_itself,
353 itemNo,
354 itemType,
355 item,
356 &box);
357 Py_INCREF(Py_None);
358 _res = Py_None;
359 return _res;
360}
361
362static PyObject *DlgObj_SelectDialogItemText(_self, _args)
363 DialogObject *_self;
364 PyObject *_args;
365{
366 PyObject *_res = NULL;
367 DialogItemIndex itemNo;
368 SInt16 strtSel;
369 SInt16 endSel;
370 if (!PyArg_ParseTuple(_args, "hhh",
371 &itemNo,
372 &strtSel,
373 &endSel))
374 return NULL;
375 SelectDialogItemText(_self->ob_itself,
376 itemNo,
377 strtSel,
378 endSel);
379 Py_INCREF(Py_None);
380 _res = Py_None;
381 return _res;
382}
383
Guido van Rossum17448e21995-01-30 11:53:55 +0000384static PyObject *DlgObj_AppendDITL(_self, _args)
385 DialogObject *_self;
386 PyObject *_args;
387{
388 PyObject *_res = NULL;
389 Handle theHandle;
390 DITLMethod method;
391 if (!PyArg_ParseTuple(_args, "O&h",
392 ResObj_Convert, &theHandle,
393 &method))
394 return NULL;
395 AppendDITL(_self->ob_itself,
396 theHandle,
397 method);
398 Py_INCREF(Py_None);
399 _res = Py_None;
400 return _res;
401}
402
403static PyObject *DlgObj_CountDITL(_self, _args)
404 DialogObject *_self;
405 PyObject *_args;
406{
407 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000408 DialogItemIndex _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000409 if (!PyArg_ParseTuple(_args, ""))
410 return NULL;
411 _rv = CountDITL(_self->ob_itself);
412 _res = Py_BuildValue("h",
413 _rv);
414 return _res;
415}
416
417static PyObject *DlgObj_ShortenDITL(_self, _args)
418 DialogObject *_self;
419 PyObject *_args;
420{
421 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000422 DialogItemIndex numberItems;
Guido van Rossum17448e21995-01-30 11:53:55 +0000423 if (!PyArg_ParseTuple(_args, "h",
424 &numberItems))
425 return NULL;
426 ShortenDITL(_self->ob_itself,
427 numberItems);
428 Py_INCREF(Py_None);
429 _res = Py_None;
430 return _res;
431}
432
Jack Jansenae8a68f1995-06-06 12:55:40 +0000433static PyObject *DlgObj_StdFilterProc(_self, _args)
434 DialogObject *_self;
435 PyObject *_args;
436{
437 PyObject *_res = NULL;
438 Boolean _rv;
439 EventRecord event;
Jack Jansen21f96871998-02-20 16:02:09 +0000440 DialogItemIndex itemHit;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000441 if (!PyArg_ParseTuple(_args, ""))
442 return NULL;
443 _rv = StdFilterProc(_self->ob_itself,
444 &event,
445 &itemHit);
446 _res = Py_BuildValue("bO&h",
447 _rv,
448 PyMac_BuildEventRecord, &event,
449 itemHit);
450 return _res;
451}
452
453static PyObject *DlgObj_SetDialogDefaultItem(_self, _args)
454 DialogObject *_self;
455 PyObject *_args;
456{
457 PyObject *_res = NULL;
458 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000459 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000460 if (!PyArg_ParseTuple(_args, "h",
461 &newItem))
462 return NULL;
463 _err = SetDialogDefaultItem(_self->ob_itself,
464 newItem);
465 if (_err != noErr) return PyMac_Error(_err);
466 Py_INCREF(Py_None);
467 _res = Py_None;
468 return _res;
469}
470
471static PyObject *DlgObj_SetDialogCancelItem(_self, _args)
472 DialogObject *_self;
473 PyObject *_args;
474{
475 PyObject *_res = NULL;
476 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000477 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000478 if (!PyArg_ParseTuple(_args, "h",
479 &newItem))
480 return NULL;
481 _err = SetDialogCancelItem(_self->ob_itself,
482 newItem);
483 if (_err != noErr) return PyMac_Error(_err);
484 Py_INCREF(Py_None);
485 _res = Py_None;
486 return _res;
487}
488
489static PyObject *DlgObj_SetDialogTracksCursor(_self, _args)
490 DialogObject *_self;
491 PyObject *_args;
492{
493 PyObject *_res = NULL;
494 OSErr _err;
495 Boolean tracks;
496 if (!PyArg_ParseTuple(_args, "b",
497 &tracks))
498 return NULL;
499 _err = SetDialogTracksCursor(_self->ob_itself,
500 tracks);
501 if (_err != noErr) return PyMac_Error(_err);
502 Py_INCREF(Py_None);
503 _res = Py_None;
504 return _res;
505}
506
Jack Jansen21f96871998-02-20 16:02:09 +0000507static PyObject *DlgObj_AutoSizeDialog(_self, _args)
508 DialogObject *_self;
509 PyObject *_args;
510{
511 PyObject *_res = NULL;
512 OSErr _err;
513 if (!PyArg_ParseTuple(_args, ""))
514 return NULL;
515 _err = AutoSizeDialog(_self->ob_itself);
516 if (_err != noErr) return PyMac_Error(_err);
517 Py_INCREF(Py_None);
518 _res = Py_None;
519 return _res;
520}
521
522static PyObject *DlgObj_GetDialogItemAsControl(_self, _args)
523 DialogObject *_self;
524 PyObject *_args;
525{
526 PyObject *_res = NULL;
527 OSErr _err;
528 SInt16 inItemNo;
529 ControlHandle outControl;
530 if (!PyArg_ParseTuple(_args, "h",
531 &inItemNo))
532 return NULL;
533 _err = GetDialogItemAsControl(_self->ob_itself,
534 inItemNo,
535 &outControl);
536 if (_err != noErr) return PyMac_Error(_err);
537 _res = Py_BuildValue("O&",
538 CtlObj_New, outControl);
539 return _res;
540}
541
542static PyObject *DlgObj_MoveDialogItem(_self, _args)
543 DialogObject *_self;
544 PyObject *_args;
545{
546 PyObject *_res = NULL;
547 OSErr _err;
548 SInt16 inItemNo;
549 SInt16 inHoriz;
550 SInt16 inVert;
551 if (!PyArg_ParseTuple(_args, "hhh",
552 &inItemNo,
553 &inHoriz,
554 &inVert))
555 return NULL;
556 _err = MoveDialogItem(_self->ob_itself,
557 inItemNo,
558 inHoriz,
559 inVert);
560 if (_err != noErr) return PyMac_Error(_err);
561 Py_INCREF(Py_None);
562 _res = Py_None;
563 return _res;
564}
565
566static PyObject *DlgObj_SizeDialogItem(_self, _args)
567 DialogObject *_self;
568 PyObject *_args;
569{
570 PyObject *_res = NULL;
571 OSErr _err;
572 SInt16 inItemNo;
Jack Jansen21f96871998-02-20 16:02:09 +0000573 SInt16 inWidth;
Jack Jansen1c4e6141998-04-21 15:23:55 +0000574 SInt16 inHeight;
Jack Jansen21f96871998-02-20 16:02:09 +0000575 if (!PyArg_ParseTuple(_args, "hhh",
576 &inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000577 &inWidth,
578 &inHeight))
Jack Jansen21f96871998-02-20 16:02:09 +0000579 return NULL;
580 _err = SizeDialogItem(_self->ob_itself,
581 inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000582 inWidth,
583 inHeight);
Jack Jansen21f96871998-02-20 16:02:09 +0000584 if (_err != noErr) return PyMac_Error(_err);
585 Py_INCREF(Py_None);
586 _res = Py_None;
587 return _res;
588}
589
Jack Jansena05ac601999-12-12 21:41:51 +0000590static PyObject *DlgObj_AppendDialogItemList(_self, _args)
591 DialogObject *_self;
592 PyObject *_args;
593{
594 PyObject *_res = NULL;
595 OSErr _err;
596 SInt16 ditlID;
597 DITLMethod method;
598 if (!PyArg_ParseTuple(_args, "hh",
599 &ditlID,
600 &method))
601 return NULL;
602 _err = AppendDialogItemList(_self->ob_itself,
603 ditlID,
604 method);
605 if (_err != noErr) return PyMac_Error(_err);
606 Py_INCREF(Py_None);
607 _res = Py_None;
608 return _res;
609}
610
611static PyObject *DlgObj_SetDialogTimeout(_self, _args)
612 DialogObject *_self;
613 PyObject *_args;
614{
615 PyObject *_res = NULL;
616 OSStatus _err;
617 SInt16 inButtonToPress;
618 UInt32 inSecondsToWait;
619 if (!PyArg_ParseTuple(_args, "hl",
620 &inButtonToPress,
621 &inSecondsToWait))
622 return NULL;
623 _err = SetDialogTimeout(_self->ob_itself,
624 inButtonToPress,
625 inSecondsToWait);
626 if (_err != noErr) return PyMac_Error(_err);
627 Py_INCREF(Py_None);
628 _res = Py_None;
629 return _res;
630}
631
632static PyObject *DlgObj_GetDialogTimeout(_self, _args)
633 DialogObject *_self;
634 PyObject *_args;
635{
636 PyObject *_res = NULL;
637 OSStatus _err;
638 SInt16 outButtonToPress;
639 UInt32 outSecondsToWait;
640 UInt32 outSecondsRemaining;
641 if (!PyArg_ParseTuple(_args, ""))
642 return NULL;
643 _err = GetDialogTimeout(_self->ob_itself,
644 &outButtonToPress,
645 &outSecondsToWait,
646 &outSecondsRemaining);
647 if (_err != noErr) return PyMac_Error(_err);
648 _res = Py_BuildValue("hll",
649 outButtonToPress,
650 outSecondsToWait,
651 outSecondsRemaining);
652 return _res;
653}
654
655static PyObject *DlgObj_SetModalDialogEventMask(_self, _args)
656 DialogObject *_self;
657 PyObject *_args;
658{
659 PyObject *_res = NULL;
660 OSStatus _err;
661 EventMask inMask;
662 if (!PyArg_ParseTuple(_args, "h",
663 &inMask))
664 return NULL;
665 _err = SetModalDialogEventMask(_self->ob_itself,
666 inMask);
667 if (_err != noErr) return PyMac_Error(_err);
668 Py_INCREF(Py_None);
669 _res = Py_None;
670 return _res;
671}
672
673static PyObject *DlgObj_GetModalDialogEventMask(_self, _args)
674 DialogObject *_self;
675 PyObject *_args;
676{
677 PyObject *_res = NULL;
678 OSStatus _err;
679 EventMask outMask;
680 if (!PyArg_ParseTuple(_args, ""))
681 return NULL;
682 _err = GetModalDialogEventMask(_self->ob_itself,
683 &outMask);
684 if (_err != noErr) return PyMac_Error(_err);
685 _res = Py_BuildValue("h",
686 outMask);
687 return _res;
688}
689
Jack Jansend96cb501996-09-23 15:48:46 +0000690static PyObject *DlgObj_GetDialogWindow(_self, _args)
691 DialogObject *_self;
692 PyObject *_args;
693{
694 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000695 WindowPtr _rv;
Jack Jansend96cb501996-09-23 15:48:46 +0000696 if (!PyArg_ParseTuple(_args, ""))
697 return NULL;
698 _rv = GetDialogWindow(_self->ob_itself);
699 _res = Py_BuildValue("O&",
Jack Jansene79dc762000-06-02 21:35:07 +0000700 WinObj_New, _rv);
Jack Jansend96cb501996-09-23 15:48:46 +0000701 return _res;
702}
703
704static PyObject *DlgObj_GetDialogDefaultItem(_self, _args)
705 DialogObject *_self;
706 PyObject *_args;
707{
708 PyObject *_res = NULL;
709 SInt16 _rv;
710 if (!PyArg_ParseTuple(_args, ""))
711 return NULL;
712 _rv = GetDialogDefaultItem(_self->ob_itself);
713 _res = Py_BuildValue("h",
714 _rv);
715 return _res;
716}
717
718static PyObject *DlgObj_GetDialogCancelItem(_self, _args)
719 DialogObject *_self;
720 PyObject *_args;
721{
722 PyObject *_res = NULL;
723 SInt16 _rv;
724 if (!PyArg_ParseTuple(_args, ""))
725 return NULL;
726 _rv = GetDialogCancelItem(_self->ob_itself);
727 _res = Py_BuildValue("h",
728 _rv);
729 return _res;
730}
731
732static PyObject *DlgObj_GetDialogKeyboardFocusItem(_self, _args)
733 DialogObject *_self;
734 PyObject *_args;
735{
736 PyObject *_res = NULL;
737 SInt16 _rv;
738 if (!PyArg_ParseTuple(_args, ""))
739 return NULL;
740 _rv = GetDialogKeyboardFocusItem(_self->ob_itself);
741 _res = Py_BuildValue("h",
742 _rv);
743 return _res;
744}
745
Jack Jansene79dc762000-06-02 21:35:07 +0000746#ifndef TARGET_API_MAC_CARBON
747
Jack Jansend96cb501996-09-23 15:48:46 +0000748static PyObject *DlgObj_SetGrafPortOfDialog(_self, _args)
749 DialogObject *_self;
750 PyObject *_args;
751{
752 PyObject *_res = NULL;
753 if (!PyArg_ParseTuple(_args, ""))
754 return NULL;
755 SetGrafPortOfDialog(_self->ob_itself);
756 Py_INCREF(Py_None);
757 _res = Py_None;
758 return _res;
759}
Jack Jansene79dc762000-06-02 21:35:07 +0000760#endif
Jack Jansend96cb501996-09-23 15:48:46 +0000761
Guido van Rossum17448e21995-01-30 11:53:55 +0000762static PyMethodDef DlgObj_methods[] = {
763 {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
764 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000765 {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
Jack Jansen2b724171996-04-10 14:48:19 +0000766 "(RgnHandle updateRgn) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000767 {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000768 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000769 {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000770 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000771 {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000772 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000773 {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000774 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000775 {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000776 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000777 {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000778 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000779 {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000780 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000781 {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1,
782 "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"},
783 {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1,
784 "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"},
785 {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1,
786 "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000787 {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
788 "(Handle theHandle, DITLMethod method) -> None"},
789 {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000790 "() -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000791 {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000792 "(DialogItemIndex numberItems) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000793 {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000794 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000795 {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000796 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000797 {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000798 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000799 {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
800 "(Boolean tracks) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000801 {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1,
802 "() -> None"},
803 {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1,
804 "(SInt16 inItemNo) -> (ControlHandle outControl)"},
805 {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1,
806 "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"},
807 {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000808 "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +0000809 {"AppendDialogItemList", (PyCFunction)DlgObj_AppendDialogItemList, 1,
810 "(SInt16 ditlID, DITLMethod method) -> None"},
811 {"SetDialogTimeout", (PyCFunction)DlgObj_SetDialogTimeout, 1,
812 "(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None"},
813 {"GetDialogTimeout", (PyCFunction)DlgObj_GetDialogTimeout, 1,
814 "() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)"},
815 {"SetModalDialogEventMask", (PyCFunction)DlgObj_SetModalDialogEventMask, 1,
816 "(EventMask inMask) -> None"},
817 {"GetModalDialogEventMask", (PyCFunction)DlgObj_GetModalDialogEventMask, 1,
818 "() -> (EventMask outMask)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000819 {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
Jack Jansene79dc762000-06-02 21:35:07 +0000820 "() -> (WindowPtr _rv)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000821 {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1,
822 "() -> (SInt16 _rv)"},
823 {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1,
824 "() -> (SInt16 _rv)"},
825 {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1,
826 "() -> (SInt16 _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +0000827
828#ifndef TARGET_API_MAC_CARBON
Jack Jansend96cb501996-09-23 15:48:46 +0000829 {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1,
830 "() -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +0000831#endif
Guido van Rossum17448e21995-01-30 11:53:55 +0000832 {NULL, NULL, 0}
833};
834
835PyMethodChain DlgObj_chain = { DlgObj_methods, &WinObj_chain };
836
837static PyObject *DlgObj_getattr(self, name)
838 DialogObject *self;
839 char *name;
840{
841 return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name);
842}
843
844#define DlgObj_setattr NULL
845
Jack Jansena05ac601999-12-12 21:41:51 +0000846#define DlgObj_compare NULL
847
848#define DlgObj_repr NULL
849
850#define DlgObj_hash NULL
851
Guido van Rossum17448e21995-01-30 11:53:55 +0000852PyTypeObject Dialog_Type = {
853 PyObject_HEAD_INIT(&PyType_Type)
854 0, /*ob_size*/
855 "Dialog", /*tp_name*/
856 sizeof(DialogObject), /*tp_basicsize*/
857 0, /*tp_itemsize*/
858 /* methods */
859 (destructor) DlgObj_dealloc, /*tp_dealloc*/
860 0, /*tp_print*/
861 (getattrfunc) DlgObj_getattr, /*tp_getattr*/
862 (setattrfunc) DlgObj_setattr, /*tp_setattr*/
Jack Jansena05ac601999-12-12 21:41:51 +0000863 (cmpfunc) DlgObj_compare, /*tp_compare*/
864 (reprfunc) DlgObj_repr, /*tp_repr*/
865 (PyNumberMethods *)0, /* tp_as_number */
866 (PySequenceMethods *)0, /* tp_as_sequence */
867 (PyMappingMethods *)0, /* tp_as_mapping */
868 (hashfunc) DlgObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +0000869};
870
871/* --------------------- End object type Dialog --------------------- */
872
873
874static PyObject *Dlg_NewDialog(_self, _args)
875 PyObject *_self;
876 PyObject *_args;
877{
878 PyObject *_res = NULL;
879 DialogPtr _rv;
880 Rect boundsRect;
881 Str255 title;
882 Boolean visible;
Jack Jansen21f96871998-02-20 16:02:09 +0000883 SInt16 procID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000884 WindowPtr behind;
885 Boolean goAwayFlag;
Jack Jansen21f96871998-02-20 16:02:09 +0000886 SInt32 refCon;
887 Handle items;
Guido van Rossum17448e21995-01-30 11:53:55 +0000888 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
889 PyMac_GetRect, &boundsRect,
890 PyMac_GetStr255, title,
891 &visible,
892 &procID,
893 WinObj_Convert, &behind,
894 &goAwayFlag,
895 &refCon,
Jack Jansen21f96871998-02-20 16:02:09 +0000896 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +0000897 return NULL;
898 _rv = NewDialog((void *)0,
899 &boundsRect,
900 title,
901 visible,
902 procID,
903 behind,
904 goAwayFlag,
905 refCon,
Jack Jansen21f96871998-02-20 16:02:09 +0000906 items);
Guido van Rossum17448e21995-01-30 11:53:55 +0000907 _res = Py_BuildValue("O&",
908 DlgObj_New, _rv);
909 return _res;
910}
911
912static PyObject *Dlg_GetNewDialog(_self, _args)
913 PyObject *_self;
914 PyObject *_args;
915{
916 PyObject *_res = NULL;
917 DialogPtr _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000918 SInt16 dialogID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000919 WindowPtr behind;
920 if (!PyArg_ParseTuple(_args, "hO&",
921 &dialogID,
922 WinObj_Convert, &behind))
923 return NULL;
924 _rv = GetNewDialog(dialogID,
925 (void *)0,
926 behind);
927 _res = Py_BuildValue("O&",
928 DlgObj_New, _rv);
929 return _res;
930}
931
Jack Jansen21f96871998-02-20 16:02:09 +0000932static PyObject *Dlg_NewColorDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000933 PyObject *_self;
934 PyObject *_args;
935{
936 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000937 DialogPtr _rv;
938 Rect boundsRect;
939 Str255 title;
940 Boolean visible;
941 SInt16 procID;
942 WindowPtr behind;
943 Boolean goAwayFlag;
944 SInt32 refCon;
945 Handle items;
946 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
947 PyMac_GetRect, &boundsRect,
948 PyMac_GetStr255, title,
949 &visible,
950 &procID,
951 WinObj_Convert, &behind,
952 &goAwayFlag,
953 &refCon,
954 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +0000955 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000956 _rv = NewColorDialog((void *)0,
957 &boundsRect,
958 title,
959 visible,
960 procID,
961 behind,
962 goAwayFlag,
963 refCon,
964 items);
965 _res = Py_BuildValue("O&",
966 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +0000967 return _res;
968}
969
970static PyObject *Dlg_ModalDialog(_self, _args)
971 PyObject *_self;
972 PyObject *_args;
973{
974 PyObject *_res = NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000975 PyObject* modalFilter;
Jack Jansen21f96871998-02-20 16:02:09 +0000976 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +0000977 if (!PyArg_ParseTuple(_args, "O",
Jack Jansenae8a68f1995-06-06 12:55:40 +0000978 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +0000979 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000980 ModalDialog(NewModalFilterProc(Dlg_PassFilterProc(modalFilter)),
Guido van Rossum17448e21995-01-30 11:53:55 +0000981 &itemHit);
982 _res = Py_BuildValue("h",
983 itemHit);
984 return _res;
985}
986
987static PyObject *Dlg_IsDialogEvent(_self, _args)
988 PyObject *_self;
989 PyObject *_args;
990{
991 PyObject *_res = NULL;
992 Boolean _rv;
993 EventRecord theEvent;
994 if (!PyArg_ParseTuple(_args, "O&",
995 PyMac_GetEventRecord, &theEvent))
996 return NULL;
997 _rv = IsDialogEvent(&theEvent);
998 _res = Py_BuildValue("b",
999 _rv);
1000 return _res;
1001}
1002
1003static PyObject *Dlg_DialogSelect(_self, _args)
1004 PyObject *_self;
1005 PyObject *_args;
1006{
1007 PyObject *_res = NULL;
1008 Boolean _rv;
1009 EventRecord theEvent;
1010 DialogPtr theDialog;
Jack Jansen21f96871998-02-20 16:02:09 +00001011 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +00001012 if (!PyArg_ParseTuple(_args, "O&",
1013 PyMac_GetEventRecord, &theEvent))
1014 return NULL;
1015 _rv = DialogSelect(&theEvent,
1016 &theDialog,
1017 &itemHit);
1018 _res = Py_BuildValue("bO&h",
1019 _rv,
1020 WinObj_WhichWindow, theDialog,
1021 itemHit);
1022 return _res;
1023}
1024
1025static PyObject *Dlg_Alert(_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 = Alert(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_StopAlert(_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 = StopAlert(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
1063static PyObject *Dlg_NoteAlert(_self, _args)
1064 PyObject *_self;
1065 PyObject *_args;
1066{
1067 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001068 DialogItemIndex _rv;
1069 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001070 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001071 if (!PyArg_ParseTuple(_args, "hO",
1072 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001073 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001074 return NULL;
1075 _rv = NoteAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001076 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001077 _res = Py_BuildValue("h",
1078 _rv);
1079 return _res;
1080}
1081
1082static PyObject *Dlg_CautionAlert(_self, _args)
1083 PyObject *_self;
1084 PyObject *_args;
1085{
1086 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001087 DialogItemIndex _rv;
1088 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001089 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001090 if (!PyArg_ParseTuple(_args, "hO",
1091 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001092 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001093 return NULL;
1094 _rv = CautionAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001095 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001096 _res = Py_BuildValue("h",
1097 _rv);
1098 return _res;
1099}
1100
Jack Jansen21f96871998-02-20 16:02:09 +00001101static PyObject *Dlg_ParamText(_self, _args)
1102 PyObject *_self;
1103 PyObject *_args;
1104{
1105 PyObject *_res = NULL;
1106 Str255 param0;
1107 Str255 param1;
1108 Str255 param2;
1109 Str255 param3;
1110 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1111 PyMac_GetStr255, param0,
1112 PyMac_GetStr255, param1,
1113 PyMac_GetStr255, param2,
1114 PyMac_GetStr255, param3))
1115 return NULL;
1116 ParamText(param0,
1117 param1,
1118 param2,
1119 param3);
1120 Py_INCREF(Py_None);
1121 _res = Py_None;
1122 return _res;
1123}
1124
Jack Jansenae8a68f1995-06-06 12:55:40 +00001125static PyObject *Dlg_GetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001126 PyObject *_self;
1127 PyObject *_args;
1128{
1129 PyObject *_res = NULL;
1130 Handle item;
1131 Str255 text;
1132 if (!PyArg_ParseTuple(_args, "O&",
1133 ResObj_Convert, &item))
1134 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001135 GetDialogItemText(item,
1136 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001137 _res = Py_BuildValue("O&",
1138 PyMac_BuildStr255, text);
1139 return _res;
1140}
1141
Jack Jansenae8a68f1995-06-06 12:55:40 +00001142static PyObject *Dlg_SetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001143 PyObject *_self;
1144 PyObject *_args;
1145{
1146 PyObject *_res = NULL;
1147 Handle item;
1148 Str255 text;
1149 if (!PyArg_ParseTuple(_args, "O&O&",
1150 ResObj_Convert, &item,
1151 PyMac_GetStr255, text))
1152 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001153 SetDialogItemText(item,
1154 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001155 Py_INCREF(Py_None);
1156 _res = Py_None;
1157 return _res;
1158}
1159
Jack Jansenae8a68f1995-06-06 12:55:40 +00001160static PyObject *Dlg_GetAlertStage(_self, _args)
1161 PyObject *_self;
1162 PyObject *_args;
1163{
1164 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001165 SInt16 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001166 if (!PyArg_ParseTuple(_args, ""))
1167 return NULL;
1168 _rv = GetAlertStage();
1169 _res = Py_BuildValue("h",
1170 _rv);
1171 return _res;
1172}
1173
Jack Jansen21f96871998-02-20 16:02:09 +00001174static PyObject *Dlg_SetDialogFont(_self, _args)
1175 PyObject *_self;
1176 PyObject *_args;
1177{
1178 PyObject *_res = NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001179 SInt16 fontNum;
Jack Jansen21f96871998-02-20 16:02:09 +00001180 if (!PyArg_ParseTuple(_args, "h",
Jack Jansena05ac601999-12-12 21:41:51 +00001181 &fontNum))
Jack Jansen21f96871998-02-20 16:02:09 +00001182 return NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001183 SetDialogFont(fontNum);
Jack Jansen21f96871998-02-20 16:02:09 +00001184 Py_INCREF(Py_None);
1185 _res = Py_None;
1186 return _res;
1187}
1188
Jack Jansenae8a68f1995-06-06 12:55:40 +00001189static PyObject *Dlg_ResetAlertStage(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001190 PyObject *_self;
1191 PyObject *_args;
1192{
1193 PyObject *_res = NULL;
1194 if (!PyArg_ParseTuple(_args, ""))
1195 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001196 ResetAlertStage();
Guido van Rossum17448e21995-01-30 11:53:55 +00001197 Py_INCREF(Py_None);
1198 _res = Py_None;
1199 return _res;
1200}
1201
Jack Jansen21f96871998-02-20 16:02:09 +00001202static PyObject *Dlg_NewFeaturesDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001203 PyObject *_self;
1204 PyObject *_args;
1205{
1206 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001207 DialogPtr _rv;
1208 Rect inBoundsRect;
1209 Str255 inTitle;
1210 Boolean inIsVisible;
1211 SInt16 inProcID;
1212 WindowPtr inBehind;
1213 Boolean inGoAwayFlag;
1214 SInt32 inRefCon;
1215 Handle inItemListHandle;
1216 UInt32 inFlags;
1217 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
1218 PyMac_GetRect, &inBoundsRect,
1219 PyMac_GetStr255, inTitle,
1220 &inIsVisible,
1221 &inProcID,
1222 WinObj_Convert, &inBehind,
1223 &inGoAwayFlag,
1224 &inRefCon,
1225 ResObj_Convert, &inItemListHandle,
1226 &inFlags))
Guido van Rossum17448e21995-01-30 11:53:55 +00001227 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001228 _rv = NewFeaturesDialog((void *)0,
1229 &inBoundsRect,
1230 inTitle,
1231 inIsVisible,
1232 inProcID,
1233 inBehind,
1234 inGoAwayFlag,
1235 inRefCon,
1236 inItemListHandle,
1237 inFlags);
1238 _res = Py_BuildValue("O&",
1239 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +00001240 return _res;
1241}
1242
Jack Jansendf901df1998-07-10 15:47:48 +00001243static PyObject *Dlg_SetUserItemHandler(_self, _args)
1244 PyObject *_self;
1245 PyObject *_args;
1246{
1247 PyObject *_res = NULL;
1248
1249 PyObject *new = NULL;
1250
1251
1252 if (!PyArg_ParseTuple(_args, "|O", &new))
1253 return NULL;
1254
1255 if (Dlg_UserItemProc_callback && new && new != Py_None) {
1256 PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
1257 return NULL;
1258 }
1259
1260 if (new == Py_None) {
1261 new = NULL;
1262 _res = Py_None;
1263 Py_INCREF(Py_None);
1264 } else {
1265 Py_INCREF(new);
1266 _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc));
1267 }
1268
1269 Dlg_UserItemProc_callback = new;
1270 return _res;
1271
1272}
1273
Guido van Rossum17448e21995-01-30 11:53:55 +00001274static PyMethodDef Dlg_methods[] = {
1275 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001276 "(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 +00001277 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001278 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1279 {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
1280 "(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 +00001281 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001282 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001283 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
1284 "(EventRecord theEvent) -> (Boolean _rv)"},
1285 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001286 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001287 {"Alert", (PyCFunction)Dlg_Alert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001288 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001289 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001290 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001291 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001292 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001293 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001294 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1295 {"ParamText", (PyCFunction)Dlg_ParamText, 1,
1296 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001297 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001298 "(Handle item) -> (Str255 text)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001299 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001300 "(Handle item, Str255 text) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001301 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001302 "() -> (SInt16 _rv)"},
1303 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
Jack Jansena05ac601999-12-12 21:41:51 +00001304 "(SInt16 fontNum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001305 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001306 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001307 {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
1308 "(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 +00001309 {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
1310 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001311 {NULL, NULL, 0}
1312};
1313
1314
1315
1316
1317void initDlg()
1318{
1319 PyObject *m;
1320 PyObject *d;
1321
1322
1323
1324
1325 m = Py_InitModule("Dlg", Dlg_methods);
1326 d = PyModule_GetDict(m);
1327 Dlg_Error = PyMac_GetOSErrException();
1328 if (Dlg_Error == NULL ||
1329 PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
1330 Py_FatalError("can't initialize Dlg.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001331 Dialog_Type.ob_type = &PyType_Type;
1332 Py_INCREF(&Dialog_Type);
1333 if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0)
1334 Py_FatalError("can't initialize DialogType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001335}
1336
1337/* ========================= End module Dlg ========================= */
1338