Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsAEUtils.cpp File Reference
#include <string.h>
#include "nsAETokens.h"
#include "nsAEUtils.h"

Go to the source code of this file.

Functions

static OSErr AECoerceDescData (const AEDesc *theAEDesc, DescType typeCode, void *dataPtr, Size maximumSize)
OSErr CreateAliasAEDesc (AliasHandle theAlias, AEDesc *ioDesc)
OSErr GetTextFromAEDesc (const AEDesc *inDesc, Handle *outTextHandle)
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 CreateThreadAEInfo (const AppleEvent *event, AppleEvent *reply, TThreadAEInfoPtr *outThreadAEInfo)
void DisposeThreadAEInfo (TThreadAEInfo *threadAEInfo)
OSErr SuspendThreadAE (TThreadAEInfo *threadAEInfo)
static OSErr AddErrorCodeToReply (TThreadAEInfo *threadAEInfo, OSErr threadError)
OSErr ResumeThreadAE (TThreadAEInfo *threadAEInfo, OSErr threadError)
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 DescToPString (const AEDesc *desc, Str255 aPString, short maxLength)
OSErr DescToCString (const AEDesc *desc, CStr255 aCString, 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 NormalizeAbsoluteIndex (const AEDesc *keyData, long *index, long maxIndex, Boolean *isAllItems)
OSErr ProcessFormRange (AEDesc *keyData, AEDesc *start, AEDesc *stop)

Function Documentation

static OSErr AddErrorCodeToReply ( TThreadAEInfo threadAEInfo,
OSErr  threadError 
) [static]

Definition at line 239 of file nsAEUtils.cpp.

{
       long          errorValue = threadError;
       
       if (threadError == noErr) return noErr;
       
       return AEPutParamPtr(&threadAEInfo->mReply, keyErrorNumber, typeLongInteger,  (Ptr)&errorValue, sizeof(long));
}

Here is the caller graph for this function:

static OSErr AECoerceDescData ( const AEDesc *  theAEDesc,
DescType  typeCode,
void dataPtr,
Size  maximumSize 
) [static]

Definition at line 150 of file nsAEUtils.cpp.

{
       OSErr err;
       
       if (theAEDesc->descriptorType != typeCode)
       {
              AEDesc coercedDesc = { typeNull, nil };
              err = AECoerceDesc(theAEDesc, typeCode, &coercedDesc);
              if (err != noErr) return err;
              
              err = AEGetDescData(&coercedDesc, dataPtr, maximumSize);
              AEDisposeDesc(&coercedDesc);
              return err;
       }
       else
       {
           return AEGetDescData(theAEDesc, dataPtr, maximumSize);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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  aCString,
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: