Skip to content

Commit

Permalink
Revert "Highlighting problem when using the dark theme on Windows
Browse files Browse the repository at this point in the history
eclipse-platform/eclipse.platform.swt#811"

This reverts commit cbda3bc.

Bundle versions are not reverted.
  • Loading branch information
fedejeanne authored and iloveeclipse committed Jun 12, 2024
1 parent 521543f commit c06713f
Show file tree
Hide file tree
Showing 20 changed files with 34 additions and 624 deletions.
1 change: 0 additions & 1 deletion bundles/org.eclipse.jface.text/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Export-Package:
org.eclipse.jface.contentassist.images,
org.eclipse.jface.internal.text;x-internal:=true,
org.eclipse.jface.internal.text.codemining;x-internal:=true,
org.eclipse.jface.internal.text.contentassist;x-internal:=true,
org.eclipse.jface.internal.text.html;x-friends:="org.eclipse.ant.ui, org.eclipse.jdt.ui, org.eclipse.ltk.ui.refactoring, org.eclipse.pde.ui, org.eclipse.ui.editors, org.eclipse.xtext.ui",
org.eclipse.jface.internal.text.link.contentassist;x-internal:=true,
org.eclipse.jface.internal.text.revisions;x-internal:=true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.JFaceResources;


/**
* Adds owner draw support for tables.
Expand All @@ -45,10 +42,6 @@ public class TableOwnerDrawSupport implements Listener {

public static void install(Table table) {
TableOwnerDrawSupport listener= new TableOwnerDrawSupport(table);
installListener(table, listener);
}

protected static void installListener(Table table, Listener listener) {
table.addListener(SWT.Dispose, listener);
table.addListener(SWT.MeasureItem, listener);
table.addListener(SWT.EraseItem, listener);
Expand Down Expand Up @@ -77,7 +70,7 @@ private static StyleRange[] getStyledRanges(TableItem item, int column) {
return (StyleRange[])item.getData(STYLED_RANGES_KEY + column);
}

protected TableOwnerDrawSupport(Table table) {
private TableOwnerDrawSupport(Table table) {
int orientation= table.getStyle() & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
fSharedLayout= new TextLayout(table.getDisplay());
fSharedLayout.setOrientation(orientation);
Expand Down Expand Up @@ -154,28 +147,7 @@ private void performPaint(Event event) {
Color oldForeground= gc.getForeground();
Color oldBackground= gc.getBackground();

if (isSelected) {
Color background= item.getParent().isFocusControl()
? getSelectedRowBackgroundColor()
: getSelectedRowBackgroundColorNoFocus();
Color foreground= item.getParent().isFocusControl()
? getSelectedRowForegroundColor()
: getSelectedRowForegroundColorNoFocus();

if (background == null) {
background= item.getDisplay().getSystemColor(
SWT.COLOR_LIST_SELECTION);
}

if (foreground == null) {
foreground= item.getDisplay().getSystemColor(
SWT.COLOR_LIST_SELECTION_TEXT);
}

gc.setBackground(background);
gc.setForeground(foreground);
gc.fillRectangle(0, event.y, item.getParent().getBounds().width, event.height);
} else {
if (!isSelected) {
Color foreground= item.getForeground(index);
gc.setForeground(foreground);

Expand Down Expand Up @@ -206,54 +178,10 @@ private void performPaint(Event event) {
gc.drawFocus(focusBounds.x, focusBounds.y, focusBounds.width + fDeltaOfLastMeasure, focusBounds.height);
}

gc.setForeground(oldForeground);
gc.setBackground(oldBackground);
}

/**
* The color to use when rendering the background of the selected row when the control has the
* input focus
*
* @return the color or <code>null</code> to use the default
*/
protected Color getSelectedRowBackgroundColor() {
ColorRegistry colorRegistry= JFaceResources.getColorRegistry();
return colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_BACKGROUND"); //$NON-NLS-1$
}

/**
* The color to use when rendering the foreground (=text) of the selected row when the control
* has the input focus
*
* @return the color or <code>null</code> to use the default
*/
protected Color getSelectedRowForegroundColor() {
ColorRegistry colorRegistry= JFaceResources.getColorRegistry();
return colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_FOREGROUND"); //$NON-NLS-1$
}

