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/aevt.c
/************************************************************************************* |
# |
# aevt.c |
# |
# Apple events handler. |
# |
# Author(s): Michael Marinkovich |
# marink@apple.com |
# |
# Modification History: |
# |
# 10/12/95 MWM Initial coding |
# |
# Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved |
# |
# |
# You may incorporate this sample code into your applications without |
# restriction, though the sample code has been provided "AS IS" and the |
# responsibility for its operation is 100% yours. However, what you are |
# not permitted to do is to redistribute the source as "DSC Sample 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 Code, but that you've made changes. |
# |
*************************************************************************************/ |
#include <AppleEvents.h> |
#include <Windows.h> |
#include "App.h" |
#include "Proto.h" |
//---------------------------------------------------------------------- |
// Globals |
//---------------------------------------------------------------------- |
extern Boolean gDone; |
extern AEEventHandlerUPP gAEOpenAppUPP; |
extern AEEventHandlerUPP gAEQuitAppUPP; |
extern AEEventHandlerUPP gAEOpenDocUPP; |
extern AEEventHandlerUPP gAEPrintDocUPP; |
//---------------------------------------------------------------------- |
// |
// AEInit - initialize all the core apple events |
// |
// |
//---------------------------------------------------------------------- |
OSErr AEInit(void) |
{ |
OSErr err = noErr; |
// allocate UPPs |
gAEOpenAppUPP = NewAEEventHandlerProc(DoAEOpenApp); |
gAEQuitAppUPP = NewAEEventHandlerProc(DoAEQuitApp); |
gAEOpenDocUPP = NewAEEventHandlerProc(DoAEOpenDoc); |
gAEPrintDocUPP = NewAEEventHandlerProc(DoAEPrintDoc); |
if (nil != gAEOpenAppUPP) // install auto Open App |
err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, |
gAEOpenAppUPP, 0L, false ); |
if (noErr == err && nil != gAEQuitAppUPP) // install auto Quit App |
err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, |
gAEQuitAppUPP, 0L, false ); |
if (noErr == err && nil != gAEOpenDocUPP) // install auto Open Document |
err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments, |
gAEOpenDocUPP, 0L,false); |
if (noErr == err && nil != gAEPrintDocUPP) // install auto Print Document |
err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments, |
gAEPrintDocUPP, 0L,false); |
return err; |
} |
//---------------------------------------------------------------------- |
// |
// AEDispose - dispose of UPPs |
// |
// |
//---------------------------------------------------------------------- |
void AEDispose(void) |
{ |
if (nil != gAEOpenAppUPP) |
DisposeRoutineDescriptor(gAEOpenAppUPP); |
if (nil != gAEQuitAppUPP) |
DisposeRoutineDescriptor(gAEQuitAppUPP); |
if (nil != gAEOpenDocUPP) |
DisposeRoutineDescriptor(gAEOpenDocUPP); |
if (nil != gAEPrintDocUPP) |
DisposeRoutineDescriptor(gAEPrintDocUPP); |
} |
//---------------------------------------------------------------------- |
// |
// DoAEOpenApp - called by the Finder at launch time |
// |
// |
//---------------------------------------------------------------------- |
pascal OSErr DoAEOpenApp(AppleEvent *event, AppleEvent reply, long refCon) |
{ |
#pragma unused( event, reply, refCon ) |
return noErr; |
} |
//---------------------------------------------------------------------- |
// |
// DoAEQuitApp - called when the Finder asks app to quit |
// |
// |
//---------------------------------------------------------------------- |
pascal OSErr DoAEQuitApp(AppleEvent *event, AppleEvent reply, long refCon) |
{ |
#pragma unused(event, reply, refCon) |
// set the global quit flag |
gDone = true; |
return noErr; |
} |
//---------------------------------------------------------------------- |
// |
// DoAEOpenDoc - called when the Finder asks app to open a document |
// |
// |
//---------------------------------------------------------------------- |
pascal OSErr DoAEOpenDoc(AppleEvent *event, AppleEvent reply, long refCon) |
{ |
#pragma unused(event, reply, refCon) |
return noErr; |
} |
//---------------------------------------------------------------------- |
// |
// DoAEPrintDoc - called when the Finder asks app to print a document |
// |
// |
//---------------------------------------------------------------------- |
pascal OSErr DoAEPrintDoc(AppleEvent *event, AppleEvent reply, long refCon) |
{ |
#pragma unused(event, reply, refCon) |
return noErr; |
} |
//---------------------------------------------------------------------- |
// |
// GotAEParams - make sure we got proper AE params for an Open |
// Document from the Finder |
// |
//---------------------------------------------------------------------- |
OSErr GotAEParams(AppleEvent *appleEvent) |
{ |
OSErr err; |
DescType type; |
Size size; |
err = AEGetAttributePtr(appleEvent, keyMissedKeywordAttr, |
typeWildCard, &type, nil, 0, &size); |
if (err == errAEDescNotFound) |
return(noErr); |
else |
if (err == noErr) |
return(errAEEventNotHandled); |
return err; |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14