home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-20 | 3.9 KB | 126 lines | [TEXT/CWIE] |
- // SVAECoercions.c
- //
- // 7Edit 3.1d1. Original version by Jon Lansdell and Nigel Humphreys.
- // 3.1 updates by Greg Sutton.
- // ©Apple Computer Inc 1995, all rights reserved.
-
- #include "SVAECoercions.h"
-
- #include "SVEditAEUtils.h"
- #include "SVAETextUtils.h"
-
- #include "SVAEAccessors.h"
- #include "SVAESelect.h"
- #include "SVToken.h"
-
-
- #pragma segment AppleEvent
-
- // Install coercion handlers that coerce a descriptor from one type to another.
-
- OSErr InstallCoercions(void)
- {
- OSErr err;
-
- err = AEInstallCoercionHandler(typeObjectSpecifier, typeMyAppl, (AECoercionHandlerUPP)NewAECoerceDescProc(CoerceObjToAnything), 0, true, false);
- err = AEInstallCoercionHandler(typeObjectSpecifier, typeMyWndw, (AECoercionHandlerUPP)NewAECoerceDescProc(CoerceObjToAnything), 0, true, false);
- err = AEInstallCoercionHandler(typeObjectSpecifier, typeMyText, (AECoercionHandlerUPP)NewAECoerceDescProc(CoerceObjToAnything), 0, true, false);
- err = AEInstallCoercionHandler(typeObjectSpecifier, typeMyTextProp, (AECoercionHandlerUPP)NewAECoerceDescProc(CoerceObjToAnything), 0, true, false);
- err = AEInstallCoercionHandler(typeObjectSpecifier, typeMyWindowProp,(AECoercionHandlerUPP)NewAECoerceDescProc(CoerceObjToAnything), 0, true, false);
- err = AEInstallCoercionHandler(typeObjectSpecifier, typeMyApplProp, (AECoercionHandlerUPP)NewAECoerceDescProc(CoerceObjToAnything), 0, true, false);
-
- err = AEInstallCoercionHandler(typeMyWndw, typeMyText, (AECoercionHandlerUPP)NewAECoerceDescProc(CoerceWindowToText), 0, true, false);
- err = AEInstallCoercionHandler(typeMyWindowProp, typeMyText, (AECoercionHandlerUPP)NewAECoerceDescProc(CoerceWindowPropertyToText), 0, true, false);
-
- return(err);
- }
-
-
- // Takes an object specifier that it resolves using AEResolve
- // then tries to coerce this result into the type specified by toType.
-
- pascal OSErr CoerceObjToAnything(const AEDesc *theAEDesc,
- DescType toType,
- long handlerRefCon,
- AEDesc *result)
- {
- #pragma unused (handlerRefCon)
-
- AEDesc objDesc = {typeNull, NULL};
- OSErr err;
-
- if (theAEDesc->descriptorType != typeObjectSpecifier)
- return(errAEWrongDataType);
-
- // resolve the object specifier
- err = AEResolve(theAEDesc, kAEIDoMinimum, &objDesc);
- if (noErr != err) goto done;
-
- // hopefully it's the right type by now, but we'll give it a nudge
- err = AECoerceDesc(&objDesc, toType, result);
-
- done:
- if (objDesc.dataHandle)
- AEDisposeDesc(&objDesc);
-
- return(err);
- } // CoerceObjToAnything
-
-
- // A window is effectively a text item that contains all the text in the window
- // so allow coercion of windows to text.
-
- pascal OSErr CoerceWindowToText(AEDesc *theAEDesc,
- DescType toType,
- long handlerRefCon,
- AEDesc *result)
- {
- #pragma unused (toType, handlerRefCon)
-
- return(TextDescFromWindowDesc(theAEDesc, result));
- }
-
- // Some window properties are effectively text so allow a coercion
- // e.g. set selection of window 1 to "Something"
-
- pascal OSErr CoerceWindowPropertyToText(AEDesc *theAEDesc,
- DescType toType,
- long handlerRefCon,
- AEDesc *result)
- {
- #pragma unused (toType, handlerRefCon)
-
- WindowPropToken aWindowPropToken;
- TextToken aTextToken;
- Size actualSize;
- short ignore;
- OSErr err;
-
- GetRawDataFromDescriptor(theAEDesc, (Ptr)&aWindowPropToken,
- sizeof(aWindowPropToken), &actualSize);
-
- switch (aWindowPropToken.tokenProperty)
- {
- case pText:
- case pContents:
- err = TextDescFromWindowToken(&(aWindowPropToken.tokenWindowToken), result);
- break;
-
- case pSelection:
- err = GetWindowSelection(aWindowPropToken.tokenWindowToken.tokenWindow,
- &aTextToken, &ignore);
- if (noErr != err) goto done;
-
- err = AECreateDesc(typeMyText, (Ptr)&aTextToken, sizeof(aTextToken), result);
- break;
-
- default: // Most properties don't make sense to be coerced from
- err = errAECoercionFail;
- } // e.g 'select insertion point before bounds of document 1'
-
- done:
- return(err);
- }
-
-
-