home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / atedit.zip / ATEDIT.PRG < prev    next >
Text File  |  1993-06-02  |  7KB  |  224 lines

  1. //.............................................................................
  2. //
  3. //   Program Name: ATEDIT.PRG        Copyright: Asta Engineering, Inc.
  4. //   Date Created: 04/30/92           Language: Clipper 5.0
  5. //   Time Created: 12:16:39             Author: John C. Burkhard
  6. //
  7. //.............................................................................
  8. // Revision: 1.01 Last Revised: 05/21/93 at 15:07:26
  9. // Description: Stand-alone version
  10. //
  11. // Removed all references to the window library to make it a stand-alone
  12. // UDC.
  13. //.............................................................................
  14.  
  15. //
  16. // Known anomalies:
  17. //
  18. // Checking LastKey() will return innacurate results.  To exit from
  19. // MemoEdit() we must stuff a K_CTRL_END into the keyboard, since MemoEdit()
  20. // seems to ignore any return values during idle states.  For this reason,
  21. // if you use the @..EDIT command in your program, don't count on LastKey()
  22. // accurately reporting the last key press!
  23. //
  24. // At some point in the future, CA will have to address this behavior or
  25. // someone will have to release a replacement MemoEdit() which is more like
  26. // TBrowse().  MemoEdit() is a hold over from the 'bad' old days and should
  27. // have been disposed of a long time ago.
  28. //
  29. // Better yet would be a get system which uses something a little more 
  30. // sophisticated than LastKey() and Updated() to return the exit state.
  31. //
  32.  
  33.  
  34. #include "inkey.ch"
  35. #include "getexit.ch"
  36. #include "memoedit.ch"
  37.  
  38. #define TAB_SIZE 5
  39.  
  40. #define ExitState( x ) sExitState := x ;
  41.    ; keyboard chr( K_CTRL_END ) ;
  42.    ; lSoftExit := .T.
  43.  
  44.  
  45. static sExitState := nil                         // for passing the exit state back to our get object
  46. static sMaxLines := 0                            // for telling our memoedit() UDF how many lines in window
  47. static sScrollable := .T.                        // for telling our memoedit() UDF if window is scrollable
  48.  
  49.  
  50. /*
  51. ** __editdisp( ) - display the contents of the edit window for an @...edit
  52. */
  53.  
  54. function __editdisp( cBuf, nTop, nLeft, nBottom, nRight, lScrollable, cColor )
  55.    local nWidth
  56.    local nLines
  57.    local nI
  58.    local cOldCol
  59.    local cLine
  60.    local GetList := { }
  61.  
  62.    nWidth := nRight - nLeft + 1
  63.    nLines := nBottom - nTop + 1
  64.    if ( empty( cColor ) )
  65.       for nI := 1 to nLines
  66.          cLine := memoline( cBuf, nWidth, nI, TAB_SIZE, .T. )
  67.          @ nTop + nI - 1, nLeft get cLine
  68.       next
  69.    else
  70.       for nI := 1 to nLines
  71.          cLine := memoline( cBuf, nWidth, nI, TAB_SIZE, .T. )
  72.          @ nTop + nI - 1, nLeft get cLine color cColor
  73.       next
  74.    endif
  75.  
  76. return nil
  77.  
  78.  
  79.  
  80. /*
  81. ** __editread( ) - reader function for @...edit command
  82. */
  83.  
  84. function __editread( oGet, nTop, nLeft, nBottom, nRight, lScrollable )
  85.    local nWidth
  86.    local nLines
  87.    local nCurLin
  88.    local cOldCol
  89.    local cBuffer
  90.  
  91.    if ( oGet:preblock != nil .and. !eval( oGet:preblock ) )
  92.       oGet:exitstate := GE_WHEN
  93.    else
  94.       sScrollable := iif( lScrollable == nil, .T., lScrollable )
  95.       cOldCol := SetColor( oGet:colorSpec )
  96.       nWidth := nRight - nLeft + 1
  97.       nLines := nBottom - nTop + 1
  98.       sMaxLines := nLines
  99.       cbuffer := eval( oGet:block )
  100.       cBuffer := memoedit( cBuffer, nTop, nLeft, nBottom, nRight, ;
  101.          .T.,;                                   // edit mode
  102.          "__editmemo",;                          // reader function
  103.          nWidth, ;
  104.          TAB_SIZE, ;
  105.          0, 0, 0, 0 )
  106.       if ( sExitState != GE_ESCAPE )
  107.          if ( sExitState == GE_DOWN .or. ( sExitState == GE_WRITE .and. !lScrollable ) )
  108.             __editdisp( cBuffer, nTop, nLeft, nBottom, nRight )
  109.          endif
  110.          eval( oGet:block, cBuffer )
  111.       endif
  112.  
  113.       oGet:exitstate := sExitState
  114.       setcolor( cOldCol )
  115.    endif
  116.  
  117. return nil
  118.  
  119.  
  120.  
  121. /*
  122. ** __editmemo( ) - memoedit() user function
  123. */
  124.  
  125. function __editmemo( nMode, nLine, nColumn )
  126.    local nRetVal
  127.    local nKey
  128.    static nLastLine
  129.    static lSoftExit
  130.  
  131.    nKey := LastKey()
  132.  
  133.    do case
  134.       case !sScrollable
  135.          do case
  136.             case nMode == ME_INIT
  137.                nLastLine := 1
  138.                lSoftExit := .F.
  139.                nRetVal := 0
  140.                keyboard chr(0)
  141.             case nMode == ME_UNKEY .or. nMode == ME_UNKEYX
  142.                nRetVal := ME_DEFAULT
  143.                do case
  144.                   case nKey == K_ESC
  145.                      sExitState := GE_ESCAPE
  146.                      nRetVal := K_ESC
  147.                   case nKey == K_CTRL_END .and. !lSoftExit
  148.                      sExitState := GE_WRITE
  149.                      nRetVal := K_CTRL_END
  150.                   case nKey == K_CTRL_END .and. lSoftExit
  151.                      nRetVal := K_CTRL_END
  152.                endcase
  153.  
  154.             case nMode == ME_IDLE
  155.  
  156.                //
  157.                // ExitState() stuffs the keyboard with a K_CTRL_END
  158.                // to force MemoEdit() to exit.  Values returned from
  159.                // idle states seem to be ignored by MemoEdit().  For
  160.                // this reason, if you use the @..EDIT command in your
  161.                // program, you can't rely on LastKey() to accurately
  162.                // report the last key pressed!
  163.                //
  164.  
  165.                do case
  166.                   case nKey == K_PGDN
  167.                      ExitState( GE_WRITE )
  168.  
  169.                   case nKey == K_PGUP
  170.                      ExitState( GE_WRITE )
  171.  
  172.                   case nKey == K_DOWN .and. nLastLine >= sMaxLines
  173.                      ExitState( GE_DOWN )
  174.  
  175.                   case nKey == K_UP .and. nLastLine == 1
  176.                      ExitState( GE_UP )
  177.  
  178.                   case nKey == K_ENTER .and. nLastLine >= sMaxLines
  179.                      ExitState( GE_DOWN )
  180.  
  181.                   case nLine > sMaxLines
  182.                      ExitState( GE_DOWN )
  183.  
  184.                   case nKey == K_CTRL_END
  185.                      ExitState( GE_WRITE )
  186.                endcase
  187.  
  188.                nLastLine := nLine
  189.  
  190.          endcase
  191.  
  192.       case sScrollable
  193.          do case
  194.             case nMode == ME_INIT
  195.                nLastLine := 1
  196.                lSoftExit := .F.
  197.                nRetVal := 0
  198.                keyboard chr(0)
  199.  
  200.             case nMode == ME_UNKEY .or. nMode == ME_UNKEYX
  201.                nRetVal := ME_DEFAULT
  202.                do case
  203.                   case nKey == K_ESC
  204.                      sExitState := GE_ESCAPE
  205.                      nRetVal := K_ESC
  206.                   case nKey == K_CTRL_END .and. lSoftExit
  207.                      sExitState := GE_WRITE
  208.                      nRetVal := K_CTRL_END
  209.                   case nKey == K_CTRL_W
  210.                      sExitState := GE_WRITE
  211.                      nRetVal := K_CTRL_END
  212.                   case nKey == K_CTRL_Q
  213.                      sExitState := GE_ESCAPE
  214.                      nRetVal := K_ESC
  215.                endcase
  216.  
  217.             case nMode == ME_IDLE
  218.                // do nothing...
  219.  
  220.          endcase
  221.    endcase
  222.  
  223. return nRetVal
  224.