; $VER: EasyListview.bb2 1.0 (2.1.1999) James L Boyd

; include EVERYTHING between the -------s at top of your code!


;* * * * * * * * * * * * * * * * * * * * * * * * * *

; important comments have been boxed in like this!

;* * * * * * * * * * * * * * * * * * * * * * * * * *


;----------------------------------------------------------------

NEWTYPE .lst
  number.w:string.s
End NEWTYPE

DONE_FIRST.b=0

Gosub buildlist
Goto skipfirst

.buildlist

If DONE_FIRST=False

TOTAL=5

Dim item$(TOTAL)

; fill item$(x) up any old way you like :)

; here's a demo :

item$(1)  ="Hello, this is an EasyListView!"
item$(2)  ="It's really easy to do this!"
item$(3)  ="Even I can do it!"
item$(4)  ="That says a lot..."
item$(5)  ="I'm trying to fill below the view..."

EndIf

Dim List lname.lst (TOTAL)

For readem.w=1 To TOTAL
  If AddItem(lname())

;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    lname()\string =  item$(readem) ; add item to list

;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  EndIf
Next readem

Return

.skipfirst

Statement SetupLV{}
  #LISTVIEWIDCMP=#GADGETUP|#GADGETDOWN|#INTUITICKS|#MOUSEBUTTONS|#MOUSEMOVE
  AddIDCMP #LISTVIEWIDCMP
End Statement

Statement EasyListView {no.w,x.w,y.w,w.w,h.w,name$}
  SHARED lname()
  GTTags #GTLV_ShowSelected,0
  GTListView 0,no,x,y,w,h,name$,$8,lname()
End Statement

Function.s ReadItem{}
  SHARED lname()
  item$=lname(EventCode)\string
Function Return item$
End Function

Statement ClearLV {no.w}

  SHARED lname ()
  GTChangeList 0,no
  ClearList lname()
  GTChangeList 0,no,lname()

End Statement

;----------------------------------------------------------------

FindScreen 0 ; get frontmost screen

*scr.Screen=Peek.l(Addr Screen(0)) ; get screen info...
hite.w=*scr\BarHeight+1            ; ...for the title bar height

; set messages to be received from listview :

SetupLV{} ; call before opening window which holds listview

; setup gadgets...including EasyListview{} :

GTButton 0,51,0,65,200,hite+5,"Clear Listview",$10

EasyListView {50,0,0,400,50,"EasyListview"}
;              ^ ^  ^  ^   ^   ^      ^
;              | |  |  |   |   |      l Title for listview
;              | |  |  |   |   |
;              | |  |  |   |   l Height of listview
;              | |  |  |   |
;              | |  |  |   l Width of listview
;              | |  |  |
;              | |  |  l Y position of listview
;              | |  |
;              | |  l X position of listview
;              | |
;              | l Window to stick listview in
;              |
;              l Listview gadget number (ALWAYS 50+ !)

; to put it into the very top-left of a GimmeZeroZero window,
; use x=-WleftOff and y=-hite ! Use 0,0 if it's a non-GimmeZeroZero
; window...

Window 0,(ScreenWidth/2)-225,(ScreenHeight/2)-60,450,120,$140f,"EasyListView Demo",1,2

AttachGTList 0,0

loop
Select WaitEvent

  Case $40
    Select GadgetHit
      Case 50 ; easylistview
        Request "",ReadItem{},"OK" ; ReadItem {} function gets string...
      Case 51
        ClearLV {50}
        DONE_FIRST=True
        Gosub rebuilditems
        GTChangeList 0,50
        Gosub buildlist
        GTChangeList 0,50,lname()
    End Select

  Case $200
    End

End Select

Goto loop

End

.rebuilditems

; here's where you redefine your items :

TOTAL=15      ; MUST use the TOTAL variable as it's
              ; used by the buildlist routine...

Dim item$(TOTAL)

; fill item$(x) up any old way you like :)

; here's a demo :

item$(1)  ="Hello, this is an EasyListView!"
item$(2)  ="It's really easy to do this!"
item$(3)  ="Even I can do it!"
item$(4)  ="That says a lot..."
item$(5)  ="I'm trying to fill below the view..."
item$(6)  ="Nearly there I think..."
item$(7)  ="Unless you're using..."
item$(8)  ="A REALLY BIG FONT!"
item$(9)  ="But that would be stupid..."
item$(10) ="And so on..."
item$(11) ="Even more stuff down here now!"
item$(12) ="I'm running out of ideas..."
item$(13) ="Am I nearly there yet?"
item$(14) ="I think so..."
item$(15) ="Ah, that's it!"

Return
