diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
index 104a1c69dfa..cab1a4f022d 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 IBM Corporation and others.
+ * Copyright (c) 2005, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -29,6 +29,7 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
@@ -45,6 +46,7 @@ import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.preferences.OverlayPreferenceStore.OverlayKey;
+import org.eclipse.cdt.internal.ui.text.c.hover.SourceViewerInformationControl;
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
@@ -329,7 +331,10 @@ public class CEditorPreferencePage extends AbstractPreferencePage {
*/
private void initializeDefaultColors() {
if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR_SYSTEM_DEFAULT)) {
- RGB rgb= fAppearanceColorList.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND).getRGB();
+ Display display= fAppearanceColorList.getDisplay();
+ RGB rgb= SourceViewerInformationControl.getVisibleBackgroundColor(display);
+ if (rgb == null)
+ rgb= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND).getRGB();
PreferenceConverter.setValue(getPreferenceStore(), PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR, rgb);
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractCompareViewerInformationControl.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractCompareViewerInformationControl.java
index 8f6a5510801..9f7b0c141f8 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractCompareViewerInformationControl.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractCompareViewerInformationControl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -44,6 +44,8 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
+import org.eclipse.cdt.internal.ui.text.c.hover.SourceViewerInformationControl;
+
/**
* Abstract class for "quick" compare views in light-weight controls.
*
@@ -75,7 +77,7 @@ public abstract class AbstractCompareViewerInformationControl extends org.eclips
private ICompareInput fCompareInput;
private Color fBackgroundColor;
- private boolean fIsSystemBackgroundColor;
+ private boolean fIsSystemBackgroundColor = true;
private Label fTitleLabel;
@@ -106,7 +108,13 @@ public abstract class AbstractCompareViewerInformationControl extends org.eclips
}
private void initializeColors() {
- RGB bgRGB= getHoverBackgroundColorRGB();
+ IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
+ RGB bgRGB;
+ if (store.getBoolean(PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR_SYSTEM_DEFAULT)) {
+ bgRGB= SourceViewerInformationControl.getVisibleBackgroundColor(getShell().getDisplay());
+ } else {
+ bgRGB= PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR);
+ }
if (bgRGB != null) {
fBackgroundColor= new Color(getShell().getDisplay(), bgRGB);
fIsSystemBackgroundColor= false;
@@ -116,13 +124,6 @@ public abstract class AbstractCompareViewerInformationControl extends org.eclips
}
}
- private RGB getHoverBackgroundColorRGB() {
- IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
- return store.getBoolean(PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR_SYSTEM_DEFAULT)
- ? null
- : PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR);
- }
-
@Override
protected void createContent(Composite parent) {
initializeColors();
@@ -207,6 +208,10 @@ public abstract class AbstractCompareViewerInformationControl extends org.eclips
return false;
}
+ protected Color getBackgroundColor() {
+ return fBackgroundColor;
+ }
+
@Override
public void setInformation(String content) {
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractSourceViewerInformationControl.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractSourceViewerInformationControl.java
index 5a379c0bddf..6004d9889e1 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractSourceViewerInformationControl.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractSourceViewerInformationControl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -41,6 +41,7 @@ import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.ui.editor.CSourceViewer;
+import org.eclipse.cdt.internal.ui.text.c.hover.SourceViewerInformationControl;
/**
* Abstract class for "quick" source views in light-weight controls.
@@ -50,15 +51,10 @@ import org.eclipse.cdt.internal.ui.editor.CSourceViewer;
public abstract class AbstractSourceViewerInformationControl extends org.eclipse.jface.text.AbstractInformationControl implements IInformationControlExtension2, DisposeListener {
private ISourceViewer fSourceViewer;
-
private Color fBackgroundColor;
-
- private boolean fIsSystemBackgroundColor;
-
+ private boolean fIsSystemBackgroundColor = true;
private Font fTextFont;
-
private StyledText fText;
-
private Label fTitleLabel;
/**
@@ -95,7 +91,13 @@ public abstract class AbstractSourceViewerInformationControl extends org.eclipse
}
private void initializeColors() {
- RGB bgRGB= getHoverBackgroundColorRGB();
+ IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
+ RGB bgRGB;
+ if (store.getBoolean(PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR_SYSTEM_DEFAULT)) {
+ bgRGB= SourceViewerInformationControl.getVisibleBackgroundColor(getShell().getDisplay());
+ } else {
+ bgRGB= PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR);
+ }
if (bgRGB != null) {
fBackgroundColor= new Color(getShell().getDisplay(), bgRGB);
fIsSystemBackgroundColor= false;
@@ -105,13 +107,6 @@ public abstract class AbstractSourceViewerInformationControl extends org.eclipse
}
}
- private RGB getHoverBackgroundColorRGB() {
- IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
- return store.getBoolean(PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR_SYSTEM_DEFAULT)
- ? null
- : PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR);
- }
-
@Override
public void createContent(Composite parent) {
Composite content= new Composite(parent, SWT.NONE);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java
index 608cd2e30b4..0eb4ff3ebe7 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java
@@ -262,8 +262,7 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
GridData gd= new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
gd.heightHint= fMacroText.getLineHeight() * 2;
fMacroText.setLayoutData(gd);
- fMacroText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
-
+
final Document doc= new Document();
CUIPlugin.getDefault().getTextTools().setupCDocument(doc);
sourceViewer.setDocument(doc);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/SourceViewerInformationControl.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/SourceViewerInformationControl.java
index 23d155cd8fd..b1ef9f28f54 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/SourceViewerInformationControl.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/SourceViewerInformationControl.java
@@ -1,13 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2002, 2008 QNX Software Systems and others.
+ * Copyright (c) 2002, 2011 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX Software Systems - Initial API and implementation
- * Anton Leherbauer (Wind River Systems)
+ * QNX Software Systems - Initial API and implementation
+ * Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.c.hover;
@@ -46,9 +46,12 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+import org.eclipse.cdt.ui.CDTUITools;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
+import org.eclipse.cdt.ui.text.ICColorConstants;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.ui.editor.CSourceViewer;
@@ -88,6 +91,10 @@ public class SourceViewerInformationControl implements IInformationControl, IInf
* @since 3.0
*/
private Font fStatusTextFont;
+ /**
+ * The color of the optional status text label or null
if none.
+ */
+ private Color fStatusTextForegroundColor;
/**
* The width size constraint.
* @since 4.0
@@ -198,16 +205,49 @@ public class SourceViewerInformationControl implements IInformationControl, IInf
GridData gd2= new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
fStatusField.setLayoutData(gd2);
- // Regarding the color see bug 41128
- fStatusField.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
+ RGB defaultColor= CDTUITools.getColorManager().getColor(ICColorConstants.C_DEFAULT).getRGB();
+ fStatusTextForegroundColor= new Color(fStatusField.getDisplay(), blend(fBackgroundColor.getRGB(), defaultColor, 0.56f));
+ fStatusField.setForeground(fStatusTextForegroundColor);
fStatusField.setBackground(fBackgroundColor);
}
addDisposeListener(this);
}
+ /**
+ * Returns an RGB that lies between the given foreground and background
+ * colors using the given mixing factor. A factor
of 1.0 will produce a
+ * color equal to fg
, while a factor
of 0.0 will produce one
+ * equal to bg
.
+ * @param bg the background color
+ * @param fg the foreground color
+ * @param factor the mixing factor, must be in [0, 1]
+ *
+ * @return the interpolated color
+ */
+ @SuppressWarnings("null")
+ private static RGB blend(RGB bg, RGB fg, float factor) {
+ // copy of org.eclipse.jface.internal.text.revisions.Colors#blend(..)
+ Assert.isLegal(bg != null);
+ Assert.isLegal(fg != null);
+ Assert.isLegal(factor >= 0f && factor <= 1f);
+
+ float complement= 1f - factor;
+ return new RGB(
+ (int) (complement * bg.red + factor * fg.red),
+ (int) (complement * bg.green + factor * fg.green),
+ (int) (complement * bg.blue + factor * fg.blue)
+ );
+ }
+
private void initializeColors() {
- RGB bgRGB= getHoverBackgroundColorRGB();
+ IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
+ RGB bgRGB;
+ if (store.getBoolean(PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR_SYSTEM_DEFAULT)) {
+ bgRGB= getVisibleBackgroundColor(fShell.getDisplay());
+ } else {
+ bgRGB= PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR);
+ }
if (bgRGB != null) {
fBackgroundColor= new Color(fShell.getDisplay(), bgRGB);
fIsSystemBackgroundColor= false;
@@ -217,11 +257,29 @@ public class SourceViewerInformationControl implements IInformationControl, IInf
}
}
- private RGB getHoverBackgroundColorRGB() {
- IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
- return store.getBoolean(PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR_SYSTEM_DEFAULT)
- ? null
- : PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR);
+ /**
+ * Returns null
if {@link SWT#COLOR_INFO_BACKGROUND} is visibly distinct from the
+ * default source text color. Otherwise, returns the editor background color.
+ *
+ * @param display the display
+ * @return an RGB or null
+ */
+ public static RGB getVisibleBackgroundColor(Display display) {
+ float[] infoBgHSB= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND).getRGB().getHSB();
+
+ Color defaultColor= CDTUITools.getColorManager().getColor(ICColorConstants.C_DEFAULT);
+ RGB defaultRGB= defaultColor != null ? defaultColor.getRGB() : new RGB(255, 255, 255);
+ float[] defaultHSB= defaultRGB.getHSB();
+
+ if (Math.abs(infoBgHSB[2] - defaultHSB[2]) < 0.5f) {
+ // workaround for dark tooltip background color, see https://bugs.eclipse.org/365051
+ IPreferenceStore preferenceStore= CUIPlugin.getDefault().getCombinedPreferenceStore();
+ boolean useDefault= preferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
+ if (useDefault)
+ return display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB();
+ return PreferenceConverter.getColor(preferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
+ }
+ return null;
}
/**
@@ -274,6 +332,10 @@ public class SourceViewerInformationControl implements IInformationControl, IInf
if (fStatusTextFont != null && !fStatusTextFont.isDisposed())
fStatusTextFont.dispose();
+ if (fStatusTextForegroundColor != null && !fStatusTextForegroundColor.isDisposed())
+ fStatusTextForegroundColor.dispose();
+
+ fStatusTextForegroundColor= null;
fStatusTextFont= null;
fTextFont= null;
fShell= null;