2 /* ========================= Module Qdoffs ========================== */
8 #define SystemSevenOrLater 1
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
*);
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)
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)
31 extern PyObject
*MenuObj_New(MenuHandle
);
32 extern int MenuObj_Convert(PyObject
*, MenuHandle
*);
34 extern PyObject
*CtlObj_New(ControlHandle
);
35 extern int CtlObj_Convert(PyObject
*, ControlHandle
*);
37 extern PyObject
*GrafObj_New(GrafPtr
);
38 extern int GrafObj_Convert(PyObject
*, GrafPtr
*);
40 extern PyObject
*BMObj_New(BitMapPtr
);
41 extern int BMObj_Convert(PyObject
*, BitMapPtr
*);
43 extern PyObject
*WinObj_WhichWindow(WindowPtr
);
45 #include <QDOffscreen.h>
47 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
50 static PyObject
*Qdoffs_Error
;
52 /* ----------------------- Object type GWorld ----------------------- */
54 PyTypeObject GWorld_Type
;
56 #define GWorldObj_Check(x) ((x)->ob_type == &GWorld_Type)
58 typedef struct GWorldObject
{
63 PyObject
*GWorldObj_New(itself
)
67 if (itself
== NULL
) return PyMac_Error(resNotFound
);
68 it
= PyObject_NEW(GWorldObject
, &GWorld_Type
);
69 if (it
== NULL
) return NULL
;
70 it
->ob_itself
= itself
;
71 return (PyObject
*)it
;
73 GWorldObj_Convert(v
, p_itself
)
77 if (!GWorldObj_Check(v
))
79 PyErr_SetString(PyExc_TypeError
, "GWorld required");
82 *p_itself
= ((GWorldObject
*)v
)->ob_itself
;
86 static void GWorldObj_dealloc(self
)
89 DisposeGWorld(self
->ob_itself
);
93 static PyObject
*GWorldObj_GetGWorldDevice(_self
, _args
)
97 PyObject
*_res
= NULL
;
99 if (!PyArg_ParseTuple(_args
, ""))
101 _rv
= GetGWorldDevice(_self
->ob_itself
);
102 _res
= Py_BuildValue("O&",
107 static PyObject
*GWorldObj_GetGWorldPixMap(_self
, _args
)
111 PyObject
*_res
= NULL
;
113 if (!PyArg_ParseTuple(_args
, ""))
115 _rv
= GetGWorldPixMap(_self
->ob_itself
);
116 _res
= Py_BuildValue("O&",
121 static PyMethodDef GWorldObj_methods
[] = {
122 {"GetGWorldDevice", (PyCFunction
)GWorldObj_GetGWorldDevice
, 1,
123 "() -> (GDHandle _rv)"},
124 {"GetGWorldPixMap", (PyCFunction
)GWorldObj_GetGWorldPixMap
, 1,
125 "() -> (PixMapHandle _rv)"},
129 PyMethodChain GWorldObj_chain
= { GWorldObj_methods
, NULL
};
131 static PyObject
*GWorldObj_getattr(self
, name
)
135 return Py_FindMethodInChain(&GWorldObj_chain
, (PyObject
*)self
, name
);
138 #define GWorldObj_setattr NULL
140 PyTypeObject GWorld_Type
= {
141 PyObject_HEAD_INIT(&PyType_Type
)
143 "GWorld", /*tp_name*/
144 sizeof(GWorldObject
), /*tp_basicsize*/
147 (destructor
) GWorldObj_dealloc
, /*tp_dealloc*/
149 (getattrfunc
) GWorldObj_getattr
, /*tp_getattr*/
150 (setattrfunc
) GWorldObj_setattr
, /*tp_setattr*/
153 /* --------------------- End object type GWorld --------------------- */
156 static PyObject
*Qdoffs_NewGWorld(_self
, _args
)
160 PyObject
*_res
= NULL
;
162 GWorldPtr offscreenGWorld
;
168 if (!PyArg_ParseTuple(_args
, "hO&O&O&l",
170 PyMac_GetRect
, &boundsRect
,
171 OptResObj_Convert
, &cTable
,
172 OptResObj_Convert
, &aGDevice
,
175 _err
= NewGWorld(&offscreenGWorld
,
181 if (_err
!= noErr
) return PyMac_Error(_err
);
182 _res
= Py_BuildValue("O&",
183 GWorldObj_New
, offscreenGWorld
);
187 static PyObject
*Qdoffs_LockPixels(_self
, _args
)
191 PyObject
*_res
= NULL
;
194 if (!PyArg_ParseTuple(_args
, "O&",
195 ResObj_Convert
, &pm
))
197 _rv
= LockPixels(pm
);
198 _res
= Py_BuildValue("b",
203 static PyObject
*Qdoffs_UnlockPixels(_self
, _args
)
207 PyObject
*_res
= NULL
;
209 if (!PyArg_ParseTuple(_args
, "O&",
210 ResObj_Convert
, &pm
))
218 static PyObject
*Qdoffs_UpdateGWorld(_self
, _args
)
222 PyObject
*_res
= NULL
;
224 GWorldPtr offscreenGWorld
;
230 if (!PyArg_ParseTuple(_args
, "hO&O&O&l",
232 PyMac_GetRect
, &boundsRect
,
233 OptResObj_Convert
, &cTable
,
234 OptResObj_Convert
, &aGDevice
,
237 _rv
= UpdateGWorld(&offscreenGWorld
,
243 _res
= Py_BuildValue("lO&",
245 GWorldObj_New
, offscreenGWorld
);
249 static PyObject
*Qdoffs_GetGWorld(_self
, _args
)
253 PyObject
*_res
= NULL
;
256 if (!PyArg_ParseTuple(_args
, ""))
260 _res
= Py_BuildValue("O&O&",
266 static PyObject
*Qdoffs_SetGWorld(_self
, _args
)
270 PyObject
*_res
= NULL
;
273 if (!PyArg_ParseTuple(_args
, "O&O&",
274 GrafObj_Convert
, &port
,
275 OptResObj_Convert
, &gdh
))
284 static PyObject
*Qdoffs_CTabChanged(_self
, _args
)
288 PyObject
*_res
= NULL
;
290 if (!PyArg_ParseTuple(_args
, "O&",
291 OptResObj_Convert
, &ctab
))
299 static PyObject
*Qdoffs_PixPatChanged(_self
, _args
)
303 PyObject
*_res
= NULL
;
305 if (!PyArg_ParseTuple(_args
, "O&",
306 ResObj_Convert
, &ppat
))
314 static PyObject
*Qdoffs_PortChanged(_self
, _args
)
318 PyObject
*_res
= NULL
;
320 if (!PyArg_ParseTuple(_args
, "O&",
321 GrafObj_Convert
, &port
))
329 static PyObject
*Qdoffs_GDeviceChanged(_self
, _args
)
333 PyObject
*_res
= NULL
;
335 if (!PyArg_ParseTuple(_args
, "O&",
336 OptResObj_Convert
, &gdh
))
344 static PyObject
*Qdoffs_AllowPurgePixels(_self
, _args
)
348 PyObject
*_res
= NULL
;
350 if (!PyArg_ParseTuple(_args
, "O&",
351 ResObj_Convert
, &pm
))
353 AllowPurgePixels(pm
);
359 static PyObject
*Qdoffs_NoPurgePixels(_self
, _args
)
363 PyObject
*_res
= NULL
;
365 if (!PyArg_ParseTuple(_args
, "O&",
366 ResObj_Convert
, &pm
))
374 static PyObject
*Qdoffs_GetPixelsState(_self
, _args
)
378 PyObject
*_res
= NULL
;
381 if (!PyArg_ParseTuple(_args
, "O&",
382 ResObj_Convert
, &pm
))
384 _rv
= GetPixelsState(pm
);
385 _res
= Py_BuildValue("l",
390 static PyObject
*Qdoffs_SetPixelsState(_self
, _args
)
394 PyObject
*_res
= NULL
;
397 if (!PyArg_ParseTuple(_args
, "O&l",
408 static PyObject
*Qdoffs_NewScreenBuffer(_self
, _args
)
412 PyObject
*_res
= NULL
;
417 PixMapHandle offscreenPixMap
;
418 if (!PyArg_ParseTuple(_args
, "O&b",
419 PyMac_GetRect
, &globalRect
,
422 _err
= NewScreenBuffer(&globalRect
,
426 if (_err
!= noErr
) return PyMac_Error(_err
);
427 _res
= Py_BuildValue("O&O&",
429 ResObj_New
, offscreenPixMap
);
433 static PyObject
*Qdoffs_DisposeScreenBuffer(_self
, _args
)
437 PyObject
*_res
= NULL
;
438 PixMapHandle offscreenPixMap
;
439 if (!PyArg_ParseTuple(_args
, "O&",
440 ResObj_Convert
, &offscreenPixMap
))
442 DisposeScreenBuffer(offscreenPixMap
);
448 static PyObject
*Qdoffs_QDDone(_self
, _args
)
452 PyObject
*_res
= NULL
;
455 if (!PyArg_ParseTuple(_args
, "O&",
456 GrafObj_Convert
, &port
))
459 _res
= Py_BuildValue("b",
464 static PyObject
*Qdoffs_OffscreenVersion(_self
, _args
)
468 PyObject
*_res
= NULL
;
470 if (!PyArg_ParseTuple(_args
, ""))
472 _rv
= OffscreenVersion();
473 _res
= Py_BuildValue("l",
478 static PyObject
*Qdoffs_NewTempScreenBuffer(_self
, _args
)
482 PyObject
*_res
= NULL
;
487 PixMapHandle offscreenPixMap
;
488 if (!PyArg_ParseTuple(_args
, "O&b",
489 PyMac_GetRect
, &globalRect
,
492 _err
= NewTempScreenBuffer(&globalRect
,
496 if (_err
!= noErr
) return PyMac_Error(_err
);
497 _res
= Py_BuildValue("O&O&",
499 ResObj_New
, offscreenPixMap
);
503 static PyObject
*Qdoffs_PixMap32Bit(_self
, _args
)
507 PyObject
*_res
= NULL
;
509 PixMapHandle pmHandle
;
510 if (!PyArg_ParseTuple(_args
, "O&",
511 ResObj_Convert
, &pmHandle
))
513 _rv
= PixMap32Bit(pmHandle
);
514 _res
= Py_BuildValue("b",
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 {"NewScreenBuffer", (PyCFunction
)Qdoffs_NewScreenBuffer
, 1,
549 "(Rect globalRect, Boolean purgeable) -> (GDHandle gdh, PixMapHandle offscreenPixMap)"},
550 {"DisposeScreenBuffer", (PyCFunction
)Qdoffs_DisposeScreenBuffer
, 1,
551 "(PixMapHandle offscreenPixMap) -> None"},
552 {"QDDone", (PyCFunction
)Qdoffs_QDDone
, 1,
553 "(GrafPtr port) -> (Boolean _rv)"},
554 {"OffscreenVersion", (PyCFunction
)Qdoffs_OffscreenVersion
, 1,
556 {"NewTempScreenBuffer", (PyCFunction
)Qdoffs_NewTempScreenBuffer
, 1,
557 "(Rect globalRect, Boolean purgeable) -> (GDHandle gdh, PixMapHandle offscreenPixMap)"},
558 {"PixMap32Bit", (PyCFunction
)Qdoffs_PixMap32Bit
, 1,
559 "(PixMapHandle pmHandle) -> (Boolean _rv)"},
574 m
= Py_InitModule("Qdoffs", Qdoffs_methods
);
575 d
= PyModule_GetDict(m
);
576 Qdoffs_Error
= PyMac_GetOSErrException();
577 if (Qdoffs_Error
== NULL
||
578 PyDict_SetItemString(d
, "Error", Qdoffs_Error
) != 0)
579 Py_FatalError("can't initialize Qdoffs.Error");
580 GWorld_Type
.ob_type
= &PyType_Type
;
581 Py_INCREF(&GWorld_Type
);
582 if (PyDict_SetItemString(d
, "GWorldType", (PyObject
*)&GWorld_Type
) != 0)
583 Py_FatalError("can't initialize GWorldType");
586 /* ======================= End module Qdoffs ======================== */