在FreeForm DW中用方向键控制上下左右切换列

姓名:李小龙         性别:男               生日:1970-01-01
国家:中国            爱好:武术            特长:截拳道         
作品:唐山大兄      偶像:叶问    

如上:焦点现在在【爱好】上,如果按向上键就到【性别】,向下键就到【偶像】,向左键就到【国家】,向右键就到【特长】。
这样的效果如何实现?

 

我们可以通过遍历所以列,然后在datawindow的key事件中去判断该将焦点移动哪个列上,具体做法如下:

 

(1)建立一个grid类型的数据窗口d_obj_free,用来存储freeform数据窗口的所有列,该数据窗口包含5个列

column=(type=char(20) updatewhereclause=no name=obj dbname="obj" ) //存储列名 column=(type=long updatewhereclause=no name=ox dbname="ox" ) //存储列X值 column=(type=long updatewhereclause=no name=oy dbname="oy" ) //存储列Y值 column=(type=long updatewhereclause=no name=ow dbname="ow" ) //存储列Width值 column=(type=long updatewhereclause=no name=oh dbname="oh" ) //存储列Height值 

 

(2)建立一个继承自datawindow的标准的控件对象:uo_datawindow

由于datawindow可以为列的visible, protect等属性设置expression内容,因此在读取这些属性时不能单纯的使用describe,在uo_datawindow中建立一个取属性的函数of_describe(string as_describe, long row)

public function string of_describe (string as_describe, long row); //======================================================================================================================== // 取得数据窗口的describe值,兼容带表达式的列 //======================================================================================================================== string ls string str_return int li_type str_return = this.describe(as_describe) if pos(str_return, "~t") < 1 then return str_return if left(str_return, 1) = '"' or left(str_return, 1) = "'" then str_return = mid(str_return, 2) if right(str_return, 1) = '"' or right(str_return, 1) = "'" then str_return = left(str_return, len(str_return) - 1) str_return = mid(str_return, pos(str_return, "~t") + len("~t")) if row < 1 or row > this.rowcount() then row = this.getrow() if row = 0 then return '' return this.describe("evaluate(~"" + str_return + "~"," + string(row) + ")") end function 

(3)在uo_datawindow中建立实例变量: datastore ids_obj ,用来存储列对象,在uo_datawindow的constructor事件中对datawindow进行遍历,并存到ids_obj中:

event constructor;ids_obj = create datastore ids_obj.dataobject = 'd_obj_free' int li string ls_objects, ls_col long ll_detail_height, row ll_detail_height = long(describe("datawindow.detail.height")) ls_objects = Object.DataWindow.Objects + '~t' ids_obj.reset() do while true li = pos(ls_objects, '~t') if li <= 0 then exit ls_col = left(ls_objects, li - 1) ls_objects = mid(ls_objects, li + 1) if ls_col = '' then continue //取出来的列为空,则继续 if lower(describe(ls_col + ".band")) <> 'detail' then continue //非detail的不要 if lower(describe(ls_col + ".type")) <> 'column' then continue //非column的不要 if long (describe(ls_col + ".TabSequence")) <= 0 then continue //非可获得焦点的不要 //if long (describe(ls_col + ".protect")) = 1 then continue //被保护的不要 //if lower(describe(ls_col + ".visible")) = '0' then continue //不可见的不要 if long (of_describe(ls_col + ".y", 1)) + long (of_describe(ls_col + ".height", 1)) > ll_detail_height then continue //detail高度以外的不要 row = ids_obj.insertrow(0) ids_obj.setitem(row, 'obj', ls_col) ids_obj.setitem(row, 'ox', long (of_describe(ls_col + ".x", 1))) ids_obj.setitem(row, 'oy', long (of_describe(ls_col + ".y", 1))) ids_obj.setitem(row, 'ow', long (of_describe(ls_col + ".width", 1))) ids_obj.setitem(row, 'oh', long (of_describe(ls_col + ".height", 1))) loop ids_obj.saveas("e:/a.xls", excel!, true) end event 

(4)uo_datawindow中建立一个取指定方向列名的函数of_getcol (string as, string ap) //as表示当前焦点列,ap表示方向

