Allow comment characters (#) to be escaped:
[python/dscho.git] / Mac / Modules / qdoffs / Qdoffsmodule.c
blobfef251f260dbfc08e58b257143781923d524bfc4
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 PyTypeObject GWorld_Type = {
141 PyObject_HEAD_INIT(&PyType_Type)
142 0, /*ob_size*/
143 "GWorld", /*tp_name*/
144 sizeof(GWorldObject), /*tp_basicsize*/
145 0, /*tp_itemsize*/
146 /* methods */
147 (destructor) GWorldObj_dealloc, /*tp_dealloc*/
148 0, /*tp_print*/
149 (getattrfunc) GWorldObj_getattr, /*tp_getattr*/
150 (setattrfunc) GWorldObj_setattr, /*tp_setattr*/
153 /* --------------------- End object type GWorld --------------------- */
156 static PyObject *Qdoffs_NewGWorld(_self, _args)
157 PyObject *_self;
158 PyObject *_args;
160 PyObject *_res = NULL;
161 QDErr _err;
162 GWorldPtr offscreenGWorld;
163 short PixelDepth;
164 Rect boundsRect;
165 CTabHandle cTable;
166 GDHandle aGDevice;
167 GWorldFlags flags;
168 if (!PyArg_ParseTuple(_args, "hO&O&O&l",
169 &PixelDepth,
170 PyMac_GetRect, &boundsRect,
171 OptResObj_Convert, &cTable,
172 OptResObj_Convert, &aGDevice,
173 &flags))
174 return NULL;
175 _err = NewGWorld(&offscreenGWorld,
176 PixelDepth,
177 &boundsRect,
178 cTable,
179 aGDevice,
180 flags);
181 if (_err != noErr) return PyMac_Error(_err);
182 _res = Py_BuildValue("O&",
183 GWorldObj_New, offscreenGWorld);
184 return _res;
187 static PyObject *Qdoffs_LockPixels(_self, _args)
188 PyObject *_self;
189 PyObject *_args;
191 PyObject *_res = NULL;
192 Boolean _rv;
193 PixMapHandle pm;
194 if (!PyArg_ParseTuple(_args, "O&",
195 ResObj_Convert, &pm))
196 return NULL;
197 _rv = LockPixels(pm);
198 _res = Py_BuildValue("b",
199 _rv);
200 return _res;
203 static PyObject *Qdoffs_UnlockPixels(_self, _args)
204 PyObject *_self;
205 PyObject *_args;
207 PyObject *_res = NULL;
208 PixMapHandle pm;
209 if (!PyArg_ParseTuple(_args, "O&",
210 ResObj_Convert, &pm))
211 return NULL;
212 UnlockPixels(pm);
213 Py_INCREF(Py_None);
214 _res = Py_None;
215 return _res;
218 static PyObject *Qdoffs_UpdateGWorld(_self, _args)
219 PyObject *_self;
220 PyObject *_args;
222 PyObject *_res = NULL;
223 GWorldFlags _rv;
224 GWorldPtr offscreenGWorld;
225 short pixelDepth;
226 Rect boundsRect;
227 CTabHandle cTable;
228 GDHandle aGDevice;
229 GWorldFlags flags;
230 if (!PyArg_ParseTuple(_args, "hO&O&O&l",
231 &pixelDepth,
232 PyMac_GetRect, &boundsRect,
233 OptResObj_Convert, &cTable,
234 OptResObj_Convert, &aGDevice,
235 &flags))
236 return NULL;
237 _rv = UpdateGWorld(&offscreenGWorld,
238 pixelDepth,
239 &boundsRect,
240 cTable,
241 aGDevice,
242 flags);
243 _res = Py_BuildValue("lO&",
244 _rv,
245 GWorldObj_New, offscreenGWorld);
246 return _res;
249 static PyObject *Qdoffs_GetGWorld(_self, _args)
250 PyObject *_self;
251 PyObject *_args;
253 PyObject *_res = NULL;
254 CGrafPtr port;
255 GDHandle gdh;
256 if (!PyArg_ParseTuple(_args, ""))
257 return NULL;
258 GetGWorld(&port,
259 &gdh);
260 _res = Py_BuildValue("O&O&",
261 GrafObj_New, port,
262 ResObj_New, gdh);
263 return _res;
266 static PyObject *Qdoffs_SetGWorld(_self, _args)
267 PyObject *_self;
268 PyObject *_args;
270 PyObject *_res = NULL;
271 CGrafPtr port;
272 GDHandle gdh;
273 if (!PyArg_ParseTuple(_args, "O&O&",
274 GrafObj_Convert, &port,
275 OptResObj_Convert, &gdh))
276 return NULL;
277 SetGWorld(port,
278 gdh);
279 Py_INCREF(Py_None);
280 _res = Py_None;
281 return _res;
284 static PyObject *Qdoffs_CTabChanged(_self, _args)
285 PyObject *_self;
286 PyObject *_args;
288 PyObject *_res = NULL;
289 CTabHandle ctab;
290 if (!PyArg_ParseTuple(_args, "O&",
291 OptResObj_Convert, &ctab))
292 return NULL;
293 CTabChanged(ctab);
294 Py_INCREF(Py_None);
295 _res = Py_None;
296 return _res;
299 static PyObject *Qdoffs_PixPatChanged(_self, _args)
300 PyObject *_self;
301 PyObject *_args;
303 PyObject *_res = NULL;
304 PixPatHandle ppat;
305 if (!PyArg_ParseTuple(_args, "O&",
306 ResObj_Convert, &ppat))
307 return NULL;
308 PixPatChanged(ppat);
309 Py_INCREF(Py_None);
310 _res = Py_None;
311 return _res;
314 static PyObject *Qdoffs_PortChanged(_self, _args)
315 PyObject *_self;
316 PyObject *_args;
318 PyObject *_res = NULL;
319 GrafPtr port;
320 if (!PyArg_ParseTuple(_args, "O&",
321 GrafObj_Convert, &port))
322 return NULL;
323 PortChanged(port);
324 Py_INCREF(Py_None);
325 _res = Py_None;
326 return _res;
329 static PyObject *Qdoffs_GDeviceChanged(_self, _args)
330 PyObject *_self;
331 PyObject *_args;
333 PyObject *_res = NULL;
334 GDHandle gdh;
335 if (!PyArg_ParseTuple(_args, "O&",
336 OptResObj_Convert, &gdh))
337 return NULL;
338 GDeviceChanged(gdh);
339 Py_INCREF(Py_None);
340 _res = Py_None;
341 return _res;
344 static PyObject *Qdoffs_AllowPurgePixels(_self, _args)
345 PyObject *_self;
346 PyObject *_args;
348 PyObject *_res = NULL;
349 PixMapHandle pm;
350 if (!PyArg_ParseTuple(_args, "O&",
351 ResObj_Convert, &pm))
352 return NULL;
353 AllowPurgePixels(pm);
354 Py_INCREF(Py_None);
355 _res = Py_None;
356 return _res;
359 static PyObject *Qdoffs_NoPurgePixels(_self, _args)
360 PyObject *_self;
361 PyObject *_args;
363 PyObject *_res = NULL;
364 PixMapHandle pm;
365 if (!PyArg_ParseTuple(_args, "O&",
366 ResObj_Convert, &pm))
367 return NULL;
368 NoPurgePixels(pm);
369 Py_INCREF(Py_None);
370 _res = Py_None;
371 return _res;
374 static PyObject *Qdoffs_GetPixelsState(_self, _args)
375 PyObject *_self;
376 PyObject *_args;
378 PyObject *_res = NULL;
379 GWorldFlags _rv;
380 PixMapHandle pm;
381 if (!PyArg_ParseTuple(_args, "O&",
382 ResObj_Convert, &pm))
383 return NULL;
384 _rv = GetPixelsState(pm);
385 _res = Py_BuildValue("l",
386 _rv);
387 return _res;
390 static PyObject *Qdoffs_SetPixelsState(_self, _args)
391 PyObject *_self;
392 PyObject *_args;
394 PyObject *_res = NULL;
395 PixMapHandle pm;
396 GWorldFlags state;
397 if (!PyArg_ParseTuple(_args, "O&l",
398 ResObj_Convert, &pm,
399 &state))
400 return NULL;
401 SetPixelsState(pm,
402 state);
403 Py_INCREF(Py_None);
404 _res = Py_None;
405 return _res;
408 static PyObject *Qdoffs_NewScreenBuffer(_self, _args)
409 PyObject *_self;
410 PyObject *_args;
412 PyObject *_res = NULL;
413 QDErr _err;
414 Rect globalRect;
415 Boolean purgeable;
416 GDHandle gdh;
417 PixMapHandle offscreenPixMap;
418 if (!PyArg_ParseTuple(_args, "O&b",
419 PyMac_GetRect, &globalRect,
420 &purgeable))
421 return NULL;
422 _err = NewScreenBuffer(&globalRect,
423 purgeable,
424 &gdh,
425 &offscreenPixMap);
426 if (_err != noErr) return PyMac_Error(_err);
427 _res = Py_BuildValue("O&O&",
428 ResObj_New, gdh,
429 ResObj_New, offscreenPixMap);
430 return _res;
433 static PyObject *Qdoffs_DisposeScreenBuffer(_self, _args)
434 PyObject *_self;
435 PyObject *_args;
437 PyObject *_res = NULL;
438 PixMapHandle offscreenPixMap;
439 if (!PyArg_ParseTuple(_args, "O&",
440 ResObj_Convert, &offscreenPixMap))
441 return NULL;
442 DisposeScreenBuffer(offscreenPixMap);
443 Py_INCREF(Py_None);
444 _res = Py_None;
445 return _res;
448 static PyObject *Qdoffs_QDDone(_self, _args)
449 PyObject *_self;
450 PyObject *_args;
452 PyObject *_res = NULL;
453 Boolean _rv;
454 GrafPtr port;
455 if (!PyArg_ParseTuple(_args, "O&",
456 GrafObj_Convert, &port))
457 return NULL;
458 _rv = QDDone(port);
459 _res = Py_BuildValue("b",
460 _rv);
461 return _res;
464 static PyObject *Qdoffs_OffscreenVersion(_self, _args)
465 PyObject *_self;
466 PyObject *_args;
468 PyObject *_res = NULL;
469 long _rv;
470 if (!PyArg_ParseTuple(_args, ""))
471 return NULL;
472 _rv = OffscreenVersion();
473 _res = Py_BuildValue("l",
474 _rv);
475 return _res;
478 static PyObject *Qdoffs_NewTempScreenBuffer(_self, _args)
479 PyObject *_self;
480 PyObject *_args;
482 PyObject *_res = NULL;
483 QDErr _err;
484 Rect globalRect;
485 Boolean purgeable;
486 GDHandle gdh;
487 PixMapHandle offscreenPixMap;
488 if (!PyArg_ParseTuple(_args, "O&b",
489 PyMac_GetRect, &globalRect,
490 &purgeable))
491 return NULL;
492 _err = NewTempScreenBuffer(&globalRect,
493 purgeable,
494 &gdh,
495 &offscreenPixMap);
496 if (_err != noErr) return PyMac_Error(_err);
497 _res = Py_BuildValue("O&O&",
498 ResObj_New, gdh,
499 ResObj_New, offscreenPixMap);
500 return _res;
503 static PyObject *Qdoffs_PixMap32Bit(_self, _args)
504 PyObject *_self;
505 PyObject *_args;
507 PyObject *_res = NULL;
508 Boolean _rv;
509 PixMapHandle pmHandle;
510 if (!PyArg_ParseTuple(_args, "O&",
511 ResObj_Convert, &pmHandle))
512 return NULL;
513 _rv = PixMap32Bit(pmHandle);
514 _res = Py_BuildValue("b",
515 _rv);
516 return _res;
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,
555 "() -> (long _rv)"},
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)"},
560 {NULL, NULL, 0}
566 void initQdoffs()
568 PyObject *m;
569 PyObject *d;
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 ======================== */