LCL-GTK1: Implement menu icon updates. Merge request !143 by Bad Sector.

This commit is contained in:
Juha 2023-03-11 12:34:49 +02:00
parent 6355188e5b
commit fed1644131
2 changed files with 17 additions and 7 deletions

View File

@ -5870,7 +5870,8 @@ begin
if not LCLMenuItem.HasIcon then
begin
// call default draw function
OldCheckMenuItemDrawProc(MenuItem,Area);
if LCLMenuItem.IsCheckItem then
OldCheckMenuItemDrawProc(MenuItem,Area);
exit;
end;
IconSize:=LCLMenuItem.GetIconSize(0);
@ -6056,6 +6057,11 @@ var
// ShortCutToText(NewShortCut);
if LabelWidget = nil then
begin
// create a label to act as padding
LabelWidget := PGtkLabel(gtk_label_new(''));
gtk_misc_set_padding(PGtkMisc(LabelWidget), 10, 0);
gtk_container_add(GTK_CONTAINER(HBoxWidget), PGtkWidget(LabelWidget));
gtk_widget_show(PGtkWidget(LabelWidget));
// create a label for the ShortCut
LabelWidget := PGtkLabel(gtk_label_new(PChar(Pointer(s))));
gtk_object_set_data(PGtkObject(MenuItemWidget), 'LCLShortCutLabel', LabelWidget);
@ -6150,7 +6156,7 @@ begin
// a separator is an empty gtkmenuitem
exit;
end;
HBoxWidget := gtk_hbox_new(false, 20);
HBoxWidget := gtk_hbox_new(false, 0);
{$ifdef GTK2}
gtk_widget_set_direction(PGtkWidget(HBoxWidget), WidgetDirection[UseRTL]);
{$endif}

View File

@ -163,10 +163,7 @@ begin
if AMenuItem.RadioItem and not AMenuItem.HasIcon then
Widget := gtk_radio_menu_item_new(nil)
else
if AMenuItem.IsCheckItem or AMenuItem.HasIcon then
Widget := gtk_check_menu_item_new
else
Widget := gtk_menu_item_new;
Widget := gtk_check_menu_item_new;
WidgetInfo := CreateWidgetInfo(Widget);
WidgetInfo^.LCLObject := AMenuItem;
@ -315,10 +312,17 @@ end;
class procedure TGtkWSMenuItem.UpdateMenuIcon(const AMenuItem: TMenuItem;
const HasIcon: Boolean; const AIcon: TBitmap);
var
HBoxWidget: PGtkWidget;
begin
if not WSCheckMenuItem(AMenuItem, 'UpdateMenuIcon') then
Exit;
// TODO
HBoxWidget := gtk_object_get_data(PGtkObject(AMenuItem.Handle), 'LCLHBox');
if HBoxWidget <> nil then begin
DestroyWidget(HBoxWidget);
gtk_object_set_data(PGtkObject(AMenuItem.Handle), 'LCLHBox', nil);
end;
UpdateInnerMenuItem(AMenuItem, PGtkWidget(AMenuItem.Handle));
end;
{$ENDIF}