home *** CD-ROM | disk | FTP | other *** search
- // Program Author: Paul Baxter
- // pbaxter@assistivetech.com
- //
- //
-
- #include <Speech.h>
- #include <Ctype.h>
- #include <DeskBus.h>
- #include <Retrace.h>
-
- #include "filter.h"
- #include "adb.h"
- #include "pref.h"
- #include "globals.h"
- #include "menu.h"
- #include "speech.h"
- #include "event.h"
- #include "command.h"
- #include "DeferredTask.h"
- #include "aeevents.h"
- #include "aeaccessors.h"
- #include "aecoercions.h"
-
- // alert defines
- #define kNoSpeachAlertID 129
- #define kNoKeyboardDriver 130
- #define kOutofMemAlertID 131
- #define kCantLoadPrefsID 132
-
- // prototypes
- static void InitMac(void);
- static void InitApp(void);
- static void KillApp(void);
- static Boolean SpeechExists(void);
-
-
- // * ****************************************************************************** *
- // * main
- // * Main entry point
- // * ****************************************************************************** *
- void main(void)
- {
- // Init the Macintosh
- InitMac();
-
- // Init the application
- InitApp();
-
- // Main Event Loop
- EventLoop();
-
- // Kill the application
- KillApp();
- }
-
- // * ****************************************************************************** *
- // * InitMac
- // * Init Macintosh ToolBax
- // * ****************************************************************************** *
- static void InitMac(void)
- {
- /* Initialize all the needed managers. */
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- InitDialogs(nil);
- InitCursor();
- MoreMasters();
- MoreMasters();
- MoreMasters();
- MoreMasters();
- MaxApplZone();
- }
-
- // * ****************************************************************************** *
- // * InitApp
- // * Init application stuff
- // * ****************************************************************************** *
- static void InitApp(void)
- {
- long saveA5;
- OSErr err;
-
- // See if we have speech
- if (!SpeechExists()) {
- StopAlert(kNoSpeachAlertID, nil);
- KillApp();
- ExitToShell();
- }
-
- // Init appleEvents
- if (HasAppleEvents()) {
- InitHLEvents();
- // I really don't care about errors here
- // This just makes it scriptable and recordable
- err = AEObjectInit();
- err = InstallAccessors();
- err = InstallCoercions();
- }
-
- // Load our prefs
- if (LoadPrefs()) {
- StopAlert(kCantLoadPrefsID, nil);
- KillApp();
- ExitToShell();
- }
-
- // Find the ADBAddress of the Keyboard
- if (!InitADBAddress()) {
- StopAlert(kNoKeyboardDriver, nil);
- KillApp();
- ExitToShell();
- }
-
- // Init the speech buffers
- if (!InitBuffers()) {
- StopAlert(kOutofMemAlertID, nil);
- KillApp();
- ExitToShell();
- }
-
- // Init our speech strings
- InitSpeechStrings();
-
- // Install our menus
- MenusInit();
-
- // Init ADB ServiceRoutines
- InitADBService();
-
- // Get our process number for the event filter
- GetCurrentProcess(&gPSN);
-
- // Install an event filter
- SetA5(saveA5 = SetA5(0));
- gFilterProc = (Ptr) InstallEventFilter((FilterHelperUPP) EventFilterHelper, (Ptr) saveA5);
-
- // install ADBService and
- if ((**gPrefs).speakChars) {
- InstallADBServiceRoutine(gKeyBoardADBAddress);
- }
-
- // Install DTask
- err = InitDeferredTask();
-
- // install JADBProc in case ADBReInit is called
- InstallJADBProc();
-
- // Do the AboutBox
- ProcessCommand(AboutCmd, nil);
- }
-
- // * ****************************************************************************** *
- // * KillApp
- // * kill application stuff
- // * ****************************************************************************** *
- static void KillApp(void)
- {
-
- // Order is important!!
- // If disposed of in the wrong order a crash will occur.
-
-
- // KillSpeech or crash!
- if (gSpeechChannel) {
- StopSpeech(gSpeechChannel);
- DisposeSpeechChannel(gSpeechChannel);
- gSpeechChannel = nil;
- }
- // remove ADBService or crash
- RemoveADBServiceRoutine(gKeyBoardADBAddress);
-
- // remove JADBProc or crash
- UnInstallJADBProc();
-
- // remove Filter or crash
- ReleaseEventFilter(gFilterProc);
-
- // RemoveDTask
- RemoveDTask();
-
- // deallocate buffers
- KillBuffers();
-
- // Save Prefs
- SavePrefs();
- }
-
- // * ****************************************************************************** *
- // * SpeechExists
- // * determine if the speech manager is present
- // * ****************************************************************************** *
- static Boolean SpeechExists(void)
- {
- Boolean speechExists = false;
- long response;
- OSErr err;
-
- err = Gestalt(gestaltSpeechAttr, &response);
- if(!err) {
- if(response & (1L << gestaltSpeechMgrPresent)) {
- speechExists = true;
- }
- }
- return speechExists;
- }
-