home *** CD-ROM | disk | FTP | other *** search
- /*==============================================================================
- Project: POV
-
- Version: 3
-
- File: aeAppHdlr.c
-
- Description:
- AppleEvent Handler for App events.
- ------------------------------------------------------------------------------
- Author:
- Eduard [esp] Schwan
- ------------------------------------------------------------------------------
- from Persistence of Vision(tm) Ray Tracer
- Copyright 1996 Persistence of Vision Team
- ------------------------------------------------------------------------------
- NOTICE: This source code file is provided so that users may experiment
- with enhancements to POV-Ray and to port the software to platforms other
- than those supported by the POV-Ray Team. There are strict rules under
- which you are permitted to use this file. The rules are in the file
- named POVLEGAL.DOC which should be distributed with this file. If
- POVLEGAL.DOC is not available or for more info please contact the POV-Ray
- Team Coordinator by leaving a message in CompuServe's Graphics Developer's
- Forum. The latest version of POV-Ray may be found there as well.
-
- This program is based on the popular DKB raytracer version 2.12.
- DKBTrace was originally written by David K. Buck.
- DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
- ------------------------------------------------------------------------------
- Change History:
- 960120 [esp]
- ==============================================================================*/
-
- #define AEAPPHDLR_C
-
- //===========================================================================
- // Headers
- //===========================================================================
-
- #include "aeAppHdlr.h"
-
- #include <AppleEvents.h> // AEInstallEventHandler
- #include <AERegistry.h> // kAECoreEventClass
- #include <AEObjects.h> // formPropertyID
-
- #include <string.h> // strlen
-
- #include "aeUtils.h" // ExtractShortFromAEDesc()
-
-
- //===========================================================================
- // Definitions
- //===========================================================================
-
-
- //===========================================================================
- // Handle null property accessor calls
- //===========================================================================
- #pragma segment Main
-
- pascal OSErr AccPropFromApp( DescType desiredClass,
- AEDesc *containerToken,
- DescType containerClass,
- DescType keyForm,
- AEDesc *keyData,
- AEDescList *tokenDesc,
- long refCon)
- {
- OSErr anError = noErr;
- DescType theProperty;
- MyToken_t aToken;
-
- // make sure we're dealing with properties
- if ((keyForm != formPropertyID) || (keyData->descriptorType != typeType))
- return errAECantSupplyType;
-
- // don't do any non-Application properties
- if (containerToken->descriptorType != typeNull)
- return errAEEventNotHandled;
-
- // extract the desired property from the key
- theProperty = **(DescType**)keyData->dataHandle;
-
- // make sure we handle this property type
- switch (theProperty)
- {
- case pName:
- case pVersion:
- // WARNING... JUST THROWN IN, NOT TESTED AT ALL! [esp]
- // return a property token
- // initialize the returned token structure as being an App property
- aToken.fClass = containerClass;
- aToken.fFlags = eTokIsProperty;
- aToken.fPropCode = theProperty;
- aToken.fValue = 0;
-
- // return the token
- anError = AECreateDesc(desiredClass, (Ptr)&aToken, sizeof(aToken), tokenDesc);
- break;
-
- case pBestType:
- case pClass:
- case pDefaultType:
- default:
- anError = errAENoSuchObject; // or property, really
- break;
- }
-
- return anError;
- } // AccPropFromApp
-
-
- //===========================================================================
- // Handle thing-from-null accessor calls
- //===========================================================================
- #pragma segment Main
-
- pascal OSErr AccThingFromApp( DescType desiredClass,
- AEDesc *containerToken,
- DescType containerClass,
- DescType keyForm,
- AEDesc *keyData,
- AEDescList *tokenDesc,
- long refCon)
- {
- OSErr anError = noErr;
- // DescType theRequestedProperty;
- MyToken_t aToken;
-
- // check for wrong container
- if (containerToken->descriptorType != typeNull)
- return errAETypeError;
-
- // determine how to look up the translator
-
- // we need to eventually do fancy stuff here, but for now, we'll drop through and
- // return the one and only translator token
-
- switch (keyForm)
- {
- case formAbsolutePosition: // 1=1st, -2=2nd from end
- {
- short theIndex;
- anError = ExtractShortFromAEDesc(keyData, &theIndex);
- break;
- }
- case formRelativePosition: // next, previous
- {
- short theIndex;
- anError = ExtractShortFromAEDesc(keyData, &theIndex);
- break;
- }
- case formTest: // A logical or a comparison
- break;
- case formRange: // everything from object 1 to object 2
- break;
- case formPropertyID: // Key data specifies an object property
- break;
- case formUniqueID: // some id that identifies exactly one object
- break;
- case formName: // Key data may be of type 'TEXT'
- break;
- default: // Key form unsupported
- anError = errAEBadKeyForm;
- }
- if (anError)
- return anError;
-
- // initialize the returned token structure as being an AppPrefs class object
- aToken.fClass = cAppPrefs;
- aToken.fFlags = eTokIsObject;
- aToken.fPropCode = typeNull; // it's an object, not a property
- aToken.fValue = 1;
-
- // return the token
- anError = AECreateDesc(desiredClass, (Ptr)&aToken, sizeof(aToken), tokenDesc);
-
- return anError;
- } // AccThingFromApp
-
-
- //===========================================================================
- // Handle null "Get Data" AEvts
- //===========================================================================
- #pragma segment Main
-
- static OSErr AppGetData( AEDesc *theToken,
- AppleEvent *reply)
- {
- OSErr anError = noErr;
- DescType theProperty;
- DescType tempType;
-
- if (GetTokDescFlags(*theToken) == eTokIsObject)
- { // we want the translator object (kObjectToken)
- // We should return an object specifier for the translator, actually
- anError = errAENoSuchObject;
- }
- else
- { // we want a property of the app (eTokIsProperty)
- theProperty = GetTokDescPropCode(*theToken);
- switch (theProperty)
- {
- case pBestType:
- case pClass:
- case pDefaultType: // why, it's an AppPrefs
- tempType = cAppPrefs;
- anError = AECreateDesc(typeType, (Ptr)&tempType, sizeof(tempType), reply);
- break;
- /*
- case pVersion: // put translator version here
- anError = AECreateDesc(cText, (Ptr)&versionBuffer, strlen(versionBuffer), reply);
- break;
- case pName:
- anError = AECreateDesc(cText, (Ptr)&tNameBuffer, strlen(tNameBuffer), reply);
- break;
- */
- default:
- anError = errAEEventNotHandled;
- break;
- }
- }
- return anError;
- } // AppGetData
-
-
- //===========================================================================
- // Handle all null (Application) AEvts
- //===========================================================================
- // Handle App AEvts
- #pragma segment Main
-
- OSErr AEAppDispatcher( AEEventID theEventID,
- AEDesc *tokenDesc,
- AppleEvent *aevt,
- AppleEvent *reply,
- long refCon)
- {
- OSErr anError;
- // DescType theTypeCode;
- // Size actualSize;
-
- // handle the event appropriately
- switch (theEventID)
- {
- case kAEGetData:
- anError = AppGetData(tokenDesc, reply);
- break;
-
- // Events not handled
- case kAEGetDataSize:
- case kAESetData:
- case kAEClone:
- case kAEClose:
- case kAECountElements:
- case kAECreateElement:
- case kAEDelete:
- case kAEDoObjectsExist:
- case kAEGetClassInfo:
- case kAEMove:
- case kAEOpen:
- default:
- anError = errAEEventNotHandled;
- break;
- }
-
- return anError;
- } // AppDispatcher
-
-