home *** CD-ROM | disk | FTP | other *** search
- #include "StrangeGlove.h"
- #include "theMenus.h"
- #include "Glove.h"
- #include <Serial.h> /* For THINK C 5.0.2, was <SerialDvr.h> for 4.0.5*/
-
- extern MenuHandle gAppleMenu, gFileMenu, gEditMenu, gGloveMenu, gTerminalMenu;
- extern MenuHandle gWindowMenu;
- extern MenuHandle gDataRateMenu, gDataBitsMenu, gStopBitsMenu, gParityMenu;
- extern Boolean gDone, gTerminal, gShowADT, gContinuous, gShowData;
- extern int gDataRate, gDataBits, gStopBits, gParity;
- extern Boolean gSmooth, gBall;
- extern GloveState gTheGlove;
-
- /***** MenuBarInit *****/
- MenuBarInit()
- {
- Handle myMenuBar;
-
- if ((myMenuBar = GetNewMBar(BASE_RES_ID)) == NIL_POINTER)
- ErrorHandler(NO_MBAR);
- SetMenuBar(myMenuBar);
-
- if ((gAppleMenu = GetMHandle(APPLE_MENU_ID)) == NIL_POINTER) /* Apple Menu */
- ErrorHandler(NO_MENU);
- AddResMenu(gAppleMenu, 'DRVR');
-
- if ((gGloveMenu = GetMenu(GLOVE_MENU_ID)) == NIL_POINTER) /* Glove Menu */
- ErrorHandler(NO_MENU);
-
- if ((gTerminalMenu = GetMenu(TERMINAL_MENU_ID)) == NIL_POINTER) /* Teminal Menu */
- ErrorHandler(NO_MENU);
-
- if ((gDataRateMenu = GetMenu(DATA_RATE_MENU_ID)) == NIL_POINTER) /* Hier. menus */
- ErrorHandler(NO_MENU);
- InsertMenu(gDataRateMenu, NOT_A_NORMAL_MENU);
- if ((gDataBitsMenu = GetMenu(DATA_BITS_MENU_ID)) == NIL_POINTER)
- ErrorHandler(NO_MENU);
- InsertMenu(gDataBitsMenu, NOT_A_NORMAL_MENU);
- if ((gStopBitsMenu = GetMenu(STOP_BITS_MENU_ID)) == NIL_POINTER)
- ErrorHandler(NO_MENU);
- InsertMenu(gStopBitsMenu, NOT_A_NORMAL_MENU);
- if ((gParityMenu = GetMenu(PARITY_MENU_ID)) == NIL_POINTER)
- ErrorHandler(NO_MENU);
- InsertMenu(gParityMenu, NOT_A_NORMAL_MENU);
-
- if ((gWindowMenu = GetMenu(WINDOW_MENU_ID)) == NIL_POINTER) /* Window Menu */
- ErrorHandler(NO_MENU);
-
- DrawMenuBar();
- }
-
-
- /***** AdjustEditMenu *****/
- AdjustEditMenu()
- {
- if (IsDAWindow(FrontWindow()))
- {
- EnableItem(gEditMenu, UNDO_ITEM);
- EnableItem(gEditMenu, CUT_ITEM);
- EnableItem(gEditMenu, COPY_ITEM);
- EnableItem(gEditMenu, PASTE_ITEM);
- EnableItem(gEditMenu, CLEAR_ITEM);
- }
- else
- {
- DisableItem(gEditMenu, UNDO_ITEM);
- DisableItem(gEditMenu, CUT_ITEM);
- DisableItem(gEditMenu, COPY_ITEM);
- DisableItem(gEditMenu, PASTE_ITEM);
- DisableItem(gEditMenu, CLEAR_ITEM);
- }
- }
-
-
- /***** DoMenuChoice *****/
- DoMenuChoice(menuChoice)
- long int menuChoice;
- {
- int theMenu;
- int theItem;
-
- if (menuChoice != 0)
- {
- theMenu = HiWord(menuChoice);
- theItem = LoWord(menuChoice);
- switch (theMenu)
- {
- case APPLE_MENU_ID:
- DoAppleChoice(theItem);
- break;
- case FILE_MENU_ID:
- DoFileChoice(theItem);
- break;
- case EDIT_MENU_ID:
- DoEditChoice(theItem);
- break;
- case GLOVE_MENU_ID:
- DoGloveChoice(theItem);
- break;
- case TERMINAL_MENU_ID:
- DoTerminalChoice(theItem);
- break;
- case DATA_RATE_MENU_ID:
- DoDataRateChoice(theItem);
- break;
- case DATA_BITS_MENU_ID:
- DoDataBitsChoice(theItem);
- break;
- case STOP_BITS_MENU_ID:
- DoStopBitsChoice(theItem);
- break;
- case PARITY_MENU_ID:
- DoParityChoice(theItem);
- break;
- case WINDOW_MENU_ID:
- DoWindowChoice(theItem);
- break;
- }
- HiliteMenu(0);
- }
- }
-
-
- /***** DoAppleChoice *****/
- DoAppleChoice(theItem)
- int theItem;
- {
- Str255 accName;
- int accNumber;
- short int itemNumber;
- DialogPtr AboutDialog;
-
- switch (theItem)
- {
- case ABOUT_ITEM:
- Alert(ABOUT_ALERT, NIL_POINTER);
- break;
- default:
- GetItem(gAppleMenu, theItem, accName);
- accNumber = OpenDeskAcc(accName);
- break;
- }
- }
-
-
- /***** DoFileChoice *****/
- DoFileChoice(theItem)
- int theItem;
- {
- switch (theItem)
- {
- case SEND_TEXT_ITEM:
- SendText();
- break;
- case DOWNLOAD_ITEM:
- DownloadSRecord();
- break;
- case QUIT_ITEM:
- gDone = TRUE;
- break;
- }
- }
-
-
- /***** DoEditChoice *****/
- DoEditChoice(theItem)
- int theItem;
- {
- SystemEdit(theItem - 1);
- }
-
-
- /***** DoGloveChoice *****/
- DoGloveChoice(theItem)
- int theItem;
- {
- switch (theItem)
- {
- case REQUEST_ITEM:
- if (gContinuous)
- StopContinuous();
- ShowData();
- GetGlove(&gTheGlove);
- DisplayGlove(&gTheGlove);
- if (gBall)
- DrawBall(gTheGlove.x + 128, 128 - gTheGlove.y, gTheGlove.z + 128);
- break;
- case CONTINUOUS_ITEM:
- if (!gContinuous)
- {
- StartContinuous();
- ShowData();
- }
- break;
- case SMOOTH_ITEM:
- ToggleSmoothing();
- break;
- }
- }
-
-
- /***** DoTerminalChoice *****/
- DoTerminalChoice(theItem)
- int theItem;
- {
- switch (theItem)
- {
- case TERMINAL_ITEM:
- if (gTerminal)
- StopTerm();
- else
- StartTerm();
- break;
- }
- }
-
-
- /***** DoDataRateChoice *****/
- DoDataRateChoice(theItem)
- int theItem;
- {
- switch (theItem)
- {
- case 1:
- gDataRate = baud300;
- break;
- case 2:
- gDataRate = baud1200;
- break;
- case 3:
- gDataRate = baud2400;
- break;
- case 4:
- gDataRate = baud4800;
- break;
- case 5:
- gDataRate = baud9600;
- break;
- case 6:
- gDataRate = baud19200;
- break;
- case 7:
- gDataRate = baud57600;
- break;
- }
- ChangeSettings(gDataRate+gDataBits+gStopBits+gParity);
- AdjustTerminalMenu();
- }
-
-
- /***** DoDataBitsChoice *****/
- DoDataBitsChoice(theItem)
- int theItem;
- {
- switch (theItem)
- {
- case 1:
- gDataBits = data7;
- break;
- case 2:
- gDataBits = data8;
- }
- ChangeSettings(gDataRate+gDataBits+gStopBits+gParity);
- AdjustTerminalMenu();
- }
-
-
- /***** DoStopBitsChoice *****/
- DoStopBitsChoice(theItem)
- int theItem;
- {
- switch (theItem)
- {
- case 1:
- gStopBits = stop10;
- break;
- case 2:
- gStopBits = stop15;
- break;
- case 3:
- gStopBits = stop20;
- break;
- }
- ChangeSettings(gDataRate+gDataBits+gStopBits+gParity);
- AdjustTerminalMenu();
- }
-
-
- /***** DoParityChoice *****/
- DoParityChoice(theItem)
- int theItem;
- {
- switch (theItem)
- {
- case 1:
- gParity = noParity;
- break;
- case 2:
- gParity = evenParity;
- break;
- case 3:
- gParity = oddParity;
- break;
- }
- ChangeSettings(gDataRate+gDataBits+gStopBits+gParity);
- AdjustTerminalMenu();
- }
-
-
- /***** DoWindowChoice *****/
- DoWindowChoice(theItem)
- int theItem;
- {
- switch (theItem)
- {
- case GLOVE_DATA_ITEM:
- if (gShowData)
- HideData();
- else
- {
- ShowData();
- DisplayGlove(&gTheGlove);
- }
- break;
- case SHOW_ADT_ITEM:
- if (gShowADT)
- HideADT();
- else
- ShowADT();
- break;
- case BALL_ITEM:
- if (gBall)
- StopBall();
- else
- {
- StartBall();
- DrawBall(gTheGlove.x + 128, 128 - gTheGlove.y, gTheGlove.z + 128);
- }
- break;
- }
- }
-
-
- /*** CheckTerminalItems ***/
- AdjustTerminalMenu()
- {
- CheckItem(gTerminalMenu, TERMINAL_ITEM, gTerminal); /* Deal with Terminal */
-
- CheckItem(gDataRateMenu, 1, (gDataRate == baud300)); /* Deal with Baud */
- CheckItem(gDataRateMenu, 2, (gDataRate == baud1200));
- CheckItem(gDataRateMenu, 3, (gDataRate == baud2400));
- CheckItem(gDataRateMenu, 4, (gDataRate == baud4800));
- CheckItem(gDataRateMenu, 5, (gDataRate == baud9600));
- CheckItem(gDataRateMenu, 6, (gDataRate == baud19200));
- CheckItem(gDataRateMenu, 7, (gDataRate == baud57600));
-
- CheckItem(gDataBitsMenu, 1, (gDataBits == data7)); /* Deal with Data Bits */
- CheckItem(gDataBitsMenu, 2, (gDataBits == data8));
-
- CheckItem(gStopBitsMenu, 1, (gStopBits == stop10)); /* Deal with Stop Bits */
- CheckItem(gStopBitsMenu, 2, (gStopBits == stop15));
- CheckItem(gStopBitsMenu, 3, (gStopBits == stop20));
-
- CheckItem(gParityMenu, 1, (gParity == noParity)); /* Deal with Parity */
- CheckItem(gParityMenu, 2, (gParity == evenParity));
- CheckItem(gParityMenu, 3, (gParity == oddParity));
- }
-
-
- /***** AdjustGloveMenu *****/
- AdjustGloveMenu()
- {
- CheckItem(gGloveMenu, REQUEST_ITEM, !gContinuous);
- CheckItem(gGloveMenu, CONTINUOUS_ITEM, gContinuous);
- CheckItem(gGloveMenu, SMOOTH_ITEM, gSmooth);
- }
-
-
- /***** AdjustWindowMenu *****/
- AdjustWindowMenu()
- {
- CheckItem(gWindowMenu, GLOVE_DATA_ITEM, gShowData);
- CheckItem(gWindowMenu, SHOW_ADT_ITEM, gShowADT);
- CheckItem(gWindowMenu, BALL_ITEM, gBall);
- }
-