home *** CD-ROM | disk | FTP | other *** search
- /***
- * Gets21.prg
- */
-
- /***
- * GET - MOUSE gets
- *
- */
-
- #include "Getexit.ch"
- #include "Inkey.ch"
- #include "Mouse.ch"
-
- #command READ ALLOWING MOUSE ;
- => ;
- Aeval(GetList, ;
- {|o| o:Reader := {|o1| GetMouseReader(o1)} }) ;
- ; ReadModal(GetList); GetList := {}
-
- MEMVAR GetList
-
- FUNCTION Gets21
-
- LOCAL cVar1 := "cVar1", ;
- cVar2 := "cVar2", ;
- cVar3 := "cVar3", ;
- cVar4 := "cVar4"
-
- LOCAL nButtons
-
- SetColor("W+/N, R+/W,,, B+/W")
- CLEAR SCREEN
- IF !MouseInit(@nButtons)
- ? "Mouse not installed"
- QUIT
- ENDIF
-
- MouseOn()
- @ 10, 10 GET cVar1 ;
- VALID iif(LastKey() == K_DOWN, (GoToGet(3), .T.), .T.)
-
- @ 10, 40 GET cVar2 ;
- VALID iif(LastKey() == K_DOWN, (GoToGet(4), .T.), .T.)
-
- @ 11, 10 GET cVar3 ;
- VALID iif(LastKey() == K_UP, (GoToGet(1), .T.), .T.)
-
- @ 11, 40 GET cVar4 ;
- VALID iif(LastKey() == K_UP, (GoToGet(2), .T.), .T.)
-
- READ ALLOWING MOUSE
- MouseOff()
-
- RETURN NIL
-
-
- proc GetMouseReader( oGet )
-
- LOCAL nCurrentGet
- LOCAL nKey
- LOCAL lHadMouse, lHadKey, lLeftPressed, lRightPressed
- LOCAL nRow, nCol
- LOCAL nMouseGet
- LOCAL lWhen
- LOCAL lValid
-
- nCurrentGet := Ascan(GetList, {|o| o == oGet })
- IF !(GetMovingTo() == NIL) .AND. nCurrentGet != GetMovingTo()
- IF nCurrentGet > GetMovingTo()
- oGet:exitState := GE_UP
- ELSE
- oGet:exitState := GE_DOWN
- ENDIF
- ELSE
- GetMovingTo(NIL)
- // read the GET if the WHEN condition is satisfied
- MouseOff()
- lWhen := GetPreValidate(oGet)
- MouseOn()
- IF ( lWhen )
- // activate the GET for reading
- MouseOff()
- oGet:SetFocus()
- MouseOn()
-
- DO WHILE ( oGet:exitState == GE_NOEXIT )
- // check for initial typeout (no editable positions)
- IF ( oGet:typeOut )
- oGet:exitState := GE_ENTER
- ENDIF
-
- // apply keystrokes until exit
- DO WHILE ( oGet:exitState == GE_NOEXIT )
- lHadMouse := .F.
- lHadKey := .F.
- DO WHILE !lHadKey .AND. !lHadMouse
- nKey := InKey()
- lHadKey := nKey != 0
- IF !lHadKey
- // No key, check mouse
- MouseRead(@lLeftPressed, @lRightPressed, @nRow, @nCol)
- nRow := Int(nRow / M_CURS_HEIGHT)
- nCol := Int(nCol / M_CURS_WIDTH)
- IF lLeftPressed .OR. lRightPressed
- nMouseGet := Ascan(GetList, ;
- {|o| nRow == o:row .AND. ;
- nCol >= o:col .AND. ;
- nCol <= o:col + ;
- Len(Transform(o:Varget(), ;
- o:Picture)) - 1})
-
- lHadMouse := nMouseGet > 0
- ENDIF
- ENDIF
- ENDDO
-
- IF lHadKey
- MouseOff()
- GetApplyKey(oGet, nKey)
- MouseOn()
- ELSE
- GoToGet(nMouseGet)
- ENDIF
- ENDDO
-
- // disallow exit if the VALID condition is not satisfied
- MouseOff()
- lValid := GetPostValidate(oGet)
- MouseOn()
- IF ( !lValid )
- oGet:exitState := GE_NOEXIT
- ENDIF
- ENDDO
-
- // de-activate the GET
- MouseOff()
- oGet:KillFocus()
- MouseOn()
- ENDIF
- ENDIF
-
- RETURN
-
-
- FUNCTION GoToGet(n)
-
- LOCAL oGetCurrent := GetActive()
- LOCAL nGetCurrent := Ascan(GetList, {|o| o == oGetCurrent})
-
- IF nGetCurrent > n
- oGetCurrent:exitState := GE_UP
- ELSE
- oGetCurrent:exitState := GE_DOWN
- ENDIF
- GetMovingTo(n)
-
- RETURN NIL
-
-
- FUNCTION GetMovingTo(n)
-
- STATIC nWhereToGo
- LOCAL nOldWhereGo := nWhereToGo
-
- IF PCount() > 0
- nWhereToGo := n
- ENDIF
-
- RETURN nOldWhereGo
-