[ Home | CW Bug Reports | Mail ]

LModelObject::GetModelTokenSelf()での formRangeサポート
Subject: SUG -- formRange support in the LModelObject::GetModelTokenSelf()
 
---------------------------------------------------------------------------
METROWERKS PRODUCT AND USAGE SECTION
 
Product name :            [ CodeWarrior Professional ]
Product version :         [ Pro 4 ]
Component name :          [ PowerPlant ]
Generating:               [ Mac OS 68K / Mac OS PowerPC ]
Purpose:                  [ application ]
 
---------------------------------------------------------------------------
SUGGESTION
 
You can support the formRange KeyForm quite easily in the
LModelObject::GetModelTokenSelf(). Just add the following code in the
switch statement. This generic method works well.
 

    //-------------------------------------------------------------------------
    //  additional case block to process formRange KeyForm
    //-------------------------------------------------------------------------
    case formRange: {
        OSErr           err;
        StAEDescriptor  selectionRecord;
        StAEDescriptor  rangeStaSpec;
        StAEDescriptor  rangeStaToken;
        StAEDescriptor  rangeEndSpec;
        StAEDescriptor  rangeEndToken;
 
        err = ::AECoerceDesc(&inKeyData,typeAERecord,selectionRecord);
        ThrowIfError_(err);
        err = ::AEGetKeyDesc(selectionRecord,keyAERangeStart,typeObjectSpecifier,rangeStaSpec);
        ThrowIfError_(err);
        err = LModelDirector::Resolve(rangeStaSpec,rangeStaToken);
        ThrowIfError_(err);
        err = ::AEGetKeyDesc(selectionRecord,keyAERangeStop,typeObjectSpecifier,rangeEndSpec);
        ThrowIfError_(err);
        err = LModelDirector::Resolve(rangeEndSpec,rangeEndToken);
        ThrowIfError_(err);
        LModelObject    *staObj = GetModelFromToken(rangeStaToken);
        LModelObject    *endObj = GetModelFromToken(rangeEndToken);
        if (   (staObj->GetModelKind() != inModelID)
            || (endObj->GetModelKind() != inModelID)) {
            Throw_(errAENoSuchObject);
        }
        const SInt32    staIdx = GetPositionOfSubModel(inModelID,staObj);
        const SInt32    endIdx = GetPositionOfSubModel(inModelID,endObj);
        if (outToken.descriptorType == typeNull) {
            err = ::AECreateList(nil,0,false,&outToken);
            ThrowIfError_(err);
        }
        for ( SInt32 idx = staIdx; idx <= endIdx; idx++ ) {
            StAEDescriptor  subToken;
            GetSubModelByPosition(inModelID,idx,subToken);
            err = ::AEPutDesc(&outToken,0,subToken);
            ThrowIfError_(err);
        }
        break;
    }
    //-------------------------------------------------------------------------
    default:
        GetSubModelByComplexKey(inModelID, inKeyForm, inKeyData,
                                outToken);
        break;


この Pageは MacOS X + Radio UserLand で作っています。