designer: correctly calculate non-visual component offsets for the designer form

git-svn-id: trunk@22815 -
This commit is contained in:
paul 2009-11-27 02:36:03 +00:00
parent 3058df5224
commit b255bc1884

View File

@ -139,19 +139,30 @@ begin
end; end;
end else end else
begin begin
ParentForm := GetDesignerForm(Component);
Result.X := LeftFromDesignInfo(Component.DesignInfo); Result.X := LeftFromDesignInfo(Component.DesignInfo);
Result.Y := TopFromDesignInfo(Component.DesignInfo); Result.Y := TopFromDesignInfo(Component.DesignInfo);
while Component.Owner <> ParentForm do
begin
Component := Component.Owner;
if Component is TControl then
begin
inc(Result.X, TControl(Component).Left);
inc(Result.Y, TControl(Component).Top);
end;
end;
end; end;
end; end;
function GetParentFormRelativeBounds(Component: TComponent): TRect; function GetParentFormRelativeBounds(Component: TComponent): TRect;
var CTopLeft: TPoint; var
CTopLeft: TPoint;
begin begin
CTopLeft:=GetParentFormRelativeTopLeft(Component); CTopLeft := GetParentFormRelativeTopLeft(Component);
Result.Left:=CTopLeft.X; Result.Left := CTopLeft.X;
Result.Top:=CTopLeft.Y; Result.Top := CTopLeft.Y;
Result.Right:=Result.Left+GetComponentWidth(Component); Result.Right := Result.Left + GetComponentWidth(Component);
Result.Bottom:=Result.Top+GetComponentHeight(Component); Result.Bottom := Result.Top + GetComponentHeight(Component);
end; end;
function GetParentFormRelativeClientOrigin(Component: TComponent): TPoint; function GetParentFormRelativeClientOrigin(Component: TComponent): TPoint;
@ -184,19 +195,35 @@ var
ParentForm: TCustomForm; ParentForm: TCustomForm;
Parent: TWinControl; Parent: TWinControl;
begin begin
if Component is TControl then begin if Component is TControl then
ParentForm:=GetParentForm(TControl(Component)); begin
Parent:=TControl(Component).Parent; ParentForm := GetParentForm(TControl(Component));
if (Parent=nil) or (ParentForm=nil) then begin Parent := TControl(Component).Parent;
Result:=Point(0,0); if (Parent = nil) or (ParentForm = nil) then
end else begin Result := Point(0, 0)
ParentOrigin:=Parent.ClientOrigin; else
FormOrigin:=ParentForm.ClientOrigin; begin
Result.X:=ParentOrigin.X-FormOrigin.X; ParentOrigin := Parent.ClientOrigin;
Result.Y:=ParentOrigin.Y-FormOrigin.Y; FormOrigin := ParentForm.ClientOrigin;
Result.X := ParentOrigin.X - FormOrigin.X;
Result.Y := ParentOrigin.Y - FormOrigin.Y;
end;
end
else
begin
Result := Point(0, 0);
ParentForm := GetDesignerForm(Component);
if ParentForm = nil then
Exit;
while Component.Owner <> ParentForm do
begin
Component := Component.Owner;
if Component is TControl then
begin
inc(Result.X, TControl(Component).Left);
inc(Result.Y, TControl(Component).Top);
end;
end; end;
end else begin
Result:=Point(0,0);
end; end;
end; end;