home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Games / Bolo 0.99.6 / More information / Sample Code / Std Autopilot / BF_AppleEvents.c < prev    next >
Encoding:
Text File  |  1995-04-28  |  3.0 KB  |  103 lines  |  [TEXT/KAHL]

  1. // Bolo code (C) Stuart Cheshire <cheshire@cs.stanford.edu> 1987-1995.
  2. // All rights reserved. This code is owned by Stuart Cheshire and is donated
  3. // free of charge for non-commercial use. You may not use this code in any
  4. // product sold for commercial profit, except shareware priced at $25 or less.
  5.  
  6. #include "BrainFrame.h"
  7. #include "BF_Main.h"
  8. #include "BF_Utils.h"
  9. #include "BF_AppleEvents.h"
  10. #include "BF_ResourceIDs.h"
  11.  
  12. local OSErr MoreParameters(const AppleEvent *e)
  13.     {
  14.     DescType returnedType;
  15.     Size actualSize;
  16.     OSErr err = AEGetAttributePtr(e, keyMissedKeywordAttr, typeWildCard,
  17.                                     &returnedType, NULL, 0, &actualSize);
  18.     if (err != errAEDescNotFound) return (errAEParamMissed); else return(noErr);
  19.     }
  20.  
  21. local pascal OSErr MyHandleOApp(const AppleEvent *e, AppleEvent *r, long Refcon)
  22.     {
  23.     OSErr err = MoreParameters(e);
  24.     r;//Unused
  25.     Refcon;//Unused
  26.     // if (!err) DebugStr("\pMyHandleOApp");
  27.     return(err);
  28.     }
  29.  
  30. local pascal OSErr MyHandleODoc(const AppleEvent *e, AppleEvent *r, long Refcon)
  31.     {
  32.     FSSpec myFSS;
  33.     AEDescList docList;
  34.     OSErr myErr;
  35.     long index, itemsInList;
  36.     Size actualSize;
  37.     AEKeyword keywd;
  38.     DescType returnedType;
  39.  
  40.     r;//Unused
  41.     Refcon;//Unused
  42.     //DebugStr("\pMyHandleODoc");
  43.  
  44.     myErr = AEGetParamDesc(e, keyDirectObject, typeAEList, &docList);
  45.     if (myErr) return(myErr);
  46.  
  47.     myErr = MoreParameters(e);
  48.     if (myErr) { AEDisposeDesc(&docList); return(myErr); }
  49.  
  50.     myErr = AECountItems(&docList, &itemsInList);
  51.     if (myErr) { AEDisposeDesc(&docList); return(myErr); }
  52.  
  53.     for (index = 1; index<=itemsInList; index++)
  54.         {
  55.         //FInfo fndrInfo;
  56.         myErr = AEGetNthPtr(&docList, index, typeFSS, &keywd, &returnedType, &myFSS, 
  57.                                     sizeof(myFSS), &actualSize);
  58.         //if (!myErr && !FSpGetFInfo(&myFSS, &fndrInfo)) process_file(&myFSS, fndrInfo.fdType);
  59.         }
  60.     AEDisposeDesc(&docList);
  61.     return(noErr);
  62.     }
  63.  
  64. local pascal OSErr MyHandlePDoc(const AppleEvent *e, AppleEvent *r, long Refcon)
  65.     {
  66.     e;//Unused
  67.     r;//Unused
  68.     Refcon;//Unused
  69.     //DebugStr("\pMyHandlePDoc");
  70.     MyStopAlert(alert_cannot_print);
  71.     return(errAENoUserInteraction);
  72.     }
  73.  
  74. #define kUserCanceled 1 // What is this supposed to be?
  75.  
  76. local pascal OSErr MyHandleQuit(const AppleEvent *e, AppleEvent *r, long Refcon)
  77.     {
  78.     OSErr err = MoreParameters(e);
  79.     r;//Unused
  80.     Refcon;//Unused
  81.     //DebugStr("\pMyHandleQuit");
  82.     if (err) return(err);
  83.     //if (quitalert()) err = kUserCanceled;
  84.     //else
  85.     quitting = TRUE;
  86.     return(err);
  87.     }
  88.  
  89. export void AppleEventInits(void)
  90.     {
  91.     EventRecord e;
  92.     if (!hasAppleEvents) return;
  93.     AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, MyHandleOApp, 0, FALSE);
  94.     AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,   MyHandleODoc, 0, FALSE);
  95.     AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,  MyHandlePDoc, 0, FALSE);
  96.     AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, MyHandleQuit, 0, FALSE);
  97.  
  98.     // Get the first event, which should be an OApp or an ODoc,
  99.     // possibly telling us which preferences file to use.
  100.     WaitNextEvent(highLevelEventMask, &e, 0, NULL);
  101.     if (e.what == kHighLevelEvent) AEProcessAppleEvent(&e);
  102.     }
  103.