extern PyObject *WinObj_New(WindowPtr);
extern int WinObj_Convert(PyObject *, WindowPtr *);
+extern PyTypeObject Window_Type;
+#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
extern PyObject *DlgObj_New(DialogPtr);
extern int DlgObj_Convert(PyObject *, DialogPtr *);
extern PyObject *CtlObj_New(ControlHandle);
extern int CtlObj_Convert(PyObject *, ControlHandle *);
+extern PyObject *GrafObj_New(GrafPtr);
+extern int GrafObj_Convert(PyObject *, GrafPtr *);
+
extern PyObject *WinObj_WhichWindow(WindowPtr);
#include <QuickDraw.h>
static PyObject *Qd_Error;
-static PyObject *Qd_OpenPort(_self, _args)
- PyObject *_self;
- PyObject *_args;
+/* ---------------------- Object type GrafPort ---------------------- */
+
+PyTypeObject GrafPort_Type;
+
+#define GrafObj_Check(x) ((x)->ob_type == &GrafPort_Type)
+
+typedef struct GrafPortObject {
+ PyObject_HEAD
+ GrafPtr ob_itself;
+} GrafPortObject;
+
+PyObject *GrafObj_New(itself)
+ GrafPtr itself;
{
- PyObject *_res = NULL;
- WindowPtr port;
- if (!PyArg_ParseTuple(_args, "O&",
- WinObj_Convert, &port))
- return NULL;
- OpenPort(port);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
+ GrafPortObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(GrafPortObject, &GrafPort_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ return (PyObject *)it;
}
-
-static PyObject *Qd_InitPort(_self, _args)
- PyObject *_self;
- PyObject *_args;
+GrafObj_Convert(v, p_itself)
+ PyObject *v;
+ GrafPtr *p_itself;
{
- PyObject *_res = NULL;
- WindowPtr port;
- if (!PyArg_ParseTuple(_args, "O&",
- WinObj_Convert, &port))
- return NULL;
- InitPort(port);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
+ if (DlgObj_Check(v) || WinObj_Check(v)) {
+ *p_itself = ((GrafPortObject *)v)->ob_itself;
+ return 1;
+ }
+ if (!GrafObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "GrafPort required");
+ return 0;
+ }
+ *p_itself = ((GrafPortObject *)v)->ob_itself;
+ return 1;
}
-static PyObject *Qd_ClosePort(_self, _args)
- PyObject *_self;
- PyObject *_args;
+static void GrafObj_dealloc(self)
+ GrafPortObject *self;
{
- PyObject *_res = NULL;
- WindowPtr port;
- if (!PyArg_ParseTuple(_args, "O&",
- WinObj_Convert, &port))
- return NULL;
- ClosePort(port);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
+ /* Cleanup of self->ob_itself goes here */
+ PyMem_DEL(self);
}
+static PyMethodDef GrafObj_methods[] = {
+ {NULL, NULL, 0}
+};
+
+PyMethodChain GrafObj_chain = { GrafObj_methods, NULL };
+
+static PyObject *GrafObj_getattr(self, name)
+ GrafPortObject *self;
+ char *name;
+{
+ if ( strcmp(name, "device") == 0 )
+ return PyInt_FromLong((long)self->ob_itself->device);
+ if ( strcmp(name, "portRect") == 0 )
+ return Py_BuildValue("O&", PyMac_BuildRect, &self->ob_itself->portRect);
+ /* XXXX Add more, as needed */
+
+ return Py_FindMethodInChain(&GrafObj_chain, (PyObject *)self, name);
+}
+
+#define GrafObj_setattr NULL
+
+PyTypeObject GrafPort_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "GrafPort", /*tp_name*/
+ sizeof(GrafPortObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) GrafObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) GrafObj_getattr, /*tp_getattr*/
+ (setattrfunc) GrafObj_setattr, /*tp_setattr*/
+};
+
+/* -------------------- End object type GrafPort -------------------- */
+
+
static PyObject *Qd_SetPort(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
- WindowPtr port;
+ GrafPtr port;
if (!PyArg_ParseTuple(_args, "O&",
- WinObj_Convert, &port))
+ GrafObj_Convert, &port))
return NULL;
SetPort(port);
Py_INCREF(Py_None);
PyObject *_args;
{
PyObject *_res = NULL;
- WindowPtr port;
+ GrafPtr port;
if (!PyArg_ParseTuple(_args, ""))
return NULL;
GetPort(&port);
_res = Py_BuildValue("O&",
- WinObj_New, port);
+ GrafObj_New, port);
return _res;
}
PyObject *_args;
{
PyObject *_res = NULL;
- long extra;
- if (!PyArg_ParseTuple(_args, "l",
- &extra))
+ Fixed extra;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetFixed, &extra))
return NULL;
SpaceExtra(extra);
Py_INCREF(Py_None);
PyObject *_args;
{
PyObject *_res = NULL;
- long extra;
- if (!PyArg_ParseTuple(_args, "l",
- &extra))
+ Fixed extra;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetFixed, &extra))
return NULL;
CharExtra(extra);
Py_INCREF(Py_None);
}
static PyMethodDef Qd_methods[] = {
- {"OpenPort", (PyCFunction)Qd_OpenPort, 1,
- "(WindowPtr port) -> None"},
- {"InitPort", (PyCFunction)Qd_InitPort, 1,
- "(WindowPtr port) -> None"},
- {"ClosePort", (PyCFunction)Qd_ClosePort, 1,
- "(WindowPtr port) -> None"},
{"SetPort", (PyCFunction)Qd_SetPort, 1,
- "(WindowPtr port) -> None"},
+ "(GrafPtr port) -> None"},
{"GetPort", (PyCFunction)Qd_GetPort, 1,
- "() -> (WindowPtr port)"},
+ "() -> (GrafPtr port)"},
{"GrafDevice", (PyCFunction)Qd_GrafDevice, 1,
"(short device) -> None"},
{"PortSize", (PyCFunction)Qd_PortSize, 1,
{"TextSize", (PyCFunction)Qd_TextSize, 1,
"(short size) -> None"},
{"SpaceExtra", (PyCFunction)Qd_SpaceExtra, 1,
- "(long extra) -> None"},
+ "(Fixed extra) -> None"},
{"DrawChar", (PyCFunction)Qd_DrawChar, 1,
"(short ch) -> None"},
{"DrawString", (PyCFunction)Qd_DrawString, 1,
{"TextWidth", (PyCFunction)Qd_TextWidth, 1,
"(Buffer textBuf, short firstByte, short byteCount) -> (short _rv)"},
{"CharExtra", (PyCFunction)Qd_CharExtra, 1,
- "(long extra) -> None"},
+ "(Fixed extra) -> None"},
{NULL, NULL, 0}
};
# Create the type objects
-GrafPtr = WindowPtr
-
class TextThingieClass(FixedInputBufferType):
def getargsCheck(self, name):
pass
TextThingie = TextThingieClass(None)
# These are temporary!
-Fixed = long
RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
PicHandle = OpaqueByValueType("PicHandle", "ResObj")
PolyHandle = OpaqueByValueType("PolyHandle", "ResObj")
PixPatHandle = OpaqueByValueType("PixPatHandle", "ResObj")
PatHandle = OpaqueByValueType("PatHandle", "ResObj")
CursHandle = OpaqueByValueType("CursHandle", "ResObj")
+CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj")
+GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj")
includestuff = includestuff + """
#include <%s>""" % MACHEADERFILE + """
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
"""
-
-class MyObjectDefinition(GlobalObjectDefinition):
+## not yet...
+##
+##class Region_ObjectDefinition(GlobalObjectDefinition):
+## def outputCheckNewArg(self):
+## Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+## def outputFreeIt(self, itselfname):
+## Output("DisposeRegion(%s);", itselfname)
+##
+##class Polygon_ObjectDefinition(GlobalObjectDefinition):
+## def outputCheckNewArg(self):
+## Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+## def outputFreeIt(self, itselfname):
+## Output("KillPoly(%s);", itselfname)
+
+class MyGRObjectDefinition(GlobalObjectDefinition):
def outputCheckNewArg(self):
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
def outputCheckConvertArg(self):
- OutLbrace("if (DlgObj_Check(v))")
- Output("*p_itself = ((WindowObject *)v)->ob_itself;")
+ OutLbrace("if (DlgObj_Check(v) || WinObj_Check(v))")
+ Output("*p_itself = ((GrafPortObject *)v)->ob_itself;")
Output("return 1;")
OutRbrace()
- Out("""
- if (v == Py_None) { *p_itself = NULL; return 1; }
- if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
+ def outputGetattrHook(self):
+ Output("""if ( strcmp(name, "device") == 0 )
+ return PyInt_FromLong((long)self->ob_itself->device);
+ if ( strcmp(name, "portRect") == 0 )
+ return Py_BuildValue("O&", PyMac_BuildRect, &self->ob_itself->portRect);
+ /* XXXX Add more, as needed */
""")
- def outputFreeIt(self, itselfname):
- Output("DisposeWindow(%s);", itselfname)
-
-# From here on it's basically all boiler plate...
# Create the generator groups and link them
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
-##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
-##module.addobject(object)
+##r_object = Region_ObjectDefinition('Region', 'QdRgn', 'RgnHandle')
+##po_object = Polygon_ObjectDefinition('Polygon', 'QdPgn', 'PolyHandle')
+##module.addobject(r_object)
+##module.addobject(po_object)
+gr_object = MyGRObjectDefinition("GrafPort", "GrafObj", "GrafPtr")
+module.addobject(gr_object)
+
# Create the generator classes used to populate the lists
Function = OSErrFunctionGenerator
# add the populated lists to the generator groups
# (in a different wordl the scan program would generate this)
for f in functions: module.add(f)
-for f in methods: object.add(f)
+##for f in r_methods: r_object.add(f)
+##for f in po_methods: po_object.add(f)
# generate output (open the output file as late as possible)
SetOutputFileName(OUTPUTFILE)