diff options
| author | Alexandr Miloslavskiy | 2020-06-11 14:53:07 +0000 |
|---|---|---|
| committer | Niraj Modi | 2020-06-16 16:35:36 +0000 |
| commit | 408f2ffeeedb087f4a67401e55d9126c4607f709 (patch) | |
| tree | 5cc1e189e07c138b7f6ee71f94eaf21f05aad62d | |
| parent | 756252408bf34f74cab0f273be607d2e2d343522 (diff) | |
| download | eclipse.platform.swt-408f2ffeeedb087f4a67401e55d9126c4607f709.tar.gz eclipse.platform.swt-408f2ffeeedb087f4a67401e55d9126c4607f709.tar.xz eclipse.platform.swt-408f2ffeeedb087f4a67401e55d9126c4607f709.zip | |
Bug 564162 - [Win] Disabled Checkbox with set foreground color is drawn slightly left compared to an enabled one
The problem was caused by a hardcoded value of 16.
Change-Id: I173c7d324704b78c8b8259b44144ff03ecba5e60
Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
2 files changed, 76 insertions, 8 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java index 25efa6873f..1e13f27a95 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java @@ -60,6 +60,7 @@ public class Button extends Control { static final int CHECK_WIDTH, CHECK_HEIGHT; static final int ICON_WIDTH = 128, ICON_HEIGHT = 128; static /*final*/ boolean COMMAND_LINK = false; + static final char[] STRING_WITH_ZERO_CHAR = new char[] {'0'}; static final long ButtonProc; static final TCHAR ButtonClass = new TCHAR (0, "BUTTON", true); static { @@ -1290,6 +1291,25 @@ LRESULT wmCommandChild (long wParam, long lParam) { return super.wmCommandChild (wParam, lParam); } +private int getCheckboxTextOffset(long hdc) { + int result = 0; + + SIZE size = new SIZE(); + + if (OS.IsAppThemed ()) { + OS.GetThemePartSize(display.hButtonTheme(), hdc, OS.BP_CHECKBOX, OS.CBS_UNCHECKEDNORMAL, null, OS.TS_TRUE, size); + result += size.cx; + } else { + result += DPIUtil.autoScaleUpUsingNativeDPI(13); + } + + // Windows uses half width of '0' as checkbox-to-text distance. + OS.GetTextExtentPoint32(hdc, STRING_WITH_ZERO_CHAR, 1, size); + result += size.cx / 2; + + return result; +} + @Override LRESULT wmNotifyChild (NMHDR hdr, long wParam, long lParam) { switch (hdr.code) { @@ -1319,14 +1339,7 @@ LRESULT wmNotifyChild (NMHDR hdr, long wParam, long lParam) { OS.DeleteObject(brush); } if (customForegroundDrawing()) { - /* - * Check-box/Radio buttons are native widget which honors - * the Win OS zoom level for both 'Square' and 'Text' part - * [Note: By-design SWT doesn't control native auto-scaling] - * Hence, custom fore-ground draw logic should auto-scale - * text-padding as per OS Native DPI level to fix bug 506371 - */ - int radioOrCheckTextPadding = DPIUtil.autoScaleUpUsingNativeDPI(16); + int radioOrCheckTextPadding = getCheckboxTextOffset(nmcd.hdc); int border = isRadioOrCheck() ? 0 : 3; int left = nmcd.left + border; int right = nmcd.right - border; diff --git a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug564162_OwnerdrawCheckboxLayout.java b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug564162_OwnerdrawCheckboxLayout.java new file mode 100644 index 0000000000..ea4eeb97a3 --- /dev/null +++ b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug564162_OwnerdrawCheckboxLayout.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * 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.manual; + +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.*; +import org.eclipse.swt.widgets.*; + +public class Bug564162_OwnerdrawCheckboxLayout { + public static void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new RowLayout(SWT.VERTICAL)); + + Font biggerFont = new Font(display, "Courier new", 15, SWT.NONE); + + for (int iFont = 0; iFont < 2; iFont++) + for (int iCheckbox = 0; iCheckbox < 2; iCheckbox++) + for (int iBackColor = 0; iBackColor < 2; iBackColor++) + for (int iDisabled = 0; iDisabled < 2; iDisabled++) + { + Button button = new Button(shell, (iCheckbox == 0) ? SWT.RADIO : SWT.CHECK); + button.setText("000 Every control with same font shall have same text position"); + + if (iFont != 0) + button.setFont(biggerFont); + + if (iBackColor != 0) + button.setForeground(shell.getForeground()); + + if (iDisabled != 0) + button.setEnabled(false); + } + + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } +} |
