@@ -19,6 +19,8 @@ extern int ResObj_Convert(PyObject *, Handle *);
1919
2020extern PyObject * WinObj_New (WindowPtr );
2121extern int WinObj_Convert (PyObject * , WindowPtr * );
22+ extern PyTypeObject Window_Type ;
23+ #define WinObj_Check (x ) ((x)->ob_type == &Window_Type)
2224
2325extern PyObject * DlgObj_New (DialogPtr );
2426extern int DlgObj_Convert (PyObject * , DialogPtr * );
@@ -31,6 +33,9 @@ extern int MenuObj_Convert(PyObject *, MenuHandle *);
3133extern PyObject * CtlObj_New (ControlHandle );
3234extern int CtlObj_Convert (PyObject * , ControlHandle * );
3335
36+ extern PyObject * GrafObj_New (GrafPtr );
37+ extern int GrafObj_Convert (PyObject * , GrafPtr * );
38+
3439extern PyObject * WinObj_WhichWindow (WindowPtr );
3540
3641#include <QuickDraw.h>
@@ -40,59 +45,96 @@ extern PyObject *WinObj_WhichWindow(WindowPtr);
4045
4146static 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+
88130static 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
25172559static 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
0 commit comments