public function string of_getcol (string as, string ap);string ls_col, ls_filter, ls_sort long row, row_p, ox, oy, ow, oh ids_obj.setfilter("obj = '" + as + "'"); ids_obj.filter() if ids_obj.rowcount() <= 0 then return as row = 1 ox = ids_obj.getitemnumber(row, 'ox') oy = ids_obj.getitemnumber(row, 'oy') ow = ids_obj.getitemnumber(row, 'ow') oh = ids_obj.getitemnumber(row, 'oh') choose case ap case 'l' ls_filter = "obj <> '" + as + "' and ( (ox < " + string(ox) + " and oy < " + string(oy + oh) + ") or ((oy + oh) < " + string(oy) + "))" ls_sort = "(oy + oh) desc, (ox + ow) desc" case 'r' ls_filter = "obj <> '" + as + "' and ( (ox > " + string(ox) + " and oy >= " + string(oy) + ") or (oy > " + string(oy + oh) + "))" ls_sort = "(oy + oh) asc, (ox + ow) asc" case 'u' ls_filter = "obj <> '" + as + "' and ((oy + oh) <= " + string(oy) + ") " ls_sort = "abs(ox + ow / 2 - " + string(ox + ow / 2) + ") asc, (oy + oh) desc" case 'd' ls_filter = "obj <> '" + as + "' and (oy >= " + string(oy + oh) + ") " ls_sort = "abs(ox + ow / 2 - " + string(ox + ow / 2) + ") asc, (oy + oh) asc" case else return as end choose ids_obj.setfilter(ls_filter) ; ids_obj.filter() if ids_obj.rowcount() = 0 then return as ids_obj.setsort(ls_sort); ids_obj.sort() row = 0 do while true row ++ ls_col = ids_obj.getitemstring(row, 'obj') if of_describe(ls_col + ".visible", getrow()) = '0' then continue //该行的该单元格不可见,则取下一个 if of_describe(ls_col + ".protect", getrow()) = '1' then continue //该行的该单元格被保护,则取下一个 return ls_col loop return as end function 

(5)在uo_datawindow的key(对应的Event ID:pbm_dwnkey)事件中,对keycode进行判断处理,并切换焦点

event key;if getrow() = 0 then return choose case key case keyleftarrow! setcolumn(of_getcol( getcolumnname(), 'l')) case keyrightarrow! setcolumn(of_getcol( getcolumnname(), 'r')) case keyuparrow! setcolumn(of_getcol( getcolumnname(), 'u')) case keydownarrow! setcolumn(of_getcol( getcolumnname(), 'd')) case else end choose end event 

(6)至此,需要的功能就实现了,通过uo_datawindow建立一个数据窗口试试看吧

 

 

下面附上uo_datawindow和d_obj_free两个对象的导出内容

<1>d_obj_free, 直接复制内容保存为 .srd格式文件,然后导入

