home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / BASIC / GLIB14.ZIP / FED.DOC < prev    next >
Encoding:
Text File  |  1988-02-06  |  16.7 KB  |  357 lines

  1.  
  2.                                 Field Editor
  3.                             Keyboard Input Handler
  4.  
  5.                            (C) InfoSoft, 1987, 1988
  6.  
  7.  
  8.           I.       Introduction
  9.  
  10.         The care and use of FED can be a tad involved so it is documented
  11.      separate from the rest of GIZLIB.  This does not mean that it can or
  12.      may be distributed seperately from the rest of GIZLIB or FED.DOC.
  13.  
  14.         There are several (indeed many!) text input handlers around.  I
  15.      know, because I have, or have looked at many of them.  Many of them
  16.      require significant editing to work, or they are not modular, or they
  17.      require the event trapping switch, or they were inadeqaute in
  18.      functionality.  This is not to imply that FED is without its own
  19.      failings, but overall, it is very flexible.
  20.  
  21.           FED, which originally stood for Field EDitor, is modular.  It can
  22.      be called from the main code of another program very easily.
  23.  
  24.           As is, FED is very flexible in most every aspect.  You can change
  25.      most all of the operating parameters with the change of a flag or
  26.      two.
  27.  
  28.           Finally, FED does not require the use of any event trapping
  29.      switch, it identifies extended key codes on its own, like most any
  30.      text input routine should.
  31.  
  32.  
  33.  
  34.           II.          FED Files
  35.  
  36.        The key FED files are:
  37.      FED-DEMO.BAS  - The demo
  38.      EMP.DAT       - A random file of 7 or so records for the demo
  39.      CHGFLD.SUB    - The FCODE handler from FED-DEMO that can be easily
  40.                      modified for use in your program.
  41.  
  42.  
  43.         The demo is a pretty simple random file allowing you to edit the
  44.      various records in the file.  It is especially easy to use after
  45.      reviewing this documentation.  You are encouraged to read this
  46.      first so that as FED-DEMO executes, you can notice some of the key
  47.      features.
  48.  
  49.  
  50.  
  51.  
  52.         III.           FED Parameters, Syntax
  53.  
  54.           FED uses several switches and 3 arguments to control the flow
  55.      and text input.  The formal or direct parameters are:
  56.  
  57.      TEXT$ - The text string to edit.
  58.      FSIZ  - An integer telling FED the maximum length allowed for the
  59.              TEXT$, the current text to be edited.
  60.      FCODE - The exit code returned by FED to tell you HOW they completed
  61.              that field or what key was pressed to exit FED.
  62.  
  63.           You should understand that you can actually use any names that
  64.      suit you in a call to a SUB...STATIC / END SUB subroutine.  That is,
  65.      you could use ED$ instead of TEXT$, or T$, or whatever you want.  FED
  66.      will operate just as expected, as long as you pass them in the right
  67.      order.  The correct syntax:
  68.  
  69.      CALL fed(text$, fsiz%, fcode%)
  70.  
  71.           The importance of FSIZ is that FED will not allow input after that
  72.      maximum size is reached, and maybe beep (bleep actually).  FED does not
  73.      change FSIZ on the return, so be sure to reset it for each successive
  74.      call.
  75.  
  76.  
  77.  
  78.  
  79.           IV.        Incorporating FED to your code
  80.  
  81.         There are a few simple things to do to get FED running in your
  82.      program:
  83.  
  84.         FED works off of 3 formal arguments (covered above) and several
  85.      COMMON parameters shared with the main, calling program.  This
  86.      allows you to share some parameters with FED very easily such as
  87.      Foreground Color, upper casing etc.
  88.  
  89.         The actual use and meaning of these common parameters are covered
  90.      later, here we are explaining how to set up for FED to work in your
  91.      program.  This is done by simply including the following line in the
  92.      beginning of your main code:
  93.  
  94.    COMMON /fedvars/ fg%, bg%, fgd%, bgd%, bleep%, edt%, nums%, num$, upcase%
  95.  
  96.         The meaning and use of the variables will be covered later, but in
  97.      setting up FED for use, it is important that you list them EXACTLY as
  98.      shown, ie in the order shown, WITH the type declarations.  The first
  99.      four are foreground and background colors and the rest are listed
  100.      alphabetically.
  101.  
  102.  
  103.  
  104.         Note that such COMMON statements must appear in your code BEFORE
  105.      any executable statements.  If you are not familar with the use of
  106.      COMMON it is suggested that you review pp 228-232 of the QB3 manual.
  107.      Also refer to the FED-DEMO source for proper set up.  In implementing
  108.      the FED variables, we have opted to make several of them COMMON to
  109.      allow FED to read and literally share the value of these varibles
  110.      with your main program and at the same time, keeps you from having to
  111.      pass all of them as formal arguments to FED. That is, intead of:
  112.  
  113.      CALL fed(t$,fsiz,fcode, fg,bg, fgd,bgd, bleep, edt, nums,num$, upcase)
  114.      all we do is:
  115.      CALL fed(t$, fsiz, fcode)
  116.  
  117.         Additionally, a benefit of this is that the COMMON switches are
  118.      used or reset MUCH less often in use than say, the text$ would be; for
  119.      example, most likely, you would set the color switches once (fg, fgd,
  120.      bg and bgd), but text$ gets changed at almost every call.
  121.  
  122.         The only restriction in this is that unlike the formal arguments
  123.      passed in the parentheses, the COMMON /fedvars/ variabls _MUST_ use
  124.      the variable names shown.  That is, while t$ can be changed to text$
  125.      or fcode can be used as fed.return.code as you please, fg must be
  126.      referenced as fg, fgd as fgd, edt as edt, upcase as upcase etc etc.
  127.  
  128.         The use of a blockname (/fedvars/) prevents FED from interfering
  129.      with other COMMON or COMMON SHARED variables, more precisely, it allows
  130.      the USE of additional COMMON or COMMMON SHARED variables.  To name
  131.      additional variables as COMMON declare them like this:
  132.  
  133.      DEFINT a-z
  134.      COMMON /fedvars/ fg%, bg%, fgd%, bgd%, _
  135.               bleep, edt%, nums%, num$, upcase%       ' FED block defined
  136.  
  137.      COMMON SHARED /newblock/ arg1, arg2, arg3        ' different block
  138.  
  139.      COMMON SHARED  a,_                               ' "blank" block of
  140.                     b,_                               '   COMMON variables
  141.                     c,_
  142.                     z
  143.  
  144.         Note that /fedvars/ need not carry the SHARED attribute, but the use
  145.      of a blockname allows FED to share those variables that it needs and
  146.      ONLY those, ie a SIZE error is not encountered if you use other COMMON
  147.      variables.  This allows for maximum flexibility.
  148.  
  149.         Of the /fedvars/ variables, only edt, a more or less auxilliary
  150.      flag is altered by FED.
  151.  
  152.  
  153.  
  154.  
  155.           V.              Internal Editting Keys
  156.  
  157.  
  158.           Internally, FED does several things to provide a professional
  159.      "look" to its operation.  First, lets look at the editing fiunctions
  160.      and keys recognized:
  161.  
  162.      HOME     Places cursor at start of text or field.
  163.      END      Places cursor at first blank at end of the text.
  164.  
  165.  
  166.      Ctrl - End   Clear line from cursor to end of line.
  167.      Ctrl - X     Clear all text from current field.
  168.      Ctrl - U     Undoes current edit.  This does not restore the text to
  169.                   it's form in a disk text file, but restores the text to
  170.                   the form it was UPON ENTRY TO FED.  It cannot know what
  171.                   the text was or what form it was in PRIOR to the CALL.
  172.  
  173.  
  174.      Arrow Keys   Move one character Right or Left.  FED will not allow the
  175.                   user to Cursor right into the hatched area if that
  176.                   means that more than 1 space trails the text.  That is,
  177.                   via the the right arrow, it will not allow more than 2
  178.                   consecutive spaces, as in "J. DOE  " or "J Q  Public".
  179.                   Multiple spaces can be achieved via the insert key
  180.                   or space however.
  181.  
  182.  
  183.      Ctrl-Arrow   Moves one word right or left
  184.      Keys
  185.  
  186.      Ins         Insert works as expected, allowing text to be inserted at
  187.                  the cursor, and changes the cursor to a block.  The Insert
  188.                  state is toggled off upon exiting FED or "finishing" the
  189.                  field or text.
  190.  
  191.  
  192.      Del         As expected, deletes characters right of the cursor.
  193.  
  194.  
  195.        No key state flags (such as a [ INS ] or [ Caps ] indicator) are
  196.      put to the screen.  This was viewed as intrusive in that where FED
  197.      places the flag could be an unacceptable location in some applications,
  198.      and it seemed to not be in the interest of speed, to be painting and
  199.      repainting such indicators.
  200.  
  201.  
  202.  
  203.  
  204.  
  205.           VI.              FED Return Codes - FCODE
  206.  
  207.           This is the half of the meat of the program (The other half is
  208.      internal).  FCODE returns to you a value dependant on what key is
  209.      pressed to complete the editing of the text.
  210.  
  211.           Needless to say, FED has undergown several forms and formats since
  212.      I first started work on it.  The object of most changes has been to
  213.      make the FCODEs more intuitive.  The current state may not seem to be
  214.      as intuitive as they could be at first glance, but in keeping the dual
  215.      goals of ease of use AND flexibility, but the actual FCODE handler
  216.      (the routine called CHGFLD in FED-DEMO) can be "canned", or predone to
  217.      be incorporated into your program.
  218.  
  219.  
  220.                               FCODE Returns:
  221.  
  222.                              Enter   -    0
  223.               F1      -    1                 F8      -    8
  224.               F2      -    2                 F9      -    9
  225.               F3      -    3                F10      -   10
  226.               F4      -    4                PgUp     -   11
  227.            Up Arrow   -    5                PgDn     -   12
  228.            Dn Arrow   -    6              Ctrl-PgUp  -   13
  229.               F7      -    7              Ctrl-PgDn  -   14
  230.                              Escape  -    15
  231.  
  232.  
  233.           Note that not EVERY possible key is trapped or returned.  Most
  234.      notably, F5 and F6 are not trapped.   This is not because FED is lazy
  235.      or dumb, but simply to cut down on the number of FCODES you need to
  236.      handle (and handle whether your program uses or needs those codes or
  237.      not) and to leave 2 keys open for response to any standing ON KEY() key
  238.      traps your main program may need to have active at all times.
  239.  
  240.         I have used FED in several applications and more often than not, the
  241.      keys trapped as is, are MORE than enough to do the job.   If you look
  242.      at FED-DEMO you will see that it does quite a bit, in record paging,
  243.      abort and save keys, and still has 3 or 4 FCODEs unused. In the long
  244.      run, you should find that FED offers a suffient number of editting keys
  245.      and with the use of a pre-done CHGFLD routine, it should be easy to
  246.      handle the number of FCODES that it can return.
  247.  
  248.           Your distribution diskette or original archive should have a file
  249.      called CHGFLD.SUB that can be easily edited (add a few RETURN <label>'s
  250.      to it and paste it into your current code).  FED and CHGFLD together
  251.      should make text input and data entry applications very easy and
  252.      simple.  Throughout the demo, you can also note the integration of
  253.      different GIZLIB functions and how they complement FED.
  254.  
  255.  
  256.  
  257.  
  258.         VII.         Internal Handling, COMMON Parameters
  259.  
  260.          FED does a few things internally on its own and a few others you
  261.      control and change throughout the course of your program by resetting
  262.      the COMMON parameters.  If you are not familiar with SHARED parameters
  263.      you should refer to your QB manual.  These are not passed as formal
  264.      arguments inside the parentheses when the program is CALLed but are set
  265.      in your main program.
  266.  
  267.  
  268.        Using the value of FSIZ as the maximum length allowed, FED provides
  269.      hatching from the end of the actual text to that maximum length.
  270.      If a string is longer than FSIZ upon entry to FED, it is truncated to
  271.      the maximum length.
  272.      ( It is important to note that upon GETting a string from a random
  273.      file, QB pads the string with spaces from the end of the text for the
  274.      length of the FIELD.  That is, if you LSET "JOHN DOE" in a FIELD 15
  275.      characters long, after a GET, the name becomes "JOHN DOE       ".  If
  276.      you pass this as is to FED with a FSIZ of 15, no hatching will appear
  277.      because FED does not distinguish the spaces as blank text or
  278.      attempt to modify the string.  See STRIP in GIZLIB for QB3.)
  279.  
  280.      - FED also highlights the current text or data as well as providing
  281.      the hatching.  When the editing is completed, and one of the 15 FCODE
  282.      keys are hit to exit the field (actually FED is exitted, and control is
  283.      returned to you), the highlighting is turned off.  This color control
  284.      is handled thru the use of 2 sets of color codes: FG, BG and FGD and
  285.      BGD.  These must be assigned valid BASIC color codes in the course of
  286.      your main code.  At the start, FED uses the FGD, BGD (as in
  287.      ForeGround_Data, BackGround_Data) colors and upon exitting, redisplays
  288.      it in the FG, BG colors.  These only need to be set once.
  289.  
  290.      - Caps or uppercase input from the keyboard can be forced on the fly
  291.      (ie without a sepoarate call) via the UCASE switch.  Set UPCASE to 1
  292.      or non zero for caps, 0 for to allow either lower or upper case.
  293.      Note: Previous to GLIB 1.3, this parameter was named 'ucase', starting
  294.      with GLIB 1.3, this is renamed 'upcase' to aviod conflicting with
  295.      QB4's statement UCASE$.
  296.  
  297.  
  298.      - Numbers ONLY can be selected in the same manner with the switch
  299.      NUMS.  When this is set, only numberic input is allowed, so to allow
  300.      for a mixed string such as an address, NUMS should be OFF (nums=0).
  301.      Additionally, you can redefine allowable characters for different
  302.      entries via NUM$.  For example, in a phone number entry the characters
  303.      "()-" may be allowable beyond 0-9, but in a dollar based entry $ and
  304.      "." may be allowable.  So prior to the CALL for a phone entry NUM$
  305.      would be set to "1234567890()-", or ".1234567890$" for the dollar
  306.      based entry.  This method of defining the entire string rather than
  307.      just the extra ()-$ or . characters was chosen to allow category type
  308.      entries also.  That is, to force, say a gender selection of M or F,
  309.      set UPCASE to 1, NUMS to 1 and NUM$ to "MF".  If NUM$ is set to null,
  310.      (num$=""), it defaults to "1234567890".
  311.  
  312.  
  313.  
  314.      - If the text string upon exitting FED is different than it was at the
  315.      start of the CALL to fed, then EDT is set to non-zero.  This allows you
  316.      to test to see if field in a record has been altrered.  FED only sets
  317.      it to 1 never to 0.  Since FED is just handling the input for different
  318.      strings, it never knows when a set of fields equalling a full record is
  319.      completed.  The EDT is how FED tells you that something has indeed
  320.      been editted.
  321.      ( Using this flag, you can include code in the CHGFLD routine to flash
  322.      a message that an EDIT is in process, as is done in FED-DEMO.  It is
  323.      also useful in precluding certain functions if an edited record is not
  324.      saved.  An example of this is shown in FED-DEMO where paging is
  325.      disallowed if a record is edited and unsaved.
  326.  
  327.      -  The final COMMON parameter to cover is BLEEP, this is a switch to
  328.      indicate whether sound is to be on or off.  The sound is more of a
  329.      bleep than a beep.  If this switch is set on (non zero) it allows the
  330.      bleep sound effect to sound at various times:
  331.      - An attempt to cursor right when the string has reached FSIZ (maximum
  332.        length).
  333.      - An attempt to enter an invalid character (an alpha character when
  334.        nums is ON).
  335.      - When an inserted character will cause the text to exceed the maximum
  336.        length.
  337.      - Cursor left attempted left of first character position.
  338.      - If cursor right appends more than 1 successive blanks to the text.
  339.  
  340.        Regardless of the state of bleep, FED disregards any such illegal
  341.      activities.  BLEEP just adds an error sound to the process.  While the
  342.      error sound has it's uses, it is not recommended that it be on all the
  343.      time - there are time when it is inappropriate.  In such cases, (such
  344.      as in an office bullpen setting where such BLEEPING would be
  345.      annoying), set BLEEP yo 0.
  346.  
  347.         In summary, the COMMON switch (0 or 1) parameters are:
  348.      UPCASE    -   Convert alpha input to Uppercase
  349.      NUMS      -   Allow (numeric) input only from NUM$
  350.      NUM$      -   Character string filter of allowable input to be used
  351.                    if NUMS is not 0.
  352.      FGD, BGD  -   Foreground and Background colors to diplay the string in
  353.                    while that string is undergoing editing via FED.
  354.      FG, BG    -   Colors FED restores the string to upon exiting FED.
  355.      EDT       -   Flag set by FED to show if text is changed.
  356.      BLEEP     -   Switch to turn on or off BLEEPER error signal.
  357.