Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions
nsAEUtils.h File Reference
#include <MacTypes.h>
#include <AppleEvents.h>
#include <AERegistry.h>
#include <ASRegistry.h>
#include <AEObjects.h>
#include <FinderRegistry.h>
#include <Files.h>
#include <Errors.h>
#include <Aliases.h>
#include <MacWindows.h>
#include "nsAEDefs.h"
#include "nsMacUtils.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  TThreadAEInfo
class  StAEDesc
class  StEventSuspender
class  StHandleHolder
class  StHandleHolder::getter
class  AEListUtils
class  AEListIterator

Defines

#define ThrowIfNil(a)   do { if (a == nil) { throw((OSErr)memFullErr); } } while (0)
#define ThrowErrIfNil(a, err)   do { if (a == nil) { OSErr theErr = (err); throw((OSErr)theErr); } } while (0)
#define ThrowErrIfTrue(a, err)   do { if (a) { OSErr theErr = (err); throw((OSErr)theErr); } } while (0)
#define ThrowIfOSErr(err)   do { OSErr theErr = (err); if (theErr != noErr) { throw((OSErr)theErr); } } while (0)
#define ThrowOSErr(err)   do { throw((OSErr)err); } while (0)
#define ThrowNoErr()   do { throw((OSErr)noErr); } while (0)
#define pObjectType   'pObT'
#define pTitle   'pTit'
#define pIsModeless   'pNMo'
#define pIsMovableModal   'pMMo'
#define pIsSuspended   'pSus'
#define pIsPalette   'pPal'
#define pIsDialog   'pDlg'
#define pLocation   'pLcn'
#define pFreeMemory   'pMem'
#define pTicks   'pTic'

Typedefs

typedef struct TThreadAEInfo TThreadAEInfo
typedef struct TThreadAEInfoTThreadAEInfoPtr

Functions

OSErr CreateAliasAEDesc (AliasHandle theAlias, AEDesc *ioDesc)
OSErr GetTextFromAEDesc (const AEDesc *inDesc, Handle *outTextHandle)
OSErr CreateThreadAEInfo (const AppleEvent *event, AppleEvent *reply, TThreadAEInfoPtr *outThreadAEInfo)
void DisposeThreadAEInfo (TThreadAEInfo *threadAEInfo)
OSErr SuspendThreadAE (TThreadAEInfo *threadAEInfo)
OSErr ResumeThreadAE (TThreadAEInfo *threadAEInfo, OSErr threadError)
OSErr AEGetDescData (const AEDesc *theAEDesc, void *dataPtr, Size maximumSize)
Size AEGetDescDataSize (const AEDesc *theAEDesc)
OSErr AEReplaceDescData (DescType typeCode, const void *dataPtr, Size dataSize, AEDesc *theAEDesc)
OSErr DescToPString (const AEDesc *desc, Str255 aPString, short maxLength)
OSErr DescToCString (const AEDesc *desc, CStr255 aPString, short maxLength)
OSErr DescToDescType (const AEDesc *desc, DescType *descType)
OSErr DescToBoolean (const AEDesc *desc, Boolean *aBoolean)
OSErr DescToFixed (const AEDesc *desc, Fixed *aFixed)
OSErr DescToFloat (const AEDesc *desc, float *aFloat)
OSErr DescToLong (const AEDesc *desc, long *aLong)
OSErr DescToRGBColor (const AEDesc *desc, RGBColor *aRGBColor)
OSErr DescToShort (const AEDesc *desc, short *aShort)
OSErr DescToTextHandle (const AEDesc *desc, Handle *text)
OSErr DescToRect (const AEDesc *desc, Rect *aRect)
OSErr DescToPoint (const AEDesc *desc, Point *aPoint)
OSErr CheckForUnusedParameters (const AppleEvent *appleEvent)
OSErr PutReplyErrorNumber (AppleEvent *reply, long errorNumber)
OSErr PutReplyErrorMessage (AppleEvent *reply, char *message)
OSErr GetObjectClassFromAppleEvent (const AppleEvent *appleEvent, DescType *objectClass)
OSErr NormalizeAbsoluteIndex (const AEDesc *keyData, long *index, long maxIndex, Boolean *isAllItems)
OSErr ProcessFormRange (AEDesc *keyData, AEDesc *start, AEDesc *stop)

Class Documentation

struct TThreadAEInfo

