LCL: Support TMenuItem.Assign(TMenuItem) and TMenu.Assign(TMenu). Issue #33345, patch from AlexeyT.

git-svn-id: trunk@57557 -
This commit is contained in:
juha 2018-03-23 10:15:47 +00:00
parent f2fad774c7
commit 7b837567c3
3 changed files with 68 additions and 1 deletions

View File

@ -314,6 +314,14 @@ begin
DoChange(Source, Rebuild);
end;
procedure TMenu.AssignTo(Dest: TPersistent);
begin
if Dest is TMenu then
Menu_Copy(Self, Dest as TMenu)
else
inherited AssignTo(Dest);
end;
procedure TMenu.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);

View File

@ -1580,7 +1580,11 @@ begin
ImageIndex := Self.ImageIndex;
Visible := Self.Visible;
end
end else
end
else
if Dest is TMenuItem then
MenuItem_Copy(Self, Dest as TMenuItem)
else
inherited AssignTo(Dest);
end;

View File

@ -339,6 +339,7 @@ type
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
procedure MenuChanged(Sender: TObject; Source: TMenuItem;
Rebuild: Boolean); virtual;
procedure AssignTo(Dest: TPersistent); override;
procedure Notification(AComponent: TComponent;
Operation: TOperation); override;
procedure ParentBidiModeChanged;
@ -476,6 +477,60 @@ uses
WSMenus,
Forms {KeyDataToShiftState};
{ Helpers for Assign() }
procedure MenuItem_Copy(ASrc, ADest: TMenuItem);
var
mi: TMenuItem;
i: integer;
begin
ADest.Clear;
ADest.Action:= ASrc.Action;
ADest.AutoCheck:= ASrc.AutoCheck;
ADest.Caption:= ASrc.Caption;
ADest.Checked:= ASrc.Checked;
ADest.Default:= ASrc.Default;
ADest.Enabled:= ASrc.Enabled;
ADest.Bitmap:= ASrc.Bitmap;
ADest.GroupIndex:= ASrc.GroupIndex;
ADest.GlyphShowMode:= ASrc.GlyphShowMode;
ADest.HelpContext:= ASrc.HelpContext;
ADest.Hint:= ASrc.Hint;
ADest.ImageIndex:= ASrc.ImageIndex;
ADest.RadioItem:= ASrc.RadioItem;
ADest.RightJustify:= ASrc.RightJustify;
ADest.ShortCut:= ASrc.ShortCut;
ADest.ShortCutKey2:= ASrc.ShortCutKey2;
ADest.ShowAlwaysCheckable:= ASrc.ShowAlwaysCheckable;
ADest.SubMenuImages:= ASrc.SubMenuImages;
ADest.SubMenuImagesWidth:= ASrc.SubMenuImagesWidth;
ADest.Visible:= ASrc.Visible;
ADest.OnClick:= ASrc.OnClick;
ADest.OnDrawItem:= ASrc.OnDrawItem;
ADest.OnMeasureItem:= ASrc.OnMeasureItem;
ADest.Tag:= ASrc.Tag;
for i:= 0 to ASrc.Count-1 do
begin
mi:= TMenuItem.Create(ASrc.Owner);
MenuItem_Copy(ASrc.Items[i], mi);
ADest.Add(mi);
end;
end;
procedure Menu_Copy(ASrc, ADest: TMenu);
begin
ADest.BidiMode:= ASrc.BidiMode;
ADest.ParentBidiMode:= ASrc.ParentBidiMode;
ADest.Images:= ASrc.Images;
ADest.ImagesWidth:= ASrc.ImagesWidth;
ADest.OwnerDraw:= ASrc.OwnerDraw;
ADest.OnDrawItem:= ASrc.OnDrawItem;
ADest.OnMeasureItem:= ASrc.OnMeasureItem;
MenuItem_Copy(ASrc.Items, ADest.Items);
end;
{ Easy Menu building }
procedure AddMenuItems(AMenu: TMenu; const Items: array of TMenuItem);