home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a009 / 6.ddi / SAMPLE.LIF / SCROLBAR.PRG < prev    next >
Encoding:
Text File  |  1991-04-14  |  3.2 KB  |  121 lines

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