IDE: designer: auto resetting frame bounds/anchors

git-svn-id: trunk@15232 -
This commit is contained in:
mattias 2008-05-26 07:40:37 +00:00
parent 34db4880ce
commit b87e7979e5
2 changed files with 44 additions and 10 deletions

View File

@ -39,9 +39,12 @@ type
TFrameDesignerForm = class(TCustomNonFormDesignerForm)
protected
FChangingBounds: Boolean;
procedure SetLookupRoot(const AValue: TComponent); override;
procedure OnControlChangeBounds(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure DoLoadBounds; override;
procedure DoSaveBounds; override;
procedure SetBounds(aLeft, aTop, aWidth, aHeight: integer); override;
@ -58,11 +61,45 @@ begin
inherited Create(AOwner);
end;
procedure TFrameDesignerForm.SetLookupRoot(const AValue: TComponent);
destructor TFrameDesignerForm.Destroy;
begin
if (AValue is TControl) then
TControl(AValue).Parent := Self;
inherited;
if LookupRoot is TControl then
TControl(LookupRoot).RemoveAllHandlersOfObject(Self);
inherited Destroy;
end;
procedure TFrameDesignerForm.SetLookupRoot(const AValue: TComponent);
var
AControl: TControl;
begin
if AValue=LookupRoot then exit;
if LookupRoot is TControl then
TControl(LookupRoot).RemoveAllHandlersOfObject(Self);
if (AValue is TControl) then begin
AControl:=TControl(AValue);
AControl.Parent := Self;
AControl.AddHandlerOnChangeBounds(@OnControlChangeBounds,true);
end;
inherited SetLookupRoot(AValue);
end;
procedure TFrameDesignerForm.OnControlChangeBounds(Sender: TObject);
var
AControl: TControl;
a: TAnchorKind;
begin
if FChangingBounds then exit;
AControl:=TControl(LookupRoot);
FChangingBounds:=true;
try
// reset anchors
for a:=Low(TAnchorKind) to High(TAnchorKind) do
AControl.AnchorSide[a].Control:=nil;
// reset bounds
AControl.SetBounds(0, 0, Width, Height);
finally
FChangingBounds:=false;
end;
end;
procedure TFrameDesignerForm.DoLoadBounds;
@ -92,7 +129,7 @@ begin
NewTop:=LongRec(LookupRoot.DesignInfo).Hi;
// resize designer form
SetNewBounds(NewLeft,NewTop,CurControl.Width,CurControl.Height);
DebugLn(['TFrameDesignerForm.DoLoadBounds ',NewLeft,',',NewTop]);
//DebugLn(['TFrameDesignerForm.DoLoadBounds ',NewLeft,',',NewTop]);
end
else
if LookupRoot <> nil then
@ -107,7 +144,7 @@ begin
LongRec(LookupRoot.DesignInfo).Hi:=Top;
// always fill the whole designer form
TControl(LookupRoot).SetBounds(0, 0, Width, Height);
DebugLn(['TFrameDesignerForm.DoSaveBounds ',Left,',',Top,' ',LongRec(LookupRoot.DesignInfo).Lo,',',LongRec(LookupRoot.DesignInfo).hi]);
//DebugLn(['TFrameDesignerForm.DoSaveBounds ',Left,',',Top,' ',LongRec(LookupRoot.DesignInfo).Lo,',',LongRec(LookupRoot.DesignInfo).hi]);
end else
if LookupRoot <> nil then
DebugLn(['Unsupported component type in TFrameDesignerForm.DoSaveBounds: ', LookupRoot.ClassName]);

View File

@ -1634,11 +1634,8 @@ begin
DebugLn(['TJITComponentList.ReaderCreateComponent creating ',DbgSName(ComponentClass),' Owner=',DbgSName(Reader.Owner),' ...']);
// allocate memory without running the constructor
Component:=TComponent(ComponentClass.newinstance);
// set csDesigning and csDesignInstance
// csDesigning is set for all components at designtime
// csDesignInstance is set for Delphi compatibility. It is used by TFrame.
// set csDesigning
SetComponentDesignMode(Component,true);
SetComponentDesignInstanceMode(Component,true);
// this is a streamed sub component => set csInline
SetComponentInlineMode(Component,true);
// now run the constructor