PB DW内容自适应 原创

PB开发者
发布于 2023-4-3 09:22
浏览
0收藏

演示GIF

PB DW内容自适应-鸿蒙开发者社区

思路

1、记录上一次DW大小、名称等信息。
2、根据DW最新大小除以上一次记录的DW大小,计算出缩放比列。
3、循环出DW中字段、控件等、根据类型分别计算出长宽高、X、Y坐标等。

源码

1、创建Custom Class对象、命名为uo_dwresize
2、使用

uo_dwresize dwresize
//open事件中
//实例化
dwresize = create uo_dwresize
//记录初始DW大小
dwresize.of_add_dwsize(dw_1)

//根据特定需求增加自适应方法
//根据DW大小,内容自适应
dwresize.of_draw_dwsize()

3、源码

forward
global type uo_dwresize from nonvisualobject
end type
type str_dwsize from structure within uo_dwresize
end type
end forward

global type str_dwsize from structure
	string	ls_classname
	long		ll_width
	long		ll_height
	datawindow		ldw_datawindow
end type

global type uo_dwresize from nonvisualobject
end type
global uo_dwresize uo_dwresize

type variables

any iany_arr[]
end variables

forward prototypes
public function any of_split (string as_bj, string as_input)
public subroutine of_add_dwsize (datawindow adw_dw)
public subroutine of_draw_dwsize ()
end prototypes

public function any of_split (string as_bj, string as_input);//================================================
//按符号分割字符串
//_of_split(as_bj,as_input)
//as_bj:符号
//as_input:字符串
//===============================================
string ls_list[] //接收返回的字符串列表
string ls_temp
integer i = 1
long  ll_pos
integer li_len

li_len = len(as_bj)  //分割符的长度
ll_pos = pos(as_input,as_bj)

do
	if ll_pos = 0 then
		ls_list[i] = as_input
	else  
		ls_list[i] = left(as_input,ll_pos - 1) 
		i++  
		as_input = mid(as_input,ll_pos + li_len)
		ll_pos = pos(as_input,as_bj)
		if ll_pos = 0 then ls_list[i] = as_input
	end if
loop while ll_pos <> 0

return ls_list
end function

public subroutine of_add_dwsize (datawindow adw_dw);long ll_for,ll_find = 0
str_dwsize str_size

for ll_for = 1 to upperbound(iany_arr)
	str_size = iany_arr[1]
	if str_size.ls_classname = adw_dw.classname() then exit
next

str_size.ls_classname = adw_dw.classname()
str_size.ll_width = adw_dw.width
str_size.ll_height = adw_dw.height
str_size.ldw_datawindow = adw_dw

if ll_find = 0 then iany_arr[upperbound(iany_arr) + 1] = str_size


end subroutine

public subroutine of_draw_dwsize ();long ll_widthOld = 0,ll_heightOld = 0
string ls_input='',ls_list[],ls_type = '',ls_band=''
dec ldc_RadioW = 0,ldc_RadioH = 0	
int ll_DWX,ll_DWY,ll_DWX2,ll_DWY2,ll_ApartW,ll_Processing
int ll_i,ll_ContentW,ll_ContentH,ll_DWHeaderH,ll_DWDetailH
long ll_textsize,ll_KJheight,ll_row
str_dwsize str_size
datawindow ldw_dw 

