Skip to content

Commit 803a4bb

Browse files
MenuItem.ImageSet() GTK4 fix.
1 parent 48e5878 commit 803a4bb

File tree

3 files changed

+96
-15
lines changed
  • bundles/org.eclipse.swt

3 files changed

+96
-15
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,26 @@ JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1box_1prepend)
319319
}
320320
#endif
321321

322+
#ifndef NO_gtk_1box_1remove
323+
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1box_1remove)
324+
(JNIEnv *env, jclass that, jlong arg0, jlong arg1)
325+
{
326+
GTK4_NATIVE_ENTER(env, that, gtk_1box_1remove_FUNC);
327+
gtk_box_remove((GtkBox *)arg0, (GtkWidget *)arg1);
328+
GTK4_NATIVE_EXIT(env, that, gtk_1box_1remove_FUNC);
329+
}
330+
#endif
331+
332+
#ifndef NO_gtk_1box_1reorder_1child_1after
333+
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1box_1reorder_1child_1after)
334+
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jlong arg2)
335+
{
336+
GTK4_NATIVE_ENTER(env, that, gtk_1box_1reorder_1child_1after_FUNC);
337+
gtk_box_reorder_child_after((GtkBox *)arg0, (GtkWidget *)arg1, (GtkWidget *)arg2);
338+
GTK4_NATIVE_EXIT(env, that, gtk_1box_1reorder_1child_1after_FUNC);
339+
}
340+
#endif
341+
322342
#ifndef NO_gtk_1button_1new_1from_1icon_1name
323343
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1button_1new_1from_1icon_1name)
324344
(JNIEnv *env, jclass that, jbyteArray arg0)
@@ -1561,6 +1581,18 @@ JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1image_1new_1from_1icon_1name)
15611581
}
15621582
#endif
15631583

