Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 330381c

Browse files
committed
Added (minimal) support for a GrafPort type
1 parent 7830ab8 commit 330381c

4 files changed

Lines changed: 139 additions & 94 deletions

File tree

Mac/Modules/qd/Qdmodule.c

Lines changed: 93 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ extern int ResObj_Convert(PyObject *, Handle *);
1919

2020
extern PyObject *WinObj_New(WindowPtr);
2121
extern int WinObj_Convert(PyObject *, WindowPtr *);
22+
extern PyTypeObject Window_Type;
23+
#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
2224

2325
extern PyObject *DlgObj_New(DialogPtr);
2426
extern int DlgObj_Convert(PyObject *, DialogPtr *);
@@ -31,6 +33,9 @@ extern int MenuObj_Convert(PyObject *, MenuHandle *);
3133
extern PyObject *CtlObj_New(ControlHandle);
3234
extern int CtlObj_Convert(PyObject *, ControlHandle *);
3335

36+
extern PyObject *GrafObj_New(GrafPtr);
37+
extern int GrafObj_Convert(PyObject *, GrafPtr *);
38+
3439
extern PyObject *WinObj_WhichWindow(WindowPtr);
3540

3641
#include <QuickDraw.h>
@@ -40,59 +45,96 @@ extern PyObject *WinObj_WhichWindow(WindowPtr);
4045

4146
static PyObject *Qd_Error;
4247

43-
static PyObject *Qd_OpenPort(_self, _args)
44-
PyObject *_self;
45-
PyObject *_args;
48+
/* ---------------------- Object type GrafPort ---------------------- */
49+
50+
PyTypeObject GrafPort_Type;
51+
52+
#define GrafObj_Check(x) ((x)->ob_type == &GrafPort_Type)
53+
54+
typedef struct GrafPortObject {
55+
PyObject_HEAD
56+
GrafPtr ob_itself;
57+
} GrafPortObject;
58+
59+
PyObject *GrafObj_New(itself)
60+
GrafPtr itself;
4661
{
47-
PyObject *_res = NULL;
48-
WindowPtr port;
49-
if (!PyArg_ParseTuple(_args, "O&",
50-
WinObj_Convert, &port))
51-
return NULL;
52-
OpenPort(port);
53-
Py_INCREF(Py_None);
54-
_res = Py_None;
55-
return _res;
62+
GrafPortObject *it;
63+
if (itself == NULL) return PyMac_Error(resNotFound);
64+
it = PyObject_NEW(GrafPortObject, &GrafPort_Type);
65+
if (it == NULL) return NULL;
66+
it->ob_itself = itself;
67+
return (PyObject *)it;
5668
}
57-
58-
static PyObject *Qd_InitPort(_self, _args)
59-
PyObject *_self;
60-
PyObject *_args;
69+
GrafObj_Convert(v, p_itself)
70+
PyObject *v;
71+
GrafPtr *p_itself;
6172
{
62-
PyObject *_res = NULL;
63-
WindowPtr port;
64-
if (!PyArg_ParseTuple(_args, "O&",
65-
WinObj_Convert, &port))
66-
return NULL;
67-
InitPort(port);
68-
Py_INCREF(Py_None);
69-
_res = Py_None;
70-
return _res;
73+
if (DlgObj_Check(v) || WinObj_Check(v)) {
74+
*p_itself = ((GrafPortObject *)v)->ob_itself;
75+
return 1;
76+
}
77+
if (!GrafObj_Check(v))
78+
{
79+
PyErr_SetString(PyExc_TypeError, "GrafPort required");
80+
return 0;
81+
}
82+
*p_itself = ((GrafPortObject *)v)->ob_itself;
83+
return 1;
7184
}
7285

73-
static PyObject *Qd_ClosePort(_self, _args)
74-
PyObject *_self;
75-
PyObject *_args;
86+
static void GrafObj_dealloc(self)
87+
GrafPortObject *self;
7688
{
77-
PyObject *_res = NULL;
78-
WindowPtr port;
79-
if (!PyArg_ParseTuple(_args, "O&",
80-
WinObj_Convert, &port))
81-
return NULL;
82-
ClosePort(port);
83-
Py_INCREF(Py_None);
84-
_res = Py_None;
85-
return _res;
89+
/* Cleanup of self->ob_itself goes here */
90+
PyMem_DEL(self);
8691
}
8792

