Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2020-01-10 15:44:17 +0000
committerAlexander Kurtakov2020-01-14 08:45:38 +0000
commit9ccf91807434740451f65dd6f4fe1ed15ecdcb72 (patch)
treebcd24a56f7704cb98fcfd80a9c6f88a426d6ade7
parentb1dd5c970b08732e5a8104bcd3adab2b8260b72e (diff)
downloadeclipse.platform.swt-9ccf91807434740451f65dd6f4fe1ed15ecdcb72.tar.gz
eclipse.platform.swt-9ccf91807434740451f65dd6f4fe1ed15ecdcb72.tar.xz
eclipse.platform.swt-9ccf91807434740451f65dd6f4fe1ed15ecdcb72.zip
Bug 553657 - [GTK] Checkbox hard to see on active part
Some themes use checkbox and toggle where the foreground (e.g. for the check mark) is equal or very similar to the themes background. In such cases we must not inherit the parents background. Change-Id: Idf18b3b52558f9bb1f4dfaf70e2d8fc5fb3251be Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java22
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug553657_CheckboxesInheritedBackground.java69
2 files changed, 90 insertions, 1 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java
index aac38587fc..1dbb41f72c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -391,6 +391,26 @@ void createWidget (int index) {
}
@Override
+void checkBackground() {
+ /*
+ * Feature in GTK: some toggle style (check, radio, and toggle) buttons
+ * have inverted colors, meaning the background color when checked is
+ * a dark color (like blue or green), and the checkmark/indicator is
+ * white. To complicate matters, this background area is an image, and
+ * overriding this with a color causes the checkmark to be invisible.
+ * The new (GTK3 >= 3.24.11) Adwaita theme is affected, as well as the
+ * default Yaru theme on Ubuntu.
+ *
+ * Part of the fix is to not inherit the parents background. See bug 553657.
+ */
+ if (toggleButtonTheming && (style & (SWT.CHECK | SWT.RADIO)) != 0) {
+ state &= ~PARENT_BACKGROUND;
+ } else {
+ super.checkBackground();
+ }
+}
+
+@Override
void deregister () {
super.deregister ();
if (boxHandle != 0) display.removeWidget (boxHandle);
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug553657_CheckboxesInheritedBackground.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug553657_CheckboxesInheritedBackground.java
new file mode 100644
index 0000000000..cabc9ebbdf
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug553657_CheckboxesInheritedBackground.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2019, 2020 Thomas Singer 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:
+ * Thomas Singer - initial implementation to test bug 546552
+ * Paul Pazderski - adaption to test bug 553657
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * An inverted toggle must not inherit background colors.
+ * <p>
+ * Result before fix: toggle state (check mark, dot, ...) is hard to read
+ * because it's color is equal or very similar to the toggles background.
+ * <p>
+ * Expected result after fix: toggle state is readable and toggles background is
+ * either as someone would expect for the used theme or equal to the shell's
+ * background.
+ */
+public class Bug553657_CheckboxesInheritedBackground {
+
+ public static void main(String[] args) {
+ final Display display = new Display();
+
+ final Shell shell = new Shell(display);
+ shell.setText("Test bug 553657");
+ shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
+ shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
+ shell.setLayout(new GridLayout(1, false));
+
+ for (int type : new int[] { SWT.CHECK, SWT.RADIO }) {
+ for (int i = 0; i < 4; i++) {
+ createToggle("Toggle type " + type + " variant " + i, i % 2 == 0, i / 2 == 0, shell, type);
+ }
+ }
+
+ shell.setSize(400, 300);
+ shell.open();
+
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+
+ display.dispose();
+ }
+
+ private static void createToggle(String text, boolean selection, boolean enabled, Composite parent, int type) {
+ final Button checkbox = new Button(parent, type);
+ checkbox.setText(text);
+ checkbox.setSelection(selection);
+ checkbox.setEnabled(enabled);
+ }
+}

Back to the top