home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / POV-Ray 3.0.2 / src / MacSource / aeAppHdlr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-14  |  7.8 KB  |  270 lines  |  [TEXT/CWIE]

  1. /*==============================================================================
  2. Project:    POV
  3.  
  4. Version:    3
  5.  
  6. File:        aeAppHdlr.c
  7.  
  8. Description:
  9.     AppleEvent Handler for App events.
  10. ------------------------------------------------------------------------------
  11. Author:
  12.     Eduard [esp] Schwan
  13. ------------------------------------------------------------------------------
  14.     from Persistence of Vision(tm) Ray Tracer
  15.     Copyright 1996 Persistence of Vision Team
  16. ------------------------------------------------------------------------------
  17.     NOTICE: This source code file is provided so that users may experiment
  18.     with enhancements to POV-Ray and to port the software to platforms other 
  19.     than those supported by the POV-Ray Team.  There are strict rules under
  20.     which you are permitted to use this file.  The rules are in the file
  21.     named POVLEGAL.DOC which should be distributed with this file. If 
  22.     POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  23.     Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  24.     Forum.  The latest version of POV-Ray may be found there as well.
  25.  
  26.     This program is based on the popular DKB raytracer version 2.12.
  27.     DKBTrace was originally written by David K. Buck.
  28.     DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  29. ------------------------------------------------------------------------------
  30. Change History:
  31.     960120    [esp]
  32. ==============================================================================*/
  33.  
  34. #define AEAPPHDLR_C
  35.  
  36. //===========================================================================
  37. // Headers
  38. //===========================================================================
  39.  
  40. #include "aeAppHdlr.h"
  41.  
  42. #include <AppleEvents.h>    // AEInstallEventHandler
  43. #include <AERegistry.h>        // kAECoreEventClass
  44. #include <AEObjects.h>        // formPropertyID
  45.  
  46. #include <string.h>            // strlen
  47.  
  48. #include "aeUtils.h"    // ExtractShortFromAEDesc()
  49.  
  50.  
  51. //===========================================================================
  52. // Definitions
  53. //===========================================================================
  54.  
  55.  
  56. //===========================================================================
  57. //       Handle null property accessor calls
  58. //===========================================================================
  59. #pragma segment Main
  60.  
  61. pascal OSErr AccPropFromApp(    DescType        desiredClass,
  62.                                 AEDesc            *containerToken,
  63.                                 DescType        containerClass,
  64.                                 DescType        keyForm,
  65.                                 AEDesc             *keyData,
  66.                                 AEDescList        *tokenDesc,
  67.                                 long            refCon)
  68.     {
  69.     OSErr        anError = noErr;
  70.     DescType    theProperty;
  71.     MyToken_t    aToken;
  72.  
  73.     // make sure we're dealing with properties
  74.     if ((keyForm != formPropertyID)  || (keyData->descriptorType != typeType))
  75.         return errAECantSupplyType;
  76.  
  77.     // don't do any non-Application properties
  78.     if (containerToken->descriptorType != typeNull)
  79.         return errAEEventNotHandled;
  80.  
  81.     // extract the desired property from the key
  82.     theProperty = **(DescType**)keyData->dataHandle;
  83.  
  84.     // make sure we handle this property type
  85.     switch (theProperty)
  86.         {
  87.         case pName:
  88.         case pVersion:
  89. // WARNING... JUST THROWN IN, NOT TESTED AT ALL! [esp]
  90.             // return a property token
  91.             // initialize the returned token structure as being an App property
  92.             aToken.fClass            = containerClass;
  93.             aToken.fFlags            = eTokIsProperty;
  94.             aToken.fPropCode        = theProperty;
  95.             aToken.fValue            = 0;
  96.         
  97.             // return the token
  98.             anError = AECreateDesc(desiredClass, (Ptr)&aToken, sizeof(aToken), tokenDesc);
  99.             break;
  100.  
  101.         case pBestType:
  102.         case pClass:
  103.         case pDefaultType:
  104.         default:
  105.             anError = errAENoSuchObject; // or property, really
  106.             break;
  107.         }
  108.  
  109.     return anError;
  110.     } // AccPropFromApp
  111.  
  112.  
  113. //===========================================================================
  114. //       Handle thing-from-null accessor calls
  115. //===========================================================================
  116. #pragma segment Main
  117.  
  118. pascal OSErr AccThingFromApp(    DescType        desiredClass,
  119.                                 AEDesc            *containerToken,
  120.                                 DescType        containerClass,
  121.                                 DescType        keyForm,
  122.                                 AEDesc             *keyData,
  123.                                 AEDescList        *tokenDesc,
  124.                                 long            refCon)
  125.     {
  126.     OSErr        anError = noErr;
  127. //    DescType    theRequestedProperty;
  128.     MyToken_t    aToken;
  129.  
  130.     // check for wrong container
  131.     if (containerToken->descriptorType != typeNull)
  132.         return errAETypeError;
  133.  
  134.     // determine how to look up the translator
  135.  
  136. // we need to eventually do fancy stuff here, but for now, we'll drop through and
  137. // return the one and only translator token
  138.  
  139.     switch (keyForm)
  140.         {
  141.         case formAbsolutePosition:    // 1=1st, -2=2nd from end
  142.             {
  143.             short    theIndex;
  144.             anError = ExtractShortFromAEDesc(keyData, &theIndex);
  145.             break;
  146.             }
  147.         case formRelativePosition:    // next, previous
  148.             {
  149.             short    theIndex;
  150.             anError = ExtractShortFromAEDesc(keyData, &theIndex);
  151.             break;
  152.             }
  153.         case formTest:                // A logical or a comparison
  154.             break;
  155.         case formRange:                // everything from object 1 to object 2
  156.             break;
  157.         case formPropertyID:        // Key data specifies an object property
  158.             break;
  159.         case formUniqueID:            // some id that identifies exactly one object
  160.             break;
  161.         case formName:                // Key data may be of type 'TEXT'
  162.             break;
  163.         default:                    // Key form unsupported
  164.             anError = errAEBadKeyForm;
  165.         }
  166.     if (anError)
  167.         return anError;
  168.  
  169.     // initialize the returned token structure as being an AppPrefs class object
  170.     aToken.fClass            = cAppPrefs;
  171.     aToken.fFlags            = eTokIsObject;
  172.     aToken.fPropCode        = typeNull; // it's an object, not a property
  173.     aToken.fValue            = 1;
  174.  
  175.     // return the token
  176.     anError = AECreateDesc(desiredClass, (Ptr)&aToken, sizeof(aToken), tokenDesc);
  177.  
  178.     return anError;
  179.     } // AccThingFromApp
  180.  
  181.  
  182. //===========================================================================
  183. //       Handle null "Get Data" AEvts
  184. //===========================================================================
  185. #pragma segment Main
  186.  
  187. static OSErr AppGetData(    AEDesc            *theToken,
  188.                             AppleEvent        *reply)
  189.     {
  190.     OSErr        anError = noErr;
  191.     DescType    theProperty;
  192.     DescType    tempType;
  193.  
  194.     if (GetTokDescFlags(*theToken) == eTokIsObject)
  195.         { // we want the translator object (kObjectToken)
  196.         // We should return an object specifier for the translator, actually
  197.         anError = errAENoSuchObject;
  198.         }
  199.     else
  200.         { // we want a property of the app (eTokIsProperty)
  201.         theProperty = GetTokDescPropCode(*theToken);
  202.         switch (theProperty)
  203.             {
  204.             case pBestType:
  205.             case pClass: 
  206.             case pDefaultType:    // why, it's an AppPrefs
  207.                 tempType = cAppPrefs;
  208.                 anError = AECreateDesc(typeType, (Ptr)&tempType, sizeof(tempType), reply);
  209.                 break;
  210. /*
  211.             case pVersion: // put translator version here
  212.                 anError = AECreateDesc(cText, (Ptr)&versionBuffer, strlen(versionBuffer), reply);
  213.                 break;
  214.             case pName:
  215.                 anError = AECreateDesc(cText, (Ptr)&tNameBuffer, strlen(tNameBuffer), reply);
  216.                 break;
  217. */
  218.             default:
  219.                 anError = errAEEventNotHandled;
  220.                 break;
  221.             }
  222.         }
  223.     return anError;
  224.     } // AppGetData
  225.  
  226.  
  227. //===========================================================================
  228. //       Handle all null (Application) AEvts
  229. //===========================================================================
  230. // Handle App AEvts
  231. #pragma segment Main
  232.  
  233. OSErr AEAppDispatcher(    AEEventID    theEventID,
  234.                         AEDesc        *tokenDesc,
  235.                         AppleEvent    *aevt,
  236.                         AppleEvent    *reply,
  237.                         long        refCon)
  238.     {
  239.     OSErr            anError;
  240. //    DescType        theTypeCode;
  241. //    Size            actualSize;
  242.  
  243.     // handle the event appropriately
  244.     switch (theEventID)
  245.         {
  246.         case kAEGetData:
  247.             anError = AppGetData(tokenDesc, reply);
  248.             break;
  249.  
  250.         // Events not handled
  251.         case kAEGetDataSize:
  252.         case kAESetData:
  253.         case kAEClone:
  254.         case kAEClose:
  255.         case kAECountElements:
  256.         case kAECreateElement:
  257.         case kAEDelete:
  258.         case kAEDoObjectsExist:
  259.         case kAEGetClassInfo:
  260.         case kAEMove:
  261.         case kAEOpen:
  262.         default:
  263.             anError = errAEEventNotHandled;
  264.             break;
  265.         }
  266.  
  267.     return anError;
  268.     } // AppDispatcher
  269.  
  270.