home *** CD-ROM | disk | FTP | other *** search
- /* File: ObjectDispatch.c */
-
- #include "AEObjects.h"
- #include "AERegistry.h"
- #include "ScriptScrap.h"
- #include "Prototypes.h"
-
-
- OSErr SendAEToObject ( const AppleEvent *message, AppleEvent *reply, long refCon,
- AEEventClass classID, AEEventID eventID,
- DescType dispatchClass, const AEDesc *ospec, const AEDesc *token)
- {
- OSErr err = noErr;
- switch (dispatchClass) {
- case 'null':
- case cApplication:
- err = App_AE_Dispatcher(message, reply, refCon, classID, eventID, ospec, token);
- break;
-
- case cWindow: /* We'll let these 2 classes share common code, for now */
- case cDocument:
- err = Win_AE_Dispatcher(message, reply, refCon, classID, eventID, ospec, token);
- break;
-
- case cEntry:
- err = Entry_AE_Dispatcher(message, reply, refCon, classID, eventID, ospec, token);
- break;
-
- case cScrapItem:
- err = Item_AE_Dispatcher(message, reply, refCon, classID, eventID, ospec, token);
- break;
-
- default:
- err = errAEEventNotHandled;
- }
- return err;
- } /* SendAEToObject */
-
-
- pascal OSErr DirectParamDispatch(AppleEvent *message, AppleEvent *reply, long refcon)
- {
- OSErr err = noErr;
- AEEventClass classID;
- AEEventID eventID;
- OSType typeCode;
- Size actualSize;
-
- AEDesc objectSpec;
- DescType dispatchClass;
- AEDesc nullDesc = {'null', 0L};
- AEDesc resolvedToken = {'null', 0L};
- AEDesc dispatchParam;
-
- (void)AEGetAttributePtr(message, keyEventClassAttr, typeType, &typeCode, (Ptr)&classID, sizeof(classID), &actualSize);
- (void)AEGetAttributePtr(message, keyEventIDAttr, typeType, &typeCode, (Ptr)&eventID, sizeof(eventID), &actualSize);
-
- /* Extract the direct parameter, which is an object specifier */
- err = AEGetParamDesc(message, keyDirectObject, typeWildCard, &objectSpec);
- if (err != noErr) return err;
- if (objectSpec.descriptorType == 'null')
- /* We special case this since AEResolve does not like a null AEDesc */
- err = SendAEToObject(message, reply, refcon, classID, eventID, 'null', &objectSpec, &nullDesc);
- else {
- err = AEResolve(&objectSpec, kAEIDoMinimum, &resolvedToken);
- if (err != noErr) return err;
- err = SendAEToObject(message, reply, refcon, classID, eventID, tokenDispatchClass(resolvedToken), &objectSpec, &resolvedToken);
- (void)AEDisposeDesc(&resolvedToken);
- (void)AEDisposeDesc(&objectSpec);
- }
-
- return err;
- } /* DirectParamDispatch */
-
-
- pascal OSErr CreateElementDispatch(AppleEvent *message, AppleEvent *reply, long refcon)
- {
- OSErr err = noErr;
- AEEventClass classID;
- AEEventID eventID;
- OSType typeCode;
- Size actualSize;
-
- AEDesc insertionLoc,
- objectSpec;
- DescType dispatchClass,
- insertionPos;
- AEDesc resolvedToken = {'null', 0L};
-
- (void)AEGetAttributePtr(message, keyEventClassAttr, typeType, &typeCode, (Ptr)&classID, sizeof(classID), &actualSize);
- (void)AEGetAttributePtr(message, keyEventIDAttr, typeType, &typeCode, (Ptr)&eventID, sizeof(eventID), &actualSize);
-
- /* We're special-casing Create Element, as the object specifier is contained in */
- /* a TypeInsertionLoc record. We'll let the Apple Event Manager coerce the */
- /* insertionLoc record into an AERecord so we can extract the fields. */
-
- err = AEGetParamDesc(message, keyAEInsertHere, typeAERecord, &insertionLoc);
- if (err != noErr) return err;
-
- /* We've decided that each object should be responsible for its own creation, so */
- /* we'll pass the resolved token to the class specified in "keyAEObjectClass" */
- err = AEGetParamPtr(message, keyAEObjectClass, typeType, &typeCode,
- (Ptr)&dispatchClass, sizeof(dispatchClass), &actualSize);
- if (err != noErr) return err;
-
- /* Since we're not using the refcon for anything, we'll get the insertion position */
- /* and pass it along in refCon */
- (void) AEGetKeyPtr(&insertionLoc, keyAEPosition, typeEnumeration, &typeCode, (Ptr)&insertionPos,
- sizeof(insertionPos), &actualSize);
-
- /* And, just to save some duplicate code, we'll extract and resolve the object */
- /* specifier here before calling the actual "Create Element" routine. */
- err = AEGetKeyDesc(&insertionLoc, keyAEObject, typeWildCard, &objectSpec);
- if (objectSpec.descriptorType != 'null') {
- err = AEResolve(&objectSpec, kAEIDoMinimum, &resolvedToken);
- if (err != noErr) return err;
- }
- err = SendAEToObject(message, reply, (long)insertionPos, /* was: refcon */
- classID, eventID, dispatchClass, &objectSpec, &resolvedToken);
-
- (void)AEDisposeDesc(&insertionLoc);
- (void)AEDisposeDesc(&resolvedToken);
- if (objectSpec.dataHandle != NULL)
- (void)AEDisposeDesc(&objectSpec);
- return err;
- } /* CreateElementDispatch */
-