93+
static PyMethodDef GrafObj_methods[] = {
94+
{NULL, NULL, 0}
95+
};
96+
97+
PyMethodChain GrafObj_chain = { GrafObj_methods, NULL };
98+
99+
static PyObject *GrafObj_getattr(self, name)
100+
GrafPortObject *self;
101+
char *name;
102+
{
103+
if ( strcmp(name, "device") == 0 )
104+
return PyInt_FromLong((long)self->ob_itself->device);
105+
if ( strcmp(name, "portRect") == 0 )
106+
return Py_BuildValue("O&", PyMac_BuildRect, &self->ob_itself->portRect);
107+
/* XXXX Add more, as needed */
108+
109+
return Py_FindMethodInChain(&GrafObj_chain, (PyObject *)self, name);
110+
}
111+
112+
#define GrafObj_setattr NULL
113+
114+
PyTypeObject GrafPort_Type = {
115+
PyObject_HEAD_INIT(&PyType_Type)
116+
0, /*ob_size*/
117+
"GrafPort", /*tp_name*/
118+
sizeof(GrafPortObject), /*tp_basicsize*/
119+
0, /*tp_itemsize*/
120+
/* methods */
121+
(destructor) GrafObj_dealloc, /*tp_dealloc*/
122+
0, /*tp_print*/
123+
(getattrfunc) GrafObj_getattr, /*tp_getattr*/
124+
(setattrfunc) GrafObj_setattr, /*tp_setattr*/
125+
};
126+
127+
/* -------------------- End object type GrafPort -------------------- */
128+
129+
88130
static PyObject *Qd_SetPort(_self, _args)
89131
PyObject *_self;
90132
PyObject *_args;
91133
{
92134
PyObject *_res = NULL;
93-
WindowPtr port;
135+
GrafPtr port;
94136
if (!PyArg_ParseTuple(_args, "O&",
95-
WinObj_Convert, &port))
137+
GrafObj_Convert, &port))
96138
return NULL;
97139
SetPort(port);
98140
Py_INCREF(Py_None);
@@ -105,12 +147,12 @@ static PyObject *Qd_GetPort(_self, _args)
105147
PyObject *_args;
106148
{
107149
PyObject *_res = NULL;
108-
WindowPtr port;
150+
GrafPtr port;
109151
if (!PyArg_ParseTuple(_args, ""))
110152
return NULL;
111153
GetPort(&port);
112154
_res = Py_BuildValue("O&",
113-
WinObj_New, port);
155+
GrafObj_New, port);
114156
return _res;
115157
}
116158

