/* 
Copyright (c) 1991-2000 UserLand Software, Inc. 

Permission is hereby granted, free of charge, to any person obtaining a 
copy of this software and associated documentation files (the 
"Software"), to deal in the Software without restriction, including 
without limitation the rights to use, copy, modify, merge, publish, 
distribute, sublicense, and/or sell copies of the Software, and to 
permit persons to whom the Software is furnished to do so, subject to the 
following conditions: 

The above copyright notice and this permission notice shall be 
included in all copies or substantial portions of the Software. 

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
*/ 


#include "iacinternal.h"


/*
7/16/94 dmb: Updated for Univeral Headers, PowerPC
*/




Boolean IACinstallhandler (AEEventClass eventclass, AEEventID id, ProcPtr handler) {
	
	OSErr ec;
	
	ec = AEInstallEventHandler (eventclass, id, NewAEEventHandlerProc (handler), 0, false);
	
	IACglobals.errorcode = ec;
	
	return (ec == noErr);
	} /*AEinstallhandler*/


Boolean IACremovehandler (AEEventClass eventclass, AEEventID id, ProcPtr handler) {

	OSErr ec;
	
	#if GENERATINGCFM
	
		long refcon;
		
		ec = AEGetEventHandler (eventclass, id, (AEEventHandlerUPP *) &handler, &refcon, false);
		
		if (ec == noErr)
			ec = AERemoveEventHandler (eventclass, id, (AEEventHandlerUPP) handler, false);
		
	#else
	
		ec = AERemoveEventHandler (eventclass, id, (AEEventHandlerUPP) handler, false);
	
	#endif
	
	IACglobals.errorcode = ec;
	
	return (ec == noErr);
	} /*IACremovehandler*/


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*/


Boolean IACinstallcoercionhandler (DescType fromtype, DescType totype, ProcPtr handler) {
	
	OSErr ec;
	
	ec = AEInstallCoercionHandler (fromtype, totype, (AECoercionHandlerUPP) NewAECoercePtrProc (handler), (long) 0, false, false);
	
	IACglobals.errorcode = ec;

	return (ec == noErr);
	} /*IACinstallcoercionhandler*/