Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Williams2019-08-07 15:03:40 +0000
committerEric Williams2019-08-08 14:08:02 +0000
commitc25bd073db68c302b4c2ec26b608ed1856ea4e6e (patch)
tree72345bf32c0803ae9770c4bf630e70c0d45cb3d5
parent4a14fb969370e1bd1c0946f327ce3bf695cd319b (diff)
downloadeclipse.platform.swt-c25bd073db68c302b4c2ec26b608ed1856ea4e6e.tar.gz
eclipse.platform.swt-c25bd073db68c302b4c2ec26b608ed1856ea4e6e.tar.xz
eclipse.platform.swt-c25bd073db68c302b4c2ec26b608ed1856ea4e6e.zip
Bug 546490: [GTK] Incorrect Table/Tree size
Address Table sizing issues. The majority of the issues stem from the fact that GTK reports a 1x1 size for Widgets which are not visible. This afflicts columns in Trees/Tables, and throws of computeSize() values. This patch addresses this by initially setting the column buttons visible whenever doing a computeSize() operation. Further more, GtkScrolledWindows without scrollbars sometimes do not change their size, likely due to caching. In order to work around, we check if the Table has an initial computed height equalling the header height, and bump that height by 1px to trigger a resize. Tested on GTK3.24 on X11 and Wayland. No AllNonBrowser JUnit tests fail. Change-Id: I35330f43a2f75b5a0f08fec47dea8a40c1b2b902 Signed-off-by: Eric Williams <ericwill@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java35
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug546940_TableSizingIssues.java141
2 files changed, 168 insertions, 8 deletions
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 2cb84f7a88..67ebd442fe 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
@@ -83,6 +83,8 @@ public class Table extends Composite {
TableColumn sortColumn;
ImageList imageList, headerImageList;
boolean firstCustomDraw;
+ /** True iff computeSize has never been called on this Table */
+ boolean firstCompute = true;
int drawState, drawFlags;
GdkRGBA background, foreground, drawForegroundRGBA;
Color headerBackground, headerForeground;
@@ -493,6 +495,18 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
checkWidget ();
if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
+ /*
+ * Set all the TableColumn buttons visible otherwise
+ * gtk_widget_get_preferred_size() will not take their size
+ * into account.
+ */
+ if (firstCompute) {
+ for (int x = 0; x < columns.length; x++) {
+ TableColumn column = columns[x];
+ if (column != null) GTK.gtk_widget_set_visible(column.buttonHandle, true);
+ }
+ firstCompute = false;
+ }
Point size = computeNativeSize (handle, wHint, hHint, changed);
/*
* In GTK 3, computeNativeSize(..) sometimes just returns the header
@@ -510,16 +524,21 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
if (wHint == SWT.DEFAULT && size.x == 0 && columnCount == 0) {
size.x = maxWidth;
}
- /*
- * In case the table doesn't contain any elements,
- * getItemCount returns 0 and size.y will be 0
- * so need to assign default height. The same applies
- * for size.x.
- */
- if (size.y == 0 && hHint == SWT.DEFAULT) size.y = DEFAULT_HEIGHT;
- if (size.x == 0 && wHint == SWT.DEFAULT) size.x = DEFAULT_WIDTH;
Rectangle trim = computeTrimInPixels (0, 0, size.x, size.y);
size.x = trim.width;
+ /*
+ * Feature in GTK: sometimes GtkScrolledWindow's with no scrollbars
+ * won't automatically adjust their size. This happens when a Table
+ * has a header, and the initial computed height was the height of
+ * the of the header.
+ *
+ * The fix is to increment the height by 1 in order to force a size
+ * update for the parent GtkScrollWindow, otherwise the headers
+ * will not be shown. This only happens once, see bug 546490.
+ */
+ if (size.y == this.headerHeight && this.headerVisible && (style & SWT.NO_SCROLL) != 0) {
+ trim.height = trim.height + 1;
+ }
size.y = trim.height;
return size;
}
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug546940_TableSizingIssues.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug546940_TableSizingIssues.java
new file mode 100644
index 0000000000..ecda40f8d8
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug546940_TableSizingIssues.java
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Patrick Tasse and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Patrick Tasse - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ControlAdapter;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+
+public class Bug546940_TableSizingIssues {
+
+ private static final int NUM_COL = 5;
+ private static final int NUM_ROW = 5;
+
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+
+ shell.setLayout(new RowLayout(SWT.VERTICAL));
+
+ Label label1 = new Label(shell, SWT.NONE);
+ label1.setText("Table #1 with no items, 5 columns packed");
+ Table table1 = new Table(shell, SWT.NO_SCROLL);
+ table1.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
+ table1.setHeaderVisible(true);
+ table1.setLinesVisible(true);
+ for (int col = 0; col < NUM_COL; col++) {
+ TableColumn column = new TableColumn(table1, SWT.CENTER);
+ column.setText("Column " + col);
+ column.pack();
+ }
+
+ Label label2 = new Label(shell, SWT.NONE);
+ label2.setText("Table #2 with no items, 5 columns width=0");
+ Table table2 = new Table(shell, SWT.NO_SCROLL);
+ table2.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
+ table2.setHeaderVisible(true);
+ table2.setLinesVisible(true);
+ for (int col = 0; col < NUM_COL; col++) {
+ TableColumn column = new TableColumn(table2, SWT.CENTER);
+ column.setText("Column " + col);
+ column.setWidth(0);
+ }
+
+ Label label3 = new Label(shell, SWT.NONE);
+ label3.setText("Table #3 with no items, 5 columns width=100");
+ Table table3 = new Table(shell, SWT.NO_SCROLL);
+ table3.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
+ table3.setHeaderVisible(true);
+ table3.setLinesVisible(true);
+ for (int col = 0; col < NUM_COL; col++) {
+ TableColumn column = new TableColumn(table3, SWT.CENTER);
+ column.setText("Column " + col);
+ column.setWidth(100);
+ }
+
+ Label label4 = new Label(shell, SWT.NONE);
+ label4.setText("Table #4 with 5 items, 5 columns width=100");
+ Table table4 = new Table(shell, SWT.NO_SCROLL);
+ table4.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
+ table4.setHeaderVisible(true);
+ table4.setLinesVisible(true);
+ for (int col = 0; col < NUM_COL; col++) {
+ TableColumn column = new TableColumn(table4, SWT.CENTER);
+ column.setText("Column " + col);
+ column.setWidth(100);
+ }
+ for (int row = 1; row <= NUM_ROW; row++) {
+ TableItem item = new TableItem(table4, SWT.NONE);
+ if (row % 2 == 0) {
+ item.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ } else {
+ item.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
+ }
+ for (int col = 0; col < NUM_COL; col++) {
+ item.setText(col, "R" + row + "C" + col);
+ }
+ }
+
+ Label label5 = new Label(shell, SWT.NONE);
+ label5.setText("Table #5 with 5 items, 5 columns packed");
+ Table table5 = new Table(shell, SWT.NO_SCROLL);
+ table5.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
+ table5.setHeaderVisible(true);
+ table5.setLinesVisible(true);
+ for (int col = 0; col < NUM_COL; col++) {
+ TableColumn column = new TableColumn(table5, SWT.CENTER);
+ column.setText("Column " + col);
+ }
+ for (int row = 1; row <= NUM_ROW; row++) {
+ TableItem item = new TableItem(table5, SWT.NONE);
+ if (row % 2 == 0) {
+ item.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ } else {
+ item.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
+ }
+ for (int col = 0; col < NUM_COL; col++) {
+ item.setText(col, "R" + row + "C" + col);
+ }
+ }
+ for (TableColumn column : table5.getColumns()) {
+ column.pack();
+ }
+
+ Label label = new Label(shell, SWT.NONE);
+ label.setText("Resize shell to see table sizes change!");
+
+ shell.setText("Table, never resized");
+ shell.pack();
+ shell.open();
+ shell.addControlListener(new ControlAdapter() {
+ @Override
+ public void controlResized(ControlEvent e) {
+ shell.setText("Table, has been resized");
+ }
+ });
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ display.dispose();
+ }
+} \ No newline at end of file

Back to the top