home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / window / ultrawin / uwdemo / menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-02  |  5.8 KB  |  158 lines

  1. /****************************************************************************/
  2. /*                                                                                                                                                    */
  3. /* MENU.C                                                                                                                                   */
  4. /*                                                                                                                                                    */
  5. /* This program is a simple demonstration of the usage of a main menu to        */
  6. /* drive an application.                                                    */
  7. /*                                                                          */
  8. /* Also included in this demo is a demonstration on how to toggle between        */
  9. /* 25 and 43/50 text modes, while keeping the same windows on the screen.        */
  10. /* Just pick the appropriate menu selection to see it!                        */
  11. /*                                                         Boyd Gafford            */
  12. /*                                                         EnQue Software        */
  13. /*                                                         02/01/92         */
  14. /*                                                                                                                                                    */
  15. /****************************************************************************/
  16. #include <ctype.h>
  17. #include "uw.h"
  18. #include "uw_globx.h"
  19. #include "uw_keys.h"
  20.  
  21.  
  22. /*----------------------- global window variables --------------------------*/
  23. MENU        Files_menu, Utility_menu, Config_menu,        /* the menus themselves        */
  24.                 Terminal_menu, Network_menu;
  25. MENU        *Drop_mnps[5];                                                        /* pointers to the above    */
  26. MENU        Top_menu, *Top_mnp = &Top_menu;                        /* main top menu!                    */
  27. WINDOW    Back_wn, *Back_wnp = &Back_wn;                        /* the desktop window            */
  28.  
  29.  
  30. /*********/
  31. /* ~main */
  32. /*       ********************************************************************/
  33. /****************************************************************************/
  34. main()
  35. {
  36.     int        back_att  = (LIGHTGRAY << 4) | BLACK,
  37.                 bdr_att   = (LIGHTGRAY << 4) | BLACK,
  38.                 csr_att   = (CYAN << 4) | YELLOW,
  39.                 first_att = (LIGHTGRAY << 4) | RED;
  40.     int        i, id, save_att, end_flag = OFF;
  41.  
  42.     init_video(80, 25);
  43.  
  44.   init_mouse();
  45.  
  46.     Drop_mnps[0] = &Files_menu;
  47.     Drop_mnps[1] = &Utility_menu;
  48.     Drop_mnps[2] = &Config_menu;
  49.     Drop_mnps[3] = &Network_menu;
  50.     Drop_mnps[4] = &Terminal_menu;
  51.  
  52.     menu_create(0, 0, V_cols, 0, M_HORIZONTAL, back_att, bdr_att, csr_att,
  53.                             first_att, NO_BDR, WN_NORMAL, Top_mnp);
  54.  
  55.   item_add(" Files         ", 1, 1, &Top_menu);
  56.   item_add(" Utilities     ", 2, 1, &Top_menu);
  57.   item_add(" Configure     ", 3, 1, &Top_menu);
  58.     item_add(" Networking    ", 4, 6, &Top_menu);
  59.     item_add(" Terminal      ", 5, 1, &Top_menu);
  60.  
  61.     menu_create(0, 1, 16, 8, M_VERTICAL, back_att, bdr_att, csr_att,
  62.                             first_att, SGL_BDR, WN_NORMAL, Drop_mnps[0]);
  63.  
  64.   item_add(" Directory     ", 6, 1, &Files_menu);
  65.   item_add(" Change Path   ", 7, 1, &Files_menu);
  66.   item_add(" OS-Shell      ", 8, 1, &Files_menu);
  67.   item_add(" Spawn Program ", 9, 1, &Files_menu);
  68.   item_add(" View a File   ", 10, 1, &Files_menu);
  69.   item_add(" Exit          ", 11, 2, &Files_menu);
  70.  
  71.     menu_create(15, 1, 33, 7, M_VERTICAL, back_att, bdr_att, csr_att,
  72.                             first_att, SGL_BDR, WN_NORMAL, Drop_mnps[1]);
  73.  
  74.   item_add(" Turn Log On/Off ", 12, 6, &Utility_menu);
  75.   item_add(" Rings to Answer ", 13, 1, &Utility_menu);
  76.   item_add(" Modem Off       ", 14, 7, &Utility_menu);
  77.   item_add(" Modem On        ", 15, 1, &Utility_menu);
  78.   item_add(" Local Log-On    ", 16, 1, &Utility_menu);
  79.  
  80.     menu_create(30, 1, 48, 6, M_VERTICAL, back_att, bdr_att, csr_att,
  81.                             first_att, SGL_BDR, WN_NORMAL, Drop_mnps[2]);
  82.  
  83.   item_add(" General Options  ", 17, 1, &Config_menu);
  84.   item_add(" Modem/Terminal   ", 18, 1, &Config_menu);
  85.   item_add(" Directories      ", 19, 1, &Config_menu);
  86.     item_add(" 25/43/50 rows    ", 20, 1, &Config_menu);
  87.  
  88.     menu_create(45, 1, 62, 9, M_VERTICAL, back_att, bdr_att, csr_att,
  89.                             first_att, SGL_BDR, WN_NORMAL, Drop_mnps[3]);
  90.  
  91.     item_add(" User Accounts  ", 21, 1, &Network_menu);
  92.     item_add(" Backup System  ", 22, 1, &Network_menu);
  93.     item_add(" Message System ", 23, 1, &Network_menu);
  94.     item_add(" File System    ", 24, 1, &Network_menu);
  95.     item_add(" Door System    ", 25, 1, &Network_menu);
  96.     item_add(" Event Setup    ", 26, 1, &Network_menu);
  97.     item_add(" Wait for Call  ", 27, 1, &Network_menu);
  98.  
  99.     menu_create(60, 1, 76, 8, M_VERTICAL, back_att, bdr_att, csr_att,
  100.                             first_att, SGL_BDR, WN_NORMAL, Drop_mnps[4]);
  101.  
  102.     item_add(" Terminal Mode ", 28, 1, &Terminal_menu);
  103.     item_add(" Hang-Up       ", 29, 1, &Terminal_menu);
  104.     item_add(" Phone List    ", 30, 1, &Terminal_menu);
  105.     item_add(" Settings      ", 31, 1, &Terminal_menu);
  106.     item_add(" Download      ", 32, 1, &Terminal_menu);
  107.     item_add(" Upload        ", 33, 1, &Terminal_menu);
  108.  
  109.     V_rows = 50;
  110.     /* first fool UltraWin into thinking we have 50 rows! */
  111.     wn_create(0, 1, 80, 49, NO_BDR, WN_NORMAL, Back_wnp);
  112.     /* create the window to the maximum possible size for VGA!    */
  113.     V_rows = 25;
  114.     /* put the V_rows back to normal */
  115.  
  116.     wn_color(WHITE, BLUE, Back_wnp);
  117.     wn_bdr_color(WHITE, BLUE, Back_wnp);
  118.     add_window(Back_wnp);
  119.     menu_set(Top_mnp);
  120.     m_show();
  121.  
  122.     while (!end_flag)
  123.     {
  124.         id = menu_system(Top_mnp, Drop_mnps, 0);
  125.         switch(id)
  126.         {
  127.             case 11:                                                                        /* time to quit!                    */
  128.                 end_flag = ON;
  129.                 break;
  130.             case 20:                                                                        /* change video mode            */
  131.                 m_hide();                                                                    /* turn off mouse                 */
  132.                 if( V_rows > 25 )                                                    /* some slick code to do    */
  133.                 {
  134.                     set_25_rows();
  135.                     wn_rfsh(Top_mnp->wnp);
  136.                     wn_clear(Back_wnp);
  137.                 } else mode43();
  138.                 V_rows = get_num_rows();
  139.                 csr_hide();                                                                /* hide hardware csr            */
  140.                 m_rowrange( 0, V_rows - 1);                                /* set new mouse y range    */
  141.                 m_show();                                                                    /* turn on mouse!                    */
  142.                 break;
  143.         }
  144.     }
  145.  
  146.     m_hide();
  147.   menu_restore(Top_mnp);
  148.   menu_destroy(Top_mnp);
  149.     for(i=0; i<5; i++)
  150.         menu_destroy(Drop_mnps[i]);
  151.     remove_window(Back_wnp);
  152.     end_mouse();
  153.   end_video();
  154. }
  155. /*** end of main ***/
  156.  
  157. /*** END OF FILE ***/
  158.