home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP25.EXE / CHP2508.PRG < prev    next >
Encoding:
Text File  |  1991-06-12  |  3.6 KB  |  129 lines

  1. /*
  2.    Listing 25.8. EditCell(), a general-purpose browse cell
  3.                  editing function.
  4.    Author: Craig Yellick
  5.    Excerpted from "Clipper 5: A Developer's Guide"
  6.    Copyright (c) 1991 M&T Books
  7.                       501 Galveston Drive
  8.                       Redwood City, CA 94063-4728
  9.                       (415) 366-3600
  10. */
  11.  
  12. #include "inkey.ch"
  13.  
  14. #define K_SPACE      32
  15. #define K_CTRL_ENTER 10
  16.  
  17. function EditCell(b, fieldName, editColor)
  18. /*
  19.    General-purpose browse cell editing function, can handle all
  20.    database field types including memo fields. If you want the
  21.    edits to "stick" you must assign fieldblock()-style
  22.    column:block instance variables. All editing, including
  23.    memo-edit, is done within the boundaries of the browse window.
  24.    On exit any appropriate browse cursor navigation messages are
  25.    passed along. Note: In order to browse a memo field the column
  26.    heading must be defined. This function uses the heading to
  27.    display a message.
  28. */
  29. local c, k, clr, crs, rex, block, cell
  30.  
  31.  
  32.   //  Retrieve the column object for the current cell.
  33.   c := b:getColumn(b:colPos)
  34.  
  35.  
  36.   //  Create a field block used to check for a memo field
  37.   //  and later used to store the edited memo back. It's
  38.   //  done this way so you can have the browse window display
  39.   //  a notation like "memo" rather than displaying a small
  40.   //  hunk of the real memo field.
  41.   //
  42.   block := fieldblock(fieldName)
  43.  
  44.  
  45.   //  Can't just "get" a memo, need a memo-edit.
  46.   if valtype(eval(block)) = "M"
  47.  
  48.     //  Tell the user what's going on.
  49.     @ b:nTop, b:nLeft clear to b:nBottom, b:nRight
  50.     @ b:nTop, b:nLeft say ;
  51.       padc("Memo Edit: Record " +lstr(recno()) ;
  52.           +', "'+ c:heading +'" Field', b:nRight -b:nLeft)
  53.     @ row() +1, b:nLeft say replicate("-", b:nRight -b:nLeft +1)
  54.  
  55.  
  56.     //  Turn cursor on and perform the memo edit
  57.     //  using the specified color.
  58.     crs := setcursor(1)
  59.     clr := setcolor(editColor)
  60.     cell := memoedit(eval(block), b:nTop +2, b:nLeft,;
  61.                                   b:nBottom, b:nRight)
  62.     setcursor(crs)
  63.     setcolor(clr)
  64.  
  65.  
  66.     //  If they didn't abandon the edit, save changes.
  67.     //  When passed a parameter, fieldblock-style code
  68.     //  blocks store the value back to the database.
  69.     //  Handiest darn thing they ever stuck in this language.
  70.     if lastkey() <> K_ESC
  71.       eval(block, cell)
  72.     endif
  73.  
  74.  
  75.     //  We mussed up the entire window, tell TBrowse to
  76.     //  clean it up.
  77.     b:configure()
  78.  
  79.  
  80.   //  Regular data type, do a GET/READ.
  81.   else
  82.  
  83.     //  Pass along any additional keystrokes.
  84.     if lastkey() = K_CTRL_ENTER
  85.       keyboard(chr(K_CTRL_Y))
  86.     elseif (lastkey() > K_SPACE) .and. (lastkey() < 256)
  87.       keyboard(chr(lastkey()))
  88.     endif
  89.  
  90.  
  91.     //  Create a get object for the field.
  92.     cell := getnew(row(), col(), ;
  93.                    c:block, fieldName,, "W/N,"+editColor)
  94.  
  95.     //  Allow up/down to exit the read, and turn the cursor off.
  96.     rex := readexit(.t.)
  97.     crs := setcursor(1)
  98.  
  99.     //  Perform the read.
  100.     readmodal({cell})
  101.  
  102.     //  Restore original cursor and read-exit states.
  103.     setcursor(crs)
  104.     readexit(rex)
  105.  
  106.  
  107.     //  If user hit a navigation key to exit, do it.
  108.     if Navigate(b, lastkey())
  109.  
  110.     //  If they pressed Enter, advance to next column.
  111.     elseif lastkey() = K_ENTER
  112.       if b:colPos < b:colCount
  113.         b:right()
  114.       else
  115.         b:down()
  116.         b:colPos := b:freeze +1
  117.       endif
  118.     endif
  119.  
  120.  
  121.     //  We changed the field value and TBrowse doesn't know it.
  122.     //  So we must force a re-read for the current row.
  123.     b:refreshCurrent()
  124.   endif
  125.  
  126. return nil
  127.  
  128. // end of file CHP2508.PRG
  129.