diff options
author | Simeon Andreev | 2018-02-19 16:17:30 +0000 |
---|---|---|
committer | Simeon Andreev | 2018-02-20 09:30:50 +0000 |
commit | 2feeddb0172f839c43ea8087619a9ea912eb88fa (patch) | |
tree | dfd78b912fdf1dff0f69754033902340ec6b4df9 | |
parent | 7b6eeb99d12f20e67e1d84a077c8f4a6977beecd (diff) | |
download | eclipse.platform.swt-2feeddb0172f839c43ea8087619a9ea912eb88fa.tar.gz eclipse.platform.swt-2feeddb0172f839c43ea8087619a9ea912eb88fa.tar.xz eclipse.platform.swt-2feeddb0172f839c43ea8087619a9ea912eb88fa.zip |
Bug 528498 - Combo menu is narrower than combo
In order to fix Bug 438992, wrap width of 1 was set for read-only
combos. This results in drop-down menus which are narrower than the
combo itself. Seen e.g. in the Eclipse Help preference page, where the
combos are as long as the page, but their entries are relatively short.
The drop-down menu is then only as short as the longest entry.
This change ensures that the GTK style option
-GtkComboBox-appears-as-list is used, for GTK versions above 3.22.5.
This changes the drop-down menu style, preventing both Bug 438992 and
Bug 528498.
The option cannot be used in earlier versions, since due to a bug, the
drop-down menu cannot be scrolled.
Change-Id: I96aecae46c6edef65e69a9ae590e713bf607dd4b
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
3 files changed, 84 insertions, 3 deletions
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 5d9e0f323f..a343cfef7f 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 @@ -208,6 +208,7 @@ public class GTK extends OS { public static final byte[] gtk_menu_bar_accel = OS.ascii("gtk-menu-bar-accel"); public static final byte[] gtk_menu_images = OS.ascii("gtk-menu-images"); public static final byte[] gtk_theme_name = OS.ascii("gtk-theme-name"); + public static final byte[] appears_as_list = OS.ascii("appears-as-list"); /** Misc **/ diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java index b2174e230c..06b9a1303f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -459,8 +459,18 @@ void createHandle (int index) { if (handle == 0) error (SWT.ERROR_NO_HANDLES); cellHandle = GTK.gtk_bin_get_child (handle); if (cellHandle == 0) error (SWT.ERROR_NO_HANDLES); - // Setting wrap width has the side effect of removing the whitespace on top in popup bug#438992 - GTK.gtk_combo_box_set_wrap_width(handle, 1); + /* + * For GTK 3.22.5 and above, we set -GtkComboBox-appears-as-list, see bug#528498. + * We cannot use this in earlier versions: due to a GTK bug the resulting drop-down list is not scrollable. + * The bug was fixed in GTK 3.22.5. + */ + if (GTK.GTK_VERSION < OS.VERSION(3, 22, 5)) { + // Setting wrap width has the side effect of removing the whitespace on top in popup bug#438992 + GTK.gtk_combo_box_set_wrap_width(handle, 1); + } else { + long /*int*/ context = GTK.gtk_widget_get_style_context(handle); + gtk_css_provider_load_from_css(context, "* { -GtkComboBox-appears-as-list: true; }"); + } } else { handle = GTK.gtk_combo_box_text_new_with_entry(); if (handle == 0) error (SWT.ERROR_NO_HANDLES); diff --git a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug528498_Combo_dropDownMenu_is_too_short.java b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug528498_Combo_dropDownMenu_is_too_short.java new file mode 100644 index 0000000000..a0baae5d79 --- /dev/null +++ b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug528498_Combo_dropDownMenu_is_too_short.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2018 Simeon Andreev 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: + * Simeon Andreev - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.manual; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + + +/** + * Description: Combo box drop-down menu is narrower than combo itself, for read-only combos. + * Steps to reproduce: + * <ol> + * <li>click on main menu entry "Window"</li> + * <li>click on "Preferences"</li> + * <li>choose "Help"</li> + * <li>click on any combo in the preference page</li> + * </ol> + * Expected results: The drop down menu is as long as the combo. + * Actual results: The drop down menu is only as long as its longest entry. + */ +public class Bug528498_Combo_dropDownMenu_is_too_short { + + public static void main (String [] args) { + Display display = new Display (); + final Shell shell = new Shell (display); + shell.setSize(200, 50); + shell.setLayout(new FillLayout()); + shell.setLocation(center(display, shell)); + shell.setText("Bug 528498"); + + Combo c = new Combo(shell, SWT.READ_ONLY); + + for (int i = 0; i < 40; ++i) { + c.add("item " + i); + } + + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); + } + + private static Point center(Display display, Shell shell) { + Rectangle displayBounds = display.getPrimaryMonitor().getBounds(); + Point shellBounds = shell.getSize(); + Point center = new Point( + displayBounds.x + (displayBounds.width - shellBounds.x) / 2, + displayBounds.y + (displayBounds.height - shellBounds.y) / 2); + + return center; + } +} |