[futurebasic] WindowList

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 2001 : Group Archive : Group : All Groups

From: SVANVOORST@...
Date: Sun, 16 Dec 2001 23:09:21 EST
The following code is adapted from "Large List Display" by STAZ.  It creates 
a list in a self-sizing window (height only) based on the font.  List Manager 
is not used.  Please watch for line wraps.

'-------------- Start FB^3 Code --------------

//---- Original "Large List Display" by STAZ -------
//---- Modified by S.VanVoorst ---

include "Tlbx Appearance.Incl"

_listElements = 50'Num list elements

dim gListRect    as rect
dim gLineHt      as short
dim gSelection   as long'Selected item

dim 24 gStringData$(_listElements)'22 characters per string
dim wndPtr as pointer
end globals

local
dim itemRect as rect
dim count    as long
dim list$
local fn showList
itemRect = gListRect
itemRect.bottom% = gListRect.top% + gLineHt
count = button(10)'List scroll thumb position
do
long if count <= _listElements
list$ = gStringData$(count)
def cbox(itemRect,list$)'Center justified (LBOX,RBOX optional)
long if count = gSelection'Selected Line
invertrect(itemRect)
end if
end if
offsetrect(itemRect,0,gLineHt)
Inc(count)
until itemRect.top% => gListRect.bottom%
end fn

local 
dim myWndRect       as rect
dim myScrollRect    as rect
dim mySeparatorRect as rect
dim pageSize        as int
local fn buildListWnd(left%,top%,listWidth%,headerHt%,visRows%)
window#-2,"WndList",(0,0)-(20,20),_docNoGrow'Start with any size window
Text _sysFont,12,0'Declare Font
gLineHt = usr fontheight'Get font height
myWndRect.left% = left%'Location of list window
myWndRect.top% = top%
myWndRect.right% = left% + listWidth% + 17'Scroll space = 16 + 1
myWndRect.bottom% =  top% + headerHt% + (visRows%*gLineHt)
window#-2,,@myWndRect'Redraw window - new size, location
wndPtr = window(_wndPointer)
LONG COLOR 56250,56670,56090,_false'Set background color (Gray)
EDIT FIELD#10,"Make 
selection.",(2,2)-(window(_width)-4,headerHt%-3),_statNoFramed,_centerJust
setrect(gListRect,0,headerHt%,window(_width)-16,window(_height))
setrect(myScrollRect,window(_width)-16,headerHt%,window(_width),window(_height

))
pageSize = Window(_height)/gLineHt
scroll button #10,1,1,_listEle
ments-(visRows%)+1,pageSize,@myScrollRect,_scrollOther
setrect(mySeparatorRect,-1,HeaderHt%-2,window(_width),headerHt%+1)
button#9,_activeBtn,,@mySeparatorRect,146'Btn Type 146 = Separator Line
window#2
end fn

local
dim x as long
local fn loadList$
for x = 1 to _listElements
gStringData$(x) = "Item "+str$(x)
next
end fn

local
dim err
LOCAL FN buildMainWnd
WINDOW#-1,"Main window",(0,0)-(300,150),_docNoGrow
wndPtr = WINDOW(_wndPointer) : if wndPtr = _nil then exit fn
edit field#2,"",(122,40)-(240,60),_statFramed,_centerJust'Display EF
err = FN 
SetThemeWindowBackground(wndPtr,_kThemeActiveDialogBackgroundBrush,_true)
text _sysFont,12,0
edit field#1,"You selected",(30,40)-(120,60),_statNoFramed,_centerJust
button#1,_activeBtn,"Show List",(100,80)-(200,100),_shadow
button#2,_activeBtn,"Quit",(220,120)-(280,140),_push
fn loadList$
window#1
END FN

local
dim top as long
dim msPt as point
dim lineSelected as int
local fn doMouse
top = button(10)'List scroll thumb position
getmouse(msPt)'Mouse click coordinates
long if fn ptinrect(msPt,gListRect)
lineSelected = (msPt.v% - gListRect.top%)/gLineHt
gSelection = top + lineSelected
edit$(10) = "Selected = " + gStringData$(gSelection)
fn showList
end if
end fn

local
dim evnt%
dim id%
dim err
LOCAL FN doDialog
evnt%=DIALOG(0)
id%=DIALOG(evnt)
SELECT evnt
case _wndRefresh
select id%
case 1'-- MAIN WINDOW --
err = fn drawthemeedittextframe(#[tehandle(2)],_true)'Display EF Frame
case 2'-- LIST WINDOW --
fn showList
end select
case _btnClick
select id%
case 1'-- SHOW LIST -- btn
fn buildListWnd(300,300,120,25,6)'(left%,top%,listWidth%,headerHt%,visRows%)
case 2'-- QUIT -- btn
end
case 10'-- LIST SCROLL -- btn
fn showList
end select
CASE _wndClose
select id%
case 1'-- MAIN WINDOW --
END
case 2'-- LIST WINDOW --
window Close(2)'Close list window
edit$(2) =  gStringData$(gSelection)'Display selection in main window
end select
END SELECT
END FN

fn buildMainWnd
on dialog fn doDialog
on mouse fn doMouse
DO
HANDLEEVENTS
UNTIL 0

'---------------- End of Code ---------

Steve Van Voorst