home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Database / CLIPR503.W96 / VALEDIT.PR_ / VALEDIT.PR
Text File  |  1995-06-20  |  4KB  |  180 lines

  1. /***
  2. *
  3. *  Valedit.prg
  4. *
  5. *  Copyright (c) 1993-1995, Computer Associates International Inc.
  6. *  All rights reserved.
  7. *
  8. *  NOTE: Compile with /a /m /n /w
  9. *
  10. */
  11.  
  12. #include "inkey.ch"
  13.  
  14.  
  15. /***
  16. *
  17. *  ValEdit( <nRow>, <nCol>, <xValue>, <[cPicture]>, <[cColor]> ) --> xNewValue
  18. *
  19. *  Uses a get object to edit value <xValue> at the screen location given
  20. *  by <nRow> and <nCol>. Uses picture <cPicture> and color <cColor> if
  21. *  passed.
  22. *
  23. *  Parameters:
  24. *     nRow     - Row at which to edit <xValue>
  25. *     nCol     - Column at which to edit <xValue>
  26. *     xValue   - The value to be edited
  27. *     cPicture - Optional picture clause for edit
  28. *     cColor   - Optional color specification for edit
  29. *
  30. *  Returns:
  31. *     The new (edited) value
  32. *
  33. *    Example usage:
  34. *
  35. *        // edits contents of myVar
  36. *        myVar := ValEdit( 10, 10, myVar )
  37. *
  38. *        // edits flashing Y/N (default N), assigns to myVar
  39. *        myVar := ValEdit( 10, 10, .F., "Y", "*W/R" )
  40. *
  41. *     // edits contents of a[i]
  42. *     a[i] := ValEdit( 10, 10, a[i] )
  43. *
  44. */
  45. FUNCTION ValEdit( nRow, nCol, xValue, cPicture, cColor )
  46.  
  47.    LOCAL ExitRequested     // User requested termination of exit
  48.    LOCAL nKey              // Current keypress
  49.    LOCAL cKey              // Character string representation of nKey
  50.    LOCAL lInsert := SET( _SET_INSERT )    // Current insert mode
  51.    LOCAL g       := GetNew( nRow, nCol,                                     ;
  52.                             { |p| IF( p == NIL, xValue, xValue := p ) }, "",;
  53.                             cPicture,                                       ;
  54.                             IF( cColor<>NIL , cColor + "," + cColor, NIL)   )
  55.  
  56.    g:setFocus()
  57.  
  58.    IF ( g:typeOut )        // No editable positions
  59.       ExitRequested := .T.
  60.    ELSE
  61.       ExitRequested := .F.
  62.    END
  63.  
  64.     //
  65.    // Keystroke processing loop
  66.     //
  67.    WHILE ( !ExitRequested )
  68.  
  69.       nKey := INKEY( 0 )
  70.  
  71.       // Key processing construct
  72.         do case
  73.         case (nKey == K_UP)
  74.             ExitRequested := .t.
  75.  
  76.         case (nKey == K_DOWN)
  77.             ExitRequested := .t.
  78.  
  79.         case (nKey == K_ESC)
  80.             g:Undo()
  81.             g:KillFocus()
  82.             RETURN (g:VarGet()) // NOTE
  83.  
  84.         case (nKey == K_PGUP)
  85.             ExitRequested := .t.
  86.  
  87.         case (nKey == K_PGDN)
  88.             ExitRequested := .t.
  89.  
  90.         case (nKey == K_CTRL_HOME)
  91.             ExitRequested := .t.
  92.  
  93.         case (nKey == K_CTRL_W)
  94.             ExitRequested := .t.
  95.  
  96.         case (nKey == K_ENTER)
  97.             ExitRequested := .t.
  98.  
  99.         case (nKEY == K_CTRL_U)
  100.             g:Undo()
  101.  
  102.         case (nKey == K_INS)
  103.             lInsert := !lInsert
  104.  
  105.         case (nKey == K_HOME)
  106.             g:Home()
  107.  
  108.         case (nKey == K_END)
  109.             g:End()
  110.  
  111.         case (nKey == K_RIGHT)
  112.             g:Right()
  113.  
  114.         case (nKey == K_LEFT)
  115.             g:Left()
  116.  
  117.         case (nKey == K_CTRL_RIGHT)
  118.             g:WordRight()
  119.  
  120.         case (nKey == K_CTRL_LEFT)
  121.             g:WordLeft()
  122.  
  123.         case (nKey == K_BS)
  124.             g:BackSpace()
  125.  
  126.         case (nKey == K_DEL)
  127.             g:Delete()
  128.  
  129.         case (nKey == K_CTRL_T)
  130.             g:DelWordRight()
  131.  
  132.         case (nKey == K_CTRL_Y)
  133.             g:DelEnd()
  134.  
  135.         otherwise
  136.             if (nKey >= 32 .and. nKey <= 127)
  137.                 // data key
  138.                 cKey := Chr(nKey)
  139.  
  140.                 if (g:Type == "N" .and. ;
  141.                     (cKey == "." .or. cKey == ","))
  142.                     // go to decimal point
  143.                     g:ToDecPos()
  144.                 else
  145.                     // send it to the get
  146.                     if ( Set(_SET_INSERT) )
  147.                         g:Insert(cKey)
  148.                     else
  149.                         g:Overstrike(cKey)
  150.                     end
  151.                 end
  152.  
  153.  
  154. #ifdef NOTDEF
  155.                 if (g:TypeOut)
  156.                     // exit get without confirm
  157.                     ExitRequested := .t.
  158.                 end
  159. #endif
  160.  
  161.             end
  162.  
  163.         endcase
  164.  
  165.     //
  166.     //    end of keystroke processing loop
  167.     //
  168.     end
  169.  
  170.     if (g:Changed)
  171.         g:Assign()
  172.     end
  173.  
  174.     g:Reset()
  175.     g:KillFocus()
  176.  
  177.     // return final value
  178.     RETURN (g:VarGet())
  179.  
  180.