blob: 070283e5ffa1b75b31a0bb4b705ed765475acd60 [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 */
Jack Jansen69e7f112001-02-06 16:14:54 +000033 args = Py_BuildValue("O&O&", DlgObj_WhichDialog, 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 */
Jack Jansen69e7f112001-02-06 16:14:54 +000084 args = Py_BuildValue("O&h", DlgObj_WhichDialog, dialog, item);
Jack Jansendf901df1998-07-10 15:47:48 +000085 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 Jansen69e7f112001-02-06 16:14:54 +000099#if 0
Jack Jansenb8c4c7b2000-08-25 22:25:54 +0000100/*
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
Jack Jansen69e7f112001-02-06 16:14:54 +0000925PyMethodChain DlgObj_chain = { DlgObj_methods, NULL };
Guido van Rossum17448e21995-01-30 11:53:55 +0000926
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 Jansen69e7f112001-02-06 16:14:54 +0000936static int DlgObj_compare(self, other)
937 DialogObject *self, *other;
938{
939 if ( self->ob_itself > other->ob_itself ) return 1;
940 if ( self->ob_itself < other->ob_itself ) return -1;
941 return 0;
942}
Jack Jansena05ac601999-12-12 21:41:51 +0000943
944#define DlgObj_repr NULL
945
Jack Jansen69e7f112001-02-06 16:14:54 +0000946static int DlgObj_hash(self)
947 DialogObject *self;
948{
949 return (int)self->ob_itself;
950}
Jack Jansena05ac601999-12-12 21:41:51 +0000951
Guido van Rossum17448e21995-01-30 11:53:55 +0000952PyTypeObject Dialog_Type = {
953 PyObject_HEAD_INIT(&PyType_Type)
954 0, /*ob_size*/
955 "Dialog", /*tp_name*/
956 sizeof(DialogObject), /*tp_basicsize*/
957 0, /*tp_itemsize*/
958 /* methods */
959 (destructor) DlgObj_dealloc, /*tp_dealloc*/
960 0, /*tp_print*/
961 (getattrfunc) DlgObj_getattr, /*tp_getattr*/
962 (setattrfunc) DlgObj_setattr, /*tp_setattr*/
Jack Jansena05ac601999-12-12 21:41:51 +0000963 (cmpfunc) DlgObj_compare, /*tp_compare*/
964 (reprfunc) DlgObj_repr, /*tp_repr*/
965 (PyNumberMethods *)0, /* tp_as_number */
966 (PySequenceMethods *)0, /* tp_as_sequence */
967 (PyMappingMethods *)0, /* tp_as_mapping */
968 (hashfunc) DlgObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +0000969};
970
971/* --------------------- End object type Dialog --------------------- */
972
973
974static PyObject *Dlg_NewDialog(_self, _args)
975 PyObject *_self;
976 PyObject *_args;
977{
978 PyObject *_res = NULL;
979 DialogPtr _rv;
980 Rect boundsRect;
981 Str255 title;
982 Boolean visible;
Jack Jansen21f96871998-02-20 16:02:09 +0000983 SInt16 procID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000984 WindowPtr behind;
985 Boolean goAwayFlag;
Jack Jansen21f96871998-02-20 16:02:09 +0000986 SInt32 refCon;
987 Handle items;
Guido van Rossum17448e21995-01-30 11:53:55 +0000988 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
989 PyMac_GetRect, &boundsRect,
990 PyMac_GetStr255, title,
991 &visible,
992 &procID,
993 WinObj_Convert, &behind,
994 &goAwayFlag,
995 &refCon,
Jack Jansen21f96871998-02-20 16:02:09 +0000996 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +0000997 return NULL;
998 _rv = NewDialog((void *)0,
999 &boundsRect,
1000 title,
1001 visible,
1002 procID,
1003 behind,
1004 goAwayFlag,
1005 refCon,
Jack Jansen21f96871998-02-20 16:02:09 +00001006 items);
Guido van Rossum17448e21995-01-30 11:53:55 +00001007 _res = Py_BuildValue("O&",
1008 DlgObj_New, _rv);
1009 return _res;
1010}
1011
1012static PyObject *Dlg_GetNewDialog(_self, _args)
1013 PyObject *_self;
1014 PyObject *_args;
1015{
1016 PyObject *_res = NULL;
1017 DialogPtr _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001018 SInt16 dialogID;
Guido van Rossum17448e21995-01-30 11:53:55 +00001019 WindowPtr behind;
1020 if (!PyArg_ParseTuple(_args, "hO&",
1021 &dialogID,
1022 WinObj_Convert, &behind))
1023 return NULL;
1024 _rv = GetNewDialog(dialogID,
1025 (void *)0,
1026 behind);
1027 _res = Py_BuildValue("O&",
1028 DlgObj_New, _rv);
1029 return _res;
1030}
1031
Jack Jansen21f96871998-02-20 16:02:09 +00001032static PyObject *Dlg_NewColorDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001033 PyObject *_self;
1034 PyObject *_args;
1035{
1036 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001037 DialogPtr _rv;
1038 Rect boundsRect;
1039 Str255 title;
1040 Boolean visible;
1041 SInt16 procID;
1042 WindowPtr behind;
1043 Boolean goAwayFlag;
1044 SInt32 refCon;
1045 Handle items;
1046 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
1047 PyMac_GetRect, &boundsRect,
1048 PyMac_GetStr255, title,
1049 &visible,
1050 &procID,
1051 WinObj_Convert, &behind,
1052 &goAwayFlag,
1053 &refCon,
1054 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +00001055 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001056 _rv = NewColorDialog((void *)0,
1057 &boundsRect,
1058 title,
1059 visible,
1060 procID,
1061 behind,
1062 goAwayFlag,
1063 refCon,
1064 items);
1065 _res = Py_BuildValue("O&",
1066 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +00001067 return _res;
1068}
1069
1070static PyObject *Dlg_ModalDialog(_self, _args)
1071 PyObject *_self;
1072 PyObject *_args;
1073{
1074 PyObject *_res = NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001075 PyObject* modalFilter;
Jack Jansen21f96871998-02-20 16:02:09 +00001076 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +00001077 if (!PyArg_ParseTuple(_args, "O",
Jack Jansenae8a68f1995-06-06 12:55:40 +00001078 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001079 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001080 ModalDialog(NewModalFilterProc(Dlg_PassFilterProc(modalFilter)),
Guido van Rossum17448e21995-01-30 11:53:55 +00001081 &itemHit);
1082 _res = Py_BuildValue("h",
1083 itemHit);
1084 return _res;
1085}
1086
1087static PyObject *Dlg_IsDialogEvent(_self, _args)
1088 PyObject *_self;
1089 PyObject *_args;
1090{
1091 PyObject *_res = NULL;
1092 Boolean _rv;
1093 EventRecord theEvent;
1094 if (!PyArg_ParseTuple(_args, "O&",
1095 PyMac_GetEventRecord, &theEvent))
1096 return NULL;
1097 _rv = IsDialogEvent(&theEvent);
1098 _res = Py_BuildValue("b",
1099 _rv);
1100 return _res;
1101}
1102
1103static PyObject *Dlg_DialogSelect(_self, _args)
1104 PyObject *_self;
1105 PyObject *_args;
1106{
1107 PyObject *_res = NULL;
1108 Boolean _rv;
1109 EventRecord theEvent;
1110 DialogPtr theDialog;
Jack Jansen21f96871998-02-20 16:02:09 +00001111 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +00001112 if (!PyArg_ParseTuple(_args, "O&",
1113 PyMac_GetEventRecord, &theEvent))
1114 return NULL;
1115 _rv = DialogSelect(&theEvent,
1116 &theDialog,
1117 &itemHit);
1118 _res = Py_BuildValue("bO&h",
1119 _rv,
Jack Jansen69e7f112001-02-06 16:14:54 +00001120 DlgObj_WhichDialog, theDialog,
Guido van Rossum17448e21995-01-30 11:53:55 +00001121 itemHit);
1122 return _res;
1123}
1124
1125static PyObject *Dlg_Alert(_self, _args)
1126 PyObject *_self;
1127 PyObject *_args;
1128{
1129 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001130 DialogItemIndex _rv;
1131 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001132 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001133 if (!PyArg_ParseTuple(_args, "hO",
1134 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001135 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001136 return NULL;
1137 _rv = Alert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001138 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001139 _res = Py_BuildValue("h",
1140 _rv);
1141 return _res;
1142}
1143
1144static PyObject *Dlg_StopAlert(_self, _args)
1145 PyObject *_self;
1146 PyObject *_args;
1147{
1148 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001149 DialogItemIndex _rv;
1150 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001151 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001152 if (!PyArg_ParseTuple(_args, "hO",
1153 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001154 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001155 return NULL;
1156 _rv = StopAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001157 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001158 _res = Py_BuildValue("h",
1159 _rv);
1160 return _res;
1161}
1162
1163static PyObject *Dlg_NoteAlert(_self, _args)
1164 PyObject *_self;
1165 PyObject *_args;
1166{
1167 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001168 DialogItemIndex _rv;
1169 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001170 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001171 if (!PyArg_ParseTuple(_args, "hO",
1172 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001173 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001174 return NULL;
1175 _rv = NoteAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001176 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001177 _res = Py_BuildValue("h",
1178 _rv);
1179 return _res;
1180}
1181
1182static PyObject *Dlg_CautionAlert(_self, _args)
1183 PyObject *_self;
1184 PyObject *_args;
1185{
1186 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001187 DialogItemIndex _rv;
1188 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001189 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001190 if (!PyArg_ParseTuple(_args, "hO",
1191 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001192 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001193 return NULL;
1194 _rv = CautionAlert(alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001195 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
Guido van Rossum17448e21995-01-30 11:53:55 +00001196 _res = Py_BuildValue("h",
1197 _rv);
1198 return _res;
1199}
1200
Jack Jansen21f96871998-02-20 16:02:09 +00001201static PyObject *Dlg_ParamText(_self, _args)
1202 PyObject *_self;
1203 PyObject *_args;
1204{
1205 PyObject *_res = NULL;
1206 Str255 param0;
1207 Str255 param1;
1208 Str255 param2;
1209 Str255 param3;
1210 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1211 PyMac_GetStr255, param0,
1212 PyMac_GetStr255, param1,
1213 PyMac_GetStr255, param2,
1214 PyMac_GetStr255, param3))
1215 return NULL;
1216 ParamText(param0,
1217 param1,
1218 param2,
1219 param3);
1220 Py_INCREF(Py_None);
1221 _res = Py_None;
1222 return _res;
1223}
1224
Jack Jansenae8a68f1995-06-06 12:55:40 +00001225static PyObject *Dlg_GetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001226 PyObject *_self;
1227 PyObject *_args;
1228{
1229 PyObject *_res = NULL;
1230 Handle item;
1231 Str255 text;
1232 if (!PyArg_ParseTuple(_args, "O&",
1233 ResObj_Convert, &item))
1234 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001235 GetDialogItemText(item,
1236 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001237 _res = Py_BuildValue("O&",
1238 PyMac_BuildStr255, text);
1239 return _res;
1240}
1241
Jack Jansenae8a68f1995-06-06 12:55:40 +00001242static PyObject *Dlg_SetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001243 PyObject *_self;
1244 PyObject *_args;
1245{
1246 PyObject *_res = NULL;
1247 Handle item;
1248 Str255 text;
1249 if (!PyArg_ParseTuple(_args, "O&O&",
1250 ResObj_Convert, &item,
1251 PyMac_GetStr255, text))
1252 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001253 SetDialogItemText(item,
1254 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001255 Py_INCREF(Py_None);
1256 _res = Py_None;
1257 return _res;
1258}
1259
Jack Jansenae8a68f1995-06-06 12:55:40 +00001260static PyObject *Dlg_GetAlertStage(_self, _args)
1261 PyObject *_self;
1262 PyObject *_args;
1263{
1264 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001265 SInt16 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001266 if (!PyArg_ParseTuple(_args, ""))
1267 return NULL;
1268 _rv = GetAlertStage();
1269 _res = Py_BuildValue("h",
1270 _rv);
1271 return _res;
1272}
1273
Jack Jansen21f96871998-02-20 16:02:09 +00001274static PyObject *Dlg_SetDialogFont(_self, _args)
1275 PyObject *_self;
1276 PyObject *_args;
1277{
1278 PyObject *_res = NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001279 SInt16 fontNum;
Jack Jansen21f96871998-02-20 16:02:09 +00001280 if (!PyArg_ParseTuple(_args, "h",
Jack Jansena05ac601999-12-12 21:41:51 +00001281 &fontNum))
Jack Jansen21f96871998-02-20 16:02:09 +00001282 return NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001283 SetDialogFont(fontNum);
Jack Jansen21f96871998-02-20 16:02:09 +00001284 Py_INCREF(Py_None);
1285 _res = Py_None;
1286 return _res;
1287}
1288
Jack Jansenae8a68f1995-06-06 12:55:40 +00001289static PyObject *Dlg_ResetAlertStage(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001290 PyObject *_self;
1291 PyObject *_args;
1292{
1293 PyObject *_res = NULL;
1294 if (!PyArg_ParseTuple(_args, ""))
1295 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001296 ResetAlertStage();
Guido van Rossum17448e21995-01-30 11:53:55 +00001297 Py_INCREF(Py_None);
1298 _res = Py_None;
1299 return _res;
1300}
1301
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001302#if TARGET_API_MAC_CARBON
1303
1304static PyObject *Dlg_GetParamText(_self, _args)
1305 PyObject *_self;
1306 PyObject *_args;
1307{
1308 PyObject *_res = NULL;
1309 Str255 param0;
1310 Str255 param1;
1311 Str255 param2;
1312 Str255 param3;
1313 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1314 PyMac_GetStr255, param0,
1315 PyMac_GetStr255, param1,
1316 PyMac_GetStr255, param2,
1317 PyMac_GetStr255, param3))
1318 return NULL;
1319 GetParamText(param0,
1320 param1,
1321 param2,
1322 param3);
1323 Py_INCREF(Py_None);
1324 _res = Py_None;
1325 return _res;
1326}
1327#endif
1328
Jack Jansen21f96871998-02-20 16:02:09 +00001329static PyObject *Dlg_NewFeaturesDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001330 PyObject *_self;
1331 PyObject *_args;
1332{
1333 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001334 DialogPtr _rv;
1335 Rect inBoundsRect;
1336 Str255 inTitle;
1337 Boolean inIsVisible;
1338 SInt16 inProcID;
1339 WindowPtr inBehind;
1340 Boolean inGoAwayFlag;
1341 SInt32 inRefCon;
1342 Handle inItemListHandle;
1343 UInt32 inFlags;
1344 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
1345 PyMac_GetRect, &inBoundsRect,
1346 PyMac_GetStr255, inTitle,
1347 &inIsVisible,
1348 &inProcID,
1349 WinObj_Convert, &inBehind,
1350 &inGoAwayFlag,
1351 &inRefCon,
1352 ResObj_Convert, &inItemListHandle,
1353 &inFlags))
Guido van Rossum17448e21995-01-30 11:53:55 +00001354 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001355 _rv = NewFeaturesDialog((void *)0,
1356 &inBoundsRect,
1357 inTitle,
1358 inIsVisible,
1359 inProcID,
1360 inBehind,
1361 inGoAwayFlag,
1362 inRefCon,
1363 inItemListHandle,
1364 inFlags);
1365 _res = Py_BuildValue("O&",
1366 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +00001367 return _res;
1368}
1369
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001370static PyObject *Dlg_GetDialogFromWindow(_self, _args)
1371 PyObject *_self;
1372 PyObject *_args;
1373{
1374 PyObject *_res = NULL;
1375 DialogPtr _rv;
1376 WindowPtr window;
1377 if (!PyArg_ParseTuple(_args, "O&",
1378 WinObj_Convert, &window))
1379 return NULL;
1380 _rv = GetDialogFromWindow(window);
1381 _res = Py_BuildValue("O&",
1382 DlgObj_New, _rv);
1383 return _res;
1384}
1385
Jack Jansendf901df1998-07-10 15:47:48 +00001386static PyObject *Dlg_SetUserItemHandler(_self, _args)
1387 PyObject *_self;
1388 PyObject *_args;
1389{
1390 PyObject *_res = NULL;
1391
1392 PyObject *new = NULL;
1393
1394
1395 if (!PyArg_ParseTuple(_args, "|O", &new))
1396 return NULL;
1397
1398 if (Dlg_UserItemProc_callback && new && new != Py_None) {
1399 PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
1400 return NULL;
1401 }
1402
1403 if (new == Py_None) {
1404 new = NULL;
1405 _res = Py_None;
1406 Py_INCREF(Py_None);
1407 } else {
1408 Py_INCREF(new);
1409 _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc));
1410 }
1411
1412 Dlg_UserItemProc_callback = new;
1413 return _res;
1414
1415}
1416
Guido van Rossum17448e21995-01-30 11:53:55 +00001417static PyMethodDef Dlg_methods[] = {
1418 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001419 "(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 +00001420 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001421 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1422 {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
1423 "(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 +00001424 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001425 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001426 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
1427 "(EventRecord theEvent) -> (Boolean _rv)"},
1428 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001429 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001430 {"Alert", (PyCFunction)Dlg_Alert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001431 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001432 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001433 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001434 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001435 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001436 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001437 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1438 {"ParamText", (PyCFunction)Dlg_ParamText, 1,
1439 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001440 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001441 "(Handle item) -> (Str255 text)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001442 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001443 "(Handle item, Str255 text) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001444 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001445 "() -> (SInt16 _rv)"},
1446 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
Jack Jansena05ac601999-12-12 21:41:51 +00001447 "(SInt16 fontNum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001448 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001449 "() -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001450
1451#if TARGET_API_MAC_CARBON
1452 {"GetParamText", (PyCFunction)Dlg_GetParamText, 1,
1453 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1454#endif
Jack Jansen21f96871998-02-20 16:02:09 +00001455 {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
1456 "(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 +00001457 {"GetDialogFromWindow", (PyCFunction)Dlg_GetDialogFromWindow, 1,
1458 "(WindowPtr window) -> (DialogPtr _rv)"},
Jack Jansendf901df1998-07-10 15:47:48 +00001459 {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
1460 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001461 {NULL, NULL, 0}
1462};
1463
1464
1465
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001466/* Return the WindowPtr corresponding to a DialogObject */
1467
1468WindowPtr
1469DlgObj_ConvertToWindow(self)
1470 PyObject *self;
1471{
1472 if ( DlgObj_Check(self) )
1473 return GetDialogWindow(((DialogObject *)self)->ob_itself);
1474 return NULL;
1475}
Jack Jansen69e7f112001-02-06 16:14:54 +00001476/* Return the object corresponding to the dialog, or None */
1477
1478PyObject *
1479DlgObj_WhichDialog(d)
1480 DialogPtr d;
1481{
1482 PyObject *it;
1483
1484 if (d == NULL) {
1485 it = Py_None;
1486 Py_INCREF(it);
1487 } else {
1488 WindowPtr w = GetDialogWindow(d);
1489
1490 it = (PyObject *) GetWRefCon(w);
1491 if (it == NULL || ((DialogObject *)it)->ob_itself != d || !DlgObj_Check(it)) {
1492#if 0
1493 /* Should do this, but we don't have an ob_freeit for dialogs yet. */
1494 it = WinObj_New(w);
1495 ((WindowObject *)it)->ob_freeit = NULL;
1496#else
1497 it = Py_None;
1498 Py_INCREF(it);
1499#endif
1500 } else {
1501 Py_INCREF(it);
1502 }
1503 }
1504 return it;
1505}
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001506
Guido van Rossum17448e21995-01-30 11:53:55 +00001507
1508void initDlg()
1509{
1510 PyObject *m;
1511 PyObject *d;
1512
1513
1514
1515
1516 m = Py_InitModule("Dlg", Dlg_methods);
1517 d = PyModule_GetDict(m);
1518 Dlg_Error = PyMac_GetOSErrException();
1519 if (Dlg_Error == NULL ||
1520 PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001521 return;
Jack Jansena755e681997-09-20 17:40:22 +00001522 Dialog_Type.ob_type = &PyType_Type;
1523 Py_INCREF(&Dialog_Type);
1524 if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0)
1525 Py_FatalError("can't initialize DialogType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001526}
1527
1528/* ========================= End module Dlg ========================= */
1529