home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Papers / C++ Exceptions / µShell / Core Utilities / AEExtras.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-02  |  7.0 KB  |  229 lines  |  [TEXT/CWIE]

  1. #ifndef __AEEXTRAS__
  2. #define __AEEXTRAS__
  3. #pragma once
  4.  
  5. /*
  6.  
  7.     Stuff which should be in the AppleEvent manager but isn't
  8.  
  9. */
  10.  
  11. // JimC 980225 NOTE - this stuff should NEVER throw an exception
  12. // they don't, this is just a reminder to myself :)
  13.  
  14. #include <AppleEvents.h>
  15. #include <AERegistry.h>
  16. #include <ASRegistry.h>
  17. #include <Processes.h>
  18.  
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22.  
  23. enum
  24. {
  25.     typeCString            = 'strC',    // null terminated string
  26.     typePString            = 'strP',    // pascal string
  27.  
  28.     typePropertyID        = 'pID ',    // a property ID (4-char code)
  29.     typeClassID            = 'cID ',    // a class ID (4-char code)
  30.     
  31.     typeTypedData        = 'TypD',    // type/data
  32.     typeFlattenedDesc    = 'fDsc',    // type/size/data
  33.     
  34.     typeDataSize        = 'Dsiz',    // data size - used for GetDataSize
  35.     typeDataExists        = 'Xist',    // data exists - used for Exists
  36.     typeElemCount        = 'Xcnt',    // data exists - used for Exists
  37.     typeDataType        = 'Dtyp',    // data type
  38.  
  39.     typeUniversalTime    = 'gmt ',    // 
  40.  
  41.     typeDateTimeZone    = 'ldtZ',    // 'ldt ' w/time zone
  42. //    typeUnivDateTime    = 'ldtG',    // typeLongDateTime converted to GMT
  43.  
  44.     keyAESingleObject    = '1obj',
  45.  
  46.     // Pseudo key forms:
  47.     formSelf            = 'self',    // psudo key-form to refer to the container in AEObjectSpec
  48.     formData            = 'data',    // psudo key-form to refer to pure data in an AEObjectSpec
  49.     formPropertyTest    = 'pTst',    
  50.  
  51.     // Absolute ordinals
  52.     formAll                = kAEAll,
  53.     formFirst            = kAEFirst,
  54.     formLast            = kAELast,
  55.     formMiddle            = kAEMiddle,
  56.     formAny                = kAEAny,
  57.     
  58.     // Insertion locations
  59.     formIn                = keyASPrepositionIn,
  60.     formBeginning        = kAEBeginning,
  61.     formEnd                = kAEEnd,
  62.     formBefore            = kAEBefore,
  63.     formAfter            = kAEAfter,
  64.     formReplace            = kAEReplace,
  65.  
  66. //    pData     = 'data',    /*  0x64617461 == keyAEData */
  67. //    pValue    = 'valu'
  68. //    pExists = 'have'
  69.  
  70.     keyAEEventTargetAttr = 'disp',     // object spcifier for object event is being sent to == 
  71.     keyAETargetTokenAttr = 'tokn',    // token from resolving keyAEEventTargetAttr
  72.  
  73.     // extra AppleEvent error parameters
  74.  
  75.     keyAEErrorActualType = 'aTyp',    // Actual type in a coercion failure
  76.     keyAEErrorFile         = 'File',    // File the error occurred in
  77.     keyAEErrorLine         = 'Line',    // Line the error occurred on
  78.     keyAEErrorFunc         = 'File',    // Function the error occurred in
  79.  
  80.     zzzzxz
  81. };
  82.  
  83.  
  84. enum {
  85.     kOSAModeDispatchToSubject = 0x20000000    // dispatch event to subject attr
  86. };
  87.  
  88. pascal OSErr InitAEExtras(AEIdleUPP idle, AEFilterUPP filter);
  89.  
  90. pascal void XAEInstallCoerceDescProc(
  91.                 DescType                 fromType,
  92.                 DescType                 toType,
  93.                 AECoerceDescProcPtr     handler);
  94.                 
  95. pascal void XAEInstallCoercePtrProc(
  96.                 DescType                 fromType,
  97.                 DescType                 toType,
  98.                 AECoercePtrProcPtr         handler);
  99.                 
  100. pascal OSErr TempAECreateDesc(
  101.                 DescType                 typeCode,
  102.                 const void*             dataPtr,
  103.                 Size                     dataSize,
  104.                 AEDesc                     *result);
  105.  
  106. pascal OSErr TempAEDuplicateDesc(
  107.                 const AEDesc            *source,
  108.                 AEDesc                    *dest);
  109.                 
  110. pascal OSErr XAEGetCoercionHandler(
  111.                 DescType                 fromType,
  112.                 DescType                 toType,
  113.                 AECoercionHandlerUPP*    handler,
  114.                 long*                    handlerRefcon,
  115.                 Boolean*                fromTypeIsDesc,
  116.                 AECoercionHandlerUPP    skipMe = nil);
  117.     // Gets the handler that the system would call for a given from/to type
  118.                 
  119. pascal OSErr XAECoercePtr(
  120.                 DescType         typeCode,
  121.                 const void*        dataPtr,
  122.                 Size            dataSize,
  123.                 DescType        toType,
  124.                 AEDesc*            result);
  125.     // Same as AECoercePtr, but can be called form a coercion handler
  126.             
  127. pascal OSErr XAECoerceDesc(
  128.                 const AEDesc*    theAEDesc,
  129.                 DescType        toType,
  130.                 AEDesc*            result);
  131.     // Same as AECoerceDesc, but can be called form a coercion handler
  132.  
  133.  
  134. pascal OSErr AEGetDescPtr(
  135.                 const AEDesc*    theAEDesc,
  136.                 DescType        desiredType,
  137.                 DescType*        typeCode,
  138.                 void*            dataPtr,
  139.                 Size            maximumSize,
  140.                 Size*            actualSize); 
  141.     // Gets the data out of an AEDesc with coercion as necessary,
  142.     // providing an API consistant with AEGetXXXPtr, etc.
  143.  
  144. pascal OSErr AEParseInsertionLocation(
  145.                 const AEDesc*        insertLoc,
  146.                 AEDesc*                container,    // the affected container
  147.                 DescType*            position,    // the position enumeration
  148.                 AEDesc*                reference,    // objects to be replaced
  149.                 DescType*            refClass);    // class of reference
  150.  
  151. pascal OSErr AEParseObjectSpecifier(
  152.                 const AEDesc*        object,
  153.                 DescType*            desiredClass,
  154.                 AEDesc*                container,
  155.                 DescType*            keyForm,
  156.                 AEDesc*                keyData);
  157.  
  158.     // routines for taking apart object specifiers and insertion locations
  159.     // note that eiter routine will accept an object specifier or an 
  160.     // insertion location but handle them slightly differently -- if an
  161.     // object specifier is passed to AEParseInsertionLocation it will be
  162.     // returned as the container and position will be fromIn -- if an
  163.     // insertion location is passed to AEParseObjectSpecifier, container
  164.     // will be the container where the insertion is to occur, keyForm
  165.     // will be the position, keyData will be the reference object (if any),
  166.     // and desiredClass will be the class of the reference object if present
  167.     
  168. DescType IsObjectSpecifier(const AEDesc* desc);
  169.  
  170. DescType IsObjectSpecifierOrInsertion(const AEDesc* desc);
  171.  
  172. DescType GetUniformItemType(const AEDesc* list, DescType type = 0, bool recursive = false);
  173.     // given an AEList check if all elements are the same type and
  174.     // return the type (or 0)
  175.     
  176. DescType GetUniformObjectClass(const AEDesc* list, DescType type = 0, bool recursive = false);
  177.     // if list is a list of object specifiers, determine is all specify the same class
  178.     // returns 0 if not all are object specs, cObject if all are object specs
  179.     // or other type if all are objects specs of uniform type
  180.  
  181. pascal OSErr AEGetEventTarget(
  182.                 const AppleEvent*    event,
  183.                 AEDesc*                target,
  184. /*
  185.                 DescType*            containerClass,
  186. */
  187.                 DescType*            desiredClass,
  188. /*                DescType*            keyForm,
  189.                 AEDesc*                keyData,
  190. */
  191.                 long                flags        = 0,
  192.                 AEKeyword*            source        = nil);
  193.     // This routine calculates the object that it the target of the
  194.     // event. The logic is:
  195.     //         keyAEEventTargetAttr if present
  196.     //         container of keyAEInsertHere if present
  197.     //        keyDirectObject if an object specifier
  198.     //        keySubjectAttr if present
  199.     
  200.     // at the moment we support kOSAModeDispatchToDirectObject and 
  201.     // kOSAModeDispatchToSubject for mode flags 
  202.  
  203. pascal OSErr AECopyParams(const AERecord *src,  AERecord *dst, Boolean overwrite);
  204.     // copies all key params of src to dst. If dst is a null descriptor 
  205.     // it is created, otherwise they are merged. If dst is a null descriptor 
  206.     // nothing happens
  207.  
  208. pascal long RandomInRange(long start, long end);
  209.  
  210. extern const ProcessSerialNumber kAESelfPSN;
  211.  
  212. const AEAddressDesc*        AEGetSelfAddress();
  213. AEIdleUPP                    AEGetDefaultIdleProc(void);
  214. AEIdleUPP                    AESetDefaultIdleProc(AEIdleUPP newProc);
  215. AEFilterUPP                    AEGetDefaultFilterProc(void);
  216. AEFilterUPP                    AESetDefaultFilterProc(AEFilterUPP newProc);
  217.  
  218. OSErr    AEBuildEventToSelf(AppleEvent* event, AEEventClass theAEEventClass, AEEventID theAEEventID, char* format, ...);
  219. OSErr    AESendEventToSelf(AEEventClass theAEEventClass, AEEventID theAEEventID, long addition_send_flags, AppleEvent *reply, char* format, ...);
  220. OSErr    AECreateEventToSelf(AEEventClass theAEEventClass, AEEventID theAEEventID, AppleEvent *event, const AEDesc *target = nil);
  221.  
  222. #ifdef __cplusplus
  223. }
  224. #endif
  225.  
  226. #endif __AEEXTRAS__
  227.  
  228.  
  229.