Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1 | |
| 2 | /* =========================== Module Win =========================== */ |
| 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 <Windows.h> |
| 36 | |
| 37 | #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ |
| 38 | |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 39 | #ifdef HAVE_UNIVERSAL_HEADERS |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 40 | #define WindowPeek WindowPtr |
| 41 | #endif |
| 42 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 43 | static PyObject *Win_Error; |
| 44 | |
| 45 | /* ----------------------- Object type Window ----------------------- */ |
| 46 | |
| 47 | PyTypeObject Window_Type; |
| 48 | |
| 49 | #define WinObj_Check(x) ((x)->ob_type == &Window_Type) |
| 50 | |
| 51 | typedef struct WindowObject { |
| 52 | PyObject_HEAD |
| 53 | WindowPtr ob_itself; |
| 54 | } WindowObject; |
| 55 | |
| 56 | PyObject *WinObj_New(itself) |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 57 | WindowPtr itself; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 58 | { |
| 59 | WindowObject *it; |
| 60 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 61 | it = PyObject_NEW(WindowObject, &Window_Type); |
| 62 | if (it == NULL) return NULL; |
| 63 | it->ob_itself = itself; |
| 64 | SetWRefCon(itself, (long)it); |
| 65 | return (PyObject *)it; |
| 66 | } |
| 67 | WinObj_Convert(v, p_itself) |
| 68 | PyObject *v; |
| 69 | WindowPtr *p_itself; |
| 70 | { |
| 71 | if (DlgObj_Check(v)) { |
| 72 | *p_itself = ((WindowObject *)v)->ob_itself; |
| 73 | return 1; |
| 74 | } |
| 75 | |
| 76 | if (v == Py_None) { *p_itself = NULL; return 1; } |
| 77 | if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; } |
| 78 | |
| 79 | if (!WinObj_Check(v)) |
| 80 | { |
| 81 | PyErr_SetString(PyExc_TypeError, "Window required"); |
| 82 | return 0; |
| 83 | } |
| 84 | *p_itself = ((WindowObject *)v)->ob_itself; |
| 85 | return 1; |
| 86 | } |
| 87 | |
| 88 | static void WinObj_dealloc(self) |
| 89 | WindowObject *self; |
| 90 | { |
| 91 | DisposeWindow(self->ob_itself); |
| 92 | PyMem_DEL(self); |
| 93 | } |
| 94 | |
| 95 | static PyObject *WinObj_GetWTitle(_self, _args) |
| 96 | WindowObject *_self; |
| 97 | PyObject *_args; |
| 98 | { |
| 99 | PyObject *_res = NULL; |
| 100 | Str255 title; |
| 101 | if (!PyArg_ParseTuple(_args, "")) |
| 102 | return NULL; |
| 103 | GetWTitle(_self->ob_itself, |
| 104 | title); |
| 105 | _res = Py_BuildValue("O&", |
| 106 | PyMac_BuildStr255, title); |
| 107 | return _res; |
| 108 | } |
| 109 | |
| 110 | static PyObject *WinObj_SelectWindow(_self, _args) |
| 111 | WindowObject *_self; |
| 112 | PyObject *_args; |
| 113 | { |
| 114 | PyObject *_res = NULL; |
| 115 | if (!PyArg_ParseTuple(_args, "")) |
| 116 | return NULL; |
| 117 | SelectWindow(_self->ob_itself); |
| 118 | Py_INCREF(Py_None); |
| 119 | _res = Py_None; |
| 120 | return _res; |
| 121 | } |
| 122 | |
| 123 | static PyObject *WinObj_HideWindow(_self, _args) |
| 124 | WindowObject *_self; |
| 125 | PyObject *_args; |
| 126 | { |
| 127 | PyObject *_res = NULL; |
| 128 | if (!PyArg_ParseTuple(_args, "")) |
| 129 | return NULL; |
| 130 | HideWindow(_self->ob_itself); |
| 131 | Py_INCREF(Py_None); |
| 132 | _res = Py_None; |
| 133 | return _res; |
| 134 | } |
| 135 | |
| 136 | static PyObject *WinObj_ShowWindow(_self, _args) |
| 137 | WindowObject *_self; |
| 138 | PyObject *_args; |
| 139 | { |
| 140 | PyObject *_res = NULL; |
| 141 | if (!PyArg_ParseTuple(_args, "")) |
| 142 | return NULL; |
| 143 | ShowWindow(_self->ob_itself); |
| 144 | Py_INCREF(Py_None); |
| 145 | _res = Py_None; |
| 146 | return _res; |
| 147 | } |
| 148 | |
| 149 | static PyObject *WinObj_ShowHide(_self, _args) |
| 150 | WindowObject *_self; |
| 151 | PyObject *_args; |
| 152 | { |
| 153 | PyObject *_res = NULL; |
| 154 | Boolean showFlag; |
| 155 | if (!PyArg_ParseTuple(_args, "b", |
| 156 | &showFlag)) |
| 157 | return NULL; |
| 158 | ShowHide(_self->ob_itself, |
| 159 | showFlag); |
| 160 | Py_INCREF(Py_None); |
| 161 | _res = Py_None; |
| 162 | return _res; |
| 163 | } |
| 164 | |
| 165 | static PyObject *WinObj_HiliteWindow(_self, _args) |
| 166 | WindowObject *_self; |
| 167 | PyObject *_args; |
| 168 | { |
| 169 | PyObject *_res = NULL; |
| 170 | Boolean fHilite; |
| 171 | if (!PyArg_ParseTuple(_args, "b", |
| 172 | &fHilite)) |
| 173 | return NULL; |
| 174 | HiliteWindow(_self->ob_itself, |
| 175 | fHilite); |
| 176 | Py_INCREF(Py_None); |
| 177 | _res = Py_None; |
| 178 | return _res; |
| 179 | } |
| 180 | |
| 181 | static PyObject *WinObj_BringToFront(_self, _args) |
| 182 | WindowObject *_self; |
| 183 | PyObject *_args; |
| 184 | { |
| 185 | PyObject *_res = NULL; |
| 186 | if (!PyArg_ParseTuple(_args, "")) |
| 187 | return NULL; |
| 188 | BringToFront(_self->ob_itself); |
| 189 | Py_INCREF(Py_None); |
| 190 | _res = Py_None; |
| 191 | return _res; |
| 192 | } |
| 193 | |
| 194 | static PyObject *WinObj_SendBehind(_self, _args) |
| 195 | WindowObject *_self; |
| 196 | PyObject *_args; |
| 197 | { |
| 198 | PyObject *_res = NULL; |
| 199 | WindowPtr behindWindow; |
| 200 | if (!PyArg_ParseTuple(_args, "O&", |
| 201 | WinObj_Convert, &behindWindow)) |
| 202 | return NULL; |
| 203 | SendBehind(_self->ob_itself, |
| 204 | behindWindow); |
| 205 | Py_INCREF(Py_None); |
| 206 | _res = Py_None; |
| 207 | return _res; |
| 208 | } |
| 209 | |
| 210 | static PyObject *WinObj_DrawGrowIcon(_self, _args) |
| 211 | WindowObject *_self; |
| 212 | PyObject *_args; |
| 213 | { |
| 214 | PyObject *_res = NULL; |
| 215 | if (!PyArg_ParseTuple(_args, "")) |
| 216 | return NULL; |
| 217 | DrawGrowIcon(_self->ob_itself); |
| 218 | Py_INCREF(Py_None); |
| 219 | _res = Py_None; |
| 220 | return _res; |
| 221 | } |
| 222 | |
| 223 | static PyObject *WinObj_MoveWindow(_self, _args) |
| 224 | WindowObject *_self; |
| 225 | PyObject *_args; |
| 226 | { |
| 227 | PyObject *_res = NULL; |
| 228 | short hGlobal; |
| 229 | short vGlobal; |
| 230 | Boolean front; |
| 231 | if (!PyArg_ParseTuple(_args, "hhb", |
| 232 | &hGlobal, |
| 233 | &vGlobal, |
| 234 | &front)) |
| 235 | return NULL; |
| 236 | MoveWindow(_self->ob_itself, |
| 237 | hGlobal, |
| 238 | vGlobal, |
| 239 | front); |
| 240 | Py_INCREF(Py_None); |
| 241 | _res = Py_None; |
| 242 | return _res; |
| 243 | } |
| 244 | |
| 245 | static PyObject *WinObj_SizeWindow(_self, _args) |
| 246 | WindowObject *_self; |
| 247 | PyObject *_args; |
| 248 | { |
| 249 | PyObject *_res = NULL; |
| 250 | short w; |
| 251 | short h; |
| 252 | Boolean fUpdate; |
| 253 | if (!PyArg_ParseTuple(_args, "hhb", |
| 254 | &w, |
| 255 | &h, |
| 256 | &fUpdate)) |
| 257 | return NULL; |
| 258 | SizeWindow(_self->ob_itself, |
| 259 | w, |
| 260 | h, |
| 261 | fUpdate); |
| 262 | Py_INCREF(Py_None); |
| 263 | _res = Py_None; |
| 264 | return _res; |
| 265 | } |
| 266 | |
| 267 | static PyObject *WinObj_ZoomWindow(_self, _args) |
| 268 | WindowObject *_self; |
| 269 | PyObject *_args; |
| 270 | { |
| 271 | PyObject *_res = NULL; |
| 272 | short partCode; |
| 273 | Boolean front; |
| 274 | if (!PyArg_ParseTuple(_args, "hb", |
| 275 | &partCode, |
| 276 | &front)) |
| 277 | return NULL; |
| 278 | ZoomWindow(_self->ob_itself, |
| 279 | partCode, |
| 280 | front); |
| 281 | Py_INCREF(Py_None); |
| 282 | _res = Py_None; |
| 283 | return _res; |
| 284 | } |
| 285 | |
| 286 | static PyObject *WinObj_BeginUpdate(_self, _args) |
| 287 | WindowObject *_self; |
| 288 | PyObject *_args; |
| 289 | { |
| 290 | PyObject *_res = NULL; |
| 291 | if (!PyArg_ParseTuple(_args, "")) |
| 292 | return NULL; |
| 293 | BeginUpdate(_self->ob_itself); |
| 294 | Py_INCREF(Py_None); |
| 295 | _res = Py_None; |
| 296 | return _res; |
| 297 | } |
| 298 | |
| 299 | static PyObject *WinObj_EndUpdate(_self, _args) |
| 300 | WindowObject *_self; |
| 301 | PyObject *_args; |
| 302 | { |
| 303 | PyObject *_res = NULL; |
| 304 | if (!PyArg_ParseTuple(_args, "")) |
| 305 | return NULL; |
| 306 | EndUpdate(_self->ob_itself); |
| 307 | Py_INCREF(Py_None); |
| 308 | _res = Py_None; |
| 309 | return _res; |
| 310 | } |
| 311 | |
| 312 | static PyObject *WinObj_SetWRefCon(_self, _args) |
| 313 | WindowObject *_self; |
| 314 | PyObject *_args; |
| 315 | { |
| 316 | PyObject *_res = NULL; |
| 317 | long data; |
| 318 | if (!PyArg_ParseTuple(_args, "l", |
| 319 | &data)) |
| 320 | return NULL; |
| 321 | SetWRefCon(_self->ob_itself, |
| 322 | data); |
| 323 | Py_INCREF(Py_None); |
| 324 | _res = Py_None; |
| 325 | return _res; |
| 326 | } |
| 327 | |
| 328 | static PyObject *WinObj_GetWRefCon(_self, _args) |
| 329 | WindowObject *_self; |
| 330 | PyObject *_args; |
| 331 | { |
| 332 | PyObject *_res = NULL; |
| 333 | long _rv; |
| 334 | if (!PyArg_ParseTuple(_args, "")) |
| 335 | return NULL; |
| 336 | _rv = GetWRefCon(_self->ob_itself); |
| 337 | _res = Py_BuildValue("l", |
| 338 | _rv); |
| 339 | return _res; |
| 340 | } |
| 341 | |
| 342 | static PyObject *WinObj_ClipAbove(_self, _args) |
| 343 | WindowObject *_self; |
| 344 | PyObject *_args; |
| 345 | { |
| 346 | PyObject *_res = NULL; |
| 347 | if (!PyArg_ParseTuple(_args, "")) |
| 348 | return NULL; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame^] | 349 | ClipAbove(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 350 | Py_INCREF(Py_None); |
| 351 | _res = Py_None; |
| 352 | return _res; |
| 353 | } |
| 354 | |
| 355 | static PyObject *WinObj_SaveOld(_self, _args) |
| 356 | WindowObject *_self; |
| 357 | PyObject *_args; |
| 358 | { |
| 359 | PyObject *_res = NULL; |
| 360 | if (!PyArg_ParseTuple(_args, "")) |
| 361 | return NULL; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame^] | 362 | SaveOld(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 363 | Py_INCREF(Py_None); |
| 364 | _res = Py_None; |
| 365 | return _res; |
| 366 | } |
| 367 | |
| 368 | static PyObject *WinObj_DrawNew(_self, _args) |
| 369 | WindowObject *_self; |
| 370 | PyObject *_args; |
| 371 | { |
| 372 | PyObject *_res = NULL; |
| 373 | Boolean update; |
| 374 | if (!PyArg_ParseTuple(_args, "b", |
| 375 | &update)) |
| 376 | return NULL; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame^] | 377 | DrawNew(_self->ob_itself, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 378 | update); |
| 379 | Py_INCREF(Py_None); |
| 380 | _res = Py_None; |
| 381 | return _res; |
| 382 | } |
| 383 | |
| 384 | static PyObject *WinObj_CalcVis(_self, _args) |
| 385 | WindowObject *_self; |
| 386 | PyObject *_args; |
| 387 | { |
| 388 | PyObject *_res = NULL; |
| 389 | if (!PyArg_ParseTuple(_args, "")) |
| 390 | return NULL; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame^] | 391 | CalcVis(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 392 | Py_INCREF(Py_None); |
| 393 | _res = Py_None; |
| 394 | return _res; |
| 395 | } |
| 396 | |
| 397 | static PyObject *WinObj_GrowWindow(_self, _args) |
| 398 | WindowObject *_self; |
| 399 | PyObject *_args; |
| 400 | { |
| 401 | PyObject *_res = NULL; |
| 402 | long _rv; |
| 403 | Point startPt; |
| 404 | Rect bBox; |
| 405 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 406 | PyMac_GetPoint, &startPt, |
| 407 | PyMac_GetRect, &bBox)) |
| 408 | return NULL; |
| 409 | _rv = GrowWindow(_self->ob_itself, |
| 410 | startPt, |
| 411 | &bBox); |
| 412 | _res = Py_BuildValue("l", |
| 413 | _rv); |
| 414 | return _res; |
| 415 | } |
| 416 | |
| 417 | static PyObject *WinObj_TrackBox(_self, _args) |
| 418 | WindowObject *_self; |
| 419 | PyObject *_args; |
| 420 | { |
| 421 | PyObject *_res = NULL; |
| 422 | Boolean _rv; |
| 423 | Point thePt; |
| 424 | short partCode; |
| 425 | if (!PyArg_ParseTuple(_args, "O&h", |
| 426 | PyMac_GetPoint, &thePt, |
| 427 | &partCode)) |
| 428 | return NULL; |
| 429 | _rv = TrackBox(_self->ob_itself, |
| 430 | thePt, |
| 431 | partCode); |
| 432 | _res = Py_BuildValue("b", |
| 433 | _rv); |
| 434 | return _res; |
| 435 | } |
| 436 | |
| 437 | static PyObject *WinObj_GetWVariant(_self, _args) |
| 438 | WindowObject *_self; |
| 439 | PyObject *_args; |
| 440 | { |
| 441 | PyObject *_res = NULL; |
| 442 | short _rv; |
| 443 | if (!PyArg_ParseTuple(_args, "")) |
| 444 | return NULL; |
| 445 | _rv = GetWVariant(_self->ob_itself); |
| 446 | _res = Py_BuildValue("h", |
| 447 | _rv); |
| 448 | return _res; |
| 449 | } |
| 450 | |
| 451 | static PyObject *WinObj_SetWTitle(_self, _args) |
| 452 | WindowObject *_self; |
| 453 | PyObject *_args; |
| 454 | { |
| 455 | PyObject *_res = NULL; |
| 456 | Str255 title; |
| 457 | if (!PyArg_ParseTuple(_args, "O&", |
| 458 | PyMac_GetStr255, title)) |
| 459 | return NULL; |
| 460 | SetWTitle(_self->ob_itself, |
| 461 | title); |
| 462 | Py_INCREF(Py_None); |
| 463 | _res = Py_None; |
| 464 | return _res; |
| 465 | } |
| 466 | |
| 467 | static PyObject *WinObj_TrackGoAway(_self, _args) |
| 468 | WindowObject *_self; |
| 469 | PyObject *_args; |
| 470 | { |
| 471 | PyObject *_res = NULL; |
| 472 | Boolean _rv; |
| 473 | Point thePt; |
| 474 | if (!PyArg_ParseTuple(_args, "O&", |
| 475 | PyMac_GetPoint, &thePt)) |
| 476 | return NULL; |
| 477 | _rv = TrackGoAway(_self->ob_itself, |
| 478 | thePt); |
| 479 | _res = Py_BuildValue("b", |
| 480 | _rv); |
| 481 | return _res; |
| 482 | } |
| 483 | |
| 484 | static PyObject *WinObj_DragWindow(_self, _args) |
| 485 | WindowObject *_self; |
| 486 | PyObject *_args; |
| 487 | { |
| 488 | PyObject *_res = NULL; |
| 489 | Point startPt; |
| 490 | Rect boundsRect; |
| 491 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 492 | PyMac_GetPoint, &startPt, |
| 493 | PyMac_GetRect, &boundsRect)) |
| 494 | return NULL; |
| 495 | DragWindow(_self->ob_itself, |
| 496 | startPt, |
| 497 | &boundsRect); |
| 498 | Py_INCREF(Py_None); |
| 499 | _res = Py_None; |
| 500 | return _res; |
| 501 | } |
| 502 | |
| 503 | static PyMethodDef WinObj_methods[] = { |
| 504 | {"GetWTitle", (PyCFunction)WinObj_GetWTitle, 1, |
| 505 | "() -> (Str255 title)"}, |
| 506 | {"SelectWindow", (PyCFunction)WinObj_SelectWindow, 1, |
| 507 | "() -> None"}, |
| 508 | {"HideWindow", (PyCFunction)WinObj_HideWindow, 1, |
| 509 | "() -> None"}, |
| 510 | {"ShowWindow", (PyCFunction)WinObj_ShowWindow, 1, |
| 511 | "() -> None"}, |
| 512 | {"ShowHide", (PyCFunction)WinObj_ShowHide, 1, |
| 513 | "(Boolean showFlag) -> None"}, |
| 514 | {"HiliteWindow", (PyCFunction)WinObj_HiliteWindow, 1, |
| 515 | "(Boolean fHilite) -> None"}, |
| 516 | {"BringToFront", (PyCFunction)WinObj_BringToFront, 1, |
| 517 | "() -> None"}, |
| 518 | {"SendBehind", (PyCFunction)WinObj_SendBehind, 1, |
| 519 | "(WindowPtr behindWindow) -> None"}, |
| 520 | {"DrawGrowIcon", (PyCFunction)WinObj_DrawGrowIcon, 1, |
| 521 | "() -> None"}, |
| 522 | {"MoveWindow", (PyCFunction)WinObj_MoveWindow, 1, |
| 523 | "(short hGlobal, short vGlobal, Boolean front) -> None"}, |
| 524 | {"SizeWindow", (PyCFunction)WinObj_SizeWindow, 1, |
| 525 | "(short w, short h, Boolean fUpdate) -> None"}, |
| 526 | {"ZoomWindow", (PyCFunction)WinObj_ZoomWindow, 1, |
| 527 | "(short partCode, Boolean front) -> None"}, |
| 528 | {"BeginUpdate", (PyCFunction)WinObj_BeginUpdate, 1, |
| 529 | "() -> None"}, |
| 530 | {"EndUpdate", (PyCFunction)WinObj_EndUpdate, 1, |
| 531 | "() -> None"}, |
| 532 | {"SetWRefCon", (PyCFunction)WinObj_SetWRefCon, 1, |
| 533 | "(long data) -> None"}, |
| 534 | {"GetWRefCon", (PyCFunction)WinObj_GetWRefCon, 1, |
| 535 | "() -> (long _rv)"}, |
| 536 | {"ClipAbove", (PyCFunction)WinObj_ClipAbove, 1, |
| 537 | "() -> None"}, |
| 538 | {"SaveOld", (PyCFunction)WinObj_SaveOld, 1, |
| 539 | "() -> None"}, |
| 540 | {"DrawNew", (PyCFunction)WinObj_DrawNew, 1, |
| 541 | "(Boolean update) -> None"}, |
| 542 | {"CalcVis", (PyCFunction)WinObj_CalcVis, 1, |
| 543 | "() -> None"}, |
| 544 | {"GrowWindow", (PyCFunction)WinObj_GrowWindow, 1, |
| 545 | "(Point startPt, Rect bBox) -> (long _rv)"}, |
| 546 | {"TrackBox", (PyCFunction)WinObj_TrackBox, 1, |
| 547 | "(Point thePt, short partCode) -> (Boolean _rv)"}, |
| 548 | {"GetWVariant", (PyCFunction)WinObj_GetWVariant, 1, |
| 549 | "() -> (short _rv)"}, |
| 550 | {"SetWTitle", (PyCFunction)WinObj_SetWTitle, 1, |
| 551 | "(Str255 title) -> None"}, |
| 552 | {"TrackGoAway", (PyCFunction)WinObj_TrackGoAway, 1, |
| 553 | "(Point thePt) -> (Boolean _rv)"}, |
| 554 | {"DragWindow", (PyCFunction)WinObj_DragWindow, 1, |
| 555 | "(Point startPt, Rect boundsRect) -> None"}, |
| 556 | {NULL, NULL, 0} |
| 557 | }; |
| 558 | |
| 559 | PyMethodChain WinObj_chain = { WinObj_methods, NULL }; |
| 560 | |
| 561 | static PyObject *WinObj_getattr(self, name) |
| 562 | WindowObject *self; |
| 563 | char *name; |
| 564 | { |
| 565 | return Py_FindMethodInChain(&WinObj_chain, (PyObject *)self, name); |
| 566 | } |
| 567 | |
| 568 | #define WinObj_setattr NULL |
| 569 | |
| 570 | PyTypeObject Window_Type = { |
| 571 | PyObject_HEAD_INIT(&PyType_Type) |
| 572 | 0, /*ob_size*/ |
| 573 | "Window", /*tp_name*/ |
| 574 | sizeof(WindowObject), /*tp_basicsize*/ |
| 575 | 0, /*tp_itemsize*/ |
| 576 | /* methods */ |
| 577 | (destructor) WinObj_dealloc, /*tp_dealloc*/ |
| 578 | 0, /*tp_print*/ |
| 579 | (getattrfunc) WinObj_getattr, /*tp_getattr*/ |
| 580 | (setattrfunc) WinObj_setattr, /*tp_setattr*/ |
| 581 | }; |
| 582 | |
| 583 | /* --------------------- End object type Window --------------------- */ |
| 584 | |
| 585 | |
| 586 | static PyObject *Win_InitWindows(_self, _args) |
| 587 | PyObject *_self; |
| 588 | PyObject *_args; |
| 589 | { |
| 590 | PyObject *_res = NULL; |
| 591 | if (!PyArg_ParseTuple(_args, "")) |
| 592 | return NULL; |
| 593 | InitWindows(); |
| 594 | Py_INCREF(Py_None); |
| 595 | _res = Py_None; |
| 596 | return _res; |
| 597 | } |
| 598 | |
| 599 | static PyObject *Win_NewWindow(_self, _args) |
| 600 | PyObject *_self; |
| 601 | PyObject *_args; |
| 602 | { |
| 603 | PyObject *_res = NULL; |
| 604 | WindowPtr _rv; |
| 605 | Rect boundsRect; |
| 606 | Str255 title; |
| 607 | Boolean visible; |
| 608 | short theProc; |
| 609 | WindowPtr behind; |
| 610 | Boolean goAwayFlag; |
| 611 | long refCon; |
| 612 | if (!PyArg_ParseTuple(_args, "O&O&bhO&bl", |
| 613 | PyMac_GetRect, &boundsRect, |
| 614 | PyMac_GetStr255, title, |
| 615 | &visible, |
| 616 | &theProc, |
| 617 | WinObj_Convert, &behind, |
| 618 | &goAwayFlag, |
| 619 | &refCon)) |
| 620 | return NULL; |
| 621 | _rv = NewWindow((void *)0, |
| 622 | &boundsRect, |
| 623 | title, |
| 624 | visible, |
| 625 | theProc, |
| 626 | behind, |
| 627 | goAwayFlag, |
| 628 | refCon); |
| 629 | _res = Py_BuildValue("O&", |
| 630 | WinObj_New, _rv); |
| 631 | return _res; |
| 632 | } |
| 633 | |
| 634 | static PyObject *Win_GetNewWindow(_self, _args) |
| 635 | PyObject *_self; |
| 636 | PyObject *_args; |
| 637 | { |
| 638 | PyObject *_res = NULL; |
| 639 | WindowPtr _rv; |
| 640 | short windowID; |
| 641 | WindowPtr behind; |
| 642 | if (!PyArg_ParseTuple(_args, "hO&", |
| 643 | &windowID, |
| 644 | WinObj_Convert, &behind)) |
| 645 | return NULL; |
| 646 | _rv = GetNewWindow(windowID, |
| 647 | (void *)0, |
| 648 | behind); |
| 649 | _res = Py_BuildValue("O&", |
| 650 | WinObj_New, _rv); |
| 651 | return _res; |
| 652 | } |
| 653 | |
| 654 | static PyObject *Win_FrontWindow(_self, _args) |
| 655 | PyObject *_self; |
| 656 | PyObject *_args; |
| 657 | { |
| 658 | PyObject *_res = NULL; |
| 659 | WindowPtr _rv; |
| 660 | if (!PyArg_ParseTuple(_args, "")) |
| 661 | return NULL; |
| 662 | _rv = FrontWindow(); |
| 663 | _res = Py_BuildValue("O&", |
Guido van Rossum | ea39abd | 1995-02-28 09:49:02 +0000 | [diff] [blame] | 664 | WinObj_WhichWindow, _rv); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 665 | return _res; |
| 666 | } |
| 667 | |
| 668 | static PyObject *Win_InvalRect(_self, _args) |
| 669 | PyObject *_self; |
| 670 | PyObject *_args; |
| 671 | { |
| 672 | PyObject *_res = NULL; |
| 673 | Rect badRect; |
| 674 | if (!PyArg_ParseTuple(_args, "O&", |
| 675 | PyMac_GetRect, &badRect)) |
| 676 | return NULL; |
| 677 | InvalRect(&badRect); |
| 678 | Py_INCREF(Py_None); |
| 679 | _res = Py_None; |
| 680 | return _res; |
| 681 | } |
| 682 | |
| 683 | static PyObject *Win_ValidRect(_self, _args) |
| 684 | PyObject *_self; |
| 685 | PyObject *_args; |
| 686 | { |
| 687 | PyObject *_res = NULL; |
| 688 | Rect goodRect; |
| 689 | if (!PyArg_ParseTuple(_args, "O&", |
| 690 | PyMac_GetRect, &goodRect)) |
| 691 | return NULL; |
| 692 | ValidRect(&goodRect); |
| 693 | Py_INCREF(Py_None); |
| 694 | _res = Py_None; |
| 695 | return _res; |
| 696 | } |
| 697 | |
| 698 | static PyObject *Win_CheckUpdate(_self, _args) |
| 699 | PyObject *_self; |
| 700 | PyObject *_args; |
| 701 | { |
| 702 | PyObject *_res = NULL; |
| 703 | Boolean _rv; |
| 704 | EventRecord theEvent; |
| 705 | if (!PyArg_ParseTuple(_args, "")) |
| 706 | return NULL; |
| 707 | _rv = CheckUpdate(&theEvent); |
| 708 | _res = Py_BuildValue("bO&", |
| 709 | _rv, |
| 710 | PyMac_BuildEventRecord, &theEvent); |
| 711 | return _res; |
| 712 | } |
| 713 | |
| 714 | static PyObject *Win_FindWindow(_self, _args) |
| 715 | PyObject *_self; |
| 716 | PyObject *_args; |
| 717 | { |
| 718 | PyObject *_res = NULL; |
| 719 | short _rv; |
| 720 | Point thePoint; |
| 721 | WindowPtr theWindow; |
| 722 | if (!PyArg_ParseTuple(_args, "O&", |
| 723 | PyMac_GetPoint, &thePoint)) |
| 724 | return NULL; |
| 725 | _rv = FindWindow(thePoint, |
| 726 | &theWindow); |
| 727 | _res = Py_BuildValue("hO&", |
| 728 | _rv, |
| 729 | WinObj_WhichWindow, theWindow); |
| 730 | return _res; |
| 731 | } |
| 732 | |
| 733 | static PyObject *Win_PinRect(_self, _args) |
| 734 | PyObject *_self; |
| 735 | PyObject *_args; |
| 736 | { |
| 737 | PyObject *_res = NULL; |
| 738 | long _rv; |
| 739 | Rect theRect; |
| 740 | Point thePt; |
| 741 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 742 | PyMac_GetRect, &theRect, |
| 743 | PyMac_GetPoint, &thePt)) |
| 744 | return NULL; |
| 745 | _rv = PinRect(&theRect, |
| 746 | thePt); |
| 747 | _res = Py_BuildValue("l", |
| 748 | _rv); |
| 749 | return _res; |
| 750 | } |
| 751 | |
| 752 | static PyObject *Win_NewCWindow(_self, _args) |
| 753 | PyObject *_self; |
| 754 | PyObject *_args; |
| 755 | { |
| 756 | PyObject *_res = NULL; |
| 757 | WindowPtr _rv; |
| 758 | Rect boundsRect; |
| 759 | Str255 title; |
| 760 | Boolean visible; |
| 761 | short procID; |
| 762 | WindowPtr behind; |
| 763 | Boolean goAwayFlag; |
| 764 | long refCon; |
| 765 | if (!PyArg_ParseTuple(_args, "O&O&bhO&bl", |
| 766 | PyMac_GetRect, &boundsRect, |
| 767 | PyMac_GetStr255, title, |
| 768 | &visible, |
| 769 | &procID, |
| 770 | WinObj_Convert, &behind, |
| 771 | &goAwayFlag, |
| 772 | &refCon)) |
| 773 | return NULL; |
| 774 | _rv = NewCWindow((void *)0, |
| 775 | &boundsRect, |
| 776 | title, |
| 777 | visible, |
| 778 | procID, |
| 779 | behind, |
| 780 | goAwayFlag, |
| 781 | refCon); |
| 782 | _res = Py_BuildValue("O&", |
| 783 | WinObj_New, _rv); |
| 784 | return _res; |
| 785 | } |
| 786 | |
| 787 | static PyObject *Win_GetNewCWindow(_self, _args) |
| 788 | PyObject *_self; |
| 789 | PyObject *_args; |
| 790 | { |
| 791 | PyObject *_res = NULL; |
| 792 | WindowPtr _rv; |
| 793 | short windowID; |
| 794 | WindowPtr behind; |
| 795 | if (!PyArg_ParseTuple(_args, "hO&", |
| 796 | &windowID, |
| 797 | WinObj_Convert, &behind)) |
| 798 | return NULL; |
| 799 | _rv = GetNewCWindow(windowID, |
| 800 | (void *)0, |
| 801 | behind); |
| 802 | _res = Py_BuildValue("O&", |
| 803 | WinObj_New, _rv); |
| 804 | return _res; |
| 805 | } |
| 806 | |
| 807 | static PyMethodDef Win_methods[] = { |
| 808 | {"InitWindows", (PyCFunction)Win_InitWindows, 1, |
| 809 | "() -> None"}, |
| 810 | {"NewWindow", (PyCFunction)Win_NewWindow, 1, |
| 811 | "(Rect boundsRect, Str255 title, Boolean visible, short theProc, WindowPtr behind, Boolean goAwayFlag, long refCon) -> (WindowPtr _rv)"}, |
| 812 | {"GetNewWindow", (PyCFunction)Win_GetNewWindow, 1, |
| 813 | "(short windowID, WindowPtr behind) -> (WindowPtr _rv)"}, |
| 814 | {"FrontWindow", (PyCFunction)Win_FrontWindow, 1, |
| 815 | "() -> (WindowPtr _rv)"}, |
| 816 | {"InvalRect", (PyCFunction)Win_InvalRect, 1, |
| 817 | "(Rect badRect) -> None"}, |
| 818 | {"ValidRect", (PyCFunction)Win_ValidRect, 1, |
| 819 | "(Rect goodRect) -> None"}, |
| 820 | {"CheckUpdate", (PyCFunction)Win_CheckUpdate, 1, |
| 821 | "() -> (Boolean _rv, EventRecord theEvent)"}, |
| 822 | {"FindWindow", (PyCFunction)Win_FindWindow, 1, |
| 823 | "(Point thePoint) -> (short _rv, WindowPtr theWindow)"}, |
| 824 | {"PinRect", (PyCFunction)Win_PinRect, 1, |
| 825 | "(Rect theRect, Point thePt) -> (long _rv)"}, |
| 826 | {"NewCWindow", (PyCFunction)Win_NewCWindow, 1, |
| 827 | "(Rect boundsRect, Str255 title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon) -> (WindowPtr _rv)"}, |
| 828 | {"GetNewCWindow", (PyCFunction)Win_GetNewCWindow, 1, |
| 829 | "(short windowID, WindowPtr behind) -> (WindowPtr _rv)"}, |
| 830 | {NULL, NULL, 0} |
| 831 | }; |
| 832 | |
| 833 | |
| 834 | |
| 835 | /* Return the object corresponding to the window, or NULL */ |
| 836 | |
| 837 | PyObject * |
| 838 | WinObj_WhichWindow(w) |
| 839 | WindowPtr w; |
| 840 | { |
| 841 | PyObject *it; |
| 842 | |
| 843 | /* XXX What if we find a stdwin window or a window belonging |
| 844 | to some other package? */ |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 845 | if (w == NULL) |
| 846 | it = NULL; |
| 847 | else |
| 848 | it = (PyObject *) GetWRefCon(w); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 849 | if (it == NULL || ((WindowObject *)it)->ob_itself != w) |
| 850 | it = Py_None; |
| 851 | Py_INCREF(it); |
| 852 | return it; |
| 853 | } |
| 854 | |
| 855 | |
| 856 | void initWin() |
| 857 | { |
| 858 | PyObject *m; |
| 859 | PyObject *d; |
| 860 | |
| 861 | |
| 862 | |
| 863 | |
| 864 | m = Py_InitModule("Win", Win_methods); |
| 865 | d = PyModule_GetDict(m); |
| 866 | Win_Error = PyMac_GetOSErrException(); |
| 867 | if (Win_Error == NULL || |
| 868 | PyDict_SetItemString(d, "Error", Win_Error) != 0) |
| 869 | Py_FatalError("can't initialize Win.Error"); |
| 870 | } |
| 871 | |
| 872 | /* ========================= End module Win ========================= */ |
| 873 | |