| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
import string |
| 7 |
|
| 8 |
|
| 9 |
MACHEADERFILE = 'Windows.h' |
| 10 |
MODNAME = '_Win' |
| 11 |
OBJECTNAME = 'Window' |
| 12 |
|
| 13 |
|
| 14 |
MODPREFIX = 'Win' |
| 15 |
OBJECTTYPE = OBJECTNAME + 'Ptr' |
| 16 |
OBJECTPREFIX = MODPREFIX + 'Obj' |
| 17 |
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' |
| 18 |
EDITFILE = string.lower(MODPREFIX) + 'edit.py' |
| 19 |
OUTPUTFILE = MODNAME + "module.c" |
| 20 |
|
| 21 |
from macsupport import * |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
WindowPtr = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX) |
| 26 |
WindowRef = WindowPtr |
| 27 |
WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX) |
| 28 |
WindowPeek.passInput = lambda name: "(WindowPeek)(%s)" % name |
| 29 |
CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj") |
| 30 |
GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj") |
| 31 |
|
| 32 |
DragReference = OpaqueByValueType("DragReference", "DragObj") |
| 33 |
|
| 34 |
RgnHandle = OpaqueByValueType("RgnHandle", "ResObj") |
| 35 |
PicHandle = OpaqueByValueType("PicHandle", "ResObj") |
| 36 |
WCTabHandle = OpaqueByValueType("WCTabHandle", "ResObj") |
| 37 |
AuxWinHandle = OpaqueByValueType("AuxWinHandle", "ResObj") |
| 38 |
PixPatHandle = OpaqueByValueType("PixPatHandle", "ResObj") |
| 39 |
AliasHandle = OpaqueByValueType("AliasHandle", "ResObj") |
| 40 |
IconRef = OpaqueByValueType("IconRef", "ResObj") |
| 41 |
|
| 42 |
WindowRegionCode = Type("WindowRegionCode", "H") |
| 43 |
WindowClass = Type("WindowClass", "l") |
| 44 |
WindowAttributes = Type("WindowAttributes", "l") |
| 45 |
WindowPositionMethod = Type("WindowPositionMethod", "l") |
| 46 |
WindowTransitionEffect = Type("WindowTransitionEffect", "l") |
| 47 |
WindowTransitionAction = Type("WindowTransitionAction", "l") |
| 48 |
RGBColor = OpaqueType("RGBColor", "QdRGB") |
| 49 |
RGBColor_ptr = RGBColor |
| 50 |
ScrollWindowOptions = Type("ScrollWindowOptions", "l") |
| 51 |
WindowPartCode = Type("WindowPartCode", "h") |
| 52 |
WindowDefPartCode = Type("WindowDefPartCode", "h") |
| 53 |
WindowModality = Type("WindowModality", "l") |
| 54 |
GDHandle = OpaqueByValueType("GDHandle", "ResObj") |
| 55 |
WindowConstrainOptions = Type("WindowConstrainOptions", "l") |
| 56 |
|
| 57 |
PropertyCreator = OSTypeType("PropertyCreator") |
| 58 |
PropertyTag = OSTypeType("PropertyTag") |
| 59 |
|
| 60 |
includestuff = includestuff + """ |
| 61 |
#include <Carbon/Carbon.h> |
| 62 |
|
| 63 |
#ifdef USE_TOOLBOX_OBJECT_GLUE |
| 64 |
extern PyObject *_WinObj_New(WindowRef); |
| 65 |
extern PyObject *_WinObj_WhichWindow(WindowRef); |
| 66 |
extern int _WinObj_Convert(PyObject *, WindowRef *); |
| 67 |
|
| 68 |
#define WinObj_New _WinObj_New |
| 69 |
#define WinObj_WhichWindow _WinObj_WhichWindow |
| 70 |
#define WinObj_Convert _WinObj_Convert |
| 71 |
#endif |
| 72 |
|
| 73 |
/* Classic calls that we emulate in carbon mode */ |
| 74 |
#define GetWindowUpdateRgn(win, rgn) GetWindowRegion((win), kWindowUpdateRgn, (rgn)) |
| 75 |
#define GetWindowStructureRgn(win, rgn) GetWindowRegion((win), kWindowStructureRgn, (rgn)) |
| 76 |
#define GetWindowContentRgn(win, rgn) GetWindowRegion((win), kWindowContentRgn, (rgn)) |
| 77 |
|
| 78 |
/* Function to dispose a window, with a "normal" calling sequence */ |
| 79 |
static void |
| 80 |
PyMac_AutoDisposeWindow(WindowPtr w) |
| 81 |
{ |
| 82 |
DisposeWindow(w); |
| 83 |
} |
| 84 |
""" |
| 85 |
|
| 86 |
finalstuff = finalstuff + """ |
| 87 |
/* Return the object corresponding to the window, or NULL */ |
| 88 |
|
| 89 |
PyObject * |
| 90 |
WinObj_WhichWindow(WindowPtr w) |
| 91 |
{ |
| 92 |
PyObject *it; |
| 93 |
|
| 94 |
if (w == NULL) { |
| 95 |
it = Py_None; |
| 96 |
Py_INCREF(it); |
| 97 |
} else { |
| 98 |
it = (PyObject *) GetWRefCon(w); |
| 99 |
if (it == NULL || !IsPointerValid((Ptr)it) || ((WindowObject *)it)->ob_itself != w || !WinObj_Check(it)) { |
| 100 |
it = WinObj_New(w); |
| 101 |
((WindowObject *)it)->ob_freeit = NULL; |
| 102 |
} else { |
| 103 |
Py_INCREF(it); |
| 104 |
} |
| 105 |
} |
| 106 |
return it; |
| 107 |
} |
| 108 |
""" |
| 109 |
|
| 110 |
initstuff = initstuff + """ |
| 111 |
PyMac_INIT_TOOLBOX_OBJECT_NEW(WindowPtr, WinObj_New); |
| 112 |
PyMac_INIT_TOOLBOX_OBJECT_NEW(WindowPtr, WinObj_WhichWindow); |
| 113 |
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(WindowPtr, WinObj_Convert); |
| 114 |
""" |
| 115 |
|
| 116 |
class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition): |
| 117 |
def outputCheckNewArg(self): |
| 118 |
Output("if (itself == NULL) return PyMac_Error(resNotFound);") |
| 119 |
Output("/* XXXX Or should we use WhichWindow code here? */") |
| 120 |
def outputStructMembers(self): |
| 121 |
GlobalObjectDefinition.outputStructMembers(self) |
| 122 |
Output("void (*ob_freeit)(%s ptr);", self.itselftype) |
| 123 |
def outputInitStructMembers(self): |
| 124 |
GlobalObjectDefinition.outputInitStructMembers(self) |
| 125 |
Output("it->ob_freeit = NULL;") |
| 126 |
Output("if (GetWRefCon(itself) == 0)") |
| 127 |
OutLbrace() |
| 128 |
Output("SetWRefCon(itself, (long)it);") |
| 129 |
Output("it->ob_freeit = PyMac_AutoDisposeWindow;") |
| 130 |
OutRbrace() |
| 131 |
def outputCheckConvertArg(self): |
| 132 |
Out(""" |
| 133 |
if (v == Py_None) { *p_itself = NULL; return 1; } |
| 134 |
if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; } |
| 135 |
""") |
| 136 |
OutLbrace() |
| 137 |
Output("DialogRef dlg;") |
| 138 |
OutLbrace("if (DlgObj_Convert(v, &dlg) && dlg)") |
| 139 |
Output("*p_itself = GetDialogWindow(dlg);") |
| 140 |
Output("return 1;") |
| 141 |
OutRbrace() |
| 142 |
Output("PyErr_Clear();") |
| 143 |
OutRbrace() |
| 144 |
def outputCleanupStructMembers(self): |
| 145 |
Output("if (self->ob_freeit && self->ob_itself)") |
| 146 |
OutLbrace() |
| 147 |
Output("SetWRefCon(self->ob_itself, 0);") |
| 148 |
Output("self->ob_freeit(self->ob_itself);") |
| 149 |
OutRbrace() |
| 150 |
Output("self->ob_itself = NULL;") |
| 151 |
Output("self->ob_freeit = NULL;") |
| 152 |
|
| 153 |
def outputCompare(self): |
| 154 |
Output() |
| 155 |
Output("static int %s_compare(%s *self, %s *other)", self.prefix, self.objecttype, self.objecttype) |
| 156 |
OutLbrace() |
| 157 |
Output("if ( self->ob_itself > other->ob_itself ) return 1;") |
| 158 |
Output("if ( self->ob_itself < other->ob_itself ) return -1;") |
| 159 |
Output("return 0;") |
| 160 |
OutRbrace() |
| 161 |
|
| 162 |
def outputHash(self): |
| 163 |
Output() |
| 164 |
Output("static int %s_hash(%s *self)", self.prefix, self.objecttype) |
| 165 |
OutLbrace() |
| 166 |
Output("return (int)self->ob_itself;") |
| 167 |
OutRbrace() |
| 168 |
|
| 169 |
def outputRepr(self): |
| 170 |
Output() |
| 171 |
Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) |
| 172 |
OutLbrace() |
| 173 |
Output("char buf[100];") |
| 174 |
Output("""sprintf(buf, "<Window object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""") |
| 175 |
Output("return PyString_FromString(buf);") |
| 176 |
OutRbrace() |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) |
| 184 |
object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) |
| 185 |
module.addobject(object) |
| 186 |
|
| 187 |
|
| 188 |
Function = OSErrWeakLinkFunctionGenerator |
| 189 |
Method = OSErrWeakLinkMethodGenerator |
| 190 |
|
| 191 |
|
| 192 |
functions = [] |
| 193 |
methods = [] |
| 194 |
execfile(INPUTFILE) |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
whichwin_body = """ |
| 199 |
long ptr; |
| 200 |
|
| 201 |
if ( !PyArg_ParseTuple(_args, "i", &ptr) ) |
| 202 |
return NULL; |
| 203 |
_res = WinObj_WhichWindow((WindowPtr)ptr); |
| 204 |
return _res; |
| 205 |
""" |
| 206 |
|
| 207 |
f = ManualGenerator("WhichWindow", whichwin_body) |
| 208 |
f.docstring = lambda : "Resolve an integer WindowPtr address to a Window object" |
| 209 |
|
| 210 |
functions.append(f) |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
execfile(EDITFILE) |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
for f in functions: module.add(f) |
| 220 |
for f in methods: object.add(f) |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
SetOutputFileName(OUTPUTFILE) |
| 226 |
module.generate() |