home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / µSim 1.1 / source / AEHandlers.c next >
Encoding:
C/C++ Source or Header  |  1997-05-23  |  5.8 KB  |  209 lines  |  [TEXT/CWIE]

  1. /*
  2. Copyright © 1993-1997 Fabrizio Oddone
  3. ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
  4. This source code is distributed as freeware:
  5. you may copy, exchange, modify this code.
  6. You may include this code in any kind of application: freeware,
  7. shareware, or commercial, provided that full credits are given.
  8. You may not sell or distribute this code for profit.
  9. */
  10.  
  11. #include    <Limits.h>
  12.  
  13. #include    "UtilsSys7.h"
  14. #include    "FabLibResIDs.h"
  15.  
  16. #include    "AEHandlers.h"
  17. #include    "Assembler.h"
  18. #include    "ControlStore.h"
  19. #include    "DoMenu.h"
  20. #include    "Globals.h"
  21. #include    "Main.h"
  22. #include    "myMemory.h"
  23. #include    "SimUtils.h"
  24.  
  25. //#pragma segment Main
  26.  
  27. static OSErr myGotRequiredParams(const AppleEvent *theAppleEvent);
  28.  
  29.  
  30. pascal OSErr myHandleOAPP(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  31.                     long /*handlerRefcon*/)
  32. {
  33. //#pragma unused (reply, handlerRefcon)
  34.  
  35. AEIdleUPP    myIdleFunctUPP = NewAEIdleProc(myIdleFunct);
  36. register OSErr    err;
  37.  
  38. if ((err = myGotRequiredParams(theAppleEvent)) == noErr)
  39.     if ((err = AESetInteractionAllowed(kAEInteractWithAll)) == noErr)
  40.         if ((err = AEInteractWithUser(kNoTimeOut, 0L, myIdleFunctUPP)) == noErr)
  41.             if (DocIsOpen() == false) {
  42.                 DoNew();
  43.                 UnloadSeg(DoNew);
  44.                 DoMenuWindows(kMItem_Microprogram);
  45.                 }
  46. if (myIdleFunctUPP)
  47.     DisposeRoutineDescriptor(myIdleFunctUPP);
  48. return err;
  49. }
  50.  
  51. pascal OSErr myHandleODOC(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  52.                     long /*handlerRefcon*/)
  53. {
  54. //#pragma unused (reply, handlerRefcon)
  55.  
  56. AEIdleUPP    myIdleFunctUPP = NewAEIdleProc(myIdleFunct);
  57. FSSpec    myFSS;
  58. FInfo    myInfo;
  59. AEDescList    docList;
  60. AEKeyword    keywd;
  61. DescType    returnedType;
  62. Size    actualSize;
  63. long    itemsInList;
  64. WindowPtr    ww;
  65. register long    i;
  66. register OSErr    err;
  67. Boolean    movableModalInFront = false;
  68.  
  69. if (noErr == (err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList))) {
  70.     if ((err = myGotRequiredParams(theAppleEvent)) == noErr)
  71.         if ((err = AESetInteractionAllowed(kAEInteractWithAll)) == noErr)
  72.             if ((err = AEInteractWithUser(kNoTimeOut, 0L, myIdleFunctUPP)) == noErr)
  73.                 if ((err = AECountItems(&docList, &itemsInList)) == noErr) {
  74.                     ww = FrontWindow();
  75.                     if (ww && isMovableModal(ww))
  76.                         movableModalInFront = true;
  77.                     else
  78.                     for (i = 1; i <= itemsInList; i++) {
  79.                         if ((err = AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType,
  80.                                                 (Ptr)&myFSS, sizeof(myFSS), &actualSize)) == noErr) {
  81.                             if ((err = FSpGetFInfoCompat(&myFSS, &myInfo)) == noErr) {
  82.                                 switch (myInfo.fdType) {
  83. /* we should get the script code from the Apple Event; how??? */
  84.                                     case kFTY_CSTOREPAD    :    
  85.                                     case kFTY_CSTORE    :    
  86.                                         if (ReadyToTerminate()) {
  87.                                             err = myOpenCSFile(&myFSS, smCurrentScript,
  88.                                                                 (myInfo.fdFlags & kfIsStationery) != 0);
  89.                                             UnloadSeg(myOpenCSFile);
  90.                                             }
  91.                                         break;
  92.                                     case kFTY_RAM    :    err = myOpenFile(&myFSS, gMMemory, kSIZE_RAM);
  93.                                                         UnloadSeg(myOpenFile);
  94.                                         break;
  95.                                     case kFTY_REG    :    err = OpenProcessorState(&myFSS);
  96.                                                         UnloadSeg(OpenProcessorState);
  97.                                         break;
  98.                                     case 'TEXT'    :    err = myAsmFile(&myFSS);
  99.                                                     UnloadSeg(myAsmFile);
  100.                                         break;
  101.                                     default :    err = paramErr;
  102.                                     }
  103.                                 }
  104.                             }
  105.                         }
  106.                     }
  107.     (void)AEDisposeDesc(&docList);
  108.     }
  109. if (movableModalInFront) {
  110.     (void) StopAlert_UPP(kALRT_PLEASEDISMISSMOVABLEMODAL, nil);
  111.     err = noErr;
  112.     }
  113. if (myIdleFunctUPP)
  114.     DisposeRoutineDescriptor(myIdleFunctUPP);
  115. return err;
  116. }
  117.  
  118. pascal OSErr myHandlePDOC(const AppleEvent */*theAppleEvent*/, AppleEvent */*reply*/,
  119.                     long /*handlerRefcon*/)
  120. {
  121. //#pragma unused (theAppleEvent, reply, handlerRefcon)
  122.  
  123. return errAEEventNotHandled;
  124. }
  125.  
  126. pascal OSErr myHandleQUIT(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  127.                     long /*handlerRefcon*/)
  128. {
  129. //#pragma unused (reply, handlerRefcon)
  130.  
  131. register OSErr    err;
  132.  
  133. err = myGotRequiredParams(theAppleEvent);
  134. return(err ? err : (ReadyToTerminate() ? (gDoneFlag = true, noErr) : userCanceledErr));
  135. }
  136.  
  137. static OSErr myGotRequiredParams(const AppleEvent *theAppleEvent)
  138. {
  139. DescType    returnedType;
  140. Size    actualSize;
  141. register OSErr    err;
  142.  
  143. err = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
  144.                         &returnedType, 0L, 0, &actualSize);
  145. return(err ? (err == errAEDescNotFound ? noErr : err) : errAEEventNotHandled);
  146. }
  147.  
  148. pascal Boolean myIdleFunct(EventRecord * event, long * sleepTime, RgnHandle * mouseRg)
  149. {
  150. switch (event->what) {
  151.     case nullEvent:
  152.         *mouseRg = (RgnHandle)nil;
  153.         *sleepTime = ULONG_MAX;
  154.         break;
  155.     case updateEvt:
  156.         DoUpdate(event);
  157.         break;
  158.     case activateEvt:
  159.         DoActivate(event);
  160.         break;
  161.     case osEvt:
  162.         DoOSEvent(event);
  163.         break;
  164.     }
  165. return false;
  166. }
  167.  
  168. pascal OSErr myHandleIO(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  169.                     long /*handlerRefcon*/)
  170. {
  171. //#pragma unused (reply, handlerRefcon)
  172.  
  173. AEIdleUPP    myIdleFunctUPP = NewAEIdleProc(myIdleFunct);
  174. register OSErr    err;
  175.  
  176. if ((err = myGotRequiredParams(theAppleEvent)) == noErr)
  177.     if ((err = AESetInteractionAllowed(kAEInteractWithSelf)) == noErr)
  178.         if ((err = AEInteractWithUser(kNoTimeOut, 0L, myIdleFunctUPP)) == noErr) {
  179.             gInTheForeground = true;
  180.             InitCursor();
  181.             if ((*gMenu_Windows)->enableFlags & 1L &&
  182.                 (*gMenu_Windows)->enableFlags & (1L << kMItem_IO))
  183.                 DoMenuWindows(kMItem_IO);
  184.             }
  185. if (myIdleFunctUPP)
  186.     DisposeRoutineDescriptor(myIdleFunctUPP);
  187. return err;
  188. }
  189.  
  190. pascal OSErr myHandleGenericAlert(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  191.                             long /*handlerRefcon*/)
  192. {
  193. //#pragma unused (reply, handlerRefcon)
  194.  
  195. AEIdleUPP    myIdleFunctUPP = NewAEIdleProc(myIdleFunct);
  196. register OSErr    err;
  197.  
  198. if ((err = myGotRequiredParams(theAppleEvent)) == noErr)
  199.     if ((err = AESetInteractionAllowed(kAEInteractWithSelf)) == noErr)
  200.         if ((err = AEInteractWithUser(kNoTimeOut, 0L, myIdleFunctUPP)) == noErr) {
  201.             gInTheForeground = true;
  202.             InitCursor();
  203.             }
  204. if (myIdleFunctUPP)
  205.     DisposeRoutineDescriptor(myIdleFunctUPP);
  206. return err;
  207. }
  208.  
  209.