home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-06 | 5.2 KB | 192 lines | [TEXT/MMCC] |
- /*****
- * CLaughsApp.cp
- *
- * Implementation of a sample application full of laughter.
- *
- * This sample app is derived from a contribution originally made
- * by Paul Gee (Thanks Paul!).
- *
- * Copyright © 1994 NeoLogic Systems. All rights reserved.
- *
- * NOTE: This sample application uses the SIOUX serial i/o emulator for outputing
- * text using printf. There are a number of bugs in this mechanism which causes
- * rather unusual behavior.
- *
- * While Laughs includes all the code necessary to open new and pre-existing files,
- * these SIOUX bugs do not allow Laughs' application menu to be accessible. The
- * application can not open pre-existing files as a result. The only possible work
- * around for this bug would be to comment out all printf statements and the call
- * to SendAEQuit in CLaughsDoc::newFile. The application will function correctly,
- * though no output will be written to the screen.
- *
- * The window can't be moved on the screen. SIOUX ignores mouse clicks directed
- * to the window.
- *
- * The Save menu item saves the text in the window NOT the NeoAccess database
- * that this application uses.
- *
- *****/
-
- #include "NeoTypes.h"
- #include <stdio.h>
- #include "LGrowZone.h"
- #include "UMemoryMgr.h"
- #include "UPowerTools.h"
- #include CNeoDatabaseNativeH
- #include CNeoMetaClassH
- #include CNeoIDListH
- #include "CLaughsApp.h"
- #include "CLaughsDoc.h"
- #include "CPerson.h"
-
- int main(void)
- {
- CLaughsApp * app;
-
- // PowerPlant asks that the following be done before an application is created.
- InitializeHeap(1);
- InitializeToolbox();
- (void)new LGrowZone(20000);
-
- // Create an application object, run it, then delete it.
- app = new CLaughsApp();
- app->Run();
- delete app;
-
- // Time to go home.
- return 0;
- }
-
- /***
- * CLaughsApp
- *
- * Initialize the application. Your initialization method should
- * at least call the inherited method. If your application class
- * defines its own instance variables or global variables, this
- * is a good place to initialize them.
- *
- ***/
- CLaughsApp::CLaughsApp(void)
- : CNeoAppRoot(kLaughsSig, kLaughsFileType)
- {
- CNeoMetaClass * meta;
-
- // Note our file type so that we can be particular in the standard get file dialog.
- FFileType = kLaughsFileType;
-
- // Let the games begin.
- printf("The SIOUX console facility causes duplicate menus in the menubar.\n");
- printf("Use the first set except when quiting, then use both the first AND second.\n\n");
-
- printf("Start Laughing...\n\n");
-
- // Add the application-specific metaclasses to the metaclass table.
- meta = new CNeoMetaClass(kPersonID, kNeoPersistID, "\pCPerson", CPerson::New);
- meta = new CNeoMetaClass(kJokerID, kPersonID, "\pCJoker", CJoker::New);
- meta = new CNeoMetaClass(kClownID, kPersonID, "\pCClown", CClown::New);
- }
-
- /***
- * createDocument
- *
- * The user chose New from the File menu.
- * In this method, you need to create a document and send it
- * a NewFile() message.
- *
- ***/
- CNeoDoc *CLaughsApp::createDocument(void)
- {
- CLaughsDoc * document = nil;
-
- NEOTRY {
- /*
- * Create your document.
- *
- * The arguments indicate whether the document is...
- * printable (FALSE),
- * a new file (TRUE),
- * remote (FALSE).
- */
- document = new CLaughsDoc(FALSE, TRUE, FALSE);
- NeoFailNil(document);
- document->SetSuperCommander(this);
-
- // Call the document’s newFile method.
- document->newDatabase();
- }
- NEOCATCH {
- /*
- * This exception handler gets executed if a failure occurred
- * anywhere within the scope of the above NEOTRY block. Since
- * this indicates that a new doc could not be created, we
- * check if an object had been allocated and if it has, delete
- * it. The exception will propagate up to the next exception
- * handler, which displays an error alert.
- */
- if (document) {
- delete document;
- document = nil;
- }
- }
- NEOENDTRY;
-
- return document;
- }
-
- /***
- * openDocument
- *
- * The user chose Open… from the File menu.
- * In this method you need to create a document
- * and send it an openFile() message.
- *
- * The aSpec is a good file specification record that contains
- * the name and vRefNum of the file the user chose to open.
- *
- ***/
-
- void CLaughsApp::OpenDocument(FSSpec *aSpec)
- {
- Boolean remote = FALSE;
- CLaughsDoc * document = nil;
-
- VOLATILE(document);
-
- NEOTRY {
- // Our parent will check to see if this is a document we have
- // already opened. If we find the file already open by the app,
- // then fDocument will refer to it. If the file is opened but
- // not by this app, then the parent will signal a failure.
- inherited::OpenDocument(aSpec);
- if (fDocument)
- return;
-
- // Create your document.
- document = new CLaughsDoc(TRUE, FALSE, remote);
- NeoFailNil(document);
- document->SetSuperCommander(this);
-
- // Call the document's openFile method. The document will open
- // a window, open the file specified in the file specification
- // record, and display it in its window.
- document->openFile(aSpec);
-
- delete document;
- document = nil;
- }
- NEOCATCH {
- /*
- * This exception handler gets executed if a failure occurred
- * anywhere within the scope of the NEOTRY block above. Since
- * this indicates that the document could not be opened, we
- * send it a unrefer message. The exception will propagate up to
- * the event loop's exception handler, which handles displaying
- * an error alert.
- */
- if (document)
- delete document;
- }
- NEOENDTRY;
- }
-
-