@@ -1027,9 +1027,6 @@ public void setID (int id) {
10271027 */
10281028@ Override
10291029public void setImage (Image image ) {
1030- //TODO: GTK4 Menu images with text are no longer supported
1031- if (GTK .GTK4 ) return ;
1032-
10331030 checkWidget ();
10341031 if (this .image == image ) return ;
10351032 if ((style & SWT .SEPARATOR ) != 0 ) return ;
@@ -1052,24 +1049,61 @@ private void _setImage (Image image) {
10521049 imageList .put (imageIndex , image );
10531050 surface = imageList .getSurface (imageIndex );
10541051 }
1055-
1056- if (!GTK3 .GTK_IS_MENU_ITEM (handle )) return ;
1057- if (OS .SWT_PADDED_MENU_ITEMS && imageHandle != 0 ) {
1058- GTK3 .gtk_image_set_from_surface (imageHandle , surface );
1059- } else {
1060- if (imageHandle == 0 ) {
1061- imageHandle = GTK3 .gtk_image_new_from_surface (surface );
1062- if (imageHandle == 0 ) error (SWT .ERROR_NO_HANDLES );
1063-
1064- GTK3 .gtk_container_add (boxHandle , imageHandle );
1065- GTK3 .gtk_box_reorder_child (boxHandle , imageHandle , 0 );
1052+ if (GTK .GTK4 ) {
1053+ if (OS .SWT_PADDED_MENU_ITEMS && imageHandle != 0 ) {
1054+ long pixbuf = ImageList .createPixbuf (image );
1055+ long texture = GDK .gdk_texture_new_for_pixbuf (pixbuf );
1056+ OS .g_object_unref (pixbuf );
1057+ GTK4 .gtk_image_set_from_paintable (imageHandle , texture );
10661058 } else {
1059+ if (imageHandle == 0 ) {
1060+ GTK4 .gtk_image_set_from_paintable (imageHandle , surface );
1061+ if (imageHandle == 0 ) error (SWT .ERROR_NO_HANDLES );
1062+
1063+ GTK4 .gtk_box_append (boxHandle , imageHandle );
1064+ GTK4 .gtk_reorder_child_after (boxHandle , imageHandle , 0 );
1065+ } else {
1066+ long pixbuf = ImageList .createPixbuf (image );
1067+ long texture = GDK .gdk_texture_new_for_pixbuf (pixbuf );
1068+ OS .g_object_unref (pixbuf );
1069+ GTK4 .gtk_image_set_from_paintable (imageHandle , texture );
1070+ }
1071+ }
1072+ return ;
1073+ } else {
1074+ if (!GTK3 .GTK_IS_MENU_ITEM (handle )) return ;
1075+ if (OS .SWT_PADDED_MENU_ITEMS && imageHandle != 0 ) {
10671076 GTK3 .gtk_image_set_from_surface (imageHandle , surface );
1077+ } else {
1078+ if (imageHandle == 0 ) {
1079+ imageHandle = GTK3 .gtk_image_new_from_surface (surface );
1080+ if (imageHandle == 0 ) error (SWT .ERROR_NO_HANDLES );
1081+
1082+ GTK3 .gtk_container_add (boxHandle , imageHandle );
1083+ GTK3 .gtk_box_reorder_child (boxHandle , imageHandle , 0 );
1084+ } else {
1085+ GTK3 .gtk_image_set_from_surface (imageHandle , surface );
1086+ }
10681087 }
10691088 }
10701089 gtk_widget_show (imageHandle );
10711090 } else {
10721091 if (imageHandle != 0 ) {
1092+ if (GTK .GTK4 ) {
1093+ if (OS .SWT_PADDED_MENU_ITEMS ) {
1094+ GTK4 .gtk_box_remove (boxHandle , imageHandle );
1095+ imageHandle = GTK .gtk_image_new ();
1096+ if (imageHandle == 0 ) error (SWT .ERROR_NO_HANDLES );
1097+ GTK .gtk_image_set_pixel_size (imageHandle , 16 );
1098+ GTK4 .gtk_box_append (boxHandle , imageHandle );
1099+ GTK4 .gtk_box_append (boxHandle , labelHandle );
1100+ gtk_widget_show (imageHandle );
1101+ } else {
1102+ GTK4 .gtk_box_remove (boxHandle , imageHandle );
1103+ imageHandle = 0 ;
1104+ }
1105+ return ;
1106+ }
10731107 if (OS .SWT_PADDED_MENU_ITEMS ) {
10741108 GTK3 .gtk_container_remove (boxHandle , imageHandle );
10751109 imageHandle = GTK .gtk_image_new ();
0 commit comments