home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-09-28 | 3.1 KB | 150 lines | [TEXT/MPS ] |
- /*
- 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);
- }
-