home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a054 / 1.img / GETPRGS.EXE / GETS21.PRG < prev    next >
Encoding:
Text File  |  1992-03-08  |  3.9 KB  |  171 lines

  1. /***
  2. * Gets21.prg
  3. */
  4.  
  5. /***
  6. * GET - MOUSE gets
  7. *
  8. */
  9.  
  10. #include "Getexit.ch"
  11. #include "Inkey.ch"
  12. #include "Mouse.ch"
  13.  
  14. #command READ ALLOWING MOUSE                                   ;
  15.          =>                                                    ;
  16.          Aeval(GetList,                                        ;
  17.                {|o| o:Reader := {|o1| GetMouseReader(o1)} })   ;
  18.          ; ReadModal(GetList); GetList := {}
  19.  
  20. MEMVAR GetList
  21.  
  22. FUNCTION Gets21
  23.  
  24. LOCAL cVar1 := "cVar1", ;
  25.       cVar2 := "cVar2", ;
  26.       cVar3 := "cVar3", ;
  27.       cVar4 := "cVar4"
  28.  
  29. LOCAL nButtons
  30.  
  31.   SetColor("W+/N, R+/W,,, B+/W")
  32.   CLEAR SCREEN
  33.   IF !MouseInit(@nButtons)
  34.     ? "Mouse not installed"
  35.     QUIT
  36.   ENDIF
  37.  
  38.   MouseOn()
  39.   @ 10, 10 GET cVar1 ;
  40.     VALID iif(LastKey() == K_DOWN,  (GoToGet(3), .T.), .T.)
  41.  
  42.   @ 10, 40 GET cVar2 ;
  43.     VALID iif(LastKey() == K_DOWN,  (GoToGet(4), .T.), .T.)
  44.  
  45.   @ 11, 10 GET cVar3 ;
  46.     VALID iif(LastKey() == K_UP,    (GoToGet(1), .T.), .T.)
  47.  
  48.   @ 11, 40 GET cVar4 ;
  49.     VALID iif(LastKey() == K_UP,    (GoToGet(2), .T.), .T.)
  50.  
  51.   READ ALLOWING MOUSE
  52.   MouseOff()
  53.  
  54. RETURN NIL
  55.  
  56.  
  57. proc GetMouseReader( oGet )
  58.  
  59. LOCAL nCurrentGet
  60. LOCAL nKey
  61. LOCAL lHadMouse, lHadKey, lLeftPressed, lRightPressed
  62. LOCAL nRow, nCol
  63. LOCAL nMouseGet
  64. LOCAL lWhen
  65. LOCAL lValid
  66.  
  67.   nCurrentGet := Ascan(GetList, {|o| o == oGet })
  68.   IF !(GetMovingTo() == NIL) .AND. nCurrentGet != GetMovingTo()
  69.     IF nCurrentGet > GetMovingTo()
  70.       oGet:exitState := GE_UP
  71.     ELSE
  72.       oGet:exitState := GE_DOWN
  73.     ENDIF
  74.   ELSE
  75.     GetMovingTo(NIL) 
  76.     // read the GET if the WHEN condition is satisfied
  77.     MouseOff()
  78.     lWhen := GetPreValidate(oGet)
  79.     MouseOn()
  80.     IF ( lWhen )
  81.       // activate the GET for reading
  82.       MouseOff()
  83.       oGet:SetFocus()
  84.       MouseOn()
  85.  
  86.       DO WHILE ( oGet:exitState == GE_NOEXIT )
  87.         // check for initial typeout (no editable positions)
  88.         IF ( oGet:typeOut )
  89.           oGet:exitState := GE_ENTER
  90.         ENDIF
  91.  
  92.         // apply keystrokes until exit
  93.         DO WHILE ( oGet:exitState == GE_NOEXIT )
  94.           lHadMouse := .F.
  95.           lHadKey   := .F.
  96.           DO WHILE !lHadKey .AND. !lHadMouse
  97.             nKey := InKey()
  98.             lHadKey := nKey != 0
  99.             IF !lHadKey
  100.               // No key, check mouse
  101.               MouseRead(@lLeftPressed, @lRightPressed, @nRow, @nCol)
  102.               nRow := Int(nRow / M_CURS_HEIGHT)
  103.               nCol := Int(nCol / M_CURS_WIDTH)
  104.               IF lLeftPressed .OR. lRightPressed
  105.                 nMouseGet := Ascan(GetList, ;
  106.                                    {|o| nRow == o:row .AND. ;
  107.                                         nCol >= o:col .AND. ;
  108.                                         nCol <= o:col + ;
  109.                                            Len(Transform(o:Varget(), ;
  110.                                                          o:Picture)) - 1})
  111.  
  112.                 lHadMouse := nMouseGet > 0
  113.               ENDIF
  114.             ENDIF
  115.           ENDDO
  116.  
  117.           IF lHadKey
  118.             MouseOff()
  119.             GetApplyKey(oGet, nKey)
  120.             MouseOn()
  121.           ELSE
  122.             GoToGet(nMouseGet)
  123.           ENDIF
  124.         ENDDO
  125.  
  126.         // disallow exit if the VALID condition is not satisfied
  127.         MouseOff()
  128.         lValid := GetPostValidate(oGet)
  129.         MouseOn()
  130.         IF ( !lValid )
  131.           oGet:exitState := GE_NOEXIT
  132.         ENDIF
  133.       ENDDO
  134.  
  135.       // de-activate the GET
  136.       MouseOff()
  137.       oGet:KillFocus()
  138.       MouseOn()
  139.     ENDIF
  140.   ENDIF
  141.  
  142. RETURN
  143.  
  144.  
  145. FUNCTION GoToGet(n)
  146.  
  147. LOCAL oGetCurrent := GetActive()
  148. LOCAL nGetCurrent := Ascan(GetList, {|o| o == oGetCurrent})
  149.  
  150.   IF nGetCurrent > n
  151.     oGetCurrent:exitState := GE_UP
  152.   ELSE
  153.     oGetCurrent:exitState := GE_DOWN
  154.   ENDIF
  155.   GetMovingTo(n)
  156.  
  157. RETURN NIL
  158.  
  159.  
  160. FUNCTION GetMovingTo(n)
  161.  
  162. STATIC nWhereToGo
  163. LOCAL  nOldWhereGo := nWhereToGo
  164.  
  165.   IF PCount() > 0
  166.     nWhereToGo := n
  167.   ENDIF
  168.  
  169. RETURN nOldWhereGo
  170.  
  171.