/*********************************************************/
/* This source code copyright (c) 1991-2001, Aaron Giles */
/* See the Read Me file for licensing information.       */
/* Contact email: mac@aarongiles.com                     */
/*********************************************************/

#ifndef __APPLEEVENTUTILS__
#define __APPLEEVENTUTILS__

/*
 * sObjectToken = generic token for all our AE object accessors
 */
 
typedef struct ObjectToken
{
	short count;
	DescType objclass, property;
	Ptr object[1];
} ObjectToken, *ObjectTokenPtr, **ObjectTokenHandle;

void AppleEventInit(void);
pascal OSErr HandleUnsupportedEvent(AppleEvent *theEvent, AppleEvent *reply, long refCon);
OSErr AENewEvent(AppleEvent *theEvent, AEEventClass theClass, AEEventID theID);
OSErr AEMakeIntlDesc(StringPtr theString, AEDesc *theDesc);
OSErr AEMakeBeginningILoc(AEDesc *theDesc, Boolean floating);
OSErr AECreateHandleDesc(DescType theType, Handle theHandle, AEDesc *theDesc);
OSErr AEAddAlias(AppleEvent *theEvent, AEKeyword theKey, FSSpec *theSpec);
OSErr AEAddAliasList(AppleEvent *theEvent, AEKeyword theKey, FSSpec *theSpec, short count);
OSErr AEExtractObject(AppleEvent *theEvent, AEKeyword theKey, AEDesc *theToken);
OSErr AEExtractInsertionLoc(AppleEvent *theEvent, AEKeyword theKey, WindowPtr *theWindow);
OSErr AEExtractGeneric(AppleEvent *theEvent, AEKeyword theKey, DescType theType,
	Size theSize, void *theData);
OSErr AEExtractTypeList(AppleEvent *theEvent, AEKeyword theKey, DescType ***theData);
OSErr AEExtractPString(AppleEvent *theEvent, AEKeyword theKey, uchar *theString);
pascal OSErr AECoerceIntlToChar(DescType fromType, Ptr theData, Size theSize, 
	DescType toType, long refCon, AEDesc *result);
pascal OSErr AECoerceRectToList(DescType fromType, Ptr theData, Size theSize, 
	DescType toType, long refCon, AEDesc *result);
pascal OSErr AECoerceListToRect(AEDesc *theAEDesc, DescType toType, long refCon, 
	AEDesc *result);
pascal OSErr AECoerceRealToFixed(DescType fromType, Ptr theData, Size theSize, 
	DescType toType, long refCon, AEDesc *result);
pascal OSErr AECoerceFixedToReal(DescType fromType, Ptr theData, Size theSize, 
	DescType toType, long refCon, AEDesc *result);
pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleep, RgnHandle *mouseRgn);
#define AEBegin() gInAppleEvent = true
#define AEEnd() gInAppleEvent = false
#define AEAddBoolean(evt, key, data) AEPutParamPtr(evt, key, typeBoolean, (void *)data, sizeof(Boolean))
#define AEAddShort(evt, key, data) AEPutParamPtr(evt, key, typeShortInteger, (void *)data, sizeof(short))
#define AEAddLong(evt, key, data) AEPutParamPtr(evt, key, typeLongInteger, (void *)data, sizeof(long))
#define AEAddFixed(evt, key, data) AEPutParamPtr(evt, key, typeFixed, (void *)data, sizeof(long))
#define AEAddType(evt, key, data) AEPutParamPtr(evt, key, typeType, (void *)data, sizeof(DescType))
#define AEAddEnumerated(evt, key, data) AEPutParamPtr(evt, key, typeEnumerated, (void *)data, sizeof(DescType))
#define AEAddQDRectangle(evt, key, data) AEPutParamPtr(evt, key, typeQDRectangle, (void *)data, sizeof(Rect))
#define AEExtractAlias(event, key, ptr) AEExtractGeneric(event, key, typeFSS, sizeof(FSSpec), ptr)
#define AEExtractBoolean(event, key, ptr) AEExtractGeneric(event, key, typeBoolean, sizeof(Boolean), ptr)
#define AEExtractShort(event, key, ptr) AEExtractGeneric(event, key, typeShortInteger, sizeof(short), ptr)
#define AEExtractLong(event, key, ptr) AEExtractGeneric(event, key, typeLongInteger, sizeof(long), ptr)
#define AEExtractFixed(event, key, ptr) AEExtractGeneric(event, key, typeFixed, sizeof(Fixed), ptr)
#define AEExtractType(event, key, ptr) AEExtractGeneric(event, key, typeType, sizeof(DescType), ptr)
#define AEExtractEnumerated(event, key, ptr) AEExtractGeneric(event, key, typeEnumerated, sizeof(DescType), ptr)
#define AEExtractQDRectangle(event, key, ptr) AEExtractGeneric(event, key, typeQDRectangle, sizeof(Rect), ptr)

#endif