for ll_row = 1 to upperbound(iany_arr)
	str_size = iany_arr[ll_row]
	ldw_dw = str_size.ldw_datawindow
	
	ll_widthOld = str_size.ll_width
	ll_heightOld = str_size.ll_height
	
	str_size.ll_width = ldw_dw.width
	str_size.ll_height = ldw_dw.height
	iany_arr[ll_row] = str_size

	ldc_RadioW = ldw_dw.width / ll_widthOld
	ldc_RadioH = ldw_dw.height / ll_heightOld

	ldw_dw.setredraw(false)
	
	ls_input = ldw_dw.Describe("DataWindow.Objects")
	ls_list = of_split('	',ls_input)
	
	ll_DWHeaderH = long(ldw_dw.describe("datawindow.header.height"))
	ll_DWDetailH = long(ldw_dw.describe("datawindow.detail.height"))
	ll_DWHeaderH = ll_DWHeaderH * ldc_RadioH
	ll_DWDetailH = ll_DWDetailH * ldc_RadioH
	ldw_dw.Modify("datawindow.header.height = '"+string(ll_DWHeaderH)+"'")
	ldw_dw.Modify("datawindow.detail.height = '"+string(ll_DWDetailH)+"'")
	
	for ll_i = 1 to upperbound(ls_list)
		ls_band = ldw_dw.describe(ls_list[ll_i] + ".band")
		ls_type = ldw_dw.describe(ls_list[ll_i] + ".type")

		if ls_band <> '!'  then
			if ls_type = 'text' or ls_type = 'column'   or ls_type = 'compute' then
				if long(ldw_dw.describe(ls_list[ll_i] + ".visible")) = 0 then continue;
				ll_ContentW = long(ldw_dw.describe(ls_list[ll_i] + ".width"))
				ll_ContentH = long(ldw_dw.describe(ls_list[ll_i] + ".height"))
				ll_DWX = long(ldw_dw.describe(ls_list[ll_i] + ".x"))
				ll_DWY = long(ldw_dw.describe(ls_list[ll_i] + ".y"))
				ll_Processing = long(ldw_dw.Object.DataWindow.Processing)
				
				//Grid 只改变宽度;不改变X,Y
				if ll_Processing = 1 then
				else
					ldw_dw.Modify(ls_list[ll_i]+".x = '"+string(ll_DWX * ldc_RadioW)+"'")
					ldw_dw.Modify(ls_list[ll_i]+".y = '"+string(ll_DWY * ldc_RadioH)+"'")
				end if
				ldw_dw.Modify(ls_list[ll_i]+".width = '"+string(ll_ContentW * ldc_RadioW)+"'")
				ldw_dw.Modify(ls_list[ll_i]+".height = '"+string(ll_ContentH * ldc_RadioH)+"'")
			elseif ls_type = 'line'  then
				ll_DWX = long(ldw_dw.describe(ls_list[ll_i] + ".x1"))
				ll_DWY = long(ldw_dw.describe(ls_list[ll_i] + ".y1"))
				ll_DWX2 = long(ldw_dw.describe(ls_list[ll_i] + ".x2"))
				ll_DWY2 = long(ldw_dw.describe(ls_list[ll_i] + ".y2"))
		
				ldw_dw.Modify(ls_list[ll_i]+".x1 = '"+string(ll_DWX * ldc_RadioW)+"'")
				ldw_dw.Modify(ls_list[ll_i]+".y1 = '"+string(ll_DWY * ldc_RadioH)+"'")
				ldw_dw.Modify(ls_list[ll_i]+".x2 = '"+string(ll_DWX2 * ldc_RadioW)+"'")
				ldw_dw.Modify(ls_list[ll_i]+".y2 = '"+string(ll_DWY2 * ldc_RadioH)+"'")
			elseif ls_type = 'rectangle' or ls_type = 'button' or ls_type = 'roundrectangle' or ls_type = 'ellipse' or ls_type = 'report' or ls_type = 'bitmap' or ls_type = 'graph' then 
				ll_ContentW = long(ldw_dw.describe(ls_list[ll_i] + ".width"))
				ll_ContentH = long(ldw_dw.describe(ls_list[ll_i] + ".height"))
				ll_DWX = long(ldw_dw.describe(ls_list[ll_i] + ".x"))
				ll_DWY = long(ldw_dw.describe(ls_list[ll_i] + ".y"))
				
				ldw_dw.Modify(ls_list[ll_i]+".x = '"+string(ll_DWX * ldc_RadioW)+"'")
				ldw_dw.Modify(ls_list[ll_i]+".y = '"+string(ll_DWY * ldc_RadioH)+"'")
				ldw_dw.Modify(ls_list[ll_i]+".width = '"+string(ll_ContentW * ldc_RadioW)+"'")
				ldw_dw.Modify(ls_list[ll_i]+".height = '"+string(ll_ContentH * ldc_RadioH)+"'")
			end if
		end if
	next
	
	ldw_dw.setredraw(true)
next

end subroutine

on uo_dwresize.create
call super::create
TriggerEvent( this, "constructor" )
end on

on uo_dwresize.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
DW按比例放大.zip 58.49K 36次下载
已于2023-4-3 09:25:55修改
收藏
回复
举报
回复
    相关推荐