home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 1.ddi / EXAMPLE.EXE / CSCAPE / EXAMPLE / DEMOMOUS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-12  |  6.0 KB  |  228 lines

  1. /*
  2.     demomous.c
  3.  
  4.     Copyright (c) 1988, by Oakland Group, Inc.
  5.     ALL RIGHTS RESERVED.
  6.  
  7.     This program demonstrates how to use a mouse with C-scape.
  8.  
  9.     There are three seds (windows).
  10.     One is a small data entry screen.
  11.     Two is a list of choices that can be selected with the mouse or
  12.         space bar.
  13.     Three is a text window.
  14.  
  15.     You can select windows by moving the mouse over the desired window.
  16.     When you are finished you can quit by pressing ESC or by 
  17.     clicking the mouse on the field that says "Done".
  18.  
  19.     This program keeps a global list of its seds.  This list
  20.     is used by the special function spc_Jump to cycle between the windows
  21.     when the TAB key is pressed in order to simulate the mouse via
  22.     the keyboard.  The special function is attached to the seds in order
  23.     to intercept the TAB key.
  24.  
  25.     All of the seds use the mouse border, bd_mouse.  You can move any window
  26.     by clicking on its border and dragging.  If you click on a corner
  27.     and drag the sed changes size. 
  28. */
  29.  
  30. #include <stdio.h>
  31. #include <cscape.h>
  32. #include <popdecl.h>        /* for pop_Prompt */
  33. #include <scancode.h>           /* for key names */
  34.  
  35. #include <useful.h>            /* for state names */
  36.  
  37. #ifdef OAK_DOS
  38. #    include <pcmode.h>         /* for pc_IsCompaq, pc_IsEGA, etc. */
  39. #endif
  40.  
  41. boolean spc_Jump(_arg2(sed_type, int));
  42.  
  43. #define WHITE_RED        0x47
  44. #define RED_WHITE        0x74
  45. #define WHITE_BLUE        0x17
  46. #define BLUE_WHITE        0x71
  47.  
  48. #define    THREETEXT        "C-scape mouse demostration.\nUse the mouse to select fields or move the windows.\n\nTo quit, click Done or press Escape."
  49.  
  50. #define    SHIP_NAMES        "US Mail,UPS Red,UPS Blue,Fedex"
  51.  
  52. char *choices[] = {
  53.         "Oregano  ",
  54.         "Basil    ",
  55.         "Garlic   ",
  56.         "Thyme    ",
  57.         "Ginger   ",
  58.         "Coriander",
  59.         "Galanga  "
  60. };
  61.  
  62. #define CHOICE_COUNT    (sizeof(choices) / sizeof(char *))
  63.  
  64. /*** global sedlist (see notes above) ***/
  65. sed_type sedlist[2];
  66.  
  67. void main()
  68. {
  69.     sed_type     sedone, sedtwo, sedthree;
  70.     menu_type     menuone, menutwo;
  71.     char         name[20], city[20], state[3], ship[20];
  72.     boolean        checklist[CHOICE_COUNT];
  73.     int            row;
  74.  
  75.     name[0] = '\0';
  76.     city[0] = '\0';
  77.     state[0] = '\0';
  78.     ship[0] = '\0';
  79.  
  80.     /* Open the display in text mode */
  81.     disp_Init(def_ModeText, NULL);
  82.  
  83.     /* Turn on the mouse */
  84.     if (!hard_InitMouse()) {
  85.         pop_Prompt("Mouse driver not found!", -1, -1, -1, 25, 0x70, bd_mouse);
  86.     }
  87.     else {
  88.         /* Turn on sedwin mouse, link in mouse border support */
  89.         /* You must call this if you want to use mouse borders */
  90.         /* You can ignore this call if you do not want to use mouse borders */
  91.  
  92.         sedwin_ClassInit();
  93.     }
  94.  
  95.     /* map colors to black and white for mono (or compaq CGAs) displays */
  96. #ifdef OAK_DOS
  97.     if (disp_GetColors() <= 2L || (pc_IsCompaq() && pc_IsCGA() && !pc_IsEGA())){
  98. #else
  99.     if (disp_GetColors() <= 2L){        /* Non-DOS system */
  100. #endif
  101.  
  102.         disp_MapMono(TRUE);
  103.     }
  104.  
  105.     /*** create the first sed ***/
  106.     /* A small data entry window */
  107.  
  108.     menuone = menu_Open();
  109.  
  110.     menu_Printf(menuone, " Customer Information \n\n");
  111.  
  112.     menu_Printf(menuone, "Name:    @fd[#########]\n\n", 
  113.         name, &string_funcs, "Enter customer name");
  114.  
  115.     menu_Printf(menuone, "City:    @fd[#########]\n\n",
  116.         city, &alpha_funcs, "Enter customer city");
  117.  
  118.     menu_Printf(menuone, "State:   @fd2[##       ]\n\n", state, &alpha_funcs,
  119.             "Enter state abbrev.", STATE_2NAMES);
  120.  
  121.     menu_Printf(menuone, "Ship By: @fd2[#########]\n\n", ship, &toggle_funcs,
  122.             "Click for courier", SHIP_NAMES);
  123.  
  124.     menu_Printf(menuone, " @fd[       Done        ]",
  125.             NULL, &click_funcs, "Click to quit");
  126.  
  127.     sedone = sed_Open(menuone);
  128.  
  129.     sed_SetColors(sedone, RED_WHITE, RED_WHITE, WHITE_RED);
  130.     sed_SetBorder(sedone, bd_mouse);
  131.     sed_SetPosition(sedone, 10, 3);
  132.  
  133.     /* Attach a mouse handler to the sed */
  134.     sed_SetMouse(sedone, sedmou_Track);
  135.  
  136.     /*** create the second sed ***/
  137.     /* A list of things to check off */
  138.  
  139.     menutwo = menu_Open();
  140.  
  141.     menu_Printf(menutwo, " Select spice(s) to ship. "); 
  142.  
  143.     for (row = 0; row < CHOICE_COUNT; row++) {
  144.         checklist[row] = FALSE;
  145.  
  146.         menu_Printf(menutwo, "@p[%d,1]@f[# %s ]", row + 2, 
  147.                         &checklist[row], &check_funcs, choices[row]);
  148.     }
  149.  
  150.     sedtwo = sed_Open(menutwo);
  151.  
  152.     sed_SetColors(sedtwo, WHITE_RED, WHITE_RED, RED_WHITE);
  153.     sed_SetBorder(sedtwo, bd_mouse);
  154.     sed_SetPosition(sedtwo, 12, 45);
  155.  
  156.     /* Attach a mouse handler to the sed */
  157.     sed_SetMouse(sedtwo, sedmou_Track);
  158.  
  159.     /*** create the third sed ***/
  160.     /* This is a text box, we will use pop_Text to create it */
  161.     sedthree = pop_Text(THREETEXT, 1, 20, -1, 40, WHITE_BLUE, bd_mouse);
  162.  
  163.     /* Attach a mouse handler to the sed */
  164.     /* For this sed we use the 'click' handler, otherwise
  165.        simply moving the mouse into this window would quit the program.
  166.     */    
  167.     sed_SetMouse(sedthree, sedmou_Click);
  168.  
  169.     /*** put the seds into the global sed list ***/
  170.     /*  This is so the special function, spc_Jump can move between 
  171.         seds without using the mouse */
  172.     sedlist[0] = sedone;
  173.     sedlist[1] = sedtwo;
  174.     sed_SetSpecial(sedone, spc_Jump);
  175.     sed_SetSpecial(sedtwo, spc_Jump);
  176.  
  177.     /*** paint the seds ***/
  178.     /* Note we only need call go on one sed, the mouse handlers
  179.         will pass control back and forth between the seds */
  180.  
  181.     sed_Repaint(sedone);
  182.     sed_Repaint(sedtwo);
  183.     sed_Repaint(sedthree);
  184.     sed_Go(sedone);
  185.  
  186.     /*** close the seds ***/
  187.     sed_Close(sedone);
  188.     sed_Close(sedtwo);
  189.     sed_Close(sedthree);
  190.  
  191.     /* shut down the display */
  192.     disp_Close();
  193. }
  194.  
  195. boolean spc_Jump(sed, scancode)
  196.     sed_type sed;
  197.     int scancode;
  198. /*
  199.     A special which intercepts the TAB key and tells
  200.     the sed to quit and 'jump' to a new window.
  201.     Uses the global list of seds found at the top of this file.
  202. */
  203. {
  204.     if (scancode == TAB) {
  205.  
  206.         /* Quit this sed */
  207.         sed_ToggleExit(sed);
  208.  
  209.         /* Find other window, tell window manager to jump to it */
  210.         if (sed == sedlist[0]) {
  211.             /* we're sed one, jump to sed two */
  212.             sed_SetNextWin(sed, sed_GetWin(sedlist[1]));
  213.  
  214.             /* put sedtwo on top of other windows */
  215.             sed_Top(sedlist[1]);
  216.         }
  217.         else {
  218.             /* we're sed two, jump to sed one */
  219.             sed_SetNextWin(sed, sed_GetWin(sedlist[0]));
  220.  
  221.             /* put sedone on top of other windows */
  222.             sed_Top(sedlist[0]);
  223.         }
  224.         return(TRUE);
  225.     }
  226.     return(FALSE);
  227. }
  228.