home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / alt / sources / 2903 / rn100src.exe / BROWSENG.PRG next >
Encoding:
Text File  |  1992-12-15  |  3.6 KB  |  149 lines

  1. #include "marislib.ch"
  2. #include "inkey.ch"
  3. #include "rn.ch"
  4.  
  5. FUNCTION BrowseNewsgroup(nTop, nLeft, nBottom, nRight, a)
  6.  
  7.    LOCAL b:= TBrowseNew(nTop, nLeft, nBottom, nRight)
  8.    LOCAL i:= 1
  9.    LOCAL nKey
  10.    LOCAL lSavReadexit := readexit(.t.)
  11.    LOCAL bUdf
  12.    LOCAl bColumn
  13.  
  14.    KeyBar({" = Select", "─┘ = Read", "Space or Tab = Read new", "Esc = Exit", "F1 = Help"}, CLR_HDR)
  15.    b:colorspec := "bg+/b, n/bg, bg+/b, bg+/b, bg+/b, gr+/b, gr+/bg"
  16.  
  17.    bColumn := TBColumnNew("", {|| padr(" " + padr(a[i,1],60) + " " + if (a[i,4] > 0, "(" + str(a[i,4],4) + ")", space(6)) + if(a[i,3] > 0, str(a[i,3],4), space(4)), 80) })
  18.    b:addColumn( bColumn )
  19.    bColumn:colorBlock := {|x| if( a[i,4] > 0, { 6, 7}, {1, 2}) }
  20.  
  21.    bUdf := {|a, b, nKey, i|UdfBrowseNewsgroup(a, b, nKey, i)}
  22.  
  23.    b:goTopBlock := { ||i := 1 }
  24.    b:goBottomBlock := { || i := len(a) }
  25.    b:skipBlock := {|n, si| si := i, ;
  26.                         i := if(n > 0, ;
  27.                            min(len(a), i + n), ;
  28.                            max (1, i+n)), ;
  29.                         i -si }
  30.    b:freeze := 1
  31.  
  32.  
  33.    do while nKey != K_ESC
  34.       while ! b:stabilize()
  35.       enddo
  36.  
  37.       IF b:hitTop .OR. b:hitBottom
  38.          sound(3500, 10, 80, 25)
  39.       ENDIF
  40.  
  41.       // Make sure that the current record is showing
  42.       // up-to-date data in case we are on a network.
  43.       b:refreshCurrent()
  44.       ForceStable(b)
  45.  
  46.       nKey := inkey(0)
  47.       b := eval(bUdf, a, b, nKey, i)
  48.    enddo
  49.    readexit (lSavReadexit)
  50. RETURN (a)
  51.  
  52.  
  53.  
  54. STATIC FUNCTION UDFBrowseNewsgroup (a,   ;     // array
  55.                 b,   ;     // TBrowse object
  56.                 nKey,;     // key pressed
  57.                 i    ;     // current position within array
  58.                 )
  59.    LOCAl aMsg
  60.    LOCAL n
  61.    LOCAL nSavPos
  62.  
  63.    do case
  64.       case chr(nKey) == 'p'
  65.          NwsPost(a[i,1])
  66.  
  67.       case nKey == asc("P")
  68.          pmail()
  69.  
  70.       case chr(nKey) == '!'
  71.          shell()
  72.  
  73.       case nKey == K_DOWN
  74.          b:down()
  75.  
  76.       case nKey == K_PGDN
  77.          b:pageDown()
  78.  
  79.       case nKey == K_PGUP
  80.          b:pageUp()
  81.  
  82.       case nKey == K_CTRL_PGDN
  83.          b:goBottom()
  84.  
  85.       case nKey == K_CTRL_PGUP
  86.          b:goTop()
  87.  
  88.       case nKey == K_HOME
  89.          b:gotop()
  90.  
  91.       case nKey == K_END
  92.          b:gobottom()
  93.  
  94.       case nKey == K_CTRL_LEFT
  95.          b:left()
  96.  
  97.       case nKey == K_CTRL_RIGHT
  98.          b:right()
  99.  
  100.       case nKey == K_UP
  101.          b:up()
  102.  
  103.       case nKey == K_SPACE .or. nKey == K_TAB
  104.             nSavPos := i
  105.             while i <= len(a)
  106.                if a[i, 4] > 0
  107.                   aMsg := ReadNewsgroup(a[i,1], READ_NG_NORMAL)
  108.                   a[i, 4] := 0
  109.                   for n := 1 to len(aMsg)
  110.                      if IsNew(aMsg[n, 4])
  111.                         a[i, 4] ++
  112.                      endif
  113.                   next
  114.                   EXIT
  115.                endif
  116.                ++i
  117.             enddo
  118.  
  119.             if i # len(a)
  120.                for n := nSavPos to i
  121.                   b:down()
  122.                next
  123.             endif
  124.  
  125.             b:refreshall()
  126.             forcestable( b )
  127.  
  128.       case nKey == K_RETURN
  129.          aMsg := ReadNewsgroup(a[i,1], READ_NG_NORMAL)
  130.          a[i, 4] := 0
  131.          for n := 1 to len(aMsg)
  132.             if IsNew(aMsg[n, 4])
  133.                a[i, 4] ++
  134.             endif
  135.          next
  136.  
  137.       case chr(nKey) == "c"   // catchup
  138.          if a[i,4] > 0
  139.             ReadNewsgroup(a[i,1], READ_NG_CATCHUP)
  140.             a[i,4] := 0
  141.             b:refreshcurrent()
  142.             ForceStable(b)
  143.          endif
  144.    endcase
  145.  
  146. RETURN (b)
  147.  
  148.  
  149.