Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1 | |
| 2 | /* =========================== Module Dlg =========================== */ |
| 3 | |
| 4 | #include "Python.h" |
| 5 | |
| 6 | |
| 7 | |
| 8 | #define SystemSevenOrLater 1 |
| 9 | |
| 10 | #include "macglue.h" |
| 11 | #include <Memory.h> |
| 12 | #include <Dialogs.h> |
| 13 | #include <Menus.h> |
| 14 | #include <Controls.h> |
| 15 | |
| 16 | extern PyObject *ResObj_New(Handle); |
| 17 | extern int ResObj_Convert(PyObject *, Handle *); |
| 18 | |
| 19 | extern PyObject *WinObj_New(WindowPtr); |
| 20 | extern int WinObj_Convert(PyObject *, WindowPtr *); |
| 21 | |
| 22 | extern PyObject *DlgObj_New(DialogPtr); |
| 23 | extern int DlgObj_Convert(PyObject *, DialogPtr *); |
| 24 | extern PyTypeObject Dialog_Type; |
| 25 | #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) |
| 26 | |
| 27 | extern PyObject *MenuObj_New(MenuHandle); |
| 28 | extern int MenuObj_Convert(PyObject *, MenuHandle *); |
| 29 | |
| 30 | extern PyObject *CtlObj_New(ControlHandle); |
| 31 | extern int CtlObj_Convert(PyObject *, ControlHandle *); |
| 32 | |
| 33 | extern PyObject *WinObj_WhichWindow(WindowPtr); |
| 34 | |
| 35 | #include <Dialogs.h> |
| 36 | |
| 37 | #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ |
| 38 | |
| 39 | /* XXX Shouldn't this be a stack? */ |
| 40 | static PyObject *Dlg_FilterProc_callback = NULL; |
| 41 | |
| 42 | static PyObject *DlgObj_New(DialogPtr); /* Forward */ |
| 43 | |
| 44 | static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog, |
| 45 | EventRecord *event, |
| 46 | short *itemHit) |
| 47 | { |
| 48 | Boolean rv; |
| 49 | PyObject *args, *res; |
| 50 | PyObject *callback = Dlg_FilterProc_callback; |
| 51 | if (callback == NULL) |
| 52 | return 0; /* Default behavior */ |
| 53 | Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */ |
| 54 | args = Py_BuildValue("O&s#", DlgObj_New, dialog, event, sizeof(EventRecord)); |
| 55 | if (args == NULL) |
| 56 | res = NULL; |
| 57 | else { |
| 58 | res = PyEval_CallObject(callback, args); |
| 59 | Py_DECREF(args); |
| 60 | } |
| 61 | if (res == NULL) { |
| 62 | fprintf(stderr, "Exception in Dialog Filter\n"); |
| 63 | PyErr_Print(); |
| 64 | *itemHit = -1; /* Fake return item */ |
| 65 | return 1; /* We handled it */ |
| 66 | } |
| 67 | else { |
| 68 | Dlg_FilterProc_callback = callback; |
| 69 | if (PyInt_Check(res)) { |
| 70 | *itemHit = PyInt_AsLong(res); |
| 71 | rv = 1; |
| 72 | } |
| 73 | else |
| 74 | rv = PyObject_IsTrue(res); |
| 75 | } |
| 76 | Py_DECREF(res); |
| 77 | return rv; |
| 78 | } |
| 79 | |
| 80 | static ModalFilterProcPtr |
| 81 | Dlg_PassFilterProc(PyObject *callback) |
| 82 | { |
| 83 | PyObject *tmp = Dlg_FilterProc_callback; |
| 84 | Dlg_FilterProc_callback = NULL; |
| 85 | if (callback == Py_None) { |
| 86 | Py_XDECREF(tmp); |
| 87 | return NULL; |
| 88 | } |
| 89 | Py_INCREF(callback); |
| 90 | Dlg_FilterProc_callback = callback; |
| 91 | Py_XDECREF(tmp); |
| 92 | return &Dlg_UnivFilterProc; |
| 93 | } |
| 94 | |
| 95 | extern PyMethodChain WinObj_chain; |
| 96 | |
| 97 | static PyObject *Dlg_Error; |
| 98 | |
| 99 | /* ----------------------- Object type Dialog ----------------------- */ |
| 100 | |
| 101 | PyTypeObject Dialog_Type; |
| 102 | |
| 103 | #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) |
| 104 | |
| 105 | typedef struct DialogObject { |
| 106 | PyObject_HEAD |
| 107 | DialogPtr ob_itself; |
| 108 | } DialogObject; |
| 109 | |
| 110 | PyObject *DlgObj_New(itself) |
| 111 | const DialogPtr itself; |
| 112 | { |
| 113 | DialogObject *it; |
| 114 | if (itself == NULL) return Py_None; |
| 115 | it = PyObject_NEW(DialogObject, &Dialog_Type); |
| 116 | if (it == NULL) return NULL; |
| 117 | it->ob_itself = itself; |
| 118 | SetWRefCon(itself, (long)it); |
| 119 | return (PyObject *)it; |
| 120 | } |
| 121 | DlgObj_Convert(v, p_itself) |
| 122 | PyObject *v; |
| 123 | DialogPtr *p_itself; |
| 124 | { |
| 125 | if (v == Py_None) { *p_itself = NULL; return 1; } |
| 126 | if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v); |
| 127 | return 1; } |
| 128 | if (!DlgObj_Check(v)) |
| 129 | { |
| 130 | PyErr_SetString(PyExc_TypeError, "Dialog required"); |
| 131 | return 0; |
| 132 | } |
| 133 | *p_itself = ((DialogObject *)v)->ob_itself; |
| 134 | return 1; |
| 135 | } |
| 136 | |
| 137 | static void DlgObj_dealloc(self) |
| 138 | DialogObject *self; |
| 139 | { |
| 140 | DisposeDialog(self->ob_itself); |
| 141 | PyMem_DEL(self); |
| 142 | } |
| 143 | |
| 144 | static PyObject *DlgObj_DrawDialog(_self, _args) |
| 145 | DialogObject *_self; |
| 146 | PyObject *_args; |
| 147 | { |
| 148 | PyObject *_res = NULL; |
| 149 | if (!PyArg_ParseTuple(_args, "")) |
| 150 | return NULL; |
| 151 | DrawDialog(_self->ob_itself); |
| 152 | Py_INCREF(Py_None); |
| 153 | _res = Py_None; |
| 154 | return _res; |
| 155 | } |
| 156 | |
| 157 | static PyObject *DlgObj_UpdtDialog(_self, _args) |
| 158 | DialogObject *_self; |
| 159 | PyObject *_args; |
| 160 | { |
| 161 | PyObject *_res = NULL; |
| 162 | if (!PyArg_ParseTuple(_args, "")) |
| 163 | return NULL; |
| 164 | UpdtDialog(_self->ob_itself, |
| 165 | _self->ob_itself->visRgn); |
| 166 | Py_INCREF(Py_None); |
| 167 | _res = Py_None; |
| 168 | return _res; |
| 169 | } |
| 170 | |
| 171 | static PyObject *DlgObj_UpdateDialog(_self, _args) |
| 172 | DialogObject *_self; |
| 173 | PyObject *_args; |
| 174 | { |
| 175 | PyObject *_res = NULL; |
| 176 | if (!PyArg_ParseTuple(_args, "")) |
| 177 | return NULL; |
| 178 | UpdateDialog(_self->ob_itself, |
| 179 | _self->ob_itself->visRgn); |
| 180 | Py_INCREF(Py_None); |
| 181 | _res = Py_None; |
| 182 | return _res; |
| 183 | } |
| 184 | |
| 185 | static PyObject *DlgObj_GetDItem(_self, _args) |
| 186 | DialogObject *_self; |
| 187 | PyObject *_args; |
| 188 | { |
| 189 | PyObject *_res = NULL; |
| 190 | short itemNo; |
| 191 | short itemType; |
| 192 | Handle item; |
| 193 | Rect box; |
| 194 | if (!PyArg_ParseTuple(_args, "h", |
| 195 | &itemNo)) |
| 196 | return NULL; |
| 197 | GetDItem(_self->ob_itself, |
| 198 | itemNo, |
| 199 | &itemType, |
| 200 | &item, |
| 201 | &box); |
| 202 | _res = Py_BuildValue("hO&O&", |
| 203 | itemType, |
| 204 | ResObj_New, item, |
| 205 | PyMac_BuildRect, &box); |
| 206 | return _res; |
| 207 | } |
| 208 | |
| 209 | static PyObject *DlgObj_SetDItem(_self, _args) |
| 210 | DialogObject *_self; |
| 211 | PyObject *_args; |
| 212 | { |
| 213 | PyObject *_res = NULL; |
| 214 | short itemNo; |
| 215 | short itemType; |
| 216 | Handle item; |
| 217 | Rect box; |
| 218 | if (!PyArg_ParseTuple(_args, "hhO&O&", |
| 219 | &itemNo, |
| 220 | &itemType, |
| 221 | ResObj_Convert, &item, |
| 222 | PyMac_GetRect, &box)) |
| 223 | return NULL; |
| 224 | SetDItem(_self->ob_itself, |
| 225 | itemNo, |
| 226 | itemType, |
| 227 | item, |
| 228 | &box); |
| 229 | Py_INCREF(Py_None); |
| 230 | _res = Py_None; |
| 231 | return _res; |
| 232 | } |
| 233 | |
| 234 | static PyObject *DlgObj_HideDItem(_self, _args) |
| 235 | DialogObject *_self; |
| 236 | PyObject *_args; |
| 237 | { |
| 238 | PyObject *_res = NULL; |
| 239 | short itemNo; |
| 240 | if (!PyArg_ParseTuple(_args, "h", |
| 241 | &itemNo)) |
| 242 | return NULL; |
| 243 | HideDItem(_self->ob_itself, |
| 244 | itemNo); |
| 245 | Py_INCREF(Py_None); |
| 246 | _res = Py_None; |
| 247 | return _res; |
| 248 | } |
| 249 | |
| 250 | static PyObject *DlgObj_ShowDItem(_self, _args) |
| 251 | DialogObject *_self; |
| 252 | PyObject *_args; |
| 253 | { |
| 254 | PyObject *_res = NULL; |
| 255 | short itemNo; |
| 256 | if (!PyArg_ParseTuple(_args, "h", |
| 257 | &itemNo)) |
| 258 | return NULL; |
| 259 | ShowDItem(_self->ob_itself, |
| 260 | itemNo); |
| 261 | Py_INCREF(Py_None); |
| 262 | _res = Py_None; |
| 263 | return _res; |
| 264 | } |
| 265 | |
| 266 | static PyObject *DlgObj_SelIText(_self, _args) |
| 267 | DialogObject *_self; |
| 268 | PyObject *_args; |
| 269 | { |
| 270 | PyObject *_res = NULL; |
| 271 | short itemNo; |
| 272 | short strtSel; |
| 273 | short endSel; |
| 274 | if (!PyArg_ParseTuple(_args, "hhh", |
| 275 | &itemNo, |
| 276 | &strtSel, |
| 277 | &endSel)) |
| 278 | return NULL; |
| 279 | SelIText(_self->ob_itself, |
| 280 | itemNo, |
| 281 | strtSel, |
| 282 | endSel); |
| 283 | Py_INCREF(Py_None); |
| 284 | _res = Py_None; |
| 285 | return _res; |
| 286 | } |
| 287 | |
| 288 | static PyObject *DlgObj_FindDItem(_self, _args) |
| 289 | DialogObject *_self; |
| 290 | PyObject *_args; |
| 291 | { |
| 292 | PyObject *_res = NULL; |
| 293 | short _rv; |
| 294 | Point thePt; |
| 295 | if (!PyArg_ParseTuple(_args, "O&", |
| 296 | PyMac_GetPoint, &thePt)) |
| 297 | return NULL; |
| 298 | _rv = FindDItem(_self->ob_itself, |
| 299 | thePt); |
| 300 | _res = Py_BuildValue("h", |
| 301 | _rv); |
| 302 | return _res; |
| 303 | } |
| 304 | |
| 305 | static PyObject *DlgObj_DlgCut(_self, _args) |
| 306 | DialogObject *_self; |
| 307 | PyObject *_args; |
| 308 | { |
| 309 | PyObject *_res = NULL; |
| 310 | if (!PyArg_ParseTuple(_args, "")) |
| 311 | return NULL; |
| 312 | DlgCut(_self->ob_itself); |
| 313 | Py_INCREF(Py_None); |
| 314 | _res = Py_None; |
| 315 | return _res; |
| 316 | } |
| 317 | |
| 318 | static PyObject *DlgObj_DlgPaste(_self, _args) |
| 319 | DialogObject *_self; |
| 320 | PyObject *_args; |
| 321 | { |
| 322 | PyObject *_res = NULL; |
| 323 | if (!PyArg_ParseTuple(_args, "")) |
| 324 | return NULL; |
| 325 | DlgPaste(_self->ob_itself); |
| 326 | Py_INCREF(Py_None); |
| 327 | _res = Py_None; |
| 328 | return _res; |
| 329 | } |
| 330 | |
| 331 | static PyObject *DlgObj_DlgCopy(_self, _args) |
| 332 | DialogObject *_self; |
| 333 | PyObject *_args; |
| 334 | { |
| 335 | PyObject *_res = NULL; |
| 336 | if (!PyArg_ParseTuple(_args, "")) |
| 337 | return NULL; |
| 338 | DlgCopy(_self->ob_itself); |
| 339 | Py_INCREF(Py_None); |
| 340 | _res = Py_None; |
| 341 | return _res; |
| 342 | } |
| 343 | |
| 344 | static PyObject *DlgObj_DlgDelete(_self, _args) |
| 345 | DialogObject *_self; |
| 346 | PyObject *_args; |
| 347 | { |
| 348 | PyObject *_res = NULL; |
| 349 | if (!PyArg_ParseTuple(_args, "")) |
| 350 | return NULL; |
| 351 | DlgDelete(_self->ob_itself); |
| 352 | Py_INCREF(Py_None); |
| 353 | _res = Py_None; |
| 354 | return _res; |
| 355 | } |
| 356 | |
| 357 | static PyObject *DlgObj_AppendDITL(_self, _args) |
| 358 | DialogObject *_self; |
| 359 | PyObject *_args; |
| 360 | { |
| 361 | PyObject *_res = NULL; |
| 362 | Handle theHandle; |
| 363 | DITLMethod method; |
| 364 | if (!PyArg_ParseTuple(_args, "O&h", |
| 365 | ResObj_Convert, &theHandle, |
| 366 | &method)) |
| 367 | return NULL; |
| 368 | AppendDITL(_self->ob_itself, |
| 369 | theHandle, |
| 370 | method); |
| 371 | Py_INCREF(Py_None); |
| 372 | _res = Py_None; |
| 373 | return _res; |
| 374 | } |
| 375 | |
| 376 | static PyObject *DlgObj_CountDITL(_self, _args) |
| 377 | DialogObject *_self; |
| 378 | PyObject *_args; |
| 379 | { |
| 380 | PyObject *_res = NULL; |
| 381 | short _rv; |
| 382 | if (!PyArg_ParseTuple(_args, "")) |
| 383 | return NULL; |
| 384 | _rv = CountDITL(_self->ob_itself); |
| 385 | _res = Py_BuildValue("h", |
| 386 | _rv); |
| 387 | return _res; |
| 388 | } |
| 389 | |
| 390 | static PyObject *DlgObj_ShortenDITL(_self, _args) |
| 391 | DialogObject *_self; |
| 392 | PyObject *_args; |
| 393 | { |
| 394 | PyObject *_res = NULL; |
| 395 | short numberItems; |
| 396 | if (!PyArg_ParseTuple(_args, "h", |
| 397 | &numberItems)) |
| 398 | return NULL; |
| 399 | ShortenDITL(_self->ob_itself, |
| 400 | numberItems); |
| 401 | Py_INCREF(Py_None); |
| 402 | _res = Py_None; |
| 403 | return _res; |
| 404 | } |
| 405 | |
| 406 | static PyMethodDef DlgObj_methods[] = { |
| 407 | {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1, |
| 408 | "() -> None"}, |
| 409 | {"UpdtDialog", (PyCFunction)DlgObj_UpdtDialog, 1, |
| 410 | "() -> None"}, |
| 411 | {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1, |
| 412 | "() -> None"}, |
| 413 | {"GetDItem", (PyCFunction)DlgObj_GetDItem, 1, |
| 414 | "(short itemNo) -> (short itemType, Handle item, Rect box)"}, |
| 415 | {"SetDItem", (PyCFunction)DlgObj_SetDItem, 1, |
| 416 | "(short itemNo, short itemType, Handle item, Rect box) -> None"}, |
| 417 | {"HideDItem", (PyCFunction)DlgObj_HideDItem, 1, |
| 418 | "(short itemNo) -> None"}, |
| 419 | {"ShowDItem", (PyCFunction)DlgObj_ShowDItem, 1, |
| 420 | "(short itemNo) -> None"}, |
| 421 | {"SelIText", (PyCFunction)DlgObj_SelIText, 1, |
| 422 | "(short itemNo, short strtSel, short endSel) -> None"}, |
| 423 | {"FindDItem", (PyCFunction)DlgObj_FindDItem, 1, |
| 424 | "(Point thePt) -> (short _rv)"}, |
| 425 | {"DlgCut", (PyCFunction)DlgObj_DlgCut, 1, |
| 426 | "() -> None"}, |
| 427 | {"DlgPaste", (PyCFunction)DlgObj_DlgPaste, 1, |
| 428 | "() -> None"}, |
| 429 | {"DlgCopy", (PyCFunction)DlgObj_DlgCopy, 1, |
| 430 | "() -> None"}, |
| 431 | {"DlgDelete", (PyCFunction)DlgObj_DlgDelete, 1, |
| 432 | "() -> None"}, |
| 433 | {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1, |
| 434 | "(Handle theHandle, DITLMethod method) -> None"}, |
| 435 | {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1, |
| 436 | "() -> (short _rv)"}, |
| 437 | {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1, |
| 438 | "(short numberItems) -> None"}, |
| 439 | {NULL, NULL, 0} |
| 440 | }; |
| 441 | |
| 442 | PyMethodChain DlgObj_chain = { DlgObj_methods, &WinObj_chain }; |
| 443 | |
| 444 | static PyObject *DlgObj_getattr(self, name) |
| 445 | DialogObject *self; |
| 446 | char *name; |
| 447 | { |
| 448 | return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name); |
| 449 | } |
| 450 | |
| 451 | #define DlgObj_setattr NULL |
| 452 | |
| 453 | PyTypeObject Dialog_Type = { |
| 454 | PyObject_HEAD_INIT(&PyType_Type) |
| 455 | 0, /*ob_size*/ |
| 456 | "Dialog", /*tp_name*/ |
| 457 | sizeof(DialogObject), /*tp_basicsize*/ |
| 458 | 0, /*tp_itemsize*/ |
| 459 | /* methods */ |
| 460 | (destructor) DlgObj_dealloc, /*tp_dealloc*/ |
| 461 | 0, /*tp_print*/ |
| 462 | (getattrfunc) DlgObj_getattr, /*tp_getattr*/ |
| 463 | (setattrfunc) DlgObj_setattr, /*tp_setattr*/ |
| 464 | }; |
| 465 | |
| 466 | /* --------------------- End object type Dialog --------------------- */ |
| 467 | |
| 468 | |
| 469 | static PyObject *Dlg_NewDialog(_self, _args) |
| 470 | PyObject *_self; |
| 471 | PyObject *_args; |
| 472 | { |
| 473 | PyObject *_res = NULL; |
| 474 | DialogPtr _rv; |
| 475 | Rect boundsRect; |
| 476 | Str255 title; |
| 477 | Boolean visible; |
| 478 | short procID; |
| 479 | WindowPtr behind; |
| 480 | Boolean goAwayFlag; |
| 481 | long refCon; |
| 482 | Handle itmLstHndl; |
| 483 | if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&", |
| 484 | PyMac_GetRect, &boundsRect, |
| 485 | PyMac_GetStr255, title, |
| 486 | &visible, |
| 487 | &procID, |
| 488 | WinObj_Convert, &behind, |
| 489 | &goAwayFlag, |
| 490 | &refCon, |
| 491 | ResObj_Convert, &itmLstHndl)) |
| 492 | return NULL; |
| 493 | _rv = NewDialog((void *)0, |
| 494 | &boundsRect, |
| 495 | title, |
| 496 | visible, |
| 497 | procID, |
| 498 | behind, |
| 499 | goAwayFlag, |
| 500 | refCon, |
| 501 | itmLstHndl); |
| 502 | _res = Py_BuildValue("O&", |
| 503 | DlgObj_New, _rv); |
| 504 | return _res; |
| 505 | } |
| 506 | |
| 507 | static PyObject *Dlg_GetNewDialog(_self, _args) |
| 508 | PyObject *_self; |
| 509 | PyObject *_args; |
| 510 | { |
| 511 | PyObject *_res = NULL; |
| 512 | DialogPtr _rv; |
| 513 | short dialogID; |
| 514 | WindowPtr behind; |
| 515 | if (!PyArg_ParseTuple(_args, "hO&", |
| 516 | &dialogID, |
| 517 | WinObj_Convert, &behind)) |
| 518 | return NULL; |
| 519 | _rv = GetNewDialog(dialogID, |
| 520 | (void *)0, |
| 521 | behind); |
| 522 | _res = Py_BuildValue("O&", |
| 523 | DlgObj_New, _rv); |
| 524 | return _res; |
| 525 | } |
| 526 | |
| 527 | static PyObject *Dlg_CouldDialog(_self, _args) |
| 528 | PyObject *_self; |
| 529 | PyObject *_args; |
| 530 | { |
| 531 | PyObject *_res = NULL; |
| 532 | short dialogID; |
| 533 | if (!PyArg_ParseTuple(_args, "h", |
| 534 | &dialogID)) |
| 535 | return NULL; |
| 536 | CouldDialog(dialogID); |
| 537 | Py_INCREF(Py_None); |
| 538 | _res = Py_None; |
| 539 | return _res; |
| 540 | } |
| 541 | |
| 542 | static PyObject *Dlg_FreeDialog(_self, _args) |
| 543 | PyObject *_self; |
| 544 | PyObject *_args; |
| 545 | { |
| 546 | PyObject *_res = NULL; |
| 547 | short dialogID; |
| 548 | if (!PyArg_ParseTuple(_args, "h", |
| 549 | &dialogID)) |
| 550 | return NULL; |
| 551 | FreeDialog(dialogID); |
| 552 | Py_INCREF(Py_None); |
| 553 | _res = Py_None; |
| 554 | return _res; |
| 555 | } |
| 556 | |
| 557 | static PyObject *Dlg_ParamText(_self, _args) |
| 558 | PyObject *_self; |
| 559 | PyObject *_args; |
| 560 | { |
| 561 | PyObject *_res = NULL; |
| 562 | Str255 param0; |
| 563 | Str255 param1; |
| 564 | Str255 param2; |
| 565 | Str255 param3; |
| 566 | if (!PyArg_ParseTuple(_args, "O&O&O&O&", |
| 567 | PyMac_GetStr255, param0, |
| 568 | PyMac_GetStr255, param1, |
| 569 | PyMac_GetStr255, param2, |
| 570 | PyMac_GetStr255, param3)) |
| 571 | return NULL; |
| 572 | ParamText(param0, |
| 573 | param1, |
| 574 | param2, |
| 575 | param3); |
| 576 | Py_INCREF(Py_None); |
| 577 | _res = Py_None; |
| 578 | return _res; |
| 579 | } |
| 580 | |
| 581 | static PyObject *Dlg_ModalDialog(_self, _args) |
| 582 | PyObject *_self; |
| 583 | PyObject *_args; |
| 584 | { |
| 585 | PyObject *_res = NULL; |
| 586 | PyObject* filterProc; |
| 587 | short itemHit; |
| 588 | if (!PyArg_ParseTuple(_args, "O", |
| 589 | &filterProc)) |
| 590 | return NULL; |
| 591 | ModalDialog(Dlg_PassFilterProc(filterProc), |
| 592 | &itemHit); |
| 593 | _res = Py_BuildValue("h", |
| 594 | itemHit); |
| 595 | return _res; |
| 596 | } |
| 597 | |
| 598 | static PyObject *Dlg_IsDialogEvent(_self, _args) |
| 599 | PyObject *_self; |
| 600 | PyObject *_args; |
| 601 | { |
| 602 | PyObject *_res = NULL; |
| 603 | Boolean _rv; |
| 604 | EventRecord theEvent; |
| 605 | if (!PyArg_ParseTuple(_args, "O&", |
| 606 | PyMac_GetEventRecord, &theEvent)) |
| 607 | return NULL; |
| 608 | _rv = IsDialogEvent(&theEvent); |
| 609 | _res = Py_BuildValue("b", |
| 610 | _rv); |
| 611 | return _res; |
| 612 | } |
| 613 | |
| 614 | static PyObject *Dlg_DialogSelect(_self, _args) |
| 615 | PyObject *_self; |
| 616 | PyObject *_args; |
| 617 | { |
| 618 | PyObject *_res = NULL; |
| 619 | Boolean _rv; |
| 620 | EventRecord theEvent; |
| 621 | DialogPtr theDialog; |
| 622 | short itemHit; |
| 623 | if (!PyArg_ParseTuple(_args, "O&", |
| 624 | PyMac_GetEventRecord, &theEvent)) |
| 625 | return NULL; |
| 626 | _rv = DialogSelect(&theEvent, |
| 627 | &theDialog, |
| 628 | &itemHit); |
| 629 | _res = Py_BuildValue("bO&h", |
| 630 | _rv, |
| 631 | WinObj_WhichWindow, theDialog, |
| 632 | itemHit); |
| 633 | return _res; |
| 634 | } |
| 635 | |
| 636 | static PyObject *Dlg_Alert(_self, _args) |
| 637 | PyObject *_self; |
| 638 | PyObject *_args; |
| 639 | { |
| 640 | PyObject *_res = NULL; |
| 641 | short _rv; |
| 642 | short alertID; |
| 643 | PyObject* filterProc; |
| 644 | if (!PyArg_ParseTuple(_args, "hO", |
| 645 | &alertID, |
| 646 | &filterProc)) |
| 647 | return NULL; |
| 648 | _rv = Alert(alertID, |
| 649 | Dlg_PassFilterProc(filterProc)); |
| 650 | _res = Py_BuildValue("h", |
| 651 | _rv); |
| 652 | return _res; |
| 653 | } |
| 654 | |
| 655 | static PyObject *Dlg_StopAlert(_self, _args) |
| 656 | PyObject *_self; |
| 657 | PyObject *_args; |
| 658 | { |
| 659 | PyObject *_res = NULL; |
| 660 | short _rv; |
| 661 | short alertID; |
| 662 | PyObject* filterProc; |
| 663 | if (!PyArg_ParseTuple(_args, "hO", |
| 664 | &alertID, |
| 665 | &filterProc)) |
| 666 | return NULL; |
| 667 | _rv = StopAlert(alertID, |
| 668 | Dlg_PassFilterProc(filterProc)); |
| 669 | _res = Py_BuildValue("h", |
| 670 | _rv); |
| 671 | return _res; |
| 672 | } |
| 673 | |
| 674 | static PyObject *Dlg_NoteAlert(_self, _args) |
| 675 | PyObject *_self; |
| 676 | PyObject *_args; |
| 677 | { |
| 678 | PyObject *_res = NULL; |
| 679 | short _rv; |
| 680 | short alertID; |
| 681 | PyObject* filterProc; |
| 682 | if (!PyArg_ParseTuple(_args, "hO", |
| 683 | &alertID, |
| 684 | &filterProc)) |
| 685 | return NULL; |
| 686 | _rv = NoteAlert(alertID, |
| 687 | Dlg_PassFilterProc(filterProc)); |
| 688 | _res = Py_BuildValue("h", |
| 689 | _rv); |
| 690 | return _res; |
| 691 | } |
| 692 | |
| 693 | static PyObject *Dlg_CautionAlert(_self, _args) |
| 694 | PyObject *_self; |
| 695 | PyObject *_args; |
| 696 | { |
| 697 | PyObject *_res = NULL; |
| 698 | short _rv; |
| 699 | short alertID; |
| 700 | PyObject* filterProc; |
| 701 | if (!PyArg_ParseTuple(_args, "hO", |
| 702 | &alertID, |
| 703 | &filterProc)) |
| 704 | return NULL; |
| 705 | _rv = CautionAlert(alertID, |
| 706 | Dlg_PassFilterProc(filterProc)); |
| 707 | _res = Py_BuildValue("h", |
| 708 | _rv); |
| 709 | return _res; |
| 710 | } |
| 711 | |
| 712 | static PyObject *Dlg_CouldAlert(_self, _args) |
| 713 | PyObject *_self; |
| 714 | PyObject *_args; |
| 715 | { |
| 716 | PyObject *_res = NULL; |
| 717 | short alertID; |
| 718 | if (!PyArg_ParseTuple(_args, "h", |
| 719 | &alertID)) |
| 720 | return NULL; |
| 721 | CouldAlert(alertID); |
| 722 | Py_INCREF(Py_None); |
| 723 | _res = Py_None; |
| 724 | return _res; |
| 725 | } |
| 726 | |
| 727 | static PyObject *Dlg_FreeAlert(_self, _args) |
| 728 | PyObject *_self; |
| 729 | PyObject *_args; |
| 730 | { |
| 731 | PyObject *_res = NULL; |
| 732 | short alertID; |
| 733 | if (!PyArg_ParseTuple(_args, "h", |
| 734 | &alertID)) |
| 735 | return NULL; |
| 736 | FreeAlert(alertID); |
| 737 | Py_INCREF(Py_None); |
| 738 | _res = Py_None; |
| 739 | return _res; |
| 740 | } |
| 741 | |
| 742 | static PyObject *Dlg_GetIText(_self, _args) |
| 743 | PyObject *_self; |
| 744 | PyObject *_args; |
| 745 | { |
| 746 | PyObject *_res = NULL; |
| 747 | Handle item; |
| 748 | Str255 text; |
| 749 | if (!PyArg_ParseTuple(_args, "O&", |
| 750 | ResObj_Convert, &item)) |
| 751 | return NULL; |
| 752 | GetIText(item, |
| 753 | text); |
| 754 | _res = Py_BuildValue("O&", |
| 755 | PyMac_BuildStr255, text); |
| 756 | return _res; |
| 757 | } |
| 758 | |
| 759 | static PyObject *Dlg_SetIText(_self, _args) |
| 760 | PyObject *_self; |
| 761 | PyObject *_args; |
| 762 | { |
| 763 | PyObject *_res = NULL; |
| 764 | Handle item; |
| 765 | Str255 text; |
| 766 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 767 | ResObj_Convert, &item, |
| 768 | PyMac_GetStr255, text)) |
| 769 | return NULL; |
| 770 | SetIText(item, |
| 771 | text); |
| 772 | Py_INCREF(Py_None); |
| 773 | _res = Py_None; |
| 774 | return _res; |
| 775 | } |
| 776 | |
| 777 | static PyObject *Dlg_NewCDialog(_self, _args) |
| 778 | PyObject *_self; |
| 779 | PyObject *_args; |
| 780 | { |
| 781 | PyObject *_res = NULL; |
| 782 | DialogPtr _rv; |
| 783 | Rect boundsRect; |
| 784 | Str255 title; |
| 785 | Boolean visible; |
| 786 | short procID; |
| 787 | WindowPtr behind; |
| 788 | Boolean goAwayFlag; |
| 789 | long refCon; |
| 790 | Handle items; |
| 791 | if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&", |
| 792 | PyMac_GetRect, &boundsRect, |
| 793 | PyMac_GetStr255, title, |
| 794 | &visible, |
| 795 | &procID, |
| 796 | WinObj_Convert, &behind, |
| 797 | &goAwayFlag, |
| 798 | &refCon, |
| 799 | ResObj_Convert, &items)) |
| 800 | return NULL; |
| 801 | _rv = NewCDialog((void *)0, |
| 802 | &boundsRect, |
| 803 | title, |
| 804 | visible, |
| 805 | procID, |
| 806 | behind, |
| 807 | goAwayFlag, |
| 808 | refCon, |
| 809 | items); |
| 810 | _res = Py_BuildValue("O&", |
| 811 | DlgObj_New, _rv); |
| 812 | return _res; |
| 813 | } |
| 814 | |
| 815 | static PyObject *Dlg_ResetAlrtStage(_self, _args) |
| 816 | PyObject *_self; |
| 817 | PyObject *_args; |
| 818 | { |
| 819 | PyObject *_res = NULL; |
| 820 | if (!PyArg_ParseTuple(_args, "")) |
| 821 | return NULL; |
| 822 | ResetAlrtStage(); |
| 823 | Py_INCREF(Py_None); |
| 824 | _res = Py_None; |
| 825 | return _res; |
| 826 | } |
| 827 | |
| 828 | static PyObject *Dlg_SetDAFont(_self, _args) |
| 829 | PyObject *_self; |
| 830 | PyObject *_args; |
| 831 | { |
| 832 | PyObject *_res = NULL; |
| 833 | short fontNum; |
| 834 | if (!PyArg_ParseTuple(_args, "h", |
| 835 | &fontNum)) |
| 836 | return NULL; |
| 837 | SetDAFont(fontNum); |
| 838 | Py_INCREF(Py_None); |
| 839 | _res = Py_None; |
| 840 | return _res; |
| 841 | } |
| 842 | |
| 843 | static PyMethodDef Dlg_methods[] = { |
| 844 | {"NewDialog", (PyCFunction)Dlg_NewDialog, 1, |
| 845 | "(Rect boundsRect, Str255 title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon, Handle itmLstHndl) -> (DialogPtr _rv)"}, |
| 846 | {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1, |
| 847 | "(short dialogID, WindowPtr behind) -> (DialogPtr _rv)"}, |
| 848 | {"CouldDialog", (PyCFunction)Dlg_CouldDialog, 1, |
| 849 | "(short dialogID) -> None"}, |
| 850 | {"FreeDialog", (PyCFunction)Dlg_FreeDialog, 1, |
| 851 | "(short dialogID) -> None"}, |
| 852 | {"ParamText", (PyCFunction)Dlg_ParamText, 1, |
| 853 | "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"}, |
| 854 | {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1, |
| 855 | "(PyObject* filterProc) -> (short itemHit)"}, |
| 856 | {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1, |
| 857 | "(EventRecord theEvent) -> (Boolean _rv)"}, |
| 858 | {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1, |
| 859 | "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, short itemHit)"}, |
| 860 | {"Alert", (PyCFunction)Dlg_Alert, 1, |
| 861 | "(short alertID, PyObject* filterProc) -> (short _rv)"}, |
| 862 | {"StopAlert", (PyCFunction)Dlg_StopAlert, 1, |
| 863 | "(short alertID, PyObject* filterProc) -> (short _rv)"}, |
| 864 | {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1, |
| 865 | "(short alertID, PyObject* filterProc) -> (short _rv)"}, |
| 866 | {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1, |
| 867 | "(short alertID, PyObject* filterProc) -> (short _rv)"}, |
| 868 | {"CouldAlert", (PyCFunction)Dlg_CouldAlert, 1, |
| 869 | "(short alertID) -> None"}, |
| 870 | {"FreeAlert", (PyCFunction)Dlg_FreeAlert, 1, |
| 871 | "(short alertID) -> None"}, |
| 872 | {"GetIText", (PyCFunction)Dlg_GetIText, 1, |
| 873 | "(Handle item) -> (Str255 text)"}, |
| 874 | {"SetIText", (PyCFunction)Dlg_SetIText, 1, |
| 875 | "(Handle item, Str255 text) -> None"}, |
| 876 | {"NewCDialog", (PyCFunction)Dlg_NewCDialog, 1, |
| 877 | "(Rect boundsRect, Str255 title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon, Handle items) -> (DialogPtr _rv)"}, |
| 878 | {"ResetAlrtStage", (PyCFunction)Dlg_ResetAlrtStage, 1, |
| 879 | "() -> None"}, |
| 880 | {"SetDAFont", (PyCFunction)Dlg_SetDAFont, 1, |
| 881 | "(short fontNum) -> None"}, |
| 882 | {NULL, NULL, 0} |
| 883 | }; |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | void initDlg() |
| 889 | { |
| 890 | PyObject *m; |
| 891 | PyObject *d; |
| 892 | |
| 893 | |
| 894 | |
| 895 | |
| 896 | m = Py_InitModule("Dlg", Dlg_methods); |
| 897 | d = PyModule_GetDict(m); |
| 898 | Dlg_Error = PyMac_GetOSErrException(); |
| 899 | if (Dlg_Error == NULL || |
| 900 | PyDict_SetItemString(d, "Error", Dlg_Error) != 0) |
| 901 | Py_FatalError("can't initialize Dlg.Error"); |
| 902 | } |
| 903 | |
| 904 | /* ========================= End module Dlg ========================= */ |
| 905 | |