Added (minimal) support for a GrafPort type

This commit is contained in:
Jack Jansen 1995-11-15 15:18:01 +00:00
parent 7830ab8f49
commit 330381cbbb
4 changed files with 137 additions and 92 deletions

View File

@ -19,6 +19,8 @@ extern int ResObj_Convert(PyObject *, Handle *);
extern PyObject *WinObj_New(WindowPtr); extern PyObject *WinObj_New(WindowPtr);
extern int WinObj_Convert(PyObject *, 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 PyObject *DlgObj_New(DialogPtr);
extern int DlgObj_Convert(PyObject *, DialogPtr *); extern int DlgObj_Convert(PyObject *, DialogPtr *);
@ -31,6 +33,9 @@ extern int MenuObj_Convert(PyObject *, MenuHandle *);
extern PyObject *CtlObj_New(ControlHandle); extern PyObject *CtlObj_New(ControlHandle);
extern int CtlObj_Convert(PyObject *, ControlHandle *); extern int CtlObj_Convert(PyObject *, ControlHandle *);
extern PyObject *GrafObj_New(GrafPtr);
extern int GrafObj_Convert(PyObject *, GrafPtr *);
extern PyObject *WinObj_WhichWindow(WindowPtr); extern PyObject *WinObj_WhichWindow(WindowPtr);
#include <QuickDraw.h> #include <QuickDraw.h>
@ -40,59 +45,96 @@ extern PyObject *WinObj_WhichWindow(WindowPtr);
static PyObject *Qd_Error; static PyObject *Qd_Error;
static PyObject *Qd_OpenPort(_self, _args) /* ---------------------- Object type GrafPort ---------------------- */
PyObject *_self;
PyObject *_args; 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; GrafPortObject *it;
WindowPtr port; if (itself == NULL) return PyMac_Error(resNotFound);
if (!PyArg_ParseTuple(_args, "O&", it = PyObject_NEW(GrafPortObject, &GrafPort_Type);
WinObj_Convert, &port)) if (it == NULL) return NULL;
return NULL; it->ob_itself = itself;
OpenPort(port); return (PyObject *)it;
Py_INCREF(Py_None); }
_res = Py_None; GrafObj_Convert(v, p_itself)
return _res; PyObject *v;
GrafPtr *p_itself;
{
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_InitPort(_self, _args) static void GrafObj_dealloc(self)
PyObject *_self; GrafPortObject *self;
PyObject *_args;
{ {
PyObject *_res = NULL; /* Cleanup of self->ob_itself goes here */
WindowPtr port; PyMem_DEL(self);
if (!PyArg_ParseTuple(_args, "O&",
WinObj_Convert, &port))
return NULL;
InitPort(port);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
} }
static PyObject *Qd_ClosePort(_self, _args) static PyMethodDef GrafObj_methods[] = {
PyObject *_self; {NULL, NULL, 0}
PyObject *_args; };
PyMethodChain GrafObj_chain = { GrafObj_methods, NULL };
static PyObject *GrafObj_getattr(self, name)
GrafPortObject *self;
char *name;
{ {
PyObject *_res = NULL; if ( strcmp(name, "device") == 0 )
WindowPtr port; return PyInt_FromLong((long)self->ob_itself->device);
if (!PyArg_ParseTuple(_args, "O&", if ( strcmp(name, "portRect") == 0 )
WinObj_Convert, &port)) return Py_BuildValue("O&", PyMac_BuildRect, &self->ob_itself->portRect);
return NULL; /* XXXX Add more, as needed */
ClosePort(port);
Py_INCREF(Py_None); return Py_FindMethodInChain(&GrafObj_chain, (PyObject *)self, name);
_res = Py_None;
return _res;
} }
#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) static PyObject *Qd_SetPort(_self, _args)
PyObject *_self; PyObject *_self;
PyObject *_args; PyObject *_args;
{ {
PyObject *_res = NULL; PyObject *_res = NULL;
WindowPtr port; GrafPtr port;
if (!PyArg_ParseTuple(_args, "O&", if (!PyArg_ParseTuple(_args, "O&",
WinObj_Convert, &port)) GrafObj_Convert, &port))
return NULL; return NULL;
SetPort(port); SetPort(port);
Py_INCREF(Py_None); Py_INCREF(Py_None);
@ -105,12 +147,12 @@ static PyObject *Qd_GetPort(_self, _args)
PyObject *_args; PyObject *_args;
{ {
PyObject *_res = NULL; PyObject *_res = NULL;
WindowPtr port; GrafPtr port;
if (!PyArg_ParseTuple(_args, "")) if (!PyArg_ParseTuple(_args, ""))
return NULL; return NULL;
GetPort(&port); GetPort(&port);
_res = Py_BuildValue("O&", _res = Py_BuildValue("O&",
WinObj_New, port); GrafObj_New, port);
return _res; return _res;
} }
@ -2378,9 +2420,9 @@ static PyObject *Qd_SpaceExtra(_self, _args)
PyObject *_args; PyObject *_args;
{ {
PyObject *_res = NULL; PyObject *_res = NULL;
long extra; Fixed extra;
if (!PyArg_ParseTuple(_args, "l", if (!PyArg_ParseTuple(_args, "O&",
&extra)) PyMac_GetFixed, &extra))
return NULL; return NULL;
SpaceExtra(extra); SpaceExtra(extra);
Py_INCREF(Py_None); Py_INCREF(Py_None);
@ -2504,9 +2546,9 @@ static PyObject *Qd_CharExtra(_self, _args)
PyObject *_args; PyObject *_args;
{ {
PyObject *_res = NULL; PyObject *_res = NULL;
long extra; Fixed extra;
if (!PyArg_ParseTuple(_args, "l", if (!PyArg_ParseTuple(_args, "O&",
&extra)) PyMac_GetFixed, &extra))
return NULL; return NULL;
CharExtra(extra); CharExtra(extra);
Py_INCREF(Py_None); Py_INCREF(Py_None);
@ -2515,16 +2557,10 @@ static PyObject *Qd_CharExtra(_self, _args)
} }
static PyMethodDef Qd_methods[] = { 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, {"SetPort", (PyCFunction)Qd_SetPort, 1,
"(WindowPtr port) -> None"}, "(GrafPtr port) -> None"},
{"GetPort", (PyCFunction)Qd_GetPort, 1, {"GetPort", (PyCFunction)Qd_GetPort, 1,
"() -> (WindowPtr port)"}, "() -> (GrafPtr port)"},
{"GrafDevice", (PyCFunction)Qd_GrafDevice, 1, {"GrafDevice", (PyCFunction)Qd_GrafDevice, 1,
"(short device) -> None"}, "(short device) -> None"},
{"PortSize", (PyCFunction)Qd_PortSize, 1, {"PortSize", (PyCFunction)Qd_PortSize, 1,
@ -2788,7 +2824,7 @@ static PyMethodDef Qd_methods[] = {
{"TextSize", (PyCFunction)Qd_TextSize, 1, {"TextSize", (PyCFunction)Qd_TextSize, 1,
"(short size) -> None"}, "(short size) -> None"},
{"SpaceExtra", (PyCFunction)Qd_SpaceExtra, 1, {"SpaceExtra", (PyCFunction)Qd_SpaceExtra, 1,
"(long extra) -> None"}, "(Fixed extra) -> None"},
{"DrawChar", (PyCFunction)Qd_DrawChar, 1, {"DrawChar", (PyCFunction)Qd_DrawChar, 1,
"(short ch) -> None"}, "(short ch) -> None"},
{"DrawString", (PyCFunction)Qd_DrawString, 1, {"DrawString", (PyCFunction)Qd_DrawString, 1,
@ -2802,7 +2838,7 @@ static PyMethodDef Qd_methods[] = {
{"TextWidth", (PyCFunction)Qd_TextWidth, 1, {"TextWidth", (PyCFunction)Qd_TextWidth, 1,
"(Buffer textBuf, short firstByte, short byteCount) -> (short _rv)"}, "(Buffer textBuf, short firstByte, short byteCount) -> (short _rv)"},
{"CharExtra", (PyCFunction)Qd_CharExtra, 1, {"CharExtra", (PyCFunction)Qd_CharExtra, 1,
"(long extra) -> None"}, "(Fixed extra) -> None"},
{NULL, NULL, 0} {NULL, NULL, 0}
}; };

View File

@ -1,20 +1,5 @@
# Generated from 'Sap:CodeWarrior7:Metrowerks CodeWarrior:MacOS Support:Headers:Universal Headers:QuickDraw.h' # Generated from 'Sap:CodeWarrior7:Metrowerks CodeWarrior:MacOS Support:Headers:Universal Headers:QuickDraw.h'
f = Function(void, 'OpenPort',
(GrafPtr, 'port', InMode),
)
functions.append(f)
f = Function(void, 'InitPort',
(GrafPtr, 'port', InMode),
)
functions.append(f)
f = Function(void, 'ClosePort',
(GrafPtr, 'port', InMode),
)
functions.append(f)
f = Function(void, 'SetPort', f = Function(void, 'SetPort',
(GrafPtr, 'port', InMode), (GrafPtr, 'port', InMode),
) )

View File

@ -49,9 +49,12 @@ class MyScanner(Scanner):
listname = "functions" listname = "functions"
if arglist: if arglist:
t, n, m = arglist[0] t, n, m = arglist[0]
if t in ("WindowPtr", "WindowPeek", "WindowRef") and m == "InMode": ## elif t == "PolyHandle" and m == "InMode":
classname = "Method" ## classname = "Method"
listname = "methods" ## listname = "p_methods"
## elif t == "RgnHandle" and m == "InMode":
## classname = "Method"
## listname = "r_methods"
return classname, listname return classname, listname
def makeblacklistnames(self): def makeblacklistnames(self):
@ -61,14 +64,18 @@ class MyScanner(Scanner):
'StdLine', 'StdLine',
'StdComment', 'StdComment',
'StdGetPic', 'StdGetPic',
'StdLine', 'OpenPort',
'InitPort',
'ClosePort',
'OpenCPort',
'InitCPort',
'CloseCPort',
] ]
def makeblacklisttypes(self): def makeblacklisttypes(self):
return [ return [
'BitMap_ptr', 'BitMap_ptr',
'CCrsrHandle', 'CCrsrHandle',
'CGrafPtr',
'CIconHandle', 'CIconHandle',
'CQDProcs', 'CQDProcs',
'CSpecArray', 'CSpecArray',

View File

@ -25,8 +25,6 @@ from macsupport import *
# Create the type objects # Create the type objects
GrafPtr = WindowPtr
class TextThingieClass(FixedInputBufferType): class TextThingieClass(FixedInputBufferType):
def getargsCheck(self, name): def getargsCheck(self, name):
pass pass
@ -34,7 +32,6 @@ class TextThingieClass(FixedInputBufferType):
TextThingie = TextThingieClass(None) TextThingie = TextThingieClass(None)
# These are temporary! # These are temporary!
Fixed = long
RgnHandle = OpaqueByValueType("RgnHandle", "ResObj") RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
PicHandle = OpaqueByValueType("PicHandle", "ResObj") PicHandle = OpaqueByValueType("PicHandle", "ResObj")
PolyHandle = OpaqueByValueType("PolyHandle", "ResObj") PolyHandle = OpaqueByValueType("PolyHandle", "ResObj")
@ -42,6 +39,8 @@ PixMapHandle = OpaqueByValueType("PixMapHandle", "ResObj")
PixPatHandle = OpaqueByValueType("PixPatHandle", "ResObj") PixPatHandle = OpaqueByValueType("PixPatHandle", "ResObj")
PatHandle = OpaqueByValueType("PatHandle", "ResObj") PatHandle = OpaqueByValueType("PatHandle", "ResObj")
CursHandle = OpaqueByValueType("CursHandle", "ResObj") CursHandle = OpaqueByValueType("CursHandle", "ResObj")
CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj")
GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj")
includestuff = includestuff + """ includestuff = includestuff + """
#include <%s>""" % MACHEADERFILE + """ #include <%s>""" % MACHEADERFILE + """
@ -49,28 +48,45 @@ includestuff = includestuff + """
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
""" """
## 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 MyObjectDefinition(GlobalObjectDefinition): class MyGRObjectDefinition(GlobalObjectDefinition):
def outputCheckNewArg(self): def outputCheckNewArg(self):
Output("if (itself == NULL) return PyMac_Error(resNotFound);") Output("if (itself == NULL) return PyMac_Error(resNotFound);")
def outputCheckConvertArg(self): def outputCheckConvertArg(self):
OutLbrace("if (DlgObj_Check(v))") OutLbrace("if (DlgObj_Check(v) || WinObj_Check(v))")
Output("*p_itself = ((WindowObject *)v)->ob_itself;") Output("*p_itself = ((GrafPortObject *)v)->ob_itself;")
Output("return 1;") Output("return 1;")
OutRbrace() OutRbrace()
Out(""" def outputGetattrHook(self):
if (v == Py_None) { *p_itself = NULL; return 1; } Output("""if ( strcmp(name, "device") == 0 )
if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; } 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 # Create the generator groups and link them
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) ##r_object = Region_ObjectDefinition('Region', 'QdRgn', 'RgnHandle')
##module.addobject(object) ##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 # Create the generator classes used to populate the lists
Function = OSErrFunctionGenerator Function = OSErrFunctionGenerator
@ -85,7 +101,8 @@ execfile(INPUTFILE)
# add the populated lists to the generator groups # add the populated lists to the generator groups
# (in a different wordl the scan program would generate this) # (in a different wordl the scan program would generate this)
for f in functions: module.add(f) 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) # generate output (open the output file as late as possible)
SetOutputFileName(OUTPUTFILE) SetOutputFileName(OUTPUTFILE)