|
25 | 25 | import org.eclipse.swt.widgets.Table;
|
26 | 26 | import org.eclipse.swt.widgets.TableItem;
|
27 | 27 |
|
| 28 | +import org.eclipse.jface.resource.ColorRegistry; |
| 29 | +import org.eclipse.jface.resource.JFaceResources; |
| 30 | + |
28 | 31 |
|
29 | 32 | /**
|
30 | 33 | * Adds owner draw support for tables.
|
@@ -147,7 +150,28 @@ private void performPaint(Event event) {
|
147 | 150 | Color oldForeground= gc.getForeground();
|
148 | 151 | Color oldBackground= gc.getBackground();
|
149 | 152 |
|
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 { |
151 | 175 | Color foreground= item.getForeground(index);
|
152 | 176 | gc.setForeground(foreground);
|
153 | 177 |
|
@@ -178,10 +202,54 @@ private void performPaint(Event event) {
|
178 | 202 | gc.drawFocus(focusBounds.x, focusBounds.y, focusBounds.width + fDeltaOfLastMeasure, focusBounds.height);
|
179 | 203 | }
|
180 | 204 |
|
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$ |
185 | 253 | }
|
186 | 254 |
|
187 | 255 | private void widgetDisposed() {
|
|
0 commit comments