home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / misc / dr.str / Source / theMenus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-07  |  7.6 KB  |  386 lines  |  [TEXT/KAHL]

  1. #include "StrangeGlove.h"
  2. #include "theMenus.h"
  3. #include "Glove.h"
  4. #include <Serial.h>                /* For THINK C 5.0.2, was <SerialDvr.h> for 4.0.5*/
  5.  
  6. extern MenuHandle        gAppleMenu, gFileMenu, gEditMenu, gGloveMenu, gTerminalMenu;
  7. extern MenuHandle        gWindowMenu;
  8. extern MenuHandle        gDataRateMenu, gDataBitsMenu, gStopBitsMenu, gParityMenu;
  9. extern Boolean            gDone, gTerminal, gShowADT, gContinuous, gShowData;
  10. extern int                gDataRate, gDataBits, gStopBits, gParity;
  11. extern Boolean            gSmooth, gBall;
  12. extern GloveState        gTheGlove;
  13.  
  14. /***** MenuBarInit *****/
  15. MenuBarInit()
  16. {
  17.     Handle    myMenuBar;
  18.     
  19.     if ((myMenuBar = GetNewMBar(BASE_RES_ID)) == NIL_POINTER)
  20.         ErrorHandler(NO_MBAR);
  21.     SetMenuBar(myMenuBar);
  22.     
  23.     if ((gAppleMenu = GetMHandle(APPLE_MENU_ID)) == NIL_POINTER)        /* Apple Menu */
  24.         ErrorHandler(NO_MENU);
  25.     AddResMenu(gAppleMenu, 'DRVR');
  26.     
  27.     if ((gGloveMenu = GetMenu(GLOVE_MENU_ID)) == NIL_POINTER)            /* Glove Menu */
  28.         ErrorHandler(NO_MENU);
  29.     
  30.     if ((gTerminalMenu = GetMenu(TERMINAL_MENU_ID)) == NIL_POINTER)        /* Teminal Menu */
  31.         ErrorHandler(NO_MENU);
  32.     
  33.     if ((gDataRateMenu = GetMenu(DATA_RATE_MENU_ID)) == NIL_POINTER)    /* Hier. menus */
  34.         ErrorHandler(NO_MENU);
  35.     InsertMenu(gDataRateMenu, NOT_A_NORMAL_MENU);
  36.     if ((gDataBitsMenu = GetMenu(DATA_BITS_MENU_ID)) == NIL_POINTER)
  37.         ErrorHandler(NO_MENU);
  38.     InsertMenu(gDataBitsMenu, NOT_A_NORMAL_MENU);
  39.     if ((gStopBitsMenu = GetMenu(STOP_BITS_MENU_ID)) == NIL_POINTER)
  40.         ErrorHandler(NO_MENU);
  41.     InsertMenu(gStopBitsMenu, NOT_A_NORMAL_MENU);
  42.     if ((gParityMenu = GetMenu(PARITY_MENU_ID)) == NIL_POINTER)
  43.         ErrorHandler(NO_MENU);
  44.     InsertMenu(gParityMenu, NOT_A_NORMAL_MENU);
  45.     
  46.     if ((gWindowMenu = GetMenu(WINDOW_MENU_ID)) == NIL_POINTER)            /* Window Menu */
  47.         ErrorHandler(NO_MENU);
  48.     
  49.     DrawMenuBar();
  50. }
  51.  
  52.  
  53. /***** AdjustEditMenu *****/
  54. AdjustEditMenu()
  55. {
  56.     if (IsDAWindow(FrontWindow()))
  57.     {
  58.         EnableItem(gEditMenu, UNDO_ITEM);
  59.         EnableItem(gEditMenu, CUT_ITEM);
  60.         EnableItem(gEditMenu, COPY_ITEM);
  61.         EnableItem(gEditMenu, PASTE_ITEM);
  62.         EnableItem(gEditMenu, CLEAR_ITEM);
  63.     }
  64.     else
  65.     {
  66.         DisableItem(gEditMenu, UNDO_ITEM);
  67.         DisableItem(gEditMenu, CUT_ITEM);
  68.         DisableItem(gEditMenu, COPY_ITEM);
  69.         DisableItem(gEditMenu, PASTE_ITEM);
  70.         DisableItem(gEditMenu, CLEAR_ITEM);
  71.     }
  72. }
  73.  
  74.  
  75. /***** DoMenuChoice *****/
  76. DoMenuChoice(menuChoice)
  77. long int    menuChoice;
  78. {
  79.     int    theMenu;
  80.     int    theItem;
  81.     
  82.     if (menuChoice != 0)
  83.     {
  84.         theMenu = HiWord(menuChoice);
  85.         theItem = LoWord(menuChoice);
  86.         switch (theMenu)
  87.         {
  88.             case APPLE_MENU_ID:
  89.                 DoAppleChoice(theItem);
  90.                 break;
  91.             case FILE_MENU_ID:
  92.                 DoFileChoice(theItem);
  93.                 break;
  94.             case EDIT_MENU_ID:
  95.                 DoEditChoice(theItem);
  96.                 break;
  97.             case GLOVE_MENU_ID:
  98.                 DoGloveChoice(theItem);
  99.                 break;
  100.             case TERMINAL_MENU_ID:
  101.                 DoTerminalChoice(theItem);
  102.                 break;
  103.             case DATA_RATE_MENU_ID:
  104.                 DoDataRateChoice(theItem);
  105.                 break;
  106.             case DATA_BITS_MENU_ID:
  107.                 DoDataBitsChoice(theItem);
  108.                 break;
  109.             case STOP_BITS_MENU_ID:
  110.                 DoStopBitsChoice(theItem);
  111.                 break;
  112.             case PARITY_MENU_ID:
  113.                 DoParityChoice(theItem);
  114.                 break;
  115.             case WINDOW_MENU_ID:
  116.                 DoWindowChoice(theItem);
  117.                 break;
  118.         }
  119.         HiliteMenu(0);
  120.     }
  121. }
  122.  
  123.  
  124. /***** DoAppleChoice *****/
  125. DoAppleChoice(theItem)
  126. int theItem;
  127. {
  128.     Str255        accName;
  129.     int            accNumber;
  130.     short int    itemNumber;
  131.     DialogPtr    AboutDialog;
  132.     
  133.     switch (theItem)
  134.     {
  135.         case ABOUT_ITEM:
  136.             Alert(ABOUT_ALERT, NIL_POINTER);
  137.             break;
  138.         default:
  139.             GetItem(gAppleMenu, theItem, accName);
  140.             accNumber = OpenDeskAcc(accName);
  141.             break;
  142.     }
  143. }
  144.  
  145.  
  146. /***** DoFileChoice *****/
  147. DoFileChoice(theItem)
  148. int theItem;
  149. {
  150.     switch (theItem)
  151.     {
  152.         case SEND_TEXT_ITEM:
  153.             SendText();
  154.             break;
  155.         case DOWNLOAD_ITEM:
  156.             DownloadSRecord();
  157.             break;
  158.         case QUIT_ITEM:
  159.             gDone = TRUE;
  160.             break;
  161.     }
  162. }
  163.  
  164.  
  165. /***** DoEditChoice *****/
  166. DoEditChoice(theItem)
  167. int theItem;
  168. {
  169.     SystemEdit(theItem - 1);
  170. }
  171.  
  172.  
  173. /***** DoGloveChoice *****/
  174. DoGloveChoice(theItem)
  175. int theItem;
  176. {
  177.     switch (theItem)
  178.     {
  179.         case REQUEST_ITEM:
  180.             if (gContinuous)
  181.                 StopContinuous();
  182.             ShowData();
  183.             GetGlove(&gTheGlove);
  184.             DisplayGlove(&gTheGlove);
  185.             if (gBall)
  186.                 DrawBall(gTheGlove.x + 128, 128 - gTheGlove.y, gTheGlove.z + 128);
  187.             break;
  188.         case CONTINUOUS_ITEM:
  189.             if (!gContinuous)
  190.             {
  191.                 StartContinuous();
  192.                 ShowData();
  193.             }
  194.             break;
  195.         case SMOOTH_ITEM:
  196.             ToggleSmoothing();
  197.             break;
  198.     }
  199. }
  200.  
  201.  
  202. /***** DoTerminalChoice *****/
  203. DoTerminalChoice(theItem)
  204. int theItem;
  205. {
  206.     switch (theItem)
  207.     {
  208.         case TERMINAL_ITEM:
  209.             if (gTerminal)
  210.                 StopTerm();
  211.             else
  212.                 StartTerm();
  213.             break;
  214.     }
  215. }
  216.  
  217.  
  218. /***** DoDataRateChoice *****/
  219. DoDataRateChoice(theItem)
  220. int theItem;
  221. {
  222.     switch (theItem)
  223.     {
  224.         case 1:
  225.             gDataRate = baud300;
  226.             break;
  227.         case 2:
  228.             gDataRate = baud1200;
  229.             break;
  230.         case 3:
  231.             gDataRate = baud2400;
  232.             break;
  233.         case 4:
  234.             gDataRate = baud4800;
  235.             break;
  236.         case 5:
  237.             gDataRate = baud9600;
  238.             break;
  239.         case 6:
  240.             gDataRate = baud19200;
  241.             break;
  242.         case 7:
  243.             gDataRate = baud57600;
  244.             break;
  245.     }
  246.     ChangeSettings(gDataRate+gDataBits+gStopBits+gParity);
  247.     AdjustTerminalMenu();
  248. }
  249.  
  250.  
  251. /***** DoDataBitsChoice *****/
  252. DoDataBitsChoice(theItem)
  253. int theItem;
  254. {
  255.     switch (theItem)
  256.     {
  257.         case 1:
  258.             gDataBits = data7;
  259.             break;
  260.         case 2:
  261.             gDataBits = data8;
  262.     }
  263.     ChangeSettings(gDataRate+gDataBits+gStopBits+gParity);
  264.     AdjustTerminalMenu();
  265. }
  266.  
  267.  
  268. /***** DoStopBitsChoice *****/
  269. DoStopBitsChoice(theItem)
  270. int theItem;
  271. {
  272.     switch (theItem)
  273.     {
  274.         case 1:
  275.             gStopBits = stop10;
  276.             break;
  277.         case 2:
  278.             gStopBits = stop15;
  279.             break;
  280.         case 3:
  281.             gStopBits = stop20;
  282.             break;
  283.     }
  284.     ChangeSettings(gDataRate+gDataBits+gStopBits+gParity);
  285.     AdjustTerminalMenu();
  286. }
  287.  
  288.  
  289. /***** DoParityChoice *****/
  290. DoParityChoice(theItem)
  291. int theItem;
  292. {
  293.     switch (theItem)
  294.     {
  295.         case 1:
  296.             gParity = noParity;
  297.             break;
  298.         case 2:
  299.             gParity = evenParity;
  300.             break;
  301.         case 3:
  302.             gParity = oddParity;
  303.             break;
  304.     }
  305.     ChangeSettings(gDataRate+gDataBits+gStopBits+gParity);
  306.     AdjustTerminalMenu();
  307. }
  308.  
  309.  
  310. /***** DoWindowChoice *****/
  311. DoWindowChoice(theItem)
  312. int theItem;
  313. {
  314.     switch (theItem)
  315.     {
  316.         case GLOVE_DATA_ITEM:
  317.             if (gShowData)
  318.                 HideData();
  319.             else
  320.             {
  321.                 ShowData();
  322.                 DisplayGlove(&gTheGlove);
  323.             }
  324.             break;
  325.         case SHOW_ADT_ITEM:
  326.             if (gShowADT)
  327.                 HideADT();
  328.             else
  329.                 ShowADT();
  330.             break;
  331.         case BALL_ITEM:
  332.             if (gBall)
  333.                 StopBall();
  334.             else
  335.             {
  336.                 StartBall();
  337.                 DrawBall(gTheGlove.x + 128, 128 - gTheGlove.y, gTheGlove.z + 128);
  338.             }
  339.             break;
  340.     }
  341. }
  342.  
  343.  
  344. /*** CheckTerminalItems ***/
  345. AdjustTerminalMenu()
  346. {
  347.     CheckItem(gTerminalMenu, TERMINAL_ITEM, gTerminal);        /* Deal with Terminal */
  348.  
  349.     CheckItem(gDataRateMenu, 1, (gDataRate == baud300));    /* Deal with Baud */
  350.     CheckItem(gDataRateMenu, 2, (gDataRate == baud1200));
  351.     CheckItem(gDataRateMenu, 3, (gDataRate == baud2400));
  352.     CheckItem(gDataRateMenu, 4, (gDataRate == baud4800));
  353.     CheckItem(gDataRateMenu, 5, (gDataRate == baud9600));
  354.     CheckItem(gDataRateMenu, 6, (gDataRate == baud19200));
  355.     CheckItem(gDataRateMenu, 7, (gDataRate == baud57600));
  356.     
  357.     CheckItem(gDataBitsMenu, 1, (gDataBits == data7));        /* Deal with Data Bits */
  358.     CheckItem(gDataBitsMenu, 2, (gDataBits == data8));
  359.     
  360.     CheckItem(gStopBitsMenu, 1, (gStopBits == stop10));        /* Deal with Stop Bits */
  361.     CheckItem(gStopBitsMenu, 2, (gStopBits == stop15));
  362.     CheckItem(gStopBitsMenu, 3, (gStopBits == stop20));
  363.     
  364.     CheckItem(gParityMenu, 1, (gParity == noParity));        /* Deal with Parity */
  365.     CheckItem(gParityMenu, 2, (gParity == evenParity));
  366.     CheckItem(gParityMenu, 3, (gParity == oddParity));
  367. }
  368.  
  369.  
  370. /***** AdjustGloveMenu *****/
  371. AdjustGloveMenu()
  372. {
  373.     CheckItem(gGloveMenu, REQUEST_ITEM, !gContinuous);
  374.     CheckItem(gGloveMenu, CONTINUOUS_ITEM, gContinuous);
  375.     CheckItem(gGloveMenu, SMOOTH_ITEM, gSmooth);
  376. }
  377.  
  378.  
  379. /***** AdjustWindowMenu *****/
  380. AdjustWindowMenu()
  381. {
  382.     CheckItem(gWindowMenu, GLOVE_DATA_ITEM, gShowData);
  383.     CheckItem(gWindowMenu, SHOW_ADT_ITEM, gShowADT);
  384.     CheckItem(gWindowMenu, BALL_ITEM, gBall);
  385. }
  386.