Exemple #1
0
static PyObject *AE_AEGetEventHandler(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	OSErr _err;
	AEEventClass theAEEventClass;
	AEEventID theAEEventID;
	AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler;
	PyObject *handler;
#ifndef AEGetEventHandler
	PyMac_PRECHECK(AEGetEventHandler);
#endif
	if (!PyArg_ParseTuple(_args, "O&O&",
	                      PyMac_GetOSType, &theAEEventClass,
	                      PyMac_GetOSType, &theAEEventID))
		return NULL;
	_err = AEGetEventHandler(theAEEventClass,
	                         theAEEventID,
	                         &handler__proc__, (long *)&handler,
	                         0);
	if (_err != noErr) return PyMac_Error(_err);
	_res = Py_BuildValue("O",
	                     handler);
	Py_INCREF(handler); /* XXX leak, but needed */
	return _res;
}
Exemple #2
0
static PyObject *AE_AEGetEventHandler(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	OSErr _err;
	AEEventClass theAEEventClass;
	AEEventID theAEEventID;
	AEEventHandlerUPP handler__proc__;
	PyObject *handler;

	if (!PyArg_ParseTuple(_args, "O&O&",
	                      AE_GetOSType, &theAEEventClass,
	                      AE_GetOSType, &theAEEventID))
		return NULL;
	_err = AEGetEventHandler(theAEEventClass,
	                         theAEEventID,
	                         &handler__proc__, (SRefCon *)&handler,
	                         0);
	if (_err != noErr) return AE_MacOSError(_err);
	/* currently only supports getting handlers installed via aem.ae.installeventhandler */
	if (handler__proc__ != upp_GenericEventHandler)
		return AE_MacOSError(errAEHandlerNotFound);
	_res = Py_BuildValue("O", handler);
	Py_INCREF(handler); /* XXX leak, but needed */
	return _res;
}
Exemple #3
0
Boolean IACremovehandler (AEEventClass eventclass, AEEventID id, ProcPtr handler) {

	OSErr ec;

		#if TARGET_RT_MAC_CFM
			#if TARGET_API_MAC_CARBON == 1
				AEEventHandlerUPP theHandler = NewAEEventHandlerUPP(handler);
				ec = AERemoveEventHandler (eventclass, id, theHandler, false);
				DisposeAEEventHandlerUPP(theHandler);

			#else	
			
				long refcon;
				
				ec = AEGetEventHandler (eventclass, id, (AEEventHandlerUPP *) &handler, &refcon, false);
				
				if (ec == noErr)
					ec = AERemoveEventHandler (eventclass, id, (AEEventHandlerUPP) handler, false);
			#endif//TARGET_API_MAC_CARBON == 0
		#else

		ec = AERemoveEventHandler (eventclass, id, (AEEventHandlerUPP) handler, false);
		
		#endif//end TARGET_RT_MAC_CFM
	
	IACglobals.errorcode = ec;
	
	return (ec == noErr);
	} /*IACremovehandler*/
Exemple #4
0
Boolean IAChandlerinstalled (OSType vclass, OSType vtoken, Boolean flsystemhandler) {
	
	/*
	return true if there's a handler installed with the indicated class and id.
	
	if flsystemhandler is true, we only consider system event handlers, if false 
	we only consider app-specific handlers.
	*/
	
	OSErr ec;
	AEEventHandlerUPP handler;
	long refcon;
	
	ec = AEGetEventHandler (vclass, vtoken, &handler, &refcon, flsystemhandler);
	
	IACglobals.errorcode = ec;
	
	return (ec == noErr);
	} /*IAChandlerinstalled*/
Exemple #5
0
Word BURGERCALL SystemProcessFilenames(SystemProcessCallBackProc Proc) 
{
	long result;				/* Gestalt temp */
	Word OldFlag;				/* Previous MacSystemTaskFlag */
	AEEventHandlerUPP OpenFileProc;		/* Current proc pointer */
	AEEventHandlerUPP PrevFileProc;		/* Previous proc pointer */
	long PrevRefCon;				/* Previous proc refcon */
	OSErr PrevErr;					/* Error getting the previous event handler */
	Foo_t FooData;					/* Data state */

	FooData.Result = TRUE;					/* Nothing processed */
	FooData.Proc = Proc;

	if (Proc && !Gestalt(gestaltAppleEventsAttr,&result)) {	/* Do I have apple events? */
		OpenFileProc = NewAEEventHandlerUPP(HandleOdoc);	/* Get the file */
		if (OpenFileProc) {
			Word i;
			
			/* Install the event handler */
			PrevErr = AEGetEventHandler(kCoreEventClass,kAEOpenDocuments,&PrevFileProc,&PrevRefCon,FALSE);
			AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,OpenFileProc,(long)&FooData, FALSE);
			i = 50;
			OldFlag = MacSystemTaskFlag;		/* Save */
			MacSystemTaskFlag = TRUE;			/* I WANT SystemTask() to be called */
			do {
				KeyboardGet();					/* Give some time to MacOS */
			} while (--i);
			MacSystemTaskFlag = OldFlag;	/* Restore the flag */
			AERemoveEventHandler(kCoreEventClass,kAEOpenDocuments,OpenFileProc,FALSE);
			DisposeAEEventHandlerUPP(OpenFileProc);	/* Kill my routine */
			if (!PrevErr) {
				AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,PrevFileProc,PrevRefCon, FALSE);
			}
		}
	}
	return FooData.Result;
}