home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a067 / 1.img / GRUMP501.EXE / GKPROPER.PRG < prev    next >
Encoding:
Text File  |  1991-08-23  |  3.4 KB  |  121 lines

  1. /*
  2.     Function: GKeyProper()
  3.     Purpose:  Alternate for GetApplyKey() for proper-case data entry
  4.     Author:   Greg Lief
  5.     Copyright (c) 1991 Greg Lief
  6.     Dialect:  Clipper 5.01
  7. */
  8.  
  9. #include "inkey.ch"
  10. #include "getexit.ch"
  11.  
  12. /*
  13.   Whenever any characters in SEPARATORS are detected, the
  14.   next character entered will be forced to upper-case.  If
  15.   you want to use other characters, make the change here.
  16. */
  17. #define SEPARATORS  " -',."
  18. #xtranslate TestBuffer() => (substr(get:buffer, get:pos - 1, 1) $ SEPARATORS)
  19.  
  20. procedure gkeyproper(get, key)
  21. static forceupper := .t.
  22.  
  23. local cKey
  24. //───── check for SET KEY and basic movement keys
  25. if ! GKeyBasic(get, key)
  26.    do case
  27.       case (key == K_INS)
  28.          Set( _SET_INSERT, ! Set(_SET_INSERT) )
  29.          setcursor( if(set(_SET_INSERT), 3, 1) )
  30.  
  31.       case (key == K_CTRL_U)
  32.          get:Undo()
  33.          forceupper := .t.        // reset flag for next time
  34.  
  35.       case (key == K_HOME)
  36.          get:Home()
  37.          forceupper := .t.
  38.  
  39.       case (key == K_END)
  40.          get:End()
  41.          forceupper := .f.
  42.  
  43.       case (key == K_RIGHT)
  44.          get:Right()
  45.          forceupper := TestBuffer()
  46.  
  47.       case (key == K_LEFT)
  48.          get:Left()
  49.          //───── if we just backspaced to the start of a word or the string,
  50.          //───── we must reset the flag to force next character upper-case
  51.          forceupper := (get:pos==1 .or. TestBuffer())
  52.  
  53.       case (key == K_CTRL_RIGHT)
  54.          get:WordRight()
  55.          forceupper := .t.  // cause we are at the beginning of a word
  56.  
  57.       case (key == K_CTRL_LEFT)
  58.          get:WordLeft()
  59.          forceupper := .t.  // cause we are at the beginning of a word
  60.  
  61.       case (key == K_BS)
  62.          get:BackSpace()
  63.          /*
  64.             if we just backspaced to the start of a word, or
  65.             the start of the string, we must reset the flag to
  66.             force the next character to be upper-case
  67.          */
  68.          forceupper := (get:pos==1 .or. TestBuffer())
  69.  
  70.       case (key == K_DEL)
  71.          get:Delete()
  72.  
  73.       case (key == K_CTRL_T)
  74.          get:DelWordRight()
  75.  
  76.       case (key == K_CTRL_Y)
  77.          get:DelEnd()
  78.  
  79.       case (key == K_CTRL_BS)
  80.          get:DelWordLeft()
  81.          forceupper := .t.
  82.  
  83.       otherwise
  84.  
  85.          if (key >= 32 .and. key <= 255)
  86.             cKey := Chr(key)
  87.             if ckey $ SEPARATORS
  88.                forceupper := .t.  // next char will be uppercase
  89.             elseif key > 64
  90.                if forceupper
  91.                   /* if the next character should be upper but they
  92.                      entered an upper, switch case to lower: huh?
  93.                      this is so that someone could enter, say,
  94.                      "dBASE" (not that they'd really want to!)
  95.                   */
  96.                   if key < 91
  97.                      ckey := chr(key + 32)
  98.                   else   /* force upper-case if necessary */
  99.                      ckey := chr(key - 32)
  100.                   endif
  101.                   forceupper := .f.
  102.                endif
  103.             endif
  104.             if ( Set(_SET_INSERT) )
  105.                get:Insert(cKey)
  106.             else
  107.                get:Overstrike(cKey)
  108.             endif
  109.             if (get:typeOut .and. !Set(_SET_CONFIRM) )
  110.                if ( Set(_SET_BELL) )
  111.                   ?? Chr(7)
  112.                endif
  113.                get:exitState := GE_ENTER
  114.             endif
  115.          endif
  116.    endcase
  117. else
  118.    forceupper := .t.
  119. endif
  120. return
  121.