home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / c / cliptree.zip / SCROLBAR.PRG < prev    next >
Text File  |  1993-02-04  |  3KB  |  123 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. #ifdef USEMETWO
  16. /***
  17. *  ScrollBarNew( <nTopRow>, <nTopColumn>, <nBottomRow>, 
  18. *     <cColorString>, <nInitPosition> ) --> aScrollBar
  19. *  
  20. *  Create a new scroll bar array with the specified coordinates
  21. *
  22. */
  23. FUNCTION ScrollBarNew( nTopRow, nTopColumn, nBottomRow, ;
  24.                         cColorString, nInitPosition )
  25.  
  26.    LOCAL aScrollBar := ARRAY( TB_ELEMENTS )
  27.  
  28.    aScrollBar[ TB_ROWTOP ]    := nTopRow
  29.    aScrollBar[ TB_COLTOP ]    := nTopColumn
  30.    aScrollBar[ TB_ROWBOTTOM ] := nBottomRow
  31.    aScrollBar[ TB_COLBOTTOM ] := nTopColumn
  32.  
  33.    // Set the default color to White on Black if none specified
  34.    IF cColorString == NIL
  35.       cColorString := "W/N"
  36.    ENDIF
  37.    aScrollBar[ TB_COLOR ]     := cColorString
  38.  
  39.    // Set the starting position
  40.    IF nInitPosition == NIL
  41.       nInitPosition := 1
  42.    ENDIF
  43.    aScrollBar[ TB_POSITION ]  := nInitPosition
  44.  
  45.    RETURN aScrollBar
  46. #endif
  47.  
  48. /***
  49. *  ScrollBarDisplay( <aScrollBar> ) --> aScrollBar
  50. *  Display a scoll bar array to the screen
  51. *
  52. */
  53. FUNCTION ScrollBarDisplay( aScrollBar )
  54.    LOCAL cOldColor, nRow
  55.  
  56.    cOldColor := SETCOLOR( aScrollBar[ TB_COLOR ] )
  57.  
  58.    // Draw the arrows
  59.    @ aScrollBar[ TB_ROWTOP ], aScrollBar[ TB_COLTOP ] SAY TB_UPARROW
  60.    @ aScrollBar[ TB_ROWBOTTOM ], aScrollBar[ TB_COLBOTTOM ] SAY TB_DNARROW
  61.  
  62.    // Draw the background
  63.    FOR nRow := (aScrollBar[ TB_ROWTOP ] + 1) TO (aScrollBar[ TB_ROWBOTTOM ] - 1)
  64.       @ nRow, aScrollBar[ TB_COLTOP ] SAY TB_BACKGROUND
  65.    NEXT
  66.  
  67.    SETCOLOR( cOldColor )
  68.  
  69.    RETURN aScrollBar
  70.  
  71. /***
  72. *  ScrollBarUpdate( <aScrollBar>, <nCurrent>, <nTotal>,
  73. *     <lForceUpdate> ) --> aScrollBar
  74. *
  75. *  Update scroll bar array with new tab position and redisplay tab
  76. *
  77. */
  78. FUNCTION ScrollBarUpdate( aScrollBar, nCurrent, nTotal, lForceUpdate )
  79.  
  80.    LOCAL cOldColor, nNewPosition
  81.    LOCAL nScrollHeight := (aScrollBar[TB_ROWBOTTOM] - 1) - ;
  82.          (aScrollBar[TB_ROWTOP])
  83.  
  84.    IF nTotal < 1
  85.       nTotal := 1
  86.    ENDIF
  87.  
  88.    IF nCurrent < 1
  89.       nCurrent := 1
  90.    ENDIF
  91.  
  92.    IF nCurrent > nTotal
  93.       nCurrent := nTotal
  94.    ENDIF
  95.  
  96.    IF lForceUpdate == NIL
  97.       lForceUpdate := .F.
  98.    ENDIF
  99.  
  100.    cOldColor := SETCOLOR( aScrollBar[ TB_COLOR ] )
  101.  
  102.    // Determine the new position
  103.    nNewPosition := ROUND( (nCurrent / nTotal) * nScrollHeight, 0 )
  104.  
  105.    // Resolve algorythm oversights
  106.    nNewPosition := IF( nNewPosition < 1, 1, nNewPosition )
  107.    nNewPosition := IF( nCurrent == 1, 1, nNewPosition )
  108.    nNewPosition := IF( nCurrent >= nTotal, nScrollHeight, nNewPosition )
  109.  
  110.    // Overwrite the old position (if different), then draw in the new one
  111.    IF nNewPosition <> aScrollBar[ TB_POSITION ] .OR. lForceUpdate
  112.       @ (aScrollBar[ TB_POSITION ] + aScrollBar[ TB_ROWTOP ]), ;
  113.          aScrollBar[ TB_COLTOP ] SAY TB_BACKGROUND
  114.       @ (nNewPosition + aScrollBar[ TB_ROWTOP ]), aScrollBar[ TB_COLTOP ] SAY ;
  115.         TB_HIGHLIGHT
  116.       aScrollBar[ TB_POSITION ] := nNewPosition
  117.    ENDIF
  118.  
  119.    SETCOLOR( cOldColor )
  120.  
  121.    RETURN aScrollBar
  122.  
  123.