home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 25.8. EditCell(), a general-purpose browse cell
- editing function.
- Author: Craig Yellick
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
- #include "inkey.ch"
-
- #define K_SPACE 32
- #define K_CTRL_ENTER 10
-
- function EditCell(b, fieldName, editColor)
- /*
- General-purpose browse cell editing function, can handle all
- database field types including memo fields. If you want the
- edits to "stick" you must assign fieldblock()-style
- column:block instance variables. All editing, including
- memo-edit, is done within the boundaries of the browse window.
- On exit any appropriate browse cursor navigation messages are
- passed along. Note: In order to browse a memo field the column
- heading must be defined. This function uses the heading to
- display a message.
- */
- local c, k, clr, crs, rex, block, cell
-
-
- // Retrieve the column object for the current cell.
- c := b:getColumn(b:colPos)
-
-
- // Create a field block used to check for a memo field
- // and later used to store the edited memo back. It's
- // done this way so you can have the browse window display
- // a notation like "memo" rather than displaying a small
- // hunk of the real memo field.
- //
- block := fieldblock(fieldName)
-
-
- // Can't just "get" a memo, need a memo-edit.
- if valtype(eval(block)) = "M"
-
- // Tell the user what's going on.
- @ b:nTop, b:nLeft clear to b:nBottom, b:nRight
- @ b:nTop, b:nLeft say ;
- padc("Memo Edit: Record " +lstr(recno()) ;
- +', "'+ c:heading +'" Field', b:nRight -b:nLeft)
- @ row() +1, b:nLeft say replicate("-", b:nRight -b:nLeft +1)
-
-
- // Turn cursor on and perform the memo edit
- // using the specified color.
- crs := setcursor(1)
- clr := setcolor(editColor)
- cell := memoedit(eval(block), b:nTop +2, b:nLeft,;
- b:nBottom, b:nRight)
- setcursor(crs)
- setcolor(clr)
-
-
- // If they didn't abandon the edit, save changes.
- // When passed a parameter, fieldblock-style code
- // blocks store the value back to the database.
- // Handiest darn thing they ever stuck in this language.
- if lastkey() <> K_ESC
- eval(block, cell)
- endif
-
-
- // We mussed up the entire window, tell TBrowse to
- // clean it up.
- b:configure()
-
-
- // Regular data type, do a GET/READ.
- else
-
- // Pass along any additional keystrokes.
- if lastkey() = K_CTRL_ENTER
- keyboard(chr(K_CTRL_Y))
- elseif (lastkey() > K_SPACE) .and. (lastkey() < 256)
- keyboard(chr(lastkey()))
- endif
-
-
- // Create a get object for the field.
- cell := getnew(row(), col(), ;
- c:block, fieldName,, "W/N,"+editColor)
-
- // Allow up/down to exit the read, and turn the cursor off.
- rex := readexit(.t.)
- crs := setcursor(1)
-
- // Perform the read.
- readmodal({cell})
-
- // Restore original cursor and read-exit states.
- setcursor(crs)
- readexit(rex)
-
-
- // If user hit a navigation key to exit, do it.
- if Navigate(b, lastkey())
-
- // If they pressed Enter, advance to next column.
- elseif lastkey() = K_ENTER
- if b:colPos < b:colCount
- b:right()
- else
- b:down()
- b:colPos := b:freeze +1
- endif
- endif
-
-
- // We changed the field value and TBrowse doesn't know it.
- // So we must force a re-read for the current row.
- b:refreshCurrent()
- endif
-
- return nil
-
- // end of file CHP2508.PRG
-