[futurebasic] WindowList

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

From: SVANVOORST@...
Date: Wed, 19 Dec 2001 21:04:36 EST
Thanks Tedd for your helpful comments.  A revised version follows: (watch for 
line wraps)

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

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

include "Tlbx Appearance.Incl"

_listElements = 32772'Num list elements
_listScrlBtn  = 11

dim gListRect    as rect
dim gLineHt      as short
dim gSelection   as long'Selected item
dim gScrollThumb as long
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(_listScrlBtn)'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 myHeaderRect  as rect
dim myFooterRect  as rect
dim myDoneBtn     as rect
dim wndWidth%     as int
dim wndHeight%    as int
local fn buildListWnd(left%,top%,listWidth%,headerHt%,footerHt%,visRows%)
window#-2,"WndList",(0,0)-(20,20),_dialogMovable'+_keepCtrlsActive'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) + footerHt%
window#-2,,@myWndRect'Redraw window - new size, location
wndPtr = window(_wndPointer)
LONG COLOR 56250,56670,56090,_false'Set background color (Gray)
wndWidth% = window(_width) : wndHeight% = window(_height)
EDIT FIELD#10,"Make 
selection.",(2,2)-(wndWidth%-4,headerHt%-3),_statNoFramed,_centerJust
setrect(gListRect,0,headerHt%+1,wndWidth%-17,wndHeight%-footerHt%-1)
setrect(myScrollRect,wndWidth%-17,headerHt%,wndWidth%-1,wndHeight%-footerHt%)
scroll button 
#_listScrlBtn,1,1,_listElements-(visRows%+1),visRows%,@myScrollRect,_scrollOth

er
if gScrollThumb > 1 then scroll button#_listScrlBtn,gScrollThumb
setrect(myHeaderRect,-1,headerHt%-2,wndWidth%,headerHt%+1)
button#9,_activeBtn,,@myHeaderRect,146'Btn Type 146 = Separator Line
setrect(myFooterRect,-1,wndHeight%-footerHt%-1,wndWidth%,wndHeight%-footerHt%+

2)
button#10,_activeBtn,,@myFooterRect,146'Btn Type 146 = Separator Line
setrect(myDoneBtn,wndWidth%-60,wndHeight%-footerHt%+4,wndWidth%-10,wndHeight%-

footerHt%+22)
button#12,_activeBtn,"Done",@myDoneBtn,_Push
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,_kThemeActi
veDialogBackgroundBrush,_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 long
local fn doMouse
top = button(11)'List scroll thumb position
getmouse(msPt)'Mouse click coordinates
long if fn ptinrect(msPt,gListRect)
lineSelected = (msPt.v% - gListRect.top%)/gLineHt'0 to visRows%-1
gSelection = top + lineSelected
gScrollThumb = button(_listScrlBtn)'Remember scroll position
window output(1)
edit$(2) =  gStringData$(gSelection)'Display selection in main window
window output(2)
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,26,6)
'(left%,top%,listWidth%,headerHt%,footerHt%,visRows%)
case 2'-- QUIT -- btn
end
case _listScrlBtn'-- LIST SCROLL -- btn
fn showList
case 12'-- DONE -- btn
window Close(2)'Close list window
setrect(gListRect,0,0,0,0)'And list rectangle
end select
case _wndClick
window#id%
select id%
case 2
scroll button#_listScrlBtn,gScrollThumb
end select
case _cursOver
select id%
case 0'Over window
cursor _arrowCursor
case > 0'Over button
cursor _arrowCursor
end select
CASE _wndClose
select id%
case 1'-- MAIN WINDOW --
END
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