Definition at line 88 of file nsAEUtils.h.

Class Members
AppleEvent mAppleEvent
Boolean mGotEventData
AppleEvent mReply
SInt32 mSuspendCount

Define Documentation

#define pFreeMemory   'pMem'

Definition at line 81 of file nsAEUtils.h.

#define pIsDialog   'pDlg'

Definition at line 76 of file nsAEUtils.h.

#define pIsModeless   'pNMo'

Definition at line 72 of file nsAEUtils.h.

#define pIsMovableModal   'pMMo'

Definition at line 73 of file nsAEUtils.h.

#define pIsPalette   'pPal'

Definition at line 75 of file nsAEUtils.h.

#define pIsSuspended   'pSus'

Definition at line 74 of file nsAEUtils.h.

#define pLocation   'pLcn'

Definition at line 77 of file nsAEUtils.h.

#define pObjectType   'pObT'

Definition at line 68 of file nsAEUtils.h.

#define pTicks   'pTic'

Definition at line 82 of file nsAEUtils.h.

#define pTitle   'pTit'

Definition at line 71 of file nsAEUtils.h.

#define ThrowErrIfNil (   a,
  err 
)    do { if (a == nil) { OSErr theErr = (err); throw((OSErr)theErr); } } while (0)

Definition at line 61 of file nsAEUtils.h.

#define ThrowErrIfTrue (   a,
  err 
)    do { if (a) { OSErr theErr = (err); throw((OSErr)theErr); } } while (0)

Definition at line 62 of file nsAEUtils.h.

#define ThrowIfNil (   a)    do { if (a == nil) { throw((OSErr)memFullErr); } } while (0)

Definition at line 60 of file nsAEUtils.h.

#define ThrowIfOSErr (   err)    do { OSErr theErr = (err); if (theErr != noErr) { throw((OSErr)theErr); } } while (0)

Definition at line 63 of file nsAEUtils.h.

#define ThrowNoErr ( )    do { throw((OSErr)noErr); } while (0)

Definition at line 65 of file nsAEUtils.h.

#define ThrowOSErr (   err)    do { throw((OSErr)err); } while (0)

Definition at line 64 of file nsAEUtils.h.


Typedef Documentation

typedef struct TThreadAEInfo TThreadAEInfo
typedef struct TThreadAEInfo * TThreadAEInfoPtr

Function Documentation

OSErr AEGetDescData ( const AEDesc *  theAEDesc,
void dataPtr,
Size  maximumSize 
)

Definition at line 107 of file nsAEUtils.cpp.

{
  OSErr err = noErr;
  
       if (theAEDesc->dataHandle)
       {
              Size dataLength = GetHandleSize(theAEDesc->dataHandle);
              BlockMoveData(*theAEDesc->dataHandle, dataPtr, Min(dataLength, maximumSize));
       }
       else
              err = paramErr;
              
       return err;
}

Here is the caller graph for this function:

Size AEGetDescDataSize ( const AEDesc *  theAEDesc)

Definition at line 127 of file nsAEUtils.cpp.

{
       Size          dataSize = 0;
       
       if (theAEDesc->dataHandle)
              dataSize = GetHandleSize(theAEDesc->dataHandle);
       
       return dataSize;
}

Here is the caller graph for this function:

OSErr AEReplaceDescData ( DescType  typeCode,
const void dataPtr,
Size  dataSize,
AEDesc *  theAEDesc 
)

Definition at line 142 of file nsAEUtils.cpp.

{
       AEDisposeDesc(theAEDesc);
       return AECreateDesc(typeCode, dataPtr, dataSize, theAEDesc);
}

Here is the caller graph for this function:

OSErr CheckForUnusedParameters ( const AppleEvent *  appleEvent)

Definition at line 717 of file nsAEUtils.cpp.

{
       OSErr         err           = noErr;
       
       DescType      actualType    = typeNull;
       Size          actualSize    = 0L;
       
       err = AEGetAttributePtr(appleEvent, 
                                                               keyMissedKeywordAttr, 
                                                               typeWildCard,
                                                               &actualType, 
                                                               nil, 
                                                               0, 
                                                               &actualSize);
                                                               
       if (err == errAEDescNotFound)
              err = noErr;
       else
              err = errAEParamMissed;
              
       return err;
}

Here is the caller graph for this function:

