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 #define GWorldObj_compare NULL
142 #define GWorldObj_repr NULL
144 #define GWorldObj_hash NULL
146 PyTypeObject GWorld_Type
= {
147 PyObject_HEAD_INIT(&PyType_Type
)
149 "GWorld", /*tp_name*/
150 sizeof(GWorldObject
), /*tp_basicsize*/
153 (destructor
) GWorldObj_dealloc
, /*tp_dealloc*/
155 (getattrfunc
) GWorldObj_getattr
, /*tp_getattr*/
156 (setattrfunc
) GWorldObj_setattr
, /*tp_setattr*/
157 (cmpfunc
) GWorldObj_compare
, /*tp_compare*/
158 (reprfunc
) GWorldObj_repr
, /*tp_repr*/
159 (PyNumberMethods
*)0, /* tp_as_number */
160 (PySequenceMethods
*)0, /* tp_as_sequence */
161 (PyMappingMethods
*)0, /* tp_as_mapping */
162 (hashfunc
) GWorldObj_hash
, /*tp_hash*/
165 /* --------------------- End object type GWorld --------------------- */
168 static PyObject
*Qdoffs_NewGWorld(_self
, _args
)
172 PyObject
*_res
= NULL
;
174 GWorldPtr offscreenGWorld
;
180 if (!PyArg_ParseTuple(_args
, "hO&O&O&l",
182 PyMac_GetRect
, &boundsRect
,
183 OptResObj_Convert
, &cTable
,
184 OptResObj_Convert
, &aGDevice
,
187 _err
= NewGWorld(&offscreenGWorld
,
193 if (_err
!= noErr
) return PyMac_Error(_err
);
194 _res
= Py_BuildValue("O&",
195 GWorldObj_New
, offscreenGWorld
);
199 static PyObject
*Qdoffs_LockPixels(_self
, _args
)
203 PyObject
*_res
= NULL
;
206 if (!PyArg_ParseTuple(_args
, "O&",
207 ResObj_Convert
, &pm
))
209 _rv
= LockPixels(pm
);
210 _res
= Py_BuildValue("b",
215 static PyObject
*Qdoffs_UnlockPixels(_self
, _args
)
219 PyObject
*_res
= NULL
;
221 if (!PyArg_ParseTuple(_args
, "O&",
222 ResObj_Convert
, &pm
))
230 static PyObject
*Qdoffs_UpdateGWorld(_self
, _args
)
234 PyObject
*_res
= NULL
;
236 GWorldPtr offscreenGWorld
;
242 if (!PyArg_ParseTuple(_args
, "hO&O&O&l",
244 PyMac_GetRect
, &boundsRect
,
245 OptResObj_Convert
, &cTable
,
246 OptResObj_Convert
, &aGDevice
,
249 _rv
= UpdateGWorld(&offscreenGWorld
,
255 _res
= Py_BuildValue("lO&",
257 GWorldObj_New
, offscreenGWorld
);
261 static PyObject
*Qdoffs_GetGWorld(_self
, _args
)
265 PyObject
*_res
= NULL
;
268 if (!PyArg_ParseTuple(_args
, ""))
272 _res
= Py_BuildValue("O&O&",
278 static PyObject
*Qdoffs_SetGWorld(_self
, _args
)
282 PyObject
*_res
= NULL
;
285 if (!PyArg_ParseTuple(_args
, "O&O&",
286 GrafObj_Convert
, &port
,
287 OptResObj_Convert
, &gdh
))
296 static PyObject
*Qdoffs_CTabChanged(_self
, _args
)
300 PyObject
*_res
= NULL
;
302 if (!PyArg_ParseTuple(_args
, "O&",
303 OptResObj_Convert
, &ctab
))
311 static PyObject
*Qdoffs_PixPatChanged(_self
, _args
)
315 PyObject
*_res
= NULL
;
317 if (!PyArg_ParseTuple(_args
, "O&",
318 ResObj_Convert
, &ppat
))
326 static PyObject
*Qdoffs_PortChanged(_self
, _args
)
330 PyObject
*_res
= NULL
;
332 if (!PyArg_ParseTuple(_args
, "O&",
333 GrafObj_Convert
, &port
))
341 static PyObject
*Qdoffs_GDeviceChanged(_self
, _args
)
345 PyObject
*_res
= NULL
;
347 if (!PyArg_ParseTuple(_args
, "O&",
348 OptResObj_Convert
, &gdh
))
356 static PyObject
*Qdoffs_AllowPurgePixels(_self
, _args
)
360 PyObject
*_res
= NULL
;
362 if (!PyArg_ParseTuple(_args
, "O&",
363 ResObj_Convert
, &pm
))
365 AllowPurgePixels(pm
);
371 static PyObject
*Qdoffs_NoPurgePixels(_self
, _args
)
375 PyObject
*_res
= NULL
;
377 if (!PyArg_ParseTuple(_args
, "O&",
378 ResObj_Convert
, &pm
))
386 static PyObject
*Qdoffs_GetPixelsState(_self
, _args
)
390 PyObject
*_res
= NULL
;
393 if (!PyArg_ParseTuple(_args
, "O&",
394 ResObj_Convert
, &pm
))
396 _rv
= GetPixelsState(pm
);
397 _res
= Py_BuildValue("l",
402 static PyObject
*Qdoffs_SetPixelsState(_self
, _args
)
406 PyObject
*_res
= NULL
;
409 if (!PyArg_ParseTuple(_args
, "O&l",
420 static PyObject
*Qdoffs_GetPixRowBytes(_self
, _args
)
424 PyObject
*_res
= NULL
;
427 if (!PyArg_ParseTuple(_args
, "O&",
428 ResObj_Convert
, &pm
))
430 _rv
= GetPixRowBytes(pm
);
431 _res
= Py_BuildValue("l",
436 static PyObject
*Qdoffs_NewScreenBuffer(_self
, _args
)
440 PyObject
*_res
= NULL
;
445 PixMapHandle offscreenPixMap
;
446 if (!PyArg_ParseTuple(_args
, "O&b",
447 PyMac_GetRect
, &globalRect
,
450 _err
= NewScreenBuffer(&globalRect
,
454 if (_err
!= noErr
) return PyMac_Error(_err
);
455 _res
= Py_BuildValue("O&O&",
457 ResObj_New
, offscreenPixMap
);
461 static PyObject
*Qdoffs_DisposeScreenBuffer(_self
, _args
)
465 PyObject
*_res
= NULL
;
466 PixMapHandle offscreenPixMap
;
467 if (!PyArg_ParseTuple(_args
, "O&",
468 ResObj_Convert
, &offscreenPixMap
))
470 DisposeScreenBuffer(offscreenPixMap
);
476 static PyObject
*Qdoffs_QDDone(_self
, _args
)
480 PyObject
*_res
= NULL
;
483 if (!PyArg_ParseTuple(_args
, "O&",
484 GrafObj_Convert
, &port
))
487 _res
= Py_BuildValue("b",
492 static PyObject
*Qdoffs_OffscreenVersion(_self
, _args
)
496 PyObject
*_res
= NULL
;
498 if (!PyArg_ParseTuple(_args
, ""))
500 _rv
= OffscreenVersion();
501 _res
= Py_BuildValue("l",
506 static PyObject
*Qdoffs_NewTempScreenBuffer(_self
, _args
)
510 PyObject
*_res
= NULL
;
515 PixMapHandle offscreenPixMap
;
516 if (!PyArg_ParseTuple(_args
, "O&b",
517 PyMac_GetRect
, &globalRect
,
520 _err
= NewTempScreenBuffer(&globalRect
,
524 if (_err
!= noErr
) return PyMac_Error(_err
);
525 _res
= Py_BuildValue("O&O&",
527 ResObj_New
, offscreenPixMap
);
531 static PyObject
*Qdoffs_PixMap32Bit(_self
, _args
)
535 PyObject
*_res
= NULL
;
537 PixMapHandle pmHandle
;
538 if (!PyArg_ParseTuple(_args
, "O&",
539 ResObj_Convert
, &pmHandle
))
541 _rv
= PixMap32Bit(pmHandle
);
542 _res
= Py_BuildValue("b",
547 static PyMethodDef Qdoffs_methods
[] = {
548 {"NewGWorld", (PyCFunction
)Qdoffs_NewGWorld
, 1,
549 "(short PixelDepth, Rect boundsRect, CTabHandle cTable, GDHandle aGDevice, GWorldFlags flags) -> (GWorldPtr offscreenGWorld)"},
550 {"LockPixels", (PyCFunction
)Qdoffs_LockPixels
, 1,
551 "(PixMapHandle pm) -> (Boolean _rv)"},
552 {"UnlockPixels", (PyCFunction
)Qdoffs_UnlockPixels
, 1,
553 "(PixMapHandle pm) -> None"},
554 {"UpdateGWorld", (PyCFunction
)Qdoffs_UpdateGWorld
, 1,
555 "(short pixelDepth, Rect boundsRect, CTabHandle cTable, GDHandle aGDevice, GWorldFlags flags) -> (GWorldFlags _rv, GWorldPtr offscreenGWorld)"},
556 {"GetGWorld", (PyCFunction
)Qdoffs_GetGWorld
, 1,
557 "() -> (CGrafPtr port, GDHandle gdh)"},
558 {"SetGWorld", (PyCFunction
)Qdoffs_SetGWorld
, 1,
559 "(CGrafPtr port, GDHandle gdh) -> None"},
560 {"CTabChanged", (PyCFunction
)Qdoffs_CTabChanged
, 1,
561 "(CTabHandle ctab) -> None"},
562 {"PixPatChanged", (PyCFunction
)Qdoffs_PixPatChanged
, 1,
563 "(PixPatHandle ppat) -> None"},
564 {"PortChanged", (PyCFunction
)Qdoffs_PortChanged
, 1,
565 "(GrafPtr port) -> None"},
566 {"GDeviceChanged", (PyCFunction
)Qdoffs_GDeviceChanged
, 1,
567 "(GDHandle gdh) -> None"},
568 {"AllowPurgePixels", (PyCFunction
)Qdoffs_AllowPurgePixels
, 1,
569 "(PixMapHandle pm) -> None"},
570 {"NoPurgePixels", (PyCFunction
)Qdoffs_NoPurgePixels
, 1,
571 "(PixMapHandle pm) -> None"},
572 {"GetPixelsState", (PyCFunction
)Qdoffs_GetPixelsState
, 1,
573 "(PixMapHandle pm) -> (GWorldFlags _rv)"},
574 {"SetPixelsState", (PyCFunction
)Qdoffs_SetPixelsState
, 1,
575 "(PixMapHandle pm, GWorldFlags state) -> None"},
576 {"GetPixRowBytes", (PyCFunction
)Qdoffs_GetPixRowBytes
, 1,
577 "(PixMapHandle pm) -> (long _rv)"},
578 {"NewScreenBuffer", (PyCFunction
)Qdoffs_NewScreenBuffer
, 1,
579 "(Rect globalRect, Boolean purgeable) -> (GDHandle gdh, PixMapHandle offscreenPixMap)"},
580 {"DisposeScreenBuffer", (PyCFunction
)Qdoffs_DisposeScreenBuffer
, 1,
581 "(PixMapHandle offscreenPixMap) -> None"},
582 {"QDDone", (PyCFunction
)Qdoffs_QDDone
, 1,
583 "(GrafPtr port) -> (Boolean _rv)"},
584 {"OffscreenVersion", (PyCFunction
)Qdoffs_OffscreenVersion
, 1,
586 {"NewTempScreenBuffer", (PyCFunction
)Qdoffs_NewTempScreenBuffer
, 1,
587 "(Rect globalRect, Boolean purgeable) -> (GDHandle gdh, PixMapHandle offscreenPixMap)"},
588 {"PixMap32Bit", (PyCFunction
)Qdoffs_PixMap32Bit
, 1,
589 "(PixMapHandle pmHandle) -> (Boolean _rv)"},
604 m
= Py_InitModule("Qdoffs", Qdoffs_methods
);
605 d
= PyModule_GetDict(m
);
606 Qdoffs_Error
= PyMac_GetOSErrException();
607 if (Qdoffs_Error
== NULL
||
608 PyDict_SetItemString(d
, "Error", Qdoffs_Error
) != 0)
609 Py_FatalError("can't initialize Qdoffs.Error");
610 GWorld_Type
.ob_type
= &PyType_Type
;
611 Py_INCREF(&GWorld_Type
);
612 if (PyDict_SetItemString(d
, "GWorldType", (PyObject
*)&GWorld_Type
) != 0)
613 Py_FatalError("can't initialize GWorldType");
616 /* ======================= End module Qdoffs ======================== */