designer: csInline component fixes:

- fix relative coords of non-visual components if their owner has parent
  - clip non-visual components by parent client rectangle

git-svn-id: trunk@23082 -
This commit is contained in:
paul 2009-12-11 07:25:18 +00:00
parent 8469b98fc7
commit 39c6ed894c
2 changed files with 48 additions and 39 deletions

View File

@ -245,7 +245,7 @@ type
destructor Destroy; override; destructor Destroy; override;
procedure Modified; override; procedure Modified; override;
procedure SelectOnlyThisComponent(AComponent:TComponent); override; procedure SelectOnlyThisComponent(AComponent: TComponent); override;
function CopySelection: boolean; override; function CopySelection: boolean; override;
function CutSelection: boolean; override; function CutSelection: boolean; override;
function CanPaste: Boolean; override; function CanPaste: Boolean; override;
@ -1338,7 +1338,7 @@ begin
end; end;
end; end;
procedure TDesigner.SelectOnlyThisComponent(AComponent:TComponent); procedure TDesigner.SelectOnlyThisComponent(AComponent: TComponent);
begin begin
ControlSelection.AssignPersistent(AComponent); ControlSelection.AssignPersistent(AComponent);
end; end;
@ -1431,14 +1431,15 @@ function TDesigner.NonVisualComponentLeftTop(AComponent: TComponent): TPoint;
begin begin
Result.X := LeftFromDesignInfo(AComponent.DesignInfo); Result.X := LeftFromDesignInfo(AComponent.DesignInfo);
Result.Y := TopFromDesignInfo(AComponent.DesignInfo); Result.Y := TopFromDesignInfo(AComponent.DesignInfo);
// convert to owner coords // convert to lookuproot coords
while AComponent.Owner <> FLookupRoot do if (AComponent.Owner <> FLookupRoot) and (FLookupRoot is TControl) then
begin begin
AComponent := AComponent.Owner; AComponent := AComponent.Owner;
if AComponent is TControl then if AComponent is TControl then
with TControl(FLookupRoot).ScreenToClient(TControl(AComponent).ClientToScreen(Point(0, 0))) do
begin begin
inc(Result.X, TControl(AComponent).Left); inc(Result.X, X);
inc(Result.Y, TControl(AComponent).Top); inc(Result.Y, Y);
end; end;
end; end;
end; end;
@ -2991,10 +2992,11 @@ var
Icon: TBitmap; Icon: TBitmap;
ItemLeft, ItemTop, ItemRight, ItemBottom: integer; ItemLeft, ItemTop, ItemRight, ItemBottom: integer;
Diff, ItemLeftTop: TPoint; Diff, ItemLeftTop: TPoint;
IconRect, TextRect: TRect; OwnerRect, IconRect, TextRect: TRect;
TextSize: TSize; TextSize: TSize;
IsSelected: Boolean; IsSelected: Boolean;
Root: TComponent; Root: TComponent;
RGN: HRGN;
begin begin
// also call draw for the inline components children // also call draw for the inline components children
if (csInline in AComponent.ComponentState) or (AComponent.Owner=nil) then if (csInline in AComponent.ComponentState) or (AComponent.Owner=nil) then
@ -3002,7 +3004,9 @@ begin
else else
Root:=AComponent.Owner; Root:=AComponent.Owner;
TComponentAccess(AComponent).GetChildren(@DrawNonVisualComponent, Root); TComponentAccess(AComponent).GetChildren(@DrawNonVisualComponent, Root);
if not ComponentIsIcon(AComponent) then if not ComponentIsIcon(AComponent) or (AComponent.Owner = nil) then
Exit;
if not (AComponent.Owner is TControl) then
Exit; Exit;
// actual draw // actual draw
Diff := FDDC.FormOrigin; Diff := FDDC.FormOrigin;
@ -3019,6 +3023,19 @@ begin
IsSelected := ControlSelection.IsSelected(AComponent); IsSelected := ControlSelection.IsSelected(AComponent);
FDDC.Save; FDDC.Save;
// set clipping
if AComponent.Owner <> FDDC.Form then
begin
OwnerRect := TControl(AComponent.Owner).ClientRect;
Diff := FDDC.Form.ScreenToClient(TControl(AComponent.Owner).ClientToScreen(Point(0, 0)));
OffsetRect(OwnerRect, Diff.X, Diff.Y);
// don't restore later FDDC.Restore will do this itself
with OwnerRect do
RGN := CreateRectRGN(Left, Top, Right, Bottom);
SelectClipRGN(FDDC.DC, RGN);
DeleteObject(RGN);
end;
if FSurface = nil then if FSurface = nil then
begin begin
FSurface := TBitmap.Create; FSurface := TBitmap.Create;
@ -3249,21 +3266,10 @@ end;
procedure TDesigner.MoveNonVisualComponentIntoForm(AComponent: TComponent); procedure TDesigner.MoveNonVisualComponentIntoForm(AComponent: TComponent);
var var
P: TPoint; X, Y: SmallInt;
Tmp: TComponent;
begin begin
P := NonVisualComponentLeftTop(AComponent); DesignInfoToLeftTop(AComponent.DesignInfo, X, Y);
Tmp := AComponent; AComponent.DesignInfo := LeftTopToDesignInfo(X, Y);
while Tmp.Owner <> FLookupRoot do
begin
Tmp := Tmp.Owner;
if Tmp is TControl then
begin
dec(P.X, TControl(Tmp).Left);
dec(P.Y, TControl(Tmp).Top);
end;
end;
AComponent.DesignInfo := LeftTopToDesignInfo(P.X, P.Y);
end; end;
procedure TDesigner.MoveNonVisualComponentsIntoForm; procedure TDesigner.MoveNonVisualComponentsIntoForm;

View File

@ -139,19 +139,22 @@ 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 <> nil) and (Component.Owner <> ParentForm) do ParentForm := GetDesignerForm(Component);
if ParentForm = nil then
Exit;
if (Component <> nil) and (Component.Owner <> ParentForm) then
begin begin
Component := Component.Owner; Component := Component.Owner;
if Component = nil then if (csInline in Component.ComponentState) and (Component is TControl) then
break;
if (csInline in Component.ComponentState) and
(Component is TControl) then
begin begin
inc(Result.X, TControl(Component).Left); with ParentForm.ScreenToClient(TControl(Component).ClientToScreen(Point(0, 0))) do
inc(Result.Y, TControl(Component).Top); begin
inc(Result.X, X);
inc(Result.Y, Y);
end;
end; end;
end; end;
end; end;
@ -218,16 +221,16 @@ begin
ParentForm := GetDesignerForm(Component); ParentForm := GetDesignerForm(Component);
if ParentForm = nil then if ParentForm = nil then
Exit; Exit;
while (Component <> nil) and (Component.Owner <> ParentForm) do if (Component <> nil) and (Component.Owner <> ParentForm) then
begin begin
Component := Component.Owner; Component := Component.Owner;
if Component = nil then if (csInline in Component.ComponentState) and (Component is TControl) then
break;
if (csInline in Component.ComponentState) and
(Component is TControl) then
begin begin
inc(Result.X, TControl(Component).Left); with ParentForm.ScreenToClient(TControl(Component).ClientToScreen(Point(0, 0))) do
inc(Result.Y, TControl(Component).Top); begin
inc(Result.X, X);
inc(Result.Y, Y);
end;
end; end;
end; end;
end; end;