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/SVAEClose.c
/* |
File: SVAEClose.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 "SVAEClose.h" |
#include "SVEditAEUtils.h" |
#include "SVEditWindow.h" // for DPtrFromWindowPtr() |
#include "SVEditFile.h" // for DoClose() |
#pragma segment AppleEvent |
pascal OSErr DoCloseWindow(const AppleEvent *theAppleEvent, |
AppleEvent *reply, |
long handlerRefCon) |
{ |
#pragma unused (reply, handlerRefCon) |
AEDesc directObj = {typeNull, NULL}; |
DescType saveOpt; |
Size actualSize; |
DescType returnedType; |
WindowToken aWindowToken; |
OSErr err; |
// pick up the direct object, which is the object (window) to close or a list of windows |
err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeWildCard, &directObj); |
// pick up optional save param, if any |
saveOpt = kAEAsk; // the default |
(void)AEGetParamPtr(theAppleEvent, keyAESaveOptions, typeEnumerated, &returnedType, |
(Ptr)&saveOpt, sizeof(saveOpt), &actualSize); |
err = GotRequiredParams(theAppleEvent); |
if (noErr != err) goto done; |
if (typeNull != directObj.descriptorType) |
err = CloseDesc(&directObj, saveOpt); |
else if (FrontWindow()) // Default to front window if |
{ // no direct object. |
aWindowToken.tokenWindow = FrontWindow(); |
err = CloseWindowToken(&aWindowToken, saveOpt); |
} |
else |
err = errAENoSuchObject; |
done: |
if (directObj.dataHandle) |
AEDisposeDesc(&directObj); |
return(err); |
} // DoCloseWindow |
OSErr CloseWindowToken(WindowToken* theToken, DescType saveOpt) |
{ |
WindowPtr aWindow; |
DPtr docPtr; |
OSErr err; |
aWindow = theToken->tokenWindow; |
docPtr = DPtrFromWindowPtr(theToken->tokenWindow); |
if (! aWindow || ! docPtr) |
return(errAENoSuchObject); |
// Should do this in prefs |
err = AESetInteractionAllowed(kAEInteractWithAll); |
if (noErr != err) goto done; |
// We do some of the close checks here to avoid |
// calling AEInteractWithUser |
if ((docPtr->dirty) || (docPtr->everSaved == false)) |
if (saveOpt != kAENo) // Don't flip layers if force no ask |
err = AEInteractWithUser(kAEDefaultTimeout, nil, nil); |
if (noErr != err) goto done; |
err = DoClose(aWindow, true, saveOpt); |
done: |
return(err); |
} |
OSErr CloseWindowDesc(AEDesc* windowDesc, DescType saveOpt) |
{ |
WindowToken aWindowToken; |
Size actualSize; |
OSErr err; |
if (typeMyWndw != windowDesc->descriptorType) |
return(errAETypeError); |
GetRawDataFromDescriptor(windowDesc, (Ptr)&aWindowToken, sizeof(aWindowToken), &actualSize); |
err = CloseWindowToken(&aWindowToken, saveOpt); |
return(err); |
} |
OSErr CloseDesc(AEDesc* aDesc, DescType saveOpt) |
{ |
AEDesc closeDesc = {typeNull, NULL}, |
windowDesc = {typeNull, NULL}, |
itemDesc = {typeNull, NULL}; |
long itemCount, |
index; |
DescType theAEKeyword; |
OSErr err; |
if (typeObjectSpecifier == aDesc->descriptorType) |
err = AEResolve(aDesc, kAEIDoMinimum, &closeDesc); |
else |
err = AEDuplicateDesc(aDesc, &closeDesc); |
if (noErr != err) goto done; |
switch (closeDesc.descriptorType) |
{ |
case typeAEList: |
err = AECountItems(&closeDesc, &itemCount); |
if (noErr != err) goto done; |
for (index = 1; index <= itemCount; index++) // Do front back order |
{ |
err = AEGetNthDesc(&closeDesc, index, typeWildCard, &theAEKeyword, &itemDesc); |
if (noErr != err) goto done; |
err = CloseDesc(&itemDesc, saveOpt); // Call recursively |
if (noErr != err) goto done; |
if (itemDesc.dataHandle) |
AEDisposeDesc(&itemDesc); |
} |
break; |
default: |
err = AECoerceDesc(&closeDesc, typeMyWndw, &windowDesc); |
if (noErr != err) goto done; |
err = CloseWindowDesc(&windowDesc, saveOpt); |
} |
done: |
if (closeDesc.dataHandle) |
AEDisposeDesc(&closeDesc); |
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