mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-06 12:40:22 +02:00
LCL-GTK3: Implement menu icons. TMenuitem.UpdateImage must be made visible (public). Issue #36607, patch from Anton Kavalenka.
git-svn-id: trunk@62586 -
This commit is contained in:
parent
a79371c9f2
commit
af1924d230
@ -4511,13 +4511,28 @@ end;
|
||||
function TGtk3MenuItem.CreateWidget(const Params: TCreateParams): PGtkWidget;
|
||||
var
|
||||
ndx:integer;
|
||||
pmenu:TMenuItem;
|
||||
pl:PGsList;
|
||||
parentMenu:TMenuItem;
|
||||
picon:PGtkImage;
|
||||
pmenu:PGtkMenuItem;
|
||||
pimgmenu:PgtkImageMenuItem absolute pmenu;
|
||||
img:TGtk3Image;
|
||||
begin
|
||||
Result:=nil;
|
||||
FWidgetType := [wtWidget, wtMenuItem];
|
||||
if MenuItem.Caption = cLineCaption then
|
||||
Result := TGtkSeparatorMenuItem.new
|
||||
else
|
||||
if (MenuItem.HasIcon) then
|
||||
begin
|
||||
pimgmenu := TGtkImageMenuItem.new();
|
||||
MenuItem.UpdateImage(true);
|
||||
img:=Tgtk3Image(MenuItem.Bitmap.Handle);
|
||||
picon := TGtkImage.new_from_pixbuf(img.Handle);
|
||||
pimgmenu^.set_image(picon);
|
||||
pimgmenu^.set_always_show_image(true);
|
||||
Result:=pimgmenu;
|
||||
end else
|
||||
if MenuItem.RadioItem and not MenuItem.HasIcon then
|
||||
begin
|
||||
Result := TGtkRadioMenuItem.new(nil);
|
||||
@ -4526,31 +4541,29 @@ begin
|
||||
ndx:=menuItem.Parent.IndexOf(MenuItem);
|
||||
if (ndx>0) then
|
||||
begin
|
||||
pMenu:=menuItem.Parent.Items[ndx-1];
|
||||
if (MenuItem.GroupIndex>0) and (pMenu.GroupIndex=MenuItem.GroupIndex) then
|
||||
ParentMenu:=menuItem.Parent.Items[ndx-1];
|
||||
if (MenuItem.GroupIndex>0) and (ParentMenu.GroupIndex=MenuItem.GroupIndex) then
|
||||
begin
|
||||
pl:=PGtkRadioMenuItem(TGtk3MenuItem(pMenu.Handle).Widget)^.get_group;
|
||||
pl:=PGtkRadioMenuItem(TGtk3MenuItem(ParentMenu.Handle).Widget)^.get_group;
|
||||
PGtkRadioMenuItem(Result)^.set_group(pl);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else
|
||||
if MenuItem.IsCheckItem or MenuItem.HasIcon then
|
||||
if MenuItem.IsCheckItem and not MenuItem.HasIcon then
|
||||
Result := TGtkCheckMenuItem.new
|
||||
else
|
||||
Result := TGtkMenuItem.new;
|
||||
|
||||
if MenuItem.Caption <> cLineCaption then
|
||||
if Assigned(Result) and (MenuItem.Caption <> cLineCaption) {and not MenuItem.HasIcon} then
|
||||
begin
|
||||
PGtkMenuItem(Result)^.use_underline := True;
|
||||
PGtkMenuItem(Result)^.set_label(PgChar(ReplaceAmpersandsWithUnderscores(MenuItem.Caption)));
|
||||
PGtkMenuItem(Result)^.set_sensitive(MenuItem.Enabled);
|
||||
// there's nothing like this in Gtk3
|
||||
// if MenuItem.RightJustify then
|
||||
// gtk_menu_item_right_justify(PGtkMenuItem(Widget));
|
||||
|
||||
end;
|
||||
|
||||
|
||||
end;
|
||||
|
||||
constructor TGtk3MenuItem.Create(const AMenuItem: TMenuItem);
|
||||
|
@ -548,7 +548,7 @@ begin
|
||||
if not WSCheckMenuItem(AMenuItem, 'UpdateMenuIcon') then
|
||||
Exit;
|
||||
// if gtk_is_check_menu_item({%H-}Pointer(AMenuItem.Handle)) <> HasIcon then
|
||||
// AMenuItem.RecreateHandle;
|
||||
AMenuItem.RecreateHandle;
|
||||
end;
|
||||
|
||||
{ TGtk3WSMenu }
|
||||
|
@ -212,8 +212,6 @@ type
|
||||
procedure SetShortCut(const AValue : TShortCut);
|
||||
procedure SetShortCutKey2(const AValue : TShortCut);
|
||||
procedure SetVisible(AValue: Boolean);
|
||||
procedure UpdateImage(forced: Boolean = false);
|
||||
procedure UpdateImages(forced: Boolean = false);
|
||||
procedure UpdateWSIcon;
|
||||
procedure ImageListChange(Sender: TObject);
|
||||
protected
|
||||
@ -246,6 +244,8 @@ type
|
||||
procedure Insert(Index: Integer; Item: TMenuItem);
|
||||
procedure RecreateHandle; virtual;
|
||||
procedure Remove(Item: TMenuItem);
|
||||
procedure UpdateImage(forced: Boolean = false);
|
||||
procedure UpdateImages(forced: Boolean = false);
|
||||
function IsCheckItem: boolean; virtual;
|
||||
function IsLine: Boolean;
|
||||
function IsInMenuBar: boolean; virtual;
|
||||
|
Loading…
Reference in New Issue
Block a user