| /******************************************************************************* |
| * 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.*; |
| import org.eclipse.swt.graphics.*; |
| import org.eclipse.swt.internal.win32.OS; |
| import org.eclipse.swt.layout.*; |
| import org.eclipse.swt.widgets.*; |
| |
| public class Bug566222_DarkCombo { |
| 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 Combo shall look good in Dark Theme"); |
| |
| for (int iStyle = 0; iStyle < 2; iStyle++) { |
| int style = (iStyle == 0) ? 0 : SWT.READ_ONLY; |
| Combo combo = new Combo(shell, style); |
| |
| for (int iItem = 0; iItem < 100; iItem++) { |
| combo.add("Item #" + iItem); |
| } |
| |
| combo.select(0); |
| } |
| |
| 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(); |
| } |
| } |