home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CADSP 1.0 / Demo / CATalkApp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  4.1 KB  |  231 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * CATalkApp.c
  3.  *
  4.  *    Application methods for an appletalk typical application.
  5.  *
  6.  *  Copyright © 1992 Bernard Bernstein.  All rights reserved.
  7.  *
  8.  *****/
  9.  
  10. #include "CATalkApp.h"
  11. #include "CATalkDoc.h"
  12.  
  13. #include <CButton.h>
  14.  
  15. extern    OSType    gSignature;
  16.  
  17. #define        kExtraMasters        4
  18. #define        kRainyDayFund        20480
  19. #define        kCriticalBalance    20480
  20. #define        kToolboxBalance        20480
  21.  
  22.  
  23. /***
  24.  * IATalkApp
  25.  *
  26.  *    Initialize the application. Your initialization method should
  27.  *    at least call the inherited method. If your application class
  28.  *    defines its own instance variables or global variables, this
  29.  *    is a good place to initialize them.
  30.  *
  31.  ***/
  32.  
  33. void CATalkApp::IATalkApp(void)
  34.  
  35. {
  36.     CApplication::IApplication( kExtraMasters, kRainyDayFund, 
  37.                         kCriticalBalance, kToolboxBalance);
  38.     
  39. }
  40.  
  41.  
  42.  
  43. /***
  44.  * SetUpFileParameters
  45.  *
  46.  *    In this routine, you specify the kinds of files your
  47.  *    application opens.
  48.  *
  49.  *
  50.  ***/
  51.  
  52. void CATalkApp::SetUpFileParameters(void)
  53.  
  54. {
  55.     inherited::SetUpFileParameters();    /* Be sure to call the default method */
  56.  
  57.     sfNumTypes = 1;
  58.     sfFileTypes[0] = 'TEXT';
  59.  
  60.     gSignature = '????';
  61. }
  62.  
  63.  
  64. /***
  65.  * SetUpMenus 
  66.  *
  67.  * Set up menus which must be created at run time, such as a
  68.  * Font menu. You can eliminate this method if your application
  69.  * does not have any such menus.
  70.  *
  71. ***/
  72.  
  73.  void CATalkApp::SetUpMenus()
  74.  {
  75.  
  76.   inherited::SetUpMenus();  /*  Superclass takes care of adding     
  77.                                 menus specified in a MBAR id = 1    
  78.                                 resource    
  79.                             */                          
  80.  
  81.         /* Add your code for creating run-time menus here */    
  82.  }
  83.  
  84.  
  85.  
  86. /***
  87.  * DoCommand
  88.  *
  89.  *    Your application will probably handle its own commands.
  90.  *    Remember, the command numbers from 1-1023 are reserved.
  91.  *  The file Commands.h contains all the predefined TCL
  92.  *  commands.
  93.  *
  94.  *    Be sure to call the default method, so you can get
  95.  *    the default behvior for standard commands.
  96.  *
  97.  ***/
  98. void CATalkApp::DoCommand(long theCommand)
  99.  
  100. {
  101.     switch (theCommand) {
  102.     
  103.         /* Your commands go here */
  104.     
  105.         default:    inherited::DoCommand(theCommand);
  106.                     break;
  107.     }
  108. }
  109.  
  110.  
  111. /***
  112.  *
  113.  * UpdateMenus 
  114.  *
  115.  *   Perform menu management tasks
  116.  *
  117. ***/
  118.  
  119.  void CATalkApp::UpdateMenus()
  120.  {
  121.   inherited::UpdateMenus();     /* Enable standard commands */      
  122.  
  123.     /* Enable the commands handled by your Application class */ 
  124.  }
  125.  
  126.  
  127. /***
  128.  * Exit
  129.  *
  130.  *    Chances are you won't need this method.
  131.  *    This is the last chance your application gets to clean up
  132.  *  things like temporary files before terminating.
  133.  *
  134.  ***/
  135.  
  136. void CATalkApp::Exit()
  137.  
  138. {
  139.     /* your exit handler here */
  140. }
  141.  
  142.  
  143. /***
  144.  * CreateDocument
  145.  *
  146.  *    The user chose New from the File menu.
  147.  *    In this method, you need to create a document and send it
  148.  *    a NewFile() message.
  149.  *
  150.  ***/
  151.  
  152. void CATalkApp::CreateDocument()
  153.  
  154. {
  155.     CATalkDoc    *theDocument = NULL;
  156.     
  157.     TRY
  158.     {
  159.         theDocument = new(CATalkDoc);
  160.         
  161.         theDocument->IATalkDoc(this, TRUE);
  162.         theDocument->NewFile();
  163.     }
  164.     
  165.     CATCH
  166.     {
  167.          
  168.          if (theDocument) theDocument->Dispose();
  169.  
  170.     }
  171.     ENDTRY;
  172. }
  173.  
  174. /***
  175.  * OpenDocument
  176.  *
  177.  *    The user chose Open… from the File menu.
  178.  *    In this method you need to create a document
  179.  *    and send it an OpenFile() message.
  180.  *
  181.  *    The macSFReply is a good SFReply record that contains
  182.  *    the name and vRefNum of the file the user chose to
  183.  *    open.
  184.  *
  185.  ***/
  186.  
  187. void CATalkApp::OpenDocument(SFReply *macSFReply)
  188.  
  189. {
  190.     CATalkDoc    *theDocument = NULL;
  191.     
  192.     TRY
  193.     {
  194.     
  195.         theDocument = new(CATalkDoc);
  196.         
  197.         theDocument->IATalkDoc(this, TRUE);
  198.     
  199.         theDocument->OpenFile(macSFReply);
  200.     }
  201.     
  202.     CATCH
  203.     {
  204.          
  205.          if (theDocument) theDocument->Dispose();
  206.     }
  207.     ENDTRY;
  208. }
  209.  
  210.  
  211.  
  212. /******************************************************************************
  213.  ForceClassReferences
  214.  
  215.      This method creates dummy references to classes that we don't want
  216.      stripped out by the linker when the application is built. This could
  217.      happen if the class is only created via new_by_name and is never directly
  218.      referenced. CApplication automatically calls this method.
  219.      
  220. ******************************************************************************/
  221. void CATalkApp::ForceClassReferences( void)
  222. {
  223.     Boolean alwaysFalse = FALSE;
  224.     CObject *dummy = NULL;
  225.     
  226.     if (alwaysFalse == TRUE)
  227.     {
  228.         member( dummy, CButton);
  229.     }
  230. }
  231.