home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a054 / 1.img / GETLIB.EXE / GETSECT.PRG < prev    next >
Encoding:
Text File  |  1992-03-09  |  2.7 KB  |  120 lines

  1. // GetSect.prg
  2. //
  3. // Get reader implementing GET ... SECTION
  4.  
  5. #include "Getexit.ch"
  6. #include "Inkey.ch"
  7.  
  8. MEMVAR GetList
  9.  
  10. PROCEDURE SectReader( oGet )
  11.  
  12. LOCAL nKey
  13. LOCAL nSect := DictAt(oGet:cargo, "SEC #")
  14. LOCAL nCurrentGet
  15.  
  16.   nCurrentGet := Ascan(GetList, {|o| o == oGet })
  17.   IF !(GetMovingTo() == NIL) .AND. nCurrentGet != GetMovingTo()
  18.     IF nCurrentGet > GetMovingTo()
  19.       oGet:exitState := GE_UP
  20.     ELSE
  21.       oGet:exitState := GE_DOWN
  22.     ENDIF
  23.   ELSE
  24.     GetMovingTo(NIL) 
  25.  
  26.     // Read the GET if the WHEN condition is satisfied
  27.     IF ( GetPreValidate(oGet) )
  28.  
  29.       // activate the GET for reading
  30.       oGet:SetFocus()
  31.  
  32.       DO WHILE ( oGet:exitState == GE_NOEXIT )
  33.  
  34.         // check for initial typeout (no editable positions)
  35.         IF ( oGet:typeOut )
  36.           oGet:exitState := GE_ENTER
  37.         ENDIF
  38.  
  39.         // apply keystrokes until exit
  40.         DO WHILE ( oGet:exitState == GE_NOEXIT )
  41.           nKey := InKey(0)
  42.           DO CASE
  43.             CASE nKey == K_TAB
  44.               oGet:exitState := GE_DOWN
  45.               GoToGet(NextSection(oGet, GetList))
  46.             
  47.             CASE nKey == K_SH_TAB
  48.               oGet:exitState := GE_UP
  49.               GoToGet(PrevSection(oGet, GetList))
  50.  
  51.             OTHERWISE
  52.               GetApplyKey( oGet, nKey )
  53.           ENDCASE
  54.         ENDDO
  55.  
  56.         // disallow exit if the VALID condition is not satisfied
  57.         IF ( !GetPostValidate(oGet) )
  58.           oGet:exitState := GE_NOEXIT
  59.         ENDIF
  60.  
  61.       ENDDO
  62.  
  63.       // de-activate the GET
  64.       oGet:KillFocus()
  65.     ENDIF
  66.   ENDIF
  67.  
  68. RETURN
  69.  
  70.  
  71. FUNCTION NextSection(oGet)
  72.  
  73. LOCAL oCurrentSection := DictAt(oGet:cargo, "SEC #")
  74. LOCAL aSections := SectionStarts()
  75.  
  76. RETURN aSections[oCurrentSection % Len(aSections) + 1, 2]
  77.  
  78.  
  79. FUNCTION PrevSection(oGet)
  80.  
  81. LOCAL oCurrentSection := DictAt(oGet:cargo, "SEC #")
  82. LOCAL aSections := SectionStarts()
  83.  
  84. RETURN iif(oCurrentSection == 1,       ;
  85.            aSections[Len(aSections), 2], ;
  86.            aSections[(oCurrentSection - 1) % Len(aSections), 2])
  87.  
  88.  
  89. FUNCTION GetSecStarts(GetList)
  90.  
  91. LOCAL aSectionStarts := {}
  92. LOCAL nGets := Len(GetList)
  93. LOCAL i
  94. LOCAL aCargo
  95.  
  96.   FOR i := 1 TO nGets
  97.     aCargo := GetList[i]:cargo
  98.     IF Ascan(aSectionStarts, ;
  99.              {|e| e[1] == DictAt(aCargo, "SEC #") } ) == 0
  100.       Aadd(aSectionStarts, ;
  101.            { DictAt(aCargo, "SEC #"), i })
  102.     ENDIF
  103.   NEXT
  104.  
  105. RETURN aSectionStarts
  106.  
  107.  
  108. // Get / Set array containing section start / get # pairs
  109.  
  110. FUNCTION SectionStarts(aSecs)
  111.  
  112. STATIC aSectionStarts := {}
  113. LOCAL aOldStarts := aSectionStarts
  114.  
  115.   IF Pcount() > 0
  116.     aSectionStarts := aSecs
  117.   ENDIF
  118.  
  119. RETURN aOldStarts
  120.