home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / NeoIntroPP3.0 folder / PowerPlant / Laughs / Source / CLaughsApp.cp next >
Encoding:
Text File  |  1994-10-06  |  5.2 KB  |  192 lines  |  [TEXT/MMCC]

  1. /*****
  2.  * CLaughsApp.cp
  3.  *
  4.  *    Implementation of a sample application full of laughter.
  5.  *
  6.  *    This sample app is derived from a contribution originally made
  7.  *    by Paul Gee (Thanks Paul!).
  8.  *
  9.  *  Copyright © 1994 NeoLogic Systems.  All rights reserved.
  10.  *
  11.  *    NOTE: This sample application uses the SIOUX serial i/o emulator for outputing
  12.  *    text using printf. There are a number of bugs in this mechanism which causes
  13.  *    rather unusual behavior.
  14.  *
  15.  *    While Laughs includes all the code necessary to open new and pre-existing files,
  16.  *    these SIOUX bugs do not allow Laughs' application menu to be accessible. The
  17.  *    application can not open pre-existing files as a result. The only possible work
  18.  *    around for this bug would be to comment out all printf statements and the call
  19.  *    to SendAEQuit in CLaughsDoc::newFile. The application will function correctly,
  20.  *    though no output will be written to the screen.
  21.  *
  22.  *    The window can't be moved on the screen. SIOUX ignores mouse clicks directed
  23.  *    to the window.
  24.  *
  25.  *    The Save menu item saves the text in the window NOT the NeoAccess database
  26.  *    that this application uses.
  27.  *
  28.  *****/
  29.  
  30. #include "NeoTypes.h"
  31. #include <stdio.h>
  32. #include "LGrowZone.h"
  33. #include "UMemoryMgr.h"
  34. #include "UPowerTools.h"
  35. #include CNeoDatabaseNativeH
  36. #include CNeoMetaClassH
  37. #include CNeoIDListH
  38. #include "CLaughsApp.h"
  39. #include "CLaughsDoc.h"
  40. #include "CPerson.h"
  41.  
  42. int main(void)
  43. {
  44.     CLaughsApp *    app;
  45.  
  46.     // PowerPlant asks that the following be done before an application is created.
  47.     InitializeHeap(1);
  48.     InitializeToolbox();
  49.     (void)new LGrowZone(20000);
  50.  
  51.     // Create an application object, run it, then delete it.
  52.     app = new CLaughsApp();
  53.     app->Run();
  54.     delete app;
  55.  
  56.     // Time to go home.
  57.     return 0;
  58. }
  59.  
  60. /***
  61.  * CLaughsApp
  62.  *
  63.  *    Initialize the application. Your initialization method should
  64.  *    at least call the inherited method. If your application class
  65.  *    defines its own instance variables or global variables, this
  66.  *    is a good place to initialize them.
  67.  *
  68.  ***/
  69. CLaughsApp::CLaughsApp(void)
  70.     : CNeoAppRoot(kLaughsSig, kLaughsFileType)
  71. {
  72.     CNeoMetaClass *        meta;
  73.  
  74.     // Note our file type so that we can be particular in the standard get file dialog.
  75.     FFileType = kLaughsFileType;
  76.  
  77.     // Let the games begin.
  78.     printf("The SIOUX console facility causes duplicate menus in the menubar.\n");
  79.     printf("Use the first set except when quiting, then use both the first AND second.\n\n");
  80.  
  81.     printf("Start Laughing...\n\n");
  82.  
  83.     // Add the application-specific metaclasses to the metaclass table.
  84.     meta = new CNeoMetaClass(kPersonID, kNeoPersistID, "\pCPerson", CPerson::New);
  85.     meta = new CNeoMetaClass(kJokerID, kPersonID, "\pCJoker", CJoker::New);
  86.     meta = new CNeoMetaClass(kClownID, kPersonID, "\pCClown", CClown::New);
  87. }
  88.  
  89. /***
  90.  * createDocument
  91.  *
  92.  *    The user chose New from the File menu.
  93.  *    In this method, you need to create a document and send it
  94.  *    a NewFile() message.
  95.  *
  96.  ***/
  97. CNeoDoc *CLaughsApp::createDocument(void)
  98. {
  99.     CLaughsDoc *    document = nil;
  100.  
  101.     NEOTRY {
  102.         /*
  103.          * Create your document.
  104.          *
  105.          * The arguments indicate whether the document is...
  106.          *    printable (FALSE),
  107.          *    a new file (TRUE),
  108.          *    remote (FALSE).
  109.          */
  110.         document = new CLaughsDoc(FALSE, TRUE, FALSE);
  111.         NeoFailNil(document);
  112.         document->SetSuperCommander(this);
  113.  
  114.         // Call the document’s newFile method.
  115.         document->newDatabase();
  116.     }
  117.     NEOCATCH {
  118.         /*
  119.          * This exception handler gets executed if a failure occurred
  120.          * anywhere within the scope of the above NEOTRY block. Since
  121.          * this indicates that a new doc could not be created, we
  122.          * check if an object had been allocated and if it has, delete
  123.          * it. The exception will propagate up to the next exception
  124.          * handler, which displays an error alert.
  125.          */
  126.         if (document) {
  127.             delete document;
  128.             document = nil;
  129.         }
  130.     }
  131.     NEOENDTRY;
  132.  
  133.     return document;
  134. }
  135.  
  136. /***
  137.  * openDocument
  138.  *
  139.  *    The user chose Open… from the File menu.
  140.  *    In this method you need to create a document
  141.  *    and send it an openFile() message.
  142.  *
  143.  *    The aSpec is a good file specification record that contains
  144.  *    the name and vRefNum of the file the user chose to open.
  145.  *
  146.  ***/
  147.  
  148. void CLaughsApp::OpenDocument(FSSpec *aSpec)
  149. {
  150.     Boolean            remote        = FALSE;
  151.     CLaughsDoc *    document    = nil;
  152.  
  153.     VOLATILE(document);
  154.  
  155.     NEOTRY {
  156.         // Our parent will check to see if this is a document we have
  157.         // already opened. If we find the file already open by the app,
  158.         // then fDocument will refer to it. If the file is opened but
  159.         // not by this app, then the parent will signal a failure.
  160.         inherited::OpenDocument(aSpec);
  161.         if (fDocument)
  162.             return;
  163.  
  164.         // Create your document.
  165.         document = new CLaughsDoc(TRUE, FALSE, remote);
  166.         NeoFailNil(document);
  167.         document->SetSuperCommander(this);
  168.  
  169.         // Call the document's openFile method. The document will open
  170.         // a window, open the file specified in the file specification
  171.         // record, and display it in its window.
  172.         document->openFile(aSpec);
  173.  
  174.         delete document;
  175.         document = nil;
  176.     }
  177.     NEOCATCH {
  178.         /*
  179.          * This exception handler gets executed if a failure occurred
  180.          * anywhere within the scope of the NEOTRY block above. Since
  181.          * this indicates that the document could not be opened, we
  182.          * send it a unrefer message. The exception will propagate up to
  183.          * the event loop's exception handler, which handles displaying
  184.          * an error alert.
  185.          */
  186.         if (document)
  187.             delete document;
  188.     }
  189.     NEOENDTRY;
  190. }
  191.  
  192.