AppleEvents.h
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:20k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /*
  2.      File:       AppleEvents.h
  3.  
  4.      Contains:   AppleEvent Package Interfaces.
  5.  
  6.      Version:    Technology: System 7.5
  7.                  Release:    QuickTime 6.0.2
  8.  
  9.      Copyright:  (c) 1989-2001 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:      For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __APPLEEVENTS__
  18. #define __APPLEEVENTS__
  19. #ifndef __MACTYPES__
  20. #include "MacTypes.h"
  21. #endif
  22. #ifndef __MIXEDMODE__
  23. #include "MixedMode.h"
  24. #endif
  25. #ifndef __NOTIFICATION__
  26. #include "Notification.h"
  27. #endif
  28. #ifndef __EVENTS__
  29. #include "Events.h"
  30. #endif
  31. /*
  32.     Note:   The functions and types for the building and parsing AppleEvent  
  33.             messages has moved to AEDataModel.h
  34. */
  35. #ifndef __AEDATAMODEL__
  36. #include "AEDataModel.h"
  37. #endif
  38. #if PRAGMA_ONCE
  39. #pragma once
  40. #endif
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. #if PRAGMA_IMPORT
  45. #pragma import on
  46. #endif
  47. #if PRAGMA_STRUCT_ALIGN
  48.     #pragma options align=mac68k
  49. #elif PRAGMA_STRUCT_PACKPUSH
  50.     #pragma pack(push, 2)
  51. #elif PRAGMA_STRUCT_PACK
  52.     #pragma pack(2)
  53. #endif
  54. enum {
  55.                                                                 /* Keywords for Apple event parameters */
  56.     keyDirectObject             = FOUR_CHAR_CODE('----'),
  57.     keyErrorNumber              = FOUR_CHAR_CODE('errn'),
  58.     keyErrorString              = FOUR_CHAR_CODE('errs'),
  59.     keyProcessSerialNumber      = FOUR_CHAR_CODE('psn '),       /* Keywords for special handlers */
  60.     keyPreDispatch              = FOUR_CHAR_CODE('phac'),       /* preHandler accessor call */
  61.     keySelectProc               = FOUR_CHAR_CODE('selh'),       /* more selector call */
  62.                                                                 /* Keyword for recording */
  63.     keyAERecorderCount          = FOUR_CHAR_CODE('recr'),       /* available only in vers 1.0.1 and greater */
  64.                                                                 /* Keyword for version information */
  65.     keyAEVersion                = FOUR_CHAR_CODE('vers')        /* available only in vers 1.0.1 and greater */
  66. };
  67. /* Event Class */
  68. enum {
  69.     kCoreEventClass             = FOUR_CHAR_CODE('aevt')
  70. };
  71. /* Event ID's */
  72. enum {
  73.     kAEOpenApplication          = FOUR_CHAR_CODE('oapp'),
  74.     kAEOpenDocuments            = FOUR_CHAR_CODE('odoc'),
  75.     kAEPrintDocuments           = FOUR_CHAR_CODE('pdoc'),
  76.     kAEQuitApplication          = FOUR_CHAR_CODE('quit'),
  77.     kAEAnswer                   = FOUR_CHAR_CODE('ansr'),
  78.     kAEApplicationDied          = FOUR_CHAR_CODE('obit')
  79. };
  80. /* Constants for recording */
  81. enum {
  82.     kAEStartRecording           = FOUR_CHAR_CODE('reca'),       /* available only in vers 1.0.1 and greater */
  83.     kAEStopRecording            = FOUR_CHAR_CODE('recc'),       /* available only in vers 1.0.1 and greater */
  84.     kAENotifyStartRecording     = FOUR_CHAR_CODE('rec1'),       /* available only in vers 1.0.1 and greater */
  85.     kAENotifyStopRecording      = FOUR_CHAR_CODE('rec0'),       /* available only in vers 1.0.1 and greater */
  86.     kAENotifyRecording          = FOUR_CHAR_CODE('recr')        /* available only in vers 1.0.1 and greater */
  87. };
  88. /* parameter to AESend */
  89. typedef OptionBits                      AESendOptions;
  90. enum {
  91.     kAENeverInteract            = 0x00000010,                   /* server should not interact with user */
  92.     kAECanInteract              = 0x00000020,                   /* server may try to interact with user */
  93.     kAEAlwaysInteract           = 0x00000030,                   /* server should always interact with user where appropriate */
  94.     kAECanSwitchLayer           = 0x00000040,                   /* interaction may switch layer */
  95.     kAEDontRecord               = 0x00001000,                   /* don't record this event - available only in vers 1.0.1 and greater */
  96.     kAEDontExecute              = 0x00002000,                   /* don't send the event for recording - available only in vers 1.0.1 and greater */
  97.     kAEProcessNonReplyEvents    = 0x00008000                    /* allow processing of non-reply events while awaiting synchronous AppleEvent reply */
  98. };
  99. typedef SInt32                          AESendMode;
  100. enum {
  101.     kAENoReply                  = 0x00000001,                   /* sender doesn't want a reply to event */
  102.     kAEQueueReply               = 0x00000002,                   /* sender wants a reply but won't wait */
  103.     kAEWaitReply                = 0x00000003,                   /* sender wants a reply and will wait */
  104.     kAEDontReconnect            = 0x00000080,                   /* don't reconnect if there is a sessClosedErr from PPCToolbox */
  105.     kAEWantReceipt              = 0x00000200                    /* (nReturnReceipt) sender wants a receipt of message */
  106. };
  107. /* Constants for timeout durations */
  108. enum {
  109.     kAEDefaultTimeout           = -1,                           /* timeout value determined by AEM */
  110.     kNoTimeOut                  = -2                            /* wait until reply comes back, however long it takes */
  111. };
  112. /* priority param of AESend */
  113. typedef SInt16                          AESendPriority;
  114. enum {
  115.     kAENormalPriority           = 0x00000000,                   /* post message at the end of the event queue */
  116.     kAEHighPriority             = 0x00000001                    /* post message at the front of the event queue (same as nAttnMsg) */
  117. };
  118. typedef SInt8                           AEEventSource;
  119. enum {
  120.     kAEUnknownSource            = 0,
  121.     kAEDirectCall               = 1,
  122.     kAESameProcess              = 2,
  123.     kAELocalProcess             = 3,
  124.     kAERemoteProcess            = 4
  125. };
  126. typedef CALLBACK_API( OSErr , AEEventHandlerProcPtr )(const AppleEvent *theAppleEvent, AppleEvent *reply, UInt32 handlerRefcon);
  127. typedef CALLBACK_API( Boolean , AEIdleProcPtr )(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn);
  128. typedef CALLBACK_API( Boolean , AEFilterProcPtr )(EventRecord *theEvent, long returnID, long transactionID, const AEAddressDesc *sender);
  129. typedef STACK_UPP_TYPE(AEEventHandlerProcPtr)                   AEEventHandlerUPP;
  130. typedef STACK_UPP_TYPE(AEIdleProcPtr)                           AEIdleUPP;
  131. typedef STACK_UPP_TYPE(AEFilterProcPtr)                         AEFilterUPP;
  132. #if OPAQUE_UPP_TYPES
  133.     EXTERN_API(AEEventHandlerUPP)
  134.     NewAEEventHandlerUPP           (AEEventHandlerProcPtr   userRoutine);
  135.     EXTERN_API(AEIdleUPP)
  136.     NewAEIdleUPP                   (AEIdleProcPtr           userRoutine);
  137.     EXTERN_API(AEFilterUPP)
  138.     NewAEFilterUPP                 (AEFilterProcPtr         userRoutine);
  139.     EXTERN_API(void)
  140.     DisposeAEEventHandlerUPP       (AEEventHandlerUPP       userUPP);
  141.     EXTERN_API(void)
  142.     DisposeAEIdleUPP               (AEIdleUPP               userUPP);
  143.     EXTERN_API(void)
  144.     DisposeAEFilterUPP             (AEFilterUPP             userUPP);
  145.     EXTERN_API(OSErr)
  146.     InvokeAEEventHandlerUPP        (const AppleEvent *      theAppleEvent,
  147.                                     AppleEvent *            reply,
  148.                                     UInt32                  handlerRefcon,
  149.                                     AEEventHandlerUPP       userUPP);
  150.     EXTERN_API(Boolean)
  151.     InvokeAEIdleUPP                (EventRecord *           theEvent,
  152.                                     long *                  sleepTime,
  153.                                     RgnHandle *             mouseRgn,
  154.                                     AEIdleUPP               userUPP);
  155.     EXTERN_API(Boolean)
  156.     InvokeAEFilterUPP              (EventRecord *           theEvent,
  157.                                     long                    returnID,
  158.                                     long                    transactionID,
  159.                                     const AEAddressDesc *   sender,
  160.                                     AEFilterUPP             userUPP);
  161. #else
  162.     enum { uppAEEventHandlerProcInfo = 0x00000FE0 };                /* pascal 2_bytes Func(4_bytes, 4_bytes, 4_bytes) */
  163.     enum { uppAEIdleProcInfo = 0x00000FD0 };                        /* pascal 1_byte Func(4_bytes, 4_bytes, 4_bytes) */
  164.     enum { uppAEFilterProcInfo = 0x00003FD0 };                      /* pascal 1_byte Func(4_bytes, 4_bytes, 4_bytes, 4_bytes) */
  165.     #define NewAEEventHandlerUPP(userRoutine)                       (AEEventHandlerUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAEEventHandlerProcInfo, GetCurrentArchitecture())
  166.     #define NewAEIdleUPP(userRoutine)                               (AEIdleUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAEIdleProcInfo, GetCurrentArchitecture())
  167.     #define NewAEFilterUPP(userRoutine)                             (AEFilterUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAEFilterProcInfo, GetCurrentArchitecture())
  168.     #define DisposeAEEventHandlerUPP(userUPP)                       DisposeRoutineDescriptor(userUPP)
  169.     #define DisposeAEIdleUPP(userUPP)                               DisposeRoutineDescriptor(userUPP)
  170.     #define DisposeAEFilterUPP(userUPP)                             DisposeRoutineDescriptor(userUPP)
  171.     #define InvokeAEEventHandlerUPP(theAppleEvent, reply, handlerRefcon, userUPP)  (OSErr)CALL_THREE_PARAMETER_UPP((userUPP), uppAEEventHandlerProcInfo, (theAppleEvent), (reply), (handlerRefcon))
  172.     #define InvokeAEIdleUPP(theEvent, sleepTime, mouseRgn, userUPP)  (Boolean)CALL_THREE_PARAMETER_UPP((userUPP), uppAEIdleProcInfo, (theEvent), (sleepTime), (mouseRgn))
  173.     #define InvokeAEFilterUPP(theEvent, returnID, transactionID, sender, userUPP)  (Boolean)CALL_FOUR_PARAMETER_UPP((userUPP), uppAEFilterProcInfo, (theEvent), (returnID), (transactionID), (sender))
  174. #endif
  175. /* support for pre-Carbon UPP routines: NewXXXProc and CallXXXProc */
  176. #define NewAEEventHandlerProc(userRoutine)                      NewAEEventHandlerUPP(userRoutine)
  177. #define NewAEIdleProc(userRoutine)                              NewAEIdleUPP(userRoutine)
  178. #define NewAEFilterProc(userRoutine)                            NewAEFilterUPP(userRoutine)
  179. #define CallAEEventHandlerProc(userRoutine, theAppleEvent, reply, handlerRefcon) InvokeAEEventHandlerUPP(theAppleEvent, reply, handlerRefcon, userRoutine)
  180. #define CallAEIdleProc(userRoutine, theEvent, sleepTime, mouseRgn) InvokeAEIdleUPP(theEvent, sleepTime, mouseRgn, userRoutine)
  181. #define CallAEFilterProc(userRoutine, theEvent, returnID, transactionID, sender) InvokeAEFilterUPP(theEvent, returnID, transactionID, sender, userRoutine)
  182. /**************************************************************************
  183.   The next couple of calls are basic routines used to create, send,
  184.   and process AppleEvents. 
  185. **************************************************************************/
  186. EXTERN_API( OSErr )
  187. AESend                          (const AppleEvent *     theAppleEvent,
  188.                                  AppleEvent *           reply,
  189.                                  AESendMode             sendMode,
  190.                                  AESendPriority         sendPriority,
  191.                                  long                   timeOutInTicks,
  192.                                  AEIdleUPP              idleProc, /* can be NULL */
  193.                                  AEFilterUPP            filterProc) /* can be NULL */       THREEWORDINLINE(0x303C, 0x0D17, 0xA816);
  194. EXTERN_API( OSErr )
  195. AEProcessAppleEvent             (const EventRecord *    theEventRecord)                     THREEWORDINLINE(0x303C, 0x021B, 0xA816);
  196. /* 
  197.  Note: during event processing, an event handler may realize that it is likely
  198.  to exceed the client's timeout limit. Passing the reply to this
  199.  routine causes a wait event to be generated that asks the client
  200.  for more time. 
  201. */
  202. EXTERN_API( OSErr )
  203. AEResetTimer                    (const AppleEvent *     reply)                              THREEWORDINLINE(0x303C, 0x0219, 0xA816);
  204. /**************************************************************************
  205.   The following three calls are used to allow applications to behave
  206.   courteously when a user interaction such as a dialog box is needed. 
  207. **************************************************************************/
  208. typedef SInt8                           AEInteractAllowed;
  209. enum {
  210.     kAEInteractWithSelf         = 0,
  211.     kAEInteractWithLocal        = 1,
  212.     kAEInteractWithAll          = 2
  213. };
  214. EXTERN_API( OSErr )
  215. AEGetInteractionAllowed         (AEInteractAllowed *    level)                              THREEWORDINLINE(0x303C, 0x021D, 0xA816);
  216. EXTERN_API( OSErr )
  217. AESetInteractionAllowed         (AEInteractAllowed      level)                              THREEWORDINLINE(0x303C, 0x011E, 0xA816);
  218. EXTERN_API( OSErr )
  219. AEInteractWithUser              (long                   timeOutInTicks,
  220.                                  NMRecPtr               nmReqPtr,
  221.                                  AEIdleUPP              idleProc)                           THREEWORDINLINE(0x303C, 0x061C, 0xA816);
  222. /**************************************************************************
  223.   These calls are used to set up and modify the event dispatch table.
  224. **************************************************************************/
  225. EXTERN_API( OSErr )
  226. AEInstallEventHandler           (AEEventClass           theAEEventClass,
  227.                                  AEEventID              theAEEventID,
  228.                                  AEEventHandlerUPP      handler,
  229.                                  long                   handlerRefcon,
  230.                                  Boolean                isSysHandler)                       THREEWORDINLINE(0x303C, 0x091F, 0xA816);
  231. EXTERN_API( OSErr )
  232. AERemoveEventHandler            (AEEventClass           theAEEventClass,
  233.                                  AEEventID              theAEEventID,
  234.                                  AEEventHandlerUPP      handler,
  235.                                  Boolean                isSysHandler)                       THREEWORDINLINE(0x303C, 0x0720, 0xA816);
  236. EXTERN_API( OSErr )
  237. AEGetEventHandler               (AEEventClass           theAEEventClass,
  238.                                  AEEventID              theAEEventID,
  239.                                  AEEventHandlerUPP *    handler,
  240.                                  long *                 handlerRefcon,
  241.                                  Boolean                isSysHandler)                       THREEWORDINLINE(0x303C, 0x0921, 0xA816);
  242. /**************************************************************************
  243.  The following four calls are available for applications which need more
  244.  sophisticated control over when and how events are processed. Applications
  245.  which implement multi-session servers or which implement their own
  246.  internal event queueing will probably be the major clients of these
  247.  routines. They can be called from within a handler to prevent the AEM from
  248.  disposing of the AppleEvent when the handler returns. They can be used to
  249.  asynchronously process the event (as MacApp does).
  250. **************************************************************************/
  251. EXTERN_API( OSErr )
  252. AESuspendTheCurrentEvent        (const AppleEvent *     theAppleEvent)                      THREEWORDINLINE(0x303C, 0x022B, 0xA816);
  253. /* 
  254.  Note: The following routine tells the AppleEvent manager that processing
  255.  is either about to resume or has been completed on a previously suspended
  256.  event. The procPtr passed in as the dispatcher parameter will be called to
  257.  attempt to redispatch the event. Several constants for the dispatcher
  258.  parameter allow special behavior. They are:
  259.     - kAEUseStandardDispatch means redispatch as if the event was just
  260.       received, using the standard AppleEvent dispatch mechanism.
  261.     - kAENoDispatch means ignore the parameter.
  262.       Use this in the case where the event has been handled and no
  263.       redispatch is needed.
  264.     - non nil means call the routine which the dispatcher points to.
  265. */
  266. /* Constants for Refcon in AEResumeTheCurrentEvent with kAEUseStandardDispatch */
  267. enum {
  268.     kAEDoNotIgnoreHandler       = 0x00000000,
  269.     kAEIgnoreAppPhacHandler     = 0x00000001,                   /* available only in vers 1.0.1 and greater */
  270.     kAEIgnoreAppEventHandler    = 0x00000002,                   /* available only in vers 1.0.1 and greater */
  271.     kAEIgnoreSysPhacHandler     = 0x00000004,                   /* available only in vers 1.0.1 and greater */
  272.     kAEIgnoreSysEventHandler    = 0x00000008,                   /* available only in vers 1.0.1 and greater */
  273.     kAEIngoreBuiltInEventHandler = 0x00000010,                  /* available only in vers 1.0.1 and greater */
  274.     kAEDontDisposeOnResume      = (long)0x80000000              /* available only in vers 1.0.1 and greater */
  275. };
  276. /* Constants for AEResumeTheCurrentEvent */
  277. enum {
  278.     kAENoDispatch               = 0,                            /* dispatch parameter to AEResumeTheCurrentEvent takes a pointer to a dispatch */
  279.     kAEUseStandardDispatch      = (long)0xFFFFFFFF              /* table, or one of these two constants */
  280. };
  281. EXTERN_API( OSErr )
  282. AEResumeTheCurrentEvent         (const AppleEvent *     theAppleEvent,
  283.                                  const AppleEvent *     reply,
  284.                                  AEEventHandlerUPP      dispatcher,
  285.                                  long                   handlerRefcon)                      THREEWORDINLINE(0x303C, 0x0818, 0xA816);
  286. EXTERN_API( OSErr )
  287. AEGetTheCurrentEvent            (AppleEvent *           theAppleEvent)                      THREEWORDINLINE(0x303C, 0x021A, 0xA816);
  288. EXTERN_API( OSErr )
  289. AESetTheCurrentEvent            (const AppleEvent *     theAppleEvent)                      THREEWORDINLINE(0x303C, 0x022C, 0xA816);
  290. /**************************************************************************
  291.   These calls are used to set up and modify special hooks into the
  292.   AppleEvent manager.
  293. **************************************************************************/
  294. EXTERN_API( OSErr )
  295. AEInstallSpecialHandler         (AEKeyword              functionClass,
  296.                                  AEEventHandlerUPP      handler,
  297.                                  Boolean                isSysHandler)                       THREEWORDINLINE(0x303C, 0x0500, 0xA816);
  298. EXTERN_API( OSErr )
  299. AERemoveSpecialHandler          (AEKeyword              functionClass,
  300.                                  AEEventHandlerUPP      handler,
  301.                                  Boolean                isSysHandler)                       THREEWORDINLINE(0x303C, 0x0501, 0xA816);
  302. EXTERN_API( OSErr )
  303. AEGetSpecialHandler             (AEKeyword              functionClass,
  304.                                  AEEventHandlerUPP *    handler,
  305.                                  Boolean                isSysHandler)                       THREEWORDINLINE(0x303C, 0x052D, 0xA816);
  306. /**************************************************************************
  307.   This call was added in version 1.0.1. If called with the keyword
  308.   keyAERecorderCount ('recr'), the number of recorders that are
  309.   currently active is returned in 'result'
  310.   (available only in vers 1.0.1 and greater).
  311. **************************************************************************/
  312. EXTERN_API( OSErr )
  313. AEManagerInfo                   (AEKeyword              keyWord,
  314.                                  long *                 result)                             THREEWORDINLINE(0x303C, 0x0441, 0xA816);
  315. #if PRAGMA_STRUCT_ALIGN
  316.     #pragma options align=reset
  317. #elif PRAGMA_STRUCT_PACKPUSH
  318.     #pragma pack(pop)
  319. #elif PRAGMA_STRUCT_PACK
  320.     #pragma pack()
  321. #endif
  322. #ifdef PRAGMA_IMPORT_OFF
  323. #pragma import off
  324. #elif PRAGMA_IMPORT
  325. #pragma import reset
  326. #endif
  327. #ifdef __cplusplus
  328. }
  329. #endif
  330. #endif /* __APPLEEVENTS__ */