home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a054 / 1.img / GETLIB.EXE / GETCALC.PRG < prev    next >
Encoding:
Text File  |  1992-03-09  |  3.6 KB  |  149 lines

  1. // GetCalc.prg
  2. //
  3. // Get reader for calculator style input of numeric data
  4.  
  5. #include "Getexit.ch"
  6. #include "Inkey.ch"
  7.  
  8. proc GetCalc( oGet )
  9.  
  10.   // read the GET if the WHEN condition is satisfied
  11.   IF ( GetPreValidate(oGet) )
  12.     // activate the GET for reading
  13.     oGet:SetFocus()
  14.  
  15.     // RS added this 
  16.     // Start at last position
  17.     oGet:end()
  18.     // Just to here
  19.  
  20.     DO WHILE ( oGet:exitState == GE_NOEXIT )
  21.       // check for initial typeout (no editable positions)
  22.       IF ( oGet:typeOut )
  23.         oGet:exitState := GE_ENTER
  24.       ENDIF
  25.  
  26.       // apply keystrokes until exit
  27.       DO WHILE ( oGet:exitState == GE_NOEXIT )
  28.         GetCalcApplyKey(oGet, InKey(0))
  29.       ENDDO
  30.  
  31.       // disallow exit if the VALID condition is not satisfied
  32.       IF ( !GetPostValidate(oGet) )
  33.         oGet:exitState := GE_NOEXIT
  34.       ENDIF
  35.     ENDDO
  36.     // de-activate the GET
  37.     oGet:KillFocus()
  38.   ENDIF
  39.  
  40. RETURN
  41.  
  42.  
  43. /***
  44. * GetCalcApplyKey()
  45. * Apply a single Inkey() keystroke to a GET.
  46. *
  47. * NOTE: GET must have focus.
  48. * Standard stuff. RS changed only BS and otherwise
  49. */
  50.  
  51. #define K_UNDO          K_CTRL_U
  52.  
  53. proc GetCalcApplyKey(oGet, nKey)
  54.  
  55. local cKey
  56. local bKeyBlock
  57. local cTemp
  58. local nTemp
  59.  
  60.   // check for SET KEY first
  61.   IF (bKeyBlock := SetKey(nKey)) <> NIL
  62.     GetDoSetKey(bKeyBlock, oGet)
  63.     RETURN                              // NOTE
  64.   ENDIF
  65.  
  66.   DO CASE
  67.     CASE nKey == K_UP
  68.       oGet:exitState := GE_UP
  69.  
  70.     CASE nKey == K_SH_TAB
  71.       oGet:exitState := GE_UP
  72.  
  73.     CASE nKey == K_DOWN
  74.       oGet:exitState := GE_DOWN
  75.  
  76.     CASE nKey == K_TAB
  77.       oGet:exitState := GE_DOWN
  78.  
  79.     CASE nKey == K_ENTER
  80.       oGet:exitState := GE_ENTER
  81.  
  82.     CASE nKey == K_ESC
  83.       IF Set(_SET_ESCAPE)
  84.         oGet:undo()
  85.         oGet:exitState := GE_ESCAPE
  86.       ENDIF
  87.  
  88.     CASE nKey == K_PGUP
  89.       oGet:exitState := GE_WRITE
  90.  
  91.     CASE nKey == K_PGDN
  92.       oGet:exitState := GE_WRITE
  93.  
  94.     CASE nKey == K_CTRL_HOME
  95.       oGet:exitState := GE_TOP
  96.  
  97.     // both ^W and ^End terminate the READ (the default)
  98.     CASE nKey == K_CTRL_W
  99.       oGet:exitState := GE_WRITE
  100.  
  101.     CASE nKey == K_UNDO
  102.       oGet:Undo()
  103.  
  104.     CASE nKey == K_BS .OR. nKey == K_DEL
  105.       oGet:delete()
  106.       IF oGet:type == "C"
  107.         cTemp := oGet:unTransform()
  108.         cTemp := " " + Substr(cTemp, 1, Len(cTemp) - 1)
  109.         oGet:buffer := Transform(cTemp, oGet:picture)
  110.       ELSE
  111.         nTemp := oGet:unTransform()
  112.         IF At(".", oGet:buffer) != 0
  113.           // There is a decimal point
  114.           nTemp := nTemp / 10
  115.         ELSE
  116.           // No decimal point, division already taken place
  117.           // by deleting last character
  118.         ENDIF
  119.         oGet:buffer := Transform(nTemp, oGet:picture)
  120.       ENDIF
  121.       oGet:display()
  122.  
  123.     OTHERWISE
  124.       IF (nKey >= Asc('0') .AND. nKey <= Asc('9')) .OR. ;
  125.           (nKey == Asc('.') .AND. ;
  126.            oGet:type == "C" .AND. At(".", oGet:buffer) == 0)
  127.  
  128.         cKey := Chr(nKey)
  129.         IF oGet:type == "C"
  130.           cTemp := oGet:unTransform()
  131.           cTemp := SubStr(cTemp, 2) + " "
  132.           oGet:buffer := Transform(cTemp, oGet:picture)
  133.         ELSE
  134.           nTemp := oGet:unTransform()
  135.           nTemp := nTemp * 10
  136.           oGet:buffer := Transform(nTemp, oGet:picture)
  137.         ENDIF
  138.         // NOTE - important to use OverStrike here to set changed
  139.         // Alternative is to stuff key yourself. However, that does
  140.         // not set changed, therefore var is not updated.
  141.         oGet:overStrike(cKey)
  142.         oGet:end()
  143.         oGet:display()
  144.     ENDIF
  145.   ENDCASE
  146.  
  147. RETURN
  148.  
  149.