home *** CD-ROM | disk | FTP | other *** search
/ AppleScript - The Beta Release / AppleScript - The Beta Release.iso / Documentation / develop / Apple Event Objects and You / Apple Event Objects (code) / ObjectDispatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-08  |  4.5 KB  |  126 lines  |  [TEXT/KAHL]

  1. /*  File: ObjectDispatch.c */
  2.  
  3. #include "AEObjects.h"
  4. #include "AERegistry.h"
  5. #include "ScriptScrap.h"
  6. #include "Prototypes.h"
  7.  
  8.  
  9. OSErr SendAEToObject (    const AppleEvent *message, AppleEvent *reply, long refCon,
  10.                                 AEEventClass classID, AEEventID eventID,
  11.                                 DescType dispatchClass, const AEDesc *ospec, const AEDesc *token)
  12. {
  13.     OSErr    err = noErr;
  14.     switch (dispatchClass) {
  15.         case 'null':
  16.         case cApplication:
  17.             err = App_AE_Dispatcher(message, reply, refCon, classID, eventID, ospec, token);
  18.         break;
  19.  
  20.         case cWindow:        /* We'll let these 2 classes share common code, for now */
  21.         case cDocument:
  22.             err = Win_AE_Dispatcher(message, reply, refCon, classID, eventID, ospec, token);
  23.         break;
  24.  
  25.         case cEntry:
  26.             err = Entry_AE_Dispatcher(message, reply, refCon, classID, eventID, ospec, token);
  27.         break;
  28.         
  29.         case cScrapItem:
  30.             err = Item_AE_Dispatcher(message, reply, refCon, classID, eventID, ospec, token);
  31.         break;
  32.         
  33.         default:
  34.             err = errAEEventNotHandled;
  35.     }
  36.     return err;
  37. } /* SendAEToObject */
  38.  
  39.  
  40. pascal OSErr DirectParamDispatch(AppleEvent *message, AppleEvent *reply, long refcon)
  41. {
  42.     OSErr            err    = noErr;
  43.     AEEventClass    classID;
  44.     AEEventID        eventID;
  45.     OSType            typeCode;
  46.     Size            actualSize;
  47.  
  48.     AEDesc            objectSpec;
  49.     DescType        dispatchClass;
  50.     AEDesc            nullDesc         = {'null', 0L};
  51.     AEDesc            resolvedToken    = {'null', 0L};
  52.     AEDesc            dispatchParam;
  53.  
  54.     (void)AEGetAttributePtr(message, keyEventClassAttr, typeType, &typeCode, (Ptr)&classID, sizeof(classID), &actualSize);
  55.     (void)AEGetAttributePtr(message, keyEventIDAttr, typeType, &typeCode, (Ptr)&eventID,    sizeof(eventID),    &actualSize);
  56.  
  57.     /*  Extract the direct parameter, which is an object specifier */
  58.     err = AEGetParamDesc(message, keyDirectObject, typeWildCard, &objectSpec);
  59.     if (err != noErr) return err;
  60.     if (objectSpec.descriptorType == 'null')
  61.         /* We special case this since AEResolve does not like a null AEDesc */
  62.         err = SendAEToObject(message, reply, refcon, classID, eventID, 'null', &objectSpec, &nullDesc);
  63.     else {
  64.         err = AEResolve(&objectSpec, kAEIDoMinimum, &resolvedToken);
  65.         if (err != noErr) return err;
  66.         err = SendAEToObject(message, reply, refcon, classID, eventID, tokenDispatchClass(resolvedToken), &objectSpec, &resolvedToken);
  67.         (void)AEDisposeDesc(&resolvedToken);
  68.         (void)AEDisposeDesc(&objectSpec);
  69.     }
  70.  
  71.     return err;
  72. } /* DirectParamDispatch */
  73.  
  74.  
  75. pascal OSErr CreateElementDispatch(AppleEvent *message, AppleEvent *reply, long refcon)
  76. {
  77.     OSErr            err    = noErr;
  78.     AEEventClass    classID;
  79.     AEEventID        eventID;
  80.     OSType            typeCode;
  81.     Size            actualSize;
  82.  
  83.     AEDesc            insertionLoc,
  84.                     objectSpec;
  85.     DescType        dispatchClass,
  86.                     insertionPos;
  87.     AEDesc            resolvedToken    = {'null', 0L};
  88.  
  89.     (void)AEGetAttributePtr(message, keyEventClassAttr, typeType, &typeCode, (Ptr)&classID, sizeof(classID), &actualSize);
  90.     (void)AEGetAttributePtr(message, keyEventIDAttr, typeType, &typeCode, (Ptr)&eventID,    sizeof(eventID),    &actualSize);
  91.  
  92.     /* We're special-casing Create Element, as the object specifier is contained in  */
  93.     /* a TypeInsertionLoc record. We'll let the Apple Event Manager coerce the          */
  94.     /* insertionLoc record into an AERecord so we can extract the fields.              */
  95.  
  96.     err = AEGetParamDesc(message, keyAEInsertHere, typeAERecord, &insertionLoc);
  97.     if (err != noErr)  return err;
  98.  
  99.     /* We've decided that each object should be responsible for its own creation, so */
  100.     /* we'll pass the resolved token to the class specified in "keyAEObjectClass"     */
  101.     err = AEGetParamPtr(message, keyAEObjectClass, typeType, &typeCode,
  102.                         (Ptr)&dispatchClass, sizeof(dispatchClass), &actualSize);
  103.     if (err != noErr)  return err;
  104.  
  105.     /* Since we're not using the refcon for anything, we'll get the insertion position */
  106.     /* and pass it along in refCon */
  107.     (void) AEGetKeyPtr(&insertionLoc, keyAEPosition, typeEnumeration, &typeCode, (Ptr)&insertionPos,
  108.                            sizeof(insertionPos), &actualSize);
  109.  
  110.     /* And, just to save some duplicate code, we'll extract and resolve the object      */
  111.     /* specifier here before calling the actual "Create Element" routine.             */
  112.     err = AEGetKeyDesc(&insertionLoc, keyAEObject, typeWildCard, &objectSpec);
  113.     if (objectSpec.descriptorType != 'null') {
  114.         err = AEResolve(&objectSpec, kAEIDoMinimum, &resolvedToken);
  115.         if (err != noErr) return err;
  116.     }
  117.     err = SendAEToObject(message, reply, (long)insertionPos, /* was: refcon */
  118.                              classID, eventID, dispatchClass, &objectSpec, &resolvedToken);
  119.  
  120.     (void)AEDisposeDesc(&insertionLoc);
  121.     (void)AEDisposeDesc(&resolvedToken);
  122.     if (objectSpec.dataHandle != NULL)
  123.     (void)AEDisposeDesc(&objectSpec);
  124.     return err;
  125. } /* CreateElementDispatch */
  126.