OSErr CreateAliasAEDesc ( AliasHandle  theAlias,
AEDesc *  ioDesc 
)

Definition at line 54 of file nsAEUtils.cpp.

{
       char          state = HGetState((Handle)theAlias);
       OSErr  err;

       HLock((Handle)theAlias);
       err = AECreateDesc(typeAlias, *theAlias, GetHandleSize((Handle)theAlias), ioDesc);
       HSetState((Handle)theAlias, state);
       return err;
}
OSErr CreateThreadAEInfo ( const AppleEvent *  event,
AppleEvent *  reply,
TThreadAEInfoPtr outThreadAEInfo 
)

Definition at line 178 of file nsAEUtils.cpp.

{
       TThreadAEInfo *threadAEInfo = nil;
       OSErr         err;
       
       err = MyNewBlockClear(sizeof(TThreadAEInfo), (void**)&threadAEInfo);
       if (err != noErr) return err;
       
       threadAEInfo->mAppleEvent = *event;
       threadAEInfo->mReply = *reply;
       threadAEInfo->mGotEventData = event && reply;
       threadAEInfo->mSuspendCount = nil;
       
       *outThreadAEInfo = threadAEInfo;
       return noErr;

exit:
       MyDisposeBlock(threadAEInfo);
       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr DescToBoolean ( const AEDesc *  desc,
Boolean aBoolean 
)

Definition at line 897 of file nsAEUtils.cpp.

{
    return AECoerceDescData(desc, typeBoolean, aBoolean, sizeof(Boolean));
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr DescToCString ( const AEDesc *  desc,
CStr255  aPString,
short  maxLength 
)

Definition at line 852 of file nsAEUtils.cpp.

{
       if (desc->descriptorType == typeChar)
       {
           long stringLen = AEGetDescDataSize(desc);
           if (stringLen >= maxLength)
               stringLen = maxLength - 1;
              if (AEGetDescData(desc, aCString, stringLen) == noErr)
              aCString[stringLen] = '\0';
       else
                     return errAECoercionFail;
       }
       else
       {
       StAEDesc tempDesc;
              if (AECoerceDesc(desc, typeChar, &tempDesc) == noErr) {
           long stringLen = AEGetDescDataSize(&tempDesc);
           if (stringLen >= maxLength)
               stringLen = maxLength - 1;
              if (AEGetDescData(&tempDesc, aCString, stringLen) == noErr)
                     aCString[stringLen] = '\0';
              else
                     return errAECoercionFail;
              } else
                     return errAECoercionFail;
       }
       return noErr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr DescToDescType ( const AEDesc *  desc,
DescType *  descType 
)

Definition at line 885 of file nsAEUtils.cpp.

{
       if (AEGetDescDataSize(desc) == sizeof(DescType))
           return AEGetDescData(desc, descType, sizeof(DescType));
       else
              return errAECoercionFail;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr DescToFixed ( const AEDesc *  desc,
Fixed *  aFixed 
)

Definition at line 906 of file nsAEUtils.cpp.

{
    return AECoerceDescData(desc, typeFixed, aFixed, sizeof(Fixed));
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr DescToFloat ( const AEDesc *  desc,
float *  aFloat 
)

Definition at line 915 of file nsAEUtils.cpp.

{
    return AECoerceDescData(desc, typeFloat, aFloat, sizeof(float));
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr DescToLong ( const AEDesc *  desc,
long aLong 
)

Definition at line 924 of file nsAEUtils.cpp.

{
    return AECoerceDescData(desc, typeLongInteger, aLong, sizeof(long));
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr DescToPoint ( const AEDesc *  desc,
Point *  aPoint 
)

Definition at line 990 of file nsAEUtils.cpp.

{
    return AECoerceDescData(desc, typeQDPoint, aPoint, sizeof(Point));
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr DescToPString ( const AEDesc *  desc,
Str255  aPString,
short  maxLength 
)

Definition at line 820 of file nsAEUtils.cpp.

{
       if (desc->descriptorType == typeChar)
       {
              long stringLen = AEGetDescDataSize(desc);
              if (stringLen > maxLength)
                     stringLen = maxLength;
              AEGetDescData(desc, aPString+1, stringLen);
              aPString[0] = stringLen;
       }
       else
       {
       StAEDesc tempDesc;
              if (AECoerceDesc(desc, typeChar, &tempDesc) == noErr) {
              long stringLen = tempDesc.GetDataSize();
              if (stringLen > maxLength)
                     stringLen = maxLength;
              AEGetDescData(&tempDesc, aPString+1, stringLen);
              aPString[0] = stringLen;
              } else
                     return errAECoercionFail;
       }
       return noErr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr DescToRect ( const AEDesc *  desc,
Rect *  aRect 
)

Definition at line 981 of file nsAEUtils.cpp.

{
    return AECoerceDescData(desc, typeRectangle, aRect, sizeof(Rect));
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr DescToRGBColor ( const AEDesc *  desc,
RGBColor *  aRGBColor 
)

Definition at line 933 of file nsAEUtils.cpp.

{
    return AECoerceDescData(desc, typeRGBColor, aRGBColor, sizeof(RGBColor));
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr DescToShort ( const AEDesc *  desc,
short *  aShort 
)

Definition at line 942 of file nsAEUtils.cpp.

{
    return AECoerceDescData(desc, typeShortInteger, aShort, sizeof(short));
}

Here is the call graph for this function:

OSErr DescToTextHandle ( const AEDesc *  desc,
Handle *  text 
)

Definition at line 951 of file nsAEUtils.cpp.

{
    Handle data = nil;
    
       if (desc->descriptorType == typeChar)
       {
           Size dataSize = ::AEGetDescDataSize(desc);
           data = ::NewHandle(dataSize);
           if (data == NULL)
               return memFullErr;
        ::HLock(data);
        ::AEGetDescData(desc, *data, dataSize);
        ::HUnlock(data);
       }
       else
       {
       StAEDesc tempDesc;
              if (::AECoerceDesc(desc, typeChar, &tempDesc) == noErr)
                  data = tempDesc.GetTextHandle();
              else
                  return errAECoercionFail;
       }
       *text = data;
       return noErr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DisposeThreadAEInfo ( TThreadAEInfo threadAEInfo)

Definition at line 205 of file nsAEUtils.cpp.

{
       AE_ASSERT(threadAEInfo && threadAEInfo->mSuspendCount == 0, "Bad suspend count");
       MyDisposeBlock(threadAEInfo);
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr GetObjectClassFromAppleEvent ( const AppleEvent *  appleEvent,
DescType *  objectClass 
)

Definition at line 790 of file nsAEUtils.cpp.

{
       OSErr  err     = noErr;
       OSType typeCode;                                 // should be typeType
       long          actualSize;
       
       // Get the class of object that we will count

       err = AEGetParamPtr(appleEvent, 
                                                         keyAEObjectClass, 
                                                         typeType, 
                                                         &typeCode,
                                                         (Ptr)objectClass, 
                                                         sizeof(DescType), 
                                                         &actualSize);
                                                         
       if (typeCode != typeType) 
              err = errAECoercionFail;
       
       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr GetTextFromAEDesc ( const AEDesc *  inDesc,
Handle *  outTextHandle 
)

Definition at line 71 of file nsAEUtils.cpp.

{
       Handle textHandle = nil;
       Size          textLength;
       OSErr  err;

       textLength = AEGetDescDataSize(inDesc);

       err = MyNewHandle(textLength, &textHandle);
       if (err != noErr) return err;
       
       MyHLock(textHandle);
       err = AECoerceDescData(inDesc, typeChar, *textHandle, textLength);
       MyHUnlock(textHandle);
       
       if (err != noErr)
              goto exit;
       
       *outTextHandle = textHandle;
       return noErr;
       
exit:
       MyDisposeHandle(textHandle);
       return err;
}

Here is the call graph for this function:

OSErr NormalizeAbsoluteIndex ( const AEDesc *  keyData,
long index,
long  maxIndex,
Boolean isAllItems 
)

Definition at line 1003 of file nsAEUtils.cpp.

{
       OSErr err = noErr;
       
       *isAllItems = false;                                                  // set to true if we receive kAEAll constant
       
       // Extract the formAbsolutePosition data, either a integer or a literal constant
       
       switch (keyData->descriptorType)
       {
              case typeLongInteger:                                          // positve or negative index
                     if (DescToLong(keyData, index) != noErr)
                            return errAECoercionFail;

                     if (*index < 0)                                                // convert a negative index from end of list to a positive index from beginning of list
                            *index = maxIndex + *index + 1;
                     break;
                     
          case typeAbsoluteOrdinal:                                                                      // 'abso'
                     DescType             ordinalDesc;
                     if (DescToDescType((AEDesc*)keyData, &ordinalDesc) != noErr)
                            ThrowOSErr(errAECoercionFail);
                     
                     switch (ordinalDesc)
                     {
                            case kAEFirst:
                                   *index = 1;
                                   break;
                                   
                            case kAEMiddle:
                                   *index = (maxIndex >> 1) + (maxIndex % 2);
                                   break;
                                          
                            case kAELast:
                                   *index = maxIndex;
                                   break;
                                          
                            case kAEAny:
                                   *index = (TickCount() % maxIndex) + 1;           // poor man's random
                                   break;
                                          
                            case kAEAll:
                                   *index = 1;
                                   *isAllItems = true;
                                   break;
                     }
                     break;

              default:
                     return errAEWrongDataType;
                     break;
       }

       // range-check the new index number
       if ((*index < 1) || (*index > maxIndex))                              
       {
              err = errAEIllegalIndex;
       }

       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr ProcessFormRange ( AEDesc *  keyData,
AEDesc *  start,
AEDesc *  stop 
)

Definition at line 1069 of file nsAEUtils.cpp.

{
       OSErr         err = noErr;
       StAEDesc             rangeRecord;
       StAEDesc             ospec;
       
       // coerce the range record data into an AERecord 
       
       err = AECoerceDesc(keyData, typeAERecord, &rangeRecord);
       if (err != noErr)
              return err;
        
       // object specifier for first object in the range
       err = AEGetKeyDesc(&rangeRecord, keyAERangeStart, typeWildCard, &ospec);
       if (err == noErr && ospec.descriptorType == typeObjectSpecifier)
              err = AEResolve(&ospec, kAEIDoMinimum, start);
              
       if (err != noErr)
              return err;
              
       ospec.Clear();
              
       // object specifier for last object in the range
       
       err = AEGetKeyDesc(&rangeRecord, keyAERangeStop, typeWildCard, &ospec);
       if (err == noErr && ospec.descriptorType == typeObjectSpecifier)
              err = AEResolve(&ospec, kAEIDoMinimum, stop);

       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr PutReplyErrorMessage ( AppleEvent *  reply,
char *  message 
)

Definition at line 765 of file nsAEUtils.cpp.

{
       OSErr err = noErr;
       
       if (reply->dataHandle != nil && message != NULL)
       {
              err = AEPutParamPtr(reply, 
                                                                keyErrorString, 
                                                                typeChar, 
                                                                (Ptr)message, 
                                                                strlen(message));
       }
       return err;
}
OSErr PutReplyErrorNumber ( AppleEvent *  reply,
long  errorNumber 
)

Definition at line 745 of file nsAEUtils.cpp.

{
       OSErr err = noErr;
       
       if (reply->dataHandle != nil && errorNumber != noErr)
       {
              err = AEPutParamPtr(reply, 
                                                                keyErrorNumber, 
                                                                typeLongInteger, 
                                                                (Ptr)&errorNumber, 
                                                                sizeof(long));
       }
       return err;
}

Here is the caller graph for this function:

OSErr ResumeThreadAE ( TThreadAEInfo threadAEInfo,
OSErr  threadError 
)

Definition at line 254 of file nsAEUtils.cpp.

{
       if (threadAEInfo == nil) return noErr;
       if (!threadAEInfo->mGotEventData) return noErr;

       -- threadAEInfo->mSuspendCount;
       
       AddErrorCodeToReply(threadAEInfo, threadError);
       
       if (threadAEInfo->mSuspendCount == 0)
              return AEResumeTheCurrentEvent(&threadAEInfo->mAppleEvent, &threadAEInfo->mReply, (AEEventHandlerUPP)kAENoDispatch, 0);

       return noErr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr SuspendThreadAE ( TThreadAEInfo threadAEInfo)

Definition at line 217 of file nsAEUtils.cpp.

{
       if (threadAEInfo == nil) return noErr;
       if (!threadAEInfo->mGotEventData) return noErr;
       
       if (threadAEInfo->mSuspendCount == 0)
       {
              OSErr  err = AESuspendTheCurrentEvent(&threadAEInfo->mAppleEvent);
              if (err != noErr) return err;
       }
       
       ++ threadAEInfo->mSuspendCount;
       return noErr;
}

Here is the caller graph for this function: