Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Source/SVAERevert.c
/* |
File: SVAERevert.c |
Contains: |
Written by: Original version by Jon Lansdell and Nigel Humphreys. |
3.1 updates by Greg Sutton. |
Copyright: Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
7/20/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
*/ |
#include "SVAERevert.h" |
#include "SVEditWindow.h" // for DPtrFromWindowPtr() |
#include "SVEditFile.h" |
#include "SVEditAEUtils.h" |
#include "SVAETextUtils.h" |
#include "SVAEAccessors.h" |
#include "SVAEDelete.h" |
#pragma segment File |
// ----------------------------------------------------------------------- |
// Name: DoRevert |
// Purpose: Handles the Revert AppleEvent. |
// ----------------------------------------------------------------------- |
pascal OSErr DoRevert(const AppleEvent *theAppleEvent, |
AppleEvent *reply, |
long handlerRefCon) |
{ |
#pragma unused (reply, handlerRefCon) |
AEDesc directObj = {typeNull, NULL}; |
WindowToken aWindowToken; |
OSErr err; |
// pick up the direct object |
err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeWildCard, &directObj); |
err = GotRequiredParams(theAppleEvent); |
if (noErr != err) goto done; |
if (typeNull != directObj.descriptorType) |
err = RevertDesc(&directObj); |
else if (FrontWindow()) // If no direct object given, default |
{ // to the front window. |
aWindowToken.tokenWindow = FrontWindow(); |
err = RevertWindowToken(&aWindowToken); |
} |
else |
err = errAENoSuchObject; |
done: |
if (directObj.dataHandle) |
AEDisposeDesc(&directObj); |
return(err); |
} // DoRevertWindow |
OSErr RevertWindowToken(WindowToken* theToken) |
{ |
DPtr docPtr; |
TextToken aTextToken; |
OSErr err; |
docPtr = DPtrFromWindowPtr(theToken->tokenWindow); |
if (! docPtr) |
return(errAENoSuchObject); |
// Get a token for all the text in the window |
err = TextTokenFromWindowToken(theToken, &aTextToken); |
if (noErr != err) goto done; |
// Delete all the text |
err = DeleteTextToken(&aTextToken); |
if (noErr != err) goto done; |
if (docPtr->everSaved) |
{ |
err = GetFileContents(docPtr->theFSSpec, docPtr); |
if (noErr != err) goto done; |
DoResizeWindow(docPtr); |
docPtr->dirty = false; |
} |
DoUpdate(docPtr->theWindow); |
done: |
return(err); |
} |
OSErr RevertWindowDesc(AEDesc* windowDesc) |
{ |
WindowToken aWindowToken; |
Size actualSize; |
OSErr err; |
if (typeMyWndw != windowDesc->descriptorType) |
return(errAETypeError); |
GetRawDataFromDescriptor(windowDesc, (Ptr)&aWindowToken, sizeof(aWindowToken), &actualSize); |
err = RevertWindowToken(&aWindowToken); |
return(err); |
} |
OSErr RevertDesc(AEDesc* aDesc) |
{ |
AEDesc revertDesc = {typeNull, NULL}, |
windowDesc = {typeNull, NULL}, |
itemDesc = {typeNull, NULL}; |
long itemCount, |
index; |
DescType theAEKeyword; |
OSErr err; |
if (typeObjectSpecifier == aDesc->descriptorType) |
err = AEResolve(aDesc, kAEIDoMinimum, &revertDesc); |
else |
err = AEDuplicateDesc(aDesc, &revertDesc); |
if (noErr != err) goto done; |
switch (revertDesc.descriptorType) |
{ |
case typeAEList: |
err = AECountItems(&revertDesc, &itemCount); |
if (noErr != err) goto done; |
for (index = 1; index <= itemCount; index++) // Do front back order |
{ |
err = AEGetNthDesc(&revertDesc, index, typeWildCard, &theAEKeyword, &itemDesc); |
if (noErr != err) goto done; |
err = RevertDesc(&itemDesc); // Call recursively |
if (noErr != err) goto done; |
if (itemDesc.dataHandle) |
AEDisposeDesc(&itemDesc); |
} |
break; |
default: |
err = AECoerceDesc(&revertDesc, typeMyWndw, &windowDesc); |
if (noErr != err) goto done; |
err = RevertWindowDesc(&windowDesc); |
} |
done: |
if (revertDesc.dataHandle) |
AEDisposeDesc(&revertDesc); |
if (windowDesc.dataHandle) |
AEDisposeDesc(&windowDesc); |
if (itemDesc.dataHandle) |
AEDisposeDesc(&itemDesc); |
return(err); |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-07-22