blob: fbbadd84759da55e2a3ad27b385d323a9e56a4fb [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;
157 SetWRefCon(itself, (long)it);
158 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;
695 DialogPtr _rv;
696 if (!PyArg_ParseTuple(_args, ""))
697 return NULL;
698 _rv = GetDialogWindow(_self->ob_itself);
699 _res = Py_BuildValue("O&",
700 WinObj_WhichWindow, _rv);
701 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
746static PyObject *DlgObj_SetGrafPortOfDialog(_self, _args)
747 DialogObject *_self;
748 PyObject *_args;
749{
750 PyObject *_res = NULL;
751 if (!PyArg_ParseTuple(_args, ""))
752 return NULL;
753 SetGrafPortOfDialog(_self->ob_itself);
754 Py_INCREF(Py_None);
755 _res = Py_None;
756 return _res;
757}
758
Guido van Rossum17448e21995-01-30 11:53:55 +0000759static PyMethodDef DlgObj_methods[] = {
760 {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
761 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000762 {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
Jack Jansen2b724171996-04-10 14:48:19 +0000763 "(RgnHandle updateRgn) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000764 {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000765 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000766 {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000767 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000768 {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000769 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000770 {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000771 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000772 {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000773 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000774 {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000775 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000776 {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000777 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000778 {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1,
779 "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"},
780 {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1,
781 "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"},
782 {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1,
783 "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000784 {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
785 "(Handle theHandle, DITLMethod method) -> None"},
786 {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000787 "() -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000788 {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000789 "(DialogItemIndex numberItems) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000790 {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000791 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000792 {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000793 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000794 {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000795 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000796 {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
797 "(Boolean tracks) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000798 {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1,
799 "() -> None"},
800 {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1,
801 "(SInt16 inItemNo) -> (ControlHandle outControl)"},
802 {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1,
803 "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"},
804 {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000805 "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +0000806 {"AppendDialogItemList", (PyCFunction)DlgObj_AppendDialogItemList, 1,
807 "(SInt16 ditlID, DITLMethod method) -> None"},
808 {"SetDialogTimeout", (PyCFunction)DlgObj_SetDialogTimeout, 1,
809 "(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None"},
810 {"GetDialogTimeout", (PyCFunction)DlgObj_GetDialogTimeout, 1,
811 "() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)"},
812 {"SetModalDialogEventMask", (PyCFunction)DlgObj_SetModalDialogEventMask, 1,
813 "(EventMask inMask) -> None"},
814 {"GetModalDialogEventMask", (PyCFunction)DlgObj_GetModalDialogEventMask, 1,
815 "() -> (EventMask outMask)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000816 {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
817 "() -> (DialogPtr _rv)"},
818 {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1,
819 "() -> (SInt16 _rv)"},
820 {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1,
821 "() -> (SInt16 _rv)"},
822 {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1,
823 "() -> (SInt16 _rv)"},
824 {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1,
825 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000826 {NULL, NULL, 0}
827};
828
829PyMethodChain DlgObj_chain = { DlgObj_methods, &WinObj_chain };
830
831static PyObject *DlgObj_getattr(self, name)
832 DialogObject *self;
833 char *name;
834{
835 return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name);
836}
837
838#define DlgObj_setattr NULL
839
Jack Jansena05ac601999-12-12 21:41:51 +0000840#define DlgObj_compare NULL
841
842#define DlgObj_repr NULL
843
844#define DlgObj_hash NULL
845
Guido van Rossum17448e21995-01-30 11:53:55 +0000846PyTypeObject Dialog_Type = {
847 PyObject_HEAD_INIT(&PyType_Type)
848 0, /*ob_size*/
849 "Dialog", /*tp_name*/
850 sizeof(DialogObject), /*tp_basicsize*/
851 0, /*tp_itemsize*/
852 /* methods */
853 (destructor) DlgObj_dealloc, /*tp_dealloc*/
854 0, /*tp_print*/
855 (getattrfunc) DlgObj_getattr, /*tp_getattr*/
856 (setattrfunc) DlgObj_setattr, /*tp_setattr*/
Jack Jansena05ac601999-12-12 21:41:51 +0000857 (cmpfunc) DlgObj_compare, /*tp_compare*/
858 (reprfunc) DlgObj_repr, /*tp_repr*/
859 (PyNumberMethods *)0, /* tp_as_number */
860 (PySequenceMethods *)0, /* tp_as_sequence */
861 (PyMappingMethods *)0, /* tp_as_mapping */
862 (hashfunc) DlgObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +0000863};
864
865/* --------------------- End object type Dialog --------------------- */
866
867
868static PyObject *Dlg_NewDialog(_self, _args)
869 PyObject *_self;
870 PyObject *_args;
871{
872 PyObject *_res = NULL;
873 DialogPtr _rv;
874 Rect boundsRect;
875 Str255 title;
876 Boolean visible;
Jack Jansen21f96871998-02-20 16:02:09 +0000877 SInt16 procID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000878 WindowPtr behind;
879 Boolean goAwayFlag;
Jack Jansen21f96871998-02-20 16:02:09 +0000880 SInt32 refCon;
881 Handle items;
Guido van Rossum17448e21995-01-30 11:53:55 +0000882 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
883 PyMac_GetRect, &boundsRect,
884 PyMac_GetStr255, title,
885 &visible,
886 &procID,
887 WinObj_Convert, &behind,
888 &goAwayFlag,
889 &refCon,
Jack Jansen21f96871998-02-20 16:02:09 +0000890 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +0000891 return NULL;
892 _rv = NewDialog((void *)0,
893 &boundsRect,
894 title,
895 visible,
896 procID,
897 behind,
898 goAwayFlag,
899 refCon,
Jack Jansen21f96871998-02-20 16:02:09 +0000900 items);
Guido van Rossum17448e21995-01-30 11:53:55 +0000901 _res = Py_BuildValue("O&",
902 DlgObj_New, _rv);
903 return _res;
904}
905
906static PyObject *Dlg_GetNewDialog(_self, _args)
907 PyObject *_self;
908 PyObject *_args;
909{
910 PyObject *_res = NULL;
911 DialogPtr _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000912 SInt16 dialogID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000913 WindowPtr behind;
914 if (!PyArg_ParseTuple(_args, "hO&",
915 &dialogID,
916 WinObj_Convert, &behind))
917 return NULL;
918 _rv = GetNewDialog(dialogID,
919 (void *)0,
920 behind);
921 _res = Py_BuildValue("O&",
922 DlgObj_New, _rv);
923 return _res;
924}
925
Jack Jansen21f96871998-02-20 16:02:09 +0000926static PyObject *Dlg_NewColorDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000927 PyObject *_self;
928 PyObject *_args;
929{
930 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000931 DialogPtr _rv;
932 Rect boundsRect;
933 Str255 title;
934 Boolean visible;
935 SInt16 procID;
936 WindowPtr behind;
937 Boolean goAwayFlag;
938 SInt32 refCon;
939 Handle items;
940 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
941 PyMac_GetRect, &boundsRect,
942 PyMac_GetStr255, title,
943 &visible,
944 &procID,
945 WinObj_Convert, &behind,
946 &goAwayFlag,
947 &refCon,
948 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +0000949 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000950 _rv = NewColorDialog((void *)0,
951 &boundsRect,
952 title,
953 visible,
954 procID,
955 behind,
956 goAwayFlag,
957 refCon,
958 items);
959 _res = Py_BuildValue("O&",
960 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +0000961 return _res;
962}
963
964static PyObject *Dlg_ModalDialog(_self, _args)
965 PyObject *_self;
966 PyObject *_args;
967{
968 PyObject *_res = NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000969 PyObject* modalFilter;
Jack Jansen21f96871998-02-20 16:02:09 +0000970 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +0000971 if (!PyArg_ParseTuple(_args, "O",
Jack Jansenae8a68f1995-06-06 12:55:40 +0000972 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +0000973 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000974 ModalDialog(NewModalFilterProc(Dlg_PassFilterProc(modalFilter)),
Guido van Rossum17448e21995-01-30 11:53:55 +0000975 &itemHit);
976 _res = Py_BuildValue("h",
977 itemHit);
978 return _res;
979}
980
981static PyObject *Dlg_IsDialogEvent(_self, _args)
982 PyObject *_self;
983 PyObject *_args;
984{
985 PyObject *_res = NULL;
986 Boolean _rv;
987 EventRecord theEvent;
988 if (!PyArg_ParseTuple(_args, "O&",
989 PyMac_GetEventRecord, &theEvent))
990 return NULL;
991 _rv = IsDialogEvent(&theEvent);
992 _res = Py_BuildValue("b",
993 _rv);
994 return _res;
995}
996
997static PyObject *Dlg_DialogSelect(_self, _args)
998 PyObject *_self;
999 PyObject *_args;
1000{
1001 PyObject *_res = NULL;
1002 Boolean _rv;
1003 EventRecord theEvent;
1004 DialogPtr theDialog;
Jack Jansen21f96871998-02-20 16:02:09 +00001005 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +00001006 if (!PyArg_ParseTuple(_args, "O&",
1007 PyMac_GetEventRecord, &theEvent))
1008 return NULL;
1009 _rv = DialogSelect(&theEvent,
1010 &theDialog,
1011 &itemHit);
1012 _res = Py_BuildValue("bO&h",
1013 _rv,
1014 WinObj_WhichWindow, theDialog,
1015 itemHit);
1016 return _res;
1017}
1018
1019static PyObject *Dlg_Alert(_self, _args)
1020 PyObject *_self;
1021 PyObject *_args;
1022{
1023 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001024 DialogItemIndex _rv;
1025 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001026 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001027 if (!PyArg_ParseTuple(_args, "hO",
1028 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001029 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001030 return NULL;
1031 _rv = Alert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001032 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001033 _res = Py_BuildValue("h",
1034 _rv);
1035 return _res;
1036}
1037
1038static PyObject *Dlg_StopAlert(_self, _args)
1039 PyObject *_self;
1040 PyObject *_args;
1041{
1042 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001043 DialogItemIndex _rv;
1044 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001045 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001046 if (!PyArg_ParseTuple(_args, "hO",
1047 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001048 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001049 return NULL;
1050 _rv = StopAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001051 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001052 _res = Py_BuildValue("h",
1053 _rv);
1054 return _res;
1055}
1056
1057static PyObject *Dlg_NoteAlert(_self, _args)
1058 PyObject *_self;
1059 PyObject *_args;
1060{
1061 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001062 DialogItemIndex _rv;
1063 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001064 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001065 if (!PyArg_ParseTuple(_args, "hO",
1066 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001067 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001068 return NULL;
1069 _rv = NoteAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001070 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001071 _res = Py_BuildValue("h",
1072 _rv);
1073 return _res;
1074}
1075
1076static PyObject *Dlg_CautionAlert(_self, _args)
1077 PyObject *_self;
1078 PyObject *_args;
1079{
1080 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001081 DialogItemIndex _rv;
1082 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001083 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001084 if (!PyArg_ParseTuple(_args, "hO",
1085 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001086 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001087 return NULL;
1088 _rv = CautionAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001089 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001090 _res = Py_BuildValue("h",
1091 _rv);
1092 return _res;
1093}
1094
Jack Jansen21f96871998-02-20 16:02:09 +00001095static PyObject *Dlg_ParamText(_self, _args)
1096 PyObject *_self;
1097 PyObject *_args;
1098{
1099 PyObject *_res = NULL;
1100 Str255 param0;
1101 Str255 param1;
1102 Str255 param2;
1103 Str255 param3;
1104 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1105 PyMac_GetStr255, param0,
1106 PyMac_GetStr255, param1,
1107 PyMac_GetStr255, param2,
1108 PyMac_GetStr255, param3))
1109 return NULL;
1110 ParamText(param0,
1111 param1,
1112 param2,
1113 param3);
1114 Py_INCREF(Py_None);
1115 _res = Py_None;
1116 return _res;
1117}
1118
Jack Jansenae8a68f1995-06-06 12:55:40 +00001119static PyObject *Dlg_GetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001120 PyObject *_self;
1121 PyObject *_args;
1122{
1123 PyObject *_res = NULL;
1124 Handle item;
1125 Str255 text;
1126 if (!PyArg_ParseTuple(_args, "O&",
1127 ResObj_Convert, &item))
1128 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001129 GetDialogItemText(item,
1130 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001131 _res = Py_BuildValue("O&",
1132 PyMac_BuildStr255, text);
1133 return _res;
1134}
1135
Jack Jansenae8a68f1995-06-06 12:55:40 +00001136static PyObject *Dlg_SetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001137 PyObject *_self;
1138 PyObject *_args;
1139{
1140 PyObject *_res = NULL;
1141 Handle item;
1142 Str255 text;
1143 if (!PyArg_ParseTuple(_args, "O&O&",
1144 ResObj_Convert, &item,
1145 PyMac_GetStr255, text))
1146 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001147 SetDialogItemText(item,
1148 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001149 Py_INCREF(Py_None);
1150 _res = Py_None;
1151 return _res;
1152}
1153
Jack Jansenae8a68f1995-06-06 12:55:40 +00001154static PyObject *Dlg_GetAlertStage(_self, _args)
1155 PyObject *_self;
1156 PyObject *_args;
1157{
1158 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001159 SInt16 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001160 if (!PyArg_ParseTuple(_args, ""))
1161 return NULL;
1162 _rv = GetAlertStage();
1163 _res = Py_BuildValue("h",
1164 _rv);
1165 return _res;
1166}
1167
Jack Jansen21f96871998-02-20 16:02:09 +00001168static PyObject *Dlg_SetDialogFont(_self, _args)
1169 PyObject *_self;
1170 PyObject *_args;
1171{
1172 PyObject *_res = NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001173 SInt16 fontNum;
Jack Jansen21f96871998-02-20 16:02:09 +00001174 if (!PyArg_ParseTuple(_args, "h",
Jack Jansena05ac601999-12-12 21:41:51 +00001175 &fontNum))
Jack Jansen21f96871998-02-20 16:02:09 +00001176 return NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001177 SetDialogFont(fontNum);
Jack Jansen21f96871998-02-20 16:02:09 +00001178 Py_INCREF(Py_None);
1179 _res = Py_None;
1180 return _res;
1181}
1182
Jack Jansenae8a68f1995-06-06 12:55:40 +00001183static PyObject *Dlg_ResetAlertStage(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001184 PyObject *_self;
1185 PyObject *_args;
1186{
1187 PyObject *_res = NULL;
1188 if (!PyArg_ParseTuple(_args, ""))
1189 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001190 ResetAlertStage();
Guido van Rossum17448e21995-01-30 11:53:55 +00001191 Py_INCREF(Py_None);
1192 _res = Py_None;
1193 return _res;
1194}
1195
Jack Jansen21f96871998-02-20 16:02:09 +00001196static PyObject *Dlg_NewFeaturesDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001197 PyObject *_self;
1198 PyObject *_args;
1199{
1200 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001201 DialogPtr _rv;
1202 Rect inBoundsRect;
1203 Str255 inTitle;
1204 Boolean inIsVisible;
1205 SInt16 inProcID;
1206 WindowPtr inBehind;
1207 Boolean inGoAwayFlag;
1208 SInt32 inRefCon;
1209 Handle inItemListHandle;
1210 UInt32 inFlags;
1211 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
1212 PyMac_GetRect, &inBoundsRect,
1213 PyMac_GetStr255, inTitle,
1214 &inIsVisible,
1215 &inProcID,
1216 WinObj_Convert, &inBehind,
1217 &inGoAwayFlag,
1218 &inRefCon,
1219 ResObj_Convert, &inItemListHandle,
1220 &inFlags))
Guido van Rossum17448e21995-01-30 11:53:55 +00001221 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001222 _rv = NewFeaturesDialog((void *)0,
1223 &inBoundsRect,
1224 inTitle,
1225 inIsVisible,
1226 inProcID,
1227 inBehind,
1228 inGoAwayFlag,
1229 inRefCon,
1230 inItemListHandle,
1231 inFlags);
1232 _res = Py_BuildValue("O&",
1233 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +00001234 return _res;
1235}
1236
Jack Jansendf901df1998-07-10 15:47:48 +00001237static PyObject *Dlg_SetUserItemHandler(_self, _args)
1238 PyObject *_self;
1239 PyObject *_args;
1240{
1241 PyObject *_res = NULL;
1242
1243 PyObject *new = NULL;
1244
1245
1246 if (!PyArg_ParseTuple(_args, "|O", &new))
1247 return NULL;
1248
1249 if (Dlg_UserItemProc_callback && new && new != Py_None) {
1250 PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
1251 return NULL;
1252 }
1253
1254 if (new == Py_None) {
1255 new = NULL;
1256 _res = Py_None;
1257 Py_INCREF(Py_None);
1258 } else {
1259 Py_INCREF(new);
1260 _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc));
1261 }
1262
1263 Dlg_UserItemProc_callback = new;
1264 return _res;
1265
1266}
1267
Guido van Rossum17448e21995-01-30 11:53:55 +00001268static PyMethodDef Dlg_methods[] = {
1269 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001270 "(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 +00001271 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001272 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1273 {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
1274 "(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 +00001275 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001276 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001277 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
1278 "(EventRecord theEvent) -> (Boolean _rv)"},
1279 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001280 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001281 {"Alert", (PyCFunction)Dlg_Alert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001282 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001283 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001284 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001285 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001286 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001287 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001288 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1289 {"ParamText", (PyCFunction)Dlg_ParamText, 1,
1290 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001291 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001292 "(Handle item) -> (Str255 text)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001293 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001294 "(Handle item, Str255 text) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001295 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001296 "() -> (SInt16 _rv)"},
1297 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
Jack Jansena05ac601999-12-12 21:41:51 +00001298 "(SInt16 fontNum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001299 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001300 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001301 {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
1302 "(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 +00001303 {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
1304 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001305 {NULL, NULL, 0}
1306};
1307
1308
1309
1310
1311void initDlg()
1312{
1313 PyObject *m;
1314 PyObject *d;
1315
1316
1317
1318
1319 m = Py_InitModule("Dlg", Dlg_methods);
1320 d = PyModule_GetDict(m);
1321 Dlg_Error = PyMac_GetOSErrException();
1322 if (Dlg_Error == NULL ||
1323 PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
1324 Py_FatalError("can't initialize Dlg.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001325 Dialog_Type.ob_type = &PyType_Type;
1326 Py_INCREF(&Dialog_Type);
1327 if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0)
1328 Py_FatalError("can't initialize DialogType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001329}
1330
1331/* ========================= End module Dlg ========================= */
1332