REM ListSelector
' These three subroutines make up a simple list selection requestor
' Define the list selector with ListSelector
' Initialize the requestor with SetList
' Make selections by calling GetSelection
'
' These subroutines require the Intuits subroutines for gadgets
'
SUB ListSelector(x%,y%,kw$(1),idx%(1),title$,dx%)
' x% = horizontal pixel offset to locate selector
' y% = vertical pixel offset to locate selector
' kw$() = 1 dimensional array containing list elements (Max. 20 chars.)
' idx%() = 1 dimensional array to hold subscripts to kw$() (returned values)
' title$ = a title string (25 characters)
' dx% = beginning gadget number
'
' List Selector is 230 pix wide by 105 pix high
'
' Requires use of Intuits.SUB/Intuits.Header
'
	SHARED x1%(),y1%()
	j%=y%+18 : BoxIndex%=dx% : count%=0 : numsel%=0 : tj%=0 : tot%=0 : Ptr%=0
	nk%=n%-(n% MOD 6)
	LINE (x%,y%+3)-(x%+230,y%+105),3,b
	LINE (x%+2,y%+4)-(x%+229,y%+104),2,b
	LINE (x%+3,y%+4)-(x%+228,y%+104),2,b
	LINE (x%+6,y%+6)-(x%+225,y%+102),1,bf
	LINE (x%+10,j%+3)-(x%+200,j%+64),2,bf
	COLOR 3,1,0
	PRINT PTAB(x%+((230-LEN(title$)*8)/2),y%+16);title$
	COLOR 2,1,0
	FOR i%=1 TO 6
		INCR count%
		PRINT PTAB(x%+18,j%+10*count%) : CALL SmallTxGad(SPACE$(20))
	NEXT i%
	COLOR 0,1,0
	' Make UP arrow
	area (x%+214,y%+22)
	area step (9,4)
	area step (-19,0)
	area step (9,-4)
	areafill 0
	line (x%+214,y%+27)-(x%+214,y%+30),0
	' Make DOWN arrow
	area (x%+214,y%+80)
	area step (-10,-4)
	area step (19,0)
	area step (-9,4)
	areafill 0
	line (x%+214,y%+72)-(x%+214,y%+75),0
	COLOR 0,1,0
	PRINT PTAB(x%+202,y%+29) : CALL SmallTxBox(" ")
	PRINT PTAB(x%+8,y%+95) : CALL SmallTxBox("OK")
	PRINT PTAB(x%+159,y%+95) : CALL SmallTxBox("Cancel")
	PRINT PTAB(x%+202,y%+79) : CALL SmallTxBox(" ")
	COLOR 2,1,0
END SUB
SUB SetList(k$(1),ix%(1),m%,w%,l%,nk%,tot%,n%)
'm% = beginning gadget number, usually 1
'n% = number of elements in array k$()
'all other parameters are passed from GetSelection
'
	SHARED x1%(),y1%()	'from gadgets subroutines
		w%=l%*6
		lj%=l%+1
		IF nk%=0 THEN
			kk%=n% MOD 6
			DECR lj%
		END IF
		COLOR 2,2,1
		FOR i%=m% TO m%+5
			PRINT PTAB(x1%(i%)-8,y1%(i%)+8);SPACE$(23)
		NEXT i%
		COLOR 1,2,0
		FOR i%=m% TO m%+5
			PRINT PTAB(x1%(i%)+8,y1%(i%)+8);k$(i%+w%-m%)
			FOR jj%=1 TO tot%
				IF ix%(jj%)-w%+1=i% THEN
					CALL CheckBox(i%,1)
				END IF
			NEXT jj%
			COLOR 1,2,0
		NEXT i%
END SUB
SUB GetSelection(kw$(),idx%(),m%,w%,l%,nk%,tot%,n%,numsel%)
'n% = number of elements in array kw$()
'numsel% = returns the number of selected items
'idx%() = contains index of array elements selected
'm% = beginning gadget number
'other parameters are needed to pass to SetList
'
	start%=m%-1
	nk%=n%-(n% MOD 6)
	DO
		CALL WaitBox(which%)
		CALL FlashRelease(which%)
		SELECT CASE which%
			CASE start%+10
				nk%=nk%-6
				IF l%<n%\6 THEN INCR l%
				CALL SetList(kw$(),idx%(),1,w%,l%,nk%,tot%,n%)
			CASE start%+9
				COLOR 0,1,0
				FOR i%=1 TO n%
					idx%(i%)=-1
				NEXT i%
				CALL SetList(kw$(),idx%(),1,w%,l%,nk%,tot%,n%)
				numsel%=0
				COLOR 1,0,1
				EXIT SUB
			CASE start%+8
				COLOR 1,0,1
				FOR jj%=1 TO tot%
					IF idx%(jj%)=-1 THEN
						INCR Ptr%
					ELSE
						idx%(jj%-Ptr%)=idx%(jj%)
						INCR numsel%
					END IF
				NEXT jj%
				EXIT SUB
			CASE start%+7
				nk%=nk%+6
				IF l%>0 THEN DECR l%
				CALL SetList(kw$(),idx%(),1,w%,l%,nk%,tot%,n%)
			CASE start%+1 TO start%+6
				IF which%<>last% THEN INCR tot%
				CALL CheckBox(which%,1)
				FOR tj%=1 TO tot%
					IF idx%(tj%)=which%+w%-m% THEN
						idx%(tj%)=-1
						tj%=1
						EXIT SELECT
					END IF
				NEXT tj%
				idx%(tot%)=which%+w%-m%
				last%=which%
		END SELECT
	LOOP
END SUB

