/*---------------------------------------------------------------------------- CompareObjects ----------------------------------------------------------------------------*/ void AEGenericClass::CompareObjects( DescType comparisonOperator, const AEDesc * object, const AEDesc * descriptorOrObject, Boolean * result) { ThrowOSErr(errAEEventNotHandled); }
/*---------------------------------------------------------------------------- CountObjects ----------------------------------------------------------------------------*/ void AEGenericClass::CountObjects( DescType desiredType, DescType containerClass, const AEDesc * container, long * result) { ThrowOSErr(errAEEventNotHandled); }
Boolean AEComparisons::CompareEnumeration(DescType oper, const AEDesc *desc1, const AEDesc *desc2) { OSErr err = noErr; Boolean result = false; long lhs; long rhs; StAEDesc charDesc; // Make each number is a long integer (in case it's a short integer or other integer type) // before extracting the data */ err = AECoerceDesc(desc1, typeChar, &charDesc); ThrowIfOSErr(err); lhs = **(long **)(charDesc.dataHandle); AEDisposeDesc(&charDesc); err = AECoerceDesc(desc2, typeChar, &charDesc); ThrowIfOSErr(err); rhs = **(long **)charDesc.dataHandle; AEDisposeDesc(&charDesc); switch (oper) { case kAEEquals: result = (lhs == rhs); // equality is the only test that makes sense for enumerators break; default: ThrowOSErr(errAEBadTestKey); } return result; }
/*---------------------------------------------------------------------------- MakeNewObject ----------------------------------------------------------------------------*/ void AEGenericClass::MakeNewObject( const DescType insertionPosition, const AEDesc* token, const AEDesc* ptrToWithData, const AEDesc* ptrToWithProperties, AppleEvent* reply) { ThrowOSErr(errAEEventNotHandled); }
/*---------------------------------------------------------------------------- HandleMozillaSuiteEvent ----------------------------------------------------------------------------*/ void AEMozillaSuiteHandler::HandleMozillaSuiteEvent(const AppleEvent *appleEvent, AppleEvent *reply) { OSErr err = noErr; AEEventID eventID; OSType typeCode; Size actualSize = 0L; // Get the event ID err = AEGetAttributePtr(appleEvent, keyEventIDAttr, typeType, &typeCode, (Ptr)&eventID, sizeof(eventID), &actualSize); ThrowIfOSErr(err); try { switch (eventID) { case kDoJavaScriptEvent: // write me! ThrowOSErr(errAEEventNotHandled); break; default: ThrowOSErr(errAEEventNotHandled); break; } } catch (OSErr catchErr) { PutReplyErrorNumber(reply, catchErr); throw; } catch ( ... ) { PutReplyErrorNumber(reply, paramErr); throw; } }
Boolean AEComparisons::TryPrimitiveComparison(DescType comparisonOperator, const AEDesc *desc1, const AEDesc *desc2) { Boolean result = false; // This has to handle all the data types used in the application's // object model implementation. switch (desc1->descriptorType) { case typeChar: result = CompareTexts(comparisonOperator, desc1, desc2); break; case typeShortInteger: // also covers typeSMInt 'shor' case typeLongInteger: // also covers typeInteger 'long' case typeMagnitude: // 'magn' result = CompareInteger(comparisonOperator, desc1, desc2); break; case typeEnumerated: result = CompareEnumeration(comparisonOperator, desc1, desc2); break; case typeFixed: result = CompareFixed(comparisonOperator, desc1, desc2); break; case typeFloat: result = CompareFloat(comparisonOperator, desc1, desc2); break; case typeBoolean: result = CompareBoolean(comparisonOperator, desc1, desc2); break; case typeRGBColor: result = CompareRGBColor(comparisonOperator, desc1, desc2); break; case typeQDRectangle: result = CompareRect(comparisonOperator, desc1, desc2); break; case typeQDPoint: result = ComparePoint(comparisonOperator, desc1, desc2); break; default: ThrowOSErr(errAEWrongDataType); } return result; }
Boolean AEComparisons::CompareInteger(DescType oper, const AEDesc *desc1, const AEDesc *desc2) { OSErr err = noErr; Boolean result = false; long lhs; long rhs; StAEDesc longDesc; // Make each number is a long integer (in case it's a short integer or other integer type) // before extracting the data */ err = AECoerceDesc(desc1, typeLongInteger, &longDesc); ThrowIfOSErr(err); lhs = **(long **)(longDesc.dataHandle); AEDisposeDesc(&longDesc); err = AECoerceDesc(desc2, typeLongInteger, &longDesc); ThrowIfOSErr(err); rhs = **(long **)longDesc.dataHandle; AEDisposeDesc(&longDesc); switch (oper) { case kAEEquals: result = (lhs == rhs); break; case kAELessThan: result = (lhs < rhs); break; case kAELessThanEquals: result = (lhs <= rhs); break; case kAEGreaterThan: result = (lhs > rhs); break; case kAEGreaterThanEquals: result = (lhs >= rhs); break; default: ThrowOSErr(errAEBadTestKey); } return result; }
Boolean AEComparisons::CompareBoolean(DescType oper, const AEDesc *desc1, const AEDesc *desc2) { Boolean result = false; Boolean bool1 = ((**(char **)desc1->dataHandle) != 0); Boolean bool2 = ((**(char **)desc2->dataHandle) != 0); if (oper == kAEEquals) result = (bool1 == bool2); else ThrowOSErr(errAEBadTestKey); // No other tests make sense return result; }
Boolean AEComparisons::CompareRect(DescType oper, const AEDesc *desc1, const AEDesc *desc2) { OSErr err = noErr; Boolean result = false; Rect lhs; Rect rhs; err = DescToRect(desc1, &lhs); ThrowIfOSErr(err); err = DescToRect(desc2, &rhs); ThrowIfOSErr(err); switch (oper) { // compare size AND location case kAEEquals: result = ((lhs.top == rhs.top) && (lhs.left == rhs.left) && (lhs.bottom == rhs.bottom) && (lhs.right == rhs.right)); break; // compare size only on the rest of the tests case kAELessThan: result = (((lhs.bottom - lhs.top) < (rhs.bottom - rhs.top)) && ((lhs.right - lhs.left) < (lhs.right - rhs.left))); break; case kAELessThanEquals: result = (((lhs.bottom - lhs.top) < (rhs.bottom - rhs.top)) && ((lhs.right - lhs.left) < (lhs.right - rhs.left))); break; case kAEGreaterThan: result = (((lhs.bottom - lhs.top) < (rhs.bottom - rhs.top)) && ((lhs.right - lhs.left) < (lhs.right - rhs.left))); break; case kAEGreaterThanEquals: result = (((lhs.bottom - lhs.top) < (rhs.bottom - rhs.top)) && ((lhs.right - lhs.left) < (lhs.right - rhs.left))); break; case kAEContains: // Note: two identical Rects contain each other, according to this test: result = ((lhs.top <= rhs.top) && (lhs.left <= rhs.left) && (lhs.bottom >= rhs.bottom) && (lhs.right >= rhs.right)); break; default: ThrowOSErr(errAEBadTestKey); // No other tests make sense } return result; }
std::string PIUActionList::GetString (uint32 inIndex) { REQUIRE_NON_NULL (sPSActionList); REQUIRE_NON_NULL (fList); std::string value; char *buffer = NULL; try { uint32 length; // Get the length ThrowIfOSErr (sPSActionList->GetStringLength (fList, inIndex, &length)); // Add one for the null terminator (unfortunately, this is necessary) length++; // Get the string into a temporary buffer buffer = new char[length]; if (buffer == NULL) ThrowOSErr (memFullErr); ThrowIfOSErr (sPSActionList->GetString (fList, inIndex, buffer, length)); // Remember value = std::string (buffer); delete[] buffer; buffer = NULL; } catch (...) { if (buffer != NULL) { delete[] buffer; buffer = NULL; } throw; } return value; }
Boolean AEComparisons::ComparePoint(DescType oper, const AEDesc *desc1, const AEDesc *desc2) { OSErr err = noErr; Boolean result = false; Point lhs; Point rhs; err = DescToPoint(desc1, &lhs); ThrowIfOSErr(err); err = DescToPoint(desc2, &rhs); ThrowIfOSErr(err); switch (oper) { case kAEEquals: result = (lhs.h = rhs.h && lhs.v == rhs.v); break; case kAELessThan: result = (lhs.h < rhs.h && lhs.v < rhs.v); break; case kAELessThanEquals: result = (lhs.h <= rhs.h && lhs.v <= rhs.v); break; case kAEGreaterThan: result = (lhs.h > rhs.h && lhs.v > rhs.v); break; case kAEGreaterThanEquals: result = (lhs.h >= rhs.h && lhs.v >= rhs.v); break; default: ThrowOSErr(errAEBadTestKey); // No other tests make sense } return result; }
Boolean AEComparisons::CompareFloat(DescType oper, const AEDesc *desc1, const AEDesc *desc2) { OSErr err = noErr; Boolean result = false; float lhs; float rhs; err = DescToFloat(desc1, &lhs); ThrowIfOSErr(err); err = DescToFloat(desc2, &rhs); ThrowIfOSErr(err); switch (oper) { case kAEEquals: result = (lhs == rhs); break; case kAELessThan: result = (lhs < rhs); break; case kAELessThanEquals: result = (lhs <= rhs); break; case kAEGreaterThan: result = (lhs > rhs); break; case kAEGreaterThanEquals: result = (lhs >= rhs); break; default: ThrowOSErr(errAEBadTestKey); } return result; }
Boolean AEComparisons::CompareRGBColor(DescType oper, const AEDesc *desc1, const AEDesc *desc2) { OSErr err = noErr; Boolean result = false; RGBColor lhs; RGBColor rhs; err = DescToRGBColor(desc1, &lhs); ThrowIfOSErr(err); err = DescToRGBColor(desc2, &rhs); ThrowIfOSErr(err); if (oper == kAEEquals) result = EqualRGB(lhs, rhs); else ThrowOSErr(errAEBadTestKey); // No other tests make sense return result; }
/*---------------------------------------------------------------------------- HandleSendMessage ----------------------------------------------------------------------------*/ void AEGenericClass::HandleSendMessage(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply) { ThrowOSErr(errAEEventNotHandled); }
Boolean AEComparisons::CompareTexts(DescType oper, const AEDesc *desc1, const AEDesc *desc2) { Boolean result = false; short compareResult; Handle lhsHandle = 0, rhsHandle = 0; char *lhs; char *rhs; long lhsSize; long rhsSize; // FIXME: this can leak lhsHandle if second conversion fails. if (DescToTextHandle(desc1, &lhsHandle) != noErr || DescToTextHandle(desc2, &rhsHandle) != noErr) goto fail; lhsSize = GetHandleSize(lhsHandle); HLock(lhsHandle); lhs = *(lhsHandle); rhsSize = GetHandleSize(rhsHandle); HLock(rhsHandle); rhs = *(rhsHandle); compareResult = ::CompareText(lhs, rhs, lhsSize, rhsSize, nil); switch (oper) { case kAEEquals: result = (compareResult == 0); break; case kAELessThan: result = (compareResult < 0); break; case kAELessThanEquals: result = (compareResult <= 0); break; case kAEGreaterThan: result = (compareResult > 0); break; case kAEGreaterThanEquals: result = (compareResult >= 0); break; case kAEBeginsWith: if (rhsSize > lhsSize) { result = false; } else { // compare only the number of characters in rhs // begin comparing at the beginning of lhs compareResult = CompareText(lhs, rhs, rhsSize, rhsSize, nil); result = (compareResult == 0); } break; case kAEEndsWith: if (rhsSize > lhsSize) { result = false; } else { // compare only the number of characters in rhs // begin comparing rhsSize characters from the end of lhs // start lhs += (lhsSize - rhsSize); compareResult = CompareText(lhs, rhs, rhsSize, rhsSize, nil); result = (compareResult == 0); } break; case kAEContains: // Here I use an inefficient search strategy, but we're dealing with small amounts // of text and by using CompareText(), we're doing the same style of comparison // as in the other cases above. result = false; while (lhsSize >= rhsSize) { compareResult = CompareText(lhs, rhs, rhsSize, rhsSize, nil); if (compareResult == 0) { result = true; break; } lhs++; lhsSize--; } break; default: ThrowOSErr(errAEBadTestKey); } fail: if (lhsHandle) DisposeHandle(lhsHandle); if (rhsHandle) DisposeHandle(rhsHandle); return result; }