Skip to content

Commit 3b5769b

Browse files
Christopher-Hermannfedejeanne
authored andcommitted
Use eclipse.ui selection colors in TableOwnerDrawSupport
1 parent 294ee65 commit 3b5769b

File tree

1 file changed

+73
-5
lines changed

1 file changed

+73
-5
lines changed

bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/TableOwnerDrawSupport.java

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import org.eclipse.swt.widgets.Table;
2626
import org.eclipse.swt.widgets.TableItem;
2727

28+
import org.eclipse.jface.resource.ColorRegistry;
29+
import org.eclipse.jface.resource.JFaceResources;
30+
2831

2932
/**
3033
* Adds owner draw support for tables.
@@ -147,7 +150,28 @@ private void performPaint(Event event) {
147150
Color oldForeground= gc.getForeground();
148151
Color oldBackground= gc.getBackground();
149152

150-
if (!isSelected) {
153+
if (isSelected) {
154+
Color background= item.getParent().isFocusControl()
155+
? getSelectedRowBackgroundColor()
156+
: getSelectedRowBackgroundColorNoFocus();
157+
Color foreground= item.getParent().isFocusControl()
158+
? getSelectedRowForegroundColor()
159+
: getSelectedRowForegroundColorNoFocus();
160+
161+
if (background == null) {
162+
background= item.getDisplay().getSystemColor(
163+
SWT.COLOR_LIST_SELECTION);
164+
}
165+
166+
if (foreground == null) {
167+
foreground= item.getDisplay().getSystemColor(
168+
SWT.COLOR_LIST_SELECTION_TEXT);
169+
}
170+
171+
gc.setBackground(background);
172+
gc.setForeground(foreground);
173+
gc.fillRectangle(0, event.y, item.getParent().getBounds().width, event.height);
174+
} else {
151175
Color foreground= item.getForeground(index);
152176
gc.setForeground(foreground);
153177

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

181-
if (!isSelected) {
182-
gc.setForeground(oldForeground);
183-
gc.setBackground(oldBackground);
184-
}
205+
gc.setForeground(oldForeground);
206+
gc.setBackground(oldBackground);
207+
}
208+
209+
/**
210+
* The color to use when rendering the background of the selected row when the control has the
211+
* input focus
212+
*
213+
* @return the color or <code>null</code> to use the default
214+
*/
215+
protected Color getSelectedRowBackgroundColor() {
216+
ColorRegistry colorRegistry= JFaceResources.getColorRegistry();
217+
return colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_BACKGROUND"); //$NON-NLS-1$
218+
}
219+
220+
/**
221+
* The color to use when rendering the foreground (=text) of the selected row when the control
222+
* has the input focus
223+
*
224+
* @return the color or <code>null</code> to use the default
225+
*/
226+
protected Color getSelectedRowForegroundColor() {
227+
ColorRegistry colorRegistry= JFaceResources.getColorRegistry();
228+
return colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_FOREGROUND"); //$NON-NLS-1$
229+
}
230+
231+
/**
232+
* The color to use when rendering the foreground (=text) of the selected row when the control
233+
* has <b>no</b> input focus
234+
*
235+
* @return the color or <code>null</code> to use the same used when control has focus
236+
* @since 3.4
237+
*/
238+
protected Color getSelectedRowForegroundColorNoFocus() {
239+
ColorRegistry colorRegistry= JFaceResources.getColorRegistry();
240+
return colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_FOREGROUND_NO_FOCUS"); //$NON-NLS-1$
241+
}
242+
243+
/**
244+
* The color to use when rendering the background of the selected row when the control has
245+
* <b>no</b> input focus
246+
*
247+
* @return the color or <code>null</code> to use the same used when control has focus
248+
* @since 3.4
249+
*/
250+
protected Color getSelectedRowBackgroundColorNoFocus() {
251+
ColorRegistry colorRegistry= JFaceResources.getColorRegistry();
252+
return colorRegistry.get("org.eclipse.ui.workbench.SELECTED_CELL_BACKGROUND_NO_FOCUS"); //$NON-NLS-1$
185253
}
186254

187255
private void widgetDisposed() {

0 commit comments

Comments
 (0)