blob: 3ab14a0c965a6b1ff70a5b0ff79744f3c983850e [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
Jack Jansenf7d5aa62000-12-10 23:43:49 +000013#if !ACCESSOR_CALLS_ARE_FUNCTIONS
14#define GetDialogTextEditHandle(dlg) (((DialogPeek)(dlg))->textH)
15#define SetPortDialogPort(dlg) SetPort(dlg)
16#define GetDialogPort(dlg) ((CGrafPtr)(dlg))
17#define GetDialogFromWindow(win) ((DialogRef)(win))
18#endif
19
Guido van Rossum17448e21995-01-30 11:53:55 +000020/* XXX Shouldn't this be a stack? */
21static PyObject *Dlg_FilterProc_callback = NULL;
22
Guido van Rossum17448e21995-01-30 11:53:55 +000023static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog,
24 EventRecord *event,
25 short *itemHit)
26{
27 Boolean rv;
28 PyObject *args, *res;
29 PyObject *callback = Dlg_FilterProc_callback;
30 if (callback == NULL)
31 return 0; /* Default behavior */
32 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
Guido van Rossum0437e891995-02-21 20:56:21 +000033 args = Py_BuildValue("O&O&", WinObj_WhichWindow, dialog, PyMac_BuildEventRecord, event);
Guido van Rossum17448e21995-01-30 11:53:55 +000034 if (args == NULL)
35 res = NULL;
36 else {
37 res = PyEval_CallObject(callback, args);
38 Py_DECREF(args);
39 }
40 if (res == NULL) {
Jack Jansendeff89c1998-10-12 20:53:15 +000041 PySys_WriteStderr("Exception in Dialog Filter\n");
Guido van Rossum17448e21995-01-30 11:53:55 +000042 PyErr_Print();
43 *itemHit = -1; /* Fake return item */
44 return 1; /* We handled it */
45 }
46 else {
47 Dlg_FilterProc_callback = callback;
48 if (PyInt_Check(res)) {
49 *itemHit = PyInt_AsLong(res);
50 rv = 1;
51 }
52 else
53 rv = PyObject_IsTrue(res);
54 }
55 Py_DECREF(res);
56 return rv;
57}
58
59static ModalFilterProcPtr
60Dlg_PassFilterProc(PyObject *callback)
61{
62 PyObject *tmp = Dlg_FilterProc_callback;
63 Dlg_FilterProc_callback = NULL;
64 if (callback == Py_None) {
65 Py_XDECREF(tmp);
66 return NULL;
67 }
68 Py_INCREF(callback);
69 Dlg_FilterProc_callback = callback;
70 Py_XDECREF(tmp);
71 return &Dlg_UnivFilterProc;
72}
73
Jack Jansendf901df1998-07-10 15:47:48 +000074static PyObject *Dlg_UserItemProc_callback = NULL;
75
76static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
77 short item)
78{
79 PyObject *args, *res;
80
81 if (Dlg_UserItemProc_callback == NULL)
82 return; /* Default behavior */
83 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
84 args = Py_BuildValue("O&h", WinObj_WhichWindow, dialog, item);
85 if (args == NULL)
86 res = NULL;
87 else {
88 res = PyEval_CallObject(Dlg_UserItemProc_callback, args);
89 Py_DECREF(args);
90 }
91 if (res == NULL) {
Jack Jansendeff89c1998-10-12 20:53:15 +000092 PySys_WriteStderr("Exception in Dialog UserItem proc\n");
Jack Jansendf901df1998-07-10 15:47:48 +000093 PyErr_Print();
94 }
95 Py_XDECREF(res);
96 return;
97}
98
Jack Jansenb8c4c7b2000-08-25 22:25:54 +000099#if 1
100/*
101** Treating DialogObjects as WindowObjects is (I think) illegal under Carbon.
102** However, as they are still identical under MacOS9 Carbon this is a problem, even
103** if we neatly call GetDialogWindow() at the right places: there's one refcon field
104** and it points to the DialogObject, so WinObj_WhichWindow will smartly return the
105** dialog object, and therefore we still don't have a WindowObject.
106** I'll leave the chaining code in place for now, with this comment to warn the
107** unsuspecting victims (i.e. me, probably, in a few weeks:-)
108*/
Guido van Rossum17448e21995-01-30 11:53:55 +0000109extern PyMethodChain WinObj_chain;
Jack Jansenb8c4c7b2000-08-25 22:25:54 +0000110#endif
Guido van Rossum17448e21995-01-30 11:53:55 +0000111
112static PyObject *Dlg_Error;
113
114/* ----------------------- Object type Dialog ----------------------- */
115
116PyTypeObject Dialog_Type;
117
118#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
119
120typedef struct DialogObject {
121 PyObject_HEAD
122 DialogPtr ob_itself;
123} DialogObject;
124
125PyObject *DlgObj_New(itself)
Guido van Rossum97842951995-02-19 15:59:49 +0000126 DialogPtr itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000127{
128 DialogObject *it;
129 if (itself == NULL) return Py_None;
130 it = PyObject_NEW(DialogObject, &Dialog_Type);
131 if (it == NULL) return NULL;
132 it->ob_itself = itself;
Jack Jansene79dc762000-06-02 21:35:07 +0000133 SetWRefCon(GetDialogWindow(itself), (long)it);
Guido van Rossum17448e21995-01-30 11:53:55 +0000134 return (PyObject *)it;
135}
136DlgObj_Convert(v, p_itself)
137 PyObject *v;
138 DialogPtr *p_itself;
139{
140 if (v == Py_None) { *p_itself = NULL; return 1; }
141 if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
142 return 1; }
143 if (!DlgObj_Check(v))
144 {
145 PyErr_SetString(PyExc_TypeError, "Dialog required");
146 return 0;
147 }
148 *p_itself = ((DialogObject *)v)->ob_itself;
149 return 1;
150}
151
152static void DlgObj_dealloc(self)
153 DialogObject *self;
154{
155 DisposeDialog(self->ob_itself);
156 PyMem_DEL(self);
157}
158
159static PyObject *DlgObj_DrawDialog(_self, _args)
160 DialogObject *_self;
161 PyObject *_args;
162{
163 PyObject *_res = NULL;
164 if (!PyArg_ParseTuple(_args, ""))
165 return NULL;
166 DrawDialog(_self->ob_itself);
167 Py_INCREF(Py_None);
168 _res = Py_None;
169 return _res;
170}
171
Guido van Rossum17448e21995-01-30 11:53:55 +0000172static PyObject *DlgObj_UpdateDialog(_self, _args)
173 DialogObject *_self;
174 PyObject *_args;
175{
176 PyObject *_res = NULL;
Jack Jansen2b724171996-04-10 14:48:19 +0000177 RgnHandle updateRgn;
178 if (!PyArg_ParseTuple(_args, "O&",
179 ResObj_Convert, &updateRgn))
Guido van Rossum17448e21995-01-30 11:53:55 +0000180 return NULL;
181 UpdateDialog(_self->ob_itself,
Jack Jansen2b724171996-04-10 14:48:19 +0000182 updateRgn);
Guido van Rossum17448e21995-01-30 11:53:55 +0000183 Py_INCREF(Py_None);
184 _res = Py_None;
185 return _res;
186}
187
Jack Jansenae8a68f1995-06-06 12:55:40 +0000188static PyObject *DlgObj_HideDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000189 DialogObject *_self;
190 PyObject *_args;
191{
192 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000193 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000194 if (!PyArg_ParseTuple(_args, "h",
195 &itemNo))
196 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000197 HideDialogItem(_self->ob_itself,
198 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000199 Py_INCREF(Py_None);
200 _res = Py_None;
201 return _res;
202}
203
Jack Jansenae8a68f1995-06-06 12:55:40 +0000204static PyObject *DlgObj_ShowDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000205 DialogObject *_self;
206 PyObject *_args;
207{
208 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000209 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000210 if (!PyArg_ParseTuple(_args, "h",
211 &itemNo))
212 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000213 ShowDialogItem(_self->ob_itself,
214 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000215 Py_INCREF(Py_None);
216 _res = Py_None;
217 return _res;
218}
219
Jack Jansenae8a68f1995-06-06 12:55:40 +0000220static PyObject *DlgObj_FindDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000221 DialogObject *_self;
222 PyObject *_args;
223{
224 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000225 DialogItemIndexZeroBased _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000226 Point thePt;
227 if (!PyArg_ParseTuple(_args, "O&",
228 PyMac_GetPoint, &thePt))
229 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000230 _rv = FindDialogItem(_self->ob_itself,
231 thePt);
Guido van Rossum17448e21995-01-30 11:53:55 +0000232 _res = Py_BuildValue("h",
233 _rv);
234 return _res;
235}
236
Jack Jansenae8a68f1995-06-06 12:55:40 +0000237static PyObject *DlgObj_DialogCut(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000238 DialogObject *_self;
239 PyObject *_args;
240{
241 PyObject *_res = NULL;
242 if (!PyArg_ParseTuple(_args, ""))
243 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000244 DialogCut(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000245 Py_INCREF(Py_None);
246 _res = Py_None;
247 return _res;
248}
249
Jack Jansenae8a68f1995-06-06 12:55:40 +0000250static PyObject *DlgObj_DialogPaste(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000251 DialogObject *_self;
252 PyObject *_args;
253{
254 PyObject *_res = NULL;
255 if (!PyArg_ParseTuple(_args, ""))
256 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000257 DialogPaste(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000258 Py_INCREF(Py_None);
259 _res = Py_None;
260 return _res;
261}
262
Jack Jansenae8a68f1995-06-06 12:55:40 +0000263static PyObject *DlgObj_DialogCopy(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000264 DialogObject *_self;
265 PyObject *_args;
266{
267 PyObject *_res = NULL;
268 if (!PyArg_ParseTuple(_args, ""))
269 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000270 DialogCopy(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000271 Py_INCREF(Py_None);
272 _res = Py_None;
273 return _res;
274}
275
Jack Jansenae8a68f1995-06-06 12:55:40 +0000276static PyObject *DlgObj_DialogDelete(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000277 DialogObject *_self;
278 PyObject *_args;
279{
280 PyObject *_res = NULL;
281 if (!PyArg_ParseTuple(_args, ""))
282 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000283 DialogDelete(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000284 Py_INCREF(Py_None);
285 _res = Py_None;
286 return _res;
287}
288
Jack Jansen21f96871998-02-20 16:02:09 +0000289static PyObject *DlgObj_GetDialogItem(_self, _args)
290 DialogObject *_self;
291 PyObject *_args;
292{
293 PyObject *_res = NULL;
294 DialogItemIndex itemNo;
295 DialogItemType itemType;
296 Handle item;
297 Rect box;
298 if (!PyArg_ParseTuple(_args, "h",
299 &itemNo))
300 return NULL;
301 GetDialogItem(_self->ob_itself,
302 itemNo,
303 &itemType,
304 &item,
305 &box);
306 _res = Py_BuildValue("hO&O&",
307 itemType,
308 OptResObj_New, item,
309 PyMac_BuildRect, &box);
310 return _res;
311}
312
313static PyObject *DlgObj_SetDialogItem(_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, "hhO&O&",
323 &itemNo,
324 &itemType,
325 ResObj_Convert, &item,
326 PyMac_GetRect, &box))
327 return NULL;
328 SetDialogItem(_self->ob_itself,
329 itemNo,
330 itemType,
331 item,
332 &box);
333 Py_INCREF(Py_None);
334 _res = Py_None;
335 return _res;
336}
337
338static PyObject *DlgObj_SelectDialogItemText(_self, _args)
339 DialogObject *_self;
340 PyObject *_args;
341{
342 PyObject *_res = NULL;
343 DialogItemIndex itemNo;
344 SInt16 strtSel;
345 SInt16 endSel;
346 if (!PyArg_ParseTuple(_args, "hhh",
347 &itemNo,
348 &strtSel,
349 &endSel))
350 return NULL;
351 SelectDialogItemText(_self->ob_itself,
352 itemNo,
353 strtSel,
354 endSel);
355 Py_INCREF(Py_None);
356 _res = Py_None;
357 return _res;
358}
359
Guido van Rossum17448e21995-01-30 11:53:55 +0000360static PyObject *DlgObj_AppendDITL(_self, _args)
361 DialogObject *_self;
362 PyObject *_args;
363{
364 PyObject *_res = NULL;
365 Handle theHandle;
366 DITLMethod method;
367 if (!PyArg_ParseTuple(_args, "O&h",
368 ResObj_Convert, &theHandle,
369 &method))
370 return NULL;
371 AppendDITL(_self->ob_itself,
372 theHandle,
373 method);
374 Py_INCREF(Py_None);
375 _res = Py_None;
376 return _res;
377}
378
379static PyObject *DlgObj_CountDITL(_self, _args)
380 DialogObject *_self;
381 PyObject *_args;
382{
383 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000384 DialogItemIndex _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000385 if (!PyArg_ParseTuple(_args, ""))
386 return NULL;
387 _rv = CountDITL(_self->ob_itself);
388 _res = Py_BuildValue("h",
389 _rv);
390 return _res;
391}
392
393static PyObject *DlgObj_ShortenDITL(_self, _args)
394 DialogObject *_self;
395 PyObject *_args;
396{
397 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000398 DialogItemIndex numberItems;
Guido van Rossum17448e21995-01-30 11:53:55 +0000399 if (!PyArg_ParseTuple(_args, "h",
400 &numberItems))
401 return NULL;
402 ShortenDITL(_self->ob_itself,
403 numberItems);
404 Py_INCREF(Py_None);
405 _res = Py_None;
406 return _res;
407}
408
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000409#if TARGET_API_MAC_CARBON
410
411static PyObject *DlgObj_InsertDialogItem(_self, _args)
412 DialogObject *_self;
413 PyObject *_args;
414{
415 PyObject *_res = NULL;
416 OSStatus _err;
417 DialogItemIndex afterItem;
418 DialogItemType itemType;
419 Handle itemHandle;
420 Rect box;
421 if (!PyArg_ParseTuple(_args, "hhO&O&",
422 &afterItem,
423 &itemType,
424 ResObj_Convert, &itemHandle,
425 PyMac_GetRect, &box))
426 return NULL;
427 _err = InsertDialogItem(_self->ob_itself,
428 afterItem,
429 itemType,
430 itemHandle,
431 &box);
432 if (_err != noErr) return PyMac_Error(_err);
433 Py_INCREF(Py_None);
434 _res = Py_None;
435 return _res;
436}
437#endif
438
439#if TARGET_API_MAC_CARBON
440
441static PyObject *DlgObj_RemoveDialogItems(_self, _args)
442 DialogObject *_self;
443 PyObject *_args;
444{
445 PyObject *_res = NULL;
446 OSStatus _err;
447 DialogItemIndex itemNo;
448 DialogItemIndex amountToRemove;
449 Boolean disposeItemData;
450 if (!PyArg_ParseTuple(_args, "hhb",
451 &itemNo,
452 &amountToRemove,
453 &disposeItemData))
454 return NULL;
455 _err = RemoveDialogItems(_self->ob_itself,
456 itemNo,
457 amountToRemove,
458 disposeItemData);
459 if (_err != noErr) return PyMac_Error(_err);
460 Py_INCREF(Py_None);
461 _res = Py_None;
462 return _res;
463}
464#endif
465
Jack Jansenae8a68f1995-06-06 12:55:40 +0000466static PyObject *DlgObj_StdFilterProc(_self, _args)
467 DialogObject *_self;
468 PyObject *_args;
469{
470 PyObject *_res = NULL;
471 Boolean _rv;
472 EventRecord event;
Jack Jansen21f96871998-02-20 16:02:09 +0000473 DialogItemIndex itemHit;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000474 if (!PyArg_ParseTuple(_args, ""))
475 return NULL;
476 _rv = StdFilterProc(_self->ob_itself,
477 &event,
478 &itemHit);
479 _res = Py_BuildValue("bO&h",
480 _rv,
481 PyMac_BuildEventRecord, &event,
482 itemHit);
483 return _res;
484}
485
486static PyObject *DlgObj_SetDialogDefaultItem(_self, _args)
487 DialogObject *_self;
488 PyObject *_args;
489{
490 PyObject *_res = NULL;
491 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000492 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000493 if (!PyArg_ParseTuple(_args, "h",
494 &newItem))
495 return NULL;
496 _err = SetDialogDefaultItem(_self->ob_itself,
497 newItem);
498 if (_err != noErr) return PyMac_Error(_err);
499 Py_INCREF(Py_None);
500 _res = Py_None;
501 return _res;
502}
503
504static PyObject *DlgObj_SetDialogCancelItem(_self, _args)
505 DialogObject *_self;
506 PyObject *_args;
507{
508 PyObject *_res = NULL;
509 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000510 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000511 if (!PyArg_ParseTuple(_args, "h",
512 &newItem))
513 return NULL;
514 _err = SetDialogCancelItem(_self->ob_itself,
515 newItem);
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_SetDialogTracksCursor(_self, _args)
523 DialogObject *_self;
524 PyObject *_args;
525{
526 PyObject *_res = NULL;
527 OSErr _err;
528 Boolean tracks;
529 if (!PyArg_ParseTuple(_args, "b",
530 &tracks))
531 return NULL;
532 _err = SetDialogTracksCursor(_self->ob_itself,
533 tracks);
534 if (_err != noErr) return PyMac_Error(_err);
535 Py_INCREF(Py_None);
536 _res = Py_None;
537 return _res;
538}
539
Jack Jansen21f96871998-02-20 16:02:09 +0000540static PyObject *DlgObj_AutoSizeDialog(_self, _args)
541 DialogObject *_self;
542 PyObject *_args;
543{
544 PyObject *_res = NULL;
545 OSErr _err;
546 if (!PyArg_ParseTuple(_args, ""))
547 return NULL;
548 _err = AutoSizeDialog(_self->ob_itself);
549 if (_err != noErr) return PyMac_Error(_err);
550 Py_INCREF(Py_None);
551 _res = Py_None;
552 return _res;
553}
554
555static PyObject *DlgObj_GetDialogItemAsControl(_self, _args)
556 DialogObject *_self;
557 PyObject *_args;
558{
559 PyObject *_res = NULL;
560 OSErr _err;
561 SInt16 inItemNo;
562 ControlHandle outControl;
563 if (!PyArg_ParseTuple(_args, "h",
564 &inItemNo))
565 return NULL;
566 _err = GetDialogItemAsControl(_self->ob_itself,
567 inItemNo,
568 &outControl);
569 if (_err != noErr) return PyMac_Error(_err);
570 _res = Py_BuildValue("O&",
571 CtlObj_New, outControl);
572 return _res;
573}
574
575static PyObject *DlgObj_MoveDialogItem(_self, _args)
576 DialogObject *_self;
577 PyObject *_args;
578{
579 PyObject *_res = NULL;
580 OSErr _err;
581 SInt16 inItemNo;
582 SInt16 inHoriz;
583 SInt16 inVert;
584 if (!PyArg_ParseTuple(_args, "hhh",
585 &inItemNo,
586 &inHoriz,
587 &inVert))
588 return NULL;
589 _err = MoveDialogItem(_self->ob_itself,
590 inItemNo,
591 inHoriz,
592 inVert);
593 if (_err != noErr) return PyMac_Error(_err);
594 Py_INCREF(Py_None);
595 _res = Py_None;
596 return _res;
597}
598
599static PyObject *DlgObj_SizeDialogItem(_self, _args)
600 DialogObject *_self;
601 PyObject *_args;
602{
603 PyObject *_res = NULL;
604 OSErr _err;
605 SInt16 inItemNo;
Jack Jansen21f96871998-02-20 16:02:09 +0000606 SInt16 inWidth;
Jack Jansen1c4e6141998-04-21 15:23:55 +0000607 SInt16 inHeight;
Jack Jansen21f96871998-02-20 16:02:09 +0000608 if (!PyArg_ParseTuple(_args, "hhh",
609 &inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000610 &inWidth,
611 &inHeight))
Jack Jansen21f96871998-02-20 16:02:09 +0000612 return NULL;
613 _err = SizeDialogItem(_self->ob_itself,
614 inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000615 inWidth,
616 inHeight);
Jack Jansen21f96871998-02-20 16:02:09 +0000617 if (_err != noErr) return PyMac_Error(_err);
618 Py_INCREF(Py_None);
619 _res = Py_None;
620 return _res;
621}
622
Jack Jansena05ac601999-12-12 21:41:51 +0000623static PyObject *DlgObj_AppendDialogItemList(_self, _args)
624 DialogObject *_self;
625 PyObject *_args;
626{
627 PyObject *_res = NULL;
628 OSErr _err;
629 SInt16 ditlID;
630 DITLMethod method;
631 if (!PyArg_ParseTuple(_args, "hh",
632 &ditlID,
633 &method))
634 return NULL;
635 _err = AppendDialogItemList(_self->ob_itself,
636 ditlID,
637 method);
638 if (_err != noErr) return PyMac_Error(_err);
639 Py_INCREF(Py_None);
640 _res = Py_None;
641 return _res;
642}
643
644static PyObject *DlgObj_SetDialogTimeout(_self, _args)
645 DialogObject *_self;
646 PyObject *_args;
647{
648 PyObject *_res = NULL;
649 OSStatus _err;
650 SInt16 inButtonToPress;
651 UInt32 inSecondsToWait;
652 if (!PyArg_ParseTuple(_args, "hl",
653 &inButtonToPress,
654 &inSecondsToWait))
655 return NULL;
656 _err = SetDialogTimeout(_self->ob_itself,
657 inButtonToPress,
658 inSecondsToWait);
659 if (_err != noErr) return PyMac_Error(_err);
660 Py_INCREF(Py_None);
661 _res = Py_None;
662 return _res;
663}
664
665static PyObject *DlgObj_GetDialogTimeout(_self, _args)
666 DialogObject *_self;
667 PyObject *_args;
668{
669 PyObject *_res = NULL;
670 OSStatus _err;
671 SInt16 outButtonToPress;
672 UInt32 outSecondsToWait;
673 UInt32 outSecondsRemaining;
674 if (!PyArg_ParseTuple(_args, ""))
675 return NULL;
676 _err = GetDialogTimeout(_self->ob_itself,
677 &outButtonToPress,
678 &outSecondsToWait,
679 &outSecondsRemaining);
680 if (_err != noErr) return PyMac_Error(_err);
681 _res = Py_BuildValue("hll",
682 outButtonToPress,
683 outSecondsToWait,
684 outSecondsRemaining);
685 return _res;
686}
687
688static PyObject *DlgObj_SetModalDialogEventMask(_self, _args)
689 DialogObject *_self;
690 PyObject *_args;
691{
692 PyObject *_res = NULL;
693 OSStatus _err;
694 EventMask inMask;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000695 if (!PyArg_ParseTuple(_args, "H",
Jack Jansena05ac601999-12-12 21:41:51 +0000696 &inMask))
697 return NULL;
698 _err = SetModalDialogEventMask(_self->ob_itself,
699 inMask);
700 if (_err != noErr) return PyMac_Error(_err);
701 Py_INCREF(Py_None);
702 _res = Py_None;
703 return _res;
704}
705
706static PyObject *DlgObj_GetModalDialogEventMask(_self, _args)
707 DialogObject *_self;
708 PyObject *_args;
709{
710 PyObject *_res = NULL;
711 OSStatus _err;
712 EventMask outMask;
713 if (!PyArg_ParseTuple(_args, ""))
714 return NULL;
715 _err = GetModalDialogEventMask(_self->ob_itself,
716 &outMask);
717 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000718 _res = Py_BuildValue("H",
Jack Jansena05ac601999-12-12 21:41:51 +0000719 outMask);
720 return _res;
721}
722
Jack Jansend96cb501996-09-23 15:48:46 +0000723static PyObject *DlgObj_GetDialogWindow(_self, _args)
724 DialogObject *_self;
725 PyObject *_args;
726{
727 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000728 WindowPtr _rv;
Jack Jansend96cb501996-09-23 15:48:46 +0000729 if (!PyArg_ParseTuple(_args, ""))
730 return NULL;
731 _rv = GetDialogWindow(_self->ob_itself);
732 _res = Py_BuildValue("O&",
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000733 WinObj_New, _rv);
734 return _res;
735}
736
737static PyObject *DlgObj_GetDialogTextEditHandle(_self, _args)
738 DialogObject *_self;
739 PyObject *_args;
740{
741 PyObject *_res = NULL;
742 TEHandle _rv;
743 if (!PyArg_ParseTuple(_args, ""))
744 return NULL;
745 _rv = GetDialogTextEditHandle(_self->ob_itself);
746 _res = Py_BuildValue("O&",
747 ResObj_New, _rv);
Jack Jansend96cb501996-09-23 15:48:46 +0000748 return _res;
749}
750
751static PyObject *DlgObj_GetDialogDefaultItem(_self, _args)
752 DialogObject *_self;
753 PyObject *_args;
754{
755 PyObject *_res = NULL;
756 SInt16 _rv;
757 if (!PyArg_ParseTuple(_args, ""))
758 return NULL;
759 _rv = GetDialogDefaultItem(_self->ob_itself);
760 _res = Py_BuildValue("h",
761 _rv);
762 return _res;
763}
764
765static PyObject *DlgObj_GetDialogCancelItem(_self, _args)
766 DialogObject *_self;
767 PyObject *_args;
768{
769 PyObject *_res = NULL;
770 SInt16 _rv;
771 if (!PyArg_ParseTuple(_args, ""))
772 return NULL;
773 _rv = GetDialogCancelItem(_self->ob_itself);
774 _res = Py_BuildValue("h",
775 _rv);
776 return _res;
777}
778
779static PyObject *DlgObj_GetDialogKeyboardFocusItem(_self, _args)
780 DialogObject *_self;
781 PyObject *_args;
782{
783 PyObject *_res = NULL;
784 SInt16 _rv;
785 if (!PyArg_ParseTuple(_args, ""))
786 return NULL;
787 _rv = GetDialogKeyboardFocusItem(_self->ob_itself);
788 _res = Py_BuildValue("h",
789 _rv);
790 return _res;
791}
792
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000793static PyObject *DlgObj_SetPortDialogPort(_self, _args)
794 DialogObject *_self;
795 PyObject *_args;
796{
797 PyObject *_res = NULL;
798 if (!PyArg_ParseTuple(_args, ""))
799 return NULL;
800 SetPortDialogPort(_self->ob_itself);
801 Py_INCREF(Py_None);
802 _res = Py_None;
803 return _res;
804}
805
806static PyObject *DlgObj_GetDialogPort(_self, _args)
807 DialogObject *_self;
808 PyObject *_args;
809{
810 PyObject *_res = NULL;
811 CGrafPtr _rv;
812 if (!PyArg_ParseTuple(_args, ""))
813 return NULL;
814 _rv = GetDialogPort(_self->ob_itself);
815 _res = Py_BuildValue("O&",
816 GrafObj_New, _rv);
817 return _res;
818}
819
Jack Jansen74a1e632000-07-14 22:37:27 +0000820#if !TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000821
Jack Jansend96cb501996-09-23 15:48:46 +0000822static PyObject *DlgObj_SetGrafPortOfDialog(_self, _args)
823 DialogObject *_self;
824 PyObject *_args;
825{
826 PyObject *_res = NULL;
827 if (!PyArg_ParseTuple(_args, ""))
828 return NULL;
829 SetGrafPortOfDialog(_self->ob_itself);
830 Py_INCREF(Py_None);
831 _res = Py_None;
832 return _res;
833}
Jack Jansene79dc762000-06-02 21:35:07 +0000834#endif
Jack Jansend96cb501996-09-23 15:48:46 +0000835
Guido van Rossum17448e21995-01-30 11:53:55 +0000836static PyMethodDef DlgObj_methods[] = {
837 {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
838 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000839 {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
Jack Jansen2b724171996-04-10 14:48:19 +0000840 "(RgnHandle updateRgn) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000841 {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000842 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000843 {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000844 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000845 {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000846 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000847 {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000848 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000849 {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000850 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000851 {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000852 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000853 {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000854 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000855 {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1,
856 "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"},
857 {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1,
858 "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"},
859 {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1,
860 "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000861 {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
862 "(Handle theHandle, DITLMethod method) -> None"},
863 {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000864 "() -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000865 {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000866 "(DialogItemIndex numberItems) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000867
868#if TARGET_API_MAC_CARBON
869 {"InsertDialogItem", (PyCFunction)DlgObj_InsertDialogItem, 1,
870 "(DialogItemIndex afterItem, DialogItemType itemType, Handle itemHandle, Rect box) -> None"},
871#endif
872
873#if TARGET_API_MAC_CARBON
874 {"RemoveDialogItems", (PyCFunction)DlgObj_RemoveDialogItems, 1,
875 "(DialogItemIndex itemNo, DialogItemIndex amountToRemove, Boolean disposeItemData) -> None"},
876#endif
Jack Jansenae8a68f1995-06-06 12:55:40 +0000877 {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000878 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000879 {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000880 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000881 {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000882 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000883 {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
884 "(Boolean tracks) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000885 {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1,
886 "() -> None"},
887 {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1,
888 "(SInt16 inItemNo) -> (ControlHandle outControl)"},
889 {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1,
890 "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"},
891 {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000892 "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +0000893 {"AppendDialogItemList", (PyCFunction)DlgObj_AppendDialogItemList, 1,
894 "(SInt16 ditlID, DITLMethod method) -> None"},
895 {"SetDialogTimeout", (PyCFunction)DlgObj_SetDialogTimeout, 1,
896 "(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None"},
897 {"GetDialogTimeout", (PyCFunction)DlgObj_GetDialogTimeout, 1,
898 "() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)"},
899 {"SetModalDialogEventMask", (PyCFunction)DlgObj_SetModalDialogEventMask, 1,
900 "(EventMask inMask) -> None"},
901 {"GetModalDialogEventMask", (PyCFunction)DlgObj_GetModalDialogEventMask, 1,
902 "() -> (EventMask outMask)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000903 {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
Jack Jansene79dc762000-06-02 21:35:07 +0000904 "() -> (WindowPtr _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000905 {"GetDialogTextEditHandle", (PyCFunction)DlgObj_GetDialogTextEditHandle, 1,
906 "() -> (TEHandle _rv)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000907 {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1,
908 "() -> (SInt16 _rv)"},
909 {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1,
910 "() -> (SInt16 _rv)"},
911 {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1,
912 "() -> (SInt16 _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000913 {"SetPortDialogPort", (PyCFunction)DlgObj_SetPortDialogPort, 1,
914 "() -> None"},
915 {"GetDialogPort", (PyCFunction)DlgObj_GetDialogPort, 1,
916 "() -> (CGrafPtr _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +0000917
Jack Jansen74a1e632000-07-14 22:37:27 +0000918#if !TARGET_API_MAC_CARBON
Jack Jansend96cb501996-09-23 15:48:46 +0000919 {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1,
920 "() -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +0000921#endif
Guido van Rossum17448e21995-01-30 11:53:55 +0000922 {NULL, NULL, 0}
923};
924
925PyMethodChain DlgObj_chain = { DlgObj_methods, &WinObj_chain };
926
927static PyObject *DlgObj_getattr(self, name)
928 DialogObject *self;
929 char *name;
930{
931 return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name);
932}
933
934#define DlgObj_setattr NULL
935
Jack Jansena05ac601999-12-12 21:41:51 +0000936#define DlgObj_compare NULL
937
938#define DlgObj_repr NULL
939
940#define DlgObj_hash NULL
941
Guido van Rossum17448e21995-01-30 11:53:55 +0000942PyTypeObject Dialog_Type = {
943 PyObject_HEAD_INIT(&PyType_Type)
944 0, /*ob_size*/
945 "Dialog", /*tp_name*/
946 sizeof(DialogObject), /*tp_basicsize*/
947 0, /*tp_itemsize*/
948 /* methods */
949 (destructor) DlgObj_dealloc, /*tp_dealloc*/
950 0, /*tp_print*/
951 (getattrfunc) DlgObj_getattr, /*tp_getattr*/
952 (setattrfunc) DlgObj_setattr, /*tp_setattr*/
Jack Jansena05ac601999-12-12 21:41:51 +0000953 (cmpfunc) DlgObj_compare, /*tp_compare*/
954 (reprfunc) DlgObj_repr, /*tp_repr*/
955 (PyNumberMethods *)0, /* tp_as_number */
956 (PySequenceMethods *)0, /* tp_as_sequence */
957 (PyMappingMethods *)0, /* tp_as_mapping */
958 (hashfunc) DlgObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +0000959};
960
961/* --------------------- End object type Dialog --------------------- */
962
963
964static PyObject *Dlg_NewDialog(_self, _args)
965 PyObject *_self;
966 PyObject *_args;
967{
968 PyObject *_res = NULL;
969 DialogPtr _rv;
970 Rect boundsRect;
971 Str255 title;
972 Boolean visible;
Jack Jansen21f96871998-02-20 16:02:09 +0000973 SInt16 procID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000974 WindowPtr behind;
975 Boolean goAwayFlag;
Jack Jansen21f96871998-02-20 16:02:09 +0000976 SInt32 refCon;
977 Handle items;
Guido van Rossum17448e21995-01-30 11:53:55 +0000978 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
979 PyMac_GetRect, &boundsRect,
980 PyMac_GetStr255, title,
981 &visible,
982 &procID,
983 WinObj_Convert, &behind,
984 &goAwayFlag,
985 &refCon,
Jack Jansen21f96871998-02-20 16:02:09 +0000986 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +0000987 return NULL;
988 _rv = NewDialog((void *)0,
989 &boundsRect,
990 title,
991 visible,
992 procID,
993 behind,
994 goAwayFlag,
995 refCon,
Jack Jansen21f96871998-02-20 16:02:09 +0000996 items);
Guido van Rossum17448e21995-01-30 11:53:55 +0000997 _res = Py_BuildValue("O&",
998 DlgObj_New, _rv);
999 return _res;
1000}
1001
1002static PyObject *Dlg_GetNewDialog(_self, _args)
1003 PyObject *_self;
1004 PyObject *_args;
1005{
1006 PyObject *_res = NULL;
1007 DialogPtr _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001008 SInt16 dialogID;
Guido van Rossum17448e21995-01-30 11:53:55 +00001009 WindowPtr behind;
1010 if (!PyArg_ParseTuple(_args, "hO&",
1011 &dialogID,
1012 WinObj_Convert, &behind))
1013 return NULL;
1014 _rv = GetNewDialog(dialogID,
1015 (void *)0,
1016 behind);
1017 _res = Py_BuildValue("O&",
1018 DlgObj_New, _rv);
1019 return _res;
1020}
1021
Jack Jansen21f96871998-02-20 16:02:09 +00001022static PyObject *Dlg_NewColorDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001023 PyObject *_self;
1024 PyObject *_args;
1025{
1026 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001027 DialogPtr _rv;
1028 Rect boundsRect;
1029 Str255 title;
1030 Boolean visible;
1031 SInt16 procID;
1032 WindowPtr behind;
1033 Boolean goAwayFlag;
1034 SInt32 refCon;
1035 Handle items;
1036 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
1037 PyMac_GetRect, &boundsRect,
1038 PyMac_GetStr255, title,
1039 &visible,
1040 &procID,
1041 WinObj_Convert, &behind,
1042 &goAwayFlag,
1043 &refCon,
1044 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +00001045 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001046 _rv = NewColorDialog((void *)0,
1047 &boundsRect,
1048 title,
1049 visible,
1050 procID,
1051 behind,
1052 goAwayFlag,
1053 refCon,
1054 items);
1055 _res = Py_BuildValue("O&",
1056 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +00001057 return _res;
1058}
1059
1060static PyObject *Dlg_ModalDialog(_self, _args)
1061 PyObject *_self;
1062 PyObject *_args;
1063{
1064 PyObject *_res = NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001065 PyObject* modalFilter;
Jack Jansen21f96871998-02-20 16:02:09 +00001066 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +00001067 if (!PyArg_ParseTuple(_args, "O",
Jack Jansenae8a68f1995-06-06 12:55:40 +00001068 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001069 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001070 ModalDialog(NewModalFilterProc(Dlg_PassFilterProc(modalFilter)),
Guido van Rossum17448e21995-01-30 11:53:55 +00001071 &itemHit);
1072 _res = Py_BuildValue("h",
1073 itemHit);
1074 return _res;
1075}
1076
1077static PyObject *Dlg_IsDialogEvent(_self, _args)
1078 PyObject *_self;
1079 PyObject *_args;
1080{
1081 PyObject *_res = NULL;
1082 Boolean _rv;
1083 EventRecord theEvent;
1084 if (!PyArg_ParseTuple(_args, "O&",
1085 PyMac_GetEventRecord, &theEvent))
1086 return NULL;
1087 _rv = IsDialogEvent(&theEvent);
1088 _res = Py_BuildValue("b",
1089 _rv);
1090 return _res;
1091}
1092
1093static PyObject *Dlg_DialogSelect(_self, _args)
1094 PyObject *_self;
1095 PyObject *_args;
1096{
1097 PyObject *_res = NULL;
1098 Boolean _rv;
1099 EventRecord theEvent;
1100 DialogPtr theDialog;
Jack Jansen21f96871998-02-20 16:02:09 +00001101 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +00001102 if (!PyArg_ParseTuple(_args, "O&",
1103 PyMac_GetEventRecord, &theEvent))
1104 return NULL;
1105 _rv = DialogSelect(&theEvent,
1106 &theDialog,
1107 &itemHit);
1108 _res = Py_BuildValue("bO&h",
1109 _rv,
1110 WinObj_WhichWindow, theDialog,
1111 itemHit);
1112 return _res;
1113}
1114
1115static PyObject *Dlg_Alert(_self, _args)
1116 PyObject *_self;
1117 PyObject *_args;
1118{
1119 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001120 DialogItemIndex _rv;
1121 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001122 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001123 if (!PyArg_ParseTuple(_args, "hO",
1124 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001125 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001126 return NULL;
1127 _rv = Alert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001128 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001129 _res = Py_BuildValue("h",
1130 _rv);
1131 return _res;
1132}
1133
1134static PyObject *Dlg_StopAlert(_self, _args)
1135 PyObject *_self;
1136 PyObject *_args;
1137{
1138 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001139 DialogItemIndex _rv;
1140 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001141 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001142 if (!PyArg_ParseTuple(_args, "hO",
1143 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001144 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001145 return NULL;
1146 _rv = StopAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001147 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001148 _res = Py_BuildValue("h",
1149 _rv);
1150 return _res;
1151}
1152
1153static PyObject *Dlg_NoteAlert(_self, _args)
1154 PyObject *_self;
1155 PyObject *_args;
1156{
1157 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001158 DialogItemIndex _rv;
1159 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001160 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001161 if (!PyArg_ParseTuple(_args, "hO",
1162 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001163 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001164 return NULL;
1165 _rv = NoteAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001166 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001167 _res = Py_BuildValue("h",
1168 _rv);
1169 return _res;
1170}
1171
1172static PyObject *Dlg_CautionAlert(_self, _args)
1173 PyObject *_self;
1174 PyObject *_args;
1175{
1176 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001177 DialogItemIndex _rv;
1178 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001179 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001180 if (!PyArg_ParseTuple(_args, "hO",
1181 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001182 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001183 return NULL;
1184 _rv = CautionAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001185 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001186 _res = Py_BuildValue("h",
1187 _rv);
1188 return _res;
1189}
1190
Jack Jansen21f96871998-02-20 16:02:09 +00001191static PyObject *Dlg_ParamText(_self, _args)
1192 PyObject *_self;
1193 PyObject *_args;
1194{
1195 PyObject *_res = NULL;
1196 Str255 param0;
1197 Str255 param1;
1198 Str255 param2;
1199 Str255 param3;
1200 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1201 PyMac_GetStr255, param0,
1202 PyMac_GetStr255, param1,
1203 PyMac_GetStr255, param2,
1204 PyMac_GetStr255, param3))
1205 return NULL;
1206 ParamText(param0,
1207 param1,
1208 param2,
1209 param3);
1210 Py_INCREF(Py_None);
1211 _res = Py_None;
1212 return _res;
1213}
1214
Jack Jansenae8a68f1995-06-06 12:55:40 +00001215static PyObject *Dlg_GetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001216 PyObject *_self;
1217 PyObject *_args;
1218{
1219 PyObject *_res = NULL;
1220 Handle item;
1221 Str255 text;
1222 if (!PyArg_ParseTuple(_args, "O&",
1223 ResObj_Convert, &item))
1224 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001225 GetDialogItemText(item,
1226 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001227 _res = Py_BuildValue("O&",
1228 PyMac_BuildStr255, text);
1229 return _res;
1230}
1231
Jack Jansenae8a68f1995-06-06 12:55:40 +00001232static PyObject *Dlg_SetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001233 PyObject *_self;
1234 PyObject *_args;
1235{
1236 PyObject *_res = NULL;
1237 Handle item;
1238 Str255 text;
1239 if (!PyArg_ParseTuple(_args, "O&O&",
1240 ResObj_Convert, &item,
1241 PyMac_GetStr255, text))
1242 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001243 SetDialogItemText(item,
1244 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001245 Py_INCREF(Py_None);
1246 _res = Py_None;
1247 return _res;
1248}
1249
Jack Jansenae8a68f1995-06-06 12:55:40 +00001250static PyObject *Dlg_GetAlertStage(_self, _args)
1251 PyObject *_self;
1252 PyObject *_args;
1253{
1254 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001255 SInt16 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001256 if (!PyArg_ParseTuple(_args, ""))
1257 return NULL;
1258 _rv = GetAlertStage();
1259 _res = Py_BuildValue("h",
1260 _rv);
1261 return _res;
1262}
1263
Jack Jansen21f96871998-02-20 16:02:09 +00001264static PyObject *Dlg_SetDialogFont(_self, _args)
1265 PyObject *_self;
1266 PyObject *_args;
1267{
1268 PyObject *_res = NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001269 SInt16 fontNum;
Jack Jansen21f96871998-02-20 16:02:09 +00001270 if (!PyArg_ParseTuple(_args, "h",
Jack Jansena05ac601999-12-12 21:41:51 +00001271 &fontNum))
Jack Jansen21f96871998-02-20 16:02:09 +00001272 return NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001273 SetDialogFont(fontNum);
Jack Jansen21f96871998-02-20 16:02:09 +00001274 Py_INCREF(Py_None);
1275 _res = Py_None;
1276 return _res;
1277}
1278
Jack Jansenae8a68f1995-06-06 12:55:40 +00001279static PyObject *Dlg_ResetAlertStage(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001280 PyObject *_self;
1281 PyObject *_args;
1282{
1283 PyObject *_res = NULL;
1284 if (!PyArg_ParseTuple(_args, ""))
1285 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001286 ResetAlertStage();
Guido van Rossum17448e21995-01-30 11:53:55 +00001287 Py_INCREF(Py_None);
1288 _res = Py_None;
1289 return _res;
1290}
1291
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001292#if TARGET_API_MAC_CARBON
1293
1294static PyObject *Dlg_GetParamText(_self, _args)
1295 PyObject *_self;
1296 PyObject *_args;
1297{
1298 PyObject *_res = NULL;
1299 Str255 param0;
1300 Str255 param1;
1301 Str255 param2;
1302 Str255 param3;
1303 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1304 PyMac_GetStr255, param0,
1305 PyMac_GetStr255, param1,
1306 PyMac_GetStr255, param2,
1307 PyMac_GetStr255, param3))
1308 return NULL;
1309 GetParamText(param0,
1310 param1,
1311 param2,
1312 param3);
1313 Py_INCREF(Py_None);
1314 _res = Py_None;
1315 return _res;
1316}
1317#endif
1318
Jack Jansen21f96871998-02-20 16:02:09 +00001319static PyObject *Dlg_NewFeaturesDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001320 PyObject *_self;
1321 PyObject *_args;
1322{
1323 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001324 DialogPtr _rv;
1325 Rect inBoundsRect;
1326 Str255 inTitle;
1327 Boolean inIsVisible;
1328 SInt16 inProcID;
1329 WindowPtr inBehind;
1330 Boolean inGoAwayFlag;
1331 SInt32 inRefCon;
1332 Handle inItemListHandle;
1333 UInt32 inFlags;
1334 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
1335 PyMac_GetRect, &inBoundsRect,
1336 PyMac_GetStr255, inTitle,
1337 &inIsVisible,
1338 &inProcID,
1339 WinObj_Convert, &inBehind,
1340 &inGoAwayFlag,
1341 &inRefCon,
1342 ResObj_Convert, &inItemListHandle,
1343 &inFlags))
Guido van Rossum17448e21995-01-30 11:53:55 +00001344 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001345 _rv = NewFeaturesDialog((void *)0,
1346 &inBoundsRect,
1347 inTitle,
1348 inIsVisible,
1349 inProcID,
1350 inBehind,
1351 inGoAwayFlag,
1352 inRefCon,
1353 inItemListHandle,
1354 inFlags);
1355 _res = Py_BuildValue("O&",
1356 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +00001357 return _res;
1358}
1359
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001360static PyObject *Dlg_GetDialogFromWindow(_self, _args)
1361 PyObject *_self;
1362 PyObject *_args;
1363{
1364 PyObject *_res = NULL;
1365 DialogPtr _rv;
1366 WindowPtr window;
1367 if (!PyArg_ParseTuple(_args, "O&",
1368 WinObj_Convert, &window))
1369 return NULL;
1370 _rv = GetDialogFromWindow(window);
1371 _res = Py_BuildValue("O&",
1372 DlgObj_New, _rv);
1373 return _res;
1374}
1375
Jack Jansendf901df1998-07-10 15:47:48 +00001376static PyObject *Dlg_SetUserItemHandler(_self, _args)
1377 PyObject *_self;
1378 PyObject *_args;
1379{
1380 PyObject *_res = NULL;
1381
1382 PyObject *new = NULL;
1383
1384
1385 if (!PyArg_ParseTuple(_args, "|O", &new))
1386 return NULL;
1387
1388 if (Dlg_UserItemProc_callback && new && new != Py_None) {
1389 PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
1390 return NULL;
1391 }
1392
1393 if (new == Py_None) {
1394 new = NULL;
1395 _res = Py_None;
1396 Py_INCREF(Py_None);
1397 } else {
1398 Py_INCREF(new);
1399 _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc));
1400 }
1401
1402 Dlg_UserItemProc_callback = new;
1403 return _res;
1404
1405}
1406
Guido van Rossum17448e21995-01-30 11:53:55 +00001407static PyMethodDef Dlg_methods[] = {
1408 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001409 "(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 +00001410 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001411 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1412 {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
1413 "(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 +00001414 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001415 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001416 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
1417 "(EventRecord theEvent) -> (Boolean _rv)"},
1418 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001419 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001420 {"Alert", (PyCFunction)Dlg_Alert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001421 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001422 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001423 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001424 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001425 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001426 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001427 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1428 {"ParamText", (PyCFunction)Dlg_ParamText, 1,
1429 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001430 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001431 "(Handle item) -> (Str255 text)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001432 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001433 "(Handle item, Str255 text) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001434 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001435 "() -> (SInt16 _rv)"},
1436 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
Jack Jansena05ac601999-12-12 21:41:51 +00001437 "(SInt16 fontNum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001438 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001439 "() -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001440
1441#if TARGET_API_MAC_CARBON
1442 {"GetParamText", (PyCFunction)Dlg_GetParamText, 1,
1443 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1444#endif
Jack Jansen21f96871998-02-20 16:02:09 +00001445 {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
1446 "(Rect inBoundsRect, Str255 inTitle, Boolean inIsVisible, SInt16 inProcID, WindowPtr inBehind, Boolean inGoAwayFlag, SInt32 inRefCon, Handle inItemListHandle, UInt32 inFlags) -> (DialogPtr _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001447 {"GetDialogFromWindow", (PyCFunction)Dlg_GetDialogFromWindow, 1,
1448 "(WindowPtr window) -> (DialogPtr _rv)"},
Jack Jansendf901df1998-07-10 15:47:48 +00001449 {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
1450 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001451 {NULL, NULL, 0}
1452};
1453
1454
1455
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001456/* Return the WindowPtr corresponding to a DialogObject */
1457
1458WindowPtr
1459DlgObj_ConvertToWindow(self)
1460 PyObject *self;
1461{
1462 if ( DlgObj_Check(self) )
1463 return GetDialogWindow(((DialogObject *)self)->ob_itself);
1464 return NULL;
1465}
1466
Guido van Rossum17448e21995-01-30 11:53:55 +00001467
1468void initDlg()
1469{
1470 PyObject *m;
1471 PyObject *d;
1472
1473
1474
1475
1476 m = Py_InitModule("Dlg", Dlg_methods);
1477 d = PyModule_GetDict(m);
1478 Dlg_Error = PyMac_GetOSErrException();
1479 if (Dlg_Error == NULL ||
1480 PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001481 return;
Jack Jansena755e681997-09-20 17:40:22 +00001482 Dialog_Type.ob_type = &PyType_Type;
1483 Py_INCREF(&Dialog_Type);
1484 if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0)
1485 Py_FatalError("can't initialize DialogType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001486}
1487
1488/* ========================= End module Dlg ========================= */
1489