Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,26 @@ JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1box_1prepend)
}
#endif

#ifndef NO_gtk_1box_1remove
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1box_1remove)
(JNIEnv *env, jclass that, jlong arg0, jlong arg1)
{
GTK4_NATIVE_ENTER(env, that, gtk_1box_1remove_FUNC);
gtk_box_remove((GtkBox *)arg0, (GtkWidget *)arg1);
GTK4_NATIVE_EXIT(env, that, gtk_1box_1remove_FUNC);
}
#endif

#ifndef NO_gtk_1box_1reorder_1child_1after
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1box_1reorder_1child_1after)
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jlong arg2)
{
GTK4_NATIVE_ENTER(env, that, gtk_1box_1reorder_1child_1after_FUNC);
gtk_box_reorder_child_after((GtkBox *)arg0, (GtkWidget *)arg1, (GtkWidget *)arg2);
GTK4_NATIVE_EXIT(env, that, gtk_1box_1reorder_1child_1after_FUNC);
}
#endif

#ifndef NO_gtk_1button_1new_1from_1icon_1name
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1button_1new_1from_1icon_1name)
(JNIEnv *env, jclass that, jbyteArray arg0)
Expand Down Expand Up @@ -1561,6 +1581,18 @@ JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1image_1new_1from_1icon_1name)
}
#endif

#ifndef NO_gtk_1image_1new_1from_1paintable
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1image_1new_1from_1paintable)
(JNIEnv *env, jclass that, jlong arg0)
{
jlong rc = 0;
GTK4_NATIVE_ENTER(env, that, gtk_1image_1new_1from_1paintable_FUNC);
rc = (jlong)gtk_image_new_from_paintable((GdkPaintable *)arg0);
GTK4_NATIVE_EXIT(env, that, gtk_1image_1new_1from_1paintable_FUNC);
return rc;
}
#endif