@@ -2378,9 +2420,9 @@ static PyObject *Qd_SpaceExtra(_self, _args)
23782420
PyObject *_args;
23792421
{
23802422
PyObject *_res = NULL;
2381-
long extra;
2382-
if (!PyArg_ParseTuple(_args, "l",
2383-
&extra))
2423+
Fixed extra;
2424+
if (!PyArg_ParseTuple(_args, "O&",
2425+
PyMac_GetFixed, &extra))
23842426
return NULL;
23852427
SpaceExtra(extra);
23862428
Py_INCREF(Py_None);
@@ -2504,9 +2546,9 @@ static PyObject *Qd_CharExtra(_self, _args)
25042546
PyObject *_args;
25052547
{
25062548
PyObject *_res = NULL;
2507-
long extra;
2508-
if (!PyArg_ParseTuple(_args, "l",
2509-
&extra))
2549+
Fixed extra;
2550+
if (!PyArg_ParseTuple(_args, "O&",
2551+
PyMac_GetFixed, &extra))
25102552
return NULL;
25112553
CharExtra(extra);
25122554
Py_INCREF(Py_None);
@@ -2515,16 +2557,10 @@ static PyObject *Qd_CharExtra(_self, _args)
25152557
}
25162558

25172559
static PyMethodDef Qd_methods[] = {
2518-
{"OpenPort", (PyCFunction)Qd_OpenPort, 1,
2519-
"(WindowPtr port) -> None"},
2520-
{"InitPort", (PyCFunction)Qd_InitPort, 1,
2521-
"(WindowPtr port) -> None"},
2522-
{"ClosePort", (PyCFunction)Qd_ClosePort, 1,
2523-
"(WindowPtr port) -> None"},
25242560
{"SetPort", (PyCFunction)Qd_SetPort, 1,
2525-
"(WindowPtr port) -> None"},
2561+
"(GrafPtr port) -> None"},
25262562
{"GetPort", (PyCFunction)Qd_GetPort, 1,
2527-
"() -> (WindowPtr port)"},
2563+
"() -> (GrafPtr port)"},
25282564
{"GrafDevice", (PyCFunction)Qd_GrafDevice, 1,
25292565
"(short device) -> None"},
25302566
{"PortSize", (PyCFunction)Qd_PortSize, 1,
@@ -2788,7 +2824,7 @@ static PyMethodDef Qd_methods[] = {
27882824
{"TextSize", (PyCFunction)Qd_TextSize, 1,
27892825
"(short size) -> None"},
27902826
{"SpaceExtra", (PyCFunction)Qd_SpaceExtra, 1,
2791-
"(long extra) -> None"},
2827+
"(Fixed extra) -> None"},
27922828
{"DrawChar", (PyCFunction)Qd_DrawChar, 1,
27932829
"(short ch) -> None"},
27942830
{"DrawString", (PyCFunction)Qd_DrawString, 1,
@@ -2802,7 +2838,7 @@ static PyMethodDef Qd_methods[] = {
28022838
{"TextWidth", (PyCFunction)Qd_TextWidth, 1,
28032839
"(Buffer textBuf, short firstByte, short byteCount) -> (short _rv)"},
28042840
{"CharExtra", (PyCFunction)Qd_CharExtra, 1,
2805-
"(long extra) -> None"},
2841+
"(Fixed extra) -> None"},
28062842
{NULL, NULL, 0}
28072843
};
28082844

Mac/Modules/qd/qdgen.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
# Generated from 'Sap:CodeWarrior7:Metrowerks CodeWarrior:MacOS Support:Headers:Universal Headers:QuickDraw.h'
22

3-
f = Function(void, 'OpenPort',
4-
(GrafPtr, 'port', InMode),
5-
)
6-
functions.append(f)
7-
8-
f = Function(void, 'InitPort',
9-
(GrafPtr, 'port', InMode),
10-
)
11-
functions.append(f)
12-
13-
f = Function(void, 'ClosePort',
14-
(GrafPtr, 'port', InMode),
15-
)
16-
functions.append(f)
17-
183
f = Function(void, 'SetPort',
194
(GrafPtr, 'port', InMode),
205
)

Mac/Modules/qd/qdscan.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ def destination(self, type, name, arglist):
4949
listname = "functions"
5050
if arglist:
5151
t, n, m = arglist[0]
52-
if t in ("WindowPtr", "WindowPeek", "WindowRef") and m == "InMode":
53-
classname = "Method"
54-
listname = "methods"
52+
## elif t == "PolyHandle" and m == "InMode":
53+
## classname = "Method"
54+
## listname = "p_methods"
55+
## elif t == "RgnHandle" and m == "InMode":
56+
## classname = "Method"
57+
## listname = "r_methods"
5558
return classname, listname
5659

5760
def makeblacklistnames(self):
@@ -61,14 +64,18 @@ def makeblacklistnames(self):
6164
'StdLine',
6265
'StdComment',
6366
'StdGetPic',
64-
'StdLine',
67+
'OpenPort',
68+
'InitPort',
69+
'ClosePort',
70+
'OpenCPort',
71+
'InitCPort',
72+
'CloseCPort',
6573
]
6674

