IonicWind Software

Creative Basic => General Questions => Topic started by: GWS on November 06, 2008, 04:32:23 AM

Title: Unlimited edit boxes & Edit-in-Place Grid
Post by: GWS on November 06, 2008, 04:32:23 AM
This is a resurrection of Larry Adcock's original post in 2002 ..

It should give many useful ideas to today's users ..


' Edit-in-Place Grid demo by L a r r y A d c o c k
'==== Uses only ONE edit control! ====================
' Concept can also be used for any program that needs a
' large number of edit boxes by placing them individually
' rather than by a loop.

' Posted: Nov 03, 2002
' Unlimited edit boxes & Edit-in-Place Grid
type edboxtype
def l:int
def t:int
def w:int
def h:int
def text:string
endtype

DEF edbox[80]:edboxtype
DEF win:WINDOW
DEF new_edbox,current_edbox, aaa,aa,bb,cc,dd:int
DEF colwid,rowht:int
WINDOW win, 10, 10, 610, 390, @caption, 0, "Larry's Little Edit-in-Place Grid", main
CONTROL win, "e,,0,0,100,25,0,1"
setcontrolcolor win, 1, rgb(0,0,0), rgb(240,240,255)

colwid=120: rowht=25
'define edbox locations, sizes, and some initial contents
aaa=0
for cc=0 to 4
for dd=0 to 13
edbox[aaa].l=(cc*colwid)+5: edbox[aaa].t=(dd*rowht)+5
edbox[aaa].w=colwid: edbox[aaa].h=rowht
aaa=aaa+1
next dd
next cc
edbox[0].text="Hill": edbox[14].text="Phil": edbox[28].text="USA"
edbox[1].text="Andretti": edbox[15].text="Mario": edbox[29].text="USA"
edbox[2].text="Villeneuve": edbox[16].text="Jacques": edbox[30].text="Canada"
edbox[3].text="Montoya": edbox[17].text="Juan Pablo": edbox[31].text="Columbia"

for cc=0 to 13
rect win, -1,(2*cc*rowht)+4,1800,(rowht+1)
next cc
for cc=0 to 2
rect win,(2*cc*colwid)+2,-1,colwid+1,1200
next cc


'display 70 edboxes
for aaa=0 to 69
move win, edbox[aaa].l,edbox[aaa].t
print win, edbox[aaa].text
next aaa

'set initial edit control position
mx=5: my=5
new_edbox=0
current_edbox=0: aaa=current_edbox
setsize win, edbox[aaa].l-3, edbox[aaa].t, edbox[aaa].w, edbox[aaa].h+2,1
setcontroltext win, 1, edbox[aaa].text
run = 1:WAITUNTIL run = 0:CLOSEWINDOW win:END

SUB main
SELECT @CLASS
CASE @IDCLOSEWINDOW
run = 0
CASE @IDLBUTTONDN
gosub edbox_hitcheck
CASE @IDMOUSEMOVE
mx=@mousex : my=@mousey
ENDSELECT
RETURN

SUB edbox_hitcheck
for bb=0 to 69
if (mx>edbox[bb].l) & (mx<(edbox[bb].l+edbox[bb].w)) & (my>edbox[bb].t) & (my<(edbox[bb].t+edbox[bb].h))
new_edbox=bb
gosub editmover
endif
next bb
RETURN

SUB editmover
edbox[current_edbox].text=getcontroltext(win,1)
g$=getcontroltext(win,1)
aa=new_edbox
rect win, edbox[current_edbox].l, edbox[current_edbox].t+1, edbox[current_edbox].w-4, edbox[current_edbox].h-3, rgb(255,255,255),rgb(255,255,255)
move win,edbox[current_edbox].l,edbox[current_edbox].t
print win , g$
current_edbox=new_edbox
setsize win, edbox[aa].l-3, edbox[aa].t, edbox[aa].w, edbox[aa].h+2,1
setcontroltext win, 1, edbox[aa].text
SETFOCUS win, 1
RETURN



all the best, :)

Graham