]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Added (minimal) support for a GrafPort type
authorJack Jansen <jack.jansen@cwi.nl>
Wed, 15 Nov 1995 15:18:01 +0000 (15:18 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Wed, 15 Nov 1995 15:18:01 +0000 (15:18 +0000)
Mac/Modules/qd/Qdmodule.c
Mac/Modules/qd/qdgen.py
Mac/Modules/qd/qdscan.py
Mac/Modules/qd/qdsupport.py

index eecdd12410dcd642a1011086ff8341038e8f964d..7174d3b72f5c4881a52efc0b29b518ccb35548a3 100644 (file)
@@ -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}
 };
 
index 19e887dae787fa09230ece17d547b24be6e2ce4a..3394b5bf3797b3e66f3e1f9a0f82c9ffcc7b40e5 100644 (file)
@@ -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),
 )
index 408c9c2eadb7b0334b55dae6ab8fab82a6f31396..229db4f672b622770291a0ae84bcc7f687f71a0c 100644 (file)
@@ -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',
index 96d54f16d055db4f7aaf18e690e0a541f4bea4f1..88215a6d5c4e1cd8ba6e89727f6b3a013c85cb02 100644 (file)
@@ -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)