diff options
author | Paul D'Pong | 2020-09-01 20:55:36 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2020-09-10 18:31:26 +0000 |
commit | d8738edda157a9479879c35b8783af214688b2c9 (patch) | |
tree | 8c22cd1175347a2fe630818f6018a7f6f855f2e6 | |
parent | 04c7e07d3fec541f5b6127ef3bf2cf2ab940e2ae (diff) | |
download | eclipse.platform.swt-d8738edda157a9479879c35b8783af214688b2c9.tar.gz eclipse.platform.swt-d8738edda157a9479879c35b8783af214688b2c9.tar.xz eclipse.platform.swt-d8738edda157a9479879c35b8783af214688b2c9.zip |
Bug 564795 - [GTK4] Adapt to GtkContainer removal -
gtk_container_get_children
Change-Id: I5d0b2a3a515e1e8b480533492cab686ebfb6895e
Signed-off-by: Paul D'Pong <sdamrong@redhat.com>
15 files changed, 546 insertions, 269 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Accessibility/gtk/org/eclipse/swt/accessibility/Accessible.java b/bundles/org.eclipse.swt/Eclipse SWT Accessibility/gtk/org/eclipse/swt/accessibility/Accessible.java index 4188173386..a838f56fee 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Accessibility/gtk/org/eclipse/swt/accessibility/Accessible.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Accessibility/gtk/org/eclipse/swt/accessibility/Accessible.java @@ -493,21 +493,32 @@ public class Accessible { long getControlHandle () { long result = control.handle; + if (control instanceof Label) { - long list = GTK.gtk_container_get_children (result); - if (list != 0) { - long temp = list; - while (temp != 0) { - long widget = OS.g_list_data( temp); - if (GTK.gtk_widget_get_visible (widget)) { - result = widget; + if (GTK.GTK4) { + for (long child = GTK.gtk_widget_get_first_child(result); child != 0; child = GTK.gtk_widget_get_next_sibling(child)) { + if (GTK.gtk_widget_get_visible(child)) { + result = child; break; } - temp = OS.g_list_next (temp); } - OS.g_list_free (list); + } else { + long list = GTK.gtk_container_get_children (result); + if (list != 0) { + long temp = list; + while (temp != 0) { + long widget = OS.g_list_data( temp); + if (GTK.gtk_widget_get_visible (widget)) { + result = widget; + break; + } + temp = OS.g_list_next (temp); + } + OS.g_list_free (list); + } } } + return result; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c index 1b54833b89..399ce37b4a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c @@ -12015,7 +12015,15 @@ JNIEXPORT jlong JNICALL GTK_NATIVE(gtk_1widget_1get_1first_1child) { jlong rc = 0; GTK_NATIVE_ENTER(env, that, gtk_1widget_1get_1first_1child_FUNC); +/* rc = (jlong)gtk_widget_get_first_child((GtkWidget *)arg0); +*/ + { + GTK_LOAD_FUNCTION(fp, gtk_widget_get_first_child) + if (fp) { + rc = (jlong)((jlong (CALLING_CONVENTION*)(GtkWidget *))fp)((GtkWidget *)arg0); + } + } GTK_NATIVE_EXIT(env, that, gtk_1widget_1get_1first_1child_FUNC); return rc; } @@ -12033,6 +12041,26 @@ JNIEXPORT jboolean JNICALL GTK_NATIVE(gtk_1widget_1get_1has_1window) } #endif +#ifndef NO_gtk_1widget_1get_1last_1child +JNIEXPORT jlong JNICALL GTK_NATIVE(gtk_1widget_1get_1last_1child) + (JNIEnv *env, jclass that, jlong arg0) +{ + jlong rc = 0; + GTK_NATIVE_ENTER(env, that, gtk_1widget_1get_1last_1child_FUNC); +/* + rc = (jlong)gtk_widget_get_last_child((GtkWidget *)arg0); +*/ + { + GTK_LOAD_FUNCTION(fp, gtk_widget_get_last_child) + if (fp) { + rc = (jlong)((jlong (CALLING_CONVENTION*)(GtkWidget *))fp)((GtkWidget *)arg0); + } + } + GTK_NATIVE_EXIT(env, that, gtk_1widget_1get_1last_1child_FUNC); + return rc; +} +#endif + #ifndef NO_gtk_1widget_1get_1mapped JNIEXPORT jboolean JNICALL GTK_NATIVE(gtk_1widget_1get_1mapped) (JNIEnv *env, jclass that, jlong arg0) @@ -12163,7 +12191,15 @@ JNIEXPORT jlong JNICALL GTK_NATIVE(gtk_1widget_1get_1next_1sibling) { jlong rc = 0; GTK_NATIVE_ENTER(env, that, gtk_1widget_1get_1next_1sibling_FUNC); +/* rc = (jlong)gtk_widget_get_next_sibling((GtkWidget *)arg0); +*/ + { + GTK_LOAD_FUNCTION(fp, gtk_widget_get_next_sibling) + if (fp) { + rc = (jlong)((jlong (CALLING_CONVENTION*)(GtkWidget *))fp)((GtkWidget *)arg0); + } + } GTK_NATIVE_EXIT(env, that, gtk_1widget_1get_1next_1sibling_FUNC); return rc; } @@ -12345,6 +12381,26 @@ fail: } #endif +#ifndef NO_gtk_1widget_1get_1prev_1sibling +JNIEXPORT jlong JNICALL GTK_NATIVE(gtk_1widget_1get_1prev_1sibling) + (JNIEnv *env, jclass that, jlong arg0) +{ + jlong rc = 0; + GTK_NATIVE_ENTER(env, that, gtk_1widget_1get_1prev_1sibling_FUNC); +/* + rc = (jlong)gtk_widget_get_prev_sibling((GtkWidget *)arg0); +*/ + { + GTK_LOAD_FUNCTION(fp, gtk_widget_get_prev_sibling) + if (fp) { + rc = (jlong)((jlong (CALLING_CONVENTION*)(GtkWidget *))fp)((GtkWidget *)arg0); + } + } + GTK_NATIVE_EXIT(env, that, gtk_1widget_1get_1prev_1sibling_FUNC); + return rc; +} +#endif + #ifndef NO_gtk_1widget_1get_1realized JNIEXPORT jboolean JNICALL GTK_NATIVE(gtk_1widget_1get_1realized) (JNIEnv *env, jclass that, jlong arg0) @@ -13169,6 +13225,24 @@ fail: } #endif +#ifndef NO_gtk_1widget_1unparent +JNIEXPORT void JNICALL GTK_NATIVE(gtk_1widget_1unparent) + (JNIEnv *env, jclass that, jlong arg0) +{ + GTK_NATIVE_ENTER(env, that, gtk_1widget_1unparent_FUNC); +/* + gtk_widget_unparent((GtkWidget *)arg0); +*/ + { + GTK_LOAD_FUNCTION(fp, gtk_widget_unparent) + if (fp) { + ((void (CALLING_CONVENTION*)(GtkWidget *))fp)((GtkWidget *)arg0); + } + } + GTK_NATIVE_EXIT(env, that, gtk_1widget_1unparent_FUNC); +} +#endif + #ifndef NO_gtk_1window_1activate_1default JNIEXPORT jboolean JNICALL GTK_NATIVE(gtk_1window_1activate_1default) (JNIEnv *env, jclass that, jlong arg0) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h index fd7b43b694..4513ebf592 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h @@ -550,8 +550,6 @@ #define NO_gdk_1device_1warp__JII #define NO_gtk_1widget_1measure #define NO_gtk_1style_1context_1add_1provider_1for_1display -#define NO_gtk_1widget_1get_1first_1child -#define NO_gtk_1widget_1get_1next_1sibling #define NO_gtk_1css_1provider_1load_1from_1data__I_3BI #define NO_gtk_1css_1provider_1load_1from_1data__J_3BJ #define NO_gdk_1display_1is_1composited diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c index 8b2a31fc41..68b71bf2c9 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c @@ -951,6 +951,7 @@ char * GTK_nativeFunctionNames[] = { "gtk_1widget_1get_1events", "gtk_1widget_1get_1first_1child", "gtk_1widget_1get_1has_1window", + "gtk_1widget_1get_1last_1child", "gtk_1widget_1get_1mapped", "gtk_1widget_1get_1margin_1bottom", "gtk_1widget_1get_1margin_1end", @@ -968,6 +969,7 @@ char * GTK_nativeFunctionNames[] = { "gtk_1widget_1get_1preferred_1height_1for_1width", "gtk_1widget_1get_1preferred_1size", "gtk_1widget_1get_1preferred_1width_1for_1height", + "gtk_1widget_1get_1prev_1sibling", "gtk_1widget_1get_1realized", "gtk_1widget_1get_1scale_1factor", "gtk_1widget_1get_1screen", @@ -1028,6 +1030,7 @@ char * GTK_nativeFunctionNames[] = { "gtk_1widget_1style_1get__J_3B_3IJ", "gtk_1widget_1style_1get__J_3B_3JJ", "gtk_1widget_1translate_1coordinates", + "gtk_1widget_1unparent", "gtk_1window_1activate_1default", "gtk_1window_1add_1accel_1group", "gtk_1window_1deiconify", diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h index 420b414ed1..e5a4136060 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h @@ -949,6 +949,7 @@ typedef enum { gtk_1widget_1get_1events_FUNC, gtk_1widget_1get_1first_1child_FUNC, gtk_1widget_1get_1has_1window_FUNC, + gtk_1widget_1get_1last_1child_FUNC, gtk_1widget_1get_1mapped_FUNC, gtk_1widget_1get_1margin_1bottom_FUNC, gtk_1widget_1get_1margin_1end_FUNC, @@ -966,6 +967,7 @@ typedef enum { gtk_1widget_1get_1preferred_1height_1for_1width_FUNC, gtk_1widget_1get_1preferred_1size_FUNC, gtk_1widget_1get_1preferred_1width_1for_1height_FUNC, + gtk_1widget_1get_1prev_1sibling_FUNC, gtk_1widget_1get_1realized_FUNC, gtk_1widget_1get_1scale_1factor_FUNC, gtk_1widget_1get_1screen_FUNC, @@ -1026,6 +1028,7 @@ typedef enum { gtk_1widget_1style_1get__J_3B_3IJ_FUNC, gtk_1widget_1style_1get__J_3B_3JJ_FUNC, gtk_1widget_1translate_1coordinates_FUNC, + gtk_1widget_1unparent_FUNC, gtk_1window_1activate_1default_FUNC, gtk_1window_1add_1accel_1group_FUNC, gtk_1window_1deiconify_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java index c7cd359205..3d05358992 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java @@ -255,13 +255,36 @@ public class GTK extends OS { /** @param widget cast=(GtkWidget *) */ public static final native boolean gtk_widget_get_sensitive(long widget); - /** @param widget cast=(GtkWidget *) */ - /* [GTK4 only, if-def'd in os.h] */ + /** + * @method flags=dynamic + * @param widget cast=(GtkWidget *) + * */ + /* [GTK4 only] */ public static final native long gtk_widget_get_first_child(long widget); - - /** @param widget cast=(GtkWidget *) */ - /* [GTK4 only, if-def'd in os.h] */ + /** + * @method flags=dynamic + * @param widget cast=(GtkWidget *) + * */ + /* [GTK4 only] */ + public static final native long gtk_widget_get_last_child(long widget); + /** + * @method flags=dynamic + * @param widget cast=(GtkWidget *) + * */ + /* [GTK4 only] */ public static final native long gtk_widget_get_next_sibling(long widget); + /** + * @method flags=dynamic + * @param widget cast=(GtkWidget *) + * */ + /* [GTK4 only] */ + public static final native long gtk_widget_get_prev_sibling(long widget); + /** + * @method flags=dynamic + * @param widget cast=(GtkWidget *) + * */ + /* [GTK4 only] */ + public static final native void gtk_widget_unparent(long widget); /** * @param widget cast=(GtkWidget *) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java index aa7a1fd4c1..82a53ae261 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java @@ -159,32 +159,44 @@ static int checkStyle (int style) { return style; } -Control [] _getChildren () { - long parentHandle = parentingHandle (); - //TODO: GTK4 no GTKContainer, and GtkWidget has no get_children function - long list = GTK.GTK4 ? 0 : GTK.gtk_container_get_children (parentHandle); - if (list == 0) return new Control [0]; - int count = OS.g_list_length (list); - Control [] children = new Control [count]; - int i = 0; - long temp = list; - while (temp != 0) { - long handle = OS.g_list_data (temp); - if (handle != 0) { - Widget widget = display.getWidget (handle); - if (widget != null && widget != this) { - if (widget instanceof Control) { - children [i++] = (Control) widget; +Control[] _getChildren () { + long parentHandle = parentingHandle(); + + if (GTK.GTK4) { + ArrayList<Control> childrenList = new ArrayList<>(); + for (long child = GTK.gtk_widget_get_first_child(parentHandle); child != 0; child = GTK.gtk_widget_get_next_sibling(child)) { + Widget childWidget = display.getWidget(child); + if (childWidget != null && childWidget instanceof Control && childWidget != this) { + childrenList.add((Control)childWidget); + } + } + + return childrenList.toArray(new Control[childrenList.size()]); + } else { + long list = GTK.gtk_container_get_children (parentHandle); + if (list == 0) return new Control [0]; + int count = OS.g_list_length (list); + Control [] children = new Control [count]; + int i = 0; + long temp = list; + while (temp != 0) { + long handle = OS.g_list_data (temp); + if (handle != 0) { + Widget widget = display.getWidget (handle); + if (widget != null && widget != this) { + if (widget instanceof Control) { + children [i++] = (Control) widget; + } } } + temp = OS.g_list_next (temp); } - temp = OS.g_list_next (temp); + OS.g_list_free (list); + if (i == count) return children; + Control [] newChildren = new Control [i]; + System.arraycopy (children, 0, newChildren, 0, i); + return newChildren; } - OS.g_list_free (list); - if (i == count) return children; - Control [] newChildren = new Control [i]; - System.arraycopy (children, 0, newChildren, 0, i); - return newChildren; } Control [] _getTabList () { @@ -745,14 +757,24 @@ public Control [] getChildren () { } int getChildrenCount () { - /* - * NOTE: The current implementation will count - * non-registered children. - */ - long list = GTK.gtk_container_get_children (handle); - if (list == 0) return 0; - int count = OS.g_list_length (list); - OS.g_list_free (list); + int count = 0; + + if (GTK.GTK4) { + for (long child = GTK.gtk_widget_get_first_child(handle); child != 0; child = GTK.gtk_widget_get_next_sibling(child)) { + count++; + } + } else { + /* + * NOTE: The current implementation will count + * non-registered children. + */ + long list = GTK.gtk_container_get_children(handle); + if (list != 0) { + count = OS.g_list_length(list); + OS.g_list_free(list); + } + } + return count; } @@ -1445,56 +1467,49 @@ void connectFixedHandleDraw () { */ void propagateDraw (long container, long cairo) { if (container == fixedHandle) { - long list = GTK.gtk_container_get_children (container); - long temp = list; - while (temp != 0) { - long child = OS.g_list_data (temp); - if (child != 0) { - Widget widget = display.getWidget (child); - if (widget != this) { - if (noChildDrawing) { - Boolean childLowered = childrenLowered.get(widget); - if (childLowered == null) { - childrenLowered.put(widget, false); - childLowered = false; - } - GtkAllocation allocation = new GtkAllocation (); - GTK.gtk_widget_get_allocation(child, allocation); - if (allocation.y < 0) { - if (!childLowered) { - if (GTK.GTK4) { - long surface = gtk_widget_get_surface(child); - GDK.gdk_toplevel_lower(surface); - } else { + if (GTK.GTK4) { + for (long child = GTK.gtk_widget_get_first_child(container); child != 0; child = GTK.gtk_widget_get_next_sibling(child)) { + //TODO: GTK4 no gtk_container_propagate_draw. Possibly not required at all. + } + } else { + long list = GTK.gtk_container_get_children (container); + long temp = list; + while (temp != 0) { + long child = OS.g_list_data (temp); + if (child != 0) { + Widget widget = display.getWidget (child); + if (widget != this) { + if (noChildDrawing) { + Boolean childLowered = childrenLowered.get(widget); + if (childLowered == null) { + childrenLowered.put(widget, false); + childLowered = false; + } + GtkAllocation allocation = new GtkAllocation (); + GTK.gtk_widget_get_allocation(child, allocation); + if (allocation.y < 0) { + if (!childLowered) { long window = gtk_widget_get_window(child); GDK.gdk_window_lower(window); + childrenLowered.put(widget, true); } - childrenLowered.put(widget, true); - } - } else { - if (childLowered) { - if (GTK.GTK4) { - long surface = gtk_widget_get_surface(child); - int width = GDK.gdk_surface_get_width(surface); - int height = GDK.gdk_surface_get_height(surface); - long layout = GDK.gdk_toplevel_layout_new(width, height); - GDK.gdk_toplevel_present(surface, width, height, layout); - } else { + } else { + if (childLowered) { long window = gtk_widget_get_window(child); GDK.gdk_window_raise(window); + childrenLowered.put(widget, false); } - childrenLowered.put(widget, false); + GTK.gtk_container_propagate_draw(container, child, cairo); } + } else { GTK.gtk_container_propagate_draw(container, child, cairo); } - } else { - GTK.gtk_container_propagate_draw(container, child, cairo); } } + temp = OS.g_list_next (temp); } - temp = OS.g_list_next (temp); + OS.g_list_free (list); } - OS.g_list_free (list); } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java index 40d4390450..e012e61938 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java @@ -1431,27 +1431,41 @@ public void setRegion (Region region) { } void setRelations () { - long parentHandle = parent.parentingHandle (); - long list = GTK.gtk_container_get_children (parentHandle); - if (list == 0) return; - int count = OS.g_list_length (list); - if (count > 1) { - /* - * the receiver is the last item in the list, so its predecessor will - * be the second-last item in the list - */ - long handle = OS.g_list_nth_data (list, count - 2); - if (handle != 0) { - Widget widget = display.getWidget (handle); - if (widget != null && widget != this) { - if (widget instanceof Control) { - Control sibling = (Control)widget; - sibling.addRelation (this); - } + long parentHandle = parent.parentingHandle(); + long handle = 0; + + if (GTK.GTK4) { + int count = 0; + for (long child = GTK.gtk_widget_get_first_child(parentHandle); child != 0; child = GTK.gtk_widget_get_next_sibling(child)) { + count++; + } + + if (count > 1) { + handle = GTK.gtk_widget_get_prev_sibling(GTK.gtk_widget_get_last_child(parentHandle)); + } + } else { + long list = GTK.gtk_container_get_children (parentHandle); + if (list == 0) return; + int count = OS.g_list_length (list); + if (count > 1) { + /* + * the receiver is the last item in the list, so its predecessor will + * be the second-last item in the list + */ + handle = OS.g_list_nth_data (list, count - 2); + } + OS.g_list_free (list); + } + + if (handle != 0) { + Widget widget = display.getWidget (handle); + if (widget != null && widget != this) { + if (widget instanceof Control) { + Control sibling = (Control)widget; + sibling.addRelation (this); } } } - OS.g_list_free (list); } /** 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 f9c3c9b7e6..1c3dbe9c49 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 @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.swt.widgets; +import java.util.*; + import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; @@ -561,14 +563,34 @@ public boolean getEnabled () { */ public MenuItem getItem (int index) { checkWidget(); - long list = GTK.gtk_container_get_children (handle); - if (list == 0) error (SWT.ERROR_CANNOT_GET_ITEM); - int count = OS.g_list_length (list); - if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE); - long data = OS.g_list_nth_data (list, index); - OS.g_list_free (list); - if (data == 0) error (SWT.ERROR_CANNOT_GET_ITEM); - return (MenuItem) display.getWidget (data); + + if (GTK.GTK4) { + long itemHandle = GTK.gtk_widget_get_first_child(handle); + if (itemHandle == 0) error(SWT.ERROR_CANNOT_GET_ITEM); + + 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); + } else { + long list = GTK.gtk_container_get_children (handle); + if (list == 0) error (SWT.ERROR_CANNOT_GET_ITEM); + int count = OS.g_list_length (list); + if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE); + long data = OS.g_list_nth_data (list, index); + OS.g_list_free (list); + if (data == 0) error (SWT.ERROR_CANNOT_GET_ITEM); + return (MenuItem) display.getWidget(data); + } } /** @@ -583,11 +605,23 @@ public MenuItem getItem (int index) { */ public int getItemCount () { checkWidget(); - long list = GTK.gtk_container_get_children (handle); - if (list == 0) return 0; - int count = OS.g_list_length (list); - OS.g_list_free (list); - return Math.max (0, count); + + int count = 0; + if (GTK.GTK4) { + long itemHandle = GTK.gtk_widget_get_first_child(handle); + if (itemHandle == 0) return 0; + while (itemHandle != 0) { + count++; + itemHandle = GTK.gtk_widget_get_next_sibling(itemHandle); + } + } else { + long list = GTK.gtk_container_get_children (handle); + if (list == 0) return 0; + count = OS.g_list_length (list); + OS.g_list_free (list); + } + + return Math.max(0, count); } /** @@ -608,25 +642,40 @@ public int getItemCount () { */ public MenuItem [] getItems () { checkWidget(); - long list = GTK.gtk_container_get_children (handle); - if (list == 0) return new MenuItem [0]; - long originalList = list; - int count = OS.g_list_length (list); - MenuItem [] items = new MenuItem [count]; - int index = 0; - for (int i=0; i<count; i++) { - long data = OS.g_list_data (list); - MenuItem item = (MenuItem) display.getWidget (data); - if (item != null) items [index++] = item; - list = OS.g_list_next (list); - } - OS.g_list_free (originalList); - if (index != items.length) { - MenuItem [] newItems = new MenuItem [index]; - System.arraycopy (items, 0, newItems, 0, index); - items = newItems; + + if (GTK.GTK4) { + long itemHandle = GTK.gtk_widget_get_first_child(handle); + if (itemHandle == 0) return new MenuItem[0]; + + ArrayList<MenuItem> items = new ArrayList<>(); + while (itemHandle != 0) { + MenuItem item = (MenuItem) display.getWidget(itemHandle); + if (item != null) items.add(item); + itemHandle = GTK.gtk_widget_get_next_sibling(itemHandle); + } + + return items.toArray(new MenuItem[items.size()]); + } else { + long list = GTK.gtk_container_get_children (handle); + if (list == 0) return new MenuItem [0]; + long originalList = list; + int count = OS.g_list_length (list); + MenuItem [] items = new MenuItem [count]; + int index = 0; + for (int i=0; i<count; i++) { + long data = OS.g_list_data (list); + MenuItem item = (MenuItem) display.getWidget (data); + if (item != null) items [index++] = item; + list = OS.g_list_next (list); + } + OS.g_list_free (originalList); + if (index != items.length) { + MenuItem [] newItems = new MenuItem [index]; + System.arraycopy (items, 0, newItems, 0, index); + items = newItems; + } + return items; } - return items; } @Override diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java index b957fa4421..db4b2b3548 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java @@ -2898,12 +2898,19 @@ void showWidget () { display.activeShell = this; display.activePending = true; } - long children = GTK.gtk_container_get_children (shellHandle), list = children; - while (list != 0) { - GTK.gtk_container_remove (shellHandle, OS.g_list_data (list)); - list = OS.g_list_next(list); + + if (GTK.GTK4) { + for (long child = GTK.gtk_widget_get_first_child(shellHandle); child != 0; child = GTK.gtk_widget_get_next_sibling(child)) { + GTK.gtk_widget_unparent(child); + } + } else { + long list = GTK.gtk_container_get_children (shellHandle); + while (list != 0) { + GTK.gtk_container_remove (shellHandle, OS.g_list_data (list)); + list = OS.g_list_next(list); + } + OS.g_list_free (list); } - OS.g_list_free (list); } if (GTK.GTK4) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java index 768b0c23d7..d518cfaf43 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java @@ -14,6 +14,8 @@ package org.eclipse.swt.widgets; +import java.util.*; + import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; @@ -277,12 +279,19 @@ void createWidget (int index) { } void createItem (TabItem item, int index) { - long list = GTK.gtk_container_get_children (handle); int itemCount = 0; - if (list != 0) { - itemCount = OS.g_list_length (list); - OS.g_list_free (list); + if (GTK.GTK4) { + for (long child = GTK.gtk_widget_get_first_child(handle); child != 0; child = GTK.gtk_widget_get_next_sibling(child)) { + itemCount++; + } + } else { + long list = GTK.gtk_container_get_children (handle); + if (list != 0) { + itemCount = OS.g_list_length (list); + OS.g_list_free (list); + } } + if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE); if (itemCount == items.length) { TabItem [] newItems = new TabItem [items.length + 4]; @@ -373,40 +382,59 @@ long eventHandle () { @Override Control[] _getChildren() { - Control [] directChildren = super._getChildren (); + Control[] directChildren = super._getChildren(); int directCount = directChildren.length; - int count = items == null ? 0 : items.length; - Control [] children = new Control [count + directCount]; - int i = 0; - for (int j = 0; j < count; j++) { - TabItem tabItem = items[j]; + int itemCount = items == null ? 0 : items.length; + Control[] children = new Control[itemCount + directCount]; + + int childrenCount = 0; + for (int itemIndex = 0; itemIndex < itemCount; itemIndex++) { + TabItem tabItem = items[itemIndex]; if (tabItem != null && !tabItem.isDisposed()) { long parentHandle = tabItem.pageHandle; - long list = GTK.gtk_container_get_children (parentHandle); - if (list != 0) { - long handle = OS.g_list_data (list); - if (handle != 0) { - Widget widget = display.getWidget (handle); - if (widget != null && widget != this) { - if (widget instanceof Control) { - children [i++] = (Control) widget; + + if (GTK.GTK4) { + ArrayList<Control> childrenList = new ArrayList<>(); + for (long child = GTK.gtk_widget_get_first_child(parentHandle); child != 0; child = GTK.gtk_widget_get_next_sibling(child)) { + Widget childWidget = display.getWidget(child); + if (childWidget != null && childWidget instanceof Control && childWidget != this) { + childrenList.add((Control)childWidget); + childrenCount++; + } + } + + children = childrenList.toArray(children); + } else { + long list = GTK.gtk_container_get_children (parentHandle); + if (list != 0) { + long handle = OS.g_list_data (list); + if (handle != 0) { + Widget widget = display.getWidget (handle); + if (widget != null && widget != this) { + if (widget instanceof Control) { + children [childrenCount++] = (Control) widget; + } } } + OS.g_list_free (list); } - OS.g_list_free (list); } } } - if (i == count + directCount) return children; - Control [] newChildren; - if (i == count) { - newChildren = children; + + if (childrenCount == itemCount + directCount) { + return children; } else { - newChildren = new Control [i + directCount]; - System.arraycopy (children, 0, newChildren, 0, i); + Control[] newChildren; + if (childrenCount == itemCount) { + newChildren = children; + } else { + newChildren = new Control [childrenCount + directCount]; + System.arraycopy (children, 0, newChildren, 0, childrenCount); + } + System.arraycopy (directChildren, 0, newChildren, childrenCount, directCount); + return newChildren; } - System.arraycopy (directChildren, 0, newChildren, i, directCount); - return newChildren; } /** @@ -427,11 +455,18 @@ Control[] _getChildren() { public TabItem getItem (int index) { checkWidget(); if (!(0 <= index && index < getItemCount())) error (SWT.ERROR_INVALID_RANGE); - long list = GTK.gtk_container_get_children (handle); - if (list == 0) error (SWT.ERROR_CANNOT_GET_ITEM); - int itemCount = OS.g_list_length (list); - OS.g_list_free (list); - if (!(0 <= index && index < itemCount)) error (SWT.ERROR_CANNOT_GET_ITEM); + + if (GTK.GTK4) { + long child = GTK.gtk_widget_get_first_child(handle); + if (child == 0) error(SWT.ERROR_CANNOT_GET_ITEM); + } else { + long list = GTK.gtk_container_get_children (handle); + if (list == 0) error (SWT.ERROR_CANNOT_GET_ITEM); + int itemCount = OS.g_list_length (list); + OS.g_list_free (list); + if (!(0 <= index && index < itemCount)) error (SWT.ERROR_CANNOT_GET_ITEM); + } + return items [index]; } @@ -456,10 +491,7 @@ public TabItem getItem (int index) { public TabItem getItem(Point point) { checkWidget(); if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - long list = GTK.gtk_container_get_children (handle); - if (list == 0) return null; - int itemCount = OS.g_list_length (list); - OS.g_list_free (list); + int itemCount = getItemCount(); for (int i = 0; i < itemCount; i++) { TabItem item = items[i]; Rectangle rect = item.getBounds(); @@ -480,10 +512,19 @@ public TabItem getItem(Point point) { */ public int getItemCount () { checkWidget(); - long list = GTK.gtk_container_get_children (handle); - if (list == 0) return 0; - int itemCount = OS.g_list_length (list); - OS.g_list_free (list); + + int itemCount = 0; + if (GTK.GTK4) { + for (long child = GTK.gtk_widget_get_first_child(handle); child != 0; child = GTK.gtk_widget_get_next_sibling(child)) { + itemCount++; + } + } else { + long list = GTK.gtk_container_get_children (handle); + if (list == 0) return 0; + itemCount = OS.g_list_length (list); + OS.g_list_free (list); + } + return itemCount; } @@ -604,14 +645,16 @@ void hookEvents () { public int indexOf (TabItem item) { checkWidget(); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - long list = GTK.gtk_container_get_children (handle); - if (list == 0) return -1; - int count = OS.g_list_length (list); - OS.g_list_free (list); - for (int i=0; i<count; i++) { - if (items [i] == item) return i; + + int index = -1; + int count = getItemCount(); + for (int i = 0; i < count; i++) { + if (items [i] == item) { + index = i; + break; + } } - return -1; + return index; } @Override @@ -621,12 +664,7 @@ Point minimumSize (int wHint, int hHint, boolean flushCache) { for (int i=0; i<children.length; i++) { Control child = children [i]; int index = 0; - int count = 0; - long list = GTK.gtk_container_get_children (handle); - if (list != 0) { - count = OS.g_list_length (list); - OS.g_list_free (list); - } + int count = getItemCount(); while (index < count) { if (items [index].control == child) break; index++; @@ -727,14 +765,11 @@ public void removeSelectionListener (SelectionListener listener) { @Override void reskinChildren (int flags) { if (items != null) { - long list = GTK.gtk_container_get_children (handle); - if (list != 0){ - int count = OS.g_list_length (list); - OS.g_list_free (list); - for (int i=0; i<count; i++) { - TabItem item = items [i]; - if (item != null) item.reskin (flags); - } + int count = getItemCount(); + + for (int i = 0; i < count; i++) { + TabItem item = items [i]; + if (item != null) item.reskin(flags); } } super.reskinChildren (flags); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java index 1b80a4060b..bb61b30a0f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java @@ -4174,23 +4174,26 @@ public void showSelection () { @Override void updateScrollBarValue (ScrollBar bar) { super.updateScrollBarValue (bar); - /* - * Bug in GTK. Scrolling changes the XWindow position - * and makes the child widgets appear to scroll even - * though when queried their position is unchanged. - * The fix is to queue a resize event for each child to - * force the position to be corrected. - */ - long parentHandle = parentingHandle (); - long list = GTK.gtk_container_get_children (parentHandle); - if (list == 0) return; - long temp = list; - while (temp != 0) { - long widget = OS.g_list_data (temp); - if (widget != 0) GTK.gtk_widget_queue_resize (widget); - temp = OS.g_list_next (temp); + + if (!GTK.GTK4) { + /* + * Bug in GTK. Scrolling changes the XWindow position + * and makes the child widgets appear to scroll even + * though when queried their position is unchanged. + * The fix is to queue a resize event for each child to + * force the position to be corrected. + */ + long parentHandle = parentingHandle (); + long list = GTK.gtk_container_get_children (parentHandle); + if (list == 0) return; + long temp = list; + while (temp != 0) { + long widget = OS.g_list_data (temp); + if (widget != 0) GTK.gtk_widget_queue_resize (widget); + temp = OS.g_list_next (temp); + } + OS.g_list_free (list); } - OS.g_list_free (list); } @Override diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java index d2cfb170bc..2ca40d308c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java @@ -14,6 +14,8 @@ package org.eclipse.swt.widgets; +import java.util.*; + import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.*; @@ -339,10 +341,19 @@ ToolItem getItemInPixels (Point point) { */ public int getItemCount () { checkWidget(); - long list = GTK.gtk_container_get_children (handle); - if (list == 0) return 0; - int itemCount = OS.g_list_length (list); - OS.g_list_free (list); + + int itemCount = 0; + if (GTK.GTK4) { + for (long child = GTK.gtk_widget_get_first_child(handle); child != 0; child = GTK.gtk_widget_get_next_sibling(child)) { + itemCount++; + } + } else { + long list = GTK.gtk_container_get_children (handle); + if (list == 0) return 0; + itemCount = OS.g_list_length (list); + OS.g_list_free (list); + } + return itemCount; } @@ -367,26 +378,38 @@ public ToolItem [] getItems () { return _getItems (); } -ToolItem [] _getItems () { - long list = GTK.gtk_container_get_children (handle); - if (list == 0) return new ToolItem [0]; - int count = OS.g_list_length (list); - ToolItem [] items = new ToolItem [count]; - long originalList = list; - int index = 0; - for (int i=0; i<count; i++) { - long data = OS.g_list_data (list); - Widget widget = display.getWidget (data); - if (widget != null) items [index++] = (ToolItem) widget; - list = OS.g_list_next (list); - } - OS.g_list_free (originalList); - if (index != items.length) { - ToolItem [] newItems = new ToolItem [index]; - System.arraycopy (items, 0, newItems, 0, index); - items = newItems; +ToolItem[] _getItems () { + if (GTK.GTK4) { + ArrayList<ToolItem> childrenList = new ArrayList<>(); + for (long child = GTK.gtk_widget_get_first_child(handle); child != 0; child = GTK.gtk_widget_get_next_sibling(child)) { + Widget childWidget = display.getWidget(child); + if (childWidget != null) { + childrenList.add((ToolItem)childWidget); + } + } + + return childrenList.toArray(new ToolItem[childrenList.size()]); + } else { + long list = GTK.gtk_container_get_children (handle); + if (list == 0) return new ToolItem [0]; + int count = OS.g_list_length (list); + ToolItem [] items = new ToolItem [count]; + long originalList = list; + int index = 0; + for (int i=0; i<count; i++) { + long data = OS.g_list_data (list); + Widget widget = display.getWidget (data); + if (widget != null) items [index++] = (ToolItem) widget; + list = OS.g_list_next (list); + } + OS.g_list_free (originalList); + if (index != items.length) { + ToolItem [] newItems = new ToolItem [index]; + System.arraycopy (items, 0, newItems, 0, index); + items = newItems; + } + return items; } - return items; } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java index 643556383d..cee52d9cae 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java @@ -211,21 +211,24 @@ void createHandle (int index) { if (GTK.GTK4) { handle = GTK.gtk_menu_button_new(); } else { - handle = GTK.gtk_menu_tool_button_new (0, null); + handle = GTK.gtk_menu_tool_button_new(0, null); } + if (handle == 0) error(SWT.ERROR_NO_HANDLES); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); /* * Feature in GTK. The arrow button of DropDown tool-item is * disabled when it does not contain menu. The fix is to * find the arrow button handle and enable it. */ - long child = GTK.gtk_bin_get_child (handle); - long list = GTK.gtk_container_get_children (child); - arrowHandle = OS.g_list_nth_data (list, 1); - if (arrowHandle != 0) { - GTK.gtk_widget_set_sensitive (arrowHandle, true); + if (GTK.GTK4) { + arrowHandle = GTK.gtk_widget_get_first_child(handle); + } else { + long child = GTK.gtk_bin_get_child(handle); + long list = GTK.gtk_container_get_children(child); + arrowHandle = OS.g_list_nth_data(list, 1); } + if (arrowHandle != 0) GTK.gtk_widget_set_sensitive (arrowHandle, true); + break; case SWT.RADIO: /* @@ -806,9 +809,18 @@ void hookEvents () { */ eventHandle = GTK.gtk_bin_get_child(handle); if ((style & SWT.DROP_DOWN) != 0) { - long list = GTK.gtk_container_get_children(eventHandle); - eventHandle = OS.g_list_nth_data(list, 0); - if (arrowHandle != 0) OS.g_signal_connect_closure (arrowHandle, OS.clicked, display.getClosure (CLICKED), false); + if (GTK.GTK4) { + eventHandle = GTK.gtk_widget_get_first_child(handle); + if (arrowHandle != 0) { + long clickGesture = GTK.gtk_gesture_click_new(); + OS.g_signal_connect(clickGesture, OS.pressed, display.gesturePressReleaseProc, GESTURE_PRESSED); + GTK.gtk_widget_add_controller(arrowHandle, clickGesture); + } + } else { + long list = GTK.gtk_container_get_children(eventHandle); + eventHandle = OS.g_list_nth_data(list, 0); + if (arrowHandle != 0) OS.g_signal_connect_closure (arrowHandle, OS.clicked, display.getClosure (CLICKED), false); + } } OS.g_signal_connect_closure (handle, OS.create_menu_proxy, display.getClosure (CREATE_MENU_PROXY), false); if (GTK.GTK4) { @@ -1373,13 +1385,17 @@ public void setToolTipText (String string) { } void setToolTipText (Shell shell, String newString) { - long child = GTK.gtk_bin_get_child (handle); - if ((style & SWT.DROP_DOWN) != 0) { - long list = GTK.gtk_container_get_children (child); - child = OS.g_list_nth_data (list, 0); - if (arrowHandle != 0) shell.setToolTipText (arrowHandle, newString); + if (GTK.GTK4) { + shell.setToolTipText(handle, newString); + } else { + long child = GTK.gtk_bin_get_child (handle); + if ((style & SWT.DROP_DOWN) != 0) { + long list = GTK.gtk_container_get_children (child); + child = OS.g_list_nth_data (list, 0); + if (arrowHandle != 0) shell.setToolTipText (arrowHandle, newString); + } + shell.setToolTipText (child != 0 ? child : handle, newString); } - shell.setToolTipText (child != 0 ? child : handle, newString); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java index 5a8fe0a2d7..b481de7fab 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java @@ -4160,23 +4160,26 @@ public void showItem (TreeItem item) { @Override void updateScrollBarValue (ScrollBar bar) { super.updateScrollBarValue (bar); - /* - * Bug in GTK. Scrolling changes the XWindow position - * and makes the child widgets appear to scroll even - * though when queried their position is unchanged. - * The fix is to queue a resize event for each child to - * force the position to be corrected. - */ - long parentHandle = parentingHandle (); - long list = GTK.gtk_container_get_children (parentHandle); - if (list == 0) return; - long temp = list; - while (temp != 0) { - long widget = OS.g_list_data (temp); - if (widget != 0) GTK.gtk_widget_queue_resize (widget); - temp = OS.g_list_next (temp); + + if (!GTK.GTK4) { + /* + * Bug in GTK. Scrolling changes the XWindow position + * and makes the child widgets appear to scroll even + * though when queried their position is unchanged. + * The fix is to queue a resize event for each child to + * force the position to be corrected. + */ + long parentHandle = parentingHandle (); + long list = GTK.gtk_container_get_children (parentHandle); + if (list == 0) return; + long temp = list; + while (temp != 0) { + long widget = OS.g_list_data (temp); + if (widget != 0) GTK.gtk_widget_queue_resize (widget); + temp = OS.g_list_next (temp); + } + OS.g_list_free (list); } - OS.g_list_free (list); } @Override |