1 2 /* ========================== Module _Dlg =========================== */ 3 4 #include "Python.h" 5 #include "pymactoolbox.h" 6 7 #if APPLE_SUPPORTS_QUICKTIME 8 9 /* Macro to test whether a weak-loaded CFM function exists */ 10 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\ 11 PyErr_SetString(PyExc_NotImplementedError, \ 12 "Not available in this shared library/OS version"); \ 13 return NULL; \ 14 }} while(0) 15 16 17 #include <Carbon/Carbon.h> 18 19 #ifdef USE_TOOLBOX_OBJECT_GLUE 20 extern PyObject *_DlgObj_New(DialogRef); 21 extern PyObject *_DlgObj_WhichDialog(DialogRef); 22 extern int _DlgObj_Convert(PyObject *, DialogRef *); 23 24 #define DlgObj_New _DlgObj_New 25 #define DlgObj_WhichDialog _DlgObj_WhichDialog 26 #define DlgObj_Convert _DlgObj_Convert 27 #endif 28 29 /* XXX Shouldn't this be a stack? */ 30 static PyObject *Dlg_FilterProc_callback = NULL; 31 32 static 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 */ 42 args = Py_BuildValue("O&O&", DlgObj_WhichDialog, dialog, PyMac_BuildEventRecord, event); 43 if (args == NULL) 44 res = NULL; 45 else { 46 res = PyEval_CallObject(callback, args); 47 Py_DECREF(args); 48 } 49 if (res == NULL) { 50 PySys_WriteStderr("Exception in Dialog Filter\n"); 51 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 68 static ModalFilterUPP 69 Dlg_PassFilterProc(PyObject *callback) 70 { 71 PyObject *tmp = Dlg_FilterProc_callback; 72 static ModalFilterUPP UnivFilterUpp = NULL; 73 74 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); 82 if ( UnivFilterUpp == NULL ) 83 UnivFilterUpp = NewModalFilterUPP(&Dlg_UnivFilterProc); 84 return UnivFilterUpp; 85 } 86 87 static PyObject *Dlg_UserItemProc_callback = NULL; 88 89 static 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 */ 97 args = Py_BuildValue("O&h", DlgObj_WhichDialog, dialog, item); 98 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) { 105 PySys_WriteStderr("Exception in Dialog UserItem proc\n"); 106 PyErr_Print(); 107 } 108 Py_XDECREF(res); 109 return; 110 } 111 112 #if 0 113 /* 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 */ 122 extern PyMethodChain WinObj_chain; 123 #endif 124 125 static PyObject *Dlg_Error; 126 127 /* ----------------------- Object type Dialog ----------------------- */ 128 129 PyTypeObject Dialog_Type; 130 131 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type || PyObject_TypeCheck((x), &Dialog_Type)) 132 133 typedef struct DialogObject { 134 PyObject_HEAD 135 DialogPtr ob_itself; 136 } DialogObject; 137 138 PyObject *DlgObj_New(DialogPtr itself) 139 { 140 DialogObject *it; 141 if (itself == NULL) { Py_INCREF(Py_None); return Py_None; } 142 it = PyObject_NEW(DialogObject, &Dialog_Type); 143 if (it == NULL) return NULL; 144 it->ob_itself = itself; 145 SetWRefCon(GetDialogWindow(itself), (long)it); 146 return (PyObject *)it; 147 } 148 149 int DlgObj_Convert(PyObject *v, DialogPtr *p_itself) 150 { 151 if (v == Py_None) { *p_itself = NULL; return 1; } 152 if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v); 153 return 1; } 154 if (!DlgObj_Check(v)) 155 { 156 PyErr_SetString(PyExc_TypeError, "Dialog required"); 157 return 0; 158 } 159 *p_itself = ((DialogObject *)v)->ob_itself; 160 return 1; 161 } 162 163 static void DlgObj_dealloc(DialogObject *self) 164 { 165 DisposeDialog(self->ob_itself); 166 self->ob_type->tp_free((PyObject *)self); 167 } 168 169 static PyObject *DlgObj_DrawDialog(DialogObject *_self, PyObject *_args) 170 { 171 PyObject *_res = NULL; 172 #ifndef DrawDialog 173 PyMac_PRECHECK(DrawDialog); 174 #endif 175 if (!PyArg_ParseTuple(_args, "")) 176 return NULL; 177 DrawDialog(_self->ob_itself); 178 Py_INCREF(Py_None); 179 _res = Py_None; 180 return _res; 181 } 182 183 static PyObject *DlgObj_UpdateDialog(DialogObject *_self, PyObject *_args) 184 { 185 PyObject *_res = NULL; 186 RgnHandle updateRgn; 187 #ifndef UpdateDialog 188 PyMac_PRECHECK(UpdateDialog); 189 #endif 190 if (!PyArg_ParseTuple(_args, "O&", 191 ResObj_Convert, &updateRgn)) 192 return NULL; 193 UpdateDialog(_self->ob_itself, 194 updateRgn); 195 Py_INCREF(Py_None); 196 _res = Py_None; 197 return _res; 198 } 199 200 static PyObject *DlgObj_HideDialogItem(DialogObject *_self, PyObject *_args) 201 { 202 PyObject *_res = NULL; 203 DialogItemIndex itemNo; 204 #ifndef HideDialogItem 205 PyMac_PRECHECK(HideDialogItem); 206 #endif 207 if (!PyArg_ParseTuple(_args, "h", 208 &itemNo)) 209 return NULL; 210 HideDialogItem(_self->ob_itself, 211 itemNo); 212 Py_INCREF(Py_None); 213 _res = Py_None; 214 return _res; 215 } 216 217 static PyObject *DlgObj_ShowDialogItem(DialogObject *_self, PyObject *_args) 218 { 219 PyObject *_res = NULL; 220 DialogItemIndex itemNo; 221 #ifndef ShowDialogItem 222 PyMac_PRECHECK(ShowDialogItem); 223 #endif 224 if (!PyArg_ParseTuple(_args, "h", 225 &itemNo)) 226 return NULL; 227 ShowDialogItem(_self->ob_itself, 228 itemNo); 229 Py_INCREF(Py_None); 230 _res = Py_None; 231 return _res; 232 } 233 234 static PyObject *DlgObj_FindDialogItem(DialogObject *_self, PyObject *_args) 235 { 236 PyObject *_res = NULL; 237 DialogItemIndexZeroBased _rv; 238 Point thePt; 239 #ifndef FindDialogItem 240 PyMac_PRECHECK(FindDialogItem); 241 #endif 242 if (!PyArg_ParseTuple(_args, "O&", 243 PyMac_GetPoint, &thePt)) 244 return NULL; 245 _rv = FindDialogItem(_self->ob_itself, 246 thePt); 247 _res = Py_BuildValue("h", 248 _rv); 249 return _res; 250 } 251 252 static PyObject *DlgObj_DialogCut(DialogObject *_self, PyObject *_args) 253 { 254 PyObject *_res = NULL; 255 #ifndef DialogCut 256 PyMac_PRECHECK(DialogCut); 257 #endif 258 if (!PyArg_ParseTuple(_args, "")) 259 return NULL; 260 DialogCut(_self->ob_itself); 261 Py_INCREF(Py_None); 262 _res = Py_None; 263 return _res; 264 } 265 266 static PyObject *DlgObj_DialogPaste(DialogObject *_self, PyObject *_args) 267 { 268 PyObject *_res = NULL; 269 #ifndef DialogPaste 270 PyMac_PRECHECK(DialogPaste); 271 #endif 272 if (!PyArg_ParseTuple(_args, "")) 273 return NULL; 274 DialogPaste(_self->ob_itself); 275 Py_INCREF(Py_None); 276 _res = Py_None; 277 return _res; 278 } 279 280 static PyObject *DlgObj_DialogCopy(DialogObject *_self, PyObject *_args) 281 { 282 PyObject *_res = NULL; 283 #ifndef DialogCopy 284 PyMac_PRECHECK(DialogCopy); 285 #endif 286 if (!PyArg_ParseTuple(_args, "")) 287 return NULL; 288 DialogCopy(_self->ob_itself); 289 Py_INCREF(Py_None); 290 _res = Py_None; 291 return _res; 292 } 293 294 static PyObject *DlgObj_DialogDelete(DialogObject *_self, PyObject *_args) 295 { 296 PyObject *_res = NULL; 297 #ifndef DialogDelete 298 PyMac_PRECHECK(DialogDelete); 299 #endif 300 if (!PyArg_ParseTuple(_args, "")) 301 return NULL; 302 DialogDelete(_self->ob_itself); 303 Py_INCREF(Py_None); 304 _res = Py_None; 305 return _res; 306 } 307 308 static PyObject *DlgObj_GetDialogItem(DialogObject *_self, PyObject *_args) 309 { 310 PyObject *_res = NULL; 311 DialogItemIndex itemNo; 312 DialogItemType itemType; 313 Handle item; 314 Rect box; 315 #ifndef GetDialogItem 316 PyMac_PRECHECK(GetDialogItem); 317 #endif 318 if (!PyArg_ParseTuple(_args, "h", 319 &itemNo)) 320 return NULL; 321 GetDialogItem(_self->ob_itself, 322 itemNo, 323 &itemType, 324 &item, 325 &box); 326 _res = Py_BuildValue("hO&O&", 327 itemType, 328 OptResObj_New, item, 329 PyMac_BuildRect, &box); 330 return _res; 331 } 332 333 static PyObject *DlgObj_SetDialogItem(DialogObject *_self, PyObject *_args) 334 { 335 PyObject *_res = NULL; 336 DialogItemIndex itemNo; 337 DialogItemType itemType; 338 Handle item; 339 Rect box; 340 #ifndef SetDialogItem 341 PyMac_PRECHECK(SetDialogItem); 342 #endif 343 if (!PyArg_ParseTuple(_args, "hhO&O&", 344 &itemNo, 345 &itemType, 346 ResObj_Convert, &item, 347 PyMac_GetRect, &box)) 348 return NULL; 349 SetDialogItem(_self->ob_itself, 350 itemNo, 351 itemType, 352 item, 353 &box); 354 Py_INCREF(Py_None); 355 _res = Py_None; 356 return _res; 357 } 358 359 static PyObject *DlgObj_SelectDialogItemText(DialogObject *_self, PyObject *_args) 360 { 361 PyObject *_res = NULL; 362 DialogItemIndex itemNo; 363 SInt16 strtSel; 364 SInt16 endSel; 365 #ifndef SelectDialogItemText 366 PyMac_PRECHECK(SelectDialogItemText); 367 #endif 368 if (!PyArg_ParseTuple(_args, "hhh", 369 &itemNo, 370 &strtSel, 371 &endSel)) 372 return NULL; 373 SelectDialogItemText(_self->ob_itself, 374 itemNo, 375 strtSel, 376 endSel); 377 Py_INCREF(Py_None); 378 _res = Py_None; 379 return _res; 380 } 381 382 static PyObject *DlgObj_AppendDITL(DialogObject *_self, PyObject *_args) 383 { 384 PyObject *_res = NULL; 385 Handle theHandle; 386 DITLMethod method; 387 #ifndef AppendDITL 388 PyMac_PRECHECK(AppendDITL); 389 #endif 390 if (!PyArg_ParseTuple(_args, "O&h", 391 ResObj_Convert, &theHandle, 392 &method)) 393 return NULL; 394 AppendDITL(_self->ob_itself, 395 theHandle, 396 method); 397 Py_INCREF(Py_None); 398 _res = Py_None; 399 return _res; 400 } 401 402 static PyObject *DlgObj_CountDITL(DialogObject *_self, PyObject *_args) 403 { 404 PyObject *_res = NULL; 405 DialogItemIndex _rv; 406 #ifndef CountDITL 407 PyMac_PRECHECK(CountDITL); 408 #endif 409 if (!PyArg_ParseTuple(_args, "")) 410 return NULL; 411 _rv = CountDITL(_self->ob_itself); 412 _res = Py_BuildValue("h", 413 _rv); 414 return _res; 415 } 416 417 static PyObject *DlgObj_ShortenDITL(DialogObject *_self, PyObject *_args) 418 { 419 PyObject *_res = NULL; 420 DialogItemIndex numberItems; 421 #ifndef ShortenDITL 422 PyMac_PRECHECK(ShortenDITL); 423 #endif 424 if (!PyArg_ParseTuple(_args, "h", 425 &numberItems)) 426 return NULL; 427 ShortenDITL(_self->ob_itself, 428 numberItems); 429 Py_INCREF(Py_None); 430 _res = Py_None; 431 return _res; 432 } 433 434 static PyObject *DlgObj_InsertDialogItem(DialogObject *_self, PyObject *_args) 435 { 436 PyObject *_res = NULL; 437 OSStatus _err; 438 DialogItemIndex afterItem; 439 DialogItemType itemType; 440 Handle itemHandle; 441 Rect box; 442 #ifndef InsertDialogItem 443 PyMac_PRECHECK(InsertDialogItem); 444 #endif 445 if (!PyArg_ParseTuple(_args, "hhO&O&", 446 &afterItem, 447 &itemType, 448 ResObj_Convert, &itemHandle, 449 PyMac_GetRect, &box)) 450 return NULL; 451 _err = InsertDialogItem(_self->ob_itself, 452 afterItem, 453 itemType, 454 itemHandle, 455 &box); 456 if (_err != noErr) return PyMac_Error(_err); 457 Py_INCREF(Py_None); 458 _res = Py_None; 459 return _res; 460 } 461 462 static PyObject *DlgObj_RemoveDialogItems(DialogObject *_self, PyObject *_args) 463 { 464 PyObject *_res = NULL; 465 OSStatus _err; 466 DialogItemIndex itemNo; 467 DialogItemIndex amountToRemove; 468 Boolean disposeItemData; 469 #ifndef RemoveDialogItems 470 PyMac_PRECHECK(RemoveDialogItems); 471 #endif 472 if (!PyArg_ParseTuple(_args, "hhb", 473 &itemNo, 474 &amountToRemove, 475 &disposeItemData)) 476 return NULL; 477 _err = RemoveDialogItems(_self->ob_itself, 478 itemNo, 479 amountToRemove, 480 disposeItemData); 481 if (_err != noErr) return PyMac_Error(_err); 482 Py_INCREF(Py_None); 483 _res = Py_None; 484 return _res; 485 } 486 487 static PyObject *DlgObj_StdFilterProc(DialogObject *_self, PyObject *_args) 488 { 489 PyObject *_res = NULL; 490 Boolean _rv; 491 EventRecord event; 492 DialogItemIndex itemHit; 493 #ifndef StdFilterProc 494 PyMac_PRECHECK(StdFilterProc); 495 #endif 496 if (!PyArg_ParseTuple(_args, "O&h", 497 PyMac_GetEventRecord, &event, 498 &itemHit)) 499 return NULL; 500 _rv = StdFilterProc(_self->ob_itself, 501 &event, 502 &itemHit); 503 _res = Py_BuildValue("bO&h", 504 _rv, 505 PyMac_BuildEventRecord, &event, 506 itemHit); 507 return _res; 508 } 509 510 static PyObject *DlgObj_SetDialogDefaultItem(DialogObject *_self, PyObject *_args) 511 { 512 PyObject *_res = NULL; 513 OSErr _err; 514 DialogItemIndex newItem; 515 #ifndef SetDialogDefaultItem 516 PyMac_PRECHECK(SetDialogDefaultItem); 517 #endif 518 if (!PyArg_ParseTuple(_args, "h", 519 &newItem)) 520 return NULL; 521 _err = SetDialogDefaultItem(_self->ob_itself, 522 newItem); 523 if (_err != noErr) return PyMac_Error(_err); 524 Py_INCREF(Py_None); 525 _res = Py_None; 526 return _res; 527 } 528 529 static PyObject *DlgObj_SetDialogCancelItem(DialogObject *_self, PyObject *_args) 530 { 531 PyObject *_res = NULL; 532 OSErr _err; 533 DialogItemIndex newItem; 534 #ifndef SetDialogCancelItem 535 PyMac_PRECHECK(SetDialogCancelItem); 536 #endif 537 if (!PyArg_ParseTuple(_args, "h", 538 &newItem)) 539 return NULL; 540 _err = SetDialogCancelItem(_self->ob_itself, 541 newItem); 542 if (_err != noErr) return PyMac_Error(_err); 543 Py_INCREF(Py_None); 544 _res = Py_None; 545 return _res; 546 } 547 548 static PyObject *DlgObj_SetDialogTracksCursor(DialogObject *_self, PyObject *_args) 549 { 550 PyObject *_res = NULL; 551 OSErr _err; 552 Boolean tracks; 553 #ifndef SetDialogTracksCursor 554 PyMac_PRECHECK(SetDialogTracksCursor); 555 #endif 556 if (!PyArg_ParseTuple(_args, "b", 557 &tracks)) 558 return NULL; 559 _err = SetDialogTracksCursor(_self->ob_itself, 560 tracks); 561 if (_err != noErr) return PyMac_Error(_err); 562 Py_INCREF(Py_None); 563 _res = Py_None; 564 return _res; 565 } 566 567 static PyObject *DlgObj_AutoSizeDialog(DialogObject *_self, PyObject *_args) 568 { 569 PyObject *_res = NULL; 570 OSErr _err; 571 #ifndef AutoSizeDialog 572 PyMac_PRECHECK(AutoSizeDialog); 573 #endif 574 if (!PyArg_ParseTuple(_args, "")) 575 return NULL; 576 _err = AutoSizeDialog(_self->ob_itself); 577 if (_err != noErr) return PyMac_Error(_err); 578 Py_INCREF(Py_None); 579 _res = Py_None; 580 return _res; 581 } 582 583 static PyObject *DlgObj_GetDialogItemAsControl(DialogObject *_self, PyObject *_args) 584 { 585 PyObject *_res = NULL; 586 OSErr _err; 587 SInt16 inItemNo; 588 ControlHandle outControl; 589 #ifndef GetDialogItemAsControl 590 PyMac_PRECHECK(GetDialogItemAsControl); 591 #endif 592 if (!PyArg_ParseTuple(_args, "h", 593 &inItemNo)) 594 return NULL; 595 _err = GetDialogItemAsControl(_self->ob_itself, 596 inItemNo, 597 &outControl); 598 if (_err != noErr) return PyMac_Error(_err); 599 _res = Py_BuildValue("O&", 600 CtlObj_New, outControl); 601 return _res; 602 } 603 604 static PyObject *DlgObj_MoveDialogItem(DialogObject *_self, PyObject *_args) 605 { 606 PyObject *_res = NULL; 607 OSErr _err; 608 SInt16 inItemNo; 609 SInt16 inHoriz; 610 SInt16 inVert; 611 #ifndef MoveDialogItem 612 PyMac_PRECHECK(MoveDialogItem); 613 #endif 614 if (!PyArg_ParseTuple(_args, "hhh", 615 &inItemNo, 616 &inHoriz, 617 &inVert)) 618 return NULL; 619 _err = MoveDialogItem(_self->ob_itself, 620 inItemNo, 621 inHoriz, 622 inVert); 623 if (_err != noErr) return PyMac_Error(_err); 624 Py_INCREF(Py_None); 625 _res = Py_None; 626 return _res; 627 } 628 629 static PyObject *DlgObj_SizeDialogItem(DialogObject *_self, PyObject *_args) 630 { 631 PyObject *_res = NULL; 632 OSErr _err; 633 SInt16 inItemNo; 634 SInt16 inWidth; 635 SInt16 inHeight; 636 #ifndef SizeDialogItem 637 PyMac_PRECHECK(SizeDialogItem); 638 #endif 639 if (!PyArg_ParseTuple(_args, "hhh", 640 &inItemNo, 641 &inWidth, 642 &inHeight)) 643 return NULL; 644 _err = SizeDialogItem(_self->ob_itself, 645 inItemNo, 646 inWidth, 647 inHeight); 648 if (_err != noErr) return PyMac_Error(_err); 649 Py_INCREF(Py_None); 650 _res = Py_None; 651 return _res; 652 } 653 654 static PyObject *DlgObj_AppendDialogItemList(DialogObject *_self, PyObject *_args) 655 { 656 PyObject *_res = NULL; 657 OSErr _err; 658 SInt16 ditlID; 659 DITLMethod method; 660 #ifndef AppendDialogItemList 661 PyMac_PRECHECK(AppendDialogItemList); 662 #endif 663 if (!PyArg_ParseTuple(_args, "hh", 664 &ditlID, 665 &method)) 666 return NULL; 667 _err = AppendDialogItemList(_self->ob_itself, 668 ditlID, 669 method); 670 if (_err != noErr) return PyMac_Error(_err); 671 Py_INCREF(Py_None); 672 _res = Py_None; 673 return _res; 674 } 675 676 static PyObject *DlgObj_SetDialogTimeout(DialogObject *_self, PyObject *_args) 677 { 678 PyObject *_res = NULL; 679 OSStatus _err; 680 SInt16 inButtonToPress; 681 UInt32 inSecondsToWait; 682 #ifndef SetDialogTimeout 683 PyMac_PRECHECK(SetDialogTimeout); 684 #endif 685 if (!PyArg_ParseTuple(_args, "hl", 686 &inButtonToPress, 687 &inSecondsToWait)) 688 return NULL; 689 _err = SetDialogTimeout(_self->ob_itself, 690 inButtonToPress, 691 inSecondsToWait); 692 if (_err != noErr) return PyMac_Error(_err); 693 Py_INCREF(Py_None); 694 _res = Py_None; 695 return _res; 696 } 697 698 static PyObject *DlgObj_GetDialogTimeout(DialogObject *_self, PyObject *_args) 699 { 700 PyObject *_res = NULL; 701 OSStatus _err; 702 SInt16 outButtonToPress; 703 UInt32 outSecondsToWait; 704 UInt32 outSecondsRemaining; 705 #ifndef GetDialogTimeout 706 PyMac_PRECHECK(GetDialogTimeout); 707 #endif 708 if (!PyArg_ParseTuple(_args, "")) 709 return NULL; 710 _err = GetDialogTimeout(_self->ob_itself, 711 &outButtonToPress, 712 &outSecondsToWait, 713 &outSecondsRemaining); 714 if (_err != noErr) return PyMac_Error(_err); 715 _res = Py_BuildValue("hll", 716 outButtonToPress, 717 outSecondsToWait, 718 outSecondsRemaining); 719 return _res; 720 } 721 722 static PyObject *DlgObj_SetModalDialogEventMask(DialogObject *_self, PyObject *_args) 723 { 724 PyObject *_res = NULL; 725 OSStatus _err; 726 EventMask inMask; 727 #ifndef SetModalDialogEventMask 728 PyMac_PRECHECK(SetModalDialogEventMask); 729 #endif 730 if (!PyArg_ParseTuple(_args, "H", 731 &inMask)) 732 return NULL; 733 _err = SetModalDialogEventMask(_self->ob_itself, 734 inMask); 735 if (_err != noErr) return PyMac_Error(_err); 736 Py_INCREF(Py_None); 737 _res = Py_None; 738 return _res; 739 } 740 741 static PyObject *DlgObj_GetModalDialogEventMask(DialogObject *_self, PyObject *_args) 742 { 743 PyObject *_res = NULL; 744 OSStatus _err; 745 EventMask outMask; 746 #ifndef GetModalDialogEventMask 747 PyMac_PRECHECK(GetModalDialogEventMask); 748 #endif 749 if (!PyArg_ParseTuple(_args, "")) 750 return NULL; 751 _err = GetModalDialogEventMask(_self->ob_itself, 752 &outMask); 753 if (_err != noErr) return PyMac_Error(_err); 754 _res = Py_BuildValue("H", 755 outMask); 756 return _res; 757 } 758 759 static PyObject *DlgObj_GetDialogWindow(DialogObject *_self, PyObject *_args) 760 { 761 PyObject *_res = NULL; 762 WindowPtr _rv; 763 #ifndef GetDialogWindow 764 PyMac_PRECHECK(GetDialogWindow); 765 #endif 766 if (!PyArg_ParseTuple(_args, "")) 767 return NULL; 768 _rv = GetDialogWindow(_self->ob_itself); 769 _res = Py_BuildValue("O&", 770 WinObj_New, _rv); 771 return _res; 772 } 773 774 static PyObject *DlgObj_GetDialogTextEditHandle(DialogObject *_self, PyObject *_args) 775 { 776 PyObject *_res = NULL; 777 TEHandle _rv; 778 #ifndef GetDialogTextEditHandle 779 PyMac_PRECHECK(GetDialogTextEditHandle); 780 #endif 781 if (!PyArg_ParseTuple(_args, "")) 782 return NULL; 783 _rv = GetDialogTextEditHandle(_self->ob_itself); 784 _res = Py_BuildValue("O&", 785 ResObj_New, _rv); 786 return _res; 787 } 788 789 static PyObject *DlgObj_GetDialogDefaultItem(DialogObject *_self, PyObject *_args) 790 { 791 PyObject *_res = NULL; 792 SInt16 _rv; 793 #ifndef GetDialogDefaultItem 794 PyMac_PRECHECK(GetDialogDefaultItem); 795 #endif 796 if (!PyArg_ParseTuple(_args, "")) 797 return NULL; 798 _rv = GetDialogDefaultItem(_self->ob_itself); 799 _res = Py_BuildValue("h", 800 _rv); 801 return _res; 802 } 803 804 static PyObject *DlgObj_GetDialogCancelItem(DialogObject *_self, PyObject *_args) 805 { 806 PyObject *_res = NULL; 807 SInt16 _rv; 808 #ifndef GetDialogCancelItem 809 PyMac_PRECHECK(GetDialogCancelItem); 810 #endif 811 if (!PyArg_ParseTuple(_args, "")) 812 return NULL; 813 _rv = GetDialogCancelItem(_self->ob_itself); 814 _res = Py_BuildValue("h", 815 _rv); 816 return _res; 817 } 818 819 static PyObject *DlgObj_GetDialogKeyboardFocusItem(DialogObject *_self, PyObject *_args) 820 { 821 PyObject *_res = NULL; 822 SInt16 _rv; 823 #ifndef GetDialogKeyboardFocusItem 824 PyMac_PRECHECK(GetDialogKeyboardFocusItem); 825 #endif 826 if (!PyArg_ParseTuple(_args, "")) 827 return NULL; 828 _rv = GetDialogKeyboardFocusItem(_self->ob_itself); 829 _res = Py_BuildValue("h", 830 _rv); 831 return _res; 832 } 833 834 static PyObject *DlgObj_SetPortDialogPort(DialogObject *_self, PyObject *_args) 835 { 836 PyObject *_res = NULL; 837 #ifndef SetPortDialogPort 838 PyMac_PRECHECK(SetPortDialogPort); 839 #endif 840 if (!PyArg_ParseTuple(_args, "")) 841 return NULL; 842 SetPortDialogPort(_self->ob_itself); 843 Py_INCREF(Py_None); 844 _res = Py_None; 845 return _res; 846 } 847 848 static PyObject *DlgObj_GetDialogPort(DialogObject *_self, PyObject *_args) 849 { 850 PyObject *_res = NULL; 851 CGrafPtr _rv; 852 #ifndef GetDialogPort 853 PyMac_PRECHECK(GetDialogPort); 854 #endif 855 if (!PyArg_ParseTuple(_args, "")) 856 return NULL; 857 _rv = GetDialogPort(_self->ob_itself); 858 _res = Py_BuildValue("O&", 859 GrafObj_New, _rv); 860 return _res; 861 } 862 863 static PyMethodDef DlgObj_methods[] = { 864 {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1, 865 PyDoc_STR("() -> None")}, 866 {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1, 867 PyDoc_STR("(RgnHandle updateRgn) -> None")}, 868 {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1, 869 PyDoc_STR("(DialogItemIndex itemNo) -> None")}, 870 {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1, 871 PyDoc_STR("(DialogItemIndex itemNo) -> None")}, 872 {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1, 873 PyDoc_STR("(Point thePt) -> (DialogItemIndexZeroBased _rv)")}, 874 {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1, 875 PyDoc_STR("() -> None")}, 876 {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1, 877 PyDoc_STR("() -> None")}, 878 {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1, 879 PyDoc_STR("() -> None")}, 880 {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1, 881 PyDoc_STR("() -> None")}, 882 {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1, 883 PyDoc_STR("(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)")}, 884 {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1, 885 PyDoc_STR("(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None")}, 886 {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1, 887 PyDoc_STR("(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None")}, 888 {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1, 889 PyDoc_STR("(Handle theHandle, DITLMethod method) -> None")}, 890 {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1, 891 PyDoc_STR("() -> (DialogItemIndex _rv)")}, 892 {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1, 893 PyDoc_STR("(DialogItemIndex numberItems) -> None")}, 894 {"InsertDialogItem", (PyCFunction)DlgObj_InsertDialogItem, 1, 895 PyDoc_STR("(DialogItemIndex afterItem, DialogItemType itemType, Handle itemHandle, Rect box) -> None")}, 896 {"RemoveDialogItems", (PyCFunction)DlgObj_RemoveDialogItems, 1, 897 PyDoc_STR("(DialogItemIndex itemNo, DialogItemIndex amountToRemove, Boolean disposeItemData) -> None")}, 898 {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1, 899 PyDoc_STR("(EventRecord event, DialogItemIndex itemHit) -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)")}, 900 {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1, 901 PyDoc_STR("(DialogItemIndex newItem) -> None")}, 902 {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1, 903 PyDoc_STR("(DialogItemIndex newItem) -> None")}, 904 {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1, 905 PyDoc_STR("(Boolean tracks) -> None")}, 906 {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1, 907 PyDoc_STR("() -> None")}, 908 {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1, 909 PyDoc_STR("(SInt16 inItemNo) -> (ControlHandle outControl)")}, 910 {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1, 911 PyDoc_STR("(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None")}, 912 {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1, 913 PyDoc_STR("(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None")}, 914 {"AppendDialogItemList", (PyCFunction)DlgObj_AppendDialogItemList, 1, 915 PyDoc_STR("(SInt16 ditlID, DITLMethod method) -> None")}, 916 {"SetDialogTimeout", (PyCFunction)DlgObj_SetDialogTimeout, 1, 917 PyDoc_STR("(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None")}, 918 {"GetDialogTimeout", (PyCFunction)DlgObj_GetDialogTimeout, 1, 919 PyDoc_STR("() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)")}, 920 {"SetModalDialogEventMask", (PyCFunction)DlgObj_SetModalDialogEventMask, 1, 921 PyDoc_STR("(EventMask inMask) -> None")}, 922 {"GetModalDialogEventMask", (PyCFunction)DlgObj_GetModalDialogEventMask, 1, 923 PyDoc_STR("() -> (EventMask outMask)")}, 924 {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1, 925 PyDoc_STR("() -> (WindowPtr _rv)")}, 926 {"GetDialogTextEditHandle", (PyCFunction)DlgObj_GetDialogTextEditHandle, 1, 927 PyDoc_STR("() -> (TEHandle _rv)")}, 928 {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1, 929 PyDoc_STR("() -> (SInt16 _rv)")}, 930 {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1, 931 PyDoc_STR("() -> (SInt16 _rv)")}, 932 {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1, 933 PyDoc_STR("() -> (SInt16 _rv)")}, 934 {"SetPortDialogPort", (PyCFunction)DlgObj_SetPortDialogPort, 1, 935 PyDoc_STR("() -> None")}, 936 {"GetDialogPort", (PyCFunction)DlgObj_GetDialogPort, 1, 937 PyDoc_STR("() -> (CGrafPtr _rv)")}, 938 {NULL, NULL, 0} 939 }; 940 941 #define DlgObj_getsetlist NULL 942 943 944 static int DlgObj_compare(DialogObject *self, DialogObject *other) 945 { 946 if ( self->ob_itself > other->ob_itself ) return 1; 947 if ( self->ob_itself < other->ob_itself ) return -1; 948 return 0; 949 } 950 951 #define DlgObj_repr NULL 952 953 static int DlgObj_hash(DialogObject *self) 954 { 955 return (int)self->ob_itself; 956 } 957 #define DlgObj_tp_init 0 958 959 #define DlgObj_tp_alloc PyType_GenericAlloc 960 961 static PyObject *DlgObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds) 962 { 963 PyObject *_self; 964 DialogPtr itself; 965 char *kw[] = {"itself", 0}; 966 967 if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, DlgObj_Convert, &itself)) return NULL; 968 if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL; 969 ((DialogObject *)_self)->ob_itself = itself; 970 return _self; 971 } 972 973 #define DlgObj_tp_free PyObject_Del 974 975 976 PyTypeObject Dialog_Type = { 977 PyObject_HEAD_INIT(NULL) 978 0, /*ob_size*/ 979 "_Dlg.Dialog", /*tp_name*/ 980 sizeof(DialogObject), /*tp_basicsize*/ 981 0, /*tp_itemsize*/ 982 /* methods */ 983 (destructor) DlgObj_dealloc, /*tp_dealloc*/ 984 0, /*tp_print*/ 985 (getattrfunc)0, /*tp_getattr*/ 986 (setattrfunc)0, /*tp_setattr*/ 987 (cmpfunc) DlgObj_compare, /*tp_compare*/ 988 (reprfunc) DlgObj_repr, /*tp_repr*/ 989 (PyNumberMethods *)0, /* tp_as_number */ 990 (PySequenceMethods *)0, /* tp_as_sequence */ 991 (PyMappingMethods *)0, /* tp_as_mapping */ 992 (hashfunc) DlgObj_hash, /*tp_hash*/ 993 0, /*tp_call*/ 994 0, /*tp_str*/ 995 PyObject_GenericGetAttr, /*tp_getattro*/ 996 PyObject_GenericSetAttr, /*tp_setattro */ 997 0, /*tp_as_buffer*/ 998 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ 999 0, /*tp_doc*/ 1000 0, /*tp_traverse*/ 1001 0, /*tp_clear*/ 1002 0, /*tp_richcompare*/ 1003 0, /*tp_weaklistoffset*/ 1004 0, /*tp_iter*/ 1005 0, /*tp_iternext*/ 1006 DlgObj_methods, /* tp_methods */ 1007 0, /*tp_members*/ 1008 DlgObj_getsetlist, /*tp_getset*/ 1009 0, /*tp_base*/ 1010 0, /*tp_dict*/ 1011 0, /*tp_descr_get*/ 1012 0, /*tp_descr_set*/ 1013 0, /*tp_dictoffset*/ 1014 DlgObj_tp_init, /* tp_init */ 1015 DlgObj_tp_alloc, /* tp_alloc */ 1016 DlgObj_tp_new, /* tp_new */ 1017 DlgObj_tp_free, /* tp_free */ 1018 }; 1019 1020 /* --------------------- End object type Dialog --------------------- */ 1021 1022 1023 static PyObject *Dlg_NewDialog(PyObject *_self, PyObject *_args) 1024 { 1025 PyObject *_res = NULL; 1026 DialogPtr _rv; 1027 Rect boundsRect; 1028 Str255 title; 1029 Boolean visible; 1030 SInt16 procID; 1031 WindowPtr behind; 1032 Boolean goAwayFlag; 1033 SInt32 refCon; 1034 Handle items; 1035 #ifndef NewDialog 1036 PyMac_PRECHECK(NewDialog); 1037 #endif 1038 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&", 1039 PyMac_GetRect, &boundsRect, 1040 PyMac_GetStr255, title, 1041 &visible, 1042 &procID, 1043 WinObj_Convert, &behind, 1044 &goAwayFlag, 1045 &refCon, 1046 ResObj_Convert, &items)) 1047 return NULL; 1048 _rv = NewDialog((void *)0, 1049 &boundsRect, 1050 title, 1051 visible, 1052 procID, 1053 behind, 1054 goAwayFlag, 1055 refCon, 1056 items); 1057 _res = Py_BuildValue("O&", 1058 DlgObj_New, _rv); 1059 return _res; 1060 } 1061 1062 static PyObject *Dlg_GetNewDialog(PyObject *_self, PyObject *_args) 1063 { 1064 PyObject *_res = NULL; 1065 DialogPtr _rv; 1066 SInt16 dialogID; 1067 WindowPtr behind; 1068 #ifndef GetNewDialog 1069 PyMac_PRECHECK(GetNewDialog); 1070 #endif 1071 if (!PyArg_ParseTuple(_args, "hO&", 1072 &dialogID, 1073 WinObj_Convert, &behind)) 1074 return NULL; 1075 _rv = GetNewDialog(dialogID, 1076 (void *)0, 1077 behind); 1078 _res = Py_BuildValue("O&", 1079 DlgObj_New, _rv); 1080 return _res; 1081 } 1082 1083 static PyObject *Dlg_NewColorDialog(PyObject *_self, PyObject *_args) 1084 { 1085 PyObject *_res = NULL; 1086 DialogPtr _rv; 1087 Rect boundsRect; 1088 Str255 title; 1089 Boolean visible; 1090 SInt16 procID; 1091 WindowPtr behind; 1092 Boolean goAwayFlag; 1093 SInt32 refCon; 1094 Handle items; 1095 #ifndef NewColorDialog 1096 PyMac_PRECHECK(NewColorDialog); 1097 #endif 1098 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&", 1099 PyMac_GetRect, &boundsRect, 1100 PyMac_GetStr255, title, 1101 &visible, 1102 &procID, 1103 WinObj_Convert, &behind, 1104 &goAwayFlag, 1105 &refCon, 1106 ResObj_Convert, &items)) 1107 return NULL; 1108 _rv = NewColorDialog((void *)0, 1109 &boundsRect, 1110 title, 1111 visible, 1112 procID, 1113 behind, 1114 goAwayFlag, 1115 refCon, 1116 items); 1117 _res = Py_BuildValue("O&", 1118 DlgObj_New, _rv); 1119 return _res; 1120 } 1121 1122 static PyObject *Dlg_ModalDialog(PyObject *_self, PyObject *_args) 1123 { 1124 PyObject *_res = NULL; 1125 PyObject* modalFilter; 1126 DialogItemIndex itemHit; 1127 #ifndef ModalDialog 1128 PyMac_PRECHECK(ModalDialog); 1129 #endif 1130 if (!PyArg_ParseTuple(_args, "O", 1131 &modalFilter)) 1132 return NULL; 1133 ModalDialog(Dlg_PassFilterProc(modalFilter), 1134 &itemHit); 1135 _res = Py_BuildValue("h", 1136 itemHit); 1137 return _res; 1138 } 1139 1140 static PyObject *Dlg_IsDialogEvent(PyObject *_self, PyObject *_args) 1141 { 1142 PyObject *_res = NULL; 1143 Boolean _rv; 1144 EventRecord theEvent; 1145 #ifndef IsDialogEvent 1146 PyMac_PRECHECK(IsDialogEvent); 1147 #endif 1148 if (!PyArg_ParseTuple(_args, "O&", 1149 PyMac_GetEventRecord, &theEvent)) 1150 return NULL; 1151 _rv = IsDialogEvent(&theEvent); 1152 _res = Py_BuildValue("b", 1153 _rv); 1154 return _res; 1155 } 1156 1157 static PyObject *Dlg_DialogSelect(PyObject *_self, PyObject *_args) 1158 { 1159 PyObject *_res = NULL; 1160 Boolean _rv; 1161 EventRecord theEvent; 1162 DialogPtr theDialog; 1163 DialogItemIndex itemHit; 1164 #ifndef DialogSelect 1165 PyMac_PRECHECK(DialogSelect); 1166 #endif 1167 if (!PyArg_ParseTuple(_args, "O&", 1168 PyMac_GetEventRecord, &theEvent)) 1169 return NULL; 1170 _rv = DialogSelect(&theEvent, 1171 &theDialog, 1172 &itemHit); 1173 _res = Py_BuildValue("bO&h", 1174 _rv, 1175 DlgObj_WhichDialog, theDialog, 1176 itemHit); 1177 return _res; 1178 } 1179 1180 static PyObject *Dlg_Alert(PyObject *_self, PyObject *_args) 1181 { 1182 PyObject *_res = NULL; 1183 DialogItemIndex _rv; 1184 SInt16 alertID; 1185 PyObject* modalFilter; 1186 #ifndef Alert 1187 PyMac_PRECHECK(Alert); 1188 #endif 1189 if (!PyArg_ParseTuple(_args, "hO", 1190 &alertID, 1191 &modalFilter)) 1192 return NULL; 1193 _rv = Alert(alertID, 1194 Dlg_PassFilterProc(modalFilter)); 1195 _res = Py_BuildValue("h", 1196 _rv); 1197 return _res; 1198 } 1199 1200 static PyObject *Dlg_StopAlert(PyObject *_self, PyObject *_args) 1201 { 1202 PyObject *_res = NULL; 1203 DialogItemIndex _rv; 1204 SInt16 alertID; 1205 PyObject* modalFilter; 1206 #ifndef StopAlert 1207 PyMac_PRECHECK(StopAlert); 1208 #endif 1209 if (!PyArg_ParseTuple(_args, "hO", 1210 &alertID, 1211 &modalFilter)) 1212 return NULL; 1213 _rv = StopAlert(alertID, 1214 Dlg_PassFilterProc(modalFilter)); 1215 _res = Py_BuildValue("h", 1216 _rv); 1217 return _res; 1218 } 1219 1220 static PyObject *Dlg_NoteAlert(PyObject *_self, PyObject *_args) 1221 { 1222 PyObject *_res = NULL; 1223 DialogItemIndex _rv; 1224 SInt16 alertID; 1225 PyObject* modalFilter; 1226 #ifndef NoteAlert 1227 PyMac_PRECHECK(NoteAlert); 1228 #endif 1229 if (!PyArg_ParseTuple(_args, "hO", 1230 &alertID, 1231 &modalFilter)) 1232 return NULL; 1233 _rv = NoteAlert(alertID, 1234 Dlg_PassFilterProc(modalFilter)); 1235 _res = Py_BuildValue("h", 1236 _rv); 1237 return _res; 1238 } 1239 1240 static PyObject *Dlg_CautionAlert(PyObject *_self, PyObject *_args) 1241 { 1242 PyObject *_res = NULL; 1243 DialogItemIndex _rv; 1244 SInt16 alertID; 1245 PyObject* modalFilter; 1246 #ifndef CautionAlert 1247 PyMac_PRECHECK(CautionAlert); 1248 #endif 1249 if (!PyArg_ParseTuple(_args, "hO", 1250 &alertID, 1251 &modalFilter)) 1252 return NULL; 1253 _rv = CautionAlert(alertID, 1254 Dlg_PassFilterProc(modalFilter)); 1255 _res = Py_BuildValue("h", 1256 _rv); 1257 return _res; 1258 } 1259 1260 static PyObject *Dlg_ParamText(PyObject *_self, PyObject *_args) 1261 { 1262 PyObject *_res = NULL; 1263 Str255 param0; 1264 Str255 param1; 1265 Str255 param2; 1266 Str255 param3; 1267 #ifndef ParamText 1268 PyMac_PRECHECK(ParamText); 1269 #endif 1270 if (!PyArg_ParseTuple(_args, "O&O&O&O&", 1271 PyMac_GetStr255, param0, 1272 PyMac_GetStr255, param1, 1273 PyMac_GetStr255, param2, 1274 PyMac_GetStr255, param3)) 1275 return NULL; 1276 ParamText(param0, 1277 param1, 1278 param2, 1279 param3); 1280 Py_INCREF(Py_None); 1281 _res = Py_None; 1282 return _res; 1283 } 1284 1285 static PyObject *Dlg_GetDialogItemText(PyObject *_self, PyObject *_args) 1286 { 1287 PyObject *_res = NULL; 1288 Handle item; 1289 Str255 text; 1290 #ifndef GetDialogItemText 1291 PyMac_PRECHECK(GetDialogItemText); 1292 #endif 1293 if (!PyArg_ParseTuple(_args, "O&", 1294 ResObj_Convert, &item)) 1295 return NULL; 1296 GetDialogItemText(item, 1297 text); 1298 _res = Py_BuildValue("O&", 1299 PyMac_BuildStr255, text); 1300 return _res; 1301 } 1302 1303 static PyObject *Dlg_SetDialogItemText(PyObject *_self, PyObject *_args) 1304 { 1305 PyObject *_res = NULL; 1306 Handle item; 1307 Str255 text; 1308 #ifndef SetDialogItemText 1309 PyMac_PRECHECK(SetDialogItemText); 1310 #endif 1311 if (!PyArg_ParseTuple(_args, "O&O&", 1312 ResObj_Convert, &item, 1313 PyMac_GetStr255, text)) 1314 return NULL; 1315 SetDialogItemText(item, 1316 text); 1317 Py_INCREF(Py_None); 1318 _res = Py_None; 1319 return _res; 1320 } 1321 1322 static PyObject *Dlg_GetAlertStage(PyObject *_self, PyObject *_args) 1323 { 1324 PyObject *_res = NULL; 1325 SInt16 _rv; 1326 #ifndef GetAlertStage 1327 PyMac_PRECHECK(GetAlertStage); 1328 #endif 1329 if (!PyArg_ParseTuple(_args, "")) 1330 return NULL; 1331 _rv = GetAlertStage(); 1332 _res = Py_BuildValue("h", 1333 _rv); 1334 return _res; 1335 } 1336 1337 static PyObject *Dlg_SetDialogFont(PyObject *_self, PyObject *_args) 1338 { 1339 PyObject *_res = NULL; 1340 SInt16 fontNum; 1341 #ifndef SetDialogFont 1342 PyMac_PRECHECK(SetDialogFont); 1343 #endif 1344 if (!PyArg_ParseTuple(_args, "h", 1345 &fontNum)) 1346 return NULL; 1347 SetDialogFont(fontNum); 1348 Py_INCREF(Py_None); 1349 _res = Py_None; 1350 return _res; 1351 } 1352 1353 static PyObject *Dlg_ResetAlertStage(PyObject *_self, PyObject *_args) 1354 { 1355 PyObject *_res = NULL; 1356 #ifndef ResetAlertStage 1357 PyMac_PRECHECK(ResetAlertStage); 1358 #endif 1359 if (!PyArg_ParseTuple(_args, "")) 1360 return NULL; 1361 ResetAlertStage(); 1362 Py_INCREF(Py_None); 1363 _res = Py_None; 1364 return _res; 1365 } 1366 1367 static PyObject *Dlg_GetParamText(PyObject *_self, PyObject *_args) 1368 { 1369 PyObject *_res = NULL; 1370 Str255 param0; 1371 Str255 param1; 1372 Str255 param2; 1373 Str255 param3; 1374 #ifndef GetParamText 1375 PyMac_PRECHECK(GetParamText); 1376 #endif 1377 if (!PyArg_ParseTuple(_args, "O&O&O&O&", 1378 PyMac_GetStr255, param0, 1379 PyMac_GetStr255, param1, 1380 PyMac_GetStr255, param2, 1381 PyMac_GetStr255, param3)) 1382 return NULL; 1383 GetParamText(param0, 1384 param1, 1385 param2, 1386 param3); 1387 Py_INCREF(Py_None); 1388 _res = Py_None; 1389 return _res; 1390 } 1391 1392 static PyObject *Dlg_NewFeaturesDialog(PyObject *_self, PyObject *_args) 1393 { 1394 PyObject *_res = NULL; 1395 DialogPtr _rv; 1396 Rect inBoundsRect; 1397 Str255 inTitle; 1398 Boolean inIsVisible; 1399 SInt16 inProcID; 1400 WindowPtr inBehind; 1401 Boolean inGoAwayFlag; 1402 SInt32 inRefCon; 1403 Handle inItemListHandle; 1404 UInt32 inFlags; 1405 #ifndef NewFeaturesDialog 1406 PyMac_PRECHECK(NewFeaturesDialog); 1407 #endif 1408 if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l", 1409 PyMac_GetRect, &inBoundsRect, 1410 PyMac_GetStr255, inTitle, 1411 &inIsVisible, 1412 &inProcID, 1413 WinObj_Convert, &inBehind, 1414 &inGoAwayFlag, 1415 &inRefCon, 1416 ResObj_Convert, &inItemListHandle, 1417 &inFlags)) 1418 return NULL; 1419 _rv = NewFeaturesDialog((void *)0, 1420 &inBoundsRect, 1421 inTitle, 1422 inIsVisible, 1423 inProcID, 1424 inBehind, 1425 inGoAwayFlag, 1426 inRefCon, 1427 inItemListHandle, 1428 inFlags); 1429 _res = Py_BuildValue("O&", 1430 DlgObj_New, _rv); 1431 return _res; 1432 } 1433 1434 static PyObject *Dlg_GetDialogFromWindow(PyObject *_self, PyObject *_args) 1435 { 1436 PyObject *_res = NULL; 1437 DialogPtr _rv; 1438 WindowPtr window; 1439 #ifndef GetDialogFromWindow 1440 PyMac_PRECHECK(GetDialogFromWindow); 1441 #endif 1442 if (!PyArg_ParseTuple(_args, "O&", 1443 WinObj_Convert, &window)) 1444 return NULL; 1445 _rv = GetDialogFromWindow(window); 1446 _res = Py_BuildValue("O&", 1447 DlgObj_New, _rv); 1448 return _res; 1449 } 1450 1451 static PyObject *Dlg_SetUserItemHandler(PyObject *_self, PyObject *_args) 1452 { 1453 PyObject *_res = NULL; 1454 1455 PyObject *new = NULL; 1456 1457 1458 if (!PyArg_ParseTuple(_args, "|O", &new)) 1459 return NULL; 1460 1461 if (Dlg_UserItemProc_callback && new && new != Py_None) { 1462 PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed"); 1463 return NULL; 1464 } 1465 1466 if (new == NULL || new == Py_None) { 1467 new = NULL; 1468 _res = Py_None; 1469 Py_INCREF(Py_None); 1470 } else { 1471 Py_INCREF(new); 1472 _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemUPP(Dlg_UnivUserItemProc)); 1473 } 1474 1475 Dlg_UserItemProc_callback = new; 1476 return _res; 1477 1478 } 1479 1480 static PyMethodDef Dlg_methods[] = { 1481 {"NewDialog", (PyCFunction)Dlg_NewDialog, 1, 1482 PyDoc_STR("(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)")}, 1483 {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1, 1484 PyDoc_STR("(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)")}, 1485 {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1, 1486 PyDoc_STR("(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)")}, 1487 {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1, 1488 PyDoc_STR("(PyObject* modalFilter) -> (DialogItemIndex itemHit)")}, 1489 {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1, 1490 PyDoc_STR("(EventRecord theEvent) -> (Boolean _rv)")}, 1491 {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1, 1492 PyDoc_STR("(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)")}, 1493 {"Alert", (PyCFunction)Dlg_Alert, 1, 1494 PyDoc_STR("(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)")}, 1495 {"StopAlert", (PyCFunction)Dlg_StopAlert, 1, 1496 PyDoc_STR("(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)")}, 1497 {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1, 1498 PyDoc_STR("(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)")}, 1499 {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1, 1500 PyDoc_STR("(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)")}, 1501 {"ParamText", (PyCFunction)Dlg_ParamText, 1, 1502 PyDoc_STR("(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None")}, 1503 {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1, 1504 PyDoc_STR("(Handle item) -> (Str255 text)")}, 1505 {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1, 1506 PyDoc_STR("(Handle item, Str255 text) -> None")}, 1507 {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1, 1508 PyDoc_STR("() -> (SInt16 _rv)")}, 1509 {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1, 1510 PyDoc_STR("(SInt16 fontNum) -> None")}, 1511 {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1, 1512 PyDoc_STR("() -> None")}, 1513 {"GetParamText", (PyCFunction)Dlg_GetParamText, 1, 1514 PyDoc_STR("(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None")}, 1515 {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1, 1516 PyDoc_STR("(Rect inBoundsRect, Str255 inTitle, Boolean inIsVisible, SInt16 inProcID, WindowPtr inBehind, Boolean inGoAwayFlag, SInt32 inRefCon, Handle inItemListHandle, UInt32 inFlags) -> (DialogPtr _rv)")}, 1517 {"GetDialogFromWindow", (PyCFunction)Dlg_GetDialogFromWindow, 1, 1518 PyDoc_STR("(WindowPtr window) -> (DialogPtr _rv)")}, 1519 {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1, 1520 PyDoc_STR(NULL)}, 1521 {NULL, NULL, 0} 1522 }; 1523 1524 1525 1526 /* Return the WindowPtr corresponding to a DialogObject */ 1527 #if 0 1528 WindowPtr 1529 DlgObj_ConvertToWindow(PyObject *self) 1530 { 1531 if ( DlgObj_Check(self) ) 1532 return GetDialogWindow(((DialogObject *)self)->ob_itself); 1533 return NULL; 1534 } 1535 #endif 1536 /* Return the object corresponding to the dialog, or None */ 1537 1538 PyObject * 1539 DlgObj_WhichDialog(DialogPtr d) 1540 { 1541 PyObject *it; 1542 1543 if (d == NULL) { 1544 it = Py_None; 1545 Py_INCREF(it); 1546 } else { 1547 WindowPtr w = GetDialogWindow(d); 1548 1549 it = (PyObject *) GetWRefCon(w); 1550 if (it == NULL || ((DialogObject *)it)->ob_itself != d || !DlgObj_Check(it)) { 1551 #if 0 1552 /* Should do this, but we don't have an ob_freeit for dialogs yet. */ 1553 it = WinObj_New(w); 1554 ((WindowObject *)it)->ob_freeit = NULL; 1555 #else 1556 it = Py_None; 1557 Py_INCREF(it); 1558 #endif 1559 } else { 1560 Py_INCREF(it); 1561 } 1562 } 1563 return it; 1564 } 1565 1566 #else /* __LP64__ */ 1567 1568 static PyMethodDef Dlg_methods[] = { 1569 {NULL, NULL, 0} 1570 }; 1571 1572 #endif /* __LP64__ */ 1573 1574 1575 void init_Dlg(void) 1576 { 1577 PyObject *m; 1578 #if APPLE_SUPPORTS_QUICKTIME 1579 PyObject *d; 1580 1581 1582 1583 PyMac_INIT_TOOLBOX_OBJECT_NEW(DialogPtr, DlgObj_New); 1584 PyMac_INIT_TOOLBOX_OBJECT_NEW(DialogPtr, DlgObj_WhichDialog); 1585 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DialogPtr, DlgObj_Convert); 1586 #endif /* APPLE_SUPPORTS_QUICKTIME */ 1587 1588 m = Py_InitModule("_Dlg", Dlg_methods); 1589 1590 #if APPLE_SUPPORTS_QUICKTIME 1591 d = PyModule_GetDict(m); 1592 Dlg_Error = PyMac_GetOSErrException(); 1593 if (Dlg_Error == NULL || 1594 PyDict_SetItemString(d, "Error", Dlg_Error) != 0) 1595 return; 1596 Dialog_Type.ob_type = &PyType_Type; 1597 if (PyType_Ready(&Dialog_Type) < 0) return; 1598 Py_INCREF(&Dialog_Type); 1599 PyModule_AddObject(m, "Dialog", (PyObject *)&Dialog_Type); 1600 /* Backward-compatible name */ 1601 Py_INCREF(&Dialog_Type); 1602 PyModule_AddObject(m, "DialogType", (PyObject *)&Dialog_Type); 1603 #endif /* APPLE_SUPPORTS_QUICKTIME */ 1604 } 1605 1606 /* ======================== End module _Dlg ========================= */ 1607 1608