#ifndef NO_gtk_1image_1set_1from_1icon_1name
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1image_1set_1from_1icon_1name)
(JNIEnv *env, jclass that, jlong arg0, jbyteArray arg1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ public class GTK4 {
* @param child cast=(GtkWidget *)
*/
public static final native void gtk_box_prepend(long box, long child);
/**
* @param box cast=(GtkBox *)
* @param child cast=(GtkWidget *)
* @param sibling cast=(GtkWidget *)
*/
public static final native void gtk_box_reorder_child_after(long box, long child, long sibling);
/**
* @param box cast=(GtkBox *)
* @param child cast=(GtkWidget *)
*/
public static final native void gtk_box_remove(long box, long child);
/**
* @param box cast=(GtkBox *)
* @param child cast=(GtkWidget *)
Expand Down Expand Up @@ -724,6 +735,8 @@ public class GTK4 {
public static final native void gtk_image_set_from_paintable(long image, long paintable);
/** @param icon_name cast=(const char *) */
public static final native long gtk_image_new_from_icon_name(byte[] icon_name);
/** @param paintable cast=(GdkPaintable *) */
public static final native long gtk_image_new_from_paintable(long paintable);
/**
* @param image cast=(GtkImage *)
* @param icon_name cast=(const gchar *)
Expand Down Expand Up @@ -882,5 +895,4 @@ public class GTK4 {
* @param gesture cast=(GtkGesture *)
*/
public static final native long gtk_gesture_get_last_updated_sequence(long gesture);

}
Original file line number Diff line number Diff line change
Expand Up @@ -1028,9 +1028,6 @@ public void setID (int id) {
*/
@Override
public void setImage (Image image) {
//TODO: GTK4 Menu images with text are no longer supported
if (GTK.GTK4) return;

checkWidget();
if (this.image == image) return;
if ((style & SWT.SEPARATOR) != 0) return;
Expand All @@ -1053,24 +1050,64 @@ private void _setImage (Image image) {
imageList.put (imageIndex, image);
surface = imageList.getSurface (imageIndex);
}

if (!GTK3.GTK_IS_MENU_ITEM (handle)) return;
if (OS.SWT_PADDED_MENU_ITEMS && imageHandle != 0) {
GTK3.gtk_image_set_from_surface(imageHandle, surface);
} else {
if (imageHandle == 0) {
imageHandle = GTK3.gtk_image_new_from_surface(surface);
if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES);

GTK3.gtk_container_add(boxHandle, imageHandle);
GTK3.gtk_box_reorder_child(boxHandle, imageHandle, 0);
if (GTK.GTK4) {
if (OS.SWT_PADDED_MENU_ITEMS && imageHandle != 0) {
long pixbuf = ImageList.createPixbuf(image);
long texture = GDK.gdk_texture_new_for_pixbuf(pixbuf);
OS.g_object_unref(pixbuf);
GTK4.gtk_image_set_from_paintable(imageHandle, texture);
} else {
if (imageHandle == 0) {
long pixbuf = ImageList.createPixbuf(image);
long texture = GDK.gdk_texture_new_for_pixbuf(pixbuf);
OS.g_object_unref(pixbuf);
GTK4.gtk_image_new_from_paintable(texture);
if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get a crash here:
(SWT:623314): Gtk-CRITICAL **: 18:01:06.474: gtk_image_set_from_paintable: assertion 'GTK_IS_IMAGE (image)' failed
Exception in thread "main" org.eclipse.swt.SWTError: No more handles
at org.eclipse.swt.SWT.error(SWT.java:4980)
at org.eclipse.swt.SWT.error(SWT.java:4865)
at org.eclipse.swt.SWT.error(SWT.java:4836)
at org.eclipse.swt.widgets.Widget.error(Widget.java:598)
at org.eclipse.swt.widgets.MenuItem._setImage(MenuItem.java:1062)
at org.eclipse.swt.widgets.MenuItem._setEnabledOrDisabledImage(MenuItem.java:990)
at org.eclipse.swt.widgets.MenuItem.setImage(MenuItem.java:1037)
at org.eclipse.swt.examples.controlexample.MenuTab.createButtonSelected(MenuTab.java:97)
at org.eclipse.swt.events.SelectionListener$1.widgetSelected(SelectionListener.java:83)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:286)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:91)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5884)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1656)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:5099)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4540)
at org.eclipse.swt.examples.controlexample.ControlExample.main(ControlExample.java:240)

As imageHandle is 0 (checked on line 1060) you clearly can't set it but have to create it first.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get a crash here: (SWT:623314): Gtk-CRITICAL **: 18:01:06.474: gtk_image_set_from_paintable: assertion 'GTK_IS_IMAGE (image)' failed Exception in thread "main" org.eclipse.swt.SWTError: No more handles at org.eclipse.swt.SWT.error(SWT.java:4980) at org.eclipse.swt.SWT.error(SWT.java:4865) at org.eclipse.swt.SWT.error(SWT.java:4836) at org.eclipse.swt.widgets.Widget.error(Widget.java:598) at org.eclipse.swt.widgets.MenuItem._setImage(MenuItem.java:1062) at org.eclipse.swt.widgets.MenuItem._setEnabledOrDisabledImage(MenuItem.java:990) at org.eclipse.swt.widgets.MenuItem.setImage(MenuItem.java:1037) at org.eclipse.swt.examples.controlexample.MenuTab.createButtonSelected(MenuTab.java:97) at org.eclipse.swt.events.SelectionListener$1.widgetSelected(SelectionListener.java:83) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:286) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:91) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5884) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1656) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:5099) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4540) at org.eclipse.swt.examples.controlexample.ControlExample.main(ControlExample.java:240)

As imageHandle is 0 (checked on line 1060) you clearly can't set it but have to create it first.

I am still seeing this error..
I took the latest commit of this PR..


GTK4.gtk_box_append(boxHandle, imageHandle);
GTK4.gtk_box_reorder_child_after(boxHandle, imageHandle, 0);
} else {
long pixbuf = ImageList.createPixbuf(image);
long texture = GDK.gdk_texture_new_for_pixbuf(pixbuf);
OS.g_object_unref(pixbuf);
GTK4.gtk_image_set_from_paintable(imageHandle, texture);
}
}
return;
} else {
if (!GTK3.GTK_IS_MENU_ITEM (handle)) return;
if (OS.SWT_PADDED_MENU_ITEMS && imageHandle != 0) {
GTK3.gtk_image_set_from_surface(imageHandle, surface);
} else {
if (imageHandle == 0) {
imageHandle = GTK3.gtk_image_new_from_surface(surface);
if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES);

GTK3.gtk_container_add(boxHandle, imageHandle);
GTK3.gtk_box_reorder_child(boxHandle, imageHandle, 0);
} else {
GTK3.gtk_image_set_from_surface(imageHandle, surface);
}
}
}
gtk_widget_show(imageHandle);
} else {
if (imageHandle != 0) {
if (GTK.GTK4) {
if (OS.SWT_PADDED_MENU_ITEMS) {
GTK4.gtk_box_remove(boxHandle, imageHandle);
imageHandle = GTK.gtk_image_new ();
if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
GTK.gtk_image_set_pixel_size (imageHandle, 16);
GTK4.gtk_box_append (boxHandle, imageHandle);
GTK4.gtk_box_append(boxHandle, labelHandle);
gtk_widget_show (imageHandle);
} else {
GTK4.gtk_box_remove(boxHandle, imageHandle);
imageHandle = 0;
}
return;
}
if (OS.SWT_PADDED_MENU_ITEMS) {
GTK3.gtk_container_remove(boxHandle, imageHandle);
imageHandle = GTK.gtk_image_new ();
Expand Down
Loading