home *** CD-ROM | disk | FTP | other *** search
- /*
- * MacAE.c, (C) SPDsoft
- * 1994, MacGzip 0.3
- * August 18, 1995; 1.0
- */
-
- #include <AppleEvents.h>
- #include "MacAE.h"
- #include "FileTypes.h"
- #include "Globals.h"
- #include "Work.h"
-
- /******************************************************************************/
- /* key codes
- *
- * I get these values from the inspection of return values of GetKeys
- * I have no idea about if they are defined somewhere...
- * If you are interested, you can get 'GetKeys' Application from
- * ftp://ivo.cps.unizar.es/SPDsoft/
- */
-
- #define IsOptKey(a) a[1] & 0x00000004 /* 0x3a in keyboard layout (?) */
- #define IsShiftKey(a) a[1] & 0x00000001 /* 0x38 in keyboard layout (?) */
- #define IsCtrlKey(a) a[1] & 0x00000008
-
- #define IsAKey(a) a[0] & 0x01000000 /* 0x00 in keyboard layout (?) */
- #define IsBKey(a) a[0] & 0x00080000 /* 0x0b in keyboard layout (?) */
- #define IsMKey(a) a[1] & 0x00400000 /* 0x2e in keyboard layout (?) */
-
-
- /******************************************************************************/
-
- #define kDropSoundID 129
-
- static OSErr MyGotRequiredParams (AppleEvent *theAppleEvent);
-
- /******************************************************************************/
- /* Standard AE */
-
- pascal OSErr MyHandleODoc ( AppleEvent *theAppleEvent,
- AppleEvent* reply,
- long handlerRefCon )
- {
- FSSpec myFSS;
- AEDescList docList;
- OSErr AEerr, res;
- long index,
- itemsInList;
- Size actualSize;
- AEKeyword keywd;
- DescType returnedType;
- KeyMap theKeys;
-
- AEerr = AEGetParamDesc (theAppleEvent, keyDirectObject, typeAEList, &docList);
- if (AEerr)
- return AEerr;
-
- AEerr = MyGotRequiredParams (theAppleEvent);
- if (AEerr)
- return AEerr;
-
- AEerr = AECountItems (&docList, &itemsInList);
-
- GetKeys(theKeys);
-
- if ( gPrefs.Misc.BeepWhenDone )
- MyBeep( kDropSoundID );
-
- for (index = 1, res=0; index <= itemsInList; index++)
- {
- AEerr = AEGetNthPtr (&docList, index, typeFSS, &keywd,
- &returnedType, (Ptr) &myFSS, sizeof(myFSS), &actualSize);
- if (AEerr)
- return AEerr;
-
- res = new_work(
- IsAKey (theKeys) ?
- kAppKeyASCII :
- IsBKey (theKeys) ?
- kAppKeyBin :
- IsMKey (theKeys) ?
- kAppKeyMBin :
- 0,
-
- gPrefs.Misc.Keys ?
- (
- IsOptKey( theKeys ) ?
- kMisc_gzip :
- IsShiftKey( theKeys ) ?
- kMisc_gunzip :
- kMisc_auto
-
- )
- :
- kMisc_auto,
- gPrefs.Misc.Keys && IsCtrlKey(theKeys),
- &myFSS );
-
- }
-
- AEerr = AEDisposeDesc (&docList);
-
- return res;
- }
-
- pascal OSErr MyHandlePDoc ( AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefCon )
- {
- /* can't print by now */
- return ( errAEEventNotHandled );
- }
-
- pascal OSErr MyHandleOApp ( AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefCon )
- {
- gApp.StartupFiles = FALSE;
-
- return ( MyGotRequiredParams (theAppleEvent) );
- }
-
-
- pascal OSErr MyHandleQuit ( AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefcon )
- {
- OSErr AEerr;
-
- if (noErr != (AEerr = MyGotRequiredParams(theAppleEvent)))
- {
- // an error occurred: do the necessary error handling
- return AEerr;
- }
-
- /* we should cleanup here */
-
- gApp.quit = TRUE;
-
- return ( noErr );
- }
-
- /******************************************************************************/
- static OSErr MyGotRequiredParams (AppleEvent *theAppleEvent)
- {
- DescType returnedType;
- Size actualSize;
- OSErr myerr;
-
- myerr = AEGetAttributePtr ( theAppleEvent, keyMissedKeywordAttr,
- typeWildCard, &returnedType, nil, 0,
- &actualSize
- );
-
- if (myerr == errAEDescNotFound) // you got all the required parameters
- return noErr;
- else if (!myerr) // you missed a required parameter
- return errAEEventNotHandled;
- else // the call to AEGetAttributePtr failed
- return myerr;
- }
-