home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource1 / chint / useful09.hnt < prev    next >
Encoding:
Text File  |  1993-09-03  |  7.8 KB  |  220 lines

  1. (***************************************************************************
  2.   How to edit fields from the same file on different windows.
  3.  
  4.   This code enables the "PgDn" and "PgUp" keys so that they can be used to
  5.   switch to a different window containing more editable fields from the
  6.   current file.
  7.  
  8.   The "PgDn" and "PgUp" functionallity can be used either while at the menu
  9.   bar, or while editing/adding/copying the records.
  10.  
  11.   You may start the Edit/Add/Copy from any window with editable fields, you
  12.   do not have to start from the first window.
  13.  
  14.   When selecting Add or Copy the program will force the user to edit all
  15.   windows that contain editable fields for that file.  This ensures that
  16.   field validation will be conducted on all fields that are new to the
  17.   record.  When selecting Edit editing other that the current window is
  18.   optional.
  19.  
  20.   1) Copy DBC.SKL to MSCRS.SKL         (MultiSCReenS skeleton)
  21.  
  22.      i) Modify the edit_rec() procedure so that it looks like this :--
  23.  
  24. void edit_rec(int fld)
  25. {
  26.     edthook = tandk;
  27.  
  28.   reDisplayAll();                                            /**/
  29.   resetBeenIn();                                             /**/
  30.   do {                                                       /**/
  31.  
  32.     ⁿIFDEF TABLESⁿ
  33.       ⁿMODNAMEⁿ_edt(filno,fld,tabidx[filno] - 1);
  34.     ⁿELSEDEFⁿ
  35.       ⁿMODNAMEⁿ_edt(filno,fld,0);
  36.     ⁿENDDEFⁿ
  37.     switchScreen(exitcode);                                  /**/
  38.     if ((exitcode == XeptKey) &&                             /**/
  39.           goThruAll && !beenInAll()) {                         /**/
  40.       dberrm(Msg_GoThroughAll);                              /**/
  41.       exitcode = Nul;                                        /**/
  42.     }                                                        /**/
  43.   } while ((exitcode != XeptKey) && (exitcode != QitKey));   /**/
  44.  
  45.     edthook = NULL;
  46. }
  47.  
  48.      ii) Modify the edit_record() function, just before the call to
  49.          "edit_rec(0)" you add the line "goThruAll = False;" which will
  50.          allow the user to edit only the fields on the current window,
  51.          set "goThruAll = True;" if you want to force the operator to go
  52.          through all windows that have editable fields if the current file.
  53.          ie :--
  54.  
  55.            goThruAll = False;   /**/
  56.            edit_rec(0);
  57.            changedkey = False;
  58.  
  59.      iii) Modify the add_record() function, just before the call to
  60.           "edit_rec(0)" you add the line "goThruAll = True;"  This
  61.           will force the operator to edit go through all the windows that
  62.           contain editable fields of the current file.  ie :--
  63.  
  64.            {}  goThruAll = True;
  65.                edit_rec(0);
  66.                if (exitcode != QitKey) {
  67.  
  68. 2     iv)  At the end of the function "do_proc()" add a call to
  69.           "reDisplayAll".  This call will ensure that each window has its
  70.           contents re-displayed when using processes like Next, Prev, Add
  71.           and Copy. ie :--
  72.  
  73.             } /* switch procno */
  74.             reDisplayAll();    /**/
  75.           }
  76.  
  77.      v)  In the procedure "do_menu()" add a clause to the sitch statement to
  78.           deal with the "PgDn" and "PgDn" keys when pressed while at the
  79.           menu.  ie :--
  80.  
  81.              /**/      case PgUp :
  82.              /**/      case PgDn : switchScreen(ctlkey);  break;
  83.                        case UArr : goud(&dm,Up);    break;
  84.                        case DArr : goud(&dm,Down);  break;
  85.  
  86.  
  87.   2) Copy DBCINC.SKL to MSCRSINC.SKL   (MultiSCReenS INClude skeleton)
  88.      6 to 8 lines from the bottom of the function ⁿMODNAMEⁿ_edt() add a new
  89.      line to allow "PgDn" and "PgUp" to leave the editing loop ie.:--
  90.  
  91.       if (exitcode == PgDn)       edt.bypass   = True; /**/
  92.       if (exitcode == PgUp)       edt.bypass   = True; /**/
  93.       if (exitcode == XeptKey)    edt.bypass   = True;
  94.       if (exitcode == QitKey)     edt.finished = True;
  95.  
  96.   3) When defining your database put editable fields from the same file
  97.      into different windows.  Also use the "Include" menu option from the
  98.      "Fields/More/More" menu and add a new function file name to the list.
  99.      If your database applicatin is called TEST then you could add a file
  100.      called ZTEST.FUN.
  101.  
  102.   5) Create the ZTEST.FUN function include file with the following code:--
  103.  
  104. uchar Msg_GoThroughAll[] = "Please use PgUp and PgDn to traverse all screens !";
  105.  
  106.   byte switchNextScr[17][17] =
  107.   /* Each line represents the possible screens to "PgDn" to for the
  108.      correspond file.  The way this one is set up simply means that
  109.      if you are editing file 1 then pressing PgDn when in window 1 will
  110.      take you to window 2.
  111.   */
  112.    {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  113.     {0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  114.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  115.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  116.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  117.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  118.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  119.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  120.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  121.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  122.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  123.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  124.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  125.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  126.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  127.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  128.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
  129.  
  130.   byte switchPrevScr[17][17] =
  131.   /* Each line represents the possible screens to "PgUp" to for the
  132.      correspond file.  The way this one is set up simply means that
  133.      if you are editing file 1 then pressing PgUp when in window 2 will
  134.      take you to window 1.
  135.   */
  136.    {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  137.     {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  138.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  139.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  140.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  141.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  142.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  143.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  144.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  145.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  146.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  147.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  148.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  149.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  150.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  151.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  152.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
  153.  
  154. bool goThruAll;
  155. bool beenInScreen[17];
  156.  
  157. void resetBeenIn(void)
  158. {
  159.   int i;
  160.  
  161.   for (i = 1; i<=16; i++) beenInScreen[i] = False;
  162.   beenInScreen[scrno] = True;
  163. }
  164.  
  165. bool beenInAll(void)
  166. {
  167.   int i;
  168.   bool tb;
  169.  
  170.   tb = True;
  171.   for (i = 1; i <= 16; i++) {
  172.     if (switchNextScr[filno][i] != 0)
  173.       tb = tb && beenInScreen[switchNextScr[filno][i]];
  174.     if (switchPrevScr[filno][i] != 0)
  175.       tb = tb && beenInScreen[switchPrevScr[filno][i]];
  176.   }
  177.   return(tb);
  178. }
  179.  
  180. void reDisplayAll(void)
  181. {
  182.   int i;
  183.   bool savDispState[17];
  184.  
  185.   for (i = 1; i <= 16; i++) {
  186.     if (switchPrevScr[filno][i] != 0) {
  187.       savDispState[i] = (uw.wa[switchPrevScr[filno][i]])->disp;
  188.       (uw.wa[switchPrevScr[filno][i]])->disp = False;
  189.     }
  190.   }
  191.  
  192.   for (i = 1; i <= 16; i++) {
  193.     if (switchPrevScr[filno][i] != 0)
  194.       displayrec(filno,switchPrevScr[filno][i]);
  195.   }
  196.  
  197.   for (i = 1; i <= 16; i++) {
  198.     if (switchPrevScr[filno][i] != 0)
  199.       if (savDispState[i]) hidewin(T_ON,uw.wa[switchPrevScr[filno][i]]);
  200.   }
  201. }
  202.  
  203. void switchScreen(uchar inKey)
  204. {
  205.   switch(inKey) {
  206.     case PgDn : if (switchNextScr[filno][scrno] != 0) {
  207.       scrno = switchNextScr[filno][scrno];
  208.       hidewin(T_ON,uw.wa[scrno]);
  209.       displayrec(filno,scrno);
  210.       beenInScreen[scrno] = True;
  211.     } break;
  212.     case PgUp : if (switchPrevScr[filno][scrno] != 0) {
  213.       hidewin(T_OFF,uw.wa[scrno]);
  214.       scrno = switchPrevScr[filno][scrno];
  215.       displayrec(filno,scrno);
  216.       beenInScreen[scrno] = True;
  217.     } break;
  218.   }
  219. }
  220.