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