* array grid - actually created on the fly, one textbox per array element. * v1.0, 4. aug 1999 - just got it to work, size the textboxes and look decently. *[2007/06/28 17:37:37] dragan - added the parameter * Author: Dragan Nedeljkovic * Alas LTD, Zrenjanin, Yugoslavia PARAMETERS taArray #define c_clib "" #define c_textbox 'textbox' #define c_checkbox 'checkbox' #define c_editbox 'editbox' if !empty(c_clib) set classlib to c_clib addi endif oArrForm=createobj("form") oArrForm.ShowTips=.t. oArrForm.addobject("oACont", "ArrCont", "taArray") with oArrForm .height=min(.oACont.height, _screen.height-100) .width=min(.oACont.width, _screen.height-100) endwith with oArrForm.oACont .top=0 .left=0 .visible=.t. endwith oArrForm.show(1) * read events * disp memo like taArray define class ArrCont as Container Name = "ArrCont" * one textbox for each array element DIMENSION aobj[1] DoCreate = .T. * copy the parameter here cArrayName="" nRows=0 nCols=0 NextRow=0 NextCol=0 lClicked=.f. PROCEDURE Init lPara laArray SET STEP ON this.cArrayName=laArray local i,j, nColWidths[1], lcSource, ; nMaxWidth, nMaxHeight, nLastLeft, nLastTop This.nRows=alen((laArray),1) This.nCols=alen((laArray),2) ? this.nrows, this.ncols, "rows, cols" dime this.aObj[This.nRows, This.nCols] this.aObj=.null. for i=1 to This.nRows for j=1 to This.nCols * I had some plan for different objects for different sorts of data, like checkboxes for logicals * but a plain old textbox is quite ok for most of the stuff cType=type(laArray+'[i,j]') do case case inlist(cType, 'C', 'N', 'Y', 'D', 'T') lClass='Atextbox' case cType='L' lClass='Acheckbox' other lClass='Atextbox' endc this.addobject("This.aobj[i,j]", lClass,i,j) with this.aobj[i,j] * we could put lcCSource=laArray+"["+allt(str(i))+','+allt(str(j))+"]" just the same and * omit the ThisForm.aArray altogether lcCSource=laArray+"["+allt(str(i))+','+allt(str(j))+"]" .controlsource=lcCSource .ToolTipText='['+trans(i)+','+trans(j)+']' if cType#'L' * this doesn't work as nice with dates, don't know why: .width=thisform.textwidth(.text)+4 else .width=12 endif endwith endfor endfor nLastLeft=2 for j=1 to this.nCols * position the columns * make all the textboxes in the same column same width, calculate max first: nMaxWidth=0 for i=1 to this.nRows with this.aobj[i,j] .left=nLastLeft nMaxWidth=max(nMaxWidth, .width) endwith endfor * then apply this max to them for i=1 to this.nRows this.aobj[i,j].width=nMaxWidth endfor nLastLeft=nLastLeft+nMaxWidth+2 endfor * calculate vertical positions * I'm not trying to align them horizontally - if we apply some other controls this * may become impossible. Make them visible, this is the last round. nLastTop=2 for i=1 to this.nRows nMaxHeight=0 for j=1 to This.nCols with this.aobj[i,j] .top=nLastTop nMaxHeight=max(nMaxHeight, .height) .visible=.t. endwith endfor nLastTop=nLastTop+nMaxHeight endfor * resize the form (or whatever container we base this on). We may check for some * max values and apply some scrollbars if necessary - left for next version. with this .width=nLastLeft .height=nLastTop endwith ENDPROC Proc MemberLostFocus lParam oThis local nNewRow, nNewCol nNewRow=oThis.nRow nNewCol=oThis.nCol NoDefault lnLastKey=lastkey() do case * clicked elsewhere case abs(This.NextRow-oThis.nRow)>1 or abs(This.NextCol-oThis.nCol)>1 nNewRow=This.NextRow nNewCol=This.NextCol store 0 to This.NextCol, This.NextRow * home, leftarrow, backtab case inList(lnLastkey, 1, 19, 15) nNewCol=iif(nNewCol= 1, This.ncols, nNewCol-1) * dnArrow case inlist(lnLastKey, 24) nNewRow=iif(nNewRow=This.nrows, 1, nNewRow+1) * upArrow case inlist(lnLastKey, 5) nNewRow=iif(nNewRow= 1, This.nrows, nNewRow-1) * end, rightarrow, enter, tab Other nNewCol=iif(nNewCol=This.ncols, 1, nNewCol+1) endcase This.aObj[nNewRow, nNewCol].setfocus endproc Proc MemberWhen lPara oThis This.nextRow=othis.nRow This.NextCol=othis.nCol endproc enddef Define Class ATextbox as c_textbox nRow=0 nCol=0 Proc Init LPara lnRow, lnCol this.nrow=lnRow this.ncol=lnCol dodefault() endproc proc When return(this.parent.memberwhen(this)) endproc proc LostFocus this.parent.MemberLostFocus(this) endproc enddefine Define Class ACheckbox as c_checkbox nRow=0 nCol=0 Proc Init LPara lnRow, lnCol this.nrow=lnRow this.ncol=lnCol dodefault() endproc proc When return(this.parent.memberwhen(this)) endproc proc LostFocus this.parent.MemberLostFocus(this) endproc enddefine