$PBExportHeader$d_obj_free.srd release 9; datawindow(units=0 timer_interval=0 color=1073741824 processing=1 HTMLDW=no print.printername="" print.documentname="" print.orientation = 0 print.margin.left = 110 print.margin.right = 110 print.margin.top = 96 print.margin.bottom = 96 print.paper.source = 0 print.paper.size = 0 print.canusedefaultprinter=yes print.prompt=no print.buttons=no print.preview.buttons=no print.cliptext=no print.overrideprintjob=no print.collate=yes hidegrayline=no grid.lines=0 ) header(height=76 color="536870912" ) summary(height=0 color="536870912" ) footer(height=0 color="536870912" ) detail(height=88 color="536870912" ) table(column=(type=char(20) updatewhereclause=no name=obj dbname="obj" ) column=(type=long updatewhereclause=no name=ox dbname="ox" ) column=(type=long updatewhereclause=no name=oy dbname="oy" ) column=(type=long updatewhereclause=no name=ow dbname="ow" ) column=(type=long updatewhereclause=no name=oh dbname="oh" ) ) text(band=header alignment="2" text="对象" border="0" color="33554432" x="9" y="8" height="64" width="640" html.valueishtml="0" name=obj_t visible="1" font.face="Times New Roman" font.height="-9" font.weight="400" font.family="1" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) text(band=header alignment="2" text="X" border="0" color="33554432" x="658" y="8" height="64" width="256" html.valueishtml="0" name=ox_t visible="1" font.face="Times New Roman" font.height="-9" font.weight="400" font.family="1" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) text(band=header alignment="2" text="Y" border="0" color="33554432" x="923" y="8" height="64" width="256" html.valueishtml="0" name=oy_t visible="1" font.face="Times New Roman" font.height="-9" font.weight="400" font.family="1" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) text(band=header alignment="2" text="WIDTH" border="0" color="33554432" x="1189" y="8" height="64" width="256" html.valueishtml="0" name=ow_t visible="1" font.face="Times New Roman" font.height="-9" font.weight="400" font.family="1" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) text(band=header alignment="2" text="HEIGHT" border="0" color="33554432" x="1454" y="8" height="64" width="256" html.valueishtml="0" name=oh_t visible="1" font.face="Times New Roman" font.height="-9" font.weight="400" font.family="1" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) column(band=detail id=1 alignment="0" tabsequence=10 border="0" color="33554432" x="9" y="8" height="72" width="640" format="[general]" html.valueishtml="0" name=obj visible="1" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes edit.imemode=0 font.face="Times New Roman" font.height="-9" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) column(band=detail id=2 alignment="1" tabsequence=20 border="0" color="33554432" x="658" y="8" height="72" width="256" format="[general]" html.valueishtml="0" name=ox visible="1" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes edit.imemode=0 font.face="Times New Roman" font.height="-9" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) column(band=detail id=3 alignment="1" tabsequence=30 border="0" color="33554432" x="923" y="8" height="72" width="256" format="[general]" html.valueishtml="0" name=oy visible="1" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes edit.imemode=0 font.face="Times New Roman" font.height="-9" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) column(band=detail id=4 alignment="1" tabsequence=40 border="0" color="33554432" x="1189" y="8" height="72" width="256" format="[general]" html.valueishtml="0" name=ow visible="1" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes edit.imemode=0 font.face="Times New Roman" font.height="-9" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) column(band=detail id=5 alignment="1" tabsequence=50 border="0" color="33554432" x="1454" y="8" height="72" width="256" format="[general]" html.valueishtml="0" name=oh visible="1" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes edit.imemode=0 font.face="Times New Roman" font.height="-9" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) htmltable(border="1" ) htmlgen(clientevents="1" clientvalidation="1" clientcomputedfields="1" clientformatting="0" clientscriptable="0" generatejavascript="1" encodeselflinkargs="1" netscapelayers="0" ) export.xml(headgroups="1" includewhitespace="0" metadatatype=0 savemetadata=0 ) import.xml() export.pdf(method=0 distill.custompostscript="0" xslfop.print="0" ) 

<2>uo_datawindow, 直接复制内容保存为 .sru格式文件,然后导入

