home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / µSim 1.0.5 / source / AEHandlers.c next >
Encoding:
Text File  |  1995-12-06  |  5.9 KB  |  214 lines  |  [TEXT/CWIE]

  1. /*
  2. Copyright © 1993,1994,1995 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. //#pragma load "MacDump"
  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. #ifndef __SCRIPT__
  85. #define    smSystemScript    -1
  86. #endif
  87.                                     case kFTY_CSTOREPAD    :    
  88.                                     case kFTY_CSTORE    :    
  89.                                         if (ReadyToTerminate()) {
  90.                                             err = myOpenCSFile(&myFSS, smSystemScript,
  91.                                                                 (myInfo.fdFlags & kfIsStationery) != 0);
  92.                                             UnloadSeg(myOpenCSFile);
  93.                                             }
  94.                                         break;
  95.                                     case kFTY_RAM    :    err = myOpenFile(&myFSS, gMMemory, kSIZE_RAM);
  96.                                                         UnloadSeg(myOpenFile);
  97.                                         break;
  98.                                     case kFTY_REG    :    err = OpenProcessorState(&myFSS);
  99.                                                         UnloadSeg(OpenProcessorState);
  100.                                         break;
  101.                                     case 'TEXT'    :    err = myAsmFile(&myFSS);
  102.                                                     UnloadSeg(myAsmFile);
  103.                                         break;
  104.                                     default :    err = paramErr;
  105.                                     }
  106.                                 }
  107.                             }
  108.                         }
  109.                     }
  110.     (void)AEDisposeDesc(&docList);
  111.     }
  112. if (movableModalInFront) {
  113.     (void) StopAlert_UPP(kALRT_PLEASEDISMISSMOVABLEMODAL, nil);
  114.     err = noErr;
  115.     }
  116. if (myIdleFunctUPP)
  117.     DisposeRoutineDescriptor(myIdleFunctUPP);
  118. return err;
  119. }
  120.  
  121. pascal OSErr myHandlePDOC(const AppleEvent */*theAppleEvent*/, AppleEvent */*reply*/,
  122.                     long /*handlerRefcon*/)
  123. {
  124. //#pragma unused (theAppleEvent, reply, handlerRefcon)
  125.  
  126. return errAEEventNotHandled;
  127. }
  128.  
  129. pascal OSErr myHandleQUIT(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  130.                     long /*handlerRefcon*/)
  131. {
  132. //#pragma unused (reply, handlerRefcon)
  133.  
  134. register OSErr    err;
  135.  
  136. err = myGotRequiredParams(theAppleEvent);
  137. return(err ? err : (ReadyToTerminate() ? (gDoneFlag = true, noErr) : userCanceledErr));
  138. }
  139.  
  140. static OSErr myGotRequiredParams(const AppleEvent *theAppleEvent)
  141. {
  142. DescType    returnedType;
  143. Size    actualSize;
  144. register OSErr    err;
  145.  
  146. err = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
  147.                         &returnedType, 0L, 0, &actualSize);
  148. return(err ? (err == errAEDescNotFound ? noErr : err) : errAEEventNotHandled);
  149. }
  150.  
  151. pascal Boolean myIdleFunct(EventRecord *event, long *sleepTime, RgnHandle *mouseRg)
  152. {
  153. switch (event->what) {
  154.     case nullEvent:
  155.         *mouseRg = (RgnHandle)nil;
  156.         *sleepTime = ULONG_MAX;
  157.         break;
  158.     case updateEvt:
  159.         DoUpdate(event);
  160.         break;
  161.     case activateEvt:
  162.         DoActivate(event);
  163.         break;
  164.     case osEvt:
  165.         DoOSEvent(event);
  166.         break;
  167.     }
  168. return false;
  169. }
  170.  
  171. pascal OSErr myHandleIO(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  172.                     long /*handlerRefcon*/)
  173. {
  174. //#pragma unused (reply, handlerRefcon)
  175.  
  176. AEIdleUPP    myIdleFunctUPP = NewAEIdleProc(myIdleFunct);
  177. register OSErr    err;
  178.  
  179. if ((err = myGotRequiredParams(theAppleEvent)) == noErr)
  180.     if ((err = AESetInteractionAllowed(kAEInteractWithSelf)) == noErr)
  181.         if ((err = AEInteractWithUser(kNoTimeOut, 0L, myIdleFunctUPP)) == noErr) {
  182.             gInTheForeground = true;
  183.             InitCursor();
  184. //            PostEvent(keyDown, 3);
  185. //            DebugStr("\pCheck menu flags");
  186.             if ((*gMenu_Windows)->enableFlags & 1L &&
  187.                 (*gMenu_Windows)->enableFlags & (1L << kMItem_IO))
  188.                 DoMenuWindows(kMItem_IO);
  189.             }
  190. if (myIdleFunctUPP)
  191.     DisposeRoutineDescriptor(myIdleFunctUPP);
  192. return err;
  193. }
  194.  
  195. pascal OSErr myHandleGenericAlert(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  196.                             long /*handlerRefcon*/)
  197. {
  198. //#pragma unused (reply, handlerRefcon)
  199.  
  200. AEIdleUPP    myIdleFunctUPP = NewAEIdleProc(myIdleFunct);
  201. register OSErr    err;
  202.  
  203. if ((err = myGotRequiredParams(theAppleEvent)) == noErr)
  204.     if ((err = AESetInteractionAllowed(kAEInteractWithSelf)) == noErr)
  205.         if ((err = AEInteractWithUser(kNoTimeOut, 0L, myIdleFunctUPP)) == noErr) {
  206.             gInTheForeground = true;
  207.             InitCursor();
  208.             }
  209. if (myIdleFunctUPP)
  210.     DisposeRoutineDescriptor(myIdleFunctUPP);
  211. return err;
  212. }
  213.  
  214.