Skip to content

Commit

Permalink
Use eclipse.ui selection colors in TableOwnerDrawSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher-Hermann authored and BeckerWdf committed May 13, 2024
1 parent 63b12a0 commit 3d38c23
Showing 1 changed file with 73 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
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 Down Expand Up @@ -147,7 +150,28 @@ private void performPaint(Event event) {
Color oldForeground= gc.getForeground();
Color oldBackground= gc.getBackground();

if (!isSelected) {
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 {
Color foreground= item.getForeground(index);
gc.setForeground(foreground);

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

if (!isSelected) {
gc.setForeground(oldForeground);
gc.setBackground(oldBackground);
}
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$
}

private void widgetDisposed() {
Expand Down

0 comments on commit 3d38c23

Please sign in to comment.