home *** CD-ROM | disk | FTP | other *** search
- /*
- Program: BOXGET()
- System: GRUMPFISH LIBRARY
- Author: Greg Lief
- Copyright (c) 1988-91, Greg Lief
- Compile instructions: clipper boxget /n/w/a
- Generic GET function
- */
-
- //───── begin preprocessor directives
-
- #include "box.ch"
- #include "grump.ch"
- #include "setcurs.ch"
- #include "inkey.ch"
-
- //───── end preprocessor directives
-
- //───── begin global declarations
-
- #define DELIMITERPAD if(set(_SET_DELIMITERS), 2, 0)
- #define TOP nrow
- #define LEFT ncol
- #define BOTTOM nrow + 2
- #define RIGHT ncol + len(cprompt) + 4 + getlength + DELIMITERPAD
-
- //───── end global declarations
-
- // the following stub program demonstrates how to use this beast
- // test code courtesy of Matt Amis and Don Bayne - thanks guys
-
- #ifdef TEST // it's not defined unless you defined it
-
- function main
- local nx := 0, cx := Space(6), dx := Ctod(""), phone := "5035881815"
- set delimiters to "││"
- set delimiters on
- @ 0, 0, maxrow(), maxcol() box replicate(chr(178), 9)
- boxget nx prompt "Numeric nrest r1 c0" row 1 column 0 norestore
- boxget nx prompt "Numeric, pic 9999 nrest r4 c0" picture "9999" ;
- norestore row 4 column 0 title "Pick a number"
- boxget nx prompt "Numeric, pic 9999, val > 20 nrest r7 c0" picture "9999" ;
- valid nX > 20 norestore row 7 column 0
- boxget nx prompt "Numeric, pic #### nrest r10 c0" picture '####' double ;
- norestore row 10 column 0
- boxget nx prompt "Numeric nrest r16 c0" boxcolor "+W/R" ;
- color "+W/RB, +GR/N" norestore row 16 column 0
- boxget nx prompt "Numeric nrest r19 c0" boxcolor "+W/R" ;
- norestore row 19 column 0
- boxget cx prompt "Character, restoreall nrest r22 c0" ;
- boxcolor "*+gr/n" restoreall row 22 column 0
- boxget cx prompt "Character, double" double
- boxget cx prompt "Character, nothing"
- boxget dx prompt "Date, pic 99/99/99" picture "99/99/99"
- boxget dx prompt "Date, pic 99/99/99, not empty valid" picture "99/99/99" ;
- valid (! empty(dx))
- boxget cx prompt "Character, this is going to be a really long message that "+;
- "will automatically get truncated by BOXGET()" boxcolor "*+gr/n"
- boxget cx prompt "Character, pic @!" picture "@!"
- boxget cx prompt "Character, pic !!!!!!" picture "!!!!!!"
- boxget phone prompt "Phone #" picture "@R (999) 999-9999"
- return nil
-
- #endif
-
-
- function boxget(cprompt, nrow, ncol, oget, cvalid, cboxcolor, ;
- norestore, restall, double, ctitle)
- static boxstack_ := {} // to store screen shots
- local x, getlength, oldscore := set(_SET_SCOREBOARD, .f.), oldscrn
- //───── set insert key to toggle both insert mode & cursor
- local oldins := setkey( K_INS, {|| setcursor( ;
- if(readinsert(! readInsert()), SC_NORMAL, SC_SPECIAL1))} )
- GFSaveEnv(, , cboxcolor) // switch to box color
- //───── initial cursor setting based on current mode
- setcursor( if(readInsert(), SC_SPECIAL1, SC_NORMAL) )
- /*
- Determine length of GET variable by verifying the length of the GET
- buffer. This is necessary not only in the event that no PICTURE
- clause was used, but also because we cannot always trust the PICTURE
- clause (e.g., "@!" and "@R"). Note that the GET must be activated with
- the setFocus() method, because the g:buffer instance variable only exists
- when the GET is active. Also notice that although the GET is activated,
- it will not appear on the screen. Why is this?? Look carefully at the
- BOXGET user-defined command in GRUMP.CH -- there lies the answer.
- */
- oget:setFocus()
-
- //───── determine length of GET buffer but check first for @S Picture
- //───── special thanks to Kevin Farley for his comments in this regard
- //───── note: this assumes that the scroll length will be two digits
- if oget:picture != NIL .and. (x := at("S", oget:picture) ) > 0
- getlength := val(substr(oget:picture, x + 1, 2))
- else
- getlength := len(oget:buffer)
- endif
- oget:killFocus()
-
- //───── truncate long prompts to fit on screen
- cprompt := substr(cprompt, 1, maxcol() - 4 - DELIMITERPAD - getlength)
-
- //───── establish defaults for box title, row, and column positions
- default ctitle to ''
- default nrow to int( maxrow() / 2) - 1
- default ncol to int( maxcol() - 3 - len(cprompt) - DELIMITERPAD - ;
- getlength ) / 2
-
- oldscrn := shadowbox(TOP, LEFT, BOTTOM, RIGHT, if(double, 1, 2), ctitle)
-
- //───── if NORESTORE was specified, add the affected portion of screen
- //───── to box stack so we can restore it later
- if norestore
- aadd(boxstack_, oldscrn )
- endif
- setpos(TOP + 1, LEFT + 2)
- oget:postBlock := cvalid // set up VALID clause manually
- dispout( cprompt )
- oget:row := row() // set up GET row manually
-
- //───── if delimiters are set ON, we must display them manually
- //───── because GETNEW() does not respect the rascally things!
- if set(_SET_DELIMITERS)
- oget:col := col() + 2
- dispout(' ' + left(set(_SET_DELIMCHARS), 1) + ;
- space(getlength) + right(set(_SET_DELIMCHARS), 1))
- else
- oget:col := col() + 1
- endif
- readmodal( { oget } )
-
- //───── restore all screens if RESTOREALL was specified
- if restall
- ByeByeBox(oldscrn)
- if ! empty(boxstack_)
- for x := len(boxstack_) to 1 step -1
- restscreen(boxstack_[x, 1], boxstack_[x, 2], boxstack_[x, 3], ;
- boxstack_[x, 4], boxstack_[x, 5])
- next
- asize(boxstack_, 0)
- endif
- elseif ! norestore
- ByeByeBox(oldscrn)
- endif
-
- //───── restore all other environmental aspects
- GFRestEnv()
- setkey(K_INS, oldins) // reset INSERT key
- set(_SET_SCOREBOARD, oldscore) // argh... does anybody use this?
- return nil
-