mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-02 19:40:28 +02:00
IDE: designer: using Left,Top properties if available for non TControl forms
git-svn-id: trunk@21619 -
This commit is contained in:
parent
370bd8aff3
commit
a288977d4c
@ -34,7 +34,7 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Types, LCLProc, LCLIntf, LCLType, Forms, Controls,
|
||||
Graphics, FormEditingIntf;
|
||||
typinfo, Graphics, FormEditingIntf;
|
||||
|
||||
type
|
||||
TDesignerDCFlag = (
|
||||
@ -116,6 +116,12 @@ function DesignInfoFrom(const ALeft, ATop: SmallInt): LongInt;
|
||||
procedure DesignInfoTo(ADesignInfo: LongInt; out ALeft, ATop: SmallInt);
|
||||
function LeftFromDesignInfo(ADesignInfo: LongInt): SmallInt;
|
||||
function TopFromDesignInfo(ADesignInfo: LongInt): SmallInt;
|
||||
procedure GetComponentLeftTopOrDesignInfo(AComponent: TComponent; out aLeft, aTop: integer); // get properties if exists, otherwise get DesignInfo
|
||||
procedure SetComponentLeftTopOrDesignInfo(AComponent: TComponent; aLeft, aTop: integer); // set properties if exists, otherwise set DesignInfo
|
||||
function TrySetOrdProp(Instance: TPersistent; const PropName: string;
|
||||
Value: integer): boolean;
|
||||
function TryGetOrdProp(Instance: TPersistent; const PropName: string;
|
||||
out Value: integer): boolean;
|
||||
|
||||
implementation
|
||||
|
||||
@ -365,6 +371,52 @@ begin
|
||||
Result := DesignInfoRec.Top;
|
||||
end;
|
||||
|
||||
procedure GetComponentLeftTopOrDesignInfo(AComponent: TComponent; out aLeft,
|
||||
aTop: integer);
|
||||
var
|
||||
Info: LongInt;
|
||||
begin
|
||||
Info:=AComponent.DesignInfo;
|
||||
if not TryGetOrdProp(AComponent,'Left',aLeft) then
|
||||
aLeft:=LeftFromDesignInfo(Info);
|
||||
if not TryGetOrdProp(AComponent,'Top',aTop) then
|
||||
aTop:=TopFromDesignInfo(Info);
|
||||
end;
|
||||
|
||||
procedure SetComponentLeftTopOrDesignInfo(AComponent: TComponent;
|
||||
aLeft, aTop: integer);
|
||||
var
|
||||
HasLeft: Boolean;
|
||||
HasTop: Boolean;
|
||||
begin
|
||||
HasLeft:=TrySetOrdProp(AComponent,'Left',aLeft);
|
||||
HasTop:=TrySetOrdProp(AComponent,'Top',aTop);
|
||||
if HasLeft and HasTop then exit;
|
||||
AComponent.DesignInfo:=DesignInfoFrom(aLeft,aTop);
|
||||
end;
|
||||
|
||||
function TrySetOrdProp(Instance: TPersistent; const PropName: string;
|
||||
Value: integer): boolean;
|
||||
var
|
||||
PropInfo: PPropInfo;
|
||||
begin
|
||||
PropInfo:=GetPropInfo(Instance.ClassType,PropName);
|
||||
if PropInfo=nil then exit(false);
|
||||
SetOrdProp(Instance,PropInfo,Value);
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function TryGetOrdProp(Instance: TPersistent; const PropName: string; out
|
||||
Value: integer): boolean;
|
||||
var
|
||||
PropInfo: PPropInfo;
|
||||
begin
|
||||
PropInfo:=GetPropInfo(Instance.ClassType,PropName);
|
||||
if PropInfo=nil then exit(false);
|
||||
Value:=GetOrdProp(Instance,PropInfo);
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
{ TDesignerDeviceContext }
|
||||
|
||||
function TDesignerDeviceContext.GetDCOrigin: TPoint;
|
||||
|
@ -109,7 +109,7 @@ procedure TNonControlDesignerForm.DoLoadBounds;
|
||||
|
||||
var
|
||||
CurDataModule: TDataModule;
|
||||
NewLeft, NewTop: SmallInt;
|
||||
NewLeft, NewTop: integer;
|
||||
NewWidth, NewHeight: Integer;
|
||||
begin
|
||||
inherited DoLoadBounds;
|
||||
@ -126,7 +126,7 @@ begin
|
||||
end else
|
||||
if LookupRoot <> nil then
|
||||
begin
|
||||
DesignInfoTo(LookupRoot.DesignInfo, NewLeft, NewTop);
|
||||
GetComponentLeftTopOrDesignInfo(LookupRoot,NewLeft,NewTop);
|
||||
SetNewBounds(NewLeft, NewTop, Width, Height);
|
||||
end;
|
||||
end;
|
||||
@ -141,7 +141,7 @@ begin
|
||||
end;
|
||||
end else if LookupRoot<>nil then begin
|
||||
//debugln('TNonControlDesignerForm.DoSaveBounds ',dbgsName(LookupRoot),' ',dbgs(Left),',',dbgs(Top));
|
||||
LookupRoot.DesignInfo := DesignInfoFrom(Left, Top)
|
||||
SetComponentLeftTopOrDesignInfo(LookupRoot,Left,Top);
|
||||
end;
|
||||
inherited DoSaveBounds;
|
||||
end;
|
||||
|
@ -1740,8 +1740,9 @@ begin
|
||||
|
||||
CompLeft := Max(Low(SmallInt), Min(High(SmallInt), CompLeft));
|
||||
CompTop := Max(Low(SmallInt), Min(High(SmallInt), CompTop));
|
||||
NewComponent.DesignInfo := DesignInfoFrom(CompLeft, CompTop);
|
||||
if ParentComponent <> nil then
|
||||
|
||||
SetComponentLeftTopOrDesignInfo(NewComponent,CompLeft,CompTop);
|
||||
if ParentComponent <> nil then
|
||||
begin
|
||||
DesignForm := GetDesignerForm(ParentComponent);
|
||||
if DesignForm <> nil then DesignForm.Invalidate;
|
||||
|
Loading…
Reference in New Issue
Block a user