home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Miscellaneous / CrunchShell Demo / myApp.c next >
Encoding:
C/C++ Source or Header  |  1988-06-19  |  2.7 KB  |  96 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  myApp.c
  3.  
  4.                             Sample Application Class        
  5.         
  6.         Copyright 1988 Gregory H. Dow.  All Rights Reserved.
  7.     
  8.     PARENT = Application
  9.     
  10.     INSTANCE VARIABLES:
  11.         OSType        signature            $ File creator
  12.         short        numTypes            $ Number of file types recognized
  13.         SFTypeList    typeList            $ Types of files recognized
  14.             
  15.     INSTANCE METHODS/MESSAGES:        long    myAppDispatcher
  16.                                         $ Initialize application
  17.         msgINITobj()
  18.                                         $ Exit application
  19.         msgEXITappl()
  20.         
  21.  ******************************************************************************/
  22.  
  23. #include "Common.h"
  24. #include "GlobalVars.h"
  25. #include "Dispatcher.h"
  26. #include "CDebugger.h"
  27. #include "CPrinter.h"
  28. #include "CApplication.h"
  29.  
  30. /*** Class Variables ***/
  31.     
  32. static ApplicationObjH    self = NULL;
  33. static char                *className = "myApp";
  34. static LongFunc            parent = ApplicationDispatcher;
  35.     
  36. /******************************************************************************
  37.  Do_INITobj {OVERRIDE}
  38.  
  39.          Initialize instance variables for an application object
  40.  ******************************************************************************/
  41.  
  42. static
  43. void    Do_INITobj()
  44. {
  45.     register    ApplicationObj    *selfPtr;
  46.     
  47.     selfPtr = *self;                    /* Dereference handle                */
  48.     
  49.     OpenResFile("\pmyApp.RSRC");        /* My application's resources        */
  50.  
  51.                                     /** Set instance variables **/
  52.     selfPtr->signature = 'SubC';        /* My creator signature                */
  53.     selfPtr->numTypes = 2;                /* Two file types recognized        */
  54.     selfPtr->typeList[0] = 'PICT';        /* PICT files are used                */
  55.     selfPtr->typeList[1] = 'TEXT';        /* TEXT files are used                */
  56.  
  57.     SetUpMyMenus();                        /* Install Menus                    */    
  58.     DrawMenuBar();
  59.     
  60.                                         /* Init the debugger object            */
  61.     gDebugger = (DebuggerObjH) NewObject(sizeof(DebuggerObj),
  62.                                          DebuggerDispatcher);
  63.     SendMsg(gDebugger, msgINITobj);
  64.                                          
  65.                                         /* Create printer object            */
  66.     gPrinter = (PrinterObjH) NewObject(sizeof(PrinterObj), PrinterDispatcher);
  67.     SendMsg(gPrinter, msgINITobj);
  68. }
  69.     
  70.         
  71. /******************************************************************************
  72.  myAppDispatcher
  73.  
  74.         Receive messages for my Application objects and invoke the
  75.         corresponding methods
  76.  ******************************************************************************/
  77.  
  78. long    myAppDispatcher(theObject, theMessage)
  79. ApplicationObjH        theObject;            /* Object receiving the message        */
  80. short                theMessage;            /* The message received                */
  81. {
  82.     EnterDispatcher();                    /* Standard dispatcher entry code    */
  83.  
  84.     switch (theMessage) {
  85.     
  86.         case msgINITobj:                /* Initialize the application        */
  87.             Do_INITobj();
  88.             break;
  89.     
  90.         default:                        /* Pass message up hierarchy        */
  91.             PassToParent();
  92.             
  93.     }
  94.     
  95.     ExitDispatcher();                    /* Standard dispatcher exit code    */
  96. }