6775
def makeblacklisttypes(self):
6876
return [
6977
'BitMap_ptr',
7078
'CCrsrHandle',
71-
'CGrafPtr',
7279
'CIconHandle',
7380
'CQDProcs',
7481
'CSpecArray',

Mac/Modules/qd/qdsupport.py

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,52 +25,68 @@
2525

2626
# Create the type objects
2727

28-
GrafPtr = WindowPtr
29-
3028
class TextThingieClass(FixedInputBufferType):
3129
def getargsCheck(self, name):
3230
pass
3331

3432
TextThingie = TextThingieClass(None)
3533

3634
# These are temporary!
37-
Fixed = long
3835
RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
3936
PicHandle = OpaqueByValueType("PicHandle", "ResObj")
4037
PolyHandle = OpaqueByValueType("PolyHandle", "ResObj")
4138
PixMapHandle = OpaqueByValueType("PixMapHandle", "ResObj")
4239
PixPatHandle = OpaqueByValueType("PixPatHandle", "ResObj")
4340
PatHandle = OpaqueByValueType("PatHandle", "ResObj")
4441
CursHandle = OpaqueByValueType("CursHandle", "ResObj")
42+
CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj")
43+
GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj")
4544

4645
includestuff = includestuff + """
4746
#include <%s>""" % MACHEADERFILE + """
4847
#include <Desk.h>
4948
5049
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
5150
"""
52-
53-
class MyObjectDefinition(GlobalObjectDefinition):
51+
## not yet...
52+
##
53+
##class Region_ObjectDefinition(GlobalObjectDefinition):
54+
## def outputCheckNewArg(self):
55+
## Output("if (itself == NULL) return PyMac_Error(resNotFound);")
56+
## def outputFreeIt(self, itselfname):
57+
## Output("DisposeRegion(%s);", itselfname)
58+
##
59+
##class Polygon_ObjectDefinition(GlobalObjectDefinition):
60+
## def outputCheckNewArg(self):
61+
## Output("if (itself == NULL) return PyMac_Error(resNotFound);")
62+
## def outputFreeIt(self, itselfname):
63+
## Output("KillPoly(%s);", itselfname)
64+
65+
class MyGRObjectDefinition(GlobalObjectDefinition):
5466
def outputCheckNewArg(self):
5567
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
5668
def outputCheckConvertArg(self):
57-
OutLbrace("if (DlgObj_Check(v))")
58-
Output("*p_itself = ((WindowObject *)v)->ob_itself;")
69+
OutLbrace("if (DlgObj_Check(v) || WinObj_Check(v))")
70+
Output("*p_itself = ((GrafPortObject *)v)->ob_itself;")
5971
Output("return 1;")
6072
OutRbrace()
61-
Out("""
62-
if (v == Py_None) { *p_itself = NULL; return 1; }
63-
if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
73+
def outputGetattrHook(self):
74+
Output("""if ( strcmp(name, "device") == 0 )
75+
return PyInt_FromLong((long)self->ob_itself->device);
76+
if ( strcmp(name, "portRect") == 0 )
77+
return Py_BuildValue("O&", PyMac_BuildRect, &self->ob_itself->portRect);
78+
/* XXXX Add more, as needed */
6479
""")
65-
def outputFreeIt(self, itselfname):
66-
Output("DisposeWindow(%s);", itselfname)
67-
68-
# From here on it's basically all boiler plate...
6980

7081
# Create the generator groups and link them
7182
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
72-
##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
73-
##module.addobject(object)
83+
##r_object = Region_ObjectDefinition('Region', 'QdRgn', 'RgnHandle')
84+
##po_object = Polygon_ObjectDefinition('Polygon', 'QdPgn', 'PolyHandle')
85+
##module.addobject(r_object)
86+
##module.addobject(po_object)
87+
gr_object = MyGRObjectDefinition("GrafPort", "GrafObj", "GrafPtr")
88+
module.addobject(gr_object)
89+
7490

7591
# Create the generator classes used to populate the lists
7692
Function = OSErrFunctionGenerator
@@ -85,7 +101,8 @@ def outputFreeIt(self, itselfname):
85101
# add the populated lists to the generator groups
86102
# (in a different wordl the scan program would generate this)
87103
for f in functions: module.add(f)
88-
for f in methods: object.add(f)
104+
##for f in r_methods: r_object.add(f)
105+
##for f in po_methods: po_object.add(f)
89106

90107
# generate output (open the output file as late as possible)
91108
SetOutputFileName(OUTPUTFILE)

0 commit comments

Comments
 (0)