Bug 567258 - [GTK4] Convert Menus, GtkMenuBar, MenuItems to
GtkPopoverMenuBar

- Add GTK4 guard on setImage in MenuItem. As of GTK4, menu images with
text is not supported. It is either an icon, or text.

- Removed unnecessary boxHandle != 0 check in setImage. It is
unnecessary because the only situation where boxHandle == 0 is when the
MenuItem's style is SWT.SEPARATOR, which is checked at the beginning of
the function

- Removed error thrown when boxHandle == 0, since we aren't creating any
new boxes + the same reasoning as removing the check

Change-Id: I2f36debb86aaafd750f042d625af68db36227673
Signed-off-by: Paul D'Pong <sdamrong@redhat.com>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/178993
Tested-by: Platform Bot <platform-bot@eclipse.org>
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java
index c0f1517..8cbb83c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java
@@ -959,6 +959,9 @@
  */
 @Override
 public void setImage (Image image) {
+	//TODO: GTK4 Menu images with text are no longer supported
+	if (GTK.GTK4) return;
+
 	checkWidget();
 	if ((style & SWT.SEPARATOR) != 0) return;
 	super.setImage (image);
@@ -976,23 +979,23 @@
 			surface = imageList.getSurface (imageIndex);
 		}
 
-		if (!GTK.GTK4 && !GTK.GTK_IS_MENU_ITEM (handle)) return;
+		if (!GTK.GTK_IS_MENU_ITEM (handle)) return;
 		if (OS.SWT_PADDED_MENU_ITEMS && imageHandle != 0) {
 			GTK.gtk_image_set_from_surface(imageHandle, surface);
 		} else {
-			if (imageHandle == 0 && boxHandle != 0) {
+			if (imageHandle == 0) {
 				imageHandle = GTK.gtk_image_new_from_surface(surface);
-				GTK3.gtk_container_add (boxHandle, imageHandle);
-				GTK3.gtk_box_reorder_child (boxHandle, imageHandle, 0);
+				if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES);
+
+				GTK3.gtk_container_add(boxHandle, imageHandle);
+				GTK3.gtk_box_reorder_child(boxHandle, imageHandle, 0);
 			} else {
 				GTK.gtk_image_set_from_surface(imageHandle, surface);
 			}
-			if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES);
 		}
-		if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
-		GTK.gtk_widget_show (imageHandle);
+		GTK.gtk_widget_show(imageHandle);
 	} else {
-		if (imageHandle != 0 && boxHandle != 0) {
+		if (imageHandle != 0) {
 			if (OS.SWT_PADDED_MENU_ITEMS) {
 				GTK3.gtk_container_remove(boxHandle, imageHandle);
 				imageHandle = GTK.gtk_image_new ();