From 0bc32656ed63e1197e01acb5ba0607d5df81ae37 Mon Sep 17 00:00:00 2001 From: Juha Date: Mon, 3 Jul 2023 16:51:51 +0300 Subject: [PATCH] LazUtils, LCL: Move LCLProc.CompareRect() -> GraphMath.SameRect(). Deprecate LCLProc.CompareRect(). --- .../anchordocking/anchordockstorage.pas | 12 ++++----- components/h2pas/h2pasconvert.pas | 8 +++--- components/lazutils/graphmath.pp | 11 ++++++++ designer/controlselection.pp | 9 +++---- designer/designer.pp | 10 +++---- ide/codecontextform.pas | 4 +-- lcl/controls.pp | 2 +- lcl/include/control.inc | 4 +-- lcl/include/dragobject.inc | 2 +- lcl/include/wincontrol.inc | 26 +++++++++---------- lcl/lclproc.pas | 17 +++++------- lcl/ldocktree.pas | 8 +++--- 12 files changed, 59 insertions(+), 54 deletions(-) diff --git a/components/anchordocking/anchordockstorage.pas b/components/anchordocking/anchordockstorage.pas index 1b688a57e1..297a161a49 100644 --- a/components/anchordocking/anchordockstorage.pas +++ b/components/anchordocking/anchordockstorage.pas @@ -9,9 +9,9 @@ interface uses Types, Classes, SysUtils, Math, // LCL - LCLProc, ExtCtrls, ComCtrls, Forms, Controls, + ExtCtrls, ComCtrls, Forms, Controls, // LazUtils - AvgLvlTree, LazConfigStorage, Laz2_XMLCfg, LazLoggerBase, LazTracer, + AvgLvlTree, LazConfigStorage, Laz2_XMLCfg, LazLoggerBase, LazTracer, GraphMath, // AnchorDocking AnchorDockStr; @@ -916,7 +916,7 @@ end; procedure TAnchorDockLayoutTreeNode.SetBoundsRect(const AValue: TRect); begin - if CompareRect(@FBoundsRect,@AValue) then exit; + if SameRect(@FBoundsRect,@AValue) then exit; FBoundsRect:=AValue; IncreaseChangeStamp; end; @@ -1001,7 +1001,7 @@ end; procedure TAnchorDockLayoutTreeNode.SetWorkAreaRect(const AValue: TRect); begin - if CompareRect(@FWorkAreaRect,@AValue) then exit; + if SameRect(@FWorkAreaRect,@AValue) then exit; FWorkAreaRect:=AValue; IncreaseChangeStamp; end; @@ -1083,7 +1083,7 @@ var a: TAnchorKind; begin Result:=false; - if (not CompareRect(@FBoundsRect,@Node.FBoundsRect)) + if (not SameRect(@FBoundsRect,@Node.FBoundsRect)) or (Count<>Node.Count) or (NodeType<>Node.NodeType) or (Name<>Node.Name) @@ -1094,7 +1094,7 @@ begin or (PageIndex<>Node.PageIndex) or (BoundSplitterPos<>Node.BoundSplitterPos) or (PixelsPerInch<>Node.PixelsPerInch) - or (not CompareRect(@FWorkAreaRect,@Node.FWorkAreaRect)) + or (not SameRect(@FWorkAreaRect,@Node.FWorkAreaRect)) then exit; for a:=low(TAnchorKind) to high(TAnchorKind) do diff --git a/components/h2pas/h2pasconvert.pas b/components/h2pas/h2pasconvert.pas index 98235191e8..b9ce1a1089 100644 --- a/components/h2pas/h2pasconvert.pas +++ b/components/h2pas/h2pasconvert.pas @@ -25,9 +25,9 @@ interface uses Classes, SysUtils, Laz_AVL_Tree, // LCL - LCLProc, LResources, Forms, Controls, Dialogs, XMLPropStorage, + LResources, Forms, Controls, Dialogs, XMLPropStorage, // LazUtils - LazConfigStorage, FileUtil, LazFileUtils, LazFileCache, + LazConfigStorage, FileUtil, LazFileUtils, LazFileCache, GraphMath, // CodeTools CodeAtom, CodeTree, KeywordFuncLists, NonPascalCodeTools, BasicCodeTools, FileProcs, CodeCache, SourceChanger, CodeToolManager, @@ -1789,7 +1789,7 @@ end; procedure TH2PasConverter.SetWindowBounds(const AValue: TRect); begin - if CompareRect(@FWindowBounds,@AValue) then exit; + if SameRect(@FWindowBounds,@AValue) then exit; FWindowBounds:=AValue; Modified:=true; end; @@ -1847,7 +1847,7 @@ end; function TH2PasConverter.IsEqual(AConverter: TH2PasConverter): boolean; begin if (FAutoOpenLastProject<>AConverter.FAutoOpenLastProject) - or (not CompareRect(@FWindowBounds,@AConverter.FWindowBounds)) + or (not SameRect(@FWindowBounds,@AConverter.FWindowBounds)) or (Fh2pasFilename<>AConverter.h2pasFilename) or (not FProjectHistory.Equals(AConverter.FProjectHistory)) then diff --git a/components/lazutils/graphmath.pp b/components/lazutils/graphmath.pp index 7f3f961c68..12363fd792 100644 --- a/components/lazutils/graphmath.pp +++ b/components/lazutils/graphmath.pp @@ -81,6 +81,7 @@ procedure MakeMinMax(var i1, i2: integer); procedure MoveRect(var ARect: TRect; x, y: Integer); procedure MoveRectToFit(var ARect: TRect; const MaxRect: TRect); +function SameRect(R1, R2: PRect): Boolean; procedure PolyBezier2Polyline(Beziers: Array of TBezier; var Points : PPoint; var Count : Longint); Overload; @@ -872,6 +873,16 @@ begin end; end; +function SameRect(R1, R2: PRect): Boolean; +begin + Result:=(R1^.Left=R2^.Left) and (R1^.Top=R2^.Top) and + (R1^.Bottom=R2^.Bottom) and (R1^.Right=R2^.Right); + {if not Result then begin + DebugLn(' DIFFER: ',R1^.Left,',',R1^.Top,',',R1^.Right,',',R1^.Bottom + ,' <> ',R2^.Left,',',R2^.Top,',',R2^.Right,',',R2^.Bottom); + end;} +end; + {------------------------------------------------------------------------------ Method: PolyBezier2Polyline Params: Beziers, Points, Count diff --git a/designer/controlselection.pp b/designer/controlselection.pp index c7f059d234..da0141b8ee 100644 --- a/designer/controlselection.pp +++ b/designer/controlselection.pp @@ -39,9 +39,9 @@ interface uses Types, Classes, SysUtils, Math, FPCanvas, // LCL - LCLIntf, LCLProc, Controls, Forms, Graphics, Menus, ComCtrls, + LCLIntf, Controls, Forms, Graphics, Menus, ComCtrls, // LazUtils - GraphType, GraphMath, + GraphType, GraphMath, LazLoggerBase, // IDEIntf PropEditUtils, ComponentEditors, FormEditingIntf, // IDE @@ -772,7 +772,7 @@ var r: TRect; begin r:=GetBounds; - Result:=not CompareRect(@r,@FMovedResizedBounds); + Result:=not SameRect(@r,@FMovedResizedBounds); end; function TSelectedControl.IsTopLvl: boolean; @@ -2838,7 +2838,6 @@ end; procedure TControlSelection.SetRubberBandBounds(ARect:TRect); var - i :integer; InvFrame: TRect; begin if FForm = nil then exit; @@ -2847,7 +2846,7 @@ begin MakeMinMax(ARect.Left, ARect.Right); MakeMinMax(ARect.Top, ARect.Bottom); - if not CompareRect(@FRubberBandBounds, @ARect) then + if not SameRect(@FRubberBandBounds, @ARect) then begin if (FForm <> nil) and (cssRubberbandPainted in FStates) then begin diff --git a/designer/designer.pp b/designer/designer.pp index 7df3532e1d..811dda02fe 100644 --- a/designer/designer.pp +++ b/designer/designer.pp @@ -40,10 +40,10 @@ uses // RTL + FCL Types, Classes, Math, SysUtils, Variants, TypInfo, // LCL - LCLProc, LCLType, LResources, LCLIntf, LMessages, InterfaceBase, + LCLType, LResources, LCLIntf, LMessages, InterfaceBase, Forms, Controls, Graphics, Dialogs, ExtCtrls, Menus, ClipBrd, // LazUtils - GraphType, LazFileUtils, LazFileCache, LazLoggerBase, LazUtilities, + GraphType, GraphMath, LazFileUtils, LazFileCache, LazLoggerBase, LazUtilities, // IDEIntf IDEDialogs, PropEdits, PropEditUtils, ComponentEditors, MenuIntf, IDEImagesIntf, FormEditingIntf, ComponentReg, IDECommands, LazIDEIntf, @@ -3716,8 +3716,8 @@ var begin NewFormBounds:=Form.BoundsRect; if FDefaultFormBoundsValid then begin - if (not CompareRect(@NewFormBounds,@FLastFormBounds)) - and (not CompareRect(@NewFormBounds,@FDefaultFormBounds)) then begin + if (not SameRect(@NewFormBounds,@FLastFormBounds)) + and (not SameRect(@NewFormBounds,@FDefaultFormBounds)) then begin //debugln('TDesigner.CheckFormBounds'); Modified; if Selection.SelectionForm=Form then begin @@ -4179,7 +4179,7 @@ var if not (Ancestor is TControl) then exit; OldBounds:=AControl.BoundsRect; NewBounds:=Ancestor.BoundsRect; - if not CompareRect(@OldBounds,@NewBounds) then begin + if not SameRect(@OldBounds,@NewBounds) then begin AControl.BoundsRect:=NewBounds; HasChanged:=true; end; diff --git a/ide/codecontextform.pas b/ide/codecontextform.pas index 3892625314..e3b12bac7b 100644 --- a/ide/codecontextform.pas +++ b/ide/codecontextform.pas @@ -42,7 +42,7 @@ uses LCLProc, LCLType, LCLIntf, LResources, LMessages, Forms, Controls, Graphics, Dialogs, Themes, Buttons, // LazUtils - LazStringUtils, + LazStringUtils, GraphMath, // SynEdit SynEdit, SynEditKeyCmds, // CodeTools @@ -882,7 +882,7 @@ var inc(y,(LineHeight-FBtnWidth) div 2); Item.NewBounds:=Bounds(AHintRect.Right-RightSpace-1,y,FBtnWidth,FBtnWidth); r:=Item.CopyAllButton.BoundsRect; - if not CompareRect(@r,@Item.NewBounds) then + if not SameRect(@r,@Item.NewBounds) then IdleConnected:=true; end; //debugln(['DrawHint ',y,' Line="',dbgstr(Line),'" LineHeight=',LineHeight,' ']); diff --git a/lcl/controls.pp b/lcl/controls.pp index 15787c6463..3d448e01f1 100644 --- a/lcl/controls.pp +++ b/lcl/controls.pp @@ -3109,7 +3109,7 @@ end; function SendAppMessage(Msg: Cardinal; WParam: WParam; LParam: LParam): Longint; begin - Result:=LCLProc.SendApplicationMessage(Msg,WParam,LParam); + Result:=SendApplicationMessage(Msg,WParam,LParam); end; procedure MoveWindowOrg(dc: hdc; X, Y: Integer); diff --git a/lcl/include/control.inc b/lcl/include/control.inc index ff78e361a6..1637ede579 100644 --- a/lcl/include/control.inc +++ b/lcl/include/control.inc @@ -1384,7 +1384,7 @@ begin if [csLoading,csDestroying]*ComponentState<>[] then exit; CurBounds:=BoundsRect; CurClientSize:=Point(ClientWidth,ClientHeight); - if (not CompareRect(@FLastDoChangeBounds,@CurBounds)) + if (not SameRect(@FLastDoChangeBounds,@CurBounds)) or (ComparePoints(CurClientSize,FLastDoChangeClientSize)<>0) then begin if FormIsUpdating then begin Include(FControlFlags,cfOnChangeBoundsNeeded); @@ -4137,7 +4137,7 @@ begin end else NewBaseParentClientSize:=FBaseParentClientSize; - if (not CompareRect(@NewBaseBounds,@FBaseBounds)) + if (not SameRect(@NewBaseBounds,@FBaseBounds)) or (NewBaseParentClientSize.cx<>FBaseParentClientSize.cx) or (NewBaseParentClientSize.cy<>FBaseParentClientSize.cy) then begin diff --git a/lcl/include/dragobject.inc b/lcl/include/dragobject.inc index 277b5e77bc..2adeee6434 100644 --- a/lcl/include/dragobject.inc +++ b/lcl/include/dragobject.inc @@ -189,7 +189,7 @@ end; procedure TDragDockObject.MoveDockImage; begin //Draw the form outlines when the position has changed - if not CompareRect(@DockRect, @EraseDockRect) then + if not SameRect(@DockRect, @EraseDockRect) then begin if HasOnDrawImage then OnDrawDockImage(Self, EraseDockRect, DockRect, disMove) diff --git a/lcl/include/wincontrol.inc b/lcl/include/wincontrol.inc index 7034017b77..0a29ec516f 100644 --- a/lcl/include/wincontrol.inc +++ b/lcl/include/wincontrol.inc @@ -2277,7 +2277,7 @@ begin if CurControl=nil then continue; NewBounds:=ControlBox.NewControlBounds; OldBounds:=CurControl.BoundsRect; - if not CompareRect(@NewBounds,@OldBounds) then begin + if not SameRect(@NewBounds,@OldBounds) then begin Result:=true; CurControl.SetBoundsKeepBase(NewBounds.Left, NewBounds.Top, @@ -3045,7 +3045,7 @@ var Control.SetBoundsKeepBase(NewLeft, NewTop, NewWidth, NewHeight); //DebugLn(['DoPosition ',DbgSName(Control),' ',cfAutoSizeNeeded in Control.FControlFlags]); NewBounds:=Control.BoundsRect; - BoundsMutated:=not CompareRect(@OldBounds,@NewBounds); + BoundsMutated:=not SameRect(@OldBounds,@NewBounds); if BoundsMutated then begin LastBoundsMutated:=Control; LastBoundsMutatedOld:=OldBounds; @@ -3414,7 +3414,7 @@ begin end; // Important: change the BaseBounds too, otherwise the changes will be undone by AlignControls OldChildBounds:=AControl.BoundsRect; - if not CompareRect(@OldChildBounds,@NewChildBounds) then begin + if not SameRect(@OldChildBounds,@NewChildBounds) then begin //DebugLn(['TWinControl.DoAutoSize moving child: ',DbgSName(AControl),' Old=',dbgs(OldChildBounds),' New=',dbgs(NewChildBounds)]); AControl.BoundsRect:=NewChildBounds; //DebugLn(['TWinControl.DoAutoSize AFTER ',DbgSName(AControl),' ',dbgs(AControl.BoundsRect)]); @@ -3721,8 +3721,8 @@ begin R := GetClientRect; AdjustClientRect(R); //if CheckPosition(Self) then - //DebugLn(['TWinControl.DoAdjustClientRectChange ',DbgSName(Self),' new=',dbgs(r),' old=',dbgs(FAdjustClientRectRealized),' ',CompareRect(@r,@FAdjustClientRectRealized)]); - if not CompareRect(@R, @FAdjustClientRectRealized) then + //DebugLn(['TWinControl.DoAdjustClientRectChange ',DbgSName(Self),' new=',dbgs(r),' old=',dbgs(FAdjustClientRectRealized),' ',SameRect(@r,@FAdjustClientRectRealized)]); + if not SameRect(@R, @FAdjustClientRectRealized) then begin // client rect changed since last AlignControl {$IF defined(VerboseAllAutoSize) or defined(VerboseClientRectBugFix) or defined(VerboseIntfSizing) or defined(VerboseOnResize)} @@ -6452,7 +6452,7 @@ begin // some widgetsets updates their clientrect when the first child was moved // do a second pass if ClientRect changed NewRect:=GetLogicalClientRect; - if not CompareRect(@ARect,@NewRect) then + if not SameRect(@ARect,@NewRect) then AlignControls(AControl, NewRect); finally EnableAlign; @@ -6933,7 +6933,7 @@ begin GetWindowSize(Handle, NewWidth, NewHeight); NewBoundsRealized:=Bounds(Message.XPos, Message.YPos, NewWidth, NewHeight); - if CompareRect(@NewBoundsRealized,@FBoundsRealized) then exit; + if SameRect(@NewBoundsRealized,@FBoundsRealized) then exit; TopParent:=GetTopParent; if (TopParent is TWinControl) @@ -7024,7 +7024,7 @@ begin NewBoundsRealized := Bounds(NewLeft, NewTop, Message.Width, Message.Height); OldClientSize := Size(0, 0); NewClientSize := Size(0, 0); - if CompareRect(@NewBoundsRealized, @FBoundsRealized) then + if SameRect(@NewBoundsRealized, @FBoundsRealized) then begin if not (wcfClientRectNeedsUpdate in FWinControlFlags) then begin @@ -7146,7 +7146,7 @@ begin {$ENDIF} //DebugLn('TWinControl.WMSize B ',Name,':',ClassName,' ',NewLeft,',',NewTop); NewBoundsRealized := Bounds(NewLeft, NewTop, NewWidth, NewHeight); - if CompareRect(@NewBoundsRealized,@FBoundsRealized) + if SameRect(@NewBoundsRealized,@FBoundsRealized) and (not (wcfClientRectNeedsUpdate in FWinControlFlags)) then exit; @@ -8118,7 +8118,7 @@ begin OldBounds := BoundsRect; NewBounds := Bounds(ALeft, ATop, AWidth, AHeight); - if not CompareRect(@NewBounds, @OldBounds) then + if not SameRect(@NewBounds, @OldBounds) then begin if [csDesigning,csDestroying,csLoading]*ComponentState=[csDesigning] then CheckDesignBounds; @@ -8516,7 +8516,7 @@ begin // this can trigger WMSize messages TWSWinControlClass(WidgetSetClass).SetBounds(Self, Left, Top, Width, Height); NewClientRect := ClientRect; - if Visible and (not CompareRect(@OldClientRect,@NewClientRect)) then + if Visible and (not SameRect(@OldClientRect,@NewClientRect)) then begin // the widgetset has changed the clientrect in an unexpected way {$IFDEF VerboseIntfSizing} @@ -8553,7 +8553,7 @@ begin if HandleAllocated and ([csLoading,csDestroying]*ComponentState=[]) and (not (csDestroyingHandle in ControlState)) - and (not CompareRect(@NewBounds,@FBoundsRealized)) + and (not SameRect(@NewBounds,@FBoundsRealized)) then begin // the new bounds were not yet sent to the InterfaceObject -> send them {$IFDEF CHECK_POSITION} @@ -8579,7 +8579,7 @@ begin if not HandleAllocated then debugln('not HandleAllocated'); if (csLoading in ComponentState) then debugln('csLoading'); if (csDestroying in ComponentState) then debugln('csDestroying'); - if (CompareRect(@NewBounds,@FBoundsRealized)) then debugln('bounds not changed'); + if (SameRect(@NewBounds,@FBoundsRealized)) then debugln('bounds not changed'); end; {$ENDIF} if not HandleAllocated then Check; diff --git a/lcl/lclproc.pas b/lcl/lclproc.pas index a22fd3af76..ea097b1631 100644 --- a/lcl/lclproc.pas +++ b/lcl/lclproc.pas @@ -113,6 +113,7 @@ procedure OwnerFormDesignerModified(AComponent: TComponent); // Deprecated in version 2.3, 2023-06. procedure FreeThenNil(var obj); deprecated 'Use LazUtilities.FreeThenNil instead'; +function CompareRect(R1, R2: PRect): Boolean; deprecated 'Use GraphMath.SameRect instead'; function OffsetRect(var Rect: TRect; DX, DY: Integer): Boolean; deprecated 'Use Types.OffsetRect instead'; procedure MoveRect(var ARect: TRect; x, y: Integer); deprecated 'Use GraphMath.MoveRect instead'; procedure MoveRectToFit(var ARect: TRect; const MaxRect: TRect); deprecated 'Use GraphMath.MoveRectToFit instead'; @@ -134,7 +135,6 @@ function RemoveAmpersands(const ASource: String): String; function RemoveAmpersands(Src: PChar; var LineLength: Longint): PChar; function CompareHandles(h1, h2: TLCLHandle): integer; -function CompareRect(R1, R2: PRect): Boolean; function ComparePoints(const p1, p2: TPoint): integer; function CompareCaret(const FirstCaret, SecondCaret: TPoint): integer; @@ -835,6 +835,11 @@ begin LazUtilities.FreeThenNil(obj); end; +function CompareRect(R1, R2: PRect): Boolean; +begin + Result := GraphMath.SameRect(R1, R2); +end; + function OffsetRect(var Rect: TRect; DX, DY: Integer): Boolean; begin Result := Types.OffsetRect(Rect, DX, DY); @@ -897,16 +902,6 @@ begin Result:=0; end; -function CompareRect(R1, R2: PRect): Boolean; -begin - Result:=(R1^.Left=R2^.Left) and (R1^.Top=R2^.Top) and - (R1^.Bottom=R2^.Bottom) and (R1^.Right=R2^.Right); - {if not Result then begin - DebugLn(' DIFFER: ',R1^.Left,',',R1^.Top,',',R1^.Right,',',R1^.Bottom - ,' <> ',R2^.Left,',',R2^.Top,',',R2^.Right,',',R2^.Bottom); - end;} -end; - function ComparePoints(const p1, p2: TPoint): integer; begin if p1.Y>p2.Y then diff --git a/lcl/ldocktree.pas b/lcl/ldocktree.pas index 3659c51b69..86be66cc0d 100644 --- a/lcl/ldocktree.pas +++ b/lcl/ldocktree.pas @@ -99,9 +99,9 @@ interface uses Math, Types, Classes, SysUtils, typinfo, // LazUtils - LazLoggerBase, + LazLoggerBase, LazTracer, GraphMath, // LCL - LCLProc, LCLType, LCLIntf, LCLStrConsts, Graphics, Controls, ExtCtrls, Forms, + LCLType, LCLIntf, Graphics, Controls, ExtCtrls, Forms, Menus, Themes, ComCtrls, LMessages, LResources; type @@ -1573,7 +1573,7 @@ procedure TLazDockTree.MessageHandler(Sender: TControl; var Message: TLMessage); NewMouseState.IsMouseDown := (GetKeyState(VK_LBUTTON) and $80) <> 0; if not CompareMem(@FMouseState, @NewMouseState, SizeOf(NewMouseState)) then begin - if not CompareRect(@FMouseState.Rect, @NewMouseState.Rect) then + if not SameRect(@FMouseState.Rect, @NewMouseState.Rect) then InvalidateRect(DockSite.Handle, @FMouseState.Rect, False); FMouseState := NewMouseState; InvalidateRect(DockSite.Handle, @NewMouseState.Rect, False); @@ -2006,7 +2006,7 @@ begin end; if not CompareMem(@FMouseState, @NewMouseState, SizeOf(NewMouseState)) then begin - if not CompareRect(@FMouseState.Rect, @NewMouseState.Rect) then + if not SameRect(@FMouseState.Rect, @NewMouseState.Rect) then InvalidateRect(Handle, @FMouseState.Rect, False); FMouseState := NewMouseState; InvalidateRect(Handle, @NewMouseState.Rect, False);