Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame^] | 1 | |
| 2 | /* =========================== Module Ctl =========================== */ |
| 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 <Controls.h> |
| 36 | |
| 37 | #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ |
| 38 | |
| 39 | extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */ |
| 40 | |
| 41 | #ifdef THINK_C |
| 42 | #define ControlActionUPP ProcPtr |
| 43 | #endif |
| 44 | |
| 45 | static PyObject *Ctl_Error; |
| 46 | |
| 47 | /* ---------------------- Object type Control ----------------------- */ |
| 48 | |
| 49 | PyTypeObject Control_Type; |
| 50 | |
| 51 | #define CtlObj_Check(x) ((x)->ob_type == &Control_Type) |
| 52 | |
| 53 | typedef struct ControlObject { |
| 54 | PyObject_HEAD |
| 55 | ControlHandle ob_itself; |
| 56 | } ControlObject; |
| 57 | |
| 58 | PyObject *CtlObj_New(itself) |
| 59 | const ControlHandle itself; |
| 60 | { |
| 61 | ControlObject *it; |
| 62 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 63 | it = PyObject_NEW(ControlObject, &Control_Type); |
| 64 | if (it == NULL) return NULL; |
| 65 | it->ob_itself = itself; |
| 66 | SetCRefCon(itself, (long)it); |
| 67 | return (PyObject *)it; |
| 68 | } |
| 69 | CtlObj_Convert(v, p_itself) |
| 70 | PyObject *v; |
| 71 | ControlHandle *p_itself; |
| 72 | { |
| 73 | if (!CtlObj_Check(v)) |
| 74 | { |
| 75 | PyErr_SetString(PyExc_TypeError, "Control required"); |
| 76 | return 0; |
| 77 | } |
| 78 | *p_itself = ((ControlObject *)v)->ob_itself; |
| 79 | return 1; |
| 80 | } |
| 81 | |
| 82 | static void CtlObj_dealloc(self) |
| 83 | ControlObject *self; |
| 84 | { |
| 85 | /* Cleanup of self->ob_itself goes here */ |
| 86 | PyMem_DEL(self); |
| 87 | } |
| 88 | |
| 89 | static PyObject *CtlObj_SetCTitle(_self, _args) |
| 90 | ControlObject *_self; |
| 91 | PyObject *_args; |
| 92 | { |
| 93 | PyObject *_res = NULL; |
| 94 | Str255 title; |
| 95 | if (!PyArg_ParseTuple(_args, "O&", |
| 96 | PyMac_GetStr255, title)) |
| 97 | return NULL; |
| 98 | SetCTitle(_self->ob_itself, |
| 99 | title); |
| 100 | Py_INCREF(Py_None); |
| 101 | _res = Py_None; |
| 102 | return _res; |
| 103 | } |
| 104 | |
| 105 | static PyObject *CtlObj_GetCTitle(_self, _args) |
| 106 | ControlObject *_self; |
| 107 | PyObject *_args; |
| 108 | { |
| 109 | PyObject *_res = NULL; |
| 110 | Str255 title; |
| 111 | if (!PyArg_ParseTuple(_args, "O&", |
| 112 | PyMac_GetStr255, title)) |
| 113 | return NULL; |
| 114 | GetCTitle(_self->ob_itself, |
| 115 | title); |
| 116 | Py_INCREF(Py_None); |
| 117 | _res = Py_None; |
| 118 | return _res; |
| 119 | } |
| 120 | |
| 121 | static PyObject *CtlObj_DisposeControl(_self, _args) |
| 122 | ControlObject *_self; |
| 123 | PyObject *_args; |
| 124 | { |
| 125 | PyObject *_res = NULL; |
| 126 | if (!PyArg_ParseTuple(_args, "")) |
| 127 | return NULL; |
| 128 | DisposeControl(_self->ob_itself); |
| 129 | Py_INCREF(Py_None); |
| 130 | _res = Py_None; |
| 131 | return _res; |
| 132 | } |
| 133 | |
| 134 | static PyObject *CtlObj_HideControl(_self, _args) |
| 135 | ControlObject *_self; |
| 136 | PyObject *_args; |
| 137 | { |
| 138 | PyObject *_res = NULL; |
| 139 | if (!PyArg_ParseTuple(_args, "")) |
| 140 | return NULL; |
| 141 | HideControl(_self->ob_itself); |
| 142 | Py_INCREF(Py_None); |
| 143 | _res = Py_None; |
| 144 | return _res; |
| 145 | } |
| 146 | |
| 147 | static PyObject *CtlObj_ShowControl(_self, _args) |
| 148 | ControlObject *_self; |
| 149 | PyObject *_args; |
| 150 | { |
| 151 | PyObject *_res = NULL; |
| 152 | if (!PyArg_ParseTuple(_args, "")) |
| 153 | return NULL; |
| 154 | ShowControl(_self->ob_itself); |
| 155 | Py_INCREF(Py_None); |
| 156 | _res = Py_None; |
| 157 | return _res; |
| 158 | } |
| 159 | |
| 160 | static PyObject *CtlObj_Draw1Control(_self, _args) |
| 161 | ControlObject *_self; |
| 162 | PyObject *_args; |
| 163 | { |
| 164 | PyObject *_res = NULL; |
| 165 | if (!PyArg_ParseTuple(_args, "")) |
| 166 | return NULL; |
| 167 | Draw1Control(_self->ob_itself); |
| 168 | Py_INCREF(Py_None); |
| 169 | _res = Py_None; |
| 170 | return _res; |
| 171 | } |
| 172 | |
| 173 | static PyObject *CtlObj_HiliteControl(_self, _args) |
| 174 | ControlObject *_self; |
| 175 | PyObject *_args; |
| 176 | { |
| 177 | PyObject *_res = NULL; |
| 178 | short hiliteState; |
| 179 | if (!PyArg_ParseTuple(_args, "h", |
| 180 | &hiliteState)) |
| 181 | return NULL; |
| 182 | HiliteControl(_self->ob_itself, |
| 183 | hiliteState); |
| 184 | Py_INCREF(Py_None); |
| 185 | _res = Py_None; |
| 186 | return _res; |
| 187 | } |
| 188 | |
| 189 | static PyObject *CtlObj_MoveControl(_self, _args) |
| 190 | ControlObject *_self; |
| 191 | PyObject *_args; |
| 192 | { |
| 193 | PyObject *_res = NULL; |
| 194 | short h; |
| 195 | short v; |
| 196 | if (!PyArg_ParseTuple(_args, "hh", |
| 197 | &h, |
| 198 | &v)) |
| 199 | return NULL; |
| 200 | MoveControl(_self->ob_itself, |
| 201 | h, |
| 202 | v); |
| 203 | Py_INCREF(Py_None); |
| 204 | _res = Py_None; |
| 205 | return _res; |
| 206 | } |
| 207 | |
| 208 | static PyObject *CtlObj_SizeControl(_self, _args) |
| 209 | ControlObject *_self; |
| 210 | PyObject *_args; |
| 211 | { |
| 212 | PyObject *_res = NULL; |
| 213 | short w; |
| 214 | short h; |
| 215 | if (!PyArg_ParseTuple(_args, "hh", |
| 216 | &w, |
| 217 | &h)) |
| 218 | return NULL; |
| 219 | SizeControl(_self->ob_itself, |
| 220 | w, |
| 221 | h); |
| 222 | Py_INCREF(Py_None); |
| 223 | _res = Py_None; |
| 224 | return _res; |
| 225 | } |
| 226 | |
| 227 | static PyObject *CtlObj_SetCtlValue(_self, _args) |
| 228 | ControlObject *_self; |
| 229 | PyObject *_args; |
| 230 | { |
| 231 | PyObject *_res = NULL; |
| 232 | short theValue; |
| 233 | if (!PyArg_ParseTuple(_args, "h", |
| 234 | &theValue)) |
| 235 | return NULL; |
| 236 | SetCtlValue(_self->ob_itself, |
| 237 | theValue); |
| 238 | Py_INCREF(Py_None); |
| 239 | _res = Py_None; |
| 240 | return _res; |
| 241 | } |
| 242 | |
| 243 | static PyObject *CtlObj_GetCtlValue(_self, _args) |
| 244 | ControlObject *_self; |
| 245 | PyObject *_args; |
| 246 | { |
| 247 | PyObject *_res = NULL; |
| 248 | short _rv; |
| 249 | if (!PyArg_ParseTuple(_args, "")) |
| 250 | return NULL; |
| 251 | _rv = GetCtlValue(_self->ob_itself); |
| 252 | _res = Py_BuildValue("h", |
| 253 | _rv); |
| 254 | return _res; |
| 255 | } |
| 256 | |
| 257 | static PyObject *CtlObj_SetCtlMin(_self, _args) |
| 258 | ControlObject *_self; |
| 259 | PyObject *_args; |
| 260 | { |
| 261 | PyObject *_res = NULL; |
| 262 | short minValue; |
| 263 | if (!PyArg_ParseTuple(_args, "h", |
| 264 | &minValue)) |
| 265 | return NULL; |
| 266 | SetCtlMin(_self->ob_itself, |
| 267 | minValue); |
| 268 | Py_INCREF(Py_None); |
| 269 | _res = Py_None; |
| 270 | return _res; |
| 271 | } |
| 272 | |
| 273 | static PyObject *CtlObj_GetCtlMin(_self, _args) |
| 274 | ControlObject *_self; |
| 275 | PyObject *_args; |
| 276 | { |
| 277 | PyObject *_res = NULL; |
| 278 | short _rv; |
| 279 | if (!PyArg_ParseTuple(_args, "")) |
| 280 | return NULL; |
| 281 | _rv = GetCtlMin(_self->ob_itself); |
| 282 | _res = Py_BuildValue("h", |
| 283 | _rv); |
| 284 | return _res; |
| 285 | } |
| 286 | |
| 287 | static PyObject *CtlObj_SetCtlMax(_self, _args) |
| 288 | ControlObject *_self; |
| 289 | PyObject *_args; |
| 290 | { |
| 291 | PyObject *_res = NULL; |
| 292 | short maxValue; |
| 293 | if (!PyArg_ParseTuple(_args, "h", |
| 294 | &maxValue)) |
| 295 | return NULL; |
| 296 | SetCtlMax(_self->ob_itself, |
| 297 | maxValue); |
| 298 | Py_INCREF(Py_None); |
| 299 | _res = Py_None; |
| 300 | return _res; |
| 301 | } |
| 302 | |
| 303 | static PyObject *CtlObj_GetCtlMax(_self, _args) |
| 304 | ControlObject *_self; |
| 305 | PyObject *_args; |
| 306 | { |
| 307 | PyObject *_res = NULL; |
| 308 | short _rv; |
| 309 | if (!PyArg_ParseTuple(_args, "")) |
| 310 | return NULL; |
| 311 | _rv = GetCtlMax(_self->ob_itself); |
| 312 | _res = Py_BuildValue("h", |
| 313 | _rv); |
| 314 | return _res; |
| 315 | } |
| 316 | |
| 317 | static PyObject *CtlObj_SetCRefCon(_self, _args) |
| 318 | ControlObject *_self; |
| 319 | PyObject *_args; |
| 320 | { |
| 321 | PyObject *_res = NULL; |
| 322 | long data; |
| 323 | if (!PyArg_ParseTuple(_args, "l", |
| 324 | &data)) |
| 325 | return NULL; |
| 326 | SetCRefCon(_self->ob_itself, |
| 327 | data); |
| 328 | Py_INCREF(Py_None); |
| 329 | _res = Py_None; |
| 330 | return _res; |
| 331 | } |
| 332 | |
| 333 | static PyObject *CtlObj_GetCRefCon(_self, _args) |
| 334 | ControlObject *_self; |
| 335 | PyObject *_args; |
| 336 | { |
| 337 | PyObject *_res = NULL; |
| 338 | long _rv; |
| 339 | if (!PyArg_ParseTuple(_args, "")) |
| 340 | return NULL; |
| 341 | _rv = GetCRefCon(_self->ob_itself); |
| 342 | _res = Py_BuildValue("l", |
| 343 | _rv); |
| 344 | return _res; |
| 345 | } |
| 346 | |
| 347 | static PyObject *CtlObj_DragControl(_self, _args) |
| 348 | ControlObject *_self; |
| 349 | PyObject *_args; |
| 350 | { |
| 351 | PyObject *_res = NULL; |
| 352 | Point startPt; |
| 353 | Rect limitRect; |
| 354 | Rect slopRect; |
| 355 | short axis; |
| 356 | if (!PyArg_ParseTuple(_args, "O&O&O&h", |
| 357 | PyMac_GetPoint, &startPt, |
| 358 | PyMac_GetRect, &limitRect, |
| 359 | PyMac_GetRect, &slopRect, |
| 360 | &axis)) |
| 361 | return NULL; |
| 362 | DragControl(_self->ob_itself, |
| 363 | startPt, |
| 364 | &limitRect, |
| 365 | &slopRect, |
| 366 | axis); |
| 367 | Py_INCREF(Py_None); |
| 368 | _res = Py_None; |
| 369 | return _res; |
| 370 | } |
| 371 | |
| 372 | static PyObject *CtlObj_TestControl(_self, _args) |
| 373 | ControlObject *_self; |
| 374 | PyObject *_args; |
| 375 | { |
| 376 | PyObject *_res = NULL; |
| 377 | short _rv; |
| 378 | Point thePt; |
| 379 | if (!PyArg_ParseTuple(_args, "O&", |
| 380 | PyMac_GetPoint, &thePt)) |
| 381 | return NULL; |
| 382 | _rv = TestControl(_self->ob_itself, |
| 383 | thePt); |
| 384 | _res = Py_BuildValue("h", |
| 385 | _rv); |
| 386 | return _res; |
| 387 | } |
| 388 | |
| 389 | static PyObject *CtlObj_TrackControl(_self, _args) |
| 390 | ControlObject *_self; |
| 391 | PyObject *_args; |
| 392 | { |
| 393 | PyObject *_res = NULL; |
| 394 | short _rv; |
| 395 | Point thePoint; |
| 396 | if (!PyArg_ParseTuple(_args, "O&", |
| 397 | PyMac_GetPoint, &thePoint)) |
| 398 | return NULL; |
| 399 | _rv = TrackControl(_self->ob_itself, |
| 400 | thePoint, |
| 401 | (ControlActionUPP)0); |
| 402 | _res = Py_BuildValue("h", |
| 403 | _rv); |
| 404 | return _res; |
| 405 | } |
| 406 | |
| 407 | static PyObject *CtlObj_GetCVariant(_self, _args) |
| 408 | ControlObject *_self; |
| 409 | PyObject *_args; |
| 410 | { |
| 411 | PyObject *_res = NULL; |
| 412 | short _rv; |
| 413 | if (!PyArg_ParseTuple(_args, "")) |
| 414 | return NULL; |
| 415 | _rv = GetCVariant(_self->ob_itself); |
| 416 | _res = Py_BuildValue("h", |
| 417 | _rv); |
| 418 | return _res; |
| 419 | } |
| 420 | |
| 421 | static PyMethodDef CtlObj_methods[] = { |
| 422 | {"SetCTitle", (PyCFunction)CtlObj_SetCTitle, 1, |
| 423 | "(Str255 title) -> None"}, |
| 424 | {"GetCTitle", (PyCFunction)CtlObj_GetCTitle, 1, |
| 425 | "(Str255 title) -> None"}, |
| 426 | {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1, |
| 427 | "() -> None"}, |
| 428 | {"HideControl", (PyCFunction)CtlObj_HideControl, 1, |
| 429 | "() -> None"}, |
| 430 | {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1, |
| 431 | "() -> None"}, |
| 432 | {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1, |
| 433 | "() -> None"}, |
| 434 | {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1, |
| 435 | "(short hiliteState) -> None"}, |
| 436 | {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1, |
| 437 | "(short h, short v) -> None"}, |
| 438 | {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1, |
| 439 | "(short w, short h) -> None"}, |
| 440 | {"SetCtlValue", (PyCFunction)CtlObj_SetCtlValue, 1, |
| 441 | "(short theValue) -> None"}, |
| 442 | {"GetCtlValue", (PyCFunction)CtlObj_GetCtlValue, 1, |
| 443 | "() -> (short _rv)"}, |
| 444 | {"SetCtlMin", (PyCFunction)CtlObj_SetCtlMin, 1, |
| 445 | "(short minValue) -> None"}, |
| 446 | {"GetCtlMin", (PyCFunction)CtlObj_GetCtlMin, 1, |
| 447 | "() -> (short _rv)"}, |
| 448 | {"SetCtlMax", (PyCFunction)CtlObj_SetCtlMax, 1, |
| 449 | "(short maxValue) -> None"}, |
| 450 | {"GetCtlMax", (PyCFunction)CtlObj_GetCtlMax, 1, |
| 451 | "() -> (short _rv)"}, |
| 452 | {"SetCRefCon", (PyCFunction)CtlObj_SetCRefCon, 1, |
| 453 | "(long data) -> None"}, |
| 454 | {"GetCRefCon", (PyCFunction)CtlObj_GetCRefCon, 1, |
| 455 | "() -> (long _rv)"}, |
| 456 | {"DragControl", (PyCFunction)CtlObj_DragControl, 1, |
| 457 | "(Point startPt, Rect limitRect, Rect slopRect, short axis) -> None"}, |
| 458 | {"TestControl", (PyCFunction)CtlObj_TestControl, 1, |
| 459 | "(Point thePt) -> (short _rv)"}, |
| 460 | {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1, |
| 461 | "(Point thePoint) -> (short _rv)"}, |
| 462 | {"GetCVariant", (PyCFunction)CtlObj_GetCVariant, 1, |
| 463 | "() -> (short _rv)"}, |
| 464 | {NULL, NULL, 0} |
| 465 | }; |
| 466 | |
| 467 | PyMethodChain CtlObj_chain = { CtlObj_methods, NULL }; |
| 468 | |
| 469 | static PyObject *CtlObj_getattr(self, name) |
| 470 | ControlObject *self; |
| 471 | char *name; |
| 472 | { |
| 473 | return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name); |
| 474 | } |
| 475 | |
| 476 | #define CtlObj_setattr NULL |
| 477 | |
| 478 | PyTypeObject Control_Type = { |
| 479 | PyObject_HEAD_INIT(&PyType_Type) |
| 480 | 0, /*ob_size*/ |
| 481 | "Control", /*tp_name*/ |
| 482 | sizeof(ControlObject), /*tp_basicsize*/ |
| 483 | 0, /*tp_itemsize*/ |
| 484 | /* methods */ |
| 485 | (destructor) CtlObj_dealloc, /*tp_dealloc*/ |
| 486 | 0, /*tp_print*/ |
| 487 | (getattrfunc) CtlObj_getattr, /*tp_getattr*/ |
| 488 | (setattrfunc) CtlObj_setattr, /*tp_setattr*/ |
| 489 | }; |
| 490 | |
| 491 | /* -------------------- End object type Control --------------------- */ |
| 492 | |
| 493 | |
| 494 | static PyObject *Ctl_NewControl(_self, _args) |
| 495 | PyObject *_self; |
| 496 | PyObject *_args; |
| 497 | { |
| 498 | PyObject *_res = NULL; |
| 499 | ControlHandle _rv; |
| 500 | WindowPtr theWindow; |
| 501 | Rect boundsRect; |
| 502 | Str255 title; |
| 503 | Boolean visible; |
| 504 | short value; |
| 505 | short min; |
| 506 | short max; |
| 507 | short procID; |
| 508 | long refCon; |
| 509 | if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl", |
| 510 | WinObj_Convert, &theWindow, |
| 511 | PyMac_GetRect, &boundsRect, |
| 512 | PyMac_GetStr255, title, |
| 513 | &visible, |
| 514 | &value, |
| 515 | &min, |
| 516 | &max, |
| 517 | &procID, |
| 518 | &refCon)) |
| 519 | return NULL; |
| 520 | _rv = NewControl(theWindow, |
| 521 | &boundsRect, |
| 522 | title, |
| 523 | visible, |
| 524 | value, |
| 525 | min, |
| 526 | max, |
| 527 | procID, |
| 528 | refCon); |
| 529 | _res = Py_BuildValue("O&", |
| 530 | CtlObj_New, _rv); |
| 531 | return _res; |
| 532 | } |
| 533 | |
| 534 | static PyObject *Ctl_GetNewControl(_self, _args) |
| 535 | PyObject *_self; |
| 536 | PyObject *_args; |
| 537 | { |
| 538 | PyObject *_res = NULL; |
| 539 | ControlHandle _rv; |
| 540 | short controlID; |
| 541 | WindowPtr owner; |
| 542 | if (!PyArg_ParseTuple(_args, "hO&", |
| 543 | &controlID, |
| 544 | WinObj_Convert, &owner)) |
| 545 | return NULL; |
| 546 | _rv = GetNewControl(controlID, |
| 547 | owner); |
| 548 | _res = Py_BuildValue("O&", |
| 549 | CtlObj_New, _rv); |
| 550 | return _res; |
| 551 | } |
| 552 | |
| 553 | static PyObject *Ctl_KillControls(_self, _args) |
| 554 | PyObject *_self; |
| 555 | PyObject *_args; |
| 556 | { |
| 557 | PyObject *_res = NULL; |
| 558 | WindowPtr theWindow; |
| 559 | if (!PyArg_ParseTuple(_args, "O&", |
| 560 | WinObj_Convert, &theWindow)) |
| 561 | return NULL; |
| 562 | KillControls(theWindow); |
| 563 | Py_INCREF(Py_None); |
| 564 | _res = Py_None; |
| 565 | return _res; |
| 566 | } |
| 567 | |
| 568 | static PyObject *Ctl_DrawControls(_self, _args) |
| 569 | PyObject *_self; |
| 570 | PyObject *_args; |
| 571 | { |
| 572 | PyObject *_res = NULL; |
| 573 | WindowPtr theWindow; |
| 574 | if (!PyArg_ParseTuple(_args, "O&", |
| 575 | WinObj_Convert, &theWindow)) |
| 576 | return NULL; |
| 577 | DrawControls(theWindow); |
| 578 | Py_INCREF(Py_None); |
| 579 | _res = Py_None; |
| 580 | return _res; |
| 581 | } |
| 582 | |
| 583 | static PyObject *Ctl_UpdtControl(_self, _args) |
| 584 | PyObject *_self; |
| 585 | PyObject *_args; |
| 586 | { |
| 587 | PyObject *_res = NULL; |
| 588 | WindowPtr theWindow; |
| 589 | if (!PyArg_ParseTuple(_args, "O&", |
| 590 | WinObj_Convert, &theWindow)) |
| 591 | return NULL; |
| 592 | UpdtControl(theWindow, |
| 593 | theWindow->visRgn); |
| 594 | Py_INCREF(Py_None); |
| 595 | _res = Py_None; |
| 596 | return _res; |
| 597 | } |
| 598 | |
| 599 | static PyObject *Ctl_UpdateControls(_self, _args) |
| 600 | PyObject *_self; |
| 601 | PyObject *_args; |
| 602 | { |
| 603 | PyObject *_res = NULL; |
| 604 | WindowPtr theWindow; |
| 605 | if (!PyArg_ParseTuple(_args, "O&", |
| 606 | WinObj_Convert, &theWindow)) |
| 607 | return NULL; |
| 608 | UpdateControls(theWindow, |
| 609 | theWindow->visRgn); |
| 610 | Py_INCREF(Py_None); |
| 611 | _res = Py_None; |
| 612 | return _res; |
| 613 | } |
| 614 | |
| 615 | static PyObject *Ctl_FindControl(_self, _args) |
| 616 | PyObject *_self; |
| 617 | PyObject *_args; |
| 618 | { |
| 619 | PyObject *_res = NULL; |
| 620 | short _rv; |
| 621 | Point thePoint; |
| 622 | WindowPtr theWindow; |
| 623 | ControlHandle theControl; |
| 624 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 625 | PyMac_GetPoint, &thePoint, |
| 626 | WinObj_Convert, &theWindow)) |
| 627 | return NULL; |
| 628 | _rv = FindControl(thePoint, |
| 629 | theWindow, |
| 630 | &theControl); |
| 631 | _res = Py_BuildValue("hO&", |
| 632 | _rv, |
| 633 | CtlObj_WhichControl, theControl); |
| 634 | return _res; |
| 635 | } |
| 636 | |
| 637 | static PyMethodDef Ctl_methods[] = { |
| 638 | {"NewControl", (PyCFunction)Ctl_NewControl, 1, |
| 639 | "(WindowPtr theWindow, Rect boundsRect, Str255 title, Boolean visible, short value, short min, short max, short procID, long refCon) -> (ControlHandle _rv)"}, |
| 640 | {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1, |
| 641 | "(short controlID, WindowPtr owner) -> (ControlHandle _rv)"}, |
| 642 | {"KillControls", (PyCFunction)Ctl_KillControls, 1, |
| 643 | "(WindowPtr theWindow) -> None"}, |
| 644 | {"DrawControls", (PyCFunction)Ctl_DrawControls, 1, |
| 645 | "(WindowPtr theWindow) -> None"}, |
| 646 | {"UpdtControl", (PyCFunction)Ctl_UpdtControl, 1, |
| 647 | "(WindowPtr theWindow) -> None"}, |
| 648 | {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1, |
| 649 | "(WindowPtr theWindow) -> None"}, |
| 650 | {"FindControl", (PyCFunction)Ctl_FindControl, 1, |
| 651 | "(Point thePoint, WindowPtr theWindow) -> (short _rv, ControlHandle theControl)"}, |
| 652 | {NULL, NULL, 0} |
| 653 | }; |
| 654 | |
| 655 | |
| 656 | |
| 657 | PyObject * |
| 658 | CtlObj_WhichControl(ControlHandle c) |
| 659 | { |
| 660 | PyObject *it; |
| 661 | |
| 662 | /* XXX What if we find a control belonging to some other package? */ |
| 663 | if (c == NULL) |
| 664 | it = NULL; |
| 665 | else |
| 666 | it = (PyObject *) GetCRefCon(c); |
| 667 | if (it == NULL || ((ControlObject *)it)->ob_itself != c) |
| 668 | it = Py_None; |
| 669 | Py_INCREF(it); |
| 670 | return it; |
| 671 | } |
| 672 | |
| 673 | |
| 674 | void initCtl() |
| 675 | { |
| 676 | PyObject *m; |
| 677 | PyObject *d; |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | m = Py_InitModule("Ctl", Ctl_methods); |
| 683 | d = PyModule_GetDict(m); |
| 684 | Ctl_Error = PyMac_GetOSErrException(); |
| 685 | if (Ctl_Error == NULL || |
| 686 | PyDict_SetItemString(d, "Error", Ctl_Error) != 0) |
| 687 | Py_FatalError("can't initialize Ctl.Error"); |
| 688 | } |
| 689 | |
| 690 | /* ========================= End module Ctl ========================= */ |
| 691 | |