home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Database / CLIPR502.DOS / SOURCE / SAMPLE / SCROLBAR.PRG < prev    next >
Encoding:
Text File  |  1993-02-15  |  3.3 KB  |  134 lines

  1. /***
  2. *
  3. *  Scrolbar.prg
  4. *
  5. *  Implements a scroll bar that can be updated as the cursor moves down
  6. *  in a TBrowse object, ACHOICE(), DBEDIT(), or MEMOEDIT()
  7. *
  8. *  Copyright (c) 1993, Computer Associates International Inc.
  9. *  All rights reserved.
  10. *
  11. *  NOTE: Compile with /n /w
  12. *
  13. */
  14.  
  15. #include "Fileman.ch"
  16.  
  17.  
  18. /***
  19. *
  20. *  ScrollBarNew( <nTopRow>, <nTopColumn>, <nBottomRow>, 
  21. *                <cColorString>, <nInitPosition> ) --> aScrollBar
  22. *  
  23. *  Create a new scroll bar array with the specified coordinates
  24. *
  25. */
  26. FUNCTION ScrollBarNew( nTopRow, nTopColumn, nBottomRow, ;
  27.                         cColorString, nInitPosition )
  28.  
  29.    LOCAL aScrollBar := ARRAY( TB_ELEMENTS )
  30.  
  31.    aScrollBar[ TB_ROWTOP ]    := nTopRow
  32.    aScrollBar[ TB_COLTOP ]    := nTopColumn
  33.    aScrollBar[ TB_ROWBOTTOM ] := nBottomRow
  34.    aScrollBar[ TB_COLBOTTOM ] := nTopColumn
  35.  
  36.    // Set the default color to White on Black if none specified
  37.    IF cColorString == NIL
  38.       cColorString := "W/N"
  39.    ENDIF
  40.    aScrollBar[ TB_COLOR ] := cColorString
  41.  
  42.    // Set the starting position
  43.    IF nInitPosition == NIL
  44.       nInitPosition := 1
  45.    ENDIF
  46.    aScrollBar[ TB_POSITION ] := nInitPosition
  47.  
  48.    RETURN ( aScrollBar )
  49.  
  50.  
  51.  
  52. /***
  53. *
  54. *  ScrollBarDisplay( <aScrollBar> ) --> aScrollBar
  55. *
  56. *  Display a scoll bar array to the screen
  57. *
  58. */
  59. FUNCTION ScrollBarDisplay( aScrollBar )
  60.    
  61.    LOCAL cOldColor
  62.    LOCAL nRow
  63.  
  64.    cOldColor := SETCOLOR( aScrollBar[ TB_COLOR ] )
  65.  
  66.    // Draw the arrows
  67.    @ aScrollBar[ TB_ROWTOP ], aScrollBar[ TB_COLTOP ] SAY TB_UPARROW
  68.    @ aScrollBar[ TB_ROWBOTTOM ], aScrollBar[ TB_COLBOTTOM ] SAY TB_DNARROW
  69.  
  70.    // Draw the background
  71.    FOR nRow := (aScrollBar[ TB_ROWTOP ] + 1) TO (aScrollBar[ TB_ROWBOTTOM ] - 1)
  72.       @ nRow, aScrollBar[ TB_COLTOP ] SAY TB_BACKGROUND
  73.    NEXT
  74.  
  75.    SETCOLOR( cOldColor )
  76.  
  77.    RETURN ( aScrollBar )
  78.  
  79.  
  80.  
  81. /***
  82. *
  83. *  ScrollBarUpdate( <aScrollBar>, <nCurrent>, <nTotal>,
  84. *     <lForceUpdate> ) --> aScrollBar
  85. *
  86. *  Update scroll bar array with new tab position and redisplay tab
  87. *
  88. */
  89. FUNCTION ScrollBarUpdate( aScrollBar, nCurrent, nTotal, lForceUpdate )
  90.  
  91.    LOCAL cOldColor
  92.    LOCAL nNewPosition
  93.    LOCAL nScrollHeight := ( aScrollBar[TB_ROWBOTTOM] - 1 ) - ;
  94.                           ( aScrollBar[TB_ROWTOP] )
  95.  
  96.    IF nTotal < 1
  97.       nTotal := 1
  98.    ENDIF
  99.  
  100.    IF nCurrent < 1
  101.       nCurrent := 1
  102.    ENDIF
  103.  
  104.    IF nCurrent > nTotal
  105.       nCurrent := nTotal
  106.    ENDIF
  107.  
  108.    IF lForceUpdate == NIL
  109.       lForceUpdate := .F.
  110.    ENDIF
  111.  
  112.    cOldColor := SETCOLOR( aScrollBar[ TB_COLOR ] )
  113.  
  114.    // Determine the new position
  115.    nNewPosition := ROUND( (nCurrent / nTotal) * nScrollHeight, 0 )
  116.  
  117.    // Resolve algorythm oversights
  118.    nNewPosition := IF( nNewPosition < 1, 1, nNewPosition )
  119.    nNewPosition := IF( nCurrent == 1, 1, nNewPosition )
  120.    nNewPosition := IF( nCurrent >= nTotal, nScrollHeight, nNewPosition )
  121.  
  122.    // Overwrite the old position (if different), then draw in the new one
  123.    IF nNewPosition <> aScrollBar[ TB_POSITION ] .OR. lForceUpdate
  124.       @ (aScrollBar[ TB_POSITION ] + aScrollBar[ TB_ROWTOP ]), ;
  125.          aScrollBar[ TB_COLTOP ] SAY TB_BACKGROUND
  126.       @ (nNewPosition + aScrollBar[ TB_ROWTOP ]), aScrollBar[ TB_COLTOP ] SAY ;
  127.         TB_HIGHLIGHT
  128.       aScrollBar[ TB_POSITION ] := nNewPosition
  129.    ENDIF
  130.  
  131.    SETCOLOR( cOldColor )
  132.  
  133.    RETURN ( aScrollBar )
  134.