Jack Jansen | a4e6ae6 | 1999-03-07 23:11:21 +0000 | [diff] [blame] | 1 | |
| 2 | /* ========================= Module Qdoffs ========================== */ |
| 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 | extern PyObject *OptResObj_New(Handle); |
| 19 | extern int OptResObj_Convert(PyObject *, Handle *); |
| 20 | |
| 21 | extern PyObject *WinObj_New(WindowPtr); |
| 22 | extern int WinObj_Convert(PyObject *, WindowPtr *); |
| 23 | extern PyTypeObject Window_Type; |
| 24 | #define WinObj_Check(x) ((x)->ob_type == &Window_Type) |
| 25 | |
| 26 | extern PyObject *DlgObj_New(DialogPtr); |
| 27 | extern int DlgObj_Convert(PyObject *, DialogPtr *); |
| 28 | extern PyTypeObject Dialog_Type; |
| 29 | #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) |
| 30 | |
| 31 | extern PyObject *MenuObj_New(MenuHandle); |
| 32 | extern int MenuObj_Convert(PyObject *, MenuHandle *); |
| 33 | |
| 34 | extern PyObject *CtlObj_New(ControlHandle); |
| 35 | extern int CtlObj_Convert(PyObject *, ControlHandle *); |
| 36 | |
| 37 | extern PyObject *GrafObj_New(GrafPtr); |
| 38 | extern int GrafObj_Convert(PyObject *, GrafPtr *); |
| 39 | |
| 40 | extern PyObject *BMObj_New(BitMapPtr); |
| 41 | extern int BMObj_Convert(PyObject *, BitMapPtr *); |
| 42 | |
| 43 | extern PyObject *WinObj_WhichWindow(WindowPtr); |
| 44 | |
| 45 | #include <QDOffscreen.h> |
| 46 | |
Jack Jansen | 6dc8ce9 | 2000-03-03 16:03:06 +0000 | [diff] [blame^] | 47 | #define as_GrafPtr(gworld) ((GrafPtr)(gworld)) |
| 48 | |
Jack Jansen | a4e6ae6 | 1999-03-07 23:11:21 +0000 | [diff] [blame] | 49 | #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ |
| 50 | |
| 51 | |
| 52 | static PyObject *Qdoffs_Error; |
| 53 | |
| 54 | /* ----------------------- Object type GWorld ----------------------- */ |
| 55 | |
| 56 | PyTypeObject GWorld_Type; |
| 57 | |
| 58 | #define GWorldObj_Check(x) ((x)->ob_type == &GWorld_Type) |
| 59 | |
| 60 | typedef struct GWorldObject { |
| 61 | PyObject_HEAD |
| 62 | GWorldPtr ob_itself; |
| 63 | } GWorldObject; |
| 64 | |
| 65 | PyObject *GWorldObj_New(itself) |
| 66 | GWorldPtr itself; |
| 67 | { |
| 68 | GWorldObject *it; |
| 69 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 70 | it = PyObject_NEW(GWorldObject, &GWorld_Type); |
| 71 | if (it == NULL) return NULL; |
| 72 | it->ob_itself = itself; |
| 73 | return (PyObject *)it; |
| 74 | } |
| 75 | GWorldObj_Convert(v, p_itself) |
| 76 | PyObject *v; |
| 77 | GWorldPtr *p_itself; |
| 78 | { |
| 79 | if (!GWorldObj_Check(v)) |
| 80 | { |
| 81 | PyErr_SetString(PyExc_TypeError, "GWorld required"); |
| 82 | return 0; |
| 83 | } |
| 84 | *p_itself = ((GWorldObject *)v)->ob_itself; |
| 85 | return 1; |
| 86 | } |
| 87 | |
| 88 | static void GWorldObj_dealloc(self) |
| 89 | GWorldObject *self; |
| 90 | { |
| 91 | DisposeGWorld(self->ob_itself); |
| 92 | PyMem_DEL(self); |
| 93 | } |
| 94 | |
| 95 | static PyObject *GWorldObj_GetGWorldDevice(_self, _args) |
| 96 | GWorldObject *_self; |
| 97 | PyObject *_args; |
| 98 | { |
| 99 | PyObject *_res = NULL; |
| 100 | GDHandle _rv; |
| 101 | if (!PyArg_ParseTuple(_args, "")) |
| 102 | return NULL; |
| 103 | _rv = GetGWorldDevice(_self->ob_itself); |
| 104 | _res = Py_BuildValue("O&", |
| 105 | ResObj_New, _rv); |
| 106 | return _res; |
| 107 | } |
| 108 | |
| 109 | static PyObject *GWorldObj_GetGWorldPixMap(_self, _args) |
| 110 | GWorldObject *_self; |
| 111 | PyObject *_args; |
| 112 | { |
| 113 | PyObject *_res = NULL; |
| 114 | PixMapHandle _rv; |
| 115 | if (!PyArg_ParseTuple(_args, "")) |
| 116 | return NULL; |
| 117 | _rv = GetGWorldPixMap(_self->ob_itself); |
| 118 | _res = Py_BuildValue("O&", |
| 119 | ResObj_New, _rv); |
| 120 | return _res; |
| 121 | } |
| 122 | |
Jack Jansen | 6dc8ce9 | 2000-03-03 16:03:06 +0000 | [diff] [blame^] | 123 | static PyObject *GWorldObj_as_GrafPtr(_self, _args) |
| 124 | GWorldObject *_self; |
| 125 | PyObject *_args; |
| 126 | { |
| 127 | PyObject *_res = NULL; |
| 128 | GrafPtr _rv; |
| 129 | if (!PyArg_ParseTuple(_args, "")) |
| 130 | return NULL; |
| 131 | _rv = as_GrafPtr(_self->ob_itself); |
| 132 | _res = Py_BuildValue("O&", |
| 133 | GrafObj_New, _rv); |
| 134 | return _res; |
| 135 | } |
| 136 | |
Jack Jansen | a4e6ae6 | 1999-03-07 23:11:21 +0000 | [diff] [blame] | 137 | static PyMethodDef GWorldObj_methods[] = { |
| 138 | {"GetGWorldDevice", (PyCFunction)GWorldObj_GetGWorldDevice, 1, |
| 139 | "() -> (GDHandle _rv)"}, |
| 140 | {"GetGWorldPixMap", (PyCFunction)GWorldObj_GetGWorldPixMap, 1, |
| 141 | "() -> (PixMapHandle _rv)"}, |
Jack Jansen | 6dc8ce9 | 2000-03-03 16:03:06 +0000 | [diff] [blame^] | 142 | {"as_GrafPtr", (PyCFunction)GWorldObj_as_GrafPtr, 1, |
| 143 | "() -> (GrafPtr _rv)"}, |
Jack Jansen | a4e6ae6 | 1999-03-07 23:11:21 +0000 | [diff] [blame] | 144 | {NULL, NULL, 0} |
| 145 | }; |
| 146 | |
| 147 | PyMethodChain GWorldObj_chain = { GWorldObj_methods, NULL }; |
| 148 | |
| 149 | static PyObject *GWorldObj_getattr(self, name) |
| 150 | GWorldObject *self; |
| 151 | char *name; |
| 152 | { |
| 153 | return Py_FindMethodInChain(&GWorldObj_chain, (PyObject *)self, name); |
| 154 | } |
| 155 | |
| 156 | #define GWorldObj_setattr NULL |
| 157 | |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 158 | #define GWorldObj_compare NULL |
| 159 | |
| 160 | #define GWorldObj_repr NULL |
| 161 | |
| 162 | #define GWorldObj_hash NULL |
| 163 | |
Jack Jansen | a4e6ae6 | 1999-03-07 23:11:21 +0000 | [diff] [blame] | 164 | PyTypeObject GWorld_Type = { |
| 165 | PyObject_HEAD_INIT(&PyType_Type) |
| 166 | 0, /*ob_size*/ |
| 167 | "GWorld", /*tp_name*/ |
| 168 | sizeof(GWorldObject), /*tp_basicsize*/ |
| 169 | 0, /*tp_itemsize*/ |
| 170 | /* methods */ |
| 171 | (destructor) GWorldObj_dealloc, /*tp_dealloc*/ |
| 172 | 0, /*tp_print*/ |
| 173 | (getattrfunc) GWorldObj_getattr, /*tp_getattr*/ |
| 174 | (setattrfunc) GWorldObj_setattr, /*tp_setattr*/ |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 175 | (cmpfunc) GWorldObj_compare, /*tp_compare*/ |
| 176 | (reprfunc) GWorldObj_repr, /*tp_repr*/ |
| 177 | (PyNumberMethods *)0, /* tp_as_number */ |
| 178 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 179 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 180 | (hashfunc) GWorldObj_hash, /*tp_hash*/ |
Jack Jansen | a4e6ae6 | 1999-03-07 23:11:21 +0000 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | /* --------------------- End object type GWorld --------------------- */ |
| 184 | |
| 185 | |
| 186 | static PyObject *Qdoffs_NewGWorld(_self, _args) |
| 187 | PyObject *_self; |
| 188 | PyObject *_args; |
| 189 | { |
| 190 | PyObject *_res = NULL; |
| 191 | QDErr _err; |
| 192 | GWorldPtr offscreenGWorld; |
| 193 | short PixelDepth; |
| 194 | Rect boundsRect; |
| 195 | CTabHandle cTable; |
| 196 | GDHandle aGDevice; |
| 197 | GWorldFlags flags; |
| 198 | if (!PyArg_ParseTuple(_args, "hO&O&O&l", |
| 199 | &PixelDepth, |
| 200 | PyMac_GetRect, &boundsRect, |
| 201 | OptResObj_Convert, &cTable, |
| 202 | OptResObj_Convert, &aGDevice, |
| 203 | &flags)) |
| 204 | return NULL; |
| 205 | _err = NewGWorld(&offscreenGWorld, |
| 206 | PixelDepth, |
| 207 | &boundsRect, |
| 208 | cTable, |
| 209 | aGDevice, |
| 210 | flags); |
| 211 | if (_err != noErr) return PyMac_Error(_err); |
| 212 | _res = Py_BuildValue("O&", |
| 213 | GWorldObj_New, offscreenGWorld); |
| 214 | return _res; |
| 215 | } |
| 216 | |
| 217 | static PyObject *Qdoffs_LockPixels(_self, _args) |
| 218 | PyObject *_self; |
| 219 | PyObject *_args; |
| 220 | { |
| 221 | PyObject *_res = NULL; |
| 222 | Boolean _rv; |
| 223 | PixMapHandle pm; |
| 224 | if (!PyArg_ParseTuple(_args, "O&", |
| 225 | ResObj_Convert, &pm)) |
| 226 | return NULL; |
| 227 | _rv = LockPixels(pm); |
| 228 | _res = Py_BuildValue("b", |
| 229 | _rv); |
| 230 | return _res; |
| 231 | } |
| 232 | |
| 233 | static PyObject *Qdoffs_UnlockPixels(_self, _args) |
| 234 | PyObject *_self; |
| 235 | PyObject *_args; |
| 236 | { |
| 237 | PyObject *_res = NULL; |
| 238 | PixMapHandle pm; |
| 239 | if (!PyArg_ParseTuple(_args, "O&", |
| 240 | ResObj_Convert, &pm)) |
| 241 | return NULL; |
| 242 | UnlockPixels(pm); |
| 243 | Py_INCREF(Py_None); |
| 244 | _res = Py_None; |
| 245 | return _res; |
| 246 | } |
| 247 | |
| 248 | static PyObject *Qdoffs_UpdateGWorld(_self, _args) |
| 249 | PyObject *_self; |
| 250 | PyObject *_args; |
| 251 | { |
| 252 | PyObject *_res = NULL; |
| 253 | GWorldFlags _rv; |
| 254 | GWorldPtr offscreenGWorld; |
| 255 | short pixelDepth; |
| 256 | Rect boundsRect; |
| 257 | CTabHandle cTable; |
| 258 | GDHandle aGDevice; |
| 259 | GWorldFlags flags; |
| 260 | if (!PyArg_ParseTuple(_args, "hO&O&O&l", |
| 261 | &pixelDepth, |
| 262 | PyMac_GetRect, &boundsRect, |
| 263 | OptResObj_Convert, &cTable, |
| 264 | OptResObj_Convert, &aGDevice, |
| 265 | &flags)) |
| 266 | return NULL; |
| 267 | _rv = UpdateGWorld(&offscreenGWorld, |
| 268 | pixelDepth, |
| 269 | &boundsRect, |
| 270 | cTable, |
| 271 | aGDevice, |
| 272 | flags); |
| 273 | _res = Py_BuildValue("lO&", |
| 274 | _rv, |
| 275 | GWorldObj_New, offscreenGWorld); |
| 276 | return _res; |
| 277 | } |
| 278 | |
| 279 | static PyObject *Qdoffs_GetGWorld(_self, _args) |
| 280 | PyObject *_self; |
| 281 | PyObject *_args; |
| 282 | { |
| 283 | PyObject *_res = NULL; |
| 284 | CGrafPtr port; |
| 285 | GDHandle gdh; |
| 286 | if (!PyArg_ParseTuple(_args, "")) |
| 287 | return NULL; |
| 288 | GetGWorld(&port, |
| 289 | &gdh); |
| 290 | _res = Py_BuildValue("O&O&", |
| 291 | GrafObj_New, port, |
| 292 | ResObj_New, gdh); |
| 293 | return _res; |
| 294 | } |
| 295 | |
| 296 | static PyObject *Qdoffs_SetGWorld(_self, _args) |
| 297 | PyObject *_self; |
| 298 | PyObject *_args; |
| 299 | { |
| 300 | PyObject *_res = NULL; |
| 301 | CGrafPtr port; |
| 302 | GDHandle gdh; |
| 303 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 304 | GrafObj_Convert, &port, |
| 305 | OptResObj_Convert, &gdh)) |
| 306 | return NULL; |
| 307 | SetGWorld(port, |
| 308 | gdh); |
| 309 | Py_INCREF(Py_None); |
| 310 | _res = Py_None; |
| 311 | return _res; |
| 312 | } |
| 313 | |
| 314 | static PyObject *Qdoffs_CTabChanged(_self, _args) |
| 315 | PyObject *_self; |
| 316 | PyObject *_args; |
| 317 | { |
| 318 | PyObject *_res = NULL; |
| 319 | CTabHandle ctab; |
| 320 | if (!PyArg_ParseTuple(_args, "O&", |
| 321 | OptResObj_Convert, &ctab)) |
| 322 | return NULL; |
| 323 | CTabChanged(ctab); |
| 324 | Py_INCREF(Py_None); |
| 325 | _res = Py_None; |
| 326 | return _res; |
| 327 | } |
| 328 | |
| 329 | static PyObject *Qdoffs_PixPatChanged(_self, _args) |
| 330 | PyObject *_self; |
| 331 | PyObject *_args; |
| 332 | { |
| 333 | PyObject *_res = NULL; |
| 334 | PixPatHandle ppat; |
| 335 | if (!PyArg_ParseTuple(_args, "O&", |
| 336 | ResObj_Convert, &ppat)) |
| 337 | return NULL; |
| 338 | PixPatChanged(ppat); |
| 339 | Py_INCREF(Py_None); |
| 340 | _res = Py_None; |
| 341 | return _res; |
| 342 | } |
| 343 | |
| 344 | static PyObject *Qdoffs_PortChanged(_self, _args) |
| 345 | PyObject *_self; |
| 346 | PyObject *_args; |
| 347 | { |
| 348 | PyObject *_res = NULL; |
| 349 | GrafPtr port; |
| 350 | if (!PyArg_ParseTuple(_args, "O&", |
| 351 | GrafObj_Convert, &port)) |
| 352 | return NULL; |
| 353 | PortChanged(port); |
| 354 | Py_INCREF(Py_None); |
| 355 | _res = Py_None; |
| 356 | return _res; |
| 357 | } |
| 358 | |
| 359 | static PyObject *Qdoffs_GDeviceChanged(_self, _args) |
| 360 | PyObject *_self; |
| 361 | PyObject *_args; |
| 362 | { |
| 363 | PyObject *_res = NULL; |
| 364 | GDHandle gdh; |
| 365 | if (!PyArg_ParseTuple(_args, "O&", |
| 366 | OptResObj_Convert, &gdh)) |
| 367 | return NULL; |
| 368 | GDeviceChanged(gdh); |
| 369 | Py_INCREF(Py_None); |
| 370 | _res = Py_None; |
| 371 | return _res; |
| 372 | } |
| 373 | |
| 374 | static PyObject *Qdoffs_AllowPurgePixels(_self, _args) |
| 375 | PyObject *_self; |
| 376 | PyObject *_args; |
| 377 | { |
| 378 | PyObject *_res = NULL; |
| 379 | PixMapHandle pm; |
| 380 | if (!PyArg_ParseTuple(_args, "O&", |
| 381 | ResObj_Convert, &pm)) |
| 382 | return NULL; |
| 383 | AllowPurgePixels(pm); |
| 384 | Py_INCREF(Py_None); |
| 385 | _res = Py_None; |
| 386 | return _res; |
| 387 | } |
| 388 | |
| 389 | static PyObject *Qdoffs_NoPurgePixels(_self, _args) |
| 390 | PyObject *_self; |
| 391 | PyObject *_args; |
| 392 | { |
| 393 | PyObject *_res = NULL; |
| 394 | PixMapHandle pm; |
| 395 | if (!PyArg_ParseTuple(_args, "O&", |
| 396 | ResObj_Convert, &pm)) |
| 397 | return NULL; |
| 398 | NoPurgePixels(pm); |
| 399 | Py_INCREF(Py_None); |
| 400 | _res = Py_None; |
| 401 | return _res; |
| 402 | } |
| 403 | |
| 404 | static PyObject *Qdoffs_GetPixelsState(_self, _args) |
| 405 | PyObject *_self; |
| 406 | PyObject *_args; |
| 407 | { |
| 408 | PyObject *_res = NULL; |
| 409 | GWorldFlags _rv; |
| 410 | PixMapHandle pm; |
| 411 | if (!PyArg_ParseTuple(_args, "O&", |
| 412 | ResObj_Convert, &pm)) |
| 413 | return NULL; |
| 414 | _rv = GetPixelsState(pm); |
| 415 | _res = Py_BuildValue("l", |
| 416 | _rv); |
| 417 | return _res; |
| 418 | } |
| 419 | |
| 420 | static PyObject *Qdoffs_SetPixelsState(_self, _args) |
| 421 | PyObject *_self; |
| 422 | PyObject *_args; |
| 423 | { |
| 424 | PyObject *_res = NULL; |
| 425 | PixMapHandle pm; |
| 426 | GWorldFlags state; |
| 427 | if (!PyArg_ParseTuple(_args, "O&l", |
| 428 | ResObj_Convert, &pm, |
| 429 | &state)) |
| 430 | return NULL; |
| 431 | SetPixelsState(pm, |
| 432 | state); |
| 433 | Py_INCREF(Py_None); |
| 434 | _res = Py_None; |
| 435 | return _res; |
| 436 | } |
| 437 | |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 438 | static PyObject *Qdoffs_GetPixRowBytes(_self, _args) |
| 439 | PyObject *_self; |
| 440 | PyObject *_args; |
| 441 | { |
| 442 | PyObject *_res = NULL; |
| 443 | long _rv; |
| 444 | PixMapHandle pm; |
| 445 | if (!PyArg_ParseTuple(_args, "O&", |
| 446 | ResObj_Convert, &pm)) |
| 447 | return NULL; |
| 448 | _rv = GetPixRowBytes(pm); |
| 449 | _res = Py_BuildValue("l", |
| 450 | _rv); |
| 451 | return _res; |
| 452 | } |
| 453 | |
Jack Jansen | a4e6ae6 | 1999-03-07 23:11:21 +0000 | [diff] [blame] | 454 | static PyObject *Qdoffs_NewScreenBuffer(_self, _args) |
| 455 | PyObject *_self; |
| 456 | PyObject *_args; |
| 457 | { |
| 458 | PyObject *_res = NULL; |
| 459 | QDErr _err; |
| 460 | Rect globalRect; |
| 461 | Boolean purgeable; |
| 462 | GDHandle gdh; |
| 463 | PixMapHandle offscreenPixMap; |
| 464 | if (!PyArg_ParseTuple(_args, "O&b", |
| 465 | PyMac_GetRect, &globalRect, |
| 466 | &purgeable)) |
| 467 | return NULL; |
| 468 | _err = NewScreenBuffer(&globalRect, |
| 469 | purgeable, |
| 470 | &gdh, |
| 471 | &offscreenPixMap); |
| 472 | if (_err != noErr) return PyMac_Error(_err); |
| 473 | _res = Py_BuildValue("O&O&", |
| 474 | ResObj_New, gdh, |
| 475 | ResObj_New, offscreenPixMap); |
| 476 | return _res; |
| 477 | } |
| 478 | |
| 479 | static PyObject *Qdoffs_DisposeScreenBuffer(_self, _args) |
| 480 | PyObject *_self; |
| 481 | PyObject *_args; |
| 482 | { |
| 483 | PyObject *_res = NULL; |
| 484 | PixMapHandle offscreenPixMap; |
| 485 | if (!PyArg_ParseTuple(_args, "O&", |
| 486 | ResObj_Convert, &offscreenPixMap)) |
| 487 | return NULL; |
| 488 | DisposeScreenBuffer(offscreenPixMap); |
| 489 | Py_INCREF(Py_None); |
| 490 | _res = Py_None; |
| 491 | return _res; |
| 492 | } |
| 493 | |
| 494 | static PyObject *Qdoffs_QDDone(_self, _args) |
| 495 | PyObject *_self; |
| 496 | PyObject *_args; |
| 497 | { |
| 498 | PyObject *_res = NULL; |
| 499 | Boolean _rv; |
| 500 | GrafPtr port; |
| 501 | if (!PyArg_ParseTuple(_args, "O&", |
| 502 | GrafObj_Convert, &port)) |
| 503 | return NULL; |
| 504 | _rv = QDDone(port); |
| 505 | _res = Py_BuildValue("b", |
| 506 | _rv); |
| 507 | return _res; |
| 508 | } |
| 509 | |
| 510 | static PyObject *Qdoffs_OffscreenVersion(_self, _args) |
| 511 | PyObject *_self; |
| 512 | PyObject *_args; |
| 513 | { |
| 514 | PyObject *_res = NULL; |
| 515 | long _rv; |
| 516 | if (!PyArg_ParseTuple(_args, "")) |
| 517 | return NULL; |
| 518 | _rv = OffscreenVersion(); |
| 519 | _res = Py_BuildValue("l", |
| 520 | _rv); |
| 521 | return _res; |
| 522 | } |
| 523 | |
| 524 | static PyObject *Qdoffs_NewTempScreenBuffer(_self, _args) |
| 525 | PyObject *_self; |
| 526 | PyObject *_args; |
| 527 | { |
| 528 | PyObject *_res = NULL; |
| 529 | QDErr _err; |
| 530 | Rect globalRect; |
| 531 | Boolean purgeable; |
| 532 | GDHandle gdh; |
| 533 | PixMapHandle offscreenPixMap; |
| 534 | if (!PyArg_ParseTuple(_args, "O&b", |
| 535 | PyMac_GetRect, &globalRect, |
| 536 | &purgeable)) |
| 537 | return NULL; |
| 538 | _err = NewTempScreenBuffer(&globalRect, |
| 539 | purgeable, |
| 540 | &gdh, |
| 541 | &offscreenPixMap); |
| 542 | if (_err != noErr) return PyMac_Error(_err); |
| 543 | _res = Py_BuildValue("O&O&", |
| 544 | ResObj_New, gdh, |
| 545 | ResObj_New, offscreenPixMap); |
| 546 | return _res; |
| 547 | } |
| 548 | |
| 549 | static PyObject *Qdoffs_PixMap32Bit(_self, _args) |
| 550 | PyObject *_self; |
| 551 | PyObject *_args; |
| 552 | { |
| 553 | PyObject *_res = NULL; |
| 554 | Boolean _rv; |
| 555 | PixMapHandle pmHandle; |
| 556 | if (!PyArg_ParseTuple(_args, "O&", |
| 557 | ResObj_Convert, &pmHandle)) |
| 558 | return NULL; |
| 559 | _rv = PixMap32Bit(pmHandle); |
| 560 | _res = Py_BuildValue("b", |
| 561 | _rv); |
| 562 | return _res; |
| 563 | } |
| 564 | |
Jack Jansen | 6dc8ce9 | 2000-03-03 16:03:06 +0000 | [diff] [blame^] | 565 | static PyObject *Qdoffs_GetPixMapBytes(_self, _args) |
| 566 | PyObject *_self; |
| 567 | PyObject *_args; |
| 568 | { |
| 569 | PyObject *_res = NULL; |
| 570 | |
| 571 | PixMapHandle pm; |
| 572 | int from, length; |
| 573 | char *cp; |
| 574 | |
| 575 | if ( !PyArg_ParseTuple(_args, "O&ii", ResObj_Convert, &pm, &from, &length) ) |
| 576 | return NULL; |
| 577 | cp = GetPixBaseAddr(pm)+from; |
| 578 | return PyString_FromStringAndSize(cp, length); |
| 579 | |
| 580 | } |
| 581 | |
| 582 | static PyObject *Qdoffs_PutPixMapBytes(_self, _args) |
| 583 | PyObject *_self; |
| 584 | PyObject *_args; |
| 585 | { |
| 586 | PyObject *_res = NULL; |
| 587 | |
| 588 | PixMapHandle pm; |
| 589 | int from, length; |
| 590 | char *cp, *icp; |
| 591 | |
| 592 | if ( !PyArg_ParseTuple(_args, "O&is#", ResObj_Convert, &pm, &from, &icp, &length) ) |
| 593 | return NULL; |
| 594 | cp = GetPixBaseAddr(pm)+from; |
| 595 | memcpy(cp, icp, length); |
| 596 | Py_INCREF(Py_None); |
| 597 | return Py_None; |
| 598 | |
| 599 | } |
| 600 | |
Jack Jansen | a4e6ae6 | 1999-03-07 23:11:21 +0000 | [diff] [blame] | 601 | static PyMethodDef Qdoffs_methods[] = { |
| 602 | {"NewGWorld", (PyCFunction)Qdoffs_NewGWorld, 1, |
| 603 | "(short PixelDepth, Rect boundsRect, CTabHandle cTable, GDHandle aGDevice, GWorldFlags flags) -> (GWorldPtr offscreenGWorld)"}, |
| 604 | {"LockPixels", (PyCFunction)Qdoffs_LockPixels, 1, |
| 605 | "(PixMapHandle pm) -> (Boolean _rv)"}, |
| 606 | {"UnlockPixels", (PyCFunction)Qdoffs_UnlockPixels, 1, |
| 607 | "(PixMapHandle pm) -> None"}, |
| 608 | {"UpdateGWorld", (PyCFunction)Qdoffs_UpdateGWorld, 1, |
| 609 | "(short pixelDepth, Rect boundsRect, CTabHandle cTable, GDHandle aGDevice, GWorldFlags flags) -> (GWorldFlags _rv, GWorldPtr offscreenGWorld)"}, |
| 610 | {"GetGWorld", (PyCFunction)Qdoffs_GetGWorld, 1, |
| 611 | "() -> (CGrafPtr port, GDHandle gdh)"}, |
| 612 | {"SetGWorld", (PyCFunction)Qdoffs_SetGWorld, 1, |
| 613 | "(CGrafPtr port, GDHandle gdh) -> None"}, |
| 614 | {"CTabChanged", (PyCFunction)Qdoffs_CTabChanged, 1, |
| 615 | "(CTabHandle ctab) -> None"}, |
| 616 | {"PixPatChanged", (PyCFunction)Qdoffs_PixPatChanged, 1, |
| 617 | "(PixPatHandle ppat) -> None"}, |
| 618 | {"PortChanged", (PyCFunction)Qdoffs_PortChanged, 1, |
| 619 | "(GrafPtr port) -> None"}, |
| 620 | {"GDeviceChanged", (PyCFunction)Qdoffs_GDeviceChanged, 1, |
| 621 | "(GDHandle gdh) -> None"}, |
| 622 | {"AllowPurgePixels", (PyCFunction)Qdoffs_AllowPurgePixels, 1, |
| 623 | "(PixMapHandle pm) -> None"}, |
| 624 | {"NoPurgePixels", (PyCFunction)Qdoffs_NoPurgePixels, 1, |
| 625 | "(PixMapHandle pm) -> None"}, |
| 626 | {"GetPixelsState", (PyCFunction)Qdoffs_GetPixelsState, 1, |
| 627 | "(PixMapHandle pm) -> (GWorldFlags _rv)"}, |
| 628 | {"SetPixelsState", (PyCFunction)Qdoffs_SetPixelsState, 1, |
| 629 | "(PixMapHandle pm, GWorldFlags state) -> None"}, |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 630 | {"GetPixRowBytes", (PyCFunction)Qdoffs_GetPixRowBytes, 1, |
| 631 | "(PixMapHandle pm) -> (long _rv)"}, |
Jack Jansen | a4e6ae6 | 1999-03-07 23:11:21 +0000 | [diff] [blame] | 632 | {"NewScreenBuffer", (PyCFunction)Qdoffs_NewScreenBuffer, 1, |
| 633 | "(Rect globalRect, Boolean purgeable) -> (GDHandle gdh, PixMapHandle offscreenPixMap)"}, |
| 634 | {"DisposeScreenBuffer", (PyCFunction)Qdoffs_DisposeScreenBuffer, 1, |
| 635 | "(PixMapHandle offscreenPixMap) -> None"}, |
| 636 | {"QDDone", (PyCFunction)Qdoffs_QDDone, 1, |
| 637 | "(GrafPtr port) -> (Boolean _rv)"}, |
| 638 | {"OffscreenVersion", (PyCFunction)Qdoffs_OffscreenVersion, 1, |
| 639 | "() -> (long _rv)"}, |
| 640 | {"NewTempScreenBuffer", (PyCFunction)Qdoffs_NewTempScreenBuffer, 1, |
| 641 | "(Rect globalRect, Boolean purgeable) -> (GDHandle gdh, PixMapHandle offscreenPixMap)"}, |
| 642 | {"PixMap32Bit", (PyCFunction)Qdoffs_PixMap32Bit, 1, |
| 643 | "(PixMapHandle pmHandle) -> (Boolean _rv)"}, |
Jack Jansen | 6dc8ce9 | 2000-03-03 16:03:06 +0000 | [diff] [blame^] | 644 | {"GetPixMapBytes", (PyCFunction)Qdoffs_GetPixMapBytes, 1, |
| 645 | "(pixmap, int start, int size) -> string. Return bytes from the pixmap"}, |
| 646 | {"PutPixMapBytes", (PyCFunction)Qdoffs_PutPixMapBytes, 1, |
| 647 | "(pixmap, int start, string data). Store bytes into the pixmap"}, |
Jack Jansen | a4e6ae6 | 1999-03-07 23:11:21 +0000 | [diff] [blame] | 648 | {NULL, NULL, 0} |
| 649 | }; |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | void initQdoffs() |
| 655 | { |
| 656 | PyObject *m; |
| 657 | PyObject *d; |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | m = Py_InitModule("Qdoffs", Qdoffs_methods); |
| 663 | d = PyModule_GetDict(m); |
| 664 | Qdoffs_Error = PyMac_GetOSErrException(); |
| 665 | if (Qdoffs_Error == NULL || |
| 666 | PyDict_SetItemString(d, "Error", Qdoffs_Error) != 0) |
| 667 | Py_FatalError("can't initialize Qdoffs.Error"); |
| 668 | GWorld_Type.ob_type = &PyType_Type; |
| 669 | Py_INCREF(&GWorld_Type); |
| 670 | if (PyDict_SetItemString(d, "GWorldType", (PyObject *)&GWorld_Type) != 0) |
| 671 | Py_FatalError("can't initialize GWorldType"); |
| 672 | } |
| 673 | |
| 674 | /* ======================= End module Qdoffs ======================== */ |
| 675 | |