home *** CD-ROM | disk | FTP | other *** search
- #include <Types.h>
- #include <AppleEvents.h>
- #include <Events.h>
- #include <Memory.h>
- #include <Processes.h>
-
- #include "globals.h"
- #include "appleEventHandlers.h"
- #include "eventHandler.h"
- #include "fileMenuRoutines.h"
-
- /* Private routines */
-
- pascal Boolean IdleProc(EventRecord *theEventRecord, long *sleepTime, RgnHandle *mouseRgn);
-
-
- /* Handle the ‘oapp’ AppleEvent. */
-
- pascal OSErr OAPPHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
- {
- #pragma unused (reply, handlerRefCon)
-
- OSErr oappErr;
- AEKeyword missedKeyWord;
- DescType actualType;
- Size actualSize;
-
- oappErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
-
- if (!oappErr) /* If no error, then a missing parameter was found */
- return errAEParamMissed;
-
- /* Do whatever needs to be done when starting up and return noErr */
-
- return noErr;
- }
-
- /* Handle the ‘odoc’ AppleEvent. */
-
- pascal OSErr ODOCHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
- {
- #pragma unused (reply, handlerRefCon)
-
- OSErr odocErr;
- AEKeyword missedKeyWord;
- DescType actualType;
- Size actualSize;
- AEDescList documentList;
- long itemsInList;
- long i;
- AEKeyword keyWord;
- DescType typeCode;
- FSSpec documentFileSpec;
- TargetID senderType;
- OSType senderCreator;
- ProcessSerialNumber thePSN;
-
- odocErr = AEGetParamDesc(&theAppleEvent, keyDirectObject, typeAEList, &documentList); /* Get list of documents to open */
- if (odocErr)
- return odocErr;
-
- odocErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
-
- if (!odocErr) /* If no error, then a missing parameter was found */
- return errAEParamMissed;
-
- /*
- If we’re in the background, see if the event was sent from the Finder. If so,
- switch to the front.
- */
-
- if (gInBackground) {
- odocErr = AEGetAttributePtr(&theAppleEvent, keyAddressAttr, typeTargetID, &actualType, (Ptr) &senderType, sizeof(senderType), &actualSize);
- BlockMove((Ptr) (&(senderType.name.u.portTypeStr)+1), (Ptr) &(senderCreator), 4);
- if (senderCreator == 'MACS') {
- thePSN.highLongOfPSN = 0;
- thePSN.lowLongOfPSN = kCurrentProcess;
- SetFrontProcess(&thePSN);
- }
- }
-
- /* Open all the documents in documentList */
-
- odocErr = AECountItems(&documentList, &itemsInList); /* Get number of documents */
-
- for (i = 1; i <= itemsInList; i++) {
- odocErr = AEGetNthPtr(&documentList, i, typeFSS, &keyWord, &typeCode, (Ptr) &documentFileSpec, sizeof(documentFileSpec), &actualSize);
- DoOpenFile(&documentFileSpec);
- }
-
- odocErr = AEDisposeDesc(&documentList); /* Dispose of AE structure created by AEGetParamDesc */
- return noErr;
- }
-
- /* Handle the ‘pdoc’ AppleEvent. */
-
- pascal OSErr PDOCHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
- {
- #pragma unused (reply, handlerRefCon)
-
- OSErr pdocErr;
- AEKeyword missedKeyWord;
- DescType actualType;
- Size actualSize;
- AEDescList documentList;
- long itemsInList;
- long i;
- AEKeyword keyWord;
- DescType typeCode;
- FSSpec documentFileSpec;
-
- pdocErr = AEGetParamDesc(&theAppleEvent, keyDirectObject, typeAEList, &documentList); /* Get list of documents to open */
-
- pdocErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
-
- if (!pdocErr) /* If no error, then a missing parameter was found */
- return errAEParamMissed;
-
- /* Print all the documents in documentList */
-
- pdocErr = AECountItems(&documentList, &itemsInList); /* Get number of documents */
-
- for (i = 1; i <= itemsInList; i++) {
- pdocErr = AEGetNthPtr(&documentList, i, typeFSS, &keyWord, &typeCode, (Ptr) &documentFileSpec, sizeof(documentFileSpec), &actualSize);
- DoPrintFile(&documentFileSpec);
- }
-
- pdocErr = AEDisposeDesc(&documentList); /* Dispose of AE structure created by AEGetParamDesc */
- return noErr;
- }
-
- /* Handle the ‘quit’ AppleEvent. */
-
- pascal OSErr QUITHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
- {
- #pragma unused (reply, handlerRefCon)
-
- OSErr quitErr;
- AEKeyword missedKeyWord;
- DescType actualType;
- Size actualSize;
-
- quitErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
-
- if (!quitErr) /* If no error, then a missing parameter was found */
- return errAEParamMissed;
-
- /* Do whatever needs to be done when quitting and return noErr */
-
- gDone = true;
- return noErr;
- }
-
- pascal Boolean IdleProc(EventRecord *theEventRecord, long *sleepTime, RgnHandle *mouseRgn)
- {
- switch (theEventRecord->what) {
- case updateEvt:
- case activateEvt:
- case osEvt: HandleEvent(theEventRecord);
- break;
- case nullEvent: *mouseRgn = nil;
- *sleepTime = 15;
- break;
- }
- return false;
- }
-
-
-