blob: 2262b544e678b70fbf63434e8ba89bfbc752f545 [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
Jack Jansen599ce9c2001-02-20 22:27:43 +000059static ModalFilterUPP
Guido van Rossum17448e21995-01-30 11:53:55 +000060Dlg_PassFilterProc(PyObject *callback)
61{
62 PyObject *tmp = Dlg_FilterProc_callback;
Jack Jansen599ce9c2001-02-20 22:27:43 +000063 static ModalFilterUPP UnivFilterUpp = NULL;
64
Guido van Rossum17448e21995-01-30 11:53:55 +000065 Dlg_FilterProc_callback = NULL;
66 if (callback == Py_None) {
67 Py_XDECREF(tmp);
68 return NULL;
69 }
70 Py_INCREF(callback);
71 Dlg_FilterProc_callback = callback;
72 Py_XDECREF(tmp);
Jack Jansen599ce9c2001-02-20 22:27:43 +000073 if ( UnivFilterUpp == NULL )
74 UnivFilterUpp = NewModalFilterUPP(&Dlg_UnivFilterProc);
75 return UnivFilterUpp;
Guido van Rossum17448e21995-01-30 11:53:55 +000076}
77
Jack Jansendf901df1998-07-10 15:47:48 +000078static PyObject *Dlg_UserItemProc_callback = NULL;
79
80static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
81 short item)
82{
83 PyObject *args, *res;
84
85 if (Dlg_UserItemProc_callback == NULL)
86 return; /* Default behavior */
87 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
Jack Jansen69e7f112001-02-06 16:14:54 +000088 args = Py_BuildValue("O&h", DlgObj_WhichDialog, dialog, item);
Jack Jansendf901df1998-07-10 15:47:48 +000089 if (args == NULL)
90 res = NULL;
91 else {
92 res = PyEval_CallObject(Dlg_UserItemProc_callback, args);
93 Py_DECREF(args);
94 }
95 if (res == NULL) {
Jack Jansendeff89c1998-10-12 20:53:15 +000096 PySys_WriteStderr("Exception in Dialog UserItem proc\n");
Jack Jansendf901df1998-07-10 15:47:48 +000097 PyErr_Print();
98 }
99 Py_XDECREF(res);
100 return;
101}
102
Jack Jansen69e7f112001-02-06 16:14:54 +0000103#if 0
Jack Jansenb8c4c7b2000-08-25 22:25:54 +0000104/*
105** Treating DialogObjects as WindowObjects is (I think) illegal under Carbon.
106** However, as they are still identical under MacOS9 Carbon this is a problem, even
107** if we neatly call GetDialogWindow() at the right places: there's one refcon field
108** and it points to the DialogObject, so WinObj_WhichWindow will smartly return the
109** dialog object, and therefore we still don't have a WindowObject.
110** I'll leave the chaining code in place for now, with this comment to warn the
111** unsuspecting victims (i.e. me, probably, in a few weeks:-)
112*/
Guido van Rossum17448e21995-01-30 11:53:55 +0000113extern PyMethodChain WinObj_chain;
Jack Jansenb8c4c7b2000-08-25 22:25:54 +0000114#endif
Guido van Rossum17448e21995-01-30 11:53:55 +0000115
116static PyObject *Dlg_Error;
117
118/* ----------------------- Object type Dialog ----------------------- */
119
120PyTypeObject Dialog_Type;
121
122#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
123
124typedef struct DialogObject {
125 PyObject_HEAD
126 DialogPtr ob_itself;
127} DialogObject;
128
129PyObject *DlgObj_New(itself)
Guido van Rossum97842951995-02-19 15:59:49 +0000130 DialogPtr itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000131{
132 DialogObject *it;
133 if (itself == NULL) return Py_None;
134 it = PyObject_NEW(DialogObject, &Dialog_Type);
135 if (it == NULL) return NULL;
136 it->ob_itself = itself;
Jack Jansene79dc762000-06-02 21:35:07 +0000137 SetWRefCon(GetDialogWindow(itself), (long)it);
Guido van Rossum17448e21995-01-30 11:53:55 +0000138 return (PyObject *)it;
139}
140DlgObj_Convert(v, p_itself)
141 PyObject *v;
142 DialogPtr *p_itself;
143{
144 if (v == Py_None) { *p_itself = NULL; return 1; }
145 if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
146 return 1; }
147 if (!DlgObj_Check(v))
148 {
149 PyErr_SetString(PyExc_TypeError, "Dialog required");
150 return 0;
151 }
152 *p_itself = ((DialogObject *)v)->ob_itself;
153 return 1;
154}
155
156static void DlgObj_dealloc(self)
157 DialogObject *self;
158{
159 DisposeDialog(self->ob_itself);
160 PyMem_DEL(self);
161}
162
163static PyObject *DlgObj_DrawDialog(_self, _args)
164 DialogObject *_self;
165 PyObject *_args;
166{
167 PyObject *_res = NULL;
168 if (!PyArg_ParseTuple(_args, ""))
169 return NULL;
170 DrawDialog(_self->ob_itself);
171 Py_INCREF(Py_None);
172 _res = Py_None;
173 return _res;
174}
175
Guido van Rossum17448e21995-01-30 11:53:55 +0000176static PyObject *DlgObj_UpdateDialog(_self, _args)
177 DialogObject *_self;
178 PyObject *_args;
179{
180 PyObject *_res = NULL;
Jack Jansen2b724171996-04-10 14:48:19 +0000181 RgnHandle updateRgn;
182 if (!PyArg_ParseTuple(_args, "O&",
183 ResObj_Convert, &updateRgn))
Guido van Rossum17448e21995-01-30 11:53:55 +0000184 return NULL;
185 UpdateDialog(_self->ob_itself,
Jack Jansen2b724171996-04-10 14:48:19 +0000186 updateRgn);
Guido van Rossum17448e21995-01-30 11:53:55 +0000187 Py_INCREF(Py_None);
188 _res = Py_None;
189 return _res;
190}
191
Jack Jansenae8a68f1995-06-06 12:55:40 +0000192static PyObject *DlgObj_HideDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000193 DialogObject *_self;
194 PyObject *_args;
195{
196 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000197 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000198 if (!PyArg_ParseTuple(_args, "h",
199 &itemNo))
200 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000201 HideDialogItem(_self->ob_itself,
202 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000203 Py_INCREF(Py_None);
204 _res = Py_None;
205 return _res;
206}
207
Jack Jansenae8a68f1995-06-06 12:55:40 +0000208static PyObject *DlgObj_ShowDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000209 DialogObject *_self;
210 PyObject *_args;
211{
212 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000213 DialogItemIndex itemNo;
Guido van Rossum17448e21995-01-30 11:53:55 +0000214 if (!PyArg_ParseTuple(_args, "h",
215 &itemNo))
216 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000217 ShowDialogItem(_self->ob_itself,
218 itemNo);
Guido van Rossum17448e21995-01-30 11:53:55 +0000219 Py_INCREF(Py_None);
220 _res = Py_None;
221 return _res;
222}
223
Jack Jansenae8a68f1995-06-06 12:55:40 +0000224static PyObject *DlgObj_FindDialogItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000225 DialogObject *_self;
226 PyObject *_args;
227{
228 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000229 DialogItemIndexZeroBased _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000230 Point thePt;
231 if (!PyArg_ParseTuple(_args, "O&",
232 PyMac_GetPoint, &thePt))
233 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000234 _rv = FindDialogItem(_self->ob_itself,
235 thePt);
Guido van Rossum17448e21995-01-30 11:53:55 +0000236 _res = Py_BuildValue("h",
237 _rv);
238 return _res;
239}
240
Jack Jansenae8a68f1995-06-06 12:55:40 +0000241static PyObject *DlgObj_DialogCut(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000242 DialogObject *_self;
243 PyObject *_args;
244{
245 PyObject *_res = NULL;
246 if (!PyArg_ParseTuple(_args, ""))
247 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000248 DialogCut(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000249 Py_INCREF(Py_None);
250 _res = Py_None;
251 return _res;
252}
253
Jack Jansenae8a68f1995-06-06 12:55:40 +0000254static PyObject *DlgObj_DialogPaste(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000255 DialogObject *_self;
256 PyObject *_args;
257{
258 PyObject *_res = NULL;
259 if (!PyArg_ParseTuple(_args, ""))
260 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000261 DialogPaste(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000262 Py_INCREF(Py_None);
263 _res = Py_None;
264 return _res;
265}
266
Jack Jansenae8a68f1995-06-06 12:55:40 +0000267static PyObject *DlgObj_DialogCopy(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000268 DialogObject *_self;
269 PyObject *_args;
270{
271 PyObject *_res = NULL;
272 if (!PyArg_ParseTuple(_args, ""))
273 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000274 DialogCopy(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000275 Py_INCREF(Py_None);
276 _res = Py_None;
277 return _res;
278}
279
Jack Jansenae8a68f1995-06-06 12:55:40 +0000280static PyObject *DlgObj_DialogDelete(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000281 DialogObject *_self;
282 PyObject *_args;
283{
284 PyObject *_res = NULL;
285 if (!PyArg_ParseTuple(_args, ""))
286 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000287 DialogDelete(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000288 Py_INCREF(Py_None);
289 _res = Py_None;
290 return _res;
291}
292
Jack Jansen21f96871998-02-20 16:02:09 +0000293static PyObject *DlgObj_GetDialogItem(_self, _args)
294 DialogObject *_self;
295 PyObject *_args;
296{
297 PyObject *_res = NULL;
298 DialogItemIndex itemNo;
299 DialogItemType itemType;
300 Handle item;
301 Rect box;
302 if (!PyArg_ParseTuple(_args, "h",
303 &itemNo))
304 return NULL;
305 GetDialogItem(_self->ob_itself,
306 itemNo,
307 &itemType,
308 &item,
309 &box);
310 _res = Py_BuildValue("hO&O&",
311 itemType,
312 OptResObj_New, item,
313 PyMac_BuildRect, &box);
314 return _res;
315}
316
317static PyObject *DlgObj_SetDialogItem(_self, _args)
318 DialogObject *_self;
319 PyObject *_args;
320{
321 PyObject *_res = NULL;
322 DialogItemIndex itemNo;
323 DialogItemType itemType;
324 Handle item;
325 Rect box;
326 if (!PyArg_ParseTuple(_args, "hhO&O&",
327 &itemNo,
328 &itemType,
329 ResObj_Convert, &item,
330 PyMac_GetRect, &box))
331 return NULL;
332 SetDialogItem(_self->ob_itself,
333 itemNo,
334 itemType,
335 item,
336 &box);
337 Py_INCREF(Py_None);
338 _res = Py_None;
339 return _res;
340}
341
342static PyObject *DlgObj_SelectDialogItemText(_self, _args)
343 DialogObject *_self;
344 PyObject *_args;
345{
346 PyObject *_res = NULL;
347 DialogItemIndex itemNo;
348 SInt16 strtSel;
349 SInt16 endSel;
350 if (!PyArg_ParseTuple(_args, "hhh",
351 &itemNo,
352 &strtSel,
353 &endSel))
354 return NULL;
355 SelectDialogItemText(_self->ob_itself,
356 itemNo,
357 strtSel,
358 endSel);
359 Py_INCREF(Py_None);
360 _res = Py_None;
361 return _res;
362}
363
Guido van Rossum17448e21995-01-30 11:53:55 +0000364static PyObject *DlgObj_AppendDITL(_self, _args)
365 DialogObject *_self;
366 PyObject *_args;
367{
368 PyObject *_res = NULL;
369 Handle theHandle;
370 DITLMethod method;
371 if (!PyArg_ParseTuple(_args, "O&h",
372 ResObj_Convert, &theHandle,
373 &method))
374 return NULL;
375 AppendDITL(_self->ob_itself,
376 theHandle,
377 method);
378 Py_INCREF(Py_None);
379 _res = Py_None;
380 return _res;
381}
382
383static PyObject *DlgObj_CountDITL(_self, _args)
384 DialogObject *_self;
385 PyObject *_args;
386{
387 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000388 DialogItemIndex _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000389 if (!PyArg_ParseTuple(_args, ""))
390 return NULL;
391 _rv = CountDITL(_self->ob_itself);
392 _res = Py_BuildValue("h",
393 _rv);
394 return _res;
395}
396
397static PyObject *DlgObj_ShortenDITL(_self, _args)
398 DialogObject *_self;
399 PyObject *_args;
400{
401 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000402 DialogItemIndex numberItems;
Guido van Rossum17448e21995-01-30 11:53:55 +0000403 if (!PyArg_ParseTuple(_args, "h",
404 &numberItems))
405 return NULL;
406 ShortenDITL(_self->ob_itself,
407 numberItems);
408 Py_INCREF(Py_None);
409 _res = Py_None;
410 return _res;
411}
412
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000413#if TARGET_API_MAC_CARBON
414
415static PyObject *DlgObj_InsertDialogItem(_self, _args)
416 DialogObject *_self;
417 PyObject *_args;
418{
419 PyObject *_res = NULL;
420 OSStatus _err;
421 DialogItemIndex afterItem;
422 DialogItemType itemType;
423 Handle itemHandle;
424 Rect box;
425 if (!PyArg_ParseTuple(_args, "hhO&O&",
426 &afterItem,
427 &itemType,
428 ResObj_Convert, &itemHandle,
429 PyMac_GetRect, &box))
430 return NULL;
431 _err = InsertDialogItem(_self->ob_itself,
432 afterItem,
433 itemType,
434 itemHandle,
435 &box);
436 if (_err != noErr) return PyMac_Error(_err);
437 Py_INCREF(Py_None);
438 _res = Py_None;
439 return _res;
440}
441#endif
442
443#if TARGET_API_MAC_CARBON
444
445static PyObject *DlgObj_RemoveDialogItems(_self, _args)
446 DialogObject *_self;
447 PyObject *_args;
448{
449 PyObject *_res = NULL;
450 OSStatus _err;
451 DialogItemIndex itemNo;
452 DialogItemIndex amountToRemove;
453 Boolean disposeItemData;
454 if (!PyArg_ParseTuple(_args, "hhb",
455 &itemNo,
456 &amountToRemove,
457 &disposeItemData))
458 return NULL;
459 _err = RemoveDialogItems(_self->ob_itself,
460 itemNo,
461 amountToRemove,
462 disposeItemData);
463 if (_err != noErr) return PyMac_Error(_err);
464 Py_INCREF(Py_None);
465 _res = Py_None;
466 return _res;
467}
468#endif
469
Jack Jansenae8a68f1995-06-06 12:55:40 +0000470static PyObject *DlgObj_StdFilterProc(_self, _args)
471 DialogObject *_self;
472 PyObject *_args;
473{
474 PyObject *_res = NULL;
475 Boolean _rv;
476 EventRecord event;
Jack Jansen21f96871998-02-20 16:02:09 +0000477 DialogItemIndex itemHit;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000478 if (!PyArg_ParseTuple(_args, ""))
479 return NULL;
480 _rv = StdFilterProc(_self->ob_itself,
481 &event,
482 &itemHit);
483 _res = Py_BuildValue("bO&h",
484 _rv,
485 PyMac_BuildEventRecord, &event,
486 itemHit);
487 return _res;
488}
489
490static PyObject *DlgObj_SetDialogDefaultItem(_self, _args)
491 DialogObject *_self;
492 PyObject *_args;
493{
494 PyObject *_res = NULL;
495 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000496 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000497 if (!PyArg_ParseTuple(_args, "h",
498 &newItem))
499 return NULL;
500 _err = SetDialogDefaultItem(_self->ob_itself,
501 newItem);
502 if (_err != noErr) return PyMac_Error(_err);
503 Py_INCREF(Py_None);
504 _res = Py_None;
505 return _res;
506}
507
508static PyObject *DlgObj_SetDialogCancelItem(_self, _args)
509 DialogObject *_self;
510 PyObject *_args;
511{
512 PyObject *_res = NULL;
513 OSErr _err;
Jack Jansen21f96871998-02-20 16:02:09 +0000514 DialogItemIndex newItem;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000515 if (!PyArg_ParseTuple(_args, "h",
516 &newItem))
517 return NULL;
518 _err = SetDialogCancelItem(_self->ob_itself,
519 newItem);
520 if (_err != noErr) return PyMac_Error(_err);
521 Py_INCREF(Py_None);
522 _res = Py_None;
523 return _res;
524}
525
526static PyObject *DlgObj_SetDialogTracksCursor(_self, _args)
527 DialogObject *_self;
528 PyObject *_args;
529{
530 PyObject *_res = NULL;
531 OSErr _err;
532 Boolean tracks;
533 if (!PyArg_ParseTuple(_args, "b",
534 &tracks))
535 return NULL;
536 _err = SetDialogTracksCursor(_self->ob_itself,
537 tracks);
538 if (_err != noErr) return PyMac_Error(_err);
539 Py_INCREF(Py_None);
540 _res = Py_None;
541 return _res;
542}
543
Jack Jansen21f96871998-02-20 16:02:09 +0000544static PyObject *DlgObj_AutoSizeDialog(_self, _args)
545 DialogObject *_self;
546 PyObject *_args;
547{
548 PyObject *_res = NULL;
549 OSErr _err;
550 if (!PyArg_ParseTuple(_args, ""))
551 return NULL;
552 _err = AutoSizeDialog(_self->ob_itself);
553 if (_err != noErr) return PyMac_Error(_err);
554 Py_INCREF(Py_None);
555 _res = Py_None;
556 return _res;
557}
558
559static PyObject *DlgObj_GetDialogItemAsControl(_self, _args)
560 DialogObject *_self;
561 PyObject *_args;
562{
563 PyObject *_res = NULL;
564 OSErr _err;
565 SInt16 inItemNo;
566 ControlHandle outControl;
567 if (!PyArg_ParseTuple(_args, "h",
568 &inItemNo))
569 return NULL;
570 _err = GetDialogItemAsControl(_self->ob_itself,
571 inItemNo,
572 &outControl);
573 if (_err != noErr) return PyMac_Error(_err);
574 _res = Py_BuildValue("O&",
575 CtlObj_New, outControl);
576 return _res;
577}
578
579static PyObject *DlgObj_MoveDialogItem(_self, _args)
580 DialogObject *_self;
581 PyObject *_args;
582{
583 PyObject *_res = NULL;
584 OSErr _err;
585 SInt16 inItemNo;
586 SInt16 inHoriz;
587 SInt16 inVert;
588 if (!PyArg_ParseTuple(_args, "hhh",
589 &inItemNo,
590 &inHoriz,
591 &inVert))
592 return NULL;
593 _err = MoveDialogItem(_self->ob_itself,
594 inItemNo,
595 inHoriz,
596 inVert);
597 if (_err != noErr) return PyMac_Error(_err);
598 Py_INCREF(Py_None);
599 _res = Py_None;
600 return _res;
601}
602
603static PyObject *DlgObj_SizeDialogItem(_self, _args)
604 DialogObject *_self;
605 PyObject *_args;
606{
607 PyObject *_res = NULL;
608 OSErr _err;
609 SInt16 inItemNo;
Jack Jansen21f96871998-02-20 16:02:09 +0000610 SInt16 inWidth;
Jack Jansen1c4e6141998-04-21 15:23:55 +0000611 SInt16 inHeight;
Jack Jansen21f96871998-02-20 16:02:09 +0000612 if (!PyArg_ParseTuple(_args, "hhh",
613 &inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000614 &inWidth,
615 &inHeight))
Jack Jansen21f96871998-02-20 16:02:09 +0000616 return NULL;
617 _err = SizeDialogItem(_self->ob_itself,
618 inItemNo,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000619 inWidth,
620 inHeight);
Jack Jansen21f96871998-02-20 16:02:09 +0000621 if (_err != noErr) return PyMac_Error(_err);
622 Py_INCREF(Py_None);
623 _res = Py_None;
624 return _res;
625}
626
Jack Jansena05ac601999-12-12 21:41:51 +0000627static PyObject *DlgObj_AppendDialogItemList(_self, _args)
628 DialogObject *_self;
629 PyObject *_args;
630{
631 PyObject *_res = NULL;
632 OSErr _err;
633 SInt16 ditlID;
634 DITLMethod method;
635 if (!PyArg_ParseTuple(_args, "hh",
636 &ditlID,
637 &method))
638 return NULL;
639 _err = AppendDialogItemList(_self->ob_itself,
640 ditlID,
641 method);
642 if (_err != noErr) return PyMac_Error(_err);
643 Py_INCREF(Py_None);
644 _res = Py_None;
645 return _res;
646}
647
648static PyObject *DlgObj_SetDialogTimeout(_self, _args)
649 DialogObject *_self;
650 PyObject *_args;
651{
652 PyObject *_res = NULL;
653 OSStatus _err;
654 SInt16 inButtonToPress;
655 UInt32 inSecondsToWait;
656 if (!PyArg_ParseTuple(_args, "hl",
657 &inButtonToPress,
658 &inSecondsToWait))
659 return NULL;
660 _err = SetDialogTimeout(_self->ob_itself,
661 inButtonToPress,
662 inSecondsToWait);
663 if (_err != noErr) return PyMac_Error(_err);
664 Py_INCREF(Py_None);
665 _res = Py_None;
666 return _res;
667}
668
669static PyObject *DlgObj_GetDialogTimeout(_self, _args)
670 DialogObject *_self;
671 PyObject *_args;
672{
673 PyObject *_res = NULL;
674 OSStatus _err;
675 SInt16 outButtonToPress;
676 UInt32 outSecondsToWait;
677 UInt32 outSecondsRemaining;
678 if (!PyArg_ParseTuple(_args, ""))
679 return NULL;
680 _err = GetDialogTimeout(_self->ob_itself,
681 &outButtonToPress,
682 &outSecondsToWait,
683 &outSecondsRemaining);
684 if (_err != noErr) return PyMac_Error(_err);
685 _res = Py_BuildValue("hll",
686 outButtonToPress,
687 outSecondsToWait,
688 outSecondsRemaining);
689 return _res;
690}
691
692static PyObject *DlgObj_SetModalDialogEventMask(_self, _args)
693 DialogObject *_self;
694 PyObject *_args;
695{
696 PyObject *_res = NULL;
697 OSStatus _err;
698 EventMask inMask;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000699 if (!PyArg_ParseTuple(_args, "H",
Jack Jansena05ac601999-12-12 21:41:51 +0000700 &inMask))
701 return NULL;
702 _err = SetModalDialogEventMask(_self->ob_itself,
703 inMask);
704 if (_err != noErr) return PyMac_Error(_err);
705 Py_INCREF(Py_None);
706 _res = Py_None;
707 return _res;
708}
709
710static PyObject *DlgObj_GetModalDialogEventMask(_self, _args)
711 DialogObject *_self;
712 PyObject *_args;
713{
714 PyObject *_res = NULL;
715 OSStatus _err;
716 EventMask outMask;
717 if (!PyArg_ParseTuple(_args, ""))
718 return NULL;
719 _err = GetModalDialogEventMask(_self->ob_itself,
720 &outMask);
721 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000722 _res = Py_BuildValue("H",
Jack Jansena05ac601999-12-12 21:41:51 +0000723 outMask);
724 return _res;
725}
726
Jack Jansend96cb501996-09-23 15:48:46 +0000727static PyObject *DlgObj_GetDialogWindow(_self, _args)
728 DialogObject *_self;
729 PyObject *_args;
730{
731 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000732 WindowPtr _rv;
Jack Jansend96cb501996-09-23 15:48:46 +0000733 if (!PyArg_ParseTuple(_args, ""))
734 return NULL;
735 _rv = GetDialogWindow(_self->ob_itself);
736 _res = Py_BuildValue("O&",
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000737 WinObj_New, _rv);
738 return _res;
739}
740
741static PyObject *DlgObj_GetDialogTextEditHandle(_self, _args)
742 DialogObject *_self;
743 PyObject *_args;
744{
745 PyObject *_res = NULL;
746 TEHandle _rv;
747 if (!PyArg_ParseTuple(_args, ""))
748 return NULL;
749 _rv = GetDialogTextEditHandle(_self->ob_itself);
750 _res = Py_BuildValue("O&",
751 ResObj_New, _rv);
Jack Jansend96cb501996-09-23 15:48:46 +0000752 return _res;
753}
754
755static PyObject *DlgObj_GetDialogDefaultItem(_self, _args)
756 DialogObject *_self;
757 PyObject *_args;
758{
759 PyObject *_res = NULL;
760 SInt16 _rv;
761 if (!PyArg_ParseTuple(_args, ""))
762 return NULL;
763 _rv = GetDialogDefaultItem(_self->ob_itself);
764 _res = Py_BuildValue("h",
765 _rv);
766 return _res;
767}
768
769static PyObject *DlgObj_GetDialogCancelItem(_self, _args)
770 DialogObject *_self;
771 PyObject *_args;
772{
773 PyObject *_res = NULL;
774 SInt16 _rv;
775 if (!PyArg_ParseTuple(_args, ""))
776 return NULL;
777 _rv = GetDialogCancelItem(_self->ob_itself);
778 _res = Py_BuildValue("h",
779 _rv);
780 return _res;
781}
782
783static PyObject *DlgObj_GetDialogKeyboardFocusItem(_self, _args)
784 DialogObject *_self;
785 PyObject *_args;
786{
787 PyObject *_res = NULL;
788 SInt16 _rv;
789 if (!PyArg_ParseTuple(_args, ""))
790 return NULL;
791 _rv = GetDialogKeyboardFocusItem(_self->ob_itself);
792 _res = Py_BuildValue("h",
793 _rv);
794 return _res;
795}
796
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000797static PyObject *DlgObj_SetPortDialogPort(_self, _args)
798 DialogObject *_self;
799 PyObject *_args;
800{
801 PyObject *_res = NULL;
802 if (!PyArg_ParseTuple(_args, ""))
803 return NULL;
804 SetPortDialogPort(_self->ob_itself);
805 Py_INCREF(Py_None);
806 _res = Py_None;
807 return _res;
808}
809
810static PyObject *DlgObj_GetDialogPort(_self, _args)
811 DialogObject *_self;
812 PyObject *_args;
813{
814 PyObject *_res = NULL;
815 CGrafPtr _rv;
816 if (!PyArg_ParseTuple(_args, ""))
817 return NULL;
818 _rv = GetDialogPort(_self->ob_itself);
819 _res = Py_BuildValue("O&",
820 GrafObj_New, _rv);
821 return _res;
822}
823
Jack Jansen74a1e632000-07-14 22:37:27 +0000824#if !TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000825
Jack Jansend96cb501996-09-23 15:48:46 +0000826static PyObject *DlgObj_SetGrafPortOfDialog(_self, _args)
827 DialogObject *_self;
828 PyObject *_args;
829{
830 PyObject *_res = NULL;
831 if (!PyArg_ParseTuple(_args, ""))
832 return NULL;
833 SetGrafPortOfDialog(_self->ob_itself);
834 Py_INCREF(Py_None);
835 _res = Py_None;
836 return _res;
837}
Jack Jansene79dc762000-06-02 21:35:07 +0000838#endif
Jack Jansend96cb501996-09-23 15:48:46 +0000839
Guido van Rossum17448e21995-01-30 11:53:55 +0000840static PyMethodDef DlgObj_methods[] = {
841 {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
842 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000843 {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
Jack Jansen2b724171996-04-10 14:48:19 +0000844 "(RgnHandle updateRgn) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000845 {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000846 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000847 {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000848 "(DialogItemIndex itemNo) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000849 {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000850 "(Point thePt) -> (DialogItemIndexZeroBased _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000851 {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000852 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000853 {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000854 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000855 {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000856 "() -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000857 {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000858 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000859 {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1,
860 "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"},
861 {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1,
862 "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"},
863 {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1,
864 "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000865 {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
866 "(Handle theHandle, DITLMethod method) -> None"},
867 {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000868 "() -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000869 {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000870 "(DialogItemIndex numberItems) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000871
872#if TARGET_API_MAC_CARBON
873 {"InsertDialogItem", (PyCFunction)DlgObj_InsertDialogItem, 1,
874 "(DialogItemIndex afterItem, DialogItemType itemType, Handle itemHandle, Rect box) -> None"},
875#endif
876
877#if TARGET_API_MAC_CARBON
878 {"RemoveDialogItems", (PyCFunction)DlgObj_RemoveDialogItems, 1,
879 "(DialogItemIndex itemNo, DialogItemIndex amountToRemove, Boolean disposeItemData) -> None"},
880#endif
Jack Jansenae8a68f1995-06-06 12:55:40 +0000881 {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000882 "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000883 {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000884 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000885 {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000886 "(DialogItemIndex newItem) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000887 {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
888 "(Boolean tracks) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000889 {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1,
890 "() -> None"},
891 {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1,
892 "(SInt16 inItemNo) -> (ControlHandle outControl)"},
893 {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1,
894 "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"},
895 {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1,
Jack Jansen1c4e6141998-04-21 15:23:55 +0000896 "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +0000897 {"AppendDialogItemList", (PyCFunction)DlgObj_AppendDialogItemList, 1,
898 "(SInt16 ditlID, DITLMethod method) -> None"},
899 {"SetDialogTimeout", (PyCFunction)DlgObj_SetDialogTimeout, 1,
900 "(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None"},
901 {"GetDialogTimeout", (PyCFunction)DlgObj_GetDialogTimeout, 1,
902 "() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)"},
903 {"SetModalDialogEventMask", (PyCFunction)DlgObj_SetModalDialogEventMask, 1,
904 "(EventMask inMask) -> None"},
905 {"GetModalDialogEventMask", (PyCFunction)DlgObj_GetModalDialogEventMask, 1,
906 "() -> (EventMask outMask)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000907 {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
Jack Jansene79dc762000-06-02 21:35:07 +0000908 "() -> (WindowPtr _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000909 {"GetDialogTextEditHandle", (PyCFunction)DlgObj_GetDialogTextEditHandle, 1,
910 "() -> (TEHandle _rv)"},
Jack Jansend96cb501996-09-23 15:48:46 +0000911 {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1,
912 "() -> (SInt16 _rv)"},
913 {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1,
914 "() -> (SInt16 _rv)"},
915 {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1,
916 "() -> (SInt16 _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000917 {"SetPortDialogPort", (PyCFunction)DlgObj_SetPortDialogPort, 1,
918 "() -> None"},
919 {"GetDialogPort", (PyCFunction)DlgObj_GetDialogPort, 1,
920 "() -> (CGrafPtr _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +0000921
Jack Jansen74a1e632000-07-14 22:37:27 +0000922#if !TARGET_API_MAC_CARBON
Jack Jansend96cb501996-09-23 15:48:46 +0000923 {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1,
924 "() -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +0000925#endif
Guido van Rossum17448e21995-01-30 11:53:55 +0000926 {NULL, NULL, 0}
927};
928
Jack Jansen69e7f112001-02-06 16:14:54 +0000929PyMethodChain DlgObj_chain = { DlgObj_methods, NULL };
Guido van Rossum17448e21995-01-30 11:53:55 +0000930
931static PyObject *DlgObj_getattr(self, name)
932 DialogObject *self;
933 char *name;
934{
935 return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name);
936}
937
938#define DlgObj_setattr NULL
939
Jack Jansen69e7f112001-02-06 16:14:54 +0000940static int DlgObj_compare(self, other)
941 DialogObject *self, *other;
942{
943 if ( self->ob_itself > other->ob_itself ) return 1;
944 if ( self->ob_itself < other->ob_itself ) return -1;
945 return 0;
946}
Jack Jansena05ac601999-12-12 21:41:51 +0000947
948#define DlgObj_repr NULL
949
Jack Jansen69e7f112001-02-06 16:14:54 +0000950static int DlgObj_hash(self)
951 DialogObject *self;
952{
953 return (int)self->ob_itself;
954}
Jack Jansena05ac601999-12-12 21:41:51 +0000955
Guido van Rossum17448e21995-01-30 11:53:55 +0000956PyTypeObject Dialog_Type = {
957 PyObject_HEAD_INIT(&PyType_Type)
958 0, /*ob_size*/
959 "Dialog", /*tp_name*/
960 sizeof(DialogObject), /*tp_basicsize*/
961 0, /*tp_itemsize*/
962 /* methods */
963 (destructor) DlgObj_dealloc, /*tp_dealloc*/
964 0, /*tp_print*/
965 (getattrfunc) DlgObj_getattr, /*tp_getattr*/
966 (setattrfunc) DlgObj_setattr, /*tp_setattr*/
Jack Jansena05ac601999-12-12 21:41:51 +0000967 (cmpfunc) DlgObj_compare, /*tp_compare*/
968 (reprfunc) DlgObj_repr, /*tp_repr*/
969 (PyNumberMethods *)0, /* tp_as_number */
970 (PySequenceMethods *)0, /* tp_as_sequence */
971 (PyMappingMethods *)0, /* tp_as_mapping */
972 (hashfunc) DlgObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +0000973};
974
975/* --------------------- End object type Dialog --------------------- */
976
977
978static PyObject *Dlg_NewDialog(_self, _args)
979 PyObject *_self;
980 PyObject *_args;
981{
982 PyObject *_res = NULL;
983 DialogPtr _rv;
984 Rect boundsRect;
985 Str255 title;
986 Boolean visible;
Jack Jansen21f96871998-02-20 16:02:09 +0000987 SInt16 procID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000988 WindowPtr behind;
989 Boolean goAwayFlag;
Jack Jansen21f96871998-02-20 16:02:09 +0000990 SInt32 refCon;
991 Handle items;
Guido van Rossum17448e21995-01-30 11:53:55 +0000992 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
993 PyMac_GetRect, &boundsRect,
994 PyMac_GetStr255, title,
995 &visible,
996 &procID,
997 WinObj_Convert, &behind,
998 &goAwayFlag,
999 &refCon,
Jack Jansen21f96871998-02-20 16:02:09 +00001000 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +00001001 return NULL;
1002 _rv = NewDialog((void *)0,
1003 &boundsRect,
1004 title,
1005 visible,
1006 procID,
1007 behind,
1008 goAwayFlag,
1009 refCon,
Jack Jansen21f96871998-02-20 16:02:09 +00001010 items);
Guido van Rossum17448e21995-01-30 11:53:55 +00001011 _res = Py_BuildValue("O&",
1012 DlgObj_New, _rv);
1013 return _res;
1014}
1015
1016static PyObject *Dlg_GetNewDialog(_self, _args)
1017 PyObject *_self;
1018 PyObject *_args;
1019{
1020 PyObject *_res = NULL;
1021 DialogPtr _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001022 SInt16 dialogID;
Guido van Rossum17448e21995-01-30 11:53:55 +00001023 WindowPtr behind;
1024 if (!PyArg_ParseTuple(_args, "hO&",
1025 &dialogID,
1026 WinObj_Convert, &behind))
1027 return NULL;
1028 _rv = GetNewDialog(dialogID,
1029 (void *)0,
1030 behind);
1031 _res = Py_BuildValue("O&",
1032 DlgObj_New, _rv);
1033 return _res;
1034}
1035
Jack Jansen21f96871998-02-20 16:02:09 +00001036static PyObject *Dlg_NewColorDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001037 PyObject *_self;
1038 PyObject *_args;
1039{
1040 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001041 DialogPtr _rv;
1042 Rect boundsRect;
1043 Str255 title;
1044 Boolean visible;
1045 SInt16 procID;
1046 WindowPtr behind;
1047 Boolean goAwayFlag;
1048 SInt32 refCon;
1049 Handle items;
1050 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
1051 PyMac_GetRect, &boundsRect,
1052 PyMac_GetStr255, title,
1053 &visible,
1054 &procID,
1055 WinObj_Convert, &behind,
1056 &goAwayFlag,
1057 &refCon,
1058 ResObj_Convert, &items))
Guido van Rossum17448e21995-01-30 11:53:55 +00001059 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001060 _rv = NewColorDialog((void *)0,
1061 &boundsRect,
1062 title,
1063 visible,
1064 procID,
1065 behind,
1066 goAwayFlag,
1067 refCon,
1068 items);
1069 _res = Py_BuildValue("O&",
1070 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +00001071 return _res;
1072}
1073
1074static PyObject *Dlg_ModalDialog(_self, _args)
1075 PyObject *_self;
1076 PyObject *_args;
1077{
1078 PyObject *_res = NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001079 PyObject* modalFilter;
Jack Jansen21f96871998-02-20 16:02:09 +00001080 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +00001081 if (!PyArg_ParseTuple(_args, "O",
Jack Jansenae8a68f1995-06-06 12:55:40 +00001082 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001083 return NULL;
Jack Jansen599ce9c2001-02-20 22:27:43 +00001084 ModalDialog(Dlg_PassFilterProc(modalFilter),
Guido van Rossum17448e21995-01-30 11:53:55 +00001085 &itemHit);
1086 _res = Py_BuildValue("h",
1087 itemHit);
1088 return _res;
1089}
1090
1091static PyObject *Dlg_IsDialogEvent(_self, _args)
1092 PyObject *_self;
1093 PyObject *_args;
1094{
1095 PyObject *_res = NULL;
1096 Boolean _rv;
1097 EventRecord theEvent;
1098 if (!PyArg_ParseTuple(_args, "O&",
1099 PyMac_GetEventRecord, &theEvent))
1100 return NULL;
1101 _rv = IsDialogEvent(&theEvent);
1102 _res = Py_BuildValue("b",
1103 _rv);
1104 return _res;
1105}
1106
1107static PyObject *Dlg_DialogSelect(_self, _args)
1108 PyObject *_self;
1109 PyObject *_args;
1110{
1111 PyObject *_res = NULL;
1112 Boolean _rv;
1113 EventRecord theEvent;
1114 DialogPtr theDialog;
Jack Jansen21f96871998-02-20 16:02:09 +00001115 DialogItemIndex itemHit;
Guido van Rossum17448e21995-01-30 11:53:55 +00001116 if (!PyArg_ParseTuple(_args, "O&",
1117 PyMac_GetEventRecord, &theEvent))
1118 return NULL;
1119 _rv = DialogSelect(&theEvent,
1120 &theDialog,
1121 &itemHit);
1122 _res = Py_BuildValue("bO&h",
1123 _rv,
Jack Jansen69e7f112001-02-06 16:14:54 +00001124 DlgObj_WhichDialog, theDialog,
Guido van Rossum17448e21995-01-30 11:53:55 +00001125 itemHit);
1126 return _res;
1127}
1128
1129static PyObject *Dlg_Alert(_self, _args)
1130 PyObject *_self;
1131 PyObject *_args;
1132{
1133 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001134 DialogItemIndex _rv;
1135 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001136 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001137 if (!PyArg_ParseTuple(_args, "hO",
1138 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001139 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001140 return NULL;
1141 _rv = Alert(alertID,
Jack Jansen599ce9c2001-02-20 22:27:43 +00001142 Dlg_PassFilterProc(modalFilter));
Guido van Rossum17448e21995-01-30 11:53:55 +00001143 _res = Py_BuildValue("h",
1144 _rv);
1145 return _res;
1146}
1147
1148static PyObject *Dlg_StopAlert(_self, _args)
1149 PyObject *_self;
1150 PyObject *_args;
1151{
1152 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001153 DialogItemIndex _rv;
1154 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001155 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001156 if (!PyArg_ParseTuple(_args, "hO",
1157 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001158 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001159 return NULL;
1160 _rv = StopAlert(alertID,
Jack Jansen599ce9c2001-02-20 22:27:43 +00001161 Dlg_PassFilterProc(modalFilter));
Guido van Rossum17448e21995-01-30 11:53:55 +00001162 _res = Py_BuildValue("h",
1163 _rv);
1164 return _res;
1165}
1166
1167static PyObject *Dlg_NoteAlert(_self, _args)
1168 PyObject *_self;
1169 PyObject *_args;
1170{
1171 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001172 DialogItemIndex _rv;
1173 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001174 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001175 if (!PyArg_ParseTuple(_args, "hO",
1176 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001177 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001178 return NULL;
1179 _rv = NoteAlert(alertID,
Jack Jansen599ce9c2001-02-20 22:27:43 +00001180 Dlg_PassFilterProc(modalFilter));
Guido van Rossum17448e21995-01-30 11:53:55 +00001181 _res = Py_BuildValue("h",
1182 _rv);
1183 return _res;
1184}
1185
1186static PyObject *Dlg_CautionAlert(_self, _args)
1187 PyObject *_self;
1188 PyObject *_args;
1189{
1190 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001191 DialogItemIndex _rv;
1192 SInt16 alertID;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001193 PyObject* modalFilter;
Guido van Rossum17448e21995-01-30 11:53:55 +00001194 if (!PyArg_ParseTuple(_args, "hO",
1195 &alertID,
Jack Jansenae8a68f1995-06-06 12:55:40 +00001196 &modalFilter))
Guido van Rossum17448e21995-01-30 11:53:55 +00001197 return NULL;
1198 _rv = CautionAlert(alertID,
Jack Jansen599ce9c2001-02-20 22:27:43 +00001199 Dlg_PassFilterProc(modalFilter));
Guido van Rossum17448e21995-01-30 11:53:55 +00001200 _res = Py_BuildValue("h",
1201 _rv);
1202 return _res;
1203}
1204
Jack Jansen21f96871998-02-20 16:02:09 +00001205static PyObject *Dlg_ParamText(_self, _args)
1206 PyObject *_self;
1207 PyObject *_args;
1208{
1209 PyObject *_res = NULL;
1210 Str255 param0;
1211 Str255 param1;
1212 Str255 param2;
1213 Str255 param3;
1214 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1215 PyMac_GetStr255, param0,
1216 PyMac_GetStr255, param1,
1217 PyMac_GetStr255, param2,
1218 PyMac_GetStr255, param3))
1219 return NULL;
1220 ParamText(param0,
1221 param1,
1222 param2,
1223 param3);
1224 Py_INCREF(Py_None);
1225 _res = Py_None;
1226 return _res;
1227}
1228
Jack Jansenae8a68f1995-06-06 12:55:40 +00001229static PyObject *Dlg_GetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001230 PyObject *_self;
1231 PyObject *_args;
1232{
1233 PyObject *_res = NULL;
1234 Handle item;
1235 Str255 text;
1236 if (!PyArg_ParseTuple(_args, "O&",
1237 ResObj_Convert, &item))
1238 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001239 GetDialogItemText(item,
1240 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001241 _res = Py_BuildValue("O&",
1242 PyMac_BuildStr255, text);
1243 return _res;
1244}
1245
Jack Jansenae8a68f1995-06-06 12:55:40 +00001246static PyObject *Dlg_SetDialogItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001247 PyObject *_self;
1248 PyObject *_args;
1249{
1250 PyObject *_res = NULL;
1251 Handle item;
1252 Str255 text;
1253 if (!PyArg_ParseTuple(_args, "O&O&",
1254 ResObj_Convert, &item,
1255 PyMac_GetStr255, text))
1256 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001257 SetDialogItemText(item,
1258 text);
Guido van Rossum17448e21995-01-30 11:53:55 +00001259 Py_INCREF(Py_None);
1260 _res = Py_None;
1261 return _res;
1262}
1263
Jack Jansenae8a68f1995-06-06 12:55:40 +00001264static PyObject *Dlg_GetAlertStage(_self, _args)
1265 PyObject *_self;
1266 PyObject *_args;
1267{
1268 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001269 SInt16 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001270 if (!PyArg_ParseTuple(_args, ""))
1271 return NULL;
1272 _rv = GetAlertStage();
1273 _res = Py_BuildValue("h",
1274 _rv);
1275 return _res;
1276}
1277
Jack Jansen21f96871998-02-20 16:02:09 +00001278static PyObject *Dlg_SetDialogFont(_self, _args)
1279 PyObject *_self;
1280 PyObject *_args;
1281{
1282 PyObject *_res = NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001283 SInt16 fontNum;
Jack Jansen21f96871998-02-20 16:02:09 +00001284 if (!PyArg_ParseTuple(_args, "h",
Jack Jansena05ac601999-12-12 21:41:51 +00001285 &fontNum))
Jack Jansen21f96871998-02-20 16:02:09 +00001286 return NULL;
Jack Jansena05ac601999-12-12 21:41:51 +00001287 SetDialogFont(fontNum);
Jack Jansen21f96871998-02-20 16:02:09 +00001288 Py_INCREF(Py_None);
1289 _res = Py_None;
1290 return _res;
1291}
1292
Jack Jansenae8a68f1995-06-06 12:55:40 +00001293static PyObject *Dlg_ResetAlertStage(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001294 PyObject *_self;
1295 PyObject *_args;
1296{
1297 PyObject *_res = NULL;
1298 if (!PyArg_ParseTuple(_args, ""))
1299 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +00001300 ResetAlertStage();
Guido van Rossum17448e21995-01-30 11:53:55 +00001301 Py_INCREF(Py_None);
1302 _res = Py_None;
1303 return _res;
1304}
1305
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001306#if TARGET_API_MAC_CARBON
1307
1308static PyObject *Dlg_GetParamText(_self, _args)
1309 PyObject *_self;
1310 PyObject *_args;
1311{
1312 PyObject *_res = NULL;
1313 Str255 param0;
1314 Str255 param1;
1315 Str255 param2;
1316 Str255 param3;
1317 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
1318 PyMac_GetStr255, param0,
1319 PyMac_GetStr255, param1,
1320 PyMac_GetStr255, param2,
1321 PyMac_GetStr255, param3))
1322 return NULL;
1323 GetParamText(param0,
1324 param1,
1325 param2,
1326 param3);
1327 Py_INCREF(Py_None);
1328 _res = Py_None;
1329 return _res;
1330}
1331#endif
1332
Jack Jansen21f96871998-02-20 16:02:09 +00001333static PyObject *Dlg_NewFeaturesDialog(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +00001334 PyObject *_self;
1335 PyObject *_args;
1336{
1337 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001338 DialogPtr _rv;
1339 Rect inBoundsRect;
1340 Str255 inTitle;
1341 Boolean inIsVisible;
1342 SInt16 inProcID;
1343 WindowPtr inBehind;
1344 Boolean inGoAwayFlag;
1345 SInt32 inRefCon;
1346 Handle inItemListHandle;
1347 UInt32 inFlags;
1348 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
1349 PyMac_GetRect, &inBoundsRect,
1350 PyMac_GetStr255, inTitle,
1351 &inIsVisible,
1352 &inProcID,
1353 WinObj_Convert, &inBehind,
1354 &inGoAwayFlag,
1355 &inRefCon,
1356 ResObj_Convert, &inItemListHandle,
1357 &inFlags))
Guido van Rossum17448e21995-01-30 11:53:55 +00001358 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001359 _rv = NewFeaturesDialog((void *)0,
1360 &inBoundsRect,
1361 inTitle,
1362 inIsVisible,
1363 inProcID,
1364 inBehind,
1365 inGoAwayFlag,
1366 inRefCon,
1367 inItemListHandle,
1368 inFlags);
1369 _res = Py_BuildValue("O&",
1370 DlgObj_New, _rv);
Guido van Rossum17448e21995-01-30 11:53:55 +00001371 return _res;
1372}
1373
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001374static PyObject *Dlg_GetDialogFromWindow(_self, _args)
1375 PyObject *_self;
1376 PyObject *_args;
1377{
1378 PyObject *_res = NULL;
1379 DialogPtr _rv;
1380 WindowPtr window;
1381 if (!PyArg_ParseTuple(_args, "O&",
1382 WinObj_Convert, &window))
1383 return NULL;
1384 _rv = GetDialogFromWindow(window);
1385 _res = Py_BuildValue("O&",
1386 DlgObj_New, _rv);
1387 return _res;
1388}
1389
Jack Jansendf901df1998-07-10 15:47:48 +00001390static PyObject *Dlg_SetUserItemHandler(_self, _args)
1391 PyObject *_self;
1392 PyObject *_args;
1393{
1394 PyObject *_res = NULL;
1395
1396 PyObject *new = NULL;
1397
1398
1399 if (!PyArg_ParseTuple(_args, "|O", &new))
1400 return NULL;
1401
1402 if (Dlg_UserItemProc_callback && new && new != Py_None) {
1403 PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
1404 return NULL;
1405 }
1406
Jack Jansen599ce9c2001-02-20 22:27:43 +00001407 if (new == NULL || new == Py_None) {
Jack Jansendf901df1998-07-10 15:47:48 +00001408 new = NULL;
1409 _res = Py_None;
1410 Py_INCREF(Py_None);
1411 } else {
1412 Py_INCREF(new);
1413 _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc));
1414 }
1415
1416 Dlg_UserItemProc_callback = new;
1417 return _res;
1418
1419}
1420
Guido van Rossum17448e21995-01-30 11:53:55 +00001421static PyMethodDef Dlg_methods[] = {
1422 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001423 "(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 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001425 "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
1426 {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
1427 "(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 +00001428 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001429 "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001430 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
1431 "(EventRecord theEvent) -> (Boolean _rv)"},
1432 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001433 "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001434 {"Alert", (PyCFunction)Dlg_Alert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001435 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001436 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001437 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001438 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001439 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001440 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001441 "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"},
1442 {"ParamText", (PyCFunction)Dlg_ParamText, 1,
1443 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001444 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001445 "(Handle item) -> (Str255 text)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001446 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001447 "(Handle item, Str255 text) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001448 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001449 "() -> (SInt16 _rv)"},
1450 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
Jack Jansena05ac601999-12-12 21:41:51 +00001451 "(SInt16 fontNum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001452 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001453 "() -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001454
1455#if TARGET_API_MAC_CARBON
1456 {"GetParamText", (PyCFunction)Dlg_GetParamText, 1,
1457 "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
1458#endif
Jack Jansen21f96871998-02-20 16:02:09 +00001459 {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
1460 "(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 +00001461 {"GetDialogFromWindow", (PyCFunction)Dlg_GetDialogFromWindow, 1,
1462 "(WindowPtr window) -> (DialogPtr _rv)"},
Jack Jansendf901df1998-07-10 15:47:48 +00001463 {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
1464 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001465 {NULL, NULL, 0}
1466};
1467
1468
1469
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001470/* Return the WindowPtr corresponding to a DialogObject */
1471
1472WindowPtr
1473DlgObj_ConvertToWindow(self)
1474 PyObject *self;
1475{
1476 if ( DlgObj_Check(self) )
1477 return GetDialogWindow(((DialogObject *)self)->ob_itself);
1478 return NULL;
1479}
Jack Jansen69e7f112001-02-06 16:14:54 +00001480/* Return the object corresponding to the dialog, or None */
1481
1482PyObject *
1483DlgObj_WhichDialog(d)
1484 DialogPtr d;
1485{
1486 PyObject *it;
1487
1488 if (d == NULL) {
1489 it = Py_None;
1490 Py_INCREF(it);
1491 } else {
1492 WindowPtr w = GetDialogWindow(d);
1493
1494 it = (PyObject *) GetWRefCon(w);
1495 if (it == NULL || ((DialogObject *)it)->ob_itself != d || !DlgObj_Check(it)) {
1496#if 0
1497 /* Should do this, but we don't have an ob_freeit for dialogs yet. */
1498 it = WinObj_New(w);
1499 ((WindowObject *)it)->ob_freeit = NULL;
1500#else
1501 it = Py_None;
1502 Py_INCREF(it);
1503#endif
1504 } else {
1505 Py_INCREF(it);
1506 }
1507 }
1508 return it;
1509}
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001510
Guido van Rossum17448e21995-01-30 11:53:55 +00001511
1512void initDlg()
1513{
1514 PyObject *m;
1515 PyObject *d;
1516
1517
1518
1519
1520 m = Py_InitModule("Dlg", Dlg_methods);
1521 d = PyModule_GetDict(m);
1522 Dlg_Error = PyMac_GetOSErrException();
1523 if (Dlg_Error == NULL ||
1524 PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001525 return;
Jack Jansena755e681997-09-20 17:40:22 +00001526 Dialog_Type.ob_type = &PyType_Type;
1527 Py_INCREF(&Dialog_Type);
1528 if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0)
1529 Py_FatalError("can't initialize DialogType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001530}
1531
1532/* ========================= End module Dlg ========================= */
1533