blob: be68b75c107fc8d5c57ed3bb63d6fa1cb067d21b [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>
Jack Jansen0e04eec2001-05-17 21:58:34 +000012#ifdef USE_TOOLBOX_OBJECT_GLUE
13extern PyObject *_DlgObj_New(DialogRef);
14extern PyObject *_DlgObj_WhichDialog(DialogRef);
15extern int _DlgObj_Convert(PyObject *, DialogRef *);
16
17#define DlgObj_New _DlgObj_New
18#define DlgObj_WhichDialog _DlgObj_WhichDialog
19#define DlgObj_Convert _DlgObj_Convert
20#endif
Guido van Rossum17448e21995-01-30 11:53:55 +000021
Jack Jansenf7d5aa62000-12-10 23:43:49 +000022#if !ACCESSOR_CALLS_ARE_FUNCTIONS
23#define GetDialogTextEditHandle(dlg) (((DialogPeek)(dlg))->textH)
24#define SetPortDialogPort(dlg) SetPort(dlg)
25#define GetDialogPort(dlg) ((CGrafPtr)(dlg))
26#define GetDialogFromWindow(win) ((DialogRef)(win))
27#endif
28
Guido van Rossum17448e21995-01-30 11:53:55 +000029/* XXX Shouldn't this be a stack? */
30static PyObject *Dlg_FilterProc_callback = NULL;
31
Guido van Rossum17448e21995-01-30 11:53:55 +000032static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog,
33 EventRecord *event,
34 short *itemHit)
35{
36 Boolean rv;
37 PyObject *args, *res;
38 PyObject *callback = Dlg_FilterProc_callback;
39 if (callback == NULL)
40 return 0; /* Default behavior */
41 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
Jack Jansen69e7f112001-02-06 16:14:54 +000042 args = Py_BuildValue("O&O&", DlgObj_WhichDialog, dialog, PyMac_BuildEventRecord, event);
Guido van Rossum17448e21995-01-30 11:53:55 +000043 if (args == NULL)
44 res = NULL;
45 else {
46 res = PyEval_CallObject(callback, args);
47 Py_DECREF(args);
48 }
49 if (res == NULL) {
Jack Jansendeff89c1998-10-12 20:53:15 +000050 PySys_WriteStderr("Exception in Dialog Filter\n");
Guido van Rossum17448e21995-01-30 11:53:55 +000051 PyErr_Print();
52 *itemHit = -1; /* Fake return item */
53 return 1; /* We handled it */
54 }
55 else {
56 Dlg_FilterProc_callback = callback;
57 if (PyInt_Check(res)) {
58 *itemHit = PyInt_AsLong(res);
59 rv = 1;
60 }
61 else
62 rv = PyObject_IsTrue(res);
63 }
64 Py_DECREF(res);
65 return rv;
66}
67
Jack Jansen599ce9c2001-02-20 22:27:43 +000068static ModalFilterUPP
Guido van Rossum17448e21995-01-30 11:53:55 +000069Dlg_PassFilterProc(PyObject *callback)
70{
71 PyObject *tmp = Dlg_FilterProc_callback;
Jack Jansen599ce9c2001-02-20 22:27:43 +000072 static ModalFilterUPP UnivFilterUpp = NULL;
73
Guido van Rossum17448e21995-01-30 11:53:55 +000074 Dlg_FilterProc_callback = NULL;
75 if (callback == Py_None) {
76 Py_XDECREF(tmp);
77 return NULL;
78 }
79 Py_INCREF(callback);
80 Dlg_FilterProc_callback = callback;
81 Py_XDECREF(tmp);
Jack Jansen599ce9c2001-02-20 22:27:43 +000082 if ( UnivFilterUpp == NULL )
83 UnivFilterUpp = NewModalFilterUPP(&Dlg_UnivFilterProc);
84 return UnivFilterUpp;
Guido van Rossum17448e21995-01-30 11:53:55 +000085}
86
Jack Jansendf901df1998-07-10 15:47:48 +000087static PyObject *Dlg_UserItemProc_callback = NULL;
88
89static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
90 short item)
91{
92 PyObject *args, *res;
93
94 if (Dlg_UserItemProc_callback == NULL)
95 return; /* Default behavior */
96 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
Jack Jansen69e7f112001-02-06 16:14:54 +000097 args = Py_BuildValue("O&h", DlgObj_WhichDialog, dialog, item);
Jack Jansendf901df1998-07-10 15:47:48 +000098 if (args == NULL)
99 res = NULL;
100 else {
101 res = PyEval_CallObject(Dlg_UserItemProc_callback, args);
102 Py_DECREF(args);
103 }
104 if (res == NULL) {
Jack Jansendeff89c1998-10-12 20:53:15 +0000105 PySys_WriteStderr("Exception in Dialog UserItem proc\n");
Jack Jansendf901df1998-07-10 15:47:48 +0000106 PyErr_Print();
107 }
108 Py_XDECREF(res);
109 return;
110}
111
Jack Jansen69e7f112001-02-06 16:14:54 +0000112#if 0
Jack Jansenb8c4c7b2000-08-25 22:25:54 +0000113/*
114** Treating DialogObjects as WindowObjects is (I think) illegal under Carbon.
115** However, as they are still identical under MacOS9 Carbon this is a problem, even
116** if we neatly call GetDialogWindow() at the right places: there's one refcon field
117** and it points to the DialogObject, so WinObj_WhichWindow will smartly return the
118** dialog object, and therefore we still don't have a WindowObject.
119** I'll leave the chaining code in place for now, with this comment to warn the
120** unsuspecting victims (i.e. me, probably, in a few weeks:-)
121*/
Guido van Rossum17448e21995-01-30 11:53:55 +0000122extern PyMethodChain WinObj_chain;
Jack Jansenb8c4c7b2000-08-25 22:25:54 +0000123#endif
Guido van Rossum17448e21995-01-30 11:53:55 +0000124
125static PyObject *Dlg_Error;
126
127/* ----------------------- Object type Dialog ----------------------- */
128
129PyTypeObject Dialog_Type;
130
131#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
132
133typedef struct DialogObject {
134 PyObject_HEAD
135 DialogPtr ob_itself;
136} DialogObject;
137
138PyObject *DlgObj_New(itself)
Guido van Rossum97842951995-02-19 15:59:49 +0000139 DialogPtr itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000140{
141 DialogObject *it;
142 if (itself == NULL) return Py_None;
143 it = PyObject_NEW(DialogObject, &Dialog_Type);
144 if (it == NULL) return NULL;
145 it->ob_itself = itself;
Jack Jansene79dc762000-06-02 21:35:07 +0000146 SetWRefCon(GetDialogWindow(itself), (long)it);
Guido van Rossum17448e21995-01-30 11:53:55 +0000147 return (PyObject *)it;
148}
149DlgObj_Convert(v, p_itself)
150 PyObject *v;
151 DialogPtr *p_itself;
152{
153 if (v == Py_None) { *p_itself = NULL; return 1; }
154 if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
155 return 1; }
156 if (!DlgObj_Check(v))
157 {
158 PyErr_SetString(PyExc_TypeError, "Dialog required");
159 return 0;
160 }
161 *p_itself = ((DialogObject *)v)->ob_itself;
162 return 1;
163}
164
165static void DlgObj_dealloc(self)
166 DialogObject *self;
167{
168 DisposeDialog(self->ob_itself);
169 PyMem_DEL(self);
170}
171
172static PyObject *DlgObj_DrawDialog(_self, _args)
173 DialogObject *_self;
174 PyObject *_args;
175{
176 PyObject *_res = NULL;
177 if (!PyArg_ParseTuple(_args, ""))
178 return NULL;
179 DrawDialog(_self->ob_itself);
180 Py_INCREF(Py_None);
181 _res = Py_None;
182 return _res;
183}
184
Guido van Rossum17448e21995-01-30 11:53:55 +0000185static PyObject *DlgObj_UpdateDialog(_self, _args)
186 DialogObject *_self;
187 PyObject *_args;
188{
189 PyObject *_res = NULL;
Jack Jansen2b724171996-04-10 14:48:19 +0000190 RgnHandle updateRgn;
191 if (!PyArg_ParseTuple(_args, "O&",
192 ResObj_Convert, &updateRgn))
Guido van Rossum17448e21995-01-30 11:53:55 +0000193 return NULL;
194 UpdateDialog(_self->ob_itself,
Jack Jansen2b724171996-04-10 14:48:19 +0000195 updateRgn);
Guido van Rossum17448e21995-01-30 11:53:55 +0000196 Py_INCREF(Py_None);
197 _res = Py_None;
198 return _res;
199}
200
Jack Jansenae8a68f1995-06-06 12:55:40 +0000201static PyObject *DlgObj_HideDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000202 DialogObject *_self;
203 PyObject *_args;
204{
205 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000206 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000207 if (!PyArg_ParseTuple(_args, "h",
208 &itemNo))
209 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000210 HideDialogItem(_self->ob_itself,
211 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000212 Py_INCREF(Py_None);
213 _res = Py_None;
214 return _res;
215}
216
Jack Jansenae8a68f1995-06-06 12:55:40 +0000217static PyObject *DlgObj_ShowDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000218 DialogObject *_self;
219 PyObject *_args;
220{
221 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000222 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000223 if (!PyArg_ParseTuple(_args, "h",
224 &itemNo))
225 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000226 ShowDialogItem(_self->ob_itself,
227 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000228 Py_INCREF(Py_None);
229 _res = Py_None;
230 return _res;
231}
232
Jack Jansenae8a68f1995-06-06 12:55:40 +0000233static PyObject *DlgObj_FindDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000234 DialogObject *_self;
235 PyObject *_args;
236{
237 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000238 DialogItemIndexZeroBased _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000239 Point thePt;
240 if (!PyArg_ParseTuple(_args, "O&",
241 PyMac_GetPoint, &thePt))
242 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000243 _rv = FindDialogItem(_self->ob_itself,
244 thePt);
Guido van Rossum17448e21995-01-30 11:53:55 +0000245 _res = Py_BuildValue("h",
246 _rv);
247 return _res;
248}
249
Jack Jansenae8a68f1995-06-06 12:55:40 +0000250static PyObject *DlgObj_DialogCut(_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 DialogCut(_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_DialogPaste(_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 DialogPaste(_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_DialogCopy(_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 DialogCopy(_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 Jansenae8a68f1995-06-06 12:55:40 +0000289static PyObject *DlgObj_DialogDelete(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000290 DialogObject *_self;
291 PyObject *_args;
292{
293 PyObject *_res = NULL;
294 if (!PyArg_ParseTuple(_args, ""))
295 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000296 DialogDelete(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000297 Py_INCREF(Py_None);
298 _res = Py_None;
299 return _res;
300}
301
Jack Jansen21f96871998-02-20 16:02:09 +0000302static PyObject *DlgObj_GetDialogItem(_self, _args)
303 DialogObject *_self;
304 PyObject *_args;
305{
306 PyObject *_res = NULL;
307 DialogItemIndex itemNo;
308 DialogItemType itemType;
309 Handle item;
310 Rect box;
311 if (!PyArg_ParseTuple(_args, "h",
312 &itemNo))
313 return NULL;
314 GetDialogItem(_self->ob_itself,
315 itemNo,
316 &itemType,
317 &item,
318 &box);
319 _res = Py_BuildValue("hO&O&",
320 itemType,
321 OptResObj_New, item,
322 PyMac_BuildRect, &box);
323 return _res;
324}
325
326static PyObject *DlgObj_SetDialogItem(_self, _args)
327 DialogObject *_self;
328 PyObject *_args;
329{
330 PyObject *_res = NULL;
331 DialogItemIndex itemNo;
332 DialogItemType itemType;
333 Handle item;
334 Rect box;
335 if (!PyArg_ParseTuple(_args, "hhO&O&",
336 &itemNo,
337 &itemType,
338 ResObj_Convert, &item,
339 PyMac_GetRect, &box))
340 return NULL;
341 SetDialogItem(_self->ob_itself,
342 itemNo,
343 itemType,
344 item,
345 &box);
346 Py_INCREF(Py_None);
347 _res = Py_None;
348 return _res;
349}
350
351static PyObject *DlgObj_SelectDialogItemText(_self, _args)
352 DialogObject *_self;
353 PyObject *_args;
354{
355 PyObject *_res = NULL;
356 DialogItemIndex itemNo;
357 SInt16 strtSel;
358 SInt16 endSel;
359 if (!PyArg_ParseTuple(_args, "hhh",
360 &itemNo,
361 &strtSel,
362 &endSel))
363 return NULL;
364 SelectDialogItemText(_self->ob_itself,
365 itemNo,
366 strtSel,
367 endSel);
368 Py_INCREF(Py_None);
369 _res = Py_None;
370 return _res;
371}
372
Guido van Rossum17448e21995-01-30 11:53:55 +0000373static PyObject *DlgObj_AppendDITL(_self, _args)
374 DialogObject *_self;
375 PyObject *_args;
376{
377 PyObject *_res = NULL;
378 Handle theHandle;
379 DITLMethod method;
380 if (!PyArg_ParseTuple(_args, "O&h",
381 ResObj_Convert, &theHandle,
382 &method))
383 return NULL;
384 AppendDITL(_self->ob_itself,
385 theHandle,
386 method);
387 Py_INCREF(Py_None);
388 _res = Py_None;
389 return _res;
390}
391
392static PyObject *DlgObj_CountDITL(_self, _args)
393 DialogObject *_self;
394 PyObject *_args;
395{
396 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000397 DialogItemIndex _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000398 if (!PyArg_ParseTuple(_args, ""))
399 return NULL;
400 _rv = CountDITL(_self->ob_itself);
401 _res = Py_BuildValue("h",
402 _rv);
403 return _res;
404}
405
406static PyObject *DlgObj_ShortenDITL(_self, _args)
407 DialogObject *_self;
408 PyObject *_args;
409{
410 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000411 DialogItemIndex numberItems;
Guido van Rossum17448e21995-01-30 11:53:55 +0000412 if (!PyArg_ParseTuple(_args, "h",
413 &numberItems))
414 return NULL;
415 ShortenDITL(_self->ob_itself,
416 numberItems);
417 Py_INCREF(Py_None);
418 _res = Py_None;
419 return _res;
420}
421
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000422#if TARGET_API_MAC_CARBON
423
424static PyObject *DlgObj_InsertDialogItem(_self, _args)
425 DialogObject *_self;
426 PyObject *_args;
427{
428 PyObject *_res = NULL;
429 OSStatus _err;
430 DialogItemIndex afterItem;
431 DialogItemType itemType;
432 Handle itemHandle;
433 Rect box;
434 if (!PyArg_ParseTuple(_args, "hhO&O&",
435 &afterItem,
436 &itemType,
437 ResObj_Convert, &itemHandle,
438 PyMac_GetRect, &box))
439 return NULL;
440 _err = InsertDialogItem(_self->ob_itself,
441 afterItem,
442 itemType,
443 itemHandle,
444 &box);
445 if (_err != noErr) return PyMac_Error(_err);
446 Py_INCREF(Py_None);
447 _res = Py_None;
448 return _res;
449}
450#endif
451
452#if TARGET_API_MAC_CARBON
453
454static PyObject *DlgObj_RemoveDialogItems(_self, _args)
455 DialogObject *_self;
456 PyObject *_args;
457{
458 PyObject *_res = NULL;
459 OSStatus _err;
460 DialogItemIndex itemNo;
461 DialogItemIndex amountToRemove;
462 Boolean disposeItemData;
463 if (!PyArg_ParseTuple(_args, "hhb",
464 &itemNo,
465 &amountToRemove,
466 &disposeItemData))
467 return NULL;
468 _err = RemoveDialogItems(_self->ob_itself,
469 itemNo,
470 amountToRemove,
471 disposeItemData);
472 if (_err != noErr) return PyMac_Error(_err);
473 Py_INCREF(Py_None);
474 _res = Py_None;
475 return _res;
476}
477#endif
478
Jack Jansenae8a68f1995-06-06 12:55:40 +0000479static PyObject *DlgObj_StdFilterProc(_self, _args)
480 DialogObject *_self;
481 PyObject *_args;
482{
483 PyObject *_res = NULL;
484 Boolean _rv;
485 EventRecord event;
Jack Jansen21f96871998-02-20 16:02:09 +0000486 DialogItemIndex itemHit;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000487 if (!PyArg_ParseTuple(_args, ""))
488 return NULL;
489 _rv = StdFilterProc(_self->ob_itself,
490 &event,
491 &itemHit);
492 _res = Py_BuildValue("bO&h",
493 _rv,
494 PyMac_BuildEventRecord, &event,
495 itemHit);
496 return _res;
497}
498
499static PyObject *DlgObj_SetDialogDefaultItem(_self, _args)
500 DialogObject *_self;
501 PyObject *_args;
502{
503 PyObject *_res = NULL;
504 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000505 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000506 if (!PyArg_ParseTuple(_args, "h",
507 &newItem))
508 return NULL;
509 _err = SetDialogDefaultItem(_self->ob_itself,
510 newItem);
511 if (_err != noErr) return PyMac_Error(_err);
512 Py_INCREF(Py_None);
513 _res = Py_None;
514 return _res;
515}
516
517static PyObject *DlgObj_SetDialogCancelItem(_self, _args)
518 DialogObject *_self;
519 PyObject *_args;
520{
521 PyObject *_res = NULL;
522 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000523 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000524 if (!PyArg_ParseTuple(_args, "h",
525 &newItem))
526 return NULL;
527 _err = SetDialogCancelItem(_self->ob_itself,
528 newItem);
529 if (_err != noErr) return PyMac_Error(_err);
530 Py_INCREF(Py_None);
531 _res = Py_None;
532 return _res;
533}
534
535static PyObject *DlgObj_SetDialogTracksCursor(_self, _args)
536 DialogObject *_self;
537 PyObject *_args;
538{
539 PyObject *_res = NULL;
540 OSErr _err;
541 Boolean tracks;
542 if (!PyArg_ParseTuple(_args, "b",
543 &tracks))
544 return NULL;
545 _err = SetDialogTracksCursor(_self->ob_itself,
546 tracks);
547 if (_err != noErr) return PyMac_Error(_err);
548 Py_INCREF(Py_None);
549 _res = Py_None;
550 return _res;
551}
552
Jack Jansen21f96871998-02-20 16:02:09 +0000553static PyObject *DlgObj_AutoSizeDialog(_self, _args)
554 DialogObject *_self;
555 PyObject *_args;
556{
557 PyObject *_res = NULL;
558 OSErr _err;
559 if (!PyArg_ParseTuple(_args, ""))
560 return NULL;
561 _err = AutoSizeDialog(_self->ob_itself);
562 if (_err != noErr) return PyMac_Error(_err);
563 Py_INCREF(Py_None);
564 _res = Py_None;
565 return _res;
566}
567
568static PyObject *DlgObj_GetDialogItemAsControl(_self, _args)
569 DialogObject *_self;
570 PyObject *_args;
571{
572 PyObject *_res = NULL;
573 OSErr _err;
574 SInt16 inItemNo;
575 ControlHandle outControl;
576 if (!PyArg_ParseTuple(_args, "h",
577 &inItemNo))
578 return NULL;
579 _err = GetDialogItemAsControl(_self->ob_itself,
580 inItemNo,
581 &outControl);
582 if (_err != noErr) return PyMac_Error(_err);
583 _res = Py_BuildValue("O&",
584 CtlObj_New, outControl);
585 return _res;
586}
587
588static PyObject *DlgObj_MoveDialogItem(_self, _args)
589 DialogObject *_self;
590 PyObject *_args;
591{
592 PyObject *_res = NULL;
593 OSErr _err;
594 SInt16 inItemNo;
595 SInt16 inHoriz;
596 SInt16 inVert;
597 if (!PyArg_ParseTuple(_args, "hhh",
598 &inItemNo,
599 &inHoriz,
600 &inVert))
601 return NULL;
602 _err = MoveDialogItem(_self->ob_itself,
603 inItemNo,
604 inHoriz,
605 inVert);
606 if (_err != noErr) return PyMac_Error(_err);
607 Py_INCREF(Py_None);
608 _res = Py_None;
609 return _res;
610}
611
612static PyObject *DlgObj_SizeDialogItem(_self, _args)
613 DialogObject *_self;
614 PyObject *_args;
615{
616 PyObject *_res = NULL;
617 OSErr _err;
618 SInt16 inItemNo;
Jack Jansen21f96871998-02-20 16:02:09 +0000619 SInt16 inWidth;
Jack Jansen1c4e6141998-04-21 15:23:55 +0000620 SInt16 inHeight;
Jack Jansen21f96871998-02-20 16:02:09 +0000621 if (!PyArg_ParseTuple(_args, "hhh",
622 &inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000623 &inWidth,
624 &inHeight))
Jack Jansen21f96871998-02-20 16:02:09 +0000625 return NULL;
626 _err = SizeDialogItem(_self->ob_itself,
627 inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000628 inWidth,
629 inHeight);
Jack Jansen21f96871998-02-20 16:02:09 +0000630 if (_err != noErr) return PyMac_Error(_err);
631 Py_INCREF(Py_None);
632 _res = Py_None;
633 return _res;
634}
635
Jack Jansena05ac601999-12-12 21:41:51 +0000636static PyObject *DlgObj_AppendDialogItemList(_self, _args)
637 DialogObject *_self;
638 PyObject *_args;
639{
640 PyObject *_res = NULL;
641 OSErr _err;
642 SInt16 ditlID;
643 DITLMethod method;
644 if (!PyArg_ParseTuple(_args, "hh",
645 &ditlID,
646 &method))
647 return NULL;
648 _err = AppendDialogItemList(_self->ob_itself,
649 ditlID,
650 method);
651 if (_err != noErr) return PyMac_Error(_err);
652 Py_INCREF(Py_None);
653 _res = Py_None;
654 return _res;
655}
656
657static PyObject *DlgObj_SetDialogTimeout(_self, _args)
658 DialogObject *_self;
659 PyObject *_args;
660{
661 PyObject *_res = NULL;
662 OSStatus _err;
663 SInt16 inButtonToPress;
664 UInt32 inSecondsToWait;
665 if (!PyArg_ParseTuple(_args, "hl",
666 &inButtonToPress,
667 &inSecondsToWait))
668 return NULL;
669 _err = SetDialogTimeout(_self->ob_itself,
670 inButtonToPress,
671 inSecondsToWait);
672 if (_err != noErr) return PyMac_Error(_err);
673 Py_INCREF(Py_None);
674 _res = Py_None;
675 return _res;
676}
677
678static PyObject *DlgObj_GetDialogTimeout(_self, _args)
679 DialogObject *_self;
680 PyObject *_args;
681{
682 PyObject *_res = NULL;
683 OSStatus _err;
684 SInt16 outButtonToPress;
685 UInt32 outSecondsToWait;
686 UInt32 outSecondsRemaining;
687 if (!PyArg_ParseTuple(_args, ""))
688 return NULL;
689 _err = GetDialogTimeout(_self->ob_itself,
690 &outButtonToPress,
691 &outSecondsToWait,
692 &outSecondsRemaining);
693 if (_err != noErr) return PyMac_Error(_err);
694 _res = Py_BuildValue("hll",
695 outButtonToPress,
696 outSecondsToWait,
697 outSecondsRemaining);
698 return _res;
699}
700
701static PyObject *DlgObj_SetModalDialogEventMask(_self, _args)
702 DialogObject *_self;
703 PyObject *_args;
704{
705 PyObject *_res = NULL;
706 OSStatus _err;
707 EventMask inMask;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000708 if (!PyArg_ParseTuple(_args, "H",
Jack Jansena05ac601999-12-12 21:41:51 +0000709 &inMask))
710 return NULL;
711 _err = SetModalDialogEventMask(_self->ob_itself,
712 inMask);
713 if (_err != noErr) return PyMac_Error(_err);
714 Py_INCREF(Py_None);
715 _res = Py_None;
716 return _res;
717}
718
719static PyObject *DlgObj_GetModalDialogEventMask(_self, _args)
720 DialogObject *_self;
721 PyObject *_args;
722{
723 PyObject *_res = NULL;
724 OSStatus _err;
725 EventMask outMask;
726 if (!PyArg_ParseTuple(_args, ""))
727 return NULL;
728 _err = GetModalDialogEventMask(_self->ob_itself,
729 &outMask);
730 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000731 _res = Py_BuildValue("H",
Jack Jansena05ac601999-12-12 21:41:51 +0000732 outMask);
733 return _res;
734}
735
Jack Jansend96cb501996-09-23 15:48:46 +0000736static PyObject *DlgObj_GetDialogWindow(_self, _args)
737 DialogObject *_self;
738 PyObject *_args;
739{
740 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000741 WindowPtr _rv;
Jack Jansend96cb501996-09-23 15:48:46 +0000742 if (!PyArg_ParseTuple(_args, ""))
743 return NULL;
744 _rv = GetDialogWindow(_self->ob_itself);
745 _res = Py_BuildValue("O&",
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000746 WinObj_New, _rv);
747 return _res;
748}
749
750static PyObject *DlgObj_GetDialogTextEditHandle(_self, _args)
751 DialogObject *_self;
752 PyObject *_args;
753{
754 PyObject *_res = NULL;
755 TEHandle _rv;
756 if (!PyArg_ParseTuple(_args, ""))
757 return NULL;
758 _rv = GetDialogTextEditHandle(_self->ob_itself);
759 _res = Py_BuildValue("O&",
760 ResObj_New, _rv);
Jack Jansend96cb501996-09-23 15:48:46 +0000761 return _res;
762}
763
764static PyObject *DlgObj_GetDialogDefaultItem(_self, _args)
765 DialogObject *_self;
766 PyObject *_args;
767{
768 PyObject *_res = NULL;
769 SInt16 _rv;
770 if (!PyArg_ParseTuple(_args, ""))
771 return NULL;
772 _rv = GetDialogDefaultItem(_self->ob_itself);
773 _res = Py_BuildValue("h",
774 _rv);
775 return _res;
776}
777
778static PyObject *DlgObj_GetDialogCancelItem(_self, _args)
779 DialogObject *_self;
780 PyObject *_args;
781{
782 PyObject *_res = NULL;
783 SInt16 _rv;
784 if (!PyArg_ParseTuple(_args, ""))
785 return NULL;
786 _rv = GetDialogCancelItem(_self->ob_itself);
787 _res = Py_BuildValue("h",
788 _rv);
789 return _res;
790}
791
792static PyObject *DlgObj_GetDialogKeyboardFocusItem(_self, _args)
793 DialogObject *_self;
794 PyObject *_args;
795{
796 PyObject *_res = NULL;
797 SInt16 _rv;
798 if (!PyArg_ParseTuple(_args, ""))
799 return NULL;
800 _rv = GetDialogKeyboardFocusItem(_self->ob_itself);
801 _res = Py_BuildValue("h",
802 _rv);
803 return _res;
804}
805
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000806static PyObject *DlgObj_SetPortDialogPort(_self, _args)
807 DialogObject *_self;
808 PyObject *_args;
809{
810 PyObject *_res = NULL;
811 if (!PyArg_ParseTuple(_args, ""))
812 return NULL;
813 SetPortDialogPort(_self->ob_itself);
814 Py_INCREF(Py_None);
815 _res = Py_None;
816 return _res;
817}
818
819static PyObject *DlgObj_GetDialogPort(_self, _args)
820 DialogObject *_self;
821 PyObject *_args;
822{
823 PyObject *_res = NULL;
824 CGrafPtr _rv;
825 if (!PyArg_ParseTuple(_args, ""))
826 return NULL;
827 _rv = GetDialogPort(_self->ob_itself);
828 _res = Py_BuildValue("O&",
829 GrafObj_New, _rv);
830 return _res;
831}
832
Jack Jansen74a1e632000-07-14 22:37:27 +0000833#if !TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000834
Jack Jansend96cb501996-09-23 15:48:46 +0000835static PyObject *DlgObj_SetGrafPortOfDialog(_self, _args)
836 DialogObject *_self;
837 PyObject *_args;
838{
839 PyObject *_res = NULL;
840 if (!PyArg_ParseTuple(_args, ""))
841 return NULL;
842 SetGrafPortOfDialog(_self->ob_itself);
843 Py_INCREF(Py_None);
844 _res = Py_None;
845 return _res;
846}
Jack Jansene79dc762000-06-02 21:35:07 +0000847#endif
Jack Jansend96cb501996-09-23 15:48:46 +0000848
Guido van Rossum17448e21995-01-30 11:53:55 +0000849static PyMethodDef DlgObj_methods[] = {
850 {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
851 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000852 {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
Jack Jansen2b724171996-04-10 14:48:19 +0000853 "(RgnHandle updateRgn) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000854 {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000855 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000856 {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000857 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000858 {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000859 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000860 {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000861 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000862 {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000863 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000864 {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000865 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000866 {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000867 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000868 {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1,
869 "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"},
870 {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1,
871 "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"},
872 {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1,
873 "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000874 {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
875 "(Handle theHandle, DITLMethod method) -> None"},
876 {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000877 "() -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000878 {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000879 "(DialogItemIndex numberItems) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000880
881#if TARGET_API_MAC_CARBON
882 {"InsertDialogItem", (PyCFunction)DlgObj_InsertDialogItem, 1,
883 "(DialogItemIndex afterItem, DialogItemType itemType, Handle itemHandle, Rect box) -> None"},
884#endif
885
886#if TARGET_API_MAC_CARBON
887 {"RemoveDialogItems", (PyCFunction)DlgObj_RemoveDialogItems, 1,
888 "(DialogItemIndex itemNo, DialogItemIndex amountToRemove, Boolean disposeItemData) -> None"},
889#endif
Jack Jansenae8a68f1995-06-06 12:55:40 +0000890 {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000891 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000892 {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000893 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000894 {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000895 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000896 {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
897 "(Boolean tracks) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000898 {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1,
899 "() -> None"},
900 {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1,
901 "(SInt16 inItemNo) -> (ControlHandle outControl)"},
902 {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1,
903 "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"},
904 {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000905 "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +0000906 {"AppendDialogItemList", (PyCFunction)DlgObj_AppendDialogItemList, 1,
907 "(SInt16 ditlID, DITLMethod method) -> None"},
908 {"SetDialogTimeout", (PyCFunction)DlgObj_SetDialogTimeout, 1,
909 "(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None"},
910 {"GetDialogTimeout", (PyCFunction)DlgObj_GetDialogTimeout, 1,
911 "() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)"},
912 {"SetModalDialogEventMask", (PyCFunction)DlgObj_SetModalDialogEventMask, 1,
913 "(EventMask inMask) -> None"},
914 {"GetModalDialogEventMask", (PyCFunction)DlgObj_GetModalDialogEventMask, 1,
915 "() -> (EventMask outMask)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000916 {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
Jack Jansene79dc762000-06-02 21:35:07 +0000917 "() -> (WindowPtr _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000918 {"GetDialogTextEditHandle", (PyCFunction)DlgObj_GetDialogTextEditHandle, 1,
919 "() -> (TEHandle _rv)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000920 {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1,
921 "() -> (SInt16 _rv)"},
922 {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1,
923 "() -> (SInt16 _rv)"},
924 {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1,
925 "() -> (SInt16 _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000926 {"SetPortDialogPort", (PyCFunction)DlgObj_SetPortDialogPort, 1,
927 "() -> None"},
928 {"GetDialogPort", (PyCFunction)DlgObj_GetDialogPort, 1,
929 "() -> (CGrafPtr _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +0000930
Jack Jansen74a1e632000-07-14 22:37:27 +0000931#if !TARGET_API_MAC_CARBON
Jack Jansend96cb501996-09-23 15:48:46 +0000932 {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1,
933 "() -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +0000934#endif
Guido van Rossum17448e21995-01-30 11:53:55 +0000935 {NULL, NULL, 0}
936};
937
Jack Jansen69e7f112001-02-06 16:14:54 +0000938PyMethodChain DlgObj_chain = { DlgObj_methods, NULL };
Guido van Rossum17448e21995-01-30 11:53:55 +0000939
940static PyObject *DlgObj_getattr(self, name)
941 DialogObject *self;
942 char *name;
943{
944 return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name);
945}
946
947#define DlgObj_setattr NULL
948
Jack Jansen69e7f112001-02-06 16:14:54 +0000949static int DlgObj_compare(self, other)
950 DialogObject *self, *other;
951{
952 if ( self->ob_itself > other->ob_itself ) return 1;
953 if ( self->ob_itself < other->ob_itself ) return -1;
954 return 0;
955}
Jack Jansena05ac601999-12-12 21:41:51 +0000956
957#define DlgObj_repr NULL
958
Jack Jansen69e7f112001-02-06 16:14:54 +0000959static int DlgObj_hash(self)
960 DialogObject *self;
961{
962 return (int)self->ob_itself;
963}
Jack Jansena05ac601999-12-12 21:41:51 +0000964
Guido van Rossum17448e21995-01-30 11:53:55 +0000965PyTypeObject Dialog_Type = {
966 PyObject_HEAD_INIT(&PyType_Type)
967 0, /*ob_size*/
968 "Dialog", /*tp_name*/
969 sizeof(DialogObject), /*tp_basicsize*/
970 0, /*tp_itemsize*/
971 /* methods */
972 (destructor) DlgObj_dealloc, /*tp_dealloc*/
973 0, /*tp_print*/
974 (getattrfunc) DlgObj_getattr, /*tp_getattr*/
975 (setattrfunc) DlgObj_setattr, /*tp_setattr*/
Jack Jansena05ac601999-12-12 21:41:51 +0000976 (cmpfunc) DlgObj_compare, /*tp_compare*/
977 (reprfunc) DlgObj_repr, /*tp_repr*/
978 (PyNumberMethods *)0, /* tp_as_number */
979 (PySequenceMethods *)0, /* tp_as_sequence */
980 (PyMappingMethods *)0, /* tp_as_mapping */
981 (hashfunc) DlgObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +0000982};
983
984/* --------------------- End object type Dialog --------------------- */
985
986
987static PyObject *Dlg_NewDialog(_self, _args)
988 PyObject *_self;
989 PyObject *_args;
990{
991 PyObject *_res = NULL;
992 DialogPtr _rv;
993 Rect boundsRect;
994 Str255 title;
995 Boolean visible;
Jack Jansen21f96871998-02-20 16:02:09 +0000996 SInt16 procID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000997 WindowPtr behind;
998 Boolean goAwayFlag;
Jack Jansen21f96871998-02-20 16:02:09 +0000999 SInt32 refCon;
1000 Handle items;
Guido van Rossum17448e21995-01-30 11:53:55 +00001001 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
1002 PyMac_GetRect, &boundsRect,
1003 PyMac_GetStr255, title,
1004 &visible,
1005 &procID,
1006 WinObj_Convert, &behind,
1007 &goAwayFlag,
1008 &refCon,
Jack Jansen21f96871998-02-20 16:02:09 +00001009 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +00001010 return NULL;
1011 _rv = NewDialog((void *)0,
1012 &boundsRect,
1013 title,
1014 visible,
1015 procID,
1016 behind,
1017 goAwayFlag,
1018 refCon,
Jack Jansen21f96871998-02-20 16:02:09 +00001019 items);
Guido van Rossum17448e21995-01-30 11:53:55 +00001020 _res = Py_BuildValue("O&",
1021 DlgObj_New, _rv);
1022 return _res;
1023}
1024
1025static PyObject *Dlg_GetNewDialog(_self, _args)
1026 PyObject *_self;
1027 PyObject *_args;
1028{
1029 PyObject *_res = NULL;
1030 DialogPtr _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001031 SInt16 dialogID;
Guido van Rossum17448e21995-01-30 11:53:55 +00001032 WindowPtr behind;
1033 if (!PyArg_ParseTuple(_args, "hO&",
1034 &dialogID,
1035 WinObj_Convert, &behind))
1036 return NULL;
1037 _rv = GetNewDialog(dialogID,
1038 (void *)0,
1039 behind);
1040 _res = Py_BuildValue("O&",
1041 DlgObj_New, _rv);
1042 return _res;
1043}
1044
Jack Jansen21f96871998-02-20 16:02:09 +00001045static PyObject *Dlg_NewColorDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001046 PyObject *_self;
1047 PyObject *_args;
1048{
1049 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001050 DialogPtr _rv;
1051 Rect boundsRect;
1052 Str255 title;
1053 Boolean visible;
1054 SInt16 procID;
1055 WindowPtr behind;
1056 Boolean goAwayFlag;
1057 SInt32 refCon;
1058 Handle items;
1059 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
1060 PyMac_GetRect, &boundsRect,
1061 PyMac_GetStr255, title,
1062 &visible,
1063 &procID,
1064 WinObj_Convert, &behind,
1065 &goAwayFlag,
1066 &refCon,
1067 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +00001068 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001069 _rv = NewColorDialog((void *)0,
1070 &boundsRect,
1071 title,
1072 visible,
1073 procID,
1074 behind,
1075 goAwayFlag,
1076 refCon,
1077 items);
1078 _res = Py_BuildValue("O&",
1079 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +00001080 return _res;
1081}
1082
1083static PyObject *Dlg_ModalDialog(_self, _args)
1084 PyObject *_self;
1085 PyObject *_args;
1086{
1087 PyObject *_res = NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001088 PyObject* modalFilter;
Jack Jansen21f96871998-02-20 16:02:09 +00001089 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +00001090 if (!PyArg_ParseTuple(_args, "O",
Jack Jansenae8a68f1995-06-06 12:55:40 +00001091 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001092 return NULL;
Jack Jansen599ce9c2001-02-20 22:27:43 +00001093 ModalDialog(Dlg_PassFilterProc(modalFilter),
Guido van Rossum17448e21995-01-30 11:53:55 +00001094 &itemHit);
1095 _res = Py_BuildValue("h",
1096 itemHit);
1097 return _res;
1098}
1099
1100static PyObject *Dlg_IsDialogEvent(_self, _args)
1101 PyObject *_self;
1102 PyObject *_args;
1103{
1104 PyObject *_res = NULL;
1105 Boolean _rv;
1106 EventRecord theEvent;
1107 if (!PyArg_ParseTuple(_args, "O&",
1108 PyMac_GetEventRecord, &theEvent))
1109 return NULL;
1110 _rv = IsDialogEvent(&theEvent);
1111 _res = Py_BuildValue("b",
1112 _rv);
1113 return _res;
1114}
1115
1116static PyObject *Dlg_DialogSelect(_self, _args)
1117 PyObject *_self;
1118 PyObject *_args;
1119{
1120 PyObject *_res = NULL;
1121 Boolean _rv;
1122 EventRecord theEvent;
1123 DialogPtr theDialog;
Jack Jansen21f96871998-02-20 16:02:09 +00001124 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +00001125 if (!PyArg_ParseTuple(_args, "O&",
1126 PyMac_GetEventRecord, &theEvent))
1127 return NULL;
1128 _rv = DialogSelect(&theEvent,
1129 &theDialog,
1130 &itemHit);
1131 _res = Py_BuildValue("bO&h",
1132 _rv,
Jack Jansen69e7f112001-02-06 16:14:54 +00001133 DlgObj_WhichDialog, theDialog,
Guido van Rossum17448e21995-01-30 11:53:55 +00001134 itemHit);
1135 return _res;
1136}
1137
1138static PyObject *Dlg_Alert(_self, _args)
1139 PyObject *_self;
1140 PyObject *_args;
1141{
1142 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001143 DialogItemIndex _rv;
1144 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001145 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001146 if (!PyArg_ParseTuple(_args, "hO",
1147 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001148 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001149 return NULL;
1150 _rv = Alert(alertID,
Jack Jansen599ce9c2001-02-20 22:27:43 +00001151 Dlg_PassFilterProc(modalFilter));
Guido van Rossum17448e21995-01-30 11:53:55 +00001152 _res = Py_BuildValue("h",
1153 _rv);
1154 return _res;
1155}
1156
1157static PyObject *Dlg_StopAlert(_self, _args)
1158 PyObject *_self;
1159 PyObject *_args;
1160{
1161 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001162 DialogItemIndex _rv;
1163 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001164 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001165 if (!PyArg_ParseTuple(_args, "hO",
1166 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001167 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001168 return NULL;
1169 _rv = StopAlert(alertID,
Jack Jansen599ce9c2001-02-20 22:27:43 +00001170 Dlg_PassFilterProc(modalFilter));
Guido van Rossum17448e21995-01-30 11:53:55 +00001171 _res = Py_BuildValue("h",
1172 _rv);
1173 return _res;
1174}
1175
1176static PyObject *Dlg_NoteAlert(_self, _args)
1177 PyObject *_self;
1178 PyObject *_args;
1179{
1180 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001181 DialogItemIndex _rv;
1182 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001183 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001184 if (!PyArg_ParseTuple(_args, "hO",
1185 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001186 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001187 return NULL;
1188 _rv = NoteAlert(alertID,
Jack Jansen599ce9c2001-02-20 22:27:43 +00001189 Dlg_PassFilterProc(modalFilter));
Guido van Rossum17448e21995-01-30 11:53:55 +00001190 _res = Py_BuildValue("h",
1191 _rv);
1192 return _res;
1193}
1194
1195static PyObject *Dlg_CautionAlert(_self, _args)
1196 PyObject *_self;
1197 PyObject *_args;
1198{
1199 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001200 DialogItemIndex _rv;
1201 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001202 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001203 if (!PyArg_ParseTuple(_args, "hO",
1204 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001205 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001206 return NULL;
1207 _rv = CautionAlert(alertID,
Jack Jansen599ce9c2001-02-20 22:27:43 +00001208 Dlg_PassFilterProc(modalFilter));
Guido van Rossum17448e21995-01-30 11:53:55 +00001209 _res = Py_BuildValue("h",
1210 _rv);
1211 return _res;
1212}
1213
Jack Jansen21f96871998-02-20 16:02:09 +00001214static PyObject *Dlg_ParamText(_self, _args)
1215 PyObject *_self;
1216 PyObject *_args;
1217{
1218 PyObject *_res = NULL;
1219 Str255 param0;
1220 Str255 param1;
1221 Str255 param2;
1222 Str255 param3;
1223 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1224 PyMac_GetStr255, param0,
1225 PyMac_GetStr255, param1,
1226 PyMac_GetStr255, param2,
1227 PyMac_GetStr255, param3))
1228 return NULL;
1229 ParamText(param0,
1230 param1,
1231 param2,
1232 param3);
1233 Py_INCREF(Py_None);
1234 _res = Py_None;
1235 return _res;
1236}
1237
Jack Jansenae8a68f1995-06-06 12:55:40 +00001238static PyObject *Dlg_GetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001239 PyObject *_self;
1240 PyObject *_args;
1241{
1242 PyObject *_res = NULL;
1243 Handle item;
1244 Str255 text;
1245 if (!PyArg_ParseTuple(_args, "O&",
1246 ResObj_Convert, &item))
1247 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001248 GetDialogItemText(item,
1249 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001250 _res = Py_BuildValue("O&",
1251 PyMac_BuildStr255, text);
1252 return _res;
1253}
1254
Jack Jansenae8a68f1995-06-06 12:55:40 +00001255static PyObject *Dlg_SetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001256 PyObject *_self;
1257 PyObject *_args;
1258{
1259 PyObject *_res = NULL;
1260 Handle item;
1261 Str255 text;
1262 if (!PyArg_ParseTuple(_args, "O&O&",
1263 ResObj_Convert, &item,
1264 PyMac_GetStr255, text))
1265 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001266 SetDialogItemText(item,
1267 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001268 Py_INCREF(Py_None);
1269 _res = Py_None;
1270 return _res;
1271}
1272
Jack Jansenae8a68f1995-06-06 12:55:40 +00001273static PyObject *Dlg_GetAlertStage(_self, _args)
1274 PyObject *_self;
1275 PyObject *_args;
1276{
1277 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001278 SInt16 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001279 if (!PyArg_ParseTuple(_args, ""))
1280 return NULL;
1281 _rv = GetAlertStage();
1282 _res = Py_BuildValue("h",
1283 _rv);
1284 return _res;
1285}
1286
Jack Jansen21f96871998-02-20 16:02:09 +00001287static PyObject *Dlg_SetDialogFont(_self, _args)
1288 PyObject *_self;
1289 PyObject *_args;
1290{
1291 PyObject *_res = NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001292 SInt16 fontNum;
Jack Jansen21f96871998-02-20 16:02:09 +00001293 if (!PyArg_ParseTuple(_args, "h",
Jack Jansena05ac601999-12-12 21:41:51 +00001294 &fontNum))
Jack Jansen21f96871998-02-20 16:02:09 +00001295 return NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001296 SetDialogFont(fontNum);
Jack Jansen21f96871998-02-20 16:02:09 +00001297 Py_INCREF(Py_None);
1298 _res = Py_None;
1299 return _res;
1300}
1301
Jack Jansenae8a68f1995-06-06 12:55:40 +00001302static PyObject *Dlg_ResetAlertStage(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001303 PyObject *_self;
1304 PyObject *_args;
1305{
1306 PyObject *_res = NULL;
1307 if (!PyArg_ParseTuple(_args, ""))
1308 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001309 ResetAlertStage();
Guido van Rossum17448e21995-01-30 11:53:55 +00001310 Py_INCREF(Py_None);
1311 _res = Py_None;
1312 return _res;
1313}
1314
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001315#if TARGET_API_MAC_CARBON
1316
1317static PyObject *Dlg_GetParamText(_self, _args)
1318 PyObject *_self;
1319 PyObject *_args;
1320{
1321 PyObject *_res = NULL;
1322 Str255 param0;
1323 Str255 param1;
1324 Str255 param2;
1325 Str255 param3;
1326 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1327 PyMac_GetStr255, param0,
1328 PyMac_GetStr255, param1,
1329 PyMac_GetStr255, param2,
1330 PyMac_GetStr255, param3))
1331 return NULL;
1332 GetParamText(param0,
1333 param1,
1334 param2,
1335 param3);
1336 Py_INCREF(Py_None);
1337 _res = Py_None;
1338 return _res;
1339}
1340#endif
1341
Jack Jansen21f96871998-02-20 16:02:09 +00001342static PyObject *Dlg_NewFeaturesDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001343 PyObject *_self;
1344 PyObject *_args;
1345{
1346 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001347 DialogPtr _rv;
1348 Rect inBoundsRect;
1349 Str255 inTitle;
1350 Boolean inIsVisible;
1351 SInt16 inProcID;
1352 WindowPtr inBehind;
1353 Boolean inGoAwayFlag;
1354 SInt32 inRefCon;
1355 Handle inItemListHandle;
1356 UInt32 inFlags;
1357 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
1358 PyMac_GetRect, &inBoundsRect,
1359 PyMac_GetStr255, inTitle,
1360 &inIsVisible,
1361 &inProcID,
1362 WinObj_Convert, &inBehind,
1363 &inGoAwayFlag,
1364 &inRefCon,
1365 ResObj_Convert, &inItemListHandle,
1366 &inFlags))
Guido van Rossum17448e21995-01-30 11:53:55 +00001367 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001368 _rv = NewFeaturesDialog((void *)0,
1369 &inBoundsRect,
1370 inTitle,
1371 inIsVisible,
1372 inProcID,
1373 inBehind,
1374 inGoAwayFlag,
1375 inRefCon,
1376 inItemListHandle,
1377 inFlags);
1378 _res = Py_BuildValue("O&",
1379 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +00001380 return _res;
1381}
1382
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001383static PyObject *Dlg_GetDialogFromWindow(_self, _args)
1384 PyObject *_self;
1385 PyObject *_args;
1386{
1387 PyObject *_res = NULL;
1388 DialogPtr _rv;
1389 WindowPtr window;
1390 if (!PyArg_ParseTuple(_args, "O&",
1391 WinObj_Convert, &window))
1392 return NULL;
1393 _rv = GetDialogFromWindow(window);
1394 _res = Py_BuildValue("O&",
1395 DlgObj_New, _rv);
1396 return _res;
1397}
1398
Jack Jansendf901df1998-07-10 15:47:48 +00001399static PyObject *Dlg_SetUserItemHandler(_self, _args)
1400 PyObject *_self;
1401 PyObject *_args;
1402{
1403 PyObject *_res = NULL;
1404
1405 PyObject *new = NULL;
1406
1407
1408 if (!PyArg_ParseTuple(_args, "|O", &new))
1409 return NULL;
1410
1411 if (Dlg_UserItemProc_callback && new && new != Py_None) {
1412 PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
1413 return NULL;
1414 }
1415
Jack Jansen599ce9c2001-02-20 22:27:43 +00001416 if (new == NULL || new == Py_None) {
Jack Jansendf901df1998-07-10 15:47:48 +00001417 new = NULL;
1418 _res = Py_None;
1419 Py_INCREF(Py_None);
1420 } else {
1421 Py_INCREF(new);
1422 _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc));
1423 }
1424
1425 Dlg_UserItemProc_callback = new;
1426 return _res;
1427
1428}
1429
Guido van Rossum17448e21995-01-30 11:53:55 +00001430static PyMethodDef Dlg_methods[] = {
1431 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001432 "(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 +00001433 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001434 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1435 {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
1436 "(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 +00001437 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001438 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001439 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
1440 "(EventRecord theEvent) -> (Boolean _rv)"},
1441 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001442 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001443 {"Alert", (PyCFunction)Dlg_Alert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001444 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001445 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001446 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001447 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001448 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001449 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001450 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1451 {"ParamText", (PyCFunction)Dlg_ParamText, 1,
1452 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001453 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001454 "(Handle item) -> (Str255 text)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001455 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001456 "(Handle item, Str255 text) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001457 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001458 "() -> (SInt16 _rv)"},
1459 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
Jack Jansena05ac601999-12-12 21:41:51 +00001460 "(SInt16 fontNum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001461 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001462 "() -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001463
1464#if TARGET_API_MAC_CARBON
1465 {"GetParamText", (PyCFunction)Dlg_GetParamText, 1,
1466 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1467#endif
Jack Jansen21f96871998-02-20 16:02:09 +00001468 {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
1469 "(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 +00001470 {"GetDialogFromWindow", (PyCFunction)Dlg_GetDialogFromWindow, 1,
1471 "(WindowPtr window) -> (DialogPtr _rv)"},
Jack Jansendf901df1998-07-10 15:47:48 +00001472 {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
1473 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001474 {NULL, NULL, 0}
1475};
1476
1477
1478
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001479/* Return the WindowPtr corresponding to a DialogObject */
Jack Jansen0e04eec2001-05-17 21:58:34 +00001480#if 0
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001481WindowPtr
1482DlgObj_ConvertToWindow(self)
1483 PyObject *self;
1484{
1485 if ( DlgObj_Check(self) )
1486 return GetDialogWindow(((DialogObject *)self)->ob_itself);
1487 return NULL;
1488}
Jack Jansen0e04eec2001-05-17 21:58:34 +00001489#endif
Jack Jansen69e7f112001-02-06 16:14:54 +00001490/* Return the object corresponding to the dialog, or None */
1491
1492PyObject *
1493DlgObj_WhichDialog(d)
1494 DialogPtr d;
1495{
1496 PyObject *it;
1497
1498 if (d == NULL) {
1499 it = Py_None;
1500 Py_INCREF(it);
1501 } else {
1502 WindowPtr w = GetDialogWindow(d);
1503
1504 it = (PyObject *) GetWRefCon(w);
1505 if (it == NULL || ((DialogObject *)it)->ob_itself != d || !DlgObj_Check(it)) {
1506#if 0
1507 /* Should do this, but we don't have an ob_freeit for dialogs yet. */
1508 it = WinObj_New(w);
1509 ((WindowObject *)it)->ob_freeit = NULL;
1510#else
1511 it = Py_None;
1512 Py_INCREF(it);
1513#endif
1514 } else {
1515 Py_INCREF(it);
1516 }
1517 }
1518 return it;
1519}
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001520
Guido van Rossum17448e21995-01-30 11:53:55 +00001521
1522void initDlg()
1523{
1524 PyObject *m;
1525 PyObject *d;
1526
1527
1528
Jack Jansen0e04eec2001-05-17 21:58:34 +00001529 PyMac_INIT_TOOLBOX_OBJECT_NEW(DlgObj_New);
1530 PyMac_INIT_TOOLBOX_OBJECT_NEW(DlgObj_WhichDialog);
1531 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DlgObj_Convert);
1532
Guido van Rossum17448e21995-01-30 11:53:55 +00001533
1534 m = Py_InitModule("Dlg", Dlg_methods);
1535 d = PyModule_GetDict(m);
1536 Dlg_Error = PyMac_GetOSErrException();
1537 if (Dlg_Error == NULL ||
1538 PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001539 return;
Jack Jansena755e681997-09-20 17:40:22 +00001540 Dialog_Type.ob_type = &PyType_Type;
1541 Py_INCREF(&Dialog_Type);
1542 if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0)
1543 Py_FatalError("can't initialize DialogType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001544}
1545
1546/* ========================= End module Dlg ========================= */
1547