$PBExportHeader$uo_datawindow.sru forward global type uo_datawindow from datawindow end type end forward global type uo_datawindow from datawindow integer width = 686 integer height = 400 string title = "none" boolean livescroll = true borderstyle borderstyle = stylelowered! event ue_dwmousemove pbm_dwnmousemove event key pbm_dwnkey end type global uo_datawindow uo_datawindow type prototypes end prototypes type variables datastore ids_obj end variables forward prototypes public function string of_describe (string as_describe, long row) public function string of_getcol (string as, string ap) end prototypes event key;if getrow() = 0 then return choose case key case keyleftarrow! setcolumn(of_getcol( getcolumnname(), 'l')) case keyrightarrow! setcolumn(of_getcol( getcolumnname(), 'r')) case keyuparrow! setcolumn(of_getcol( getcolumnname(), 'u')) case keydownarrow! setcolumn(of_getcol( getcolumnname(), 'd')) case else end choose end event public function string of_describe (string as_describe, long row); //======================================================================================================================== // 取得数据窗口的describe值,兼容带表达式的列 //======================================================================================================================== string ls string str_return int li_type str_return = this.describe(as_describe) if pos(str_return, "~t") < 1 then return str_return if left(str_return, 1) = '"' or left(str_return, 1) = "'" then str_return = mid(str_return, 2) if right(str_return, 1) = '"' or right(str_return, 1) = "'" then str_return = left(str_return, len(str_return) - 1) str_return = mid(str_return, pos(str_return, "~t") + len("~t")) if row < 1 or row > this.rowcount() then row = this.getrow() if row = 0 then return '' return this.describe("evaluate(~"" + str_return + "~"," + string(row) + ")") end function public function string of_getcol (string as, string ap);string ls_col, ls_filter, ls_sort long row, row_p, ox, oy, ow, oh ids_obj.setfilter("obj = '" + as + "'"); ids_obj.filter() if ids_obj.rowcount() <= 0 then return as row = 1 ox = ids_obj.getitemnumber(row, 'ox') oy = ids_obj.getitemnumber(row, 'oy') ow = ids_obj.getitemnumber(row, 'ow') oh = ids_obj.getitemnumber(row, 'oh') choose case ap case 'l' ls_filter = "obj <> '" + as + "' and ( (ox < " + string(ox) + " and oy < " + string(oy + oh) + ") or ((oy + oh) < " + string(oy) + "))" ls_sort = "(oy + oh) desc, (ox + ow) desc" case 'r' ls_filter = "obj <> '" + as + "' and ( (ox > " + string(ox) + " and oy >= " + string(oy) + ") or (oy > " + string(oy + oh) + "))" ls_sort = "(oy + oh) asc, (ox + ow) asc" case 'u' ls_filter = "obj <> '" + as + "' and ((oy + oh) <= " + string(oy) + ") " ls_sort = "abs(ox + ow / 2 - " + string(ox + ow / 2) + ") asc, (oy + oh) desc" case 'd' ls_filter = "obj <> '" + as + "' and (oy >= " + string(oy + oh) + ") " ls_sort = "abs(ox + ow / 2 - " + string(ox + ow / 2) + ") asc, (oy + oh) asc" case else return as end choose ids_obj.setfilter(ls_filter) ; ids_obj.filter() if ids_obj.rowcount() = 0 then return as ids_obj.setsort(ls_sort); ids_obj.sort() row = 0 do while true row ++ ls_col = ids_obj.getitemstring(row, 'obj') if of_describe(ls_col + ".visible", getrow()) = '0' then continue //该行的该单元格不可见,则取下一个 if of_describe(ls_col + ".protect", getrow()) = '1' then continue //该行的该单元格被保护,则取下一个 return ls_col loop return as end function on uo_datawindow.create end on on uo_datawindow.destroy end on event constructor;ids_obj = create datastore ids_obj.dataobject = 'd_obj_free' int li string ls_objects, ls_col long ll_detail_height, row ll_detail_height = long(describe("datawindow.detail.height")) ls_objects = Object.DataWindow.Objects + '~t' ids_obj.reset() do while true li = pos(ls_objects, '~t') if li <= 0 then exit ls_col = left(ls_objects, li - 1) ls_objects = mid(ls_objects, li + 1) if ls_col = '' then continue //取出来的列为空,则继续 if lower(describe(ls_col + ".band")) <> 'detail' then continue //非detail的不要 if lower(describe(ls_col + ".type")) <> 'column' then continue //非column的不要 if long (describe(ls_col + ".TabSequence")) <= 0 then continue //非可获得焦点的不要 //if long (describe(ls_col + ".protect")) = 1 then continue //被保护的不要 //if lower(describe(ls_col + ".visible")) = '0' then continue //不可见的不要 if long (of_describe(ls_col + ".y", 1)) + long (of_describe(ls_col + ".height", 1)) > ll_detail_height then continue //detail高度以外的不要 row = ids_obj.insertrow(0) ids_obj.setitem(row, 'obj', ls_col) ids_obj.setitem(row, 'ox', long (of_describe(ls_col + ".x", 1))) ids_obj.setitem(row, 'oy', long (of_describe(ls_col + ".y", 1))) ids_obj.setitem(row, 'ow', long (of_describe(ls_col + ".width", 1))) ids_obj.setitem(row, 'oh', long (of_describe(ls_col + ".height", 1))) loop end event event destructor;if isvalid(ids_obj) then destroy ids_obj end event 

你可能感兴趣的:(String,function,filter,header,border,alignment)