界面库

优化代码
This commit is contained in:
JianjunLiu 2022-11-01 10:29:54 +08:00
parent 39d57baf2e
commit fe6e2c7eae
5 changed files with 140 additions and 243 deletions

View File

@ -1129,14 +1129,6 @@ type tcontrol = class(tcomponent)
end
return array(x,y);
end
function IsContainer(cd);virtual;
begin
{
@explan(说明)判断当前是否可以作为容器 %%
@param(cd)(tcontrol 及其子类) cd 是否可以为子项 %%
}
return false;
end
function getid();
begin
return Fid;
@ -1180,7 +1172,7 @@ type tcontrol = class(tcomponent)
@ignore(忽略)
@explan(说明) 判断是否可以作为父节点
}
return(AParent is getparenttype())and AParent.IsContainer(self(true));
return(AParent is getparenttype()) ;//and AParent.IsContainer(self(true));
return false;
end
function Recycling();override; //销毁处理

View File

@ -154,10 +154,6 @@ type tgraphiccontrol = class(TControl)
begin
inherited;
end
function IsContainer(cd);override;
begin
return false;
end
function Create(AOwner:TComponent);override;
begin
inherited;

View File

@ -1300,14 +1300,6 @@ type TVCForm = class(TScrollingWinControl)
end
end;
end
function IsContainer(cd);override;
begin
{**
@explan(说明) 重写该方法,该类可以作为容器 %%
**}
if cd is class(TComponent)then return Controls.indexof(cd)<0;
return true;
end
function Paint();override;
begin
inherited;
@ -2239,7 +2231,7 @@ type TListBox = class(TcustomListBox)
"height","width","left","top","items",
"multisel","checkbox","popupmenu","wsdlgmodalframe",
"onmousedown","onmouseup",
"onselectionchange"
"onselchanged"
);
end
@ -2339,7 +2331,7 @@ type TColorbox=class(TcustomListBox)
"height","width","left","top",
"wsdlgmodalframe","popupmenu","parentcolor","parentfont",
"onmousedown","onmouseup",
"onselectionchange"
"onselchanged"
);
end
private
@ -2357,7 +2349,7 @@ type TColorCombobox=class(TCustomComboBoxbase)
inherited;
FListBox.visible := false;
FListBox.WsPopUp := true;
FListBox.onSelectionChange := function(o,e)
FListBox.onselchanged := function(o,e)
begin
if o.visible then
begin
@ -2984,7 +2976,7 @@ type tpagecontrol = class(tcustompagecontrol)
begin
return array("name","left","top","width","height",
"align","anchors","color","font","parentcolor","parentfont","border","caption","popupmenu","enabled","visible","cursel","cursor",
"wsdlgmodalframe","wssizebox","OnSelChange");
"wsdlgmodalframe","wssizebox","onselchange");
end
end
//二分控件
@ -4495,10 +4487,6 @@ type tmonthcalendar = class(TCustomControl)
FCalender.top := 1;
FCalender.host := self(true);
end
function isContainer(cd);override;
begin
return 0;
end
function paint();override;
begin
if FCalender then FCalender.paint();
@ -4909,10 +4897,6 @@ type ttimepicker = class(tthreeEntry)
end
end
function isContainer(cd);override;
begin
return 0;
end
function getTime();override;begin
{**
@explan(说明)获取控件当前选择的时间%%

View File

@ -1,40 +1,6 @@
unit utslvclpage;
interface
uses utslvclauxiliary,utslvclbase,utslvclgdi;
type tcustomtabitem = class() //TTCITEMA
{**
@explan(说明)tab控件标签对象 %%
**}
private
FPageCtrl;
FCaption;
FVisible;
FPageSheet;
function SetVisible(v);//设置可见
begin
nv := v?true:false;
if nv<>FVisible then
begin
FVisible := v;
end
end
function SetCaption(s);//设置标签
begin
if ifstring(s) and s<>FCaption then
begin
FCaption := s;
psztext := FCaption;
if PageSheet is class(tcustomtabsheet) then PageSheet.Caption := s;
end
end
public
function Create();//构造
begin
FVisible:= true;
end
property Caption read FCaption write SetCaption;
property PageSheet read FPageSheet Write FPageSheet;
end
type tcustomtabsheet = class(TCustomControl) //控件页面
{**
@explan(说明)page控件页面 %%
@ -51,28 +17,6 @@ type tcustomtabsheet = class(TCustomControl) //
Parent.SetTabText(id,s);
end
end
function SetParent(p);override; //设置父窗口
begin
if (P is class(tcustompagecontrol) ) and parent<>p then
begin
oldparent := Parent;
if oldparent then
begin
oldparent.RemovePage(self);
end
inherited;
parent.addtabitem(self(true));
end else
if not(p is class(TWincontrol)) then
begin
if Parent then
begin
id := Parent.GetPageID(self);
Parent.RemovePageTab(id);
end
inherited;
end
end
public
function paint();override; //设计器模式下绘制网格
begin
@ -89,22 +33,23 @@ type tcustomtabsheet = class(TCustomControl) //
function create(AOwner);override;
begin
inherited;
WsDlgModalFrame := true;
Caption := "tab";
Visible := false;
end
function CreateParams(p);override;
{function CreateParams(p);override;
begin
inherited;
p.exstyle := 0x101;
end
end }
end
type tcustompagecontrol = class(TCustomControl)
private
FirstViewIndex; //第一个展示的序号
FCurrentid;
FPrevid;
FCurrentid; //当前
FPrevid; //上一个
FTabItems; //
FOnSelChange;
FOnSelChanged;
FOnSelChanging; //正在改变
//FOnrclick;
FTabPosition;
@ -120,8 +65,8 @@ type tcustompagecontrol = class(TCustomControl)
if FTabPosition=v then exit;
if not(v in array(alTop,alBottom,alLeft,alRight)) then exit;
FTabPosition := v;
InvalidateRect(nil,false);
DoControlAlign();
InvalidateRect(nil,false);
end
function GetTabCount();
begin
@ -129,7 +74,7 @@ type tcustompagecontrol = class(TCustomControl)
end
function CreateTableItem(cp);
begin
r := new tcustomtabitem();
r := new tcustomtabitem();
r.caption := cp;
return r;
end
@ -218,8 +163,7 @@ type tcustompagecontrol = class(TCustomControl)
alTop:
begin
if FTabItemswidth then
begin
begin
FClientarea[1] :=rec[1]+FTabHeight;
if length(FTabItemswidth)>1 and (FMaxsize>(rec[2]-rec[0])) then
begin
@ -244,8 +188,7 @@ type tcustompagecontrol = class(TCustomControl)
alBottom:
begin
if FTabItemswidth then
begin
begin
FClientarea[3] :=rec[3]-FTabHeight;
if length(FTabItemswidth)>1 and (FMaxsize>(rec[2]-rec[0])) then
begin
@ -287,8 +230,7 @@ type tcustompagecontrol = class(TCustomControl)
FirstViewIndex--;
CalcTabs();
end
end
end
end
end
function setselidx(id); //选择序号
@ -296,7 +238,7 @@ type tcustompagecontrol = class(TCustomControl)
if FCurrentid= id then return ;
if id>=0 and id<FTabItems.length() then
begin
if OnSelChanging then
if fOnSelChanging then
begin
e := new tuieventbase(0,FPrevid,FCurrentid,0); //m,w,l,h
doonSelChanging(self(true),e);
@ -307,7 +249,7 @@ type tcustompagecontrol = class(TCustomControl)
InsureIdxVisible(id);
InvalidateRect(nil,false);
DoControlAlign();
if OnSelChange then
if FOnSelChanged then
begin
doonSelChange(self(true),new tuieventbase(0,FPrevid,FCurrentid,0));
end
@ -326,11 +268,10 @@ type tcustompagecontrol = class(TCustomControl)
rec := FTabRects[i];
dc.pen.color := rgb(200,200,200);
if rec then
begin
begin
if FCurrentid=i then
begin
dc.brush.color := rgb(100,192,250);//rgb(230,240,250);//rgb(200,200,200);
dc.brush.color := 0xf0f0f0;//rgb(100,192,250);//rgb(230,240,250);//rgb(200,200,200);
end else dc.brush.color := rgb(254,254,254);
dc.draw("roundrect",array(rec[0:1],rec[2:3],array(2,2)));
//dc.draw("rectangle",array(rec[0:1],rec[2:3],array(5,5)));
@ -358,8 +299,7 @@ type tcustompagecontrol = class(TCustomControl)
rc1 := array((FScrollBtnRect[0]+1,FScrollBtnRect[3]-FTabHeight+1),FScrollBtnRect[2:3]-1);
dc.draw("framecontrol",rc1,DFC_SCROLL,DFCS_SCROLLDOWN);
end
end
end
end
end
function ScrollPrev(); //滚动到下一个
@ -384,15 +324,59 @@ type tcustompagecontrol = class(TCustomControl)
alLeft,alRight :
begin
if rec and (rec[3]<Fprevrect[1]) then return ;
end
end
end ;
FirstViewIndex++ ;
CalcTabs();
InvalidateRect(nil,false);
end
end
end
function RemovePageTab(id);//移除sheet
begin
if not(id>=0) then return ;
FTabItems.splice(id,1);
if id = FCurrentid then
begin
if id = 0 then
begin
if FTabItems.length()=0 then
begin
FCurrentid := -1;
end
end
return setselidx(id-1);
end else
if id<FCurrentid then
begin
FCurrentid--;
end
CalcTabs();
InvalidateRect(nil,false);
end
function addtabitem(page);//添加sheet
begin
//if not(page is class(tcustomtabsheet)) then return -1;
for i := 0 to FTabItems.length()-1 do
begin
if FTabItems[i].PageSheet = page then return -1;
end
if page then
cp := page.Caption;
it := CreateTableItem(cp);
FTabItems.Push(it);
if FTabItems.length()>1 then
begin
if page then
begin
page.visible := false;
end
end
it.PageSheet := Page;
if FCurrentid=-1 then
begin
setselidx(0);
end
end
public
function getsheetrect(); //获得sheet
begin
@ -409,8 +393,7 @@ type tcustompagecontrol = class(TCustomControl)
end
function create(aowner);
begin
inherited;
inherited;
end
function AfterConstruction();override;
begin
@ -426,13 +409,25 @@ type tcustompagecontrol = class(TCustomControl)
FPrevid := -1;
FTabItems := new tnumindexarray();
end
function ControlAppended(AControl);override;
begin
if not(AControl is class(tcustomtabsheet)) then return;
addtabitem(AControl);
end
function ControlDeleted(AControl);override;
begin
if not(AControl is class(tcustomtabsheet)) then return;
id := GetPageID(AControl);
RemovePageTab(id);
//fcoolbands.deleteitem(AControl,true);
end
Function SetCurSel(id); //设置当前序号
begin
if id is class(tcustomtabsheet) then
begin
return SetCurSel(GetPageID(id));
end
if ifnumber(id) then
if ifnumber(id) and id>=0 then
begin
iid := integer(id);
setselidx(iid);
@ -474,20 +469,21 @@ type tcustompagecontrol = class(TCustomControl)
if onrclick and (mb = mbRight) then
begin
CallMessgeFunction(onrclick,o,e);
end
end
return ;
end
//
end
end
function doonSelChange(o,e);virtual;
begin
CallMessgeFunction(OnSelChange,o,e);
CallMessgeFunction(FOnSelChanged,o,e);
end
function doonSelChanging(o,e);virtual;
begin
CallMessgeFunction(OnSelChanging,o,e);
CallMessgeFunction(fOnSelChanging,o,e);
end
function TabRect(AIndex: Integer);
function TabRect(AIndex: Integer); //获取区域
begin
r := FTabRects[AIndex];
if r then return r;
@ -496,14 +492,9 @@ type tcustompagecontrol = class(TCustomControl)
function GetTabText(AIndex);//获得caption
begin
r := "";
if AIndex<FTabItems.Count and AIndex>0 then return FTabItems[AIndex].Caption;
if AIndex<FTabItems.length() and AIndex>0 then return FTabItems[AIndex].Caption;
return r;
end
function IsContainer(cd);override;//是否容纳
begin
if cd is class(tcustomtabsheet) then return true;
return false;
end
function GetPageID(page);//获得page序号
begin
{**
@ -528,9 +519,9 @@ type tcustompagecontrol = class(TCustomControl)
for i := 0 to FTabItems.length()-1 do
begin
it := FTabItems[i];
if it and it.PageSheet then
pg := it.PageSheet;
if it and pg then
begin
pg := it.PageSheet;
if i=FCurrentid then
begin
pg.Visible := true;
@ -543,109 +534,12 @@ type tcustompagecontrol = class(TCustomControl)
rc[2]-=2;
rc[3]-=2;
end
pg.SetBoundsrect(rc);
pg.SetBoundsrect(rc);
end else
pg.Visible := false;
end
end
end
function RemovePageTab(id);//移除sheet
begin
if not(id>=0) then return ;
FTabItems.splice(id,1);
if id = FCurrentid then
begin
if id = 0 then
begin
if FTabItems.length()=0 then
begin
FCurrentid := -1;
end
end
return setselidx(id-1);
end else
if id<FCurrentid then
begin
FCurrentid--;
end
CalcTabs();
InvalidateRect(nil,false);
end
function RemovePage(i);//移除sheet
begin
{**
@explan(说明)移除page %%
@param(i)(integer) page序号 %%;
**}
ii := -1;
if ifnumber(i) then ii := i;
else
ii := GetPageID(i);
if ii<0 or ii>=FTabItems.length() then return ;
item := FTabItems[ii];
if ifobj(item) then
begin
pg := item.PageSheet;
if pg then pg.parent := nil;
end
//setselidx(0); //移除
end
function addcontrol(page);
begin
{**
@explan(说明) 添加控件 %%
@param(page)(tcustomtabsheet) sheet;
**}
if not(page is class(tcustomtabsheet)) then return -1;
add := true;
for i := 0 to Controls.count-1 do
begin
if Controls[i]=page then add := false;
end
if add then
begin
page.Visible := false;
page.parent := self;
end
end
function addtabitem(page);//添加sheet
begin
if not(page is class(tcustomtabsheet)) then return -1;
add := true;
for i := 0 to FTabItems.length()-1 do
begin
if FTabItems[i].PageSheet = page then add := false;
end
add1 := false;
for i := 0 to Controls.count-1 do
begin
if Controls[i]=page then add1 := true;
end
if add and add1 then
begin
it := CreateTableItem(page.caption);
FTabItems.Push(it);
if FTabItems.length()>1 then page.visible := false;
it.PageSheet := Page;
if {HandleAllocated() and} FCurrentid=-1 then
begin
setselidx(0);
end
end
end
function InitializeWnd();override;
begin
inherited;
end
function AppendPage(page);
begin
{**
@explan(说明)添加pagesheet %%
@param(page)(tcustomtabsheet)sheet %%;
**}
if not(page is class(tcustomtabsheet)) then return -1;
addcontrol(page);
end
end
function SetTabText(i,Value);
begin
{**
@ -671,22 +565,23 @@ type tcustompagecontrol = class(TCustomControl)
{**
@explan(说明) 修改标签的次序 %%
@param(AIndex)(integer) 位置 %%
@param(AIndexnew)(integer) 新位置 %%
@param(AIndexnew)(integer) 新位置 %%
**}
if (AIndex<>AIndexnew) and (AIndex>=0) and
(AIndex<FTabItems.length()) and (AIndexnew>=0) and (AIndexnew<FTabItems.length()) then
(AIndex<FTabItems.length()) and (AIndexnew>=0) and
(AIndexnew<FTabItems.length()) then
begin
FTabItems(AIndex,AIndexnew);
FTabItems.swap(AIndex,AIndexnew);
CalcTabs();
InvalidateRect(nil,false);
end
end
function Recycling();override;
begin
FTabItems.splice(0,FTabItems.length());
inherited;
FOnSelChanged := nil;
FOnSelChanging := nil;
FTabItems.splice(0,nil);
inherited;
end
{**
@param(cursel)(integer) 当前选中序号 %%
@ -696,14 +591,47 @@ type tcustompagecontrol = class(TCustomControl)
@param(Onrclcik)(function[tcustompagecontrol,tuieventbase]) 右键点击 %%
**}
property cursel:lazyinteger read FCurrentid write SetCurSel;
property OnSelChange:eventhandler read FOnSelChange write FOnSelChange;
property OnSelChanged:eventhandler read FOnSelChanged write FOnSelChanged;
property OnSelChanging:eventhandler read FOnSelChanging write FOnSelChanging;
//property onrclick:eventhandler read Fonrclick write Fonrclick;
property TabCount read GetTabCount;
property TabPosition:tabalign read FTabPosition write SetTabPosition;
end
implementation
type tcustomtabitem = class() //
{**
@explan(说明)tab控件标签对象 %%
**}
private
FPageCtrl;
FCaption;
FVisible;
FPageSheet;
function SetVisible(v);//设置可见
begin
nv := v?true:false;
if nv<>FVisible then
begin
FVisible := v;
end
end
function SetCaption(s);//设置标签
begin
if ifstring(s) and s<>FCaption then
begin
FCaption := s;
psztext := FCaption;
if PageSheet is class(tcustomtabsheet) then PageSheet.Caption := s;
end
end
public
function Create();//构造
begin
FVisible:= true;
FCaption := "";
end
property Caption read FCaption write SetCaption;
property PageSheet read FPageSheet Write FPageSheet;
end
initialization
end.

View File

@ -3646,7 +3646,8 @@ type TcustomListBox=class(TCustomListBoxbase)
property ItemCount read GetItemCount;
property Multisel:bool read FMultisel write SetMultisel;
property checkbox:bool read fcheckbox write setcheckbox;
property onSelectionChange:eventhandler read FselectionChange write FselectionChange;
property onSelectionChange read FselectionChange write FselectionChange;
property onSelchanged:eventhandler read FselectionChange write FselectionChange;
property Items:strings read GetData write setData;
protected
function CheckListItems(s);
@ -4081,7 +4082,7 @@ type TcustomComboBox=class(TCustomComboBoxbase)
FListBox.Border := true;
FListBox.Visible := false;
FListBox.WsPopUp := true;
FListBox.onselectionchange := function(o,e);
FListBox.onselchanged := function(o,e);
begin
if feditischanging then return ;
r := getCurrentItemText();
@ -5796,10 +5797,6 @@ type tcustomprogressbar=class(TCustomControl)
FbarColor:=0xD77800;
color:=0xf0f0f0;
end
function isContainer(cd);override;
begin
return 0;
end
function paint();override;
begin
inherited;