home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / zfrms110.zip / ZFORMS.C < prev    next >
C/C++ Source or Header  |  1993-09-06  |  16KB  |  364 lines

  1. /* Z-Forms demo source code for version 1.1 */
  2. #include "zforms.h"
  3. #include <stdlib.h>
  4.  
  5. /* window for foreground/background demo */
  6. WINDOW *pBackWin;
  7.  
  8. /*****************************************************************************/
  9. /* A demonstration of the TTY functions.  Any keypresses are written         */
  10. /* into the window in TTY mode, with auto-scrolling                          */
  11. void TTYDemo(int Item) {
  12.    WINDOW TTYWin = {
  13.       0, 10, 70, NULL, NULL, 5, 8, 0x0720, BS_SINGLELINE, BRIGHTWHITE, BLACK,
  14.       DS_LOWERRIGHT, DARKGREY, "TTY Test Window", 
  15.       "Type any data into the window, F1 to clear, or Escape to exit"
  16.       };
  17.    WINDOW *pTTYWin;
  18.    int Key=0;
  19.  
  20.    /* open the window */
  21.    pTTYWin = Z_OpenWindow(&TTYWin);
  22.    
  23.    /* position the cursor */
  24.    Z_SetCursor(pTTYWin, 1, 1);
  25.  
  26.    /* get data for the window */
  27.    while(Key != k_Esc) {
  28.       Key = Z_GetKey();
  29.       if(Key == k_F1) {
  30.          Z_ClearWindow(pTTYWin);
  31.          Z_SetCursor(pTTYWin, 1, 1);
  32.          }
  33.       else Z_CharOverTTY(pTTYWin, (char)Key);
  34.       }
  35.  
  36.    /* close the window and exit */
  37.    Z_CloseWindow(pTTYWin);
  38.    }
  39.  
  40. /*****************************************************************************/
  41. /* A demonstration of the updating of background windows.  The function      */
  42. /* writes characters into the background window, which scrolls behind the    */
  43. /* foreground window                                                         */
  44. void BackgroundFunc(void) {
  45.    static unsigned char i=0x20;
  46.    int j;
  47.    char String[60];
  48.    
  49.    /* build string to display */
  50.    for(j=0;j<58;j++) {
  51.       String[j] = i++;
  52.       if(i >=127) i = 0x20;
  53.       }
  54.    String[j] = 0;
  55.    
  56.    /* display it and scroll */
  57.    Z_TextOver(pBackWin, String, 1, 8);
  58.    Z_ScrollUp(pBackWin, 1);
  59.    }
  60.    
  61. /*****************************************************************************/
  62. /* A demonstration of the updating of background windows, and background     */
  63. /* processes.  The function sets the packground process, which writes        */
  64. /* characters into the background window, which scrolls behind the           */
  65. /* foreground window                                                         */
  66. void BackgroundDemo(int Item) {
  67.    WINDOW BackWin = {
  68.       0, 10, 60, NULL, NULL, 10, 8, 0x2720, BS_SINGLELINE, BLACK, GREEN,
  69.       DS_LOWERRIGHT, DARKGREY, NULL, "Background Window"
  70.       };
  71.    WINDOW ForeWin = {
  72.       0, 7, 40, NULL, NULL, 5, 5, 0x1720, BS_DOUBLELINE, YELLOW, BLUE,
  73.       DS_LOWERRIGHT, DARKGREY, "Foreground Window", 
  74.       "Press Escape to end the test"
  75.       };
  76.    static char ForeResp[20] = "          ";
  77.    PROMPT ForePrompt[] = { 
  78.       ForeResp, "Prompt: ", "##########", 10, 8, 4, YELLOW, BLUE,
  79.          BRIGHTWHITE, BLUE, BLACK, CYAN, NULL, NULL,
  80.       NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL};
  81.    int ForeExit[] = { k_Esc, k_NoKey };   
  82.    WINDOW *pForeWin;
  83.    int Key=0;
  84.  
  85.    /* open the window */
  86.    pBackWin = Z_OpenWindow(&BackWin);
  87.    pForeWin = Z_OpenWindow(&ForeWin);
  88.    
  89.    /* put some text on the forground window */
  90.    Z_TextOut(pForeWin, "This window is the foreground window", 2, 2, 
  91.       BRIGHTWHITE, BLUE);
  92.  
  93.    /* position the cursor */
  94.    Z_SetCursor(pBackWin, 1, 1);
  95.  
  96.    /* set the background function */
  97.    Z_SetBackgroundProcess(BackgroundFunc, 100);
  98.  
  99.    /* get a key press */   
  100.    /* handle the data entry fields */
  101.    Key = Z_HandleInputs(pForeWin, NULL, ForePrompt, ForeExit);
  102.  
  103.    /* reset background process */
  104.    Z_SetBackgroundProcess(NULL, 50);
  105.  
  106.    /* close the window and exit */
  107.    Z_CloseWindow(pForeWin);
  108.    Z_CloseWindow(pBackWin);
  109.    }
  110.  
  111. /*****************************************************************************/
  112. /* Test the speed of window drawing.  This function displays a 15X60 window, */
  113. /* then alternately displays and removes it when a key is pressed.           */
  114. void SpeedDemo(int Item) {
  115.    WINDOW SecondWin = {
  116.       0, 15, 60, NULL, NULL, 10, 3, 0x2720, BS_SINGLELINE, BLACK, GREEN,
  117.       DS_LOWERRIGHT, DARKGREY, "Test Window", NULL
  118.       };
  119.    WINDOW InstructWin = {
  120.       0, 2, 56, NULL, NULL, 12, 19, 0x1E20, BS_DOUBLELINE, YELLOW, BLUE,
  121.       DS_LOWERRIGHT, DARKGREY, "Window Speed Demo", 
  122.       "Press Any Key To Open/Close Window, or Escape To Exit"
  123.       };
  124.    WINDOW *pSecWin, *pInstructWin;
  125.    int Key=0;
  126.  
  127.    /* open both windows */
  128.    pSecWin = Z_OpenWindow(&SecondWin);
  129.    pInstructWin = Z_OpenWindow(&InstructWin);
  130.  
  131.    /* push one window, then pop it */
  132.    while(Key != k_Esc) {
  133.       Key = Z_GetKey();
  134.       if(pSecWin->fShown) Z_HideWindow(pSecWin);
  135.       else Z_ShowWindow(pSecWin);    
  136.       }
  137.  
  138.    /* close both windows and exit */
  139.    Z_CloseWindow(pInstructWin);
  140.    Z_CloseWindow(pSecWin);
  141.    }
  142.  
  143. /*****************************************************************************/
  144. /* This is the verification function for the third line of the prompt.       */
  145. /* The response must begin with an 'A' in order to be verified               */
  146. int VerifyPrompt3(char *Line) {
  147.    if(Line[0] == 'A') return(1);
  148.    else {
  149.       Z_InformUser("Invalid Response", "This response must begin with 'A'", 
  150.          " <OK> ", NULL);
  151.       return(0);
  152.       }
  153.    }
  154.  
  155. /*****************************************************************************/
  156. /* A demo of Prompt handling                                                 */
  157. void PromptDemo(int Item) {
  158.    WINDOW PromptWin = {
  159.       0, 10, 60, NULL, NULL, 10, 8, 0x1020, BS_DOUBLELINE, YELLOW, BLUE,
  160.       DS_LOWERRIGHT, DARKGREY, "Data Entry Demo", "F2-Exit  Esc-Abort" };
  161.    WINDOW *pPromptWin;
  162.    WINDOW PromptHintWin = {
  163.       0, 1, 58, NULL, NULL, 11, 16, 0x1020, BS_NOBORDER, BLACK, BLACK,
  164.       DS_NONE, BLACK, NULL, NULL };
  165.    WINDOW *pPHWin;
  166.    int Key;
  167.    static char Response1[20] = "", Response2[15] = "", Response3[15] = "";
  168.    PROMPT TestPrompt[] = { 
  169.       Response1, "Numeric Prompt: ", "(999) 999-9999", 14, 15, 2, YELLOW, BLUE,
  170.          BRIGHTWHITE, BLUE, BLACK, CYAN, NULL, 
  171.          " This field will accept only numbers                ",
  172.       Response2, "Upper Case Prompt: ", "UUUUUUUUUU", 10, 12, 4, YELLOW, BLUE,
  173.          YELLOW, BLUE, BLACK, CYAN, NULL, 
  174.          " This prompt will accept only upper case letters        ",
  175.       Response3, "Any Data: ", "##########", 10, 21, 6, YELLOW, BLUE,
  176.          YELLOW, BLUE, BLACK, CYAN, VerifyPrompt3, 
  177.          " This prompt will accept any data starting with 'A'",
  178.       NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL};
  179.    int PromptExit[] = { k_F2, k_Esc, k_NoKey };   
  180.  
  181.    /* open prompt window */
  182.    pPromptWin = Z_OpenWindow(&PromptWin);
  183.    pPHWin = Z_OpenWindow(&PromptHintWin);
  184.  
  185.    /* handle the data entry fields */
  186.    Key = Z_HandleInputs(pPromptWin, pPHWin, TestPrompt, PromptExit);
  187.  
  188.    /* close the window and exit */
  189.    Z_CloseWindow(pPHWin);
  190.    Z_CloseWindow(pPromptWin);
  191.    }
  192.  
  193. /*****************************************************************************/
  194. /* A demo of a simple picklist                                               */
  195. void TestPickList(void) {
  196.    PICKLIST TestPL = {
  197.       10, 5, 10, 60, 58, PLF_VERTSCROLL, YELLOW, BLUE, BLACK, CYAN, 
  198.          BS_SINGLELINE, YELLOW, BLUE, 0x1020, DS_LOWERRIGHT, DARKGREY, 
  199.          "PickList Demonstration" };
  200.    PICKLIST *pPL;
  201.    PICKLIST_ITEM *pPLI;
  202.    
  203.    /* test the picklist */
  204.    pPL = &TestPL;
  205.    Z_AddPickListItem(pPL, "Line 1");
  206.    Z_AddPickListItem(pPL, "Line 2");
  207.    Z_AddPickListItem(pPL, "Line 3");
  208.    Z_AddPickListItem(pPL, "Line 4");
  209.    Z_AddPickListItem(pPL, "Line 5");
  210.    Z_AddPickListItem(pPL, "Line 6");
  211.    Z_AddPickListItem(pPL, "Line 7");
  212.    Z_AddPickListItem(pPL, "Line 8");
  213.    Z_AddPickListItem(pPL, "Line 9");
  214.    Z_AddPickListItem(pPL, "Line 10");
  215.    Z_AddPickListItem(pPL, "Line 11");
  216.    Z_AddPickListItem(pPL, "Line 12");
  217.    Z_AddPickListItem(pPL, "Line 13");
  218.    Z_AddPickListItem(pPL, "Line 14");
  219.    pPLI = Z_HandlePickList(pPL);
  220.    if(pPLI) Z_InformUser("PickList Choice", pPLI->ItemText, " <OK> ", NULL);
  221.    }
  222.  
  223. /*****************************************************************************/
  224. /* Main window and main menu processing                                      */
  225. /* There are only 5 line of code in this function.  The rest is structure    */
  226. /* initialization.  The other functions in the code are called by Z-Forms as */
  227. /* the result of some user action                                            */
  228. void main(void) {
  229.    /* main window, covering the whole 80X25 display */
  230.    WINDOW MainWin = {
  231.       0, 25, 80, NULL, NULL, 0, 0, 0x03b0, BS_SINGLELINE, YELLOW, BLUE, 
  232.       DS_NONE, 0, " Z-Forms Demonstration Program ", 
  233.       "Complete Demo Source in ZFORMS.C" };
  234.    WINDOW *pWin;
  235.    static int OneOfVar=0, CheckVar=0;
  236.    static char DataVar[35] = "                   ";
  237.  
  238. #ifdef __Z_INIT_EXT__
  239.    /* these initializations are for MSC6 and other compilers that allow */
  240.    /* unsized array initialzations within a structure                   */
  241.    static MENU VertMenu = {
  242.       33, 2, 5, 20, 18, MMF_VERTMENU | MMF_USEHINT, BRIGHTWHITE, BLUE, 
  243.       LT_RED, BLUE, BLUE, CYAN, WHITE, BLUE, 1, 23, 78, BS_SINGLELINE, 
  244.       YELLOW, BLUE, 0, 0, NULL,
  245.          "TTY Demo", MIF_CALLFUNC, 'T', 0,  1, 1, (void *)TTYDemo,
  246.             " TTY demo with auto-scrolling        ",
  247.          "Background Demo", MIF_CALLFUNC, 'B', 0,  1, 2, (void *)BackgroundDemo,
  248.             " Demo of background processes/windows",
  249.          "Nothing", MIF_CALLEXIT, 'N', 0,  1, 3, NULL,
  250.             " Dummy option does nothing           ",
  251.          NULL, 0, 0, 0, 0, 0, NULL, "" };
  252.    static DIALOG TestDialog = {
  253.       10, 5, 13, 60, DBF_USEHINT, 0x1E20, YELLOW, BLUE, 11, 16, 58, 
  254.       BS_DOUBLELINE, YELLOW, BLUE, DS_LOWERRIGHT, 0x8, "Test Dialog Box", NULL,
  255.          "This is a text control", CSF_TEXT, CSS_NOACTIVATE | CSS_CALLNOTHING, 
  256.             0, 0, 20, 2, 1, 22, YELLOW, BLUE, CYAN, BLUE, NULL, NULL, NULL,
  257.          "Data Entry: ", CSF_DATAENTRY, CSS_ACTIVATE | CSS_CALLNOTHING, 
  258.             k_Alt_D, 0, 3, 4, 0, 0x1E0A, WHITE, BLUE, CYAN, BLUE, DataVar, 
  259.             "This is a data entry control", NULL,
  260.          "Checkbox", CSF_CHECKBOX, CSS_ACTIVATE | CSS_CALLNOTHING, k_Alt_C, 3,
  261.             42, 4, 0, 0, WHITE, BLUE, BRIGHTWHITE, BLUE, &CheckVar, 
  262.             "This is a check box control", NULL,
  263.          "OneOfButton1", CSF_ONEOFBUTTON, CSS_ACTIVATE | CSS_CALLNOTHING, 
  264.             k_Alt_O, 0, 22, 6, 0, 0, WHITE, BLUE, BRIGHTWHITE, BLUE, &OneOfVar,
  265.             "This is a group of one-of buttons", NULL,
  266.          "OneOfButton2", CSF_ONEOFBUTTON, CSS_ACTIVATE | CSS_CALLNOTHING, 
  267.             k_Alt_N, 1, 22, 7, 0, 1, WHITE, BLUE, BRIGHTWHITE, BLUE, &OneOfVar,
  268.             "This is a group of one-of buttons", NULL,
  269.          " <Exit> ", CSF_BUTTON, CSS_ACTIVATE | CSS_EXIT, k_Esc, 0, 26, 9, 0,
  270.             0, WHITE, RED, BRIGHTWHITE, RED, NULL, "This is a button control",
  271.             NULL,
  272.          NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, "", NULL};
  273.    static MENU MainMenu = {
  274.       1, 1, 1, 78, 0, MMF_HORIZMENU | MMF_USEHINT, BRIGHTWHITE, BLUE, 
  275.       LT_RED, BLUE, BLUE, CYAN, YELLOW, BLUE, 1, 23, 78, BS_NOBORDER, 
  276.       BLACK, BLACK, 0, 0, NULL,
  277.          "Speed Demo", MIF_CALLFUNC, 'S', 0,  3, 0, (void *)SpeedDemo, 
  278.             " Display and hide a window           ",
  279.          "Data Entry", MIF_CALLFUNC, 'D', 0,  18, 0, (void *)PromptDemo, 
  280.             " Demonstration of Data Entry fields  ",
  281.          "Menu", MIF_CALLMENU, 'M', 0,  32, 0, (void *)&VertMenu, 
  282.             " Demonstration of a Vertical Menu    ",
  283.          "Dialog Box", MIF_CALLDIALOG, 'I', 1,  40, 0, (void *)&TestDialog, 
  284.             " Demonstration of a Dialog Box       ",
  285.          "PickList", MIF_CALLFUNC, 'P', 0,  54, 0, (void *)&TestPickList, 
  286.             " Demonstration of a Pick List        ",
  287.          "Exit", MIF_CALLEXIT, 'X', 1,  70, 0, NULL, 
  288.             " Exit the Z-Forms demo               ",
  289.          NULL, 0, 0, 0, 0, 0, NULL, "" };
  290. #else
  291.    /* these initializations are for those compilers which do not allow */
  292.    /* unsized array initializations in structures                      */
  293.    static MENU_ITEM VertMenuItem[] = {
  294.          "TTY Demo", MIF_CALLFUNC, 'T', 0,  1, 1, (void *)TTYDemo,
  295.             " TTY demo with auto-scrolling        ",
  296.          "Background Demo", MIF_CALLFUNC, 'B', 0,  1, 2, (void *)BackgroundDemo,
  297.             " Demo of background processes/windows",
  298.          "Nothing", MIF_CALLEXIT, 'N', 0,  1, 3, NULL,
  299.             " Dummy option does nothing           ",
  300.          NULL, 0, 0, 0, 0, 0, NULL, "" };
  301.    static MENU VertMenu = {
  302.       33, 2, 5, 20, 18, MMF_VERTMENU | MMF_USEHINT, BRIGHTWHITE, BLUE, 
  303.       LT_RED, BLUE, BLUE, CYAN, WHITE, BLUE, 1, 23, 78, BS_SINGLELINE, 
  304.       YELLOW, BLUE, 0, 0, NULL, VertMenuItem };
  305.    static DLG_CONTROL TestDialogControl[] = {
  306.          "This is a text control", CSF_TEXT, CSS_NOACTIVATE | CSS_CALLNOTHING, 
  307.             0, 0, 20, 2, 1, 22, YELLOW, BLUE, CYAN, BLUE, NULL, NULL, NULL,
  308.          "Data Entry: ", CSF_DATAENTRY, CSS_ACTIVATE | CSS_CALLNOTHING, 
  309.             k_Alt_D, 0, 3, 4, 0, 0x1E0A, WHITE, BLUE, CYAN, BLUE, DataVar, 
  310.             "This is a data entry control", NULL,
  311.          "Checkbox", CSF_CHECKBOX, CSS_ACTIVATE | CSS_CALLNOTHING, k_Alt_C, 3,
  312.             42, 4, 0, 0, WHITE, BLUE, BRIGHTWHITE, BLUE, &CheckVar, 
  313.             "This is a check box control", NULL,
  314.          "OneOfButton1", CSF_ONEOFBUTTON, CSS_ACTIVATE | CSS_CALLNOTHING, 
  315.             k_Alt_O, 0, 22, 6, 0, 0, WHITE, BLUE, BRIGHTWHITE, BLUE, &OneOfVar,
  316.             "This is a group of one-of buttons", NULL,
  317.          "OneOfButton2", CSF_ONEOFBUTTON, CSS_ACTIVATE | CSS_CALLNOTHING, 
  318.             k_Alt_N, 1, 22, 7, 0, 1, WHITE, BLUE, BRIGHTWHITE, BLUE, &OneOfVar,
  319.             "This is a group of one-of buttons", NULL,
  320.          " <Exit> ", CSF_BUTTON, CSS_ACTIVATE | CSS_EXIT, k_Esc, 0, 26, 9, 0,
  321.             0, WHITE, RED, BRIGHTWHITE, RED, NULL, "This is a button control",
  322.             NULL,
  323.          NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, "", NULL};
  324.    static DIALOG TestDialog = {
  325.       10, 5, 13, 60, DBF_USEHINT, 0x1E20, YELLOW, BLUE, 11, 16, 58, 
  326.       BS_DOUBLELINE, YELLOW, BLUE, DS_LOWERRIGHT, 0x8, "Test Dialog Box", 
  327.       NULL, TestDialogControl };
  328.    static MENU_ITEM MainMenuItem[] = {
  329.          "Speed Demo", MIF_CALLFUNC, 'S', 0,  3, 0, (void *)SpeedDemo, 
  330.             " Display and hide a window           ",
  331.          "Data Entry", MIF_CALLFUNC, 'D', 0,  18, 0, (void *)PromptDemo, 
  332.             " Demonstration of Data Entry fields  ",
  333.          "Menu", MIF_CALLMENU, 'M', 0,  32, 0, (void *)&VertMenu, 
  334.             " Demonstration of a Vertical Menu    ",
  335.          "Dialog Box", MIF_CALLDIALOG, 'I', 1,  40, 0, (void *)&TestDialog, 
  336.             " Demonstration of a Dialog Box       ",
  337.          "PickList", MIF_CALLFUNC, 'P', 0,  54, 0, (void *)&TestPickList, 
  338.             " Demonstration of a Pick List        ",
  339.          "Exit", MIF_CALLEXIT, 'X', 1,  70, 0, NULL, 
  340.             " Exit the Z-Forms demo               ",
  341.          NULL, 0, 0, 0, 0, 0, NULL, "" };
  342.    static MENU MainMenu = {
  343.       1, 1, 1, 78, 0, MMF_HORIZMENU | MMF_USEHINT, BRIGHTWHITE, BLUE, 
  344.       LT_RED, BLUE, BLUE, CYAN, YELLOW, BLUE, 1, 23, 78, BS_NOBORDER, 
  345.       BLACK, BLACK, 0, 0, NULL, MainMenuItem};
  346. #endif
  347.  
  348.    /* open the main window */
  349.    pWin = Z_OpenWindow(&MainWin);
  350.  
  351.    /* display the welcoming dialog box */
  352.    Z_Alert(ALERT_THREEBEEP);
  353.    Z_InformUser("Z-Forms V1.1", "Welcome to the Z-Forms Demo!", 
  354.       "<Continue>", NULL);
  355.  
  356.    /* display and handle the main menu */
  357.    Z_HandleMenu(&MainMenu);
  358.    
  359.    /* close the main window and exit */
  360.    Z_Alert(ALERT_TWOTONES);
  361.    Z_CloseWindow(pWin);
  362.    Z_ClearScreen(' ', WHITE);
  363.    }
  364.