1999-06-21 12:14:26 -03:00
|
|
|
# This script generates a Python interface for an Apple Macintosh Manager.
|
|
|
|
# It uses the "bgen" package to generate C code.
|
|
|
|
# The function specifications are generated by scanning the mamager's header file,
|
|
|
|
# using the "scantools" package (customized for this particular manager).
|
|
|
|
|
|
|
|
import string
|
|
|
|
|
|
|
|
# Declarations that change for each manager
|
2004-07-18 03:16:08 -03:00
|
|
|
MACHEADERFILE = 'Drag.h' # The Apple header file
|
|
|
|
MODNAME = '_Drag' # The name of the module
|
|
|
|
OBJECTNAME = 'DragObj' # The basic name of the objects used here
|
1999-06-21 12:14:26 -03:00
|
|
|
|
|
|
|
# The following is *usually* unchanged but may still require tuning
|
2004-07-18 03:16:08 -03:00
|
|
|
MODPREFIX = 'Drag' # The prefix for module-wide routines
|
|
|
|
OBJECTTYPE = 'DragRef' # The C type used to represent them
|
|
|
|
OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
|
1999-06-21 12:14:26 -03:00
|
|
|
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
|
2004-07-18 03:16:08 -03:00
|
|
|
OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
|
1999-06-21 12:14:26 -03:00
|
|
|
|
|
|
|
from macsupport import *
|
|
|
|
|
|
|
|
# Create the type objects
|
|
|
|
|
2000-12-10 19:43:49 -04:00
|
|
|
DragRef = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX)
|
|
|
|
DragItemRef = Type("ItemReference", "l")
|
|
|
|
# Old names
|
|
|
|
DragReference = DragRef
|
|
|
|
ItemReference = DragItemRef
|
|
|
|
|
1999-06-21 12:14:26 -03:00
|
|
|
PixMapHandle = OpaqueByValueType("PixMapHandle", "ResObj")
|
|
|
|
RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
|
|
|
|
AEDesc = OpaqueType('AEDesc')
|
|
|
|
AEDesc_ptr = AEDesc
|
|
|
|
RGBColor = OpaqueType("RGBColor", "QdRGB")
|
|
|
|
|
|
|
|
FlavorType = OSTypeType("FlavorType")
|
|
|
|
DragAttributes = Type("DragAttributes", "l")
|
2000-12-10 19:43:49 -04:00
|
|
|
DragBehaviors = Type("DragBehaviors", "l")
|
1999-06-21 12:14:26 -03:00
|
|
|
DragImageFlags = Type("DragImageFlags", "l")
|
|
|
|
DragImageTranslucency = Type("DragImageTranslucency", "l")
|
|
|
|
DragRegionMessage = Type("DragRegionMessage", "h")
|
|
|
|
ZoomAcceleration = Type("ZoomAcceleration", "h")
|
|
|
|
FlavorFlags = Type("FlavorFlags", "l")
|
|
|
|
DragTrackingMessage = Type("DragTrackingMessage", "h")
|
|
|
|
|
|
|
|
includestuff = includestuff + """
|
2001-05-22 18:56:42 -03:00
|
|
|
#include <Carbon/Carbon.h>
|
1999-06-21 12:14:26 -03:00
|
|
|
|
|
|
|
/* Callback glue routines */
|
|
|
|
DragTrackingHandlerUPP dragglue_TrackingHandlerUPP;
|
|
|
|
DragReceiveHandlerUPP dragglue_ReceiveHandlerUPP;
|
|
|
|
DragSendDataUPP dragglue_SendDataUPP;
|
|
|
|
#if 0
|
|
|
|
DragInputUPP dragglue_InputUPP;
|
|
|
|
DragDrawingUPP dragglue_DrawingUPP;
|
|
|
|
#endif
|
2001-05-17 18:58:34 -03:00
|
|
|
|
|
|
|
#ifdef USE_TOOLBOX_OBJECT_GLUE
|
|
|
|
extern PyObject *_DragObj_New(DragRef);
|
|
|
|
extern int _DragObj_Convert(PyObject *, DragRef *);
|
|
|
|
|
|
|
|
#define DragObj_New _DragObj_New
|
|
|
|
#define DragObj_Convert _DragObj_Convert
|
|
|
|
#endif
|
1999-06-21 12:14:26 -03:00
|
|
|
"""
|
|
|
|
|
|
|
|
finalstuff = finalstuff + """
|
|
|
|
static pascal OSErr
|
|
|
|
dragglue_TrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
|
|
|
|
void *handlerRefCon, DragReference theDrag)
|
|
|
|
{
|
2004-07-18 03:16:08 -03:00
|
|
|
PyObject *args, *rv;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
args = Py_BuildValue("hO&O&", theMessage, DragObj_New, theDrag, WinObj_WhichWindow, theWindow);
|
|
|
|
if ( args == NULL )
|
|
|
|
return -1;
|
|
|
|
rv = PyEval_CallObject((PyObject *)handlerRefCon, args);
|
|
|
|
Py_DECREF(args);
|
|
|
|
if ( rv == NULL ) {
|
|
|
|
PySys_WriteStderr("Drag: Exception in TrackingHandler\\n");
|
|
|
|
PyErr_Print();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
i = -1;
|
|
|
|
if ( rv == Py_None )
|
|
|
|
i = 0;
|
|
|
|
else
|
|
|
|
PyArg_Parse(rv, "l", &i);
|
|
|
|
Py_DECREF(rv);
|
|
|
|
return i;
|
1999-06-21 12:14:26 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static pascal OSErr
|
|
|
|
dragglue_ReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
|
|
|
|
DragReference theDrag)
|
|
|
|
{
|
2004-07-18 03:16:08 -03:00
|
|
|
PyObject *args, *rv;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
args = Py_BuildValue("O&O&", DragObj_New, theDrag, WinObj_WhichWindow, theWindow);
|
|
|
|
if ( args == NULL )
|
|
|
|
return -1;
|
|
|
|
rv = PyEval_CallObject((PyObject *)handlerRefCon, args);
|
|
|
|
Py_DECREF(args);
|
|
|
|
if ( rv == NULL ) {
|
|
|
|
PySys_WriteStderr("Drag: Exception in ReceiveHandler\\n");
|
|
|
|
PyErr_Print();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
i = -1;
|
|
|
|
if ( rv == Py_None )
|
|
|
|
i = 0;
|
|
|
|
else
|
|
|
|
PyArg_Parse(rv, "l", &i);
|
|
|
|
Py_DECREF(rv);
|
|
|
|
return i;
|
1999-06-21 12:14:26 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static pascal OSErr
|
|
|
|
dragglue_SendData(FlavorType theType, void *dragSendRefCon,
|
|
|
|
ItemReference theItem, DragReference theDrag)
|
|
|
|
{
|
2004-07-18 03:16:08 -03:00
|
|
|
DragObjObject *self = (DragObjObject *)dragSendRefCon;
|
|
|
|
PyObject *args, *rv;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if ( self->sendproc == NULL )
|
|
|
|
return -1;
|
|
|
|
args = Py_BuildValue("O&l", PyMac_BuildOSType, theType, theItem);
|
|
|
|
if ( args == NULL )
|
|
|
|
return -1;
|
|
|
|
rv = PyEval_CallObject(self->sendproc, args);
|
|
|
|
Py_DECREF(args);
|
|
|
|
if ( rv == NULL ) {
|
|
|
|
PySys_WriteStderr("Drag: Exception in SendDataHandler\\n");
|
|
|
|
PyErr_Print();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
i = -1;
|
|
|
|
if ( rv == Py_None )
|
|
|
|
i = 0;
|
|
|
|
else
|
|
|
|
PyArg_Parse(rv, "l", &i);
|
|
|
|
Py_DECREF(rv);
|
|
|
|
return i;
|
1999-06-21 12:14:26 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static pascal OSErr
|
|
|
|
dragglue_Input(Point *mouse, short *modifiers,
|
|
|
|
void *dragSendRefCon, DragReference theDrag)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static pascal OSErr
|
|
|
|
dragglue_Drawing(xxxx
|
|
|
|
void *dragSendRefCon, DragReference theDrag)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2001-05-17 18:58:34 -03:00
|
|
|
initstuff = initstuff + """
|
2004-07-18 03:16:08 -03:00
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(DragRef, DragObj_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DragRef, DragObj_Convert);
|
2001-05-17 18:58:34 -03:00
|
|
|
"""
|
|
|
|
|
1999-06-21 12:14:26 -03:00
|
|
|
variablestuff = """
|
2001-05-22 18:56:42 -03:00
|
|
|
dragglue_TrackingHandlerUPP = NewDragTrackingHandlerUPP(dragglue_TrackingHandler);
|
|
|
|
dragglue_ReceiveHandlerUPP = NewDragReceiveHandlerUPP(dragglue_ReceiveHandler);
|
|
|
|
dragglue_SendDataUPP = NewDragSendDataUPP(dragglue_SendData);
|
1999-06-21 12:14:26 -03:00
|
|
|
#if 0
|
2001-05-22 18:56:42 -03:00
|
|
|
dragglue_InputUPP = NewDragInputUPP(dragglue_Input);
|
|
|
|
dragglue_DrawingUPP = NewDragDrawingUPP(dragglue_Drawing);
|
1999-06-21 12:14:26 -03:00
|
|
|
#endif
|
2004-07-18 03:16:08 -03:00
|
|
|
"""
|
1999-06-21 12:14:26 -03:00
|
|
|
|
2002-12-03 19:40:22 -04:00
|
|
|
class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
def outputCheckNewArg(self):
|
|
|
|
Output("""if (itself == NULL) {
|
|
|
|
PyErr_SetString(Drag_Error,"Cannot create null Drag");
|
|
|
|
return NULL;
|
|
|
|
}""")
|
|
|
|
def outputFreeIt(self, itselfname):
|
|
|
|
## Output("DisposeDrag(%s);", itselfname)
|
|
|
|
Output("Py_XDECREF(self->sendproc);")
|
|
|
|
## Output("Py_XDECREF(self->inputproc);")
|
|
|
|
## Output("Py_XDECREF(self->drawingproc);")
|
|
|
|
|
|
|
|
def outputStructMembers(self):
|
|
|
|
GlobalObjectDefinition.outputStructMembers(self)
|
|
|
|
Output("PyObject *sendproc;")
|
|
|
|
## Output("PyObject *inputproc;")
|
|
|
|
## Output("PyObject *drawingproc;")
|
|
|
|
|
|
|
|
def outputInitStructMembers(self):
|
|
|
|
GlobalObjectDefinition.outputInitStructMembers(self)
|
|
|
|
Output("it->sendproc = NULL;")
|
|
|
|
## Output("it->inputproc = NULL;")
|
|
|
|
## Output("it->drawingproc = NULL;")
|
|
|
|
|
|
|
|
|
1999-06-21 12:14:26 -03:00
|
|
|
# Create the generator groups and link them
|
|
|
|
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff, variablestuff)
|
|
|
|
object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
|
|
|
|
module.addobject(object)
|
|
|
|
|
|
|
|
# Create the generator classes used to populate the lists
|
2002-03-24 20:32:17 -04:00
|
|
|
Function = OSErrWeakLinkFunctionGenerator
|
|
|
|
Method = OSErrWeakLinkMethodGenerator
|
1999-06-21 12:14:26 -03:00
|
|
|
|
|
|
|
# Create and populate the lists
|
|
|
|
functions = []
|
|
|
|
methods = []
|
2007-08-11 21:43:29 -03:00
|
|
|
exec(open(INPUTFILE).read())
|
1999-06-21 12:14:26 -03:00
|
|
|
|
|
|
|
# add the populated lists to the generator groups
|
|
|
|
for f in functions: module.add(f)
|
|
|
|
for f in methods: object.add(f)
|
|
|
|
|
|
|
|
# Manual generators for the callbacks
|
|
|
|
|
|
|
|
installtracking_body = """
|
|
|
|
PyObject *callback;
|
|
|
|
WindowPtr theWindow = NULL;
|
|
|
|
OSErr _err;
|
2004-07-18 03:16:08 -03:00
|
|
|
|
1999-06-21 12:14:26 -03:00
|
|
|
if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) )
|
2004-07-18 03:16:08 -03:00
|
|
|
return NULL;
|
|
|
|
Py_INCREF(callback); /* Cannot decref later, too bad */
|
1999-06-21 12:14:26 -03:00
|
|
|
_err = InstallTrackingHandler(dragglue_TrackingHandlerUPP, theWindow, (void *)callback);
|
2004-07-18 03:16:08 -03:00
|
|
|
if (_err != noErr) return PyMac_Error(_err);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
_res = Py_None;
|
|
|
|
return _res;
|
1999-06-21 12:14:26 -03:00
|
|
|
"""
|
|
|
|
installtracking = ManualGenerator("InstallTrackingHandler", installtracking_body)
|
|
|
|
module.add(installtracking)
|
|
|
|
|
|
|
|
installreceive_body = """
|
|
|
|
PyObject *callback;
|
|
|
|
WindowPtr theWindow = NULL;
|
|
|
|
OSErr _err;
|
2004-07-18 03:16:08 -03:00
|
|
|
|
1999-06-21 12:14:26 -03:00
|
|
|
if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) )
|
2004-07-18 03:16:08 -03:00
|
|
|
return NULL;
|
|
|
|
Py_INCREF(callback); /* Cannot decref later, too bad */
|
1999-06-21 12:14:26 -03:00
|
|
|
_err = InstallReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow, (void *)callback);
|
2004-07-18 03:16:08 -03:00
|
|
|
if (_err != noErr) return PyMac_Error(_err);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
_res = Py_None;
|
|
|
|
return _res;
|
1999-06-21 12:14:26 -03:00
|
|
|
"""
|
|
|
|
installreceive = ManualGenerator("InstallReceiveHandler", installreceive_body)
|
|
|
|
module.add(installreceive)
|
|
|
|
|
|
|
|
removetracking_body = """
|
|
|
|
WindowPtr theWindow = NULL;
|
|
|
|
OSErr _err;
|
2004-07-18 03:16:08 -03:00
|
|
|
|
1999-06-21 12:14:26 -03:00
|
|
|
if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) )
|
2004-07-18 03:16:08 -03:00
|
|
|
return NULL;
|
1999-06-21 12:14:26 -03:00
|
|
|
_err = RemoveTrackingHandler(dragglue_TrackingHandlerUPP, theWindow);
|
2004-07-18 03:16:08 -03:00
|
|
|
if (_err != noErr) return PyMac_Error(_err);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
_res = Py_None;
|
|
|
|
return _res;
|
1999-06-21 12:14:26 -03:00
|
|
|
"""
|
|
|
|
removetracking = ManualGenerator("RemoveTrackingHandler", removetracking_body)
|
|
|
|
module.add(removetracking)
|
|
|
|
|
|
|
|
removereceive_body = """
|
|
|
|
WindowPtr theWindow = NULL;
|
|
|
|
OSErr _err;
|
2004-07-18 03:16:08 -03:00
|
|
|
|
1999-06-21 12:14:26 -03:00
|
|
|
if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) )
|
2004-07-18 03:16:08 -03:00
|
|
|
return NULL;
|
1999-06-21 12:14:26 -03:00
|
|
|
_err = RemoveReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow);
|
2004-07-18 03:16:08 -03:00
|
|
|
if (_err != noErr) return PyMac_Error(_err);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
_res = Py_None;
|
|
|
|
return _res;
|
1999-06-21 12:14:26 -03:00
|
|
|
"""
|
|
|
|
removereceive = ManualGenerator("RemoveReceiveHandler", removereceive_body)
|
|
|
|
module.add(removereceive)
|
|
|
|
|
|
|
|
# generate output (open the output file as late as possible)
|
|
|
|
SetOutputFileName(OUTPUTFILE)
|
|
|
|
module.generate()
|