From fe6e2c7eae682104d38a05c861409cc8d087bedc Mon Sep 17 00:00:00 2001 From: JianjunLiu Date: Tue, 1 Nov 2022 10:29:54 +0800 Subject: [PATCH] =?UTF-8?q?=E7=95=8C=E9=9D=A2=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化代码 --- funcext/tvclib/tcontrol.tsf | 10 +- funcext/tvclib/tgraphiccontrol.tsf | 4 - funcext/tvclib/tslvcl.tsf | 24 +-- funcext/tvclib/utslvclpage.tsf | 336 ++++++++++++----------------- funcext/tvclib/utslvclstdctl.tsf | 9 +- 5 files changed, 140 insertions(+), 243 deletions(-) diff --git a/funcext/tvclib/tcontrol.tsf b/funcext/tvclib/tcontrol.tsf index 9693a2e..56725a2 100644 --- a/funcext/tvclib/tcontrol.tsf +++ b/funcext/tvclib/tcontrol.tsf @@ -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; //ٴ diff --git a/funcext/tvclib/tgraphiccontrol.tsf b/funcext/tvclib/tgraphiccontrol.tsf index 59ad0be..bd646b4 100644 --- a/funcext/tvclib/tgraphiccontrol.tsf +++ b/funcext/tvclib/tgraphiccontrol.tsf @@ -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; diff --git a/funcext/tvclib/tslvcl.tsf b/funcext/tvclib/tslvcl.tsf index 2bda4ce..3a9095a 100644 --- a/funcext/tvclib/tslvcl.tsf +++ b/funcext/tvclib/tslvcl.tsf @@ -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(˵)ȡؼǰѡʱ%% diff --git a/funcext/tvclib/utslvclpage.tsf b/funcext/tvclib/utslvclpage.tsf index 0f5ce3f..f4fc5a9 100644 --- a/funcext/tvclib/utslvclpage.tsf +++ b/funcext/tvclib/utslvclpage.tsf @@ -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=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 id1 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 AIndex0 then return FTabItems[AIndex].Caption; + if AIndex0 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=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=0) and (AIndexnew=0) and + (AIndexnewFVisible 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. \ No newline at end of file diff --git a/funcext/tvclib/utslvclstdctl.tsf b/funcext/tvclib/utslvclstdctl.tsf index 15b8298..55ad6ba 100644 --- a/funcext/tvclib/utslvclstdctl.tsf +++ b/funcext/tvclib/utslvclstdctl.tsf @@ -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;