2 /* ========================= Module _Qdoffs ========================= */
9 #include "pywintoolbox.h"
12 #include "pymactoolbox.h"
15 /* Macro to test whether a weak-loaded CFM function exists */
16 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
17 PyErr_SetString(PyExc_NotImplementedError, \
18 "Not available in this shared library/OS version"); \
23 #ifdef WITHOUT_FRAMEWORKS
24 #include <QDOffscreen.h>
26 #include <Carbon/Carbon.h>
29 #ifdef USE_TOOLBOX_OBJECT_GLUE
30 extern PyObject
*_GWorldObj_New(GWorldPtr
);
31 extern int _GWorldObj_Convert(PyObject
*, GWorldPtr
*);
33 #define GWorldObj_New _GWorldObj_New
34 #define GWorldObj_Convert _GWorldObj_Convert
37 #define as_GrafPtr(gworld) ((GrafPtr)(gworld))
40 static PyObject
*Qdoffs_Error
;
42 /* ----------------------- Object type GWorld ----------------------- */
44 PyTypeObject GWorld_Type
;
46 #define GWorldObj_Check(x) ((x)->ob_type == &GWorld_Type || PyObject_TypeCheck((x), &GWorld_Type))
48 typedef struct GWorldObject
{
53 PyObject
*GWorldObj_New(GWorldPtr itself
)
56 if (itself
== NULL
) return PyMac_Error(resNotFound
);
57 it
= PyObject_NEW(GWorldObject
, &GWorld_Type
);
58 if (it
== NULL
) return NULL
;
59 it
->ob_itself
= itself
;
60 return (PyObject
*)it
;
62 int GWorldObj_Convert(PyObject
*v
, GWorldPtr
*p_itself
)
64 if (!GWorldObj_Check(v
))
66 PyErr_SetString(PyExc_TypeError
, "GWorld required");
69 *p_itself
= ((GWorldObject
*)v
)->ob_itself
;
73 static void GWorldObj_dealloc(GWorldObject
*self
)
75 DisposeGWorld(self
->ob_itself
);
76 self
->ob_type
->tp_free((PyObject
*)self
);
79 static PyObject
*GWorldObj_GetGWorldDevice(GWorldObject
*_self
, PyObject
*_args
)
81 PyObject
*_res
= NULL
;
83 #ifndef GetGWorldDevice
84 PyMac_PRECHECK(GetGWorldDevice
);
86 if (!PyArg_ParseTuple(_args
, ""))
88 _rv
= GetGWorldDevice(_self
->ob_itself
);
89 _res
= Py_BuildValue("O&",
94 static PyObject
*GWorldObj_GetGWorldPixMap(GWorldObject
*_self
, PyObject
*_args
)
96 PyObject
*_res
= NULL
;
98 #ifndef GetGWorldPixMap
99 PyMac_PRECHECK(GetGWorldPixMap
);
101 if (!PyArg_ParseTuple(_args
, ""))
103 _rv
= GetGWorldPixMap(_self
->ob_itself
);
104 _res
= Py_BuildValue("O&",
109 static PyObject
*GWorldObj_as_GrafPtr(GWorldObject
*_self
, PyObject
*_args
)
111 PyObject
*_res
= NULL
;
114 PyMac_PRECHECK(as_GrafPtr
);
116 if (!PyArg_ParseTuple(_args
, ""))
118 _rv
= as_GrafPtr(_self
->ob_itself
);
119 _res
= Py_BuildValue("O&",
124 static PyMethodDef GWorldObj_methods
[] = {
125 {"GetGWorldDevice", (PyCFunction
)GWorldObj_GetGWorldDevice
, 1,
126 PyDoc_STR("() -> (GDHandle _rv)")},
127 {"GetGWorldPixMap", (PyCFunction
)GWorldObj_GetGWorldPixMap
, 1,
128 PyDoc_STR("() -> (PixMapHandle _rv)")},
129 {"as_GrafPtr", (PyCFunction
)GWorldObj_as_GrafPtr
, 1,
130 PyDoc_STR("() -> (GrafPtr _rv)")},
134 #define GWorldObj_getsetlist NULL
137 #define GWorldObj_compare NULL
139 #define GWorldObj_repr NULL
141 #define GWorldObj_hash NULL
142 #define GWorldObj_tp_init 0
144 #define GWorldObj_tp_alloc PyType_GenericAlloc
146 static PyObject
*GWorldObj_tp_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
)
150 char *kw
[] = {"itself", 0};
152 if (!PyArg_ParseTupleAndKeywords(args
, kwds
, "O&", kw
, GWorldObj_Convert
, &itself
)) return NULL
;
153 if ((self
= type
->tp_alloc(type
, 0)) == NULL
) return NULL
;
154 ((GWorldObject
*)self
)->ob_itself
= itself
;
158 #define GWorldObj_tp_free PyObject_Del
161 PyTypeObject GWorld_Type
= {
162 PyObject_HEAD_INIT(NULL
)
164 "_Qdoffs.GWorld", /*tp_name*/
165 sizeof(GWorldObject
), /*tp_basicsize*/
168 (destructor
) GWorldObj_dealloc
, /*tp_dealloc*/
170 (getattrfunc
)0, /*tp_getattr*/
171 (setattrfunc
)0, /*tp_setattr*/
172 (cmpfunc
) GWorldObj_compare
, /*tp_compare*/
173 (reprfunc
) GWorldObj_repr
, /*tp_repr*/
174 (PyNumberMethods
*)0, /* tp_as_number */
175 (PySequenceMethods
*)0, /* tp_as_sequence */
176 (PyMappingMethods
*)0, /* tp_as_mapping */
177 (hashfunc
) GWorldObj_hash
, /*tp_hash*/
180 PyObject_GenericGetAttr
, /*tp_getattro*/
181 PyObject_GenericSetAttr
, /*tp_setattro */
183 Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
, /* tp_flags */
187 0, /*tp_richcompare*/
188 0, /*tp_weaklistoffset*/
191 GWorldObj_methods
, /* tp_methods */
193 GWorldObj_getsetlist
, /*tp_getset*/
199 GWorldObj_tp_init
, /* tp_init */
200 GWorldObj_tp_alloc
, /* tp_alloc */
201 GWorldObj_tp_new
, /* tp_new */
202 GWorldObj_tp_free
, /* tp_free */
205 /* --------------------- End object type GWorld --------------------- */
208 static PyObject
*Qdoffs_NewGWorld(PyObject
*_self
, PyObject
*_args
)
210 PyObject
*_res
= NULL
;
212 GWorldPtr offscreenGWorld
;
219 PyMac_PRECHECK(NewGWorld
);
221 if (!PyArg_ParseTuple(_args
, "hO&O&O&l",
223 PyMac_GetRect
, &boundsRect
,
224 OptResObj_Convert
, &cTable
,
225 OptResObj_Convert
, &aGDevice
,
228 _err
= NewGWorld(&offscreenGWorld
,
234 if (_err
!= noErr
) return PyMac_Error(_err
);
235 _res
= Py_BuildValue("O&",
236 GWorldObj_New
, offscreenGWorld
);
240 static PyObject
*Qdoffs_LockPixels(PyObject
*_self
, PyObject
*_args
)
242 PyObject
*_res
= NULL
;
246 PyMac_PRECHECK(LockPixels
);
248 if (!PyArg_ParseTuple(_args
, "O&",
249 ResObj_Convert
, &pm
))
251 _rv
= LockPixels(pm
);
252 _res
= Py_BuildValue("b",
257 static PyObject
*Qdoffs_UnlockPixels(PyObject
*_self
, PyObject
*_args
)
259 PyObject
*_res
= NULL
;
262 PyMac_PRECHECK(UnlockPixels
);
264 if (!PyArg_ParseTuple(_args
, "O&",
265 ResObj_Convert
, &pm
))
273 static PyObject
*Qdoffs_UpdateGWorld(PyObject
*_self
, PyObject
*_args
)
275 PyObject
*_res
= NULL
;
277 GWorldPtr offscreenGWorld
;
284 PyMac_PRECHECK(UpdateGWorld
);
286 if (!PyArg_ParseTuple(_args
, "hO&O&O&l",
288 PyMac_GetRect
, &boundsRect
,
289 OptResObj_Convert
, &cTable
,
290 OptResObj_Convert
, &aGDevice
,
293 _rv
= UpdateGWorld(&offscreenGWorld
,
299 _res
= Py_BuildValue("lO&",
301 GWorldObj_New
, offscreenGWorld
);
305 static PyObject
*Qdoffs_GetGWorld(PyObject
*_self
, PyObject
*_args
)
307 PyObject
*_res
= NULL
;
311 PyMac_PRECHECK(GetGWorld
);
313 if (!PyArg_ParseTuple(_args
, ""))
317 _res
= Py_BuildValue("O&O&",
323 static PyObject
*Qdoffs_SetGWorld(PyObject
*_self
, PyObject
*_args
)
325 PyObject
*_res
= NULL
;
329 PyMac_PRECHECK(SetGWorld
);
331 if (!PyArg_ParseTuple(_args
, "O&O&",
332 GrafObj_Convert
, &port
,
333 OptResObj_Convert
, &gdh
))
342 static PyObject
*Qdoffs_CTabChanged(PyObject
*_self
, PyObject
*_args
)
344 PyObject
*_res
= NULL
;
347 PyMac_PRECHECK(CTabChanged
);
349 if (!PyArg_ParseTuple(_args
, "O&",
350 OptResObj_Convert
, &ctab
))
358 static PyObject
*Qdoffs_PixPatChanged(PyObject
*_self
, PyObject
*_args
)
360 PyObject
*_res
= NULL
;
362 #ifndef PixPatChanged
363 PyMac_PRECHECK(PixPatChanged
);
365 if (!PyArg_ParseTuple(_args
, "O&",
366 ResObj_Convert
, &ppat
))
374 static PyObject
*Qdoffs_PortChanged(PyObject
*_self
, PyObject
*_args
)
376 PyObject
*_res
= NULL
;
379 PyMac_PRECHECK(PortChanged
);
381 if (!PyArg_ParseTuple(_args
, "O&",
382 GrafObj_Convert
, &port
))
390 static PyObject
*Qdoffs_GDeviceChanged(PyObject
*_self
, PyObject
*_args
)
392 PyObject
*_res
= NULL
;
394 #ifndef GDeviceChanged
395 PyMac_PRECHECK(GDeviceChanged
);
397 if (!PyArg_ParseTuple(_args
, "O&",
398 OptResObj_Convert
, &gdh
))
406 static PyObject
*Qdoffs_AllowPurgePixels(PyObject
*_self
, PyObject
*_args
)
408 PyObject
*_res
= NULL
;
410 #ifndef AllowPurgePixels
411 PyMac_PRECHECK(AllowPurgePixels
);
413 if (!PyArg_ParseTuple(_args
, "O&",
414 ResObj_Convert
, &pm
))
416 AllowPurgePixels(pm
);
422 static PyObject
*Qdoffs_NoPurgePixels(PyObject
*_self
, PyObject
*_args
)
424 PyObject
*_res
= NULL
;
426 #ifndef NoPurgePixels
427 PyMac_PRECHECK(NoPurgePixels
);
429 if (!PyArg_ParseTuple(_args
, "O&",
430 ResObj_Convert
, &pm
))
438 static PyObject
*Qdoffs_GetPixelsState(PyObject
*_self
, PyObject
*_args
)
440 PyObject
*_res
= NULL
;
443 #ifndef GetPixelsState
444 PyMac_PRECHECK(GetPixelsState
);
446 if (!PyArg_ParseTuple(_args
, "O&",
447 ResObj_Convert
, &pm
))
449 _rv
= GetPixelsState(pm
);
450 _res
= Py_BuildValue("l",
455 static PyObject
*Qdoffs_SetPixelsState(PyObject
*_self
, PyObject
*_args
)
457 PyObject
*_res
= NULL
;
460 #ifndef SetPixelsState
461 PyMac_PRECHECK(SetPixelsState
);
463 if (!PyArg_ParseTuple(_args
, "O&l",
474 static PyObject
*Qdoffs_GetPixRowBytes(PyObject
*_self
, PyObject
*_args
)
476 PyObject
*_res
= NULL
;
479 #ifndef GetPixRowBytes
480 PyMac_PRECHECK(GetPixRowBytes
);
482 if (!PyArg_ParseTuple(_args
, "O&",
483 ResObj_Convert
, &pm
))
485 _rv
= GetPixRowBytes(pm
);
486 _res
= Py_BuildValue("l",
491 static PyObject
*Qdoffs_NewScreenBuffer(PyObject
*_self
, PyObject
*_args
)
493 PyObject
*_res
= NULL
;
498 PixMapHandle offscreenPixMap
;
499 #ifndef NewScreenBuffer
500 PyMac_PRECHECK(NewScreenBuffer
);
502 if (!PyArg_ParseTuple(_args
, "O&b",
503 PyMac_GetRect
, &globalRect
,
506 _err
= NewScreenBuffer(&globalRect
,
510 if (_err
!= noErr
) return PyMac_Error(_err
);
511 _res
= Py_BuildValue("O&O&",
513 ResObj_New
, offscreenPixMap
);
517 static PyObject
*Qdoffs_DisposeScreenBuffer(PyObject
*_self
, PyObject
*_args
)
519 PyObject
*_res
= NULL
;
520 PixMapHandle offscreenPixMap
;
521 #ifndef DisposeScreenBuffer
522 PyMac_PRECHECK(DisposeScreenBuffer
);
524 if (!PyArg_ParseTuple(_args
, "O&",
525 ResObj_Convert
, &offscreenPixMap
))
527 DisposeScreenBuffer(offscreenPixMap
);
533 static PyObject
*Qdoffs_QDDone(PyObject
*_self
, PyObject
*_args
)
535 PyObject
*_res
= NULL
;
539 PyMac_PRECHECK(QDDone
);
541 if (!PyArg_ParseTuple(_args
, "O&",
542 GrafObj_Convert
, &port
))
545 _res
= Py_BuildValue("b",
550 static PyObject
*Qdoffs_OffscreenVersion(PyObject
*_self
, PyObject
*_args
)
552 PyObject
*_res
= NULL
;
554 #ifndef OffscreenVersion
555 PyMac_PRECHECK(OffscreenVersion
);
557 if (!PyArg_ParseTuple(_args
, ""))
559 _rv
= OffscreenVersion();
560 _res
= Py_BuildValue("l",
565 static PyObject
*Qdoffs_NewTempScreenBuffer(PyObject
*_self
, PyObject
*_args
)
567 PyObject
*_res
= NULL
;
572 PixMapHandle offscreenPixMap
;
573 #ifndef NewTempScreenBuffer
574 PyMac_PRECHECK(NewTempScreenBuffer
);
576 if (!PyArg_ParseTuple(_args
, "O&b",
577 PyMac_GetRect
, &globalRect
,
580 _err
= NewTempScreenBuffer(&globalRect
,
584 if (_err
!= noErr
) return PyMac_Error(_err
);
585 _res
= Py_BuildValue("O&O&",
587 ResObj_New
, offscreenPixMap
);
591 static PyObject
*Qdoffs_PixMap32Bit(PyObject
*_self
, PyObject
*_args
)
593 PyObject
*_res
= NULL
;
595 PixMapHandle pmHandle
;
597 PyMac_PRECHECK(PixMap32Bit
);
599 if (!PyArg_ParseTuple(_args
, "O&",
600 ResObj_Convert
, &pmHandle
))
602 _rv
= PixMap32Bit(pmHandle
);
603 _res
= Py_BuildValue("b",
608 static PyObject
*Qdoffs_GetPixMapBytes(PyObject
*_self
, PyObject
*_args
)
610 PyObject
*_res
= NULL
;
616 if ( !PyArg_ParseTuple(_args
, "O&ii", ResObj_Convert
, &pm
, &from
, &length
) )
618 cp
= GetPixBaseAddr(pm
)+from
;
619 _res
= PyString_FromStringAndSize(cp
, length
);
624 static PyObject
*Qdoffs_PutPixMapBytes(PyObject
*_self
, PyObject
*_args
)
626 PyObject
*_res
= NULL
;
632 if ( !PyArg_ParseTuple(_args
, "O&is#", ResObj_Convert
, &pm
, &from
, &icp
, &length
) )
634 cp
= GetPixBaseAddr(pm
)+from
;
635 memcpy(cp
, icp
, length
);
642 static PyMethodDef Qdoffs_methods
[] = {
643 {"NewGWorld", (PyCFunction
)Qdoffs_NewGWorld
, 1,
644 PyDoc_STR("(short PixelDepth, Rect boundsRect, CTabHandle cTable, GDHandle aGDevice, GWorldFlags flags) -> (GWorldPtr offscreenGWorld)")},
645 {"LockPixels", (PyCFunction
)Qdoffs_LockPixels
, 1,
646 PyDoc_STR("(PixMapHandle pm) -> (Boolean _rv)")},
647 {"UnlockPixels", (PyCFunction
)Qdoffs_UnlockPixels
, 1,
648 PyDoc_STR("(PixMapHandle pm) -> None")},
649 {"UpdateGWorld", (PyCFunction
)Qdoffs_UpdateGWorld
, 1,
650 PyDoc_STR("(short pixelDepth, Rect boundsRect, CTabHandle cTable, GDHandle aGDevice, GWorldFlags flags) -> (GWorldFlags _rv, GWorldPtr offscreenGWorld)")},
651 {"GetGWorld", (PyCFunction
)Qdoffs_GetGWorld
, 1,
652 PyDoc_STR("() -> (CGrafPtr port, GDHandle gdh)")},
653 {"SetGWorld", (PyCFunction
)Qdoffs_SetGWorld
, 1,
654 PyDoc_STR("(CGrafPtr port, GDHandle gdh) -> None")},
655 {"CTabChanged", (PyCFunction
)Qdoffs_CTabChanged
, 1,
656 PyDoc_STR("(CTabHandle ctab) -> None")},
657 {"PixPatChanged", (PyCFunction
)Qdoffs_PixPatChanged
, 1,
658 PyDoc_STR("(PixPatHandle ppat) -> None")},
659 {"PortChanged", (PyCFunction
)Qdoffs_PortChanged
, 1,
660 PyDoc_STR("(GrafPtr port) -> None")},
661 {"GDeviceChanged", (PyCFunction
)Qdoffs_GDeviceChanged
, 1,
662 PyDoc_STR("(GDHandle gdh) -> None")},
663 {"AllowPurgePixels", (PyCFunction
)Qdoffs_AllowPurgePixels
, 1,
664 PyDoc_STR("(PixMapHandle pm) -> None")},
665 {"NoPurgePixels", (PyCFunction
)Qdoffs_NoPurgePixels
, 1,
666 PyDoc_STR("(PixMapHandle pm) -> None")},
667 {"GetPixelsState", (PyCFunction
)Qdoffs_GetPixelsState
, 1,
668 PyDoc_STR("(PixMapHandle pm) -> (GWorldFlags _rv)")},
669 {"SetPixelsState", (PyCFunction
)Qdoffs_SetPixelsState
, 1,
670 PyDoc_STR("(PixMapHandle pm, GWorldFlags state) -> None")},
671 {"GetPixRowBytes", (PyCFunction
)Qdoffs_GetPixRowBytes
, 1,
672 PyDoc_STR("(PixMapHandle pm) -> (long _rv)")},
673 {"NewScreenBuffer", (PyCFunction
)Qdoffs_NewScreenBuffer
, 1,
674 PyDoc_STR("(Rect globalRect, Boolean purgeable) -> (GDHandle gdh, PixMapHandle offscreenPixMap)")},
675 {"DisposeScreenBuffer", (PyCFunction
)Qdoffs_DisposeScreenBuffer
, 1,
676 PyDoc_STR("(PixMapHandle offscreenPixMap) -> None")},
677 {"QDDone", (PyCFunction
)Qdoffs_QDDone
, 1,
678 PyDoc_STR("(GrafPtr port) -> (Boolean _rv)")},
679 {"OffscreenVersion", (PyCFunction
)Qdoffs_OffscreenVersion
, 1,
680 PyDoc_STR("() -> (long _rv)")},
681 {"NewTempScreenBuffer", (PyCFunction
)Qdoffs_NewTempScreenBuffer
, 1,
682 PyDoc_STR("(Rect globalRect, Boolean purgeable) -> (GDHandle gdh, PixMapHandle offscreenPixMap)")},
683 {"PixMap32Bit", (PyCFunction
)Qdoffs_PixMap32Bit
, 1,
684 PyDoc_STR("(PixMapHandle pmHandle) -> (Boolean _rv)")},
685 {"GetPixMapBytes", (PyCFunction
)Qdoffs_GetPixMapBytes
, 1,
686 PyDoc_STR("(pixmap, int start, int size) -> string. Return bytes from the pixmap")},
687 {"PutPixMapBytes", (PyCFunction
)Qdoffs_PutPixMapBytes
, 1,
688 PyDoc_STR("(pixmap, int start, string data). Store bytes into the pixmap")},
695 void init_Qdoffs(void)
702 PyMac_INIT_TOOLBOX_OBJECT_NEW(GWorldPtr
, GWorldObj_New
);
703 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(GWorldPtr
, GWorldObj_Convert
);
706 m
= Py_InitModule("_Qdoffs", Qdoffs_methods
);
707 d
= PyModule_GetDict(m
);
708 Qdoffs_Error
= PyMac_GetOSErrException();
709 if (Qdoffs_Error
== NULL
||
710 PyDict_SetItemString(d
, "Error", Qdoffs_Error
) != 0)
712 GWorld_Type
.ob_type
= &PyType_Type
;
713 if (PyType_Ready(&GWorld_Type
) < 0) return;
714 Py_INCREF(&GWorld_Type
);
715 PyModule_AddObject(m
, "GWorld", (PyObject
*)&GWorld_Type
);
716 /* Backward-compatible name */
717 Py_INCREF(&GWorld_Type
);
718 PyModule_AddObject(m
, "GWorldType", (PyObject
*)&GWorld_Type
);
721 /* ======================= End module _Qdoffs ======================= */