diff options
author | Eric Williams | 2017-07-19 15:22:48 +0000 |
---|---|---|
committer | Eric Williams | 2017-07-21 19:21:21 +0000 |
commit | 02caa3d3e3329b6e6fb4a2bd1918747a3ca3ba20 (patch) | |
tree | 1b555fd5788382ea3477c023cc8faac44ab7e8aa /bundles/org.eclipse.swt/Eclipse SWT | |
parent | 02be325df51425fdbab5879baeb539157bb148df (diff) | |
download | eclipse.platform.swt-02caa3d3e3329b6e6fb4a2bd1918747a3ca3ba20.tar.gz eclipse.platform.swt-02caa3d3e3329b6e6fb4a2bd1918747a3ca3ba20.tar.xz eclipse.platform.swt-02caa3d3e3329b6e6fb4a2bd1918747a3ca3ba20.zip |
Bug 486068: [GTK3.20+] Allocation warnings printed in error console
This patch fixes up GTK warnings which occur on GTK3.20 and above. They
happen when running any SWT application, though mostly when running the
Eclipse IDE itself. An example of the type of warning fixed by this
patch:
Gtk-WARNING **: Negative content width -1 (allocation 1, extents 1x1)
while allocating gadget (node trough, owner GtkProgressBar)
On GTK3.20+, size calculations take into account GtkCSSNode elements
which we cannot access. The fix: if the to-be-allocated size minus these
elements is < 0, allocate the preferred size instead.
Tested on GTK3.20, 3.22 and 3.18. No visible breakages in the IDE or
ControlExample. No failing JUnit test cases occur.
Change-Id: I2d3234ba16f3a90c7b81b859a4910cc26337f362
Signed-off-by: Eric Williams <ericwill@redhat.com>
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT')
6 files changed, 42 insertions, 1 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java index b00a45ce9b..89ccd944c9 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java @@ -895,6 +895,9 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize gtk_widget_get_preferred_size (boxHandle, requisition); allocation.width = boxWidth; allocation.height = boxHeight; + Point sizes = resizeCalculationsGTK3(boxHandle, boxWidth, boxHeight); + allocation.width = sizes.x; + allocation.height = sizes.y; OS.gtk_widget_size_allocate (boxHandle, allocation); } return result; 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 70c11d9d45..a36df6ec1f 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 @@ -999,6 +999,9 @@ void resizeHandle (int width, int height) { if (OS.GTK3) { OS.swt_fixed_resize (OS.gtk_widget_get_parent (topHandle), topHandle, width, height); if (topHandle != handle) { + Point sizes = resizeCalculationsGTK3 (handle, width, height); + width = sizes.x; + height = sizes.y; OS.swt_fixed_resize (OS.gtk_widget_get_parent (handle), handle, width, height); } } else { @@ -1007,6 +1010,22 @@ void resizeHandle (int width, int height) { } } +Point resizeCalculationsGTK3 (long /*int*/ widget, int width, int height) { + Point sizes = new Point (width, height); + /* + * Feature in GTK3.20+: size calculations take into account GtkCSSNode + * elements which we cannot access. If the to-be-allocated size minus + * these elements is < 0, allocate the preferred size instead. See bug 486068. + */ + if (OS.GTK_VERSION >= OS.VERSION(3, 20, 0)) { + GtkRequisition requisition = new GtkRequisition(); + OS.gtk_widget_get_preferred_size(widget, requisition, null); + sizes.x = (width - (requisition.width - width)) < 0 ? requisition.width : width; + sizes.y = (height - (requisition.height - height)) < 0 ? requisition.height : height; + } + return sizes; +} + int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { // bug in GTK2 crashes JVM, in GTK3 the new shell only. See bug 472743 width = Math.min(width, (2 << 14) - 1); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java index 43057c6497..2d4109b8a8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java @@ -427,6 +427,9 @@ void resizeHandle (int width, int height) { if (OS.GTK3) { OS.swt_fixed_resize (OS.gtk_widget_get_parent (fixedHandle), fixedHandle, width, height); long /*int*/ child = frameHandle != 0 ? frameHandle : handle; + Point sizes = resizeCalculationsGTK3 (child, width, height); + width = sizes.x; + height = sizes.y; OS.swt_fixed_resize (OS.gtk_widget_get_parent (child), child, width, height); } else { OS.gtk_widget_set_size_request (fixedHandle, width, height); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java index 80e9c6de45..e8fdbfd4a5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java @@ -12,6 +12,7 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.gtk.*; /** @@ -181,6 +182,16 @@ long /*int*/ gtk_realize (long /*int*/ widget) { return 0; } +/* + * Feature in GTK3.20+: ProgressBar has a very large minimum size, + * too large to use for SWT. It's necessary to shrink it even though it emits + * 2 warnings. For this reason, do not perform GtkCSSNode calculations. + */ +@Override +Point resizeCalculationsGTK3 (long /*int*/ widget, int width, int height) { + return new Point (width, height); +} + @Override void releaseWidget () { super.releaseWidget (); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java index c7069eb493..3a8a734d42 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java @@ -476,6 +476,9 @@ void resizeHandle (int width, int height) { OS.swt_fixed_resize (OS.gtk_widget_get_parent(fixedHandle), fixedHandle, width, height); } long /*int*/ child = scrolledHandle != 0 ? scrolledHandle : handle; + Point sizes = resizeCalculationsGTK3 (child, width, height); + width = sizes.x; + height = sizes.y; OS.swt_fixed_resize (OS.gtk_widget_get_parent(child), child, width, height); } else { if (fixedHandle != 0) OS.gtk_widget_set_size_request (fixedHandle, width, height); 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 e82d864ba3..f7288d34d1 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 @@ -981,13 +981,15 @@ void forceResize (int width, int height) { if ((style & SWT.MIRRORED) != 0) clientWidth = getClientWidth (); } GtkRequisition requisition = new GtkRequisition (); - gtk_widget_get_preferred_size (vboxHandle, requisition); GtkAllocation allocation = new GtkAllocation (); int border = OS.gtk_container_get_border_width (shellHandle); allocation.x = border; allocation.y = border; allocation.width = width; allocation.height = height; + // Call gtk_widget_get_preferred_size() on GTK 3.20+ to prevent warnings. + // See bug 486068. + if (OS.GTK_VERSION >= OS.VERSION(3, 20, 0)) gtk_widget_get_preferred_size (vboxHandle, requisition); OS.gtk_widget_size_allocate (vboxHandle, allocation); if (OS.GTK3) { if ((style & SWT.MIRRORED) != 0) moveChildren (clientWidth); |