home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / cforms / part01 / example / test.frm < prev   
Encoding:
Text File  |  1992-05-18  |  4.5 KB  |  156 lines

  1. /*
  2.  * Test application for CForms.
  3.  * $Log:    test.frm,v $
  4. Revision 1.1  92/01/19  12:42:55  lasse
  5. Initial revision
  6.  
  7.  */
  8.  
  9. CCode {
  10.     #include <stdio.h>
  11.     main()
  12.     {
  13.         if (cforms_init() != OK) {
  14.             fprintf(stderr, "Failed to start cforms\n");
  15.             exit(1);
  16.         }
  17.  
  18.         if (pic_call(picture("main"), NULL) != OK) {
  19.             fprintf(stderr, "No main picture\n");
  20.         }
  21.  
  22.         cforms_end();
  23.     }
  24. }
  25.  
  26. Viewport view {
  27.     Pos 0,0;
  28.     Size 80, 24;
  29. }
  30.  
  31. Event Key DOWN  { fld_move(fld_down(current.field));  }
  32. Event Key UP    { fld_move(fld_up(current.field));    }
  33. Event Key CR    { fld_move(fld_next(current.field)); }
  34. Event Key TAB   { fld_move(fld_next(current.field)); }
  35. Event Key HELP  { message("You're using CForms"); }
  36. Event Key F8    { pic_leave(); }
  37.  
  38. Picture Main Viewport View {
  39.     Event Entry     { fld_set(current.field, "X"); }
  40.     Event Exit      { fld_set(current.field, " "); }
  41.     Event Key LEFT  { fld_move(fld_left(current.field));  }
  42.     Event Key RIGHT { fld_move(fld_right(current.field)); }
  43.     Event Key F8 Forget;
  44.  
  45.     Event Key CR {
  46.     if (!picture(current.field->name)) {
  47.         message("Choise not available");
  48.     }
  49.     else pic_call(picture(current.field->name), NULL);
  50.     }
  51.  
  52.     Literal 25, 1, "M a i n   M e n u";    
  53.     Literal 25, 2, "-----------------";    
  54.  
  55.     Field List { Pos 10, 10; Type Char(1); Protected;
  56.     LValue "[";  RValue "] Adress book"; }
  57.  
  58.     Field Play    { Pos +0, +2; Type Char(1); Protected;
  59.     LValue "[";  RValue "] Play Game"; }
  60.  
  61.     Field Status  { Pos +0, +2; Type Char(1); Protected;
  62.     LValue "[";  RValue "] Status Report"; }
  63.  
  64.  
  65.     Field Reg     { Pos 40, 10; Type Char(1); Protected;
  66.     LValue "[";  RValue "] Registration"; }
  67.  
  68.  
  69.     Field Exit    {
  70.     Pos 10, 20; Type Char(1); Protected;  LValue "["; RValue "] Exit";
  71.     Event Key CR {
  72.         pic_leave();
  73.     }
  74.     }
  75. }
  76.  
  77. ccode {
  78.    int cur_row = 0;
  79. }
  80.  
  81. Picture Welcome Viewport View {
  82.  
  83.     Event Draw {
  84.     fld_set(field("name"), fld_get(field("list:name%d", cur_row)));
  85.     fld_set(field("adress"), fld_get(field("list:adress%d", cur_row)));
  86.     }
  87.  
  88.     Event Key F8 { pic_leave(); message("Canceled"); }
  89.  
  90.     Event Key F1 { 
  91.     fld_set(field("list:name%d", cur_row), fld_get(field("name")));
  92.     fld_set(field("list:adress%d", cur_row), fld_get(field("adress")));
  93.     message("Inserted");
  94.     pic_leave();
  95.     }
  96.  
  97.     Literal 25, 1,  "Person registration";
  98.     Literal +0, +1, "-------------------";
  99.  
  100.     Field name {
  101.     Pos 20, 5;
  102.     Type Char(20);
  103.     LValue "Name: ";
  104.     Uppercase;
  105.     }
  106.  
  107.     Field adress {
  108.     Pos 20, 7;
  109.     Type Char(20);
  110.     LValue "Adress: ";
  111.     Uppercase;
  112.     }
  113.  
  114.     Literal +0, +5, "(F1 - Update)    (F8 - Leave)";
  115. }
  116.  
  117. Picture List Viewport View
  118. {
  119.     Literal 25, 1,  "List of persons";
  120.     Literal +0, +1, "---------------";
  121.  
  122.     Event Key CR { pic_call(picture("welcome"), NULL); }
  123.  
  124.     Event Key DOWN {
  125.     if (cur_row < 9 && !fld_isempty(current.field)) {
  126.          fld_move(field("Name%d", ++cur_row));
  127.     }
  128.     }
  129.     Event Key UP   { if (cur_row > 0) fld_move(field("Name%d", --cur_row)); }
  130.     Event Key Left { return; }
  131.     Event Key Right { return; }
  132.  
  133.     Field Name0   { Pos 10, 5;   Type Char(20); LValue "["; Protected; }
  134.     Field Adress0 { Pos +20, +0; Type Char(20); RValue "]"; Protected; }
  135.     Field Name1   { Pos -20, +1; Type Char(20); LValue "["; Protected; }
  136.     Field Adress1 { Pos +20, +0; Type Char(20); RValue "]"; Protected; }
  137.     Field Name2   { Pos -20, +1; Type Char(20); LValue "["; Protected; }
  138.     Field Adress2 { Pos +20, +0; Type Char(20); RValue "]"; Protected; }
  139.     Field Name3   { Pos -20, +1; Type Char(20); LValue "["; Protected; }
  140.     Field Adress3 { Pos +20, +0; Type Char(20); RValue "]"; Protected; }
  141.     Field Name4   { Pos -20, +1; Type Char(20); LValue "["; Protected; }
  142.     Field Adress4 { Pos +20, +0; Type Char(20); RValue "]"; Protected; }
  143.     Field Name5   { Pos -20, +1; Type Char(20); LValue "["; Protected; }
  144.     Field Adress5 { Pos +20, +0; Type Char(20); RValue "]"; Protected; }
  145.     Field Name6   { Pos -20, +1; Type Char(20); LValue "["; Protected; }
  146.     Field Adress6 { Pos +20, +0; Type Char(20); RValue "]"; Protected; }
  147.     Field Name7   { Pos -20, +1; Type Char(20); LValue "["; Protected; }
  148.     Field Adress7 { Pos +20, +0; Type Char(20); RValue "]"; Protected; }
  149.     Field Name8   { Pos -20, +1; Type Char(20); LValue "["; Protected; }
  150.     Field Adress8 { Pos +20, +0; Type Char(20); RValue "]"; Protected; }
  151.     Field Name9   { Pos -20, +1; Type Char(20); LValue "["; Protected; }
  152.     Field Adress9 { Pos +20, +0; Type Char(20); RValue "]"; Protected; }
  153.  
  154.     Literal -20, +5, "(F8 - Leave)";
  155. }
  156.