The 0.5 release happened on 2/15, not on 2/14. :-)
[python/dscho.git] / Mac / Modules / qdoffs / Qdoffsmodule.c
blob13ec478c6503c63deed47fe6022798b4d85beeaa
2 /* ========================= Module Qdoffs ========================== */
4 #include "Python.h"
8 #define SystemSevenOrLater 1
10 #include "macglue.h"
11 #include <Memory.h>
12 #include <Dialogs.h>
13 #include <Menus.h>
14 #include <Controls.h>
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 {
59 PyObject_HEAD
60 GWorldPtr ob_itself;
61 } GWorldObject;
63 PyObject *GWorldObj_New(itself)
64 GWorldPtr itself;
66 GWorldObject *it;
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)
74 PyObject *v;
75 GWorldPtr *p_itself;
77 if (!GWorldObj_Check(v))
79 PyErr_SetString(PyExc_TypeError, "GWorld required");
80 return 0;
82 *p_itself = ((GWorldObject *)v)->ob_itself;
83 return 1;
86 static void GWorldObj_dealloc(self)
87 GWorldObject *self;
89 DisposeGWorld(self->ob_itself);
90 PyMem_DEL(self);
93 static PyObject *GWorldObj_GetGWorldDevice(_self, _args)
94 GWorldObject *_self;
95 PyObject *_args;
97 PyObject *_res = NULL;
98 GDHandle _rv;
99 if (!PyArg_ParseTuple(_args, ""))
100 return NULL;
101 _rv = GetGWorldDevice(_self->ob_itself);
102 _res = Py_BuildValue("O&",
103 ResObj_New, _rv);
104 return _res;
107 static PyObject *GWorldObj_GetGWorldPixMap(_self, _args)
108 GWorldObject *_self;
109 PyObject *_args;
111 PyObject *_res = NULL;
112 PixMapHandle _rv;
113 if (!PyArg_ParseTuple(_args, ""))
114 return NULL;
115 _rv = GetGWorldPixMap(_self->ob_itself);
116 _res = Py_BuildValue("O&",
117 ResObj_New, _rv);
118 return _res;
121 static PyMethodDef GWorldObj_methods[] = {
122 {"GetGWorldDevice", (PyCFunction)GWorldObj_GetGWorldDevice, 1,
123 "() -> (GDHandle _rv)"},
124 {"GetGWorldPixMap", (PyCFunction)GWorldObj_GetGWorldPixMap, 1,
125 "() -> (PixMapHandle _rv)"},
126 {NULL, NULL, 0}
129 PyMethodChain GWorldObj_chain = { GWorldObj_methods, NULL };
131 static PyObject *GWorldObj_getattr(self, name)
132 GWorldObject *self;
133 char *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)
148 0, /*ob_size*/
149 "GWorld", /*tp_name*/
150 sizeof(GWorldObject), /*tp_basicsize*/
151 0, /*tp_itemsize*/
152 /* methods */
153 (destructor) GWorldObj_dealloc, /*tp_dealloc*/
154 0, /*tp_print*/
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)
169 PyObject *_self;
170 PyObject *_args;
172 PyObject *_res = NULL;
173 QDErr _err;
174 GWorldPtr offscreenGWorld;
175 short PixelDepth;
176 Rect boundsRect;
177 CTabHandle cTable;
178 GDHandle aGDevice;
179 GWorldFlags flags;
180 if (!PyArg_ParseTuple(_args, "hO&O&O&l",
181 &PixelDepth,
182 PyMac_GetRect, &boundsRect,
183 OptResObj_Convert, &cTable,
184 OptResObj_Convert, &aGDevice,
185 &flags))
186 return NULL;
187 _err = NewGWorld(&offscreenGWorld,
188 PixelDepth,
189 &boundsRect,
190 cTable,
191 aGDevice,
192 flags);
193 if (_err != noErr) return PyMac_Error(_err);
194 _res = Py_BuildValue("O&",
195 GWorldObj_New, offscreenGWorld);
196 return _res;
199 static PyObject *Qdoffs_LockPixels(_self, _args)
200 PyObject *_self;
201 PyObject *_args;
203 PyObject *_res = NULL;
204 Boolean _rv;
205 PixMapHandle pm;
206 if (!PyArg_ParseTuple(_args, "O&",
207 ResObj_Convert, &pm))
208 return NULL;
209 _rv = LockPixels(pm);
210 _res = Py_BuildValue("b",
211 _rv);
212 return _res;
215 static PyObject *Qdoffs_UnlockPixels(_self, _args)
216 PyObject *_self;
217 PyObject *_args;
219 PyObject *_res = NULL;
220 PixMapHandle pm;
221 if (!PyArg_ParseTuple(_args, "O&",
222 ResObj_Convert, &pm))
223 return NULL;
224 UnlockPixels(pm);
225 Py_INCREF(Py_None);
226 _res = Py_None;
227 return _res;
230 static PyObject *Qdoffs_UpdateGWorld(_self, _args)
231 PyObject *_self;
232 PyObject *_args;
234 PyObject *_res = NULL;
235 GWorldFlags _rv;
236 GWorldPtr offscreenGWorld;
237 short pixelDepth;
238 Rect boundsRect;
239 CTabHandle cTable;
240 GDHandle aGDevice;
241 GWorldFlags flags;
242 if (!PyArg_ParseTuple(_args, "hO&O&O&l",
243 &pixelDepth,
244 PyMac_GetRect, &boundsRect,
245 OptResObj_Convert, &cTable,
246 OptResObj_Convert, &aGDevice,
247 &flags))
248 return NULL;
249 _rv = UpdateGWorld(&offscreenGWorld,
250 pixelDepth,
251 &boundsRect,
252 cTable,
253 aGDevice,
254 flags);
255 _res = Py_BuildValue("lO&",
256 _rv,
257 GWorldObj_New, offscreenGWorld);
258 return _res;
261 static PyObject *Qdoffs_GetGWorld(_self, _args)
262 PyObject *_self;
263 PyObject *_args;
265 PyObject *_res = NULL;
266 CGrafPtr port;
267 GDHandle gdh;
268 if (!PyArg_ParseTuple(_args, ""))
269 return NULL;
270 GetGWorld(&port,
271 &gdh);
272 _res = Py_BuildValue("O&O&",
273 GrafObj_New, port,
274 ResObj_New, gdh);
275 return _res;
278 static PyObject *Qdoffs_SetGWorld(_self, _args)
279 PyObject *_self;
280 PyObject *_args;
282 PyObject *_res = NULL;
283 CGrafPtr port;
284 GDHandle gdh;
285 if (!PyArg_ParseTuple(_args, "O&O&",
286 GrafObj_Convert, &port,
287 OptResObj_Convert, &gdh))
288 return NULL;
289 SetGWorld(port,
290 gdh);
291 Py_INCREF(Py_None);
292 _res = Py_None;
293 return _res;
296 static PyObject *Qdoffs_CTabChanged(_self, _args)
297 PyObject *_self;
298 PyObject *_args;
300 PyObject *_res = NULL;
301 CTabHandle ctab;
302 if (!PyArg_ParseTuple(_args, "O&",
303 OptResObj_Convert, &ctab))
304 return NULL;
305 CTabChanged(ctab);
306 Py_INCREF(Py_None);
307 _res = Py_None;
308 return _res;
311 static PyObject *Qdoffs_PixPatChanged(_self, _args)
312 PyObject *_self;
313 PyObject *_args;
315 PyObject *_res = NULL;
316 PixPatHandle ppat;
317 if (!PyArg_ParseTuple(_args, "O&",
318 ResObj_Convert, &ppat))
319 return NULL;
320 PixPatChanged(ppat);
321 Py_INCREF(Py_None);
322 _res = Py_None;
323 return _res;
326 static PyObject *Qdoffs_PortChanged(_self, _args)
327 PyObject *_self;
328 PyObject *_args;
330 PyObject *_res = NULL;
331 GrafPtr port;
332 if (!PyArg_ParseTuple(_args, "O&",
333 GrafObj_Convert, &port))
334 return NULL;
335 PortChanged(port);
336 Py_INCREF(Py_None);
337 _res = Py_None;
338 return _res;
341 static PyObject *Qdoffs_GDeviceChanged(_self, _args)
342 PyObject *_self;
343 PyObject *_args;
345 PyObject *_res = NULL;
346 GDHandle gdh;
347 if (!PyArg_ParseTuple(_args, "O&",
348 OptResObj_Convert, &gdh))
349 return NULL;
350 GDeviceChanged(gdh);
351 Py_INCREF(Py_None);
352 _res = Py_None;
353 return _res;
356 static PyObject *Qdoffs_AllowPurgePixels(_self, _args)
357 PyObject *_self;
358 PyObject *_args;
360 PyObject *_res = NULL;
361 PixMapHandle pm;
362 if (!PyArg_ParseTuple(_args, "O&",
363 ResObj_Convert, &pm))
364 return NULL;
365 AllowPurgePixels(pm);
366 Py_INCREF(Py_None);
367 _res = Py_None;
368 return _res;
371 static PyObject *Qdoffs_NoPurgePixels(_self, _args)
372 PyObject *_self;
373 PyObject *_args;
375 PyObject *_res = NULL;
376 PixMapHandle pm;
377 if (!PyArg_ParseTuple(_args, "O&",
378 ResObj_Convert, &pm))
379 return NULL;
380 NoPurgePixels(pm);
381 Py_INCREF(Py_None);
382 _res = Py_None;
383 return _res;
386 static PyObject *Qdoffs_GetPixelsState(_self, _args)
387 PyObject *_self;
388 PyObject *_args;
390 PyObject *_res = NULL;
391 GWorldFlags _rv;
392 PixMapHandle pm;
393 if (!PyArg_ParseTuple(_args, "O&",
394 ResObj_Convert, &pm))
395 return NULL;
396 _rv = GetPixelsState(pm);
397 _res = Py_BuildValue("l",
398 _rv);
399 return _res;
402 static PyObject *Qdoffs_SetPixelsState(_self, _args)
403 PyObject *_self;
404 PyObject *_args;
406 PyObject *_res = NULL;
407 PixMapHandle pm;
408 GWorldFlags state;
409 if (!PyArg_ParseTuple(_args, "O&l",
410 ResObj_Convert, &pm,
411 &state))
412 return NULL;
413 SetPixelsState(pm,
414 state);
415 Py_INCREF(Py_None);
416 _res = Py_None;
417 return _res;
420 static PyObject *Qdoffs_GetPixRowBytes(_self, _args)
421 PyObject *_self;
422 PyObject *_args;
424 PyObject *_res = NULL;
425 long _rv;
426 PixMapHandle pm;
427 if (!PyArg_ParseTuple(_args, "O&",
428 ResObj_Convert, &pm))
429 return NULL;
430 _rv = GetPixRowBytes(pm);
431 _res = Py_BuildValue("l",
432 _rv);
433 return _res;
436 static PyObject *Qdoffs_NewScreenBuffer(_self, _args)
437 PyObject *_self;
438 PyObject *_args;
440 PyObject *_res = NULL;
441 QDErr _err;
442 Rect globalRect;
443 Boolean purgeable;
444 GDHandle gdh;
445 PixMapHandle offscreenPixMap;
446 if (!PyArg_ParseTuple(_args, "O&b",
447 PyMac_GetRect, &globalRect,
448 &purgeable))
449 return NULL;
450 _err = NewScreenBuffer(&globalRect,
451 purgeable,
452 &gdh,
453 &offscreenPixMap);
454 if (_err != noErr) return PyMac_Error(_err);
455 _res = Py_BuildValue("O&O&",
456 ResObj_New, gdh,
457 ResObj_New, offscreenPixMap);
458 return _res;
461 static PyObject *Qdoffs_DisposeScreenBuffer(_self, _args)
462 PyObject *_self;
463 PyObject *_args;
465 PyObject *_res = NULL;
466 PixMapHandle offscreenPixMap;
467 if (!PyArg_ParseTuple(_args, "O&",
468 ResObj_Convert, &offscreenPixMap))
469 return NULL;
470 DisposeScreenBuffer(offscreenPixMap);
471 Py_INCREF(Py_None);
472 _res = Py_None;
473 return _res;
476 static PyObject *Qdoffs_QDDone(_self, _args)
477 PyObject *_self;
478 PyObject *_args;
480 PyObject *_res = NULL;
481 Boolean _rv;
482 GrafPtr port;
483 if (!PyArg_ParseTuple(_args, "O&",
484 GrafObj_Convert, &port))
485 return NULL;
486 _rv = QDDone(port);
487 _res = Py_BuildValue("b",
488 _rv);
489 return _res;
492 static PyObject *Qdoffs_OffscreenVersion(_self, _args)
493 PyObject *_self;
494 PyObject *_args;
496 PyObject *_res = NULL;
497 long _rv;
498 if (!PyArg_ParseTuple(_args, ""))
499 return NULL;
500 _rv = OffscreenVersion();
501 _res = Py_BuildValue("l",
502 _rv);
503 return _res;
506 static PyObject *Qdoffs_NewTempScreenBuffer(_self, _args)
507 PyObject *_self;
508 PyObject *_args;
510 PyObject *_res = NULL;
511 QDErr _err;
512 Rect globalRect;
513 Boolean purgeable;
514 GDHandle gdh;
515 PixMapHandle offscreenPixMap;
516 if (!PyArg_ParseTuple(_args, "O&b",
517 PyMac_GetRect, &globalRect,
518 &purgeable))
519 return NULL;
520 _err = NewTempScreenBuffer(&globalRect,
521 purgeable,
522 &gdh,
523 &offscreenPixMap);
524 if (_err != noErr) return PyMac_Error(_err);
525 _res = Py_BuildValue("O&O&",
526 ResObj_New, gdh,
527 ResObj_New, offscreenPixMap);
528 return _res;
531 static PyObject *Qdoffs_PixMap32Bit(_self, _args)
532 PyObject *_self;
533 PyObject *_args;
535 PyObject *_res = NULL;
536 Boolean _rv;
537 PixMapHandle pmHandle;
538 if (!PyArg_ParseTuple(_args, "O&",
539 ResObj_Convert, &pmHandle))
540 return NULL;
541 _rv = PixMap32Bit(pmHandle);
542 _res = Py_BuildValue("b",
543 _rv);
544 return _res;
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,
585 "() -> (long _rv)"},
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)"},
590 {NULL, NULL, 0}
596 void initQdoffs()
598 PyObject *m;
599 PyObject *d;
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 ======================== */