AmendHub

Download:

nulleric

/

Fix-a-Fork

/

amendments

/

1

Apple Event Handler for OpenDocs


eric made amendment 1 about 1 year ago
--- main.c Wed Nov 8 10:47:50 2023 +++ main.c Wed Nov 8 10:47:50 2023 @@ -0,0 +1,65 @@ +#include <Files.h> +#include <StandardFile.h> +#include <Events.h> +#include <AppleEvents.h> +#include <GestaltEqu.h> + +#include <Types.h> + +// Globals +//OSType gType = 0; +//OSType gCreator = 0; +//Boolean gHandledByDnD = false; + +pascal OSErr DoOpenDoc(AppleEvent *event, AppleEvent *reply, long handlerRefcon); +pascal OSErr DoOpenDoc(AppleEvent *event, AppleEvent *reply, long handlerRefcon) +{ + FSSpec fss; + AEDescList docList; + OSErr err; + long index, itemsInList; + Size actualSize; + AEKeyword keywd; + DescType returnedType; + //short frefNum; + + //err = AEGetParamDesc(event, keyDirectObject, typeAEList, %docList); + if(err != noErr) return err; + err = AECountItems(&docList, &itemsInList); + if(err != noErr) return err; + + for(index = 1; index <= itemsInList; index++) + { + err = AEGetNthPtr(&docList, index, typeFSS, &keywd, &returnedType, (Ptr)&fss, sizeof(fss), &actualSize); + if(err != noErr) return err; + + // got file + //gHandledByDnD = true; + } + AEDisposeDesc(&docList); + return noErr; +} + +void InstallEventHandlers() +{ + EventRecord event; + long hasAppleEvents; + OSErr err; + short i = 0; + + if(Gestalt(gestaltAppleEventsAttr, &hasAppleEvents) == noErr) + { + AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, &DoOpenDoc, 0L, false); + } else { + return; + } + WaitNextEvent(highLevelEventMask, &event, 0, 0); + if(event.what == kHighLevelEvent) + AEProcessAppleEvent(&event); +} + +void main() +{ + InstallEventHandlers(); + return; +}