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

- Fixed GTK4 way of getting SWT's MenuItem object from Menu. No longer
dependent on the menu container widget (which no longer exists in GTK4).

Change-Id: Ib7c8f6fd022e59aa3ff5345d0d557d1c6ba0f527
Signed-off-by: Paul D'Pong <sdamrong@redhat.com>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/178996
Tested-by: Alexander Kurtakov <akurtako@redhat.com>
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java
index e134bd4..1121ab5 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java
@@ -589,26 +589,13 @@
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
  */
-public MenuItem getItem (int index) {
+public MenuItem getItem(int index) {
 	checkWidget();
 
 	if (GTK.GTK4) {
-		long itemHandle = GTK.gtk_widget_get_first_child(handle);
-		if (itemHandle == 0) error(SWT.ERROR_CANNOT_GET_ITEM);
+		if (index < 0 || index >= items.size()) error(SWT.ERROR_INVALID_RANGE);
 
-		int childIndex = 0;
-		while (itemHandle != 0) {
-			if (childIndex == index) {
-				break;
-			}
-			childIndex++;
-			itemHandle = GTK.gtk_widget_get_next_sibling(itemHandle);
-		}
-
-		if (index < 0 || index >= childIndex) error(SWT.ERROR_INVALID_RANGE);
-		if (itemHandle == 0) error(SWT.ERROR_CANNOT_GET_ITEM);
-
-		return (MenuItem) display.getWidget(itemHandle);
+		return items.get(index);
 	} else {
 		long list = GTK3.gtk_container_get_children (handle);
 		if (list == 0) error (SWT.ERROR_CANNOT_GET_ITEM);