Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXi Yan2018-07-10 11:36:24 -0400
committerEric Williams2019-06-18 09:25:16 -0400
commit9270e7077c6a9288b57223989a2308a5885cd5a7 (patch)
treea459508ea80af59edd778f64c7d83728fd7c4537
parent47276e7681ad612719fc947fb2ec0fb2cecd3690 (diff)
downloadeclipse.platform.swt-9270e7077c6a9288b57223989a2308a5885cd5a7.tar.gz
eclipse.platform.swt-9270e7077c6a9288b57223989a2308a5885cd5a7.tar.xz
eclipse.platform.swt-9270e7077c6a9288b57223989a2308a5885cd5a7.zip
Bug 395296: [GTK] Incorrect ToolBar width on Linux
Set the "homogeneous" property to false by default for all ToolItems. This prevents a large ToolItem from dictating the size of all other ToolItems belonging to the same ToolBar. For some reason, this property is enabled by default in GTK3. Tested using a child Eclipse, the Git rebase interactive view, and the snippets attached to this Gerrit. No AllNonBrowser JUnit failures are observed. Environment: Fedora 30, GTK3.24. Change-Id: I437309217fb5e706bce04e82a63a227e1a2baef0 Signed-off-by: Eric Williams <ericwill@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c10
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java13
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java5
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug395296_LongerText.java80
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug395296_ToolBarWidth.java91
7 files changed, 201 insertions, 0 deletions
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 9783370d4a..cff4af958e 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
@@ -10466,6 +10466,16 @@ JNIEXPORT jlong JNICALL GTK_NATIVE(_1gtk_1tool_1item_1retrieve_1proxy_1menu_1ite
}
#endif
+#ifndef NO__1gtk_1tool_1item_1set_1homogeneous
+JNIEXPORT void JNICALL GTK_NATIVE(_1gtk_1tool_1item_1set_1homogeneous)
+ (JNIEnv *env, jclass that, jlong arg0, jboolean arg1)
+{
+ GTK_NATIVE_ENTER(env, that, _1gtk_1tool_1item_1set_1homogeneous_FUNC);
+ gtk_tool_item_set_homogeneous((GtkToolItem *)arg0, (gboolean)arg1);
+ GTK_NATIVE_EXIT(env, that, _1gtk_1tool_1item_1set_1homogeneous_FUNC);
+}
+#endif
+
#ifndef NO__1gtk_1tool_1item_1set_1is_1important
JNIEXPORT void JNICALL GTK_NATIVE(_1gtk_1tool_1item_1set_1is_1important)
(JNIEnv *env, jclass that, jlong arg0, jboolean arg1)
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 9218cda91e..5d197cffd2 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
@@ -828,6 +828,7 @@ char * GTK_nativeFunctionNames[] = {
"_1gtk_1tool_1button_1set_1use_1underline",
"_1gtk_1tool_1item_1get_1proxy_1menu_1item",
"_1gtk_1tool_1item_1retrieve_1proxy_1menu_1item",
+ "_1gtk_1tool_1item_1set_1homogeneous",
"_1gtk_1tool_1item_1set_1is_1important",
"_1gtk_1tool_1item_1set_1proxy_1menu_1item",
"_1gtk_1toolbar_1insert",
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 8fa62cb8c8..064d2d514b 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
@@ -826,6 +826,7 @@ typedef enum {
_1gtk_1tool_1button_1set_1use_1underline_FUNC,
_1gtk_1tool_1item_1get_1proxy_1menu_1item_FUNC,
_1gtk_1tool_1item_1retrieve_1proxy_1menu_1item_FUNC,
+ _1gtk_1tool_1item_1set_1homogeneous_FUNC,
_1gtk_1tool_1item_1set_1is_1important_FUNC,
_1gtk_1tool_1item_1set_1proxy_1menu_1item_FUNC,
_1gtk_1toolbar_1insert_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 179be70ba4..892a8ba683 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
@@ -7017,6 +7017,19 @@ public class GTK extends OS {
}
/**
* @param item cast=(GtkToolItem *)
+ * @param homogeneous cast=(gboolean)
+ */
+ public static final native void _gtk_tool_item_set_homogeneous(long item, boolean homogeneous);
+ public static final void gtk_tool_item_set_homogeneous(long item, boolean homogeneous) {
+ lock.lock();
+ try {
+ _gtk_tool_item_set_homogeneous(item, homogeneous);
+ } finally {
+ lock.unlock();
+ }
+ }
+ /**
+ * @param item cast=(GtkToolItem *)
* @param menu_id cast=(const gchar *)
* @param widget cast=(GtkWidget *)
*/
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 c4897b4c4f..46d3bc0372 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
@@ -247,6 +247,11 @@ void createHandle (int index) {
*/
if ((parent.style & SWT.RIGHT) != 0) GTK.gtk_tool_item_set_is_important (handle, true);
if ((style & SWT.SEPARATOR) == 0) GTK.gtk_tool_button_set_use_underline (handle, true);
+ /*
+ * Set the "homogeneous" property to false, otherwise all ToolItems will be as large as
+ * the largest one in the ToolBar. See bug 548331, 395296 for more information.
+ */
+ GTK.gtk_tool_item_set_homogeneous(handle, false);
}
@Override
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug395296_LongerText.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug395296_LongerText.java
new file mode 100644
index 0000000000..e0eb627f5f
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug395296_LongerText.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Red Hat and others. All rights reserved.
+ * The contents of this file are made available under the terms
+ * of the GNU Lesser General Public License (LGPL) Version 2.1 that
+ * accompanies this distribution (lgpl-v21.txt). The LGPL is also
+ * available at http://www.gnu.org/licenses/lgpl.html. If the version
+ * of the LGPL at http://www.gnu.org is different to the version of
+ * the LGPL accompanying this distribution and there is any conflict
+ * between the two license versions, the terms of the LGPL accompanying
+ * this distribution shall govern.
+ *
+ * Contributors:
+ * Red Hat - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+/*
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+
+public class Bug395296_LongerText {
+
+ private static ToolItem itemChange;
+ private static ToolBar bar;
+
+ public static void main (String [] args) {
+ Display display = new Display();
+ Shell shell = new Shell (display);
+ shell.setLayout(new GridLayout());
+
+ Text textEntry = new Text(shell, SWT.NONE);
+ textEntry.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
+
+ Button setItemText = new Button(shell, SWT.PUSH);
+ setItemText.setText("Set Item Text");
+ setItemText.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String text = textEntry.getText();
+ if (itemChange != null) {
+ itemChange.setText(text);
+ }
+ }
+ });
+
+ bar = new ToolBar (shell, SWT.WRAP);
+ for (int i=0; i<3; i++) {
+ ToolItem item = new ToolItem (bar, SWT.PUSH);
+ item.setText ("ITEM " + i);
+ }
+
+ itemChange = new ToolItem(bar, SWT.PUSH);
+ itemChange.setText("1234567890111111111111");
+
+ Rectangle clientArea = shell.getClientArea ();
+ bar.setLocation (clientArea.x, clientArea.y);
+
+ bar.pack ();
+ shell.open ();
+
+ while (!shell.isDisposed ()) {
+ if (!display.readAndDispatch ()) display.sleep ();
+ }
+ display.dispose ();
+ }
+}
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug395296_ToolBarWidth.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug395296_ToolBarWidth.java
new file mode 100644
index 0000000000..4d63fe8f5a
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug395296_ToolBarWidth.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Red Hat and others. All rights reserved.
+ * The contents of this file are made available under the terms
+ * of the GNU Lesser General Public License (LGPL) Version 2.1 that
+ * accompanies this distribution (lgpl-v21.txt). The LGPL is also
+ * available at http://www.gnu.org/licenses/lgpl.html. If the version
+ * of the LGPL at http://www.gnu.org is different to the version of
+ * the LGPL accompanying this distribution and there is any conflict
+ * between the two license versions, the terms of the LGPL accompanying
+ * this distribution shall govern.
+ *
+ * Contributors:
+ * Red Hat - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+
+public final class Bug395296_ToolBarWidth {
+
+ private static ToolBar tb;
+ private static ToolItem item4;
+
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new GridLayout());
+
+ Composite buttonComp = new Composite(shell, SWT.NONE);
+ buttonComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ buttonComp.setLayout(new RowLayout());
+ addButton(buttonComp, "Item 4");
+ addButton(buttonComp, "Rebase HEAD to");
+ addButton(buttonComp, "Save Stash");
+
+ tb = new ToolBar(shell, SWT.FLAT);
+ tb.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
+ tb.setBackground(tb.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
+
+ for (int i = 0; i < 3; i++) {
+ new ToolItem(tb, SWT.NONE).setText("Item " + i);
+ }
+
+ final Composite comp = new Composite(shell, SWT.BORDER);
+ comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ comp.addPaintListener(e -> {
+ Point size = comp.getSize();
+ int d = 50;
+ for (int i = d; i < size.x; i += d) {
+ e.gc.drawLine(i, 0, i, size.y);
+ }
+ });
+
+ shell.setSize(600, 300);
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+
+ private static void addButton(Composite parent, final String label) {
+ Button bt = new Button(parent, SWT.PUSH);
+ bt.setText(label);
+ bt.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (item4 != null) {
+ item4.dispose();
+ }
+ item4 = new ToolItem(tb, SWT.NONE);
+ item4.setText(label);
+ }
+ });
+ }
+
+} \ No newline at end of file

Back to the top