home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 15 / develop 15 code / Floating Windows / Sample / Source / appleEventHandlers.c next >
Encoding:
C/C++ Source or Header  |  1992-11-06  |  4.8 KB  |  169 lines  |  [TEXT/MPS ]

  1. #include <Types.h>
  2. #include <AppleEvents.h>
  3. #include <Events.h>
  4. #include <Memory.h>
  5. #include <Processes.h>
  6.  
  7. #include "globals.h"
  8. #include "appleEventHandlers.h"
  9. #include "eventHandler.h"
  10. #include "fileMenuRoutines.h"
  11.  
  12. /*    Private routines */
  13.     
  14. pascal    Boolean IdleProc(EventRecord *theEventRecord, long *sleepTime, RgnHandle *mouseRgn);
  15.     
  16.     
  17. /*    Handle the ‘oapp’ AppleEvent.    */
  18.  
  19. pascal OSErr    OAPPHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
  20. {
  21. #pragma unused (reply, handlerRefCon)
  22.  
  23.     OSErr        oappErr;
  24.     AEKeyword    missedKeyWord;
  25.     DescType    actualType;
  26.     Size        actualSize;
  27.     
  28.     oappErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
  29.  
  30.     if (!oappErr)                    /* If no error, then a missing parameter was found */
  31.         return errAEParamMissed;
  32.     
  33.     /*    Do whatever needs to be done when starting up and return noErr */
  34.     
  35.     return    noErr;
  36. }
  37.  
  38. /*    Handle the ‘odoc’ AppleEvent.    */
  39.  
  40. pascal OSErr    ODOCHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
  41. {
  42. #pragma unused (reply, handlerRefCon)
  43.  
  44.     OSErr            odocErr;
  45.     AEKeyword        missedKeyWord;
  46.     DescType        actualType;
  47.     Size            actualSize;
  48.     AEDescList        documentList;
  49.     long            itemsInList;
  50.     long            i;
  51.     AEKeyword        keyWord;
  52.     DescType        typeCode;
  53.     FSSpec            documentFileSpec;
  54.     TargetID        senderType;
  55.     OSType            senderCreator;
  56.     ProcessSerialNumber    thePSN;
  57.     
  58.     odocErr = AEGetParamDesc(&theAppleEvent, keyDirectObject, typeAEList, &documentList);    /* Get list of documents to open */
  59.     if (odocErr)
  60.         return odocErr;
  61.         
  62.     odocErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
  63.  
  64.     if (!odocErr)                    /* If no error, then a missing parameter was found */
  65.         return errAEParamMissed;
  66.     
  67.     /* 
  68.         If we’re in the background, see if the event was sent from the Finder.  If so,
  69.         switch to the front.
  70.     */
  71.     
  72.     if (gInBackground) {
  73.         odocErr = AEGetAttributePtr(&theAppleEvent, keyAddressAttr, typeTargetID, &actualType, (Ptr) &senderType, sizeof(senderType), &actualSize);
  74.         BlockMove((Ptr) (&(senderType.name.u.portTypeStr)+1), (Ptr) &(senderCreator), 4);
  75.         if (senderCreator == 'MACS') {
  76.             thePSN.highLongOfPSN = 0;
  77.             thePSN.lowLongOfPSN = kCurrentProcess;
  78.             SetFrontProcess(&thePSN);
  79.         }
  80.     }
  81.  
  82.     /* Open all the documents in documentList */
  83.     
  84.     odocErr = AECountItems(&documentList, &itemsInList);        /* Get number of documents */
  85.     
  86.     for (i = 1; i <= itemsInList; i++) {
  87.         odocErr = AEGetNthPtr(&documentList, i, typeFSS, &keyWord, &typeCode, (Ptr) &documentFileSpec, sizeof(documentFileSpec), &actualSize);
  88.         DoOpenFile(&documentFileSpec);
  89.     }
  90.         
  91.     odocErr = AEDisposeDesc(&documentList);            /* Dispose of AE structure created by AEGetParamDesc */
  92.     return    noErr;
  93. }
  94.  
  95. /*    Handle the ‘pdoc’ AppleEvent.    */
  96.  
  97. pascal OSErr    PDOCHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
  98. {
  99. #pragma unused (reply, handlerRefCon)
  100.  
  101.     OSErr        pdocErr;
  102.     AEKeyword    missedKeyWord;
  103.     DescType    actualType;
  104.     Size        actualSize;
  105.     AEDescList    documentList;
  106.     long        itemsInList;
  107.     long        i;
  108.     AEKeyword    keyWord;
  109.     DescType    typeCode;
  110.     FSSpec        documentFileSpec;
  111.     
  112.     pdocErr = AEGetParamDesc(&theAppleEvent, keyDirectObject, typeAEList, &documentList);    /* Get list of documents to open */
  113.     
  114.     pdocErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
  115.  
  116.     if (!pdocErr)                    /* If no error, then a missing parameter was found */
  117.         return errAEParamMissed;
  118.     
  119.     /* Print all the documents in documentList */
  120.     
  121.     pdocErr = AECountItems(&documentList, &itemsInList);        /* Get number of documents */
  122.     
  123.     for (i = 1; i <= itemsInList; i++) {
  124.         pdocErr = AEGetNthPtr(&documentList, i, typeFSS, &keyWord, &typeCode, (Ptr) &documentFileSpec, sizeof(documentFileSpec), &actualSize);
  125.         DoPrintFile(&documentFileSpec);
  126.     }
  127.         
  128.     pdocErr = AEDisposeDesc(&documentList);                    /* Dispose of AE structure created by AEGetParamDesc */
  129.     return    noErr;
  130. }
  131.  
  132. /*    Handle the ‘quit’ AppleEvent.    */
  133.  
  134. pascal OSErr    QUITHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
  135. {
  136. #pragma unused (reply, handlerRefCon)
  137.  
  138.     OSErr        quitErr;
  139.     AEKeyword    missedKeyWord;
  140.     DescType    actualType;
  141.     Size        actualSize;
  142.     
  143.     quitErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
  144.  
  145.     if (!quitErr)                    /* If no error, then a missing parameter was found */
  146.         return errAEParamMissed;
  147.     
  148.     /*    Do whatever needs to be done when quitting and return noErr */
  149.     
  150.     gDone = true;    
  151.     return    noErr;
  152. }
  153.  
  154. pascal    Boolean IdleProc(EventRecord *theEventRecord, long *sleepTime, RgnHandle *mouseRgn)
  155. {    
  156.     switch (theEventRecord->what) {
  157.         case updateEvt:
  158.         case activateEvt:
  159.         case osEvt:            HandleEvent(theEventRecord);
  160.                             break;
  161.         case nullEvent:        *mouseRgn = nil;
  162.                             *sleepTime = 15;
  163.                             break;
  164.     }
  165.     return false;
  166. }
  167.  
  168.  
  169.