summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/qd
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1995-11-15 15:18:01 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1995-11-15 15:18:01 (GMT)
commit330381cbbb394e7e7a6841879b22218884750ca2 (patch)
treefa8f57b2d389854c6c59812ecf57b88e22cb343c /Mac/Modules/qd
parent7830ab8f499d7e42d5acdeaf5ff048c7e49a889e (diff)
downloadcpython-330381cbbb394e7e7a6841879b22218884750ca2.zip
cpython-330381cbbb394e7e7a6841879b22218884750ca2.tar.gz
cpython-330381cbbb394e7e7a6841879b22218884750ca2.tar.bz2
Added (minimal) support for a GrafPort type
Diffstat (limited to 'Mac/Modules/qd')
-rw-r--r--Mac/Modules/qd/Qdmodule.c150
-rw-r--r--Mac/Modules/qd/qdgen.py15
-rw-r--r--Mac/Modules/qd/qdscan.py17
-rw-r--r--Mac/Modules/qd/qdsupport.py51
4 files changed, 139 insertions, 94 deletions
diff --git a/Mac/Modules/qd/Qdmodule.c b/Mac/Modules/qd/Qdmodule.c
index eecdd12..7174d3b 100644
--- a/Mac/Modules/qd/Qdmodule.c
+++ b/Mac/Modules/qd/Qdmodule.c
@@ -19,6 +19,8 @@ extern int ResObj_Convert(PyObject *, Handle *);
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 *);
@@ -31,6 +33,9 @@ extern int MenuObj_Convert(PyObject *, MenuHandle *);
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>
@@ -40,59 +45,96 @@ extern PyObject *WinObj_WhichWindow(WindowPtr);
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);
@@ -105,12 +147,12 @@ static PyObject *Qd_GetPort(_self, _args)
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;
}
@@ -2378,9 +2420,9 @@ static PyObject *Qd_SpaceExtra(_self, _args)
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);
@@ -2504,9 +2546,9 @@ static PyObject *Qd_CharExtra(_self, _args)
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);
@@ -2515,16 +2557,10 @@ static PyObject *Qd_CharExtra(_self, _args)
}
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,
@@ -2788,7 +2824,7 @@ static PyMethodDef Qd_methods[] = {
{"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,
@@ -2802,7 +2838,7 @@ static PyMethodDef Qd_methods[] = {
{"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}
};
diff --git a/Mac/Modules/qd/qdgen.py b/Mac/Modules/qd/qdgen.py
index 19e887d..3394b5b 100644
--- a/Mac/Modules/qd/qdgen.py
+++ b/Mac/Modules/qd/qdgen.py
@@ -1,20 +1,5 @@
# 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',
(GrafPtr, 'port', InMode),
)
diff --git a/Mac/Modules/qd/qdscan.py b/Mac/Modules/qd/qdscan.py
index 408c9c2..229db4f 100644
--- a/Mac/Modules/qd/qdscan.py
+++ b/Mac/Modules/qd/qdscan.py
@@ -49,9 +49,12 @@ class MyScanner(Scanner):
listname = "functions"
if arglist:
t, n, m = arglist[0]
- if t in ("WindowPtr", "WindowPeek", "WindowRef") and m == "InMode":
- classname = "Method"
- listname = "methods"
+## elif t == "PolyHandle" and m == "InMode":
+## classname = "Method"
+## listname = "p_methods"
+## elif t == "RgnHandle" and m == "InMode":
+## classname = "Method"
+## listname = "r_methods"
return classname, listname
def makeblacklistnames(self):
@@ -61,14 +64,18 @@ class MyScanner(Scanner):
'StdLine',
'StdComment',
'StdGetPic',
- 'StdLine',
+ 'OpenPort',
+ 'InitPort',
+ 'ClosePort',
+ 'OpenCPort',
+ 'InitCPort',
+ 'CloseCPort',
]
def makeblacklisttypes(self):
return [
'BitMap_ptr',
'CCrsrHandle',
- 'CGrafPtr',
'CIconHandle',
'CQDProcs',
'CSpecArray',
diff --git a/Mac/Modules/qd/qdsupport.py b/Mac/Modules/qd/qdsupport.py
index 96d54f1..88215a6 100644
--- a/Mac/Modules/qd/qdsupport.py
+++ b/Mac/Modules/qd/qdsupport.py
@@ -25,8 +25,6 @@ from macsupport import *
# Create the type objects
-GrafPtr = WindowPtr
-
class TextThingieClass(FixedInputBufferType):
def getargsCheck(self, name):
pass
@@ -34,7 +32,6 @@ class TextThingieClass(FixedInputBufferType):
TextThingie = TextThingieClass(None)
# These are temporary!
-Fixed = long
RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
PicHandle = OpaqueByValueType("PicHandle", "ResObj")
PolyHandle = OpaqueByValueType("PolyHandle", "ResObj")
@@ -42,6 +39,8 @@ PixMapHandle = OpaqueByValueType("PixMapHandle", "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 + """
@@ -49,28 +48,45 @@ includestuff = includestuff + """
#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
@@ -85,7 +101,8 @@ execfile(INPUTFILE)
# 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)