void ObjectTraverse(const AEDescList *object) { static int recurse=0; long count; AEKeyword keyword; DescType data_desc; MacSize data_size; char buffer[1024]; OSStatus err; if (noErr == AECountItems(object, &count)) { for (int i = 1; i <= count; i++) // AERecord starts at index 1 { err = AESizeOfNthItem(object, i, &data_desc, &data_size); if (noErr == err) { err = AEGetNthPtr(object, i, data_desc, &keyword, &data_desc, buffer, 1024, &data_size); if (logfile) { long r; for (r = 0; r < recurse; r++) fprintf(logfile," "); fprintf(logfile,"key:'%c%c%c%c' desc:'%c%c%c%c' size: %ld", FCC_TO_CHARS(keyword), FCC_TO_CHARS(data_desc), data_size); if (err == noErr) { if (data_size == 4) { int val = *((int*) buffer); if ((data_desc == typeSInt32) || (data_desc == typeUInt32)) fprintf(logfile," value: %d", val); if ((data_desc == typeSInt32) || (data_desc == typeUInt32)) fprintf(logfile," value:'%c%c%c%c'", FCC_TO_CHARS(val)); } } fprintf(logfile,"\r"); } if ((err == noErr) && ((data_desc == cObjectSpecifier) || (data_desc == cAEList) || (data_desc == typeAERecord))) { AEDesc obj2; err = AEGetNthDesc(object, i, data_desc, &keyword, &obj2); if (err == noErr) { recurse++; ObjectTraverse(&obj2); recurse--; } } } } } }
uni_char* GetNewStringFromListAndIndex(const AEDescList* desc, long index) { uni_char* uniText = NULL; DescType data_desc; MacSize data_size; OSStatus err; AEKeyword keyword; err = AESizeOfNthItem(desc, index, &data_desc, &data_size); if ((err == noErr) && (data_desc == typeUnicodeText || data_desc == typeChar)) { if (data_desc == typeUnicodeText) { uniText = new uni_char[data_size/2 + 1]; err = AEGetNthPtr(desc, index, data_desc, &keyword, &data_desc, uniText, data_size, &data_size); uniText[data_size/2] = 0; if (err != noErr) { delete [] uniText; uniText = NULL; } } else if (data_desc == typeChar) { char* macText = new char[data_size + 1]; if (macText) { err = AEGetNthPtr(desc, index, data_desc, &keyword, &data_desc, macText, data_size, &data_size); if (err == noErr) { macText[data_size] = 0; uniText = new uni_char[data_size + 1]; gTextConverter->ConvertStringFromMacC(macText, uniText, data_size+1); if (gTextConverter->GotConversionError()) { delete [] uniText; uniText = NULL; } } delete [] macText; } } } return uniText; }
static pascal OSErr odocHandler(const AppleEvent* inEvent, AppleEvent* /*reply*/, long refCon) { AEDescList documentList; OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList, &documentList); if (err == noErr) { err = checkAppleEventForMissingParams(*inEvent); if (err == noErr) { long documentCount; err = AECountItems(&documentList, &documentCount); for (long documentIndex = 1; err == noErr && documentIndex <= documentCount; documentIndex++) { // What kind of document is it? DescType returnedType; Size actualSize; err = AESizeOfNthItem(&documentList, documentIndex, &returnedType, &actualSize); if (err == noErr) { // It is just a normal document file AEKeyword keyword; FSRef ref; err = AEGetNthPtr(&documentList, documentIndex, typeFSRef, &keyword, &returnedType, (Ptr)&ref, sizeof(FSRef), &actualSize); if (err == noErr) { char buf[1024]; err = FSRefMakePath(&ref, reinterpret_cast<UInt8*>(buf), 1024); if ( err == noErr ) reinterpret_cast<mainForm*>(refCon)->fileOpen(QString::fromUtf8(buf)); } } } } AEDisposeDesc(&documentList); } return err; }
static PyObject *AEDesc_AESizeOfNthItem(AEDescObject *_self, PyObject *_args) { PyObject *_res = NULL; OSErr _err; long index; DescType typeCode; Size dataSize; #ifndef AESizeOfNthItem PyMac_PRECHECK(AESizeOfNthItem); #endif if (!PyArg_ParseTuple(_args, "l", &index)) return NULL; _err = AESizeOfNthItem(&_self->ob_itself, index, &typeCode, &dataSize); if (_err != noErr) return PyMac_Error(_err); _res = Py_BuildValue("O&l", PyMac_BuildOSType, typeCode, dataSize); return _res; }