Bug 563473 - [Dark theme][WIN32] Progress bar background is light

Change-Id: I5997182e72b769da763bb94f91a4f8e7cdda467d
Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java
index e182761..75ded24 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java
@@ -2231,6 +2231,7 @@
 	display.setData("org.eclipse.swt.internal.win32.Table.headerLineColor",    isDarkTheme ? new Color(display, 0x50, 0x50, 0x50) : null);
 	display.setData("org.eclipse.swt.internal.win32.Label.disabledForegroundColor", isDarkTheme ? new Color(display, 0x80, 0x80, 0x80) : null);
 	display.setData("org.eclipse.swt.internal.win32.Combo.useDarkTheme",       isDarkTheme);
+	display.setData("org.eclipse.swt.internal.win32.ProgressBar.useColors",    isDarkTheme);
 }
 
 public static final boolean SetWindowText (long hWnd, TCHAR lpString) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
index 49cedcc..5100783 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
@@ -241,6 +241,20 @@
 	 */
 	static final String COMBO_USE_DARK_THEME = "org.eclipse.swt.internal.win32.Combo.useDarkTheme"; //$NON-NLS-1$
 	boolean comboUseDarkTheme = false;
+	/**
+	 * Use .setForeground() .setBackground() theme for ProgressBar.
+	 * Limitations:<br>
+	 * <ul>
+	 *   <li>Does not affect already created controls.</li>
+	 * </ul>
+	 * Side effects:
+	 * <ul>
+	 *   <li>ProgressBar's shine animation is lost.</li>
+	 * </ul>
+	 * Expects a <code>boolean</code> value.
+	 */
+	static final String PROGRESSBAR_USE_COLORS = "org.eclipse.swt.internal.win32.ProgressBar.useColors"; //$NON-NLS-1$
+	boolean progressbarUseColors = false;
 
 	/* Custom icons */
 	long hIconSearch;
@@ -4415,6 +4429,9 @@
 				!disableCustomThemeTweaks &&
 				OS.IsDarkModeAvailable();
 			break;
+		case PROGRESSBAR_USE_COLORS:
+			progressbarUseColors = !disableCustomThemeTweaks && _toBoolean(value);
+			break;
 	}
 
 	/* Remove the key/value pair */
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java
index c761b0a..88124e9 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java
@@ -137,6 +137,12 @@
 @Override
 void createHandle () {
 	super.createHandle ();
+
+	if (display.progressbarUseColors) {
+		char[] noTheme = new char[]{0};
+		OS.SetWindowTheme(handle, noTheme, noTheme);
+	}
+
 	startTimer ();
 }
 
diff --git a/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug563473_DarkProgressBar.java b/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug563473_DarkProgressBar.java
new file mode 100644
index 0000000..7ecff46
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug563473_DarkProgressBar.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2020 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.win32.snippets;
+
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.internal.win32.OS;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+
+public class Bug563473_DarkProgressBar {
+	static void setColors(Control control, Color backColor, Color foreColor) {
+		control.setBackground(backColor);
+		control.setForeground(foreColor);
+
+		if (control instanceof Composite) {
+			for (Control child : ((Composite)control).getChildren()) {
+				setColors(child, backColor, foreColor);
+			}
+		}
+	}
+
+	public static void main(String[] args) {
+		final Display display = new Display();
+		OS.setTheme(true);
+
+		final Shell shell = new Shell(display);
+		GridLayout layout = new GridLayout(1, true);
+		layout.horizontalSpacing = 10;
+		shell.setLayout(layout);
+
+		Label hint = new Label(shell, 0);
+		hint.setText("The ProgressBar's background shall look good in Dark Theme");
+
+		ProgressBar progress = new ProgressBar(shell, 0);
+		progress.setSelection(75);
+
+		Color backColor = new Color(display, 0x30, 0x30, 0x30);
+		Color foreColor = new Color(display, 0xD0, 0xD0, 0xD0);
+		setColors(shell, backColor, foreColor);
+
+		shell.pack();
+		shell.open();
+
+		while (!shell.isDisposed()) {
+			if (!display.readAndDispatch()) {
+				display.sleep();
+			}
+		}
+
+		display.dispose();
+	}
+}