home *** CD-ROM | disk | FTP | other *** search
- /***
- * getsys.prg
- * Standard Clipper 5.0 GET/READ subsystem!
- * Copyright (c) 1990 Nantucket Corp. All rights reserved.
- *
- * Note: compile with /n/w/a
- */
-
- #include "set.ch"
- #include "inkey.ch"
-
-
- #define K_UNDO K_CTRL_U
-
-
- static __Updated := .f.
- static __Format
-
- static KillRead := .f.
-
-
-
- /***
- * __SetFormat()
- */
- func __SetFormat(b)
- __Format := if ( ValType(b) == "B", b, NIL )
- return (NIL)
-
-
-
- /***
- * __KillRead()
- *
- * CLEAR GETS service
- */
- func __KillRead()
- KillRead := .t.
- return (NIL)
-
-
-
- /***
- * Updated()
- */
- func Updated()
- return (__Updated)
-
-
-
- /***
- * ReadExit()
- */
- func ReadExit(lNew)
- return ( Set(_SET_EXIT, lNew) )
-
-
-
- /***
- * ReadInsert()
- */
- func ReadInsert(lNew)
- return ( Set(_SET_INSERT, lNew) )
-
-
-
- /***
- * ShowScoreboard()
- */
- proc ShowScoreboard()
- local nRow, nCol
- if ( Set(_SET_SCOREBOARD) )
- nRow := row()
- nCol := col()
- @ 0, 60 SAY if( Set(_SET_INSERT), "Ins", " " )
- @ nRow, nCol SAY ""
- end
- return
-
-
-
- /***
- * DateMsg()
- */
- static func DateMsg()
- local nRow, nCol
-
- if ( Set(_SET_SCOREBOARD) )
- nRow := Row()
- nCol := Col()
- @ 0, 60 SAY "Invalid Date"
- @ nRow, nCol SAY ""
-
- while ( Nextkey() == 0 )
- end
-
- @ 0, 60 SAY " "
- @ nRow, nCol SAY ""
- end
-
- return (.f.)
-
-
-
- /***
- * RangeCheck()
- */
- func RangeCheck(xValue, lChanged, aRange)
- local cMsg, nRow, nCol
-
- /*
- if (!lChanged)
- return (.t.)
- end
- */
-
- if ( xValue >= aRange[1] .and. xValue <= aRange[2] )
- return (.t.) /* NOTE */
- end
-
- if ( Set(_SET_SCOREBOARD) )
- cMsg := "Range: " + Ltrim(Transform(aRange[1], "")) + ;
- " - " + Ltrim(Transform(aRange[2], ""))
-
- if ( Len(cMsg) > MaxCol() )
- cMsg := Substr( cMsg, 1, MaxCol() )
- end
-
- nRow := Row()
- nCol := Col()
- @ 0, Min( 60, MaxCol() - Len(cMsg) ) SAY cMsg
- @ nRow, nCol SAY ""
-
- while ( NextKey() == 0 )
- end
-
- @ 0, Min( 60, MaxCol() - Len(cMsg) ) SAY Replicate( " ", Len(cMsg) )
- @ nRow, nCol SAY ""
- end
-
- return (.f.)
-
-
-
- /***
- * ReadModal()
- */
- func ReadModal(aList)
-
- local g
- local i, new
- local nLen
- local nKey, cKey
- local bKeyBlock
- local saveReadVar
- local localUpdated
- local localReadExit
- local GetExitRequested
- local GetExitGranted
-
- /* format? */
- if ( ValType(__Format) == "B" )
- Eval(__Format)
- end
-
- if ( Empty(aList) )
- /* S87 compat. */
- @ MaxRow()-1, 0 SAY ""
- return (.f.)
- end
-
- /* CAUTION save readexit? */
- localReadExit := Set(_SET_EXIT)
-
- /* set CLEAR GETS flag off */
- KillRead := .f.
-
- /* set Updated() flag off */
- __Updated := localUpdated := .f.
-
- /* save, set ReadVar() */
- saveReadVar := ReadVar("")
-
- nLen := Len(aList)
-
- /***
- * READ loop
- */
-
- i := 1
- while (i != 0 .and. !KillRead)
-
- /* set current get */
- g := aList[i]
-
- /* set ReadVar() */
- ReadVar(Upper(g:name))
-
- /* pre-validation (WHEN clause) */
- if ( g:preBlock != NIL .and. !Eval( g:preBlock ) )
- /* CAUTION needs to bounce */
- if ( ++i > nLen )
- i := if( localReadExit, 0, nLen )
- end
- loop /* NOTE */
- end
-
- ShowScoreboard()
-
- /* Give to it the focus, Kenneth */
- g:setFocus()
-
- /***
- * GET loop
- */
-
- GetExitGranted := .f.
-
- while (!GetExitGranted)
-
- if (g:typeOut)
- /* no editable positions */
- /* CAUTION should it bounce? not s87 compat but */
- GetExitRequested := .t.
- if ((new := i + 1) > Len(aList) )
- new := 0 /* CAUTION typeout w/readexit? */
- end
- else
- GetExitRequested := .f.
- end
-
- /***
- * keystroke processing loop
- */
-
- while (!GetExitRequested)
-
- nKey := Inkey(0)
-
- if ( (bKeyBlock := SetKey(nKey)) != NIL )
-
- if (g:changed)
- g:assign()
- end
-
- /* run SET KEY block */
- Eval(bKeyBlock, ProcName(2), ProcLine(2), ReadVar())
-
- /* in case var was reassigned in SET KEY code */
- g:updateBuffer()
-
- /* in case insert status was diddled in SET KEY code */
- ShowScoreboard()
-
- /* if CLEAR GETS was issued in SET KEY code, get out */
- if (KillRead)
- exit /* NOTE */
- end
-
- loop /* NOTE */
- end
-
- /***
- * key processing switch
- */
-
- do case
- case (nKey == K_UP)
- GetExitRequested := .t.
- if ((new := i - 1) < 1)
- new := if( localReadExit, 0, 1 )
- end
-
- case (nKey == K_DOWN)
- GetExitRequested := .t.
- if ((new := i + 1) > nLen)
- new := if( localReadExit, 0, nLen )
- end
-
- case (nKey == K_ESC)
- if ( Set(_SET_ESCAPE) )
- g:undo()
- GetExitRequested := .t.
- KillRead := .t.
- end
-
- case (nKey == K_PGUP)
- GetExitRequested := .t.
- new := 0
-
- case (nKey == K_PGDN)
- GetExitRequested := .t.
- new := 0
-
- case (nKey == K_CTRL_HOME)
- GetExitRequested := .t.
- new := 1
- #ifdef NOTDEF
- /* this code causes both ^W and ^End to behave like ^End */
- case (nKey == K_CTRL_END)
- GetExitRequested := .t.
- new := Len(aList)
- #else
- /* this code causes both ^W and ^End to behave like ^W */
- case (nKey == K_CTRL_W)
- GetExitRequested := .t.
- new := 0
- #endif
- case (nKey == K_ENTER)
- GetExitRequested := .t.
- if ((new := i + 1) > Len(aList) )
- new := 0 /* CAUTION typeout w/readexit? */
- end
-
- case (nKEY == K_UNDO)
- g:undo()
-
- case (nKey == K_INS)
- Set( _SET_INSERT, !Set(_SET_INSERT) )
- ShowScoreboard()
-
- case (nKey == K_HOME)
- g:home()
-
- case (nKey == K_END)
- g:end()
-
- case (nKey == K_RIGHT)
- g:right()
-
- case (nKey == K_LEFT)
- g:left()
-
- case (nKey == K_CTRL_RIGHT)
- g:wordRight()
-
- case (nKey == K_CTRL_LEFT)
- g:wordLeft()
-
- case (nKey == K_BS)
- g:backSpace()
-
- case (nKey == K_DEL)
- g:delete()
-
- case (nKey == K_CTRL_T)
- g:delWordRight()
-
- case (nKey == K_CTRL_Y)
- g:delEnd()
-
- otherwise
- /* data key */
- cKey := Chr(nKey)
-
- if (g:type == "N" .and. (cKey == "." .or. cKey == ","))
- g:toDecPos()
- else
- if ( Set(_SET_INSERT) )
- g:insert(cKey)
- else
- g:overstrike(cKey)
- end
- end
-
- if (g:typeOut .and. !Set(_SET_CONFIRM) )
-
- /* ding */
- if ( Set(_SET_BELL) )
- ?? Chr(7)
- end
-
- GetExitRequested := .t.
- if ((new := i + 1) > Len(aList) )
- new := 0 /* CAUTION typeout w/readexit? */
- end
- end
-
- endcase
-
- end /* end of keystroke processing loop */
-
-
- /***
- * if KillRead (from CLEAR GETS in SetKey() or key escape),
- * fall out
- */
- if (KillRead)
- exit /* NOTE */
- end
-
-
- /* check for bad date before sprucing up edit buffer */
- if (g:badDate())
-
- g:home()
- DateMsg()
- ShowScoreboard()
-
- loop /* NOTE */
- end
-
- /* assign get var */
- if (g:changed)
- __Updated := localUpdated := .t.
- g:assign()
- end
-
- /* reset editing machinery (and redisplay) */
- g:reset()
-
- if (Valtype(g:postBlock) == "B")
- /* run the valid block */
- GetExitGranted := Eval(g:postBlock, g:getVar(), g:changed)
-
- /* in case insert status was changed in valid code */
- ShowScoreboard()
-
- /* in case var was reassigned in valid code */
- g:updateBuffer()
-
- /* in case nested read changed global updated flag */
- __Updated := localUpdated
-
- else
- /* no valid clause */
- GetExitGranted := .t.
-
- end
-
- end /* end of GET editing loop */
-
- /* take away from it the focus, Kenneth */
- g:killFocus()
-
- /* set getList index for next edit */
- i := new
-
- end /* end of READ loop */
-
- /* reset CLEAR GETS flag */
- KillRead := .f.
-
- /* S87 compat. */
- @ MaxRow()-1, 0 SAY ""
-
- /* restore readvar */
- ReadVar(saveReadVar)
-
- return (__Updated)
-