[futurebasic] RE: [FB] Appearance button edit fields

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 2007 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Fri, 25 May 2007 21:17:19 -0400
Dennis wrote:

>Thanks Brian. I am home and got Steve Van Voorst assistance prior to leaving
>and program is complete. Thanks all.


That Steve is Fast (no punt intended)!

And just as I was having fun.

Ken


include "Subs Help tags.Incl"

#define FMFontFamily as SInt16
toolbox fn FMGetFontFamilyFromName(Str255 iName) = FMFontFamily

_colsInGrid = 5
_rowsInGrid = 5

begin record gridBuilder
dim as long startID
dim as long incrementID
dim as long x
dim as long y
dim as long howWide
dim as long howHigh
dim as long cols
dim as long rows
dim as long horzGap
dim as long vertGap
end record

begin record cellInfo
dim as long  fieldID
dim as str31 cellWord
end record

dim as cellInfo  gridCell( _colsInGrid, _rowsInGrid )

gridCell.cellWord( 1, 1 ) = "anchor"
gridCell.cellWord( 1, 2 ) = "dot"
gridCell.cellWord( 1, 3 ) = ""
gridCell.cellWord( 1, 4 ) = "plum"
gridCell.cellWord( 1, 5 ) = "pilgrim"
gridCell.cellWord( 2, 1 ) = "sew"
gridCell.cellWord( 2, 2 ) = ""
gridCell.cellWord( 2, 3 ) = "line"
gridCell.cellWord( 2, 4 ) = "steer"
gridCell.cellWord( 2, 5 ) = "mess"
gridCell.cellWord( 3, 1 ) = "mass"
gridCell.cellWord( 3, 2 ) = "band"
gridCell.cellWord( 3, 3 ) = "cares"
gridCell.cellWord( 3, 4 ) = ""
gridCell.cellWord( 3, 5 ) = "pure"
gridCell.cellWord( 4, 1 ) = "his"
gridCell.cellWord( 4, 2 ) = "rustles"
gridCell.cellWord( 4, 3 ) = ""
gridCell.cellWord( 4, 4 ) = "gal"
gridCell.cellWord( 4, 5 ) = "bus"
gridCell.cellWord( 5, 1 ) = "canvas"
gridCell.cellWord( 5, 2 ) = "we"
gridCell.cellWord( 5, 3 ) = "but"
gridCell.cellWord( 5, 4 ) = "hand"
gridCell.cellWord( 5, 5 ) = "campus"

local fn BuildEditTextGridByRow( grid as .gridBuilder )
dim as rect    r
dim as long    i, j, cellID
dim as str255  s, helpStr
dim as ControlFontStyleRec tfs

tfs.flags           = _kControlUseFontMask¬
                       _kControlUseSizeMask¬
                       _kControlUseFaceMask¬
                       _kControlUseJustMask¬
                  _kControlUseBackcolorMask¬
                  _kControlUseForecolorMask
tfs.font            = fn FMGetFontFamilyFromName("Arial")
tfs.size            = 10
tfs.style           = _boldBit%
tfs.just            = _teJustCenter

tfs.forecolor.red   = 0
tfs.forecolor.green = 0
tfs.forecolor.blue  = 65535

tfs.backcolor.red   = 65535
tfs.backcolor.green = 65535
tfs.backcolor.blue  = 65535

setrect( r, grid.x, grid.y, grid.x +¬
  grid.howWide, grid.y + grid.howHigh )
if grid.incrementID = 0 then grid.incrementID = 1
cellID = grid.startID

for i = 1 to grid.rows
for j = 1 to grid.cols
// Store the id of each Text Edit button in the array
gridCell.fieldID( j, i ) = cellID

appearance button cellID, _activeBtn,¬
,,,, @r,_kControlEditTextProc
def SetButtonFontStyle(  cellID, tfs )
s = "Col:" + str$( j ) + " Row:" + str$( i )
def SetButtonTextString( cellID, s  )
helpStr = "Help string for Cell No." + str$( cellID )
def ButtonHelpSetText(   cellID, helpStr )
offsetrect( r, grid.howWide + grid.vertGap, 0 )
cellID++
next j
offsetrect( r, -(( grid.howWide + grid.vertGap) *¬
  grid.cols), grid.howHigh + grid.horzGap )
next i

end fn


local fn FillGridWithTestWords
dim as long  i, j, fieldID
dim as str31 wordStr
dim as ControlFontStyleRec tfs

tfs.flags = _kControlUseFontMask¬
        _kControlUseBackcolorMask¬
        _kControlUseForecolorMask

for i = 1 to _colsInGrid
for j = 1 to _rowsInGrid

fieldID = gridCell.fieldID( i, j )
wordStr = gridCell.cellWord( i, j )

long if ( wordStr[0] )

tfs.forecolor.red   = 65535
tfs.forecolor.green = 0
tfs.forecolor.blue  = 0

tfs.backcolor.red   = 65535
tfs.backcolor.green = 65535
tfs.backcolor.blue  = 65535

def SetButtonFontStyle(  fieldID, tfs )
def SetButtonTextString( fieldID, wordStr  )

xelse

tfs.forecolor.red   = 0
tfs.forecolor.green = 0
tfs.forecolor.blue  = 0

tfs.backcolor.red   = 0
tfs.backcolor.green = 0
tfs.backcolor.blue  = 0

def SetButtonFontStyle(  fieldID, tfs )
def SetButtonTextString( fieldID, wordStr  )

end if
next j
next i

end fn


local fn BuildWindow
dim as rect        r
dim as gridBuilder grid

setrect( r, 0, 0, 505, 200 )
window -1, "Colored Grids and Text", @r, _docNoGrow

setrect( r, 160, 160, 495, 180 )
button 100, _activeBtn,¬
"Fill grid with words (empty cells in black)...", @r, _push

grid.startID     =  1
grid.incrementID =  1
grid.x           = 10
grid.y           = 10
grid.howWide     = 90
grid.howHigh     = 20
grid.cols        =  _colsInGrid
grid.rows        =  _rowsInGrid
grid.horzGap     =  8
grid.vertGap     =  8

fn BuildEditTextGridByRow( grid )

window 1

end fn


local fn ClearFocus
dim as OSErr err

err = fn ClearKeyboardFocus( window( _wndRef ) )

end fn


local fn DetectClickInField( fieldID as long )
dim as ControlFontStyleRec tfs

long if ( fieldID < 100 )
long if ( fn ButtonTextString$( fieldID ) )
fn ClearFocus
exit fn
xelse

tfs.flags = _kControlUseFontMask¬
        _kControlUseBackcolorMask¬
        _kControlUseForecolorMask

tfs.forecolor.red   = 0
tfs.forecolor.green = 0
tfs.forecolor.blue  = 0

tfs.backcolor.red   = 65535
tfs.backcolor.green = 65535
tfs.backcolor.blue  = 65535

def SetButtonFontStyle(  fieldID, tfs )
def SetButtonTextString( fieldID, ""  )

end if
end if

end fn


local fn DoDialog
dim as long  evnt, id

_crReturn = 13

evnt = dialog(0)
id = dialog(evnt)

select case( evnt )
case _wndRefresh
print "Width:"; window( _width); " Height"; window( _height )
case _wndClose : end
case _btnClick
select( id )
fn DetectClickInField( id )
case 100
fn FillGridWithTestWords
fn ClearFocus
end select
case 16
select ( id )
case _crReturn
fn ClearFocus
end select
end select

end fn

on dialog fn DoDialog

fn BuildWindow

do
handleevents
until gFBQuit