diff options
author | Eric Williams | 2017-10-10 20:04:13 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2017-10-12 05:34:07 +0000 |
commit | dbb0707aaf394479cecab65956b04e6677e546d3 (patch) | |
tree | cd4865c3a678c1604bfd40755bfaa3ef94e6e0e1 /bundles/org.eclipse.swt/Eclipse SWT/gtk | |
parent | 700f51a9dadbb2758a6fdb36646cac1c42f17cf9 (diff) | |
download | eclipse.platform.swt-dbb0707aaf394479cecab65956b04e6677e546d3.tar.gz eclipse.platform.swt-dbb0707aaf394479cecab65956b04e6677e546d3.tar.xz eclipse.platform.swt-dbb0707aaf394479cecab65956b04e6677e546d3.zip |
Bug 525763: [GTK3] [dark theme] Vertical bar to the left of line
numbers is not dark
This fix targets an issue on the GTK3 dark theme where the side rulers
have a white background.
Part of the fix was to revert some of the background color machinery to
pre color port functionality. Some fixes in bug 477950 were made to
prevent another issue from happening where ToolBars that are children of
CTabFolders have a light background color. The proper fix for that issue
is to use !getBackground().equals(color) instead of always setting the
background color.
Tested on GTK3.8 to 3.22, and GTK2.24. Tested under normal, dark, and
classic themes.
Change-Id: Ie70c050c954c443bf2445407c49fb9cb7d84c1e3
Signed-off-by: Eric Williams <ericwill@redhat.com>
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk')
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java | 52 | ||||
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java | 26 |
2 files changed, 55 insertions, 23 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java index 8eb2682430..0f6e9d4504 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java @@ -2727,8 +2727,14 @@ public Color getBackground () { checkWidget(); Color color; if (OS.GTK3) { - color = Color.gtk_new (display, this.getBackgroundGdkRGBA (), backgroundAlpha); - return color; + if (backgroundAlpha == 0) { + color = Color.gtk_new (display, this.getBackgroundGdkRGBA (), 0); + return color; + } else { + Control control = findBackgroundControl (); + if (control == null) control = this; + return Color.gtk_new (display, control.getBackgroundGdkRGBA(), backgroundAlpha); + } } else { if (backgroundAlpha == 0) { color = Color.gtk_new (display, this.getBackgroundGdkColor (), 0); @@ -2774,6 +2780,9 @@ public Image getBackgroundImage () { GdkRGBA getContextBackgroundGdkRGBA () { assert OS.GTK3 : "GTK3 code was run by GTK2"; long /*int*/ fontHandle = fontHandle (); + if ((state & BACKGROUND) == 0) { + return display.COLOR_WIDGET_BACKGROUND_RGBA; + } if (OS.GTK_VERSION >= OS.VERSION(3, 14, 0)) { if (provider != 0) { return display.gtk_css_parse_background (provider, null); @@ -2784,9 +2793,6 @@ GdkRGBA getContextBackgroundGdkRGBA () { long /*int*/ context = OS.gtk_widget_get_style_context (fontHandle); GdkRGBA rgba = new GdkRGBA (); OS.gtk_style_context_get_background_color (context, OS.GTK_STATE_FLAG_NORMAL, rgba); - if ((state & BACKGROUND) == 0) { - return display.COLOR_WIDGET_BACKGROUND_RGBA; - } return rgba; } } @@ -4442,6 +4448,21 @@ public void setBackground (Color color) { } } +/** + * This method determines whether or not a background color should be set. + * + * Since bug 421836, the default behavior on GTK3 is to always set the background + * color (and this method still reflects that). However, if a widget needs to implement + * different behavior, this method can be overridden on a per widget basis. + * + * @param color the color which is to be set as the background color + * + * @return true if the background color needs to be changed, false otherwise + */ +boolean backgroundChangeNeeded (Color color) { + return true; +} + private void _setBackground (Color color) { if (((state & BACKGROUND) == 0) && color == null) return; boolean set = false; @@ -4449,8 +4470,11 @@ private void _setBackground (Color color) { GdkRGBA rgba = null; if (color != null) { rgba = color.handleRGBA; + backgroundAlpha = color.getAlpha(); + } else { + rgba = defaultBackground(); } - set = true; + set = backgroundChangeNeeded(color); if (set) { if (color == null) { state &= ~BACKGROUND; @@ -4474,7 +4498,6 @@ private void _setBackground (Color color) { set = oldColor.pixel != gdkColor.pixel; } if (set) { - if (color == null) { state &= ~BACKGROUND; } else { @@ -4582,20 +4605,18 @@ void setBackgroundGdkRGBA(GdkRGBA rgba) { void setBackgroundGdkRGBA (long /*int*/ handle, GdkRGBA rgba) { assert OS.GTK3 : "GTK3 code was run by GTK2"; - backgroundAlpha = 255; + double alpha = 1.0; if (rgba == null) { if ((state & PARENT_BACKGROUND) != 0) { - backgroundAlpha = 0; + alpha = 0; Control control = findBackgroundControl(); if (control == null) control = this; - rgba = control == this ? null : control.getBackgroundGdkRGBA(); - } else { - rgba = defaultBackground (); + rgba = control.getBackgroundGdkRGBA(); } } else { - backgroundAlpha = (int) (rgba.alpha * 255); + alpha = backgroundAlpha; } - if (rgba != null) rgba.alpha = (float) backgroundAlpha / 255; + if (rgba != null) rgba.alpha = alpha / (float)255; long /*int*/ context = OS.gtk_widget_get_style_context (handle); setBackgroundGdkRGBA (context, handle, rgba); OS.gtk_style_context_invalidate (context); @@ -5325,7 +5346,8 @@ public boolean setParent (Composite parent) { void setParentBackground () { if (OS.GTK3) { - backgroundAlpha = 0; + setBackgroundGdkRGBA (handle, null); + if (fixedHandle != 0) setBackgroundGdkRGBA (fixedHandle, null); } else { setBackgroundGdkColor (handle, null); if (fixedHandle != 0) setBackgroundGdkColor (fixedHandle, null); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java index 131a0d04b4..45a97a48a2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java @@ -12,6 +12,7 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.*; +import org.eclipse.swt.custom.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; @@ -543,6 +544,23 @@ void relayout () { } @Override +boolean backgroundChangeNeeded(Color color) { + /* + * CTabFolder has two different background colors depending on whether it + * has focus or not. However, calling getBackground() on CTabFolder only reports one + * of the colors, which causes its children (usually ToolBar) to have mismatching + * backgrounds in certain scenarios. + * + * Fix: only set the background if necessary (i.e. not all the time). + */ + if (parent != null && parent instanceof CTabFolder) { + return !getBackground().equals(color); + } else { + return super.backgroundChangeNeeded(color); + } +} + +@Override void releaseChildren (boolean destroy) { ToolItem [] items = getItems (); for (int i=0; i<items.length; i++) { @@ -612,14 +630,6 @@ void setBackgroundGdkRGBA (long /*int*/ context, long /*int*/ handle, GdkRGBA rg } @Override -void setParentBackground () { - if (OS.GTK3) { - setBackgroundGdkRGBA (handle, display.getSystemColor(SWT.COLOR_TRANSPARENT).handleRGBA); - } - super.setParentBackground(); -} - -@Override void setForegroundGdkRGBA (long /*int*/ handle, GdkRGBA rgba) { assert OS.GTK3 : "GTK3 code was run by GTK2"; if (OS.GTK_VERSION >= OS.VERSION(3, 14, 0)) { |