home *** CD-ROM | disk | FTP | other *** search
/ Resource for Source: C/C++ / Resource for Source - C-C++.iso / misc_src / cslib16b / demo / panel / cspandem.cpp next >
Encoding:
C/C++ Source or Header  |  1995-11-01  |  13.6 KB  |  372 lines

  1. /***********************************************************************
  2.  
  3.                                        CSA Library, Version 1.6.b 
  4.  
  5.  
  6.                The CSA Library.
  7.            A demonstration of the PANEL class.
  8.  
  9.                                            Copyright(c) 1994,1995 
  10.                                                            Combis 
  11.                                                   The Netherlands 
  12. ***********************************************************************/
  13.  
  14.  
  15. #include "conio.h"
  16. #include "stdio.h"
  17. #include "cskeys.h"
  18. #include "cspanel.h"
  19.  
  20.  
  21.  
  22.  
  23.  
  24. void main(void)
  25. {
  26.  
  27.   desktop();
  28.  
  29. ////////////////////// Explanation ////////////////////////////////
  30.  
  31.   WINDOW w1;
  32.   w1.head(" Panel Demonstration Program ");
  33.   w1.activate();
  34.  
  35.   cprintf("\n\n\r ");
  36.   cprintf("\n\r                    This program will show you     ");
  37.   cprintf("\n\r                    three PANELS.                  ");
  38.   cprintf("\n\r                    The first one will be very     ");
  39.   cprintf("\n\r                    simple. It is intended to      ");
  40.   cprintf("\n\r                    demonstrate the defaults.      ");
  41.   cprintf("\n\r                                                   ");
  42.   cprintf("\n\r                    The second panel is quite      ");
  43.   cprintf("\n\r                    elaborate, using most of       ");
  44.   cprintf("\n\r                    the available options.         ");
  45.   cprintf("\n\r                                                   ");
  46.   cprintf("\n\r                    The last panel shows the       ");
  47.   cprintf("\n\r                    automatic data validation,     ");
  48.   cprintf("\n\r                    applied to different data      ");
  49.   cprintf("\n\r                    types.                         ");
  50.   cprintf("\n\r                                                   ");
  51.   cprintf("\n\r                    Hit any key to continue.       ");
  52.  
  53.   cskey();
  54.  
  55.  
  56.   w1.clear();
  57.   cprintf("\n\r ");
  58.   cprintf("\n\r                           About data validation.      ");
  59.   cprintf("\n\r                                                       ");
  60.   cprintf("\n\r               The validation of the edited fields is done afterwards.   ");
  61.   cprintf("\n\r               This means you can enter almost anything, but you can only    ");
  62.   cprintf("\n\r               advance to the next field if the string satisfies the   ");
  63.   cprintf("\n\r               validation restrains.                   ");
  64.   cprintf("\n\r                                                       ");
  65.   cprintf("\n\r               strings:  No validation by default.     ");
  66.   cprintf("\n\r               integers: Maximal 5 digits and no       ");
  67.   cprintf("\n\r                         preceding zero's.             ");
  68.   cprintf("\n\r               longs:    Maximal 10 digits and no      ");
  69.   cprintf("\n\r                         preceding zero's.             ");
  70.   cprintf("\n\r               date:     Valid calendar date,          ");
  71.   cprintf("\n\r                         leap years are accounted for. ");
  72.   cprintf("\n\r               float:                                  ");
  73.   cprintf("\n\r               double:   Valid floating point number,  ");
  74.   cprintf("\n\r                         meaningless preceding         ");
  75.   cprintf("\n\r                         zero's are not allowed.       ");
  76.   cprintf("\n\r                                                       ");
  77.   cprintf("\n\r                    Hit any key to continue.           ");
  78.  
  79.   cskey();
  80.  
  81.  
  82. /////////////////////// The Keys ////////////////////////////////////
  83.   w1.clear();
  84.   cprintf("\n\n\n\r                             A VERY simple panel. ");
  85.   cprintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\r");
  86.   cprintf("         EDIT KEYS: delete, backspace, cursor, insert, tab.   \n\r" );
  87.   cprintf("         EXIT:      enter or esc.               \n\r");
  88.   cprintf("\n                    All fields can be edited.     ");
  89.  
  90.  
  91. /////////////////////// Variables for the 1st panel ///////////////////
  92.  
  93.   char st[26]="The first field."; // Allocate for at least 25 characters
  94.   int i=25;
  95.   char c='Y';
  96.  
  97.  
  98. /////////////////////// Define the 1st panel //////////////////////////
  99.   PANEL pan1;              // Declare panel.
  100.  
  101.   pan1.height(9);          // Set the height
  102.   pan1.width(40);          // Set the width
  103.  
  104.   pan1.add_field(2,2,25,st);      // Add field at pos 2,2 with length 25
  105.   pan1.add_field(4,2,7,i);      // Add field at pos 4,2 with length 7
  106.   pan1.add_field(6,2,1,c);      // Add field at pos 6,2 with length 1
  107.  
  108. /////////////////////// Browse through it //////////////////////////////
  109.  
  110.   pan1.read();              // Display and edit
  111.  
  112.  
  113. /////////////////////// Show the code //////////////////////////////////
  114.   w1.activate();
  115.   w1.clear();
  116.  
  117.   WINDOW w2;
  118.   w2.set_dim(-1,-1,24,80);
  119.   w2.head(" This is all it took! ");
  120.   w2.activate();
  121.   cprintf("                                                                        \n\r");
  122.   cprintf(" char st[26]=\"The first field.\"; // Allocate for at least 25 characters \n\r");
  123.   cprintf(" int i=25;                                                              \n\r");
  124.   cprintf(" char c='Y';                                                            \n\r");
  125.   cprintf("                                                                        \n\r");
  126.   cprintf(" PANEL pan1;                     // Declare panel.                      \n\r");
  127.   cprintf("                                                                        \n\r");
  128.   cprintf(" pan1.height(9);                 // Set the height                      \n\r");
  129.   cprintf(" pan1.width(40);                 // Set the width                       \n\r");
  130.   cprintf("                                                                        \n\r");
  131.   cprintf(" pan1.add_field(2,2,25,st);      // Add field at pos 2,2 with length 25 \n\r");
  132.   cprintf(" pan1.add_field(4,2,7,i);        // Add field at pos 4,2 with length 7  \n\r");
  133.   cprintf(" pan1.add_field(6,2,1,c);        // Add field at pos 6,2 with length 1  \n\r");
  134.   cprintf("                                                                        \n\r");
  135.   cprintf(" pan1.read();                    // Display and edit                    \n\r");
  136.   cprintf("                                                                        \n\r");
  137.   cprintf("               // Notice the conversion from integer to string and      \n\r");
  138.   cprintf("               // vice versa is done automatically.                     \n\r");
  139.   cprintf("               // The syntax for adding a field is the same             \n\r");
  140.   cprintf("               // in all cases.                                           \n\r");
  141.   cprintf("                                                                        \n\r");
  142.   cprintf("    Hit any key to continue......                                       ");
  143.  
  144.  
  145.   cskey();
  146.  
  147.  
  148.  
  149.  
  150. /////////////////////// Complex Panel ///////////////////////////////
  151.  
  152.   cprintf("\n\n\r      A complicated panel. ");
  153.  
  154.  
  155.   w2.remove();
  156.   w2.set_dim(-1,-1,19,60);
  157.   w2.head(" Panel 2 ");
  158.   w2.activate();
  159.  
  160.   w2.clear();
  161.  
  162.   cprintf("\n\n\r");
  163.   cprintf("   The next panel you can only 'exit' by pressing    \n\r");
  164.   cprintf("   F10 while the cursor is in the 'exit' field.      \n\r");
  165.   cprintf("   The 'ESC' key has been disabled.                  \n\r");
  166.   cprintf("                                                     \n\r");
  167.   cprintf("   Strings which are longer then the                 \n\r");
  168.   cprintf("   field will SCROLL within the field.               \n\r");
  169.   cprintf("                                                     \n\r");
  170.   cprintf("   Two fields are 'browse only' which                \n\r");
  171.   cprintf("   means you are able to put the cursor              \n\r");
  172.   cprintf("   at the field, but are not allowed to edit.        \n\r");
  173.   cprintf("   One field is 'display only', which make           \n\r");
  174.   cprintf("   the cursor skip it.                               \n\r");
  175.   cprintf("                                                     \n\r");
  176.   cprintf("                Hit any key to continue. ");
  177.  
  178.   cskey();
  179.   w2.remove();
  180.  
  181.  
  182. /////////////////////// Variables for the panel ///////////////////
  183.  
  184.   char name[]="Neil A. Armstrong ";
  185.   char ship[]="USS Enterprise  ";
  186.   char rank[]="Retired ";
  187.   char acco[]="The first man ever to set foot on the moon. ";
  188.   char info[]="Neil Armstrong was an astronaut in the years 1962-1970.";
  189.   char birth[]="22/03/1930";
  190.   char ok[]="You can leave the panel by pressing F10 in this field.";
  191.  
  192.  
  193. ///////////////////////// PANEL DEFINITION /////////////////////
  194.   PANEL panel;
  195.  
  196.   panel.set_dim(4,11,17,65);               // Size and Position of panel
  197.   panel.head(" Panel 2 ");                     // Heading
  198.   panel.border(BORDER_DOUBLE);               // Type of border
  199.   panel.activate();                   // Make panel-window visible
  200.  
  201.   gotoyx(2,10); cprintf("Astronaut: ");
  202.   panel.add_field(3,10,25,name);
  203.  
  204.   gotoyx(5,10); cprintf("Favourite space ship: ");
  205.   panel.add_field(6,10,25,ship);
  206.   panel.protect(DISPLAY);               // Display only (no editting).
  207.  
  208.   gotoyx(2,40); cprintf("Rank: ");
  209.   panel.add_field(3,40,15,rank);
  210.  
  211.   gotoyx(5,40); cprintf("Birthday (DD/MM/YYYY): ");
  212.   panel.add_field(6,40,birth);
  213.  
  214.   gotoyx(8,10); cprintf("Accomplishment: ");
  215.   panel.add_field(9,10,30,acco);
  216.   panel.mod_field.max_len(60);               // Max. 60 pos. for the string
  217.  
  218.   gotoyx(10,10); cprintf("Additional info: ");
  219.   panel.add_field(11,10,25,info);
  220.   panel.protect(BROWSE);
  221.  
  222.   panel.add_field(15,4,strlen(ok)+2,ok);
  223.   panel.mod_field.border(BORDER_SINGLE);       // A field with a border!
  224.   panel.mod_field.head("Exit");
  225.   panel.mod_field.border_color(panel.screen_color());
  226.   panel.protect(BROWSE);
  227.   panel.exit_field(TRUE);
  228.  
  229.   panel.exit_key(F10);
  230.  
  231.   panel.escape_off();
  232.  
  233.  
  234. /////////////////////// Browse through it //////////////////////////////
  235.  
  236.   panel.read();
  237.  
  238. /////////////////////// Removing panel /////////////////////////////////
  239.  
  240.   panel.remove();
  241.  
  242. /////////////////////// Do some explaining //////////////////////////
  243.   w1.clear();
  244.  
  245.  
  246.   w2.remove();
  247.   w2.head(" Data validation example ");
  248.   w2.set_dim(3,-1,20,60);
  249.   w2.activate();
  250.  
  251.   w2.clear();
  252.  
  253.   cprintf("\n\r");
  254.   cprintf("   The last panel gives an impression          \n\r");
  255.   cprintf("   of the capabilities concerning              \n\r");
  256.   cprintf("   data validation.                            \n\r");
  257.   cprintf("                                               \n\r");
  258.   cprintf("   For each supported type a field             \n\r");
  259.   cprintf("   is present.                                 \n\r");
  260.   cprintf("                                               \n\r");
  261.   cprintf("   You can't leave a field until               \n\r");
  262.   cprintf("   the edited string is considered             \n\r");
  263.   cprintf("   valid.                                      \n\r");
  264.   cprintf("                                               \n\r");
  265.   cprintf("   Leave the panel by pressing 'F10' or 'ESC'. \n\r");
  266.   cprintf("   'ESC' will exit the panel immediately,      \n\r");
  267.   cprintf("   even with invalid fields.                   \n\r");
  268.   cprintf("   See for yourself!                           \n\r");
  269.   cprintf("                                               \n\r");
  270.   cprintf("                Hit any key to continue. ");
  271.   cskey();
  272.   w2.remove();
  273.   w1.clear();
  274.  
  275.  
  276. /////////////////////// Variables for the panel ///////////////////
  277.  
  278.   char str[]="Some string.";
  279.   char ch='c';
  280.   int  in=123;
  281.   long lo=1234567890;
  282.   float fl=3.14159265358;
  283.   double df=1.1;
  284.   DATE date="22/03/1930";
  285.  
  286.  
  287.  
  288. ///////////////////////// PANEL DEFINITION /////////////////////
  289.  
  290.  
  291.   panel.set_dim(-1,-1,21,75);
  292.   panel.head(" Data Validation  ");
  293.   panel.border(BORDER_DOUBLE);
  294.   panel.activate();
  295.  
  296.   gotoyx(1,40); cprintf(" Min        Max        Picture");
  297.   gotoyx(2,40); cprintf("                     String");
  298.   gotoyx(3,40); cprintf("                             ");
  299.  
  300.   gotoyx(4,10); cprintf("String: ");
  301.   panel.add_field(4,20,15,str);
  302.   panel.mod_field.set_max("zyx");
  303.   panel.mod_field.set_min("Aaa");
  304.   gotoyx(4,40); cprintf("'AAA' < X < 'zyx'");
  305.  
  306.  
  307.  
  308.   gotoyx(6,10); cprintf("Character: ");
  309.   panel.add_field(6,20,1,ch);
  310.   panel.mod_field.set_max('z');
  311.   panel.mod_field.set_min('a');
  312.   gotoyx(6,40); cprintf("  'a' < X < 'z'");
  313.  
  314.  
  315.   gotoyx(8,10); cprintf("Integer: ");
  316.   panel.add_field(8,20,9,in);
  317.   panel.mod_field.picture("ooo");
  318.   panel.mod_field.set_max(399);
  319.   panel.mod_field.set_min(100);
  320.   gotoyx(8,40); cprintf("  100 < X < 399          ooo");
  321.  
  322.  
  323.  
  324.   gotoyx(10,10); cprintf("Long: ");
  325.   panel.add_field(10,20,18,lo);
  326.   panel.mod_field.set_min(10L);
  327.   gotoyx(10,40); cprintf("   10 < X");
  328.  
  329.  
  330.  
  331.   gotoyx(12,10); cprintf("Float: ");
  332.   panel.add_field(12,20,15,fl);
  333.   panel.mod_field.set_max(9e10);
  334.   panel.mod_field.set_min(1e-10);
  335.   gotoyx(12,40); cprintf("1e-10 < X < 9e10");
  336.  
  337.  
  338.  
  339.   gotoyx(14,10); cprintf("Double: ");
  340.   panel.add_field(14,20,25,df);
  341.   panel.mod_field.set_max(1e6);
  342.   panel.mod_field.picture("o.oo[0|e|E]o");
  343.   gotoyx(14,40); cprintf("        X < 1e6     o.oo[0|e|E]o");
  344.  
  345.  
  346.   gotoyx(16,10); cprintf("Date: ");
  347.   panel.add_field(16,20,date);
  348.  
  349.   DATE dm="31/12/1999";
  350.   DATE di="01/01/1900";
  351.   panel.mod_field.set_max(dm);
  352.   panel.mod_field.set_min(di);
  353.   gotoyx(16,35); cprintf("01/01/1900 < X < 31/12/1999" );
  354.   gotoyx(19,25); cprintf("Exit with ESC or F10");
  355.  
  356.  
  357.   panel.exit_key(F10);
  358.  
  359.  
  360. /////////////////////// Browse through it //////////////////////////////
  361.  
  362.   panel.read();
  363.  
  364. /////////////////////// removing panel /////////////////////////////////
  365.  
  366.  
  367.   panel.remove();
  368.   pan1.remove();
  369.  
  370.  
  371. }
  372.