/**
* The color to use when rendering the foreground (=text) of the selected row when the control
* has <b>no</b> input focus
*
* @return the color or <code>null</code> to use the same used when control has focus
* @since 3.4
*/
protected Color getSelectedRowForegroundColorNoFocus() {
ColorRegistry colorRegistry= JFaceResources.getColorRegistry();
return colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_FOREGROUND_NO_FOCUS"); //$NON-NLS-1$
}

/**
* The color to use when rendering the background of the selected row when the control has
* <b>no</b> input focus
*
* @return the color or <code>null</code> to use the same used when control has focus
* @since 3.4
*/
protected Color getSelectedRowBackgroundColorNoFocus() {
ColorRegistry colorRegistry= JFaceResources.getColorRegistry();
return colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_BACKGROUND_NO_FOCUS"); //$NON-NLS-1$
if (!isSelected) {
gc.setForeground(oldForeground);
gc.setBackground(oldBackground);
}
}

private void widgetDisposed() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

import org.eclipse.jface.internal.text.contentassist.CompletionTableDrawSupport;
import org.eclipse.jface.internal.text.TableOwnerDrawSupport;
import org.eclipse.jface.preference.JFacePreferences;
import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.JFaceColors;
Expand Down Expand Up @@ -269,7 +269,7 @@ private void createProposalSelector() {

fIsColoredLabelsSupportEnabled= fContentAssistant.isColoredLabelsSupportEnabled();
if (fIsColoredLabelsSupportEnabled)
CompletionTableDrawSupport.install(fProposalTable);
TableOwnerDrawSupport.install(fProposalTable);

fProposalTable.setLocation(0, 0);
if (fAdditionalInfoController != null)
Expand Down Expand Up @@ -572,7 +572,7 @@ private void setProposals(ICompletionProposal[] proposals) {

item.setText(displayString);
if (fIsColoredLabelsSupportEnabled)
CompletionTableDrawSupport.storeStyleRanges(item, 0, styleRanges);
TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges);

item.setData(p);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
import org.eclipse.jface.bindings.keys.SWTKeySupport;
import org.eclipse.jface.contentassist.IContentAssistSubjectControl;
import org.eclipse.jface.internal.text.InformationControlReplacer;
import org.eclipse.jface.internal.text.contentassist.CompletionTableDrawSupport;
import org.eclipse.jface.internal.text.TableOwnerDrawSupport;
import org.eclipse.jface.preference.JFacePreferences;
import org.eclipse.jface.resource.JFaceColors;
import org.eclipse.jface.resource.JFaceResources;
Expand Down Expand Up @@ -613,7 +613,7 @@ void createProposalSelector() {

fIsColoredLabelsSupportEnabled= fContentAssistant.isColoredLabelsSupportEnabled();
if (fIsColoredLabelsSupportEnabled)
CompletionTableDrawSupport.install(fProposalTable);
TableOwnerDrawSupport.install(fProposalTable);

fProposalTable.setLocation(0, 0);
if (fAdditionalInfoController != null)
Expand Down Expand Up @@ -904,7 +904,7 @@ private void handleSetData(Event event) {

item.setText(displayString);
if (fIsColoredLabelsSupportEnabled)
CompletionTableDrawSupport.storeStyleRanges(item, 0, styleRanges);
TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges);

item.setImage(image);
item.setData(current);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.util.Util;
import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
Expand Down Expand Up @@ -153,8 +151,8 @@ private void hookListener(final ColumnViewer viewer) {
* @return the color or <code>null</code> to use the default
*/
protected Color getSelectedCellBackgroundColor(ViewerCell cell) {
ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
return colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_BACKGROUND"); //$NON-NLS-1$
return removeNonFocusedSelectionInformation ? null
: cell.getItem().getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
}

/**
Expand All @@ -166,8 +164,7 @@ protected Color getSelectedCellBackgroundColor(ViewerCell cell) {
* @return the color or <code>null</code> to use the default
*/
protected Color getSelectedCellForegroundColor(ViewerCell cell) {
ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
return colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_FOREGROUND"); //$NON-NLS-1$
return null;
}

/**
Expand All @@ -181,8 +178,7 @@ protected Color getSelectedCellForegroundColor(ViewerCell cell) {
* @since 3.4
*/
protected Color getSelectedCellForegroundColorNoFocus(ViewerCell cell) {
ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
return colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_FOREGROUND_NO_FOCUS"); //$NON-NLS-1$
return null;
}

/**
Expand All @@ -196,8 +192,7 @@ protected Color getSelectedCellForegroundColorNoFocus(ViewerCell cell) {
* @since 3.4
*/
protected Color getSelectedCellBackgroundColorNoFocus(ViewerCell cell) {
ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
return colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_BACKGROUND_NO_FOCUS"); //$NON-NLS-1$
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import java.util.HashSet;
import java.util.Set;

import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Rectangle;
Expand Down Expand Up @@ -168,16 +166,20 @@ public void update(ViewerCell cell) {
}

/**
* Handle the erase event. The default implementation colors the background of
* selected areas with "org.eclipse.ui.workbench.SELECTED_CELL_BACKGROUND" and
* foregrounds with "org.eclipse.ui.workbench.SELECTED_CELL_FOREGROUND". Note
* that this implementation causes non-native behavior on some platforms.
* Subclasses should override this method and <b>not</b> call the super
* Handle the erase event. The default implementation colors the background
* of selected areas with {@link SWT#COLOR_LIST_SELECTION} and foregrounds
* with {@link SWT#COLOR_LIST_SELECTION_TEXT}. Note that this
* implementation causes non-native behavior on some platforms. Subclasses
* should override this method and <b>not</b> call the super
* implementation.
*
* @param event the erase event
* @param element the model object
* @param event
* the erase event
* @param element
* the model object
* @see SWT#EraseItem
* @see SWT#COLOR_LIST_SELECTION
* @see SWT#COLOR_LIST_SELECTION_TEXT
*/
protected void erase(Event event, Object element) {

Expand All @@ -187,16 +189,11 @@ protected void erase(Event event, Object element) {
Color oldForeground = event.gc.getForeground();
Color oldBackground = event.gc.getBackground();

ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
if (event.widget instanceof Control control && control.isFocusControl()) {
event.gc.setBackground(colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_BACKGROUND")); //$NON-NLS-1$
event.gc.setForeground(colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_FOREGROUND")); //$NON-NLS-1$
} else {
event.gc.setBackground(colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_BACKGROUND_NO_FOCUS")); //$NON-NLS-1$
event.gc.setForeground(colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_FOREGROUND_NO_FOCUS")); //$NON-NLS-1$
}
event.gc.setBackground(event.item.getDisplay().getSystemColor(
SWT.COLOR_LIST_SELECTION));
event.gc.setForeground(event.item.getDisplay().getSystemColor(
SWT.COLOR_LIST_SELECTION_TEXT));
event.gc.fillRectangle(bounds);

/* restore the old GC colors */
event.gc.setForeground(oldForeground);
event.gc.setBackground(oldBackground);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ protected void erase(Event event, Object element) {
// info has been set by 'update': announce that we paint ourselves
event.detail &= ~SWT.FOREGROUND;
}
super.erase(event, element);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.eclipse.jface.viewers;

import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.internal.ColumnViewerSelectionColorListener;
import org.eclipse.jface.viewers.internal.ExpandableNode;
import org.eclipse.pde.api.tools.annotations.NoExtend;
import org.eclipse.swt.SWT;
Expand Down Expand Up @@ -120,7 +119,6 @@ public TableViewer(Composite parent, int style) {
public TableViewer(Table table) {
this.table = table;
hookControl(table);
overwriteSelectionColor();
}

@Override
Expand Down Expand Up @@ -509,13 +507,4 @@ void handleExpandableNodeClicked(Widget w) {
}
}

/**
* The color of the selected item is drawn by the OS. On some OS the color might
* be not accessible. To fix this issue the background color for selected items
* is drawn in a custom method.
*/
private void overwriteSelectionColor() {
ColumnViewerSelectionColorListener.addListenerToViewer(this);
}

}
Loading

0 comments on commit c06713f

Please sign in to comment.