home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / pow_tb.zip / TBSTACK2.PRG < prev    next >
Text File  |  1993-05-14  |  5KB  |  187 lines

  1.    /* tbStack2.prg: This is similar to tbStack1, with all supplier 
  2.    address details stacked vertically in column 2 of the browse 
  3.    display, but this one omits blank entries. It therefore has to 
  4.    dynamically vary the number of lines used to display each record.
  5.    Hot stuff! I was pleased when I got this to work!!
  6.    
  7.    Copyright (C) Dave Boettcher 1993. This source code, and functional 
  8.    fragments thereof, may only be distributed unchanged and as part of 
  9.    the file POWER_TB.ARJ. See POWER_TB.TXT for full copyright details.
  10.    
  11.    Last change:  14 May 93       6:52 pm
  12.    */
  13.    
  14.    #include "setcurs.ch"
  15.    #include "inkey.ch"
  16.    #include "box.ch"
  17.    
  18.    static nLines := 6
  19.    static nLineNumber := 1
  20.    static nLineLength := 20
  21.    
  22. function main()
  23.    
  24.    local oBrowse
  25.    local oColumn
  26.    local nKey
  27.    local lCont := .T.
  28.    local oldColour := setcolor("w+/b")
  29.    local oldCursor := setcursor(SC_NONE)   
  30.    
  31.    use supplier new
  32.    
  33.    clear screen
  34.    @ 0, 0, 24, 79 box B_DOUBLE
  35.    
  36.    oBrowse := tbrowsedb(1, 1, 23, 78)
  37.    oBrowse:headsep   := "─┬─"
  38.    oBrowse:colsep    := " │ "
  39.    oBrowse:goBottomBlock := { || dbGoBottom(), nLineNumber := nLines }
  40.    oBrowse:goTopBlock := { || dbGoTop(), nLineNumber := 1 }
  41.    oBrowse:skipBlock := { |n| multiskip(n) }
  42.    
  43.    oColumn := TBColumnNew("Name", {|| col1Conts() })
  44.    oColumn:width := 30
  45.    oColumn:footsep := "─┴─"
  46.    oBrowse:AddColumn(oColumn)
  47.    
  48.    oColumn := TBColumnNew("Details", {|| col2Conts() })
  49.    oColumn:width := nLineLength 
  50.    oColumn:footsep := "─┴─"
  51.    oBrowse:AddColumn(oColumn)
  52.    
  53.    do while lCont
  54.       
  55.       do while .not. oBrowse:stable .AND. (nKey := InKey()) == 0
  56.          oBrowse:Stabilize()
  57.       enddo
  58.       
  59.       if oBrowse:stable
  60.          if (oBrowse:hitTop .OR. oBrowse:hitBottom)
  61.             Tone(125,0)
  62.          endif
  63.          nKey := InKey(0)
  64.       endif
  65.       
  66.       Do Case
  67.          Case nKey == K_DOWN        ;  oBrowse:Down()
  68.          Case nKey == K_UP          ;  oBrowse:Up()
  69.          Case nKey == K_LEFT        ;  oBrowse:Left()
  70.          Case nKey == K_RIGHT       ;  oBrowse:Right()
  71.          Case nKey == K_PGDN        ;  oBrowse:PageDown()
  72.          Case nKey == K_PGUP        ;  oBrowse:PageUp()
  73.          Case nKey == K_CTRL_PGUP   ;  oBrowse:GoTop()
  74.          Case nKey == K_CTRL_PGDN   ;  oBrowse:GoBottom()
  75.          Case nKey == K_ESC         ;  lCont := .F.
  76.       endcase
  77.       
  78.    enddo
  79.    
  80.    setcolor(oldColour)
  81.    setcursor(oldCursor)
  82.    clear screen
  83.    
  84.    return nil
  85.    
  86.    
  87. function col1Conts()
  88.    
  89.    local cStr
  90.    
  91.    if nLineNumber == 1
  92.       cStr := supplier->name
  93.    else
  94.       cStr := " "
  95.    endif
  96.    
  97.    return cStr
  98.    
  99.    
  100. function col2Conts()
  101.    
  102.    local cStr
  103.    
  104.    do case
  105.       case nLineNumber == 1
  106.          cStr := supplier->street
  107.       case nLineNumber == 2
  108.          cStr := supplier->village
  109.       case nLineNumber == 3
  110.          cStr := supplier->town
  111.       case nLineNumber == 4
  112.          cStr := supplier->county
  113.       case nLineNumber == 5
  114.          cStr := supplier->postcode
  115.       case nLineNumber == 6
  116.          cStr := replicate("-", nLineLength) 
  117.    endcase
  118.    
  119.    return cStr
  120.    
  121.    
  122.    
  123. function MultiSkip( nRequested )
  124.    
  125.    local nAllowed := 0
  126.    
  127.    do case
  128.          
  129.       case nRequested == 0
  130.          
  131.          skip 0
  132.          
  133.       case nRequested > 0
  134.          
  135.          do while (!eof()) .and. nAllowed < nRequested
  136.             
  137.             nLineNumber++
  138.             nAllowed++
  139.             
  140.             if nLineNumber > 1 .and. nLineNumber < nLines
  141.                if empty(col2Conts())
  142.                   nAllowed--
  143.                endif
  144.             endif
  145.             
  146.             if nLineNumber > nLines
  147.                skip 1
  148.                nLineNumber := 1
  149.             endif
  150.             
  151.          enddo
  152.          
  153.          if eof()
  154.             nAllowed--
  155.             nLineNumber := nLines
  156.             skip -1
  157.          endif
  158.          
  159.       case nRequested < 0
  160.          
  161.          do while (!bof()) .and. nAllowed > nRequested
  162.             
  163.             nLineNumber--
  164.             nAllowed--
  165.             
  166.             if nLineNumber > 1 .and. nLineNumber < nLines
  167.                if empty(col2Conts())
  168.                   nAllowed++
  169.                endif
  170.             endif
  171.             
  172.             if nLineNumber == 0
  173.                skip -1
  174.                nLineNumber := nLines
  175.             endif
  176.             
  177.          enddo
  178.          
  179.          if bof()
  180.             nAllowed++
  181.             nLineNumber := 1
  182.          endif
  183.          
  184.    endcase
  185.    
  186.    return (nAllowed)
  187.