@@ -1027,9 +1027,6 @@ public void setID (int id) {
1027
1027
*/
1028
1028
@ Override
1029
1029
public void setImage (Image image ) {
1030
- //TODO: GTK4 Menu images with text are no longer supported
1031
- if (GTK .GTK4 ) return ;
1032
-
1033
1030
checkWidget ();
1034
1031
if (this .image == image ) return ;
1035
1032
if ((style & SWT .SEPARATOR ) != 0 ) return ;
@@ -1052,24 +1049,61 @@ private void _setImage (Image image) {
1052
1049
imageList .put (imageIndex , image );
1053
1050
surface = imageList .getSurface (imageIndex );
1054
1051
}
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 );
1066
1058
} 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 ) {
1067
1076
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
+ }
1068
1087
}
1069
1088
}
1070
1089
gtk_widget_show (imageHandle );
1071
1090
} else {
1072
1091
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
+ }
1073
1107
if (OS .SWT_PADDED_MENU_ITEMS ) {
1074
1108
GTK3 .gtk_container_remove (boxHandle , imageHandle );
1075
1109
imageHandle = GTK .gtk_image_new ();
0 commit comments