From e855fce170a6e2e131b35413f8457e456187ece5 Mon Sep 17 00:00:00 2001 From: JianjunLiu Date: Tue, 1 Nov 2022 14:40:24 +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 浠g爜鏁寸悊 --- funcext/tvclib/tcontrol.tsf | 85 +++++++++++++--------------------- funcext/tvclib/tslvcl.tsf | 2 +- funcext/tvclib/twincontrol.tsf | 16 ++++--- funcext/tvclib/utslvclpage.tsf | 8 ++++ 4 files changed, 49 insertions(+), 62 deletions(-) diff --git a/funcext/tvclib/tcontrol.tsf b/funcext/tvclib/tcontrol.tsf index 56725a2..ebd32ef 100644 --- a/funcext/tvclib/tcontrol.tsf +++ b/funcext/tvclib/tcontrol.tsf @@ -85,9 +85,6 @@ type tcontrol = class(tcomponent) //FMouseEntered;//: boolean; FVisible;//: Boolean; //可见 FID; //id - - FOnMeasureItem; - FOnDrawItem; #!end //位置信息 FLeft:integer; //左边 @@ -342,6 +339,15 @@ type tcontrol = class(tcomponent) bindmessage(i,findfunction(v,o)); end end + function preparesetparent(np); + begin + if (np is getparenttype()) then + begin + if not CheckNewParent(np) then return ; + if not np.checknewchild(self(true)) then return ; + end + SetParent(np); + end protected //部分属性设置 function GetControlFont();virtual; begin @@ -496,7 +502,7 @@ type tcontrol = class(tcomponent) @explan(说明) 子控件删除 %% **} end - function operatectrl(actrl,op);virtual; //控件操作通知 + function operatectrl(actrl,op); //控件操作通知 begin idx := FControls.indexof(actrl); if op=opRemove then @@ -689,36 +695,6 @@ type tcontrol = class(tcomponent) begin DoCNCOMMAND(o,e); end - function CNMEASUREITEM(o,e):CN_MEASUREITEM;virtual; - begin - CallMessgeFunction(FOnMeasureItem,o,e); - DoMeasureItem(o,e); - end - function DoMeasureItem(o,e);virtual; - begin - {** - @explan(说明) 控件测量通知消息 %% - @param(o)(TWinControl) 控件自身 %% - @param(e)(TMMEASUREITEM) 消息 %% - **} - end - function CNDRAWITEM(o,e):CN_DRAWITEM;virtual; - begin - //tb := new tbrush(); - //tbh := tb.handle; - //odh := _wapi.SelectObject(canvas.Handle,tbh); - DoDrawItem(o,e); - //_wapi.SelectObject(canvas.Handle,odh); - end - function DoDrawItem(o,e);virtual; - begin - { - @explan(说明) 控件绘制通知消息 %% - @param(o)(TWinControl) 控件自身 %% - @param(e)(TMDRAWITEM) 消息 %% - } - CallMessgeFunction(FOnDrawItem,o,e); - end function DoMouseEnter(o,e);virtual; begin { @@ -993,8 +969,6 @@ type tcontrol = class(tcomponent) CallMessgeFunction(OnSize,o,e); DoWMSIZE(o,e); end - - function CMCursorChanged(o,e):CM_CURSORCHANGED;virtual; begin //if SetTempCursor(o.Cursor) then e.skip := true; @@ -1166,15 +1140,22 @@ type tcontrol = class(tcomponent) FCursor := new tcustomcursor(); FCursor.id := IDC_ARROW; end - procedure CheckNewParent(AParent:TWinControl);virtual; //检查parent + function checknewparent(AParent:TWinControl);virtual; //检查parent begin { - @ignore(忽略) - @explan(说明) 判断是否可以作为父节点 + @explan(说明) 判断是否可以作为当前类型的父节点 %% + @return(bool) } - return(AParent is getparenttype()) ;//and AParent.IsContainer(self(true)); - return false; + return true; end + function checknewchild(achild);virtual;//检查child + begin + { + @explan(说明) 判断是否可以作为当前类型的子节点 %% + @return(bool) + } + return true; + end function Recycling();override; //销毁处理 begin {** @@ -1281,10 +1262,6 @@ type tcontrol = class(tcomponent) begin //if Dragging() then DragManager.DragStop(Drop); end - function getmessagehandle(id);virtual; - begin - if ifnumber(id)and FMessagehandle then return FMessagehandle[id]; - end function dispatch(o,e);virtual; //分发消息 begin {** @@ -1292,8 +1269,12 @@ type tcontrol = class(tcomponent) @param(o)()控件自身 %% @param(e)(tuieventbase) 消息类及其子类 %% **} - func := getmessagehandle(e.Msg); - if func then call(func,o,e); + id := e.Msg; + if ifnumber(id) and FMessagehandle then + begin + func := FMessagehandle[id]; + if func then call(func,o,e); + end end procedure DoControlAlign();virtual;//调整子控件位置 begin @@ -1491,7 +1472,7 @@ type tcontrol = class(tcomponent) property OnDblClick:eventhandler read FOnDblClick write FOnDblClick; //property OnResize read FOnResize write FOnResize; property OnShowHint read FOnShowHint write FOnShowHint; - property Parent read FParent write SetParent; + property Parent read FParent write preparesetparent; property PopupMenu:tpopupmenu read FPopupMenu write FPopupMenu{read GetPopupmenu write SetPopupMenu}; //property ShowHint read FShowHint write SetShowHint ; property Visible:bool read FVisible write SetVisible ; @@ -1507,16 +1488,14 @@ type tcontrol = class(tcomponent) @param(Height)(integer) 高度 %% @param(Width)(integer) 宽度 %% @param(Zorder)(integer) 设置控件在父窗口的次序,最底层为 0 %% - @param(Top)() 上方位置 %% - @param(Left)() 左边 %% + @param(Top)(integer) 上方位置 %% + @param(Left)(integer) 左边 %% **} property BoundsRect read GetBoundsRect write SetBoundsRect; property Zorder read GetZorder write SetZorder; property ControlState: TControlState read FControlState write FControlState; property Color:color read getcolor write SetColor;//FColor; property BKBitmap:tbitmap read FBKBitmap write SetBitmap; - property OnMeasureItem read FOnMeasureItem write FOnMeasureItem; - property OnDrawItem read FOnDrawItem write FOnDrawItem; //property OnMouseEnter:eventhandler read FOnMouseEnter write FOnMouseEnter; //property OnMouseLeave:eventhandler read FOnMouseLeave write FOnMouseLeave; property Controls read FControls; @@ -1526,8 +1505,6 @@ type tcontrol = class(tcomponent) @param(Controls)(TFpList of tcontrol) 子组件 %% @param(OnMouseLeave)(function[TControl,tuieventbase]) 鼠标离开回调 %% @param(OnMouseEnter)(function[TControl,tuieventbase]) 鼠标进入回调 %% - @param(OnMeasureItem)(function[TControl,TMMEASUREITEM]) 控件测量回调 %% - @param(OnDrawItem)(function[TControl,TMDRAWITEM]) 控件绘制回调 %% @param(Color)(integer) 背景色 %% **} function isCustomPaint(); //提供给gtk使用 diff --git a/funcext/tvclib/tslvcl.tsf b/funcext/tvclib/tslvcl.tsf index 3a9095a..7a4491b 100644 --- a/funcext/tvclib/tslvcl.tsf +++ b/funcext/tvclib/tslvcl.tsf @@ -3021,7 +3021,7 @@ type TPairSplitterSide=class(TCustomControl) oldparent.RemoveSide(self); end inherited; - parent.AddSide(self); + parent.AddSide(self(true)); end else if not(p is class(TWincontrol))then begin diff --git a/funcext/tvclib/twincontrol.tsf b/funcext/tvclib/twincontrol.tsf index e44d551..4567025 100644 --- a/funcext/tvclib/twincontrol.tsf +++ b/funcext/tvclib/twincontrol.tsf @@ -1961,9 +1961,10 @@ type TWinControl = class(tcontrol) end function SetParent(NewParent);override; //type_twinctrol begin + ih := HandleAllocated(); if(NewParent=parent)and(NewParent is class(TWinControl))then //避免wrapcontrol句柄发生改变的问题 begin - if HandleAllocated()and NewParent.HandleAllocated()then + if ih and NewParent.HandleAllocated()then begin if _wapi.GetParent(self.Handle)=NewParent.Handle then return; end @@ -1974,7 +1975,8 @@ type TWinControl = class(tcontrol) //都有句柄 callparent := false; callalocate := false; - if HandleAllocated()and NewParent.HandleAllocated()then + ph := NewParent.HandleAllocated(); + if ih and ph then begin if WsPopUp then begin @@ -1983,12 +1985,12 @@ type TWinControl = class(tcontrol) end else if _wapi.SetParent(FHandle,NewParent.handle)then callparent := true; end else - if HandleAllocated()and not(NewParent.HandleAllocated())then + if ih and not(ph)then begin DestroyHandle(); callparent := true; end else - if not(HandleAllocated())and NewParent.HandleAllocated()then + if not(ih)and ph then begin callparent := true; callalocate := true; @@ -1997,8 +1999,8 @@ type TWinControl = class(tcontrol) callparent := true; end if callparent then - begin - class(tcontrol).SetParent(NewParent); + begin + inherited SetParent(NewParent);//class(tcontrol).SetParent(NewParent); if Align <> alNone then begin NewParent.DoControlAlign(); @@ -2007,7 +2009,7 @@ type TWinControl = class(tcontrol) if callalocate then HandleNeeded(); end else begin - if HandleAllocated()then DestroyHandle(); + if ih then DestroyHandle(); inherited SetParent(NewParent); end end diff --git a/funcext/tvclib/utslvclpage.tsf b/funcext/tvclib/utslvclpage.tsf index f4fc5a9..944a1c5 100644 --- a/funcext/tvclib/utslvclpage.tsf +++ b/funcext/tvclib/utslvclpage.tsf @@ -572,6 +572,14 @@ type tcustompagecontrol = class(TCustomControl) (AIndexnew