blob: 13ec478c6503c63deed47fe6022798b4d85beeaa [file] [log] [blame]
Jack Jansena4e6ae61999-03-07 23:11:21 +00001
2/* ========================= Module Qdoffs ========================== */
3
4#include "Python.h"
5
6
7
8#define SystemSevenOrLater 1
9
10#include "macglue.h"
11#include <Memory.h>
12#include <Dialogs.h>
13#include <Menus.h>
14#include <Controls.h>
15
16extern PyObject *ResObj_New(Handle);
17extern int ResObj_Convert(PyObject *, Handle *);
18extern PyObject *OptResObj_New(Handle);
19extern int OptResObj_Convert(PyObject *, Handle *);
20
21extern PyObject *WinObj_New(WindowPtr);
22extern int WinObj_Convert(PyObject *, WindowPtr *);
23extern PyTypeObject Window_Type;
24#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
25
26extern PyObject *DlgObj_New(DialogPtr);
27extern int DlgObj_Convert(PyObject *, DialogPtr *);
28extern PyTypeObject Dialog_Type;
29#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
30
31extern PyObject *MenuObj_New(MenuHandle);
32extern int MenuObj_Convert(PyObject *, MenuHandle *);
33
34extern PyObject *CtlObj_New(ControlHandle);
35extern int CtlObj_Convert(PyObject *, ControlHandle *);
36
37extern PyObject *GrafObj_New(GrafPtr);
38extern int GrafObj_Convert(PyObject *, GrafPtr *);
39
40extern PyObject *BMObj_New(BitMapPtr);
41extern int BMObj_Convert(PyObject *, BitMapPtr *);
42
43extern PyObject *WinObj_WhichWindow(WindowPtr);
44
45#include <QDOffscreen.h>
46
47#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
48
49
50static PyObject *Qdoffs_Error;
51
52/* ----------------------- Object type GWorld ----------------------- */
53
54PyTypeObject GWorld_Type;
55
56#define GWorldObj_Check(x) ((x)->ob_type == &GWorld_Type)
57
58typedef struct GWorldObject {
59 PyObject_HEAD
60 GWorldPtr ob_itself;
61} GWorldObject;
62
63PyObject *GWorldObj_New(itself)
64 GWorldPtr itself;
65{
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;
72}
73GWorldObj_Convert(v, p_itself)
74 PyObject *v;
75 GWorldPtr *p_itself;
76{
77 if (!GWorldObj_Check(v))
78 {
79 PyErr_SetString(PyExc_TypeError, "GWorld required");
80 return 0;
81 }
82 *p_itself = ((GWorldObject *)v)->ob_itself;
83 return 1;
84}
85
86static void GWorldObj_dealloc(self)
87 GWorldObject *self;
88{
89 DisposeGWorld(self->ob_itself);
90 PyMem_DEL(self);
91}
92
93static PyObject *GWorldObj_GetGWorldDevice(_self, _args)
94 GWorldObject *_self;
95 PyObject *_args;
96{
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;
105}
106
107static PyObject *GWorldObj_GetGWorldPixMap(_self, _args)
108 GWorldObject *_self;
109 PyObject *_args;
110{
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;
119}
120
121static 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}
127};
128
129PyMethodChain GWorldObj_chain = { GWorldObj_methods, NULL };
130
131static PyObject *GWorldObj_getattr(self, name)
132 GWorldObject *self;
133 char *name;
134{
135 return Py_FindMethodInChain(&GWorldObj_chain, (PyObject *)self, name);
136}
137
138#define GWorldObj_setattr NULL
139
Jack Jansena05ac601999-12-12 21:41:51 +0000140#define GWorldObj_compare NULL
141
142#define GWorldObj_repr NULL
143
144#define GWorldObj_hash NULL
145
Jack Jansena4e6ae61999-03-07 23:11:21 +0000146PyTypeObject 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*/
Jack Jansena05ac601999-12-12 21:41:51 +0000157 (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*/
Jack Jansena4e6ae61999-03-07 23:11:21 +0000163};
164
165/* --------------------- End object type GWorld --------------------- */
166
167
168static PyObject *Qdoffs_NewGWorld(_self, _args)
169 PyObject *_self;
170 PyObject *_args;
171{
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;
197}
198
199static PyObject *Qdoffs_LockPixels(_self, _args)
200 PyObject *_self;
201 PyObject *_args;
202{
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;
213}
214
215static PyObject *Qdoffs_UnlockPixels(_self, _args)
216 PyObject *_self;
217 PyObject *_args;
218{
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;
228}
229
230static PyObject *Qdoffs_UpdateGWorld(_self, _args)
231 PyObject *_self;
232 PyObject *_args;
233{
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;
259}
260
261static PyObject *Qdoffs_GetGWorld(_self, _args)
262 PyObject *_self;
263 PyObject *_args;
264{
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;
276}
277
278static PyObject *Qdoffs_SetGWorld(_self, _args)
279 PyObject *_self;
280 PyObject *_args;
281{
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;
294}
295
296static PyObject *Qdoffs_CTabChanged(_self, _args)
297 PyObject *_self;
298 PyObject *_args;
299{
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;
309}
310
311static PyObject *Qdoffs_PixPatChanged(_self, _args)
312 PyObject *_self;
313 PyObject *_args;
314{
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;
324}
325
326static PyObject *Qdoffs_PortChanged(_self, _args)
327 PyObject *_self;
328 PyObject *_args;
329{
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;
339}
340
341static PyObject *Qdoffs_GDeviceChanged(_self, _args)
342 PyObject *_self;
343 PyObject *_args;
344{
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;
354}
355
356static PyObject *Qdoffs_AllowPurgePixels(_self, _args)
357 PyObject *_self;
358 PyObject *_args;
359{
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;
369}
370
371static PyObject *Qdoffs_NoPurgePixels(_self, _args)
372 PyObject *_self;
373 PyObject *_args;
374{
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;
384}
385
386static PyObject *Qdoffs_GetPixelsState(_self, _args)
387 PyObject *_self;
388 PyObject *_args;
389{
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;
400}
401
402static PyObject *Qdoffs_SetPixelsState(_self, _args)
403 PyObject *_self;
404 PyObject *_args;
405{
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;
418}
419
Jack Jansena05ac601999-12-12 21:41:51 +0000420static PyObject *Qdoffs_GetPixRowBytes(_self, _args)
421 PyObject *_self;
422 PyObject *_args;
423{
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;
434}
435
Jack Jansena4e6ae61999-03-07 23:11:21 +0000436static PyObject *Qdoffs_NewScreenBuffer(_self, _args)
437 PyObject *_self;
438 PyObject *_args;
439{
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;
459}
460
461static PyObject *Qdoffs_DisposeScreenBuffer(_self, _args)
462 PyObject *_self;
463 PyObject *_args;
464{
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;
474}
475
476static PyObject *Qdoffs_QDDone(_self, _args)
477 PyObject *_self;
478 PyObject *_args;
479{
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;
490}
491
492static PyObject *Qdoffs_OffscreenVersion(_self, _args)
493 PyObject *_self;
494 PyObject *_args;
495{
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;
504}
505
506static PyObject *Qdoffs_NewTempScreenBuffer(_self, _args)
507 PyObject *_self;
508 PyObject *_args;
509{
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;
529}
530
531static PyObject *Qdoffs_PixMap32Bit(_self, _args)
532 PyObject *_self;
533 PyObject *_args;
534{
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;
545}
546
547static 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"},
Jack Jansena05ac601999-12-12 21:41:51 +0000576 {"GetPixRowBytes", (PyCFunction)Qdoffs_GetPixRowBytes, 1,
577 "(PixMapHandle pm) -> (long _rv)"},
Jack Jansena4e6ae61999-03-07 23:11:21 +0000578 {"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}
591};
592
593
594
595
596void initQdoffs()
597{
598 PyObject *m;
599 PyObject *d;
600
601
602
603
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");
614}
615
616/* ======================= End module Qdoffs ======================== */
617