diff options
author | Alexandr Miloslavskiy | 2021-01-22 00:37:15 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2021-11-30 11:25:09 +0000 |
commit | a7642d4f4e1a84def15e4eaeef51b5be2e087172 (patch) | |
tree | 67a9f7ab4c25b415a089351809f35f33e56aacb5 /tests/org.eclipse.swt.tests.gtk/ManualTests/org | |
parent | be07a05df93c0325c98d310e7151ab77c5c94bc4 (diff) | |
download | eclipse.platform.swt-a7642d4f4e1a84def15e4eaeef51b5be2e087172.tar.gz eclipse.platform.swt-a7642d4f4e1a84def15e4eaeef51b5be2e087172.tar.xz eclipse.platform.swt-a7642d4f4e1a84def15e4eaeef51b5be2e087172.zip |
Bug 570502 - [GTK3] Readonly Combo ignored set background color
The problem in code before patch is: if 'setForeground()' is called
first, it eventually leads to 'gtk_css_provider_load_from_css()' being
called with context for 'handle' instead of 'buttonHandle'. When
'setBackground()' is called later, it ignores correct 'context' because
'provider' is already allocated.
The patch reworks code to a simpler approach: a single function
'updateCss()' which handles generating css for all cases. All other
code paths simply invoke this central function. For further simplicity,
the same css provider is used everywhere.
Benefit#1 is that there is no longer any potential to use the wrong
context/provider, such as in the bug fixed here.
Benefit#2 is that '.setBackgroundGdkRGBA()' no longer needs to guess
the old color when called with rgba=null. Instead, it can simply omit
this part in the new css, which will cause GTK to use default color
again.
Benefit#3 is that it is no longer needed to cache 'cssButtonBackground'
and 'cssButtonForeground'. By reducing the state, code becomes easier
to read and more reliable.
This patch also does trivial refactoring in 'releaseHandle()'. As a
result, it becomes obvious that 'entryHandle' was not released in old
code. Not sure if it's a bug, and I really want to finish this patch
already, so it's left for someone else to figure.
Old code had 'setBackgroundGdkRGBA (fixedHandle, rgba)'. I don't think
that it's useful in any way, so I removed it.
Change-Id: I3dc79a4730d09706385c18b8c25ec2b79329ffc4
Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/176058
Tested-by: Platform Bot <platform-bot@eclipse.org>
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'tests/org.eclipse.swt.tests.gtk/ManualTests/org')
-rw-r--r-- | tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug570502_ReadonlyComboBackground.java | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug570502_ReadonlyComboBackground.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug570502_ReadonlyComboBackground.java new file mode 100644 index 0000000000..a8886009e5 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug570502_ReadonlyComboBackground.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * 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.gtk.snippets; + +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.layout.*; +import org.eclipse.swt.widgets.*; + +public class Bug570502_ReadonlyComboBackground { + public static void main(String[] args) { + final Display display = new Display(); + final Color clrBack = new Color(0x41, 0x41, 0x41); + final Color clrFore = new Color(0xcf, 0xcf, 0xcf); + + final Shell shell = new Shell(display); + shell.setLayout(new GridLayout()); + shell.setForeground(clrFore); + shell.setBackground(clrBack); + + Label hint = new Label(shell, 0); + hint.setText( + "There are multiple problems with Combo colors :\n" + + "1) Fore+Back, READ_ONLY: Background color and button's triangle are wrong\n" + + "2) Back+Fore, DROP_DOWN: Button's triangle is wrong\n" + + "3) Back+Fore, SIMPLE: Button's triangle is wrong\n" + + "4) Back only: fore colors are weird, not fixed in this patch" + ); + + Composite composite = new Composite(shell, 0); + composite.setForeground(clrFore); + composite.setBackground(clrBack); + composite.setLayout(new GridLayout(7, false)); + + int styles[] = {SWT.READ_ONLY, SWT.DROP_DOWN, SWT.SIMPLE}; + new Label(composite, 0).setText(""); + new Label(composite, 0).setText("Default"); + new Label(composite, 0).setText("Back+Fore, then default"); + new Label(composite, 0).setText("Fore only"); + new Label(composite, 0).setText("Back only"); + new Label(composite, 0).setText("Fore+Back"); + new Label(composite, 0).setText("Back+Fore"); + + for (int style : styles) { + switch (style) { + case SWT.READ_ONLY: + new Label(composite, 0).setText("READ_ONLY"); + break; + case SWT.DROP_DOWN: + new Label(composite, 0).setText("DROP_DOWN"); + break; + case SWT.SIMPLE: + new Label(composite, 0).setText("SIMPLE"); + break; + } + + for (int iColoring = 0; iColoring < 6; iColoring++) { + final Combo combo = new Combo(composite, style); + combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + combo.setItems("Item 1", "Item 2"); + combo.select(0); + + switch (iColoring) { + case 0: + break; + case 1: + combo.setBackground(clrBack); + combo.setForeground(clrFore); + combo.setBackground(null); + combo.setForeground(null); + break; + case 2: + combo.setForeground(clrFore); + break; + case 3: + combo.setBackground(clrBack); + break; + case 4: + combo.setForeground(clrFore); + combo.setBackground(clrBack); + break; + case 5: + combo.setBackground(clrBack); + combo.setForeground(clrFore); + break; + } + } + } + + shell.pack(); + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + display.dispose(); + } +} |