home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1995 September / Image.iso / visualob / install / samples / employee / udftbrow.cl_ / udftbrow.cl
Encoding:
Text File  |  1994-08-18  |  4.8 KB  |  186 lines

  1. // UDFTBROW.PRG
  2. // Employee Information TBrowse library functions
  3. // November, 1993
  4.  
  5. #include "sys.ch"
  6.  
  7. FUNCTION Init_Tb(TheArray, TheTop, TheLeft, TheBottom, TheRight, TheCondition)
  8.    LOCAL TheBrowse, OldColor, TheCount, TheTotal, TheColumn
  9.  
  10.    TheBrowse := TBrowseDB(TheTop, TheLeft, TheBottom, TheRight)
  11.  
  12.    TheBrowse:HeadSep   := '═╤═'
  13.    TheBrowse:ColSep    := ' │ '
  14.    TheBrowse:ColorSpec := Browse_Color()
  15.  
  16.    TheTotal  := Len(TheArray)
  17.    FOR TheCount := 1 TO TheTotal
  18.       TheColumn := TBColumnNew(TheArray[TheCount, 1], ;
  19.                                 TheArray[TheCount, 2])
  20.       TheColumn:DefColor := {3, 4}
  21.       TheBrowse:AddColumn(TheColumn)
  22.    NEXT
  23.  
  24.    IF ISBLOCK(TheCondition)
  25.       TheBrowse:GoTopBlock    := { |          | GoTop_Tb(          TheCondition) }
  26.       TheBrowse:GoBottomBlock := { |          | GoBot_Tb(          TheCondition) }
  27.       TheBrowse:SkipBlock     := { | TheCount | Skip_Tb (TheCount, TheCondition) }
  28.    ENDIF
  29.  
  30.    RETURN TheBrowse
  31.  
  32.  
  33. FUNCTION Browse_Tb(TheArray, TheTop, TheLeft, TheBottom, TheRight, ;
  34.                    TheTitle, TheCondition)
  35.    LOCAL OldCursor, OldWindow, TheBrowse, TheKey, TheReturn
  36.  
  37.    OldCursor := SetCursor(SC_NONE)
  38.  
  39.    IF RecCount() = 0
  40.       ErrorMsg('NO RECORDS TO BROWSE')
  41.       RETURN ""
  42.  
  43.    ELSEIF !EOF()
  44.  
  45.    ELSEIF Bottom_It()
  46.  
  47.    ELSEIF EOF()
  48.       ErrorMsg('NO RECORDS TO BROWSE')
  49.       RETURN ""
  50.  
  51.    ENDIF
  52.  
  53.    OldWindow := Win_Open(TheTop, TheLeft, TheBottom, TheRight, TheTitle)
  54.    TheBrowse := Init_Tb(TheArray, TheTop + 1, TheLeft + 1, ;
  55.                         TheBottom - 2, TheRight - 1, TheCondition)
  56.  
  57.    DO WHILE TRUE
  58.  
  59.       DO WHILE (!TheBrowse:Stabilize()) .AND. (NextKey() = 0)
  60.       ENDDO
  61.  
  62.       Win_Msg(TheBottom - 1, TheLeft, TheRight,      ;
  63.               'Record: ' + LTrim(Str(RecNo()))     + ;
  64.               '   '                                + ;
  65.               'of: ' + LTrim(Str(RecCount())))
  66.  
  67.       TheKey := InKey(0)
  68.  
  69.       IF Movement(TheKey, TheBrowse)
  70.       ELSEIF TheKey = K_ESC
  71.          EXIT
  72.  
  73.       ELSEIF TheKey = K_ENTER
  74.          EXIT
  75.       ENDIF
  76.    ENDDO
  77.  
  78.    Win_Close(OldWindow)
  79.    SetCursor(OldCursor)
  80.  
  81.    TheReturn := Macro(IndexKey())
  82.  
  83.    IF LastKey() = K_ESC
  84.       RETURN Space(Len(TheReturn))
  85.    ENDIF
  86.  
  87.    RETURN TheReturn
  88.  
  89.  
  90. FUNCTION GoTop_Tb(TheCondition)
  91.  
  92.    DO WHILE (Eval(TheCondition)) .AND. (!BOF())
  93.       Skip_It(-1)
  94.  
  95.       IF !Eval(TheCondition)
  96.          Skip_It(1)
  97.          EXIT
  98.       ENDIF
  99.  
  100.    ENDDO
  101.  
  102.    RETURN NIL
  103.  
  104.  
  105. FUNCTION GoBot_Tb(TheCondition)
  106.  
  107.    DO WHILE (Eval(TheCondition) .AND. (!EOF()))
  108.       Skip_It(1)
  109.    ENDDO
  110.  
  111.    Skip_It(-1)
  112.  
  113.    RETURN NIL
  114.  
  115.  
  116. FUNCTION Skip_Tb(TheTotal, TheCondition)
  117.    LOCAL TheCount, OldAlias, OldOrder
  118.  
  119.    OldAlias := Select()
  120.    OldOrder := IndexOrd()
  121.    TheCount := 0
  122.  
  123.    IF TheTotal = 0
  124.       Skip_It(0)
  125.  
  126.    ELSEIF (TheTotal > 0) .AND. (!EOF())
  127.       DO WHILE TheCount < TheTotal
  128.          Skip_It(1)
  129.          IF (!Eval(TheCondition)) .OR. (EOF())
  130.             Skip_It(-1)
  131.             EXIT
  132.          ENDIF
  133.  
  134.          ++TheCount
  135.       ENDDO
  136.  
  137.    ELSEIF TheTotal < 0
  138.       DO WHILE TheCount > TheTotal
  139.          Skip_It(-1)
  140.          IF BOF()
  141.             EXIT
  142.          ENDIF
  143.          IF !Eval(TheCondition)
  144.             Skip_It(1)
  145.             EXIT
  146.          ENDIF
  147.  
  148.          --TheCount
  149.       ENDDO
  150.  
  151.    ENDIF
  152.  
  153.    Order_It(OldOrder, OldAlias)
  154.  
  155.    RETURN TheCount
  156.  
  157.  
  158. FUNCTION Movement(TheKey, TheBrowse)
  159.    LOCAL ThePointer
  160.    STATIC TheKeyList
  161.  
  162.    TheKeyList := {                                                          ;
  163.                    K_DOWN       , { | TheBrowse | TheBrowse:Down()     } , ;
  164.                    K_UP         , { | TheBrowse | TheBrowse:Up()       } , ;
  165.                    K_PGDN       , { | TheBrowse | TheBrowse:PageDown() } , ;
  166.                    K_PGUP       , { | TheBrowse | TheBrowse:PageUp()   } , ;
  167.                    K_CTRL_PGUP  , { | TheBrowse | TheBrowse:GoTop()    } , ;
  168.                    K_CTRL_PGDN  , { | TheBrowse | TheBrowse:GoBottom() } , ;
  169.                    K_RIGHT      , { | TheBrowse | TheBrowse:Right()    } , ;
  170.                    K_LEFT       , { | TheBrowse | TheBrowse:Left()     } , ;
  171.                    K_HOME       , { | TheBrowse | TheBrowse:Home()     } , ;
  172.                    K_END        , { | TheBrowse | TheBrowse:End()      } , ;
  173.                    K_CTRL_LEFT  , { | TheBrowse | TheBrowse:PanLeft()  } , ;
  174.                    K_CTRL_RIGHT , { | TheBrowse | TheBrowse:PanRight() } , ;
  175.                    K_CTRL_HOME  , { | TheBrowse | TheBrowse:PanHome()  } , ;
  176.                    K_CTRL_END   , { | TheBrowse | TheBrowse:PanEnd()   }   ;
  177.                  }
  178.  
  179.    ThePointer := AScan(TheKeyList, TheKey)
  180.    IF ThePointer != 0
  181.       Eval(TheKeyList[++ThePointer], TheBrowse)
  182.    ENDIF
  183.  
  184.    RETURN ThePointer != 0
  185. 
  186.