home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / caftrdrk.sit / GlueCode.c < prev    next >
C/C++ Source or Header  |  1990-08-18  |  2KB  |  102 lines

  1. #include <SetUpA4.h>
  2. #include <oops.h>
  3.  
  4. /*
  5.  * Get the name of the subclass that the glue code will use.  If the
  6.  * subclass file is funky then use the default base class CAfterDark.
  7.  */
  8.  
  9. #include "GlueCode.h"
  10.  
  11. #ifndef SUBCLASS
  12. #include "CAfterDark.h"
  13. #define SUBCLASS CAfterDark
  14. #endif
  15.  
  16. /*
  17.  * The main() code glues together the default After Dark calling
  18.  * mechanism to an object/message interface.
  19.  */  
  20. pascal OSErr main(Handle *storage, RgnHandle blankRgn,
  21.                     short message, GMParamBlockPtr params)
  22. {
  23.     OSErr err = noErr;
  24.  
  25.     /*
  26.      * Setup THINK C's A4 global environment.
  27.      */
  28.     RememberA0();
  29.     SetUpA4();
  30.     
  31.     /*
  32.      * If we've allocated storage then lock it down.
  33.      */
  34.     if (*storage != 0) {
  35.         MoveHHi(*storage);
  36.         HLock(*storage);
  37.     }
  38.     
  39.     switch (message) {
  40.     /*
  41.      * Initialize creates a new object and assigns it to storage.  If
  42.      * there's a problem then it returns MemError() which is what After
  43.      * Dark expects.  Otherwise, lock the object down and send it an 
  44.      * Initialize message.
  45.      */
  46.     case Initialize:
  47.         *storage = new(SUBCLASS);
  48.         if (*storage == 0)
  49.             return MemError();
  50.         MoveHHi(*storage);
  51.         HLock(*storage);
  52.         err = ((CAfterDark *)*storage)->Init(blankRgn, params);
  53.         break;
  54.         
  55.     /*
  56.      * Close sends the object a Close message and then deletes the object.
  57.      */
  58.     case Close:
  59.         err = ((CAfterDark *)*storage)->Close(blankRgn, params);
  60.         delete(*storage);
  61.         *storage = 0;
  62.         break;
  63.     
  64.     /*
  65.      * Blank just sends the object a blank message.
  66.      */
  67.     case Blank:
  68.         err = ((CAfterDark *)*storage)->Blank(blankRgn, params);
  69.         break;
  70.     
  71.     /*
  72.      * DrawFrame just sends the object a blank message.
  73.      */
  74.     case DrawFrame:
  75.         err = ((CAfterDark *)*storage)->DrawFrame(blankRgn, params);
  76.         break;
  77.             
  78.     /*
  79.      * The default case for other messages is to check and see
  80.      * if they're ButtomMessages.  If so, a SetUp message is sent
  81.      * to the object.
  82.      */
  83.     default:
  84.         if (message >= ButtonMessage)
  85.             err = ((CAfterDark *)*storage)->SetUp(blankRgn, message, params);
  86.         break;
  87.     }
  88.     
  89.     /*
  90.      * If we've allocated storage then we should unlock what we've
  91.      * previously locked.
  92.      */
  93.     if (*storage != 0)
  94.         HUnlock(*storage);
  95.         
  96.     /*
  97.      * Restore THINK C's A4 global environment.
  98.      */
  99.     RestoreA4();
  100.     
  101.     return err;
  102. }