2 /* ========================= Module Qdoffs ========================== */
9 #include "pymactoolbox.h"
11 #ifdef WITHOUT_FRAMEWORKS
12 #include <QDOffscreen.h>
14 #include <Carbon/Carbon.h>
17 #ifdef USE_TOOLBOX_OBJECT_GLUE
18 extern PyObject
*_GWorldObj_New(GWorldPtr
);
19 extern int _GWorldObj_Convert(PyObject
*, GWorldPtr
*);
21 #define GWorldObj_New _GWorldObj_New
22 #define GWorldObj_Convert _GWorldObj_Convert
25 #define as_GrafPtr(gworld) ((GrafPtr)(gworld))
28 static PyObject
*Qdoffs_Error
;
30 /* ----------------------- Object type GWorld ----------------------- */
32 PyTypeObject GWorld_Type
;
34 #define GWorldObj_Check(x) ((x)->ob_type == &GWorld_Type)
36 typedef struct GWorldObject
{
41 PyObject
*GWorldObj_New(GWorldPtr itself
)
44 if (itself
== NULL
) return PyMac_Error(resNotFound
);
45 it
= PyObject_NEW(GWorldObject
, &GWorld_Type
);
46 if (it
== NULL
) return NULL
;
47 it
->ob_itself
= itself
;
48 return (PyObject
*)it
;
50 GWorldObj_Convert(PyObject
*v
, GWorldPtr
*p_itself
)
52 if (!GWorldObj_Check(v
))
54 PyErr_SetString(PyExc_TypeError
, "GWorld required");
57 *p_itself
= ((GWorldObject
*)v
)->ob_itself
;
61 static void GWorldObj_dealloc(GWorldObject
*self
)
63 DisposeGWorld(self
->ob_itself
);
67 static PyObject
*GWorldObj_GetGWorldDevice(GWorldObject
*_self
, PyObject
*_args
)
69 PyObject
*_res
= NULL
;
71 if (!PyArg_ParseTuple(_args
, ""))
73 _rv
= GetGWorldDevice(_self
->ob_itself
);
74 _res
= Py_BuildValue("O&",
79 static PyObject
*GWorldObj_GetGWorldPixMap(GWorldObject
*_self
, PyObject
*_args
)
81 PyObject
*_res
= NULL
;
83 if (!PyArg_ParseTuple(_args
, ""))
85 _rv
= GetGWorldPixMap(_self
->ob_itself
);
86 _res
= Py_BuildValue("O&",
91 static PyObject
*GWorldObj_as_GrafPtr(GWorldObject
*_self
, PyObject
*_args
)
93 PyObject
*_res
= NULL
;
95 if (!PyArg_ParseTuple(_args
, ""))
97 _rv
= as_GrafPtr(_self
->ob_itself
);
98 _res
= Py_BuildValue("O&",
103 static PyMethodDef GWorldObj_methods
[] = {
104 {"GetGWorldDevice", (PyCFunction
)GWorldObj_GetGWorldDevice
, 1,
105 "() -> (GDHandle _rv)"},
106 {"GetGWorldPixMap", (PyCFunction
)GWorldObj_GetGWorldPixMap
, 1,
107 "() -> (PixMapHandle _rv)"},
108 {"as_GrafPtr", (PyCFunction
)GWorldObj_as_GrafPtr
, 1,
109 "() -> (GrafPtr _rv)"},
113 PyMethodChain GWorldObj_chain
= { GWorldObj_methods
, NULL
};
115 static PyObject
*GWorldObj_getattr(GWorldObject
*self
, char *name
)
117 return Py_FindMethodInChain(&GWorldObj_chain
, (PyObject
*)self
, name
);
120 #define GWorldObj_setattr NULL
122 #define GWorldObj_compare NULL
124 #define GWorldObj_repr NULL
126 #define GWorldObj_hash NULL
128 PyTypeObject GWorld_Type
= {
129 PyObject_HEAD_INIT(&PyType_Type
)
131 "GWorld", /*tp_name*/
132 sizeof(GWorldObject
), /*tp_basicsize*/
135 (destructor
) GWorldObj_dealloc
, /*tp_dealloc*/
137 (getattrfunc
) GWorldObj_getattr
, /*tp_getattr*/
138 (setattrfunc
) GWorldObj_setattr
, /*tp_setattr*/
139 (cmpfunc
) GWorldObj_compare
, /*tp_compare*/
140 (reprfunc
) GWorldObj_repr
, /*tp_repr*/
141 (PyNumberMethods
*)0, /* tp_as_number */
142 (PySequenceMethods
*)0, /* tp_as_sequence */
143 (PyMappingMethods
*)0, /* tp_as_mapping */
144 (hashfunc
) GWorldObj_hash
, /*tp_hash*/
147 /* --------------------- End object type GWorld --------------------- */
150 static PyObject
*Qdoffs_NewGWorld(PyObject
*_self
, PyObject
*_args
)
152 PyObject
*_res
= NULL
;
154 GWorldPtr offscreenGWorld
;
160 if (!PyArg_ParseTuple(_args
, "hO&O&O&l",
162 PyMac_GetRect
, &boundsRect
,
163 OptResObj_Convert
, &cTable
,
164 OptResObj_Convert
, &aGDevice
,
167 _err
= NewGWorld(&offscreenGWorld
,
173 if (_err
!= noErr
) return PyMac_Error(_err
);
174 _res
= Py_BuildValue("O&",
175 GWorldObj_New
, offscreenGWorld
);
179 static PyObject
*Qdoffs_LockPixels(PyObject
*_self
, PyObject
*_args
)
181 PyObject
*_res
= NULL
;
184 if (!PyArg_ParseTuple(_args
, "O&",
185 ResObj_Convert
, &pm
))
187 _rv
= LockPixels(pm
);
188 _res
= Py_BuildValue("b",
193 static PyObject
*Qdoffs_UnlockPixels(PyObject
*_self
, PyObject
*_args
)
195 PyObject
*_res
= NULL
;
197 if (!PyArg_ParseTuple(_args
, "O&",
198 ResObj_Convert
, &pm
))
206 static PyObject
*Qdoffs_UpdateGWorld(PyObject
*_self
, PyObject
*_args
)
208 PyObject
*_res
= NULL
;
210 GWorldPtr offscreenGWorld
;
216 if (!PyArg_ParseTuple(_args
, "hO&O&O&l",
218 PyMac_GetRect
, &boundsRect
,
219 OptResObj_Convert
, &cTable
,
220 OptResObj_Convert
, &aGDevice
,
223 _rv
= UpdateGWorld(&offscreenGWorld
,
229 _res
= Py_BuildValue("lO&",
231 GWorldObj_New
, offscreenGWorld
);
235 static PyObject
*Qdoffs_GetGWorld(PyObject
*_self
, PyObject
*_args
)
237 PyObject
*_res
= NULL
;
240 if (!PyArg_ParseTuple(_args
, ""))
244 _res
= Py_BuildValue("O&O&",
250 static PyObject
*Qdoffs_SetGWorld(PyObject
*_self
, PyObject
*_args
)
252 PyObject
*_res
= NULL
;
255 if (!PyArg_ParseTuple(_args
, "O&O&",
256 GrafObj_Convert
, &port
,
257 OptResObj_Convert
, &gdh
))
266 static PyObject
*Qdoffs_CTabChanged(PyObject
*_self
, PyObject
*_args
)
268 PyObject
*_res
= NULL
;
270 if (!PyArg_ParseTuple(_args
, "O&",
271 OptResObj_Convert
, &ctab
))
279 static PyObject
*Qdoffs_PixPatChanged(PyObject
*_self
, PyObject
*_args
)
281 PyObject
*_res
= NULL
;
283 if (!PyArg_ParseTuple(_args
, "O&",
284 ResObj_Convert
, &ppat
))
292 static PyObject
*Qdoffs_PortChanged(PyObject
*_self
, PyObject
*_args
)
294 PyObject
*_res
= NULL
;
296 if (!PyArg_ParseTuple(_args
, "O&",
297 GrafObj_Convert
, &port
))
305 static PyObject
*Qdoffs_GDeviceChanged(PyObject
*_self
, PyObject
*_args
)
307 PyObject
*_res
= NULL
;
309 if (!PyArg_ParseTuple(_args
, "O&",
310 OptResObj_Convert
, &gdh
))
318 static PyObject
*Qdoffs_AllowPurgePixels(PyObject
*_self
, PyObject
*_args
)
320 PyObject
*_res
= NULL
;
322 if (!PyArg_ParseTuple(_args
, "O&",
323 ResObj_Convert
, &pm
))
325 AllowPurgePixels(pm
);
331 static PyObject
*Qdoffs_NoPurgePixels(PyObject
*_self
, PyObject
*_args
)
333 PyObject
*_res
= NULL
;
335 if (!PyArg_ParseTuple(_args
, "O&",
336 ResObj_Convert
, &pm
))
344 static PyObject
*Qdoffs_GetPixelsState(PyObject
*_self
, PyObject
*_args
)
346 PyObject
*_res
= NULL
;
349 if (!PyArg_ParseTuple(_args
, "O&",
350 ResObj_Convert
, &pm
))
352 _rv
= GetPixelsState(pm
);
353 _res
= Py_BuildValue("l",
358 static PyObject
*Qdoffs_SetPixelsState(PyObject
*_self
, PyObject
*_args
)
360 PyObject
*_res
= NULL
;
363 if (!PyArg_ParseTuple(_args
, "O&l",
374 static PyObject
*Qdoffs_GetPixRowBytes(PyObject
*_self
, PyObject
*_args
)
376 PyObject
*_res
= NULL
;
379 if (!PyArg_ParseTuple(_args
, "O&",
380 ResObj_Convert
, &pm
))
382 _rv
= GetPixRowBytes(pm
);
383 _res
= Py_BuildValue("l",
388 static PyObject
*Qdoffs_NewScreenBuffer(PyObject
*_self
, PyObject
*_args
)
390 PyObject
*_res
= NULL
;
395 PixMapHandle offscreenPixMap
;
396 if (!PyArg_ParseTuple(_args
, "O&b",
397 PyMac_GetRect
, &globalRect
,
400 _err
= NewScreenBuffer(&globalRect
,
404 if (_err
!= noErr
) return PyMac_Error(_err
);
405 _res
= Py_BuildValue("O&O&",
407 ResObj_New
, offscreenPixMap
);
411 static PyObject
*Qdoffs_DisposeScreenBuffer(PyObject
*_self
, PyObject
*_args
)
413 PyObject
*_res
= NULL
;
414 PixMapHandle offscreenPixMap
;
415 if (!PyArg_ParseTuple(_args
, "O&",
416 ResObj_Convert
, &offscreenPixMap
))
418 DisposeScreenBuffer(offscreenPixMap
);
424 static PyObject
*Qdoffs_QDDone(PyObject
*_self
, PyObject
*_args
)
426 PyObject
*_res
= NULL
;
429 if (!PyArg_ParseTuple(_args
, "O&",
430 GrafObj_Convert
, &port
))
433 _res
= Py_BuildValue("b",
438 static PyObject
*Qdoffs_OffscreenVersion(PyObject
*_self
, PyObject
*_args
)
440 PyObject
*_res
= NULL
;
442 if (!PyArg_ParseTuple(_args
, ""))
444 _rv
= OffscreenVersion();
445 _res
= Py_BuildValue("l",
450 static PyObject
*Qdoffs_NewTempScreenBuffer(PyObject
*_self
, PyObject
*_args
)
452 PyObject
*_res
= NULL
;
457 PixMapHandle offscreenPixMap
;
458 if (!PyArg_ParseTuple(_args
, "O&b",
459 PyMac_GetRect
, &globalRect
,
462 _err
= NewTempScreenBuffer(&globalRect
,
466 if (_err
!= noErr
) return PyMac_Error(_err
);
467 _res
= Py_BuildValue("O&O&",
469 ResObj_New
, offscreenPixMap
);
473 static PyObject
*Qdoffs_PixMap32Bit(PyObject
*_self
, PyObject
*_args
)
475 PyObject
*_res
= NULL
;
477 PixMapHandle pmHandle
;
478 if (!PyArg_ParseTuple(_args
, "O&",
479 ResObj_Convert
, &pmHandle
))
481 _rv
= PixMap32Bit(pmHandle
);
482 _res
= Py_BuildValue("b",
487 static PyObject
*Qdoffs_GetPixMapBytes(PyObject
*_self
, PyObject
*_args
)
489 PyObject
*_res
= NULL
;
495 if ( !PyArg_ParseTuple(_args
, "O&ii", ResObj_Convert
, &pm
, &from
, &length
) )
497 cp
= GetPixBaseAddr(pm
)+from
;
498 return PyString_FromStringAndSize(cp
, length
);
502 static PyObject
*Qdoffs_PutPixMapBytes(PyObject
*_self
, PyObject
*_args
)
504 PyObject
*_res
= NULL
;
510 if ( !PyArg_ParseTuple(_args
, "O&is#", ResObj_Convert
, &pm
, &from
, &icp
, &length
) )
512 cp
= GetPixBaseAddr(pm
)+from
;
513 memcpy(cp
, icp
, length
);
519 static PyMethodDef Qdoffs_methods
[] = {
520 {"NewGWorld", (PyCFunction
)Qdoffs_NewGWorld
, 1,
521 "(short PixelDepth, Rect boundsRect, CTabHandle cTable, GDHandle aGDevice, GWorldFlags flags) -> (GWorldPtr offscreenGWorld)"},
522 {"LockPixels", (PyCFunction
)Qdoffs_LockPixels
, 1,
523 "(PixMapHandle pm) -> (Boolean _rv)"},
524 {"UnlockPixels", (PyCFunction
)Qdoffs_UnlockPixels
, 1,
525 "(PixMapHandle pm) -> None"},
526 {"UpdateGWorld", (PyCFunction
)Qdoffs_UpdateGWorld
, 1,
527 "(short pixelDepth, Rect boundsRect, CTabHandle cTable, GDHandle aGDevice, GWorldFlags flags) -> (GWorldFlags _rv, GWorldPtr offscreenGWorld)"},
528 {"GetGWorld", (PyCFunction
)Qdoffs_GetGWorld
, 1,
529 "() -> (CGrafPtr port, GDHandle gdh)"},
530 {"SetGWorld", (PyCFunction
)Qdoffs_SetGWorld
, 1,
531 "(CGrafPtr port, GDHandle gdh) -> None"},
532 {"CTabChanged", (PyCFunction
)Qdoffs_CTabChanged
, 1,
533 "(CTabHandle ctab) -> None"},
534 {"PixPatChanged", (PyCFunction
)Qdoffs_PixPatChanged
, 1,
535 "(PixPatHandle ppat) -> None"},
536 {"PortChanged", (PyCFunction
)Qdoffs_PortChanged
, 1,
537 "(GrafPtr port) -> None"},
538 {"GDeviceChanged", (PyCFunction
)Qdoffs_GDeviceChanged
, 1,
539 "(GDHandle gdh) -> None"},
540 {"AllowPurgePixels", (PyCFunction
)Qdoffs_AllowPurgePixels
, 1,
541 "(PixMapHandle pm) -> None"},
542 {"NoPurgePixels", (PyCFunction
)Qdoffs_NoPurgePixels
, 1,
543 "(PixMapHandle pm) -> None"},
544 {"GetPixelsState", (PyCFunction
)Qdoffs_GetPixelsState
, 1,
545 "(PixMapHandle pm) -> (GWorldFlags _rv)"},
546 {"SetPixelsState", (PyCFunction
)Qdoffs_SetPixelsState
, 1,
547 "(PixMapHandle pm, GWorldFlags state) -> None"},
548 {"GetPixRowBytes", (PyCFunction
)Qdoffs_GetPixRowBytes
, 1,
549 "(PixMapHandle pm) -> (long _rv)"},
550 {"NewScreenBuffer", (PyCFunction
)Qdoffs_NewScreenBuffer
, 1,
551 "(Rect globalRect, Boolean purgeable) -> (GDHandle gdh, PixMapHandle offscreenPixMap)"},
552 {"DisposeScreenBuffer", (PyCFunction
)Qdoffs_DisposeScreenBuffer
, 1,
553 "(PixMapHandle offscreenPixMap) -> None"},
554 {"QDDone", (PyCFunction
)Qdoffs_QDDone
, 1,
555 "(GrafPtr port) -> (Boolean _rv)"},
556 {"OffscreenVersion", (PyCFunction
)Qdoffs_OffscreenVersion
, 1,
558 {"NewTempScreenBuffer", (PyCFunction
)Qdoffs_NewTempScreenBuffer
, 1,
559 "(Rect globalRect, Boolean purgeable) -> (GDHandle gdh, PixMapHandle offscreenPixMap)"},
560 {"PixMap32Bit", (PyCFunction
)Qdoffs_PixMap32Bit
, 1,
561 "(PixMapHandle pmHandle) -> (Boolean _rv)"},
562 {"GetPixMapBytes", (PyCFunction
)Qdoffs_GetPixMapBytes
, 1,
563 "(pixmap, int start, int size) -> string. Return bytes from the pixmap"},
564 {"PutPixMapBytes", (PyCFunction
)Qdoffs_PutPixMapBytes
, 1,
565 "(pixmap, int start, string data). Store bytes into the pixmap"},
572 void initQdoffs(void)
579 PyMac_INIT_TOOLBOX_OBJECT_NEW(GWorldPtr
, GWorldObj_New
);
580 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(GWorldPtr
, GWorldObj_Convert
);
583 m
= Py_InitModule("Qdoffs", Qdoffs_methods
);
584 d
= PyModule_GetDict(m
);
585 Qdoffs_Error
= PyMac_GetOSErrException();
586 if (Qdoffs_Error
== NULL
||
587 PyDict_SetItemString(d
, "Error", Qdoffs_Error
) != 0)
589 GWorld_Type
.ob_type
= &PyType_Type
;
590 Py_INCREF(&GWorld_Type
);
591 if (PyDict_SetItemString(d
, "GWorldType", (PyObject
*)&GWorld_Type
) != 0)
592 Py_FatalError("can't initialize GWorldType");
595 /* ======================= End module Qdoffs ======================== */