@@ -110,6 +110,7 @@ public class ViewsPreferencePage extends PreferencePage implements IWorkbenchPre
110110 private ControlDecoration colorFontsDecorator ;
111111 private ColorsAndFontsTheme currentColorsAndFontsTheme ;
112112 private Map <String , String > themeAssociations ;
113+ private boolean highContrastMode ;
113114
114115 private Button themingEnabled ;
115116 private Button rescaleAtRuntime ;
@@ -125,11 +126,15 @@ protected Control createContents(Composite parent) {
125126
126127 Composite comp = new Composite (parent , SWT .NONE );
127128
128- themingEnabled = createCheckButton (comp , WorkbenchMessages .ThemingEnabled , engine != null );
129+ highContrastMode = parent .getDisplay ().getHighContrast ();
130+ // Deactivate theming in high contrast mode
131+ themingEnabled = createCheckButton (comp , WorkbenchMessages .ThemingEnabled , isThemingPossible ());
132+ themingEnabled .setEnabled (!highContrastMode );
129133
130- // if started with "-cssTheme none", CSS settings should be disabled
131- // but other appearance settings should be *not* disabled
132- if (engine == null ) {
134+ // if started with "-cssTheme none" or if high contrast mode is active,
135+ // CSS settings should be disabled but other appearance settings should be *not*
136+ // disabled
137+ if (!isThemingPossible ()) {
133138 GridLayout layout = new GridLayout (1 , false );
134139 layout .horizontalSpacing = 10 ;
135140 comp .setLayout (layout );
@@ -192,6 +197,21 @@ protected Control createContents(Composite parent) {
192197 return comp ;
193198 }
194199
200+ /**
201+ * @return <code>true</code> if there is a theme engine set (<i>i.e.</i> if the
202+ * workbench started with the checkbox "enable theming" set to
203+ * <code>true</code>) and the <i>high contrast mode</i> is
204+ * <strong>disabled on the OS.
205+ *
206+ * @implNote Currently only Windows is able to tell if <i>high contrast mode</i>
207+ * is active. Linux and Mac lack this functionality (they always say
208+ * it is <b>disabled</b>).
209+ *
210+ */
211+ private boolean isThemingPossible () {
212+ return engine != null && !highContrastMode ;
213+ }
214+
195215 private void createRescaleAtRuntimeCheckButton (Composite parent ) {
196216 if (!OS .isWindows ()) {
197217 return ;
@@ -313,7 +333,7 @@ public void init(IWorkbench workbench) {
313333 public boolean performOk () {
314334 IEclipsePreferences prefs = InstanceScope .INSTANCE
315335 .getNode (PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT );
316- if (engine != null ) {
336+ if (isThemingPossible () ) {
317337 ITheme theme = getSelectedTheme ();
318338 if (theme != null ) {
319339 engine .setTheme (getSelectedTheme (), true );
@@ -326,9 +346,14 @@ public boolean performOk() {
326346 apiStore .setValue (IWorkbenchPreferenceConstants .USE_COLORED_LABELS , useColoredLabels .getSelection ());
327347
328348 prefs .putBoolean (StackRenderer .MRU_KEY , enableMru .getSelection ());
329- boolean themingEnabledChanged = prefs .getBoolean (PartRenderingEngine .ENABLED_THEME_KEY , true ) != themingEnabled
330- .getSelection ();
331- prefs .putBoolean (PartRenderingEngine .ENABLED_THEME_KEY , themingEnabled .getSelection ());
349+ boolean themingEnabledChanged = false ;
350+ // Only if the setting is modifiable by the user does checking for it (and
351+ // storing it) make sense
352+ if (themingEnabled .isEnabled ()) {
353+ themingEnabledChanged = prefs .getBoolean (PartRenderingEngine .ENABLED_THEME_KEY , true ) != themingEnabled
354+ .getSelection ();
355+ prefs .putBoolean (PartRenderingEngine .ENABLED_THEME_KEY , themingEnabled .getSelection ());
356+ }
332357
333358 boolean isRescaleAtRuntimeChanged = false ;
334359 if (rescaleAtRuntime != null ) {
@@ -356,7 +381,7 @@ public boolean performOk() {
356381 String restartDialogTitle = null ;
357382 String restartDialogMessage = null ;
358383
359- if (engine != null ) {
384+ if (isThemingPossible () ) {
360385 ITheme theme = getSelectedTheme ();
361386 boolean themeChanged = theme != null && !theme .equals (currentTheme );
362387 boolean colorsAndFontsThemeChanged = !PlatformUI .getWorkbench ().getThemeManager ().getCurrentTheme ().getId ()
@@ -417,7 +442,7 @@ private void setColorsAndFontsTheme(ColorsAndFontsTheme theme) {
417442 protected void performDefaults () {
418443 IEclipsePreferences defaultPrefs = DefaultScope .INSTANCE
419444 .getNode (PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT );
420- if (engine != null ) {
445+ if (isThemingPossible () ) {
421446 setColorsAndFontsTheme (currentColorsAndFontsTheme );
422447
423448 engine .setTheme (defaultTheme , true );
@@ -441,7 +466,7 @@ protected void performDefaults() {
441466
442467 @ Override
443468 public boolean performCancel () {
444- if (engine != null ) {
469+ if (isThemingPossible () ) {
445470 setColorsAndFontsTheme (currentColorsAndFontsTheme );
446471
447472 if (currentTheme != null && !currentTheme .equals (engine .getActiveTheme ())) {
0 commit comments