home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 13.52 Demonstration of Windowing Functions
- Author: Joe Booth
- 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
- */
-
- //───── NOTE: must compile with the /N option!
-
- #include "box.ch"
-
- static wstack := {}
- memvar getlist // to squelch compiler warnings
-
- #define TOP wstack[len(wstack), 1]
- #define LEFT wstack[len(wstack), 2]
- #define BOTTOM wstack[len(wstack), 3]
- #define RIGHT wstack[len(wstack), 4]
- #define CONTENTS wstack[len(wstack), 5]
-
- #define TESTING // to compile test program -- remove at will
-
- // begin test program
-
- #ifdef TESTING
-
- /* user-defined command to allow familiar @..SAY / @..GET style syntax */
- #xcommand @ <r>, <c> WSAY <t> => WSay( <r>, <c>, <t> )
- #xcommand @ <r>, <c> WGET <v> [<list,...>] => ;
- @ WRow( <r> ), WCol( <c> ) get <v> [<list>]
-
- #include "inkey.ch"
- #include "fileio.ch"
- #define LOGFILE "change.log" // default name for log file
- #define CRLF chr(13)+chr(10) // self-explanatory
-
- function sugg_box
- local mwho := space(3), mdate := date(), mtime := time(), x
- local handle, mnotes := [], lines, oldcolor := setcolor()
- local oldf10
- local oldscore := set(_SET_SCOREBOARD, .F.) // shut off scoreboard
- WCreate(5, 20, 16, 60, "B+/W") // Display a window
- /* note that all of the following @ coordinates will be
- positioned relative to the active window! */
- @ 0, 2 wsay "Change Suggestions"
- @ 1, 1 wsay "Who :"
- @ 2, 1 wsay "Date:"
- @ 3, 1 wsay "Time:"
- @ 4, 1 wsay "Idea:"
-
- @ 1, 7 wget mwho picture "!!!"
- @ 2, 7 wget mdate
- @ 3, 7 wget mtime
- read
- if lastkey() <> K_ESC
- /* enable F10 to emulate Ctrl-W keypress -- see below */
- oldf10 := setkey(K_F10, { || quicksave() } )
- @ 11, 8 wsay "Press F10 to save notes"
- mnotes := memoedit(mnotes, WRow(4), WCol(7), WRow(10), WCol(38), .t.)
- if ! empty(mnotes)
- if file( LOGFILE )
- handle := fopen( LOGFILE, FO_READWRITE)
- /* move to end of file in order to append to it */
- fseek(handle, 0, FS_END)
- else
- handle := fcreate( LOGFILE, FC_NORMAL)
- endif
- Fwrite(handle, "WHO: " + mwho + " on " + dtoc(mdate) + ;
- " at " + mtime + CRLF, 34)
- lines := mlcount(mnotes, 50)
- for x = 1 to lines
- fwrite(handle, memoline(mnotes, 50, x), 50)
- next
- fwrite(handle, CRLF)
- fclose(handle)
- endif
- setkey(K_F10, oldf10)
- endif
- WKill()
- setcolor(oldcolor) // reset color
- set(_SET_SCOREBOARD, oldscore) // reset SCOREBOARD status
- return NIL
-
- static function quicksave
- keyboard chr(23)
- return nil
-
- #endif
-
- // end test program -- begin main windowing functions
-
-
- /* WCreate() - create and open active window */
- function WCreate(t, l, b, r, w_color)
- /* use current color setting if color was not passed */
- w_color := if(w_color = NIL, setcolor(), w_color)
- /* add this information to the window stack */
- aadd(wstack, { t, l, b, r, savescreen(t, l, b, r) } )
- setcolor(w_color)
- @ t, l, b, r box B_DOUBLE_SINGLE + ' '
- return NIL
-
-
- /* WKill() - close active window and remove from stack */
- function WKill
- /* make sure window stack is not empty */
- if ! empty(wstack)
- /* restore previous screen under this window */
- Restscreen( TOP, LEFT, BOTTOM, RIGHT, CONTENTS)
- /* truncate window stack */
- asize(wstack, len(wstack) - 1)
- endif
- return NIL
-
-
- /* WRow() - returns row relative to window */
- function WRow(_offrow)
- return if(empty(wstack), 0, TOP + _offrow)
-
-
- /* WCol() - returns column relative to window */
- function WCol(_offcol)
- return if(empty(wstack), 0, LEFT + _offcol)
-
- /* WClear() - clear contents of active window */
- function WClear
- if ! empty(wstack)
- scroll(TOP + 1, LEFT + 1, BOTTOM - 1, RIGHT - 1, 0)
- endif
- return NIL
-
-
- /* WSay() - @..SAY redirected to current window */
- function WSay(wrow, wcol, wtext)
- if ! empty(wstack)
- @ WRow(wrow), WCol(wcol) say wtext
- endif
- return NIL
-
-
- /* WPrompt() - @..PROMPT redirected to current window */
- function WPrompt(wrow, wcol, wtext)
- if ! empty(wstack)
- @ WRow(wrow), WCol(wcol) prompt wtext
- endif
- return NIL
-
- // end of file CHP1352.PRG
-