1584+
#ifndef NO_gtk_1image_1new_1from_1paintable
1585+
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1image_1new_1from_1paintable)
1586+
(JNIEnv *env, jclass that, jlong arg0)
1587+
{
1588+
jlong rc = 0;
1589+
GTK4_NATIVE_ENTER(env, that, gtk_1image_1new_1from_1paintable_FUNC);
1590+
rc = (jlong)gtk_image_new_from_paintable((GdkPaintable *)arg0);
1591+
GTK4_NATIVE_EXIT(env, that, gtk_1image_1new_1from_1paintable_FUNC);
1592+
return rc;
1593+
}
1594+
#endif
1595+
15641596
#ifndef NO_gtk_1image_1set_1from_1icon_1name
15651597
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1image_1set_1from_1icon_1name)
15661598
(JNIEnv *env, jclass that, jlong arg0, jbyteArray arg1)

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ public class GTK4 {
7070
* @param child cast=(GtkWidget *)
7171
*/
7272
public static final native void gtk_box_prepend(long box, long child);
73+
/**
74+
* @param box cast=(GtkBox *)
75+
* @param child cast=(GtkWidget *)
76+
* @param sibling cast=(GtkWidget *)
77+
*/
78+
public static final native void gtk_box_reorder_child_after(long box, long child, long sibling);
79+
/**
80+
* @param box cast=(GtkBox *)
81+
* @param child cast=(GtkWidget *)
82+
*/
83+
public static final native void gtk_box_remove(long box, long child);
7384
/**
7485
* @param box cast=(GtkBox *)
7586
* @param child cast=(GtkWidget *)
@@ -724,6 +735,8 @@ public class GTK4 {
724735
public static final native void gtk_image_set_from_paintable(long image, long paintable);
725736
/** @param icon_name cast=(const char *) */
726737
public static final native long gtk_image_new_from_icon_name(byte[] icon_name);
738+
/** @param paintable cast=(GdkPaintable *) */
739+
public static final native long gtk_image_new_from_paintable(long paintable);
727740
/**
728741
* @param image cast=(GtkImage *)
729742
* @param icon_name cast=(const gchar *)
@@ -882,5 +895,4 @@ public class GTK4 {
882895
* @param gesture cast=(GtkGesture *)
883896
*/
884897
public static final native long gtk_gesture_get_last_updated_sequence(long gesture);
885-
886898
}

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,9 +1028,6 @@ public void setID (int id) {
10281028
*/
10291029
@Override
10301030
public void setImage (Image image) {
1031-
//TODO: GTK4 Menu images with text are no longer supported
1032-
if (GTK.GTK4) return;
1033-
10341031
checkWidget();
10351032
if (this.image == image) return;
10361033
if ((style & SWT.SEPARATOR) != 0) return;
@@ -1053,24 +1050,64 @@ private void _setImage (Image image) {
10531050
imageList.put (imageIndex, image);
10541051
surface = imageList.getSurface (imageIndex);
10551052
}
1056-
1057-
if (!GTK3.GTK_IS_MENU_ITEM (handle)) return;
1058-
if (OS.SWT_PADDED_MENU_ITEMS && imageHandle != 0) {
1059-
GTK3.gtk_image_set_from_surface(imageHandle, surface);
1060-
} else {
1061-
if (imageHandle == 0) {
1062-
imageHandle = GTK3.gtk_image_new_from_surface(surface);
1063-
if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES);
1064-
1065-
GTK3.gtk_container_add(boxHandle, imageHandle);
1066-
GTK3.gtk_box_reorder_child(boxHandle, imageHandle, 0);
1053+
if (GTK.GTK4) {
1054+
if (OS.SWT_PADDED_MENU_ITEMS && imageHandle != 0) {
1055+
long pixbuf = ImageList.createPixbuf(image);
1056+
long texture = GDK.gdk_texture_new_for_pixbuf(pixbuf);
1057+
OS.g_object_unref(pixbuf);
1058+
GTK4.gtk_image_set_from_paintable(imageHandle, texture);
10671059
} else {
1060+
if (imageHandle == 0) {
1061+
long pixbuf = ImageList.createPixbuf(image);
1062+
long texture = GDK.gdk_texture_new_for_pixbuf(pixbuf);
1063+
OS.g_object_unref(pixbuf);
1064+
GTK4.gtk_image_new_from_paintable(texture);
1065+
if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES);
1066+
1067+
GTK4.gtk_box_append(boxHandle, imageHandle);
1068+
GTK4.gtk_box_reorder_child_after(boxHandle, imageHandle, 0);
1069+
} else {
1070+
long pixbuf = ImageList.createPixbuf(image);
1071+
long texture = GDK.gdk_texture_new_for_pixbuf(pixbuf);
1072+
OS.g_object_unref(pixbuf);
1073+
GTK4.gtk_image_set_from_paintable(imageHandle, texture);
1074+
}
1075+
}
1076+
return;
1077+
} else {
1078+
if (!GTK3.GTK_IS_MENU_ITEM (handle)) return;
1079+
if (OS.SWT_PADDED_MENU_ITEMS && imageHandle != 0) {
10681080
GTK3.gtk_image_set_from_surface(imageHandle, surface);
1081+
} else {
1082+
if (imageHandle == 0) {
1083+
imageHandle = GTK3.gtk_image_new_from_surface(surface);
1084+
if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES);
1085+
1086+
GTK3.gtk_container_add(boxHandle, imageHandle);
1087+
GTK3.gtk_box_reorder_child(boxHandle, imageHandle, 0);
1088+
} else {
1089+
GTK3.gtk_image_set_from_surface(imageHandle, surface);
1090+
}
10691091
}
10701092
}
10711093
gtk_widget_show(imageHandle);
10721094
} else {
10731095
if (imageHandle != 0) {
1096+
if (GTK.GTK4) {
1097+
if (OS.SWT_PADDED_MENU_ITEMS) {
1098+
GTK4.gtk_box_remove(boxHandle, imageHandle);
1099+
imageHandle = GTK.gtk_image_new ();
1100+
if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
1101+
GTK.gtk_image_set_pixel_size (imageHandle, 16);
1102+
GTK4.gtk_box_append (boxHandle, imageHandle);
1103+
GTK4.gtk_box_append(boxHandle, labelHandle);
1104+
gtk_widget_show (imageHandle);
1105+
} else {
1106+
GTK4.gtk_box_remove(boxHandle, imageHandle);
1107+
imageHandle = 0;
1108+
}
1109+
return;
1110+
}
10741111
if (OS.SWT_PADDED_MENU_ITEMS) {
10751112
GTK3.gtk_container_remove(boxHandle, imageHandle);
10761113
imageHandle = GTK.gtk_image_new ();

0 commit comments

Comments
 (0)