Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandr Miloslavskiy2021-01-19 18:49:40 +0000
committerAlexandr Miloslavskiy2021-01-19 22:01:52 +0000
commit9811dcdeaa5af1aad13ab9c4e568491407d2783d (patch)
tree8baba07dab3930eb3b1718758deb5c26d38c40bd
parent8d0d128482117b425a670465246af185b5e098b3 (diff)
downloadeclipse.platform.swt-9811dcdeaa5af1aad13ab9c4e568491407d2783d.tar.gz
eclipse.platform.swt-9811dcdeaa5af1aad13ab9c4e568491407d2783d.tar.xz
eclipse.platform.swt-9811dcdeaa5af1aad13ab9c4e568491407d2783d.zip
Bug 570489 - [GTK] Combo's selection background is broken after Combo.setBackground()
In Bug 543908, author succumbed to the sin of copy&paste and incorrectly replaced 'buttonProvider' with 'provider', causing two bugs at once: * Selection background and foreground colors no longer apply * Combo's button is no longer styled Let's fix that. I also added a small code readability refactoring in 'Combo.setBackgroundGdkRGBA()'. Change-Id: Ic0137cf4f01b151e3565553159cffafa23985000 Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java10
-rw-r--r--tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug570489_Gtk_ComboSetBackground.java62
2 files changed, 67 insertions, 5 deletions
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 7c2d3d10b3..1eb9f99d7e 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
@@ -2216,9 +2216,9 @@ void setButtonBackgroundGdkRGBA (GdkRGBA rgba) {
OS.g_object_unref(buttonProvider);
}
if (GTK.GTK4) {
- GTK.gtk_css_provider_load_from_data (provider, Converter.wcsToMbcs (finalCss, true), -1);
+ GTK.gtk_css_provider_load_from_data (buttonProvider, Converter.wcsToMbcs (finalCss, true), -1);
} else {
- GTK.gtk_css_provider_load_from_data (provider, Converter.wcsToMbcs (finalCss, true), -1, null);
+ GTK.gtk_css_provider_load_from_data (buttonProvider, Converter.wcsToMbcs (finalCss, true), -1, null);
}
}
@@ -2253,8 +2253,7 @@ void setBackgroundGdkRGBA (long context, long handle, GdkRGBA rgba) {
} else {
background = rgba;
}
- // CSS to be parsed for various widgets within Combo
- String css = "* {";
+
String color, menuColor;
if (rgba != null) {
color = display.gtk_rgba_to_css_string (rgba);
@@ -2268,8 +2267,9 @@ void setBackgroundGdkRGBA (long context, long handle, GdkRGBA rgba) {
menuColor = display.gtk_rgba_to_css_string (display.COLOR_LIST_BACKGROUND_RGBA);
}
- css += "background: " + color + ";}\n";
+ // CSS to be parsed for various widgets within Combo
+ String css = "* {background: " + color + ";}\n";
// Set the selected background color
GdkRGBA selectedBackground = display.getSystemColor(SWT.COLOR_LIST_SELECTION).handle;
GdkRGBA selectedForeground = display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT).handle;
diff --git a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug570489_Gtk_ComboSetBackground.java b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug570489_Gtk_ComboSetBackground.java
new file mode 100644
index 0000000000..f50036e914
--- /dev/null
+++ b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug570489_Gtk_ComboSetBackground.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Syntevo 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:
+ * Syntevo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.tests.manual;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+
+public class Bug570489_Gtk_ComboSetBackground {
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new GridLayout(1, true));
+
+ final Text hint = new Text(shell, SWT.READ_ONLY | SWT.MULTI);
+ hint.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ hint.setText(
+ "1) Run this snippet on GTK\n" +
+ "2) Check checkbox below\n" +
+ "3) Notice that combo's selection background is no longer visible\n" +
+ "4) Notice that combo's button wasn't styled"
+ );
+
+ final Combo combo = new Combo(shell, 0);
+ combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ combo.setText("Test combo text");
+ combo.setSelection(new Point(5, 10));
+
+ Button button = new Button(shell, SWT.CHECK);
+ button.setText("Set custom background color");
+ button.addListener(SWT.Selection, e -> {
+ final boolean isSelected = ((Button)e.widget).getSelection();
+ if (isSelected) {
+ combo.setForeground(new Color(0xCF, 0xCF, 0xCF));
+ combo.setBackground(new Color(0x41, 0x41, 0x41));
+ } else {
+ combo.setForeground(null);
+ combo.setBackground(null);
+ }
+ });
+
+ shell.pack();
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+}

Back to the top