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/AppleEventHandler.c
/* |
File: AppleEventHandler.c |
Contains: xxx put contents here xxx |
Version: xxx put version here xxx |
Copyright: © 1999 by Apple Computer, Inc., all rights reserved. |
File Ownership: |
DRI: xxx put dri here xxx |
Other Contact: xxx put other contact here xxx |
Technology: xxx put technology here xxx |
Writers: |
(BWS) Brent Schorsch |
Change History (most recent first): |
<SP1> 7/1/99 BWS first checked in |
*/ |
//¥ ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ Includes |
#include <Errors.h> |
#include "AppleEventHandler.h" |
//¥ ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ Private Definitions |
//¥ ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ Private Types |
//¥ ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ Private Variables |
static AEEventHandlerUPP gAppleEventHandler; |
static Boolean *gQuitFlag; |
//¥ ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ Private Functions |
static OSErr AppleEventHandler(const AppleEvent *inEvent, AppleEvent *outReply, UInt32 inRefCon); |
//¥ ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ Public Variables |
//¥ ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ AppleEventsInit |
void |
AppleEventsInit(void) |
{ |
//¥ Install our AppleEvent dispatch routine |
gAppleEventHandler = NewAEEventHandlerProc(AppleEventHandler); |
AEInstallEventHandler(typeWildCard, typeWildCard, gAppleEventHandler, 0L, false); |
} |
//¥ ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ AppleEventsShutDown |
void |
AppleEventsShutDown(void) |
{ |
AERemoveEventHandler(typeWildCard, typeWildCard, gAppleEventHandler, false); |
DisposeRoutineDescriptor(gAppleEventHandler); |
} |
#pragma mark - |
//¥ ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ AppleEventsGotRequiredParams |
Boolean |
AppleEventsGotRequiredParams(const AppleEvent *inEvent) |
{ |
DescType returnedType; |
Size actualSize; |
OSErr theErr; |
theErr = AEGetAttributePtr(inEvent, keyMissedKeywordAttr, typeWildCard, &returnedType, nil, 0, &actualSize); |
return (errAEDescNotFound == theErr); |
} |
//¥ ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ AppleEventsRegisterQuitFlag |
void |
AppleEventsRegisterQuitFlag(Boolean *inFlag) |
{ |
if (nil != inFlag) |
gQuitFlag = inFlag; |
} |
//¥ ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ AppleEventHandler |
static OSErr |
AppleEventHandler(const AppleEvent *inEvent, AppleEvent *outReply, UInt32 inRefCon) |
{ |
#pragma unused (outReply, inRefCon) |
OSErr theErr; |
DescType actualType; |
Size actualSize; |
DescType eventClass, eventID; |
theErr = AEGetAttributePtr(inEvent, keyEventClassAttr, typeType, &actualType, &eventClass, sizeof (eventClass), &actualSize); |
if (noErr != theErr) |
return (theErr); |
theErr = AEGetAttributePtr(inEvent, keyEventIDAttr, typeType, &actualType, &eventID, sizeof (eventID), &actualSize); |
if (noErr != theErr) |
return (theErr); |
if (eventClass == kCoreEventClass) |
{ |
switch (eventID) |
{ |
case kAEOpenApplication: |
return (errAEEventNotHandled); |
break; |
case kAEOpenDocuments: |
return (errAEEventNotHandled); |
break; |
case kAEPrintDocuments: |
return (errAEEventNotHandled); |
break; |
case kAEQuitApplication: |
if (AppleEventsGotRequiredParams(inEvent)) |
{ |
if (nil != gQuitFlag) |
*gQuitFlag ^= 1; |
return (noErr); |
} |
else |
{ |
return (errAEParamMissed); |
} |
break; |
default: |
return (errAEHandlerNotFound); |
} |
} |
return (noErr); |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-10-14