From dd3790a1446afe8dae6516c0cd3905ef4d295a8a Mon Sep 17 00:00:00 2001 From: Conrad Groth Date: Sun, 22 Oct 2017 13:44:51 +0200 Subject: Bug 518737 - [Win32] Background switches to light if tree widget is disabled Also use a custom background for disabled trees. Trees with the default foreground and background colors use the native behavior, i.e. the background gets a light grey. The foreground color for disabled trees always gets dark grey, even if the user specified another foreground color, because that's what all SWT widgets do. Change-Id: If0965abef9b83014cec8b1dd4817c99013596c8f Signed-off-by: Conrad Groth --- .../win32/org/eclipse/swt/widgets/Control.java | 8 +++++ .../win32/org/eclipse/swt/widgets/Table.java | 8 ----- .../win32/org/eclipse/swt/widgets/Tree.java | 42 ++++------------------ 3 files changed, 15 insertions(+), 43 deletions(-) (limited to 'bundles/org.eclipse.swt') diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java index d1aff71670..c50b01d641 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java @@ -1749,6 +1749,14 @@ boolean hasCursor () { return OS.GetCursorPos (pt) && OS.PtInRect (rect, pt); } +boolean hasCustomBackground() { + return background != -1; +} + +boolean hasCustomForeground() { + return foreground != -1; +} + boolean hasFocus () { /* * If a non-SWT child of the control has focus, diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java index 302172e371..525a467671 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java @@ -2944,14 +2944,6 @@ boolean hasChildren () { return false; } -boolean hasCustomBackground() { - return background != -1; -} - -boolean hasCustomForeground() { - return foreground != -1; -} - boolean hitTestSelection (int index, int x, int y) { int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (count == 0) return false; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java index dba3101232..6f3d4672f6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java @@ -1447,7 +1447,7 @@ LRESULT CDDS_POSTPAINT (NMTVCUSTOMDRAW nmcd, long /*int*/ wParam, long /*int*/ l LRESULT CDDS_PREPAINT (NMTVCUSTOMDRAW nmcd, long /*int*/ wParam, long /*int*/ lParam) { if (explorerTheme) { - if ((OS.IsWindowEnabled (handle) && hooks (SWT.EraseItem)) || findImageControl () != null) { + if ((OS.IsWindowEnabled (handle) && hooks (SWT.EraseItem)) || hasCustomBackground() || findImageControl () != null) { RECT rect = new RECT (); OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom); drawBackground (nmcd.hdc, rect); @@ -2700,26 +2700,18 @@ void enableDrag (boolean enabled) { void enableWidget (boolean enabled) { super.enableWidget (enabled); /* - * Feature in Windows. When a tree is given a background color - * using TVM_SETBKCOLOR and the tree is disabled, Windows draws - * the tree using the background color rather than the disabled - * colors. This is different from the table which draws grayed. - * The fix is to set the default background color while the tree - * is disabled and restore it when enabled. - */ - Control control = findBackgroundControl (); - /* * Bug in Windows. On Vista only, Windows does not draw using * the background color when the tree is disabled. The fix is * to set the default color, even when the color has not been * changed, causing Windows to draw correctly. */ + Control control = findBackgroundControl (); if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) { if (control == null) control = this; } if (control != null) { if (control.backgroundImage == null) { - _setBackgroundPixel (enabled ? control.getBackgroundPixel () : -1); + _setBackgroundPixel (hasCustomBackground() ? control.getBackgroundPixel () : -1); } } if (hwndParent != 0) OS.EnableWindow (hwndParent, enabled); @@ -2729,7 +2721,7 @@ void enableWidget (boolean enabled) { * TVS_FULLROWSELECT, the background color for the * entire row is filled when an item is painted, * drawing on top of the sort column color. The fix - * is to clear TVS_FULLROWSELECT when a their is + * is to clear TVS_FULLROWSELECT when there is * as sort column. */ updateFullSelection (); @@ -3670,20 +3662,8 @@ public TreeColumn getSortColumn () { } int getSortColumnPixel () { - int pixel = OS.IsWindowEnabled (handle) ? getBackgroundPixel () : OS.GetSysColor (OS.COLOR_3DFACE); - int red = pixel & 0xFF; - int green = (pixel & 0xFF00) >> 8; - int blue = (pixel & 0xFF0000) >> 16; - if (red > 240 && green > 240 && blue > 240) { - red -= 8; - green -= 8; - blue -= 8; - } else { - red = Math.min (0xFF, (red / 10) + red); - green = Math.min (0xFF, (green / 10) + green); - blue = Math.min (0xFF, (blue / 10) + blue); - } - return (red & 0xFF) | ((green & 0xFF) << 8) | ((blue & 0xFF) << 16); + int pixel = OS.IsWindowEnabled (handle) || hasCustomBackground() ? getBackgroundPixel () : OS.GetSysColor (OS.COLOR_3DFACE); + return getSlightlyDifferentColor(pixel); } /** @@ -4599,15 +4579,7 @@ void setBackgroundPixel (int pixel) { setBackgroundImage (control.backgroundImage); return; } - /* - * Feature in Windows. When a tree is given a background color - * using TVM_SETBKCOLOR and the tree is disabled, Windows draws - * the tree using the background color rather than the disabled - * colors. This is different from the table which draws grayed. - * The fix is to set the default background color while the tree - * is disabled and restore it when enabled. - */ - if (OS.IsWindowEnabled (handle)) _setBackgroundPixel (pixel); + _setBackgroundPixel (pixel); /* * Feature in Windows. When the tree has the style -- cgit v1.2.3