home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / Talking KeyBoard / Source / AppleEvents / aeevents.c < prev    next >
Encoding:
Text File  |  1998-06-06  |  3.5 KB  |  104 lines  |  [TEXT/CWIE]

  1. // Program Author: Paul Baxter
  2. //    pbaxter@assistivetech.com
  3. //
  4. //
  5. #include <Speech.h>
  6. #include <DeskBus.h>
  7. #include <Retrace.h>
  8.  
  9. #include "pref.h"
  10. #include "globals.h"
  11. #include "aeevents.h"
  12. #include "aegetdata.h"
  13. #include "aesetdata.h"
  14. #include "command.h"
  15.  
  16. static pascal short AEHandlerOAPP(AppleEvent *event, AppleEvent *reply, long refCon);
  17. static pascal short AEHandlerODOC(AppleEvent *event, AppleEvent *reply, long refCon);
  18. static pascal short AEHandlerPDOC(AppleEvent *event, AppleEvent *reply, long refCon);
  19. static pascal short AEHandlerQUIT(AppleEvent *event, AppleEvent *reply, long refCon);
  20.  
  21. // * ****************************************************************************** *
  22. // *    AEHandlerOAPP
  23. // *                            Handle Open Application
  24. // * ****************************************************************************** *
  25. static pascal short AEHandlerOAPP(AppleEvent *event, AppleEvent *reply, long refCon)
  26. {
  27. #pragma unused (event, reply, refCon)
  28.     return(0);
  29. }
  30.     
  31. // * ****************************************************************************** *
  32. // *    AEHandlerODOC
  33. // *                            Handle Open Document
  34. // * ****************************************************************************** *
  35. pascal short AEHandlerODOC(AppleEvent *event, AppleEvent *reply, long refCon)
  36. {
  37. #pragma unused (event, reply, refCon)
  38.     return(0);
  39. }
  40.     
  41. // * ****************************************************************************** *
  42. // *    AEHandlerPDOC
  43. // *                            Handle Print Document
  44. // * ****************************************************************************** *
  45. pascal short AEHandlerPDOC(AppleEvent *event, AppleEvent *reply, long refCon)
  46. {
  47. #pragma unused (event, reply, refCon)
  48.     return(0);
  49. }
  50.  
  51. // * ****************************************************************************** *
  52. // *    AEHandlerQUIT
  53. // *                            Handle Quit
  54. // * ****************************************************************************** *
  55. pascal short AEHandlerQUIT(AppleEvent *event, AppleEvent *reply, long refCon)
  56. {
  57. #pragma unused (event, reply, refCon)
  58.     ProcessCommand(CHANGEVALUE(QuitCmd, kTrueValue), nil);
  59.     return(0);
  60. }
  61.     
  62. // * ****************************************************************************** *
  63. // *    InitHLEvents
  64. // *                            Init High Level Events
  65. // * ****************************************************************************** *
  66. void InitHLEvents(void)
  67. {
  68.     short err=0;
  69.  
  70.     if (HasAppleEvents()) {
  71.         err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, 
  72.                 NewAEEventHandlerProc(AEHandlerOAPP), 0, 0);
  73.         err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, 
  74.                 NewAEEventHandlerProc(AEHandlerODOC), 0, 0);
  75.         err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, 
  76.                 NewAEEventHandlerProc(AEHandlerPDOC), 0, 0);
  77.         err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, 
  78.                 NewAEEventHandlerProc(AEHandlerQUIT), 0, 0);
  79.         err = AEInstallEventHandler( kAECoreSuite, kAESetData,
  80.                 NewAEEventHandlerProc(DoSetData),   0, 0);
  81.         err = AEInstallEventHandler( kAECoreSuite, kAEGetData,
  82.                 NewAEEventHandlerProc(DoGetData),   0, 0);
  83.     }
  84. }
  85.  
  86.  
  87. // * ****************************************************************************** *
  88. // *    HasAppleEvents
  89. // *                            See if we have High Level events
  90. // * ****************************************************************************** *
  91. Boolean HasAppleEvents(void)
  92. {
  93.     OSErr err;
  94.     long response;
  95.     Boolean appleEvents = false;
  96.  
  97.     err = Gestalt(gestaltAppleEventsAttr, &response);
  98.     if(!err) {
  99.         if(response & (1L << gestaltAppleEventsPresent)) {
  100.             appleEvents = true;
  101.         }
  102.     }
  103.     return appleEvents;
  104. }