diff options
author | Eric Williams | 2019-09-26 15:26:22 +0000 |
---|---|---|
committer | Eric Williams | 2019-09-26 15:41:33 +0000 |
commit | 512c60182d2ecd4943eec96919606ab7de737c56 (patch) | |
tree | 337761f3539614536f6be575fb7172135a3a5215 | |
parent | 31a17ee03130c15b9352457a517867c84846bc63 (diff) | |
download | eclipse.platform.swt-512c60182d2ecd4943eec96919606ab7de737c56.tar.gz eclipse.platform.swt-512c60182d2ecd4943eec96919606ab7de737c56.tar.xz eclipse.platform.swt-512c60182d2ecd4943eec96919606ab7de737c56.zip |
Bug 543895: [GTK] Extra space to the right of ToolItems without text
Only set a ToolItem as "important" if it actually has text. Otherwise
this ToolItem will show its label even if no text is set, causing
extra padding.
Tested on GTK3.24 with the snippet attached. NoAllNonBrowser JUnit
tests fail.
Change-Id: I588ca39abf7b1ce8606bd3e36cd15a8fb62a33b7
Signed-off-by: Eric Williams <ericwill@redhat.com>
3 files changed, 76 insertions, 6 deletions
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 730e92c059..17297f4f29 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 @@ -243,12 +243,6 @@ void createHandle (int index) { if ((parent.state & FONT) != 0) { setFontDescription (parent.getFontDescription()); } - /* - * Feature in GTK. GtkToolButton class uses this property to - * determine whether to show or hide its label when the toolbar - * style is GTK_TOOLBAR_BOTH_HORIZ (or SWT.RIGHT). - */ - 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 @@ -1243,6 +1237,13 @@ public void setText (String string) { byte [] buffer = Converter.wcsToMbcs (chars, true); GTK.gtk_label_set_text_with_mnemonic (labelHandle, buffer); /* + * Only set important if this ToolItem actually has text. + * See bug 543895. + */ + if ((parent.style & SWT.RIGHT) != 0) { + GTK.gtk_tool_item_set_is_important (handle, !string.isEmpty()); + } + /* * If Text/Image of a tool-item changes, then it is * required to reset the proxy menu. Otherwise, the * old menuItem appears in the overflow menu. diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug543895_ToolItemExtraSpace.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug543895_ToolItemExtraSpace.java new file mode 100644 index 0000000000..e3ff24a4d5 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug543895_ToolItemExtraSpace.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2019 Andreu B 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: + * Andreu B - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; + +public class Bug543895_ToolItemExtraSpace { + + public static void main(String[] args) { + + Display d = new Display(); + + Shell s = new Shell(d); + s.setLayout(new GridLayout()); + + Image img = new Image(d, "./images/save.png"); + + ToolBar bar_1 = new ToolBar(s, SWT.FLAT | SWT.RIGHT); + + ToolItem ti_1_1 = new ToolItem(bar_1, SWT.PUSH); + ti_1_1.setImage(img); + + ToolItem ti_1_2 = new ToolItem(bar_1, SWT.PUSH); + ti_1_2.setImage(img); + + ToolItem ti_1_3 = new ToolItem(bar_1, SWT.PUSH); + ti_1_3.setImage(img); + + new Label(s, SWT.SEPARATOR | SWT.HORIZONTAL); + + ToolBar bar_2 = new ToolBar(s, SWT.FLAT | SWT.RIGHT); + + ToolItem ti_2_1 = new ToolItem(bar_2, SWT.PUSH); + ti_2_1.setImage(img); + + ToolItem ti_2_2 = new ToolItem(bar_2, SWT.PUSH); + ti_2_2.setImage(img); + + ToolItem ti_2_3 = new ToolItem(bar_2, SWT.PUSH); + ti_2_3.setImage(img); + ti_2_3.setText("foo"); + + s.open(); + while (!s.isDisposed()) { + if (!d.readAndDispatch()) { + d.sleep(); + } + } + d.dispose(); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/images/save.png b/tests/org.eclipse.swt.tests.gtk/images/save.png Binary files differnew file mode 100644 index 0000000000..764361f184 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/images/save.png |