@@ -30,21 +30,45 @@ extern int MenuObj_Convert(PyObject *, MenuHandle *);
3030extern PyObject * CtlObj_New (ControlHandle );
3131extern int CtlObj_Convert (PyObject * , ControlHandle * );
3232
33+ extern PyObject * WinObj_WhichWindow (WindowPtr );
34+
3335#include <AppleEvents.h>
3436
3537#ifdef THINK_C
38+ #define AEIdleProcPtr IdleProcPtr
3639#define AEFilterProcPtr EventFilterProcPtr
3740#define AEEventHandlerProcPtr EventHandlerProcPtr
3841#endif
3942
43+ #ifndef __MWERKS__
44+ /* Actually, this is "if not universal headers".
45+ ** I'm trying to setup the code here so that is easily automated,
46+ ** as follows:
47+ ** - Use the UPP in the source
48+ ** - for pre-universal headers, #define each UPP as the corresponding ProcPtr
49+ ** - for each routine we pass we declare a upp_xxx that
50+ ** we initialize to the correct value in the init routine.
51+ */
52+ #define AEIdleUPP AEIdleProcPtr
53+ #define AEFilterUPP AEFilterProcPtr
54+ #define AEEventHandlerUPP AEEventHandlerProcPtr
55+ #define NewAEIdleProc (x ) (x)
56+ #define NewAEFilterProc (x ) (x)
57+ #define NewAEEventHandlerProc (x ) (x)
58+ #endif
59+
4060static pascal OSErr GenericEventHandler (); /* Forward */
4161
62+ AEEventHandlerUPP upp_GenericEventHandler ;
63+
4264static pascal Boolean AEIdleProc (EventRecord * theEvent , long * sleepTime , RgnHandle * mouseRgn )
4365{
4466 (void ) PyMac_Idle ();
4567 return 0 ;
4668}
4769
70+ AEIdleUPP upp_AEIdleProc ;
71+
4872static PyObject * AE_Error ;
4973
5074/* ----------------------- Object type AEDesc ----------------------- */
@@ -733,8 +757,8 @@ static PyObject *AEDesc_AESend(_self, _args)
733757 sendMode ,
734758 sendPriority ,
735759 timeOutInTicks ,
736- AEIdleProc ,
737- (AEFilterProcPtr )0 );
760+ upp_AEIdleProc ,
761+ (AEFilterUPP )0 );
738762 if (_err != noErr ) return PyMac_Error (_err );
739763 _res = Py_BuildValue ("O&" ,
740764 AEDesc_New , & reply );
@@ -778,7 +802,7 @@ static PyObject *AEDesc_AEResumeTheCurrentEvent(_self, _args)
778802 PyObject * _res = NULL ;
779803 OSErr _err ;
780804 AppleEvent reply ;
781- AEEventHandlerProcPtr dispatcher__proc__ = GenericEventHandler ;
805+ AEEventHandlerUPP dispatcher__proc__ = upp_GenericEventHandler ;
782806 PyObject * dispatcher ;
783807 if (!PyArg_ParseTuple (_args , "O&O" ,
784808 AEDesc_Convert , & reply ,
@@ -790,6 +814,7 @@ static PyObject *AEDesc_AEResumeTheCurrentEvent(_self, _args)
790814 if (_err != noErr ) return PyMac_Error (_err );
791815 Py_INCREF (Py_None );
792816 _res = Py_None ;
817+ Py_INCREF (dispatcher ); /* XXX leak, but needed */
793818 return _res ;
794819}
795820
@@ -1103,7 +1128,7 @@ static PyObject *AE_AEInteractWithUser(_self, _args)
11031128 return NULL ;
11041129 _err = AEInteractWithUser (timeOutInTicks ,
11051130 (NMRecPtr )0 ,
1106- AEIdleProc );
1131+ upp_AEIdleProc );
11071132 if (_err != noErr ) return PyMac_Error (_err );
11081133 Py_INCREF (Py_None );
11091134 _res = Py_None ;
@@ -1118,7 +1143,7 @@ static PyObject *AE_AEInstallEventHandler(_self, _args)
11181143 OSErr _err ;
11191144 AEEventClass theAEEventClass ;
11201145 AEEventID theAEEventID ;
1121- AEEventHandlerProcPtr handler__proc__ = GenericEventHandler ;
1146+ AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler ;
11221147 PyObject * handler ;
11231148 if (!PyArg_ParseTuple (_args , "O&O&O" ,
11241149 PyMac_GetOSType , & theAEEventClass ,
@@ -1132,6 +1157,7 @@ static PyObject *AE_AEInstallEventHandler(_self, _args)
11321157 if (_err != noErr ) return PyMac_Error (_err );
11331158 Py_INCREF (Py_None );
11341159 _res = Py_None ;
1160+ Py_INCREF (handler ); /* XXX leak, but needed */
11351161 return _res ;
11361162}
11371163
@@ -1149,7 +1175,7 @@ static PyObject *AE_AERemoveEventHandler(_self, _args)
11491175 return NULL ;
11501176 _err = AERemoveEventHandler (theAEEventClass ,
11511177 theAEEventID ,
1152- GenericEventHandler ,
1178+ upp_GenericEventHandler ,
11531179 0 );
11541180 if (_err != noErr ) return PyMac_Error (_err );
11551181 Py_INCREF (Py_None );
@@ -1244,6 +1270,9 @@ void initAE()
12441270
12451271
12461272
1273+ upp_AEIdleProc = NewAEIdleProc (AEIdleProc );
1274+ upp_GenericEventHandler = NewAEEventHandlerProc (GenericEventHandler );
1275+
12471276
12481277 m = Py_InitModule ("AE" , AE_methods );
12491278 d = PyModule_GetDict (m );
0 commit comments